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 if (eval { require Time
::HiRes
; 1; }) {
23 $t0 = [Time
::HiRes
::gettimeofday
()];
25 our $number_of_git_cmds = 0;
28 CGI-
>compile() if $ENV{'MOD_PERL'};
32 our $version = "++GIT_VERSION++";
33 our $my_url = $cgi->url();
34 our $my_uri = $cgi->url(-absolute
=> 1);
36 # Base URL for relative URLs in gitweb ($logo, $favicon, ...),
37 # needed and used only for URLs with nonempty PATH_INFO
38 our $base_url = $my_url;
40 # When the script is used as DirectoryIndex, the URL does not contain the name
41 # of the script file itself, and $cgi->url() fails to strip PATH_INFO, so we
42 # have to do it ourselves. We make $path_info global because it's also used
45 # Another issue with the script being the DirectoryIndex is that the resulting
46 # $my_url data is not the full script URL: this is good, because we want
47 # generated links to keep implying the script name if it wasn't explicitly
48 # indicated in the URL we're handling, but it means that $my_url cannot be used
50 # Therefore, if we needed to strip PATH_INFO, then we know that we have
51 # to build the base URL ourselves:
52 our $path_info = $ENV{"PATH_INFO"};
54 if ($my_url =~ s
,\Q
$path_info\E
$,, &&
55 $my_uri =~ s
,\Q
$path_info\E
$,, &&
56 defined $ENV{'SCRIPT_NAME'}) {
57 $base_url = $cgi->url(-base
=> 1) . $ENV{'SCRIPT_NAME'};
61 # core git executable to use
62 # this can just be "git" if your webserver has a sensible PATH
63 our $GIT = "++GIT_BINDIR++/git";
65 # absolute fs-path which will be prepended to the project path
66 #our $projectroot = "/pub/scm";
67 our $projectroot = "++GITWEB_PROJECTROOT++";
69 # fs traversing limit for getting project list
70 # the number is relative to the projectroot
71 our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
73 # target of the home link on top of all pages
74 our $home_link = $my_uri || "/";
76 # string of the home link on top of all pages
77 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
79 # name of your site or organization to appear in page titles
80 # replace this with something more descriptive for clearer bookmarks
81 our $site_name = "++GITWEB_SITENAME++"
82 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
84 # filename of html text to include at top of each page
85 our $site_header = "++GITWEB_SITE_HEADER++";
86 # html text to include at home page
87 our $home_text = "++GITWEB_HOMETEXT++";
88 # filename of html text to include at bottom of each page
89 our $site_footer = "++GITWEB_SITE_FOOTER++";
92 our @stylesheets = ("++GITWEB_CSS++");
93 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
94 our $stylesheet = undef;
96 # URI of GIT logo (72x27 size)
97 our $logo = "++GITWEB_LOGO++";
98 # URI of GIT favicon, assumed to be image/png type
99 our $favicon = "++GITWEB_FAVICON++";
100 # URI of gitweb.js (JavaScript code for gitweb)
101 our $javascript = "++GITWEB_JS++";
103 # URI and label (title) of GIT logo link
104 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
105 #our $logo_label = "git documentation";
106 our $logo_url = "http://git-scm.com/";
107 our $logo_label = "git homepage";
109 # source of projects list
110 our $projects_list = "++GITWEB_LIST++";
112 # the width (in characters) of the projects list "Description" column
113 our $projects_list_description_width = 25;
115 # default order of projects list
116 # valid values are none, project, descr, owner, and age
117 our $default_projects_order = "project";
119 # show repository only if this file exists
120 # (only effective if this variable evaluates to true)
121 our $export_ok = "++GITWEB_EXPORT_OK++";
123 # show repository only if this subroutine returns true
124 # when given the path to the project, for example:
125 # sub { return -e "$_[0]/git-daemon-export-ok"; }
126 our $export_auth_hook = undef;
128 # only allow viewing of repositories also shown on the overview page
129 our $strict_export = "++GITWEB_STRICT_EXPORT++";
131 # list of git base URLs used for URL to where fetch project from,
132 # i.e. full URL is "$git_base_url/$project"
133 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
135 # default blob_plain mimetype and default charset for text/plain blob
136 our $default_blob_plain_mimetype = 'text/plain';
137 our $default_text_plain_charset = undef;
139 # file to use for guessing MIME types before trying /etc/mime.types
140 # (relative to the current git repository)
141 our $mimetypes_file = undef;
143 # assume this charset if line contains non-UTF-8 characters;
144 # it should be valid encoding (see Encoding::Supported(3pm) for list),
145 # for which encoding all byte sequences are valid, for example
146 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
147 # could be even 'utf-8' for the old behavior)
148 our $fallback_encoding = 'latin1';
150 # rename detection options for git-diff and git-diff-tree
151 # - default is '-M', with the cost proportional to
152 # (number of removed files) * (number of new files).
153 # - more costly is '-C' (which implies '-M'), with the cost proportional to
154 # (number of changed files + number of removed files) * (number of new files)
155 # - even more costly is '-C', '--find-copies-harder' with cost
156 # (number of files in the original tree) * (number of new files)
157 # - one might want to include '-B' option, e.g. '-B', '-M'
158 our @diff_opts = ('-M'); # taken from git_commit
160 # Disables features that would allow repository owners to inject script into
162 our $prevent_xss = 0;
164 # information about snapshot formats that gitweb is capable of serving
165 our %known_snapshot_formats = (
167 # 'display' => display name,
168 # 'type' => mime type,
169 # 'suffix' => filename suffix,
170 # 'format' => --format for git-archive,
171 # 'compressor' => [compressor command and arguments]
172 # (array reference, optional)
173 # 'disabled' => boolean (optional)}
176 'display' => 'tar.gz',
177 'type' => 'application/x-gzip',
178 'suffix' => '.tar.gz',
180 'compressor' => ['gzip']},
183 'display' => 'tar.bz2',
184 'type' => 'application/x-bzip2',
185 'suffix' => '.tar.bz2',
187 'compressor' => ['bzip2']},
190 'display' => 'tar.xz',
191 'type' => 'application/x-xz',
192 'suffix' => '.tar.xz',
194 'compressor' => ['xz'],
199 'type' => 'application/x-zip',
204 # Aliases so we understand old gitweb.snapshot values in repository
206 our %known_snapshot_format_aliases = (
211 # backward compatibility: legacy gitweb config support
212 'x-gzip' => undef, 'gz' => undef,
213 'x-bzip2' => undef, 'bz2' => undef,
214 'x-zip' => undef, '' => undef,
217 # Pixel sizes for icons and avatars. If the default font sizes or lineheights
218 # are changed, it may be appropriate to change these values too via
225 # You define site-wide feature defaults here; override them with
226 # $GITWEB_CONFIG as necessary.
229 # 'sub' => feature-sub (subroutine),
230 # 'override' => allow-override (boolean),
231 # 'default' => [ default options...] (array reference)}
233 # if feature is overridable (it means that allow-override has true value),
234 # then feature-sub will be called with default options as parameters;
235 # return value of feature-sub indicates if to enable specified feature
237 # if there is no 'sub' key (no feature-sub), then feature cannot be
240 # use gitweb_get_feature(<feature>) to retrieve the <feature> value
241 # (an array) or gitweb_check_feature(<feature>) to check if <feature>
244 # Enable the 'blame' blob view, showing the last commit that modified
245 # each line in the file. This can be very CPU-intensive.
247 # To enable system wide have in $GITWEB_CONFIG
248 # $feature{'blame'}{'default'} = [1];
249 # To have project specific config enable override in $GITWEB_CONFIG
250 # $feature{'blame'}{'override'} = 1;
251 # and in project config gitweb.blame = 0|1;
253 'sub' => sub { feature_bool
('blame', @_) },
257 # Enable the 'snapshot' link, providing a compressed archive of any
258 # tree. This can potentially generate high traffic if you have large
261 # Value is a list of formats defined in %known_snapshot_formats that
263 # To disable system wide have in $GITWEB_CONFIG
264 # $feature{'snapshot'}{'default'} = [];
265 # To have project specific config enable override in $GITWEB_CONFIG
266 # $feature{'snapshot'}{'override'} = 1;
267 # and in project config, a comma-separated list of formats or "none"
268 # to disable. Example: gitweb.snapshot = tbz2,zip;
270 'sub' => \
&feature_snapshot
,
272 'default' => ['tgz']},
274 # Enable text search, which will list the commits which match author,
275 # committer or commit text to a given string. Enabled by default.
276 # Project specific override is not supported.
281 # Enable grep search, which will list the files in currently selected
282 # tree containing the given string. Enabled by default. This can be
283 # potentially CPU-intensive, of course.
285 # To enable system wide have in $GITWEB_CONFIG
286 # $feature{'grep'}{'default'} = [1];
287 # To have project specific config enable override in $GITWEB_CONFIG
288 # $feature{'grep'}{'override'} = 1;
289 # and in project config gitweb.grep = 0|1;
291 'sub' => sub { feature_bool
('grep', @_) },
295 # Enable the pickaxe search, which will list the commits that modified
296 # a given string in a file. This can be practical and quite faster
297 # alternative to 'blame', but still potentially CPU-intensive.
299 # To enable system wide have in $GITWEB_CONFIG
300 # $feature{'pickaxe'}{'default'} = [1];
301 # To have project specific config enable override in $GITWEB_CONFIG
302 # $feature{'pickaxe'}{'override'} = 1;
303 # and in project config gitweb.pickaxe = 0|1;
305 'sub' => sub { feature_bool
('pickaxe', @_) },
309 # Make gitweb use an alternative format of the URLs which can be
310 # more readable and natural-looking: project name is embedded
311 # directly in the path and the query string contains other
312 # auxiliary information. All gitweb installations recognize
313 # URL in either format; this configures in which formats gitweb
316 # To enable system wide have in $GITWEB_CONFIG
317 # $feature{'pathinfo'}{'default'} = [1];
318 # Project specific override is not supported.
320 # Note that you will need to change the default location of CSS,
321 # favicon, logo and possibly other files to an absolute URL. Also,
322 # if gitweb.cgi serves as your indexfile, you will need to force
323 # $my_uri to contain the script name in your $GITWEB_CONFIG.
328 # Make gitweb consider projects in project root subdirectories
329 # to be forks of existing projects. Given project $projname.git,
330 # projects matching $projname/*.git will not be shown in the main
331 # projects list, instead a '+' mark will be added to $projname
332 # there and a 'forks' view will be enabled for the project, listing
333 # all the forks. If project list is taken from a file, forks have
334 # to be listed after the main project.
336 # To enable system wide have in $GITWEB_CONFIG
337 # $feature{'forks'}{'default'} = [1];
338 # Project specific override is not supported.
343 # Insert custom links to the action bar of all project pages.
344 # This enables you mainly to link to third-party scripts integrating
345 # into gitweb; e.g. git-browser for graphical history representation
346 # or custom web-based repository administration interface.
348 # The 'default' value consists of a list of triplets in the form
349 # (label, link, position) where position is the label after which
350 # to insert the link and link is a format string where %n expands
351 # to the project name, %f to the project path within the filesystem,
352 # %h to the current hash (h gitweb parameter) and %b to the current
353 # hash base (hb gitweb parameter); %% expands to %.
355 # To enable system wide have in $GITWEB_CONFIG e.g.
356 # $feature{'actions'}{'default'} = [('graphiclog',
357 # '/git-browser/by-commit.html?r=%n', 'summary')];
358 # Project specific override is not supported.
363 # Allow gitweb scan project content tags described in ctags/
364 # of project repository, and display the popular Web 2.0-ish
365 # "tag cloud" near the project list. Note that this is something
366 # COMPLETELY different from the normal Git tags.
368 # gitweb by itself can show existing tags, but it does not handle
369 # tagging itself; you need an external application for that.
370 # For an example script, check Girocco's cgi/tagproj.cgi.
371 # You may want to install the HTML::TagCloud Perl module to get
372 # a pretty tag cloud instead of just a list of tags.
374 # To enable system wide have in $GITWEB_CONFIG
375 # $feature{'ctags'}{'default'} = ['path_to_tag_script'];
376 # Project specific override is not supported.
381 # The maximum number of patches in a patchset generated in patch
382 # view. Set this to 0 or undef to disable patch view, or to a
383 # negative number to remove any limit.
385 # To disable system wide have in $GITWEB_CONFIG
386 # $feature{'patches'}{'default'} = [0];
387 # To have project specific config enable override in $GITWEB_CONFIG
388 # $feature{'patches'}{'override'} = 1;
389 # and in project config gitweb.patches = 0|n;
390 # where n is the maximum number of patches allowed in a patchset.
392 'sub' => \
&feature_patches
,
396 # Avatar support. When this feature is enabled, views such as
397 # shortlog or commit will display an avatar associated with
398 # the email of the committer(s) and/or author(s).
400 # Currently available providers are gravatar and picon.
401 # If an unknown provider is specified, the feature is disabled.
403 # Gravatar depends on Digest::MD5.
404 # Picon currently relies on the indiana.edu database.
406 # To enable system wide have in $GITWEB_CONFIG
407 # $feature{'avatar'}{'default'} = ['<provider>'];
408 # where <provider> is either gravatar or picon.
409 # To have project specific config enable override in $GITWEB_CONFIG
410 # $feature{'avatar'}{'override'} = 1;
411 # and in project config gitweb.avatar = <provider>;
413 'sub' => \
&feature_avatar
,
417 # Enable displaying how much time and how many git commands
418 # it took to generate and display page. Disabled by default.
419 # Project specific override is not supported.
425 sub gitweb_get_feature
{
427 return unless exists $feature{$name};
428 my ($sub, $override, @defaults) = (
429 $feature{$name}{'sub'},
430 $feature{$name}{'override'},
431 @{$feature{$name}{'default'}});
432 if (!$override) { return @defaults; }
434 warn "feature $name is not overridable";
437 return $sub->(@defaults);
440 # A wrapper to check if a given feature is enabled.
441 # With this, you can say
443 # my $bool_feat = gitweb_check_feature('bool_feat');
444 # gitweb_check_feature('bool_feat') or somecode;
448 # my ($bool_feat) = gitweb_get_feature('bool_feat');
449 # (gitweb_get_feature('bool_feat'))[0] or somecode;
451 sub gitweb_check_feature
{
452 return (gitweb_get_feature
(@_))[0];
458 my ($val) = git_get_project_config
($key, '--bool');
462 } elsif ($val eq 'true') {
464 } elsif ($val eq 'false') {
469 sub feature_snapshot
{
472 my ($val) = git_get_project_config
('snapshot');
475 @fmts = ($val eq 'none' ? () : split /\s*[,\s]\s*/, $val);
481 sub feature_patches
{
482 my @val = (git_get_project_config
('patches', '--int'));
492 my @val = (git_get_project_config
('avatar'));
494 return @val ? @val : @_;
497 # checking HEAD file with -e is fragile if the repository was
498 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
500 sub check_head_link
{
502 my $headfile = "$dir/HEAD";
503 return ((-e
$headfile) ||
504 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
507 sub check_export_ok
{
509 return (check_head_link
($dir) &&
510 (!$export_ok || -e
"$dir/$export_ok") &&
511 (!$export_auth_hook || $export_auth_hook->($dir)));
514 # process alternate names for backward compatibility
515 # filter out unsupported (unknown) snapshot formats
516 sub filter_snapshot_fmts
{
520 exists $known_snapshot_format_aliases{$_} ?
521 $known_snapshot_format_aliases{$_} : $_} @fmts;
523 exists $known_snapshot_formats{$_} &&
524 !$known_snapshot_formats{$_}{'disabled'}} @fmts;
527 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
528 if (-e
$GITWEB_CONFIG) {
531 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
532 do $GITWEB_CONFIG_SYSTEM if -e
$GITWEB_CONFIG_SYSTEM;
535 # version of the core git binary
536 our $git_version = qx("$GIT" --version) =~ m/git version (.*)$/ ? $1 : "unknown";
537 $number_of_git_cmds++;
539 $projects_list ||= $projectroot;
541 # ======================================================================
542 # input validation and dispatch
544 # input parameters can be collected from a variety of sources (presently, CGI
545 # and PATH_INFO), so we define an %input_params hash that collects them all
546 # together during validation: this allows subsequent uses (e.g. href()) to be
547 # agnostic of the parameter origin
549 our %input_params = ();
551 # input parameters are stored with the long parameter name as key. This will
552 # also be used in the href subroutine to convert parameters to their CGI
553 # equivalent, and since the href() usage is the most frequent one, we store
554 # the name -> CGI key mapping here, instead of the reverse.
556 # XXX: Warning: If you touch this, check the search form for updating,
559 our @cgi_param_mapping = (
567 hash_parent_base
=> "hpb",
572 snapshot_format
=> "sf",
573 extra_options
=> "opt",
574 search_use_regexp
=> "sr",
575 # this must be last entry (for manipulation from JavaScript)
578 our %cgi_param_mapping = @cgi_param_mapping;
580 # we will also need to know the possible actions, for validation
582 "blame" => \
&git_blame
,
583 "blame_incremental" => \
&git_blame_incremental
,
584 "blame_data" => \
&git_blame_data
,
585 "blobdiff" => \
&git_blobdiff
,
586 "blobdiff_plain" => \
&git_blobdiff_plain
,
587 "blob" => \
&git_blob
,
588 "blob_plain" => \
&git_blob_plain
,
589 "commitdiff" => \
&git_commitdiff
,
590 "commitdiff_plain" => \
&git_commitdiff_plain
,
591 "commit" => \
&git_commit
,
592 "forks" => \
&git_forks
,
593 "heads" => \
&git_heads
,
594 "history" => \
&git_history
,
596 "patch" => \
&git_patch
,
597 "patches" => \
&git_patches
,
599 "atom" => \
&git_atom
,
600 "search" => \
&git_search
,
601 "search_help" => \
&git_search_help
,
602 "shortlog" => \
&git_shortlog
,
603 "summary" => \
&git_summary
,
605 "tags" => \
&git_tags
,
606 "tree" => \
&git_tree
,
607 "snapshot" => \
&git_snapshot
,
608 "object" => \
&git_object
,
609 # those below don't need $project
610 "opml" => \
&git_opml
,
611 "project_list" => \
&git_project_list
,
612 "project_index" => \
&git_project_index
,
615 # finally, we have the hash of allowed extra_options for the commands that
617 our %allowed_options = (
618 "--no-merges" => [ qw(rss atom log shortlog history) ],
621 # fill %input_params with the CGI parameters. All values except for 'opt'
622 # should be single values, but opt can be an array. We should probably
623 # build an array of parameters that can be multi-valued, but since for the time
624 # being it's only this one, we just single it out
625 while (my ($name, $symbol) = each %cgi_param_mapping) {
626 if ($symbol eq 'opt') {
627 $input_params{$name} = [ $cgi->param($symbol) ];
629 $input_params{$name} = $cgi->param($symbol);
633 # now read PATH_INFO and update the parameter list for missing parameters
634 sub evaluate_path_info
{
635 return if defined $input_params{'project'};
636 return if !$path_info;
637 $path_info =~ s
,^/+,,;
638 return if !$path_info;
640 # find which part of PATH_INFO is project
641 my $project = $path_info;
643 while ($project && !check_head_link
("$projectroot/$project")) {
644 $project =~ s
,/*[^/]*$,,;
646 return unless $project;
647 $input_params{'project'} = $project;
649 # do not change any parameters if an action is given using the query string
650 return if $input_params{'action'};
651 $path_info =~ s
,^\Q
$project\E
/*,,;
653 # next, check if we have an action
654 my $action = $path_info;
656 if (exists $actions{$action}) {
657 $path_info =~ s
,^$action/*,,;
658 $input_params{'action'} = $action;
661 # list of actions that want hash_base instead of hash, but can have no
662 # pathname (f) parameter
669 # [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name]
670 my ($parentrefname, $parentpathname, $refname, $pathname) =
671 ($path_info =~ /^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/);
673 # first, analyze the 'current' part
674 if (defined $pathname) {
675 # we got "branch:filename" or "branch:dir/"
676 # we could use git_get_type(branch:pathname), but:
677 # - it needs $git_dir
678 # - it does a git() call
679 # - the convention of terminating directories with a slash
680 # makes it superfluous
681 # - embedding the action in the PATH_INFO would make it even
683 $pathname =~ s
,^/+,,;
684 if (!$pathname || substr($pathname, -1) eq "/") {
685 $input_params{'action'} ||= "tree";
688 # the default action depends on whether we had parent info
690 if ($parentrefname) {
691 $input_params{'action'} ||= "blobdiff_plain";
693 $input_params{'action'} ||= "blob_plain";
696 $input_params{'hash_base'} ||= $refname;
697 $input_params{'file_name'} ||= $pathname;
698 } elsif (defined $refname) {
699 # we got "branch". In this case we have to choose if we have to
700 # set hash or hash_base.
702 # Most of the actions without a pathname only want hash to be
703 # set, except for the ones specified in @wants_base that want
704 # hash_base instead. It should also be noted that hand-crafted
705 # links having 'history' as an action and no pathname or hash
706 # set will fail, but that happens regardless of PATH_INFO.
707 $input_params{'action'} ||= "shortlog";
708 if (grep { $_ eq $input_params{'action'} } @wants_base) {
709 $input_params{'hash_base'} ||= $refname;
711 $input_params{'hash'} ||= $refname;
715 # next, handle the 'parent' part, if present
716 if (defined $parentrefname) {
717 # a missing pathspec defaults to the 'current' filename, allowing e.g.
718 # someproject/blobdiff/oldrev..newrev:/filename
719 if ($parentpathname) {
720 $parentpathname =~ s
,^/+,,;
721 $parentpathname =~ s
,/$,,;
722 $input_params{'file_parent'} ||= $parentpathname;
724 $input_params{'file_parent'} ||= $input_params{'file_name'};
726 # we assume that hash_parent_base is wanted if a path was specified,
727 # or if the action wants hash_base instead of hash
728 if (defined $input_params{'file_parent'} ||
729 grep { $_ eq $input_params{'action'} } @wants_base) {
730 $input_params{'hash_parent_base'} ||= $parentrefname;
732 $input_params{'hash_parent'} ||= $parentrefname;
736 # for the snapshot action, we allow URLs in the form
737 # $project/snapshot/$hash.ext
738 # where .ext determines the snapshot and gets removed from the
739 # passed $refname to provide the $hash.
741 # To be able to tell that $refname includes the format extension, we
742 # require the following two conditions to be satisfied:
743 # - the hash input parameter MUST have been set from the $refname part
744 # of the URL (i.e. they must be equal)
745 # - the snapshot format MUST NOT have been defined already (e.g. from
747 # It's also useless to try any matching unless $refname has a dot,
748 # so we check for that too
749 if (defined $input_params{'action'} &&
750 $input_params{'action'} eq 'snapshot' &&
751 defined $refname && index($refname, '.') != -1 &&
752 $refname eq $input_params{'hash'} &&
753 !defined $input_params{'snapshot_format'}) {
754 # We loop over the known snapshot formats, checking for
755 # extensions. Allowed extensions are both the defined suffix
756 # (which includes the initial dot already) and the snapshot
757 # format key itself, with a prepended dot
758 while (my ($fmt, $opt) = each %known_snapshot_formats) {
760 unless ($hash =~ s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) {
764 # a valid suffix was found, so set the snapshot format
765 # and reset the hash parameter
766 $input_params{'snapshot_format'} = $fmt;
767 $input_params{'hash'} = $hash;
768 # we also set the format suffix to the one requested
769 # in the URL: this way a request for e.g. .tgz returns
770 # a .tgz instead of a .tar.gz
771 $known_snapshot_formats{$fmt}{'suffix'} = $sfx;
776 evaluate_path_info
();
778 our $action = $input_params{'action'};
779 if (defined $action) {
780 if (!validate_action
($action)) {
781 die_error
(400, "Invalid action parameter");
785 # parameters which are pathnames
786 our $project = $input_params{'project'};
787 if (defined $project) {
788 if (!validate_project
($project)) {
790 die_error
(404, "No such project");
794 our $file_name = $input_params{'file_name'};
795 if (defined $file_name) {
796 if (!validate_pathname
($file_name)) {
797 die_error
(400, "Invalid file parameter");
801 our $file_parent = $input_params{'file_parent'};
802 if (defined $file_parent) {
803 if (!validate_pathname
($file_parent)) {
804 die_error
(400, "Invalid file parent parameter");
808 # parameters which are refnames
809 our $hash = $input_params{'hash'};
811 if (!validate_refname
($hash)) {
812 die_error
(400, "Invalid hash parameter");
816 our $hash_parent = $input_params{'hash_parent'};
817 if (defined $hash_parent) {
818 if (!validate_refname
($hash_parent)) {
819 die_error
(400, "Invalid hash parent parameter");
823 our $hash_base = $input_params{'hash_base'};
824 if (defined $hash_base) {
825 if (!validate_refname
($hash_base)) {
826 die_error
(400, "Invalid hash base parameter");
830 our @extra_options = @{$input_params{'extra_options'}};
831 # @extra_options is always defined, since it can only be (currently) set from
832 # CGI, and $cgi->param() returns the empty array in array context if the param
834 foreach my $opt (@extra_options) {
835 if (not exists $allowed_options{$opt}) {
836 die_error
(400, "Invalid option parameter");
838 if (not grep(/^$action$/, @{$allowed_options{$opt}})) {
839 die_error
(400, "Invalid option parameter for this action");
843 our $hash_parent_base = $input_params{'hash_parent_base'};
844 if (defined $hash_parent_base) {
845 if (!validate_refname
($hash_parent_base)) {
846 die_error
(400, "Invalid hash parent base parameter");
851 our $page = $input_params{'page'};
853 if ($page =~ m/[^0-9]/) {
854 die_error
(400, "Invalid page parameter");
858 our $searchtype = $input_params{'searchtype'};
859 if (defined $searchtype) {
860 if ($searchtype =~ m/[^a-z]/) {
861 die_error
(400, "Invalid searchtype parameter");
865 our $search_use_regexp = $input_params{'search_use_regexp'};
867 our $searchtext = $input_params{'searchtext'};
869 if (defined $searchtext) {
870 if (length($searchtext) < 2) {
871 die_error
(403, "At least two characters are required for search parameter");
873 $search_regexp = $search_use_regexp ? $searchtext : quotemeta $searchtext;
876 # path to the current git repository
878 $git_dir = "$projectroot/$project" if $project;
880 # list of supported snapshot formats
881 our @snapshot_fmts = gitweb_get_feature
('snapshot');
882 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
884 # check that the avatar feature is set to a known provider name,
885 # and for each provider check if the dependencies are satisfied.
886 # if the provider name is invalid or the dependencies are not met,
887 # reset $git_avatar to the empty string.
888 our ($git_avatar) = gitweb_get_feature
('avatar');
889 if ($git_avatar eq 'gravatar') {
890 $git_avatar = '' unless (eval { require Digest
::MD5
; 1; });
891 } elsif ($git_avatar eq 'picon') {
898 if (!defined $action) {
900 $action = git_get_type
($hash);
901 } elsif (defined $hash_base && defined $file_name) {
902 $action = git_get_type
("$hash_base:$file_name");
903 } elsif (defined $project) {
906 $action = 'project_list';
909 if (!defined($actions{$action})) {
910 die_error
(400, "Unknown action");
912 if ($action !~ m/^(?:opml|project_list|project_index)$/ &&
914 die_error
(400, "Project needed");
916 $actions{$action}->();
919 ## ======================================================================
924 # default is to use -absolute url() i.e. $my_uri
925 my $href = $params{-full
} ? $my_url : $my_uri;
927 $params{'project'} = $project unless exists $params{'project'};
929 if ($params{-replay
}) {
930 while (my ($name, $symbol) = each %cgi_param_mapping) {
931 if (!exists $params{$name}) {
932 $params{$name} = $input_params{$name};
937 my $use_pathinfo = gitweb_check_feature
('pathinfo');
938 if ($use_pathinfo and defined $params{'project'}) {
939 # try to put as many parameters as possible in PATH_INFO:
942 # - hash_parent or hash_parent_base:/file_parent
943 # - hash or hash_base:/filename
944 # - the snapshot_format as an appropriate suffix
946 # When the script is the root DirectoryIndex for the domain,
947 # $href here would be something like http://gitweb.example.com/
948 # Thus, we strip any trailing / from $href, to spare us double
949 # slashes in the final URL
952 # Then add the project name, if present
953 $href .= "/".esc_url
($params{'project'});
954 delete $params{'project'};
956 # since we destructively absorb parameters, we keep this
957 # boolean that remembers if we're handling a snapshot
958 my $is_snapshot = $params{'action'} eq 'snapshot';
960 # Summary just uses the project path URL, any other action is
962 if (defined $params{'action'}) {
963 $href .= "/".esc_url
($params{'action'}) unless $params{'action'} eq 'summary';
964 delete $params{'action'};
967 # Next, we put hash_parent_base:/file_parent..hash_base:/file_name,
968 # stripping nonexistent or useless pieces
969 $href .= "/" if ($params{'hash_base'} || $params{'hash_parent_base'}
970 || $params{'hash_parent'} || $params{'hash'});
971 if (defined $params{'hash_base'}) {
972 if (defined $params{'hash_parent_base'}) {
973 $href .= esc_url
($params{'hash_parent_base'});
974 # skip the file_parent if it's the same as the file_name
975 if (defined $params{'file_parent'}) {
976 if (defined $params{'file_name'} && $params{'file_parent'} eq $params{'file_name'}) {
977 delete $params{'file_parent'};
978 } elsif ($params{'file_parent'} !~ /\.\./) {
979 $href .= ":/".esc_url
($params{'file_parent'});
980 delete $params{'file_parent'};
984 delete $params{'hash_parent'};
985 delete $params{'hash_parent_base'};
986 } elsif (defined $params{'hash_parent'}) {
987 $href .= esc_url
($params{'hash_parent'}). "..";
988 delete $params{'hash_parent'};
991 $href .= esc_url
($params{'hash_base'});
992 if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) {
993 $href .= ":/".esc_url
($params{'file_name'});
994 delete $params{'file_name'};
996 delete $params{'hash'};
997 delete $params{'hash_base'};
998 } elsif (defined $params{'hash'}) {
999 $href .= esc_url
($params{'hash'});
1000 delete $params{'hash'};
1003 # If the action was a snapshot, we can absorb the
1004 # snapshot_format parameter too
1006 my $fmt = $params{'snapshot_format'};
1007 # snapshot_format should always be defined when href()
1008 # is called, but just in case some code forgets, we
1009 # fall back to the default
1010 $fmt ||= $snapshot_fmts[0];
1011 $href .= $known_snapshot_formats{$fmt}{'suffix'};
1012 delete $params{'snapshot_format'};
1016 # now encode the parameters explicitly
1018 for (my $i = 0; $i < @cgi_param_mapping; $i += 2) {
1019 my ($name, $symbol) = ($cgi_param_mapping[$i], $cgi_param_mapping[$i+1]);
1020 if (defined $params{$name}) {
1021 if (ref($params{$name}) eq "ARRAY") {
1022 foreach my $par (@{$params{$name}}) {
1023 push @result, $symbol . "=" . esc_param
($par);
1026 push @result, $symbol . "=" . esc_param
($params{$name});
1030 $href .= "?" . join(';', @result) if scalar @result;
1036 ## ======================================================================
1037 ## validation, quoting/unquoting and escaping
1039 sub validate_action
{
1040 my $input = shift || return undef;
1041 return undef unless exists $actions{$input};
1045 sub validate_project
{
1046 my $input = shift || return undef;
1047 if (!validate_pathname
($input) ||
1048 !(-d
"$projectroot/$input") ||
1049 !check_export_ok
("$projectroot/$input") ||
1050 ($strict_export && !project_in_list
($input))) {
1057 sub validate_pathname
{
1058 my $input = shift || return undef;
1060 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
1061 # at the beginning, at the end, and between slashes.
1062 # also this catches doubled slashes
1063 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
1066 # no null characters
1067 if ($input =~ m!\0!) {
1073 sub validate_refname
{
1074 my $input = shift || return undef;
1076 # textual hashes are O.K.
1077 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
1080 # it must be correct pathname
1081 $input = validate_pathname
($input)
1083 # restrictions on ref name according to git-check-ref-format
1084 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
1090 # decode sequences of octets in utf8 into Perl's internal form,
1091 # which is utf-8 with utf8 flag set if needed. gitweb writes out
1092 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
1095 if (utf8
::valid
($str)) {
1099 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
1103 # quote unsafe chars, but keep the slash, even when it's not
1104 # correct, but quoted slashes look too horrible in bookmarks
1107 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
1113 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
1116 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
1122 # replace invalid utf8 character with SUBSTITUTION sequence
1127 $str = to_utf8
($str);
1128 $str = $cgi->escapeHTML($str);
1129 if ($opts{'-nbsp'}) {
1130 $str =~ s/ / /g;
1132 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
1136 # quote control characters and escape filename to HTML
1141 $str = to_utf8
($str);
1142 $str = $cgi->escapeHTML($str);
1143 if ($opts{'-nbsp'}) {
1144 $str =~ s/ / /g;
1146 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
1150 # Make control characters "printable", using character escape codes (CEC)
1154 my %es = ( # character escape codes, aka escape sequences
1155 "\t" => '\t', # tab (HT)
1156 "\n" => '\n', # line feed (LF)
1157 "\r" => '\r', # carrige return (CR)
1158 "\f" => '\f', # form feed (FF)
1159 "\b" => '\b', # backspace (BS)
1160 "\a" => '\a', # alarm (bell) (BEL)
1161 "\e" => '\e', # escape (ESC)
1162 "\013" => '\v', # vertical tab (VT)
1163 "\000" => '\0', # nul character (NUL)
1165 my $chr = ( (exists $es{$cntrl})
1167 : sprintf('\%2x', ord($cntrl)) );
1168 if ($opts{-nohtml
}) {
1171 return "<span class=\"cntrl\">$chr</span>";
1175 # Alternatively use unicode control pictures codepoints,
1176 # Unicode "printable representation" (PR)
1181 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
1182 if ($opts{-nohtml
}) {
1185 return "<span class=\"cntrl\">$chr</span>";
1189 # git may return quoted and escaped filenames
1195 my %es = ( # character escape codes, aka escape sequences
1196 't' => "\t", # tab (HT, TAB)
1197 'n' => "\n", # newline (NL)
1198 'r' => "\r", # return (CR)
1199 'f' => "\f", # form feed (FF)
1200 'b' => "\b", # backspace (BS)
1201 'a' => "\a", # alarm (bell) (BEL)
1202 'e' => "\e", # escape (ESC)
1203 'v' => "\013", # vertical tab (VT)
1206 if ($seq =~ m/^[0-7]{1,3}$/) {
1207 # octal char sequence
1208 return chr(oct($seq));
1209 } elsif (exists $es{$seq}) {
1210 # C escape sequence, aka character escape code
1213 # quoted ordinary character
1217 if ($str =~ m/^"(.*)"$/) {
1220 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
1225 # escape tabs (convert tabs to spaces)
1229 while ((my $pos = index($line, "\t")) != -1) {
1230 if (my $count = (8 - ($pos % 8))) {
1231 my $spaces = ' ' x
$count;
1232 $line =~ s/\t/$spaces/;
1239 sub project_in_list
{
1240 my $project = shift;
1241 my @list = git_get_projects_list
();
1242 return @list && scalar(grep { $_->{'path'} eq $project } @list);
1245 ## ----------------------------------------------------------------------
1246 ## HTML aware string manipulation
1248 # Try to chop given string on a word boundary between position
1249 # $len and $len+$add_len. If there is no word boundary there,
1250 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
1251 # (marking chopped part) would be longer than given string.
1255 my $add_len = shift || 10;
1256 my $where = shift || 'right'; # 'left' | 'center' | 'right'
1258 # Make sure perl knows it is utf8 encoded so we don't
1259 # cut in the middle of a utf8 multibyte char.
1260 $str = to_utf8
($str);
1262 # allow only $len chars, but don't cut a word if it would fit in $add_len
1263 # if it doesn't fit, cut it if it's still longer than the dots we would add
1264 # remove chopped character entities entirely
1266 # when chopping in the middle, distribute $len into left and right part
1267 # return early if chopping wouldn't make string shorter
1268 if ($where eq 'center') {
1269 return $str if ($len + 5 >= length($str)); # filler is length 5
1272 return $str if ($len + 4 >= length($str)); # filler is length 4
1275 # regexps: ending and beginning with word part up to $add_len
1276 my $endre = qr/.{$len}\w{0,$add_len}/;
1277 my $begre = qr/\w{0,$add_len}.{$len}/;
1279 if ($where eq 'left') {
1280 $str =~ m/^(.*?)($begre)$/;
1281 my ($lead, $body) = ($1, $2);
1282 if (length($lead) > 4) {
1283 $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
1286 return "$lead$body";
1288 } elsif ($where eq 'center') {
1289 $str =~ m/^($endre)(.*)$/;
1290 my ($left, $str) = ($1, $2);
1291 $str =~ m/^(.*?)($begre)$/;
1292 my ($mid, $right) = ($1, $2);
1293 if (length($mid) > 5) {
1294 $left =~ s/&[^;]*$//;
1295 $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
1298 return "$left$mid$right";
1301 $str =~ m/^($endre)(.*)$/;
1304 if (length($tail) > 4) {
1305 $body =~ s/&[^;]*$//;
1308 return "$body$tail";
1312 # takes the same arguments as chop_str, but also wraps a <span> around the
1313 # result with a title attribute if it does get chopped. Additionally, the
1314 # string is HTML-escaped.
1315 sub chop_and_escape_str
{
1318 my $chopped = chop_str
(@_);
1319 if ($chopped eq $str) {
1320 return esc_html
($chopped);
1322 $str =~ s/[[:cntrl:]]/?/g;
1323 return $cgi->span({-title
=>$str}, esc_html
($chopped));
1327 ## ----------------------------------------------------------------------
1328 ## functions returning short strings
1330 # CSS class for given age value (in seconds)
1334 if (!defined $age) {
1336 } elsif ($age < 60*60*2) {
1338 } elsif ($age < 60*60*24*2) {
1345 # convert age in seconds to "nn units ago" string
1350 if ($age > 60*60*24*365*2) {
1351 $age_str = (int $age/60/60/24/365);
1352 $age_str .= " years ago";
1353 } elsif ($age > 60*60*24*(365/12)*2) {
1354 $age_str = int $age/60/60/24/(365/12);
1355 $age_str .= " months ago";
1356 } elsif ($age > 60*60*24*7*2) {
1357 $age_str = int $age/60/60/24/7;
1358 $age_str .= " weeks ago";
1359 } elsif ($age > 60*60*24*2) {
1360 $age_str = int $age/60/60/24;
1361 $age_str .= " days ago";
1362 } elsif ($age > 60*60*2) {
1363 $age_str = int $age/60/60;
1364 $age_str .= " hours ago";
1365 } elsif ($age > 60*2) {
1366 $age_str = int $age/60;
1367 $age_str .= " min ago";
1368 } elsif ($age > 2) {
1369 $age_str = int $age;
1370 $age_str .= " sec ago";
1372 $age_str .= " right now";
1378 S_IFINVALID
=> 0030000,
1379 S_IFGITLINK
=> 0160000,
1382 # submodule/subproject, a commit object reference
1386 return (($mode & S_IFMT
) == S_IFGITLINK
)
1389 # convert file mode in octal to symbolic file mode string
1391 my $mode = oct shift;
1393 if (S_ISGITLINK
($mode)) {
1394 return 'm---------';
1395 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1396 return 'drwxr-xr-x';
1397 } elsif (S_ISLNK
($mode)) {
1398 return 'lrwxrwxrwx';
1399 } elsif (S_ISREG
($mode)) {
1400 # git cares only about the executable bit
1401 if ($mode & S_IXUSR
) {
1402 return '-rwxr-xr-x';
1404 return '-rw-r--r--';
1407 return '----------';
1411 # convert file mode in octal to file type string
1415 if ($mode !~ m/^[0-7]+$/) {
1421 if (S_ISGITLINK
($mode)) {
1423 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1425 } elsif (S_ISLNK
($mode)) {
1427 } elsif (S_ISREG
($mode)) {
1434 # convert file mode in octal to file type description string
1435 sub file_type_long
{
1438 if ($mode !~ m/^[0-7]+$/) {
1444 if (S_ISGITLINK
($mode)) {
1446 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1448 } elsif (S_ISLNK
($mode)) {
1450 } elsif (S_ISREG
($mode)) {
1451 if ($mode & S_IXUSR
) {
1452 return "executable";
1462 ## ----------------------------------------------------------------------
1463 ## functions returning short HTML fragments, or transforming HTML fragments
1464 ## which don't belong to other sections
1466 # format line of commit message.
1467 sub format_log_line_html
{
1470 $line = esc_html
($line, -nbsp
=>1);
1471 $line =~ s
{\b([0-9a-fA-F
]{8,40})\b}{
1472 $cgi->a({-href
=> href
(action
=>"object", hash
=>$1),
1473 -class => "text"}, $1);
1479 # format marker of refs pointing to given object
1481 # the destination action is chosen based on object type and current context:
1482 # - for annotated tags, we choose the tag view unless it's the current view
1483 # already, in which case we go to shortlog view
1484 # - for other refs, we keep the current view if we're in history, shortlog or
1485 # log view, and select shortlog otherwise
1486 sub format_ref_marker
{
1487 my ($refs, $id) = @_;
1490 if (defined $refs->{$id}) {
1491 foreach my $ref (@{$refs->{$id}}) {
1492 # this code exploits the fact that non-lightweight tags are the
1493 # only indirect objects, and that they are the only objects for which
1494 # we want to use tag instead of shortlog as action
1495 my ($type, $name) = qw();
1496 my $indirect = ($ref =~ s/\^\{\}$//);
1497 # e.g. tags/v2.6.11 or heads/next
1498 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1507 $class .= " indirect" if $indirect;
1509 my $dest_action = "shortlog";
1512 $dest_action = "tag" unless $action eq "tag";
1513 } elsif ($action =~ /^(history|(short)?log)$/) {
1514 $dest_action = $action;
1518 $dest .= "refs/" unless $ref =~ m
!^refs
/!;
1521 my $link = $cgi->a({
1523 action
=>$dest_action,
1527 $markers .= " <span class=\"$class\" title=\"$ref\">" .
1533 return ' <span class="refs">'. $markers . '</span>';
1539 # format, perhaps shortened and with markers, title line
1540 sub format_subject_html
{
1541 my ($long, $short, $href, $extra) = @_;
1542 $extra = '' unless defined($extra);
1544 if (length($short) < length($long)) {
1545 $long =~ s/[[:cntrl:]]/?/g;
1546 return $cgi->a({-href
=> $href, -class => "list subject",
1547 -title
=> to_utf8
($long)},
1548 esc_html
($short)) . $extra;
1550 return $cgi->a({-href
=> $href, -class => "list subject"},
1551 esc_html
($long)) . $extra;
1555 # Rather than recomputing the url for an email multiple times, we cache it
1556 # after the first hit. This gives a visible benefit in views where the avatar
1557 # for the same email is used repeatedly (e.g. shortlog).
1558 # The cache is shared by all avatar engines (currently gravatar only), which
1559 # are free to use it as preferred. Since only one avatar engine is used for any
1560 # given page, there's no risk for cache conflicts.
1561 our %avatar_cache = ();
1563 # Compute the picon url for a given email, by using the picon search service over at
1564 # http://www.cs.indiana.edu/picons/search.html
1566 my $email = lc shift;
1567 if (!$avatar_cache{$email}) {
1568 my ($user, $domain) = split('@', $email);
1569 $avatar_cache{$email} =
1570 "http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/" .
1572 "users+domains+unknown/up/single";
1574 return $avatar_cache{$email};
1577 # Compute the gravatar url for a given email, if it's not in the cache already.
1578 # Gravatar stores only the part of the URL before the size, since that's the
1579 # one computationally more expensive. This also allows reuse of the cache for
1580 # different sizes (for this particular engine).
1582 my $email = lc shift;
1584 $avatar_cache{$email} ||=
1585 "http://www.gravatar.com/avatar/" .
1586 Digest
::MD5
::md5_hex
($email) . "?s=";
1587 return $avatar_cache{$email} . $size;
1590 # Insert an avatar for the given $email at the given $size if the feature
1592 sub git_get_avatar
{
1593 my ($email, %opts) = @_;
1594 my $pre_white = ($opts{-pad_before
} ? " " : "");
1595 my $post_white = ($opts{-pad_after
} ? " " : "");
1596 $opts{-size
} ||= 'default';
1597 my $size = $avatar_size{$opts{-size
}} || $avatar_size{'default'};
1599 if ($git_avatar eq 'gravatar') {
1600 $url = gravatar_url
($email, $size);
1601 } elsif ($git_avatar eq 'picon') {
1602 $url = picon_url
($email);
1604 # Other providers can be added by extending the if chain, defining $url
1605 # as needed. If no variant puts something in $url, we assume avatars
1606 # are completely disabled/unavailable.
1609 "<img width=\"$size\" " .
1610 "class=\"avatar\" " .
1619 # format the author name of the given commit with the given tag
1620 # the author name is chopped and escaped according to the other
1621 # optional parameters (see chop_str).
1622 sub format_author_html
{
1625 my $author = chop_and_escape_str
($co->{'author_name'}, @_);
1626 return "<$tag class=\"author\">" .
1627 git_get_avatar
($co->{'author_email'}, -pad_after
=> 1) .
1628 $author . "</$tag>";
1631 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1632 sub format_git_diff_header_line
{
1634 my $diffinfo = shift;
1635 my ($from, $to) = @_;
1637 if ($diffinfo->{'nparents'}) {
1639 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1640 if ($to->{'href'}) {
1641 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1642 esc_path
($to->{'file'}));
1643 } else { # file was deleted (no href)
1644 $line .= esc_path
($to->{'file'});
1648 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1649 if ($from->{'href'}) {
1650 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1651 'a/' . esc_path
($from->{'file'}));
1652 } else { # file was added (no href)
1653 $line .= 'a/' . esc_path
($from->{'file'});
1656 if ($to->{'href'}) {
1657 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1658 'b/' . esc_path
($to->{'file'}));
1659 } else { # file was deleted
1660 $line .= 'b/' . esc_path
($to->{'file'});
1664 return "<div class=\"diff header\">$line</div>\n";
1667 # format extended diff header line, before patch itself
1668 sub format_extended_diff_header_line
{
1670 my $diffinfo = shift;
1671 my ($from, $to) = @_;
1674 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1675 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1676 esc_path
($from->{'file'}));
1678 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1679 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1680 esc_path
($to->{'file'}));
1682 # match single <mode>
1683 if ($line =~ m/\s(\d{6})$/) {
1684 $line .= '<span class="info"> (' .
1685 file_type_long
($1) .
1689 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1690 # can match only for combined diff
1692 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1693 if ($from->{'href'}[$i]) {
1694 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1696 substr($diffinfo->{'from_id'}[$i],0,7));
1701 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1704 if ($to->{'href'}) {
1705 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1706 substr($diffinfo->{'to_id'},0,7));
1711 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1712 # can match only for ordinary diff
1713 my ($from_link, $to_link);
1714 if ($from->{'href'}) {
1715 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1716 substr($diffinfo->{'from_id'},0,7));
1718 $from_link = '0' x
7;
1720 if ($to->{'href'}) {
1721 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1722 substr($diffinfo->{'to_id'},0,7));
1726 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1727 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1730 return $line . "<br/>\n";
1733 # format from-file/to-file diff header
1734 sub format_diff_from_to_header
{
1735 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1740 #assert($line =~ m/^---/) if DEBUG;
1741 # no extra formatting for "^--- /dev/null"
1742 if (! $diffinfo->{'nparents'}) {
1743 # ordinary (single parent) diff
1744 if ($line =~ m!^--- "?a/!) {
1745 if ($from->{'href'}) {
1747 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1748 esc_path
($from->{'file'}));
1751 esc_path
($from->{'file'});
1754 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1757 # combined diff (merge commit)
1758 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1759 if ($from->{'href'}[$i]) {
1761 $cgi->a({-href
=>href
(action
=>"blobdiff",
1762 hash_parent
=>$diffinfo->{'from_id'}[$i],
1763 hash_parent_base
=>$parents[$i],
1764 file_parent
=>$from->{'file'}[$i],
1765 hash
=>$diffinfo->{'to_id'},
1767 file_name
=>$to->{'file'}),
1769 -title
=>"diff" . ($i+1)},
1772 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1773 esc_path
($from->{'file'}[$i]));
1775 $line = '--- /dev/null';
1777 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1782 #assert($line =~ m/^\+\+\+/) if DEBUG;
1783 # no extra formatting for "^+++ /dev/null"
1784 if ($line =~ m!^\+\+\+ "?b/!) {
1785 if ($to->{'href'}) {
1787 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1788 esc_path
($to->{'file'}));
1791 esc_path
($to->{'file'});
1794 $result .= qq
!<div
class="diff to_file">$line</div
>\n!;
1799 # create note for patch simplified by combined diff
1800 sub format_diff_cc_simplified
{
1801 my ($diffinfo, @parents) = @_;
1804 $result .= "<div class=\"diff header\">" .
1806 if (!is_deleted
($diffinfo)) {
1807 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1809 hash
=>$diffinfo->{'to_id'},
1810 file_name
=>$diffinfo->{'to_file'}),
1812 esc_path
($diffinfo->{'to_file'}));
1814 $result .= esc_path
($diffinfo->{'to_file'});
1816 $result .= "</div>\n" . # class="diff header"
1817 "<div class=\"diff nodifferences\">" .
1819 "</div>\n"; # class="diff nodifferences"
1824 # format patch (diff) line (not to be used for diff headers)
1825 sub format_diff_line
{
1827 my ($from, $to) = @_;
1828 my $diff_class = "";
1832 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1834 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
1835 if ($line =~ m/^\@{3}/) {
1836 $diff_class = " chunk_header";
1837 } elsif ($line =~ m/^\\/) {
1838 $diff_class = " incomplete";
1839 } elsif ($prefix =~ tr/+/+/) {
1840 $diff_class = " add";
1841 } elsif ($prefix =~ tr/-/-/) {
1842 $diff_class = " rem";
1845 # assume ordinary diff
1846 my $char = substr($line, 0, 1);
1848 $diff_class = " add";
1849 } elsif ($char eq '-') {
1850 $diff_class = " rem";
1851 } elsif ($char eq '@') {
1852 $diff_class = " chunk_header";
1853 } elsif ($char eq "\\") {
1854 $diff_class = " incomplete";
1857 $line = untabify
($line);
1858 if ($from && $to && $line =~ m/^\@{2} /) {
1859 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1860 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1862 $from_lines = 0 unless defined $from_lines;
1863 $to_lines = 0 unless defined $to_lines;
1865 if ($from->{'href'}) {
1866 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1867 -class=>"list"}, $from_text);
1869 if ($to->{'href'}) {
1870 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1871 -class=>"list"}, $to_text);
1873 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1874 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1875 return "<div class=\"diff$diff_class\">$line</div>\n";
1876 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1877 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1878 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1880 @from_text = split(' ', $ranges);
1881 for (my $i = 0; $i < @from_text; ++$i) {
1882 ($from_start[$i], $from_nlines[$i]) =
1883 (split(',', substr($from_text[$i], 1)), 0);
1886 $to_text = pop @from_text;
1887 $to_start = pop @from_start;
1888 $to_nlines = pop @from_nlines;
1890 $line = "<span class=\"chunk_info\">$prefix ";
1891 for (my $i = 0; $i < @from_text; ++$i) {
1892 if ($from->{'href'}[$i]) {
1893 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1894 -class=>"list"}, $from_text[$i]);
1896 $line .= $from_text[$i];
1900 if ($to->{'href'}) {
1901 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1902 -class=>"list"}, $to_text);
1906 $line .= " $prefix</span>" .
1907 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1908 return "<div class=\"diff$diff_class\">$line</div>\n";
1910 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1913 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1914 # linked. Pass the hash of the tree/commit to snapshot.
1915 sub format_snapshot_links
{
1917 my $num_fmts = @snapshot_fmts;
1918 if ($num_fmts > 1) {
1919 # A parenthesized list of links bearing format names.
1920 # e.g. "snapshot (_tar.gz_ _zip_)"
1921 return "snapshot (" . join(' ', map
1928 }, $known_snapshot_formats{$_}{'display'})
1929 , @snapshot_fmts) . ")";
1930 } elsif ($num_fmts == 1) {
1931 # A single "snapshot" link whose tooltip bears the format name.
1933 my ($fmt) = @snapshot_fmts;
1939 snapshot_format
=>$fmt
1941 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1943 } else { # $num_fmts == 0
1948 ## ......................................................................
1949 ## functions returning values to be passed, perhaps after some
1950 ## transformation, to other functions; e.g. returning arguments to href()
1952 # returns hash to be passed to href to generate gitweb URL
1953 # in -title key it returns description of link
1955 my $format = shift || 'Atom';
1956 my %res = (action
=> lc($format));
1958 # feed links are possible only for project views
1959 return unless (defined $project);
1960 # some views should link to OPML, or to generic project feed,
1961 # or don't have specific feed yet (so they should use generic)
1962 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
1965 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
1966 # from tag links; this also makes possible to detect branch links
1967 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
1968 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
1971 # find log type for feed description (title)
1973 if (defined $file_name) {
1974 $type = "history of $file_name";
1975 $type .= "/" if ($action eq 'tree');
1976 $type .= " on '$branch'" if (defined $branch);
1978 $type = "log of $branch" if (defined $branch);
1981 $res{-title
} = $type;
1982 $res{'hash'} = (defined $branch ? "refs/heads/$branch" : undef);
1983 $res{'file_name'} = $file_name;
1988 ## ----------------------------------------------------------------------
1989 ## git utility subroutines, invoking git commands
1991 # returns path to the core git executable and the --git-dir parameter as list
1993 $number_of_git_cmds++;
1994 return $GIT, '--git-dir='.$git_dir;
1997 # quote the given arguments for passing them to the shell
1998 # quote_command("command", "arg 1", "arg with ' and ! characters")
1999 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
2000 # Try to avoid using this function wherever possible.
2003 map { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ );
2006 # get HEAD ref of given project as hash
2007 sub git_get_head_hash
{
2008 my $project = shift;
2009 my $o_git_dir = $git_dir;
2011 $git_dir = "$projectroot/$project";
2012 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
2015 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
2019 if (defined $o_git_dir) {
2020 $git_dir = $o_git_dir;
2025 # get type of given object
2029 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
2031 close $fd or return;
2036 # repository configuration
2037 our $config_file = '';
2040 # store multiple values for single key as anonymous array reference
2041 # single values stored directly in the hash, not as [ <value> ]
2042 sub hash_set_multi
{
2043 my ($hash, $key, $value) = @_;
2045 if (!exists $hash->{$key}) {
2046 $hash->{$key} = $value;
2047 } elsif (!ref $hash->{$key}) {
2048 $hash->{$key} = [ $hash->{$key}, $value ];
2050 push @{$hash->{$key}}, $value;
2054 # return hash of git project configuration
2055 # optionally limited to some section, e.g. 'gitweb'
2056 sub git_parse_project_config
{
2057 my $section_regexp = shift;
2062 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
2065 while (my $keyval = <$fh>) {
2067 my ($key, $value) = split(/\n/, $keyval, 2);
2069 hash_set_multi
(\
%config, $key, $value)
2070 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
2077 # convert config value to boolean: 'true' or 'false'
2078 # no value, number > 0, 'true' and 'yes' values are true
2079 # rest of values are treated as false (never as error)
2080 sub config_to_bool
{
2083 return 1 if !defined $val; # section.key
2085 # strip leading and trailing whitespace
2089 return (($val =~ /^\d+$/ && $val) || # section.key = 1
2090 ($val =~ /^(?:true|yes)$/i)); # section.key = true
2093 # convert config value to simple decimal number
2094 # an optional value suffix of 'k', 'm', or 'g' will cause the value
2095 # to be multiplied by 1024, 1048576, or 1073741824
2099 # strip leading and trailing whitespace
2103 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
2105 # unknown unit is treated as 1
2106 return $num * ($unit eq 'g' ? 1073741824 :
2107 $unit eq 'm' ? 1048576 :
2108 $unit eq 'k' ? 1024 : 1);
2113 # convert config value to array reference, if needed
2114 sub config_to_multi
{
2117 return ref($val) ? $val : (defined($val) ? [ $val ] : []);
2120 sub git_get_project_config
{
2121 my ($key, $type) = @_;
2124 return unless ($key);
2125 $key =~ s/^gitweb\.//;
2126 return if ($key =~ m/\W/);
2129 if (defined $type) {
2132 unless ($type eq 'bool' || $type eq 'int');
2136 if (!defined $config_file ||
2137 $config_file ne "$git_dir/config") {
2138 %config = git_parse_project_config
('gitweb');
2139 $config_file = "$git_dir/config";
2142 # check if config variable (key) exists
2143 return unless exists $config{"gitweb.$key"};
2146 if (!defined $type) {
2147 return $config{"gitweb.$key"};
2148 } elsif ($type eq 'bool') {
2149 # backward compatibility: 'git config --bool' returns true/false
2150 return config_to_bool
($config{"gitweb.$key"}) ? 'true' : 'false';
2151 } elsif ($type eq 'int') {
2152 return config_to_int
($config{"gitweb.$key"});
2154 return $config{"gitweb.$key"};
2157 # get hash of given path at given ref
2158 sub git_get_hash_by_path
{
2160 my $path = shift || return undef;
2165 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
2166 or die_error
(500, "Open git-ls-tree failed");
2168 close $fd or return undef;
2170 if (!defined $line) {
2171 # there is no tree or hash given by $path at $base
2175 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2176 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
2177 if (defined $type && $type ne $2) {
2178 # type doesn't match
2184 # get path of entry with given hash at given tree-ish (ref)
2185 # used to get 'from' filename for combined diff (merge commit) for renames
2186 sub git_get_path_by_hash
{
2187 my $base = shift || return;
2188 my $hash = shift || return;
2192 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
2194 while (my $line = <$fd>) {
2197 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
2198 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
2199 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
2208 ## ......................................................................
2209 ## git utility functions, directly accessing git repository
2211 sub git_get_project_description
{
2214 $git_dir = "$projectroot/$path";
2215 open my $fd, '<', "$git_dir/description"
2216 or return git_get_project_config
('description');
2219 if (defined $descr) {
2225 sub git_get_project_ctags
{
2229 $git_dir = "$projectroot/$path";
2230 opendir my $dh, "$git_dir/ctags"
2232 foreach (grep { -f
$_ } map { "$git_dir/ctags/$_" } readdir($dh)) {
2233 open my $ct, '<', $_ or next;
2237 my $ctag = $_; $ctag =~ s
#.*/##;
2238 $ctags->{$ctag} = $val;
2244 sub git_populate_project_tagcloud
{
2247 # First, merge different-cased tags; tags vote on casing
2249 foreach (keys %$ctags) {
2250 $ctags_lc{lc $_}->{count
} += $ctags->{$_};
2251 if (not $ctags_lc{lc $_}->{topcount
}
2252 or $ctags_lc{lc $_}->{topcount
} < $ctags->{$_}) {
2253 $ctags_lc{lc $_}->{topcount
} = $ctags->{$_};
2254 $ctags_lc{lc $_}->{topname
} = $_;
2259 if (eval { require HTML
::TagCloud
; 1; }) {
2260 $cloud = HTML
::TagCloud-
>new;
2261 foreach (sort keys %ctags_lc) {
2262 # Pad the title with spaces so that the cloud looks
2264 my $title = $ctags_lc{$_}->{topname
};
2265 $title =~ s/ / /g;
2266 $title =~ s/^/ /g;
2267 $title =~ s/$/ /g;
2268 $cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count
});
2271 $cloud = \
%ctags_lc;
2276 sub git_show_project_tagcloud
{
2277 my ($cloud, $count) = @_;
2278 print STDERR
ref($cloud)."..\n";
2279 if (ref $cloud eq 'HTML::TagCloud') {
2280 return $cloud->html_and_css($count);
2282 my @tags = sort { $cloud->{$a}->{count
} <=> $cloud->{$b}->{count
} } keys %$cloud;
2283 return '<p align="center">' . join (', ', map {
2284 "<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"
2285 } splice(@tags, 0, $count)) . '</p>';
2289 sub git_get_project_url_list
{
2292 $git_dir = "$projectroot/$path";
2293 open my $fd, '<', "$git_dir/cloneurl"
2294 or return wantarray ?
2295 @{ config_to_multi
(git_get_project_config
('url')) } :
2296 config_to_multi
(git_get_project_config
('url'));
2297 my @git_project_url_list = map { chomp; $_ } <$fd>;
2300 return wantarray ? @git_project_url_list : \
@git_project_url_list;
2303 sub git_get_projects_list
{
2308 $filter =~ s/\.git$//;
2310 my $check_forks = gitweb_check_feature
('forks');
2312 if (-d
$projects_list) {
2313 # search in directory
2314 my $dir = $projects_list . ($filter ? "/$filter" : '');
2315 # remove the trailing "/"
2317 my $pfxlen = length("$dir");
2318 my $pfxdepth = ($dir =~ tr!/!!);
2321 follow_fast
=> 1, # follow symbolic links
2322 follow_skip
=> 2, # ignore duplicates
2323 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
2325 # skip project-list toplevel, if we get it.
2326 return if (m!^[/.]$!);
2327 # only directories can be git repositories
2328 return unless (-d
$_);
2329 # don't traverse too deep (Find is super slow on os x)
2330 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
2331 $File::Find
::prune
= 1;
2335 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
2336 # we check related file in $projectroot
2337 my $path = ($filter ? "$filter/" : '') . $subdir;
2338 if (check_export_ok
("$projectroot/$path")) {
2339 push @list, { path
=> $path };
2340 $File::Find
::prune
= 1;
2345 } elsif (-f
$projects_list) {
2346 # read from file(url-encoded):
2347 # 'git%2Fgit.git Linus+Torvalds'
2348 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2349 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2351 open my $fd, '<', $projects_list or return;
2353 while (my $line = <$fd>) {
2355 my ($path, $owner) = split ' ', $line;
2356 $path = unescape
($path);
2357 $owner = unescape
($owner);
2358 if (!defined $path) {
2361 if ($filter ne '') {
2362 # looking for forks;
2363 my $pfx = substr($path, 0, length($filter));
2364 if ($pfx ne $filter) {
2367 my $sfx = substr($path, length($filter));
2368 if ($sfx !~ /^\/.*\
.git
$/) {
2371 } elsif ($check_forks) {
2373 foreach my $filter (keys %paths) {
2374 # looking for forks;
2375 my $pfx = substr($path, 0, length($filter));
2376 if ($pfx ne $filter) {
2379 my $sfx = substr($path, length($filter));
2380 if ($sfx !~ /^\/.*\
.git
$/) {
2383 # is a fork, don't include it in
2388 if (check_export_ok
("$projectroot/$path")) {
2391 owner
=> to_utf8
($owner),
2394 (my $forks_path = $path) =~ s/\.git$//;
2395 $paths{$forks_path}++;
2403 our $gitweb_project_owner = undef;
2404 sub git_get_project_list_from_file
{
2406 return if (defined $gitweb_project_owner);
2408 $gitweb_project_owner = {};
2409 # read from file (url-encoded):
2410 # 'git%2Fgit.git Linus+Torvalds'
2411 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2412 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2413 if (-f
$projects_list) {
2414 open(my $fd, '<', $projects_list);
2415 while (my $line = <$fd>) {
2417 my ($pr, $ow) = split ' ', $line;
2418 $pr = unescape
($pr);
2419 $ow = unescape
($ow);
2420 $gitweb_project_owner->{$pr} = to_utf8
($ow);
2426 sub git_get_project_owner
{
2427 my $project = shift;
2430 return undef unless $project;
2431 $git_dir = "$projectroot/$project";
2433 if (!defined $gitweb_project_owner) {
2434 git_get_project_list_from_file
();
2437 if (exists $gitweb_project_owner->{$project}) {
2438 $owner = $gitweb_project_owner->{$project};
2440 if (!defined $owner){
2441 $owner = git_get_project_config
('owner');
2443 if (!defined $owner) {
2444 $owner = get_file_owner
("$git_dir");
2450 sub git_get_last_activity
{
2454 $git_dir = "$projectroot/$path";
2455 open($fd, "-|", git_cmd
(), 'for-each-ref',
2456 '--format=%(committer)',
2457 '--sort=-committerdate',
2459 'refs/heads') or return;
2460 my $most_recent = <$fd>;
2461 close $fd or return;
2462 if (defined $most_recent &&
2463 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
2465 my $age = time - $timestamp;
2466 return ($age, age_string
($age));
2468 return (undef, undef);
2471 sub git_get_references
{
2472 my $type = shift || "";
2474 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
2475 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
2476 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
2477 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
2480 while (my $line = <$fd>) {
2482 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
2483 if (defined $refs{$1}) {
2484 push @{$refs{$1}}, $2;
2490 close $fd or return;
2494 sub git_get_rev_name_tags
{
2495 my $hash = shift || return undef;
2497 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
2499 my $name_rev = <$fd>;
2502 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
2505 # catches also '$hash undefined' output
2510 ## ----------------------------------------------------------------------
2511 ## parse to hash functions
2515 my $tz = shift || "-0000";
2518 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
2519 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
2520 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
2521 $date{'hour'} = $hour;
2522 $date{'minute'} = $min;
2523 $date{'mday'} = $mday;
2524 $date{'day'} = $days[$wday];
2525 $date{'month'} = $months[$mon];
2526 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2527 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2528 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2529 $mday, $months[$mon], $hour ,$min;
2530 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2531 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2533 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2534 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2535 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2536 $date{'hour_local'} = $hour;
2537 $date{'minute_local'} = $min;
2538 $date{'tz_local'} = $tz;
2539 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2540 1900+$year, $mon+1, $mday,
2541 $hour, $min, $sec, $tz);
2550 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
2551 $tag{'id'} = $tag_id;
2552 while (my $line = <$fd>) {
2554 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2555 $tag{'object'} = $1;
2556 } elsif ($line =~ m/^type (.+)$/) {
2558 } elsif ($line =~ m/^tag (.+)$/) {
2560 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2561 $tag{'author'} = $1;
2562 $tag{'author_epoch'} = $2;
2563 $tag{'author_tz'} = $3;
2564 if ($tag{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2565 $tag{'author_name'} = $1;
2566 $tag{'author_email'} = $2;
2568 $tag{'author_name'} = $tag{'author'};
2570 } elsif ($line =~ m/--BEGIN/) {
2571 push @comment, $line;
2573 } elsif ($line eq "") {
2577 push @comment, <$fd>;
2578 $tag{'comment'} = \
@comment;
2579 close $fd or return;
2580 if (!defined $tag{'name'}) {
2586 sub parse_commit_text
{
2587 my ($commit_text, $withparents) = @_;
2588 my @commit_lines = split '\n', $commit_text;
2591 pop @commit_lines; # Remove '\0'
2593 if (! @commit_lines) {
2597 my $header = shift @commit_lines;
2598 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2601 ($co{'id'}, my @parents) = split ' ', $header;
2602 while (my $line = shift @commit_lines) {
2603 last if $line eq "\n";
2604 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2606 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2608 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2609 $co{'author'} = to_utf8
($1);
2610 $co{'author_epoch'} = $2;
2611 $co{'author_tz'} = $3;
2612 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2613 $co{'author_name'} = $1;
2614 $co{'author_email'} = $2;
2616 $co{'author_name'} = $co{'author'};
2618 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2619 $co{'committer'} = to_utf8
($1);
2620 $co{'committer_epoch'} = $2;
2621 $co{'committer_tz'} = $3;
2622 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2623 $co{'committer_name'} = $1;
2624 $co{'committer_email'} = $2;
2626 $co{'committer_name'} = $co{'committer'};
2630 if (!defined $co{'tree'}) {
2633 $co{'parents'} = \
@parents;
2634 $co{'parent'} = $parents[0];
2636 foreach my $title (@commit_lines) {
2639 $co{'title'} = chop_str
($title, 80, 5);
2640 # remove leading stuff of merges to make the interesting part visible
2641 if (length($title) > 50) {
2642 $title =~ s/^Automatic //;
2643 $title =~ s/^merge (of|with) /Merge ... /i;
2644 if (length($title) > 50) {
2645 $title =~ s/(http|rsync):\/\///;
2647 if (length($title) > 50) {
2648 $title =~ s/(master|www|rsync)\.//;
2650 if (length($title) > 50) {
2651 $title =~ s/kernel.org:?//;
2653 if (length($title) > 50) {
2654 $title =~ s/\/pub\/scm//;
2657 $co{'title_short'} = chop_str
($title, 50, 5);
2661 if (! defined $co{'title'} || $co{'title'} eq "") {
2662 $co{'title'} = $co{'title_short'} = '(no commit message)';
2664 # remove added spaces
2665 foreach my $line (@commit_lines) {
2668 $co{'comment'} = \
@commit_lines;
2670 my $age = time - $co{'committer_epoch'};
2672 $co{'age_string'} = age_string
($age);
2673 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2674 if ($age > 60*60*24*7*2) {
2675 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2676 $co{'age_string_age'} = $co{'age_string'};
2678 $co{'age_string_date'} = $co{'age_string'};
2679 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2685 my ($commit_id) = @_;
2690 open my $fd, "-|", git_cmd
(), "rev-list",
2696 or die_error
(500, "Open git-rev-list failed");
2697 %co = parse_commit_text
(<$fd>, 1);
2704 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2712 open my $fd, "-|", git_cmd
(), "rev-list",
2715 ("--max-count=" . $maxcount),
2716 ("--skip=" . $skip),
2720 ($filename ? ($filename) : ())
2721 or die_error
(500, "Open git-rev-list failed");
2722 while (my $line = <$fd>) {
2723 my %co = parse_commit_text
($line);
2728 return wantarray ? @cos : \
@cos;
2731 # parse line of git-diff-tree "raw" output
2732 sub parse_difftree_raw_line
{
2736 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2737 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2738 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2739 $res{'from_mode'} = $1;
2740 $res{'to_mode'} = $2;
2741 $res{'from_id'} = $3;
2743 $res{'status'} = $5;
2744 $res{'similarity'} = $6;
2745 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2746 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2748 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2751 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2752 # combined diff (for merge commit)
2753 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2754 $res{'nparents'} = length($1);
2755 $res{'from_mode'} = [ split(' ', $2) ];
2756 $res{'to_mode'} = pop @{$res{'from_mode'}};
2757 $res{'from_id'} = [ split(' ', $3) ];
2758 $res{'to_id'} = pop @{$res{'from_id'}};
2759 $res{'status'} = [ split('', $4) ];
2760 $res{'to_file'} = unquote
($5);
2762 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2763 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2764 $res{'commit'} = $1;
2767 return wantarray ? %res : \
%res;
2770 # wrapper: return parsed line of git-diff-tree "raw" output
2771 # (the argument might be raw line, or parsed info)
2772 sub parsed_difftree_line
{
2773 my $line_or_ref = shift;
2775 if (ref($line_or_ref) eq "HASH") {
2776 # pre-parsed (or generated by hand)
2777 return $line_or_ref;
2779 return parse_difftree_raw_line
($line_or_ref);
2783 # parse line of git-ls-tree output
2784 sub parse_ls_tree_line
{
2789 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2790 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2798 $res{'name'} = unquote
($4);
2801 return wantarray ? %res : \
%res;
2804 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2805 sub parse_from_to_diffinfo
{
2806 my ($diffinfo, $from, $to, @parents) = @_;
2808 if ($diffinfo->{'nparents'}) {
2810 $from->{'file'} = [];
2811 $from->{'href'} = [];
2812 fill_from_file_info
($diffinfo, @parents)
2813 unless exists $diffinfo->{'from_file'};
2814 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2815 $from->{'file'}[$i] =
2816 defined $diffinfo->{'from_file'}[$i] ?
2817 $diffinfo->{'from_file'}[$i] :
2818 $diffinfo->{'to_file'};
2819 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2820 $from->{'href'}[$i] = href
(action
=>"blob",
2821 hash_base
=>$parents[$i],
2822 hash
=>$diffinfo->{'from_id'}[$i],
2823 file_name
=>$from->{'file'}[$i]);
2825 $from->{'href'}[$i] = undef;
2829 # ordinary (not combined) diff
2830 $from->{'file'} = $diffinfo->{'from_file'};
2831 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2832 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2833 hash
=>$diffinfo->{'from_id'},
2834 file_name
=>$from->{'file'});
2836 delete $from->{'href'};
2840 $to->{'file'} = $diffinfo->{'to_file'};
2841 if (!is_deleted
($diffinfo)) { # file exists in result
2842 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2843 hash
=>$diffinfo->{'to_id'},
2844 file_name
=>$to->{'file'});
2846 delete $to->{'href'};
2850 ## ......................................................................
2851 ## parse to array of hashes functions
2853 sub git_get_heads_list
{
2857 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2858 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
2859 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2862 while (my $line = <$fd>) {
2866 my ($refinfo, $committerinfo) = split(/\0/, $line);
2867 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2868 my ($committer, $epoch, $tz) =
2869 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2870 $ref_item{'fullname'} = $name;
2871 $name =~ s!^refs/heads/!!;
2873 $ref_item{'name'} = $name;
2874 $ref_item{'id'} = $hash;
2875 $ref_item{'title'} = $title || '(no commit message)';
2876 $ref_item{'epoch'} = $epoch;
2878 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2880 $ref_item{'age'} = "unknown";
2883 push @headslist, \
%ref_item;
2887 return wantarray ? @headslist : \
@headslist;
2890 sub git_get_tags_list
{
2894 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2895 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
2896 '--format=%(objectname) %(objecttype) %(refname) '.
2897 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2900 while (my $line = <$fd>) {
2904 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2905 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2906 my ($creator, $epoch, $tz) =
2907 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2908 $ref_item{'fullname'} = $name;
2909 $name =~ s!^refs/tags/!!;
2911 $ref_item{'type'} = $type;
2912 $ref_item{'id'} = $id;
2913 $ref_item{'name'} = $name;
2914 if ($type eq "tag") {
2915 $ref_item{'subject'} = $title;
2916 $ref_item{'reftype'} = $reftype;
2917 $ref_item{'refid'} = $refid;
2919 $ref_item{'reftype'} = $type;
2920 $ref_item{'refid'} = $id;
2923 if ($type eq "tag" || $type eq "commit") {
2924 $ref_item{'epoch'} = $epoch;
2926 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2928 $ref_item{'age'} = "unknown";
2932 push @tagslist, \
%ref_item;
2936 return wantarray ? @tagslist : \
@tagslist;
2939 ## ----------------------------------------------------------------------
2940 ## filesystem-related functions
2942 sub get_file_owner
{
2945 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2946 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2947 if (!defined $gcos) {
2951 $owner =~ s/[,;].*$//;
2952 return to_utf8
($owner);
2955 # assume that file exists
2957 my $filename = shift;
2959 open my $fd, '<', $filename;
2960 print map { to_utf8
($_) } <$fd>;
2964 ## ......................................................................
2965 ## mimetype related functions
2967 sub mimetype_guess_file
{
2968 my $filename = shift;
2969 my $mimemap = shift;
2970 -r
$mimemap or return undef;
2973 open(my $mh, '<', $mimemap) or return undef;
2975 next if m/^#/; # skip comments
2976 my ($mimetype, $exts) = split(/\t+/);
2977 if (defined $exts) {
2978 my @exts = split(/\s+/, $exts);
2979 foreach my $ext (@exts) {
2980 $mimemap{$ext} = $mimetype;
2986 $filename =~ /\.([^.]*)$/;
2987 return $mimemap{$1};
2990 sub mimetype_guess
{
2991 my $filename = shift;
2993 $filename =~ /\./ or return undef;
2995 if ($mimetypes_file) {
2996 my $file = $mimetypes_file;
2997 if ($file !~ m!^/!) { # if it is relative path
2998 # it is relative to project
2999 $file = "$projectroot/$project/$file";
3001 $mime = mimetype_guess_file
($filename, $file);
3003 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
3009 my $filename = shift;
3012 my $mime = mimetype_guess
($filename);
3013 $mime and return $mime;
3017 return $default_blob_plain_mimetype unless $fd;
3020 return 'text/plain';
3021 } elsif (! $filename) {
3022 return 'application/octet-stream';
3023 } elsif ($filename =~ m/\.png$/i) {
3025 } elsif ($filename =~ m/\.gif$/i) {
3027 } elsif ($filename =~ m/\.jpe?g$/i) {
3028 return 'image/jpeg';
3030 return 'application/octet-stream';
3034 sub blob_contenttype
{
3035 my ($fd, $file_name, $type) = @_;
3037 $type ||= blob_mimetype
($fd, $file_name);
3038 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
3039 $type .= "; charset=$default_text_plain_charset";
3045 ## ======================================================================
3046 ## functions printing HTML: header, footer, error page
3048 sub git_header_html
{
3049 my $status = shift || "200 OK";
3050 my $expires = shift;
3052 my $title = "$site_name";
3053 if (defined $project) {
3054 $title .= " - " . to_utf8
($project);
3055 if (defined $action) {
3056 $title .= "/$action";
3057 if (defined $file_name) {
3058 $title .= " - " . esc_path
($file_name);
3059 if ($action eq "tree" && $file_name !~ m
|/$|) {
3066 # require explicit support from the UA if we are to send the page as
3067 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
3068 # we have to do this because MSIE sometimes globs '*/*', pretending to
3069 # support xhtml+xml but choking when it gets what it asked for.
3070 if (defined $cgi->http('HTTP_ACCEPT') &&
3071 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
3072 $cgi->Accept('application/xhtml+xml') != 0) {
3073 $content_type = 'application/xhtml+xml';
3075 $content_type = 'text/html';
3077 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
3078 -status
=> $status, -expires
=> $expires);
3079 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
3081 <?xml version="1.0" encoding="utf-8"?>
3082 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3083 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
3084 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
3085 <!-- git core binaries version $git_version -->
3087 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
3088 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
3089 <meta name="robots" content="index, nofollow"/>
3090 <title>$title</title>
3092 # the stylesheet, favicon etc urls won't work correctly with path_info
3093 # unless we set the appropriate base URL
3094 if ($ENV{'PATH_INFO'}) {
3095 print "<base href=\"".esc_url
($base_url)."\" />\n";
3097 # print out each stylesheet that exist, providing backwards capability
3098 # for those people who defined $stylesheet in a config file
3099 if (defined $stylesheet) {
3100 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
3102 foreach my $stylesheet (@stylesheets) {
3103 next unless $stylesheet;
3104 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
3107 if (defined $project) {
3108 my %href_params = get_feed_info
();
3109 if (!exists $href_params{'-title'}) {
3110 $href_params{'-title'} = 'log';
3113 foreach my $format qw(RSS Atom) {
3114 my $type = lc($format);
3116 '-rel' => 'alternate',
3117 '-title' => "$project - $href_params{'-title'} - $format feed",
3118 '-type' => "application/$type+xml"
3121 $href_params{'action'} = $type;
3122 $link_attr{'-href'} = href
(%href_params);
3124 "rel=\"$link_attr{'-rel'}\" ".
3125 "title=\"$link_attr{'-title'}\" ".
3126 "href=\"$link_attr{'-href'}\" ".
3127 "type=\"$link_attr{'-type'}\" ".
3130 $href_params{'extra_options'} = '--no-merges';
3131 $link_attr{'-href'} = href
(%href_params);
3132 $link_attr{'-title'} .= ' (no merges)';
3134 "rel=\"$link_attr{'-rel'}\" ".
3135 "title=\"$link_attr{'-title'}\" ".
3136 "href=\"$link_attr{'-href'}\" ".
3137 "type=\"$link_attr{'-type'}\" ".
3142 printf('<link rel="alternate" title="%s projects list" '.
3143 'href="%s" type="text/plain; charset=utf-8" />'."\n",
3144 $site_name, href
(project
=>undef, action
=>"project_index"));
3145 printf('<link rel="alternate" title="%s projects feeds" '.
3146 'href="%s" type="text/x-opml" />'."\n",
3147 $site_name, href
(project
=>undef, action
=>"opml"));
3149 if (defined $favicon) {
3150 print qq(<link rel="shortcut icon" href="$favicon" type="image/png" />\n);
3156 if (-f
$site_header) {
3157 insert_file
($site_header);
3160 print "<div class=\"page_header\">\n" .
3161 $cgi->a({-href
=> esc_url
($logo_url),
3162 -title
=> $logo_label},
3163 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
3164 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
3165 if (defined $project) {
3166 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
3167 if (defined $action) {
3174 my $have_search = gitweb_check_feature
('search');
3175 if (defined $project && $have_search) {
3176 if (!defined $searchtext) {
3180 if (defined $hash_base) {
3181 $search_hash = $hash_base;
3182 } elsif (defined $hash) {
3183 $search_hash = $hash;
3185 $search_hash = "HEAD";
3187 my $action = $my_uri;
3188 my $use_pathinfo = gitweb_check_feature
('pathinfo');
3189 if ($use_pathinfo) {
3190 $action .= "/".esc_url
($project);
3192 print $cgi->startform(-method => "get", -action
=> $action) .
3193 "<div class=\"search\">\n" .
3195 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
3196 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
3197 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
3198 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
3199 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
3200 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
3202 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
3203 "<span title=\"Extended regular expression\">" .
3204 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
3205 -checked
=> $search_use_regexp) .
3208 $cgi->end_form() . "\n";
3212 sub git_footer_html
{
3213 my $feed_class = 'rss_logo';
3215 print "<div class=\"page_footer\">\n";
3216 if (defined $project) {
3217 my $descr = git_get_project_description
($project);
3218 if (defined $descr) {
3219 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
3222 my %href_params = get_feed_info
();
3223 if (!%href_params) {
3224 $feed_class .= ' generic';
3226 $href_params{'-title'} ||= 'log';
3228 foreach my $format qw(RSS Atom) {
3229 $href_params{'action'} = lc($format);
3230 print $cgi->a({-href
=> href
(%href_params),
3231 -title
=> "$href_params{'-title'} $format feed",
3232 -class => $feed_class}, $format)."\n";
3236 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
3237 -class => $feed_class}, "OPML") . " ";
3238 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
3239 -class => $feed_class}, "TXT") . "\n";
3241 print "</div>\n"; # class="page_footer"
3243 if (defined $t0 && gitweb_check_feature
('timed')) {
3244 print "<div id=\"generating_info\">\n";
3245 print 'This page took '.
3246 '<span id="generating_time" class="time_span">'.
3247 Time
::HiRes
::tv_interval
($t0, [Time
::HiRes
::gettimeofday
()]).
3250 '<span id="generating_cmd">'.
3251 $number_of_git_cmds.
3252 '</span> git commands '.
3254 print "</div>\n"; # class="page_footer"
3257 if (-f
$site_footer) {
3258 insert_file
($site_footer);
3261 print qq
!<script type
="text/javascript" src
="$javascript"></script
>\n!;
3262 if ($action eq 'blame_incremental') {
3263 print qq
!<script type
="text/javascript">\n!.
3264 qq
!startBlame
("!. href(action=>"blame_data
", -replay=>1) .qq!",\n!.
3265 qq
! "!. href() .qq!");\n!.
3268 print qq
!<script type
="text/javascript">\n!.
3269 qq
!window
.onload
= fixLinks
;\n!.
3277 # die_error(<http_status_code>, <error_message>)
3278 # Example: die_error(404, 'Hash not found')
3279 # By convention, use the following status codes (as defined in RFC 2616):
3280 # 400: Invalid or missing CGI parameters, or
3281 # requested object exists but has wrong type.
3282 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
3283 # this server or project.
3284 # 404: Requested object/revision/project doesn't exist.
3285 # 500: The server isn't configured properly, or
3286 # an internal error occurred (e.g. failed assertions caused by bugs), or
3287 # an unknown error occurred (e.g. the git binary died unexpectedly).
3289 my $status = shift || 500;
3290 my $error = shift || "Internal server error";
3292 my %http_responses = (400 => '400 Bad Request',
3293 403 => '403 Forbidden',
3294 404 => '404 Not Found',
3295 500 => '500 Internal Server Error');
3296 git_header_html
($http_responses{$status});
3298 <div class="page_body">
3308 ## ----------------------------------------------------------------------
3309 ## functions printing or outputting HTML: navigation
3311 sub git_print_page_nav
{
3312 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
3313 $extra = '' if !defined $extra; # pager or formats
3315 my @navs = qw(summary shortlog log commit commitdiff tree);
3317 @navs = grep { $_ ne $suppress } @navs;
3320 my %arg = map { $_ => {action
=>$_} } @navs;
3321 if (defined $head) {
3322 for (qw(commit commitdiff)) {
3323 $arg{$_}{'hash'} = $head;
3325 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
3326 for (qw(shortlog log)) {
3327 $arg{$_}{'hash'} = $head;
3332 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
3333 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
3335 my @actions = gitweb_get_feature
('actions');
3338 'n' => $project, # project name
3339 'f' => $git_dir, # project path within filesystem
3340 'h' => $treehead || '', # current hash ('h' parameter)
3341 'b' => $treebase || '', # hash base ('hb' parameter)
3344 my ($label, $link, $pos) = splice(@actions,0,3);
3346 @navs = map { $_ eq $pos ? ($_, $label) : $_ } @navs;
3348 $link =~ s/%([%nfhb])/$repl{$1}/g;
3349 $arg{$label}{'_href'} = $link;
3352 print "<div class=\"page_nav\">\n" .
3354 map { $_ eq $current ?
3355 $_ : $cgi->a({-href
=> ($arg{$_}{_href
} ? $arg{$_}{_href
} : href
(%{$arg{$_}}))}, "$_")
3357 print "<br/>\n$extra<br/>\n" .
3361 sub format_paging_nav
{
3362 my ($action, $hash, $head, $page, $has_next_link) = @_;
3366 if ($hash ne $head || $page) {
3367 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
3369 $paging_nav .= "HEAD";
3373 $paging_nav .= " ⋅ " .
3374 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
3375 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3377 $paging_nav .= " ⋅ prev";
3380 if ($has_next_link) {
3381 $paging_nav .= " ⋅ " .
3382 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
3383 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3385 $paging_nav .= " ⋅ next";
3391 ## ......................................................................
3392 ## functions printing or outputting HTML: div
3394 sub git_print_header_div
{
3395 my ($action, $title, $hash, $hash_base) = @_;
3398 $args{'action'} = $action;
3399 $args{'hash'} = $hash if $hash;
3400 $args{'hash_base'} = $hash_base if $hash_base;
3402 print "<div class=\"header\">\n" .
3403 $cgi->a({-href
=> href
(%args), -class => "title"},
3404 $title ? $title : $action) .
3408 sub print_local_time
{
3410 if ($date{'hour_local'} < 6) {
3411 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3412 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3414 printf(" (%02d:%02d %s)",
3415 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3419 # Outputs the author name and date in long form
3420 sub git_print_authorship
{
3423 my $tag = $opts{-tag
} || 'div';
3425 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
3426 print "<$tag class=\"author_date\">" .
3427 esc_html
($co->{'author_name'}) .
3429 print_local_time
(%ad) if ($opts{-localtime});
3430 print "]" . git_get_avatar
($co->{'author_email'}, -pad_before
=> 1)
3434 # Outputs table rows containing the full author or committer information,
3435 # in the format expected for 'commit' view (& similia).
3436 # Parameters are a commit hash reference, followed by the list of people
3437 # to output information for. If the list is empty it defalts to both
3438 # author and committer.
3439 sub git_print_authorship_rows
{
3441 # too bad we can't use @people = @_ || ('author', 'committer')
3443 @people = ('author', 'committer') unless @people;
3444 foreach my $who (@people) {
3445 my %wd = parse_date
($co->{"${who}_epoch"}, $co->{"${who}_tz"});
3446 print "<tr><td>$who</td><td>" . esc_html
($co->{$who}) . "</td>" .
3447 "<td rowspan=\"2\">" .
3448 git_get_avatar
($co->{"${who}_email"}, -size
=> 'double') .
3451 "<td></td><td> $wd{'rfc2822'}";
3452 print_local_time
(%wd);
3458 sub git_print_page_path
{
3464 print "<div class=\"page_path\">";
3465 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
3466 -title
=> 'tree root'}, to_utf8
("[$project]"));
3468 if (defined $name) {
3469 my @dirname = split '/', $name;
3470 my $basename = pop @dirname;
3473 foreach my $dir (@dirname) {
3474 $fullname .= ($fullname ? '/' : '') . $dir;
3475 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
3477 -title
=> $fullname}, esc_path
($dir));
3480 if (defined $type && $type eq 'blob') {
3481 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
3483 -title
=> $name}, esc_path
($basename));
3484 } elsif (defined $type && $type eq 'tree') {
3485 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
3487 -title
=> $name}, esc_path
($basename));
3490 print esc_path
($basename);
3493 print "<br/></div>\n";
3500 if ($opts{'-remove_title'}) {
3501 # remove title, i.e. first line of log
3504 # remove leading empty lines
3505 while (defined $log->[0] && $log->[0] eq "") {
3512 foreach my $line (@$log) {
3513 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
3516 if (! $opts{'-remove_signoff'}) {
3517 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
3520 # remove signoff lines
3527 # print only one empty line
3528 # do not print empty line after signoff
3530 next if ($empty || $signoff);
3536 print format_log_line_html
($line) . "<br/>\n";
3539 if ($opts{'-final_empty_line'}) {
3540 # end with single empty line
3541 print "<br/>\n" unless $empty;
3545 # return link target (what link points to)
3546 sub git_get_link_target
{
3551 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3555 $link_target = <$fd>;
3560 return $link_target;
3563 # given link target, and the directory (basedir) the link is in,
3564 # return target of link relative to top directory (top tree);
3565 # return undef if it is not possible (including absolute links).
3566 sub normalize_link_target
{
3567 my ($link_target, $basedir) = @_;
3569 # absolute symlinks (beginning with '/') cannot be normalized
3570 return if (substr($link_target, 0, 1) eq '/');
3572 # normalize link target to path from top (root) tree (dir)
3575 $path = $basedir . '/' . $link_target;
3577 # we are in top (root) tree (dir)
3578 $path = $link_target;
3581 # remove //, /./, and /../
3583 foreach my $part (split('/', $path)) {
3584 # discard '.' and ''
3585 next if (!$part || $part eq '.');
3587 if ($part eq '..') {
3591 # link leads outside repository (outside top dir)
3595 push @path_parts, $part;
3598 $path = join('/', @path_parts);
3603 # print tree entry (row of git_tree), but without encompassing <tr> element
3604 sub git_print_tree_entry
{
3605 my ($t, $basedir, $hash_base, $have_blame) = @_;
3608 $base_key{'hash_base'} = $hash_base if defined $hash_base;
3610 # The format of a table row is: mode list link. Where mode is
3611 # the mode of the entry, list is the name of the entry, an href,
3612 # and link is the action links of the entry.
3614 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
3615 if ($t->{'type'} eq "blob") {
3616 print "<td class=\"list\">" .
3617 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3618 file_name
=>"$basedir$t->{'name'}", %base_key),
3619 -class => "list"}, esc_path
($t->{'name'}));
3620 if (S_ISLNK
(oct $t->{'mode'})) {
3621 my $link_target = git_get_link_target
($t->{'hash'});
3623 my $norm_target = normalize_link_target
($link_target, $basedir);
3624 if (defined $norm_target) {
3626 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
3627 file_name
=>$norm_target),
3628 -title
=> $norm_target}, esc_path
($link_target));
3630 print " -> " . esc_path
($link_target);
3635 print "<td class=\"link\">";
3636 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3637 file_name
=>"$basedir$t->{'name'}", %base_key)},
3641 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
3642 file_name
=>"$basedir$t->{'name'}", %base_key)},
3645 if (defined $hash_base) {
3647 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3648 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
3652 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
3653 file_name
=>"$basedir$t->{'name'}")},
3657 } elsif ($t->{'type'} eq "tree") {
3658 print "<td class=\"list\">";
3659 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3660 file_name
=>"$basedir$t->{'name'}", %base_key)},
3661 esc_path
($t->{'name'}));
3663 print "<td class=\"link\">";
3664 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3665 file_name
=>"$basedir$t->{'name'}", %base_key)},
3667 if (defined $hash_base) {
3669 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3670 file_name
=>"$basedir$t->{'name'}")},
3675 # unknown object: we can only present history for it
3676 # (this includes 'commit' object, i.e. submodule support)
3677 print "<td class=\"list\">" .
3678 esc_path
($t->{'name'}) .
3680 print "<td class=\"link\">";
3681 if (defined $hash_base) {
3682 print $cgi->a({-href
=> href
(action
=>"history",
3683 hash_base
=>$hash_base,
3684 file_name
=>"$basedir$t->{'name'}")},
3691 ## ......................................................................
3692 ## functions printing large fragments of HTML
3694 # get pre-image filenames for merge (combined) diff
3695 sub fill_from_file_info
{
3696 my ($diff, @parents) = @_;
3698 $diff->{'from_file'} = [ ];
3699 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
3700 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3701 if ($diff->{'status'}[$i] eq 'R' ||
3702 $diff->{'status'}[$i] eq 'C') {
3703 $diff->{'from_file'}[$i] =
3704 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
3711 # is current raw difftree line of file deletion
3713 my $diffinfo = shift;
3715 return $diffinfo->{'to_id'} eq ('0' x
40);
3718 # does patch correspond to [previous] difftree raw line
3719 # $diffinfo - hashref of parsed raw diff format
3720 # $patchinfo - hashref of parsed patch diff format
3721 # (the same keys as in $diffinfo)
3722 sub is_patch_split
{
3723 my ($diffinfo, $patchinfo) = @_;
3725 return defined $diffinfo && defined $patchinfo
3726 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3730 sub git_difftree_body
{
3731 my ($difftree, $hash, @parents) = @_;
3732 my ($parent) = $parents[0];
3733 my $have_blame = gitweb_check_feature
('blame');
3734 print "<div class=\"list_head\">\n";
3735 if ($#{$difftree} > 10) {
3736 print(($#{$difftree} + 1) . " files changed:\n");
3740 print "<table class=\"" .
3741 (@parents > 1 ? "combined " : "") .
3744 # header only for combined diff in 'commitdiff' view
3745 my $has_header = @$difftree && @parents > 1 && $action eq 'commitdiff';
3748 print "<thead><tr>\n" .
3749 "<th></th><th></th>\n"; # filename, patchN link
3750 for (my $i = 0; $i < @parents; $i++) {
3751 my $par = $parents[$i];
3753 $cgi->a({-href
=> href
(action
=>"commitdiff",
3754 hash
=>$hash, hash_parent
=>$par),
3755 -title
=> 'commitdiff to parent number ' .
3756 ($i+1) . ': ' . substr($par,0,7)},
3760 print "</tr></thead>\n<tbody>\n";
3765 foreach my $line (@{$difftree}) {
3766 my $diff = parsed_difftree_line
($line);
3769 print "<tr class=\"dark\">\n";
3771 print "<tr class=\"light\">\n";
3775 if (exists $diff->{'nparents'}) { # combined diff
3777 fill_from_file_info
($diff, @parents)
3778 unless exists $diff->{'from_file'};
3780 if (!is_deleted
($diff)) {
3781 # file exists in the result (child) commit
3783 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3784 file_name
=>$diff->{'to_file'},
3786 -class => "list"}, esc_path
($diff->{'to_file'})) .
3790 esc_path
($diff->{'to_file'}) .
3794 if ($action eq 'commitdiff') {
3797 print "<td class=\"link\">" .
3798 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3803 my $has_history = 0;
3804 my $not_deleted = 0;
3805 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3806 my $hash_parent = $parents[$i];
3807 my $from_hash = $diff->{'from_id'}[$i];
3808 my $from_path = $diff->{'from_file'}[$i];
3809 my $status = $diff->{'status'}[$i];
3811 $has_history ||= ($status ne 'A');
3812 $not_deleted ||= ($status ne 'D');
3814 if ($status eq 'A') {
3815 print "<td class=\"link\" align=\"right\"> | </td>\n";
3816 } elsif ($status eq 'D') {
3817 print "<td class=\"link\">" .
3818 $cgi->a({-href
=> href
(action
=>"blob",
3821 file_name
=>$from_path)},
3825 if ($diff->{'to_id'} eq $from_hash) {
3826 print "<td class=\"link nochange\">";
3828 print "<td class=\"link\">";
3830 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3831 hash
=>$diff->{'to_id'},
3832 hash_parent
=>$from_hash,
3834 hash_parent_base
=>$hash_parent,
3835 file_name
=>$diff->{'to_file'},
3836 file_parent
=>$from_path)},
3842 print "<td class=\"link\">";
3844 print $cgi->a({-href
=> href
(action
=>"blob",
3845 hash
=>$diff->{'to_id'},
3846 file_name
=>$diff->{'to_file'},
3849 print " | " if ($has_history);
3852 print $cgi->a({-href
=> href
(action
=>"history",
3853 file_name
=>$diff->{'to_file'},
3860 next; # instead of 'else' clause, to avoid extra indent
3862 # else ordinary diff
3864 my ($to_mode_oct, $to_mode_str, $to_file_type);
3865 my ($from_mode_oct, $from_mode_str, $from_file_type);
3866 if ($diff->{'to_mode'} ne ('0' x
6)) {
3867 $to_mode_oct = oct $diff->{'to_mode'};
3868 if (S_ISREG
($to_mode_oct)) { # only for regular file
3869 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3871 $to_file_type = file_type
($diff->{'to_mode'});
3873 if ($diff->{'from_mode'} ne ('0' x
6)) {
3874 $from_mode_oct = oct $diff->{'from_mode'};
3875 if (S_ISREG
($to_mode_oct)) { # only for regular file
3876 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3878 $from_file_type = file_type
($diff->{'from_mode'});
3881 if ($diff->{'status'} eq "A") { # created
3882 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3883 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3884 $mode_chng .= "]</span>";
3886 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3887 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3888 -class => "list"}, esc_path
($diff->{'file'}));
3890 print "<td>$mode_chng</td>\n";
3891 print "<td class=\"link\">";
3892 if ($action eq 'commitdiff') {
3895 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3898 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3899 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3903 } elsif ($diff->{'status'} eq "D") { # deleted
3904 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3906 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3907 hash_base
=>$parent, file_name
=>$diff->{'file'}),
3908 -class => "list"}, esc_path
($diff->{'file'}));
3910 print "<td>$mode_chng</td>\n";
3911 print "<td class=\"link\">";
3912 if ($action eq 'commitdiff') {
3915 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3918 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3919 hash_base
=>$parent, file_name
=>$diff->{'file'})},
3922 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3923 file_name
=>$diff->{'file'})},
3926 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3927 file_name
=>$diff->{'file'})},
3931 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3932 my $mode_chnge = "";
3933 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3934 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3935 if ($from_file_type ne $to_file_type) {
3936 $mode_chnge .= " from $from_file_type to $to_file_type";
3938 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3939 if ($from_mode_str && $to_mode_str) {
3940 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3941 } elsif ($to_mode_str) {
3942 $mode_chnge .= " mode: $to_mode_str";
3945 $mode_chnge .= "]</span>\n";
3948 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3949 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3950 -class => "list"}, esc_path
($diff->{'file'}));
3952 print "<td>$mode_chnge</td>\n";
3953 print "<td class=\"link\">";
3954 if ($action eq 'commitdiff') {
3957 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3959 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3960 # "commit" view and modified file (not onlu mode changed)
3961 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3962 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3963 hash_base
=>$hash, hash_parent_base
=>$parent,
3964 file_name
=>$diff->{'file'})},
3968 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3969 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3972 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3973 file_name
=>$diff->{'file'})},
3976 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3977 file_name
=>$diff->{'file'})},
3981 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3982 my %status_name = ('R' => 'moved', 'C' => 'copied');
3983 my $nstatus = $status_name{$diff->{'status'}};
3985 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3986 # mode also for directories, so we cannot use $to_mode_str
3987 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3990 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3991 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
3992 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3993 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3994 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3995 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
3996 -class => "list"}, esc_path
($diff->{'from_file'})) .
3997 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3998 "<td class=\"link\">";
3999 if ($action eq 'commitdiff') {
4002 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
4004 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
4005 # "commit" view and modified file (not only pure rename or copy)
4006 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4007 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
4008 hash_base
=>$hash, hash_parent_base
=>$parent,
4009 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
4013 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4014 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
4017 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
4018 file_name
=>$diff->{'to_file'})},
4021 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
4022 file_name
=>$diff->{'to_file'})},
4026 } # we should not encounter Unmerged (U) or Unknown (X) status
4029 print "</tbody>" if $has_header;
4033 sub git_patchset_body
{
4034 my ($fd, $difftree, $hash, @hash_parents) = @_;
4035 my ($hash_parent) = $hash_parents[0];
4037 my $is_combined = (@hash_parents > 1);
4039 my $patch_number = 0;
4045 print "<div class=\"patchset\">\n";
4047 # skip to first patch
4048 while ($patch_line = <$fd>) {
4051 last if ($patch_line =~ m/^diff /);
4055 while ($patch_line) {
4057 # parse "git diff" header line
4058 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
4059 # $1 is from_name, which we do not use
4060 $to_name = unquote
($2);
4061 $to_name =~ s!^b/!!;
4062 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
4063 # $1 is 'cc' or 'combined', which we do not use
4064 $to_name = unquote
($2);
4069 # check if current patch belong to current raw line
4070 # and parse raw git-diff line if needed
4071 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
4072 # this is continuation of a split patch
4073 print "<div class=\"patch cont\">\n";
4075 # advance raw git-diff output if needed
4076 $patch_idx++ if defined $diffinfo;
4078 # read and prepare patch information
4079 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4081 # compact combined diff output can have some patches skipped
4082 # find which patch (using pathname of result) we are at now;
4084 while ($to_name ne $diffinfo->{'to_file'}) {
4085 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4086 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4087 "</div>\n"; # class="patch"
4092 last if $patch_idx > $#$difftree;
4093 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4097 # modifies %from, %to hashes
4098 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
4100 # this is first patch for raw difftree line with $patch_idx index
4101 # we index @$difftree array from 0, but number patches from 1
4102 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
4106 #assert($patch_line =~ m/^diff /) if DEBUG;
4107 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
4109 # print "git diff" header
4110 print format_git_diff_header_line
($patch_line, $diffinfo,
4113 # print extended diff header
4114 print "<div class=\"diff extended_header\">\n";
4116 while ($patch_line = <$fd>) {
4119 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
4121 print format_extended_diff_header_line
($patch_line, $diffinfo,
4124 print "</div>\n"; # class="diff extended_header"
4126 # from-file/to-file diff header
4127 if (! $patch_line) {
4128 print "</div>\n"; # class="patch"
4131 next PATCH
if ($patch_line =~ m/^diff /);
4132 #assert($patch_line =~ m/^---/) if DEBUG;
4134 my $last_patch_line = $patch_line;
4135 $patch_line = <$fd>;
4137 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
4139 print format_diff_from_to_header
($last_patch_line, $patch_line,
4140 $diffinfo, \
%from, \
%to,
4145 while ($patch_line = <$fd>) {
4148 next PATCH
if ($patch_line =~ m/^diff /);
4150 print format_diff_line
($patch_line, \
%from, \
%to);
4154 print "</div>\n"; # class="patch"
4157 # for compact combined (--cc) format, with chunk and patch simpliciaction
4158 # patchset might be empty, but there might be unprocessed raw lines
4159 for (++$patch_idx if $patch_number > 0;
4160 $patch_idx < @$difftree;
4162 # read and prepare patch information
4163 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4165 # generate anchor for "patch" links in difftree / whatchanged part
4166 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4167 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4168 "</div>\n"; # class="patch"
4173 if ($patch_number == 0) {
4174 if (@hash_parents > 1) {
4175 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
4177 print "<div class=\"diff nodifferences\">No differences found</div>\n";
4181 print "</div>\n"; # class="patchset"
4184 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4186 # fills project list info (age, description, owner, forks) for each
4187 # project in the list, removing invalid projects from returned list
4188 # NOTE: modifies $projlist, but does not remove entries from it
4189 sub fill_project_list_info
{
4190 my ($projlist, $check_forks) = @_;
4193 my $show_ctags = gitweb_check_feature
('ctags');
4195 foreach my $pr (@$projlist) {
4196 my (@activity) = git_get_last_activity
($pr->{'path'});
4197 unless (@activity) {
4200 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
4201 if (!defined $pr->{'descr'}) {
4202 my $descr = git_get_project_description
($pr->{'path'}) || "";
4203 $descr = to_utf8
($descr);
4204 $pr->{'descr_long'} = $descr;
4205 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
4207 if (!defined $pr->{'owner'}) {
4208 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
4211 my $pname = $pr->{'path'};
4212 if (($pname =~ s/\.git$//) &&
4213 ($pname !~ /\/$/) &&
4214 (-d
"$projectroot/$pname")) {
4215 $pr->{'forks'} = "-d $projectroot/$pname";
4220 $show_ctags and $pr->{'ctags'} = git_get_project_ctags
($pr->{'path'});
4221 push @projects, $pr;
4227 # print 'sort by' <th> element, generating 'sort by $name' replay link
4228 # if that order is not selected
4230 my ($name, $order, $header) = @_;
4231 $header ||= ucfirst($name);
4233 if ($order eq $name) {
4234 print "<th>$header</th>\n";
4237 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
4238 -class => "header"}, $header) .
4243 sub git_project_list_body
{
4244 # actually uses global variable $project
4245 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
4247 my $check_forks = gitweb_check_feature
('forks');
4248 my @projects = fill_project_list_info
($projlist, $check_forks);
4250 $order ||= $default_projects_order;
4251 $from = 0 unless defined $from;
4252 $to = $#projects if (!defined $to || $#projects < $to);
4255 project
=> { key
=> 'path', type
=> 'str' },
4256 descr
=> { key
=> 'descr_long', type
=> 'str' },
4257 owner
=> { key
=> 'owner', type
=> 'str' },
4258 age
=> { key
=> 'age', type
=> 'num' }
4260 my $oi = $order_info{$order};
4261 if ($oi->{'type'} eq 'str') {
4262 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
4264 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
4267 my $show_ctags = gitweb_check_feature
('ctags');
4270 foreach my $p (@projects) {
4271 foreach my $ct (keys %{$p->{'ctags'}}) {
4272 $ctags{$ct} += $p->{'ctags'}->{$ct};
4275 my $cloud = git_populate_project_tagcloud
(\
%ctags);
4276 print git_show_project_tagcloud
($cloud, 64);
4279 print "<table class=\"project_list\">\n";
4280 unless ($no_header) {
4283 print "<th></th>\n";
4285 print_sort_th
('project', $order, 'Project');
4286 print_sort_th
('descr', $order, 'Description');
4287 print_sort_th
('owner', $order, 'Owner');
4288 print_sort_th
('age', $order, 'Last Change');
4289 print "<th></th>\n" . # for links
4293 my $tagfilter = $cgi->param('by_tag');
4294 for (my $i = $from; $i <= $to; $i++) {
4295 my $pr = $projects[$i];
4297 next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}};
4298 next if $searchtext and not $pr->{'path'} =~ /$searchtext/
4299 and not $pr->{'descr_long'} =~ /$searchtext/;
4300 # Weed out forks or non-matching entries of search
4302 my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s
#\.git$#/#;
4303 $forkbase="^$forkbase" if $forkbase;
4304 next if not $searchtext and not $tagfilter and $show_ctags
4305 and $pr->{'path'} =~ m
#$forkbase.*/.*#; # regexp-safe
4309 print "<tr class=\"dark\">\n";
4311 print "<tr class=\"light\">\n";
4316 if ($pr->{'forks'}) {
4317 print "<!-- $pr->{'forks'} -->\n";
4318 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
4322 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4323 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
4324 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4325 -class => "list", -title
=> $pr->{'descr_long'}},
4326 esc_html
($pr->{'descr'})) . "</td>\n" .
4327 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
4328 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
4329 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
4330 "<td class=\"link\">" .
4331 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
4332 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
4333 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
4334 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
4335 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
4339 if (defined $extra) {
4342 print "<td></td>\n";
4344 print "<td colspan=\"5\">$extra</td>\n" .
4350 sub git_shortlog_body
{
4351 # uses global variable $project
4352 my ($commitlist, $from, $to, $refs, $extra) = @_;
4354 $from = 0 unless defined $from;
4355 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4357 print "<table class=\"shortlog\">\n";
4359 for (my $i = $from; $i <= $to; $i++) {
4360 my %co = %{$commitlist->[$i]};
4361 my $commit = $co{'id'};
4362 my $ref = format_ref_marker
($refs, $commit);
4364 print "<tr class=\"dark\">\n";
4366 print "<tr class=\"light\">\n";
4369 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
4370 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4371 format_author_html
('td', \
%co, 10) . "<td>";
4372 print format_subject_html
($co{'title'}, $co{'title_short'},
4373 href
(action
=>"commit", hash
=>$commit), $ref);
4375 "<td class=\"link\">" .
4376 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
4377 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
4378 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
4379 my $snapshot_links = format_snapshot_links
($commit);
4380 if (defined $snapshot_links) {
4381 print " | " . $snapshot_links;
4386 if (defined $extra) {
4388 "<td colspan=\"4\">$extra</td>\n" .
4394 sub git_history_body
{
4395 # Warning: assumes constant type (blob or tree) during history
4396 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
4398 $from = 0 unless defined $from;
4399 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
4401 print "<table class=\"history\">\n";
4403 for (my $i = $from; $i <= $to; $i++) {
4404 my %co = %{$commitlist->[$i]};
4408 my $commit = $co{'id'};
4410 my $ref = format_ref_marker
($refs, $commit);
4413 print "<tr class=\"dark\">\n";
4415 print "<tr class=\"light\">\n";
4418 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4419 # shortlog: format_author_html('td', \%co, 10)
4420 format_author_html
('td', \
%co, 15, 3) . "<td>";
4421 # originally git_history used chop_str($co{'title'}, 50)
4422 print format_subject_html
($co{'title'}, $co{'title_short'},
4423 href
(action
=>"commit", hash
=>$commit), $ref);
4425 "<td class=\"link\">" .
4426 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
4427 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
4429 if ($ftype eq 'blob') {
4430 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
4431 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
4432 if (defined $blob_current && defined $blob_parent &&
4433 $blob_current ne $blob_parent) {
4435 $cgi->a({-href
=> href
(action
=>"blobdiff",
4436 hash
=>$blob_current, hash_parent
=>$blob_parent,
4437 hash_base
=>$hash_base, hash_parent_base
=>$commit,
4438 file_name
=>$file_name)},
4445 if (defined $extra) {
4447 "<td colspan=\"4\">$extra</td>\n" .
4454 # uses global variable $project
4455 my ($taglist, $from, $to, $extra) = @_;
4456 $from = 0 unless defined $from;
4457 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
4459 print "<table class=\"tags\">\n";
4461 for (my $i = $from; $i <= $to; $i++) {
4462 my $entry = $taglist->[$i];
4464 my $comment = $tag{'subject'};
4466 if (defined $comment) {
4467 $comment_short = chop_str
($comment, 30, 5);
4470 print "<tr class=\"dark\">\n";
4472 print "<tr class=\"light\">\n";
4475 if (defined $tag{'age'}) {
4476 print "<td><i>$tag{'age'}</i></td>\n";
4478 print "<td></td>\n";
4481 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
4482 -class => "list name"}, esc_html
($tag{'name'})) .
4485 if (defined $comment) {
4486 print format_subject_html
($comment, $comment_short,
4487 href
(action
=>"tag", hash
=>$tag{'id'}));
4490 "<td class=\"selflink\">";
4491 if ($tag{'type'} eq "tag") {
4492 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
4497 "<td class=\"link\">" . " | " .
4498 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
4499 if ($tag{'reftype'} eq "commit") {
4500 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
4501 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
4502 } elsif ($tag{'reftype'} eq "blob") {
4503 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
4508 if (defined $extra) {
4510 "<td colspan=\"5\">$extra</td>\n" .
4516 sub git_heads_body
{
4517 # uses global variable $project
4518 my ($headlist, $head, $from, $to, $extra) = @_;
4519 $from = 0 unless defined $from;
4520 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
4522 print "<table class=\"heads\">\n";
4524 for (my $i = $from; $i <= $to; $i++) {
4525 my $entry = $headlist->[$i];
4527 my $curr = $ref{'id'} eq $head;
4529 print "<tr class=\"dark\">\n";
4531 print "<tr class=\"light\">\n";
4534 print "<td><i>$ref{'age'}</i></td>\n" .
4535 ($curr ? "<td class=\"current_head\">" : "<td>") .
4536 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
4537 -class => "list name"},esc_html
($ref{'name'})) .
4539 "<td class=\"link\">" .
4540 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
4541 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
4542 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
4546 if (defined $extra) {
4548 "<td colspan=\"3\">$extra</td>\n" .
4554 sub git_search_grep_body
{
4555 my ($commitlist, $from, $to, $extra) = @_;
4556 $from = 0 unless defined $from;
4557 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4559 print "<table class=\"commit_search\">\n";
4561 for (my $i = $from; $i <= $to; $i++) {
4562 my %co = %{$commitlist->[$i]};
4566 my $commit = $co{'id'};
4568 print "<tr class=\"dark\">\n";
4570 print "<tr class=\"light\">\n";
4573 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4574 format_author_html
('td', \
%co, 15, 5) .
4576 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4577 -class => "list subject"},
4578 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
4579 my $comment = $co{'comment'};
4580 foreach my $line (@$comment) {
4581 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
4582 my ($lead, $match, $trail) = ($1, $2, $3);
4583 $match = chop_str
($match, 70, 5, 'center');
4584 my $contextlen = int((80 - length($match))/2);
4585 $contextlen = 30 if ($contextlen > 30);
4586 $lead = chop_str
($lead, $contextlen, 10, 'left');
4587 $trail = chop_str
($trail, $contextlen, 10, 'right');
4589 $lead = esc_html
($lead);
4590 $match = esc_html
($match);
4591 $trail = esc_html
($trail);
4593 print "$lead<span class=\"match\">$match</span>$trail<br />";
4597 "<td class=\"link\">" .
4598 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4600 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
4602 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4606 if (defined $extra) {
4608 "<td colspan=\"3\">$extra</td>\n" .
4614 ## ======================================================================
4615 ## ======================================================================
4618 sub git_project_list
{
4619 my $order = $input_params{'order'};
4620 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4621 die_error
(400, "Unknown order parameter");
4624 my @list = git_get_projects_list
();
4626 die_error
(404, "No projects found");
4630 if (-f
$home_text) {
4631 print "<div class=\"index_include\">\n";
4632 insert_file
($home_text);
4635 print $cgi->startform(-method => "get") .
4636 "<p class=\"projsearch\">Search:\n" .
4637 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
4639 $cgi->end_form() . "\n";
4640 git_project_list_body
(\
@list, $order);
4645 my $order = $input_params{'order'};
4646 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4647 die_error
(400, "Unknown order parameter");
4650 my @list = git_get_projects_list
($project);
4652 die_error
(404, "No forks found");
4656 git_print_page_nav
('','');
4657 git_print_header_div
('summary', "$project forks");
4658 git_project_list_body
(\
@list, $order);
4662 sub git_project_index
{
4663 my @projects = git_get_projects_list
($project);
4666 -type
=> 'text/plain',
4667 -charset
=> 'utf-8',
4668 -content_disposition
=> 'inline; filename="index.aux"');
4670 foreach my $pr (@projects) {
4671 if (!exists $pr->{'owner'}) {
4672 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
4675 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
4676 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
4677 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4678 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4682 print "$path $owner\n";
4687 my $descr = git_get_project_description
($project) || "none";
4688 my %co = parse_commit
("HEAD");
4689 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
4690 my $head = $co{'id'};
4692 my $owner = git_get_project_owner
($project);
4694 my $refs = git_get_references
();
4695 # These get_*_list functions return one more to allow us to see if
4696 # there are more ...
4697 my @taglist = git_get_tags_list
(16);
4698 my @headlist = git_get_heads_list
(16);
4700 my $check_forks = gitweb_check_feature
('forks');
4703 @forklist = git_get_projects_list
($project);
4707 git_print_page_nav
('summary','', $head);
4709 print "<div class=\"title\"> </div>\n";
4710 print "<table class=\"projects_list\">\n" .
4711 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
4712 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
4713 if (defined $cd{'rfc2822'}) {
4714 print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4717 # use per project git URL list in $projectroot/$project/cloneurl
4718 # or make project git URL from git base URL and project name
4719 my $url_tag = "URL";
4720 my @url_list = git_get_project_url_list
($project);
4721 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4722 foreach my $git_url (@url_list) {
4723 next unless $git_url;
4724 print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";
4729 my $show_ctags = gitweb_check_feature
('ctags');
4731 my $ctags = git_get_project_ctags
($project);
4732 my $cloud = git_populate_project_tagcloud
($ctags);
4733 print "<tr id=\"metadata_ctags\"><td>Content tags:<br />";
4734 print "</td>\n<td>" unless %$ctags;
4735 print "<form action=\"$show_ctags\" method=\"post\"><input type=\"hidden\" name=\"p\" value=\"$project\" />Add: <input type=\"text\" name=\"t\" size=\"8\" /></form>";
4736 print "</td>\n<td>" if %$ctags;
4737 print git_show_project_tagcloud
($cloud, 48);
4743 # If XSS prevention is on, we don't include README.html.
4744 # TODO: Allow a readme in some safe format.
4745 if (!$prevent_xss && -s
"$projectroot/$project/README.html") {
4746 print "<div class=\"title\">readme</div>\n" .
4747 "<div class=\"readme\">\n";
4748 insert_file
("$projectroot/$project/README.html");
4749 print "\n</div>\n"; # class="readme"
4752 # we need to request one more than 16 (0..15) to check if
4754 my @commitlist = $head ? parse_commits
($head, 17) : ();
4756 git_print_header_div
('shortlog');
4757 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
4758 $#commitlist <= 15 ? undef :
4759 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
4763 git_print_header_div
('tags');
4764 git_tags_body
(\
@taglist, 0, 15,
4765 $#taglist <= 15 ? undef :
4766 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
4770 git_print_header_div
('heads');
4771 git_heads_body
(\
@headlist, $head, 0, 15,
4772 $#headlist <= 15 ? undef :
4773 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
4777 git_print_header_div
('forks');
4778 git_project_list_body
(\
@forklist, 'age', 0, 15,
4779 $#forklist <= 15 ? undef :
4780 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
4788 my $head = git_get_head_hash
($project);
4790 git_print_page_nav
('','', $head,undef,$head);
4791 my %tag = parse_tag
($hash);
4794 die_error
(404, "Unknown tag object");
4797 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
4798 print "<div class=\"title_text\">\n" .
4799 "<table class=\"object_header\">\n" .
4801 "<td>object</td>\n" .
4802 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4803 $tag{'object'}) . "</td>\n" .
4804 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4805 $tag{'type'}) . "</td>\n" .
4807 if (defined($tag{'author'})) {
4808 git_print_authorship_rows
(\
%tag, 'author');
4810 print "</table>\n\n" .
4812 print "<div class=\"page_body\">";
4813 my $comment = $tag{'comment'};
4814 foreach my $line (@$comment) {
4816 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4822 sub git_blame_common
{
4823 my $format = shift || 'porcelain';
4824 if ($format eq 'porcelain' && $cgi->param('js')) {
4825 $format = 'incremental';
4826 $action = 'blame_incremental'; # for page title etc
4830 gitweb_check_feature
('blame')
4831 or die_error
(403, "Blame view not allowed");
4834 die_error
(400, "No file name given") unless $file_name;
4835 $hash_base ||= git_get_head_hash
($project);
4836 die_error
(404, "Couldn't find base commit") unless $hash_base;
4837 my %co = parse_commit
($hash_base)
4838 or die_error
(404, "Commit not found");
4840 if (!defined $hash) {
4841 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4842 or die_error
(404, "Error looking up file");
4844 $ftype = git_get_type
($hash);
4845 if ($ftype !~ "blob") {
4846 die_error
(400, "Object is not a blob");
4851 if ($format eq 'incremental') {
4852 # get file contents (as base)
4853 open $fd, "-|", git_cmd
(), 'cat-file', 'blob', $hash
4854 or die_error
(500, "Open git-cat-file failed");
4855 } elsif ($format eq 'data') {
4856 # run git-blame --incremental
4857 open $fd, "-|", git_cmd
(), "blame", "--incremental",
4858 $hash_base, "--", $file_name
4859 or die_error
(500, "Open git-blame --incremental failed");
4861 # run git-blame --porcelain
4862 open $fd, "-|", git_cmd
(), "blame", '-p',
4863 $hash_base, '--', $file_name
4864 or die_error
(500, "Open git-blame --porcelain failed");
4867 # incremental blame data returns early
4868 if ($format eq 'data') {
4870 -type
=>"text/plain", -charset
=> "utf-8",
4871 -status
=> "200 OK");
4872 local $| = 1; # output autoflush
4875 or print "ERROR $!\n";
4878 if (defined $t0 && gitweb_check_feature
('timed')) {
4880 Time
::HiRes
::tv_interval
($t0, [Time
::HiRes
::gettimeofday
()]).
4881 ' '.$number_of_git_cmds;
4891 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
4894 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4897 $cgi->a({-href
=> href
(action
=>$action, file_name
=>$file_name)},
4899 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4900 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4901 git_print_page_path
($file_name, $ftype, $hash_base);
4904 if ($format eq 'incremental') {
4905 print "<noscript>\n<div class=\"error\"><center><b>\n".
4906 "This page requires JavaScript to run.\n Use ".
4907 $cgi->a({-href
=> href
(action
=>'blame',javascript
=>0,-replay
=>1)},
4910 "</b></center></div>\n</noscript>\n";
4912 print qq
!<div id
="progress_bar" style
="width: 100%; background-color: yellow"></div
>\n!;
4915 print qq
!<div
class="page_body">\n!;
4916 print qq
!<div id
="progress_info">... / ...</div
>\n!
4917 if ($format eq 'incremental');
4918 print qq
!<table id
="blame_table" class="blame" width
="100%">\n!.
4919 #qq!<col width="5.5em" /><col width="2.5em" /><col width="*" />\n!.
4921 qq
!<tr
><th
>Commit
</th><th>Line</th
><th
>Data
</th></tr
>\n!.
4925 my @rev_color = qw(light dark);
4926 my $num_colors = scalar(@rev_color);
4927 my $current_color = 0;
4929 if ($format eq 'incremental') {
4930 my $color_class = $rev_color[$current_color];
4935 while (my $line = <$fd>) {
4939 print qq
!<tr id
="l$linenr" class="$color_class">!.
4940 qq
!<td
class="sha1"><a href
=""> </a></td
>!.
4941 qq
!<td
class="linenr">!.
4942 qq
!<a
class="linenr" href
="">$linenr</a></td
>!;
4943 print qq
!<td
class="pre">! . esc_html
($line) . "</td>\n";
4947 } else { # porcelain, i.e. ordinary blame
4948 my %metainfo = (); # saves information about commits
4952 while (my $line = <$fd>) {
4954 # the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]
4955 # no <lines in group> for subsequent lines in group of lines
4956 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4957 ($line =~ /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);
4958 if (!exists $metainfo{$full_rev}) {
4959 $metainfo{$full_rev} = { 'nprevious' => 0 };
4961 my $meta = $metainfo{$full_rev};
4963 while ($data = <$fd>) {
4965 last if ($data =~ s/^\t//); # contents of line
4966 if ($data =~ /^(\S+)(?: (.*))?$/) {
4967 $meta->{$1} = $2 unless exists $meta->{$1};
4969 if ($data =~ /^previous /) {
4970 $meta->{'nprevious'}++;
4973 my $short_rev = substr($full_rev, 0, 8);
4974 my $author = $meta->{'author'};
4976 parse_date
($meta->{'author-time'}, $meta->{'author-tz'});
4977 my $date = $date{'iso-tz'};
4979 $current_color = ($current_color + 1) % $num_colors;
4981 my $tr_class = $rev_color[$current_color];
4982 $tr_class .= ' boundary' if (exists $meta->{'boundary'});
4983 $tr_class .= ' no-previous' if ($meta->{'nprevious'} == 0);
4984 $tr_class .= ' multiple-previous' if ($meta->{'nprevious'} > 1);
4985 print "<tr id=\"l$lineno\" class=\"$tr_class\">\n";
4987 print "<td class=\"sha1\"";
4988 print " title=\"". esc_html
($author) . ", $date\"";
4989 print " rowspan=\"$group_size\"" if ($group_size > 1);
4991 print $cgi->a({-href
=> href
(action
=>"commit",
4993 file_name
=>$file_name)},
4994 esc_html
($short_rev));
4995 if ($group_size >= 2) {
4996 my @author_initials = ($author =~ /\b([[:upper:]])\B/g);
4997 if (@author_initials) {
4999 esc_html
(join('', @author_initials));
5005 # 'previous' <sha1 of parent commit> <filename at commit>
5006 if (exists $meta->{'previous'} &&
5007 $meta->{'previous'} =~ /^([a-fA-F0-9]{40}) (.*)$/) {
5008 $meta->{'parent'} = $1;
5009 $meta->{'file_parent'} = unquote
($2);
5012 exists($meta->{'parent'}) ?
5013 $meta->{'parent'} : $full_rev;
5014 my $linenr_filename =
5015 exists($meta->{'file_parent'}) ?
5016 $meta->{'file_parent'} : unquote
($meta->{'filename'});
5017 my $blamed = href
(action
=> 'blame',
5018 file_name
=> $linenr_filename,
5019 hash_base
=> $linenr_commit);
5020 print "<td class=\"linenr\">";
5021 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
5022 -class => "linenr" },
5025 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
5033 "</table>\n"; # class="blame"
5034 print "</div>\n"; # class="blame_body"
5036 or print "Reading blob failed\n";
5045 sub git_blame_incremental
{
5046 git_blame_common
('incremental');
5049 sub git_blame_data
{
5050 git_blame_common
('data');
5054 my $head = git_get_head_hash
($project);
5056 git_print_page_nav
('','', $head,undef,$head);
5057 git_print_header_div
('summary', $project);
5059 my @tagslist = git_get_tags_list
();
5061 git_tags_body
(\
@tagslist);
5067 my $head = git_get_head_hash
($project);
5069 git_print_page_nav
('','', $head,undef,$head);
5070 git_print_header_div
('summary', $project);
5072 my @headslist = git_get_heads_list
();
5074 git_heads_body
(\
@headslist, $head);
5079 sub git_blob_plain
{
5083 if (!defined $hash) {
5084 if (defined $file_name) {
5085 my $base = $hash_base || git_get_head_hash
($project);
5086 $hash = git_get_hash_by_path
($base, $file_name, "blob")
5087 or die_error
(404, "Cannot find file");
5089 die_error
(400, "No file name defined");
5091 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5092 # blobs defined by non-textual hash id's can be cached
5096 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
5097 or die_error
(500, "Open git-cat-file blob '$hash' failed");
5099 # content-type (can include charset)
5100 $type = blob_contenttype
($fd, $file_name, $type);
5102 # "save as" filename, even when no $file_name is given
5103 my $save_as = "$hash";
5104 if (defined $file_name) {
5105 $save_as = $file_name;
5106 } elsif ($type =~ m/^text\//) {
5110 # With XSS prevention on, blobs of all types except a few known safe
5111 # ones are served with "Content-Disposition: attachment" to make sure
5112 # they don't run in our security domain. For certain image types,
5113 # blob view writes an <img> tag referring to blob_plain view, and we
5114 # want to be sure not to break that by serving the image as an
5115 # attachment (though Firefox 3 doesn't seem to care).
5116 my $sandbox = $prevent_xss &&
5117 $type !~ m!^(?:text/plain|image/(?:gif|png|jpeg))$!;
5121 -expires
=> $expires,
5122 -content_disposition
=>
5123 ($sandbox ? 'attachment' : 'inline')
5124 . '; filename="' . $save_as . '"');
5126 binmode STDOUT
, ':raw';
5128 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5135 if (!defined $hash) {
5136 if (defined $file_name) {
5137 my $base = $hash_base || git_get_head_hash
($project);
5138 $hash = git_get_hash_by_path
($base, $file_name, "blob")
5139 or die_error
(404, "Cannot find file");
5141 die_error
(400, "No file name defined");
5143 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5144 # blobs defined by non-textual hash id's can be cached
5148 my $have_blame = gitweb_check_feature
('blame');
5149 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
5150 or die_error
(500, "Couldn't cat $file_name, $hash");
5151 my $mimetype = blob_mimetype
($fd, $file_name);
5152 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
5154 return git_blob_plain
($mimetype);
5156 # we can have blame only for text/* mimetype
5157 $have_blame &&= ($mimetype =~ m!^text/!);
5159 git_header_html
(undef, $expires);
5160 my $formats_nav = '';
5161 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5162 if (defined $file_name) {
5165 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
5170 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5173 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5176 $cgi->a({-href
=> href
(action
=>"blob",
5177 hash_base
=>"HEAD", file_name
=>$file_name)},
5181 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5184 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5185 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5187 print "<div class=\"page_nav\">\n" .
5188 "<br/><br/></div>\n" .
5189 "<div class=\"title\">$hash</div>\n";
5191 git_print_page_path
($file_name, "blob", $hash_base);
5192 print "<div class=\"page_body\">\n";
5193 if ($mimetype =~ m!^image/!) {
5194 print qq
!<img type
="$mimetype"!;
5196 print qq
! alt
="$file_name" title
="$file_name"!;
5199 href(action=>"blob_plain
", hash=>$hash,
5200 hash_base=>$hash_base, file_name=>$file_name) .
5204 while (my $line = <$fd>) {
5207 $line = untabify
($line);
5208 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
5209 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
5213 or print "Reading blob failed.\n";
5219 if (!defined $hash_base) {
5220 $hash_base = "HEAD";
5222 if (!defined $hash) {
5223 if (defined $file_name) {
5224 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
5229 die_error
(404, "No such tree") unless defined($hash);
5234 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
5235 or die_error
(500, "Open git-ls-tree failed");
5236 @entries = map { chomp; $_ } <$fd>;
5238 or die_error
(404, "Reading tree failed");
5241 my $refs = git_get_references
();
5242 my $ref = format_ref_marker
($refs, $hash_base);
5245 my $have_blame = gitweb_check_feature
('blame');
5246 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5248 if (defined $file_name) {
5250 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5252 $cgi->a({-href
=> href
(action
=>"tree",
5253 hash_base
=>"HEAD", file_name
=>$file_name)},
5256 my $snapshot_links = format_snapshot_links
($hash);
5257 if (defined $snapshot_links) {
5258 # FIXME: Should be available when we have no hash base as well.
5259 push @views_nav, $snapshot_links;
5261 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
5262 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
5265 print "<div class=\"page_nav\">\n";
5266 print "<br/><br/></div>\n";
5267 print "<div class=\"title\">$hash</div>\n";
5269 if (defined $file_name) {
5270 $basedir = $file_name;
5271 if ($basedir ne '' && substr($basedir, -1) ne '/') {
5274 git_print_page_path
($file_name, 'tree', $hash_base);
5276 print "<div class=\"page_body\">\n";
5277 print "<table class=\"tree\">\n";
5279 # '..' (top directory) link if possible
5280 if (defined $hash_base &&
5281 defined $file_name && $file_name =~ m![^/]+$!) {
5283 print "<tr class=\"dark\">\n";
5285 print "<tr class=\"light\">\n";
5289 my $up = $file_name;
5290 $up =~ s!/?[^/]+$!!;
5291 undef $up unless $up;
5292 # based on git_print_tree_entry
5293 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
5294 print '<td class="list">';
5295 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
5299 print "<td class=\"link\"></td>\n";
5303 foreach my $line (@entries) {
5304 my %t = parse_ls_tree_line
($line, -z
=> 1);
5307 print "<tr class=\"dark\">\n";
5309 print "<tr class=\"light\">\n";
5313 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
5317 print "</table>\n" .
5323 my $format = $input_params{'snapshot_format'};
5324 if (!@snapshot_fmts) {
5325 die_error
(403, "Snapshots not allowed");
5327 # default to first supported snapshot format
5328 $format ||= $snapshot_fmts[0];
5329 if ($format !~ m/^[a-z0-9]+$/) {
5330 die_error
(400, "Invalid snapshot format parameter");
5331 } elsif (!exists($known_snapshot_formats{$format})) {
5332 die_error
(400, "Unknown snapshot format");
5333 } elsif ($known_snapshot_formats{$format}{'disabled'}) {
5334 die_error
(403, "Snapshot format not allowed");
5335 } elsif (!grep($_ eq $format, @snapshot_fmts)) {
5336 die_error
(403, "Unsupported snapshot format");
5339 if (!defined $hash) {
5340 $hash = git_get_head_hash
($project);
5343 my $name = $project;
5344 $name =~ s
,([^/])/*\
.git
$,$1,;
5345 $name = basename
($name);
5346 my $filename = to_utf8
($name);
5347 $name =~ s/\047/\047\\\047\047/g;
5349 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
5350 $cmd = quote_command
(
5351 git_cmd
(), 'archive',
5352 "--format=$known_snapshot_formats{$format}{'format'}",
5353 "--prefix=$name/", $hash);
5354 if (exists $known_snapshot_formats{$format}{'compressor'}) {
5355 $cmd .= ' | ' . quote_command
(@{$known_snapshot_formats{$format}{'compressor'}});
5359 -type
=> $known_snapshot_formats{$format}{'type'},
5360 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
5361 -status
=> '200 OK');
5363 open my $fd, "-|", $cmd
5364 or die_error
(500, "Execute git-archive failed");
5365 binmode STDOUT
, ':raw';
5367 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5372 my $head = git_get_head_hash
($project);
5373 if (!defined $hash) {
5376 if (!defined $page) {
5379 my $refs = git_get_references
();
5381 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5383 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#commitlist >= 100);
5385 my ($patch_max) = gitweb_get_feature
('patches');
5387 if ($patch_max < 0 || @commitlist <= $patch_max) {
5388 $paging_nav .= " ⋅ " .
5389 $cgi->a({-href
=> href
(action
=>"patches", -replay
=>1)},
5395 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
5398 my %co = parse_commit
($hash);
5400 git_print_header_div
('summary', $project);
5401 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
5403 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
5404 for (my $i = 0; $i <= $to; $i++) {
5405 my %co = %{$commitlist[$i]};
5407 my $commit = $co{'id'};
5408 my $ref = format_ref_marker
($refs, $commit);
5409 my %ad = parse_date
($co{'author_epoch'});
5410 git_print_header_div
('commit',
5411 "<span class=\"age\">$co{'age_string'}</span>" .
5412 esc_html
($co{'title'}) . $ref,
5414 print "<div class=\"title_text\">\n" .
5415 "<div class=\"log_link\">\n" .
5416 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
5418 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
5420 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
5423 git_print_authorship
(\
%co, -tag
=> 'span');
5424 print "<br/>\n</div>\n";
5426 print "<div class=\"log_body\">\n";
5427 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
5430 if ($#commitlist >= 100) {
5431 print "<div class=\"page_nav\">\n";
5432 print $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5433 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5440 $hash ||= $hash_base || "HEAD";
5441 my %co = parse_commit
($hash)
5442 or die_error
(404, "Unknown commit object");
5444 my $parent = $co{'parent'};
5445 my $parents = $co{'parents'}; # listref
5447 # we need to prepare $formats_nav before any parameter munging
5449 if (!defined $parent) {
5451 $formats_nav .= '(initial)';
5452 } elsif (@$parents == 1) {
5453 # single parent commit
5456 $cgi->a({-href
=> href
(action
=>"commit",
5458 esc_html
(substr($parent, 0, 7))) .
5465 $cgi->a({-href
=> href
(action
=>"commit",
5467 esc_html
(substr($_, 0, 7)));
5471 if (gitweb_check_feature
('patches')) {
5472 $formats_nav .= " | " .
5473 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
5477 if (!defined $parent) {
5481 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
5483 (@$parents <= 1 ? $parent : '-c'),
5485 or die_error
(500, "Open git-diff-tree failed");
5486 @difftree = map { chomp; $_ } <$fd>;
5487 close $fd or die_error
(404, "Reading git-diff-tree failed");
5489 # non-textual hash id's can be cached
5491 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5494 my $refs = git_get_references
();
5495 my $ref = format_ref_marker
($refs, $co{'id'});
5497 git_header_html
(undef, $expires);
5498 git_print_page_nav
('commit', '',
5499 $hash, $co{'tree'}, $hash,
5502 if (defined $co{'parent'}) {
5503 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
5505 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
5507 print "<div class=\"title_text\">\n" .
5508 "<table class=\"object_header\">\n";
5509 git_print_authorship_rows
(\
%co);
5510 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
5513 "<td class=\"sha1\">" .
5514 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
5515 class => "list"}, $co{'tree'}) .
5517 "<td class=\"link\">" .
5518 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
5520 my $snapshot_links = format_snapshot_links
($hash);
5521 if (defined $snapshot_links) {
5522 print " | " . $snapshot_links;
5527 foreach my $par (@$parents) {
5530 "<td class=\"sha1\">" .
5531 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
5532 class => "list"}, $par) .
5534 "<td class=\"link\">" .
5535 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
5537 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
5544 print "<div class=\"page_body\">\n";
5545 git_print_log
($co{'comment'});
5548 git_difftree_body
(\
@difftree, $hash, @$parents);
5554 # object is defined by:
5555 # - hash or hash_base alone
5556 # - hash_base and file_name
5559 # - hash or hash_base alone
5560 if ($hash || ($hash_base && !defined $file_name)) {
5561 my $object_id = $hash || $hash_base;
5563 open my $fd, "-|", quote_command
(
5564 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
5565 or die_error
(404, "Object does not exist");
5569 or die_error
(404, "Object does not exist");
5571 # - hash_base and file_name
5572 } elsif ($hash_base && defined $file_name) {
5573 $file_name =~ s
,/+$,,;
5575 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
5576 or die_error
(404, "Base object does not exist");
5578 # here errors should not hapen
5579 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
5580 or die_error
(500, "Open git-ls-tree failed");
5584 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
5585 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
5586 die_error
(404, "File or directory for given base does not exist");
5591 die_error
(400, "Not enough information to find object");
5594 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
5595 hash
=>$hash, hash_base
=>$hash_base,
5596 file_name
=>$file_name),
5597 -status
=> '302 Found');
5601 my $format = shift || 'html';
5608 # preparing $fd and %diffinfo for git_patchset_body
5610 if (defined $hash_base && defined $hash_parent_base) {
5611 if (defined $file_name) {
5613 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5614 $hash_parent_base, $hash_base,
5615 "--", (defined $file_parent ? $file_parent : ()), $file_name
5616 or die_error
(500, "Open git-diff-tree failed");
5617 @difftree = map { chomp; $_ } <$fd>;
5619 or die_error
(404, "Reading git-diff-tree failed");
5621 or die_error
(404, "Blob diff not found");
5623 } elsif (defined $hash &&
5624 $hash =~ /[0-9a-fA-F]{40}/) {
5625 # try to find filename from $hash
5627 # read filtered raw output
5628 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5629 $hash_parent_base, $hash_base, "--"
5630 or die_error
(500, "Open git-diff-tree failed");
5632 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
5634 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
5635 map { chomp; $_ } <$fd>;
5637 or die_error
(404, "Reading git-diff-tree failed");
5639 or die_error
(404, "Blob diff not found");
5642 die_error
(400, "Missing one of the blob diff parameters");
5645 if (@difftree > 1) {
5646 die_error
(400, "Ambiguous blob diff specification");
5649 %diffinfo = parse_difftree_raw_line
($difftree[0]);
5650 $file_parent ||= $diffinfo{'from_file'} || $file_name;
5651 $file_name ||= $diffinfo{'to_file'};
5653 $hash_parent ||= $diffinfo{'from_id'};
5654 $hash ||= $diffinfo{'to_id'};
5656 # non-textual hash id's can be cached
5657 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
5658 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
5663 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5664 '-p', ($format eq 'html' ? "--full-index" : ()),
5665 $hash_parent_base, $hash_base,
5666 "--", (defined $file_parent ? $file_parent : ()), $file_name
5667 or die_error
(500, "Open git-diff-tree failed");
5670 # old/legacy style URI -- not generated anymore since 1.4.3.
5672 die_error
('404 Not Found', "Missing one of the blob diff parameters")
5676 if ($format eq 'html') {
5678 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
5680 git_header_html
(undef, $expires);
5681 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5682 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5683 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5685 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
5686 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
5688 if (defined $file_name) {
5689 git_print_page_path
($file_name, "blob", $hash_base);
5691 print "<div class=\"page_path\"></div>\n";
5694 } elsif ($format eq 'plain') {
5696 -type
=> 'text/plain',
5697 -charset
=> 'utf-8',
5698 -expires
=> $expires,
5699 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
5701 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5704 die_error
(400, "Unknown blobdiff format");
5708 if ($format eq 'html') {
5709 print "<div class=\"page_body\">\n";
5711 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
5714 print "</div>\n"; # class="page_body"
5718 while (my $line = <$fd>) {
5719 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
5720 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
5724 last if $line =~ m!^\+\+\+!;
5732 sub git_blobdiff_plain
{
5733 git_blobdiff
('plain');
5736 sub git_commitdiff
{
5738 my $format = $params{-format
} || 'html';
5740 my ($patch_max) = gitweb_get_feature
('patches');
5741 if ($format eq 'patch') {
5742 die_error
(403, "Patch view not allowed") unless $patch_max;
5745 $hash ||= $hash_base || "HEAD";
5746 my %co = parse_commit
($hash)
5747 or die_error
(404, "Unknown commit object");
5749 # choose format for commitdiff for merge
5750 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
5751 $hash_parent = '--cc';
5753 # we need to prepare $formats_nav before almost any parameter munging
5755 if ($format eq 'html') {
5757 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
5760 $formats_nav .= " | " .
5761 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
5765 if (defined $hash_parent &&
5766 $hash_parent ne '-c' && $hash_parent ne '--cc') {
5767 # commitdiff with two commits given
5768 my $hash_parent_short = $hash_parent;
5769 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5770 $hash_parent_short = substr($hash_parent, 0, 7);
5774 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
5775 if ($co{'parents'}[$i] eq $hash_parent) {
5776 $formats_nav .= ' parent ' . ($i+1);
5780 $formats_nav .= ': ' .
5781 $cgi->a({-href
=> href
(action
=>"commitdiff",
5782 hash
=>$hash_parent)},
5783 esc_html
($hash_parent_short)) .
5785 } elsif (!$co{'parent'}) {
5787 $formats_nav .= ' (initial)';
5788 } elsif (scalar @{$co{'parents'}} == 1) {
5789 # single parent commit
5792 $cgi->a({-href
=> href
(action
=>"commitdiff",
5793 hash
=>$co{'parent'})},
5794 esc_html
(substr($co{'parent'}, 0, 7))) .
5798 if ($hash_parent eq '--cc') {
5799 $formats_nav .= ' | ' .
5800 $cgi->a({-href
=> href
(action
=>"commitdiff",
5801 hash
=>$hash, hash_parent
=>'-c')},
5803 } else { # $hash_parent eq '-c'
5804 $formats_nav .= ' | ' .
5805 $cgi->a({-href
=> href
(action
=>"commitdiff",
5806 hash
=>$hash, hash_parent
=>'--cc')},
5812 $cgi->a({-href
=> href
(action
=>"commitdiff",
5814 esc_html
(substr($_, 0, 7)));
5815 } @{$co{'parents'}} ) .
5820 my $hash_parent_param = $hash_parent;
5821 if (!defined $hash_parent_param) {
5822 # --cc for multiple parents, --root for parentless
5823 $hash_parent_param =
5824 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
5830 if ($format eq 'html') {
5831 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5832 "--no-commit-id", "--patch-with-raw", "--full-index",
5833 $hash_parent_param, $hash, "--"
5834 or die_error
(500, "Open git-diff-tree failed");
5836 while (my $line = <$fd>) {
5838 # empty line ends raw part of diff-tree output
5840 push @difftree, scalar parse_difftree_raw_line
($line);
5843 } elsif ($format eq 'plain') {
5844 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5845 '-p', $hash_parent_param, $hash, "--"
5846 or die_error
(500, "Open git-diff-tree failed");
5847 } elsif ($format eq 'patch') {
5848 # For commit ranges, we limit the output to the number of
5849 # patches specified in the 'patches' feature.
5850 # For single commits, we limit the output to a single patch,
5851 # diverging from the git-format-patch default.
5852 my @commit_spec = ();
5854 if ($patch_max > 0) {
5855 push @commit_spec, "-$patch_max";
5857 push @commit_spec, '-n', "$hash_parent..$hash";
5859 if ($params{-single
}) {
5860 push @commit_spec, '-1';
5862 if ($patch_max > 0) {
5863 push @commit_spec, "-$patch_max";
5865 push @commit_spec, "-n";
5867 push @commit_spec, '--root', $hash;
5869 open $fd, "-|", git_cmd
(), "format-patch", '--encoding=utf8',
5870 '--stdout', @commit_spec
5871 or die_error
(500, "Open git-format-patch failed");
5873 die_error
(400, "Unknown commitdiff format");
5876 # non-textual hash id's can be cached
5878 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5882 # write commit message
5883 if ($format eq 'html') {
5884 my $refs = git_get_references
();
5885 my $ref = format_ref_marker
($refs, $co{'id'});
5887 git_header_html
(undef, $expires);
5888 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5889 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
5890 print "<div class=\"title_text\">\n" .
5891 "<table class=\"object_header\">\n";
5892 git_print_authorship_rows
(\
%co);
5895 print "<div class=\"page_body\">\n";
5896 if (@{$co{'comment'}} > 1) {
5897 print "<div class=\"log\">\n";
5898 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
5899 print "</div>\n"; # class="log"
5902 } elsif ($format eq 'plain') {
5903 my $refs = git_get_references
("tags");
5904 my $tagname = git_get_rev_name_tags
($hash);
5905 my $filename = basename
($project) . "-$hash.patch";
5908 -type
=> 'text/plain',
5909 -charset
=> 'utf-8',
5910 -expires
=> $expires,
5911 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5912 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5913 print "From: " . to_utf8
($co{'author'}) . "\n";
5914 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5915 print "Subject: " . to_utf8
($co{'title'}) . "\n";
5917 print "X-Git-Tag: $tagname\n" if $tagname;
5918 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5920 foreach my $line (@{$co{'comment'}}) {
5921 print to_utf8
($line) . "\n";
5924 } elsif ($format eq 'patch') {
5925 my $filename = basename
($project) . "-$hash.patch";
5928 -type
=> 'text/plain',
5929 -charset
=> 'utf-8',
5930 -expires
=> $expires,
5931 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5935 if ($format eq 'html') {
5936 my $use_parents = !defined $hash_parent ||
5937 $hash_parent eq '-c' || $hash_parent eq '--cc';
5938 git_difftree_body
(\
@difftree, $hash,
5939 $use_parents ? @{$co{'parents'}} : $hash_parent);
5942 git_patchset_body
($fd, \
@difftree, $hash,
5943 $use_parents ? @{$co{'parents'}} : $hash_parent);
5945 print "</div>\n"; # class="page_body"
5948 } elsif ($format eq 'plain') {
5952 or print "Reading git-diff-tree failed\n";
5953 } elsif ($format eq 'patch') {
5957 or print "Reading git-format-patch failed\n";
5961 sub git_commitdiff_plain
{
5962 git_commitdiff
(-format
=> 'plain');
5965 # format-patch-style patches
5967 git_commitdiff
(-format
=> 'patch', -single
=> 1);
5971 git_commitdiff
(-format
=> 'patch');
5975 if (!defined $hash_base) {
5976 $hash_base = git_get_head_hash
($project);
5978 if (!defined $page) {
5982 my %co = parse_commit
($hash_base)
5983 or die_error
(404, "Unknown commit object");
5985 my $refs = git_get_references
();
5986 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5988 my @commitlist = parse_commits
($hash_base, 101, (100 * $page),
5989 $file_name, "--full-history")
5990 or die_error
(404, "No such file or directory on given branch");
5992 if (!defined $hash && defined $file_name) {
5993 # some commits could have deleted file in question,
5994 # and not have it in tree, but one of them has to have it
5995 for (my $i = 0; $i <= @commitlist; $i++) {
5996 $hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
5997 last if defined $hash;
6000 if (defined $hash) {
6001 $ftype = git_get_type
($hash);
6003 if (!defined $ftype) {
6004 die_error
(500, "Unknown type of object");
6007 my $paging_nav = '';
6010 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
6011 file_name
=>$file_name)},
6013 $paging_nav .= " ⋅ " .
6014 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
6015 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
6017 $paging_nav .= "first";
6018 $paging_nav .= " ⋅ prev";
6021 if ($#commitlist >= 100) {
6023 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
6024 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
6025 $paging_nav .= " ⋅ $next_link";
6027 $paging_nav .= " ⋅ next";
6031 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
6032 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
6033 git_print_page_path
($file_name, $ftype, $hash_base);
6035 git_history_body
(\
@commitlist, 0, 99,
6036 $refs, $hash_base, $ftype, $next_link);
6042 gitweb_check_feature
('search') or die_error
(403, "Search is disabled");
6043 if (!defined $searchtext) {
6044 die_error
(400, "Text field is empty");
6046 if (!defined $hash) {
6047 $hash = git_get_head_hash
($project);
6049 my %co = parse_commit
($hash);
6051 die_error
(404, "Unknown commit object");
6053 if (!defined $page) {
6057 $searchtype ||= 'commit';
6058 if ($searchtype eq 'pickaxe') {
6059 # pickaxe may take all resources of your box and run for several minutes
6060 # with every query - so decide by yourself how public you make this feature
6061 gitweb_check_feature
('pickaxe')
6062 or die_error
(403, "Pickaxe is disabled");
6064 if ($searchtype eq 'grep') {
6065 gitweb_check_feature
('grep')[0]
6066 or die_error
(403, "Grep is disabled");
6071 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
6073 if ($searchtype eq 'commit') {
6074 $greptype = "--grep=";
6075 } elsif ($searchtype eq 'author') {
6076 $greptype = "--author=";
6077 } elsif ($searchtype eq 'committer') {
6078 $greptype = "--committer=";
6080 $greptype .= $searchtext;
6081 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
6082 $greptype, '--regexp-ignore-case',
6083 $search_use_regexp ? '--extended-regexp' : '--fixed-strings');
6085 my $paging_nav = '';
6088 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
6089 searchtext
=>$searchtext,
6090 searchtype
=>$searchtype)},
6092 $paging_nav .= " ⋅ " .
6093 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
6094 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
6096 $paging_nav .= "first";
6097 $paging_nav .= " ⋅ prev";
6100 if ($#commitlist >= 100) {
6102 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
6103 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
6104 $paging_nav .= " ⋅ $next_link";
6106 $paging_nav .= " ⋅ next";
6109 if ($#commitlist >= 100) {
6112 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
6113 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6114 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
6117 if ($searchtype eq 'pickaxe') {
6118 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
6119 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6121 print "<table class=\"pickaxe search\">\n";
6124 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
6125 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
6126 ($search_use_regexp ? '--pickaxe-regex' : ());
6129 while (my $line = <$fd>) {
6133 my %set = parse_difftree_raw_line
($line);
6134 if (defined $set{'commit'}) {
6135 # finish previous commit
6138 "<td class=\"link\">" .
6139 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
6141 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
6147 print "<tr class=\"dark\">\n";
6149 print "<tr class=\"light\">\n";
6152 %co = parse_commit
($set{'commit'});
6153 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
6154 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
6155 "<td><i>$author</i></td>\n" .
6157 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
6158 -class => "list subject"},
6159 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
6160 } elsif (defined $set{'to_id'}) {
6161 next if ($set{'to_id'} =~ m/^0{40}$/);
6163 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
6164 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
6166 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
6172 # finish last commit (warning: repetition!)
6175 "<td class=\"link\">" .
6176 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
6178 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
6186 if ($searchtype eq 'grep') {
6187 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
6188 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6190 print "<table class=\"grep_search\">\n";
6194 open my $fd, "-|", git_cmd
(), 'grep', '-n',
6195 $search_use_regexp ? ('-E', '-i') : '-F',
6196 $searchtext, $co{'tree'};
6198 while (my $line = <$fd>) {
6200 my ($file, $lno, $ltext, $binary);
6201 last if ($matches++ > 1000);
6202 if ($line =~ /^Binary file (.+) matches$/) {
6206 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
6208 if ($file ne $lastfile) {
6209 $lastfile and print "</td></tr>\n";
6211 print "<tr class=\"dark\">\n";
6213 print "<tr class=\"light\">\n";
6215 print "<td class=\"list\">".
6216 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6217 file_name
=>"$file"),
6218 -class => "list"}, esc_path
($file));
6219 print "</td><td>\n";
6223 print "<div class=\"binary\">Binary file</div>\n";
6225 $ltext = untabify
($ltext);
6226 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
6227 $ltext = esc_html
($1, -nbsp
=>1);
6228 $ltext .= '<span class="match">';
6229 $ltext .= esc_html
($2, -nbsp
=>1);
6230 $ltext .= '</span>';
6231 $ltext .= esc_html
($3, -nbsp
=>1);
6233 $ltext = esc_html
($ltext, -nbsp
=>1);
6235 print "<div class=\"pre\">" .
6236 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6237 file_name
=>"$file").'#l'.$lno,
6238 -class => "linenr"}, sprintf('%4i', $lno))
6239 . ' ' . $ltext . "</div>\n";
6243 print "</td></tr>\n";
6244 if ($matches > 1000) {
6245 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
6248 print "<div class=\"diff nodifferences\">No matches found</div>\n";
6257 sub git_search_help
{
6259 git_print_page_nav
('','', $hash,$hash,$hash);
6261 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
6262 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
6263 the pattern entered is recognized as the POSIX extended
6264 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
6267 <dt><b>commit</b></dt>
6268 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
6270 my $have_grep = gitweb_check_feature
('grep');
6273 <dt><b>grep</b></dt>
6274 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
6275 a different one) are searched for the given pattern. On large trees, this search can take
6276 a while and put some strain on the server, so please use it with some consideration. Note that
6277 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
6278 case-sensitive.</dd>
6282 <dt><b>author</b></dt>
6283 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
6284 <dt><b>committer</b></dt>
6285 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
6287 my $have_pickaxe = gitweb_check_feature
('pickaxe');
6288 if ($have_pickaxe) {
6290 <dt><b>pickaxe</b></dt>
6291 <dd>All commits that caused the string to appear or disappear from any file (changes that
6292 added, removed or "modified" the string) will be listed. This search can take a while and
6293 takes a lot of strain on the server, so please use it wisely. Note that since you may be
6294 interested even in changes just changing the case as well, this search is case sensitive.</dd>
6302 my $head = git_get_head_hash
($project);
6303 if (!defined $hash) {
6306 if (!defined $page) {
6309 my $refs = git_get_references
();
6311 my $commit_hash = $hash;
6312 if (defined $hash_parent) {
6313 $commit_hash = "$hash_parent..$hash";
6315 my @commitlist = parse_commits
($commit_hash, 101, (100 * $page));
6317 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#commitlist >= 100);
6319 if ($#commitlist >= 100) {
6321 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
6322 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
6324 my $patch_max = gitweb_check_feature
('patches');
6326 if ($patch_max < 0 || @commitlist <= $patch_max) {
6327 $paging_nav .= " ⋅ " .
6328 $cgi->a({-href
=> href
(action
=>"patches", -replay
=>1)},
6334 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
6335 git_print_header_div
('summary', $project);
6337 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
6342 ## ......................................................................
6343 ## feeds (RSS, Atom; OPML)
6346 my $format = shift || 'atom';
6347 my $have_blame = gitweb_check_feature
('blame');
6349 # Atom: http://www.atomenabled.org/developers/syndication/
6350 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
6351 if ($format ne 'rss' && $format ne 'atom') {
6352 die_error
(400, "Unknown web feed format");
6355 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
6356 my $head = $hash || 'HEAD';
6357 my @commitlist = parse_commits
($head, 150, 0, $file_name);
6361 my $content_type = "application/$format+xml";
6362 if (defined $cgi->http('HTTP_ACCEPT') &&
6363 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
6364 # browser (feed reader) prefers text/xml
6365 $content_type = 'text/xml';
6367 if (defined($commitlist[0])) {
6368 %latest_commit = %{$commitlist[0]};
6369 my $latest_epoch = $latest_commit{'committer_epoch'};
6370 %latest_date = parse_date
($latest_epoch);
6371 my $if_modified = $cgi->http('IF_MODIFIED_SINCE');
6372 if (defined $if_modified) {
6374 if (eval { require HTTP
::Date
; 1; }) {
6375 $since = HTTP
::Date
::str2time
($if_modified);
6376 } elsif (eval { require Time
::ParseDate
; 1; }) {
6377 $since = Time
::ParseDate
::parsedate
($if_modified, GMT
=> 1);
6379 if (defined $since && $latest_epoch <= $since) {
6381 -type
=> $content_type,
6382 -charset
=> 'utf-8',
6383 -last_modified
=> $latest_date{'rfc2822'},
6384 -status
=> '304 Not Modified');
6389 -type
=> $content_type,
6390 -charset
=> 'utf-8',
6391 -last_modified
=> $latest_date{'rfc2822'});
6394 -type
=> $content_type,
6395 -charset
=> 'utf-8');
6398 # Optimization: skip generating the body if client asks only
6399 # for Last-Modified date.
6400 return if ($cgi->request_method() eq 'HEAD');
6403 my $title = "$site_name - $project/$action";
6404 my $feed_type = 'log';
6405 if (defined $hash) {
6406 $title .= " - '$hash'";
6407 $feed_type = 'branch log';
6408 if (defined $file_name) {
6409 $title .= " :: $file_name";
6410 $feed_type = 'history';
6412 } elsif (defined $file_name) {
6413 $title .= " - $file_name";
6414 $feed_type = 'history';
6416 $title .= " $feed_type";
6417 my $descr = git_get_project_description
($project);
6418 if (defined $descr) {
6419 $descr = esc_html
($descr);
6421 $descr = "$project " .
6422 ($format eq 'rss' ? 'RSS' : 'Atom') .
6425 my $owner = git_get_project_owner
($project);
6426 $owner = esc_html
($owner);
6430 if (defined $file_name) {
6431 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
6432 } elsif (defined $hash) {
6433 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
6435 $alt_url = href
(-full
=>1, action
=>"summary");
6437 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
6438 if ($format eq 'rss') {
6440 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
6443 print "<title>$title</title>\n" .
6444 "<link>$alt_url</link>\n" .
6445 "<description>$descr</description>\n" .
6446 "<language>en</language>\n" .
6447 # project owner is responsible for 'editorial' content
6448 "<managingEditor>$owner</managingEditor>\n";
6449 if (defined $logo || defined $favicon) {
6450 # prefer the logo to the favicon, since RSS
6451 # doesn't allow both
6452 my $img = esc_url
($logo || $favicon);
6454 "<url>$img</url>\n" .
6455 "<title>$title</title>\n" .
6456 "<link>$alt_url</link>\n" .
6460 print "<pubDate>$latest_date{'rfc2822'}</pubDate>\n";
6461 print "<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";
6463 print "<generator>gitweb v.$version/$git_version</generator>\n";
6464 } elsif ($format eq 'atom') {
6466 <feed xmlns="http://www.w3.org/2005/Atom">
6468 print "<title>$title</title>\n" .
6469 "<subtitle>$descr</subtitle>\n" .
6470 '<link rel="alternate" type="text/html" href="' .
6471 $alt_url . '" />' . "\n" .
6472 '<link rel="self" type="' . $content_type . '" href="' .
6473 $cgi->self_url() . '" />' . "\n" .
6474 "<id>" . href
(-full
=>1) . "</id>\n" .
6475 # use project owner for feed author
6476 "<author><name>$owner</name></author>\n";
6477 if (defined $favicon) {
6478 print "<icon>" . esc_url
($favicon) . "</icon>\n";
6480 if (defined $logo_url) {
6481 # not twice as wide as tall: 72 x 27 pixels
6482 print "<logo>" . esc_url
($logo) . "</logo>\n";
6484 if (! %latest_date) {
6485 # dummy date to keep the feed valid until commits trickle in:
6486 print "<updated>1970-01-01T00:00:00Z</updated>\n";
6488 print "<updated>$latest_date{'iso-8601'}</updated>\n";
6490 print "<generator version='$version/$git_version'>gitweb</generator>\n";
6494 for (my $i = 0; $i <= $#commitlist; $i++) {
6495 my %co = %{$commitlist[$i]};
6496 my $commit = $co{'id'};
6497 # we read 150, we always show 30 and the ones more recent than 48 hours
6498 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
6501 my %cd = parse_date
($co{'author_epoch'});
6503 # get list of changed files
6504 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6505 $co{'parent'} || "--root",
6506 $co{'id'}, "--", (defined $file_name ? $file_name : ())
6508 my @difftree = map { chomp; $_ } <$fd>;
6512 # print element (entry, item)
6513 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
6514 if ($format eq 'rss') {
6516 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
6517 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
6518 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
6519 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
6520 "<link>$co_url</link>\n" .
6521 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
6522 "<content:encoded>" .
6524 } elsif ($format eq 'atom') {
6526 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
6527 "<updated>$cd{'iso-8601'}</updated>\n" .
6529 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
6530 if ($co{'author_email'}) {
6531 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
6533 print "</author>\n" .
6534 # use committer for contributor
6536 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
6537 if ($co{'committer_email'}) {
6538 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
6540 print "</contributor>\n" .
6541 "<published>$cd{'iso-8601'}</published>\n" .
6542 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
6543 "<id>$co_url</id>\n" .
6544 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
6545 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
6547 my $comment = $co{'comment'};
6549 foreach my $line (@$comment) {
6550 $line = esc_html
($line);
6553 print "</pre><ul>\n";
6554 foreach my $difftree_line (@difftree) {
6555 my %difftree = parse_difftree_raw_line
($difftree_line);
6556 next if !$difftree{'from_id'};
6558 my $file = $difftree{'file'} || $difftree{'to_file'};
6562 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
6563 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
6564 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
6565 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
6566 -title
=> "diff"}, 'D');
6568 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
6569 file_name
=>$file, hash_base
=>$commit),
6570 -title
=> "blame"}, 'B');
6572 # if this is not a feed of a file history
6573 if (!defined $file_name || $file_name ne $file) {
6574 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
6575 file_name
=>$file, hash
=>$commit),
6576 -title
=> "history"}, 'H');
6578 $file = esc_path
($file);
6582 if ($format eq 'rss') {
6583 print "</ul>]]>\n" .
6584 "</content:encoded>\n" .
6586 } elsif ($format eq 'atom') {
6587 print "</ul>\n</div>\n" .
6594 if ($format eq 'rss') {
6595 print "</channel>\n</rss>\n";
6596 } elsif ($format eq 'atom') {
6610 my @list = git_get_projects_list
();
6613 -type
=> 'text/xml',
6614 -charset
=> 'utf-8',
6615 -content_disposition
=> 'inline; filename="opml.xml"');
6618 <?xml version="1.0" encoding="utf-8"?>
6619 <opml version="1.0">
6621 <title>$site_name OPML Export</title>
6624 <outline text="git RSS feeds">
6627 foreach my $pr (@list) {
6629 my $head = git_get_head_hash
($proj{'path'});
6630 if (!defined $head) {
6633 $git_dir = "$projectroot/$proj{'path'}";
6634 my %co = parse_commit
($head);
6639 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
6640 my $rss = href
('project' => $proj{'path'}, 'action' => 'rss', -full
=> 1);
6641 my $html = href
('project' => $proj{'path'}, 'action' => 'summary', -full
=> 1);
6642 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";