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 # Insert an avatar for the given $email at the given $size if the feature
1518 sub git_get_avatar
{
1519 my ($email, %opts) = @_;
1520 my $pre_white = ($opts{-pad_before
} ? " " : "");
1521 my $post_white = ($opts{-pad_after
} ? " " : "");
1522 $opts{-size
} ||= 'default';
1523 my $size = $avatar_size{$opts{-size
}} || $avatar_size{'default'};
1525 if ($git_avatar eq 'gravatar') {
1526 $url = "http://www.gravatar.com/avatar/" .
1527 Digest
::MD5
::md5_hex
(lc $email) . "?s=$size";
1529 # Currently only gravatars are supported, but other forms such as
1530 # picons can be added by putting an else up here and defining $url
1531 # as needed. If no variant puts something in $url, we assume avatars
1532 # are completely disabled/unavailable.
1535 "<img width=\"$size\" " .
1536 "class=\"avatar\" " .
1544 # format the author name of the given commit with the given tag
1545 # the author name is chopped and escaped according to the other
1546 # optional parameters (see chop_str).
1547 sub format_author_html
{
1550 my $author = chop_and_escape_str
($co->{'author_name'}, @_);
1551 return "<$tag class=\"author\">" .
1552 git_get_avatar
($co->{'author_email'}, -pad_after
=> 1) .
1553 $author . "</$tag>";
1556 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1557 sub format_git_diff_header_line
{
1559 my $diffinfo = shift;
1560 my ($from, $to) = @_;
1562 if ($diffinfo->{'nparents'}) {
1564 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1565 if ($to->{'href'}) {
1566 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1567 esc_path
($to->{'file'}));
1568 } else { # file was deleted (no href)
1569 $line .= esc_path
($to->{'file'});
1573 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1574 if ($from->{'href'}) {
1575 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1576 'a/' . esc_path
($from->{'file'}));
1577 } else { # file was added (no href)
1578 $line .= 'a/' . esc_path
($from->{'file'});
1581 if ($to->{'href'}) {
1582 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1583 'b/' . esc_path
($to->{'file'}));
1584 } else { # file was deleted
1585 $line .= 'b/' . esc_path
($to->{'file'});
1589 return "<div class=\"diff header\">$line</div>\n";
1592 # format extended diff header line, before patch itself
1593 sub format_extended_diff_header_line
{
1595 my $diffinfo = shift;
1596 my ($from, $to) = @_;
1599 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1600 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1601 esc_path
($from->{'file'}));
1603 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1604 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1605 esc_path
($to->{'file'}));
1607 # match single <mode>
1608 if ($line =~ m/\s(\d{6})$/) {
1609 $line .= '<span class="info"> (' .
1610 file_type_long
($1) .
1614 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1615 # can match only for combined diff
1617 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1618 if ($from->{'href'}[$i]) {
1619 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1621 substr($diffinfo->{'from_id'}[$i],0,7));
1626 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1629 if ($to->{'href'}) {
1630 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1631 substr($diffinfo->{'to_id'},0,7));
1636 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1637 # can match only for ordinary diff
1638 my ($from_link, $to_link);
1639 if ($from->{'href'}) {
1640 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1641 substr($diffinfo->{'from_id'},0,7));
1643 $from_link = '0' x
7;
1645 if ($to->{'href'}) {
1646 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1647 substr($diffinfo->{'to_id'},0,7));
1651 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1652 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1655 return $line . "<br/>\n";
1658 # format from-file/to-file diff header
1659 sub format_diff_from_to_header
{
1660 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1665 #assert($line =~ m/^---/) if DEBUG;
1666 # no extra formatting for "^--- /dev/null"
1667 if (! $diffinfo->{'nparents'}) {
1668 # ordinary (single parent) diff
1669 if ($line =~ m!^--- "?a/!) {
1670 if ($from->{'href'}) {
1672 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1673 esc_path
($from->{'file'}));
1676 esc_path
($from->{'file'});
1679 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1682 # combined diff (merge commit)
1683 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1684 if ($from->{'href'}[$i]) {
1686 $cgi->a({-href
=>href
(action
=>"blobdiff",
1687 hash_parent
=>$diffinfo->{'from_id'}[$i],
1688 hash_parent_base
=>$parents[$i],
1689 file_parent
=>$from->{'file'}[$i],
1690 hash
=>$diffinfo->{'to_id'},
1692 file_name
=>$to->{'file'}),
1694 -title
=>"diff" . ($i+1)},
1697 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1698 esc_path
($from->{'file'}[$i]));
1700 $line = '--- /dev/null';
1702 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1707 #assert($line =~ m/^\+\+\+/) if DEBUG;
1708 # no extra formatting for "^+++ /dev/null"
1709 if ($line =~ m!^\+\+\+ "?b/!) {
1710 if ($to->{'href'}) {
1712 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1713 esc_path
($to->{'file'}));
1716 esc_path
($to->{'file'});
1719 $result .= qq
!<div
class="diff to_file">$line</div
>\n!;
1724 # create note for patch simplified by combined diff
1725 sub format_diff_cc_simplified
{
1726 my ($diffinfo, @parents) = @_;
1729 $result .= "<div class=\"diff header\">" .
1731 if (!is_deleted
($diffinfo)) {
1732 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1734 hash
=>$diffinfo->{'to_id'},
1735 file_name
=>$diffinfo->{'to_file'}),
1737 esc_path
($diffinfo->{'to_file'}));
1739 $result .= esc_path
($diffinfo->{'to_file'});
1741 $result .= "</div>\n" . # class="diff header"
1742 "<div class=\"diff nodifferences\">" .
1744 "</div>\n"; # class="diff nodifferences"
1749 # format patch (diff) line (not to be used for diff headers)
1750 sub format_diff_line
{
1752 my ($from, $to) = @_;
1753 my $diff_class = "";
1757 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1759 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
1760 if ($line =~ m/^\@{3}/) {
1761 $diff_class = " chunk_header";
1762 } elsif ($line =~ m/^\\/) {
1763 $diff_class = " incomplete";
1764 } elsif ($prefix =~ tr/+/+/) {
1765 $diff_class = " add";
1766 } elsif ($prefix =~ tr/-/-/) {
1767 $diff_class = " rem";
1770 # assume ordinary diff
1771 my $char = substr($line, 0, 1);
1773 $diff_class = " add";
1774 } elsif ($char eq '-') {
1775 $diff_class = " rem";
1776 } elsif ($char eq '@') {
1777 $diff_class = " chunk_header";
1778 } elsif ($char eq "\\") {
1779 $diff_class = " incomplete";
1782 $line = untabify
($line);
1783 if ($from && $to && $line =~ m/^\@{2} /) {
1784 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1785 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1787 $from_lines = 0 unless defined $from_lines;
1788 $to_lines = 0 unless defined $to_lines;
1790 if ($from->{'href'}) {
1791 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1792 -class=>"list"}, $from_text);
1794 if ($to->{'href'}) {
1795 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1796 -class=>"list"}, $to_text);
1798 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1799 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1800 return "<div class=\"diff$diff_class\">$line</div>\n";
1801 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1802 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1803 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1805 @from_text = split(' ', $ranges);
1806 for (my $i = 0; $i < @from_text; ++$i) {
1807 ($from_start[$i], $from_nlines[$i]) =
1808 (split(',', substr($from_text[$i], 1)), 0);
1811 $to_text = pop @from_text;
1812 $to_start = pop @from_start;
1813 $to_nlines = pop @from_nlines;
1815 $line = "<span class=\"chunk_info\">$prefix ";
1816 for (my $i = 0; $i < @from_text; ++$i) {
1817 if ($from->{'href'}[$i]) {
1818 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1819 -class=>"list"}, $from_text[$i]);
1821 $line .= $from_text[$i];
1825 if ($to->{'href'}) {
1826 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1827 -class=>"list"}, $to_text);
1831 $line .= " $prefix</span>" .
1832 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1833 return "<div class=\"diff$diff_class\">$line</div>\n";
1835 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1838 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1839 # linked. Pass the hash of the tree/commit to snapshot.
1840 sub format_snapshot_links
{
1842 my $num_fmts = @snapshot_fmts;
1843 if ($num_fmts > 1) {
1844 # A parenthesized list of links bearing format names.
1845 # e.g. "snapshot (_tar.gz_ _zip_)"
1846 return "snapshot (" . join(' ', map
1853 }, $known_snapshot_formats{$_}{'display'})
1854 , @snapshot_fmts) . ")";
1855 } elsif ($num_fmts == 1) {
1856 # A single "snapshot" link whose tooltip bears the format name.
1858 my ($fmt) = @snapshot_fmts;
1864 snapshot_format
=>$fmt
1866 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1868 } else { # $num_fmts == 0
1873 ## ......................................................................
1874 ## functions returning values to be passed, perhaps after some
1875 ## transformation, to other functions; e.g. returning arguments to href()
1877 # returns hash to be passed to href to generate gitweb URL
1878 # in -title key it returns description of link
1880 my $format = shift || 'Atom';
1881 my %res = (action
=> lc($format));
1883 # feed links are possible only for project views
1884 return unless (defined $project);
1885 # some views should link to OPML, or to generic project feed,
1886 # or don't have specific feed yet (so they should use generic)
1887 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
1890 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
1891 # from tag links; this also makes possible to detect branch links
1892 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
1893 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
1896 # find log type for feed description (title)
1898 if (defined $file_name) {
1899 $type = "history of $file_name";
1900 $type .= "/" if ($action eq 'tree');
1901 $type .= " on '$branch'" if (defined $branch);
1903 $type = "log of $branch" if (defined $branch);
1906 $res{-title
} = $type;
1907 $res{'hash'} = (defined $branch ? "refs/heads/$branch" : undef);
1908 $res{'file_name'} = $file_name;
1913 ## ----------------------------------------------------------------------
1914 ## git utility subroutines, invoking git commands
1916 # returns path to the core git executable and the --git-dir parameter as list
1918 return $GIT, '--git-dir='.$git_dir;
1921 # quote the given arguments for passing them to the shell
1922 # quote_command("command", "arg 1", "arg with ' and ! characters")
1923 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
1924 # Try to avoid using this function wherever possible.
1927 map { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ );
1930 # get HEAD ref of given project as hash
1931 sub git_get_head_hash
{
1932 my $project = shift;
1933 my $o_git_dir = $git_dir;
1935 $git_dir = "$projectroot/$project";
1936 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1939 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1943 if (defined $o_git_dir) {
1944 $git_dir = $o_git_dir;
1949 # get type of given object
1953 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1955 close $fd or return;
1960 # repository configuration
1961 our $config_file = '';
1964 # store multiple values for single key as anonymous array reference
1965 # single values stored directly in the hash, not as [ <value> ]
1966 sub hash_set_multi
{
1967 my ($hash, $key, $value) = @_;
1969 if (!exists $hash->{$key}) {
1970 $hash->{$key} = $value;
1971 } elsif (!ref $hash->{$key}) {
1972 $hash->{$key} = [ $hash->{$key}, $value ];
1974 push @{$hash->{$key}}, $value;
1978 # return hash of git project configuration
1979 # optionally limited to some section, e.g. 'gitweb'
1980 sub git_parse_project_config
{
1981 my $section_regexp = shift;
1986 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
1989 while (my $keyval = <$fh>) {
1991 my ($key, $value) = split(/\n/, $keyval, 2);
1993 hash_set_multi
(\
%config, $key, $value)
1994 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
2001 # convert config value to boolean: 'true' or 'false'
2002 # no value, number > 0, 'true' and 'yes' values are true
2003 # rest of values are treated as false (never as error)
2004 sub config_to_bool
{
2007 return 1 if !defined $val; # section.key
2009 # strip leading and trailing whitespace
2013 return (($val =~ /^\d+$/ && $val) || # section.key = 1
2014 ($val =~ /^(?:true|yes)$/i)); # section.key = true
2017 # convert config value to simple decimal number
2018 # an optional value suffix of 'k', 'm', or 'g' will cause the value
2019 # to be multiplied by 1024, 1048576, or 1073741824
2023 # strip leading and trailing whitespace
2027 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
2029 # unknown unit is treated as 1
2030 return $num * ($unit eq 'g' ? 1073741824 :
2031 $unit eq 'm' ? 1048576 :
2032 $unit eq 'k' ? 1024 : 1);
2037 # convert config value to array reference, if needed
2038 sub config_to_multi
{
2041 return ref($val) ? $val : (defined($val) ? [ $val ] : []);
2044 sub git_get_project_config
{
2045 my ($key, $type) = @_;
2048 return unless ($key);
2049 $key =~ s/^gitweb\.//;
2050 return if ($key =~ m/\W/);
2053 if (defined $type) {
2056 unless ($type eq 'bool' || $type eq 'int');
2060 if (!defined $config_file ||
2061 $config_file ne "$git_dir/config") {
2062 %config = git_parse_project_config
('gitweb');
2063 $config_file = "$git_dir/config";
2066 # check if config variable (key) exists
2067 return unless exists $config{"gitweb.$key"};
2070 if (!defined $type) {
2071 return $config{"gitweb.$key"};
2072 } elsif ($type eq 'bool') {
2073 # backward compatibility: 'git config --bool' returns true/false
2074 return config_to_bool
($config{"gitweb.$key"}) ? 'true' : 'false';
2075 } elsif ($type eq 'int') {
2076 return config_to_int
($config{"gitweb.$key"});
2078 return $config{"gitweb.$key"};
2081 # get hash of given path at given ref
2082 sub git_get_hash_by_path
{
2084 my $path = shift || return undef;
2089 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
2090 or die_error
(500, "Open git-ls-tree failed");
2092 close $fd or return undef;
2094 if (!defined $line) {
2095 # there is no tree or hash given by $path at $base
2099 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2100 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
2101 if (defined $type && $type ne $2) {
2102 # type doesn't match
2108 # get path of entry with given hash at given tree-ish (ref)
2109 # used to get 'from' filename for combined diff (merge commit) for renames
2110 sub git_get_path_by_hash
{
2111 my $base = shift || return;
2112 my $hash = shift || return;
2116 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
2118 while (my $line = <$fd>) {
2121 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
2122 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
2123 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
2132 ## ......................................................................
2133 ## git utility functions, directly accessing git repository
2135 sub git_get_project_description
{
2138 $git_dir = "$projectroot/$path";
2139 open my $fd, '<', "$git_dir/description"
2140 or return git_get_project_config
('description');
2143 if (defined $descr) {
2149 sub git_get_project_ctags
{
2153 $git_dir = "$projectroot/$path";
2154 opendir my $dh, "$git_dir/ctags"
2156 foreach (grep { -f
$_ } map { "$git_dir/ctags/$_" } readdir($dh)) {
2157 open my $ct, '<', $_ or next;
2161 my $ctag = $_; $ctag =~ s
#.*/##;
2162 $ctags->{$ctag} = $val;
2168 sub git_populate_project_tagcloud
{
2171 # First, merge different-cased tags; tags vote on casing
2173 foreach (keys %$ctags) {
2174 $ctags_lc{lc $_}->{count
} += $ctags->{$_};
2175 if (not $ctags_lc{lc $_}->{topcount
}
2176 or $ctags_lc{lc $_}->{topcount
} < $ctags->{$_}) {
2177 $ctags_lc{lc $_}->{topcount
} = $ctags->{$_};
2178 $ctags_lc{lc $_}->{topname
} = $_;
2183 if (eval { require HTML
::TagCloud
; 1; }) {
2184 $cloud = HTML
::TagCloud-
>new;
2185 foreach (sort keys %ctags_lc) {
2186 # Pad the title with spaces so that the cloud looks
2188 my $title = $ctags_lc{$_}->{topname
};
2189 $title =~ s/ / /g;
2190 $title =~ s/^/ /g;
2191 $title =~ s/$/ /g;
2192 $cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count
});
2195 $cloud = \
%ctags_lc;
2200 sub git_show_project_tagcloud
{
2201 my ($cloud, $count) = @_;
2202 print STDERR
ref($cloud)."..\n";
2203 if (ref $cloud eq 'HTML::TagCloud') {
2204 return $cloud->html_and_css($count);
2206 my @tags = sort { $cloud->{$a}->{count
} <=> $cloud->{$b}->{count
} } keys %$cloud;
2207 return '<p align="center">' . join (', ', map {
2208 "<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"
2209 } splice(@tags, 0, $count)) . '</p>';
2213 sub git_get_project_url_list
{
2216 $git_dir = "$projectroot/$path";
2217 open my $fd, '<', "$git_dir/cloneurl"
2218 or return wantarray ?
2219 @{ config_to_multi
(git_get_project_config
('url')) } :
2220 config_to_multi
(git_get_project_config
('url'));
2221 my @git_project_url_list = map { chomp; $_ } <$fd>;
2224 return wantarray ? @git_project_url_list : \
@git_project_url_list;
2227 sub git_get_projects_list
{
2232 $filter =~ s/\.git$//;
2234 my $check_forks = gitweb_check_feature
('forks');
2236 if (-d
$projects_list) {
2237 # search in directory
2238 my $dir = $projects_list . ($filter ? "/$filter" : '');
2239 # remove the trailing "/"
2241 my $pfxlen = length("$dir");
2242 my $pfxdepth = ($dir =~ tr!/!!);
2245 follow_fast
=> 1, # follow symbolic links
2246 follow_skip
=> 2, # ignore duplicates
2247 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
2249 # skip project-list toplevel, if we get it.
2250 return if (m!^[/.]$!);
2251 # only directories can be git repositories
2252 return unless (-d
$_);
2253 # don't traverse too deep (Find is super slow on os x)
2254 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
2255 $File::Find
::prune
= 1;
2259 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
2260 # we check related file in $projectroot
2261 my $path = ($filter ? "$filter/" : '') . $subdir;
2262 if (check_export_ok
("$projectroot/$path")) {
2263 push @list, { path
=> $path };
2264 $File::Find
::prune
= 1;
2269 } elsif (-f
$projects_list) {
2270 # read from file(url-encoded):
2271 # 'git%2Fgit.git Linus+Torvalds'
2272 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2273 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2275 open my $fd, '<', $projects_list or return;
2277 while (my $line = <$fd>) {
2279 my ($path, $owner) = split ' ', $line;
2280 $path = unescape
($path);
2281 $owner = unescape
($owner);
2282 if (!defined $path) {
2285 if ($filter ne '') {
2286 # looking for forks;
2287 my $pfx = substr($path, 0, length($filter));
2288 if ($pfx ne $filter) {
2291 my $sfx = substr($path, length($filter));
2292 if ($sfx !~ /^\/.*\
.git
$/) {
2295 } elsif ($check_forks) {
2297 foreach my $filter (keys %paths) {
2298 # looking for forks;
2299 my $pfx = substr($path, 0, length($filter));
2300 if ($pfx ne $filter) {
2303 my $sfx = substr($path, length($filter));
2304 if ($sfx !~ /^\/.*\
.git
$/) {
2307 # is a fork, don't include it in
2312 if (check_export_ok
("$projectroot/$path")) {
2315 owner
=> to_utf8
($owner),
2318 (my $forks_path = $path) =~ s/\.git$//;
2319 $paths{$forks_path}++;
2327 our $gitweb_project_owner = undef;
2328 sub git_get_project_list_from_file
{
2330 return if (defined $gitweb_project_owner);
2332 $gitweb_project_owner = {};
2333 # read from file (url-encoded):
2334 # 'git%2Fgit.git Linus+Torvalds'
2335 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2336 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2337 if (-f
$projects_list) {
2338 open(my $fd, '<', $projects_list);
2339 while (my $line = <$fd>) {
2341 my ($pr, $ow) = split ' ', $line;
2342 $pr = unescape
($pr);
2343 $ow = unescape
($ow);
2344 $gitweb_project_owner->{$pr} = to_utf8
($ow);
2350 sub git_get_project_owner
{
2351 my $project = shift;
2354 return undef unless $project;
2355 $git_dir = "$projectroot/$project";
2357 if (!defined $gitweb_project_owner) {
2358 git_get_project_list_from_file
();
2361 if (exists $gitweb_project_owner->{$project}) {
2362 $owner = $gitweb_project_owner->{$project};
2364 if (!defined $owner){
2365 $owner = git_get_project_config
('owner');
2367 if (!defined $owner) {
2368 $owner = get_file_owner
("$git_dir");
2374 sub git_get_last_activity
{
2378 $git_dir = "$projectroot/$path";
2379 open($fd, "-|", git_cmd
(), 'for-each-ref',
2380 '--format=%(committer)',
2381 '--sort=-committerdate',
2383 'refs/heads') or return;
2384 my $most_recent = <$fd>;
2385 close $fd or return;
2386 if (defined $most_recent &&
2387 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
2389 my $age = time - $timestamp;
2390 return ($age, age_string
($age));
2392 return (undef, undef);
2395 sub git_get_references
{
2396 my $type = shift || "";
2398 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
2399 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
2400 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
2401 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
2404 while (my $line = <$fd>) {
2406 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
2407 if (defined $refs{$1}) {
2408 push @{$refs{$1}}, $2;
2414 close $fd or return;
2418 sub git_get_rev_name_tags
{
2419 my $hash = shift || return undef;
2421 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
2423 my $name_rev = <$fd>;
2426 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
2429 # catches also '$hash undefined' output
2434 ## ----------------------------------------------------------------------
2435 ## parse to hash functions
2439 my $tz = shift || "-0000";
2442 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
2443 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
2444 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
2445 $date{'hour'} = $hour;
2446 $date{'minute'} = $min;
2447 $date{'mday'} = $mday;
2448 $date{'day'} = $days[$wday];
2449 $date{'month'} = $months[$mon];
2450 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2451 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2452 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2453 $mday, $months[$mon], $hour ,$min;
2454 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2455 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2457 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2458 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2459 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2460 $date{'hour_local'} = $hour;
2461 $date{'minute_local'} = $min;
2462 $date{'tz_local'} = $tz;
2463 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2464 1900+$year, $mon+1, $mday,
2465 $hour, $min, $sec, $tz);
2474 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
2475 $tag{'id'} = $tag_id;
2476 while (my $line = <$fd>) {
2478 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2479 $tag{'object'} = $1;
2480 } elsif ($line =~ m/^type (.+)$/) {
2482 } elsif ($line =~ m/^tag (.+)$/) {
2484 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2485 $tag{'author'} = $1;
2486 $tag{'author_epoch'} = $2;
2487 $tag{'author_tz'} = $3;
2488 if ($tag{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2489 $tag{'author_name'} = $1;
2490 $tag{'author_email'} = $2;
2492 $tag{'author_name'} = $tag{'author'};
2494 } elsif ($line =~ m/--BEGIN/) {
2495 push @comment, $line;
2497 } elsif ($line eq "") {
2501 push @comment, <$fd>;
2502 $tag{'comment'} = \
@comment;
2503 close $fd or return;
2504 if (!defined $tag{'name'}) {
2510 sub parse_commit_text
{
2511 my ($commit_text, $withparents) = @_;
2512 my @commit_lines = split '\n', $commit_text;
2515 pop @commit_lines; # Remove '\0'
2517 if (! @commit_lines) {
2521 my $header = shift @commit_lines;
2522 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2525 ($co{'id'}, my @parents) = split ' ', $header;
2526 while (my $line = shift @commit_lines) {
2527 last if $line eq "\n";
2528 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2530 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2532 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2534 $co{'author_epoch'} = $2;
2535 $co{'author_tz'} = $3;
2536 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2537 $co{'author_name'} = $1;
2538 $co{'author_email'} = $2;
2540 $co{'author_name'} = $co{'author'};
2542 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2543 $co{'committer'} = $1;
2544 $co{'committer_epoch'} = $2;
2545 $co{'committer_tz'} = $3;
2546 $co{'committer_name'} = $co{'committer'};
2547 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2548 $co{'committer_name'} = $1;
2549 $co{'committer_email'} = $2;
2551 $co{'committer_name'} = $co{'committer'};
2555 if (!defined $co{'tree'}) {
2558 $co{'parents'} = \
@parents;
2559 $co{'parent'} = $parents[0];
2561 foreach my $title (@commit_lines) {
2564 $co{'title'} = chop_str
($title, 80, 5);
2565 # remove leading stuff of merges to make the interesting part visible
2566 if (length($title) > 50) {
2567 $title =~ s/^Automatic //;
2568 $title =~ s/^merge (of|with) /Merge ... /i;
2569 if (length($title) > 50) {
2570 $title =~ s/(http|rsync):\/\///;
2572 if (length($title) > 50) {
2573 $title =~ s/(master|www|rsync)\.//;
2575 if (length($title) > 50) {
2576 $title =~ s/kernel.org:?//;
2578 if (length($title) > 50) {
2579 $title =~ s/\/pub\/scm//;
2582 $co{'title_short'} = chop_str
($title, 50, 5);
2586 if (! defined $co{'title'} || $co{'title'} eq "") {
2587 $co{'title'} = $co{'title_short'} = '(no commit message)';
2589 # remove added spaces
2590 foreach my $line (@commit_lines) {
2593 $co{'comment'} = \
@commit_lines;
2595 my $age = time - $co{'committer_epoch'};
2597 $co{'age_string'} = age_string
($age);
2598 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2599 if ($age > 60*60*24*7*2) {
2600 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2601 $co{'age_string_age'} = $co{'age_string'};
2603 $co{'age_string_date'} = $co{'age_string'};
2604 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2610 my ($commit_id) = @_;
2615 open my $fd, "-|", git_cmd
(), "rev-list",
2621 or die_error
(500, "Open git-rev-list failed");
2622 %co = parse_commit_text
(<$fd>, 1);
2629 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2637 open my $fd, "-|", git_cmd
(), "rev-list",
2640 ("--max-count=" . $maxcount),
2641 ("--skip=" . $skip),
2645 ($filename ? ($filename) : ())
2646 or die_error
(500, "Open git-rev-list failed");
2647 while (my $line = <$fd>) {
2648 my %co = parse_commit_text
($line);
2653 return wantarray ? @cos : \
@cos;
2656 # parse line of git-diff-tree "raw" output
2657 sub parse_difftree_raw_line
{
2661 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2662 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2663 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2664 $res{'from_mode'} = $1;
2665 $res{'to_mode'} = $2;
2666 $res{'from_id'} = $3;
2668 $res{'status'} = $5;
2669 $res{'similarity'} = $6;
2670 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2671 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2673 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2676 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2677 # combined diff (for merge commit)
2678 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2679 $res{'nparents'} = length($1);
2680 $res{'from_mode'} = [ split(' ', $2) ];
2681 $res{'to_mode'} = pop @{$res{'from_mode'}};
2682 $res{'from_id'} = [ split(' ', $3) ];
2683 $res{'to_id'} = pop @{$res{'from_id'}};
2684 $res{'status'} = [ split('', $4) ];
2685 $res{'to_file'} = unquote
($5);
2687 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2688 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2689 $res{'commit'} = $1;
2692 return wantarray ? %res : \
%res;
2695 # wrapper: return parsed line of git-diff-tree "raw" output
2696 # (the argument might be raw line, or parsed info)
2697 sub parsed_difftree_line
{
2698 my $line_or_ref = shift;
2700 if (ref($line_or_ref) eq "HASH") {
2701 # pre-parsed (or generated by hand)
2702 return $line_or_ref;
2704 return parse_difftree_raw_line
($line_or_ref);
2708 # parse line of git-ls-tree output
2709 sub parse_ls_tree_line
{
2714 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2715 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2723 $res{'name'} = unquote
($4);
2726 return wantarray ? %res : \
%res;
2729 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2730 sub parse_from_to_diffinfo
{
2731 my ($diffinfo, $from, $to, @parents) = @_;
2733 if ($diffinfo->{'nparents'}) {
2735 $from->{'file'} = [];
2736 $from->{'href'} = [];
2737 fill_from_file_info
($diffinfo, @parents)
2738 unless exists $diffinfo->{'from_file'};
2739 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2740 $from->{'file'}[$i] =
2741 defined $diffinfo->{'from_file'}[$i] ?
2742 $diffinfo->{'from_file'}[$i] :
2743 $diffinfo->{'to_file'};
2744 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2745 $from->{'href'}[$i] = href
(action
=>"blob",
2746 hash_base
=>$parents[$i],
2747 hash
=>$diffinfo->{'from_id'}[$i],
2748 file_name
=>$from->{'file'}[$i]);
2750 $from->{'href'}[$i] = undef;
2754 # ordinary (not combined) diff
2755 $from->{'file'} = $diffinfo->{'from_file'};
2756 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2757 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2758 hash
=>$diffinfo->{'from_id'},
2759 file_name
=>$from->{'file'});
2761 delete $from->{'href'};
2765 $to->{'file'} = $diffinfo->{'to_file'};
2766 if (!is_deleted
($diffinfo)) { # file exists in result
2767 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2768 hash
=>$diffinfo->{'to_id'},
2769 file_name
=>$to->{'file'});
2771 delete $to->{'href'};
2775 ## ......................................................................
2776 ## parse to array of hashes functions
2778 sub git_get_heads_list
{
2782 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2783 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
2784 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2787 while (my $line = <$fd>) {
2791 my ($refinfo, $committerinfo) = split(/\0/, $line);
2792 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2793 my ($committer, $epoch, $tz) =
2794 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2795 $ref_item{'fullname'} = $name;
2796 $name =~ s!^refs/heads/!!;
2798 $ref_item{'name'} = $name;
2799 $ref_item{'id'} = $hash;
2800 $ref_item{'title'} = $title || '(no commit message)';
2801 $ref_item{'epoch'} = $epoch;
2803 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2805 $ref_item{'age'} = "unknown";
2808 push @headslist, \
%ref_item;
2812 return wantarray ? @headslist : \
@headslist;
2815 sub git_get_tags_list
{
2819 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2820 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
2821 '--format=%(objectname) %(objecttype) %(refname) '.
2822 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2825 while (my $line = <$fd>) {
2829 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2830 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2831 my ($creator, $epoch, $tz) =
2832 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2833 $ref_item{'fullname'} = $name;
2834 $name =~ s!^refs/tags/!!;
2836 $ref_item{'type'} = $type;
2837 $ref_item{'id'} = $id;
2838 $ref_item{'name'} = $name;
2839 if ($type eq "tag") {
2840 $ref_item{'subject'} = $title;
2841 $ref_item{'reftype'} = $reftype;
2842 $ref_item{'refid'} = $refid;
2844 $ref_item{'reftype'} = $type;
2845 $ref_item{'refid'} = $id;
2848 if ($type eq "tag" || $type eq "commit") {
2849 $ref_item{'epoch'} = $epoch;
2851 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2853 $ref_item{'age'} = "unknown";
2857 push @tagslist, \
%ref_item;
2861 return wantarray ? @tagslist : \
@tagslist;
2864 ## ----------------------------------------------------------------------
2865 ## filesystem-related functions
2867 sub get_file_owner
{
2870 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2871 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2872 if (!defined $gcos) {
2876 $owner =~ s/[,;].*$//;
2877 return to_utf8
($owner);
2880 # assume that file exists
2882 my $filename = shift;
2884 open my $fd, '<', $filename;
2885 print map { to_utf8
($_) } <$fd>;
2889 ## ......................................................................
2890 ## mimetype related functions
2892 sub mimetype_guess_file
{
2893 my $filename = shift;
2894 my $mimemap = shift;
2895 -r
$mimemap or return undef;
2898 open(my $mh, '<', $mimemap) or return undef;
2900 next if m/^#/; # skip comments
2901 my ($mimetype, $exts) = split(/\t+/);
2902 if (defined $exts) {
2903 my @exts = split(/\s+/, $exts);
2904 foreach my $ext (@exts) {
2905 $mimemap{$ext} = $mimetype;
2911 $filename =~ /\.([^.]*)$/;
2912 return $mimemap{$1};
2915 sub mimetype_guess
{
2916 my $filename = shift;
2918 $filename =~ /\./ or return undef;
2920 if ($mimetypes_file) {
2921 my $file = $mimetypes_file;
2922 if ($file !~ m!^/!) { # if it is relative path
2923 # it is relative to project
2924 $file = "$projectroot/$project/$file";
2926 $mime = mimetype_guess_file
($filename, $file);
2928 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2934 my $filename = shift;
2937 my $mime = mimetype_guess
($filename);
2938 $mime and return $mime;
2942 return $default_blob_plain_mimetype unless $fd;
2945 return 'text/plain';
2946 } elsif (! $filename) {
2947 return 'application/octet-stream';
2948 } elsif ($filename =~ m/\.png$/i) {
2950 } elsif ($filename =~ m/\.gif$/i) {
2952 } elsif ($filename =~ m/\.jpe?g$/i) {
2953 return 'image/jpeg';
2955 return 'application/octet-stream';
2959 sub blob_contenttype
{
2960 my ($fd, $file_name, $type) = @_;
2962 $type ||= blob_mimetype
($fd, $file_name);
2963 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
2964 $type .= "; charset=$default_text_plain_charset";
2970 ## ======================================================================
2971 ## functions printing HTML: header, footer, error page
2973 sub git_header_html
{
2974 my $status = shift || "200 OK";
2975 my $expires = shift;
2977 my $title = "$site_name";
2978 if (defined $project) {
2979 $title .= " - " . to_utf8
($project);
2980 if (defined $action) {
2981 $title .= "/$action";
2982 if (defined $file_name) {
2983 $title .= " - " . esc_path
($file_name);
2984 if ($action eq "tree" && $file_name !~ m
|/$|) {
2991 # require explicit support from the UA if we are to send the page as
2992 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2993 # we have to do this because MSIE sometimes globs '*/*', pretending to
2994 # support xhtml+xml but choking when it gets what it asked for.
2995 if (defined $cgi->http('HTTP_ACCEPT') &&
2996 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2997 $cgi->Accept('application/xhtml+xml') != 0) {
2998 $content_type = 'application/xhtml+xml';
3000 $content_type = 'text/html';
3002 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
3003 -status
=> $status, -expires
=> $expires);
3004 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
3006 <?xml version="1.0" encoding="utf-8"?>
3007 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3008 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
3009 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
3010 <!-- git core binaries version $git_version -->
3012 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
3013 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
3014 <meta name="robots" content="index, nofollow"/>
3015 <title>$title</title>
3017 # the stylesheet, favicon etc urls won't work correctly with path_info
3018 # unless we set the appropriate base URL
3019 if ($ENV{'PATH_INFO'}) {
3020 print "<base href=\"".esc_url
($base_url)."\" />\n";
3022 # print out each stylesheet that exist, providing backwards capability
3023 # for those people who defined $stylesheet in a config file
3024 if (defined $stylesheet) {
3025 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
3027 foreach my $stylesheet (@stylesheets) {
3028 next unless $stylesheet;
3029 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
3032 if (defined $project) {
3033 my %href_params = get_feed_info
();
3034 if (!exists $href_params{'-title'}) {
3035 $href_params{'-title'} = 'log';
3038 foreach my $format qw(RSS Atom) {
3039 my $type = lc($format);
3041 '-rel' => 'alternate',
3042 '-title' => "$project - $href_params{'-title'} - $format feed",
3043 '-type' => "application/$type+xml"
3046 $href_params{'action'} = $type;
3047 $link_attr{'-href'} = href
(%href_params);
3049 "rel=\"$link_attr{'-rel'}\" ".
3050 "title=\"$link_attr{'-title'}\" ".
3051 "href=\"$link_attr{'-href'}\" ".
3052 "type=\"$link_attr{'-type'}\" ".
3055 $href_params{'extra_options'} = '--no-merges';
3056 $link_attr{'-href'} = href
(%href_params);
3057 $link_attr{'-title'} .= ' (no merges)';
3059 "rel=\"$link_attr{'-rel'}\" ".
3060 "title=\"$link_attr{'-title'}\" ".
3061 "href=\"$link_attr{'-href'}\" ".
3062 "type=\"$link_attr{'-type'}\" ".
3067 printf('<link rel="alternate" title="%s projects list" '.
3068 'href="%s" type="text/plain; charset=utf-8" />'."\n",
3069 $site_name, href
(project
=>undef, action
=>"project_index"));
3070 printf('<link rel="alternate" title="%s projects feeds" '.
3071 'href="%s" type="text/x-opml" />'."\n",
3072 $site_name, href
(project
=>undef, action
=>"opml"));
3074 if (defined $favicon) {
3075 print qq(<link rel="shortcut icon" href="$favicon" type="image/png" />\n);
3081 if (-f
$site_header) {
3082 insert_file
($site_header);
3085 print "<div class=\"page_header\">\n" .
3086 $cgi->a({-href
=> esc_url
($logo_url),
3087 -title
=> $logo_label},
3088 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
3089 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
3090 if (defined $project) {
3091 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
3092 if (defined $action) {
3099 my $have_search = gitweb_check_feature
('search');
3100 if (defined $project && $have_search) {
3101 if (!defined $searchtext) {
3105 if (defined $hash_base) {
3106 $search_hash = $hash_base;
3107 } elsif (defined $hash) {
3108 $search_hash = $hash;
3110 $search_hash = "HEAD";
3112 my $action = $my_uri;
3113 my $use_pathinfo = gitweb_check_feature
('pathinfo');
3114 if ($use_pathinfo) {
3115 $action .= "/".esc_url
($project);
3117 print $cgi->startform(-method => "get", -action
=> $action) .
3118 "<div class=\"search\">\n" .
3120 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
3121 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
3122 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
3123 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
3124 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
3125 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
3127 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
3128 "<span title=\"Extended regular expression\">" .
3129 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
3130 -checked
=> $search_use_regexp) .
3133 $cgi->end_form() . "\n";
3137 sub git_footer_html
{
3138 my $feed_class = 'rss_logo';
3140 print "<div class=\"page_footer\">\n";
3141 if (defined $project) {
3142 my $descr = git_get_project_description
($project);
3143 if (defined $descr) {
3144 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
3147 my %href_params = get_feed_info
();
3148 if (!%href_params) {
3149 $feed_class .= ' generic';
3151 $href_params{'-title'} ||= 'log';
3153 foreach my $format qw(RSS Atom) {
3154 $href_params{'action'} = lc($format);
3155 print $cgi->a({-href
=> href
(%href_params),
3156 -title
=> "$href_params{'-title'} $format feed",
3157 -class => $feed_class}, $format)."\n";
3161 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
3162 -class => $feed_class}, "OPML") . " ";
3163 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
3164 -class => $feed_class}, "TXT") . "\n";
3166 print "</div>\n"; # class="page_footer"
3168 if (-f
$site_footer) {
3169 insert_file
($site_footer);
3176 # die_error(<http_status_code>, <error_message>)
3177 # Example: die_error(404, 'Hash not found')
3178 # By convention, use the following status codes (as defined in RFC 2616):
3179 # 400: Invalid or missing CGI parameters, or
3180 # requested object exists but has wrong type.
3181 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
3182 # this server or project.
3183 # 404: Requested object/revision/project doesn't exist.
3184 # 500: The server isn't configured properly, or
3185 # an internal error occurred (e.g. failed assertions caused by bugs), or
3186 # an unknown error occurred (e.g. the git binary died unexpectedly).
3188 my $status = shift || 500;
3189 my $error = shift || "Internal server error";
3191 my %http_responses = (400 => '400 Bad Request',
3192 403 => '403 Forbidden',
3193 404 => '404 Not Found',
3194 500 => '500 Internal Server Error');
3195 git_header_html
($http_responses{$status});
3197 <div class="page_body">
3207 ## ----------------------------------------------------------------------
3208 ## functions printing or outputting HTML: navigation
3210 sub git_print_page_nav
{
3211 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
3212 $extra = '' if !defined $extra; # pager or formats
3214 my @navs = qw(summary shortlog log commit commitdiff tree);
3216 @navs = grep { $_ ne $suppress } @navs;
3219 my %arg = map { $_ => {action
=>$_} } @navs;
3220 if (defined $head) {
3221 for (qw(commit commitdiff)) {
3222 $arg{$_}{'hash'} = $head;
3224 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
3225 for (qw(shortlog log)) {
3226 $arg{$_}{'hash'} = $head;
3231 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
3232 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
3234 my @actions = gitweb_get_feature
('actions');
3237 'n' => $project, # project name
3238 'f' => $git_dir, # project path within filesystem
3239 'h' => $treehead || '', # current hash ('h' parameter)
3240 'b' => $treebase || '', # hash base ('hb' parameter)
3243 my ($label, $link, $pos) = splice(@actions,0,3);
3245 @navs = map { $_ eq $pos ? ($_, $label) : $_ } @navs;
3247 $link =~ s/%([%nfhb])/$repl{$1}/g;
3248 $arg{$label}{'_href'} = $link;
3251 print "<div class=\"page_nav\">\n" .
3253 map { $_ eq $current ?
3254 $_ : $cgi->a({-href
=> ($arg{$_}{_href
} ? $arg{$_}{_href
} : href
(%{$arg{$_}}))}, "$_")
3256 print "<br/>\n$extra<br/>\n" .
3260 sub format_paging_nav
{
3261 my ($action, $hash, $head, $page, $has_next_link) = @_;
3265 if ($hash ne $head || $page) {
3266 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
3268 $paging_nav .= "HEAD";
3272 $paging_nav .= " ⋅ " .
3273 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
3274 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3276 $paging_nav .= " ⋅ prev";
3279 if ($has_next_link) {
3280 $paging_nav .= " ⋅ " .
3281 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
3282 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3284 $paging_nav .= " ⋅ next";
3290 ## ......................................................................
3291 ## functions printing or outputting HTML: div
3293 sub git_print_header_div
{
3294 my ($action, $title, $hash, $hash_base) = @_;
3297 $args{'action'} = $action;
3298 $args{'hash'} = $hash if $hash;
3299 $args{'hash_base'} = $hash_base if $hash_base;
3301 print "<div class=\"header\">\n" .
3302 $cgi->a({-href
=> href
(%args), -class => "title"},
3303 $title ? $title : $action) .
3307 sub print_local_time
{
3309 if ($date{'hour_local'} < 6) {
3310 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3311 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3313 printf(" (%02d:%02d %s)",
3314 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3318 # Outputs the author name and date in long form
3319 sub git_print_authorship
{
3322 my $tag = $opts{-tag
} || 'div';
3324 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
3325 print "<$tag class=\"author_date\">" .
3326 esc_html
($co->{'author_name'}) .
3328 print_local_time
(%ad) if ($opts{-localtime});
3329 print "]" . git_get_avatar
($co->{'author_email'}, -pad_before
=> 1)
3333 # Outputs table rows containing the full author or committer information,
3334 # in the format expected for 'commit' view (& similia).
3335 # Parameters are a commit hash reference, followed by the list of people
3336 # to output information for. If the list is empty it defalts to both
3337 # author and committer.
3338 sub git_print_authorship_rows
{
3340 # too bad we can't use @people = @_ || ('author', 'committer')
3342 @people = ('author', 'committer') unless @people;
3343 foreach my $who (@people) {
3344 my %wd = parse_date
($co->{"${who}_epoch"}, $co->{"${who}_tz"});
3345 print "<tr><td>$who</td><td>" . esc_html
($co->{$who}) . "</td>" .
3346 "<td rowspan=\"2\">" .
3347 git_get_avatar
($co->{"${who}_email"}, -size
=> 'double') .
3350 "<td></td><td> $wd{'rfc2822'}";
3351 print_local_time
(%wd);
3357 sub git_print_page_path
{
3363 print "<div class=\"page_path\">";
3364 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
3365 -title
=> 'tree root'}, to_utf8
("[$project]"));
3367 if (defined $name) {
3368 my @dirname = split '/', $name;
3369 my $basename = pop @dirname;
3372 foreach my $dir (@dirname) {
3373 $fullname .= ($fullname ? '/' : '') . $dir;
3374 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
3376 -title
=> $fullname}, esc_path
($dir));
3379 if (defined $type && $type eq 'blob') {
3380 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
3382 -title
=> $name}, esc_path
($basename));
3383 } elsif (defined $type && $type eq 'tree') {
3384 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
3386 -title
=> $name}, esc_path
($basename));
3389 print esc_path
($basename);
3392 print "<br/></div>\n";
3399 if ($opts{'-remove_title'}) {
3400 # remove title, i.e. first line of log
3403 # remove leading empty lines
3404 while (defined $log->[0] && $log->[0] eq "") {
3411 foreach my $line (@$log) {
3412 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
3415 if (! $opts{'-remove_signoff'}) {
3416 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
3419 # remove signoff lines
3426 # print only one empty line
3427 # do not print empty line after signoff
3429 next if ($empty || $signoff);
3435 print format_log_line_html
($line) . "<br/>\n";
3438 if ($opts{'-final_empty_line'}) {
3439 # end with single empty line
3440 print "<br/>\n" unless $empty;
3444 # return link target (what link points to)
3445 sub git_get_link_target
{
3450 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3454 $link_target = <$fd>;
3459 return $link_target;
3462 # given link target, and the directory (basedir) the link is in,
3463 # return target of link relative to top directory (top tree);
3464 # return undef if it is not possible (including absolute links).
3465 sub normalize_link_target
{
3466 my ($link_target, $basedir) = @_;
3468 # absolute symlinks (beginning with '/') cannot be normalized
3469 return if (substr($link_target, 0, 1) eq '/');
3471 # normalize link target to path from top (root) tree (dir)
3474 $path = $basedir . '/' . $link_target;
3476 # we are in top (root) tree (dir)
3477 $path = $link_target;
3480 # remove //, /./, and /../
3482 foreach my $part (split('/', $path)) {
3483 # discard '.' and ''
3484 next if (!$part || $part eq '.');
3486 if ($part eq '..') {
3490 # link leads outside repository (outside top dir)
3494 push @path_parts, $part;
3497 $path = join('/', @path_parts);
3502 # print tree entry (row of git_tree), but without encompassing <tr> element
3503 sub git_print_tree_entry
{
3504 my ($t, $basedir, $hash_base, $have_blame) = @_;
3507 $base_key{'hash_base'} = $hash_base if defined $hash_base;
3509 # The format of a table row is: mode list link. Where mode is
3510 # the mode of the entry, list is the name of the entry, an href,
3511 # and link is the action links of the entry.
3513 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
3514 if ($t->{'type'} eq "blob") {
3515 print "<td class=\"list\">" .
3516 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3517 file_name
=>"$basedir$t->{'name'}", %base_key),
3518 -class => "list"}, esc_path
($t->{'name'}));
3519 if (S_ISLNK
(oct $t->{'mode'})) {
3520 my $link_target = git_get_link_target
($t->{'hash'});
3522 my $norm_target = normalize_link_target
($link_target, $basedir);
3523 if (defined $norm_target) {
3525 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
3526 file_name
=>$norm_target),
3527 -title
=> $norm_target}, esc_path
($link_target));
3529 print " -> " . esc_path
($link_target);
3534 print "<td class=\"link\">";
3535 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3536 file_name
=>"$basedir$t->{'name'}", %base_key)},
3540 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
3541 file_name
=>"$basedir$t->{'name'}", %base_key)},
3544 if (defined $hash_base) {
3546 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3547 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
3551 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
3552 file_name
=>"$basedir$t->{'name'}")},
3556 } elsif ($t->{'type'} eq "tree") {
3557 print "<td class=\"list\">";
3558 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3559 file_name
=>"$basedir$t->{'name'}", %base_key)},
3560 esc_path
($t->{'name'}));
3562 print "<td class=\"link\">";
3563 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3564 file_name
=>"$basedir$t->{'name'}", %base_key)},
3566 if (defined $hash_base) {
3568 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3569 file_name
=>"$basedir$t->{'name'}")},
3574 # unknown object: we can only present history for it
3575 # (this includes 'commit' object, i.e. submodule support)
3576 print "<td class=\"list\">" .
3577 esc_path
($t->{'name'}) .
3579 print "<td class=\"link\">";
3580 if (defined $hash_base) {
3581 print $cgi->a({-href
=> href
(action
=>"history",
3582 hash_base
=>$hash_base,
3583 file_name
=>"$basedir$t->{'name'}")},
3590 ## ......................................................................
3591 ## functions printing large fragments of HTML
3593 # get pre-image filenames for merge (combined) diff
3594 sub fill_from_file_info
{
3595 my ($diff, @parents) = @_;
3597 $diff->{'from_file'} = [ ];
3598 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
3599 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3600 if ($diff->{'status'}[$i] eq 'R' ||
3601 $diff->{'status'}[$i] eq 'C') {
3602 $diff->{'from_file'}[$i] =
3603 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
3610 # is current raw difftree line of file deletion
3612 my $diffinfo = shift;
3614 return $diffinfo->{'to_id'} eq ('0' x
40);
3617 # does patch correspond to [previous] difftree raw line
3618 # $diffinfo - hashref of parsed raw diff format
3619 # $patchinfo - hashref of parsed patch diff format
3620 # (the same keys as in $diffinfo)
3621 sub is_patch_split
{
3622 my ($diffinfo, $patchinfo) = @_;
3624 return defined $diffinfo && defined $patchinfo
3625 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3629 sub git_difftree_body
{
3630 my ($difftree, $hash, @parents) = @_;
3631 my ($parent) = $parents[0];
3632 my $have_blame = gitweb_check_feature
('blame');
3633 print "<div class=\"list_head\">\n";
3634 if ($#{$difftree} > 10) {
3635 print(($#{$difftree} + 1) . " files changed:\n");
3639 print "<table class=\"" .
3640 (@parents > 1 ? "combined " : "") .
3643 # header only for combined diff in 'commitdiff' view
3644 my $has_header = @$difftree && @parents > 1 && $action eq 'commitdiff';
3647 print "<thead><tr>\n" .
3648 "<th></th><th></th>\n"; # filename, patchN link
3649 for (my $i = 0; $i < @parents; $i++) {
3650 my $par = $parents[$i];
3652 $cgi->a({-href
=> href
(action
=>"commitdiff",
3653 hash
=>$hash, hash_parent
=>$par),
3654 -title
=> 'commitdiff to parent number ' .
3655 ($i+1) . ': ' . substr($par,0,7)},
3659 print "</tr></thead>\n<tbody>\n";
3664 foreach my $line (@{$difftree}) {
3665 my $diff = parsed_difftree_line
($line);
3668 print "<tr class=\"dark\">\n";
3670 print "<tr class=\"light\">\n";
3674 if (exists $diff->{'nparents'}) { # combined diff
3676 fill_from_file_info
($diff, @parents)
3677 unless exists $diff->{'from_file'};
3679 if (!is_deleted
($diff)) {
3680 # file exists in the result (child) commit
3682 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3683 file_name
=>$diff->{'to_file'},
3685 -class => "list"}, esc_path
($diff->{'to_file'})) .
3689 esc_path
($diff->{'to_file'}) .
3693 if ($action eq 'commitdiff') {
3696 print "<td class=\"link\">" .
3697 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3702 my $has_history = 0;
3703 my $not_deleted = 0;
3704 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3705 my $hash_parent = $parents[$i];
3706 my $from_hash = $diff->{'from_id'}[$i];
3707 my $from_path = $diff->{'from_file'}[$i];
3708 my $status = $diff->{'status'}[$i];
3710 $has_history ||= ($status ne 'A');
3711 $not_deleted ||= ($status ne 'D');
3713 if ($status eq 'A') {
3714 print "<td class=\"link\" align=\"right\"> | </td>\n";
3715 } elsif ($status eq 'D') {
3716 print "<td class=\"link\">" .
3717 $cgi->a({-href
=> href
(action
=>"blob",
3720 file_name
=>$from_path)},
3724 if ($diff->{'to_id'} eq $from_hash) {
3725 print "<td class=\"link nochange\">";
3727 print "<td class=\"link\">";
3729 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3730 hash
=>$diff->{'to_id'},
3731 hash_parent
=>$from_hash,
3733 hash_parent_base
=>$hash_parent,
3734 file_name
=>$diff->{'to_file'},
3735 file_parent
=>$from_path)},
3741 print "<td class=\"link\">";
3743 print $cgi->a({-href
=> href
(action
=>"blob",
3744 hash
=>$diff->{'to_id'},
3745 file_name
=>$diff->{'to_file'},
3748 print " | " if ($has_history);
3751 print $cgi->a({-href
=> href
(action
=>"history",
3752 file_name
=>$diff->{'to_file'},
3759 next; # instead of 'else' clause, to avoid extra indent
3761 # else ordinary diff
3763 my ($to_mode_oct, $to_mode_str, $to_file_type);
3764 my ($from_mode_oct, $from_mode_str, $from_file_type);
3765 if ($diff->{'to_mode'} ne ('0' x
6)) {
3766 $to_mode_oct = oct $diff->{'to_mode'};
3767 if (S_ISREG
($to_mode_oct)) { # only for regular file
3768 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3770 $to_file_type = file_type
($diff->{'to_mode'});
3772 if ($diff->{'from_mode'} ne ('0' x
6)) {
3773 $from_mode_oct = oct $diff->{'from_mode'};
3774 if (S_ISREG
($to_mode_oct)) { # only for regular file
3775 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3777 $from_file_type = file_type
($diff->{'from_mode'});
3780 if ($diff->{'status'} eq "A") { # created
3781 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3782 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3783 $mode_chng .= "]</span>";
3785 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3786 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3787 -class => "list"}, esc_path
($diff->{'file'}));
3789 print "<td>$mode_chng</td>\n";
3790 print "<td class=\"link\">";
3791 if ($action eq 'commitdiff') {
3794 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3797 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3798 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3802 } elsif ($diff->{'status'} eq "D") { # deleted
3803 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3805 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3806 hash_base
=>$parent, 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->{'from_id'},
3818 hash_base
=>$parent, file_name
=>$diff->{'file'})},
3821 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3822 file_name
=>$diff->{'file'})},
3825 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3826 file_name
=>$diff->{'file'})},
3830 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3831 my $mode_chnge = "";
3832 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3833 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3834 if ($from_file_type ne $to_file_type) {
3835 $mode_chnge .= " from $from_file_type to $to_file_type";
3837 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3838 if ($from_mode_str && $to_mode_str) {
3839 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3840 } elsif ($to_mode_str) {
3841 $mode_chnge .= " mode: $to_mode_str";
3844 $mode_chnge .= "]</span>\n";
3847 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3848 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3849 -class => "list"}, esc_path
($diff->{'file'}));
3851 print "<td>$mode_chnge</td>\n";
3852 print "<td class=\"link\">";
3853 if ($action eq 'commitdiff') {
3856 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3858 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3859 # "commit" view and modified file (not onlu mode changed)
3860 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3861 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3862 hash_base
=>$hash, hash_parent_base
=>$parent,
3863 file_name
=>$diff->{'file'})},
3867 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3868 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3871 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3872 file_name
=>$diff->{'file'})},
3875 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3876 file_name
=>$diff->{'file'})},
3880 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3881 my %status_name = ('R' => 'moved', 'C' => 'copied');
3882 my $nstatus = $status_name{$diff->{'status'}};
3884 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3885 # mode also for directories, so we cannot use $to_mode_str
3886 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3889 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3890 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
3891 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3892 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3893 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3894 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
3895 -class => "list"}, esc_path
($diff->{'from_file'})) .
3896 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3897 "<td class=\"link\">";
3898 if ($action eq 'commitdiff') {
3901 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3903 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3904 # "commit" view and modified file (not only pure rename or copy)
3905 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3906 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3907 hash_base
=>$hash, hash_parent_base
=>$parent,
3908 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
3912 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3913 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
3916 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3917 file_name
=>$diff->{'to_file'})},
3920 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3921 file_name
=>$diff->{'to_file'})},
3925 } # we should not encounter Unmerged (U) or Unknown (X) status
3928 print "</tbody>" if $has_header;
3932 sub git_patchset_body
{
3933 my ($fd, $difftree, $hash, @hash_parents) = @_;
3934 my ($hash_parent) = $hash_parents[0];
3936 my $is_combined = (@hash_parents > 1);
3938 my $patch_number = 0;
3944 print "<div class=\"patchset\">\n";
3946 # skip to first patch
3947 while ($patch_line = <$fd>) {
3950 last if ($patch_line =~ m/^diff /);
3954 while ($patch_line) {
3956 # parse "git diff" header line
3957 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
3958 # $1 is from_name, which we do not use
3959 $to_name = unquote
($2);
3960 $to_name =~ s!^b/!!;
3961 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
3962 # $1 is 'cc' or 'combined', which we do not use
3963 $to_name = unquote
($2);
3968 # check if current patch belong to current raw line
3969 # and parse raw git-diff line if needed
3970 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
3971 # this is continuation of a split patch
3972 print "<div class=\"patch cont\">\n";
3974 # advance raw git-diff output if needed
3975 $patch_idx++ if defined $diffinfo;
3977 # read and prepare patch information
3978 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3980 # compact combined diff output can have some patches skipped
3981 # find which patch (using pathname of result) we are at now;
3983 while ($to_name ne $diffinfo->{'to_file'}) {
3984 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3985 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3986 "</div>\n"; # class="patch"
3991 last if $patch_idx > $#$difftree;
3992 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3996 # modifies %from, %to hashes
3997 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
3999 # this is first patch for raw difftree line with $patch_idx index
4000 # we index @$difftree array from 0, but number patches from 1
4001 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
4005 #assert($patch_line =~ m/^diff /) if DEBUG;
4006 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
4008 # print "git diff" header
4009 print format_git_diff_header_line
($patch_line, $diffinfo,
4012 # print extended diff header
4013 print "<div class=\"diff extended_header\">\n";
4015 while ($patch_line = <$fd>) {
4018 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
4020 print format_extended_diff_header_line
($patch_line, $diffinfo,
4023 print "</div>\n"; # class="diff extended_header"
4025 # from-file/to-file diff header
4026 if (! $patch_line) {
4027 print "</div>\n"; # class="patch"
4030 next PATCH
if ($patch_line =~ m/^diff /);
4031 #assert($patch_line =~ m/^---/) if DEBUG;
4033 my $last_patch_line = $patch_line;
4034 $patch_line = <$fd>;
4036 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
4038 print format_diff_from_to_header
($last_patch_line, $patch_line,
4039 $diffinfo, \
%from, \
%to,
4044 while ($patch_line = <$fd>) {
4047 next PATCH
if ($patch_line =~ m/^diff /);
4049 print format_diff_line
($patch_line, \
%from, \
%to);
4053 print "</div>\n"; # class="patch"
4056 # for compact combined (--cc) format, with chunk and patch simpliciaction
4057 # patchset might be empty, but there might be unprocessed raw lines
4058 for (++$patch_idx if $patch_number > 0;
4059 $patch_idx < @$difftree;
4061 # read and prepare patch information
4062 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4064 # generate anchor for "patch" links in difftree / whatchanged part
4065 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4066 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4067 "</div>\n"; # class="patch"
4072 if ($patch_number == 0) {
4073 if (@hash_parents > 1) {
4074 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
4076 print "<div class=\"diff nodifferences\">No differences found</div>\n";
4080 print "</div>\n"; # class="patchset"
4083 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4085 # fills project list info (age, description, owner, forks) for each
4086 # project in the list, removing invalid projects from returned list
4087 # NOTE: modifies $projlist, but does not remove entries from it
4088 sub fill_project_list_info
{
4089 my ($projlist, $check_forks) = @_;
4092 my $show_ctags = gitweb_check_feature
('ctags');
4094 foreach my $pr (@$projlist) {
4095 my (@activity) = git_get_last_activity
($pr->{'path'});
4096 unless (@activity) {
4099 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
4100 if (!defined $pr->{'descr'}) {
4101 my $descr = git_get_project_description
($pr->{'path'}) || "";
4102 $descr = to_utf8
($descr);
4103 $pr->{'descr_long'} = $descr;
4104 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
4106 if (!defined $pr->{'owner'}) {
4107 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
4110 my $pname = $pr->{'path'};
4111 if (($pname =~ s/\.git$//) &&
4112 ($pname !~ /\/$/) &&
4113 (-d
"$projectroot/$pname")) {
4114 $pr->{'forks'} = "-d $projectroot/$pname";
4119 $show_ctags and $pr->{'ctags'} = git_get_project_ctags
($pr->{'path'});
4120 push @projects, $pr;
4126 # print 'sort by' <th> element, generating 'sort by $name' replay link
4127 # if that order is not selected
4129 my ($name, $order, $header) = @_;
4130 $header ||= ucfirst($name);
4132 if ($order eq $name) {
4133 print "<th>$header</th>\n";
4136 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
4137 -class => "header"}, $header) .
4142 sub git_project_list_body
{
4143 # actually uses global variable $project
4144 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
4146 my $check_forks = gitweb_check_feature
('forks');
4147 my @projects = fill_project_list_info
($projlist, $check_forks);
4149 $order ||= $default_projects_order;
4150 $from = 0 unless defined $from;
4151 $to = $#projects if (!defined $to || $#projects < $to);
4154 project
=> { key
=> 'path', type
=> 'str' },
4155 descr
=> { key
=> 'descr_long', type
=> 'str' },
4156 owner
=> { key
=> 'owner', type
=> 'str' },
4157 age
=> { key
=> 'age', type
=> 'num' }
4159 my $oi = $order_info{$order};
4160 if ($oi->{'type'} eq 'str') {
4161 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
4163 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
4166 my $show_ctags = gitweb_check_feature
('ctags');
4169 foreach my $p (@projects) {
4170 foreach my $ct (keys %{$p->{'ctags'}}) {
4171 $ctags{$ct} += $p->{'ctags'}->{$ct};
4174 my $cloud = git_populate_project_tagcloud
(\
%ctags);
4175 print git_show_project_tagcloud
($cloud, 64);
4178 print "<table class=\"project_list\">\n";
4179 unless ($no_header) {
4182 print "<th></th>\n";
4184 print_sort_th
('project', $order, 'Project');
4185 print_sort_th
('descr', $order, 'Description');
4186 print_sort_th
('owner', $order, 'Owner');
4187 print_sort_th
('age', $order, 'Last Change');
4188 print "<th></th>\n" . # for links
4192 my $tagfilter = $cgi->param('by_tag');
4193 for (my $i = $from; $i <= $to; $i++) {
4194 my $pr = $projects[$i];
4196 next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}};
4197 next if $searchtext and not $pr->{'path'} =~ /$searchtext/
4198 and not $pr->{'descr_long'} =~ /$searchtext/;
4199 # Weed out forks or non-matching entries of search
4201 my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s
#\.git$#/#;
4202 $forkbase="^$forkbase" if $forkbase;
4203 next if not $searchtext and not $tagfilter and $show_ctags
4204 and $pr->{'path'} =~ m
#$forkbase.*/.*#; # regexp-safe
4208 print "<tr class=\"dark\">\n";
4210 print "<tr class=\"light\">\n";
4215 if ($pr->{'forks'}) {
4216 print "<!-- $pr->{'forks'} -->\n";
4217 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
4221 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4222 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
4223 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4224 -class => "list", -title
=> $pr->{'descr_long'}},
4225 esc_html
($pr->{'descr'})) . "</td>\n" .
4226 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
4227 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
4228 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
4229 "<td class=\"link\">" .
4230 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
4231 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
4232 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
4233 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
4234 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
4238 if (defined $extra) {
4241 print "<td></td>\n";
4243 print "<td colspan=\"5\">$extra</td>\n" .
4249 sub git_shortlog_body
{
4250 # uses global variable $project
4251 my ($commitlist, $from, $to, $refs, $extra) = @_;
4253 $from = 0 unless defined $from;
4254 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4256 print "<table class=\"shortlog\">\n";
4258 for (my $i = $from; $i <= $to; $i++) {
4259 my %co = %{$commitlist->[$i]};
4260 my $commit = $co{'id'};
4261 my $ref = format_ref_marker
($refs, $commit);
4263 print "<tr class=\"dark\">\n";
4265 print "<tr class=\"light\">\n";
4268 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
4269 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4270 format_author_html
('td', \
%co, 10) . "<td>";
4271 print format_subject_html
($co{'title'}, $co{'title_short'},
4272 href
(action
=>"commit", hash
=>$commit), $ref);
4274 "<td class=\"link\">" .
4275 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
4276 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
4277 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
4278 my $snapshot_links = format_snapshot_links
($commit);
4279 if (defined $snapshot_links) {
4280 print " | " . $snapshot_links;
4285 if (defined $extra) {
4287 "<td colspan=\"4\">$extra</td>\n" .
4293 sub git_history_body
{
4294 # Warning: assumes constant type (blob or tree) during history
4295 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
4297 $from = 0 unless defined $from;
4298 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
4300 print "<table class=\"history\">\n";
4302 for (my $i = $from; $i <= $to; $i++) {
4303 my %co = %{$commitlist->[$i]};
4307 my $commit = $co{'id'};
4309 my $ref = format_ref_marker
($refs, $commit);
4312 print "<tr class=\"dark\">\n";
4314 print "<tr class=\"light\">\n";
4317 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4318 # shortlog: format_author_html('td', \%co, 10)
4319 format_author_html
('td', \
%co, 15, 3) . "<td>";
4320 # originally git_history used chop_str($co{'title'}, 50)
4321 print format_subject_html
($co{'title'}, $co{'title_short'},
4322 href
(action
=>"commit", hash
=>$commit), $ref);
4324 "<td class=\"link\">" .
4325 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
4326 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
4328 if ($ftype eq 'blob') {
4329 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
4330 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
4331 if (defined $blob_current && defined $blob_parent &&
4332 $blob_current ne $blob_parent) {
4334 $cgi->a({-href
=> href
(action
=>"blobdiff",
4335 hash
=>$blob_current, hash_parent
=>$blob_parent,
4336 hash_base
=>$hash_base, hash_parent_base
=>$commit,
4337 file_name
=>$file_name)},
4344 if (defined $extra) {
4346 "<td colspan=\"4\">$extra</td>\n" .
4353 # uses global variable $project
4354 my ($taglist, $from, $to, $extra) = @_;
4355 $from = 0 unless defined $from;
4356 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
4358 print "<table class=\"tags\">\n";
4360 for (my $i = $from; $i <= $to; $i++) {
4361 my $entry = $taglist->[$i];
4363 my $comment = $tag{'subject'};
4365 if (defined $comment) {
4366 $comment_short = chop_str
($comment, 30, 5);
4369 print "<tr class=\"dark\">\n";
4371 print "<tr class=\"light\">\n";
4374 if (defined $tag{'age'}) {
4375 print "<td><i>$tag{'age'}</i></td>\n";
4377 print "<td></td>\n";
4380 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
4381 -class => "list name"}, esc_html
($tag{'name'})) .
4384 if (defined $comment) {
4385 print format_subject_html
($comment, $comment_short,
4386 href
(action
=>"tag", hash
=>$tag{'id'}));
4389 "<td class=\"selflink\">";
4390 if ($tag{'type'} eq "tag") {
4391 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
4396 "<td class=\"link\">" . " | " .
4397 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
4398 if ($tag{'reftype'} eq "commit") {
4399 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
4400 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
4401 } elsif ($tag{'reftype'} eq "blob") {
4402 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
4407 if (defined $extra) {
4409 "<td colspan=\"5\">$extra</td>\n" .
4415 sub git_heads_body
{
4416 # uses global variable $project
4417 my ($headlist, $head, $from, $to, $extra) = @_;
4418 $from = 0 unless defined $from;
4419 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
4421 print "<table class=\"heads\">\n";
4423 for (my $i = $from; $i <= $to; $i++) {
4424 my $entry = $headlist->[$i];
4426 my $curr = $ref{'id'} eq $head;
4428 print "<tr class=\"dark\">\n";
4430 print "<tr class=\"light\">\n";
4433 print "<td><i>$ref{'age'}</i></td>\n" .
4434 ($curr ? "<td class=\"current_head\">" : "<td>") .
4435 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
4436 -class => "list name"},esc_html
($ref{'name'})) .
4438 "<td class=\"link\">" .
4439 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
4440 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
4441 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
4445 if (defined $extra) {
4447 "<td colspan=\"3\">$extra</td>\n" .
4453 sub git_search_grep_body
{
4454 my ($commitlist, $from, $to, $extra) = @_;
4455 $from = 0 unless defined $from;
4456 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4458 print "<table class=\"commit_search\">\n";
4460 for (my $i = $from; $i <= $to; $i++) {
4461 my %co = %{$commitlist->[$i]};
4465 my $commit = $co{'id'};
4467 print "<tr class=\"dark\">\n";
4469 print "<tr class=\"light\">\n";
4472 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4473 format_author_html
('td', \
%co, 15, 5) .
4475 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4476 -class => "list subject"},
4477 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
4478 my $comment = $co{'comment'};
4479 foreach my $line (@$comment) {
4480 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
4481 my ($lead, $match, $trail) = ($1, $2, $3);
4482 $match = chop_str
($match, 70, 5, 'center');
4483 my $contextlen = int((80 - length($match))/2);
4484 $contextlen = 30 if ($contextlen > 30);
4485 $lead = chop_str
($lead, $contextlen, 10, 'left');
4486 $trail = chop_str
($trail, $contextlen, 10, 'right');
4488 $lead = esc_html
($lead);
4489 $match = esc_html
($match);
4490 $trail = esc_html
($trail);
4492 print "$lead<span class=\"match\">$match</span>$trail<br />";
4496 "<td class=\"link\">" .
4497 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4499 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
4501 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4505 if (defined $extra) {
4507 "<td colspan=\"3\">$extra</td>\n" .
4513 ## ======================================================================
4514 ## ======================================================================
4517 sub git_project_list
{
4518 my $order = $input_params{'order'};
4519 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4520 die_error
(400, "Unknown order parameter");
4523 my @list = git_get_projects_list
();
4525 die_error
(404, "No projects found");
4529 if (-f
$home_text) {
4530 print "<div class=\"index_include\">\n";
4531 insert_file
($home_text);
4534 print $cgi->startform(-method => "get") .
4535 "<p class=\"projsearch\">Search:\n" .
4536 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
4538 $cgi->end_form() . "\n";
4539 git_project_list_body
(\
@list, $order);
4544 my $order = $input_params{'order'};
4545 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4546 die_error
(400, "Unknown order parameter");
4549 my @list = git_get_projects_list
($project);
4551 die_error
(404, "No forks found");
4555 git_print_page_nav
('','');
4556 git_print_header_div
('summary', "$project forks");
4557 git_project_list_body
(\
@list, $order);
4561 sub git_project_index
{
4562 my @projects = git_get_projects_list
($project);
4565 -type
=> 'text/plain',
4566 -charset
=> 'utf-8',
4567 -content_disposition
=> 'inline; filename="index.aux"');
4569 foreach my $pr (@projects) {
4570 if (!exists $pr->{'owner'}) {
4571 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
4574 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
4575 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
4576 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4577 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4581 print "$path $owner\n";
4586 my $descr = git_get_project_description
($project) || "none";
4587 my %co = parse_commit
("HEAD");
4588 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
4589 my $head = $co{'id'};
4591 my $owner = git_get_project_owner
($project);
4593 my $refs = git_get_references
();
4594 # These get_*_list functions return one more to allow us to see if
4595 # there are more ...
4596 my @taglist = git_get_tags_list
(16);
4597 my @headlist = git_get_heads_list
(16);
4599 my $check_forks = gitweb_check_feature
('forks');
4602 @forklist = git_get_projects_list
($project);
4606 git_print_page_nav
('summary','', $head);
4608 print "<div class=\"title\"> </div>\n";
4609 print "<table class=\"projects_list\">\n" .
4610 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
4611 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
4612 if (defined $cd{'rfc2822'}) {
4613 print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4616 # use per project git URL list in $projectroot/$project/cloneurl
4617 # or make project git URL from git base URL and project name
4618 my $url_tag = "URL";
4619 my @url_list = git_get_project_url_list
($project);
4620 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4621 foreach my $git_url (@url_list) {
4622 next unless $git_url;
4623 print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";
4628 my $show_ctags = gitweb_check_feature
('ctags');
4630 my $ctags = git_get_project_ctags
($project);
4631 my $cloud = git_populate_project_tagcloud
($ctags);
4632 print "<tr id=\"metadata_ctags\"><td>Content tags:<br />";
4633 print "</td>\n<td>" unless %$ctags;
4634 print "<form action=\"$show_ctags\" method=\"post\"><input type=\"hidden\" name=\"p\" value=\"$project\" />Add: <input type=\"text\" name=\"t\" size=\"8\" /></form>";
4635 print "</td>\n<td>" if %$ctags;
4636 print git_show_project_tagcloud
($cloud, 48);
4642 # If XSS prevention is on, we don't include README.html.
4643 # TODO: Allow a readme in some safe format.
4644 if (!$prevent_xss && -s
"$projectroot/$project/README.html") {
4645 print "<div class=\"title\">readme</div>\n" .
4646 "<div class=\"readme\">\n";
4647 insert_file
("$projectroot/$project/README.html");
4648 print "\n</div>\n"; # class="readme"
4651 # we need to request one more than 16 (0..15) to check if
4653 my @commitlist = $head ? parse_commits
($head, 17) : ();
4655 git_print_header_div
('shortlog');
4656 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
4657 $#commitlist <= 15 ? undef :
4658 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
4662 git_print_header_div
('tags');
4663 git_tags_body
(\
@taglist, 0, 15,
4664 $#taglist <= 15 ? undef :
4665 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
4669 git_print_header_div
('heads');
4670 git_heads_body
(\
@headlist, $head, 0, 15,
4671 $#headlist <= 15 ? undef :
4672 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
4676 git_print_header_div
('forks');
4677 git_project_list_body
(\
@forklist, 'age', 0, 15,
4678 $#forklist <= 15 ? undef :
4679 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
4687 my $head = git_get_head_hash
($project);
4689 git_print_page_nav
('','', $head,undef,$head);
4690 my %tag = parse_tag
($hash);
4693 die_error
(404, "Unknown tag object");
4696 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
4697 print "<div class=\"title_text\">\n" .
4698 "<table class=\"object_header\">\n" .
4700 "<td>object</td>\n" .
4701 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4702 $tag{'object'}) . "</td>\n" .
4703 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4704 $tag{'type'}) . "</td>\n" .
4706 if (defined($tag{'author'})) {
4707 git_print_authorship_rows
(\
%tag, 'author');
4709 print "</table>\n\n" .
4711 print "<div class=\"page_body\">";
4712 my $comment = $tag{'comment'};
4713 foreach my $line (@$comment) {
4715 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4723 gitweb_check_feature
('blame')
4724 or die_error
(403, "Blame view not allowed");
4727 die_error
(400, "No file name given") unless $file_name;
4728 $hash_base ||= git_get_head_hash
($project);
4729 die_error
(404, "Couldn't find base commit") unless $hash_base;
4730 my %co = parse_commit
($hash_base)
4731 or die_error
(404, "Commit not found");
4733 if (!defined $hash) {
4734 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4735 or die_error
(404, "Error looking up file");
4737 $ftype = git_get_type
($hash);
4738 if ($ftype !~ "blob") {
4739 die_error
(400, "Object is not a blob");
4743 # run git-blame --porcelain
4744 open my $fd, "-|", git_cmd
(), "blame", '-p',
4745 $hash_base, '--', $file_name
4746 or die_error
(500, "Open git-blame failed");
4751 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
4754 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4757 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4759 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4760 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4761 git_print_page_path
($file_name, $ftype, $hash_base);
4764 my @rev_color = qw(light2 dark2);
4765 my $num_colors = scalar(@rev_color);
4766 my $current_color = 0;
4770 <div class="page_body">
4771 <table class="blame">
4772 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
4775 while (my $line = <$fd>) {
4777 # the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]
4778 # no <lines in group> for subsequent lines in group of lines
4779 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4780 ($line =~ /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);
4781 if (!exists $metainfo{$full_rev}) {
4782 $metainfo{$full_rev} = {};
4784 my $meta = $metainfo{$full_rev};
4786 while ($data = <$fd>) {
4788 last if ($data =~ s/^\t//); # contents of line
4789 if ($data =~ /^(\S+) (.*)$/) {
4793 my $short_rev = substr($full_rev, 0, 8);
4794 my $author = $meta->{'author'};
4796 parse_date
($meta->{'author-time'}, $meta->{'author-tz'});
4797 my $date = $date{'iso-tz'};
4799 $current_color = ($current_color + 1) % $num_colors;
4801 print "<tr id=\"l$lineno\" class=\"$rev_color[$current_color]\">\n";
4803 print "<td class=\"sha1\"";
4804 print " title=\"". esc_html
($author) . ", $date\"";
4805 print " rowspan=\"$group_size\"" if ($group_size > 1);
4807 print $cgi->a({-href
=> href
(action
=>"commit",
4809 file_name
=>$file_name)},
4810 esc_html
($short_rev));
4814 if (!exists $meta->{'parent'}) {
4815 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
4816 or die_error
(500, "Open git-rev-parse failed");
4817 $parent_commit = <$dd>;
4819 chomp($parent_commit);
4820 $meta->{'parent'} = $parent_commit;
4822 $parent_commit = $meta->{'parent'};
4824 my $blamed = href
(action
=> 'blame',
4825 file_name
=> $meta->{'filename'},
4826 hash_base
=> $parent_commit);
4827 print "<td class=\"linenr\">";
4828 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
4829 -class => "linenr" },
4832 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
4838 or print "Reading blob failed\n";
4845 my $head = git_get_head_hash
($project);
4847 git_print_page_nav
('','', $head,undef,$head);
4848 git_print_header_div
('summary', $project);
4850 my @tagslist = git_get_tags_list
();
4852 git_tags_body
(\
@tagslist);
4858 my $head = git_get_head_hash
($project);
4860 git_print_page_nav
('','', $head,undef,$head);
4861 git_print_header_div
('summary', $project);
4863 my @headslist = git_get_heads_list
();
4865 git_heads_body
(\
@headslist, $head);
4870 sub git_blob_plain
{
4874 if (!defined $hash) {
4875 if (defined $file_name) {
4876 my $base = $hash_base || git_get_head_hash
($project);
4877 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4878 or die_error
(404, "Cannot find file");
4880 die_error
(400, "No file name defined");
4882 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4883 # blobs defined by non-textual hash id's can be cached
4887 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4888 or die_error
(500, "Open git-cat-file blob '$hash' failed");
4890 # content-type (can include charset)
4891 $type = blob_contenttype
($fd, $file_name, $type);
4893 # "save as" filename, even when no $file_name is given
4894 my $save_as = "$hash";
4895 if (defined $file_name) {
4896 $save_as = $file_name;
4897 } elsif ($type =~ m/^text\//) {
4901 # With XSS prevention on, blobs of all types except a few known safe
4902 # ones are served with "Content-Disposition: attachment" to make sure
4903 # they don't run in our security domain. For certain image types,
4904 # blob view writes an <img> tag referring to blob_plain view, and we
4905 # want to be sure not to break that by serving the image as an
4906 # attachment (though Firefox 3 doesn't seem to care).
4907 my $sandbox = $prevent_xss &&
4908 $type !~ m!^(?:text/plain|image/(?:gif|png|jpeg))$!;
4912 -expires
=> $expires,
4913 -content_disposition
=>
4914 ($sandbox ? 'attachment' : 'inline')
4915 . '; filename="' . $save_as . '"');
4917 binmode STDOUT
, ':raw';
4919 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4926 if (!defined $hash) {
4927 if (defined $file_name) {
4928 my $base = $hash_base || git_get_head_hash
($project);
4929 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4930 or die_error
(404, "Cannot find file");
4932 die_error
(400, "No file name defined");
4934 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4935 # blobs defined by non-textual hash id's can be cached
4939 my $have_blame = gitweb_check_feature
('blame');
4940 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4941 or die_error
(500, "Couldn't cat $file_name, $hash");
4942 my $mimetype = blob_mimetype
($fd, $file_name);
4943 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
4945 return git_blob_plain
($mimetype);
4947 # we can have blame only for text/* mimetype
4948 $have_blame &&= ($mimetype =~ m!^text/!);
4950 git_header_html
(undef, $expires);
4951 my $formats_nav = '';
4952 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4953 if (defined $file_name) {
4956 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
4961 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4964 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4967 $cgi->a({-href
=> href
(action
=>"blob",
4968 hash_base
=>"HEAD", file_name
=>$file_name)},
4972 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4975 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4976 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4978 print "<div class=\"page_nav\">\n" .
4979 "<br/><br/></div>\n" .
4980 "<div class=\"title\">$hash</div>\n";
4982 git_print_page_path
($file_name, "blob", $hash_base);
4983 print "<div class=\"page_body\">\n";
4984 if ($mimetype =~ m!^image/!) {
4985 print qq
!<img type
="$mimetype"!;
4987 print qq
! alt
="$file_name" title
="$file_name"!;
4990 href(action=>"blob_plain
", hash=>$hash,
4991 hash_base=>$hash_base, file_name=>$file_name) .
4995 while (my $line = <$fd>) {
4998 $line = untabify
($line);
4999 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
5000 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
5004 or print "Reading blob failed.\n";
5010 if (!defined $hash_base) {
5011 $hash_base = "HEAD";
5013 if (!defined $hash) {
5014 if (defined $file_name) {
5015 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
5020 die_error
(404, "No such tree") unless defined($hash);
5025 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
5026 or die_error
(500, "Open git-ls-tree failed");
5027 @entries = map { chomp; $_ } <$fd>;
5029 or die_error
(404, "Reading tree failed");
5032 my $refs = git_get_references
();
5033 my $ref = format_ref_marker
($refs, $hash_base);
5036 my $have_blame = gitweb_check_feature
('blame');
5037 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5039 if (defined $file_name) {
5041 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5043 $cgi->a({-href
=> href
(action
=>"tree",
5044 hash_base
=>"HEAD", file_name
=>$file_name)},
5047 my $snapshot_links = format_snapshot_links
($hash);
5048 if (defined $snapshot_links) {
5049 # FIXME: Should be available when we have no hash base as well.
5050 push @views_nav, $snapshot_links;
5052 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
5053 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
5056 print "<div class=\"page_nav\">\n";
5057 print "<br/><br/></div>\n";
5058 print "<div class=\"title\">$hash</div>\n";
5060 if (defined $file_name) {
5061 $basedir = $file_name;
5062 if ($basedir ne '' && substr($basedir, -1) ne '/') {
5065 git_print_page_path
($file_name, 'tree', $hash_base);
5067 print "<div class=\"page_body\">\n";
5068 print "<table class=\"tree\">\n";
5070 # '..' (top directory) link if possible
5071 if (defined $hash_base &&
5072 defined $file_name && $file_name =~ m![^/]+$!) {
5074 print "<tr class=\"dark\">\n";
5076 print "<tr class=\"light\">\n";
5080 my $up = $file_name;
5081 $up =~ s!/?[^/]+$!!;
5082 undef $up unless $up;
5083 # based on git_print_tree_entry
5084 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
5085 print '<td class="list">';
5086 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
5090 print "<td class=\"link\"></td>\n";
5094 foreach my $line (@entries) {
5095 my %t = parse_ls_tree_line
($line, -z
=> 1);
5098 print "<tr class=\"dark\">\n";
5100 print "<tr class=\"light\">\n";
5104 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
5108 print "</table>\n" .
5114 my $format = $input_params{'snapshot_format'};
5115 if (!@snapshot_fmts) {
5116 die_error
(403, "Snapshots not allowed");
5118 # default to first supported snapshot format
5119 $format ||= $snapshot_fmts[0];
5120 if ($format !~ m/^[a-z0-9]+$/) {
5121 die_error
(400, "Invalid snapshot format parameter");
5122 } elsif (!exists($known_snapshot_formats{$format})) {
5123 die_error
(400, "Unknown snapshot format");
5124 } elsif (!grep($_ eq $format, @snapshot_fmts)) {
5125 die_error
(403, "Unsupported snapshot format");
5128 if (!defined $hash) {
5129 $hash = git_get_head_hash
($project);
5132 my $name = $project;
5133 $name =~ s
,([^/])/*\
.git
$,$1,;
5134 $name = basename
($name);
5135 my $filename = to_utf8
($name);
5136 $name =~ s/\047/\047\\\047\047/g;
5138 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
5139 $cmd = quote_command
(
5140 git_cmd
(), 'archive',
5141 "--format=$known_snapshot_formats{$format}{'format'}",
5142 "--prefix=$name/", $hash);
5143 if (exists $known_snapshot_formats{$format}{'compressor'}) {
5144 $cmd .= ' | ' . quote_command
(@{$known_snapshot_formats{$format}{'compressor'}});
5148 -type
=> $known_snapshot_formats{$format}{'type'},
5149 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
5150 -status
=> '200 OK');
5152 open my $fd, "-|", $cmd
5153 or die_error
(500, "Execute git-archive failed");
5154 binmode STDOUT
, ':raw';
5156 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5161 my $head = git_get_head_hash
($project);
5162 if (!defined $hash) {
5165 if (!defined $page) {
5168 my $refs = git_get_references
();
5170 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5172 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#commitlist >= 100);
5174 my ($patch_max) = gitweb_get_feature
('patches');
5176 if ($patch_max < 0 || @commitlist <= $patch_max) {
5177 $paging_nav .= " ⋅ " .
5178 $cgi->a({-href
=> href
(action
=>"patches", -replay
=>1)},
5184 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
5187 my %co = parse_commit
($hash);
5189 git_print_header_div
('summary', $project);
5190 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
5192 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
5193 for (my $i = 0; $i <= $to; $i++) {
5194 my %co = %{$commitlist[$i]};
5196 my $commit = $co{'id'};
5197 my $ref = format_ref_marker
($refs, $commit);
5198 my %ad = parse_date
($co{'author_epoch'});
5199 git_print_header_div
('commit',
5200 "<span class=\"age\">$co{'age_string'}</span>" .
5201 esc_html
($co{'title'}) . $ref,
5203 print "<div class=\"title_text\">\n" .
5204 "<div class=\"log_link\">\n" .
5205 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
5207 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
5209 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
5212 git_print_authorship
(\
%co, -tag
=> 'span');
5213 print "<br/>\n</div>\n";
5215 print "<div class=\"log_body\">\n";
5216 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
5219 if ($#commitlist >= 100) {
5220 print "<div class=\"page_nav\">\n";
5221 print $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5222 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5229 $hash ||= $hash_base || "HEAD";
5230 my %co = parse_commit
($hash)
5231 or die_error
(404, "Unknown commit object");
5233 my $parent = $co{'parent'};
5234 my $parents = $co{'parents'}; # listref
5236 # we need to prepare $formats_nav before any parameter munging
5238 if (!defined $parent) {
5240 $formats_nav .= '(initial)';
5241 } elsif (@$parents == 1) {
5242 # single parent commit
5245 $cgi->a({-href
=> href
(action
=>"commit",
5247 esc_html
(substr($parent, 0, 7))) .
5254 $cgi->a({-href
=> href
(action
=>"commit",
5256 esc_html
(substr($_, 0, 7)));
5260 if (gitweb_check_feature
('patches')) {
5261 $formats_nav .= " | " .
5262 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
5266 if (!defined $parent) {
5270 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
5272 (@$parents <= 1 ? $parent : '-c'),
5274 or die_error
(500, "Open git-diff-tree failed");
5275 @difftree = map { chomp; $_ } <$fd>;
5276 close $fd or die_error
(404, "Reading git-diff-tree failed");
5278 # non-textual hash id's can be cached
5280 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5283 my $refs = git_get_references
();
5284 my $ref = format_ref_marker
($refs, $co{'id'});
5286 git_header_html
(undef, $expires);
5287 git_print_page_nav
('commit', '',
5288 $hash, $co{'tree'}, $hash,
5291 if (defined $co{'parent'}) {
5292 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
5294 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
5296 print "<div class=\"title_text\">\n" .
5297 "<table class=\"object_header\">\n";
5298 git_print_authorship_rows
(\
%co);
5299 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
5302 "<td class=\"sha1\">" .
5303 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
5304 class => "list"}, $co{'tree'}) .
5306 "<td class=\"link\">" .
5307 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
5309 my $snapshot_links = format_snapshot_links
($hash);
5310 if (defined $snapshot_links) {
5311 print " | " . $snapshot_links;
5316 foreach my $par (@$parents) {
5319 "<td class=\"sha1\">" .
5320 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
5321 class => "list"}, $par) .
5323 "<td class=\"link\">" .
5324 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
5326 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
5333 print "<div class=\"page_body\">\n";
5334 git_print_log
($co{'comment'});
5337 git_difftree_body
(\
@difftree, $hash, @$parents);
5343 # object is defined by:
5344 # - hash or hash_base alone
5345 # - hash_base and file_name
5348 # - hash or hash_base alone
5349 if ($hash || ($hash_base && !defined $file_name)) {
5350 my $object_id = $hash || $hash_base;
5352 open my $fd, "-|", quote_command
(
5353 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
5354 or die_error
(404, "Object does not exist");
5358 or die_error
(404, "Object does not exist");
5360 # - hash_base and file_name
5361 } elsif ($hash_base && defined $file_name) {
5362 $file_name =~ s
,/+$,,;
5364 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
5365 or die_error
(404, "Base object does not exist");
5367 # here errors should not hapen
5368 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
5369 or die_error
(500, "Open git-ls-tree failed");
5373 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
5374 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
5375 die_error
(404, "File or directory for given base does not exist");
5380 die_error
(400, "Not enough information to find object");
5383 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
5384 hash
=>$hash, hash_base
=>$hash_base,
5385 file_name
=>$file_name),
5386 -status
=> '302 Found');
5390 my $format = shift || 'html';
5397 # preparing $fd and %diffinfo for git_patchset_body
5399 if (defined $hash_base && defined $hash_parent_base) {
5400 if (defined $file_name) {
5402 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5403 $hash_parent_base, $hash_base,
5404 "--", (defined $file_parent ? $file_parent : ()), $file_name
5405 or die_error
(500, "Open git-diff-tree failed");
5406 @difftree = map { chomp; $_ } <$fd>;
5408 or die_error
(404, "Reading git-diff-tree failed");
5410 or die_error
(404, "Blob diff not found");
5412 } elsif (defined $hash &&
5413 $hash =~ /[0-9a-fA-F]{40}/) {
5414 # try to find filename from $hash
5416 # read filtered raw output
5417 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5418 $hash_parent_base, $hash_base, "--"
5419 or die_error
(500, "Open git-diff-tree failed");
5421 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
5423 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
5424 map { chomp; $_ } <$fd>;
5426 or die_error
(404, "Reading git-diff-tree failed");
5428 or die_error
(404, "Blob diff not found");
5431 die_error
(400, "Missing one of the blob diff parameters");
5434 if (@difftree > 1) {
5435 die_error
(400, "Ambiguous blob diff specification");
5438 %diffinfo = parse_difftree_raw_line
($difftree[0]);
5439 $file_parent ||= $diffinfo{'from_file'} || $file_name;
5440 $file_name ||= $diffinfo{'to_file'};
5442 $hash_parent ||= $diffinfo{'from_id'};
5443 $hash ||= $diffinfo{'to_id'};
5445 # non-textual hash id's can be cached
5446 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
5447 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
5452 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5453 '-p', ($format eq 'html' ? "--full-index" : ()),
5454 $hash_parent_base, $hash_base,
5455 "--", (defined $file_parent ? $file_parent : ()), $file_name
5456 or die_error
(500, "Open git-diff-tree failed");
5459 # old/legacy style URI -- not generated anymore since 1.4.3.
5461 die_error
('404 Not Found', "Missing one of the blob diff parameters")
5465 if ($format eq 'html') {
5467 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
5469 git_header_html
(undef, $expires);
5470 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5471 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5472 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5474 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
5475 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
5477 if (defined $file_name) {
5478 git_print_page_path
($file_name, "blob", $hash_base);
5480 print "<div class=\"page_path\"></div>\n";
5483 } elsif ($format eq 'plain') {
5485 -type
=> 'text/plain',
5486 -charset
=> 'utf-8',
5487 -expires
=> $expires,
5488 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
5490 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5493 die_error
(400, "Unknown blobdiff format");
5497 if ($format eq 'html') {
5498 print "<div class=\"page_body\">\n";
5500 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
5503 print "</div>\n"; # class="page_body"
5507 while (my $line = <$fd>) {
5508 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
5509 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
5513 last if $line =~ m!^\+\+\+!;
5521 sub git_blobdiff_plain
{
5522 git_blobdiff
('plain');
5525 sub git_commitdiff
{
5527 my $format = $params{-format
} || 'html';
5529 my ($patch_max) = gitweb_get_feature
('patches');
5530 if ($format eq 'patch') {
5531 die_error
(403, "Patch view not allowed") unless $patch_max;
5534 $hash ||= $hash_base || "HEAD";
5535 my %co = parse_commit
($hash)
5536 or die_error
(404, "Unknown commit object");
5538 # choose format for commitdiff for merge
5539 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
5540 $hash_parent = '--cc';
5542 # we need to prepare $formats_nav before almost any parameter munging
5544 if ($format eq 'html') {
5546 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
5549 $formats_nav .= " | " .
5550 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
5554 if (defined $hash_parent &&
5555 $hash_parent ne '-c' && $hash_parent ne '--cc') {
5556 # commitdiff with two commits given
5557 my $hash_parent_short = $hash_parent;
5558 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5559 $hash_parent_short = substr($hash_parent, 0, 7);
5563 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
5564 if ($co{'parents'}[$i] eq $hash_parent) {
5565 $formats_nav .= ' parent ' . ($i+1);
5569 $formats_nav .= ': ' .
5570 $cgi->a({-href
=> href
(action
=>"commitdiff",
5571 hash
=>$hash_parent)},
5572 esc_html
($hash_parent_short)) .
5574 } elsif (!$co{'parent'}) {
5576 $formats_nav .= ' (initial)';
5577 } elsif (scalar @{$co{'parents'}} == 1) {
5578 # single parent commit
5581 $cgi->a({-href
=> href
(action
=>"commitdiff",
5582 hash
=>$co{'parent'})},
5583 esc_html
(substr($co{'parent'}, 0, 7))) .
5587 if ($hash_parent eq '--cc') {
5588 $formats_nav .= ' | ' .
5589 $cgi->a({-href
=> href
(action
=>"commitdiff",
5590 hash
=>$hash, hash_parent
=>'-c')},
5592 } else { # $hash_parent eq '-c'
5593 $formats_nav .= ' | ' .
5594 $cgi->a({-href
=> href
(action
=>"commitdiff",
5595 hash
=>$hash, hash_parent
=>'--cc')},
5601 $cgi->a({-href
=> href
(action
=>"commitdiff",
5603 esc_html
(substr($_, 0, 7)));
5604 } @{$co{'parents'}} ) .
5609 my $hash_parent_param = $hash_parent;
5610 if (!defined $hash_parent_param) {
5611 # --cc for multiple parents, --root for parentless
5612 $hash_parent_param =
5613 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
5619 if ($format eq 'html') {
5620 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5621 "--no-commit-id", "--patch-with-raw", "--full-index",
5622 $hash_parent_param, $hash, "--"
5623 or die_error
(500, "Open git-diff-tree failed");
5625 while (my $line = <$fd>) {
5627 # empty line ends raw part of diff-tree output
5629 push @difftree, scalar parse_difftree_raw_line
($line);
5632 } elsif ($format eq 'plain') {
5633 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5634 '-p', $hash_parent_param, $hash, "--"
5635 or die_error
(500, "Open git-diff-tree failed");
5636 } elsif ($format eq 'patch') {
5637 # For commit ranges, we limit the output to the number of
5638 # patches specified in the 'patches' feature.
5639 # For single commits, we limit the output to a single patch,
5640 # diverging from the git-format-patch default.
5641 my @commit_spec = ();
5643 if ($patch_max > 0) {
5644 push @commit_spec, "-$patch_max";
5646 push @commit_spec, '-n', "$hash_parent..$hash";
5648 if ($params{-single
}) {
5649 push @commit_spec, '-1';
5651 if ($patch_max > 0) {
5652 push @commit_spec, "-$patch_max";
5654 push @commit_spec, "-n";
5656 push @commit_spec, '--root', $hash;
5658 open $fd, "-|", git_cmd
(), "format-patch", '--encoding=utf8',
5659 '--stdout', @commit_spec
5660 or die_error
(500, "Open git-format-patch failed");
5662 die_error
(400, "Unknown commitdiff format");
5665 # non-textual hash id's can be cached
5667 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5671 # write commit message
5672 if ($format eq 'html') {
5673 my $refs = git_get_references
();
5674 my $ref = format_ref_marker
($refs, $co{'id'});
5676 git_header_html
(undef, $expires);
5677 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5678 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
5679 print "<div class=\"title_text\">\n" .
5680 "<table class=\"object_header\">\n";
5681 git_print_authorship_rows
(\
%co);
5684 print "<div class=\"page_body\">\n";
5685 if (@{$co{'comment'}} > 1) {
5686 print "<div class=\"log\">\n";
5687 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
5688 print "</div>\n"; # class="log"
5691 } elsif ($format eq 'plain') {
5692 my $refs = git_get_references
("tags");
5693 my $tagname = git_get_rev_name_tags
($hash);
5694 my $filename = basename
($project) . "-$hash.patch";
5697 -type
=> 'text/plain',
5698 -charset
=> 'utf-8',
5699 -expires
=> $expires,
5700 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5701 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5702 print "From: " . to_utf8
($co{'author'}) . "\n";
5703 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5704 print "Subject: " . to_utf8
($co{'title'}) . "\n";
5706 print "X-Git-Tag: $tagname\n" if $tagname;
5707 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5709 foreach my $line (@{$co{'comment'}}) {
5710 print to_utf8
($line) . "\n";
5713 } elsif ($format eq 'patch') {
5714 my $filename = basename
($project) . "-$hash.patch";
5717 -type
=> 'text/plain',
5718 -charset
=> 'utf-8',
5719 -expires
=> $expires,
5720 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5724 if ($format eq 'html') {
5725 my $use_parents = !defined $hash_parent ||
5726 $hash_parent eq '-c' || $hash_parent eq '--cc';
5727 git_difftree_body
(\
@difftree, $hash,
5728 $use_parents ? @{$co{'parents'}} : $hash_parent);
5731 git_patchset_body
($fd, \
@difftree, $hash,
5732 $use_parents ? @{$co{'parents'}} : $hash_parent);
5734 print "</div>\n"; # class="page_body"
5737 } elsif ($format eq 'plain') {
5741 or print "Reading git-diff-tree failed\n";
5742 } elsif ($format eq 'patch') {
5746 or print "Reading git-format-patch failed\n";
5750 sub git_commitdiff_plain
{
5751 git_commitdiff
(-format
=> 'plain');
5754 # format-patch-style patches
5756 git_commitdiff
(-format
=> 'patch', -single
=> 1);
5760 git_commitdiff
(-format
=> 'patch');
5764 if (!defined $hash_base) {
5765 $hash_base = git_get_head_hash
($project);
5767 if (!defined $page) {
5771 my %co = parse_commit
($hash_base)
5772 or die_error
(404, "Unknown commit object");
5774 my $refs = git_get_references
();
5775 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5777 my @commitlist = parse_commits
($hash_base, 101, (100 * $page),
5778 $file_name, "--full-history")
5779 or die_error
(404, "No such file or directory on given branch");
5781 if (!defined $hash && defined $file_name) {
5782 # some commits could have deleted file in question,
5783 # and not have it in tree, but one of them has to have it
5784 for (my $i = 0; $i <= @commitlist; $i++) {
5785 $hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
5786 last if defined $hash;
5789 if (defined $hash) {
5790 $ftype = git_get_type
($hash);
5792 if (!defined $ftype) {
5793 die_error
(500, "Unknown type of object");
5796 my $paging_nav = '';
5799 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5800 file_name
=>$file_name)},
5802 $paging_nav .= " ⋅ " .
5803 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5804 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5806 $paging_nav .= "first";
5807 $paging_nav .= " ⋅ prev";
5810 if ($#commitlist >= 100) {
5812 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5813 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5814 $paging_nav .= " ⋅ $next_link";
5816 $paging_nav .= " ⋅ next";
5820 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5821 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5822 git_print_page_path
($file_name, $ftype, $hash_base);
5824 git_history_body
(\
@commitlist, 0, 99,
5825 $refs, $hash_base, $ftype, $next_link);
5831 gitweb_check_feature
('search') or die_error
(403, "Search is disabled");
5832 if (!defined $searchtext) {
5833 die_error
(400, "Text field is empty");
5835 if (!defined $hash) {
5836 $hash = git_get_head_hash
($project);
5838 my %co = parse_commit
($hash);
5840 die_error
(404, "Unknown commit object");
5842 if (!defined $page) {
5846 $searchtype ||= 'commit';
5847 if ($searchtype eq 'pickaxe') {
5848 # pickaxe may take all resources of your box and run for several minutes
5849 # with every query - so decide by yourself how public you make this feature
5850 gitweb_check_feature
('pickaxe')
5851 or die_error
(403, "Pickaxe is disabled");
5853 if ($searchtype eq 'grep') {
5854 gitweb_check_feature
('grep')[0]
5855 or die_error
(403, "Grep is disabled");
5860 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5862 if ($searchtype eq 'commit') {
5863 $greptype = "--grep=";
5864 } elsif ($searchtype eq 'author') {
5865 $greptype = "--author=";
5866 } elsif ($searchtype eq 'committer') {
5867 $greptype = "--committer=";
5869 $greptype .= $searchtext;
5870 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
5871 $greptype, '--regexp-ignore-case',
5872 $search_use_regexp ? '--extended-regexp' : '--fixed-strings');
5874 my $paging_nav = '';
5877 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5878 searchtext
=>$searchtext,
5879 searchtype
=>$searchtype)},
5881 $paging_nav .= " ⋅ " .
5882 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5883 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5885 $paging_nav .= "first";
5886 $paging_nav .= " ⋅ prev";
5889 if ($#commitlist >= 100) {
5891 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5892 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5893 $paging_nav .= " ⋅ $next_link";
5895 $paging_nav .= " ⋅ next";
5898 if ($#commitlist >= 100) {
5901 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5902 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5903 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5906 if ($searchtype eq 'pickaxe') {
5907 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5908 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5910 print "<table class=\"pickaxe search\">\n";
5913 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
5914 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
5915 ($search_use_regexp ? '--pickaxe-regex' : ());
5918 while (my $line = <$fd>) {
5922 my %set = parse_difftree_raw_line
($line);
5923 if (defined $set{'commit'}) {
5924 # finish previous commit
5927 "<td class=\"link\">" .
5928 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5930 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5936 print "<tr class=\"dark\">\n";
5938 print "<tr class=\"light\">\n";
5941 %co = parse_commit
($set{'commit'});
5942 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
5943 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5944 "<td><i>$author</i></td>\n" .
5946 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5947 -class => "list subject"},
5948 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
5949 } elsif (defined $set{'to_id'}) {
5950 next if ($set{'to_id'} =~ m/^0{40}$/);
5952 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5953 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
5955 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5961 # finish last commit (warning: repetition!)
5964 "<td class=\"link\">" .
5965 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5967 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5975 if ($searchtype eq 'grep') {
5976 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5977 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5979 print "<table class=\"grep_search\">\n";
5983 open my $fd, "-|", git_cmd
(), 'grep', '-n',
5984 $search_use_regexp ? ('-E', '-i') : '-F',
5985 $searchtext, $co{'tree'};
5987 while (my $line = <$fd>) {
5989 my ($file, $lno, $ltext, $binary);
5990 last if ($matches++ > 1000);
5991 if ($line =~ /^Binary file (.+) matches$/) {
5995 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5997 if ($file ne $lastfile) {
5998 $lastfile and print "</td></tr>\n";
6000 print "<tr class=\"dark\">\n";
6002 print "<tr class=\"light\">\n";
6004 print "<td class=\"list\">".
6005 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6006 file_name
=>"$file"),
6007 -class => "list"}, esc_path
($file));
6008 print "</td><td>\n";
6012 print "<div class=\"binary\">Binary file</div>\n";
6014 $ltext = untabify
($ltext);
6015 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
6016 $ltext = esc_html
($1, -nbsp
=>1);
6017 $ltext .= '<span class="match">';
6018 $ltext .= esc_html
($2, -nbsp
=>1);
6019 $ltext .= '</span>';
6020 $ltext .= esc_html
($3, -nbsp
=>1);
6022 $ltext = esc_html
($ltext, -nbsp
=>1);
6024 print "<div class=\"pre\">" .
6025 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6026 file_name
=>"$file").'#l'.$lno,
6027 -class => "linenr"}, sprintf('%4i', $lno))
6028 . ' ' . $ltext . "</div>\n";
6032 print "</td></tr>\n";
6033 if ($matches > 1000) {
6034 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
6037 print "<div class=\"diff nodifferences\">No matches found</div>\n";
6046 sub git_search_help
{
6048 git_print_page_nav
('','', $hash,$hash,$hash);
6050 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
6051 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
6052 the pattern entered is recognized as the POSIX extended
6053 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
6056 <dt><b>commit</b></dt>
6057 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
6059 my $have_grep = gitweb_check_feature
('grep');
6062 <dt><b>grep</b></dt>
6063 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
6064 a different one) are searched for the given pattern. On large trees, this search can take
6065 a while and put some strain on the server, so please use it with some consideration. Note that
6066 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
6067 case-sensitive.</dd>
6071 <dt><b>author</b></dt>
6072 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
6073 <dt><b>committer</b></dt>
6074 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
6076 my $have_pickaxe = gitweb_check_feature
('pickaxe');
6077 if ($have_pickaxe) {
6079 <dt><b>pickaxe</b></dt>
6080 <dd>All commits that caused the string to appear or disappear from any file (changes that
6081 added, removed or "modified" the string) will be listed. This search can take a while and
6082 takes a lot of strain on the server, so please use it wisely. Note that since you may be
6083 interested even in changes just changing the case as well, this search is case sensitive.</dd>
6091 my $head = git_get_head_hash
($project);
6092 if (!defined $hash) {
6095 if (!defined $page) {
6098 my $refs = git_get_references
();
6100 my $commit_hash = $hash;
6101 if (defined $hash_parent) {
6102 $commit_hash = "$hash_parent..$hash";
6104 my @commitlist = parse_commits
($commit_hash, 101, (100 * $page));
6106 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#commitlist >= 100);
6108 if ($#commitlist >= 100) {
6110 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
6111 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
6113 my $patch_max = gitweb_check_feature
('patches');
6115 if ($patch_max < 0 || @commitlist <= $patch_max) {
6116 $paging_nav .= " ⋅ " .
6117 $cgi->a({-href
=> href
(action
=>"patches", -replay
=>1)},
6123 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
6124 git_print_header_div
('summary', $project);
6126 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
6131 ## ......................................................................
6132 ## feeds (RSS, Atom; OPML)
6135 my $format = shift || 'atom';
6136 my $have_blame = gitweb_check_feature
('blame');
6138 # Atom: http://www.atomenabled.org/developers/syndication/
6139 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
6140 if ($format ne 'rss' && $format ne 'atom') {
6141 die_error
(400, "Unknown web feed format");
6144 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
6145 my $head = $hash || 'HEAD';
6146 my @commitlist = parse_commits
($head, 150, 0, $file_name);
6150 my $content_type = "application/$format+xml";
6151 if (defined $cgi->http('HTTP_ACCEPT') &&
6152 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
6153 # browser (feed reader) prefers text/xml
6154 $content_type = 'text/xml';
6156 if (defined($commitlist[0])) {
6157 %latest_commit = %{$commitlist[0]};
6158 my $latest_epoch = $latest_commit{'committer_epoch'};
6159 %latest_date = parse_date
($latest_epoch);
6160 my $if_modified = $cgi->http('IF_MODIFIED_SINCE');
6161 if (defined $if_modified) {
6163 if (eval { require HTTP
::Date
; 1; }) {
6164 $since = HTTP
::Date
::str2time
($if_modified);
6165 } elsif (eval { require Time
::ParseDate
; 1; }) {
6166 $since = Time
::ParseDate
::parsedate
($if_modified, GMT
=> 1);
6168 if (defined $since && $latest_epoch <= $since) {
6170 -type
=> $content_type,
6171 -charset
=> 'utf-8',
6172 -last_modified
=> $latest_date{'rfc2822'},
6173 -status
=> '304 Not Modified');
6178 -type
=> $content_type,
6179 -charset
=> 'utf-8',
6180 -last_modified
=> $latest_date{'rfc2822'});
6183 -type
=> $content_type,
6184 -charset
=> 'utf-8');
6187 # Optimization: skip generating the body if client asks only
6188 # for Last-Modified date.
6189 return if ($cgi->request_method() eq 'HEAD');
6192 my $title = "$site_name - $project/$action";
6193 my $feed_type = 'log';
6194 if (defined $hash) {
6195 $title .= " - '$hash'";
6196 $feed_type = 'branch log';
6197 if (defined $file_name) {
6198 $title .= " :: $file_name";
6199 $feed_type = 'history';
6201 } elsif (defined $file_name) {
6202 $title .= " - $file_name";
6203 $feed_type = 'history';
6205 $title .= " $feed_type";
6206 my $descr = git_get_project_description
($project);
6207 if (defined $descr) {
6208 $descr = esc_html
($descr);
6210 $descr = "$project " .
6211 ($format eq 'rss' ? 'RSS' : 'Atom') .
6214 my $owner = git_get_project_owner
($project);
6215 $owner = esc_html
($owner);
6219 if (defined $file_name) {
6220 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
6221 } elsif (defined $hash) {
6222 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
6224 $alt_url = href
(-full
=>1, action
=>"summary");
6226 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
6227 if ($format eq 'rss') {
6229 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
6232 print "<title>$title</title>\n" .
6233 "<link>$alt_url</link>\n" .
6234 "<description>$descr</description>\n" .
6235 "<language>en</language>\n" .
6236 # project owner is responsible for 'editorial' content
6237 "<managingEditor>$owner</managingEditor>\n";
6238 if (defined $logo || defined $favicon) {
6239 # prefer the logo to the favicon, since RSS
6240 # doesn't allow both
6241 my $img = esc_url
($logo || $favicon);
6243 "<url>$img</url>\n" .
6244 "<title>$title</title>\n" .
6245 "<link>$alt_url</link>\n" .
6249 print "<pubDate>$latest_date{'rfc2822'}</pubDate>\n";
6250 print "<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";
6252 print "<generator>gitweb v.$version/$git_version</generator>\n";
6253 } elsif ($format eq 'atom') {
6255 <feed xmlns="http://www.w3.org/2005/Atom">
6257 print "<title>$title</title>\n" .
6258 "<subtitle>$descr</subtitle>\n" .
6259 '<link rel="alternate" type="text/html" href="' .
6260 $alt_url . '" />' . "\n" .
6261 '<link rel="self" type="' . $content_type . '" href="' .
6262 $cgi->self_url() . '" />' . "\n" .
6263 "<id>" . href
(-full
=>1) . "</id>\n" .
6264 # use project owner for feed author
6265 "<author><name>$owner</name></author>\n";
6266 if (defined $favicon) {
6267 print "<icon>" . esc_url
($favicon) . "</icon>\n";
6269 if (defined $logo_url) {
6270 # not twice as wide as tall: 72 x 27 pixels
6271 print "<logo>" . esc_url
($logo) . "</logo>\n";
6273 if (! %latest_date) {
6274 # dummy date to keep the feed valid until commits trickle in:
6275 print "<updated>1970-01-01T00:00:00Z</updated>\n";
6277 print "<updated>$latest_date{'iso-8601'}</updated>\n";
6279 print "<generator version='$version/$git_version'>gitweb</generator>\n";
6283 for (my $i = 0; $i <= $#commitlist; $i++) {
6284 my %co = %{$commitlist[$i]};
6285 my $commit = $co{'id'};
6286 # we read 150, we always show 30 and the ones more recent than 48 hours
6287 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
6290 my %cd = parse_date
($co{'author_epoch'});
6292 # get list of changed files
6293 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6294 $co{'parent'} || "--root",
6295 $co{'id'}, "--", (defined $file_name ? $file_name : ())
6297 my @difftree = map { chomp; $_ } <$fd>;
6301 # print element (entry, item)
6302 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
6303 if ($format eq 'rss') {
6305 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
6306 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
6307 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
6308 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
6309 "<link>$co_url</link>\n" .
6310 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
6311 "<content:encoded>" .
6313 } elsif ($format eq 'atom') {
6315 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
6316 "<updated>$cd{'iso-8601'}</updated>\n" .
6318 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
6319 if ($co{'author_email'}) {
6320 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
6322 print "</author>\n" .
6323 # use committer for contributor
6325 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
6326 if ($co{'committer_email'}) {
6327 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
6329 print "</contributor>\n" .
6330 "<published>$cd{'iso-8601'}</published>\n" .
6331 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
6332 "<id>$co_url</id>\n" .
6333 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
6334 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
6336 my $comment = $co{'comment'};
6338 foreach my $line (@$comment) {
6339 $line = esc_html
($line);
6342 print "</pre><ul>\n";
6343 foreach my $difftree_line (@difftree) {
6344 my %difftree = parse_difftree_raw_line
($difftree_line);
6345 next if !$difftree{'from_id'};
6347 my $file = $difftree{'file'} || $difftree{'to_file'};
6351 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
6352 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
6353 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
6354 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
6355 -title
=> "diff"}, 'D');
6357 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
6358 file_name
=>$file, hash_base
=>$commit),
6359 -title
=> "blame"}, 'B');
6361 # if this is not a feed of a file history
6362 if (!defined $file_name || $file_name ne $file) {
6363 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
6364 file_name
=>$file, hash
=>$commit),
6365 -title
=> "history"}, 'H');
6367 $file = esc_path
($file);
6371 if ($format eq 'rss') {
6372 print "</ul>]]>\n" .
6373 "</content:encoded>\n" .
6375 } elsif ($format eq 'atom') {
6376 print "</ul>\n</div>\n" .
6383 if ($format eq 'rss') {
6384 print "</channel>\n</rss>\n";
6385 } elsif ($format eq 'atom') {
6399 my @list = git_get_projects_list
();
6402 -type
=> 'text/xml',
6403 -charset
=> 'utf-8',
6404 -content_disposition
=> 'inline; filename="opml.xml"');
6407 <?xml version="1.0" encoding="utf-8"?>
6408 <opml version="1.0">
6410 <title>$site_name OPML Export</title>
6413 <outline text="git RSS feeds">
6416 foreach my $pr (@list) {
6418 my $head = git_get_head_hash
($proj{'path'});
6419 if (!defined $head) {
6422 $git_dir = "$projectroot/$proj{'path'}";
6423 my %co = parse_commit
($head);
6428 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
6429 my $rss = href
('project' => $proj{'path'}, 'action' => 'rss', -full
=> 1);
6430 my $html = href
('project' => $proj{'path'}, 'action' => 'summary', -full
=> 1);
6431 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";