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
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
1302 return (($mode & S_IFMT
) == S_IFGITLINK
)
1305 # convert file mode in octal to symbolic file mode string
1307 my $mode = oct shift;
1309 if (S_ISGITLINK
($mode)) {
1310 return 'm---------';
1311 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1312 return 'drwxr-xr-x';
1313 } elsif (S_ISLNK
($mode)) {
1314 return 'lrwxrwxrwx';
1315 } elsif (S_ISREG
($mode)) {
1316 # git cares only about the executable bit
1317 if ($mode & S_IXUSR
) {
1318 return '-rwxr-xr-x';
1320 return '-rw-r--r--';
1323 return '----------';
1327 # convert file mode in octal to file type string
1331 if ($mode !~ m/^[0-7]+$/) {
1337 if (S_ISGITLINK
($mode)) {
1339 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1341 } elsif (S_ISLNK
($mode)) {
1343 } elsif (S_ISREG
($mode)) {
1350 # convert file mode in octal to file type description string
1351 sub file_type_long
{
1354 if ($mode !~ m/^[0-7]+$/) {
1360 if (S_ISGITLINK
($mode)) {
1362 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1364 } elsif (S_ISLNK
($mode)) {
1366 } elsif (S_ISREG
($mode)) {
1367 if ($mode & S_IXUSR
) {
1368 return "executable";
1378 ## ----------------------------------------------------------------------
1379 ## functions returning short HTML fragments, or transforming HTML fragments
1380 ## which don't belong to other sections
1382 # format line of commit message.
1383 sub format_log_line_html
{
1386 $line = esc_html
($line, -nbsp
=>1);
1387 $line =~ s
{\b([0-9a
-fA
-F
]{8,40})\b}{
1388 $cgi->a({-href
=> href
(action
=>"object", hash
=>$1),
1389 -class => "text"}, $1);
1395 # format marker of refs pointing to given object
1397 # the destination action is chosen based on object type and current context:
1398 # - for annotated tags, we choose the tag view unless it's the current view
1399 # already, in which case we go to shortlog view
1400 # - for other refs, we keep the current view if we're in history, shortlog or
1401 # log view, and select shortlog otherwise
1402 sub format_ref_marker
{
1403 my ($refs, $id) = @_;
1406 if (defined $refs->{$id}) {
1407 foreach my $ref (@
{$refs->{$id}}) {
1408 # this code exploits the fact that non-lightweight tags are the
1409 # only indirect objects, and that they are the only objects for which
1410 # we want to use tag instead of shortlog as action
1411 my ($type, $name) = qw();
1412 my $indirect = ($ref =~ s/\^\{\}$//);
1413 # e.g. tags/v2.6.11 or heads/next
1414 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1423 $class .= " indirect" if $indirect;
1425 my $dest_action = "shortlog";
1428 $dest_action = "tag" unless $action eq "tag";
1429 } elsif ($action =~ /^(history|(short)?log)$/) {
1430 $dest_action = $action;
1434 $dest .= "refs/" unless $ref =~ m
!^refs
/!;
1437 my $link = $cgi->a({
1439 action
=>$dest_action,
1443 $markers .= " <span class=\"$class\" title=\"$ref\">" .
1449 return ' <span class="refs">'. $markers . '</span>';
1455 # format, perhaps shortened and with markers, title line
1456 sub format_subject_html
{
1457 my ($long, $short, $href, $extra) = @_;
1458 $extra = '' unless defined($extra);
1460 if (length($short) < length($long)) {
1461 $long =~ s/[[:cntrl:]]/?/g;
1462 return $cgi->a({-href
=> $href, -class => "list subject",
1463 -title
=> to_utf8
($long)},
1464 esc_html
($short) . $extra);
1466 return $cgi->a({-href
=> $href, -class => "list subject"},
1467 esc_html
($long) . $extra);
1471 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1472 sub format_git_diff_header_line
{
1474 my $diffinfo = shift;
1475 my ($from, $to) = @_;
1477 if ($diffinfo->{'nparents'}) {
1479 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1480 if ($to->{'href'}) {
1481 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1482 esc_path
($to->{'file'}));
1483 } else { # file was deleted (no href)
1484 $line .= esc_path
($to->{'file'});
1488 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1489 if ($from->{'href'}) {
1490 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1491 'a/' . esc_path
($from->{'file'}));
1492 } else { # file was added (no href)
1493 $line .= 'a/' . esc_path
($from->{'file'});
1496 if ($to->{'href'}) {
1497 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1498 'b/' . esc_path
($to->{'file'}));
1499 } else { # file was deleted
1500 $line .= 'b/' . esc_path
($to->{'file'});
1504 return "<div class=\"diff header\">$line</div>\n";
1507 # format extended diff header line, before patch itself
1508 sub format_extended_diff_header_line
{
1510 my $diffinfo = shift;
1511 my ($from, $to) = @_;
1514 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1515 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1516 esc_path
($from->{'file'}));
1518 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1519 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1520 esc_path
($to->{'file'}));
1522 # match single <mode>
1523 if ($line =~ m/\s(\d{6})$/) {
1524 $line .= '<span class="info"> (' .
1525 file_type_long
($1) .
1529 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1530 # can match only for combined diff
1532 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1533 if ($from->{'href'}[$i]) {
1534 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1536 substr($diffinfo->{'from_id'}[$i],0,7));
1541 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1544 if ($to->{'href'}) {
1545 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1546 substr($diffinfo->{'to_id'},0,7));
1551 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1552 # can match only for ordinary diff
1553 my ($from_link, $to_link);
1554 if ($from->{'href'}) {
1555 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1556 substr($diffinfo->{'from_id'},0,7));
1558 $from_link = '0' x
7;
1560 if ($to->{'href'}) {
1561 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1562 substr($diffinfo->{'to_id'},0,7));
1566 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1567 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1570 return $line . "<br/>\n";
1573 # format from-file/to-file diff header
1574 sub format_diff_from_to_header
{
1575 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1580 #assert($line =~ m/^---/) if DEBUG;
1581 # no extra formatting for "^--- /dev/null"
1582 if (! $diffinfo->{'nparents'}) {
1583 # ordinary (single parent) diff
1584 if ($line =~ m!^--- "?a/!) {
1585 if ($from->{'href'}) {
1587 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1588 esc_path
($from->{'file'}));
1591 esc_path
($from->{'file'});
1594 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1597 # combined diff (merge commit)
1598 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1599 if ($from->{'href'}[$i]) {
1601 $cgi->a({-href
=>href
(action
=>"blobdiff",
1602 hash_parent
=>$diffinfo->{'from_id'}[$i],
1603 hash_parent_base
=>$parents[$i],
1604 file_parent
=>$from->{'file'}[$i],
1605 hash
=>$diffinfo->{'to_id'},
1607 file_name
=>$to->{'file'}),
1609 -title
=>"diff" . ($i+1)},
1612 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1613 esc_path
($from->{'file'}[$i]));
1615 $line = '--- /dev/null';
1617 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1622 #assert($line =~ m/^\+\+\+/) if DEBUG;
1623 # no extra formatting for "^+++ /dev/null"
1624 if ($line =~ m!^\+\+\+ "?b/!) {
1625 if ($to->{'href'}) {
1627 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1628 esc_path
($to->{'file'}));
1631 esc_path
($to->{'file'});
1634 $result .= qq!<div
class="diff to_file">$line</div
>\n!;
1639 # create note for patch simplified by combined diff
1640 sub format_diff_cc_simplified
{
1641 my ($diffinfo, @parents) = @_;
1644 $result .= "<div class=\"diff header\">" .
1646 if (!is_deleted
($diffinfo)) {
1647 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1649 hash
=>$diffinfo->{'to_id'},
1650 file_name
=>$diffinfo->{'to_file'}),
1652 esc_path
($diffinfo->{'to_file'}));
1654 $result .= esc_path
($diffinfo->{'to_file'});
1656 $result .= "</div>\n" . # class="diff header"
1657 "<div class=\"diff nodifferences\">" .
1659 "</div>\n"; # class="diff nodifferences"
1664 # format patch (diff) line (not to be used for diff headers)
1665 sub format_diff_line
{
1667 my ($from, $to) = @_;
1668 my $diff_class = "";
1672 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1674 my $prefix = substr($line, 0, scalar @
{$from->{'href'}});
1675 if ($line =~ m/^\@{3}/) {
1676 $diff_class = " chunk_header";
1677 } elsif ($line =~ m/^\\/) {
1678 $diff_class = " incomplete";
1679 } elsif ($prefix =~ tr/+/+/) {
1680 $diff_class = " add";
1681 } elsif ($prefix =~ tr/-/-/) {
1682 $diff_class = " rem";
1685 # assume ordinary diff
1686 my $char = substr($line, 0, 1);
1688 $diff_class = " add";
1689 } elsif ($char eq '-') {
1690 $diff_class = " rem";
1691 } elsif ($char eq '@') {
1692 $diff_class = " chunk_header";
1693 } elsif ($char eq "\\") {
1694 $diff_class = " incomplete";
1697 $line = untabify
($line);
1698 if ($from && $to && $line =~ m/^\@{2} /) {
1699 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1700 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1702 $from_lines = 0 unless defined $from_lines;
1703 $to_lines = 0 unless defined $to_lines;
1705 if ($from->{'href'}) {
1706 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1707 -class=>"list"}, $from_text);
1709 if ($to->{'href'}) {
1710 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1711 -class=>"list"}, $to_text);
1713 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1714 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1715 return "<div class=\"diff$diff_class\">$line</div>\n";
1716 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1717 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1718 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1720 @from_text = split(' ', $ranges);
1721 for (my $i = 0; $i < @from_text; ++$i) {
1722 ($from_start[$i], $from_nlines[$i]) =
1723 (split(',', substr($from_text[$i], 1)), 0);
1726 $to_text = pop @from_text;
1727 $to_start = pop @from_start;
1728 $to_nlines = pop @from_nlines;
1730 $line = "<span class=\"chunk_info\">$prefix ";
1731 for (my $i = 0; $i < @from_text; ++$i) {
1732 if ($from->{'href'}[$i]) {
1733 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1734 -class=>"list"}, $from_text[$i]);
1736 $line .= $from_text[$i];
1740 if ($to->{'href'}) {
1741 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1742 -class=>"list"}, $to_text);
1746 $line .= " $prefix</span>" .
1747 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1748 return "<div class=\"diff$diff_class\">$line</div>\n";
1750 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1753 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1754 # linked. Pass the hash of the tree/commit to snapshot.
1755 sub format_snapshot_links
{
1757 my $num_fmts = @snapshot_fmts;
1758 if ($num_fmts > 1) {
1759 # A parenthesized list of links bearing format names.
1760 # e.g. "snapshot (_tar.gz_ _zip_)"
1761 return "snapshot (" . join(' ', map
1768 }, $known_snapshot_formats{$_}{'display'})
1769 , @snapshot_fmts) . ")";
1770 } elsif ($num_fmts == 1) {
1771 # A single "snapshot" link whose tooltip bears the format name.
1773 my ($fmt) = @snapshot_fmts;
1779 snapshot_format
=>$fmt
1781 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1783 } else { # $num_fmts == 0
1788 ## ......................................................................
1789 ## functions returning values to be passed, perhaps after some
1790 ## transformation, to other functions; e.g. returning arguments to href()
1792 # returns hash to be passed to href to generate gitweb URL
1793 # in -title key it returns description of link
1795 my $format = shift || 'Atom';
1796 my %res = (action
=> lc($format));
1798 # feed links are possible only for project views
1799 return unless (defined $project);
1800 # some views should link to OPML, or to generic project feed,
1801 # or don't have specific feed yet (so they should use generic)
1802 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
1805 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
1806 # from tag links; this also makes possible to detect branch links
1807 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
1808 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
1811 # find log type for feed description (title)
1813 if (defined $file_name) {
1814 $type = "history of $file_name";
1815 $type .= "/" if ($action eq 'tree');
1816 $type .= " on '$branch'" if (defined $branch);
1818 $type = "log of $branch" if (defined $branch);
1821 $res{-title
} = $type;
1822 $res{'hash'} = (defined $branch ?
"refs/heads/$branch" : undef);
1823 $res{'file_name'} = $file_name;
1828 ## ----------------------------------------------------------------------
1829 ## git utility subroutines, invoking git commands
1831 # returns path to the core git executable and the --git-dir parameter as list
1833 return $GIT, '--git-dir='.$git_dir;
1836 # quote the given arguments for passing them to the shell
1837 # quote_command("command", "arg 1", "arg with ' and ! characters")
1838 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
1839 # Try to avoid using this function wherever possible.
1842 map( { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ ));
1845 # get HEAD ref of given project as hash
1846 sub git_get_head_hash
{
1847 my $project = shift;
1848 my $o_git_dir = $git_dir;
1850 $git_dir = "$projectroot/$project";
1851 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1854 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1858 if (defined $o_git_dir) {
1859 $git_dir = $o_git_dir;
1864 # get type of given object
1868 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1870 close $fd or return;
1875 # repository configuration
1876 our $config_file = '';
1879 # store multiple values for single key as anonymous array reference
1880 # single values stored directly in the hash, not as [ <value> ]
1881 sub hash_set_multi
{
1882 my ($hash, $key, $value) = @_;
1884 if (!exists $hash->{$key}) {
1885 $hash->{$key} = $value;
1886 } elsif (!ref $hash->{$key}) {
1887 $hash->{$key} = [ $hash->{$key}, $value ];
1889 push @
{$hash->{$key}}, $value;
1893 # return hash of git project configuration
1894 # optionally limited to some section, e.g. 'gitweb'
1895 sub git_parse_project_config
{
1896 my $section_regexp = shift;
1901 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
1904 while (my $keyval = <$fh>) {
1906 my ($key, $value) = split(/\n/, $keyval, 2);
1908 hash_set_multi
(\
%config, $key, $value)
1909 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
1916 # convert config value to boolean: 'true' or 'false'
1917 # no value, number > 0, 'true' and 'yes' values are true
1918 # rest of values are treated as false (never as error)
1919 sub config_to_bool
{
1922 return 1 if !defined $val; # section.key
1924 # strip leading and trailing whitespace
1928 return (($val =~ /^\d+$/ && $val) || # section.key = 1
1929 ($val =~ /^(?:true|yes)$/i)); # section.key = true
1932 # convert config value to simple decimal number
1933 # an optional value suffix of 'k', 'm', or 'g' will cause the value
1934 # to be multiplied by 1024, 1048576, or 1073741824
1938 # strip leading and trailing whitespace
1942 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
1944 # unknown unit is treated as 1
1945 return $num * ($unit eq 'g' ?
1073741824 :
1946 $unit eq 'm' ?
1048576 :
1947 $unit eq 'k' ?
1024 : 1);
1952 # convert config value to array reference, if needed
1953 sub config_to_multi
{
1956 return ref($val) ?
$val : (defined($val) ?
[ $val ] : []);
1959 sub git_get_project_config
{
1960 my ($key, $type) = @_;
1963 return unless ($key);
1964 $key =~ s/^gitweb\.//;
1965 return if ($key =~ m/\W/);
1968 if (defined $type) {
1971 unless ($type eq 'bool' || $type eq 'int');
1975 if (!defined $config_file ||
1976 $config_file ne "$git_dir/config") {
1977 %config = git_parse_project_config
('gitweb');
1978 $config_file = "$git_dir/config";
1981 # check if config variable (key) exists
1982 return unless exists $config{"gitweb.$key"};
1985 if (!defined $type) {
1986 return $config{"gitweb.$key"};
1987 } elsif ($type eq 'bool') {
1988 # backward compatibility: 'git config --bool' returns true/false
1989 return config_to_bool
($config{"gitweb.$key"}) ?
'true' : 'false';
1990 } elsif ($type eq 'int') {
1991 return config_to_int
($config{"gitweb.$key"});
1993 return $config{"gitweb.$key"};
1996 # get hash of given path at given ref
1997 sub git_get_hash_by_path
{
1999 my $path = shift || return undef;
2004 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
2005 or die_error
(500, "Open git-ls-tree failed");
2007 close $fd or return undef;
2009 if (!defined $line) {
2010 # there is no tree or hash given by $path at $base
2014 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2015 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
2016 if (defined $type && $type ne $2) {
2017 # type doesn't match
2023 # get path of entry with given hash at given tree-ish (ref)
2024 # used to get 'from' filename for combined diff (merge commit) for renames
2025 sub git_get_path_by_hash
{
2026 my $base = shift || return;
2027 my $hash = shift || return;
2031 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
2033 while (my $line = <$fd>) {
2036 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
2037 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
2038 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
2047 ## ......................................................................
2048 ## git utility functions, directly accessing git repository
2050 sub git_get_project_description
{
2053 $git_dir = "$projectroot/$path";
2054 open my $fd, "$git_dir/description"
2055 or return git_get_project_config
('description');
2058 if (defined $descr) {
2064 sub git_get_project_ctags
{
2068 $git_dir = "$projectroot/$path";
2069 unless (opendir D
, "$git_dir/ctags") {
2072 foreach (grep { -f
$_ } map { "$git_dir/ctags/$_" } readdir(D
)) {
2073 open CT
, $_ or next;
2077 my $ctag = $_; $ctag =~ s
#.*/##;
2078 $ctags->{$ctag} = $val;
2084 sub git_populate_project_tagcloud
{
2087 # First, merge different-cased tags; tags vote on casing
2089 foreach (keys %$ctags) {
2090 $ctags_lc{lc $_}->{count
} += $ctags->{$_};
2091 if (not $ctags_lc{lc $_}->{topcount
}
2092 or $ctags_lc{lc $_}->{topcount
} < $ctags->{$_}) {
2093 $ctags_lc{lc $_}->{topcount
} = $ctags->{$_};
2094 $ctags_lc{lc $_}->{topname
} = $_;
2099 if (eval { require HTML
::TagCloud
; 1; }) {
2100 $cloud = HTML
::TagCloud
->new;
2101 foreach (sort keys %ctags_lc) {
2102 # Pad the title with spaces so that the cloud looks
2104 my $title = $ctags_lc{$_}->{topname
};
2105 $title =~ s/ / /g;
2106 $title =~ s/^/ /g;
2107 $title =~ s/$/ /g;
2108 $cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count
});
2111 $cloud = \
%ctags_lc;
2116 sub git_show_project_tagcloud
{
2117 my ($cloud, $count) = @_;
2118 print STDERR
ref($cloud)."..\n";
2119 if (ref $cloud eq 'HTML::TagCloud') {
2120 return $cloud->html_and_css($count);
2122 my @tags = sort { $cloud->{$a}->{count
} <=> $cloud->{$b}->{count
} } keys %$cloud;
2123 return '<p align="center">' . join (', ', map {
2124 "<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"
2125 } splice(@tags, 0, $count)) . '</p>';
2129 sub git_get_project_url_list
{
2132 $git_dir = "$projectroot/$path";
2133 open my $fd, "$git_dir/cloneurl"
2134 or return wantarray ?
2135 @
{ config_to_multi
(git_get_project_config
('url')) } :
2136 config_to_multi
(git_get_project_config
('url'));
2137 my @git_project_url_list = map { chomp; $_ } <$fd>;
2140 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
2143 sub git_get_projects_list
{
2148 $filter =~ s/\.git$//;
2150 my $check_forks = gitweb_check_feature
('forks');
2152 if (-d
$projects_list) {
2153 # search in directory
2154 my $dir = $projects_list . ($filter ?
"/$filter" : '');
2155 # remove the trailing "/"
2157 my $pfxlen = length("$dir");
2158 my $pfxdepth = ($dir =~ tr!/!!);
2161 follow_fast
=> 1, # follow symbolic links
2162 follow_skip
=> 2, # ignore duplicates
2163 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
2165 # skip project-list toplevel, if we get it.
2166 return if (m!^[/.]$!);
2167 # only directories can be git repositories
2168 return unless (-d
$_);
2169 # don't traverse too deep (Find is super slow on os x)
2170 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
2171 $File::Find
::prune
= 1;
2175 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
2176 # we check related file in $projectroot
2177 my $path = ($filter ?
"$filter/" : '') . $subdir;
2178 if (check_export_ok
("$projectroot/$path")) {
2179 push @list, { path
=> $path };
2180 $File::Find
::prune
= 1;
2185 } elsif (-f
$projects_list) {
2186 # read from file(url-encoded):
2187 # 'git%2Fgit.git Linus+Torvalds'
2188 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2189 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2191 open my ($fd), $projects_list or return;
2193 while (my $line = <$fd>) {
2195 my ($path, $owner) = split ' ', $line;
2196 $path = unescape
($path);
2197 $owner = unescape
($owner);
2198 if (!defined $path) {
2201 if ($filter ne '') {
2202 # looking for forks;
2203 my $pfx = substr($path, 0, length($filter));
2204 if ($pfx ne $filter) {
2207 my $sfx = substr($path, length($filter));
2208 if ($sfx !~ /^\/.*\
.git
$/) {
2211 } elsif ($check_forks) {
2213 foreach my $filter (keys %paths) {
2214 # looking for forks;
2215 my $pfx = substr($path, 0, length($filter));
2216 if ($pfx ne $filter) {
2219 my $sfx = substr($path, length($filter));
2220 if ($sfx !~ /^\/.*\
.git
$/) {
2223 # is a fork, don't include it in
2228 if (check_export_ok
("$projectroot/$path")) {
2231 owner
=> to_utf8
($owner),
2234 (my $forks_path = $path) =~ s/\.git$//;
2235 $paths{$forks_path}++;
2243 our $gitweb_project_owner = undef;
2244 sub git_get_project_list_from_file
{
2246 return if (defined $gitweb_project_owner);
2248 $gitweb_project_owner = {};
2249 # read from file (url-encoded):
2250 # 'git%2Fgit.git Linus+Torvalds'
2251 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2252 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2253 if (-f
$projects_list) {
2254 open (my $fd , $projects_list);
2255 while (my $line = <$fd>) {
2257 my ($pr, $ow) = split ' ', $line;
2258 $pr = unescape
($pr);
2259 $ow = unescape
($ow);
2260 $gitweb_project_owner->{$pr} = to_utf8
($ow);
2266 sub git_get_project_owner
{
2267 my $project = shift;
2270 return undef unless $project;
2271 $git_dir = "$projectroot/$project";
2273 if (!defined $gitweb_project_owner) {
2274 git_get_project_list_from_file
();
2277 if (exists $gitweb_project_owner->{$project}) {
2278 $owner = $gitweb_project_owner->{$project};
2280 if (!defined $owner){
2281 $owner = git_get_project_config
('owner');
2283 if (!defined $owner) {
2284 $owner = get_file_owner
("$git_dir");
2290 sub git_get_last_activity
{
2294 $git_dir = "$projectroot/$path";
2295 open($fd, "-|", git_cmd
(), 'for-each-ref',
2296 '--format=%(committer)',
2297 '--sort=-committerdate',
2299 'refs/heads') or return;
2300 my $most_recent = <$fd>;
2301 close $fd or return;
2302 if (defined $most_recent &&
2303 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
2305 my $age = time - $timestamp;
2306 return ($age, age_string
($age));
2308 return (undef, undef);
2311 sub git_get_references
{
2312 my $type = shift || "";
2314 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
2315 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
2316 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
2317 ($type ?
("--", "refs/$type") : ()) # use -- <pattern> if $type
2320 while (my $line = <$fd>) {
2322 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
2323 if (defined $refs{$1}) {
2324 push @
{$refs{$1}}, $2;
2330 close $fd or return;
2334 sub git_get_rev_name_tags
{
2335 my $hash = shift || return undef;
2337 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
2339 my $name_rev = <$fd>;
2342 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
2345 # catches also '$hash undefined' output
2350 ## ----------------------------------------------------------------------
2351 ## parse to hash functions
2355 my $tz = shift || "-0000";
2358 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
2359 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
2360 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
2361 $date{'hour'} = $hour;
2362 $date{'minute'} = $min;
2363 $date{'mday'} = $mday;
2364 $date{'day'} = $days[$wday];
2365 $date{'month'} = $months[$mon];
2366 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2367 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2368 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2369 $mday, $months[$mon], $hour ,$min;
2370 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2371 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2373 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2374 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2375 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2376 $date{'hour_local'} = $hour;
2377 $date{'minute_local'} = $min;
2378 $date{'tz_local'} = $tz;
2379 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2380 1900+$year, $mon+1, $mday,
2381 $hour, $min, $sec, $tz);
2390 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
2391 $tag{'id'} = $tag_id;
2392 while (my $line = <$fd>) {
2394 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2395 $tag{'object'} = $1;
2396 } elsif ($line =~ m/^type (.+)$/) {
2398 } elsif ($line =~ m/^tag (.+)$/) {
2400 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2401 $tag{'author'} = $1;
2404 } elsif ($line =~ m/--BEGIN/) {
2405 push @comment, $line;
2407 } elsif ($line eq "") {
2411 push @comment, <$fd>;
2412 $tag{'comment'} = \
@comment;
2413 close $fd or return;
2414 if (!defined $tag{'name'}) {
2420 sub parse_commit_text
{
2421 my ($commit_text, $withparents) = @_;
2422 my @commit_lines = split '\n', $commit_text;
2425 pop @commit_lines; # Remove '\0'
2427 if (! @commit_lines) {
2431 my $header = shift @commit_lines;
2432 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2435 ($co{'id'}, my @parents) = split ' ', $header;
2436 while (my $line = shift @commit_lines) {
2437 last if $line eq "\n";
2438 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2440 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2442 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2444 $co{'author_epoch'} = $2;
2445 $co{'author_tz'} = $3;
2446 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2447 $co{'author_name'} = $1;
2448 $co{'author_email'} = $2;
2450 $co{'author_name'} = $co{'author'};
2452 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2453 $co{'committer'} = $1;
2454 $co{'committer_epoch'} = $2;
2455 $co{'committer_tz'} = $3;
2456 $co{'committer_name'} = $co{'committer'};
2457 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2458 $co{'committer_name'} = $1;
2459 $co{'committer_email'} = $2;
2461 $co{'committer_name'} = $co{'committer'};
2465 if (!defined $co{'tree'}) {
2468 $co{'parents'} = \
@parents;
2469 $co{'parent'} = $parents[0];
2471 foreach my $title (@commit_lines) {
2474 $co{'title'} = chop_str
($title, 80, 5);
2475 # remove leading stuff of merges to make the interesting part visible
2476 if (length($title) > 50) {
2477 $title =~ s/^Automatic //;
2478 $title =~ s/^merge (of|with) /Merge ... /i;
2479 if (length($title) > 50) {
2480 $title =~ s/(http|rsync):\/\///;
2482 if (length($title) > 50) {
2483 $title =~ s/(master|www|rsync)\.//;
2485 if (length($title) > 50) {
2486 $title =~ s/kernel.org:?//;
2488 if (length($title) > 50) {
2489 $title =~ s/\/pub\/scm//;
2492 $co{'title_short'} = chop_str
($title, 50, 5);
2496 if (! defined $co{'title'} || $co{'title'} eq "") {
2497 $co{'title'} = $co{'title_short'} = '(no commit message)';
2499 # remove added spaces
2500 foreach my $line (@commit_lines) {
2503 $co{'comment'} = \
@commit_lines;
2505 my $age = time - $co{'committer_epoch'};
2507 $co{'age_string'} = age_string
($age);
2508 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2509 if ($age > 60*60*24*7*2) {
2510 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2511 $co{'age_string_age'} = $co{'age_string'};
2513 $co{'age_string_date'} = $co{'age_string'};
2514 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2520 my ($commit_id) = @_;
2525 open my $fd, "-|", git_cmd
(), "rev-list",
2531 or die_error
(500, "Open git-rev-list failed");
2532 %co = parse_commit_text
(<$fd>, 1);
2539 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2547 open my $fd, "-|", git_cmd
(), "rev-list",
2550 ("--max-count=" . $maxcount),
2551 ("--skip=" . $skip),
2555 ($filename ?
($filename) : ())
2556 or die_error
(500, "Open git-rev-list failed");
2557 while (my $line = <$fd>) {
2558 my %co = parse_commit_text
($line);
2563 return wantarray ?
@cos : \
@cos;
2566 # parse line of git-diff-tree "raw" output
2567 sub parse_difftree_raw_line
{
2571 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2572 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2573 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2574 $res{'from_mode'} = $1;
2575 $res{'to_mode'} = $2;
2576 $res{'from_id'} = $3;
2578 $res{'status'} = $5;
2579 $res{'similarity'} = $6;
2580 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2581 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2583 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2586 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2587 # combined diff (for merge commit)
2588 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2589 $res{'nparents'} = length($1);
2590 $res{'from_mode'} = [ split(' ', $2) ];
2591 $res{'to_mode'} = pop @
{$res{'from_mode'}};
2592 $res{'from_id'} = [ split(' ', $3) ];
2593 $res{'to_id'} = pop @
{$res{'from_id'}};
2594 $res{'status'} = [ split('', $4) ];
2595 $res{'to_file'} = unquote
($5);
2597 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2598 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2599 $res{'commit'} = $1;
2602 return wantarray ?
%res : \
%res;
2605 # wrapper: return parsed line of git-diff-tree "raw" output
2606 # (the argument might be raw line, or parsed info)
2607 sub parsed_difftree_line
{
2608 my $line_or_ref = shift;
2610 if (ref($line_or_ref) eq "HASH") {
2611 # pre-parsed (or generated by hand)
2612 return $line_or_ref;
2614 return parse_difftree_raw_line
($line_or_ref);
2618 # parse line of git-ls-tree output
2619 sub parse_ls_tree_line
{
2624 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2625 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2633 $res{'name'} = unquote
($4);
2636 return wantarray ?
%res : \
%res;
2639 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2640 sub parse_from_to_diffinfo
{
2641 my ($diffinfo, $from, $to, @parents) = @_;
2643 if ($diffinfo->{'nparents'}) {
2645 $from->{'file'} = [];
2646 $from->{'href'} = [];
2647 fill_from_file_info
($diffinfo, @parents)
2648 unless exists $diffinfo->{'from_file'};
2649 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2650 $from->{'file'}[$i] =
2651 defined $diffinfo->{'from_file'}[$i] ?
2652 $diffinfo->{'from_file'}[$i] :
2653 $diffinfo->{'to_file'};
2654 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2655 $from->{'href'}[$i] = href
(action
=>"blob",
2656 hash_base
=>$parents[$i],
2657 hash
=>$diffinfo->{'from_id'}[$i],
2658 file_name
=>$from->{'file'}[$i]);
2660 $from->{'href'}[$i] = undef;
2664 # ordinary (not combined) diff
2665 $from->{'file'} = $diffinfo->{'from_file'};
2666 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2667 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2668 hash
=>$diffinfo->{'from_id'},
2669 file_name
=>$from->{'file'});
2671 delete $from->{'href'};
2675 $to->{'file'} = $diffinfo->{'to_file'};
2676 if (!is_deleted
($diffinfo)) { # file exists in result
2677 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2678 hash
=>$diffinfo->{'to_id'},
2679 file_name
=>$to->{'file'});
2681 delete $to->{'href'};
2685 ## ......................................................................
2686 ## parse to array of hashes functions
2688 sub git_get_heads_list
{
2692 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2693 ($limit ?
'--count='.($limit+1) : ()), '--sort=-committerdate',
2694 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2697 while (my $line = <$fd>) {
2701 my ($refinfo, $committerinfo) = split(/\0/, $line);
2702 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2703 my ($committer, $epoch, $tz) =
2704 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2705 $ref_item{'fullname'} = $name;
2706 $name =~ s!^refs/heads/!!;
2708 $ref_item{'name'} = $name;
2709 $ref_item{'id'} = $hash;
2710 $ref_item{'title'} = $title || '(no commit message)';
2711 $ref_item{'epoch'} = $epoch;
2713 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2715 $ref_item{'age'} = "unknown";
2718 push @headslist, \
%ref_item;
2722 return wantarray ?
@headslist : \
@headslist;
2725 sub git_get_tags_list
{
2729 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2730 ($limit ?
'--count='.($limit+1) : ()), '--sort=-creatordate',
2731 '--format=%(objectname) %(objecttype) %(refname) '.
2732 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2735 while (my $line = <$fd>) {
2739 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2740 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2741 my ($creator, $epoch, $tz) =
2742 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2743 $ref_item{'fullname'} = $name;
2744 $name =~ s!^refs/tags/!!;
2746 $ref_item{'type'} = $type;
2747 $ref_item{'id'} = $id;
2748 $ref_item{'name'} = $name;
2749 if ($type eq "tag") {
2750 $ref_item{'subject'} = $title;
2751 $ref_item{'reftype'} = $reftype;
2752 $ref_item{'refid'} = $refid;
2754 $ref_item{'reftype'} = $type;
2755 $ref_item{'refid'} = $id;
2758 if ($type eq "tag" || $type eq "commit") {
2759 $ref_item{'epoch'} = $epoch;
2761 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2763 $ref_item{'age'} = "unknown";
2767 push @tagslist, \
%ref_item;
2771 return wantarray ?
@tagslist : \
@tagslist;
2774 ## ----------------------------------------------------------------------
2775 ## filesystem-related functions
2777 sub get_file_owner
{
2780 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2781 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2782 if (!defined $gcos) {
2786 $owner =~ s/[,;].*$//;
2787 return to_utf8
($owner);
2790 # assume that file exists
2792 my $filename = shift;
2794 open my $fd, '<', $filename;
2795 print map { to_utf8
($_) } <$fd>;
2799 ## ......................................................................
2800 ## mimetype related functions
2802 sub mimetype_guess_file
{
2803 my $filename = shift;
2804 my $mimemap = shift;
2805 -r
$mimemap or return undef;
2808 open(MIME
, $mimemap) or return undef;
2810 next if m/^#/; # skip comments
2811 my ($mime, $exts) = split(/\t+/);
2812 if (defined $exts) {
2813 my @exts = split(/\s+/, $exts);
2814 foreach my $ext (@exts) {
2815 $mimemap{$ext} = $mime;
2821 $filename =~ /\.([^.]*)$/;
2822 return $mimemap{$1};
2825 sub mimetype_guess
{
2826 my $filename = shift;
2828 $filename =~ /\./ or return undef;
2830 if ($mimetypes_file) {
2831 my $file = $mimetypes_file;
2832 if ($file !~ m!^/!) { # if it is relative path
2833 # it is relative to project
2834 $file = "$projectroot/$project/$file";
2836 $mime = mimetype_guess_file
($filename, $file);
2838 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2844 my $filename = shift;
2847 my $mime = mimetype_guess
($filename);
2848 $mime and return $mime;
2852 return $default_blob_plain_mimetype unless $fd;
2855 return 'text/plain';
2856 } elsif (! $filename) {
2857 return 'application/octet-stream';
2858 } elsif ($filename =~ m/\.png$/i) {
2860 } elsif ($filename =~ m/\.gif$/i) {
2862 } elsif ($filename =~ m/\.jpe?g$/i) {
2863 return 'image/jpeg';
2865 return 'application/octet-stream';
2869 sub blob_contenttype
{
2870 my ($fd, $file_name, $type) = @_;
2872 $type ||= blob_mimetype
($fd, $file_name);
2873 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
2874 $type .= "; charset=$default_text_plain_charset";
2880 ## ======================================================================
2881 ## functions printing HTML: header, footer, error page
2883 sub git_header_html
{
2884 my $status = shift || "200 OK";
2885 my $expires = shift;
2887 my $title = "$site_name";
2888 if (defined $project) {
2889 $title .= " - " . to_utf8
($project);
2890 if (defined $action) {
2891 $title .= "/$action";
2892 if (defined $file_name) {
2893 $title .= " - " . esc_path
($file_name);
2894 if ($action eq "tree" && $file_name !~ m
|/$|) {
2901 # require explicit support from the UA if we are to send the page as
2902 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2903 # we have to do this because MSIE sometimes globs '*/*', pretending to
2904 # support xhtml+xml but choking when it gets what it asked for.
2905 if (defined $cgi->http('HTTP_ACCEPT') &&
2906 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2907 $cgi->Accept('application/xhtml+xml') != 0) {
2908 $content_type = 'application/xhtml+xml';
2910 $content_type = 'text/html';
2912 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2913 -status
=> $status, -expires
=> $expires);
2914 my $mod_perl_version = $ENV{'MOD_PERL'} ?
" $ENV{'MOD_PERL'}" : '';
2916 <?xml version="1.0" encoding="utf-8"?>
2917 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2918 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2919 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2920 <!-- git core binaries version $git_version -->
2922 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2923 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2924 <meta name="robots" content="index, nofollow"/>
2925 <title>$title</title>
2927 # the stylesheet, favicon etc urls won't work correctly with path_info
2928 # unless we set the appropriate base URL
2929 if ($ENV{'PATH_INFO'}) {
2930 print "<base href=\"".esc_url
($base_url)."\" />\n";
2932 # print out each stylesheet that exist, providing backwards capability
2933 # for those people who defined $stylesheet in a config file
2934 if (defined $stylesheet) {
2935 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2937 foreach my $stylesheet (@stylesheets) {
2938 next unless $stylesheet;
2939 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2942 if (defined $project) {
2943 my %href_params = get_feed_info
();
2944 if (!exists $href_params{'-title'}) {
2945 $href_params{'-title'} = 'log';
2948 foreach my $format qw(RSS Atom) {
2949 my $type = lc($format);
2951 '-rel' => 'alternate',
2952 '-title' => "$project - $href_params{'-title'} - $format feed",
2953 '-type' => "application/$type+xml"
2956 $href_params{'action'} = $type;
2957 $link_attr{'-href'} = href
(%href_params);
2959 "rel=\"$link_attr{'-rel'}\" ".
2960 "title=\"$link_attr{'-title'}\" ".
2961 "href=\"$link_attr{'-href'}\" ".
2962 "type=\"$link_attr{'-type'}\" ".
2965 $href_params{'extra_options'} = '--no-merges';
2966 $link_attr{'-href'} = href
(%href_params);
2967 $link_attr{'-title'} .= ' (no merges)';
2969 "rel=\"$link_attr{'-rel'}\" ".
2970 "title=\"$link_attr{'-title'}\" ".
2971 "href=\"$link_attr{'-href'}\" ".
2972 "type=\"$link_attr{'-type'}\" ".
2977 printf('<link rel="alternate" title="%s projects list" '.
2978 'href="%s" type="text/plain; charset=utf-8" />'."\n",
2979 $site_name, href
(project
=>undef, action
=>"project_index"));
2980 printf('<link rel="alternate" title="%s projects feeds" '.
2981 'href="%s" type="text/x-opml" />'."\n",
2982 $site_name, href
(project
=>undef, action
=>"opml"));
2984 if (defined $favicon) {
2985 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png" />\n);
2991 if (-f
$site_header) {
2992 insert_file
($site_header);
2995 print "<div class=\"page_header\">\n" .
2996 $cgi->a({-href
=> esc_url
($logo_url),
2997 -title
=> $logo_label},
2998 qq(<img src
="$logo" width
="72" height
="27" alt
="git" class="logo"/>));
2999 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
3000 if (defined $project) {
3001 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
3002 if (defined $action) {
3009 my $have_search = gitweb_check_feature
('search');
3010 if (defined $project && $have_search) {
3011 if (!defined $searchtext) {
3015 if (defined $hash_base) {
3016 $search_hash = $hash_base;
3017 } elsif (defined $hash) {
3018 $search_hash = $hash;
3020 $search_hash = "HEAD";
3022 my $action = $my_uri;
3023 my $use_pathinfo = gitweb_check_feature
('pathinfo');
3024 if ($use_pathinfo) {
3025 $action .= "/".esc_url
($project);
3027 print $cgi->startform(-method
=> "get", -action
=> $action) .
3028 "<div class=\"search\">\n" .
3030 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
3031 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
3032 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
3033 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
3034 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
3035 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
3037 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
3038 "<span title=\"Extended regular expression\">" .
3039 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
3040 -checked
=> $search_use_regexp) .
3043 $cgi->end_form() . "\n";
3047 sub git_footer_html
{
3048 my $feed_class = 'rss_logo';
3050 print "<div class=\"page_footer\">\n";
3051 if (defined $project) {
3052 my $descr = git_get_project_description
($project);
3053 if (defined $descr) {
3054 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
3057 my %href_params = get_feed_info
();
3058 if (!%href_params) {
3059 $feed_class .= ' generic';
3061 $href_params{'-title'} ||= 'log';
3063 foreach my $format qw(RSS Atom) {
3064 $href_params{'action'} = lc($format);
3065 print $cgi->a({-href
=> href
(%href_params),
3066 -title
=> "$href_params{'-title'} $format feed",
3067 -class => $feed_class}, $format)."\n";
3071 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
3072 -class => $feed_class}, "OPML") . " ";
3073 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
3074 -class => $feed_class}, "TXT") . "\n";
3076 print "</div>\n"; # class="page_footer"
3078 if (-f
$site_footer) {
3079 insert_file
($site_footer);
3086 # die_error(<http_status_code>, <error_message>)
3087 # Example: die_error(404, 'Hash not found')
3088 # By convention, use the following status codes (as defined in RFC 2616):
3089 # 400: Invalid or missing CGI parameters, or
3090 # requested object exists but has wrong type.
3091 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
3092 # this server or project.
3093 # 404: Requested object/revision/project doesn't exist.
3094 # 500: The server isn't configured properly, or
3095 # an internal error occurred (e.g. failed assertions caused by bugs), or
3096 # an unknown error occurred (e.g. the git binary died unexpectedly).
3098 my $status = shift || 500;
3099 my $error = shift || "Internal server error";
3101 my %http_responses = (400 => '400 Bad Request',
3102 403 => '403 Forbidden',
3103 404 => '404 Not Found',
3104 500 => '500 Internal Server Error');
3105 git_header_html
($http_responses{$status});
3107 <div class="page_body">
3117 ## ----------------------------------------------------------------------
3118 ## functions printing or outputting HTML: navigation
3120 sub git_print_page_nav
{
3121 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
3122 $extra = '' if !defined $extra; # pager or formats
3124 my @navs = qw(summary shortlog log commit commitdiff tree);
3126 @navs = grep { $_ ne $suppress } @navs;
3129 my %arg = map { $_ => {action
=>$_} } @navs;
3130 if (defined $head) {
3131 for (qw(commit commitdiff)) {
3132 $arg{$_}{'hash'} = $head;
3134 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
3135 for (qw(shortlog log)) {
3136 $arg{$_}{'hash'} = $head;
3141 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
3142 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
3144 my @actions = gitweb_get_feature
('actions');
3147 'n' => $project, # project name
3148 'f' => $git_dir, # project path within filesystem
3149 'h' => $treehead || '', # current hash ('h' parameter)
3150 'b' => $treebase || '', # hash base ('hb' parameter)
3153 my ($label, $link, $pos) = splice(@actions,0,3);
3155 @navs = map { $_ eq $pos ?
($_, $label) : $_ } @navs;
3157 $link =~ s/%([%nfhb])/$repl{$1}/g;
3158 $arg{$label}{'_href'} = $link;
3161 print "<div class=\"page_nav\">\n" .
3163 map { $_ eq $current ?
3164 $_ : $cgi->a({-href
=> ($arg{$_}{_href
} ?
$arg{$_}{_href
} : href
(%{$arg{$_}}))}, "$_")
3166 print "<br/>\n$extra<br/>\n" .
3170 sub format_paging_nav
{
3171 my ($action, $hash, $head, $page, $has_next_link) = @_;
3175 if ($hash ne $head || $page) {
3176 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
3178 $paging_nav .= "HEAD";
3182 $paging_nav .= " ⋅ " .
3183 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
3184 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3186 $paging_nav .= " ⋅ prev";
3189 if ($has_next_link) {
3190 $paging_nav .= " ⋅ " .
3191 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
3192 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3194 $paging_nav .= " ⋅ next";
3200 ## ......................................................................
3201 ## functions printing or outputting HTML: div
3203 sub git_print_header_div
{
3204 my ($action, $title, $hash, $hash_base) = @_;
3207 $args{'action'} = $action;
3208 $args{'hash'} = $hash if $hash;
3209 $args{'hash_base'} = $hash_base if $hash_base;
3211 print "<div class=\"header\">\n" .
3212 $cgi->a({-href
=> href
(%args), -class => "title"},
3213 $title ?
$title : $action) .
3217 sub git_print_authorship
{
3220 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
3221 print "<div class=\"author_date\">" .
3222 esc_html
($co->{'author_name'}) .
3224 if ($ad{'hour_local'} < 6) {
3225 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3226 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3228 printf(" (%02d:%02d %s)",
3229 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3234 sub git_print_page_path
{
3240 print "<div class=\"page_path\">";
3241 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
3242 -title
=> 'tree root'}, to_utf8
("[$project]"));
3244 if (defined $name) {
3245 my @dirname = split '/', $name;
3246 my $basename = pop @dirname;
3249 foreach my $dir (@dirname) {
3250 $fullname .= ($fullname ?
'/' : '') . $dir;
3251 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
3253 -title
=> $fullname}, esc_path
($dir));
3256 if (defined $type && $type eq 'blob') {
3257 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
3259 -title
=> $name}, esc_path
($basename));
3260 } elsif (defined $type && $type eq 'tree') {
3261 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
3263 -title
=> $name}, esc_path
($basename));
3266 print esc_path
($basename);
3269 print "<br/></div>\n";
3276 if ($opts{'-remove_title'}) {
3277 # remove title, i.e. first line of log
3280 # remove leading empty lines
3281 while (defined $log->[0] && $log->[0] eq "") {
3288 foreach my $line (@
$log) {
3289 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
3292 if (! $opts{'-remove_signoff'}) {
3293 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
3296 # remove signoff lines
3303 # print only one empty line
3304 # do not print empty line after signoff
3306 next if ($empty || $signoff);
3312 print format_log_line_html
($line) . "<br/>\n";
3315 if ($opts{'-final_empty_line'}) {
3316 # end with single empty line
3317 print "<br/>\n" unless $empty;
3321 # return link target (what link points to)
3322 sub git_get_link_target
{
3327 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3331 $link_target = <$fd>;
3336 return $link_target;
3339 # given link target, and the directory (basedir) the link is in,
3340 # return target of link relative to top directory (top tree);
3341 # return undef if it is not possible (including absolute links).
3342 sub normalize_link_target
{
3343 my ($link_target, $basedir, $hash_base) = @_;
3345 # we can normalize symlink target only if $hash_base is provided
3346 return unless $hash_base;
3348 # absolute symlinks (beginning with '/') cannot be normalized
3349 return if (substr($link_target, 0, 1) eq '/');
3351 # normalize link target to path from top (root) tree (dir)
3354 $path = $basedir . '/' . $link_target;
3356 # we are in top (root) tree (dir)
3357 $path = $link_target;
3360 # remove //, /./, and /../
3362 foreach my $part (split('/', $path)) {
3363 # discard '.' and ''
3364 next if (!$part || $part eq '.');
3366 if ($part eq '..') {
3370 # link leads outside repository (outside top dir)
3374 push @path_parts, $part;
3377 $path = join('/', @path_parts);
3382 # print tree entry (row of git_tree), but without encompassing <tr> element
3383 sub git_print_tree_entry
{
3384 my ($t, $basedir, $hash_base, $have_blame) = @_;
3387 $base_key{'hash_base'} = $hash_base if defined $hash_base;
3389 # The format of a table row is: mode list link. Where mode is
3390 # the mode of the entry, list is the name of the entry, an href,
3391 # and link is the action links of the entry.
3393 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
3394 if ($t->{'type'} eq "blob") {
3395 print "<td class=\"list\">" .
3396 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3397 file_name
=>"$basedir$t->{'name'}", %base_key),
3398 -class => "list"}, esc_path
($t->{'name'}));
3399 if (S_ISLNK
(oct $t->{'mode'})) {
3400 my $link_target = git_get_link_target
($t->{'hash'});
3402 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
3403 if (defined $norm_target) {
3405 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
3406 file_name
=>$norm_target),
3407 -title
=> $norm_target}, esc_path
($link_target));
3409 print " -> " . esc_path
($link_target);
3414 print "<td class=\"link\">";
3415 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3416 file_name
=>"$basedir$t->{'name'}", %base_key)},
3420 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
3421 file_name
=>"$basedir$t->{'name'}", %base_key)},
3424 if (defined $hash_base) {
3426 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3427 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
3431 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
3432 file_name
=>"$basedir$t->{'name'}")},
3436 } elsif ($t->{'type'} eq "tree") {
3437 print "<td class=\"list\">";
3438 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3439 file_name
=>"$basedir$t->{'name'}", %base_key)},
3440 esc_path
($t->{'name'}));
3442 print "<td class=\"link\">";
3443 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3444 file_name
=>"$basedir$t->{'name'}", %base_key)},
3446 if (defined $hash_base) {
3448 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3449 file_name
=>"$basedir$t->{'name'}")},
3454 # unknown object: we can only present history for it
3455 # (this includes 'commit' object, i.e. submodule support)
3456 print "<td class=\"list\">" .
3457 esc_path
($t->{'name'}) .
3459 print "<td class=\"link\">";
3460 if (defined $hash_base) {
3461 print $cgi->a({-href
=> href
(action
=>"history",
3462 hash_base
=>$hash_base,
3463 file_name
=>"$basedir$t->{'name'}")},
3470 ## ......................................................................
3471 ## functions printing large fragments of HTML
3473 # get pre-image filenames for merge (combined) diff
3474 sub fill_from_file_info
{
3475 my ($diff, @parents) = @_;
3477 $diff->{'from_file'} = [ ];
3478 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
3479 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3480 if ($diff->{'status'}[$i] eq 'R' ||
3481 $diff->{'status'}[$i] eq 'C') {
3482 $diff->{'from_file'}[$i] =
3483 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
3490 # is current raw difftree line of file deletion
3492 my $diffinfo = shift;
3494 return $diffinfo->{'to_id'} eq ('0' x
40);
3497 # does patch correspond to [previous] difftree raw line
3498 # $diffinfo - hashref of parsed raw diff format
3499 # $patchinfo - hashref of parsed patch diff format
3500 # (the same keys as in $diffinfo)
3501 sub is_patch_split
{
3502 my ($diffinfo, $patchinfo) = @_;
3504 return defined $diffinfo && defined $patchinfo
3505 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3509 sub git_difftree_body
{
3510 my ($difftree, $hash, @parents) = @_;
3511 my ($parent) = $parents[0];
3512 my $have_blame = gitweb_check_feature
('blame');
3513 print "<div class=\"list_head\">\n";
3514 if ($#{$difftree} > 10) {
3515 print(($#{$difftree} + 1) . " files changed:\n");
3519 print "<table class=\"" .
3520 (@parents > 1 ?
"combined " : "") .
3523 # header only for combined diff in 'commitdiff' view
3524 my $has_header = @
$difftree && @parents > 1 && $action eq 'commitdiff';
3527 print "<thead><tr>\n" .
3528 "<th></th><th></th>\n"; # filename, patchN link
3529 for (my $i = 0; $i < @parents; $i++) {
3530 my $par = $parents[$i];
3532 $cgi->a({-href
=> href
(action
=>"commitdiff",
3533 hash
=>$hash, hash_parent
=>$par),
3534 -title
=> 'commitdiff to parent number ' .
3535 ($i+1) . ': ' . substr($par,0,7)},
3539 print "</tr></thead>\n<tbody>\n";
3544 foreach my $line (@
{$difftree}) {
3545 my $diff = parsed_difftree_line
($line);
3548 print "<tr class=\"dark\">\n";
3550 print "<tr class=\"light\">\n";
3554 if (exists $diff->{'nparents'}) { # combined diff
3556 fill_from_file_info
($diff, @parents)
3557 unless exists $diff->{'from_file'};
3559 if (!is_deleted
($diff)) {
3560 # file exists in the result (child) commit
3562 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3563 file_name
=>$diff->{'to_file'},
3565 -class => "list"}, esc_path
($diff->{'to_file'})) .
3569 esc_path
($diff->{'to_file'}) .
3573 if ($action eq 'commitdiff') {
3576 print "<td class=\"link\">" .
3577 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3582 my $has_history = 0;
3583 my $not_deleted = 0;
3584 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3585 my $hash_parent = $parents[$i];
3586 my $from_hash = $diff->{'from_id'}[$i];
3587 my $from_path = $diff->{'from_file'}[$i];
3588 my $status = $diff->{'status'}[$i];
3590 $has_history ||= ($status ne 'A');
3591 $not_deleted ||= ($status ne 'D');
3593 if ($status eq 'A') {
3594 print "<td class=\"link\" align=\"right\"> | </td>\n";
3595 } elsif ($status eq 'D') {
3596 print "<td class=\"link\">" .
3597 $cgi->a({-href
=> href
(action
=>"blob",
3600 file_name
=>$from_path)},
3604 if ($diff->{'to_id'} eq $from_hash) {
3605 print "<td class=\"link nochange\">";
3607 print "<td class=\"link\">";
3609 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3610 hash
=>$diff->{'to_id'},
3611 hash_parent
=>$from_hash,
3613 hash_parent_base
=>$hash_parent,
3614 file_name
=>$diff->{'to_file'},
3615 file_parent
=>$from_path)},
3621 print "<td class=\"link\">";
3623 print $cgi->a({-href
=> href
(action
=>"blob",
3624 hash
=>$diff->{'to_id'},
3625 file_name
=>$diff->{'to_file'},
3628 print " | " if ($has_history);
3631 print $cgi->a({-href
=> href
(action
=>"history",
3632 file_name
=>$diff->{'to_file'},
3639 next; # instead of 'else' clause, to avoid extra indent
3641 # else ordinary diff
3643 my ($to_mode_oct, $to_mode_str, $to_file_type);
3644 my ($from_mode_oct, $from_mode_str, $from_file_type);
3645 if ($diff->{'to_mode'} ne ('0' x
6)) {
3646 $to_mode_oct = oct $diff->{'to_mode'};
3647 if (S_ISREG
($to_mode_oct)) { # only for regular file
3648 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3650 $to_file_type = file_type
($diff->{'to_mode'});
3652 if ($diff->{'from_mode'} ne ('0' x
6)) {
3653 $from_mode_oct = oct $diff->{'from_mode'};
3654 if (S_ISREG
($to_mode_oct)) { # only for regular file
3655 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3657 $from_file_type = file_type
($diff->{'from_mode'});
3660 if ($diff->{'status'} eq "A") { # created
3661 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3662 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3663 $mode_chng .= "]</span>";
3665 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3666 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3667 -class => "list"}, esc_path
($diff->{'file'}));
3669 print "<td>$mode_chng</td>\n";
3670 print "<td class=\"link\">";
3671 if ($action eq 'commitdiff') {
3674 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3677 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3678 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3682 } elsif ($diff->{'status'} eq "D") { # deleted
3683 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3685 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3686 hash_base
=>$parent, file_name
=>$diff->{'file'}),
3687 -class => "list"}, esc_path
($diff->{'file'}));
3689 print "<td>$mode_chng</td>\n";
3690 print "<td class=\"link\">";
3691 if ($action eq 'commitdiff') {
3694 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3697 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3698 hash_base
=>$parent, file_name
=>$diff->{'file'})},
3701 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3702 file_name
=>$diff->{'file'})},
3705 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3706 file_name
=>$diff->{'file'})},
3710 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3711 my $mode_chnge = "";
3712 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3713 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3714 if ($from_file_type ne $to_file_type) {
3715 $mode_chnge .= " from $from_file_type to $to_file_type";
3717 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3718 if ($from_mode_str && $to_mode_str) {
3719 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3720 } elsif ($to_mode_str) {
3721 $mode_chnge .= " mode: $to_mode_str";
3724 $mode_chnge .= "]</span>\n";
3727 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3728 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3729 -class => "list"}, esc_path
($diff->{'file'}));
3731 print "<td>$mode_chnge</td>\n";
3732 print "<td class=\"link\">";
3733 if ($action eq 'commitdiff') {
3736 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3738 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3739 # "commit" view and modified file (not onlu mode changed)
3740 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3741 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3742 hash_base
=>$hash, hash_parent_base
=>$parent,
3743 file_name
=>$diff->{'file'})},
3747 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3748 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3751 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3752 file_name
=>$diff->{'file'})},
3755 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3756 file_name
=>$diff->{'file'})},
3760 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3761 my %status_name = ('R' => 'moved', 'C' => 'copied');
3762 my $nstatus = $status_name{$diff->{'status'}};
3764 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3765 # mode also for directories, so we cannot use $to_mode_str
3766 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3769 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3770 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
3771 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3772 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3773 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3774 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
3775 -class => "list"}, esc_path
($diff->{'from_file'})) .
3776 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3777 "<td class=\"link\">";
3778 if ($action eq 'commitdiff') {
3781 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3783 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3784 # "commit" view and modified file (not only pure rename or copy)
3785 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3786 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3787 hash_base
=>$hash, hash_parent_base
=>$parent,
3788 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
3792 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3793 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
3796 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3797 file_name
=>$diff->{'to_file'})},
3800 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3801 file_name
=>$diff->{'to_file'})},
3805 } # we should not encounter Unmerged (U) or Unknown (X) status
3808 print "</tbody>" if $has_header;
3812 sub git_patchset_body
{
3813 my ($fd, $difftree, $hash, @hash_parents) = @_;
3814 my ($hash_parent) = $hash_parents[0];
3816 my $is_combined = (@hash_parents > 1);
3818 my $patch_number = 0;
3824 print "<div class=\"patchset\">\n";
3826 # skip to first patch
3827 while ($patch_line = <$fd>) {
3830 last if ($patch_line =~ m/^diff /);
3834 while ($patch_line) {
3836 # parse "git diff" header line
3837 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
3838 # $1 is from_name, which we do not use
3839 $to_name = unquote
($2);
3840 $to_name =~ s!^b/!!;
3841 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
3842 # $1 is 'cc' or 'combined', which we do not use
3843 $to_name = unquote
($2);
3848 # check if current patch belong to current raw line
3849 # and parse raw git-diff line if needed
3850 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
3851 # this is continuation of a split patch
3852 print "<div class=\"patch cont\">\n";
3854 # advance raw git-diff output if needed
3855 $patch_idx++ if defined $diffinfo;
3857 # read and prepare patch information
3858 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3860 # compact combined diff output can have some patches skipped
3861 # find which patch (using pathname of result) we are at now;
3863 while ($to_name ne $diffinfo->{'to_file'}) {
3864 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3865 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3866 "</div>\n"; # class="patch"
3871 last if $patch_idx > $#$difftree;
3872 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3876 # modifies %from, %to hashes
3877 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
3879 # this is first patch for raw difftree line with $patch_idx index
3880 # we index @$difftree array from 0, but number patches from 1
3881 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3885 #assert($patch_line =~ m/^diff /) if DEBUG;
3886 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
3888 # print "git diff" header
3889 print format_git_diff_header_line
($patch_line, $diffinfo,
3892 # print extended diff header
3893 print "<div class=\"diff extended_header\">\n";
3895 while ($patch_line = <$fd>) {
3898 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
3900 print format_extended_diff_header_line
($patch_line, $diffinfo,
3903 print "</div>\n"; # class="diff extended_header"
3905 # from-file/to-file diff header
3906 if (! $patch_line) {
3907 print "</div>\n"; # class="patch"
3910 next PATCH
if ($patch_line =~ m/^diff /);
3911 #assert($patch_line =~ m/^---/) if DEBUG;
3913 my $last_patch_line = $patch_line;
3914 $patch_line = <$fd>;
3916 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3918 print format_diff_from_to_header
($last_patch_line, $patch_line,
3919 $diffinfo, \
%from, \
%to,
3924 while ($patch_line = <$fd>) {
3927 next PATCH
if ($patch_line =~ m/^diff /);
3929 print format_diff_line
($patch_line, \
%from, \
%to);
3933 print "</div>\n"; # class="patch"
3936 # for compact combined (--cc) format, with chunk and patch simpliciaction
3937 # patchset might be empty, but there might be unprocessed raw lines
3938 for (++$patch_idx if $patch_number > 0;
3939 $patch_idx < @
$difftree;
3941 # read and prepare patch information
3942 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3944 # generate anchor for "patch" links in difftree / whatchanged part
3945 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3946 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3947 "</div>\n"; # class="patch"
3952 if ($patch_number == 0) {
3953 if (@hash_parents > 1) {
3954 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3956 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3960 print "</div>\n"; # class="patchset"
3963 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3965 # fills project list info (age, description, owner, forks) for each
3966 # project in the list, removing invalid projects from returned list
3967 # NOTE: modifies $projlist, but does not remove entries from it
3968 sub fill_project_list_info
{
3969 my ($projlist, $check_forks) = @_;
3972 my $show_ctags = gitweb_check_feature
('ctags');
3974 foreach my $pr (@
$projlist) {
3975 my (@activity) = git_get_last_activity
($pr->{'path'});
3976 unless (@activity) {
3979 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
3980 if (!defined $pr->{'descr'}) {
3981 my $descr = git_get_project_description
($pr->{'path'}) || "";
3982 $descr = to_utf8
($descr);
3983 $pr->{'descr_long'} = $descr;
3984 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
3986 if (!defined $pr->{'owner'}) {
3987 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
3990 my $pname = $pr->{'path'};
3991 if (($pname =~ s/\.git$//) &&
3992 ($pname !~ /\/$/) &&
3993 (-d
"$projectroot/$pname")) {
3994 $pr->{'forks'} = "-d $projectroot/$pname";
3999 $show_ctags and $pr->{'ctags'} = git_get_project_ctags
($pr->{'path'});
4000 push @projects, $pr;
4006 # print 'sort by' <th> element, generating 'sort by $name' replay link
4007 # if that order is not selected
4009 my ($name, $order, $header) = @_;
4010 $header ||= ucfirst($name);
4012 if ($order eq $name) {
4013 print "<th>$header</th>\n";
4016 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
4017 -class => "header"}, $header) .
4022 sub git_project_list_body
{
4023 # actually uses global variable $project
4024 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
4026 my $check_forks = gitweb_check_feature
('forks');
4027 my @projects = fill_project_list_info
($projlist, $check_forks);
4029 $order ||= $default_projects_order;
4030 $from = 0 unless defined $from;
4031 $to = $#projects if (!defined $to || $#projects < $to);
4034 project
=> { key
=> 'path', type
=> 'str' },
4035 descr
=> { key
=> 'descr_long', type
=> 'str' },
4036 owner
=> { key
=> 'owner', type
=> 'str' },
4037 age
=> { key
=> 'age', type
=> 'num' }
4039 my $oi = $order_info{$order};
4040 if ($oi->{'type'} eq 'str') {
4041 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
4043 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
4046 my $show_ctags = gitweb_check_feature
('ctags');
4049 foreach my $p (@projects) {
4050 foreach my $ct (keys %{$p->{'ctags'}}) {
4051 $ctags{$ct} += $p->{'ctags'}->{$ct};
4054 my $cloud = git_populate_project_tagcloud
(\
%ctags);
4055 print git_show_project_tagcloud
($cloud, 64);
4058 print "<table class=\"project_list\">\n";
4059 unless ($no_header) {
4062 print "<th></th>\n";
4064 print_sort_th
('project', $order, 'Project');
4065 print_sort_th
('descr', $order, 'Description');
4066 print_sort_th
('owner', $order, 'Owner');
4067 print_sort_th
('age', $order, 'Last Change');
4068 print "<th></th>\n" . # for links
4072 my $tagfilter = $cgi->param('by_tag');
4073 for (my $i = $from; $i <= $to; $i++) {
4074 my $pr = $projects[$i];
4076 next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}};
4077 next if $searchtext and not $pr->{'path'} =~ /$searchtext/
4078 and not $pr->{'descr_long'} =~ /$searchtext/;
4079 # Weed out forks or non-matching entries of search
4081 my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s
#\.git$#/#;
4082 $forkbase="^$forkbase" if $forkbase;
4083 next if not $searchtext and not $tagfilter and $show_ctags
4084 and $pr->{'path'} =~ m
#$forkbase.*/.*#; # regexp-safe
4088 print "<tr class=\"dark\">\n";
4090 print "<tr class=\"light\">\n";
4095 if ($pr->{'forks'}) {
4096 print "<!-- $pr->{'forks'} -->\n";
4097 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
4101 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4102 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
4103 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4104 -class => "list", -title
=> $pr->{'descr_long'}},
4105 esc_html
($pr->{'descr'})) . "</td>\n" .
4106 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
4107 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
4108 (defined $pr->{'age_string'} ?
$pr->{'age_string'} : "No commits") . "</td>\n" .
4109 "<td class=\"link\">" .
4110 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
4111 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
4112 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
4113 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
4114 ($pr->{'forks'} ?
" | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
4118 if (defined $extra) {
4121 print "<td></td>\n";
4123 print "<td colspan=\"5\">$extra</td>\n" .
4129 sub git_shortlog_body
{
4130 # uses global variable $project
4131 my ($commitlist, $from, $to, $refs, $extra) = @_;
4133 $from = 0 unless defined $from;
4134 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4136 print "<table class=\"shortlog\">\n";
4138 for (my $i = $from; $i <= $to; $i++) {
4139 my %co = %{$commitlist->[$i]};
4140 my $commit = $co{'id'};
4141 my $ref = format_ref_marker
($refs, $commit);
4143 print "<tr class=\"dark\">\n";
4145 print "<tr class=\"light\">\n";
4148 my $author = chop_and_escape_str
($co{'author_name'}, 10);
4149 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
4150 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4151 "<td><i>" . $author . "</i></td>\n" .
4153 print format_subject_html
($co{'title'}, $co{'title_short'},
4154 href
(action
=>"commit", hash
=>$commit), $ref);
4156 "<td class=\"link\">" .
4157 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
4158 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
4159 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
4160 my $snapshot_links = format_snapshot_links
($commit);
4161 if (defined $snapshot_links) {
4162 print " | " . $snapshot_links;
4167 if (defined $extra) {
4169 "<td colspan=\"4\">$extra</td>\n" .
4175 sub git_history_body
{
4176 # Warning: assumes constant type (blob or tree) during history
4177 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
4179 $from = 0 unless defined $from;
4180 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
4182 print "<table class=\"history\">\n";
4184 for (my $i = $from; $i <= $to; $i++) {
4185 my %co = %{$commitlist->[$i]};
4189 my $commit = $co{'id'};
4191 my $ref = format_ref_marker
($refs, $commit);
4194 print "<tr class=\"dark\">\n";
4196 print "<tr class=\"light\">\n";
4199 # shortlog uses chop_str($co{'author_name'}, 10)
4200 my $author = chop_and_escape_str
($co{'author_name'}, 15, 3);
4201 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4202 "<td><i>" . $author . "</i></td>\n" .
4204 # originally git_history used chop_str($co{'title'}, 50)
4205 print format_subject_html
($co{'title'}, $co{'title_short'},
4206 href
(action
=>"commit", hash
=>$commit), $ref);
4208 "<td class=\"link\">" .
4209 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
4210 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
4212 if ($ftype eq 'blob') {
4213 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
4214 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
4215 if (defined $blob_current && defined $blob_parent &&
4216 $blob_current ne $blob_parent) {
4218 $cgi->a({-href
=> href
(action
=>"blobdiff",
4219 hash
=>$blob_current, hash_parent
=>$blob_parent,
4220 hash_base
=>$hash_base, hash_parent_base
=>$commit,
4221 file_name
=>$file_name)},
4228 if (defined $extra) {
4230 "<td colspan=\"4\">$extra</td>\n" .
4237 # uses global variable $project
4238 my ($taglist, $from, $to, $extra) = @_;
4239 $from = 0 unless defined $from;
4240 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
4242 print "<table class=\"tags\">\n";
4244 for (my $i = $from; $i <= $to; $i++) {
4245 my $entry = $taglist->[$i];
4247 my $comment = $tag{'subject'};
4249 if (defined $comment) {
4250 $comment_short = chop_str
($comment, 30, 5);
4253 print "<tr class=\"dark\">\n";
4255 print "<tr class=\"light\">\n";
4258 if (defined $tag{'age'}) {
4259 print "<td><i>$tag{'age'}</i></td>\n";
4261 print "<td></td>\n";
4264 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
4265 -class => "list name"}, esc_html
($tag{'name'})) .
4268 if (defined $comment) {
4269 print format_subject_html
($comment, $comment_short,
4270 href
(action
=>"tag", hash
=>$tag{'id'}));
4273 "<td class=\"selflink\">";
4274 if ($tag{'type'} eq "tag") {
4275 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
4280 "<td class=\"link\">" . " | " .
4281 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
4282 if ($tag{'reftype'} eq "commit") {
4283 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
4284 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
4285 } elsif ($tag{'reftype'} eq "blob") {
4286 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
4291 if (defined $extra) {
4293 "<td colspan=\"5\">$extra</td>\n" .
4299 sub git_heads_body
{
4300 # uses global variable $project
4301 my ($headlist, $head, $from, $to, $extra) = @_;
4302 $from = 0 unless defined $from;
4303 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
4305 print "<table class=\"heads\">\n";
4307 for (my $i = $from; $i <= $to; $i++) {
4308 my $entry = $headlist->[$i];
4310 my $curr = $ref{'id'} eq $head;
4312 print "<tr class=\"dark\">\n";
4314 print "<tr class=\"light\">\n";
4317 print "<td><i>$ref{'age'}</i></td>\n" .
4318 ($curr ?
"<td class=\"current_head\">" : "<td>") .
4319 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
4320 -class => "list name"},esc_html
($ref{'name'})) .
4322 "<td class=\"link\">" .
4323 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
4324 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
4325 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
4329 if (defined $extra) {
4331 "<td colspan=\"3\">$extra</td>\n" .
4337 sub git_search_grep_body
{
4338 my ($commitlist, $from, $to, $extra) = @_;
4339 $from = 0 unless defined $from;
4340 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4342 print "<table class=\"commit_search\">\n";
4344 for (my $i = $from; $i <= $to; $i++) {
4345 my %co = %{$commitlist->[$i]};
4349 my $commit = $co{'id'};
4351 print "<tr class=\"dark\">\n";
4353 print "<tr class=\"light\">\n";
4356 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
4357 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4358 "<td><i>" . $author . "</i></td>\n" .
4360 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4361 -class => "list subject"},
4362 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
4363 my $comment = $co{'comment'};
4364 foreach my $line (@
$comment) {
4365 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
4366 my ($lead, $match, $trail) = ($1, $2, $3);
4367 $match = chop_str
($match, 70, 5, 'center');
4368 my $contextlen = int((80 - length($match))/2);
4369 $contextlen = 30 if ($contextlen > 30);
4370 $lead = chop_str
($lead, $contextlen, 10, 'left');
4371 $trail = chop_str
($trail, $contextlen, 10, 'right');
4373 $lead = esc_html
($lead);
4374 $match = esc_html
($match);
4375 $trail = esc_html
($trail);
4377 print "$lead<span class=\"match\">$match</span>$trail<br />";
4381 "<td class=\"link\">" .
4382 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4384 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
4386 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4390 if (defined $extra) {
4392 "<td colspan=\"3\">$extra</td>\n" .
4398 ## ======================================================================
4399 ## ======================================================================
4402 sub git_project_list
{
4403 my $order = $input_params{'order'};
4404 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4405 die_error
(400, "Unknown order parameter");
4408 my @list = git_get_projects_list
();
4410 die_error
(404, "No projects found");
4414 if (-f
$home_text) {
4415 print "<div class=\"index_include\">\n";
4416 insert_file
($home_text);
4419 print $cgi->startform(-method
=> "get") .
4420 "<p class=\"projsearch\">Search:\n" .
4421 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
4423 $cgi->end_form() . "\n";
4424 git_project_list_body
(\
@list, $order);
4429 my $order = $input_params{'order'};
4430 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4431 die_error
(400, "Unknown order parameter");
4434 my @list = git_get_projects_list
($project);
4436 die_error
(404, "No forks found");
4440 git_print_page_nav
('','');
4441 git_print_header_div
('summary', "$project forks");
4442 git_project_list_body
(\
@list, $order);
4446 sub git_project_index
{
4447 my @projects = git_get_projects_list
($project);
4450 -type
=> 'text/plain',
4451 -charset
=> 'utf-8',
4452 -content_disposition
=> 'inline; filename="index.aux"');
4454 foreach my $pr (@projects) {
4455 if (!exists $pr->{'owner'}) {
4456 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
4459 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
4460 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
4461 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4462 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4466 print "$path $owner\n";
4471 my $descr = git_get_project_description
($project) || "none";
4472 my %co = parse_commit
("HEAD");
4473 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
4474 my $head = $co{'id'};
4476 my $owner = git_get_project_owner
($project);
4478 my $refs = git_get_references
();
4479 # These get_*_list functions return one more to allow us to see if
4480 # there are more ...
4481 my @taglist = git_get_tags_list
(16);
4482 my @headlist = git_get_heads_list
(16);
4484 my $check_forks = gitweb_check_feature
('forks');
4487 @forklist = git_get_projects_list
($project);
4491 git_print_page_nav
('summary','', $head);
4493 print "<div class=\"title\"> </div>\n";
4494 print "<table class=\"projects_list\">\n" .
4495 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
4496 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
4497 if (defined $cd{'rfc2822'}) {
4498 print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4501 # use per project git URL list in $projectroot/$project/cloneurl
4502 # or make project git URL from git base URL and project name
4503 my $url_tag = "URL";
4504 my @url_list = git_get_project_url_list
($project);
4505 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4506 foreach my $git_url (@url_list) {
4507 next unless $git_url;
4508 print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";
4513 my $show_ctags = gitweb_check_feature
('ctags');
4515 my $ctags = git_get_project_ctags
($project);
4516 my $cloud = git_populate_project_tagcloud
($ctags);
4517 print "<tr id=\"metadata_ctags\"><td>Content tags:<br />";
4518 print "</td>\n<td>" unless %$ctags;
4519 print "<form action=\"$show_ctags\" method=\"post\"><input type=\"hidden\" name=\"p\" value=\"$project\" />Add: <input type=\"text\" name=\"t\" size=\"8\" /></form>";
4520 print "</td>\n<td>" if %$ctags;
4521 print git_show_project_tagcloud
($cloud, 48);
4527 # If XSS prevention is on, we don't include README.html.
4528 # TODO: Allow a readme in some safe format.
4529 if (!$prevent_xss && -s
"$projectroot/$project/README.html") {
4530 print "<div class=\"title\">readme</div>\n" .
4531 "<div class=\"readme\">\n";
4532 insert_file
("$projectroot/$project/README.html");
4533 print "\n</div>\n"; # class="readme"
4536 # we need to request one more than 16 (0..15) to check if
4538 my @commitlist = $head ? parse_commits
($head, 17) : ();
4540 git_print_header_div
('shortlog');
4541 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
4542 $#commitlist <= 15 ?
undef :
4543 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
4547 git_print_header_div
('tags');
4548 git_tags_body
(\
@taglist, 0, 15,
4549 $#taglist <= 15 ?
undef :
4550 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
4554 git_print_header_div
('heads');
4555 git_heads_body
(\
@headlist, $head, 0, 15,
4556 $#headlist <= 15 ?
undef :
4557 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
4561 git_print_header_div
('forks');
4562 git_project_list_body
(\
@forklist, 'age', 0, 15,
4563 $#forklist <= 15 ?
undef :
4564 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
4572 my $head = git_get_head_hash
($project);
4574 git_print_page_nav
('','', $head,undef,$head);
4575 my %tag = parse_tag
($hash);
4578 die_error
(404, "Unknown tag object");
4581 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
4582 print "<div class=\"title_text\">\n" .
4583 "<table class=\"object_header\">\n" .
4585 "<td>object</td>\n" .
4586 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4587 $tag{'object'}) . "</td>\n" .
4588 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4589 $tag{'type'}) . "</td>\n" .
4591 if (defined($tag{'author'})) {
4592 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
4593 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
4594 print "<tr><td></td><td>" . $ad{'rfc2822'} .
4595 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
4598 print "</table>\n\n" .
4600 print "<div class=\"page_body\">";
4601 my $comment = $tag{'comment'};
4602 foreach my $line (@
$comment) {
4604 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4612 gitweb_check_feature
('blame')
4613 or die_error
(403, "Blame view not allowed");
4616 die_error
(400, "No file name given") unless $file_name;
4617 $hash_base ||= git_get_head_hash
($project);
4618 die_error
(404, "Couldn't find base commit") unless $hash_base;
4619 my %co = parse_commit
($hash_base)
4620 or die_error
(404, "Commit not found");
4622 if (!defined $hash) {
4623 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4624 or die_error
(404, "Error looking up file");
4626 $ftype = git_get_type
($hash);
4627 if ($ftype !~ "blob") {
4628 die_error
(400, "Object is not a blob");
4632 # run git-blame --porcelain
4633 open my $fd, "-|", git_cmd
(), "blame", '-p',
4634 $hash_base, '--', $file_name
4635 or die_error
(500, "Open git-blame failed");
4640 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
4643 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4646 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4648 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4649 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4650 git_print_page_path
($file_name, $ftype, $hash_base);
4653 my @rev_color = qw(light2 dark2);
4654 my $num_colors = scalar(@rev_color);
4655 my $current_color = 0;
4659 <div class="page_body">
4660 <table class="blame">
4661 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
4664 while (my $line = <$fd>) {
4666 # the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]
4667 # no <lines in group> for subsequent lines in group of lines
4668 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4669 ($line =~ /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);
4670 if (!exists $metainfo{$full_rev}) {
4671 $metainfo{$full_rev} = {};
4673 my $meta = $metainfo{$full_rev};
4675 while ($data = <$fd>) {
4677 last if ($data =~ s/^\t//); # contents of line
4678 if ($data =~ /^(\S+) (.*)$/) {
4682 my $short_rev = substr($full_rev, 0, 8);
4683 my $author = $meta->{'author'};
4685 parse_date
($meta->{'author-time'}, $meta->{'author-tz'});
4686 my $date = $date{'iso-tz'};
4688 $current_color = ($current_color + 1) % $num_colors;
4690 print "<tr id=\"l$lineno\" class=\"$rev_color[$current_color]\">\n";
4692 print "<td class=\"sha1\"";
4693 print " title=\"". esc_html
($author) . ", $date\"";
4694 print " rowspan=\"$group_size\"" if ($group_size > 1);
4696 print $cgi->a({-href
=> href
(action
=>"commit",
4698 file_name
=>$file_name)},
4699 esc_html
($short_rev));
4703 if (!exists $meta->{'parent'}) {
4704 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
4705 or die_error
(500, "Open git-rev-parse failed");
4706 $parent_commit = <$dd>;
4708 chomp($parent_commit);
4709 $meta->{'parent'} = $parent_commit;
4711 $parent_commit = $meta->{'parent'};
4713 my $blamed = href
(action
=> 'blame',
4714 file_name
=> $meta->{'filename'},
4715 hash_base
=> $parent_commit);
4716 print "<td class=\"linenr\">";
4717 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
4718 -class => "linenr" },
4721 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
4727 or print "Reading blob failed\n";
4734 my $head = git_get_head_hash
($project);
4736 git_print_page_nav
('','', $head,undef,$head);
4737 git_print_header_div
('summary', $project);
4739 my @tagslist = git_get_tags_list
();
4741 git_tags_body
(\
@tagslist);
4747 my $head = git_get_head_hash
($project);
4749 git_print_page_nav
('','', $head,undef,$head);
4750 git_print_header_div
('summary', $project);
4752 my @headslist = git_get_heads_list
();
4754 git_heads_body
(\
@headslist, $head);
4759 sub git_blob_plain
{
4763 if (!defined $hash) {
4764 if (defined $file_name) {
4765 my $base = $hash_base || git_get_head_hash
($project);
4766 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4767 or die_error
(404, "Cannot find file");
4769 die_error
(400, "No file name defined");
4771 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4772 # blobs defined by non-textual hash id's can be cached
4776 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4777 or die_error
(500, "Open git-cat-file blob '$hash' failed");
4779 # content-type (can include charset)
4780 $type = blob_contenttype
($fd, $file_name, $type);
4782 # "save as" filename, even when no $file_name is given
4783 my $save_as = "$hash";
4784 if (defined $file_name) {
4785 $save_as = $file_name;
4786 } elsif ($type =~ m/^text\//) {
4790 # With XSS prevention on, blobs of all types except a few known safe
4791 # ones are served with "Content-Disposition: attachment" to make sure
4792 # they don't run in our security domain. For certain image types,
4793 # blob view writes an <img> tag referring to blob_plain view, and we
4794 # want to be sure not to break that by serving the image as an
4795 # attachment (though Firefox 3 doesn't seem to care).
4796 my $sandbox = $prevent_xss &&
4797 $type !~ m!^(?:text/plain|image/(?:gif|png|jpeg))$!;
4801 -expires
=> $expires,
4802 -content_disposition
=>
4803 ($sandbox ?
'attachment' : 'inline')
4804 . '; filename="' . $save_as . '"');
4806 binmode STDOUT
, ':raw';
4808 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4816 if (!defined $hash) {
4817 if (defined $file_name) {
4818 my $base = $hash_base || git_get_head_hash
($project);
4819 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4820 or die_error
(404, "Cannot find file");
4822 die_error
(400, "No file name defined");
4824 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4825 # blobs defined by non-textual hash id's can be cached
4829 my $have_blame = gitweb_check_feature
('blame');
4830 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4831 or die_error
(500, "Couldn't cat $file_name, $hash");
4832 my $mimetype = blob_mimetype
($fd, $file_name);
4833 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
4835 return git_blob_plain
($mimetype);
4837 # we can have blame only for text/* mimetype
4838 $have_blame &&= ($mimetype =~ m!^text/!);
4840 git_header_html
(undef, $expires);
4841 my $formats_nav = '';
4842 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4843 if (defined $file_name) {
4846 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
4851 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4854 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4857 $cgi->a({-href
=> href
(action
=>"blob",
4858 hash_base
=>"HEAD", file_name
=>$file_name)},
4862 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4865 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4866 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4868 print "<div class=\"page_nav\">\n" .
4869 "<br/><br/></div>\n" .
4870 "<div class=\"title\">$hash</div>\n";
4872 git_print_page_path
($file_name, "blob", $hash_base);
4873 print "<div class=\"page_body\">\n";
4874 if ($mimetype =~ m!^image/!) {
4875 print qq!<img type
="$mimetype"!;
4877 print qq! alt
="$file_name" title
="$file_name"!;
4880 href(action=>"blob_plain
", hash=>$hash,
4881 hash_base=>$hash_base, file_name=>$file_name) .
4885 while (my $line = <$fd>) {
4888 $line = untabify
($line);
4889 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4890 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4894 or print "Reading blob failed.\n";
4900 if (!defined $hash_base) {
4901 $hash_base = "HEAD";
4903 if (!defined $hash) {
4904 if (defined $file_name) {
4905 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4910 die_error
(404, "No such tree") unless defined($hash);
4912 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4913 or die_error
(500, "Open git-ls-tree failed");
4914 my @entries = map { chomp; $_ } <$fd>;
4915 close $fd or die_error
(404, "Reading tree failed");
4918 my $refs = git_get_references
();
4919 my $ref = format_ref_marker
($refs, $hash_base);
4922 my $have_blame = gitweb_check_feature
('blame');
4923 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4925 if (defined $file_name) {
4927 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4929 $cgi->a({-href
=> href
(action
=>"tree",
4930 hash_base
=>"HEAD", file_name
=>$file_name)},
4933 my $snapshot_links = format_snapshot_links
($hash);
4934 if (defined $snapshot_links) {
4935 # FIXME: Should be available when we have no hash base as well.
4936 push @views_nav, $snapshot_links;
4938 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4939 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4942 print "<div class=\"page_nav\">\n";
4943 print "<br/><br/></div>\n";
4944 print "<div class=\"title\">$hash</div>\n";
4946 if (defined $file_name) {
4947 $basedir = $file_name;
4948 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4951 git_print_page_path
($file_name, 'tree', $hash_base);
4953 print "<div class=\"page_body\">\n";
4954 print "<table class=\"tree\">\n";
4956 # '..' (top directory) link if possible
4957 if (defined $hash_base &&
4958 defined $file_name && $file_name =~ m![^/]+$!) {
4960 print "<tr class=\"dark\">\n";
4962 print "<tr class=\"light\">\n";
4966 my $up = $file_name;
4967 $up =~ s!/?[^/]+$!!;
4968 undef $up unless $up;
4969 # based on git_print_tree_entry
4970 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4971 print '<td class="list">';
4972 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4976 print "<td class=\"link\"></td>\n";
4980 foreach my $line (@entries) {
4981 my %t = parse_ls_tree_line
($line, -z
=> 1);
4984 print "<tr class=\"dark\">\n";
4986 print "<tr class=\"light\">\n";
4990 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4994 print "</table>\n" .
5000 my $format = $input_params{'snapshot_format'};
5001 if (!@snapshot_fmts) {
5002 die_error
(403, "Snapshots not allowed");
5004 # default to first supported snapshot format
5005 $format ||= $snapshot_fmts[0];
5006 if ($format !~ m/^[a-z0-9]+$/) {
5007 die_error
(400, "Invalid snapshot format parameter");
5008 } elsif (!exists($known_snapshot_formats{$format})) {
5009 die_error
(400, "Unknown snapshot format");
5010 } elsif (!grep($_ eq $format, @snapshot_fmts)) {
5011 die_error
(403, "Unsupported snapshot format");
5014 if (!defined $hash) {
5015 $hash = git_get_head_hash
($project);
5018 my $name = $project;
5019 $name =~ s
,([^/])/*\
.git
$,$1,;
5020 $name = basename
($name);
5021 my $filename = to_utf8
($name);
5022 $name =~ s/\047/\047\\\047\047/g;
5024 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
5025 $cmd = quote_command
(
5026 git_cmd
(), 'archive',
5027 "--format=$known_snapshot_formats{$format}{'format'}",
5028 "--prefix=$name/", $hash);
5029 if (exists $known_snapshot_formats{$format}{'compressor'}) {
5030 $cmd .= ' | ' . quote_command
(@
{$known_snapshot_formats{$format}{'compressor'}});
5034 -type
=> $known_snapshot_formats{$format}{'type'},
5035 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
5036 -status
=> '200 OK');
5038 open my $fd, "-|", $cmd
5039 or die_error
(500, "Execute git-archive failed");
5040 binmode STDOUT
, ':raw';
5042 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5047 my $head = git_get_head_hash
($project);
5048 if (!defined $hash) {
5051 if (!defined $page) {
5054 my $refs = git_get_references
();
5056 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5058 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#commitlist >= 100);
5060 my ($patch_max) = gitweb_get_feature
('patches');
5062 if ($patch_max < 0 || @commitlist <= $patch_max) {
5063 $paging_nav .= " ⋅ " .
5064 $cgi->a({-href
=> href
(action
=>"patches", -replay
=>1)},
5070 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
5073 my %co = parse_commit
($hash);
5075 git_print_header_div
('summary', $project);
5076 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
5078 my $to = ($#commitlist >= 99) ?
(99) : ($#commitlist);
5079 for (my $i = 0; $i <= $to; $i++) {
5080 my %co = %{$commitlist[$i]};
5082 my $commit = $co{'id'};
5083 my $ref = format_ref_marker
($refs, $commit);
5084 my %ad = parse_date
($co{'author_epoch'});
5085 git_print_header_div
('commit',
5086 "<span class=\"age\">$co{'age_string'}</span>" .
5087 esc_html
($co{'title'}) . $ref,
5089 print "<div class=\"title_text\">\n" .
5090 "<div class=\"log_link\">\n" .
5091 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
5093 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
5095 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
5098 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
5101 print "<div class=\"log_body\">\n";
5102 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
5105 if ($#commitlist >= 100) {
5106 print "<div class=\"page_nav\">\n";
5107 print $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5108 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5115 $hash ||= $hash_base || "HEAD";
5116 my %co = parse_commit
($hash)
5117 or die_error
(404, "Unknown commit object");
5118 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5119 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
5121 my $parent = $co{'parent'};
5122 my $parents = $co{'parents'}; # listref
5124 # we need to prepare $formats_nav before any parameter munging
5126 if (!defined $parent) {
5128 $formats_nav .= '(initial)';
5129 } elsif (@
$parents == 1) {
5130 # single parent commit
5133 $cgi->a({-href
=> href
(action
=>"commit",
5135 esc_html
(substr($parent, 0, 7))) .
5142 $cgi->a({-href
=> href
(action
=>"commit",
5144 esc_html
(substr($_, 0, 7)));
5148 if (gitweb_check_feature
('patches')) {
5149 $formats_nav .= " | " .
5150 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
5154 if (!defined $parent) {
5158 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
5160 (@
$parents <= 1 ?
$parent : '-c'),
5162 or die_error
(500, "Open git-diff-tree failed");
5163 @difftree = map { chomp; $_ } <$fd>;
5164 close $fd or die_error
(404, "Reading git-diff-tree failed");
5166 # non-textual hash id's can be cached
5168 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5171 my $refs = git_get_references
();
5172 my $ref = format_ref_marker
($refs, $co{'id'});
5174 git_header_html
(undef, $expires);
5175 git_print_page_nav
('commit', '',
5176 $hash, $co{'tree'}, $hash,
5179 if (defined $co{'parent'}) {
5180 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
5182 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
5184 print "<div class=\"title_text\">\n" .
5185 "<table class=\"object_header\">\n";
5186 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
5188 "<td></td><td> $ad{'rfc2822'}";
5189 if ($ad{'hour_local'} < 6) {
5190 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
5191 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
5193 printf(" (%02d:%02d %s)",
5194 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
5198 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
5199 print "<tr><td></td><td> $cd{'rfc2822'}" .
5200 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
5202 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
5205 "<td class=\"sha1\">" .
5206 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
5207 class => "list"}, $co{'tree'}) .
5209 "<td class=\"link\">" .
5210 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
5212 my $snapshot_links = format_snapshot_links
($hash);
5213 if (defined $snapshot_links) {
5214 print " | " . $snapshot_links;
5219 foreach my $par (@
$parents) {
5222 "<td class=\"sha1\">" .
5223 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
5224 class => "list"}, $par) .
5226 "<td class=\"link\">" .
5227 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
5229 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
5236 print "<div class=\"page_body\">\n";
5237 git_print_log
($co{'comment'});
5240 git_difftree_body
(\
@difftree, $hash, @
$parents);
5246 # object is defined by:
5247 # - hash or hash_base alone
5248 # - hash_base and file_name
5251 # - hash or hash_base alone
5252 if ($hash || ($hash_base && !defined $file_name)) {
5253 my $object_id = $hash || $hash_base;
5255 open my $fd, "-|", quote_command
(
5256 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
5257 or die_error
(404, "Object does not exist");
5261 or die_error
(404, "Object does not exist");
5263 # - hash_base and file_name
5264 } elsif ($hash_base && defined $file_name) {
5265 $file_name =~ s
,/+$,,;
5267 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
5268 or die_error
(404, "Base object does not exist");
5270 # here errors should not hapen
5271 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
5272 or die_error
(500, "Open git-ls-tree failed");
5276 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
5277 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
5278 die_error
(404, "File or directory for given base does not exist");
5283 die_error
(400, "Not enough information to find object");
5286 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
5287 hash
=>$hash, hash_base
=>$hash_base,
5288 file_name
=>$file_name),
5289 -status
=> '302 Found');
5293 my $format = shift || 'html';
5300 # preparing $fd and %diffinfo for git_patchset_body
5302 if (defined $hash_base && defined $hash_parent_base) {
5303 if (defined $file_name) {
5305 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5306 $hash_parent_base, $hash_base,
5307 "--", (defined $file_parent ?
$file_parent : ()), $file_name
5308 or die_error
(500, "Open git-diff-tree failed");
5309 @difftree = map { chomp; $_ } <$fd>;
5311 or die_error
(404, "Reading git-diff-tree failed");
5313 or die_error
(404, "Blob diff not found");
5315 } elsif (defined $hash &&
5316 $hash =~ /[0-9a-fA-F]{40}/) {
5317 # try to find filename from $hash
5319 # read filtered raw output
5320 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5321 $hash_parent_base, $hash_base, "--"
5322 or die_error
(500, "Open git-diff-tree failed");
5324 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
5326 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
5327 map { chomp; $_ } <$fd>;
5329 or die_error
(404, "Reading git-diff-tree failed");
5331 or die_error
(404, "Blob diff not found");
5334 die_error
(400, "Missing one of the blob diff parameters");
5337 if (@difftree > 1) {
5338 die_error
(400, "Ambiguous blob diff specification");
5341 %diffinfo = parse_difftree_raw_line
($difftree[0]);
5342 $file_parent ||= $diffinfo{'from_file'} || $file_name;
5343 $file_name ||= $diffinfo{'to_file'};
5345 $hash_parent ||= $diffinfo{'from_id'};
5346 $hash ||= $diffinfo{'to_id'};
5348 # non-textual hash id's can be cached
5349 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
5350 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
5355 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5356 '-p', ($format eq 'html' ?
"--full-index" : ()),
5357 $hash_parent_base, $hash_base,
5358 "--", (defined $file_parent ?
$file_parent : ()), $file_name
5359 or die_error
(500, "Open git-diff-tree failed");
5362 # old/legacy style URI -- not generated anymore since 1.4.3.
5364 die_error
('404 Not Found', "Missing one of the blob diff parameters")
5368 if ($format eq 'html') {
5370 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
5372 git_header_html
(undef, $expires);
5373 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5374 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5375 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5377 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
5378 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
5380 if (defined $file_name) {
5381 git_print_page_path
($file_name, "blob", $hash_base);
5383 print "<div class=\"page_path\"></div>\n";
5386 } elsif ($format eq 'plain') {
5388 -type
=> 'text/plain',
5389 -charset
=> 'utf-8',
5390 -expires
=> $expires,
5391 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
5393 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5396 die_error
(400, "Unknown blobdiff format");
5400 if ($format eq 'html') {
5401 print "<div class=\"page_body\">\n";
5403 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
5406 print "</div>\n"; # class="page_body"
5410 while (my $line = <$fd>) {
5411 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
5412 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
5416 last if $line =~ m!^\+\+\+!;
5424 sub git_blobdiff_plain
{
5425 git_blobdiff
('plain');
5428 sub git_commitdiff
{
5430 my $format = $params{-format
} || 'html';
5432 my ($patch_max) = gitweb_get_feature
('patches');
5433 if ($format eq 'patch') {
5434 die_error
(403, "Patch view not allowed") unless $patch_max;
5437 $hash ||= $hash_base || "HEAD";
5438 my %co = parse_commit
($hash)
5439 or die_error
(404, "Unknown commit object");
5441 # choose format for commitdiff for merge
5442 if (! defined $hash_parent && @
{$co{'parents'}} > 1) {
5443 $hash_parent = '--cc';
5445 # we need to prepare $formats_nav before almost any parameter munging
5447 if ($format eq 'html') {
5449 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
5452 $formats_nav .= " | " .
5453 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
5457 if (defined $hash_parent &&
5458 $hash_parent ne '-c' && $hash_parent ne '--cc') {
5459 # commitdiff with two commits given
5460 my $hash_parent_short = $hash_parent;
5461 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5462 $hash_parent_short = substr($hash_parent, 0, 7);
5466 for (my $i = 0; $i < @
{$co{'parents'}}; $i++) {
5467 if ($co{'parents'}[$i] eq $hash_parent) {
5468 $formats_nav .= ' parent ' . ($i+1);
5472 $formats_nav .= ': ' .
5473 $cgi->a({-href
=> href
(action
=>"commitdiff",
5474 hash
=>$hash_parent)},
5475 esc_html
($hash_parent_short)) .
5477 } elsif (!$co{'parent'}) {
5479 $formats_nav .= ' (initial)';
5480 } elsif (scalar @
{$co{'parents'}} == 1) {
5481 # single parent commit
5484 $cgi->a({-href
=> href
(action
=>"commitdiff",
5485 hash
=>$co{'parent'})},
5486 esc_html
(substr($co{'parent'}, 0, 7))) .
5490 if ($hash_parent eq '--cc') {
5491 $formats_nav .= ' | ' .
5492 $cgi->a({-href
=> href
(action
=>"commitdiff",
5493 hash
=>$hash, hash_parent
=>'-c')},
5495 } else { # $hash_parent eq '-c'
5496 $formats_nav .= ' | ' .
5497 $cgi->a({-href
=> href
(action
=>"commitdiff",
5498 hash
=>$hash, hash_parent
=>'--cc')},
5504 $cgi->a({-href
=> href
(action
=>"commitdiff",
5506 esc_html
(substr($_, 0, 7)));
5507 } @
{$co{'parents'}} ) .
5512 my $hash_parent_param = $hash_parent;
5513 if (!defined $hash_parent_param) {
5514 # --cc for multiple parents, --root for parentless
5515 $hash_parent_param =
5516 @
{$co{'parents'}} > 1 ?
'--cc' : $co{'parent'} || '--root';
5522 if ($format eq 'html') {
5523 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5524 "--no-commit-id", "--patch-with-raw", "--full-index",
5525 $hash_parent_param, $hash, "--"
5526 or die_error
(500, "Open git-diff-tree failed");
5528 while (my $line = <$fd>) {
5530 # empty line ends raw part of diff-tree output
5532 push @difftree, scalar parse_difftree_raw_line
($line);
5535 } elsif ($format eq 'plain') {
5536 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5537 '-p', $hash_parent_param, $hash, "--"
5538 or die_error
(500, "Open git-diff-tree failed");
5539 } elsif ($format eq 'patch') {
5540 # For commit ranges, we limit the output to the number of
5541 # patches specified in the 'patches' feature.
5542 # For single commits, we limit the output to a single patch,
5543 # diverging from the git-format-patch default.
5544 my @commit_spec = ();
5546 if ($patch_max > 0) {
5547 push @commit_spec, "-$patch_max";
5549 push @commit_spec, '-n', "$hash_parent..$hash";
5551 if ($params{-single
}) {
5552 push @commit_spec, '-1';
5554 if ($patch_max > 0) {
5555 push @commit_spec, "-$patch_max";
5557 push @commit_spec, "-n";
5559 push @commit_spec, '--root', $hash;
5561 open $fd, "-|", git_cmd
(), "format-patch", '--encoding=utf8',
5562 '--stdout', @commit_spec
5563 or die_error
(500, "Open git-format-patch failed");
5565 die_error
(400, "Unknown commitdiff format");
5568 # non-textual hash id's can be cached
5570 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5574 # write commit message
5575 if ($format eq 'html') {
5576 my $refs = git_get_references
();
5577 my $ref = format_ref_marker
($refs, $co{'id'});
5579 git_header_html
(undef, $expires);
5580 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5581 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
5582 git_print_authorship
(\
%co);
5583 print "<div class=\"page_body\">\n";
5584 if (@
{$co{'comment'}} > 1) {
5585 print "<div class=\"log\">\n";
5586 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
5587 print "</div>\n"; # class="log"
5590 } elsif ($format eq 'plain') {
5591 my $refs = git_get_references
("tags");
5592 my $tagname = git_get_rev_name_tags
($hash);
5593 my $filename = basename
($project) . "-$hash.patch";
5596 -type
=> 'text/plain',
5597 -charset
=> 'utf-8',
5598 -expires
=> $expires,
5599 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5600 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5601 print "From: " . to_utf8
($co{'author'}) . "\n";
5602 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5603 print "Subject: " . to_utf8
($co{'title'}) . "\n";
5605 print "X-Git-Tag: $tagname\n" if $tagname;
5606 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5608 foreach my $line (@
{$co{'comment'}}) {
5609 print to_utf8
($line) . "\n";
5612 } elsif ($format eq 'patch') {
5613 my $filename = basename
($project) . "-$hash.patch";
5616 -type
=> 'text/plain',
5617 -charset
=> 'utf-8',
5618 -expires
=> $expires,
5619 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5623 if ($format eq 'html') {
5624 my $use_parents = !defined $hash_parent ||
5625 $hash_parent eq '-c' || $hash_parent eq '--cc';
5626 git_difftree_body
(\
@difftree, $hash,
5627 $use_parents ? @
{$co{'parents'}} : $hash_parent);
5630 git_patchset_body
($fd, \
@difftree, $hash,
5631 $use_parents ? @
{$co{'parents'}} : $hash_parent);
5633 print "</div>\n"; # class="page_body"
5636 } elsif ($format eq 'plain') {
5640 or print "Reading git-diff-tree failed\n";
5641 } elsif ($format eq 'patch') {
5645 or print "Reading git-format-patch failed\n";
5649 sub git_commitdiff_plain
{
5650 git_commitdiff
(-format
=> 'plain');
5653 # format-patch-style patches
5655 git_commitdiff
(-format
=> 'patch', -single
=> 1);
5659 git_commitdiff
(-format
=> 'patch');
5663 if (!defined $hash_base) {
5664 $hash_base = git_get_head_hash
($project);
5666 if (!defined $page) {
5670 my %co = parse_commit
($hash_base)
5671 or die_error
(404, "Unknown commit object");
5673 my $refs = git_get_references
();
5674 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5676 my @commitlist = parse_commits
($hash_base, 101, (100 * $page),
5677 $file_name, "--full-history")
5678 or die_error
(404, "No such file or directory on given branch");
5680 if (!defined $hash && defined $file_name) {
5681 # some commits could have deleted file in question,
5682 # and not have it in tree, but one of them has to have it
5683 for (my $i = 0; $i <= @commitlist; $i++) {
5684 $hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
5685 last if defined $hash;
5688 if (defined $hash) {
5689 $ftype = git_get_type
($hash);
5691 if (!defined $ftype) {
5692 die_error
(500, "Unknown type of object");
5695 my $paging_nav = '';
5698 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5699 file_name
=>$file_name)},
5701 $paging_nav .= " ⋅ " .
5702 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5703 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5705 $paging_nav .= "first";
5706 $paging_nav .= " ⋅ prev";
5709 if ($#commitlist >= 100) {
5711 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5712 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5713 $paging_nav .= " ⋅ $next_link";
5715 $paging_nav .= " ⋅ next";
5719 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5720 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5721 git_print_page_path
($file_name, $ftype, $hash_base);
5723 git_history_body
(\
@commitlist, 0, 99,
5724 $refs, $hash_base, $ftype, $next_link);
5730 gitweb_check_feature
('search') or die_error
(403, "Search is disabled");
5731 if (!defined $searchtext) {
5732 die_error
(400, "Text field is empty");
5734 if (!defined $hash) {
5735 $hash = git_get_head_hash
($project);
5737 my %co = parse_commit
($hash);
5739 die_error
(404, "Unknown commit object");
5741 if (!defined $page) {
5745 $searchtype ||= 'commit';
5746 if ($searchtype eq 'pickaxe') {
5747 # pickaxe may take all resources of your box and run for several minutes
5748 # with every query - so decide by yourself how public you make this feature
5749 gitweb_check_feature
('pickaxe')
5750 or die_error
(403, "Pickaxe is disabled");
5752 if ($searchtype eq 'grep') {
5753 gitweb_check_feature
('grep')
5754 or die_error
(403, "Grep is disabled");
5759 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5761 if ($searchtype eq 'commit') {
5762 $greptype = "--grep=";
5763 } elsif ($searchtype eq 'author') {
5764 $greptype = "--author=";
5765 } elsif ($searchtype eq 'committer') {
5766 $greptype = "--committer=";
5768 $greptype .= $searchtext;
5769 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
5770 $greptype, '--regexp-ignore-case',
5771 $search_use_regexp ?
'--extended-regexp' : '--fixed-strings');
5773 my $paging_nav = '';
5776 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5777 searchtext
=>$searchtext,
5778 searchtype
=>$searchtype)},
5780 $paging_nav .= " ⋅ " .
5781 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5782 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5784 $paging_nav .= "first";
5785 $paging_nav .= " ⋅ prev";
5788 if ($#commitlist >= 100) {
5790 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5791 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5792 $paging_nav .= " ⋅ $next_link";
5794 $paging_nav .= " ⋅ next";
5797 if ($#commitlist >= 100) {
5800 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5801 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5802 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5805 if ($searchtype eq 'pickaxe') {
5806 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5807 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5809 print "<table class=\"pickaxe search\">\n";
5812 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
5813 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
5814 ($search_use_regexp ?
'--pickaxe-regex' : ());
5817 while (my $line = <$fd>) {
5821 my %set = parse_difftree_raw_line
($line);
5822 if (defined $set{'commit'}) {
5823 # finish previous commit
5826 "<td class=\"link\">" .
5827 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5829 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5835 print "<tr class=\"dark\">\n";
5837 print "<tr class=\"light\">\n";
5840 %co = parse_commit
($set{'commit'});
5841 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
5842 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5843 "<td><i>$author</i></td>\n" .
5845 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5846 -class => "list subject"},
5847 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
5848 } elsif (defined $set{'to_id'}) {
5849 next if ($set{'to_id'} =~ m/^0{40}$/);
5851 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5852 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
5854 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5860 # finish last commit (warning: repetition!)
5863 "<td class=\"link\">" .
5864 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5866 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5874 if ($searchtype eq 'grep') {
5875 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5876 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5878 print "<table class=\"grep_search\">\n";
5882 open my $fd, "-|", git_cmd
(), 'grep', '-n',
5883 $search_use_regexp ?
('-E', '-i') : '-F',
5884 $searchtext, $co{'tree'};
5886 while (my $line = <$fd>) {
5888 my ($file, $lno, $ltext, $binary);
5889 last if ($matches++ > 1000);
5890 if ($line =~ /^Binary file (.+) matches$/) {
5894 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5896 if ($file ne $lastfile) {
5897 $lastfile and print "</td></tr>\n";
5899 print "<tr class=\"dark\">\n";
5901 print "<tr class=\"light\">\n";
5903 print "<td class=\"list\">".
5904 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5905 file_name
=>"$file"),
5906 -class => "list"}, esc_path
($file));
5907 print "</td><td>\n";
5911 print "<div class=\"binary\">Binary file</div>\n";
5913 $ltext = untabify
($ltext);
5914 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
5915 $ltext = esc_html
($1, -nbsp
=>1);
5916 $ltext .= '<span class="match">';
5917 $ltext .= esc_html
($2, -nbsp
=>1);
5918 $ltext .= '</span>';
5919 $ltext .= esc_html
($3, -nbsp
=>1);
5921 $ltext = esc_html
($ltext, -nbsp
=>1);
5923 print "<div class=\"pre\">" .
5924 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5925 file_name
=>"$file").'#l'.$lno,
5926 -class => "linenr"}, sprintf('%4i', $lno))
5927 . ' ' . $ltext . "</div>\n";
5931 print "</td></tr>\n";
5932 if ($matches > 1000) {
5933 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5936 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5945 sub git_search_help
{
5947 git_print_page_nav
('','', $hash,$hash,$hash);
5949 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
5950 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
5951 the pattern entered is recognized as the POSIX extended
5952 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
5955 <dt><b>commit</b></dt>
5956 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
5958 my $have_grep = gitweb_check_feature
('grep');
5961 <dt><b>grep</b></dt>
5962 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5963 a different one) are searched for the given pattern. On large trees, this search can take
5964 a while and put some strain on the server, so please use it with some consideration. Note that
5965 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
5966 case-sensitive.</dd>
5970 <dt><b>author</b></dt>
5971 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
5972 <dt><b>committer</b></dt>
5973 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
5975 my $have_pickaxe = gitweb_check_feature
('pickaxe');
5976 if ($have_pickaxe) {
5978 <dt><b>pickaxe</b></dt>
5979 <dd>All commits that caused the string to appear or disappear from any file (changes that
5980 added, removed or "modified" the string) will be listed. This search can take a while and
5981 takes a lot of strain on the server, so please use it wisely. Note that since you may be
5982 interested even in changes just changing the case as well, this search is case sensitive.</dd>
5990 my $head = git_get_head_hash
($project);
5991 if (!defined $hash) {
5994 if (!defined $page) {
5997 my $refs = git_get_references
();
5999 my $commit_hash = $hash;
6000 if (defined $hash_parent) {
6001 $commit_hash = "$hash_parent..$hash";
6003 my @commitlist = parse_commits
($commit_hash, 101, (100 * $page));
6005 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#commitlist >= 100);
6007 if ($#commitlist >= 100) {
6009 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
6010 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
6012 my $patch_max = gitweb_check_feature
('patches');
6014 if ($patch_max < 0 || @commitlist <= $patch_max) {
6015 $paging_nav .= " ⋅ " .
6016 $cgi->a({-href
=> href
(action
=>"patches", -replay
=>1)},
6022 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
6023 git_print_header_div
('summary', $project);
6025 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
6030 ## ......................................................................
6031 ## feeds (RSS, Atom; OPML)
6034 my $format = shift || 'atom';
6035 my $have_blame = gitweb_check_feature
('blame');
6037 # Atom: http://www.atomenabled.org/developers/syndication/
6038 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
6039 if ($format ne 'rss' && $format ne 'atom') {
6040 die_error
(400, "Unknown web feed format");
6043 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
6044 my $head = $hash || 'HEAD';
6045 my @commitlist = parse_commits
($head, 150, 0, $file_name);
6049 my $content_type = "application/$format+xml";
6050 if (defined $cgi->http('HTTP_ACCEPT') &&
6051 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
6052 # browser (feed reader) prefers text/xml
6053 $content_type = 'text/xml';
6055 if (defined($commitlist[0])) {
6056 %latest_commit = %{$commitlist[0]};
6057 my $latest_epoch = $latest_commit{'committer_epoch'};
6058 %latest_date = parse_date
($latest_epoch);
6059 my $if_modified = $cgi->http('IF_MODIFIED_SINCE');
6060 if (defined $if_modified) {
6062 if (eval { require HTTP
::Date
; 1; }) {
6063 $since = HTTP
::Date
::str2time
($if_modified);
6064 } elsif (eval { require Time
::ParseDate
; 1; }) {
6065 $since = Time
::ParseDate
::parsedate
($if_modified, GMT
=> 1);
6067 if (defined $since && $latest_epoch <= $since) {
6069 -type
=> $content_type,
6070 -charset
=> 'utf-8',
6071 -last_modified
=> $latest_date{'rfc2822'},
6072 -status
=> '304 Not Modified');
6077 -type
=> $content_type,
6078 -charset
=> 'utf-8',
6079 -last_modified
=> $latest_date{'rfc2822'});
6082 -type
=> $content_type,
6083 -charset
=> 'utf-8');
6086 # Optimization: skip generating the body if client asks only
6087 # for Last-Modified date.
6088 return if ($cgi->request_method() eq 'HEAD');
6091 my $title = "$site_name - $project/$action";
6092 my $feed_type = 'log';
6093 if (defined $hash) {
6094 $title .= " - '$hash'";
6095 $feed_type = 'branch log';
6096 if (defined $file_name) {
6097 $title .= " :: $file_name";
6098 $feed_type = 'history';
6100 } elsif (defined $file_name) {
6101 $title .= " - $file_name";
6102 $feed_type = 'history';
6104 $title .= " $feed_type";
6105 my $descr = git_get_project_description
($project);
6106 if (defined $descr) {
6107 $descr = esc_html
($descr);
6109 $descr = "$project " .
6110 ($format eq 'rss' ?
'RSS' : 'Atom') .
6113 my $owner = git_get_project_owner
($project);
6114 $owner = esc_html
($owner);
6118 if (defined $file_name) {
6119 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
6120 } elsif (defined $hash) {
6121 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
6123 $alt_url = href
(-full
=>1, action
=>"summary");
6125 print qq!<?xml version
="1.0" encoding
="utf-8"?
>\n!;
6126 if ($format eq 'rss') {
6128 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
6131 print "<title>$title</title>\n" .
6132 "<link>$alt_url</link>\n" .
6133 "<description>$descr</description>\n" .
6134 "<language>en</language>\n" .
6135 # project owner is responsible for 'editorial' content
6136 "<managingEditor>$owner</managingEditor>\n";
6137 if (defined $logo || defined $favicon) {
6138 # prefer the logo to the favicon, since RSS
6139 # doesn't allow both
6140 my $img = esc_url
($logo || $favicon);
6142 "<url>$img</url>\n" .
6143 "<title>$title</title>\n" .
6144 "<link>$alt_url</link>\n" .
6148 print "<pubDate>$latest_date{'rfc2822'}</pubDate>\n";
6149 print "<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";
6151 print "<generator>gitweb v.$version/$git_version</generator>\n";
6152 } elsif ($format eq 'atom') {
6154 <feed xmlns="http://www.w3.org/2005/Atom">
6156 print "<title>$title</title>\n" .
6157 "<subtitle>$descr</subtitle>\n" .
6158 '<link rel="alternate" type="text/html" href="' .
6159 $alt_url . '" />' . "\n" .
6160 '<link rel="self" type="' . $content_type . '" href="' .
6161 $cgi->self_url() . '" />' . "\n" .
6162 "<id>" . href
(-full
=>1) . "</id>\n" .
6163 # use project owner for feed author
6164 "<author><name>$owner</name></author>\n";
6165 if (defined $favicon) {
6166 print "<icon>" . esc_url
($favicon) . "</icon>\n";
6168 if (defined $logo_url) {
6169 # not twice as wide as tall: 72 x 27 pixels
6170 print "<logo>" . esc_url
($logo) . "</logo>\n";
6172 if (! %latest_date) {
6173 # dummy date to keep the feed valid until commits trickle in:
6174 print "<updated>1970-01-01T00:00:00Z</updated>\n";
6176 print "<updated>$latest_date{'iso-8601'}</updated>\n";
6178 print "<generator version='$version/$git_version'>gitweb</generator>\n";
6182 for (my $i = 0; $i <= $#commitlist; $i++) {
6183 my %co = %{$commitlist[$i]};
6184 my $commit = $co{'id'};
6185 # we read 150, we always show 30 and the ones more recent than 48 hours
6186 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
6189 my %cd = parse_date
($co{'author_epoch'});
6191 # get list of changed files
6192 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6193 $co{'parent'} || "--root",
6194 $co{'id'}, "--", (defined $file_name ?
$file_name : ())
6196 my @difftree = map { chomp; $_ } <$fd>;
6200 # print element (entry, item)
6201 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
6202 if ($format eq 'rss') {
6204 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
6205 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
6206 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
6207 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
6208 "<link>$co_url</link>\n" .
6209 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
6210 "<content:encoded>" .
6212 } elsif ($format eq 'atom') {
6214 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
6215 "<updated>$cd{'iso-8601'}</updated>\n" .
6217 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
6218 if ($co{'author_email'}) {
6219 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
6221 print "</author>\n" .
6222 # use committer for contributor
6224 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
6225 if ($co{'committer_email'}) {
6226 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
6228 print "</contributor>\n" .
6229 "<published>$cd{'iso-8601'}</published>\n" .
6230 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
6231 "<id>$co_url</id>\n" .
6232 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
6233 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
6235 my $comment = $co{'comment'};
6237 foreach my $line (@
$comment) {
6238 $line = esc_html
($line);
6241 print "</pre><ul>\n";
6242 foreach my $difftree_line (@difftree) {
6243 my %difftree = parse_difftree_raw_line
($difftree_line);
6244 next if !$difftree{'from_id'};
6246 my $file = $difftree{'file'} || $difftree{'to_file'};
6250 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
6251 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
6252 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
6253 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
6254 -title
=> "diff"}, 'D');
6256 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
6257 file_name
=>$file, hash_base
=>$commit),
6258 -title
=> "blame"}, 'B');
6260 # if this is not a feed of a file history
6261 if (!defined $file_name || $file_name ne $file) {
6262 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
6263 file_name
=>$file, hash
=>$commit),
6264 -title
=> "history"}, 'H');
6266 $file = esc_path
($file);
6270 if ($format eq 'rss') {
6271 print "</ul>]]>\n" .
6272 "</content:encoded>\n" .
6274 } elsif ($format eq 'atom') {
6275 print "</ul>\n</div>\n" .
6282 if ($format eq 'rss') {
6283 print "</channel>\n</rss>\n";
6284 } elsif ($format eq 'atom') {
6298 my @list = git_get_projects_list
();
6301 -type
=> 'text/xml',
6302 -charset
=> 'utf-8',
6303 -content_disposition
=> 'inline; filename="opml.xml"');
6306 <?xml version="1.0" encoding="utf-8"?>
6307 <opml version="1.0">
6309 <title>$site_name OPML Export</title>
6312 <outline text="git RSS feeds">
6315 foreach my $pr (@list) {
6317 my $head = git_get_head_hash
($proj{'path'});
6318 if (!defined $head) {
6321 $git_dir = "$projectroot/$proj{'path'}";
6322 my %co = parse_commit
($head);
6327 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
6328 my $rss = href
('project' => $proj{'path'}, 'action' => 'rss', -full
=> 1);
6329 my $html = href
('project' => $proj{'path'}, 'action' => 'summary', -full
=> 1);
6330 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";