3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI
qw(:standard :escapeHTML -nosticky);
13 use CGI
::Util
qw(unescape);
14 use CGI
::Carp
qw(fatalsToBrowser);
18 use File
::Basename
qw(basename);
19 binmode STDOUT
, ':utf8';
22 CGI
->compile() if $ENV{'MOD_PERL'};
26 our $version = "++GIT_VERSION++";
27 our $my_url = $cgi->url();
28 our $my_uri = $cgi->url(-absolute
=> 1);
30 # Base URL for relative URLs in gitweb ($logo, $favicon, ...),
31 # needed and used only for URLs with nonempty PATH_INFO
32 our $base_url = $my_url;
34 # When the script is used as DirectoryIndex, the URL does not contain the name
35 # of the script file itself, and $cgi->url() fails to strip PATH_INFO, so we
36 # have to do it ourselves. We make $path_info global because it's also used
39 # Another issue with the script being the DirectoryIndex is that the resulting
40 # $my_url data is not the full script URL: this is good, because we want
41 # generated links to keep implying the script name if it wasn't explicitly
42 # indicated in the URL we're handling, but it means that $my_url cannot be used
44 # Therefore, if we needed to strip PATH_INFO, then we know that we have
45 # to build the base URL ourselves:
46 our $path_info = $ENV{"PATH_INFO"};
48 if ($my_url =~ s
,\Q
$path_info\E
$,, &&
49 $my_uri =~ s
,\Q
$path_info\E
$,, &&
50 defined $ENV{'SCRIPT_NAME'}) {
51 $base_url = $cgi->url(-base
=> 1) . $ENV{'SCRIPT_NAME'};
55 # core git executable to use
56 # this can just be "git" if your webserver has a sensible PATH
57 our $GIT = "++GIT_BINDIR++/git";
59 # absolute fs-path which will be prepended to the project path
60 #our $projectroot = "/pub/scm";
61 our $projectroot = "++GITWEB_PROJECTROOT++";
63 # fs traversing limit for getting project list
64 # the number is relative to the projectroot
65 our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
67 # target of the home link on top of all pages
68 our $home_link = $my_uri || "/";
70 # string of the home link on top of all pages
71 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
73 # name of your site or organization to appear in page titles
74 # replace this with something more descriptive for clearer bookmarks
75 our $site_name = "++GITWEB_SITENAME++"
76 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
78 # filename of html text to include at top of each page
79 our $site_header = "++GITWEB_SITE_HEADER++";
80 # html text to include at home page
81 our $home_text = "++GITWEB_HOMETEXT++";
82 # filename of html text to include at bottom of each page
83 our $site_footer = "++GITWEB_SITE_FOOTER++";
86 our @stylesheets = ("++GITWEB_CSS++");
87 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
88 our $stylesheet = undef;
89 # URI of GIT logo (72x27 size)
90 our $logo = "++GITWEB_LOGO++";
91 # URI of GIT favicon, assumed to be image/png type
92 our $favicon = "++GITWEB_FAVICON++";
94 # URI and label (title) of GIT logo link
95 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
96 #our $logo_label = "git documentation";
97 our $logo_url = "http://git.or.cz/";
98 our $logo_label = "git homepage";
100 # source of projects list
101 our $projects_list = "++GITWEB_LIST++";
103 # the width (in characters) of the projects list "Description" column
104 our $projects_list_description_width = 25;
106 # default order of projects list
107 # valid values are none, project, descr, owner, and age
108 our $default_projects_order = "project";
110 # show repository only if this file exists
111 # (only effective if this variable evaluates to true)
112 our $export_ok = "++GITWEB_EXPORT_OK++";
114 # show repository only if this subroutine returns true
115 # when given the path to the project, for example:
116 # sub { return -e "$_[0]/git-daemon-export-ok"; }
117 our $export_auth_hook = undef;
119 # only allow viewing of repositories also shown on the overview page
120 our $strict_export = "++GITWEB_STRICT_EXPORT++";
122 # list of git base URLs used for URL to where fetch project from,
123 # i.e. full URL is "$git_base_url/$project"
124 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
126 # default blob_plain mimetype and default charset for text/plain blob
127 our $default_blob_plain_mimetype = 'text/plain';
128 our $default_text_plain_charset = undef;
130 # file to use for guessing MIME types before trying /etc/mime.types
131 # (relative to the current git repository)
132 our $mimetypes_file = undef;
134 # assume this charset if line contains non-UTF-8 characters;
135 # it should be valid encoding (see Encoding::Supported(3pm) for list),
136 # for which encoding all byte sequences are valid, for example
137 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
138 # could be even 'utf-8' for the old behavior)
139 our $fallback_encoding = 'latin1';
141 # rename detection options for git-diff and git-diff-tree
142 # - default is '-M', with the cost proportional to
143 # (number of removed files) * (number of new files).
144 # - more costly is '-C' (which implies '-M'), with the cost proportional to
145 # (number of changed files + number of removed files) * (number of new files)
146 # - even more costly is '-C', '--find-copies-harder' with cost
147 # (number of files in the original tree) * (number of new files)
148 # - one might want to include '-B' option, e.g. '-B', '-M'
149 our @diff_opts = ('-M'); # taken from git_commit
151 # Disables features that would allow repository owners to inject script into
153 our $prevent_xss = 0;
155 # information about snapshot formats that gitweb is capable of serving
156 our %known_snapshot_formats = (
158 # 'display' => display name,
159 # 'type' => mime type,
160 # 'suffix' => filename suffix,
161 # 'format' => --format for git-archive,
162 # 'compressor' => [compressor command and arguments]
163 # (array reference, optional)}
166 'display' => 'tar.gz',
167 'type' => 'application/x-gzip',
168 'suffix' => '.tar.gz',
170 'compressor' => ['gzip']},
173 'display' => 'tar.bz2',
174 'type' => 'application/x-bzip2',
175 'suffix' => '.tar.bz2',
177 'compressor' => ['bzip2']},
181 'type' => 'application/x-zip',
186 # Aliases so we understand old gitweb.snapshot values in repository
188 our %known_snapshot_format_aliases = (
192 # backward compatibility: legacy gitweb config support
193 'x-gzip' => undef, 'gz' => undef,
194 'x-bzip2' => undef, 'bz2' => undef,
195 'x-zip' => undef, '' => undef,
198 # You define site-wide feature defaults here; override them with
199 # $GITWEB_CONFIG as necessary.
202 # 'sub' => feature-sub (subroutine),
203 # 'override' => allow-override (boolean),
204 # 'default' => [ default options...] (array reference)}
206 # if feature is overridable (it means that allow-override has true value),
207 # then feature-sub will be called with default options as parameters;
208 # return value of feature-sub indicates if to enable specified feature
210 # if there is no 'sub' key (no feature-sub), then feature cannot be
213 # use gitweb_get_feature(<feature>) to retrieve the <feature> value
214 # (an array) or gitweb_check_feature(<feature>) to check if <feature>
217 # Enable the 'blame' blob view, showing the last commit that modified
218 # each line in the file. This can be very CPU-intensive.
220 # To enable system wide have in $GITWEB_CONFIG
221 # $feature{'blame'}{'default'} = [1];
222 # To have project specific config enable override in $GITWEB_CONFIG
223 # $feature{'blame'}{'override'} = 1;
224 # and in project config gitweb.blame = 0|1;
226 'sub' => sub { feature_bool
('blame', @_) },
230 # Enable the 'snapshot' link, providing a compressed archive of any
231 # tree. This can potentially generate high traffic if you have large
234 # Value is a list of formats defined in %known_snapshot_formats that
236 # To disable system wide have in $GITWEB_CONFIG
237 # $feature{'snapshot'}{'default'} = [];
238 # To have project specific config enable override in $GITWEB_CONFIG
239 # $feature{'snapshot'}{'override'} = 1;
240 # and in project config, a comma-separated list of formats or "none"
241 # to disable. Example: gitweb.snapshot = tbz2,zip;
243 'sub' => \
&feature_snapshot
,
245 'default' => ['tgz']},
247 # Enable text search, which will list the commits which match author,
248 # committer or commit text to a given string. Enabled by default.
249 # Project specific override is not supported.
254 # Enable grep search, which will list the files in currently selected
255 # tree containing the given string. Enabled by default. This can be
256 # potentially CPU-intensive, of course.
258 # To enable system wide have in $GITWEB_CONFIG
259 # $feature{'grep'}{'default'} = [1];
260 # To have project specific config enable override in $GITWEB_CONFIG
261 # $feature{'grep'}{'override'} = 1;
262 # and in project config gitweb.grep = 0|1;
264 'sub' => sub { feature_bool
('grep', @_) },
268 # Enable the pickaxe search, which will list the commits that modified
269 # a given string in a file. This can be practical and quite faster
270 # alternative to 'blame', but still potentially CPU-intensive.
272 # To enable system wide have in $GITWEB_CONFIG
273 # $feature{'pickaxe'}{'default'} = [1];
274 # To have project specific config enable override in $GITWEB_CONFIG
275 # $feature{'pickaxe'}{'override'} = 1;
276 # and in project config gitweb.pickaxe = 0|1;
278 'sub' => sub { feature_bool
('pickaxe', @_) },
282 # Make gitweb use an alternative format of the URLs which can be
283 # more readable and natural-looking: project name is embedded
284 # directly in the path and the query string contains other
285 # auxiliary information. All gitweb installations recognize
286 # URL in either format; this configures in which formats gitweb
289 # To enable system wide have in $GITWEB_CONFIG
290 # $feature{'pathinfo'}{'default'} = [1];
291 # Project specific override is not supported.
293 # Note that you will need to change the default location of CSS,
294 # favicon, logo and possibly other files to an absolute URL. Also,
295 # if gitweb.cgi serves as your indexfile, you will need to force
296 # $my_uri to contain the script name in your $GITWEB_CONFIG.
301 # Make gitweb consider projects in project root subdirectories
302 # to be forks of existing projects. Given project $projname.git,
303 # projects matching $projname/*.git will not be shown in the main
304 # projects list, instead a '+' mark will be added to $projname
305 # there and a 'forks' view will be enabled for the project, listing
306 # all the forks. If project list is taken from a file, forks have
307 # to be listed after the main project.
309 # To enable system wide have in $GITWEB_CONFIG
310 # $feature{'forks'}{'default'} = [1];
311 # Project specific override is not supported.
316 # Insert custom links to the action bar of all project pages.
317 # This enables you mainly to link to third-party scripts integrating
318 # into gitweb; e.g. git-browser for graphical history representation
319 # or custom web-based repository administration interface.
321 # The 'default' value consists of a list of triplets in the form
322 # (label, link, position) where position is the label after which
323 # to insert the link and link is a format string where %n expands
324 # to the project name, %f to the project path within the filesystem,
325 # %h to the current hash (h gitweb parameter) and %b to the current
326 # hash base (hb gitweb parameter); %% expands to %.
328 # To enable system wide have in $GITWEB_CONFIG e.g.
329 # $feature{'actions'}{'default'} = [('graphiclog',
330 # '/git-browser/by-commit.html?r=%n', 'summary')];
331 # Project specific override is not supported.
336 # Allow gitweb scan project content tags described in ctags/
337 # of project repository, and display the popular Web 2.0-ish
338 # "tag cloud" near the project list. Note that this is something
339 # COMPLETELY different from the normal Git tags.
341 # gitweb by itself can show existing tags, but it does not handle
342 # tagging itself; you need an external application for that.
343 # For an example script, check Girocco's cgi/tagproj.cgi.
344 # You may want to install the HTML::TagCloud Perl module to get
345 # a pretty tag cloud instead of just a list of tags.
347 # To enable system wide have in $GITWEB_CONFIG
348 # $feature{'ctags'}{'default'} = ['path_to_tag_script'];
349 # Project specific override is not supported.
354 # The maximum number of patches in a patchset generated in patch
355 # view. Set this to 0 or undef to disable patch view, or to a
356 # negative number to remove any limit.
358 # To disable system wide have in $GITWEB_CONFIG
359 # $feature{'patches'}{'default'} = [0];
360 # To have project specific config enable override in $GITWEB_CONFIG
361 # $feature{'patches'}{'override'} = 1;
362 # and in project config gitweb.patches = 0|n;
363 # where n is the maximum number of patches allowed in a patchset.
365 'sub' => \
&feature_patches
,
370 sub gitweb_get_feature
{
372 return unless exists $feature{$name};
373 my ($sub, $override, @defaults) = (
374 $feature{$name}{'sub'},
375 $feature{$name}{'override'},
376 @
{$feature{$name}{'default'}});
377 if (!$override) { return @defaults; }
379 warn "feature $name is not overrideable";
382 return $sub->(@defaults);
385 # A wrapper to check if a given feature is enabled.
386 # With this, you can say
388 # my $bool_feat = gitweb_check_feature('bool_feat');
389 # gitweb_check_feature('bool_feat') or somecode;
393 # my ($bool_feat) = gitweb_get_feature('bool_feat');
394 # (gitweb_get_feature('bool_feat'))[0] or somecode;
396 sub gitweb_check_feature
{
397 return (gitweb_get_feature
(@_))[0];
403 my ($val) = git_get_project_config
($key, '--bool');
407 } elsif ($val eq 'true') {
409 } elsif ($val eq 'false') {
414 sub feature_snapshot
{
417 my ($val) = git_get_project_config
('snapshot');
420 @fmts = ($val eq 'none' ?
() : split /\s*[,\s]\s*/, $val);
426 sub feature_patches
{
427 my @val = (git_get_project_config
('patches', '--int'));
436 # checking HEAD file with -e is fragile if the repository was
437 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
439 sub check_head_link
{
441 my $headfile = "$dir/HEAD";
442 return ((-e
$headfile) ||
443 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
446 sub check_export_ok
{
448 return (check_head_link
($dir) &&
449 (!$export_ok || -e
"$dir/$export_ok") &&
450 (!$export_auth_hook || $export_auth_hook->($dir)));
453 # process alternate names for backward compatibility
454 # filter out unsupported (unknown) snapshot formats
455 sub filter_snapshot_fmts
{
459 exists $known_snapshot_format_aliases{$_} ?
460 $known_snapshot_format_aliases{$_} : $_} @fmts;
461 @fmts = grep(exists $known_snapshot_formats{$_}, @fmts);
465 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
466 if (-e
$GITWEB_CONFIG) {
469 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
470 do $GITWEB_CONFIG_SYSTEM if -e
$GITWEB_CONFIG_SYSTEM;
473 # version of the core git binary
474 our $git_version = qx("$GIT" --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
476 $projects_list ||= $projectroot;
478 # ======================================================================
479 # input validation and dispatch
481 # input parameters can be collected from a variety of sources (presently, CGI
482 # and PATH_INFO), so we define an %input_params hash that collects them all
483 # together during validation: this allows subsequent uses (e.g. href()) to be
484 # agnostic of the parameter origin
486 our %input_params = ();
488 # input parameters are stored with the long parameter name as key. This will
489 # also be used in the href subroutine to convert parameters to their CGI
490 # equivalent, and since the href() usage is the most frequent one, we store
491 # the name -> CGI key mapping here, instead of the reverse.
493 # XXX: Warning: If you touch this, check the search form for updating,
496 our @cgi_param_mapping = (
504 hash_parent_base
=> "hpb",
509 snapshot_format
=> "sf",
510 extra_options
=> "opt",
511 search_use_regexp
=> "sr",
513 our %cgi_param_mapping = @cgi_param_mapping;
515 # we will also need to know the possible actions, for validation
517 "blame" => \
&git_blame
,
518 "blobdiff" => \
&git_blobdiff
,
519 "blobdiff_plain" => \
&git_blobdiff_plain
,
520 "blob" => \
&git_blob
,
521 "blob_plain" => \
&git_blob_plain
,
522 "commitdiff" => \
&git_commitdiff
,
523 "commitdiff_plain" => \
&git_commitdiff_plain
,
524 "commit" => \
&git_commit
,
525 "forks" => \
&git_forks
,
526 "heads" => \
&git_heads
,
527 "history" => \
&git_history
,
529 "patch" => \
&git_patch
,
530 "patches" => \
&git_patches
,
532 "atom" => \
&git_atom
,
533 "search" => \
&git_search
,
534 "search_help" => \
&git_search_help
,
535 "shortlog" => \
&git_shortlog
,
536 "summary" => \
&git_summary
,
538 "tags" => \
&git_tags
,
539 "tree" => \
&git_tree
,
540 "snapshot" => \
&git_snapshot
,
541 "object" => \
&git_object
,
542 # those below don't need $project
543 "opml" => \
&git_opml
,
544 "project_list" => \
&git_project_list
,
545 "project_index" => \
&git_project_index
,
548 # finally, we have the hash of allowed extra_options for the commands that
550 our %allowed_options = (
551 "--no-merges" => [ qw(rss atom log shortlog history) ],
554 # fill %input_params with the CGI parameters. All values except for 'opt'
555 # should be single values, but opt can be an array. We should probably
556 # build an array of parameters that can be multi-valued, but since for the time
557 # being it's only this one, we just single it out
558 while (my ($name, $symbol) = each %cgi_param_mapping) {
559 if ($symbol eq 'opt') {
560 $input_params{$name} = [ $cgi->param($symbol) ];
562 $input_params{$name} = $cgi->param($symbol);
566 # now read PATH_INFO and update the parameter list for missing parameters
567 sub evaluate_path_info
{
568 return if defined $input_params{'project'};
569 return if !$path_info;
570 $path_info =~ s
,^/+,,;
571 return if !$path_info;
573 # find which part of PATH_INFO is project
574 my $project = $path_info;
576 while ($project && !check_head_link
("$projectroot/$project")) {
577 $project =~ s
,/*[^/]*$,,;
579 return unless $project;
580 $input_params{'project'} = $project;
582 # do not change any parameters if an action is given using the query string
583 return if $input_params{'action'};
584 $path_info =~ s
,^\Q
$project\E
/*,,;
586 # next, check if we have an action
587 my $action = $path_info;
589 if (exists $actions{$action}) {
590 $path_info =~ s
,^$action/*,,;
591 $input_params{'action'} = $action;
594 # list of actions that want hash_base instead of hash, but can have no
595 # pathname (f) parameter
602 # [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name]
603 my ($parentrefname, $parentpathname, $refname, $pathname) =
604 ($path_info =~ /^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/);
606 # first, analyze the 'current' part
607 if (defined $pathname) {
608 # we got "branch:filename" or "branch:dir/"
609 # we could use git_get_type(branch:pathname), but:
610 # - it needs $git_dir
611 # - it does a git() call
612 # - the convention of terminating directories with a slash
613 # makes it superfluous
614 # - embedding the action in the PATH_INFO would make it even
616 $pathname =~ s
,^/+,,;
617 if (!$pathname || substr($pathname, -1) eq "/") {
618 $input_params{'action'} ||= "tree";
621 # the default action depends on whether we had parent info
623 if ($parentrefname) {
624 $input_params{'action'} ||= "blobdiff_plain";
626 $input_params{'action'} ||= "blob_plain";
629 $input_params{'hash_base'} ||= $refname;
630 $input_params{'file_name'} ||= $pathname;
631 } elsif (defined $refname) {
632 # we got "branch". In this case we have to choose if we have to
633 # set hash or hash_base.
635 # Most of the actions without a pathname only want hash to be
636 # set, except for the ones specified in @wants_base that want
637 # hash_base instead. It should also be noted that hand-crafted
638 # links having 'history' as an action and no pathname or hash
639 # set will fail, but that happens regardless of PATH_INFO.
640 $input_params{'action'} ||= "shortlog";
641 if (grep { $_ eq $input_params{'action'} } @wants_base) {
642 $input_params{'hash_base'} ||= $refname;
644 $input_params{'hash'} ||= $refname;
648 # next, handle the 'parent' part, if present
649 if (defined $parentrefname) {
650 # a missing pathspec defaults to the 'current' filename, allowing e.g.
651 # someproject/blobdiff/oldrev..newrev:/filename
652 if ($parentpathname) {
653 $parentpathname =~ s
,^/+,,;
654 $parentpathname =~ s
,/$,,;
655 $input_params{'file_parent'} ||= $parentpathname;
657 $input_params{'file_parent'} ||= $input_params{'file_name'};
659 # we assume that hash_parent_base is wanted if a path was specified,
660 # or if the action wants hash_base instead of hash
661 if (defined $input_params{'file_parent'} ||
662 grep { $_ eq $input_params{'action'} } @wants_base) {
663 $input_params{'hash_parent_base'} ||= $parentrefname;
665 $input_params{'hash_parent'} ||= $parentrefname;
669 # for the snapshot action, we allow URLs in the form
670 # $project/snapshot/$hash.ext
671 # where .ext determines the snapshot and gets removed from the
672 # passed $refname to provide the $hash.
674 # To be able to tell that $refname includes the format extension, we
675 # require the following two conditions to be satisfied:
676 # - the hash input parameter MUST have been set from the $refname part
677 # of the URL (i.e. they must be equal)
678 # - the snapshot format MUST NOT have been defined already (e.g. from
680 # It's also useless to try any matching unless $refname has a dot,
681 # so we check for that too
682 if (defined $input_params{'action'} &&
683 $input_params{'action'} eq 'snapshot' &&
684 defined $refname && index($refname, '.') != -1 &&
685 $refname eq $input_params{'hash'} &&
686 !defined $input_params{'snapshot_format'}) {
687 # We loop over the known snapshot formats, checking for
688 # extensions. Allowed extensions are both the defined suffix
689 # (which includes the initial dot already) and the snapshot
690 # format key itself, with a prepended dot
691 while (my ($fmt, %opt) = each %known_snapshot_formats) {
694 $hash =~ s/(\Q$opt{'suffix'}\E|\Q.$fmt\E)$//;
695 next unless $sfx = $1;
696 # a valid suffix was found, so set the snapshot format
697 # and reset the hash parameter
698 $input_params{'snapshot_format'} = $fmt;
699 $input_params{'hash'} = $hash;
700 # we also set the format suffix to the one requested
701 # in the URL: this way a request for e.g. .tgz returns
702 # a .tgz instead of a .tar.gz
703 $known_snapshot_formats{$fmt}{'suffix'} = $sfx;
708 evaluate_path_info
();
710 our $action = $input_params{'action'};
711 if (defined $action) {
712 if (!validate_action
($action)) {
713 die_error
(400, "Invalid action parameter");
717 # parameters which are pathnames
718 our $project = $input_params{'project'};
719 if (defined $project) {
720 if (!validate_project
($project)) {
722 die_error
(404, "No such project");
726 our $file_name = $input_params{'file_name'};
727 if (defined $file_name) {
728 if (!validate_pathname
($file_name)) {
729 die_error
(400, "Invalid file parameter");
733 our $file_parent = $input_params{'file_parent'};
734 if (defined $file_parent) {
735 if (!validate_pathname
($file_parent)) {
736 die_error
(400, "Invalid file parent parameter");
740 # parameters which are refnames
741 our $hash = $input_params{'hash'};
743 if (!validate_refname
($hash)) {
744 die_error
(400, "Invalid hash parameter");
748 our $hash_parent = $input_params{'hash_parent'};
749 if (defined $hash_parent) {
750 if (!validate_refname
($hash_parent)) {
751 die_error
(400, "Invalid hash parent parameter");
755 our $hash_base = $input_params{'hash_base'};
756 if (defined $hash_base) {
757 if (!validate_refname
($hash_base)) {
758 die_error
(400, "Invalid hash base parameter");
762 our @extra_options = @
{$input_params{'extra_options'}};
763 # @extra_options is always defined, since it can only be (currently) set from
764 # CGI, and $cgi->param() returns the empty array in array context if the param
766 foreach my $opt (@extra_options) {
767 if (not exists $allowed_options{$opt}) {
768 die_error
(400, "Invalid option parameter");
770 if (not grep(/^$action$/, @
{$allowed_options{$opt}})) {
771 die_error
(400, "Invalid option parameter for this action");
775 our $hash_parent_base = $input_params{'hash_parent_base'};
776 if (defined $hash_parent_base) {
777 if (!validate_refname
($hash_parent_base)) {
778 die_error
(400, "Invalid hash parent base parameter");
783 our $page = $input_params{'page'};
785 if ($page =~ m/[^0-9]/) {
786 die_error
(400, "Invalid page parameter");
790 our $searchtype = $input_params{'searchtype'};
791 if (defined $searchtype) {
792 if ($searchtype =~ m/[^a-z]/) {
793 die_error
(400, "Invalid searchtype parameter");
797 our $search_use_regexp = $input_params{'search_use_regexp'};
799 our $searchtext = $input_params{'searchtext'};
801 if (defined $searchtext) {
802 if (length($searchtext) < 2) {
803 die_error
(403, "At least two characters are required for search parameter");
805 $search_regexp = $search_use_regexp ?
$searchtext : quotemeta $searchtext;
808 # path to the current git repository
810 $git_dir = "$projectroot/$project" if $project;
812 # list of supported snapshot formats
813 our @snapshot_fmts = gitweb_get_feature
('snapshot');
814 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
817 if (!defined $action) {
819 $action = git_get_type
($hash);
820 } elsif (defined $hash_base && defined $file_name) {
821 $action = git_get_type
("$hash_base:$file_name");
822 } elsif (defined $project) {
825 $action = 'project_list';
828 if (!defined($actions{$action})) {
829 die_error
(400, "Unknown action");
831 if ($action !~ m/^(opml|project_list|project_index)$/ &&
833 die_error
(400, "Project needed");
835 $actions{$action}->();
838 ## ======================================================================
843 # default is to use -absolute url() i.e. $my_uri
844 my $href = $params{-full
} ?
$my_url : $my_uri;
846 $params{'project'} = $project unless exists $params{'project'};
848 if ($params{-replay
}) {
849 while (my ($name, $symbol) = each %cgi_param_mapping) {
850 if (!exists $params{$name}) {
851 $params{$name} = $input_params{$name};
856 my $use_pathinfo = gitweb_check_feature
('pathinfo');
857 if ($use_pathinfo and defined $params{'project'}) {
858 # try to put as many parameters as possible in PATH_INFO:
861 # - hash_parent or hash_parent_base:/file_parent
862 # - hash or hash_base:/filename
863 # - the snapshot_format as an appropriate suffix
865 # When the script is the root DirectoryIndex for the domain,
866 # $href here would be something like http://gitweb.example.com/
867 # Thus, we strip any trailing / from $href, to spare us double
868 # slashes in the final URL
871 # Then add the project name, if present
872 $href .= "/".esc_url
($params{'project'});
873 delete $params{'project'};
875 # since we destructively absorb parameters, we keep this
876 # boolean that remembers if we're handling a snapshot
877 my $is_snapshot = $params{'action'} eq 'snapshot';
879 # Summary just uses the project path URL, any other action is
881 if (defined $params{'action'}) {
882 $href .= "/".esc_url
($params{'action'}) unless $params{'action'} eq 'summary';
883 delete $params{'action'};
886 # Next, we put hash_parent_base:/file_parent..hash_base:/file_name,
887 # stripping nonexistent or useless pieces
888 $href .= "/" if ($params{'hash_base'} || $params{'hash_parent_base'}
889 || $params{'hash_parent'} || $params{'hash'});
890 if (defined $params{'hash_base'}) {
891 if (defined $params{'hash_parent_base'}) {
892 $href .= esc_url
($params{'hash_parent_base'});
893 # skip the file_parent if it's the same as the file_name
894 delete $params{'file_parent'} if $params{'file_parent'} eq $params{'file_name'};
895 if (defined $params{'file_parent'} && $params{'file_parent'} !~ /\.\./) {
896 $href .= ":/".esc_url
($params{'file_parent'});
897 delete $params{'file_parent'};
900 delete $params{'hash_parent'};
901 delete $params{'hash_parent_base'};
902 } elsif (defined $params{'hash_parent'}) {
903 $href .= esc_url
($params{'hash_parent'}). "..";
904 delete $params{'hash_parent'};
907 $href .= esc_url
($params{'hash_base'});
908 if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) {
909 $href .= ":/".esc_url
($params{'file_name'});
910 delete $params{'file_name'};
912 delete $params{'hash'};
913 delete $params{'hash_base'};
914 } elsif (defined $params{'hash'}) {
915 $href .= esc_url
($params{'hash'});
916 delete $params{'hash'};
919 # If the action was a snapshot, we can absorb the
920 # snapshot_format parameter too
922 my $fmt = $params{'snapshot_format'};
923 # snapshot_format should always be defined when href()
924 # is called, but just in case some code forgets, we
925 # fall back to the default
926 $fmt ||= $snapshot_fmts[0];
927 $href .= $known_snapshot_formats{$fmt}{'suffix'};
928 delete $params{'snapshot_format'};
932 # now encode the parameters explicitly
934 for (my $i = 0; $i < @cgi_param_mapping; $i += 2) {
935 my ($name, $symbol) = ($cgi_param_mapping[$i], $cgi_param_mapping[$i+1]);
936 if (defined $params{$name}) {
937 if (ref($params{$name}) eq "ARRAY") {
938 foreach my $par (@
{$params{$name}}) {
939 push @result, $symbol . "=" . esc_param
($par);
942 push @result, $symbol . "=" . esc_param
($params{$name});
946 $href .= "?" . join(';', @result) if scalar @result;
952 ## ======================================================================
953 ## validation, quoting/unquoting and escaping
955 sub validate_action
{
956 my $input = shift || return undef;
957 return undef unless exists $actions{$input};
961 sub validate_project
{
962 my $input = shift || return undef;
963 if (!validate_pathname
($input) ||
964 !(-d
"$projectroot/$input") ||
965 !check_export_ok
("$projectroot/$input") ||
966 ($strict_export && !project_in_list
($input))) {
973 sub validate_pathname
{
974 my $input = shift || return undef;
976 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
977 # at the beginning, at the end, and between slashes.
978 # also this catches doubled slashes
979 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
983 if ($input =~ m!\0!) {
989 sub validate_refname
{
990 my $input = shift || return undef;
992 # textual hashes are O.K.
993 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
996 # it must be correct pathname
997 $input = validate_pathname
($input)
999 # restrictions on ref name according to git-check-ref-format
1000 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
1006 # decode sequences of octets in utf8 into Perl's internal form,
1007 # which is utf-8 with utf8 flag set if needed. gitweb writes out
1008 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
1011 if (utf8
::valid
($str)) {
1015 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
1019 # quote unsafe chars, but keep the slash, even when it's not
1020 # correct, but quoted slashes look too horrible in bookmarks
1023 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
1029 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
1032 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
1038 # replace invalid utf8 character with SUBSTITUTION sequence
1039 sub esc_html
($;%) {
1043 $str = to_utf8
($str);
1044 $str = $cgi->escapeHTML($str);
1045 if ($opts{'-nbsp'}) {
1046 $str =~ s/ / /g;
1048 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
1052 # quote control characters and escape filename to HTML
1057 $str = to_utf8
($str);
1058 $str = $cgi->escapeHTML($str);
1059 if ($opts{'-nbsp'}) {
1060 $str =~ s/ / /g;
1062 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
1066 # Make control characters "printable", using character escape codes (CEC)
1070 my %es = ( # character escape codes, aka escape sequences
1071 "\t" => '\t', # tab (HT)
1072 "\n" => '\n', # line feed (LF)
1073 "\r" => '\r', # carrige return (CR)
1074 "\f" => '\f', # form feed (FF)
1075 "\b" => '\b', # backspace (BS)
1076 "\a" => '\a', # alarm (bell) (BEL)
1077 "\e" => '\e', # escape (ESC)
1078 "\013" => '\v', # vertical tab (VT)
1079 "\000" => '\0', # nul character (NUL)
1081 my $chr = ( (exists $es{$cntrl})
1083 : sprintf('\%2x', ord($cntrl)) );
1084 if ($opts{-nohtml
}) {
1087 return "<span class=\"cntrl\">$chr</span>";
1091 # Alternatively use unicode control pictures codepoints,
1092 # Unicode "printable representation" (PR)
1097 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
1098 if ($opts{-nohtml
}) {
1101 return "<span class=\"cntrl\">$chr</span>";
1105 # git may return quoted and escaped filenames
1111 my %es = ( # character escape codes, aka escape sequences
1112 't' => "\t", # tab (HT, TAB)
1113 'n' => "\n", # newline (NL)
1114 'r' => "\r", # return (CR)
1115 'f' => "\f", # form feed (FF)
1116 'b' => "\b", # backspace (BS)
1117 'a' => "\a", # alarm (bell) (BEL)
1118 'e' => "\e", # escape (ESC)
1119 'v' => "\013", # vertical tab (VT)
1122 if ($seq =~ m/^[0-7]{1,3}$/) {
1123 # octal char sequence
1124 return chr(oct($seq));
1125 } elsif (exists $es{$seq}) {
1126 # C escape sequence, aka character escape code
1129 # quoted ordinary character
1133 if ($str =~ m/^"(.*)"$/) {
1136 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
1141 # escape tabs (convert tabs to spaces)
1145 while ((my $pos = index($line, "\t")) != -1) {
1146 if (my $count = (8 - ($pos % 8))) {
1147 my $spaces = ' ' x
$count;
1148 $line =~ s/\t/$spaces/;
1155 sub project_in_list
{
1156 my $project = shift;
1157 my @list = git_get_projects_list
();
1158 return @list && scalar(grep { $_->{'path'} eq $project } @list);
1161 ## ----------------------------------------------------------------------
1162 ## HTML aware string manipulation
1164 # Try to chop given string on a word boundary between position
1165 # $len and $len+$add_len. If there is no word boundary there,
1166 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
1167 # (marking chopped part) would be longer than given string.
1171 my $add_len = shift || 10;
1172 my $where = shift || 'right'; # 'left' | 'center' | 'right'
1174 # Make sure perl knows it is utf8 encoded so we don't
1175 # cut in the middle of a utf8 multibyte char.
1176 $str = to_utf8
($str);
1178 # allow only $len chars, but don't cut a word if it would fit in $add_len
1179 # if it doesn't fit, cut it if it's still longer than the dots we would add
1180 # remove chopped character entities entirely
1182 # when chopping in the middle, distribute $len into left and right part
1183 # return early if chopping wouldn't make string shorter
1184 if ($where eq 'center') {
1185 return $str if ($len + 5 >= length($str)); # filler is length 5
1188 return $str if ($len + 4 >= length($str)); # filler is length 4
1191 # regexps: ending and beginning with word part up to $add_len
1192 my $endre = qr/.{$len}\w{0,$add_len}/;
1193 my $begre = qr/\w{0,$add_len}.{$len}/;
1195 if ($where eq 'left') {
1196 $str =~ m/^(.*?)($begre)$/;
1197 my ($lead, $body) = ($1, $2);
1198 if (length($lead) > 4) {
1199 $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
1202 return "$lead$body";
1204 } elsif ($where eq 'center') {
1205 $str =~ m/^($endre)(.*)$/;
1206 my ($left, $str) = ($1, $2);
1207 $str =~ m/^(.*?)($begre)$/;
1208 my ($mid, $right) = ($1, $2);
1209 if (length($mid) > 5) {
1210 $left =~ s/&[^;]*$//;
1211 $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
1214 return "$left$mid$right";
1217 $str =~ m/^($endre)(.*)$/;
1220 if (length($tail) > 4) {
1221 $body =~ s/&[^;]*$//;
1224 return "$body$tail";
1228 # takes the same arguments as chop_str, but also wraps a <span> around the
1229 # result with a title attribute if it does get chopped. Additionally, the
1230 # string is HTML-escaped.
1231 sub chop_and_escape_str
{
1234 my $chopped = chop_str
(@_);
1235 if ($chopped eq $str) {
1236 return esc_html
($chopped);
1238 $str =~ s/([[:cntrl:]])/?/g;
1239 return $cgi->span({-title
=>$str}, esc_html
($chopped));
1243 ## ----------------------------------------------------------------------
1244 ## functions returning short strings
1246 # CSS class for given age value (in seconds)
1250 if (!defined $age) {
1252 } elsif ($age < 60*60*2) {
1254 } elsif ($age < 60*60*24*2) {
1261 # convert age in seconds to "nn units ago" string
1266 if ($age > 60*60*24*365*2) {
1267 $age_str = (int $age/60/60/24/365);
1268 $age_str .= " years ago";
1269 } elsif ($age > 60*60*24*(365/12)*2) {
1270 $age_str = int $age/60/60/24/(365/12);
1271 $age_str .= " months ago";
1272 } elsif ($age > 60*60*24*7*2) {
1273 $age_str = int $age/60/60/24/7;
1274 $age_str .= " weeks ago";
1275 } elsif ($age > 60*60*24*2) {
1276 $age_str = int $age/60/60/24;
1277 $age_str .= " days ago";
1278 } elsif ($age > 60*60*2) {
1279 $age_str = int $age/60/60;
1280 $age_str .= " hours ago";
1281 } elsif ($age > 60*2) {
1282 $age_str = int $age/60;
1283 $age_str .= " min ago";
1284 } elsif ($age > 2) {
1285 $age_str = int $age;
1286 $age_str .= " sec ago";
1288 $age_str .= " right now";
1294 S_IFINVALID
=> 0030000,
1295 S_IFGITLINK
=> 0160000,
1298 # submodule/subproject, a commit object reference
1299 sub S_ISGITLINK
($) {
1302 return (($mode & S_IFMT
) == S_IFGITLINK
)
1305 # convert file mode in octal to symbolic file mode string
1307 my $mode = oct shift;
1309 if (S_ISGITLINK
($mode)) {
1310 return 'm---------';
1311 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1312 return 'drwxr-xr-x';
1313 } elsif (S_ISLNK
($mode)) {
1314 return 'lrwxrwxrwx';
1315 } elsif (S_ISREG
($mode)) {
1316 # git cares only about the executable bit
1317 if ($mode & S_IXUSR
) {
1318 return '-rwxr-xr-x';
1320 return '-rw-r--r--';
1323 return '----------';
1327 # convert file mode in octal to file type string
1331 if ($mode !~ m/^[0-7]+$/) {
1337 if (S_ISGITLINK
($mode)) {
1339 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1341 } elsif (S_ISLNK
($mode)) {
1343 } elsif (S_ISREG
($mode)) {
1350 # convert file mode in octal to file type description string
1351 sub file_type_long
{
1354 if ($mode !~ m/^[0-7]+$/) {
1360 if (S_ISGITLINK
($mode)) {
1362 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1364 } elsif (S_ISLNK
($mode)) {
1366 } elsif (S_ISREG
($mode)) {
1367 if ($mode & S_IXUSR
) {
1368 return "executable";
1378 ## ----------------------------------------------------------------------
1379 ## functions returning short HTML fragments, or transforming HTML fragments
1380 ## which don't belong to other sections
1382 # format line of commit message.
1383 sub format_log_line_html
{
1386 $line = esc_html
($line, -nbsp
=>1);
1387 if ($line =~ m/\b([0-9a-fA-F]{8,40})\b/) {
1390 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
1391 -class => "text"}, $hash_text);
1392 $line =~ s/$hash_text/$link/;
1397 # format marker of refs pointing to given object
1399 # the destination action is chosen based on object type and current context:
1400 # - for annotated tags, we choose the tag view unless it's the current view
1401 # already, in which case we go to shortlog view
1402 # - for other refs, we keep the current view if we're in history, shortlog or
1403 # log view, and select shortlog otherwise
1404 sub format_ref_marker
{
1405 my ($refs, $id) = @_;
1408 if (defined $refs->{$id}) {
1409 foreach my $ref (@
{$refs->{$id}}) {
1410 # this code exploits the fact that non-lightweight tags are the
1411 # only indirect objects, and that they are the only objects for which
1412 # we want to use tag instead of shortlog as action
1413 my ($type, $name) = qw();
1414 my $indirect = ($ref =~ s/\^\{\}$//);
1415 # e.g. tags/v2.6.11 or heads/next
1416 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1425 $class .= " indirect" if $indirect;
1427 my $dest_action = "shortlog";
1430 $dest_action = "tag" unless $action eq "tag";
1431 } elsif ($action =~ /^(history|(short)?log)$/) {
1432 $dest_action = $action;
1436 $dest .= "refs/" unless $ref =~ m
!^refs
/!;
1439 my $link = $cgi->a({
1441 action
=>$dest_action,
1445 $markers .= " <span class=\"$class\" title=\"$ref\">" .
1451 return ' <span class="refs">'. $markers . '</span>';
1457 # format, perhaps shortened and with markers, title line
1458 sub format_subject_html
{
1459 my ($long, $short, $href, $extra) = @_;
1460 $extra = '' unless defined($extra);
1462 if (length($short) < length($long)) {
1463 return $cgi->a({-href
=> $href, -class => "list subject",
1464 -title
=> to_utf8
($long)},
1465 esc_html
($short) . $extra);
1467 return $cgi->a({-href
=> $href, -class => "list subject"},
1468 esc_html
($long) . $extra);
1472 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1473 sub format_git_diff_header_line
{
1475 my $diffinfo = shift;
1476 my ($from, $to) = @_;
1478 if ($diffinfo->{'nparents'}) {
1480 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1481 if ($to->{'href'}) {
1482 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1483 esc_path
($to->{'file'}));
1484 } else { # file was deleted (no href)
1485 $line .= esc_path
($to->{'file'});
1489 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1490 if ($from->{'href'}) {
1491 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1492 'a/' . esc_path
($from->{'file'}));
1493 } else { # file was added (no href)
1494 $line .= 'a/' . esc_path
($from->{'file'});
1497 if ($to->{'href'}) {
1498 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1499 'b/' . esc_path
($to->{'file'}));
1500 } else { # file was deleted
1501 $line .= 'b/' . esc_path
($to->{'file'});
1505 return "<div class=\"diff header\">$line</div>\n";
1508 # format extended diff header line, before patch itself
1509 sub format_extended_diff_header_line
{
1511 my $diffinfo = shift;
1512 my ($from, $to) = @_;
1515 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1516 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1517 esc_path
($from->{'file'}));
1519 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1520 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1521 esc_path
($to->{'file'}));
1523 # match single <mode>
1524 if ($line =~ m/\s(\d{6})$/) {
1525 $line .= '<span class="info"> (' .
1526 file_type_long
($1) .
1530 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1531 # can match only for combined diff
1533 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1534 if ($from->{'href'}[$i]) {
1535 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1537 substr($diffinfo->{'from_id'}[$i],0,7));
1542 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1545 if ($to->{'href'}) {
1546 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1547 substr($diffinfo->{'to_id'},0,7));
1552 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1553 # can match only for ordinary diff
1554 my ($from_link, $to_link);
1555 if ($from->{'href'}) {
1556 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1557 substr($diffinfo->{'from_id'},0,7));
1559 $from_link = '0' x
7;
1561 if ($to->{'href'}) {
1562 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1563 substr($diffinfo->{'to_id'},0,7));
1567 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1568 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1571 return $line . "<br/>\n";
1574 # format from-file/to-file diff header
1575 sub format_diff_from_to_header
{
1576 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1581 #assert($line =~ m/^---/) if DEBUG;
1582 # no extra formatting for "^--- /dev/null"
1583 if (! $diffinfo->{'nparents'}) {
1584 # ordinary (single parent) diff
1585 if ($line =~ m!^--- "?a/!) {
1586 if ($from->{'href'}) {
1588 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1589 esc_path
($from->{'file'}));
1592 esc_path
($from->{'file'});
1595 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1598 # combined diff (merge commit)
1599 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1600 if ($from->{'href'}[$i]) {
1602 $cgi->a({-href
=>href
(action
=>"blobdiff",
1603 hash_parent
=>$diffinfo->{'from_id'}[$i],
1604 hash_parent_base
=>$parents[$i],
1605 file_parent
=>$from->{'file'}[$i],
1606 hash
=>$diffinfo->{'to_id'},
1608 file_name
=>$to->{'file'}),
1610 -title
=>"diff" . ($i+1)},
1613 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1614 esc_path
($from->{'file'}[$i]));
1616 $line = '--- /dev/null';
1618 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1623 #assert($line =~ m/^\+\+\+/) if DEBUG;
1624 # no extra formatting for "^+++ /dev/null"
1625 if ($line =~ m!^\+\+\+ "?b/!) {
1626 if ($to->{'href'}) {
1628 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1629 esc_path
($to->{'file'}));
1632 esc_path
($to->{'file'});
1635 $result .= qq!<div
class="diff to_file">$line</div
>\n!;
1640 # create note for patch simplified by combined diff
1641 sub format_diff_cc_simplified
{
1642 my ($diffinfo, @parents) = @_;
1645 $result .= "<div class=\"diff header\">" .
1647 if (!is_deleted
($diffinfo)) {
1648 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1650 hash
=>$diffinfo->{'to_id'},
1651 file_name
=>$diffinfo->{'to_file'}),
1653 esc_path
($diffinfo->{'to_file'}));
1655 $result .= esc_path
($diffinfo->{'to_file'});
1657 $result .= "</div>\n" . # class="diff header"
1658 "<div class=\"diff nodifferences\">" .
1660 "</div>\n"; # class="diff nodifferences"
1665 # format patch (diff) line (not to be used for diff headers)
1666 sub format_diff_line
{
1668 my ($from, $to) = @_;
1669 my $diff_class = "";
1673 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1675 my $prefix = substr($line, 0, scalar @
{$from->{'href'}});
1676 if ($line =~ m/^\@{3}/) {
1677 $diff_class = " chunk_header";
1678 } elsif ($line =~ m/^\\/) {
1679 $diff_class = " incomplete";
1680 } elsif ($prefix =~ tr/+/+/) {
1681 $diff_class = " add";
1682 } elsif ($prefix =~ tr/-/-/) {
1683 $diff_class = " rem";
1686 # assume ordinary diff
1687 my $char = substr($line, 0, 1);
1689 $diff_class = " add";
1690 } elsif ($char eq '-') {
1691 $diff_class = " rem";
1692 } elsif ($char eq '@') {
1693 $diff_class = " chunk_header";
1694 } elsif ($char eq "\\") {
1695 $diff_class = " incomplete";
1698 $line = untabify
($line);
1699 if ($from && $to && $line =~ m/^\@{2} /) {
1700 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1701 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1703 $from_lines = 0 unless defined $from_lines;
1704 $to_lines = 0 unless defined $to_lines;
1706 if ($from->{'href'}) {
1707 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1708 -class=>"list"}, $from_text);
1710 if ($to->{'href'}) {
1711 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1712 -class=>"list"}, $to_text);
1714 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1715 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1716 return "<div class=\"diff$diff_class\">$line</div>\n";
1717 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1718 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1719 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1721 @from_text = split(' ', $ranges);
1722 for (my $i = 0; $i < @from_text; ++$i) {
1723 ($from_start[$i], $from_nlines[$i]) =
1724 (split(',', substr($from_text[$i], 1)), 0);
1727 $to_text = pop @from_text;
1728 $to_start = pop @from_start;
1729 $to_nlines = pop @from_nlines;
1731 $line = "<span class=\"chunk_info\">$prefix ";
1732 for (my $i = 0; $i < @from_text; ++$i) {
1733 if ($from->{'href'}[$i]) {
1734 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1735 -class=>"list"}, $from_text[$i]);
1737 $line .= $from_text[$i];
1741 if ($to->{'href'}) {
1742 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1743 -class=>"list"}, $to_text);
1747 $line .= " $prefix</span>" .
1748 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1749 return "<div class=\"diff$diff_class\">$line</div>\n";
1751 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1754 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1755 # linked. Pass the hash of the tree/commit to snapshot.
1756 sub format_snapshot_links
{
1758 my $num_fmts = @snapshot_fmts;
1759 if ($num_fmts > 1) {
1760 # A parenthesized list of links bearing format names.
1761 # e.g. "snapshot (_tar.gz_ _zip_)"
1762 return "snapshot (" . join(' ', map
1769 }, $known_snapshot_formats{$_}{'display'})
1770 , @snapshot_fmts) . ")";
1771 } elsif ($num_fmts == 1) {
1772 # A single "snapshot" link whose tooltip bears the format name.
1774 my ($fmt) = @snapshot_fmts;
1780 snapshot_format
=>$fmt
1782 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1784 } else { # $num_fmts == 0
1789 ## ......................................................................
1790 ## functions returning values to be passed, perhaps after some
1791 ## transformation, to other functions; e.g. returning arguments to href()
1793 # returns hash to be passed to href to generate gitweb URL
1794 # in -title key it returns description of link
1796 my $format = shift || 'Atom';
1797 my %res = (action
=> lc($format));
1799 # feed links are possible only for project views
1800 return unless (defined $project);
1801 # some views should link to OPML, or to generic project feed,
1802 # or don't have specific feed yet (so they should use generic)
1803 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
1806 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
1807 # from tag links; this also makes possible to detect branch links
1808 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
1809 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
1812 # find log type for feed description (title)
1814 if (defined $file_name) {
1815 $type = "history of $file_name";
1816 $type .= "/" if ($action eq 'tree');
1817 $type .= " on '$branch'" if (defined $branch);
1819 $type = "log of $branch" if (defined $branch);
1822 $res{-title
} = $type;
1823 $res{'hash'} = (defined $branch ?
"refs/heads/$branch" : undef);
1824 $res{'file_name'} = $file_name;
1829 ## ----------------------------------------------------------------------
1830 ## git utility subroutines, invoking git commands
1832 # returns path to the core git executable and the --git-dir parameter as list
1834 return $GIT, '--git-dir='.$git_dir;
1837 # quote the given arguments for passing them to the shell
1838 # quote_command("command", "arg 1", "arg with ' and ! characters")
1839 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
1840 # Try to avoid using this function wherever possible.
1843 map( { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ ));
1846 # get HEAD ref of given project as hash
1847 sub git_get_head_hash
{
1848 my $project = shift;
1849 my $o_git_dir = $git_dir;
1851 $git_dir = "$projectroot/$project";
1852 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1855 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1859 if (defined $o_git_dir) {
1860 $git_dir = $o_git_dir;
1865 # get type of given object
1869 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1871 close $fd or return;
1876 # repository configuration
1877 our $config_file = '';
1880 # store multiple values for single key as anonymous array reference
1881 # single values stored directly in the hash, not as [ <value> ]
1882 sub hash_set_multi
{
1883 my ($hash, $key, $value) = @_;
1885 if (!exists $hash->{$key}) {
1886 $hash->{$key} = $value;
1887 } elsif (!ref $hash->{$key}) {
1888 $hash->{$key} = [ $hash->{$key}, $value ];
1890 push @
{$hash->{$key}}, $value;
1894 # return hash of git project configuration
1895 # optionally limited to some section, e.g. 'gitweb'
1896 sub git_parse_project_config
{
1897 my $section_regexp = shift;
1902 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
1905 while (my $keyval = <$fh>) {
1907 my ($key, $value) = split(/\n/, $keyval, 2);
1909 hash_set_multi
(\
%config, $key, $value)
1910 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
1917 # convert config value to boolean: 'true' or 'false'
1918 # no value, number > 0, 'true' and 'yes' values are true
1919 # rest of values are treated as false (never as error)
1920 sub config_to_bool
{
1923 return 1 if !defined $val; # section.key
1925 # strip leading and trailing whitespace
1929 return (($val =~ /^\d+$/ && $val) || # section.key = 1
1930 ($val =~ /^(?:true|yes)$/i)); # section.key = true
1933 # convert config value to simple decimal number
1934 # an optional value suffix of 'k', 'm', or 'g' will cause the value
1935 # to be multiplied by 1024, 1048576, or 1073741824
1939 # strip leading and trailing whitespace
1943 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
1945 # unknown unit is treated as 1
1946 return $num * ($unit eq 'g' ?
1073741824 :
1947 $unit eq 'm' ?
1048576 :
1948 $unit eq 'k' ?
1024 : 1);
1953 # convert config value to array reference, if needed
1954 sub config_to_multi
{
1957 return ref($val) ?
$val : (defined($val) ?
[ $val ] : []);
1960 sub git_get_project_config
{
1961 my ($key, $type) = @_;
1964 return unless ($key);
1965 $key =~ s/^gitweb\.//;
1966 return if ($key =~ m/\W/);
1969 if (defined $type) {
1972 unless ($type eq 'bool' || $type eq 'int');
1976 if (!defined $config_file ||
1977 $config_file ne "$git_dir/config") {
1978 %config = git_parse_project_config
('gitweb');
1979 $config_file = "$git_dir/config";
1982 # check if config variable (key) exists
1983 return unless exists $config{"gitweb.$key"};
1986 if (!defined $type) {
1987 return $config{"gitweb.$key"};
1988 } elsif ($type eq 'bool') {
1989 # backward compatibility: 'git config --bool' returns true/false
1990 return config_to_bool
($config{"gitweb.$key"}) ?
'true' : 'false';
1991 } elsif ($type eq 'int') {
1992 return config_to_int
($config{"gitweb.$key"});
1994 return $config{"gitweb.$key"};
1997 # get hash of given path at given ref
1998 sub git_get_hash_by_path
{
2000 my $path = shift || return undef;
2005 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
2006 or die_error
(500, "Open git-ls-tree failed");
2008 close $fd or return undef;
2010 if (!defined $line) {
2011 # there is no tree or hash given by $path at $base
2015 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2016 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
2017 if (defined $type && $type ne $2) {
2018 # type doesn't match
2024 # get path of entry with given hash at given tree-ish (ref)
2025 # used to get 'from' filename for combined diff (merge commit) for renames
2026 sub git_get_path_by_hash
{
2027 my $base = shift || return;
2028 my $hash = shift || return;
2032 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
2034 while (my $line = <$fd>) {
2037 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
2038 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
2039 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
2048 ## ......................................................................
2049 ## git utility functions, directly accessing git repository
2051 sub git_get_project_description
{
2054 $git_dir = "$projectroot/$path";
2055 open my $fd, "$git_dir/description"
2056 or return git_get_project_config
('description');
2059 if (defined $descr) {
2065 sub git_get_project_ctags
{
2069 $git_dir = "$projectroot/$path";
2070 unless (opendir D
, "$git_dir/ctags") {
2073 foreach (grep { -f
$_ } map { "$git_dir/ctags/$_" } readdir(D
)) {
2074 open CT
, $_ or next;
2078 my $ctag = $_; $ctag =~ s
#.*/##;
2079 $ctags->{$ctag} = $val;
2085 sub git_populate_project_tagcloud
{
2088 # First, merge different-cased tags; tags vote on casing
2090 foreach (keys %$ctags) {
2091 $ctags_lc{lc $_}->{count
} += $ctags->{$_};
2092 if (not $ctags_lc{lc $_}->{topcount
}
2093 or $ctags_lc{lc $_}->{topcount
} < $ctags->{$_}) {
2094 $ctags_lc{lc $_}->{topcount
} = $ctags->{$_};
2095 $ctags_lc{lc $_}->{topname
} = $_;
2100 if (eval { require HTML
::TagCloud
; 1; }) {
2101 $cloud = HTML
::TagCloud
->new;
2102 foreach (sort keys %ctags_lc) {
2103 # Pad the title with spaces so that the cloud looks
2105 my $title = $ctags_lc{$_}->{topname
};
2106 $title =~ s/ / /g;
2107 $title =~ s/^/ /g;
2108 $title =~ s/$/ /g;
2109 $cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count
});
2112 $cloud = \
%ctags_lc;
2117 sub git_show_project_tagcloud
{
2118 my ($cloud, $count) = @_;
2119 print STDERR
ref($cloud)."..\n";
2120 if (ref $cloud eq 'HTML::TagCloud') {
2121 return $cloud->html_and_css($count);
2123 my @tags = sort { $cloud->{$a}->{count
} <=> $cloud->{$b}->{count
} } keys %$cloud;
2124 return '<p align="center">' . join (', ', map {
2125 "<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"
2126 } splice(@tags, 0, $count)) . '</p>';
2130 sub git_get_project_url_list
{
2133 $git_dir = "$projectroot/$path";
2134 open my $fd, "$git_dir/cloneurl"
2135 or return wantarray ?
2136 @
{ config_to_multi
(git_get_project_config
('url')) } :
2137 config_to_multi
(git_get_project_config
('url'));
2138 my @git_project_url_list = map { chomp; $_ } <$fd>;
2141 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
2144 sub git_get_projects_list
{
2149 $filter =~ s/\.git$//;
2151 my $check_forks = gitweb_check_feature
('forks');
2153 if (-d
$projects_list) {
2154 # search in directory
2155 my $dir = $projects_list . ($filter ?
"/$filter" : '');
2156 # remove the trailing "/"
2158 my $pfxlen = length("$dir");
2159 my $pfxdepth = ($dir =~ tr!/!!);
2162 follow_fast
=> 1, # follow symbolic links
2163 follow_skip
=> 2, # ignore duplicates
2164 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
2166 # skip project-list toplevel, if we get it.
2167 return if (m!^[/.]$!);
2168 # only directories can be git repositories
2169 return unless (-d
$_);
2170 # don't traverse too deep (Find is super slow on os x)
2171 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
2172 $File::Find
::prune
= 1;
2176 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
2177 # we check related file in $projectroot
2178 my $path = ($filter ?
"$filter/" : '') . $subdir;
2179 if (check_export_ok
("$projectroot/$path")) {
2180 push @list, { path
=> $path };
2181 $File::Find
::prune
= 1;
2186 } elsif (-f
$projects_list) {
2187 # read from file(url-encoded):
2188 # 'git%2Fgit.git Linus+Torvalds'
2189 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2190 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2192 open my ($fd), $projects_list or return;
2194 while (my $line = <$fd>) {
2196 my ($path, $owner) = split ' ', $line;
2197 $path = unescape
($path);
2198 $owner = unescape
($owner);
2199 if (!defined $path) {
2202 if ($filter ne '') {
2203 # looking for forks;
2204 my $pfx = substr($path, 0, length($filter));
2205 if ($pfx ne $filter) {
2208 my $sfx = substr($path, length($filter));
2209 if ($sfx !~ /^\/.*\
.git
$/) {
2212 } elsif ($check_forks) {
2214 foreach my $filter (keys %paths) {
2215 # looking for forks;
2216 my $pfx = substr($path, 0, length($filter));
2217 if ($pfx ne $filter) {
2220 my $sfx = substr($path, length($filter));
2221 if ($sfx !~ /^\/.*\
.git
$/) {
2224 # is a fork, don't include it in
2229 if (check_export_ok
("$projectroot/$path")) {
2232 owner
=> to_utf8
($owner),
2235 (my $forks_path = $path) =~ s/\.git$//;
2236 $paths{$forks_path}++;
2244 our $gitweb_project_owner = undef;
2245 sub git_get_project_list_from_file
{
2247 return if (defined $gitweb_project_owner);
2249 $gitweb_project_owner = {};
2250 # read from file (url-encoded):
2251 # 'git%2Fgit.git Linus+Torvalds'
2252 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2253 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2254 if (-f
$projects_list) {
2255 open (my $fd , $projects_list);
2256 while (my $line = <$fd>) {
2258 my ($pr, $ow) = split ' ', $line;
2259 $pr = unescape
($pr);
2260 $ow = unescape
($ow);
2261 $gitweb_project_owner->{$pr} = to_utf8
($ow);
2267 sub git_get_project_owner
{
2268 my $project = shift;
2271 return undef unless $project;
2272 $git_dir = "$projectroot/$project";
2274 if (!defined $gitweb_project_owner) {
2275 git_get_project_list_from_file
();
2278 if (exists $gitweb_project_owner->{$project}) {
2279 $owner = $gitweb_project_owner->{$project};
2281 if (!defined $owner){
2282 $owner = git_get_project_config
('owner');
2284 if (!defined $owner) {
2285 $owner = get_file_owner
("$git_dir");
2291 sub git_get_last_activity
{
2295 $git_dir = "$projectroot/$path";
2296 open($fd, "-|", git_cmd
(), 'for-each-ref',
2297 '--format=%(committer)',
2298 '--sort=-committerdate',
2300 'refs/heads') or return;
2301 my $most_recent = <$fd>;
2302 close $fd or return;
2303 if (defined $most_recent &&
2304 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
2306 my $age = time - $timestamp;
2307 return ($age, age_string
($age));
2309 return (undef, undef);
2312 sub git_get_references
{
2313 my $type = shift || "";
2315 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
2316 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
2317 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
2318 ($type ?
("--", "refs/$type") : ()) # use -- <pattern> if $type
2321 while (my $line = <$fd>) {
2323 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
2324 if (defined $refs{$1}) {
2325 push @
{$refs{$1}}, $2;
2331 close $fd or return;
2335 sub git_get_rev_name_tags
{
2336 my $hash = shift || return undef;
2338 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
2340 my $name_rev = <$fd>;
2343 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
2346 # catches also '$hash undefined' output
2351 ## ----------------------------------------------------------------------
2352 ## parse to hash functions
2356 my $tz = shift || "-0000";
2359 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
2360 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
2361 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
2362 $date{'hour'} = $hour;
2363 $date{'minute'} = $min;
2364 $date{'mday'} = $mday;
2365 $date{'day'} = $days[$wday];
2366 $date{'month'} = $months[$mon];
2367 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2368 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2369 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2370 $mday, $months[$mon], $hour ,$min;
2371 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2372 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2374 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2375 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2376 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2377 $date{'hour_local'} = $hour;
2378 $date{'minute_local'} = $min;
2379 $date{'tz_local'} = $tz;
2380 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2381 1900+$year, $mon+1, $mday,
2382 $hour, $min, $sec, $tz);
2391 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
2392 $tag{'id'} = $tag_id;
2393 while (my $line = <$fd>) {
2395 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2396 $tag{'object'} = $1;
2397 } elsif ($line =~ m/^type (.+)$/) {
2399 } elsif ($line =~ m/^tag (.+)$/) {
2401 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2402 $tag{'author'} = $1;
2405 } elsif ($line =~ m/--BEGIN/) {
2406 push @comment, $line;
2408 } elsif ($line eq "") {
2412 push @comment, <$fd>;
2413 $tag{'comment'} = \
@comment;
2414 close $fd or return;
2415 if (!defined $tag{'name'}) {
2421 sub parse_commit_text
{
2422 my ($commit_text, $withparents) = @_;
2423 my @commit_lines = split '\n', $commit_text;
2426 pop @commit_lines; # Remove '\0'
2428 if (! @commit_lines) {
2432 my $header = shift @commit_lines;
2433 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2436 ($co{'id'}, my @parents) = split ' ', $header;
2437 while (my $line = shift @commit_lines) {
2438 last if $line eq "\n";
2439 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2441 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2443 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2445 $co{'author_epoch'} = $2;
2446 $co{'author_tz'} = $3;
2447 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2448 $co{'author_name'} = $1;
2449 $co{'author_email'} = $2;
2451 $co{'author_name'} = $co{'author'};
2453 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2454 $co{'committer'} = $1;
2455 $co{'committer_epoch'} = $2;
2456 $co{'committer_tz'} = $3;
2457 $co{'committer_name'} = $co{'committer'};
2458 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2459 $co{'committer_name'} = $1;
2460 $co{'committer_email'} = $2;
2462 $co{'committer_name'} = $co{'committer'};
2466 if (!defined $co{'tree'}) {
2469 $co{'parents'} = \
@parents;
2470 $co{'parent'} = $parents[0];
2472 foreach my $title (@commit_lines) {
2475 $co{'title'} = chop_str
($title, 80, 5);
2476 # remove leading stuff of merges to make the interesting part visible
2477 if (length($title) > 50) {
2478 $title =~ s/^Automatic //;
2479 $title =~ s/^merge (of|with) /Merge ... /i;
2480 if (length($title) > 50) {
2481 $title =~ s/(http|rsync):\/\///;
2483 if (length($title) > 50) {
2484 $title =~ s/(master|www|rsync)\.//;
2486 if (length($title) > 50) {
2487 $title =~ s/kernel.org:?//;
2489 if (length($title) > 50) {
2490 $title =~ s/\/pub\/scm//;
2493 $co{'title_short'} = chop_str
($title, 50, 5);
2497 if (! defined $co{'title'} || $co{'title'} eq "") {
2498 $co{'title'} = $co{'title_short'} = '(no commit message)';
2500 # remove added spaces
2501 foreach my $line (@commit_lines) {
2504 $co{'comment'} = \
@commit_lines;
2506 my $age = time - $co{'committer_epoch'};
2508 $co{'age_string'} = age_string
($age);
2509 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2510 if ($age > 60*60*24*7*2) {
2511 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2512 $co{'age_string_age'} = $co{'age_string'};
2514 $co{'age_string_date'} = $co{'age_string'};
2515 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2521 my ($commit_id) = @_;
2526 open my $fd, "-|", git_cmd
(), "rev-list",
2532 or die_error
(500, "Open git-rev-list failed");
2533 %co = parse_commit_text
(<$fd>, 1);
2540 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2548 open my $fd, "-|", git_cmd
(), "rev-list",
2551 ("--max-count=" . $maxcount),
2552 ("--skip=" . $skip),
2556 ($filename ?
($filename) : ())
2557 or die_error
(500, "Open git-rev-list failed");
2558 while (my $line = <$fd>) {
2559 my %co = parse_commit_text
($line);
2564 return wantarray ?
@cos : \
@cos;
2567 # parse line of git-diff-tree "raw" output
2568 sub parse_difftree_raw_line
{
2572 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2573 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2574 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2575 $res{'from_mode'} = $1;
2576 $res{'to_mode'} = $2;
2577 $res{'from_id'} = $3;
2579 $res{'status'} = $5;
2580 $res{'similarity'} = $6;
2581 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2582 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2584 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2587 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2588 # combined diff (for merge commit)
2589 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2590 $res{'nparents'} = length($1);
2591 $res{'from_mode'} = [ split(' ', $2) ];
2592 $res{'to_mode'} = pop @
{$res{'from_mode'}};
2593 $res{'from_id'} = [ split(' ', $3) ];
2594 $res{'to_id'} = pop @
{$res{'from_id'}};
2595 $res{'status'} = [ split('', $4) ];
2596 $res{'to_file'} = unquote
($5);
2598 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2599 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2600 $res{'commit'} = $1;
2603 return wantarray ?
%res : \
%res;
2606 # wrapper: return parsed line of git-diff-tree "raw" output
2607 # (the argument might be raw line, or parsed info)
2608 sub parsed_difftree_line
{
2609 my $line_or_ref = shift;
2611 if (ref($line_or_ref) eq "HASH") {
2612 # pre-parsed (or generated by hand)
2613 return $line_or_ref;
2615 return parse_difftree_raw_line
($line_or_ref);
2619 # parse line of git-ls-tree output
2620 sub parse_ls_tree_line
($;%) {
2625 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2626 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2634 $res{'name'} = unquote
($4);
2637 return wantarray ?
%res : \
%res;
2640 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2641 sub parse_from_to_diffinfo
{
2642 my ($diffinfo, $from, $to, @parents) = @_;
2644 if ($diffinfo->{'nparents'}) {
2646 $from->{'file'} = [];
2647 $from->{'href'} = [];
2648 fill_from_file_info
($diffinfo, @parents)
2649 unless exists $diffinfo->{'from_file'};
2650 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2651 $from->{'file'}[$i] =
2652 defined $diffinfo->{'from_file'}[$i] ?
2653 $diffinfo->{'from_file'}[$i] :
2654 $diffinfo->{'to_file'};
2655 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2656 $from->{'href'}[$i] = href
(action
=>"blob",
2657 hash_base
=>$parents[$i],
2658 hash
=>$diffinfo->{'from_id'}[$i],
2659 file_name
=>$from->{'file'}[$i]);
2661 $from->{'href'}[$i] = undef;
2665 # ordinary (not combined) diff
2666 $from->{'file'} = $diffinfo->{'from_file'};
2667 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2668 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2669 hash
=>$diffinfo->{'from_id'},
2670 file_name
=>$from->{'file'});
2672 delete $from->{'href'};
2676 $to->{'file'} = $diffinfo->{'to_file'};
2677 if (!is_deleted
($diffinfo)) { # file exists in result
2678 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2679 hash
=>$diffinfo->{'to_id'},
2680 file_name
=>$to->{'file'});
2682 delete $to->{'href'};
2686 ## ......................................................................
2687 ## parse to array of hashes functions
2689 sub git_get_heads_list
{
2693 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2694 ($limit ?
'--count='.($limit+1) : ()), '--sort=-committerdate',
2695 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2698 while (my $line = <$fd>) {
2702 my ($refinfo, $committerinfo) = split(/\0/, $line);
2703 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2704 my ($committer, $epoch, $tz) =
2705 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2706 $ref_item{'fullname'} = $name;
2707 $name =~ s!^refs/heads/!!;
2709 $ref_item{'name'} = $name;
2710 $ref_item{'id'} = $hash;
2711 $ref_item{'title'} = $title || '(no commit message)';
2712 $ref_item{'epoch'} = $epoch;
2714 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2716 $ref_item{'age'} = "unknown";
2719 push @headslist, \
%ref_item;
2723 return wantarray ?
@headslist : \
@headslist;
2726 sub git_get_tags_list
{
2730 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2731 ($limit ?
'--count='.($limit+1) : ()), '--sort=-creatordate',
2732 '--format=%(objectname) %(objecttype) %(refname) '.
2733 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2736 while (my $line = <$fd>) {
2740 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2741 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2742 my ($creator, $epoch, $tz) =
2743 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2744 $ref_item{'fullname'} = $name;
2745 $name =~ s!^refs/tags/!!;
2747 $ref_item{'type'} = $type;
2748 $ref_item{'id'} = $id;
2749 $ref_item{'name'} = $name;
2750 if ($type eq "tag") {
2751 $ref_item{'subject'} = $title;
2752 $ref_item{'reftype'} = $reftype;
2753 $ref_item{'refid'} = $refid;
2755 $ref_item{'reftype'} = $type;
2756 $ref_item{'refid'} = $id;
2759 if ($type eq "tag" || $type eq "commit") {
2760 $ref_item{'epoch'} = $epoch;
2762 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2764 $ref_item{'age'} = "unknown";
2768 push @tagslist, \
%ref_item;
2772 return wantarray ?
@tagslist : \
@tagslist;
2775 ## ----------------------------------------------------------------------
2776 ## filesystem-related functions
2778 sub get_file_owner
{
2781 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2782 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2783 if (!defined $gcos) {
2787 $owner =~ s/[,;].*$//;
2788 return to_utf8
($owner);
2791 # assume that file exists
2793 my $filename = shift;
2795 open my $fd, '<', $filename;
2796 print map { to_utf8
($_) } <$fd>;
2800 ## ......................................................................
2801 ## mimetype related functions
2803 sub mimetype_guess_file
{
2804 my $filename = shift;
2805 my $mimemap = shift;
2806 -r
$mimemap or return undef;
2809 open(MIME
, $mimemap) or return undef;
2811 next if m/^#/; # skip comments
2812 my ($mime, $exts) = split(/\t+/);
2813 if (defined $exts) {
2814 my @exts = split(/\s+/, $exts);
2815 foreach my $ext (@exts) {
2816 $mimemap{$ext} = $mime;
2822 $filename =~ /\.([^.]*)$/;
2823 return $mimemap{$1};
2826 sub mimetype_guess
{
2827 my $filename = shift;
2829 $filename =~ /\./ or return undef;
2831 if ($mimetypes_file) {
2832 my $file = $mimetypes_file;
2833 if ($file !~ m!^/!) { # if it is relative path
2834 # it is relative to project
2835 $file = "$projectroot/$project/$file";
2837 $mime = mimetype_guess_file
($filename, $file);
2839 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2845 my $filename = shift;
2848 my $mime = mimetype_guess
($filename);
2849 $mime and return $mime;
2853 return $default_blob_plain_mimetype unless $fd;
2856 return 'text/plain';
2857 } elsif (! $filename) {
2858 return 'application/octet-stream';
2859 } elsif ($filename =~ m/\.png$/i) {
2861 } elsif ($filename =~ m/\.gif$/i) {
2863 } elsif ($filename =~ m/\.jpe?g$/i) {
2864 return 'image/jpeg';
2866 return 'application/octet-stream';
2870 sub blob_contenttype
{
2871 my ($fd, $file_name, $type) = @_;
2873 $type ||= blob_mimetype
($fd, $file_name);
2874 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
2875 $type .= "; charset=$default_text_plain_charset";
2881 ## ======================================================================
2882 ## functions printing HTML: header, footer, error page
2884 sub git_header_html
{
2885 my $status = shift || "200 OK";
2886 my $expires = shift;
2888 my $title = "$site_name";
2889 if (defined $project) {
2890 $title .= " - " . to_utf8
($project);
2891 if (defined $action) {
2892 $title .= "/$action";
2893 if (defined $file_name) {
2894 $title .= " - " . esc_path
($file_name);
2895 if ($action eq "tree" && $file_name !~ m
|/$|) {
2902 # require explicit support from the UA if we are to send the page as
2903 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2904 # we have to do this because MSIE sometimes globs '*/*', pretending to
2905 # support xhtml+xml but choking when it gets what it asked for.
2906 if (defined $cgi->http('HTTP_ACCEPT') &&
2907 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2908 $cgi->Accept('application/xhtml+xml') != 0) {
2909 $content_type = 'application/xhtml+xml';
2911 $content_type = 'text/html';
2913 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2914 -status
=> $status, -expires
=> $expires);
2915 my $mod_perl_version = $ENV{'MOD_PERL'} ?
" $ENV{'MOD_PERL'}" : '';
2917 <?xml version="1.0" encoding="utf-8"?>
2918 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2919 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2920 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2921 <!-- git core binaries version $git_version -->
2923 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2924 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2925 <meta name="robots" content="index, nofollow"/>
2926 <title>$title</title>
2928 # the stylesheet, favicon etc urls won't work correctly with path_info
2929 # unless we set the appropriate base URL
2930 if ($ENV{'PATH_INFO'}) {
2931 print "<base href=\"".esc_url
($base_url)."\" />\n";
2933 # print out each stylesheet that exist, providing backwards capability
2934 # for those people who defined $stylesheet in a config file
2935 if (defined $stylesheet) {
2936 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2938 foreach my $stylesheet (@stylesheets) {
2939 next unless $stylesheet;
2940 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2943 if (defined $project) {
2944 my %href_params = get_feed_info
();
2945 if (!exists $href_params{'-title'}) {
2946 $href_params{'-title'} = 'log';
2949 foreach my $format qw(RSS Atom) {
2950 my $type = lc($format);
2952 '-rel' => 'alternate',
2953 '-title' => "$project - $href_params{'-title'} - $format feed",
2954 '-type' => "application/$type+xml"
2957 $href_params{'action'} = $type;
2958 $link_attr{'-href'} = href
(%href_params);
2960 "rel=\"$link_attr{'-rel'}\" ".
2961 "title=\"$link_attr{'-title'}\" ".
2962 "href=\"$link_attr{'-href'}\" ".
2963 "type=\"$link_attr{'-type'}\" ".
2966 $href_params{'extra_options'} = '--no-merges';
2967 $link_attr{'-href'} = href
(%href_params);
2968 $link_attr{'-title'} .= ' (no merges)';
2970 "rel=\"$link_attr{'-rel'}\" ".
2971 "title=\"$link_attr{'-title'}\" ".
2972 "href=\"$link_attr{'-href'}\" ".
2973 "type=\"$link_attr{'-type'}\" ".
2978 printf('<link rel="alternate" title="%s projects list" '.
2979 'href="%s" type="text/plain; charset=utf-8" />'."\n",
2980 $site_name, href
(project
=>undef, action
=>"project_index"));
2981 printf('<link rel="alternate" title="%s projects feeds" '.
2982 'href="%s" type="text/x-opml" />'."\n",
2983 $site_name, href
(project
=>undef, action
=>"opml"));
2985 if (defined $favicon) {
2986 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png" />\n);
2992 if (-f
$site_header) {
2993 insert_file
($site_header);
2996 print "<div class=\"page_header\">\n" .
2997 $cgi->a({-href
=> esc_url
($logo_url),
2998 -title
=> $logo_label},
2999 qq(<img src
="$logo" width
="72" height
="27" alt
="git" class="logo"/>));
3000 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
3001 if (defined $project) {
3002 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
3003 if (defined $action) {
3010 my $have_search = gitweb_check_feature
('search');
3011 if (defined $project && $have_search) {
3012 if (!defined $searchtext) {
3016 if (defined $hash_base) {
3017 $search_hash = $hash_base;
3018 } elsif (defined $hash) {
3019 $search_hash = $hash;
3021 $search_hash = "HEAD";
3023 my $action = $my_uri;
3024 my $use_pathinfo = gitweb_check_feature
('pathinfo');
3025 if ($use_pathinfo) {
3026 $action .= "/".esc_url
($project);
3028 print $cgi->startform(-method
=> "get", -action
=> $action) .
3029 "<div class=\"search\">\n" .
3031 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
3032 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
3033 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
3034 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
3035 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
3036 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
3038 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
3039 "<span title=\"Extended regular expression\">" .
3040 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
3041 -checked
=> $search_use_regexp) .
3044 $cgi->end_form() . "\n";
3048 sub git_footer_html
{
3049 my $feed_class = 'rss_logo';
3051 print "<div class=\"page_footer\">\n";
3052 if (defined $project) {
3053 my $descr = git_get_project_description
($project);
3054 if (defined $descr) {
3055 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
3058 my %href_params = get_feed_info
();
3059 if (!%href_params) {
3060 $feed_class .= ' generic';
3062 $href_params{'-title'} ||= 'log';
3064 foreach my $format qw(RSS Atom) {
3065 $href_params{'action'} = lc($format);
3066 print $cgi->a({-href
=> href
(%href_params),
3067 -title
=> "$href_params{'-title'} $format feed",
3068 -class => $feed_class}, $format)."\n";
3072 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
3073 -class => $feed_class}, "OPML") . " ";
3074 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
3075 -class => $feed_class}, "TXT") . "\n";
3077 print "</div>\n"; # class="page_footer"
3079 if (-f
$site_footer) {
3080 insert_file
($site_footer);
3087 # die_error(<http_status_code>, <error_message>)
3088 # Example: die_error(404, 'Hash not found')
3089 # By convention, use the following status codes (as defined in RFC 2616):
3090 # 400: Invalid or missing CGI parameters, or
3091 # requested object exists but has wrong type.
3092 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
3093 # this server or project.
3094 # 404: Requested object/revision/project doesn't exist.
3095 # 500: The server isn't configured properly, or
3096 # an internal error occurred (e.g. failed assertions caused by bugs), or
3097 # an unknown error occurred (e.g. the git binary died unexpectedly).
3099 my $status = shift || 500;
3100 my $error = shift || "Internal server error";
3102 my %http_responses = (400 => '400 Bad Request',
3103 403 => '403 Forbidden',
3104 404 => '404 Not Found',
3105 500 => '500 Internal Server Error');
3106 git_header_html
($http_responses{$status});
3108 <div class="page_body">
3118 ## ----------------------------------------------------------------------
3119 ## functions printing or outputting HTML: navigation
3121 sub git_print_page_nav
{
3122 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
3123 $extra = '' if !defined $extra; # pager or formats
3125 my @navs = qw(summary shortlog log commit commitdiff tree);
3127 @navs = grep { $_ ne $suppress } @navs;
3130 my %arg = map { $_ => {action
=>$_} } @navs;
3131 if (defined $head) {
3132 for (qw(commit commitdiff)) {
3133 $arg{$_}{'hash'} = $head;
3135 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
3136 for (qw(shortlog log)) {
3137 $arg{$_}{'hash'} = $head;
3142 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
3143 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
3145 my @actions = gitweb_get_feature
('actions');
3148 'n' => $project, # project name
3149 'f' => $git_dir, # project path within filesystem
3150 'h' => $treehead || '', # current hash ('h' parameter)
3151 'b' => $treebase || '', # hash base ('hb' parameter)
3154 my ($label, $link, $pos) = splice(@actions,0,3);
3156 @navs = map { $_ eq $pos ?
($_, $label) : $_ } @navs;
3158 $link =~ s/%([%nfhb])/$repl{$1}/g;
3159 $arg{$label}{'_href'} = $link;
3162 print "<div class=\"page_nav\">\n" .
3164 map { $_ eq $current ?
3165 $_ : $cgi->a({-href
=> ($arg{$_}{_href
} ?
$arg{$_}{_href
} : href
(%{$arg{$_}}))}, "$_")
3167 print "<br/>\n$extra<br/>\n" .
3171 sub format_paging_nav
{
3172 my ($action, $hash, $head, $page, $has_next_link) = @_;
3176 if ($hash ne $head || $page) {
3177 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
3179 $paging_nav .= "HEAD";
3183 $paging_nav .= " ⋅ " .
3184 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
3185 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3187 $paging_nav .= " ⋅ prev";
3190 if ($has_next_link) {
3191 $paging_nav .= " ⋅ " .
3192 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
3193 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3195 $paging_nav .= " ⋅ next";
3201 ## ......................................................................
3202 ## functions printing or outputting HTML: div
3204 sub git_print_header_div
{
3205 my ($action, $title, $hash, $hash_base) = @_;
3208 $args{'action'} = $action;
3209 $args{'hash'} = $hash if $hash;
3210 $args{'hash_base'} = $hash_base if $hash_base;
3212 print "<div class=\"header\">\n" .
3213 $cgi->a({-href
=> href
(%args), -class => "title"},
3214 $title ?
$title : $action) .
3218 #sub git_print_authorship (\%) {
3219 sub git_print_authorship
{
3222 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
3223 print "<div class=\"author_date\">" .
3224 esc_html
($co->{'author_name'}) .
3226 if ($ad{'hour_local'} < 6) {
3227 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3228 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3230 printf(" (%02d:%02d %s)",
3231 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3236 sub git_print_page_path
{
3242 print "<div class=\"page_path\">";
3243 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
3244 -title
=> 'tree root'}, to_utf8
("[$project]"));
3246 if (defined $name) {
3247 my @dirname = split '/', $name;
3248 my $basename = pop @dirname;
3251 foreach my $dir (@dirname) {
3252 $fullname .= ($fullname ?
'/' : '') . $dir;
3253 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
3255 -title
=> $fullname}, esc_path
($dir));
3258 if (defined $type && $type eq 'blob') {
3259 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
3261 -title
=> $name}, esc_path
($basename));
3262 } elsif (defined $type && $type eq 'tree') {
3263 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
3265 -title
=> $name}, esc_path
($basename));
3268 print esc_path
($basename);
3271 print "<br/></div>\n";
3274 # sub git_print_log (\@;%) {
3275 sub git_print_log
($;%) {
3279 if ($opts{'-remove_title'}) {
3280 # remove title, i.e. first line of log
3283 # remove leading empty lines
3284 while (defined $log->[0] && $log->[0] eq "") {
3291 foreach my $line (@
$log) {
3292 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
3295 if (! $opts{'-remove_signoff'}) {
3296 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
3299 # remove signoff lines
3306 # print only one empty line
3307 # do not print empty line after signoff
3309 next if ($empty || $signoff);
3315 print format_log_line_html
($line) . "<br/>\n";
3318 if ($opts{'-final_empty_line'}) {
3319 # end with single empty line
3320 print "<br/>\n" unless $empty;
3324 # return link target (what link points to)
3325 sub git_get_link_target
{
3330 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3334 $link_target = <$fd>;
3339 return $link_target;
3342 # given link target, and the directory (basedir) the link is in,
3343 # return target of link relative to top directory (top tree);
3344 # return undef if it is not possible (including absolute links).
3345 sub normalize_link_target
{
3346 my ($link_target, $basedir, $hash_base) = @_;
3348 # we can normalize symlink target only if $hash_base is provided
3349 return unless $hash_base;
3351 # absolute symlinks (beginning with '/') cannot be normalized
3352 return if (substr($link_target, 0, 1) eq '/');
3354 # normalize link target to path from top (root) tree (dir)
3357 $path = $basedir . '/' . $link_target;
3359 # we are in top (root) tree (dir)
3360 $path = $link_target;
3363 # remove //, /./, and /../
3365 foreach my $part (split('/', $path)) {
3366 # discard '.' and ''
3367 next if (!$part || $part eq '.');
3369 if ($part eq '..') {
3373 # link leads outside repository (outside top dir)
3377 push @path_parts, $part;
3380 $path = join('/', @path_parts);
3385 # print tree entry (row of git_tree), but without encompassing <tr> element
3386 sub git_print_tree_entry
{
3387 my ($t, $basedir, $hash_base, $have_blame) = @_;
3390 $base_key{'hash_base'} = $hash_base if defined $hash_base;
3392 # The format of a table row is: mode list link. Where mode is
3393 # the mode of the entry, list is the name of the entry, an href,
3394 # and link is the action links of the entry.
3396 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
3397 if ($t->{'type'} eq "blob") {
3398 print "<td class=\"list\">" .
3399 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3400 file_name
=>"$basedir$t->{'name'}", %base_key),
3401 -class => "list"}, esc_path
($t->{'name'}));
3402 if (S_ISLNK
(oct $t->{'mode'})) {
3403 my $link_target = git_get_link_target
($t->{'hash'});
3405 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
3406 if (defined $norm_target) {
3408 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
3409 file_name
=>$norm_target),
3410 -title
=> $norm_target}, esc_path
($link_target));
3412 print " -> " . esc_path
($link_target);
3417 print "<td class=\"link\">";
3418 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3419 file_name
=>"$basedir$t->{'name'}", %base_key)},
3423 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
3424 file_name
=>"$basedir$t->{'name'}", %base_key)},
3427 if (defined $hash_base) {
3429 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3430 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
3434 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
3435 file_name
=>"$basedir$t->{'name'}")},
3439 } elsif ($t->{'type'} eq "tree") {
3440 print "<td class=\"list\">";
3441 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3442 file_name
=>"$basedir$t->{'name'}", %base_key)},
3443 esc_path
($t->{'name'}));
3445 print "<td class=\"link\">";
3446 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3447 file_name
=>"$basedir$t->{'name'}", %base_key)},
3449 if (defined $hash_base) {
3451 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3452 file_name
=>"$basedir$t->{'name'}")},
3457 # unknown object: we can only present history for it
3458 # (this includes 'commit' object, i.e. submodule support)
3459 print "<td class=\"list\">" .
3460 esc_path
($t->{'name'}) .
3462 print "<td class=\"link\">";
3463 if (defined $hash_base) {
3464 print $cgi->a({-href
=> href
(action
=>"history",
3465 hash_base
=>$hash_base,
3466 file_name
=>"$basedir$t->{'name'}")},
3473 ## ......................................................................
3474 ## functions printing large fragments of HTML
3476 # get pre-image filenames for merge (combined) diff
3477 sub fill_from_file_info
{
3478 my ($diff, @parents) = @_;
3480 $diff->{'from_file'} = [ ];
3481 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
3482 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3483 if ($diff->{'status'}[$i] eq 'R' ||
3484 $diff->{'status'}[$i] eq 'C') {
3485 $diff->{'from_file'}[$i] =
3486 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
3493 # is current raw difftree line of file deletion
3495 my $diffinfo = shift;
3497 return $diffinfo->{'to_id'} eq ('0' x
40);
3500 # does patch correspond to [previous] difftree raw line
3501 # $diffinfo - hashref of parsed raw diff format
3502 # $patchinfo - hashref of parsed patch diff format
3503 # (the same keys as in $diffinfo)
3504 sub is_patch_split
{
3505 my ($diffinfo, $patchinfo) = @_;
3507 return defined $diffinfo && defined $patchinfo
3508 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3512 sub git_difftree_body
{
3513 my ($difftree, $hash, @parents) = @_;
3514 my ($parent) = $parents[0];
3515 my $have_blame = gitweb_check_feature
('blame');
3516 print "<div class=\"list_head\">\n";
3517 if ($#{$difftree} > 10) {
3518 print(($#{$difftree} + 1) . " files changed:\n");
3522 print "<table class=\"" .
3523 (@parents > 1 ?
"combined " : "") .
3526 # header only for combined diff in 'commitdiff' view
3527 my $has_header = @
$difftree && @parents > 1 && $action eq 'commitdiff';
3530 print "<thead><tr>\n" .
3531 "<th></th><th></th>\n"; # filename, patchN link
3532 for (my $i = 0; $i < @parents; $i++) {
3533 my $par = $parents[$i];
3535 $cgi->a({-href
=> href
(action
=>"commitdiff",
3536 hash
=>$hash, hash_parent
=>$par),
3537 -title
=> 'commitdiff to parent number ' .
3538 ($i+1) . ': ' . substr($par,0,7)},
3542 print "</tr></thead>\n<tbody>\n";
3547 foreach my $line (@
{$difftree}) {
3548 my $diff = parsed_difftree_line
($line);
3551 print "<tr class=\"dark\">\n";
3553 print "<tr class=\"light\">\n";
3557 if (exists $diff->{'nparents'}) { # combined diff
3559 fill_from_file_info
($diff, @parents)
3560 unless exists $diff->{'from_file'};
3562 if (!is_deleted
($diff)) {
3563 # file exists in the result (child) commit
3565 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3566 file_name
=>$diff->{'to_file'},
3568 -class => "list"}, esc_path
($diff->{'to_file'})) .
3572 esc_path
($diff->{'to_file'}) .
3576 if ($action eq 'commitdiff') {
3579 print "<td class=\"link\">" .
3580 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3585 my $has_history = 0;
3586 my $not_deleted = 0;
3587 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3588 my $hash_parent = $parents[$i];
3589 my $from_hash = $diff->{'from_id'}[$i];
3590 my $from_path = $diff->{'from_file'}[$i];
3591 my $status = $diff->{'status'}[$i];
3593 $has_history ||= ($status ne 'A');
3594 $not_deleted ||= ($status ne 'D');
3596 if ($status eq 'A') {
3597 print "<td class=\"link\" align=\"right\"> | </td>\n";
3598 } elsif ($status eq 'D') {
3599 print "<td class=\"link\">" .
3600 $cgi->a({-href
=> href
(action
=>"blob",
3603 file_name
=>$from_path)},
3607 if ($diff->{'to_id'} eq $from_hash) {
3608 print "<td class=\"link nochange\">";
3610 print "<td class=\"link\">";
3612 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3613 hash
=>$diff->{'to_id'},
3614 hash_parent
=>$from_hash,
3616 hash_parent_base
=>$hash_parent,
3617 file_name
=>$diff->{'to_file'},
3618 file_parent
=>$from_path)},
3624 print "<td class=\"link\">";
3626 print $cgi->a({-href
=> href
(action
=>"blob",
3627 hash
=>$diff->{'to_id'},
3628 file_name
=>$diff->{'to_file'},
3631 print " | " if ($has_history);
3634 print $cgi->a({-href
=> href
(action
=>"history",
3635 file_name
=>$diff->{'to_file'},
3642 next; # instead of 'else' clause, to avoid extra indent
3644 # else ordinary diff
3646 my ($to_mode_oct, $to_mode_str, $to_file_type);
3647 my ($from_mode_oct, $from_mode_str, $from_file_type);
3648 if ($diff->{'to_mode'} ne ('0' x
6)) {
3649 $to_mode_oct = oct $diff->{'to_mode'};
3650 if (S_ISREG
($to_mode_oct)) { # only for regular file
3651 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3653 $to_file_type = file_type
($diff->{'to_mode'});
3655 if ($diff->{'from_mode'} ne ('0' x
6)) {
3656 $from_mode_oct = oct $diff->{'from_mode'};
3657 if (S_ISREG
($to_mode_oct)) { # only for regular file
3658 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3660 $from_file_type = file_type
($diff->{'from_mode'});
3663 if ($diff->{'status'} eq "A") { # created
3664 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3665 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3666 $mode_chng .= "]</span>";
3668 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3669 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3670 -class => "list"}, esc_path
($diff->{'file'}));
3672 print "<td>$mode_chng</td>\n";
3673 print "<td class=\"link\">";
3674 if ($action eq 'commitdiff') {
3677 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3680 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3681 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3685 } elsif ($diff->{'status'} eq "D") { # deleted
3686 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3688 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3689 hash_base
=>$parent, file_name
=>$diff->{'file'}),
3690 -class => "list"}, esc_path
($diff->{'file'}));
3692 print "<td>$mode_chng</td>\n";
3693 print "<td class=\"link\">";
3694 if ($action eq 'commitdiff') {
3697 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3700 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3701 hash_base
=>$parent, file_name
=>$diff->{'file'})},
3704 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3705 file_name
=>$diff->{'file'})},
3708 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3709 file_name
=>$diff->{'file'})},
3713 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3714 my $mode_chnge = "";
3715 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3716 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3717 if ($from_file_type ne $to_file_type) {
3718 $mode_chnge .= " from $from_file_type to $to_file_type";
3720 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3721 if ($from_mode_str && $to_mode_str) {
3722 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3723 } elsif ($to_mode_str) {
3724 $mode_chnge .= " mode: $to_mode_str";
3727 $mode_chnge .= "]</span>\n";
3730 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3731 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3732 -class => "list"}, esc_path
($diff->{'file'}));
3734 print "<td>$mode_chnge</td>\n";
3735 print "<td class=\"link\">";
3736 if ($action eq 'commitdiff') {
3739 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3741 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3742 # "commit" view and modified file (not onlu mode changed)
3743 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3744 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3745 hash_base
=>$hash, hash_parent_base
=>$parent,
3746 file_name
=>$diff->{'file'})},
3750 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3751 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3754 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3755 file_name
=>$diff->{'file'})},
3758 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3759 file_name
=>$diff->{'file'})},
3763 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3764 my %status_name = ('R' => 'moved', 'C' => 'copied');
3765 my $nstatus = $status_name{$diff->{'status'}};
3767 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3768 # mode also for directories, so we cannot use $to_mode_str
3769 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3772 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3773 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
3774 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3775 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3776 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3777 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
3778 -class => "list"}, esc_path
($diff->{'from_file'})) .
3779 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3780 "<td class=\"link\">";
3781 if ($action eq 'commitdiff') {
3784 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3786 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3787 # "commit" view and modified file (not only pure rename or copy)
3788 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3789 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3790 hash_base
=>$hash, hash_parent_base
=>$parent,
3791 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
3795 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3796 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
3799 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3800 file_name
=>$diff->{'to_file'})},
3803 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3804 file_name
=>$diff->{'to_file'})},
3808 } # we should not encounter Unmerged (U) or Unknown (X) status
3811 print "</tbody>" if $has_header;
3815 sub git_patchset_body
{
3816 my ($fd, $difftree, $hash, @hash_parents) = @_;
3817 my ($hash_parent) = $hash_parents[0];
3819 my $is_combined = (@hash_parents > 1);
3821 my $patch_number = 0;
3827 print "<div class=\"patchset\">\n";
3829 # skip to first patch
3830 while ($patch_line = <$fd>) {
3833 last if ($patch_line =~ m/^diff /);
3837 while ($patch_line) {
3839 # parse "git diff" header line
3840 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
3841 # $1 is from_name, which we do not use
3842 $to_name = unquote
($2);
3843 $to_name =~ s!^b/!!;
3844 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
3845 # $1 is 'cc' or 'combined', which we do not use
3846 $to_name = unquote
($2);
3851 # check if current patch belong to current raw line
3852 # and parse raw git-diff line if needed
3853 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
3854 # this is continuation of a split patch
3855 print "<div class=\"patch cont\">\n";
3857 # advance raw git-diff output if needed
3858 $patch_idx++ if defined $diffinfo;
3860 # read and prepare patch information
3861 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3863 # compact combined diff output can have some patches skipped
3864 # find which patch (using pathname of result) we are at now;
3866 while ($to_name ne $diffinfo->{'to_file'}) {
3867 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3868 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3869 "</div>\n"; # class="patch"
3874 last if $patch_idx > $#$difftree;
3875 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3879 # modifies %from, %to hashes
3880 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
3882 # this is first patch for raw difftree line with $patch_idx index
3883 # we index @$difftree array from 0, but number patches from 1
3884 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3888 #assert($patch_line =~ m/^diff /) if DEBUG;
3889 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
3891 # print "git diff" header
3892 print format_git_diff_header_line
($patch_line, $diffinfo,
3895 # print extended diff header
3896 print "<div class=\"diff extended_header\">\n";
3898 while ($patch_line = <$fd>) {
3901 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
3903 print format_extended_diff_header_line
($patch_line, $diffinfo,
3906 print "</div>\n"; # class="diff extended_header"
3908 # from-file/to-file diff header
3909 if (! $patch_line) {
3910 print "</div>\n"; # class="patch"
3913 next PATCH
if ($patch_line =~ m/^diff /);
3914 #assert($patch_line =~ m/^---/) if DEBUG;
3916 my $last_patch_line = $patch_line;
3917 $patch_line = <$fd>;
3919 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3921 print format_diff_from_to_header
($last_patch_line, $patch_line,
3922 $diffinfo, \
%from, \
%to,
3927 while ($patch_line = <$fd>) {
3930 next PATCH
if ($patch_line =~ m/^diff /);
3932 print format_diff_line
($patch_line, \
%from, \
%to);
3936 print "</div>\n"; # class="patch"
3939 # for compact combined (--cc) format, with chunk and patch simpliciaction
3940 # patchset might be empty, but there might be unprocessed raw lines
3941 for (++$patch_idx if $patch_number > 0;
3942 $patch_idx < @
$difftree;
3944 # read and prepare patch information
3945 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3947 # generate anchor for "patch" links in difftree / whatchanged part
3948 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3949 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3950 "</div>\n"; # class="patch"
3955 if ($patch_number == 0) {
3956 if (@hash_parents > 1) {
3957 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3959 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3963 print "</div>\n"; # class="patchset"
3966 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3968 # fills project list info (age, description, owner, forks) for each
3969 # project in the list, removing invalid projects from returned list
3970 # NOTE: modifies $projlist, but does not remove entries from it
3971 sub fill_project_list_info
{
3972 my ($projlist, $check_forks) = @_;
3975 my $show_ctags = gitweb_check_feature
('ctags');
3977 foreach my $pr (@
$projlist) {
3978 my (@activity) = git_get_last_activity
($pr->{'path'});
3979 unless (@activity) {
3982 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
3983 if (!defined $pr->{'descr'}) {
3984 my $descr = git_get_project_description
($pr->{'path'}) || "";
3985 $descr = to_utf8
($descr);
3986 $pr->{'descr_long'} = $descr;
3987 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
3989 if (!defined $pr->{'owner'}) {
3990 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
3993 my $pname = $pr->{'path'};
3994 if (($pname =~ s/\.git$//) &&
3995 ($pname !~ /\/$/) &&
3996 (-d
"$projectroot/$pname")) {
3997 $pr->{'forks'} = "-d $projectroot/$pname";
4002 $show_ctags and $pr->{'ctags'} = git_get_project_ctags
($pr->{'path'});
4003 push @projects, $pr;
4009 # print 'sort by' <th> element, generating 'sort by $name' replay link
4010 # if that order is not selected
4012 my ($name, $order, $header) = @_;
4013 $header ||= ucfirst($name);
4015 if ($order eq $name) {
4016 print "<th>$header</th>\n";
4019 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
4020 -class => "header"}, $header) .
4025 sub git_project_list_body
{
4026 # actually uses global variable $project
4027 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
4029 my $check_forks = gitweb_check_feature
('forks');
4030 my @projects = fill_project_list_info
($projlist, $check_forks);
4032 $order ||= $default_projects_order;
4033 $from = 0 unless defined $from;
4034 $to = $#projects if (!defined $to || $#projects < $to);
4037 project
=> { key
=> 'path', type
=> 'str' },
4038 descr
=> { key
=> 'descr_long', type
=> 'str' },
4039 owner
=> { key
=> 'owner', type
=> 'str' },
4040 age
=> { key
=> 'age', type
=> 'num' }
4042 my $oi = $order_info{$order};
4043 if ($oi->{'type'} eq 'str') {
4044 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
4046 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
4049 my $show_ctags = gitweb_check_feature
('ctags');
4052 foreach my $p (@projects) {
4053 foreach my $ct (keys %{$p->{'ctags'}}) {
4054 $ctags{$ct} += $p->{'ctags'}->{$ct};
4057 my $cloud = git_populate_project_tagcloud
(\
%ctags);
4058 print git_show_project_tagcloud
($cloud, 64);
4061 print "<table class=\"project_list\">\n";
4062 unless ($no_header) {
4065 print "<th></th>\n";
4067 print_sort_th
('project', $order, 'Project');
4068 print_sort_th
('descr', $order, 'Description');
4069 print_sort_th
('owner', $order, 'Owner');
4070 print_sort_th
('age', $order, 'Last Change');
4071 print "<th></th>\n" . # for links
4075 my $tagfilter = $cgi->param('by_tag');
4076 for (my $i = $from; $i <= $to; $i++) {
4077 my $pr = $projects[$i];
4079 next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}};
4080 next if $searchtext and not $pr->{'path'} =~ /$searchtext/
4081 and not $pr->{'descr_long'} =~ /$searchtext/;
4082 # Weed out forks or non-matching entries of search
4084 my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s
#\.git$#/#;
4085 $forkbase="^$forkbase" if $forkbase;
4086 next if not $searchtext and not $tagfilter and $show_ctags
4087 and $pr->{'path'} =~ m
#$forkbase.*/.*#; # regexp-safe
4091 print "<tr class=\"dark\">\n";
4093 print "<tr class=\"light\">\n";
4098 if ($pr->{'forks'}) {
4099 print "<!-- $pr->{'forks'} -->\n";
4100 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
4104 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4105 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
4106 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4107 -class => "list", -title
=> $pr->{'descr_long'}},
4108 esc_html
($pr->{'descr'})) . "</td>\n" .
4109 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
4110 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
4111 (defined $pr->{'age_string'} ?
$pr->{'age_string'} : "No commits") . "</td>\n" .
4112 "<td class=\"link\">" .
4113 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
4114 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
4115 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
4116 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
4117 ($pr->{'forks'} ?
" | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
4121 if (defined $extra) {
4124 print "<td></td>\n";
4126 print "<td colspan=\"5\">$extra</td>\n" .
4132 sub git_shortlog_body
{
4133 # uses global variable $project
4134 my ($commitlist, $from, $to, $refs, $extra) = @_;
4136 $from = 0 unless defined $from;
4137 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4139 print "<table class=\"shortlog\">\n";
4141 for (my $i = $from; $i <= $to; $i++) {
4142 my %co = %{$commitlist->[$i]};
4143 my $commit = $co{'id'};
4144 my $ref = format_ref_marker
($refs, $commit);
4146 print "<tr class=\"dark\">\n";
4148 print "<tr class=\"light\">\n";
4151 my $author = chop_and_escape_str
($co{'author_name'}, 10);
4152 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
4153 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4154 "<td><i>" . $author . "</i></td>\n" .
4156 print format_subject_html
($co{'title'}, $co{'title_short'},
4157 href
(action
=>"commit", hash
=>$commit), $ref);
4159 "<td class=\"link\">" .
4160 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
4161 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
4162 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
4163 my $snapshot_links = format_snapshot_links
($commit);
4164 if (defined $snapshot_links) {
4165 print " | " . $snapshot_links;
4170 if (defined $extra) {
4172 "<td colspan=\"4\">$extra</td>\n" .
4178 sub git_history_body
{
4179 # Warning: assumes constant type (blob or tree) during history
4180 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
4182 $from = 0 unless defined $from;
4183 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
4185 print "<table class=\"history\">\n";
4187 for (my $i = $from; $i <= $to; $i++) {
4188 my %co = %{$commitlist->[$i]};
4192 my $commit = $co{'id'};
4194 my $ref = format_ref_marker
($refs, $commit);
4197 print "<tr class=\"dark\">\n";
4199 print "<tr class=\"light\">\n";
4202 # shortlog uses chop_str($co{'author_name'}, 10)
4203 my $author = chop_and_escape_str
($co{'author_name'}, 15, 3);
4204 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4205 "<td><i>" . $author . "</i></td>\n" .
4207 # originally git_history used chop_str($co{'title'}, 50)
4208 print format_subject_html
($co{'title'}, $co{'title_short'},
4209 href
(action
=>"commit", hash
=>$commit), $ref);
4211 "<td class=\"link\">" .
4212 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
4213 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
4215 if ($ftype eq 'blob') {
4216 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
4217 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
4218 if (defined $blob_current && defined $blob_parent &&
4219 $blob_current ne $blob_parent) {
4221 $cgi->a({-href
=> href
(action
=>"blobdiff",
4222 hash
=>$blob_current, hash_parent
=>$blob_parent,
4223 hash_base
=>$hash_base, hash_parent_base
=>$commit,
4224 file_name
=>$file_name)},
4231 if (defined $extra) {
4233 "<td colspan=\"4\">$extra</td>\n" .
4240 # uses global variable $project
4241 my ($taglist, $from, $to, $extra) = @_;
4242 $from = 0 unless defined $from;
4243 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
4245 print "<table class=\"tags\">\n";
4247 for (my $i = $from; $i <= $to; $i++) {
4248 my $entry = $taglist->[$i];
4250 my $comment = $tag{'subject'};
4252 if (defined $comment) {
4253 $comment_short = chop_str
($comment, 30, 5);
4256 print "<tr class=\"dark\">\n";
4258 print "<tr class=\"light\">\n";
4261 if (defined $tag{'age'}) {
4262 print "<td><i>$tag{'age'}</i></td>\n";
4264 print "<td></td>\n";
4267 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
4268 -class => "list name"}, esc_html
($tag{'name'})) .
4271 if (defined $comment) {
4272 print format_subject_html
($comment, $comment_short,
4273 href
(action
=>"tag", hash
=>$tag{'id'}));
4276 "<td class=\"selflink\">";
4277 if ($tag{'type'} eq "tag") {
4278 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
4283 "<td class=\"link\">" . " | " .
4284 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
4285 if ($tag{'reftype'} eq "commit") {
4286 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
4287 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
4288 } elsif ($tag{'reftype'} eq "blob") {
4289 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
4294 if (defined $extra) {
4296 "<td colspan=\"5\">$extra</td>\n" .
4302 sub git_heads_body
{
4303 # uses global variable $project
4304 my ($headlist, $head, $from, $to, $extra) = @_;
4305 $from = 0 unless defined $from;
4306 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
4308 print "<table class=\"heads\">\n";
4310 for (my $i = $from; $i <= $to; $i++) {
4311 my $entry = $headlist->[$i];
4313 my $curr = $ref{'id'} eq $head;
4315 print "<tr class=\"dark\">\n";
4317 print "<tr class=\"light\">\n";
4320 print "<td><i>$ref{'age'}</i></td>\n" .
4321 ($curr ?
"<td class=\"current_head\">" : "<td>") .
4322 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
4323 -class => "list name"},esc_html
($ref{'name'})) .
4325 "<td class=\"link\">" .
4326 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
4327 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
4328 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
4332 if (defined $extra) {
4334 "<td colspan=\"3\">$extra</td>\n" .
4340 sub git_search_grep_body
{
4341 my ($commitlist, $from, $to, $extra) = @_;
4342 $from = 0 unless defined $from;
4343 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4345 print "<table class=\"commit_search\">\n";
4347 for (my $i = $from; $i <= $to; $i++) {
4348 my %co = %{$commitlist->[$i]};
4352 my $commit = $co{'id'};
4354 print "<tr class=\"dark\">\n";
4356 print "<tr class=\"light\">\n";
4359 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
4360 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4361 "<td><i>" . $author . "</i></td>\n" .
4363 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4364 -class => "list subject"},
4365 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
4366 my $comment = $co{'comment'};
4367 foreach my $line (@
$comment) {
4368 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
4369 my ($lead, $match, $trail) = ($1, $2, $3);
4370 $match = chop_str
($match, 70, 5, 'center');
4371 my $contextlen = int((80 - length($match))/2);
4372 $contextlen = 30 if ($contextlen > 30);
4373 $lead = chop_str
($lead, $contextlen, 10, 'left');
4374 $trail = chop_str
($trail, $contextlen, 10, 'right');
4376 $lead = esc_html
($lead);
4377 $match = esc_html
($match);
4378 $trail = esc_html
($trail);
4380 print "$lead<span class=\"match\">$match</span>$trail<br />";
4384 "<td class=\"link\">" .
4385 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4387 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
4389 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4393 if (defined $extra) {
4395 "<td colspan=\"3\">$extra</td>\n" .
4401 ## ======================================================================
4402 ## ======================================================================
4405 sub git_project_list
{
4406 my $order = $input_params{'order'};
4407 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4408 die_error
(400, "Unknown order parameter");
4411 my @list = git_get_projects_list
();
4413 die_error
(404, "No projects found");
4417 if (-f
$home_text) {
4418 print "<div class=\"index_include\">\n";
4419 insert_file
($home_text);
4422 print $cgi->startform(-method
=> "get") .
4423 "<p class=\"projsearch\">Search:\n" .
4424 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
4426 $cgi->end_form() . "\n";
4427 git_project_list_body
(\
@list, $order);
4432 my $order = $input_params{'order'};
4433 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4434 die_error
(400, "Unknown order parameter");
4437 my @list = git_get_projects_list
($project);
4439 die_error
(404, "No forks found");
4443 git_print_page_nav
('','');
4444 git_print_header_div
('summary', "$project forks");
4445 git_project_list_body
(\
@list, $order);
4449 sub git_project_index
{
4450 my @projects = git_get_projects_list
($project);
4453 -type
=> 'text/plain',
4454 -charset
=> 'utf-8',
4455 -content_disposition
=> 'inline; filename="index.aux"');
4457 foreach my $pr (@projects) {
4458 if (!exists $pr->{'owner'}) {
4459 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
4462 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
4463 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
4464 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4465 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4469 print "$path $owner\n";
4474 my $descr = git_get_project_description
($project) || "none";
4475 my %co = parse_commit
("HEAD");
4476 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
4477 my $head = $co{'id'};
4479 my $owner = git_get_project_owner
($project);
4481 my $refs = git_get_references
();
4482 # These get_*_list functions return one more to allow us to see if
4483 # there are more ...
4484 my @taglist = git_get_tags_list
(16);
4485 my @headlist = git_get_heads_list
(16);
4487 my $check_forks = gitweb_check_feature
('forks');
4490 @forklist = git_get_projects_list
($project);
4494 git_print_page_nav
('summary','', $head);
4496 print "<div class=\"title\"> </div>\n";
4497 print "<table class=\"projects_list\">\n" .
4498 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
4499 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
4500 if (defined $cd{'rfc2822'}) {
4501 print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4504 # use per project git URL list in $projectroot/$project/cloneurl
4505 # or make project git URL from git base URL and project name
4506 my $url_tag = "URL";
4507 my @url_list = git_get_project_url_list
($project);
4508 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4509 foreach my $git_url (@url_list) {
4510 next unless $git_url;
4511 print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";
4516 my $show_ctags = gitweb_check_feature
('ctags');
4518 my $ctags = git_get_project_ctags
($project);
4519 my $cloud = git_populate_project_tagcloud
($ctags);
4520 print "<tr id=\"metadata_ctags\"><td>Content tags:<br />";
4521 print "</td>\n<td>" unless %$ctags;
4522 print "<form action=\"$show_ctags\" method=\"post\"><input type=\"hidden\" name=\"p\" value=\"$project\" />Add: <input type=\"text\" name=\"t\" size=\"8\" /></form>";
4523 print "</td>\n<td>" if %$ctags;
4524 print git_show_project_tagcloud
($cloud, 48);
4530 # If XSS prevention is on, we don't include README.html.
4531 # TODO: Allow a readme in some safe format.
4532 if (!$prevent_xss && -s
"$projectroot/$project/README.html") {
4533 print "<div class=\"title\">readme</div>\n" .
4534 "<div class=\"readme\">\n";
4535 insert_file
("$projectroot/$project/README.html");
4536 print "\n</div>\n"; # class="readme"
4539 # we need to request one more than 16 (0..15) to check if
4541 my @commitlist = $head ? parse_commits
($head, 17) : ();
4543 git_print_header_div
('shortlog');
4544 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
4545 $#commitlist <= 15 ?
undef :
4546 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
4550 git_print_header_div
('tags');
4551 git_tags_body
(\
@taglist, 0, 15,
4552 $#taglist <= 15 ?
undef :
4553 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
4557 git_print_header_div
('heads');
4558 git_heads_body
(\
@headlist, $head, 0, 15,
4559 $#headlist <= 15 ?
undef :
4560 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
4564 git_print_header_div
('forks');
4565 git_project_list_body
(\
@forklist, 'age', 0, 15,
4566 $#forklist <= 15 ?
undef :
4567 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
4575 my $head = git_get_head_hash
($project);
4577 git_print_page_nav
('','', $head,undef,$head);
4578 my %tag = parse_tag
($hash);
4581 die_error
(404, "Unknown tag object");
4584 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
4585 print "<div class=\"title_text\">\n" .
4586 "<table class=\"object_header\">\n" .
4588 "<td>object</td>\n" .
4589 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4590 $tag{'object'}) . "</td>\n" .
4591 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4592 $tag{'type'}) . "</td>\n" .
4594 if (defined($tag{'author'})) {
4595 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
4596 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
4597 print "<tr><td></td><td>" . $ad{'rfc2822'} .
4598 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
4601 print "</table>\n\n" .
4603 print "<div class=\"page_body\">";
4604 my $comment = $tag{'comment'};
4605 foreach my $line (@
$comment) {
4607 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4615 gitweb_check_feature
('blame')
4616 or die_error
(403, "Blame view not allowed");
4619 die_error
(400, "No file name given") unless $file_name;
4620 $hash_base ||= git_get_head_hash
($project);
4621 die_error
(404, "Couldn't find base commit") unless $hash_base;
4622 my %co = parse_commit
($hash_base)
4623 or die_error
(404, "Commit not found");
4625 if (!defined $hash) {
4626 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4627 or die_error
(404, "Error looking up file");
4629 $ftype = git_get_type
($hash);
4630 if ($ftype !~ "blob") {
4631 die_error
(400, "Object is not a blob");
4635 # run git-blame --porcelain
4636 open my $fd, "-|", git_cmd
(), "blame", '-p',
4637 $hash_base, '--', $file_name
4638 or die_error
(500, "Open git-blame failed");
4643 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
4646 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4649 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4651 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4652 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4653 git_print_page_path
($file_name, $ftype, $hash_base);
4656 my @rev_color = qw(light2 dark2);
4657 my $num_colors = scalar(@rev_color);
4658 my $current_color = 0;
4662 <div class="page_body">
4663 <table class="blame">
4664 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
4667 while (my $line = <$fd>) {
4669 # the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]
4670 # no <lines in group> for subsequent lines in group of lines
4671 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4672 ($line =~ /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);
4673 if (!exists $metainfo{$full_rev}) {
4674 $metainfo{$full_rev} = {};
4676 my $meta = $metainfo{$full_rev};
4678 while ($data = <$fd>) {
4680 last if ($data =~ s/^\t//); # contents of line
4681 if ($data =~ /^(\S+) (.*)$/) {
4685 my $short_rev = substr($full_rev, 0, 8);
4686 my $author = $meta->{'author'};
4688 parse_date
($meta->{'author-time'}, $meta->{'author-tz'});
4689 my $date = $date{'iso-tz'};
4691 $current_color = ($current_color + 1) % $num_colors;
4693 print "<tr id=\"l$lineno\" class=\"$rev_color[$current_color]\">\n";
4695 print "<td class=\"sha1\"";
4696 print " title=\"". esc_html
($author) . ", $date\"";
4697 print " rowspan=\"$group_size\"" if ($group_size > 1);
4699 print $cgi->a({-href
=> href
(action
=>"commit",
4701 file_name
=>$file_name)},
4702 esc_html
($short_rev));
4706 if (!exists $meta->{'parent'}) {
4707 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
4708 or die_error
(500, "Open git-rev-parse failed");
4709 $parent_commit = <$dd>;
4711 chomp($parent_commit);
4712 $meta->{'parent'} = $parent_commit;
4714 $parent_commit = $meta->{'parent'};
4716 my $blamed = href
(action
=> 'blame',
4717 file_name
=> $meta->{'filename'},
4718 hash_base
=> $parent_commit);
4719 print "<td class=\"linenr\">";
4720 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
4721 -class => "linenr" },
4724 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
4730 or print "Reading blob failed\n";
4737 my $head = git_get_head_hash
($project);
4739 git_print_page_nav
('','', $head,undef,$head);
4740 git_print_header_div
('summary', $project);
4742 my @tagslist = git_get_tags_list
();
4744 git_tags_body
(\
@tagslist);
4750 my $head = git_get_head_hash
($project);
4752 git_print_page_nav
('','', $head,undef,$head);
4753 git_print_header_div
('summary', $project);
4755 my @headslist = git_get_heads_list
();
4757 git_heads_body
(\
@headslist, $head);
4762 sub git_blob_plain
{
4766 if (!defined $hash) {
4767 if (defined $file_name) {
4768 my $base = $hash_base || git_get_head_hash
($project);
4769 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4770 or die_error
(404, "Cannot find file");
4772 die_error
(400, "No file name defined");
4774 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4775 # blobs defined by non-textual hash id's can be cached
4779 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4780 or die_error
(500, "Open git-cat-file blob '$hash' failed");
4782 # content-type (can include charset)
4783 $type = blob_contenttype
($fd, $file_name, $type);
4785 # "save as" filename, even when no $file_name is given
4786 my $save_as = "$hash";
4787 if (defined $file_name) {
4788 $save_as = $file_name;
4789 } elsif ($type =~ m/^text\//) {
4793 # With XSS prevention on, blobs of all types except a few known safe
4794 # ones are served with "Content-Disposition: attachment" to make sure
4795 # they don't run in our security domain. For certain image types,
4796 # blob view writes an <img> tag referring to blob_plain view, and we
4797 # want to be sure not to break that by serving the image as an
4798 # attachment (though Firefox 3 doesn't seem to care).
4799 my $sandbox = $prevent_xss &&
4800 $type !~ m!^(?:text/plain|image/(?:gif|png|jpeg))$!;
4804 -expires
=> $expires,
4805 -content_disposition
=>
4806 ($sandbox ?
'attachment' : 'inline')
4807 . '; filename="' . $save_as . '"');
4809 binmode STDOUT
, ':raw';
4811 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4819 if (!defined $hash) {
4820 if (defined $file_name) {
4821 my $base = $hash_base || git_get_head_hash
($project);
4822 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4823 or die_error
(404, "Cannot find file");
4825 die_error
(400, "No file name defined");
4827 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4828 # blobs defined by non-textual hash id's can be cached
4832 my $have_blame = gitweb_check_feature
('blame');
4833 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4834 or die_error
(500, "Couldn't cat $file_name, $hash");
4835 my $mimetype = blob_mimetype
($fd, $file_name);
4836 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
4838 return git_blob_plain
($mimetype);
4840 # we can have blame only for text/* mimetype
4841 $have_blame &&= ($mimetype =~ m!^text/!);
4843 git_header_html
(undef, $expires);
4844 my $formats_nav = '';
4845 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4846 if (defined $file_name) {
4849 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
4854 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4857 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4860 $cgi->a({-href
=> href
(action
=>"blob",
4861 hash_base
=>"HEAD", file_name
=>$file_name)},
4865 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4868 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4869 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4871 print "<div class=\"page_nav\">\n" .
4872 "<br/><br/></div>\n" .
4873 "<div class=\"title\">$hash</div>\n";
4875 git_print_page_path
($file_name, "blob", $hash_base);
4876 print "<div class=\"page_body\">\n";
4877 if ($mimetype =~ m!^image/!) {
4878 print qq!<img type
="$mimetype"!;
4880 print qq! alt
="$file_name" title
="$file_name"!;
4883 href(action=>"blob_plain
", hash=>$hash,
4884 hash_base=>$hash_base, file_name=>$file_name) .
4888 while (my $line = <$fd>) {
4891 $line = untabify
($line);
4892 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4893 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4897 or print "Reading blob failed.\n";
4903 if (!defined $hash_base) {
4904 $hash_base = "HEAD";
4906 if (!defined $hash) {
4907 if (defined $file_name) {
4908 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4913 die_error
(404, "No such tree") unless defined($hash);
4915 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4916 or die_error
(500, "Open git-ls-tree failed");
4917 my @entries = map { chomp; $_ } <$fd>;
4918 close $fd or die_error
(404, "Reading tree failed");
4921 my $refs = git_get_references
();
4922 my $ref = format_ref_marker
($refs, $hash_base);
4925 my $have_blame = gitweb_check_feature
('blame');
4926 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4928 if (defined $file_name) {
4930 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4932 $cgi->a({-href
=> href
(action
=>"tree",
4933 hash_base
=>"HEAD", file_name
=>$file_name)},
4936 my $snapshot_links = format_snapshot_links
($hash);
4937 if (defined $snapshot_links) {
4938 # FIXME: Should be available when we have no hash base as well.
4939 push @views_nav, $snapshot_links;
4941 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4942 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4945 print "<div class=\"page_nav\">\n";
4946 print "<br/><br/></div>\n";
4947 print "<div class=\"title\">$hash</div>\n";
4949 if (defined $file_name) {
4950 $basedir = $file_name;
4951 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4954 git_print_page_path
($file_name, 'tree', $hash_base);
4956 print "<div class=\"page_body\">\n";
4957 print "<table class=\"tree\">\n";
4959 # '..' (top directory) link if possible
4960 if (defined $hash_base &&
4961 defined $file_name && $file_name =~ m![^/]+$!) {
4963 print "<tr class=\"dark\">\n";
4965 print "<tr class=\"light\">\n";
4969 my $up = $file_name;
4970 $up =~ s!/?[^/]+$!!;
4971 undef $up unless $up;
4972 # based on git_print_tree_entry
4973 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4974 print '<td class="list">';
4975 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4979 print "<td class=\"link\"></td>\n";
4983 foreach my $line (@entries) {
4984 my %t = parse_ls_tree_line
($line, -z
=> 1);
4987 print "<tr class=\"dark\">\n";
4989 print "<tr class=\"light\">\n";
4993 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4997 print "</table>\n" .
5003 my $format = $input_params{'snapshot_format'};
5004 if (!@snapshot_fmts) {
5005 die_error
(403, "Snapshots not allowed");
5007 # default to first supported snapshot format
5008 $format ||= $snapshot_fmts[0];
5009 if ($format !~ m/^[a-z0-9]+$/) {
5010 die_error
(400, "Invalid snapshot format parameter");
5011 } elsif (!exists($known_snapshot_formats{$format})) {
5012 die_error
(400, "Unknown snapshot format");
5013 } elsif (!grep($_ eq $format, @snapshot_fmts)) {
5014 die_error
(403, "Unsupported snapshot format");
5017 if (!defined $hash) {
5018 $hash = git_get_head_hash
($project);
5021 my $name = $project;
5022 $name =~ s
,([^/])/*\
.git
$,$1,;
5023 $name = basename
($name);
5024 my $filename = to_utf8
($name);
5025 $name =~ s/\047/\047\\\047\047/g;
5027 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
5028 $cmd = quote_command
(
5029 git_cmd
(), 'archive',
5030 "--format=$known_snapshot_formats{$format}{'format'}",
5031 "--prefix=$name/", $hash);
5032 if (exists $known_snapshot_formats{$format}{'compressor'}) {
5033 $cmd .= ' | ' . quote_command
(@
{$known_snapshot_formats{$format}{'compressor'}});
5037 -type
=> $known_snapshot_formats{$format}{'type'},
5038 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
5039 -status
=> '200 OK');
5041 open my $fd, "-|", $cmd
5042 or die_error
(500, "Execute git-archive failed");
5043 binmode STDOUT
, ':raw';
5045 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5050 my $head = git_get_head_hash
($project);
5051 if (!defined $hash) {
5054 if (!defined $page) {
5057 my $refs = git_get_references
();
5059 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5061 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#commitlist >= 100);
5063 my ($patch_max) = gitweb_get_feature
('patches');
5065 if ($patch_max < 0 || @commitlist <= $patch_max) {
5066 $paging_nav .= " ⋅ " .
5067 $cgi->a({-href
=> href
(action
=>"patches", -replay
=>1)},
5073 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
5076 my %co = parse_commit
($hash);
5078 git_print_header_div
('summary', $project);
5079 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
5081 my $to = ($#commitlist >= 99) ?
(99) : ($#commitlist);
5082 for (my $i = 0; $i <= $to; $i++) {
5083 my %co = %{$commitlist[$i]};
5085 my $commit = $co{'id'};
5086 my $ref = format_ref_marker
($refs, $commit);
5087 my %ad = parse_date
($co{'author_epoch'});
5088 git_print_header_div
('commit',
5089 "<span class=\"age\">$co{'age_string'}</span>" .
5090 esc_html
($co{'title'}) . $ref,
5092 print "<div class=\"title_text\">\n" .
5093 "<div class=\"log_link\">\n" .
5094 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
5096 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
5098 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
5101 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
5104 print "<div class=\"log_body\">\n";
5105 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
5108 if ($#commitlist >= 100) {
5109 print "<div class=\"page_nav\">\n";
5110 print $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5111 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5118 $hash ||= $hash_base || "HEAD";
5119 my %co = parse_commit
($hash)
5120 or die_error
(404, "Unknown commit object");
5121 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5122 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
5124 my $parent = $co{'parent'};
5125 my $parents = $co{'parents'}; # listref
5127 # we need to prepare $formats_nav before any parameter munging
5129 if (!defined $parent) {
5131 $formats_nav .= '(initial)';
5132 } elsif (@
$parents == 1) {
5133 # single parent commit
5136 $cgi->a({-href
=> href
(action
=>"commit",
5138 esc_html
(substr($parent, 0, 7))) .
5145 $cgi->a({-href
=> href
(action
=>"commit",
5147 esc_html
(substr($_, 0, 7)));
5151 if (gitweb_check_feature
('patches')) {
5152 $formats_nav .= " | " .
5153 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
5157 if (!defined $parent) {
5161 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
5163 (@
$parents <= 1 ?
$parent : '-c'),
5165 or die_error
(500, "Open git-diff-tree failed");
5166 @difftree = map { chomp; $_ } <$fd>;
5167 close $fd or die_error
(404, "Reading git-diff-tree failed");
5169 # non-textual hash id's can be cached
5171 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5174 my $refs = git_get_references
();
5175 my $ref = format_ref_marker
($refs, $co{'id'});
5177 git_header_html
(undef, $expires);
5178 git_print_page_nav
('commit', '',
5179 $hash, $co{'tree'}, $hash,
5182 if (defined $co{'parent'}) {
5183 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
5185 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
5187 print "<div class=\"title_text\">\n" .
5188 "<table class=\"object_header\">\n";
5189 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
5191 "<td></td><td> $ad{'rfc2822'}";
5192 if ($ad{'hour_local'} < 6) {
5193 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
5194 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
5196 printf(" (%02d:%02d %s)",
5197 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
5201 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
5202 print "<tr><td></td><td> $cd{'rfc2822'}" .
5203 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
5205 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
5208 "<td class=\"sha1\">" .
5209 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
5210 class => "list"}, $co{'tree'}) .
5212 "<td class=\"link\">" .
5213 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
5215 my $snapshot_links = format_snapshot_links
($hash);
5216 if (defined $snapshot_links) {
5217 print " | " . $snapshot_links;
5222 foreach my $par (@
$parents) {
5225 "<td class=\"sha1\">" .
5226 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
5227 class => "list"}, $par) .
5229 "<td class=\"link\">" .
5230 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
5232 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
5239 print "<div class=\"page_body\">\n";
5240 git_print_log
($co{'comment'});
5243 git_difftree_body
(\
@difftree, $hash, @
$parents);
5249 # object is defined by:
5250 # - hash or hash_base alone
5251 # - hash_base and file_name
5254 # - hash or hash_base alone
5255 if ($hash || ($hash_base && !defined $file_name)) {
5256 my $object_id = $hash || $hash_base;
5258 open my $fd, "-|", quote_command
(
5259 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
5260 or die_error
(404, "Object does not exist");
5264 or die_error
(404, "Object does not exist");
5266 # - hash_base and file_name
5267 } elsif ($hash_base && defined $file_name) {
5268 $file_name =~ s
,/+$,,;
5270 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
5271 or die_error
(404, "Base object does not exist");
5273 # here errors should not hapen
5274 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
5275 or die_error
(500, "Open git-ls-tree failed");
5279 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
5280 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
5281 die_error
(404, "File or directory for given base does not exist");
5286 die_error
(400, "Not enough information to find object");
5289 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
5290 hash
=>$hash, hash_base
=>$hash_base,
5291 file_name
=>$file_name),
5292 -status
=> '302 Found');
5296 my $format = shift || 'html';
5303 # preparing $fd and %diffinfo for git_patchset_body
5305 if (defined $hash_base && defined $hash_parent_base) {
5306 if (defined $file_name) {
5308 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5309 $hash_parent_base, $hash_base,
5310 "--", (defined $file_parent ?
$file_parent : ()), $file_name
5311 or die_error
(500, "Open git-diff-tree failed");
5312 @difftree = map { chomp; $_ } <$fd>;
5314 or die_error
(404, "Reading git-diff-tree failed");
5316 or die_error
(404, "Blob diff not found");
5318 } elsif (defined $hash &&
5319 $hash =~ /[0-9a-fA-F]{40}/) {
5320 # try to find filename from $hash
5322 # read filtered raw output
5323 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5324 $hash_parent_base, $hash_base, "--"
5325 or die_error
(500, "Open git-diff-tree failed");
5327 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
5329 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
5330 map { chomp; $_ } <$fd>;
5332 or die_error
(404, "Reading git-diff-tree failed");
5334 or die_error
(404, "Blob diff not found");
5337 die_error
(400, "Missing one of the blob diff parameters");
5340 if (@difftree > 1) {
5341 die_error
(400, "Ambiguous blob diff specification");
5344 %diffinfo = parse_difftree_raw_line
($difftree[0]);
5345 $file_parent ||= $diffinfo{'from_file'} || $file_name;
5346 $file_name ||= $diffinfo{'to_file'};
5348 $hash_parent ||= $diffinfo{'from_id'};
5349 $hash ||= $diffinfo{'to_id'};
5351 # non-textual hash id's can be cached
5352 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
5353 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
5358 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5359 '-p', ($format eq 'html' ?
"--full-index" : ()),
5360 $hash_parent_base, $hash_base,
5361 "--", (defined $file_parent ?
$file_parent : ()), $file_name
5362 or die_error
(500, "Open git-diff-tree failed");
5365 # old/legacy style URI -- not generated anymore since 1.4.3.
5367 die_error
('404 Not Found', "Missing one of the blob diff parameters")
5371 if ($format eq 'html') {
5373 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
5375 git_header_html
(undef, $expires);
5376 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5377 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5378 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5380 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
5381 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
5383 if (defined $file_name) {
5384 git_print_page_path
($file_name, "blob", $hash_base);
5386 print "<div class=\"page_path\"></div>\n";
5389 } elsif ($format eq 'plain') {
5391 -type
=> 'text/plain',
5392 -charset
=> 'utf-8',
5393 -expires
=> $expires,
5394 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
5396 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5399 die_error
(400, "Unknown blobdiff format");
5403 if ($format eq 'html') {
5404 print "<div class=\"page_body\">\n";
5406 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
5409 print "</div>\n"; # class="page_body"
5413 while (my $line = <$fd>) {
5414 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
5415 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
5419 last if $line =~ m!^\+\+\+!;
5427 sub git_blobdiff_plain
{
5428 git_blobdiff
('plain');
5431 sub git_commitdiff
{
5433 my $format = $params{-format
} || 'html';
5435 my ($patch_max) = gitweb_get_feature
('patches');
5436 if ($format eq 'patch') {
5437 die_error
(403, "Patch view not allowed") unless $patch_max;
5440 $hash ||= $hash_base || "HEAD";
5441 my %co = parse_commit
($hash)
5442 or die_error
(404, "Unknown commit object");
5444 # choose format for commitdiff for merge
5445 if (! defined $hash_parent && @
{$co{'parents'}} > 1) {
5446 $hash_parent = '--cc';
5448 # we need to prepare $formats_nav before almost any parameter munging
5450 if ($format eq 'html') {
5452 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
5455 $formats_nav .= " | " .
5456 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
5460 if (defined $hash_parent &&
5461 $hash_parent ne '-c' && $hash_parent ne '--cc') {
5462 # commitdiff with two commits given
5463 my $hash_parent_short = $hash_parent;
5464 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5465 $hash_parent_short = substr($hash_parent, 0, 7);
5469 for (my $i = 0; $i < @
{$co{'parents'}}; $i++) {
5470 if ($co{'parents'}[$i] eq $hash_parent) {
5471 $formats_nav .= ' parent ' . ($i+1);
5475 $formats_nav .= ': ' .
5476 $cgi->a({-href
=> href
(action
=>"commitdiff",
5477 hash
=>$hash_parent)},
5478 esc_html
($hash_parent_short)) .
5480 } elsif (!$co{'parent'}) {
5482 $formats_nav .= ' (initial)';
5483 } elsif (scalar @
{$co{'parents'}} == 1) {
5484 # single parent commit
5487 $cgi->a({-href
=> href
(action
=>"commitdiff",
5488 hash
=>$co{'parent'})},
5489 esc_html
(substr($co{'parent'}, 0, 7))) .
5493 if ($hash_parent eq '--cc') {
5494 $formats_nav .= ' | ' .
5495 $cgi->a({-href
=> href
(action
=>"commitdiff",
5496 hash
=>$hash, hash_parent
=>'-c')},
5498 } else { # $hash_parent eq '-c'
5499 $formats_nav .= ' | ' .
5500 $cgi->a({-href
=> href
(action
=>"commitdiff",
5501 hash
=>$hash, hash_parent
=>'--cc')},
5507 $cgi->a({-href
=> href
(action
=>"commitdiff",
5509 esc_html
(substr($_, 0, 7)));
5510 } @
{$co{'parents'}} ) .
5515 my $hash_parent_param = $hash_parent;
5516 if (!defined $hash_parent_param) {
5517 # --cc for multiple parents, --root for parentless
5518 $hash_parent_param =
5519 @
{$co{'parents'}} > 1 ?
'--cc' : $co{'parent'} || '--root';
5525 if ($format eq 'html') {
5526 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5527 "--no-commit-id", "--patch-with-raw", "--full-index",
5528 $hash_parent_param, $hash, "--"
5529 or die_error
(500, "Open git-diff-tree failed");
5531 while (my $line = <$fd>) {
5533 # empty line ends raw part of diff-tree output
5535 push @difftree, scalar parse_difftree_raw_line
($line);
5538 } elsif ($format eq 'plain') {
5539 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5540 '-p', $hash_parent_param, $hash, "--"
5541 or die_error
(500, "Open git-diff-tree failed");
5542 } elsif ($format eq 'patch') {
5543 # For commit ranges, we limit the output to the number of
5544 # patches specified in the 'patches' feature.
5545 # For single commits, we limit the output to a single patch,
5546 # diverging from the git-format-patch default.
5547 my @commit_spec = ();
5549 if ($patch_max > 0) {
5550 push @commit_spec, "-$patch_max";
5552 push @commit_spec, '-n', "$hash_parent..$hash";
5554 if ($params{-single
}) {
5555 push @commit_spec, '-1';
5557 if ($patch_max > 0) {
5558 push @commit_spec, "-$patch_max";
5560 push @commit_spec, "-n";
5562 push @commit_spec, '--root', $hash;
5564 open $fd, "-|", git_cmd
(), "format-patch", '--encoding=utf8',
5565 '--stdout', @commit_spec
5566 or die_error
(500, "Open git-format-patch failed");
5568 die_error
(400, "Unknown commitdiff format");
5571 # non-textual hash id's can be cached
5573 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5577 # write commit message
5578 if ($format eq 'html') {
5579 my $refs = git_get_references
();
5580 my $ref = format_ref_marker
($refs, $co{'id'});
5582 git_header_html
(undef, $expires);
5583 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5584 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
5585 git_print_authorship
(\
%co);
5586 print "<div class=\"page_body\">\n";
5587 if (@
{$co{'comment'}} > 1) {
5588 print "<div class=\"log\">\n";
5589 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
5590 print "</div>\n"; # class="log"
5593 } elsif ($format eq 'plain') {
5594 my $refs = git_get_references
("tags");
5595 my $tagname = git_get_rev_name_tags
($hash);
5596 my $filename = basename
($project) . "-$hash.patch";
5599 -type
=> 'text/plain',
5600 -charset
=> 'utf-8',
5601 -expires
=> $expires,
5602 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5603 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5604 print "From: " . to_utf8
($co{'author'}) . "\n";
5605 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5606 print "Subject: " . to_utf8
($co{'title'}) . "\n";
5608 print "X-Git-Tag: $tagname\n" if $tagname;
5609 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5611 foreach my $line (@
{$co{'comment'}}) {
5612 print to_utf8
($line) . "\n";
5615 } elsif ($format eq 'patch') {
5616 my $filename = basename
($project) . "-$hash.patch";
5619 -type
=> 'text/plain',
5620 -charset
=> 'utf-8',
5621 -expires
=> $expires,
5622 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5626 if ($format eq 'html') {
5627 my $use_parents = !defined $hash_parent ||
5628 $hash_parent eq '-c' || $hash_parent eq '--cc';
5629 git_difftree_body
(\
@difftree, $hash,
5630 $use_parents ? @
{$co{'parents'}} : $hash_parent);
5633 git_patchset_body
($fd, \
@difftree, $hash,
5634 $use_parents ? @
{$co{'parents'}} : $hash_parent);
5636 print "</div>\n"; # class="page_body"
5639 } elsif ($format eq 'plain') {
5643 or print "Reading git-diff-tree failed\n";
5644 } elsif ($format eq 'patch') {
5648 or print "Reading git-format-patch failed\n";
5652 sub git_commitdiff_plain
{
5653 git_commitdiff
(-format
=> 'plain');
5656 # format-patch-style patches
5658 git_commitdiff
(-format
=> 'patch', -single
=> 1);
5662 git_commitdiff
(-format
=> 'patch');
5666 if (!defined $hash_base) {
5667 $hash_base = git_get_head_hash
($project);
5669 if (!defined $page) {
5673 my %co = parse_commit
($hash_base)
5674 or die_error
(404, "Unknown commit object");
5676 my $refs = git_get_references
();
5677 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5679 my @commitlist = parse_commits
($hash_base, 101, (100 * $page),
5680 $file_name, "--full-history")
5681 or die_error
(404, "No such file or directory on given branch");
5683 if (!defined $hash && defined $file_name) {
5684 # some commits could have deleted file in question,
5685 # and not have it in tree, but one of them has to have it
5686 for (my $i = 0; $i <= @commitlist; $i++) {
5687 $hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
5688 last if defined $hash;
5691 if (defined $hash) {
5692 $ftype = git_get_type
($hash);
5694 if (!defined $ftype) {
5695 die_error
(500, "Unknown type of object");
5698 my $paging_nav = '';
5701 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5702 file_name
=>$file_name)},
5704 $paging_nav .= " ⋅ " .
5705 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5706 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5708 $paging_nav .= "first";
5709 $paging_nav .= " ⋅ prev";
5712 if ($#commitlist >= 100) {
5714 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5715 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5716 $paging_nav .= " ⋅ $next_link";
5718 $paging_nav .= " ⋅ next";
5722 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5723 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5724 git_print_page_path
($file_name, $ftype, $hash_base);
5726 git_history_body
(\
@commitlist, 0, 99,
5727 $refs, $hash_base, $ftype, $next_link);
5733 gitweb_check_feature
('search') or die_error
(403, "Search is disabled");
5734 if (!defined $searchtext) {
5735 die_error
(400, "Text field is empty");
5737 if (!defined $hash) {
5738 $hash = git_get_head_hash
($project);
5740 my %co = parse_commit
($hash);
5742 die_error
(404, "Unknown commit object");
5744 if (!defined $page) {
5748 $searchtype ||= 'commit';
5749 if ($searchtype eq 'pickaxe') {
5750 # pickaxe may take all resources of your box and run for several minutes
5751 # with every query - so decide by yourself how public you make this feature
5752 gitweb_check_feature
('pickaxe')
5753 or die_error
(403, "Pickaxe is disabled");
5755 if ($searchtype eq 'grep') {
5756 gitweb_check_feature
('grep')
5757 or die_error
(403, "Grep is disabled");
5762 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5764 if ($searchtype eq 'commit') {
5765 $greptype = "--grep=";
5766 } elsif ($searchtype eq 'author') {
5767 $greptype = "--author=";
5768 } elsif ($searchtype eq 'committer') {
5769 $greptype = "--committer=";
5771 $greptype .= $searchtext;
5772 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
5773 $greptype, '--regexp-ignore-case',
5774 $search_use_regexp ?
'--extended-regexp' : '--fixed-strings');
5776 my $paging_nav = '';
5779 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5780 searchtext
=>$searchtext,
5781 searchtype
=>$searchtype)},
5783 $paging_nav .= " ⋅ " .
5784 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5785 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5787 $paging_nav .= "first";
5788 $paging_nav .= " ⋅ prev";
5791 if ($#commitlist >= 100) {
5793 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5794 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5795 $paging_nav .= " ⋅ $next_link";
5797 $paging_nav .= " ⋅ next";
5800 if ($#commitlist >= 100) {
5803 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5804 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5805 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5808 if ($searchtype eq 'pickaxe') {
5809 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5810 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5812 print "<table class=\"pickaxe search\">\n";
5815 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
5816 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
5817 ($search_use_regexp ?
'--pickaxe-regex' : ());
5820 while (my $line = <$fd>) {
5824 my %set = parse_difftree_raw_line
($line);
5825 if (defined $set{'commit'}) {
5826 # finish previous commit
5829 "<td class=\"link\">" .
5830 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5832 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5838 print "<tr class=\"dark\">\n";
5840 print "<tr class=\"light\">\n";
5843 %co = parse_commit
($set{'commit'});
5844 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
5845 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5846 "<td><i>$author</i></td>\n" .
5848 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5849 -class => "list subject"},
5850 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
5851 } elsif (defined $set{'to_id'}) {
5852 next if ($set{'to_id'} =~ m/^0{40}$/);
5854 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5855 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
5857 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5863 # finish last commit (warning: repetition!)
5866 "<td class=\"link\">" .
5867 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5869 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5877 if ($searchtype eq 'grep') {
5878 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5879 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5881 print "<table class=\"grep_search\">\n";
5885 open my $fd, "-|", git_cmd
(), 'grep', '-n',
5886 $search_use_regexp ?
('-E', '-i') : '-F',
5887 $searchtext, $co{'tree'};
5889 while (my $line = <$fd>) {
5891 my ($file, $lno, $ltext, $binary);
5892 last if ($matches++ > 1000);
5893 if ($line =~ /^Binary file (.+) matches$/) {
5897 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5899 if ($file ne $lastfile) {
5900 $lastfile and print "</td></tr>\n";
5902 print "<tr class=\"dark\">\n";
5904 print "<tr class=\"light\">\n";
5906 print "<td class=\"list\">".
5907 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5908 file_name
=>"$file"),
5909 -class => "list"}, esc_path
($file));
5910 print "</td><td>\n";
5914 print "<div class=\"binary\">Binary file</div>\n";
5916 $ltext = untabify
($ltext);
5917 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
5918 $ltext = esc_html
($1, -nbsp
=>1);
5919 $ltext .= '<span class="match">';
5920 $ltext .= esc_html
($2, -nbsp
=>1);
5921 $ltext .= '</span>';
5922 $ltext .= esc_html
($3, -nbsp
=>1);
5924 $ltext = esc_html
($ltext, -nbsp
=>1);
5926 print "<div class=\"pre\">" .
5927 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5928 file_name
=>"$file").'#l'.$lno,
5929 -class => "linenr"}, sprintf('%4i', $lno))
5930 . ' ' . $ltext . "</div>\n";
5934 print "</td></tr>\n";
5935 if ($matches > 1000) {
5936 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5939 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5948 sub git_search_help
{
5950 git_print_page_nav
('','', $hash,$hash,$hash);
5952 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
5953 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
5954 the pattern entered is recognized as the POSIX extended
5955 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
5958 <dt><b>commit</b></dt>
5959 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
5961 my $have_grep = gitweb_check_feature
('grep');
5964 <dt><b>grep</b></dt>
5965 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5966 a different one) are searched for the given pattern. On large trees, this search can take
5967 a while and put some strain on the server, so please use it with some consideration. Note that
5968 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
5969 case-sensitive.</dd>
5973 <dt><b>author</b></dt>
5974 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
5975 <dt><b>committer</b></dt>
5976 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
5978 my $have_pickaxe = gitweb_check_feature
('pickaxe');
5979 if ($have_pickaxe) {
5981 <dt><b>pickaxe</b></dt>
5982 <dd>All commits that caused the string to appear or disappear from any file (changes that
5983 added, removed or "modified" the string) will be listed. This search can take a while and
5984 takes a lot of strain on the server, so please use it wisely. Note that since you may be
5985 interested even in changes just changing the case as well, this search is case sensitive.</dd>
5993 my $head = git_get_head_hash
($project);
5994 if (!defined $hash) {
5997 if (!defined $page) {
6000 my $refs = git_get_references
();
6002 my $commit_hash = $hash;
6003 if (defined $hash_parent) {
6004 $commit_hash = "$hash_parent..$hash";
6006 my @commitlist = parse_commits
($commit_hash, 101, (100 * $page));
6008 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#commitlist >= 100);
6010 if ($#commitlist >= 100) {
6012 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
6013 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
6015 my $patch_max = gitweb_check_feature
('patches');
6017 if ($patch_max < 0 || @commitlist <= $patch_max) {
6018 $paging_nav .= " ⋅ " .
6019 $cgi->a({-href
=> href
(action
=>"patches", -replay
=>1)},
6025 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
6026 git_print_header_div
('summary', $project);
6028 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
6033 ## ......................................................................
6034 ## feeds (RSS, Atom; OPML)
6037 my $format = shift || 'atom';
6038 my $have_blame = gitweb_check_feature
('blame');
6040 # Atom: http://www.atomenabled.org/developers/syndication/
6041 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
6042 if ($format ne 'rss' && $format ne 'atom') {
6043 die_error
(400, "Unknown web feed format");
6046 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
6047 my $head = $hash || 'HEAD';
6048 my @commitlist = parse_commits
($head, 150, 0, $file_name);
6052 my $content_type = "application/$format+xml";
6053 if (defined $cgi->http('HTTP_ACCEPT') &&
6054 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
6055 # browser (feed reader) prefers text/xml
6056 $content_type = 'text/xml';
6058 if (defined($commitlist[0])) {
6059 %latest_commit = %{$commitlist[0]};
6060 my $latest_epoch = $latest_commit{'committer_epoch'};
6061 %latest_date = parse_date
($latest_epoch);
6062 my $if_modified = $cgi->http('IF_MODIFIED_SINCE');
6063 if (defined $if_modified) {
6065 if (eval { require HTTP
::Date
; 1; }) {
6066 $since = HTTP
::Date
::str2time
($if_modified);
6067 } elsif (eval { require Time
::ParseDate
; 1; }) {
6068 $since = Time
::ParseDate
::parsedate
($if_modified, GMT
=> 1);
6070 if (defined $since && $latest_epoch <= $since) {
6072 -type
=> $content_type,
6073 -charset
=> 'utf-8',
6074 -last_modified
=> $latest_date{'rfc2822'},
6075 -status
=> '304 Not Modified');
6080 -type
=> $content_type,
6081 -charset
=> 'utf-8',
6082 -last_modified
=> $latest_date{'rfc2822'});
6085 -type
=> $content_type,
6086 -charset
=> 'utf-8');
6089 # Optimization: skip generating the body if client asks only
6090 # for Last-Modified date.
6091 return if ($cgi->request_method() eq 'HEAD');
6094 my $title = "$site_name - $project/$action";
6095 my $feed_type = 'log';
6096 if (defined $hash) {
6097 $title .= " - '$hash'";
6098 $feed_type = 'branch log';
6099 if (defined $file_name) {
6100 $title .= " :: $file_name";
6101 $feed_type = 'history';
6103 } elsif (defined $file_name) {
6104 $title .= " - $file_name";
6105 $feed_type = 'history';
6107 $title .= " $feed_type";
6108 my $descr = git_get_project_description
($project);
6109 if (defined $descr) {
6110 $descr = esc_html
($descr);
6112 $descr = "$project " .
6113 ($format eq 'rss' ?
'RSS' : 'Atom') .
6116 my $owner = git_get_project_owner
($project);
6117 $owner = esc_html
($owner);
6121 if (defined $file_name) {
6122 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
6123 } elsif (defined $hash) {
6124 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
6126 $alt_url = href
(-full
=>1, action
=>"summary");
6128 print qq!<?xml version
="1.0" encoding
="utf-8"?
>\n!;
6129 if ($format eq 'rss') {
6131 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
6134 print "<title>$title</title>\n" .
6135 "<link>$alt_url</link>\n" .
6136 "<description>$descr</description>\n" .
6137 "<language>en</language>\n" .
6138 # project owner is responsible for 'editorial' content
6139 "<managingEditor>$owner</managingEditor>\n";
6140 if (defined $logo || defined $favicon) {
6141 # prefer the logo to the favicon, since RSS
6142 # doesn't allow both
6143 my $img = esc_url
($logo || $favicon);
6145 "<url>$img</url>\n" .
6146 "<title>$title</title>\n" .
6147 "<link>$alt_url</link>\n" .
6151 print "<pubDate>$latest_date{'rfc2822'}</pubDate>\n";
6152 print "<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";
6154 print "<generator>gitweb v.$version/$git_version</generator>\n";
6155 } elsif ($format eq 'atom') {
6157 <feed xmlns="http://www.w3.org/2005/Atom">
6159 print "<title>$title</title>\n" .
6160 "<subtitle>$descr</subtitle>\n" .
6161 '<link rel="alternate" type="text/html" href="' .
6162 $alt_url . '" />' . "\n" .
6163 '<link rel="self" type="' . $content_type . '" href="' .
6164 $cgi->self_url() . '" />' . "\n" .
6165 "<id>" . href
(-full
=>1) . "</id>\n" .
6166 # use project owner for feed author
6167 "<author><name>$owner</name></author>\n";
6168 if (defined $favicon) {
6169 print "<icon>" . esc_url
($favicon) . "</icon>\n";
6171 if (defined $logo_url) {
6172 # not twice as wide as tall: 72 x 27 pixels
6173 print "<logo>" . esc_url
($logo) . "</logo>\n";
6175 if (! %latest_date) {
6176 # dummy date to keep the feed valid until commits trickle in:
6177 print "<updated>1970-01-01T00:00:00Z</updated>\n";
6179 print "<updated>$latest_date{'iso-8601'}</updated>\n";
6181 print "<generator version='$version/$git_version'>gitweb</generator>\n";
6185 for (my $i = 0; $i <= $#commitlist; $i++) {
6186 my %co = %{$commitlist[$i]};
6187 my $commit = $co{'id'};
6188 # we read 150, we always show 30 and the ones more recent than 48 hours
6189 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
6192 my %cd = parse_date
($co{'author_epoch'});
6194 # get list of changed files
6195 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6196 $co{'parent'} || "--root",
6197 $co{'id'}, "--", (defined $file_name ?
$file_name : ())
6199 my @difftree = map { chomp; $_ } <$fd>;
6203 # print element (entry, item)
6204 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
6205 if ($format eq 'rss') {
6207 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
6208 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
6209 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
6210 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
6211 "<link>$co_url</link>\n" .
6212 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
6213 "<content:encoded>" .
6215 } elsif ($format eq 'atom') {
6217 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
6218 "<updated>$cd{'iso-8601'}</updated>\n" .
6220 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
6221 if ($co{'author_email'}) {
6222 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
6224 print "</author>\n" .
6225 # use committer for contributor
6227 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
6228 if ($co{'committer_email'}) {
6229 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
6231 print "</contributor>\n" .
6232 "<published>$cd{'iso-8601'}</published>\n" .
6233 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
6234 "<id>$co_url</id>\n" .
6235 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
6236 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
6238 my $comment = $co{'comment'};
6240 foreach my $line (@
$comment) {
6241 $line = esc_html
($line);
6244 print "</pre><ul>\n";
6245 foreach my $difftree_line (@difftree) {
6246 my %difftree = parse_difftree_raw_line
($difftree_line);
6247 next if !$difftree{'from_id'};
6249 my $file = $difftree{'file'} || $difftree{'to_file'};
6253 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
6254 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
6255 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
6256 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
6257 -title
=> "diff"}, 'D');
6259 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
6260 file_name
=>$file, hash_base
=>$commit),
6261 -title
=> "blame"}, 'B');
6263 # if this is not a feed of a file history
6264 if (!defined $file_name || $file_name ne $file) {
6265 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
6266 file_name
=>$file, hash
=>$commit),
6267 -title
=> "history"}, 'H');
6269 $file = esc_path
($file);
6273 if ($format eq 'rss') {
6274 print "</ul>]]>\n" .
6275 "</content:encoded>\n" .
6277 } elsif ($format eq 'atom') {
6278 print "</ul>\n</div>\n" .
6285 if ($format eq 'rss') {
6286 print "</channel>\n</rss>\n";
6287 } elsif ($format eq 'atom') {
6301 my @list = git_get_projects_list
();
6304 -type
=> 'text/xml',
6305 -charset
=> 'utf-8',
6306 -content_disposition
=> 'inline; filename="opml.xml"');
6309 <?xml version="1.0" encoding="utf-8"?>
6310 <opml version="1.0">
6312 <title>$site_name OPML Export</title>
6315 <outline text="git RSS feeds">
6318 foreach my $pr (@list) {
6320 my $head = git_get_head_hash
($proj{'path'});
6321 if (!defined $head) {
6324 $git_dir = "$projectroot/$proj{'path'}";
6325 my %co = parse_commit
($head);
6330 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
6331 my $rss = href
('project' => $proj{'path'}, 'action' => 'rss', -full
=> 1);
6332 my $html = href
('project' => $proj{'path'}, 'action' => 'summary', -full
=> 1);
6333 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";