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;
90 # URI of GIT logo (72x27 size)
91 our $logo = "++GITWEB_LOGO++";
92 # URI of GIT favicon, assumed to be image/png type
93 our $favicon = "++GITWEB_FAVICON++";
95 # URI and label (title) of GIT logo link
96 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
97 #our $logo_label = "git documentation";
98 our $logo_url = "http://git.or.cz/";
99 our $logo_label = "git homepage";
101 # source of projects list
102 our $projects_list = "++GITWEB_LIST++";
104 # the width (in characters) of the projects list "Description" column
105 our $projects_list_description_width = 25;
107 # default order of projects list
108 # valid values are none, project, descr, owner, and age
109 our $default_projects_order = "project";
111 # show repository only if this file exists
112 # (only effective if this variable evaluates to true)
113 our $export_ok = "++GITWEB_EXPORT_OK++";
115 # show repository only if this subroutine returns true
116 # when given the path to the project, for example:
117 # sub { return -e "$_[0]/git-daemon-export-ok"; }
118 our $export_auth_hook = undef;
120 # only allow viewing of repositories also shown on the overview page
121 our $strict_export = "++GITWEB_STRICT_EXPORT++";
123 # list of git base URLs used for URL to where fetch project from,
124 # i.e. full URL is "$git_base_url/$project"
125 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
127 # default blob_plain mimetype and default charset for text/plain blob
128 our $default_blob_plain_mimetype = 'text/plain';
129 our $default_text_plain_charset = undef;
131 # file to use for guessing MIME types before trying /etc/mime.types
132 # (relative to the current git repository)
133 our $mimetypes_file = undef;
135 # assume this charset if line contains non-UTF-8 characters;
136 # it should be valid encoding (see Encoding::Supported(3pm) for list),
137 # for which encoding all byte sequences are valid, for example
138 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
139 # could be even 'utf-8' for the old behavior)
140 our $fallback_encoding = 'latin1';
142 # rename detection options for git-diff and git-diff-tree
143 # - default is '-M', with the cost proportional to
144 # (number of removed files) * (number of new files).
145 # - more costly is '-C' (which implies '-M'), with the cost proportional to
146 # (number of changed files + number of removed files) * (number of new files)
147 # - even more costly is '-C', '--find-copies-harder' with cost
148 # (number of files in the original tree) * (number of new files)
149 # - one might want to include '-B' option, e.g. '-B', '-M'
150 our @diff_opts = ('-M'); # taken from git_commit
152 # Disables features that would allow repository owners to inject script into
154 our $prevent_xss = 0;
156 # information about snapshot formats that gitweb is capable of serving
157 our %known_snapshot_formats = (
159 # 'display' => display name,
160 # 'type' => mime type,
161 # 'suffix' => filename suffix,
162 # 'format' => --format for git-archive,
163 # 'compressor' => [compressor command and arguments]
164 # (array reference, 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']},
182 'type' => 'application/x-zip',
187 # Aliases so we understand old gitweb.snapshot values in repository
189 our %known_snapshot_format_aliases = (
193 # backward compatibility: legacy gitweb config support
194 'x-gzip' => undef, 'gz' => undef,
195 'x-bzip2' => undef, 'bz2' => undef,
196 'x-zip' => undef, '' => undef,
199 # Pixel sizes for icons and avatars. If the default font sizes or lineheights
200 # are changed, it may be appropriate to change these values too via
207 # You define site-wide feature defaults here; override them with
208 # $GITWEB_CONFIG as necessary.
211 # 'sub' => feature-sub (subroutine),
212 # 'override' => allow-override (boolean),
213 # 'default' => [ default options...] (array reference)}
215 # if feature is overridable (it means that allow-override has true value),
216 # then feature-sub will be called with default options as parameters;
217 # return value of feature-sub indicates if to enable specified feature
219 # if there is no 'sub' key (no feature-sub), then feature cannot be
222 # use gitweb_get_feature(<feature>) to retrieve the <feature> value
223 # (an array) or gitweb_check_feature(<feature>) to check if <feature>
226 # Enable the 'blame' blob view, showing the last commit that modified
227 # each line in the file. This can be very CPU-intensive.
229 # To enable system wide have in $GITWEB_CONFIG
230 # $feature{'blame'}{'default'} = [1];
231 # To have project specific config enable override in $GITWEB_CONFIG
232 # $feature{'blame'}{'override'} = 1;
233 # and in project config gitweb.blame = 0|1;
235 'sub' => sub { feature_bool
('blame', @_) },
239 # Enable the 'snapshot' link, providing a compressed archive of any
240 # tree. This can potentially generate high traffic if you have large
243 # Value is a list of formats defined in %known_snapshot_formats that
245 # To disable system wide have in $GITWEB_CONFIG
246 # $feature{'snapshot'}{'default'} = [];
247 # To have project specific config enable override in $GITWEB_CONFIG
248 # $feature{'snapshot'}{'override'} = 1;
249 # and in project config, a comma-separated list of formats or "none"
250 # to disable. Example: gitweb.snapshot = tbz2,zip;
252 'sub' => \
&feature_snapshot
,
254 'default' => ['tgz']},
256 # Enable text search, which will list the commits which match author,
257 # committer or commit text to a given string. Enabled by default.
258 # Project specific override is not supported.
263 # Enable grep search, which will list the files in currently selected
264 # tree containing the given string. Enabled by default. This can be
265 # potentially CPU-intensive, of course.
267 # To enable system wide have in $GITWEB_CONFIG
268 # $feature{'grep'}{'default'} = [1];
269 # To have project specific config enable override in $GITWEB_CONFIG
270 # $feature{'grep'}{'override'} = 1;
271 # and in project config gitweb.grep = 0|1;
273 'sub' => sub { feature_bool
('grep', @_) },
277 # Enable the pickaxe search, which will list the commits that modified
278 # a given string in a file. This can be practical and quite faster
279 # alternative to 'blame', but still potentially CPU-intensive.
281 # To enable system wide have in $GITWEB_CONFIG
282 # $feature{'pickaxe'}{'default'} = [1];
283 # To have project specific config enable override in $GITWEB_CONFIG
284 # $feature{'pickaxe'}{'override'} = 1;
285 # and in project config gitweb.pickaxe = 0|1;
287 'sub' => sub { feature_bool
('pickaxe', @_) },
291 # Make gitweb use an alternative format of the URLs which can be
292 # more readable and natural-looking: project name is embedded
293 # directly in the path and the query string contains other
294 # auxiliary information. All gitweb installations recognize
295 # URL in either format; this configures in which formats gitweb
298 # To enable system wide have in $GITWEB_CONFIG
299 # $feature{'pathinfo'}{'default'} = [1];
300 # Project specific override is not supported.
302 # Note that you will need to change the default location of CSS,
303 # favicon, logo and possibly other files to an absolute URL. Also,
304 # if gitweb.cgi serves as your indexfile, you will need to force
305 # $my_uri to contain the script name in your $GITWEB_CONFIG.
310 # Make gitweb consider projects in project root subdirectories
311 # to be forks of existing projects. Given project $projname.git,
312 # projects matching $projname/*.git will not be shown in the main
313 # projects list, instead a '+' mark will be added to $projname
314 # there and a 'forks' view will be enabled for the project, listing
315 # all the forks. If project list is taken from a file, forks have
316 # to be listed after the main project.
318 # To enable system wide have in $GITWEB_CONFIG
319 # $feature{'forks'}{'default'} = [1];
320 # Project specific override is not supported.
325 # Insert custom links to the action bar of all project pages.
326 # This enables you mainly to link to third-party scripts integrating
327 # into gitweb; e.g. git-browser for graphical history representation
328 # or custom web-based repository administration interface.
330 # The 'default' value consists of a list of triplets in the form
331 # (label, link, position) where position is the label after which
332 # to insert the link and link is a format string where %n expands
333 # to the project name, %f to the project path within the filesystem,
334 # %h to the current hash (h gitweb parameter) and %b to the current
335 # hash base (hb gitweb parameter); %% expands to %.
337 # To enable system wide have in $GITWEB_CONFIG e.g.
338 # $feature{'actions'}{'default'} = [('graphiclog',
339 # '/git-browser/by-commit.html?r=%n', 'summary')];
340 # Project specific override is not supported.
345 # Allow gitweb scan project content tags described in ctags/
346 # of project repository, and display the popular Web 2.0-ish
347 # "tag cloud" near the project list. Note that this is something
348 # COMPLETELY different from the normal Git tags.
350 # gitweb by itself can show existing tags, but it does not handle
351 # tagging itself; you need an external application for that.
352 # For an example script, check Girocco's cgi/tagproj.cgi.
353 # You may want to install the HTML::TagCloud Perl module to get
354 # a pretty tag cloud instead of just a list of tags.
356 # To enable system wide have in $GITWEB_CONFIG
357 # $feature{'ctags'}{'default'} = ['path_to_tag_script'];
358 # Project specific override is not supported.
363 # The maximum number of patches in a patchset generated in patch
364 # view. Set this to 0 or undef to disable patch view, or to a
365 # negative number to remove any limit.
367 # To disable system wide have in $GITWEB_CONFIG
368 # $feature{'patches'}{'default'} = [0];
369 # To have project specific config enable override in $GITWEB_CONFIG
370 # $feature{'patches'}{'override'} = 1;
371 # and in project config gitweb.patches = 0|n;
372 # where n is the maximum number of patches allowed in a patchset.
374 'sub' => \
&feature_patches
,
378 # Avatar support. When this feature is enabled, views such as
379 # shortlog or commit will display an avatar associated with
380 # the email of the committer(s) and/or author(s).
382 # Currently only the gravatar provider is available, and it
383 # depends on Digest::MD5. If an unknown provider is specified,
384 # the feature is disabled.
386 # To enable system wide have in $GITWEB_CONFIG
387 # $feature{'avatar'}{'default'} = ['gravatar'];
388 # To have project specific config enable override in $GITWEB_CONFIG
389 # $feature{'avatar'}{'override'} = 1;
390 # and in project config gitweb.avatar = gravatar;
392 'sub' => \
&feature_avatar
,
397 sub gitweb_get_feature
{
399 return unless exists $feature{$name};
400 my ($sub, $override, @defaults) = (
401 $feature{$name}{'sub'},
402 $feature{$name}{'override'},
403 @{$feature{$name}{'default'}});
404 if (!$override) { return @defaults; }
406 warn "feature $name is not overrideable";
409 return $sub->(@defaults);
412 # A wrapper to check if a given feature is enabled.
413 # With this, you can say
415 # my $bool_feat = gitweb_check_feature('bool_feat');
416 # gitweb_check_feature('bool_feat') or somecode;
420 # my ($bool_feat) = gitweb_get_feature('bool_feat');
421 # (gitweb_get_feature('bool_feat'))[0] or somecode;
423 sub gitweb_check_feature
{
424 return (gitweb_get_feature
(@_))[0];
430 my ($val) = git_get_project_config
($key, '--bool');
434 } elsif ($val eq 'true') {
436 } elsif ($val eq 'false') {
441 sub feature_snapshot
{
444 my ($val) = git_get_project_config
('snapshot');
447 @fmts = ($val eq 'none' ? () : split /\s*[,\s]\s*/, $val);
453 sub feature_patches
{
454 my @val = (git_get_project_config
('patches', '--int'));
464 my @val = (git_get_project_config
('avatar'));
466 return @val ? @val : @_;
469 # checking HEAD file with -e is fragile if the repository was
470 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
472 sub check_head_link
{
474 my $headfile = "$dir/HEAD";
475 return ((-e
$headfile) ||
476 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
479 sub check_export_ok
{
481 return (check_head_link
($dir) &&
482 (!$export_ok || -e
"$dir/$export_ok") &&
483 (!$export_auth_hook || $export_auth_hook->($dir)));
486 # process alternate names for backward compatibility
487 # filter out unsupported (unknown) snapshot formats
488 sub filter_snapshot_fmts
{
492 exists $known_snapshot_format_aliases{$_} ?
493 $known_snapshot_format_aliases{$_} : $_} @fmts;
495 exists $known_snapshot_formats{$_} } @fmts;
498 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
499 if (-e
$GITWEB_CONFIG) {
502 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
503 do $GITWEB_CONFIG_SYSTEM if -e
$GITWEB_CONFIG_SYSTEM;
506 # version of the core git binary
507 our $git_version = qx("$GIT" --version) =~ m/git version (.*)$/ ? $1 : "unknown";
509 $projects_list ||= $projectroot;
511 # ======================================================================
512 # input validation and dispatch
514 # input parameters can be collected from a variety of sources (presently, CGI
515 # and PATH_INFO), so we define an %input_params hash that collects them all
516 # together during validation: this allows subsequent uses (e.g. href()) to be
517 # agnostic of the parameter origin
519 our %input_params = ();
521 # input parameters are stored with the long parameter name as key. This will
522 # also be used in the href subroutine to convert parameters to their CGI
523 # equivalent, and since the href() usage is the most frequent one, we store
524 # the name -> CGI key mapping here, instead of the reverse.
526 # XXX: Warning: If you touch this, check the search form for updating,
529 our @cgi_param_mapping = (
537 hash_parent_base
=> "hpb",
542 snapshot_format
=> "sf",
543 extra_options
=> "opt",
544 search_use_regexp
=> "sr",
546 our %cgi_param_mapping = @cgi_param_mapping;
548 # we will also need to know the possible actions, for validation
550 "blame" => \
&git_blame
,
551 "blobdiff" => \
&git_blobdiff
,
552 "blobdiff_plain" => \
&git_blobdiff_plain
,
553 "blob" => \
&git_blob
,
554 "blob_plain" => \
&git_blob_plain
,
555 "commitdiff" => \
&git_commitdiff
,
556 "commitdiff_plain" => \
&git_commitdiff_plain
,
557 "commit" => \
&git_commit
,
558 "forks" => \
&git_forks
,
559 "heads" => \
&git_heads
,
560 "history" => \
&git_history
,
562 "patch" => \
&git_patch
,
563 "patches" => \
&git_patches
,
565 "atom" => \
&git_atom
,
566 "search" => \
&git_search
,
567 "search_help" => \
&git_search_help
,
568 "shortlog" => \
&git_shortlog
,
569 "summary" => \
&git_summary
,
571 "tags" => \
&git_tags
,
572 "tree" => \
&git_tree
,
573 "snapshot" => \
&git_snapshot
,
574 "object" => \
&git_object
,
575 # those below don't need $project
576 "opml" => \
&git_opml
,
577 "project_list" => \
&git_project_list
,
578 "project_index" => \
&git_project_index
,
581 # finally, we have the hash of allowed extra_options for the commands that
583 our %allowed_options = (
584 "--no-merges" => [ qw(rss atom log shortlog history) ],
587 # fill %input_params with the CGI parameters. All values except for 'opt'
588 # should be single values, but opt can be an array. We should probably
589 # build an array of parameters that can be multi-valued, but since for the time
590 # being it's only this one, we just single it out
591 while (my ($name, $symbol) = each %cgi_param_mapping) {
592 if ($symbol eq 'opt') {
593 $input_params{$name} = [ $cgi->param($symbol) ];
595 $input_params{$name} = $cgi->param($symbol);
599 # now read PATH_INFO and update the parameter list for missing parameters
600 sub evaluate_path_info
{
601 return if defined $input_params{'project'};
602 return if !$path_info;
603 $path_info =~ s
,^/+,,;
604 return if !$path_info;
606 # find which part of PATH_INFO is project
607 my $project = $path_info;
609 while ($project && !check_head_link
("$projectroot/$project")) {
610 $project =~ s
,/*[^/]*$,,;
612 return unless $project;
613 $input_params{'project'} = $project;
615 # do not change any parameters if an action is given using the query string
616 return if $input_params{'action'};
617 $path_info =~ s
,^\Q
$project\E
/*,,;
619 # next, check if we have an action
620 my $action = $path_info;
622 if (exists $actions{$action}) {
623 $path_info =~ s
,^$action/*,,;
624 $input_params{'action'} = $action;
627 # list of actions that want hash_base instead of hash, but can have no
628 # pathname (f) parameter
635 # [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name]
636 my ($parentrefname, $parentpathname, $refname, $pathname) =
637 ($path_info =~ /^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/);
639 # first, analyze the 'current' part
640 if (defined $pathname) {
641 # we got "branch:filename" or "branch:dir/"
642 # we could use git_get_type(branch:pathname), but:
643 # - it needs $git_dir
644 # - it does a git() call
645 # - the convention of terminating directories with a slash
646 # makes it superfluous
647 # - embedding the action in the PATH_INFO would make it even
649 $pathname =~ s
,^/+,,;
650 if (!$pathname || substr($pathname, -1) eq "/") {
651 $input_params{'action'} ||= "tree";
654 # the default action depends on whether we had parent info
656 if ($parentrefname) {
657 $input_params{'action'} ||= "blobdiff_plain";
659 $input_params{'action'} ||= "blob_plain";
662 $input_params{'hash_base'} ||= $refname;
663 $input_params{'file_name'} ||= $pathname;
664 } elsif (defined $refname) {
665 # we got "branch". In this case we have to choose if we have to
666 # set hash or hash_base.
668 # Most of the actions without a pathname only want hash to be
669 # set, except for the ones specified in @wants_base that want
670 # hash_base instead. It should also be noted that hand-crafted
671 # links having 'history' as an action and no pathname or hash
672 # set will fail, but that happens regardless of PATH_INFO.
673 $input_params{'action'} ||= "shortlog";
674 if (grep { $_ eq $input_params{'action'} } @wants_base) {
675 $input_params{'hash_base'} ||= $refname;
677 $input_params{'hash'} ||= $refname;
681 # next, handle the 'parent' part, if present
682 if (defined $parentrefname) {
683 # a missing pathspec defaults to the 'current' filename, allowing e.g.
684 # someproject/blobdiff/oldrev..newrev:/filename
685 if ($parentpathname) {
686 $parentpathname =~ s
,^/+,,;
687 $parentpathname =~ s
,/$,,;
688 $input_params{'file_parent'} ||= $parentpathname;
690 $input_params{'file_parent'} ||= $input_params{'file_name'};
692 # we assume that hash_parent_base is wanted if a path was specified,
693 # or if the action wants hash_base instead of hash
694 if (defined $input_params{'file_parent'} ||
695 grep { $_ eq $input_params{'action'} } @wants_base) {
696 $input_params{'hash_parent_base'} ||= $parentrefname;
698 $input_params{'hash_parent'} ||= $parentrefname;
702 # for the snapshot action, we allow URLs in the form
703 # $project/snapshot/$hash.ext
704 # where .ext determines the snapshot and gets removed from the
705 # passed $refname to provide the $hash.
707 # To be able to tell that $refname includes the format extension, we
708 # require the following two conditions to be satisfied:
709 # - the hash input parameter MUST have been set from the $refname part
710 # of the URL (i.e. they must be equal)
711 # - the snapshot format MUST NOT have been defined already (e.g. from
713 # It's also useless to try any matching unless $refname has a dot,
714 # so we check for that too
715 if (defined $input_params{'action'} &&
716 $input_params{'action'} eq 'snapshot' &&
717 defined $refname && index($refname, '.') != -1 &&
718 $refname eq $input_params{'hash'} &&
719 !defined $input_params{'snapshot_format'}) {
720 # We loop over the known snapshot formats, checking for
721 # extensions. Allowed extensions are both the defined suffix
722 # (which includes the initial dot already) and the snapshot
723 # format key itself, with a prepended dot
724 while (my ($fmt, $opt) = each %known_snapshot_formats) {
726 unless ($hash =~ s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) {
730 # a valid suffix was found, so set the snapshot format
731 # and reset the hash parameter
732 $input_params{'snapshot_format'} = $fmt;
733 $input_params{'hash'} = $hash;
734 # we also set the format suffix to the one requested
735 # in the URL: this way a request for e.g. .tgz returns
736 # a .tgz instead of a .tar.gz
737 $known_snapshot_formats{$fmt}{'suffix'} = $sfx;
742 evaluate_path_info
();
744 our $action = $input_params{'action'};
745 if (defined $action) {
746 if (!validate_action
($action)) {
747 die_error
(400, "Invalid action parameter");
751 # parameters which are pathnames
752 our $project = $input_params{'project'};
753 if (defined $project) {
754 if (!validate_project
($project)) {
756 die_error
(404, "No such project");
760 our $file_name = $input_params{'file_name'};
761 if (defined $file_name) {
762 if (!validate_pathname
($file_name)) {
763 die_error
(400, "Invalid file parameter");
767 our $file_parent = $input_params{'file_parent'};
768 if (defined $file_parent) {
769 if (!validate_pathname
($file_parent)) {
770 die_error
(400, "Invalid file parent parameter");
774 # parameters which are refnames
775 our $hash = $input_params{'hash'};
777 if (!validate_refname
($hash)) {
778 die_error
(400, "Invalid hash parameter");
782 our $hash_parent = $input_params{'hash_parent'};
783 if (defined $hash_parent) {
784 if (!validate_refname
($hash_parent)) {
785 die_error
(400, "Invalid hash parent parameter");
789 our $hash_base = $input_params{'hash_base'};
790 if (defined $hash_base) {
791 if (!validate_refname
($hash_base)) {
792 die_error
(400, "Invalid hash base parameter");
796 our @extra_options = @{$input_params{'extra_options'}};
797 # @extra_options is always defined, since it can only be (currently) set from
798 # CGI, and $cgi->param() returns the empty array in array context if the param
800 foreach my $opt (@extra_options) {
801 if (not exists $allowed_options{$opt}) {
802 die_error
(400, "Invalid option parameter");
804 if (not grep(/^$action$/, @{$allowed_options{$opt}})) {
805 die_error
(400, "Invalid option parameter for this action");
809 our $hash_parent_base = $input_params{'hash_parent_base'};
810 if (defined $hash_parent_base) {
811 if (!validate_refname
($hash_parent_base)) {
812 die_error
(400, "Invalid hash parent base parameter");
817 our $page = $input_params{'page'};
819 if ($page =~ m/[^0-9]/) {
820 die_error
(400, "Invalid page parameter");
824 our $searchtype = $input_params{'searchtype'};
825 if (defined $searchtype) {
826 if ($searchtype =~ m/[^a-z]/) {
827 die_error
(400, "Invalid searchtype parameter");
831 our $search_use_regexp = $input_params{'search_use_regexp'};
833 our $searchtext = $input_params{'searchtext'};
835 if (defined $searchtext) {
836 if (length($searchtext) < 2) {
837 die_error
(403, "At least two characters are required for search parameter");
839 $search_regexp = $search_use_regexp ? $searchtext : quotemeta $searchtext;
842 # path to the current git repository
844 $git_dir = "$projectroot/$project" if $project;
846 # list of supported snapshot formats
847 our @snapshot_fmts = gitweb_get_feature
('snapshot');
848 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
850 # check that the avatar feature is set to a known provider name,
851 # and for each provider check if the dependencies are satisfied.
852 # if the provider name is invalid or the dependencies are not met,
853 # reset $git_avatar to the empty string.
854 our ($git_avatar) = gitweb_get_feature
('avatar');
855 if ($git_avatar eq 'gravatar') {
856 $git_avatar = '' unless (eval { require Digest
::MD5
; 1; });
862 if (!defined $action) {
864 $action = git_get_type
($hash);
865 } elsif (defined $hash_base && defined $file_name) {
866 $action = git_get_type
("$hash_base:$file_name");
867 } elsif (defined $project) {
870 $action = 'project_list';
873 if (!defined($actions{$action})) {
874 die_error
(400, "Unknown action");
876 if ($action !~ m/^(?:opml|project_list|project_index)$/ &&
878 die_error
(400, "Project needed");
880 $actions{$action}->();
883 ## ======================================================================
888 # default is to use -absolute url() i.e. $my_uri
889 my $href = $params{-full
} ? $my_url : $my_uri;
891 $params{'project'} = $project unless exists $params{'project'};
893 if ($params{-replay
}) {
894 while (my ($name, $symbol) = each %cgi_param_mapping) {
895 if (!exists $params{$name}) {
896 $params{$name} = $input_params{$name};
901 my $use_pathinfo = gitweb_check_feature
('pathinfo');
902 if ($use_pathinfo and defined $params{'project'}) {
903 # try to put as many parameters as possible in PATH_INFO:
906 # - hash_parent or hash_parent_base:/file_parent
907 # - hash or hash_base:/filename
908 # - the snapshot_format as an appropriate suffix
910 # When the script is the root DirectoryIndex for the domain,
911 # $href here would be something like http://gitweb.example.com/
912 # Thus, we strip any trailing / from $href, to spare us double
913 # slashes in the final URL
916 # Then add the project name, if present
917 $href .= "/".esc_url
($params{'project'});
918 delete $params{'project'};
920 # since we destructively absorb parameters, we keep this
921 # boolean that remembers if we're handling a snapshot
922 my $is_snapshot = $params{'action'} eq 'snapshot';
924 # Summary just uses the project path URL, any other action is
926 if (defined $params{'action'}) {
927 $href .= "/".esc_url
($params{'action'}) unless $params{'action'} eq 'summary';
928 delete $params{'action'};
931 # Next, we put hash_parent_base:/file_parent..hash_base:/file_name,
932 # stripping nonexistent or useless pieces
933 $href .= "/" if ($params{'hash_base'} || $params{'hash_parent_base'}
934 || $params{'hash_parent'} || $params{'hash'});
935 if (defined $params{'hash_base'}) {
936 if (defined $params{'hash_parent_base'}) {
937 $href .= esc_url
($params{'hash_parent_base'});
938 # skip the file_parent if it's the same as the file_name
939 delete $params{'file_parent'} if $params{'file_parent'} eq $params{'file_name'};
940 if (defined $params{'file_parent'} && $params{'file_parent'} !~ /\.\./) {
941 $href .= ":/".esc_url
($params{'file_parent'});
942 delete $params{'file_parent'};
945 delete $params{'hash_parent'};
946 delete $params{'hash_parent_base'};
947 } elsif (defined $params{'hash_parent'}) {
948 $href .= esc_url
($params{'hash_parent'}). "..";
949 delete $params{'hash_parent'};
952 $href .= esc_url
($params{'hash_base'});
953 if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) {
954 $href .= ":/".esc_url
($params{'file_name'});
955 delete $params{'file_name'};
957 delete $params{'hash'};
958 delete $params{'hash_base'};
959 } elsif (defined $params{'hash'}) {
960 $href .= esc_url
($params{'hash'});
961 delete $params{'hash'};
964 # If the action was a snapshot, we can absorb the
965 # snapshot_format parameter too
967 my $fmt = $params{'snapshot_format'};
968 # snapshot_format should always be defined when href()
969 # is called, but just in case some code forgets, we
970 # fall back to the default
971 $fmt ||= $snapshot_fmts[0];
972 $href .= $known_snapshot_formats{$fmt}{'suffix'};
973 delete $params{'snapshot_format'};
977 # now encode the parameters explicitly
979 for (my $i = 0; $i < @cgi_param_mapping; $i += 2) {
980 my ($name, $symbol) = ($cgi_param_mapping[$i], $cgi_param_mapping[$i+1]);
981 if (defined $params{$name}) {
982 if (ref($params{$name}) eq "ARRAY") {
983 foreach my $par (@{$params{$name}}) {
984 push @result, $symbol . "=" . esc_param
($par);
987 push @result, $symbol . "=" . esc_param
($params{$name});
991 $href .= "?" . join(';', @result) if scalar @result;
997 ## ======================================================================
998 ## validation, quoting/unquoting and escaping
1000 sub validate_action
{
1001 my $input = shift || return undef;
1002 return undef unless exists $actions{$input};
1006 sub validate_project
{
1007 my $input = shift || return undef;
1008 if (!validate_pathname
($input) ||
1009 !(-d
"$projectroot/$input") ||
1010 !check_export_ok
("$projectroot/$input") ||
1011 ($strict_export && !project_in_list
($input))) {
1018 sub validate_pathname
{
1019 my $input = shift || return undef;
1021 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
1022 # at the beginning, at the end, and between slashes.
1023 # also this catches doubled slashes
1024 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
1027 # no null characters
1028 if ($input =~ m!\0!) {
1034 sub validate_refname
{
1035 my $input = shift || return undef;
1037 # textual hashes are O.K.
1038 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
1041 # it must be correct pathname
1042 $input = validate_pathname
($input)
1044 # restrictions on ref name according to git-check-ref-format
1045 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
1051 # decode sequences of octets in utf8 into Perl's internal form,
1052 # which is utf-8 with utf8 flag set if needed. gitweb writes out
1053 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
1056 if (utf8
::valid
($str)) {
1060 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
1064 # quote unsafe chars, but keep the slash, even when it's not
1065 # correct, but quoted slashes look too horrible in bookmarks
1068 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
1074 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
1077 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
1083 # replace invalid utf8 character with SUBSTITUTION sequence
1088 $str = to_utf8
($str);
1089 $str = $cgi->escapeHTML($str);
1090 if ($opts{'-nbsp'}) {
1091 $str =~ s/ / /g;
1093 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
1097 # quote control characters and escape filename to HTML
1102 $str = to_utf8
($str);
1103 $str = $cgi->escapeHTML($str);
1104 if ($opts{'-nbsp'}) {
1105 $str =~ s/ / /g;
1107 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
1111 # Make control characters "printable", using character escape codes (CEC)
1115 my %es = ( # character escape codes, aka escape sequences
1116 "\t" => '\t', # tab (HT)
1117 "\n" => '\n', # line feed (LF)
1118 "\r" => '\r', # carrige return (CR)
1119 "\f" => '\f', # form feed (FF)
1120 "\b" => '\b', # backspace (BS)
1121 "\a" => '\a', # alarm (bell) (BEL)
1122 "\e" => '\e', # escape (ESC)
1123 "\013" => '\v', # vertical tab (VT)
1124 "\000" => '\0', # nul character (NUL)
1126 my $chr = ( (exists $es{$cntrl})
1128 : sprintf('\%2x', ord($cntrl)) );
1129 if ($opts{-nohtml
}) {
1132 return "<span class=\"cntrl\">$chr</span>";
1136 # Alternatively use unicode control pictures codepoints,
1137 # Unicode "printable representation" (PR)
1142 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
1143 if ($opts{-nohtml
}) {
1146 return "<span class=\"cntrl\">$chr</span>";
1150 # git may return quoted and escaped filenames
1156 my %es = ( # character escape codes, aka escape sequences
1157 't' => "\t", # tab (HT, TAB)
1158 'n' => "\n", # newline (NL)
1159 'r' => "\r", # return (CR)
1160 'f' => "\f", # form feed (FF)
1161 'b' => "\b", # backspace (BS)
1162 'a' => "\a", # alarm (bell) (BEL)
1163 'e' => "\e", # escape (ESC)
1164 'v' => "\013", # vertical tab (VT)
1167 if ($seq =~ m/^[0-7]{1,3}$/) {
1168 # octal char sequence
1169 return chr(oct($seq));
1170 } elsif (exists $es{$seq}) {
1171 # C escape sequence, aka character escape code
1174 # quoted ordinary character
1178 if ($str =~ m/^"(.*)"$/) {
1181 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
1186 # escape tabs (convert tabs to spaces)
1190 while ((my $pos = index($line, "\t")) != -1) {
1191 if (my $count = (8 - ($pos % 8))) {
1192 my $spaces = ' ' x
$count;
1193 $line =~ s/\t/$spaces/;
1200 sub project_in_list
{
1201 my $project = shift;
1202 my @list = git_get_projects_list
();
1203 return @list && scalar(grep { $_->{'path'} eq $project } @list);
1206 ## ----------------------------------------------------------------------
1207 ## HTML aware string manipulation
1209 # Try to chop given string on a word boundary between position
1210 # $len and $len+$add_len. If there is no word boundary there,
1211 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
1212 # (marking chopped part) would be longer than given string.
1216 my $add_len = shift || 10;
1217 my $where = shift || 'right'; # 'left' | 'center' | 'right'
1219 # Make sure perl knows it is utf8 encoded so we don't
1220 # cut in the middle of a utf8 multibyte char.
1221 $str = to_utf8
($str);
1223 # allow only $len chars, but don't cut a word if it would fit in $add_len
1224 # if it doesn't fit, cut it if it's still longer than the dots we would add
1225 # remove chopped character entities entirely
1227 # when chopping in the middle, distribute $len into left and right part
1228 # return early if chopping wouldn't make string shorter
1229 if ($where eq 'center') {
1230 return $str if ($len + 5 >= length($str)); # filler is length 5
1233 return $str if ($len + 4 >= length($str)); # filler is length 4
1236 # regexps: ending and beginning with word part up to $add_len
1237 my $endre = qr/.{$len}\w{0,$add_len}/;
1238 my $begre = qr/\w{0,$add_len}.{$len}/;
1240 if ($where eq 'left') {
1241 $str =~ m/^(.*?)($begre)$/;
1242 my ($lead, $body) = ($1, $2);
1243 if (length($lead) > 4) {
1244 $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
1247 return "$lead$body";
1249 } elsif ($where eq 'center') {
1250 $str =~ m/^($endre)(.*)$/;
1251 my ($left, $str) = ($1, $2);
1252 $str =~ m/^(.*?)($begre)$/;
1253 my ($mid, $right) = ($1, $2);
1254 if (length($mid) > 5) {
1255 $left =~ s/&[^;]*$//;
1256 $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
1259 return "$left$mid$right";
1262 $str =~ m/^($endre)(.*)$/;
1265 if (length($tail) > 4) {
1266 $body =~ s/&[^;]*$//;
1269 return "$body$tail";
1273 # takes the same arguments as chop_str, but also wraps a <span> around the
1274 # result with a title attribute if it does get chopped. Additionally, the
1275 # string is HTML-escaped.
1276 sub chop_and_escape_str
{
1279 my $chopped = chop_str
(@_);
1280 if ($chopped eq $str) {
1281 return esc_html
($chopped);
1283 $str =~ s/[[:cntrl:]]/?/g;
1284 return $cgi->span({-title
=>$str}, esc_html
($chopped));
1288 ## ----------------------------------------------------------------------
1289 ## functions returning short strings
1291 # CSS class for given age value (in seconds)
1295 if (!defined $age) {
1297 } elsif ($age < 60*60*2) {
1299 } elsif ($age < 60*60*24*2) {
1306 # convert age in seconds to "nn units ago" string
1311 if ($age > 60*60*24*365*2) {
1312 $age_str = (int $age/60/60/24/365);
1313 $age_str .= " years ago";
1314 } elsif ($age > 60*60*24*(365/12)*2) {
1315 $age_str = int $age/60/60/24/(365/12);
1316 $age_str .= " months ago";
1317 } elsif ($age > 60*60*24*7*2) {
1318 $age_str = int $age/60/60/24/7;
1319 $age_str .= " weeks ago";
1320 } elsif ($age > 60*60*24*2) {
1321 $age_str = int $age/60/60/24;
1322 $age_str .= " days ago";
1323 } elsif ($age > 60*60*2) {
1324 $age_str = int $age/60/60;
1325 $age_str .= " hours ago";
1326 } elsif ($age > 60*2) {
1327 $age_str = int $age/60;
1328 $age_str .= " min ago";
1329 } elsif ($age > 2) {
1330 $age_str = int $age;
1331 $age_str .= " sec ago";
1333 $age_str .= " right now";
1339 S_IFINVALID
=> 0030000,
1340 S_IFGITLINK
=> 0160000,
1343 # submodule/subproject, a commit object reference
1347 return (($mode & S_IFMT
) == S_IFGITLINK
)
1350 # convert file mode in octal to symbolic file mode string
1352 my $mode = oct shift;
1354 if (S_ISGITLINK
($mode)) {
1355 return 'm---------';
1356 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1357 return 'drwxr-xr-x';
1358 } elsif (S_ISLNK
($mode)) {
1359 return 'lrwxrwxrwx';
1360 } elsif (S_ISREG
($mode)) {
1361 # git cares only about the executable bit
1362 if ($mode & S_IXUSR
) {
1363 return '-rwxr-xr-x';
1365 return '-rw-r--r--';
1368 return '----------';
1372 # convert file mode in octal to file type string
1376 if ($mode !~ m/^[0-7]+$/) {
1382 if (S_ISGITLINK
($mode)) {
1384 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1386 } elsif (S_ISLNK
($mode)) {
1388 } elsif (S_ISREG
($mode)) {
1395 # convert file mode in octal to file type description string
1396 sub file_type_long
{
1399 if ($mode !~ m/^[0-7]+$/) {
1405 if (S_ISGITLINK
($mode)) {
1407 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1409 } elsif (S_ISLNK
($mode)) {
1411 } elsif (S_ISREG
($mode)) {
1412 if ($mode & S_IXUSR
) {
1413 return "executable";
1423 ## ----------------------------------------------------------------------
1424 ## functions returning short HTML fragments, or transforming HTML fragments
1425 ## which don't belong to other sections
1427 # format line of commit message.
1428 sub format_log_line_html
{
1431 $line = esc_html
($line, -nbsp
=>1);
1432 $line =~ s
{\b([0-9a-fA-F
]{8,40})\b}{
1433 $cgi->a({-href
=> href
(action
=>"object", hash
=>$1),
1434 -class => "text"}, $1);
1440 # format marker of refs pointing to given object
1442 # the destination action is chosen based on object type and current context:
1443 # - for annotated tags, we choose the tag view unless it's the current view
1444 # already, in which case we go to shortlog view
1445 # - for other refs, we keep the current view if we're in history, shortlog or
1446 # log view, and select shortlog otherwise
1447 sub format_ref_marker
{
1448 my ($refs, $id) = @_;
1451 if (defined $refs->{$id}) {
1452 foreach my $ref (@{$refs->{$id}}) {
1453 # this code exploits the fact that non-lightweight tags are the
1454 # only indirect objects, and that they are the only objects for which
1455 # we want to use tag instead of shortlog as action
1456 my ($type, $name) = qw();
1457 my $indirect = ($ref =~ s/\^\{\}$//);
1458 # e.g. tags/v2.6.11 or heads/next
1459 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1468 $class .= " indirect" if $indirect;
1470 my $dest_action = "shortlog";
1473 $dest_action = "tag" unless $action eq "tag";
1474 } elsif ($action =~ /^(history|(short)?log)$/) {
1475 $dest_action = $action;
1479 $dest .= "refs/" unless $ref =~ m
!^refs
/!;
1482 my $link = $cgi->a({
1484 action
=>$dest_action,
1488 $markers .= " <span class=\"$class\" title=\"$ref\">" .
1494 return ' <span class="refs">'. $markers . '</span>';
1500 # format, perhaps shortened and with markers, title line
1501 sub format_subject_html
{
1502 my ($long, $short, $href, $extra) = @_;
1503 $extra = '' unless defined($extra);
1505 if (length($short) < length($long)) {
1506 $long =~ s/[[:cntrl:]]/?/g;
1507 return $cgi->a({-href
=> $href, -class => "list subject",
1508 -title
=> to_utf8
($long)},
1509 esc_html
($short) . $extra);
1511 return $cgi->a({-href
=> $href, -class => "list subject"},
1512 esc_html
($long) . $extra);
1516 # Rather than recomputing the url for an email multiple times, we cache it
1517 # after the first hit. This gives a visible benefit in views where the avatar
1518 # for the same email is used repeatedly (e.g. shortlog).
1519 # The cache is shared by all avatar engines (currently gravatar only), which
1520 # are free to use it as preferred. Since only one avatar engine is used for any
1521 # given page, there's no risk for cache conflicts.
1522 our %avatar_cache = ();
1524 # Compute the gravatar url for a given email, if it's not in the cache already.
1525 # Gravatar stores only the part of the URL before the size, since that's the
1526 # one computationally more expensive. This also allows reuse of the cache for
1527 # different sizes (for this particular engine).
1529 my $email = lc shift;
1531 $avatar_cache{$email} ||=
1532 "http://www.gravatar.com/avatar/" .
1533 Digest
::MD5
::md5_hex
($email) . "?s=";
1534 return $avatar_cache{$email} . $size;
1537 # Insert an avatar for the given $email at the given $size if the feature
1539 sub git_get_avatar
{
1540 my ($email, %opts) = @_;
1541 my $pre_white = ($opts{-pad_before
} ? " " : "");
1542 my $post_white = ($opts{-pad_after
} ? " " : "");
1543 $opts{-size
} ||= 'default';
1544 my $size = $avatar_size{$opts{-size
}} || $avatar_size{'default'};
1546 if ($git_avatar eq 'gravatar') {
1547 $url = gravatar_url
($email, $size);
1549 # Currently only gravatars are supported, but other forms such as
1550 # picons can be added by putting an else up here and defining $url
1551 # as needed. If no variant puts something in $url, we assume avatars
1552 # are completely disabled/unavailable.
1555 "<img width=\"$size\" " .
1556 "class=\"avatar\" " .
1564 # format the author name of the given commit with the given tag
1565 # the author name is chopped and escaped according to the other
1566 # optional parameters (see chop_str).
1567 sub format_author_html
{
1570 my $author = chop_and_escape_str
($co->{'author_name'}, @_);
1571 return "<$tag class=\"author\">" .
1572 git_get_avatar
($co->{'author_email'}, -pad_after
=> 1) .
1573 $author . "</$tag>";
1576 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1577 sub format_git_diff_header_line
{
1579 my $diffinfo = shift;
1580 my ($from, $to) = @_;
1582 if ($diffinfo->{'nparents'}) {
1584 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1585 if ($to->{'href'}) {
1586 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1587 esc_path
($to->{'file'}));
1588 } else { # file was deleted (no href)
1589 $line .= esc_path
($to->{'file'});
1593 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1594 if ($from->{'href'}) {
1595 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1596 'a/' . esc_path
($from->{'file'}));
1597 } else { # file was added (no href)
1598 $line .= 'a/' . esc_path
($from->{'file'});
1601 if ($to->{'href'}) {
1602 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1603 'b/' . esc_path
($to->{'file'}));
1604 } else { # file was deleted
1605 $line .= 'b/' . esc_path
($to->{'file'});
1609 return "<div class=\"diff header\">$line</div>\n";
1612 # format extended diff header line, before patch itself
1613 sub format_extended_diff_header_line
{
1615 my $diffinfo = shift;
1616 my ($from, $to) = @_;
1619 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1620 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1621 esc_path
($from->{'file'}));
1623 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1624 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1625 esc_path
($to->{'file'}));
1627 # match single <mode>
1628 if ($line =~ m/\s(\d{6})$/) {
1629 $line .= '<span class="info"> (' .
1630 file_type_long
($1) .
1634 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1635 # can match only for combined diff
1637 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1638 if ($from->{'href'}[$i]) {
1639 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1641 substr($diffinfo->{'from_id'}[$i],0,7));
1646 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1649 if ($to->{'href'}) {
1650 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1651 substr($diffinfo->{'to_id'},0,7));
1656 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1657 # can match only for ordinary diff
1658 my ($from_link, $to_link);
1659 if ($from->{'href'}) {
1660 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1661 substr($diffinfo->{'from_id'},0,7));
1663 $from_link = '0' x
7;
1665 if ($to->{'href'}) {
1666 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1667 substr($diffinfo->{'to_id'},0,7));
1671 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1672 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1675 return $line . "<br/>\n";
1678 # format from-file/to-file diff header
1679 sub format_diff_from_to_header
{
1680 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1685 #assert($line =~ m/^---/) if DEBUG;
1686 # no extra formatting for "^--- /dev/null"
1687 if (! $diffinfo->{'nparents'}) {
1688 # ordinary (single parent) diff
1689 if ($line =~ m!^--- "?a/!) {
1690 if ($from->{'href'}) {
1692 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1693 esc_path
($from->{'file'}));
1696 esc_path
($from->{'file'});
1699 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1702 # combined diff (merge commit)
1703 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1704 if ($from->{'href'}[$i]) {
1706 $cgi->a({-href
=>href
(action
=>"blobdiff",
1707 hash_parent
=>$diffinfo->{'from_id'}[$i],
1708 hash_parent_base
=>$parents[$i],
1709 file_parent
=>$from->{'file'}[$i],
1710 hash
=>$diffinfo->{'to_id'},
1712 file_name
=>$to->{'file'}),
1714 -title
=>"diff" . ($i+1)},
1717 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1718 esc_path
($from->{'file'}[$i]));
1720 $line = '--- /dev/null';
1722 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1727 #assert($line =~ m/^\+\+\+/) if DEBUG;
1728 # no extra formatting for "^+++ /dev/null"
1729 if ($line =~ m!^\+\+\+ "?b/!) {
1730 if ($to->{'href'}) {
1732 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1733 esc_path
($to->{'file'}));
1736 esc_path
($to->{'file'});
1739 $result .= qq
!<div
class="diff to_file">$line</div
>\n!;
1744 # create note for patch simplified by combined diff
1745 sub format_diff_cc_simplified
{
1746 my ($diffinfo, @parents) = @_;
1749 $result .= "<div class=\"diff header\">" .
1751 if (!is_deleted
($diffinfo)) {
1752 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1754 hash
=>$diffinfo->{'to_id'},
1755 file_name
=>$diffinfo->{'to_file'}),
1757 esc_path
($diffinfo->{'to_file'}));
1759 $result .= esc_path
($diffinfo->{'to_file'});
1761 $result .= "</div>\n" . # class="diff header"
1762 "<div class=\"diff nodifferences\">" .
1764 "</div>\n"; # class="diff nodifferences"
1769 # format patch (diff) line (not to be used for diff headers)
1770 sub format_diff_line
{
1772 my ($from, $to) = @_;
1773 my $diff_class = "";
1777 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1779 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
1780 if ($line =~ m/^\@{3}/) {
1781 $diff_class = " chunk_header";
1782 } elsif ($line =~ m/^\\/) {
1783 $diff_class = " incomplete";
1784 } elsif ($prefix =~ tr/+/+/) {
1785 $diff_class = " add";
1786 } elsif ($prefix =~ tr/-/-/) {
1787 $diff_class = " rem";
1790 # assume ordinary diff
1791 my $char = substr($line, 0, 1);
1793 $diff_class = " add";
1794 } elsif ($char eq '-') {
1795 $diff_class = " rem";
1796 } elsif ($char eq '@') {
1797 $diff_class = " chunk_header";
1798 } elsif ($char eq "\\") {
1799 $diff_class = " incomplete";
1802 $line = untabify
($line);
1803 if ($from && $to && $line =~ m/^\@{2} /) {
1804 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1805 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1807 $from_lines = 0 unless defined $from_lines;
1808 $to_lines = 0 unless defined $to_lines;
1810 if ($from->{'href'}) {
1811 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1812 -class=>"list"}, $from_text);
1814 if ($to->{'href'}) {
1815 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1816 -class=>"list"}, $to_text);
1818 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1819 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1820 return "<div class=\"diff$diff_class\">$line</div>\n";
1821 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1822 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1823 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1825 @from_text = split(' ', $ranges);
1826 for (my $i = 0; $i < @from_text; ++$i) {
1827 ($from_start[$i], $from_nlines[$i]) =
1828 (split(',', substr($from_text[$i], 1)), 0);
1831 $to_text = pop @from_text;
1832 $to_start = pop @from_start;
1833 $to_nlines = pop @from_nlines;
1835 $line = "<span class=\"chunk_info\">$prefix ";
1836 for (my $i = 0; $i < @from_text; ++$i) {
1837 if ($from->{'href'}[$i]) {
1838 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1839 -class=>"list"}, $from_text[$i]);
1841 $line .= $from_text[$i];
1845 if ($to->{'href'}) {
1846 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1847 -class=>"list"}, $to_text);
1851 $line .= " $prefix</span>" .
1852 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1853 return "<div class=\"diff$diff_class\">$line</div>\n";
1855 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1858 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1859 # linked. Pass the hash of the tree/commit to snapshot.
1860 sub format_snapshot_links
{
1862 my $num_fmts = @snapshot_fmts;
1863 if ($num_fmts > 1) {
1864 # A parenthesized list of links bearing format names.
1865 # e.g. "snapshot (_tar.gz_ _zip_)"
1866 return "snapshot (" . join(' ', map
1873 }, $known_snapshot_formats{$_}{'display'})
1874 , @snapshot_fmts) . ")";
1875 } elsif ($num_fmts == 1) {
1876 # A single "snapshot" link whose tooltip bears the format name.
1878 my ($fmt) = @snapshot_fmts;
1884 snapshot_format
=>$fmt
1886 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1888 } else { # $num_fmts == 0
1893 ## ......................................................................
1894 ## functions returning values to be passed, perhaps after some
1895 ## transformation, to other functions; e.g. returning arguments to href()
1897 # returns hash to be passed to href to generate gitweb URL
1898 # in -title key it returns description of link
1900 my $format = shift || 'Atom';
1901 my %res = (action
=> lc($format));
1903 # feed links are possible only for project views
1904 return unless (defined $project);
1905 # some views should link to OPML, or to generic project feed,
1906 # or don't have specific feed yet (so they should use generic)
1907 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
1910 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
1911 # from tag links; this also makes possible to detect branch links
1912 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
1913 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
1916 # find log type for feed description (title)
1918 if (defined $file_name) {
1919 $type = "history of $file_name";
1920 $type .= "/" if ($action eq 'tree');
1921 $type .= " on '$branch'" if (defined $branch);
1923 $type = "log of $branch" if (defined $branch);
1926 $res{-title
} = $type;
1927 $res{'hash'} = (defined $branch ? "refs/heads/$branch" : undef);
1928 $res{'file_name'} = $file_name;
1933 ## ----------------------------------------------------------------------
1934 ## git utility subroutines, invoking git commands
1936 # returns path to the core git executable and the --git-dir parameter as list
1938 return $GIT, '--git-dir='.$git_dir;
1941 # quote the given arguments for passing them to the shell
1942 # quote_command("command", "arg 1", "arg with ' and ! characters")
1943 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
1944 # Try to avoid using this function wherever possible.
1947 map { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ );
1950 # get HEAD ref of given project as hash
1951 sub git_get_head_hash
{
1952 my $project = shift;
1953 my $o_git_dir = $git_dir;
1955 $git_dir = "$projectroot/$project";
1956 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1959 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1963 if (defined $o_git_dir) {
1964 $git_dir = $o_git_dir;
1969 # get type of given object
1973 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1975 close $fd or return;
1980 # repository configuration
1981 our $config_file = '';
1984 # store multiple values for single key as anonymous array reference
1985 # single values stored directly in the hash, not as [ <value> ]
1986 sub hash_set_multi
{
1987 my ($hash, $key, $value) = @_;
1989 if (!exists $hash->{$key}) {
1990 $hash->{$key} = $value;
1991 } elsif (!ref $hash->{$key}) {
1992 $hash->{$key} = [ $hash->{$key}, $value ];
1994 push @{$hash->{$key}}, $value;
1998 # return hash of git project configuration
1999 # optionally limited to some section, e.g. 'gitweb'
2000 sub git_parse_project_config
{
2001 my $section_regexp = shift;
2006 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
2009 while (my $keyval = <$fh>) {
2011 my ($key, $value) = split(/\n/, $keyval, 2);
2013 hash_set_multi
(\
%config, $key, $value)
2014 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
2021 # convert config value to boolean: 'true' or 'false'
2022 # no value, number > 0, 'true' and 'yes' values are true
2023 # rest of values are treated as false (never as error)
2024 sub config_to_bool
{
2027 return 1 if !defined $val; # section.key
2029 # strip leading and trailing whitespace
2033 return (($val =~ /^\d+$/ && $val) || # section.key = 1
2034 ($val =~ /^(?:true|yes)$/i)); # section.key = true
2037 # convert config value to simple decimal number
2038 # an optional value suffix of 'k', 'm', or 'g' will cause the value
2039 # to be multiplied by 1024, 1048576, or 1073741824
2043 # strip leading and trailing whitespace
2047 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
2049 # unknown unit is treated as 1
2050 return $num * ($unit eq 'g' ? 1073741824 :
2051 $unit eq 'm' ? 1048576 :
2052 $unit eq 'k' ? 1024 : 1);
2057 # convert config value to array reference, if needed
2058 sub config_to_multi
{
2061 return ref($val) ? $val : (defined($val) ? [ $val ] : []);
2064 sub git_get_project_config
{
2065 my ($key, $type) = @_;
2068 return unless ($key);
2069 $key =~ s/^gitweb\.//;
2070 return if ($key =~ m/\W/);
2073 if (defined $type) {
2076 unless ($type eq 'bool' || $type eq 'int');
2080 if (!defined $config_file ||
2081 $config_file ne "$git_dir/config") {
2082 %config = git_parse_project_config
('gitweb');
2083 $config_file = "$git_dir/config";
2086 # check if config variable (key) exists
2087 return unless exists $config{"gitweb.$key"};
2090 if (!defined $type) {
2091 return $config{"gitweb.$key"};
2092 } elsif ($type eq 'bool') {
2093 # backward compatibility: 'git config --bool' returns true/false
2094 return config_to_bool
($config{"gitweb.$key"}) ? 'true' : 'false';
2095 } elsif ($type eq 'int') {
2096 return config_to_int
($config{"gitweb.$key"});
2098 return $config{"gitweb.$key"};
2101 # get hash of given path at given ref
2102 sub git_get_hash_by_path
{
2104 my $path = shift || return undef;
2109 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
2110 or die_error
(500, "Open git-ls-tree failed");
2112 close $fd or return undef;
2114 if (!defined $line) {
2115 # there is no tree or hash given by $path at $base
2119 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2120 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
2121 if (defined $type && $type ne $2) {
2122 # type doesn't match
2128 # get path of entry with given hash at given tree-ish (ref)
2129 # used to get 'from' filename for combined diff (merge commit) for renames
2130 sub git_get_path_by_hash
{
2131 my $base = shift || return;
2132 my $hash = shift || return;
2136 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
2138 while (my $line = <$fd>) {
2141 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
2142 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
2143 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
2152 ## ......................................................................
2153 ## git utility functions, directly accessing git repository
2155 sub git_get_project_description
{
2158 $git_dir = "$projectroot/$path";
2159 open my $fd, '<', "$git_dir/description"
2160 or return git_get_project_config
('description');
2163 if (defined $descr) {
2169 sub git_get_project_ctags
{
2173 $git_dir = "$projectroot/$path";
2174 opendir my $dh, "$git_dir/ctags"
2176 foreach (grep { -f
$_ } map { "$git_dir/ctags/$_" } readdir($dh)) {
2177 open my $ct, '<', $_ or next;
2181 my $ctag = $_; $ctag =~ s
#.*/##;
2182 $ctags->{$ctag} = $val;
2188 sub git_populate_project_tagcloud
{
2191 # First, merge different-cased tags; tags vote on casing
2193 foreach (keys %$ctags) {
2194 $ctags_lc{lc $_}->{count
} += $ctags->{$_};
2195 if (not $ctags_lc{lc $_}->{topcount
}
2196 or $ctags_lc{lc $_}->{topcount
} < $ctags->{$_}) {
2197 $ctags_lc{lc $_}->{topcount
} = $ctags->{$_};
2198 $ctags_lc{lc $_}->{topname
} = $_;
2203 if (eval { require HTML
::TagCloud
; 1; }) {
2204 $cloud = HTML
::TagCloud-
>new;
2205 foreach (sort keys %ctags_lc) {
2206 # Pad the title with spaces so that the cloud looks
2208 my $title = $ctags_lc{$_}->{topname
};
2209 $title =~ s/ / /g;
2210 $title =~ s/^/ /g;
2211 $title =~ s/$/ /g;
2212 $cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count
});
2215 $cloud = \
%ctags_lc;
2220 sub git_show_project_tagcloud
{
2221 my ($cloud, $count) = @_;
2222 print STDERR
ref($cloud)."..\n";
2223 if (ref $cloud eq 'HTML::TagCloud') {
2224 return $cloud->html_and_css($count);
2226 my @tags = sort { $cloud->{$a}->{count
} <=> $cloud->{$b}->{count
} } keys %$cloud;
2227 return '<p align="center">' . join (', ', map {
2228 "<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"
2229 } splice(@tags, 0, $count)) . '</p>';
2233 sub git_get_project_url_list
{
2236 $git_dir = "$projectroot/$path";
2237 open my $fd, '<', "$git_dir/cloneurl"
2238 or return wantarray ?
2239 @{ config_to_multi
(git_get_project_config
('url')) } :
2240 config_to_multi
(git_get_project_config
('url'));
2241 my @git_project_url_list = map { chomp; $_ } <$fd>;
2244 return wantarray ? @git_project_url_list : \
@git_project_url_list;
2247 sub git_get_projects_list
{
2252 $filter =~ s/\.git$//;
2254 my $check_forks = gitweb_check_feature
('forks');
2256 if (-d
$projects_list) {
2257 # search in directory
2258 my $dir = $projects_list . ($filter ? "/$filter" : '');
2259 # remove the trailing "/"
2261 my $pfxlen = length("$dir");
2262 my $pfxdepth = ($dir =~ tr!/!!);
2265 follow_fast
=> 1, # follow symbolic links
2266 follow_skip
=> 2, # ignore duplicates
2267 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
2269 # skip project-list toplevel, if we get it.
2270 return if (m!^[/.]$!);
2271 # only directories can be git repositories
2272 return unless (-d
$_);
2273 # don't traverse too deep (Find is super slow on os x)
2274 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
2275 $File::Find
::prune
= 1;
2279 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
2280 # we check related file in $projectroot
2281 my $path = ($filter ? "$filter/" : '') . $subdir;
2282 if (check_export_ok
("$projectroot/$path")) {
2283 push @list, { path
=> $path };
2284 $File::Find
::prune
= 1;
2289 } elsif (-f
$projects_list) {
2290 # read from file(url-encoded):
2291 # 'git%2Fgit.git Linus+Torvalds'
2292 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2293 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2295 open my $fd, '<', $projects_list or return;
2297 while (my $line = <$fd>) {
2299 my ($path, $owner) = split ' ', $line;
2300 $path = unescape
($path);
2301 $owner = unescape
($owner);
2302 if (!defined $path) {
2305 if ($filter ne '') {
2306 # looking for forks;
2307 my $pfx = substr($path, 0, length($filter));
2308 if ($pfx ne $filter) {
2311 my $sfx = substr($path, length($filter));
2312 if ($sfx !~ /^\/.*\
.git
$/) {
2315 } elsif ($check_forks) {
2317 foreach my $filter (keys %paths) {
2318 # looking for forks;
2319 my $pfx = substr($path, 0, length($filter));
2320 if ($pfx ne $filter) {
2323 my $sfx = substr($path, length($filter));
2324 if ($sfx !~ /^\/.*\
.git
$/) {
2327 # is a fork, don't include it in
2332 if (check_export_ok
("$projectroot/$path")) {
2335 owner
=> to_utf8
($owner),
2338 (my $forks_path = $path) =~ s/\.git$//;
2339 $paths{$forks_path}++;
2347 our $gitweb_project_owner = undef;
2348 sub git_get_project_list_from_file
{
2350 return if (defined $gitweb_project_owner);
2352 $gitweb_project_owner = {};
2353 # read from file (url-encoded):
2354 # 'git%2Fgit.git Linus+Torvalds'
2355 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2356 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2357 if (-f
$projects_list) {
2358 open(my $fd, '<', $projects_list);
2359 while (my $line = <$fd>) {
2361 my ($pr, $ow) = split ' ', $line;
2362 $pr = unescape
($pr);
2363 $ow = unescape
($ow);
2364 $gitweb_project_owner->{$pr} = to_utf8
($ow);
2370 sub git_get_project_owner
{
2371 my $project = shift;
2374 return undef unless $project;
2375 $git_dir = "$projectroot/$project";
2377 if (!defined $gitweb_project_owner) {
2378 git_get_project_list_from_file
();
2381 if (exists $gitweb_project_owner->{$project}) {
2382 $owner = $gitweb_project_owner->{$project};
2384 if (!defined $owner){
2385 $owner = git_get_project_config
('owner');
2387 if (!defined $owner) {
2388 $owner = get_file_owner
("$git_dir");
2394 sub git_get_last_activity
{
2398 $git_dir = "$projectroot/$path";
2399 open($fd, "-|", git_cmd
(), 'for-each-ref',
2400 '--format=%(committer)',
2401 '--sort=-committerdate',
2403 'refs/heads') or return;
2404 my $most_recent = <$fd>;
2405 close $fd or return;
2406 if (defined $most_recent &&
2407 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
2409 my $age = time - $timestamp;
2410 return ($age, age_string
($age));
2412 return (undef, undef);
2415 sub git_get_references
{
2416 my $type = shift || "";
2418 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
2419 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
2420 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
2421 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
2424 while (my $line = <$fd>) {
2426 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
2427 if (defined $refs{$1}) {
2428 push @{$refs{$1}}, $2;
2434 close $fd or return;
2438 sub git_get_rev_name_tags
{
2439 my $hash = shift || return undef;
2441 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
2443 my $name_rev = <$fd>;
2446 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
2449 # catches also '$hash undefined' output
2454 ## ----------------------------------------------------------------------
2455 ## parse to hash functions
2459 my $tz = shift || "-0000";
2462 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
2463 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
2464 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
2465 $date{'hour'} = $hour;
2466 $date{'minute'} = $min;
2467 $date{'mday'} = $mday;
2468 $date{'day'} = $days[$wday];
2469 $date{'month'} = $months[$mon];
2470 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2471 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2472 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2473 $mday, $months[$mon], $hour ,$min;
2474 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2475 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2477 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2478 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2479 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2480 $date{'hour_local'} = $hour;
2481 $date{'minute_local'} = $min;
2482 $date{'tz_local'} = $tz;
2483 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2484 1900+$year, $mon+1, $mday,
2485 $hour, $min, $sec, $tz);
2494 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
2495 $tag{'id'} = $tag_id;
2496 while (my $line = <$fd>) {
2498 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2499 $tag{'object'} = $1;
2500 } elsif ($line =~ m/^type (.+)$/) {
2502 } elsif ($line =~ m/^tag (.+)$/) {
2504 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2505 $tag{'author'} = $1;
2506 $tag{'author_epoch'} = $2;
2507 $tag{'author_tz'} = $3;
2508 if ($tag{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2509 $tag{'author_name'} = $1;
2510 $tag{'author_email'} = $2;
2512 $tag{'author_name'} = $tag{'author'};
2514 } elsif ($line =~ m/--BEGIN/) {
2515 push @comment, $line;
2517 } elsif ($line eq "") {
2521 push @comment, <$fd>;
2522 $tag{'comment'} = \
@comment;
2523 close $fd or return;
2524 if (!defined $tag{'name'}) {
2530 sub parse_commit_text
{
2531 my ($commit_text, $withparents) = @_;
2532 my @commit_lines = split '\n', $commit_text;
2535 pop @commit_lines; # Remove '\0'
2537 if (! @commit_lines) {
2541 my $header = shift @commit_lines;
2542 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2545 ($co{'id'}, my @parents) = split ' ', $header;
2546 while (my $line = shift @commit_lines) {
2547 last if $line eq "\n";
2548 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2550 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2552 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2554 $co{'author_epoch'} = $2;
2555 $co{'author_tz'} = $3;
2556 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2557 $co{'author_name'} = $1;
2558 $co{'author_email'} = $2;
2560 $co{'author_name'} = $co{'author'};
2562 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2563 $co{'committer'} = $1;
2564 $co{'committer_epoch'} = $2;
2565 $co{'committer_tz'} = $3;
2566 $co{'committer_name'} = $co{'committer'};
2567 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2568 $co{'committer_name'} = $1;
2569 $co{'committer_email'} = $2;
2571 $co{'committer_name'} = $co{'committer'};
2575 if (!defined $co{'tree'}) {
2578 $co{'parents'} = \
@parents;
2579 $co{'parent'} = $parents[0];
2581 foreach my $title (@commit_lines) {
2584 $co{'title'} = chop_str
($title, 80, 5);
2585 # remove leading stuff of merges to make the interesting part visible
2586 if (length($title) > 50) {
2587 $title =~ s/^Automatic //;
2588 $title =~ s/^merge (of|with) /Merge ... /i;
2589 if (length($title) > 50) {
2590 $title =~ s/(http|rsync):\/\///;
2592 if (length($title) > 50) {
2593 $title =~ s/(master|www|rsync)\.//;
2595 if (length($title) > 50) {
2596 $title =~ s/kernel.org:?//;
2598 if (length($title) > 50) {
2599 $title =~ s/\/pub\/scm//;
2602 $co{'title_short'} = chop_str
($title, 50, 5);
2606 if (! defined $co{'title'} || $co{'title'} eq "") {
2607 $co{'title'} = $co{'title_short'} = '(no commit message)';
2609 # remove added spaces
2610 foreach my $line (@commit_lines) {
2613 $co{'comment'} = \
@commit_lines;
2615 my $age = time - $co{'committer_epoch'};
2617 $co{'age_string'} = age_string
($age);
2618 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2619 if ($age > 60*60*24*7*2) {
2620 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2621 $co{'age_string_age'} = $co{'age_string'};
2623 $co{'age_string_date'} = $co{'age_string'};
2624 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2630 my ($commit_id) = @_;
2635 open my $fd, "-|", git_cmd
(), "rev-list",
2641 or die_error
(500, "Open git-rev-list failed");
2642 %co = parse_commit_text
(<$fd>, 1);
2649 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2657 open my $fd, "-|", git_cmd
(), "rev-list",
2660 ("--max-count=" . $maxcount),
2661 ("--skip=" . $skip),
2665 ($filename ? ($filename) : ())
2666 or die_error
(500, "Open git-rev-list failed");
2667 while (my $line = <$fd>) {
2668 my %co = parse_commit_text
($line);
2673 return wantarray ? @cos : \
@cos;
2676 # parse line of git-diff-tree "raw" output
2677 sub parse_difftree_raw_line
{
2681 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2682 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2683 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2684 $res{'from_mode'} = $1;
2685 $res{'to_mode'} = $2;
2686 $res{'from_id'} = $3;
2688 $res{'status'} = $5;
2689 $res{'similarity'} = $6;
2690 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2691 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2693 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2696 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2697 # combined diff (for merge commit)
2698 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2699 $res{'nparents'} = length($1);
2700 $res{'from_mode'} = [ split(' ', $2) ];
2701 $res{'to_mode'} = pop @{$res{'from_mode'}};
2702 $res{'from_id'} = [ split(' ', $3) ];
2703 $res{'to_id'} = pop @{$res{'from_id'}};
2704 $res{'status'} = [ split('', $4) ];
2705 $res{'to_file'} = unquote
($5);
2707 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2708 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2709 $res{'commit'} = $1;
2712 return wantarray ? %res : \
%res;
2715 # wrapper: return parsed line of git-diff-tree "raw" output
2716 # (the argument might be raw line, or parsed info)
2717 sub parsed_difftree_line
{
2718 my $line_or_ref = shift;
2720 if (ref($line_or_ref) eq "HASH") {
2721 # pre-parsed (or generated by hand)
2722 return $line_or_ref;
2724 return parse_difftree_raw_line
($line_or_ref);
2728 # parse line of git-ls-tree output
2729 sub parse_ls_tree_line
{
2734 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2735 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2743 $res{'name'} = unquote
($4);
2746 return wantarray ? %res : \
%res;
2749 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2750 sub parse_from_to_diffinfo
{
2751 my ($diffinfo, $from, $to, @parents) = @_;
2753 if ($diffinfo->{'nparents'}) {
2755 $from->{'file'} = [];
2756 $from->{'href'} = [];
2757 fill_from_file_info
($diffinfo, @parents)
2758 unless exists $diffinfo->{'from_file'};
2759 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2760 $from->{'file'}[$i] =
2761 defined $diffinfo->{'from_file'}[$i] ?
2762 $diffinfo->{'from_file'}[$i] :
2763 $diffinfo->{'to_file'};
2764 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2765 $from->{'href'}[$i] = href
(action
=>"blob",
2766 hash_base
=>$parents[$i],
2767 hash
=>$diffinfo->{'from_id'}[$i],
2768 file_name
=>$from->{'file'}[$i]);
2770 $from->{'href'}[$i] = undef;
2774 # ordinary (not combined) diff
2775 $from->{'file'} = $diffinfo->{'from_file'};
2776 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2777 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2778 hash
=>$diffinfo->{'from_id'},
2779 file_name
=>$from->{'file'});
2781 delete $from->{'href'};
2785 $to->{'file'} = $diffinfo->{'to_file'};
2786 if (!is_deleted
($diffinfo)) { # file exists in result
2787 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2788 hash
=>$diffinfo->{'to_id'},
2789 file_name
=>$to->{'file'});
2791 delete $to->{'href'};
2795 ## ......................................................................
2796 ## parse to array of hashes functions
2798 sub git_get_heads_list
{
2802 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2803 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
2804 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2807 while (my $line = <$fd>) {
2811 my ($refinfo, $committerinfo) = split(/\0/, $line);
2812 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2813 my ($committer, $epoch, $tz) =
2814 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2815 $ref_item{'fullname'} = $name;
2816 $name =~ s!^refs/heads/!!;
2818 $ref_item{'name'} = $name;
2819 $ref_item{'id'} = $hash;
2820 $ref_item{'title'} = $title || '(no commit message)';
2821 $ref_item{'epoch'} = $epoch;
2823 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2825 $ref_item{'age'} = "unknown";
2828 push @headslist, \
%ref_item;
2832 return wantarray ? @headslist : \
@headslist;
2835 sub git_get_tags_list
{
2839 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2840 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
2841 '--format=%(objectname) %(objecttype) %(refname) '.
2842 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2845 while (my $line = <$fd>) {
2849 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2850 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2851 my ($creator, $epoch, $tz) =
2852 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2853 $ref_item{'fullname'} = $name;
2854 $name =~ s!^refs/tags/!!;
2856 $ref_item{'type'} = $type;
2857 $ref_item{'id'} = $id;
2858 $ref_item{'name'} = $name;
2859 if ($type eq "tag") {
2860 $ref_item{'subject'} = $title;
2861 $ref_item{'reftype'} = $reftype;
2862 $ref_item{'refid'} = $refid;
2864 $ref_item{'reftype'} = $type;
2865 $ref_item{'refid'} = $id;
2868 if ($type eq "tag" || $type eq "commit") {
2869 $ref_item{'epoch'} = $epoch;
2871 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2873 $ref_item{'age'} = "unknown";
2877 push @tagslist, \
%ref_item;
2881 return wantarray ? @tagslist : \
@tagslist;
2884 ## ----------------------------------------------------------------------
2885 ## filesystem-related functions
2887 sub get_file_owner
{
2890 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2891 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2892 if (!defined $gcos) {
2896 $owner =~ s/[,;].*$//;
2897 return to_utf8
($owner);
2900 # assume that file exists
2902 my $filename = shift;
2904 open my $fd, '<', $filename;
2905 print map { to_utf8
($_) } <$fd>;
2909 ## ......................................................................
2910 ## mimetype related functions
2912 sub mimetype_guess_file
{
2913 my $filename = shift;
2914 my $mimemap = shift;
2915 -r
$mimemap or return undef;
2918 open(my $mh, '<', $mimemap) or return undef;
2920 next if m/^#/; # skip comments
2921 my ($mimetype, $exts) = split(/\t+/);
2922 if (defined $exts) {
2923 my @exts = split(/\s+/, $exts);
2924 foreach my $ext (@exts) {
2925 $mimemap{$ext} = $mimetype;
2931 $filename =~ /\.([^.]*)$/;
2932 return $mimemap{$1};
2935 sub mimetype_guess
{
2936 my $filename = shift;
2938 $filename =~ /\./ or return undef;
2940 if ($mimetypes_file) {
2941 my $file = $mimetypes_file;
2942 if ($file !~ m!^/!) { # if it is relative path
2943 # it is relative to project
2944 $file = "$projectroot/$project/$file";
2946 $mime = mimetype_guess_file
($filename, $file);
2948 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2954 my $filename = shift;
2957 my $mime = mimetype_guess
($filename);
2958 $mime and return $mime;
2962 return $default_blob_plain_mimetype unless $fd;
2965 return 'text/plain';
2966 } elsif (! $filename) {
2967 return 'application/octet-stream';
2968 } elsif ($filename =~ m/\.png$/i) {
2970 } elsif ($filename =~ m/\.gif$/i) {
2972 } elsif ($filename =~ m/\.jpe?g$/i) {
2973 return 'image/jpeg';
2975 return 'application/octet-stream';
2979 sub blob_contenttype
{
2980 my ($fd, $file_name, $type) = @_;
2982 $type ||= blob_mimetype
($fd, $file_name);
2983 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
2984 $type .= "; charset=$default_text_plain_charset";
2990 ## ======================================================================
2991 ## functions printing HTML: header, footer, error page
2993 sub git_header_html
{
2994 my $status = shift || "200 OK";
2995 my $expires = shift;
2997 my $title = "$site_name";
2998 if (defined $project) {
2999 $title .= " - " . to_utf8
($project);
3000 if (defined $action) {
3001 $title .= "/$action";
3002 if (defined $file_name) {
3003 $title .= " - " . esc_path
($file_name);
3004 if ($action eq "tree" && $file_name !~ m
|/$|) {
3011 # require explicit support from the UA if we are to send the page as
3012 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
3013 # we have to do this because MSIE sometimes globs '*/*', pretending to
3014 # support xhtml+xml but choking when it gets what it asked for.
3015 if (defined $cgi->http('HTTP_ACCEPT') &&
3016 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
3017 $cgi->Accept('application/xhtml+xml') != 0) {
3018 $content_type = 'application/xhtml+xml';
3020 $content_type = 'text/html';
3022 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
3023 -status
=> $status, -expires
=> $expires);
3024 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
3026 <?xml version="1.0" encoding="utf-8"?>
3027 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3028 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
3029 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
3030 <!-- git core binaries version $git_version -->
3032 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
3033 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
3034 <meta name="robots" content="index, nofollow"/>
3035 <title>$title</title>
3037 # the stylesheet, favicon etc urls won't work correctly with path_info
3038 # unless we set the appropriate base URL
3039 if ($ENV{'PATH_INFO'}) {
3040 print "<base href=\"".esc_url
($base_url)."\" />\n";
3042 # print out each stylesheet that exist, providing backwards capability
3043 # for those people who defined $stylesheet in a config file
3044 if (defined $stylesheet) {
3045 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
3047 foreach my $stylesheet (@stylesheets) {
3048 next unless $stylesheet;
3049 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
3052 if (defined $project) {
3053 my %href_params = get_feed_info
();
3054 if (!exists $href_params{'-title'}) {
3055 $href_params{'-title'} = 'log';
3058 foreach my $format qw(RSS Atom) {
3059 my $type = lc($format);
3061 '-rel' => 'alternate',
3062 '-title' => "$project - $href_params{'-title'} - $format feed",
3063 '-type' => "application/$type+xml"
3066 $href_params{'action'} = $type;
3067 $link_attr{'-href'} = href
(%href_params);
3069 "rel=\"$link_attr{'-rel'}\" ".
3070 "title=\"$link_attr{'-title'}\" ".
3071 "href=\"$link_attr{'-href'}\" ".
3072 "type=\"$link_attr{'-type'}\" ".
3075 $href_params{'extra_options'} = '--no-merges';
3076 $link_attr{'-href'} = href
(%href_params);
3077 $link_attr{'-title'} .= ' (no merges)';
3079 "rel=\"$link_attr{'-rel'}\" ".
3080 "title=\"$link_attr{'-title'}\" ".
3081 "href=\"$link_attr{'-href'}\" ".
3082 "type=\"$link_attr{'-type'}\" ".
3087 printf('<link rel="alternate" title="%s projects list" '.
3088 'href="%s" type="text/plain; charset=utf-8" />'."\n",
3089 $site_name, href
(project
=>undef, action
=>"project_index"));
3090 printf('<link rel="alternate" title="%s projects feeds" '.
3091 'href="%s" type="text/x-opml" />'."\n",
3092 $site_name, href
(project
=>undef, action
=>"opml"));
3094 if (defined $favicon) {
3095 print qq(<link rel="shortcut icon" href="$favicon" type="image/png" />\n);
3101 if (-f
$site_header) {
3102 insert_file
($site_header);
3105 print "<div class=\"page_header\">\n" .
3106 $cgi->a({-href
=> esc_url
($logo_url),
3107 -title
=> $logo_label},
3108 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
3109 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
3110 if (defined $project) {
3111 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
3112 if (defined $action) {
3119 my $have_search = gitweb_check_feature
('search');
3120 if (defined $project && $have_search) {
3121 if (!defined $searchtext) {
3125 if (defined $hash_base) {
3126 $search_hash = $hash_base;
3127 } elsif (defined $hash) {
3128 $search_hash = $hash;
3130 $search_hash = "HEAD";
3132 my $action = $my_uri;
3133 my $use_pathinfo = gitweb_check_feature
('pathinfo');
3134 if ($use_pathinfo) {
3135 $action .= "/".esc_url
($project);
3137 print $cgi->startform(-method => "get", -action
=> $action) .
3138 "<div class=\"search\">\n" .
3140 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
3141 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
3142 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
3143 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
3144 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
3145 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
3147 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
3148 "<span title=\"Extended regular expression\">" .
3149 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
3150 -checked
=> $search_use_regexp) .
3153 $cgi->end_form() . "\n";
3157 sub git_footer_html
{
3158 my $feed_class = 'rss_logo';
3160 print "<div class=\"page_footer\">\n";
3161 if (defined $project) {
3162 my $descr = git_get_project_description
($project);
3163 if (defined $descr) {
3164 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
3167 my %href_params = get_feed_info
();
3168 if (!%href_params) {
3169 $feed_class .= ' generic';
3171 $href_params{'-title'} ||= 'log';
3173 foreach my $format qw(RSS Atom) {
3174 $href_params{'action'} = lc($format);
3175 print $cgi->a({-href
=> href
(%href_params),
3176 -title
=> "$href_params{'-title'} $format feed",
3177 -class => $feed_class}, $format)."\n";
3181 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
3182 -class => $feed_class}, "OPML") . " ";
3183 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
3184 -class => $feed_class}, "TXT") . "\n";
3186 print "</div>\n"; # class="page_footer"
3188 if (-f
$site_footer) {
3189 insert_file
($site_footer);
3196 # die_error(<http_status_code>, <error_message>)
3197 # Example: die_error(404, 'Hash not found')
3198 # By convention, use the following status codes (as defined in RFC 2616):
3199 # 400: Invalid or missing CGI parameters, or
3200 # requested object exists but has wrong type.
3201 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
3202 # this server or project.
3203 # 404: Requested object/revision/project doesn't exist.
3204 # 500: The server isn't configured properly, or
3205 # an internal error occurred (e.g. failed assertions caused by bugs), or
3206 # an unknown error occurred (e.g. the git binary died unexpectedly).
3208 my $status = shift || 500;
3209 my $error = shift || "Internal server error";
3211 my %http_responses = (400 => '400 Bad Request',
3212 403 => '403 Forbidden',
3213 404 => '404 Not Found',
3214 500 => '500 Internal Server Error');
3215 git_header_html
($http_responses{$status});
3217 <div class="page_body">
3227 ## ----------------------------------------------------------------------
3228 ## functions printing or outputting HTML: navigation
3230 sub git_print_page_nav
{
3231 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
3232 $extra = '' if !defined $extra; # pager or formats
3234 my @navs = qw(summary shortlog log commit commitdiff tree);
3236 @navs = grep { $_ ne $suppress } @navs;
3239 my %arg = map { $_ => {action
=>$_} } @navs;
3240 if (defined $head) {
3241 for (qw(commit commitdiff)) {
3242 $arg{$_}{'hash'} = $head;
3244 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
3245 for (qw(shortlog log)) {
3246 $arg{$_}{'hash'} = $head;
3251 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
3252 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
3254 my @actions = gitweb_get_feature
('actions');
3257 'n' => $project, # project name
3258 'f' => $git_dir, # project path within filesystem
3259 'h' => $treehead || '', # current hash ('h' parameter)
3260 'b' => $treebase || '', # hash base ('hb' parameter)
3263 my ($label, $link, $pos) = splice(@actions,0,3);
3265 @navs = map { $_ eq $pos ? ($_, $label) : $_ } @navs;
3267 $link =~ s/%([%nfhb])/$repl{$1}/g;
3268 $arg{$label}{'_href'} = $link;
3271 print "<div class=\"page_nav\">\n" .
3273 map { $_ eq $current ?
3274 $_ : $cgi->a({-href
=> ($arg{$_}{_href
} ? $arg{$_}{_href
} : href
(%{$arg{$_}}))}, "$_")
3276 print "<br/>\n$extra<br/>\n" .
3280 sub format_paging_nav
{
3281 my ($action, $hash, $head, $page, $has_next_link) = @_;
3285 if ($hash ne $head || $page) {
3286 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
3288 $paging_nav .= "HEAD";
3292 $paging_nav .= " ⋅ " .
3293 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
3294 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3296 $paging_nav .= " ⋅ prev";
3299 if ($has_next_link) {
3300 $paging_nav .= " ⋅ " .
3301 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
3302 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3304 $paging_nav .= " ⋅ next";
3310 ## ......................................................................
3311 ## functions printing or outputting HTML: div
3313 sub git_print_header_div
{
3314 my ($action, $title, $hash, $hash_base) = @_;
3317 $args{'action'} = $action;
3318 $args{'hash'} = $hash if $hash;
3319 $args{'hash_base'} = $hash_base if $hash_base;
3321 print "<div class=\"header\">\n" .
3322 $cgi->a({-href
=> href
(%args), -class => "title"},
3323 $title ? $title : $action) .
3327 sub print_local_time
{
3329 if ($date{'hour_local'} < 6) {
3330 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3331 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3333 printf(" (%02d:%02d %s)",
3334 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3338 # Outputs the author name and date in long form
3339 sub git_print_authorship
{
3342 my $tag = $opts{-tag
} || 'div';
3344 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
3345 print "<$tag class=\"author_date\">" .
3346 esc_html
($co->{'author_name'}) .
3348 print_local_time
(%ad) if ($opts{-localtime});
3349 print "]" . git_get_avatar
($co->{'author_email'}, -pad_before
=> 1)
3353 # Outputs table rows containing the full author or committer information,
3354 # in the format expected for 'commit' view (& similia).
3355 # Parameters are a commit hash reference, followed by the list of people
3356 # to output information for. If the list is empty it defalts to both
3357 # author and committer.
3358 sub git_print_authorship_rows
{
3360 # too bad we can't use @people = @_ || ('author', 'committer')
3362 @people = ('author', 'committer') unless @people;
3363 foreach my $who (@people) {
3364 my %wd = parse_date
($co->{"${who}_epoch"}, $co->{"${who}_tz"});
3365 print "<tr><td>$who</td><td>" . esc_html
($co->{$who}) . "</td>" .
3366 "<td rowspan=\"2\">" .
3367 git_get_avatar
($co->{"${who}_email"}, -size
=> 'double') .
3370 "<td></td><td> $wd{'rfc2822'}";
3371 print_local_time
(%wd);
3377 sub git_print_page_path
{
3383 print "<div class=\"page_path\">";
3384 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
3385 -title
=> 'tree root'}, to_utf8
("[$project]"));
3387 if (defined $name) {
3388 my @dirname = split '/', $name;
3389 my $basename = pop @dirname;
3392 foreach my $dir (@dirname) {
3393 $fullname .= ($fullname ? '/' : '') . $dir;
3394 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
3396 -title
=> $fullname}, esc_path
($dir));
3399 if (defined $type && $type eq 'blob') {
3400 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
3402 -title
=> $name}, esc_path
($basename));
3403 } elsif (defined $type && $type eq 'tree') {
3404 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
3406 -title
=> $name}, esc_path
($basename));
3409 print esc_path
($basename);
3412 print "<br/></div>\n";
3419 if ($opts{'-remove_title'}) {
3420 # remove title, i.e. first line of log
3423 # remove leading empty lines
3424 while (defined $log->[0] && $log->[0] eq "") {
3431 foreach my $line (@$log) {
3432 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
3435 if (! $opts{'-remove_signoff'}) {
3436 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
3439 # remove signoff lines
3446 # print only one empty line
3447 # do not print empty line after signoff
3449 next if ($empty || $signoff);
3455 print format_log_line_html
($line) . "<br/>\n";
3458 if ($opts{'-final_empty_line'}) {
3459 # end with single empty line
3460 print "<br/>\n" unless $empty;
3464 # return link target (what link points to)
3465 sub git_get_link_target
{
3470 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3474 $link_target = <$fd>;
3479 return $link_target;
3482 # given link target, and the directory (basedir) the link is in,
3483 # return target of link relative to top directory (top tree);
3484 # return undef if it is not possible (including absolute links).
3485 sub normalize_link_target
{
3486 my ($link_target, $basedir) = @_;
3488 # absolute symlinks (beginning with '/') cannot be normalized
3489 return if (substr($link_target, 0, 1) eq '/');
3491 # normalize link target to path from top (root) tree (dir)
3494 $path = $basedir . '/' . $link_target;
3496 # we are in top (root) tree (dir)
3497 $path = $link_target;
3500 # remove //, /./, and /../
3502 foreach my $part (split('/', $path)) {
3503 # discard '.' and ''
3504 next if (!$part || $part eq '.');
3506 if ($part eq '..') {
3510 # link leads outside repository (outside top dir)
3514 push @path_parts, $part;
3517 $path = join('/', @path_parts);
3522 # print tree entry (row of git_tree), but without encompassing <tr> element
3523 sub git_print_tree_entry
{
3524 my ($t, $basedir, $hash_base, $have_blame) = @_;
3527 $base_key{'hash_base'} = $hash_base if defined $hash_base;
3529 # The format of a table row is: mode list link. Where mode is
3530 # the mode of the entry, list is the name of the entry, an href,
3531 # and link is the action links of the entry.
3533 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
3534 if ($t->{'type'} eq "blob") {
3535 print "<td class=\"list\">" .
3536 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3537 file_name
=>"$basedir$t->{'name'}", %base_key),
3538 -class => "list"}, esc_path
($t->{'name'}));
3539 if (S_ISLNK
(oct $t->{'mode'})) {
3540 my $link_target = git_get_link_target
($t->{'hash'});
3542 my $norm_target = normalize_link_target
($link_target, $basedir);
3543 if (defined $norm_target) {
3545 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
3546 file_name
=>$norm_target),
3547 -title
=> $norm_target}, esc_path
($link_target));
3549 print " -> " . esc_path
($link_target);
3554 print "<td class=\"link\">";
3555 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3556 file_name
=>"$basedir$t->{'name'}", %base_key)},
3560 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
3561 file_name
=>"$basedir$t->{'name'}", %base_key)},
3564 if (defined $hash_base) {
3566 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3567 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
3571 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
3572 file_name
=>"$basedir$t->{'name'}")},
3576 } elsif ($t->{'type'} eq "tree") {
3577 print "<td class=\"list\">";
3578 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3579 file_name
=>"$basedir$t->{'name'}", %base_key)},
3580 esc_path
($t->{'name'}));
3582 print "<td class=\"link\">";
3583 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3584 file_name
=>"$basedir$t->{'name'}", %base_key)},
3586 if (defined $hash_base) {
3588 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3589 file_name
=>"$basedir$t->{'name'}")},
3594 # unknown object: we can only present history for it
3595 # (this includes 'commit' object, i.e. submodule support)
3596 print "<td class=\"list\">" .
3597 esc_path
($t->{'name'}) .
3599 print "<td class=\"link\">";
3600 if (defined $hash_base) {
3601 print $cgi->a({-href
=> href
(action
=>"history",
3602 hash_base
=>$hash_base,
3603 file_name
=>"$basedir$t->{'name'}")},
3610 ## ......................................................................
3611 ## functions printing large fragments of HTML
3613 # get pre-image filenames for merge (combined) diff
3614 sub fill_from_file_info
{
3615 my ($diff, @parents) = @_;
3617 $diff->{'from_file'} = [ ];
3618 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
3619 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3620 if ($diff->{'status'}[$i] eq 'R' ||
3621 $diff->{'status'}[$i] eq 'C') {
3622 $diff->{'from_file'}[$i] =
3623 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
3630 # is current raw difftree line of file deletion
3632 my $diffinfo = shift;
3634 return $diffinfo->{'to_id'} eq ('0' x
40);
3637 # does patch correspond to [previous] difftree raw line
3638 # $diffinfo - hashref of parsed raw diff format
3639 # $patchinfo - hashref of parsed patch diff format
3640 # (the same keys as in $diffinfo)
3641 sub is_patch_split
{
3642 my ($diffinfo, $patchinfo) = @_;
3644 return defined $diffinfo && defined $patchinfo
3645 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3649 sub git_difftree_body
{
3650 my ($difftree, $hash, @parents) = @_;
3651 my ($parent) = $parents[0];
3652 my $have_blame = gitweb_check_feature
('blame');
3653 print "<div class=\"list_head\">\n";
3654 if ($#{$difftree} > 10) {
3655 print(($#{$difftree} + 1) . " files changed:\n");
3659 print "<table class=\"" .
3660 (@parents > 1 ? "combined " : "") .
3663 # header only for combined diff in 'commitdiff' view
3664 my $has_header = @$difftree && @parents > 1 && $action eq 'commitdiff';
3667 print "<thead><tr>\n" .
3668 "<th></th><th></th>\n"; # filename, patchN link
3669 for (my $i = 0; $i < @parents; $i++) {
3670 my $par = $parents[$i];
3672 $cgi->a({-href
=> href
(action
=>"commitdiff",
3673 hash
=>$hash, hash_parent
=>$par),
3674 -title
=> 'commitdiff to parent number ' .
3675 ($i+1) . ': ' . substr($par,0,7)},
3679 print "</tr></thead>\n<tbody>\n";
3684 foreach my $line (@{$difftree}) {
3685 my $diff = parsed_difftree_line
($line);
3688 print "<tr class=\"dark\">\n";
3690 print "<tr class=\"light\">\n";
3694 if (exists $diff->{'nparents'}) { # combined diff
3696 fill_from_file_info
($diff, @parents)
3697 unless exists $diff->{'from_file'};
3699 if (!is_deleted
($diff)) {
3700 # file exists in the result (child) commit
3702 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3703 file_name
=>$diff->{'to_file'},
3705 -class => "list"}, esc_path
($diff->{'to_file'})) .
3709 esc_path
($diff->{'to_file'}) .
3713 if ($action eq 'commitdiff') {
3716 print "<td class=\"link\">" .
3717 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3722 my $has_history = 0;
3723 my $not_deleted = 0;
3724 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3725 my $hash_parent = $parents[$i];
3726 my $from_hash = $diff->{'from_id'}[$i];
3727 my $from_path = $diff->{'from_file'}[$i];
3728 my $status = $diff->{'status'}[$i];
3730 $has_history ||= ($status ne 'A');
3731 $not_deleted ||= ($status ne 'D');
3733 if ($status eq 'A') {
3734 print "<td class=\"link\" align=\"right\"> | </td>\n";
3735 } elsif ($status eq 'D') {
3736 print "<td class=\"link\">" .
3737 $cgi->a({-href
=> href
(action
=>"blob",
3740 file_name
=>$from_path)},
3744 if ($diff->{'to_id'} eq $from_hash) {
3745 print "<td class=\"link nochange\">";
3747 print "<td class=\"link\">";
3749 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3750 hash
=>$diff->{'to_id'},
3751 hash_parent
=>$from_hash,
3753 hash_parent_base
=>$hash_parent,
3754 file_name
=>$diff->{'to_file'},
3755 file_parent
=>$from_path)},
3761 print "<td class=\"link\">";
3763 print $cgi->a({-href
=> href
(action
=>"blob",
3764 hash
=>$diff->{'to_id'},
3765 file_name
=>$diff->{'to_file'},
3768 print " | " if ($has_history);
3771 print $cgi->a({-href
=> href
(action
=>"history",
3772 file_name
=>$diff->{'to_file'},
3779 next; # instead of 'else' clause, to avoid extra indent
3781 # else ordinary diff
3783 my ($to_mode_oct, $to_mode_str, $to_file_type);
3784 my ($from_mode_oct, $from_mode_str, $from_file_type);
3785 if ($diff->{'to_mode'} ne ('0' x
6)) {
3786 $to_mode_oct = oct $diff->{'to_mode'};
3787 if (S_ISREG
($to_mode_oct)) { # only for regular file
3788 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3790 $to_file_type = file_type
($diff->{'to_mode'});
3792 if ($diff->{'from_mode'} ne ('0' x
6)) {
3793 $from_mode_oct = oct $diff->{'from_mode'};
3794 if (S_ISREG
($to_mode_oct)) { # only for regular file
3795 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3797 $from_file_type = file_type
($diff->{'from_mode'});
3800 if ($diff->{'status'} eq "A") { # created
3801 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3802 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3803 $mode_chng .= "]</span>";
3805 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3806 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3807 -class => "list"}, esc_path
($diff->{'file'}));
3809 print "<td>$mode_chng</td>\n";
3810 print "<td class=\"link\">";
3811 if ($action eq 'commitdiff') {
3814 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3817 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3818 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3822 } elsif ($diff->{'status'} eq "D") { # deleted
3823 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3825 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3826 hash_base
=>$parent, file_name
=>$diff->{'file'}),
3827 -class => "list"}, esc_path
($diff->{'file'}));
3829 print "<td>$mode_chng</td>\n";
3830 print "<td class=\"link\">";
3831 if ($action eq 'commitdiff') {
3834 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3837 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3838 hash_base
=>$parent, file_name
=>$diff->{'file'})},
3841 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3842 file_name
=>$diff->{'file'})},
3845 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3846 file_name
=>$diff->{'file'})},
3850 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3851 my $mode_chnge = "";
3852 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3853 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3854 if ($from_file_type ne $to_file_type) {
3855 $mode_chnge .= " from $from_file_type to $to_file_type";
3857 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3858 if ($from_mode_str && $to_mode_str) {
3859 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3860 } elsif ($to_mode_str) {
3861 $mode_chnge .= " mode: $to_mode_str";
3864 $mode_chnge .= "]</span>\n";
3867 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3868 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3869 -class => "list"}, esc_path
($diff->{'file'}));
3871 print "<td>$mode_chnge</td>\n";
3872 print "<td class=\"link\">";
3873 if ($action eq 'commitdiff') {
3876 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3878 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3879 # "commit" view and modified file (not onlu mode changed)
3880 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3881 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3882 hash_base
=>$hash, hash_parent_base
=>$parent,
3883 file_name
=>$diff->{'file'})},
3887 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3888 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3891 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3892 file_name
=>$diff->{'file'})},
3895 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3896 file_name
=>$diff->{'file'})},
3900 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3901 my %status_name = ('R' => 'moved', 'C' => 'copied');
3902 my $nstatus = $status_name{$diff->{'status'}};
3904 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3905 # mode also for directories, so we cannot use $to_mode_str
3906 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3909 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3910 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
3911 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3912 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3913 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3914 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
3915 -class => "list"}, esc_path
($diff->{'from_file'})) .
3916 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3917 "<td class=\"link\">";
3918 if ($action eq 'commitdiff') {
3921 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3923 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3924 # "commit" view and modified file (not only pure rename or copy)
3925 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3926 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3927 hash_base
=>$hash, hash_parent_base
=>$parent,
3928 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
3932 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3933 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
3936 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3937 file_name
=>$diff->{'to_file'})},
3940 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3941 file_name
=>$diff->{'to_file'})},
3945 } # we should not encounter Unmerged (U) or Unknown (X) status
3948 print "</tbody>" if $has_header;
3952 sub git_patchset_body
{
3953 my ($fd, $difftree, $hash, @hash_parents) = @_;
3954 my ($hash_parent) = $hash_parents[0];
3956 my $is_combined = (@hash_parents > 1);
3958 my $patch_number = 0;
3964 print "<div class=\"patchset\">\n";
3966 # skip to first patch
3967 while ($patch_line = <$fd>) {
3970 last if ($patch_line =~ m/^diff /);
3974 while ($patch_line) {
3976 # parse "git diff" header line
3977 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
3978 # $1 is from_name, which we do not use
3979 $to_name = unquote
($2);
3980 $to_name =~ s!^b/!!;
3981 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
3982 # $1 is 'cc' or 'combined', which we do not use
3983 $to_name = unquote
($2);
3988 # check if current patch belong to current raw line
3989 # and parse raw git-diff line if needed
3990 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
3991 # this is continuation of a split patch
3992 print "<div class=\"patch cont\">\n";
3994 # advance raw git-diff output if needed
3995 $patch_idx++ if defined $diffinfo;
3997 # read and prepare patch information
3998 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4000 # compact combined diff output can have some patches skipped
4001 # find which patch (using pathname of result) we are at now;
4003 while ($to_name ne $diffinfo->{'to_file'}) {
4004 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4005 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4006 "</div>\n"; # class="patch"
4011 last if $patch_idx > $#$difftree;
4012 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4016 # modifies %from, %to hashes
4017 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
4019 # this is first patch for raw difftree line with $patch_idx index
4020 # we index @$difftree array from 0, but number patches from 1
4021 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
4025 #assert($patch_line =~ m/^diff /) if DEBUG;
4026 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
4028 # print "git diff" header
4029 print format_git_diff_header_line
($patch_line, $diffinfo,
4032 # print extended diff header
4033 print "<div class=\"diff extended_header\">\n";
4035 while ($patch_line = <$fd>) {
4038 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
4040 print format_extended_diff_header_line
($patch_line, $diffinfo,
4043 print "</div>\n"; # class="diff extended_header"
4045 # from-file/to-file diff header
4046 if (! $patch_line) {
4047 print "</div>\n"; # class="patch"
4050 next PATCH
if ($patch_line =~ m/^diff /);
4051 #assert($patch_line =~ m/^---/) if DEBUG;
4053 my $last_patch_line = $patch_line;
4054 $patch_line = <$fd>;
4056 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
4058 print format_diff_from_to_header
($last_patch_line, $patch_line,
4059 $diffinfo, \
%from, \
%to,
4064 while ($patch_line = <$fd>) {
4067 next PATCH
if ($patch_line =~ m/^diff /);
4069 print format_diff_line
($patch_line, \
%from, \
%to);
4073 print "</div>\n"; # class="patch"
4076 # for compact combined (--cc) format, with chunk and patch simpliciaction
4077 # patchset might be empty, but there might be unprocessed raw lines
4078 for (++$patch_idx if $patch_number > 0;
4079 $patch_idx < @$difftree;
4081 # read and prepare patch information
4082 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4084 # generate anchor for "patch" links in difftree / whatchanged part
4085 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4086 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4087 "</div>\n"; # class="patch"
4092 if ($patch_number == 0) {
4093 if (@hash_parents > 1) {
4094 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
4096 print "<div class=\"diff nodifferences\">No differences found</div>\n";
4100 print "</div>\n"; # class="patchset"
4103 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4105 # fills project list info (age, description, owner, forks) for each
4106 # project in the list, removing invalid projects from returned list
4107 # NOTE: modifies $projlist, but does not remove entries from it
4108 sub fill_project_list_info
{
4109 my ($projlist, $check_forks) = @_;
4112 my $show_ctags = gitweb_check_feature
('ctags');
4114 foreach my $pr (@$projlist) {
4115 my (@activity) = git_get_last_activity
($pr->{'path'});
4116 unless (@activity) {
4119 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
4120 if (!defined $pr->{'descr'}) {
4121 my $descr = git_get_project_description
($pr->{'path'}) || "";
4122 $descr = to_utf8
($descr);
4123 $pr->{'descr_long'} = $descr;
4124 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
4126 if (!defined $pr->{'owner'}) {
4127 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
4130 my $pname = $pr->{'path'};
4131 if (($pname =~ s/\.git$//) &&
4132 ($pname !~ /\/$/) &&
4133 (-d
"$projectroot/$pname")) {
4134 $pr->{'forks'} = "-d $projectroot/$pname";
4139 $show_ctags and $pr->{'ctags'} = git_get_project_ctags
($pr->{'path'});
4140 push @projects, $pr;
4146 # print 'sort by' <th> element, generating 'sort by $name' replay link
4147 # if that order is not selected
4149 my ($name, $order, $header) = @_;
4150 $header ||= ucfirst($name);
4152 if ($order eq $name) {
4153 print "<th>$header</th>\n";
4156 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
4157 -class => "header"}, $header) .
4162 sub git_project_list_body
{
4163 # actually uses global variable $project
4164 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
4166 my $check_forks = gitweb_check_feature
('forks');
4167 my @projects = fill_project_list_info
($projlist, $check_forks);
4169 $order ||= $default_projects_order;
4170 $from = 0 unless defined $from;
4171 $to = $#projects if (!defined $to || $#projects < $to);
4174 project
=> { key
=> 'path', type
=> 'str' },
4175 descr
=> { key
=> 'descr_long', type
=> 'str' },
4176 owner
=> { key
=> 'owner', type
=> 'str' },
4177 age
=> { key
=> 'age', type
=> 'num' }
4179 my $oi = $order_info{$order};
4180 if ($oi->{'type'} eq 'str') {
4181 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
4183 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
4186 my $show_ctags = gitweb_check_feature
('ctags');
4189 foreach my $p (@projects) {
4190 foreach my $ct (keys %{$p->{'ctags'}}) {
4191 $ctags{$ct} += $p->{'ctags'}->{$ct};
4194 my $cloud = git_populate_project_tagcloud
(\
%ctags);
4195 print git_show_project_tagcloud
($cloud, 64);
4198 print "<table class=\"project_list\">\n";
4199 unless ($no_header) {
4202 print "<th></th>\n";
4204 print_sort_th
('project', $order, 'Project');
4205 print_sort_th
('descr', $order, 'Description');
4206 print_sort_th
('owner', $order, 'Owner');
4207 print_sort_th
('age', $order, 'Last Change');
4208 print "<th></th>\n" . # for links
4212 my $tagfilter = $cgi->param('by_tag');
4213 for (my $i = $from; $i <= $to; $i++) {
4214 my $pr = $projects[$i];
4216 next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}};
4217 next if $searchtext and not $pr->{'path'} =~ /$searchtext/
4218 and not $pr->{'descr_long'} =~ /$searchtext/;
4219 # Weed out forks or non-matching entries of search
4221 my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s
#\.git$#/#;
4222 $forkbase="^$forkbase" if $forkbase;
4223 next if not $searchtext and not $tagfilter and $show_ctags
4224 and $pr->{'path'} =~ m
#$forkbase.*/.*#; # regexp-safe
4228 print "<tr class=\"dark\">\n";
4230 print "<tr class=\"light\">\n";
4235 if ($pr->{'forks'}) {
4236 print "<!-- $pr->{'forks'} -->\n";
4237 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
4241 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4242 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
4243 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4244 -class => "list", -title
=> $pr->{'descr_long'}},
4245 esc_html
($pr->{'descr'})) . "</td>\n" .
4246 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
4247 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
4248 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
4249 "<td class=\"link\">" .
4250 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
4251 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
4252 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
4253 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
4254 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
4258 if (defined $extra) {
4261 print "<td></td>\n";
4263 print "<td colspan=\"5\">$extra</td>\n" .
4269 sub git_shortlog_body
{
4270 # uses global variable $project
4271 my ($commitlist, $from, $to, $refs, $extra) = @_;
4273 $from = 0 unless defined $from;
4274 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4276 print "<table class=\"shortlog\">\n";
4278 for (my $i = $from; $i <= $to; $i++) {
4279 my %co = %{$commitlist->[$i]};
4280 my $commit = $co{'id'};
4281 my $ref = format_ref_marker
($refs, $commit);
4283 print "<tr class=\"dark\">\n";
4285 print "<tr class=\"light\">\n";
4288 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
4289 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4290 format_author_html
('td', \
%co, 10) . "<td>";
4291 print format_subject_html
($co{'title'}, $co{'title_short'},
4292 href
(action
=>"commit", hash
=>$commit), $ref);
4294 "<td class=\"link\">" .
4295 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
4296 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
4297 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
4298 my $snapshot_links = format_snapshot_links
($commit);
4299 if (defined $snapshot_links) {
4300 print " | " . $snapshot_links;
4305 if (defined $extra) {
4307 "<td colspan=\"4\">$extra</td>\n" .
4313 sub git_history_body
{
4314 # Warning: assumes constant type (blob or tree) during history
4315 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
4317 $from = 0 unless defined $from;
4318 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
4320 print "<table class=\"history\">\n";
4322 for (my $i = $from; $i <= $to; $i++) {
4323 my %co = %{$commitlist->[$i]};
4327 my $commit = $co{'id'};
4329 my $ref = format_ref_marker
($refs, $commit);
4332 print "<tr class=\"dark\">\n";
4334 print "<tr class=\"light\">\n";
4337 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4338 # shortlog: format_author_html('td', \%co, 10)
4339 format_author_html
('td', \
%co, 15, 3) . "<td>";
4340 # originally git_history used chop_str($co{'title'}, 50)
4341 print format_subject_html
($co{'title'}, $co{'title_short'},
4342 href
(action
=>"commit", hash
=>$commit), $ref);
4344 "<td class=\"link\">" .
4345 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
4346 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
4348 if ($ftype eq 'blob') {
4349 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
4350 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
4351 if (defined $blob_current && defined $blob_parent &&
4352 $blob_current ne $blob_parent) {
4354 $cgi->a({-href
=> href
(action
=>"blobdiff",
4355 hash
=>$blob_current, hash_parent
=>$blob_parent,
4356 hash_base
=>$hash_base, hash_parent_base
=>$commit,
4357 file_name
=>$file_name)},
4364 if (defined $extra) {
4366 "<td colspan=\"4\">$extra</td>\n" .
4373 # uses global variable $project
4374 my ($taglist, $from, $to, $extra) = @_;
4375 $from = 0 unless defined $from;
4376 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
4378 print "<table class=\"tags\">\n";
4380 for (my $i = $from; $i <= $to; $i++) {
4381 my $entry = $taglist->[$i];
4383 my $comment = $tag{'subject'};
4385 if (defined $comment) {
4386 $comment_short = chop_str
($comment, 30, 5);
4389 print "<tr class=\"dark\">\n";
4391 print "<tr class=\"light\">\n";
4394 if (defined $tag{'age'}) {
4395 print "<td><i>$tag{'age'}</i></td>\n";
4397 print "<td></td>\n";
4400 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
4401 -class => "list name"}, esc_html
($tag{'name'})) .
4404 if (defined $comment) {
4405 print format_subject_html
($comment, $comment_short,
4406 href
(action
=>"tag", hash
=>$tag{'id'}));
4409 "<td class=\"selflink\">";
4410 if ($tag{'type'} eq "tag") {
4411 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
4416 "<td class=\"link\">" . " | " .
4417 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
4418 if ($tag{'reftype'} eq "commit") {
4419 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
4420 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
4421 } elsif ($tag{'reftype'} eq "blob") {
4422 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
4427 if (defined $extra) {
4429 "<td colspan=\"5\">$extra</td>\n" .
4435 sub git_heads_body
{
4436 # uses global variable $project
4437 my ($headlist, $head, $from, $to, $extra) = @_;
4438 $from = 0 unless defined $from;
4439 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
4441 print "<table class=\"heads\">\n";
4443 for (my $i = $from; $i <= $to; $i++) {
4444 my $entry = $headlist->[$i];
4446 my $curr = $ref{'id'} eq $head;
4448 print "<tr class=\"dark\">\n";
4450 print "<tr class=\"light\">\n";
4453 print "<td><i>$ref{'age'}</i></td>\n" .
4454 ($curr ? "<td class=\"current_head\">" : "<td>") .
4455 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
4456 -class => "list name"},esc_html
($ref{'name'})) .
4458 "<td class=\"link\">" .
4459 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
4460 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
4461 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
4465 if (defined $extra) {
4467 "<td colspan=\"3\">$extra</td>\n" .
4473 sub git_search_grep_body
{
4474 my ($commitlist, $from, $to, $extra) = @_;
4475 $from = 0 unless defined $from;
4476 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4478 print "<table class=\"commit_search\">\n";
4480 for (my $i = $from; $i <= $to; $i++) {
4481 my %co = %{$commitlist->[$i]};
4485 my $commit = $co{'id'};
4487 print "<tr class=\"dark\">\n";
4489 print "<tr class=\"light\">\n";
4492 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4493 format_author_html
('td', \
%co, 15, 5) .
4495 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4496 -class => "list subject"},
4497 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
4498 my $comment = $co{'comment'};
4499 foreach my $line (@$comment) {
4500 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
4501 my ($lead, $match, $trail) = ($1, $2, $3);
4502 $match = chop_str
($match, 70, 5, 'center');
4503 my $contextlen = int((80 - length($match))/2);
4504 $contextlen = 30 if ($contextlen > 30);
4505 $lead = chop_str
($lead, $contextlen, 10, 'left');
4506 $trail = chop_str
($trail, $contextlen, 10, 'right');
4508 $lead = esc_html
($lead);
4509 $match = esc_html
($match);
4510 $trail = esc_html
($trail);
4512 print "$lead<span class=\"match\">$match</span>$trail<br />";
4516 "<td class=\"link\">" .
4517 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4519 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
4521 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4525 if (defined $extra) {
4527 "<td colspan=\"3\">$extra</td>\n" .
4533 ## ======================================================================
4534 ## ======================================================================
4537 sub git_project_list
{
4538 my $order = $input_params{'order'};
4539 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4540 die_error
(400, "Unknown order parameter");
4543 my @list = git_get_projects_list
();
4545 die_error
(404, "No projects found");
4549 if (-f
$home_text) {
4550 print "<div class=\"index_include\">\n";
4551 insert_file
($home_text);
4554 print $cgi->startform(-method => "get") .
4555 "<p class=\"projsearch\">Search:\n" .
4556 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
4558 $cgi->end_form() . "\n";
4559 git_project_list_body
(\
@list, $order);
4564 my $order = $input_params{'order'};
4565 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4566 die_error
(400, "Unknown order parameter");
4569 my @list = git_get_projects_list
($project);
4571 die_error
(404, "No forks found");
4575 git_print_page_nav
('','');
4576 git_print_header_div
('summary', "$project forks");
4577 git_project_list_body
(\
@list, $order);
4581 sub git_project_index
{
4582 my @projects = git_get_projects_list
($project);
4585 -type
=> 'text/plain',
4586 -charset
=> 'utf-8',
4587 -content_disposition
=> 'inline; filename="index.aux"');
4589 foreach my $pr (@projects) {
4590 if (!exists $pr->{'owner'}) {
4591 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
4594 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
4595 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
4596 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4597 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4601 print "$path $owner\n";
4606 my $descr = git_get_project_description
($project) || "none";
4607 my %co = parse_commit
("HEAD");
4608 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
4609 my $head = $co{'id'};
4611 my $owner = git_get_project_owner
($project);
4613 my $refs = git_get_references
();
4614 # These get_*_list functions return one more to allow us to see if
4615 # there are more ...
4616 my @taglist = git_get_tags_list
(16);
4617 my @headlist = git_get_heads_list
(16);
4619 my $check_forks = gitweb_check_feature
('forks');
4622 @forklist = git_get_projects_list
($project);
4626 git_print_page_nav
('summary','', $head);
4628 print "<div class=\"title\"> </div>\n";
4629 print "<table class=\"projects_list\">\n" .
4630 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
4631 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
4632 if (defined $cd{'rfc2822'}) {
4633 print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4636 # use per project git URL list in $projectroot/$project/cloneurl
4637 # or make project git URL from git base URL and project name
4638 my $url_tag = "URL";
4639 my @url_list = git_get_project_url_list
($project);
4640 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4641 foreach my $git_url (@url_list) {
4642 next unless $git_url;
4643 print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";
4648 my $show_ctags = gitweb_check_feature
('ctags');
4650 my $ctags = git_get_project_ctags
($project);
4651 my $cloud = git_populate_project_tagcloud
($ctags);
4652 print "<tr id=\"metadata_ctags\"><td>Content tags:<br />";
4653 print "</td>\n<td>" unless %$ctags;
4654 print "<form action=\"$show_ctags\" method=\"post\"><input type=\"hidden\" name=\"p\" value=\"$project\" />Add: <input type=\"text\" name=\"t\" size=\"8\" /></form>";
4655 print "</td>\n<td>" if %$ctags;
4656 print git_show_project_tagcloud
($cloud, 48);
4662 # If XSS prevention is on, we don't include README.html.
4663 # TODO: Allow a readme in some safe format.
4664 if (!$prevent_xss && -s
"$projectroot/$project/README.html") {
4665 print "<div class=\"title\">readme</div>\n" .
4666 "<div class=\"readme\">\n";
4667 insert_file
("$projectroot/$project/README.html");
4668 print "\n</div>\n"; # class="readme"
4671 # we need to request one more than 16 (0..15) to check if
4673 my @commitlist = $head ? parse_commits
($head, 17) : ();
4675 git_print_header_div
('shortlog');
4676 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
4677 $#commitlist <= 15 ? undef :
4678 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
4682 git_print_header_div
('tags');
4683 git_tags_body
(\
@taglist, 0, 15,
4684 $#taglist <= 15 ? undef :
4685 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
4689 git_print_header_div
('heads');
4690 git_heads_body
(\
@headlist, $head, 0, 15,
4691 $#headlist <= 15 ? undef :
4692 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
4696 git_print_header_div
('forks');
4697 git_project_list_body
(\
@forklist, 'age', 0, 15,
4698 $#forklist <= 15 ? undef :
4699 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
4707 my $head = git_get_head_hash
($project);
4709 git_print_page_nav
('','', $head,undef,$head);
4710 my %tag = parse_tag
($hash);
4713 die_error
(404, "Unknown tag object");
4716 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
4717 print "<div class=\"title_text\">\n" .
4718 "<table class=\"object_header\">\n" .
4720 "<td>object</td>\n" .
4721 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4722 $tag{'object'}) . "</td>\n" .
4723 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4724 $tag{'type'}) . "</td>\n" .
4726 if (defined($tag{'author'})) {
4727 git_print_authorship_rows
(\
%tag, 'author');
4729 print "</table>\n\n" .
4731 print "<div class=\"page_body\">";
4732 my $comment = $tag{'comment'};
4733 foreach my $line (@$comment) {
4735 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4743 gitweb_check_feature
('blame')
4744 or die_error
(403, "Blame view not allowed");
4747 die_error
(400, "No file name given") unless $file_name;
4748 $hash_base ||= git_get_head_hash
($project);
4749 die_error
(404, "Couldn't find base commit") unless $hash_base;
4750 my %co = parse_commit
($hash_base)
4751 or die_error
(404, "Commit not found");
4753 if (!defined $hash) {
4754 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4755 or die_error
(404, "Error looking up file");
4757 $ftype = git_get_type
($hash);
4758 if ($ftype !~ "blob") {
4759 die_error
(400, "Object is not a blob");
4763 # run git-blame --porcelain
4764 open my $fd, "-|", git_cmd
(), "blame", '-p',
4765 $hash_base, '--', $file_name
4766 or die_error
(500, "Open git-blame failed");
4771 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
4774 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4777 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4779 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4780 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4781 git_print_page_path
($file_name, $ftype, $hash_base);
4784 my @rev_color = qw(light2 dark2);
4785 my $num_colors = scalar(@rev_color);
4786 my $current_color = 0;
4790 <div class="page_body">
4791 <table class="blame">
4792 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
4795 while (my $line = <$fd>) {
4797 # the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]
4798 # no <lines in group> for subsequent lines in group of lines
4799 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4800 ($line =~ /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);
4801 if (!exists $metainfo{$full_rev}) {
4802 $metainfo{$full_rev} = {};
4804 my $meta = $metainfo{$full_rev};
4806 while ($data = <$fd>) {
4808 last if ($data =~ s/^\t//); # contents of line
4809 if ($data =~ /^(\S+) (.*)$/) {
4813 my $short_rev = substr($full_rev, 0, 8);
4814 my $author = $meta->{'author'};
4816 parse_date
($meta->{'author-time'}, $meta->{'author-tz'});
4817 my $date = $date{'iso-tz'};
4819 $current_color = ($current_color + 1) % $num_colors;
4821 print "<tr id=\"l$lineno\" class=\"$rev_color[$current_color]\">\n";
4823 print "<td class=\"sha1\"";
4824 print " title=\"". esc_html
($author) . ", $date\"";
4825 print " rowspan=\"$group_size\"" if ($group_size > 1);
4827 print $cgi->a({-href
=> href
(action
=>"commit",
4829 file_name
=>$file_name)},
4830 esc_html
($short_rev));
4834 if (!exists $meta->{'parent'}) {
4835 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
4836 or die_error
(500, "Open git-rev-parse failed");
4837 $parent_commit = <$dd>;
4839 chomp($parent_commit);
4840 $meta->{'parent'} = $parent_commit;
4842 $parent_commit = $meta->{'parent'};
4844 my $blamed = href
(action
=> 'blame',
4845 file_name
=> $meta->{'filename'},
4846 hash_base
=> $parent_commit);
4847 print "<td class=\"linenr\">";
4848 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
4849 -class => "linenr" },
4852 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
4858 or print "Reading blob failed\n";
4865 my $head = git_get_head_hash
($project);
4867 git_print_page_nav
('','', $head,undef,$head);
4868 git_print_header_div
('summary', $project);
4870 my @tagslist = git_get_tags_list
();
4872 git_tags_body
(\
@tagslist);
4878 my $head = git_get_head_hash
($project);
4880 git_print_page_nav
('','', $head,undef,$head);
4881 git_print_header_div
('summary', $project);
4883 my @headslist = git_get_heads_list
();
4885 git_heads_body
(\
@headslist, $head);
4890 sub git_blob_plain
{
4894 if (!defined $hash) {
4895 if (defined $file_name) {
4896 my $base = $hash_base || git_get_head_hash
($project);
4897 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4898 or die_error
(404, "Cannot find file");
4900 die_error
(400, "No file name defined");
4902 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4903 # blobs defined by non-textual hash id's can be cached
4907 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4908 or die_error
(500, "Open git-cat-file blob '$hash' failed");
4910 # content-type (can include charset)
4911 $type = blob_contenttype
($fd, $file_name, $type);
4913 # "save as" filename, even when no $file_name is given
4914 my $save_as = "$hash";
4915 if (defined $file_name) {
4916 $save_as = $file_name;
4917 } elsif ($type =~ m/^text\//) {
4921 # With XSS prevention on, blobs of all types except a few known safe
4922 # ones are served with "Content-Disposition: attachment" to make sure
4923 # they don't run in our security domain. For certain image types,
4924 # blob view writes an <img> tag referring to blob_plain view, and we
4925 # want to be sure not to break that by serving the image as an
4926 # attachment (though Firefox 3 doesn't seem to care).
4927 my $sandbox = $prevent_xss &&
4928 $type !~ m!^(?:text/plain|image/(?:gif|png|jpeg))$!;
4932 -expires
=> $expires,
4933 -content_disposition
=>
4934 ($sandbox ? 'attachment' : 'inline')
4935 . '; filename="' . $save_as . '"');
4937 binmode STDOUT
, ':raw';
4939 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4946 if (!defined $hash) {
4947 if (defined $file_name) {
4948 my $base = $hash_base || git_get_head_hash
($project);
4949 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4950 or die_error
(404, "Cannot find file");
4952 die_error
(400, "No file name defined");
4954 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4955 # blobs defined by non-textual hash id's can be cached
4959 my $have_blame = gitweb_check_feature
('blame');
4960 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4961 or die_error
(500, "Couldn't cat $file_name, $hash");
4962 my $mimetype = blob_mimetype
($fd, $file_name);
4963 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
4965 return git_blob_plain
($mimetype);
4967 # we can have blame only for text/* mimetype
4968 $have_blame &&= ($mimetype =~ m!^text/!);
4970 git_header_html
(undef, $expires);
4971 my $formats_nav = '';
4972 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4973 if (defined $file_name) {
4976 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
4981 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4984 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4987 $cgi->a({-href
=> href
(action
=>"blob",
4988 hash_base
=>"HEAD", file_name
=>$file_name)},
4992 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4995 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4996 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4998 print "<div class=\"page_nav\">\n" .
4999 "<br/><br/></div>\n" .
5000 "<div class=\"title\">$hash</div>\n";
5002 git_print_page_path
($file_name, "blob", $hash_base);
5003 print "<div class=\"page_body\">\n";
5004 if ($mimetype =~ m!^image/!) {
5005 print qq
!<img type
="$mimetype"!;
5007 print qq
! alt
="$file_name" title
="$file_name"!;
5010 href(action=>"blob_plain
", hash=>$hash,
5011 hash_base=>$hash_base, file_name=>$file_name) .
5015 while (my $line = <$fd>) {
5018 $line = untabify
($line);
5019 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
5020 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
5024 or print "Reading blob failed.\n";
5030 if (!defined $hash_base) {
5031 $hash_base = "HEAD";
5033 if (!defined $hash) {
5034 if (defined $file_name) {
5035 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
5040 die_error
(404, "No such tree") unless defined($hash);
5045 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
5046 or die_error
(500, "Open git-ls-tree failed");
5047 @entries = map { chomp; $_ } <$fd>;
5049 or die_error
(404, "Reading tree failed");
5052 my $refs = git_get_references
();
5053 my $ref = format_ref_marker
($refs, $hash_base);
5056 my $have_blame = gitweb_check_feature
('blame');
5057 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5059 if (defined $file_name) {
5061 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5063 $cgi->a({-href
=> href
(action
=>"tree",
5064 hash_base
=>"HEAD", file_name
=>$file_name)},
5067 my $snapshot_links = format_snapshot_links
($hash);
5068 if (defined $snapshot_links) {
5069 # FIXME: Should be available when we have no hash base as well.
5070 push @views_nav, $snapshot_links;
5072 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
5073 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
5076 print "<div class=\"page_nav\">\n";
5077 print "<br/><br/></div>\n";
5078 print "<div class=\"title\">$hash</div>\n";
5080 if (defined $file_name) {
5081 $basedir = $file_name;
5082 if ($basedir ne '' && substr($basedir, -1) ne '/') {
5085 git_print_page_path
($file_name, 'tree', $hash_base);
5087 print "<div class=\"page_body\">\n";
5088 print "<table class=\"tree\">\n";
5090 # '..' (top directory) link if possible
5091 if (defined $hash_base &&
5092 defined $file_name && $file_name =~ m![^/]+$!) {
5094 print "<tr class=\"dark\">\n";
5096 print "<tr class=\"light\">\n";
5100 my $up = $file_name;
5101 $up =~ s!/?[^/]+$!!;
5102 undef $up unless $up;
5103 # based on git_print_tree_entry
5104 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
5105 print '<td class="list">';
5106 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
5110 print "<td class=\"link\"></td>\n";
5114 foreach my $line (@entries) {
5115 my %t = parse_ls_tree_line
($line, -z
=> 1);
5118 print "<tr class=\"dark\">\n";
5120 print "<tr class=\"light\">\n";
5124 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
5128 print "</table>\n" .
5134 my $format = $input_params{'snapshot_format'};
5135 if (!@snapshot_fmts) {
5136 die_error
(403, "Snapshots not allowed");
5138 # default to first supported snapshot format
5139 $format ||= $snapshot_fmts[0];
5140 if ($format !~ m/^[a-z0-9]+$/) {
5141 die_error
(400, "Invalid snapshot format parameter");
5142 } elsif (!exists($known_snapshot_formats{$format})) {
5143 die_error
(400, "Unknown snapshot format");
5144 } elsif (!grep($_ eq $format, @snapshot_fmts)) {
5145 die_error
(403, "Unsupported snapshot format");
5148 if (!defined $hash) {
5149 $hash = git_get_head_hash
($project);
5152 my $name = $project;
5153 $name =~ s
,([^/])/*\
.git
$,$1,;
5154 $name = basename
($name);
5155 my $filename = to_utf8
($name);
5156 $name =~ s/\047/\047\\\047\047/g;
5158 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
5159 $cmd = quote_command
(
5160 git_cmd
(), 'archive',
5161 "--format=$known_snapshot_formats{$format}{'format'}",
5162 "--prefix=$name/", $hash);
5163 if (exists $known_snapshot_formats{$format}{'compressor'}) {
5164 $cmd .= ' | ' . quote_command
(@{$known_snapshot_formats{$format}{'compressor'}});
5168 -type
=> $known_snapshot_formats{$format}{'type'},
5169 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
5170 -status
=> '200 OK');
5172 open my $fd, "-|", $cmd
5173 or die_error
(500, "Execute git-archive failed");
5174 binmode STDOUT
, ':raw';
5176 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5181 my $head = git_get_head_hash
($project);
5182 if (!defined $hash) {
5185 if (!defined $page) {
5188 my $refs = git_get_references
();
5190 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5192 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#commitlist >= 100);
5194 my ($patch_max) = gitweb_get_feature
('patches');
5196 if ($patch_max < 0 || @commitlist <= $patch_max) {
5197 $paging_nav .= " ⋅ " .
5198 $cgi->a({-href
=> href
(action
=>"patches", -replay
=>1)},
5204 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
5207 my %co = parse_commit
($hash);
5209 git_print_header_div
('summary', $project);
5210 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
5212 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
5213 for (my $i = 0; $i <= $to; $i++) {
5214 my %co = %{$commitlist[$i]};
5216 my $commit = $co{'id'};
5217 my $ref = format_ref_marker
($refs, $commit);
5218 my %ad = parse_date
($co{'author_epoch'});
5219 git_print_header_div
('commit',
5220 "<span class=\"age\">$co{'age_string'}</span>" .
5221 esc_html
($co{'title'}) . $ref,
5223 print "<div class=\"title_text\">\n" .
5224 "<div class=\"log_link\">\n" .
5225 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
5227 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
5229 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
5232 git_print_authorship
(\
%co, -tag
=> 'span');
5233 print "<br/>\n</div>\n";
5235 print "<div class=\"log_body\">\n";
5236 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
5239 if ($#commitlist >= 100) {
5240 print "<div class=\"page_nav\">\n";
5241 print $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5242 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5249 $hash ||= $hash_base || "HEAD";
5250 my %co = parse_commit
($hash)
5251 or die_error
(404, "Unknown commit object");
5253 my $parent = $co{'parent'};
5254 my $parents = $co{'parents'}; # listref
5256 # we need to prepare $formats_nav before any parameter munging
5258 if (!defined $parent) {
5260 $formats_nav .= '(initial)';
5261 } elsif (@$parents == 1) {
5262 # single parent commit
5265 $cgi->a({-href
=> href
(action
=>"commit",
5267 esc_html
(substr($parent, 0, 7))) .
5274 $cgi->a({-href
=> href
(action
=>"commit",
5276 esc_html
(substr($_, 0, 7)));
5280 if (gitweb_check_feature
('patches')) {
5281 $formats_nav .= " | " .
5282 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
5286 if (!defined $parent) {
5290 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
5292 (@$parents <= 1 ? $parent : '-c'),
5294 or die_error
(500, "Open git-diff-tree failed");
5295 @difftree = map { chomp; $_ } <$fd>;
5296 close $fd or die_error
(404, "Reading git-diff-tree failed");
5298 # non-textual hash id's can be cached
5300 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5303 my $refs = git_get_references
();
5304 my $ref = format_ref_marker
($refs, $co{'id'});
5306 git_header_html
(undef, $expires);
5307 git_print_page_nav
('commit', '',
5308 $hash, $co{'tree'}, $hash,
5311 if (defined $co{'parent'}) {
5312 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
5314 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
5316 print "<div class=\"title_text\">\n" .
5317 "<table class=\"object_header\">\n";
5318 git_print_authorship_rows
(\
%co);
5319 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
5322 "<td class=\"sha1\">" .
5323 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
5324 class => "list"}, $co{'tree'}) .
5326 "<td class=\"link\">" .
5327 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
5329 my $snapshot_links = format_snapshot_links
($hash);
5330 if (defined $snapshot_links) {
5331 print " | " . $snapshot_links;
5336 foreach my $par (@$parents) {
5339 "<td class=\"sha1\">" .
5340 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
5341 class => "list"}, $par) .
5343 "<td class=\"link\">" .
5344 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
5346 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
5353 print "<div class=\"page_body\">\n";
5354 git_print_log
($co{'comment'});
5357 git_difftree_body
(\
@difftree, $hash, @$parents);
5363 # object is defined by:
5364 # - hash or hash_base alone
5365 # - hash_base and file_name
5368 # - hash or hash_base alone
5369 if ($hash || ($hash_base && !defined $file_name)) {
5370 my $object_id = $hash || $hash_base;
5372 open my $fd, "-|", quote_command
(
5373 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
5374 or die_error
(404, "Object does not exist");
5378 or die_error
(404, "Object does not exist");
5380 # - hash_base and file_name
5381 } elsif ($hash_base && defined $file_name) {
5382 $file_name =~ s
,/+$,,;
5384 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
5385 or die_error
(404, "Base object does not exist");
5387 # here errors should not hapen
5388 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
5389 or die_error
(500, "Open git-ls-tree failed");
5393 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
5394 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
5395 die_error
(404, "File or directory for given base does not exist");
5400 die_error
(400, "Not enough information to find object");
5403 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
5404 hash
=>$hash, hash_base
=>$hash_base,
5405 file_name
=>$file_name),
5406 -status
=> '302 Found');
5410 my $format = shift || 'html';
5417 # preparing $fd and %diffinfo for git_patchset_body
5419 if (defined $hash_base && defined $hash_parent_base) {
5420 if (defined $file_name) {
5422 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5423 $hash_parent_base, $hash_base,
5424 "--", (defined $file_parent ? $file_parent : ()), $file_name
5425 or die_error
(500, "Open git-diff-tree failed");
5426 @difftree = map { chomp; $_ } <$fd>;
5428 or die_error
(404, "Reading git-diff-tree failed");
5430 or die_error
(404, "Blob diff not found");
5432 } elsif (defined $hash &&
5433 $hash =~ /[0-9a-fA-F]{40}/) {
5434 # try to find filename from $hash
5436 # read filtered raw output
5437 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5438 $hash_parent_base, $hash_base, "--"
5439 or die_error
(500, "Open git-diff-tree failed");
5441 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
5443 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
5444 map { chomp; $_ } <$fd>;
5446 or die_error
(404, "Reading git-diff-tree failed");
5448 or die_error
(404, "Blob diff not found");
5451 die_error
(400, "Missing one of the blob diff parameters");
5454 if (@difftree > 1) {
5455 die_error
(400, "Ambiguous blob diff specification");
5458 %diffinfo = parse_difftree_raw_line
($difftree[0]);
5459 $file_parent ||= $diffinfo{'from_file'} || $file_name;
5460 $file_name ||= $diffinfo{'to_file'};
5462 $hash_parent ||= $diffinfo{'from_id'};
5463 $hash ||= $diffinfo{'to_id'};
5465 # non-textual hash id's can be cached
5466 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
5467 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
5472 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5473 '-p', ($format eq 'html' ? "--full-index" : ()),
5474 $hash_parent_base, $hash_base,
5475 "--", (defined $file_parent ? $file_parent : ()), $file_name
5476 or die_error
(500, "Open git-diff-tree failed");
5479 # old/legacy style URI -- not generated anymore since 1.4.3.
5481 die_error
('404 Not Found', "Missing one of the blob diff parameters")
5485 if ($format eq 'html') {
5487 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
5489 git_header_html
(undef, $expires);
5490 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5491 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5492 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5494 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
5495 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
5497 if (defined $file_name) {
5498 git_print_page_path
($file_name, "blob", $hash_base);
5500 print "<div class=\"page_path\"></div>\n";
5503 } elsif ($format eq 'plain') {
5505 -type
=> 'text/plain',
5506 -charset
=> 'utf-8',
5507 -expires
=> $expires,
5508 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
5510 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5513 die_error
(400, "Unknown blobdiff format");
5517 if ($format eq 'html') {
5518 print "<div class=\"page_body\">\n";
5520 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
5523 print "</div>\n"; # class="page_body"
5527 while (my $line = <$fd>) {
5528 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
5529 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
5533 last if $line =~ m!^\+\+\+!;
5541 sub git_blobdiff_plain
{
5542 git_blobdiff
('plain');
5545 sub git_commitdiff
{
5547 my $format = $params{-format
} || 'html';
5549 my ($patch_max) = gitweb_get_feature
('patches');
5550 if ($format eq 'patch') {
5551 die_error
(403, "Patch view not allowed") unless $patch_max;
5554 $hash ||= $hash_base || "HEAD";
5555 my %co = parse_commit
($hash)
5556 or die_error
(404, "Unknown commit object");
5558 # choose format for commitdiff for merge
5559 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
5560 $hash_parent = '--cc';
5562 # we need to prepare $formats_nav before almost any parameter munging
5564 if ($format eq 'html') {
5566 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
5569 $formats_nav .= " | " .
5570 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
5574 if (defined $hash_parent &&
5575 $hash_parent ne '-c' && $hash_parent ne '--cc') {
5576 # commitdiff with two commits given
5577 my $hash_parent_short = $hash_parent;
5578 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5579 $hash_parent_short = substr($hash_parent, 0, 7);
5583 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
5584 if ($co{'parents'}[$i] eq $hash_parent) {
5585 $formats_nav .= ' parent ' . ($i+1);
5589 $formats_nav .= ': ' .
5590 $cgi->a({-href
=> href
(action
=>"commitdiff",
5591 hash
=>$hash_parent)},
5592 esc_html
($hash_parent_short)) .
5594 } elsif (!$co{'parent'}) {
5596 $formats_nav .= ' (initial)';
5597 } elsif (scalar @{$co{'parents'}} == 1) {
5598 # single parent commit
5601 $cgi->a({-href
=> href
(action
=>"commitdiff",
5602 hash
=>$co{'parent'})},
5603 esc_html
(substr($co{'parent'}, 0, 7))) .
5607 if ($hash_parent eq '--cc') {
5608 $formats_nav .= ' | ' .
5609 $cgi->a({-href
=> href
(action
=>"commitdiff",
5610 hash
=>$hash, hash_parent
=>'-c')},
5612 } else { # $hash_parent eq '-c'
5613 $formats_nav .= ' | ' .
5614 $cgi->a({-href
=> href
(action
=>"commitdiff",
5615 hash
=>$hash, hash_parent
=>'--cc')},
5621 $cgi->a({-href
=> href
(action
=>"commitdiff",
5623 esc_html
(substr($_, 0, 7)));
5624 } @{$co{'parents'}} ) .
5629 my $hash_parent_param = $hash_parent;
5630 if (!defined $hash_parent_param) {
5631 # --cc for multiple parents, --root for parentless
5632 $hash_parent_param =
5633 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
5639 if ($format eq 'html') {
5640 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5641 "--no-commit-id", "--patch-with-raw", "--full-index",
5642 $hash_parent_param, $hash, "--"
5643 or die_error
(500, "Open git-diff-tree failed");
5645 while (my $line = <$fd>) {
5647 # empty line ends raw part of diff-tree output
5649 push @difftree, scalar parse_difftree_raw_line
($line);
5652 } elsif ($format eq 'plain') {
5653 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5654 '-p', $hash_parent_param, $hash, "--"
5655 or die_error
(500, "Open git-diff-tree failed");
5656 } elsif ($format eq 'patch') {
5657 # For commit ranges, we limit the output to the number of
5658 # patches specified in the 'patches' feature.
5659 # For single commits, we limit the output to a single patch,
5660 # diverging from the git-format-patch default.
5661 my @commit_spec = ();
5663 if ($patch_max > 0) {
5664 push @commit_spec, "-$patch_max";
5666 push @commit_spec, '-n', "$hash_parent..$hash";
5668 if ($params{-single
}) {
5669 push @commit_spec, '-1';
5671 if ($patch_max > 0) {
5672 push @commit_spec, "-$patch_max";
5674 push @commit_spec, "-n";
5676 push @commit_spec, '--root', $hash;
5678 open $fd, "-|", git_cmd
(), "format-patch", '--encoding=utf8',
5679 '--stdout', @commit_spec
5680 or die_error
(500, "Open git-format-patch failed");
5682 die_error
(400, "Unknown commitdiff format");
5685 # non-textual hash id's can be cached
5687 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5691 # write commit message
5692 if ($format eq 'html') {
5693 my $refs = git_get_references
();
5694 my $ref = format_ref_marker
($refs, $co{'id'});
5696 git_header_html
(undef, $expires);
5697 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5698 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
5699 print "<div class=\"title_text\">\n" .
5700 "<table class=\"object_header\">\n";
5701 git_print_authorship_rows
(\
%co);
5704 print "<div class=\"page_body\">\n";
5705 if (@{$co{'comment'}} > 1) {
5706 print "<div class=\"log\">\n";
5707 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
5708 print "</div>\n"; # class="log"
5711 } elsif ($format eq 'plain') {
5712 my $refs = git_get_references
("tags");
5713 my $tagname = git_get_rev_name_tags
($hash);
5714 my $filename = basename
($project) . "-$hash.patch";
5717 -type
=> 'text/plain',
5718 -charset
=> 'utf-8',
5719 -expires
=> $expires,
5720 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5721 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5722 print "From: " . to_utf8
($co{'author'}) . "\n";
5723 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5724 print "Subject: " . to_utf8
($co{'title'}) . "\n";
5726 print "X-Git-Tag: $tagname\n" if $tagname;
5727 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5729 foreach my $line (@{$co{'comment'}}) {
5730 print to_utf8
($line) . "\n";
5733 } elsif ($format eq 'patch') {
5734 my $filename = basename
($project) . "-$hash.patch";
5737 -type
=> 'text/plain',
5738 -charset
=> 'utf-8',
5739 -expires
=> $expires,
5740 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5744 if ($format eq 'html') {
5745 my $use_parents = !defined $hash_parent ||
5746 $hash_parent eq '-c' || $hash_parent eq '--cc';
5747 git_difftree_body
(\
@difftree, $hash,
5748 $use_parents ? @{$co{'parents'}} : $hash_parent);
5751 git_patchset_body
($fd, \
@difftree, $hash,
5752 $use_parents ? @{$co{'parents'}} : $hash_parent);
5754 print "</div>\n"; # class="page_body"
5757 } elsif ($format eq 'plain') {
5761 or print "Reading git-diff-tree failed\n";
5762 } elsif ($format eq 'patch') {
5766 or print "Reading git-format-patch failed\n";
5770 sub git_commitdiff_plain
{
5771 git_commitdiff
(-format
=> 'plain');
5774 # format-patch-style patches
5776 git_commitdiff
(-format
=> 'patch', -single
=> 1);
5780 git_commitdiff
(-format
=> 'patch');
5784 if (!defined $hash_base) {
5785 $hash_base = git_get_head_hash
($project);
5787 if (!defined $page) {
5791 my %co = parse_commit
($hash_base)
5792 or die_error
(404, "Unknown commit object");
5794 my $refs = git_get_references
();
5795 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5797 my @commitlist = parse_commits
($hash_base, 101, (100 * $page),
5798 $file_name, "--full-history")
5799 or die_error
(404, "No such file or directory on given branch");
5801 if (!defined $hash && defined $file_name) {
5802 # some commits could have deleted file in question,
5803 # and not have it in tree, but one of them has to have it
5804 for (my $i = 0; $i <= @commitlist; $i++) {
5805 $hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
5806 last if defined $hash;
5809 if (defined $hash) {
5810 $ftype = git_get_type
($hash);
5812 if (!defined $ftype) {
5813 die_error
(500, "Unknown type of object");
5816 my $paging_nav = '';
5819 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5820 file_name
=>$file_name)},
5822 $paging_nav .= " ⋅ " .
5823 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5824 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5826 $paging_nav .= "first";
5827 $paging_nav .= " ⋅ prev";
5830 if ($#commitlist >= 100) {
5832 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5833 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5834 $paging_nav .= " ⋅ $next_link";
5836 $paging_nav .= " ⋅ next";
5840 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5841 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5842 git_print_page_path
($file_name, $ftype, $hash_base);
5844 git_history_body
(\
@commitlist, 0, 99,
5845 $refs, $hash_base, $ftype, $next_link);
5851 gitweb_check_feature
('search') or die_error
(403, "Search is disabled");
5852 if (!defined $searchtext) {
5853 die_error
(400, "Text field is empty");
5855 if (!defined $hash) {
5856 $hash = git_get_head_hash
($project);
5858 my %co = parse_commit
($hash);
5860 die_error
(404, "Unknown commit object");
5862 if (!defined $page) {
5866 $searchtype ||= 'commit';
5867 if ($searchtype eq 'pickaxe') {
5868 # pickaxe may take all resources of your box and run for several minutes
5869 # with every query - so decide by yourself how public you make this feature
5870 gitweb_check_feature
('pickaxe')
5871 or die_error
(403, "Pickaxe is disabled");
5873 if ($searchtype eq 'grep') {
5874 gitweb_check_feature
('grep')[0]
5875 or die_error
(403, "Grep is disabled");
5880 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5882 if ($searchtype eq 'commit') {
5883 $greptype = "--grep=";
5884 } elsif ($searchtype eq 'author') {
5885 $greptype = "--author=";
5886 } elsif ($searchtype eq 'committer') {
5887 $greptype = "--committer=";
5889 $greptype .= $searchtext;
5890 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
5891 $greptype, '--regexp-ignore-case',
5892 $search_use_regexp ? '--extended-regexp' : '--fixed-strings');
5894 my $paging_nav = '';
5897 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5898 searchtext
=>$searchtext,
5899 searchtype
=>$searchtype)},
5901 $paging_nav .= " ⋅ " .
5902 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5903 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5905 $paging_nav .= "first";
5906 $paging_nav .= " ⋅ prev";
5909 if ($#commitlist >= 100) {
5911 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5912 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5913 $paging_nav .= " ⋅ $next_link";
5915 $paging_nav .= " ⋅ next";
5918 if ($#commitlist >= 100) {
5921 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5922 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5923 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5926 if ($searchtype eq 'pickaxe') {
5927 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5928 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5930 print "<table class=\"pickaxe search\">\n";
5933 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
5934 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
5935 ($search_use_regexp ? '--pickaxe-regex' : ());
5938 while (my $line = <$fd>) {
5942 my %set = parse_difftree_raw_line
($line);
5943 if (defined $set{'commit'}) {
5944 # finish previous commit
5947 "<td class=\"link\">" .
5948 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5950 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5956 print "<tr class=\"dark\">\n";
5958 print "<tr class=\"light\">\n";
5961 %co = parse_commit
($set{'commit'});
5962 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
5963 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5964 "<td><i>$author</i></td>\n" .
5966 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5967 -class => "list subject"},
5968 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
5969 } elsif (defined $set{'to_id'}) {
5970 next if ($set{'to_id'} =~ m/^0{40}$/);
5972 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5973 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
5975 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5981 # finish last commit (warning: repetition!)
5984 "<td class=\"link\">" .
5985 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5987 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5995 if ($searchtype eq 'grep') {
5996 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5997 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5999 print "<table class=\"grep_search\">\n";
6003 open my $fd, "-|", git_cmd
(), 'grep', '-n',
6004 $search_use_regexp ? ('-E', '-i') : '-F',
6005 $searchtext, $co{'tree'};
6007 while (my $line = <$fd>) {
6009 my ($file, $lno, $ltext, $binary);
6010 last if ($matches++ > 1000);
6011 if ($line =~ /^Binary file (.+) matches$/) {
6015 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
6017 if ($file ne $lastfile) {
6018 $lastfile and print "</td></tr>\n";
6020 print "<tr class=\"dark\">\n";
6022 print "<tr class=\"light\">\n";
6024 print "<td class=\"list\">".
6025 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6026 file_name
=>"$file"),
6027 -class => "list"}, esc_path
($file));
6028 print "</td><td>\n";
6032 print "<div class=\"binary\">Binary file</div>\n";
6034 $ltext = untabify
($ltext);
6035 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
6036 $ltext = esc_html
($1, -nbsp
=>1);
6037 $ltext .= '<span class="match">';
6038 $ltext .= esc_html
($2, -nbsp
=>1);
6039 $ltext .= '</span>';
6040 $ltext .= esc_html
($3, -nbsp
=>1);
6042 $ltext = esc_html
($ltext, -nbsp
=>1);
6044 print "<div class=\"pre\">" .
6045 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6046 file_name
=>"$file").'#l'.$lno,
6047 -class => "linenr"}, sprintf('%4i', $lno))
6048 . ' ' . $ltext . "</div>\n";
6052 print "</td></tr>\n";
6053 if ($matches > 1000) {
6054 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
6057 print "<div class=\"diff nodifferences\">No matches found</div>\n";
6066 sub git_search_help
{
6068 git_print_page_nav
('','', $hash,$hash,$hash);
6070 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
6071 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
6072 the pattern entered is recognized as the POSIX extended
6073 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
6076 <dt><b>commit</b></dt>
6077 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
6079 my $have_grep = gitweb_check_feature
('grep');
6082 <dt><b>grep</b></dt>
6083 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
6084 a different one) are searched for the given pattern. On large trees, this search can take
6085 a while and put some strain on the server, so please use it with some consideration. Note that
6086 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
6087 case-sensitive.</dd>
6091 <dt><b>author</b></dt>
6092 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
6093 <dt><b>committer</b></dt>
6094 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
6096 my $have_pickaxe = gitweb_check_feature
('pickaxe');
6097 if ($have_pickaxe) {
6099 <dt><b>pickaxe</b></dt>
6100 <dd>All commits that caused the string to appear or disappear from any file (changes that
6101 added, removed or "modified" the string) will be listed. This search can take a while and
6102 takes a lot of strain on the server, so please use it wisely. Note that since you may be
6103 interested even in changes just changing the case as well, this search is case sensitive.</dd>
6111 my $head = git_get_head_hash
($project);
6112 if (!defined $hash) {
6115 if (!defined $page) {
6118 my $refs = git_get_references
();
6120 my $commit_hash = $hash;
6121 if (defined $hash_parent) {
6122 $commit_hash = "$hash_parent..$hash";
6124 my @commitlist = parse_commits
($commit_hash, 101, (100 * $page));
6126 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#commitlist >= 100);
6128 if ($#commitlist >= 100) {
6130 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
6131 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
6133 my $patch_max = gitweb_check_feature
('patches');
6135 if ($patch_max < 0 || @commitlist <= $patch_max) {
6136 $paging_nav .= " ⋅ " .
6137 $cgi->a({-href
=> href
(action
=>"patches", -replay
=>1)},
6143 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
6144 git_print_header_div
('summary', $project);
6146 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
6151 ## ......................................................................
6152 ## feeds (RSS, Atom; OPML)
6155 my $format = shift || 'atom';
6156 my $have_blame = gitweb_check_feature
('blame');
6158 # Atom: http://www.atomenabled.org/developers/syndication/
6159 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
6160 if ($format ne 'rss' && $format ne 'atom') {
6161 die_error
(400, "Unknown web feed format");
6164 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
6165 my $head = $hash || 'HEAD';
6166 my @commitlist = parse_commits
($head, 150, 0, $file_name);
6170 my $content_type = "application/$format+xml";
6171 if (defined $cgi->http('HTTP_ACCEPT') &&
6172 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
6173 # browser (feed reader) prefers text/xml
6174 $content_type = 'text/xml';
6176 if (defined($commitlist[0])) {
6177 %latest_commit = %{$commitlist[0]};
6178 my $latest_epoch = $latest_commit{'committer_epoch'};
6179 %latest_date = parse_date
($latest_epoch);
6180 my $if_modified = $cgi->http('IF_MODIFIED_SINCE');
6181 if (defined $if_modified) {
6183 if (eval { require HTTP
::Date
; 1; }) {
6184 $since = HTTP
::Date
::str2time
($if_modified);
6185 } elsif (eval { require Time
::ParseDate
; 1; }) {
6186 $since = Time
::ParseDate
::parsedate
($if_modified, GMT
=> 1);
6188 if (defined $since && $latest_epoch <= $since) {
6190 -type
=> $content_type,
6191 -charset
=> 'utf-8',
6192 -last_modified
=> $latest_date{'rfc2822'},
6193 -status
=> '304 Not Modified');
6198 -type
=> $content_type,
6199 -charset
=> 'utf-8',
6200 -last_modified
=> $latest_date{'rfc2822'});
6203 -type
=> $content_type,
6204 -charset
=> 'utf-8');
6207 # Optimization: skip generating the body if client asks only
6208 # for Last-Modified date.
6209 return if ($cgi->request_method() eq 'HEAD');
6212 my $title = "$site_name - $project/$action";
6213 my $feed_type = 'log';
6214 if (defined $hash) {
6215 $title .= " - '$hash'";
6216 $feed_type = 'branch log';
6217 if (defined $file_name) {
6218 $title .= " :: $file_name";
6219 $feed_type = 'history';
6221 } elsif (defined $file_name) {
6222 $title .= " - $file_name";
6223 $feed_type = 'history';
6225 $title .= " $feed_type";
6226 my $descr = git_get_project_description
($project);
6227 if (defined $descr) {
6228 $descr = esc_html
($descr);
6230 $descr = "$project " .
6231 ($format eq 'rss' ? 'RSS' : 'Atom') .
6234 my $owner = git_get_project_owner
($project);
6235 $owner = esc_html
($owner);
6239 if (defined $file_name) {
6240 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
6241 } elsif (defined $hash) {
6242 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
6244 $alt_url = href
(-full
=>1, action
=>"summary");
6246 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
6247 if ($format eq 'rss') {
6249 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
6252 print "<title>$title</title>\n" .
6253 "<link>$alt_url</link>\n" .
6254 "<description>$descr</description>\n" .
6255 "<language>en</language>\n" .
6256 # project owner is responsible for 'editorial' content
6257 "<managingEditor>$owner</managingEditor>\n";
6258 if (defined $logo || defined $favicon) {
6259 # prefer the logo to the favicon, since RSS
6260 # doesn't allow both
6261 my $img = esc_url
($logo || $favicon);
6263 "<url>$img</url>\n" .
6264 "<title>$title</title>\n" .
6265 "<link>$alt_url</link>\n" .
6269 print "<pubDate>$latest_date{'rfc2822'}</pubDate>\n";
6270 print "<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";
6272 print "<generator>gitweb v.$version/$git_version</generator>\n";
6273 } elsif ($format eq 'atom') {
6275 <feed xmlns="http://www.w3.org/2005/Atom">
6277 print "<title>$title</title>\n" .
6278 "<subtitle>$descr</subtitle>\n" .
6279 '<link rel="alternate" type="text/html" href="' .
6280 $alt_url . '" />' . "\n" .
6281 '<link rel="self" type="' . $content_type . '" href="' .
6282 $cgi->self_url() . '" />' . "\n" .
6283 "<id>" . href
(-full
=>1) . "</id>\n" .
6284 # use project owner for feed author
6285 "<author><name>$owner</name></author>\n";
6286 if (defined $favicon) {
6287 print "<icon>" . esc_url
($favicon) . "</icon>\n";
6289 if (defined $logo_url) {
6290 # not twice as wide as tall: 72 x 27 pixels
6291 print "<logo>" . esc_url
($logo) . "</logo>\n";
6293 if (! %latest_date) {
6294 # dummy date to keep the feed valid until commits trickle in:
6295 print "<updated>1970-01-01T00:00:00Z</updated>\n";
6297 print "<updated>$latest_date{'iso-8601'}</updated>\n";
6299 print "<generator version='$version/$git_version'>gitweb</generator>\n";
6303 for (my $i = 0; $i <= $#commitlist; $i++) {
6304 my %co = %{$commitlist[$i]};
6305 my $commit = $co{'id'};
6306 # we read 150, we always show 30 and the ones more recent than 48 hours
6307 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
6310 my %cd = parse_date
($co{'author_epoch'});
6312 # get list of changed files
6313 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6314 $co{'parent'} || "--root",
6315 $co{'id'}, "--", (defined $file_name ? $file_name : ())
6317 my @difftree = map { chomp; $_ } <$fd>;
6321 # print element (entry, item)
6322 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
6323 if ($format eq 'rss') {
6325 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
6326 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
6327 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
6328 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
6329 "<link>$co_url</link>\n" .
6330 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
6331 "<content:encoded>" .
6333 } elsif ($format eq 'atom') {
6335 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
6336 "<updated>$cd{'iso-8601'}</updated>\n" .
6338 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
6339 if ($co{'author_email'}) {
6340 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
6342 print "</author>\n" .
6343 # use committer for contributor
6345 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
6346 if ($co{'committer_email'}) {
6347 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
6349 print "</contributor>\n" .
6350 "<published>$cd{'iso-8601'}</published>\n" .
6351 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
6352 "<id>$co_url</id>\n" .
6353 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
6354 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
6356 my $comment = $co{'comment'};
6358 foreach my $line (@$comment) {
6359 $line = esc_html
($line);
6362 print "</pre><ul>\n";
6363 foreach my $difftree_line (@difftree) {
6364 my %difftree = parse_difftree_raw_line
($difftree_line);
6365 next if !$difftree{'from_id'};
6367 my $file = $difftree{'file'} || $difftree{'to_file'};
6371 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
6372 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
6373 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
6374 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
6375 -title
=> "diff"}, 'D');
6377 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
6378 file_name
=>$file, hash_base
=>$commit),
6379 -title
=> "blame"}, 'B');
6381 # if this is not a feed of a file history
6382 if (!defined $file_name || $file_name ne $file) {
6383 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
6384 file_name
=>$file, hash
=>$commit),
6385 -title
=> "history"}, 'H');
6387 $file = esc_path
($file);
6391 if ($format eq 'rss') {
6392 print "</ul>]]>\n" .
6393 "</content:encoded>\n" .
6395 } elsif ($format eq 'atom') {
6396 print "</ul>\n</div>\n" .
6403 if ($format eq 'rss') {
6404 print "</channel>\n</rss>\n";
6405 } elsif ($format eq 'atom') {
6419 my @list = git_get_projects_list
();
6422 -type
=> 'text/xml',
6423 -charset
=> 'utf-8',
6424 -content_disposition
=> 'inline; filename="opml.xml"');
6427 <?xml version="1.0" encoding="utf-8"?>
6428 <opml version="1.0">
6430 <title>$site_name OPML Export</title>
6433 <outline text="git RSS feeds">
6436 foreach my $pr (@list) {
6438 my $head = git_get_head_hash
($proj{'path'});
6439 if (!defined $head) {
6442 $git_dir = "$projectroot/$proj{'path'}";
6443 my %co = parse_commit
($head);
6448 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
6449 my $rss = href
('project' => $proj{'path'}, 'action' => 'rss', -full
=> 1);
6450 my $html = href
('project' => $proj{'path'}, 'action' => 'summary', -full
=> 1);
6451 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";