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 # Enable showing size of blobs in a 'tree' view, in a separate
310 # column, similar to what 'ls -l' does. This cost a bit of IO.
312 # To disable system wide have in $GITWEB_CONFIG
313 # $feature{'show-sizes'}{'default'} = [0];
314 # To have project specific config enable override in $GITWEB_CONFIG
315 # $feature{'show-sizes'}{'override'} = 1;
316 # and in project config gitweb.showsizes = 0|1;
318 'sub' => sub { feature_bool
('showsizes', @_) },
322 # Make gitweb use an alternative format of the URLs which can be
323 # more readable and natural-looking: project name is embedded
324 # directly in the path and the query string contains other
325 # auxiliary information. All gitweb installations recognize
326 # URL in either format; this configures in which formats gitweb
329 # To enable system wide have in $GITWEB_CONFIG
330 # $feature{'pathinfo'}{'default'} = [1];
331 # Project specific override is not supported.
333 # Note that you will need to change the default location of CSS,
334 # favicon, logo and possibly other files to an absolute URL. Also,
335 # if gitweb.cgi serves as your indexfile, you will need to force
336 # $my_uri to contain the script name in your $GITWEB_CONFIG.
341 # Make gitweb consider projects in project root subdirectories
342 # to be forks of existing projects. Given project $projname.git,
343 # projects matching $projname/*.git will not be shown in the main
344 # projects list, instead a '+' mark will be added to $projname
345 # there and a 'forks' view will be enabled for the project, listing
346 # all the forks. If project list is taken from a file, forks have
347 # to be listed after the main project.
349 # To enable system wide have in $GITWEB_CONFIG
350 # $feature{'forks'}{'default'} = [1];
351 # Project specific override is not supported.
356 # Insert custom links to the action bar of all project pages.
357 # This enables you mainly to link to third-party scripts integrating
358 # into gitweb; e.g. git-browser for graphical history representation
359 # or custom web-based repository administration interface.
361 # The 'default' value consists of a list of triplets in the form
362 # (label, link, position) where position is the label after which
363 # to insert the link and link is a format string where %n expands
364 # to the project name, %f to the project path within the filesystem,
365 # %h to the current hash (h gitweb parameter) and %b to the current
366 # hash base (hb gitweb parameter); %% expands to %.
368 # To enable system wide have in $GITWEB_CONFIG e.g.
369 # $feature{'actions'}{'default'} = [('graphiclog',
370 # '/git-browser/by-commit.html?r=%n', 'summary')];
371 # Project specific override is not supported.
376 # Allow gitweb scan project content tags described in ctags/
377 # of project repository, and display the popular Web 2.0-ish
378 # "tag cloud" near the project list. Note that this is something
379 # COMPLETELY different from the normal Git tags.
381 # gitweb by itself can show existing tags, but it does not handle
382 # tagging itself; you need an external application for that.
383 # For an example script, check Girocco's cgi/tagproj.cgi.
384 # You may want to install the HTML::TagCloud Perl module to get
385 # a pretty tag cloud instead of just a list of tags.
387 # To enable system wide have in $GITWEB_CONFIG
388 # $feature{'ctags'}{'default'} = ['path_to_tag_script'];
389 # Project specific override is not supported.
394 # The maximum number of patches in a patchset generated in patch
395 # view. Set this to 0 or undef to disable patch view, or to a
396 # negative number to remove any limit.
398 # To disable system wide have in $GITWEB_CONFIG
399 # $feature{'patches'}{'default'} = [0];
400 # To have project specific config enable override in $GITWEB_CONFIG
401 # $feature{'patches'}{'override'} = 1;
402 # and in project config gitweb.patches = 0|n;
403 # where n is the maximum number of patches allowed in a patchset.
405 'sub' => \
&feature_patches
,
409 # Avatar support. When this feature is enabled, views such as
410 # shortlog or commit will display an avatar associated with
411 # the email of the committer(s) and/or author(s).
413 # Currently available providers are gravatar and picon.
414 # If an unknown provider is specified, the feature is disabled.
416 # Gravatar depends on Digest::MD5.
417 # Picon currently relies on the indiana.edu database.
419 # To enable system wide have in $GITWEB_CONFIG
420 # $feature{'avatar'}{'default'} = ['<provider>'];
421 # where <provider> is either gravatar or picon.
422 # To have project specific config enable override in $GITWEB_CONFIG
423 # $feature{'avatar'}{'override'} = 1;
424 # and in project config gitweb.avatar = <provider>;
426 'sub' => \
&feature_avatar
,
430 # Enable displaying how much time and how many git commands
431 # it took to generate and display page. Disabled by default.
432 # Project specific override is not supported.
437 # Enable turning some links into links to actions which require
438 # JavaScript to run (like 'blame_incremental'). Not enabled by
439 # default. Project specific override is currently not supported.
440 'javascript-actions' => {
445 sub gitweb_get_feature
{
447 return unless exists $feature{$name};
448 my ($sub, $override, @defaults) = (
449 $feature{$name}{'sub'},
450 $feature{$name}{'override'},
451 @{$feature{$name}{'default'}});
452 if (!$override) { return @defaults; }
454 warn "feature $name is not overridable";
457 return $sub->(@defaults);
460 # A wrapper to check if a given feature is enabled.
461 # With this, you can say
463 # my $bool_feat = gitweb_check_feature('bool_feat');
464 # gitweb_check_feature('bool_feat') or somecode;
468 # my ($bool_feat) = gitweb_get_feature('bool_feat');
469 # (gitweb_get_feature('bool_feat'))[0] or somecode;
471 sub gitweb_check_feature
{
472 return (gitweb_get_feature
(@_))[0];
478 my ($val) = git_get_project_config
($key, '--bool');
482 } elsif ($val eq 'true') {
484 } elsif ($val eq 'false') {
489 sub feature_snapshot
{
492 my ($val) = git_get_project_config
('snapshot');
495 @fmts = ($val eq 'none' ? () : split /\s*[,\s]\s*/, $val);
501 sub feature_patches
{
502 my @val = (git_get_project_config
('patches', '--int'));
512 my @val = (git_get_project_config
('avatar'));
514 return @val ? @val : @_;
517 # checking HEAD file with -e is fragile if the repository was
518 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
520 sub check_head_link
{
522 my $headfile = "$dir/HEAD";
523 return ((-e
$headfile) ||
524 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
527 sub check_export_ok
{
529 return (check_head_link
($dir) &&
530 (!$export_ok || -e
"$dir/$export_ok") &&
531 (!$export_auth_hook || $export_auth_hook->($dir)));
534 # process alternate names for backward compatibility
535 # filter out unsupported (unknown) snapshot formats
536 sub filter_snapshot_fmts
{
540 exists $known_snapshot_format_aliases{$_} ?
541 $known_snapshot_format_aliases{$_} : $_} @fmts;
543 exists $known_snapshot_formats{$_} &&
544 !$known_snapshot_formats{$_}{'disabled'}} @fmts;
547 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
548 if (-e
$GITWEB_CONFIG) {
551 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
552 do $GITWEB_CONFIG_SYSTEM if -e
$GITWEB_CONFIG_SYSTEM;
555 # version of the core git binary
556 our $git_version = qx("$GIT" --version) =~ m/git version (.*)$/ ? $1 : "unknown";
557 $number_of_git_cmds++;
559 $projects_list ||= $projectroot;
561 # ======================================================================
562 # input validation and dispatch
564 # input parameters can be collected from a variety of sources (presently, CGI
565 # and PATH_INFO), so we define an %input_params hash that collects them all
566 # together during validation: this allows subsequent uses (e.g. href()) to be
567 # agnostic of the parameter origin
569 our %input_params = ();
571 # input parameters are stored with the long parameter name as key. This will
572 # also be used in the href subroutine to convert parameters to their CGI
573 # equivalent, and since the href() usage is the most frequent one, we store
574 # the name -> CGI key mapping here, instead of the reverse.
576 # XXX: Warning: If you touch this, check the search form for updating,
579 our @cgi_param_mapping = (
587 hash_parent_base
=> "hpb",
592 snapshot_format
=> "sf",
593 extra_options
=> "opt",
594 search_use_regexp
=> "sr",
595 # this must be last entry (for manipulation from JavaScript)
598 our %cgi_param_mapping = @cgi_param_mapping;
600 # we will also need to know the possible actions, for validation
602 "blame" => \
&git_blame
,
603 "blame_incremental" => \
&git_blame_incremental
,
604 "blame_data" => \
&git_blame_data
,
605 "blobdiff" => \
&git_blobdiff
,
606 "blobdiff_plain" => \
&git_blobdiff_plain
,
607 "blob" => \
&git_blob
,
608 "blob_plain" => \
&git_blob_plain
,
609 "commitdiff" => \
&git_commitdiff
,
610 "commitdiff_plain" => \
&git_commitdiff_plain
,
611 "commit" => \
&git_commit
,
612 "forks" => \
&git_forks
,
613 "heads" => \
&git_heads
,
614 "history" => \
&git_history
,
616 "patch" => \
&git_patch
,
617 "patches" => \
&git_patches
,
619 "atom" => \
&git_atom
,
620 "search" => \
&git_search
,
621 "search_help" => \
&git_search_help
,
622 "shortlog" => \
&git_shortlog
,
623 "summary" => \
&git_summary
,
625 "tags" => \
&git_tags
,
626 "tree" => \
&git_tree
,
627 "snapshot" => \
&git_snapshot
,
628 "object" => \
&git_object
,
629 # those below don't need $project
630 "opml" => \
&git_opml
,
631 "project_list" => \
&git_project_list
,
632 "project_index" => \
&git_project_index
,
635 # finally, we have the hash of allowed extra_options for the commands that
637 our %allowed_options = (
638 "--no-merges" => [ qw(rss atom log shortlog history) ],
641 # fill %input_params with the CGI parameters. All values except for 'opt'
642 # should be single values, but opt can be an array. We should probably
643 # build an array of parameters that can be multi-valued, but since for the time
644 # being it's only this one, we just single it out
645 while (my ($name, $symbol) = each %cgi_param_mapping) {
646 if ($symbol eq 'opt') {
647 $input_params{$name} = [ $cgi->param($symbol) ];
649 $input_params{$name} = $cgi->param($symbol);
653 # now read PATH_INFO and update the parameter list for missing parameters
654 sub evaluate_path_info
{
655 return if defined $input_params{'project'};
656 return if !$path_info;
657 $path_info =~ s
,^/+,,;
658 return if !$path_info;
660 # find which part of PATH_INFO is project
661 my $project = $path_info;
663 while ($project && !check_head_link
("$projectroot/$project")) {
664 $project =~ s
,/*[^/]*$,,;
666 return unless $project;
667 $input_params{'project'} = $project;
669 # do not change any parameters if an action is given using the query string
670 return if $input_params{'action'};
671 $path_info =~ s
,^\Q
$project\E
/*,,;
673 # next, check if we have an action
674 my $action = $path_info;
676 if (exists $actions{$action}) {
677 $path_info =~ s
,^$action/*,,;
678 $input_params{'action'} = $action;
681 # list of actions that want hash_base instead of hash, but can have no
682 # pathname (f) parameter
689 # [$hash_parent_base[:$file_parent]..]$hash_parent[:$file_name]
690 my ($parentrefname, $parentpathname, $refname, $pathname) =
691 ($path_info =~ /^(?:(.+?)(?::(.+))?\.\.)?(.+?)(?::(.+))?$/);
693 # first, analyze the 'current' part
694 if (defined $pathname) {
695 # we got "branch:filename" or "branch:dir/"
696 # we could use git_get_type(branch:pathname), but:
697 # - it needs $git_dir
698 # - it does a git() call
699 # - the convention of terminating directories with a slash
700 # makes it superfluous
701 # - embedding the action in the PATH_INFO would make it even
703 $pathname =~ s
,^/+,,;
704 if (!$pathname || substr($pathname, -1) eq "/") {
705 $input_params{'action'} ||= "tree";
708 # the default action depends on whether we had parent info
710 if ($parentrefname) {
711 $input_params{'action'} ||= "blobdiff_plain";
713 $input_params{'action'} ||= "blob_plain";
716 $input_params{'hash_base'} ||= $refname;
717 $input_params{'file_name'} ||= $pathname;
718 } elsif (defined $refname) {
719 # we got "branch". In this case we have to choose if we have to
720 # set hash or hash_base.
722 # Most of the actions without a pathname only want hash to be
723 # set, except for the ones specified in @wants_base that want
724 # hash_base instead. It should also be noted that hand-crafted
725 # links having 'history' as an action and no pathname or hash
726 # set will fail, but that happens regardless of PATH_INFO.
727 $input_params{'action'} ||= "shortlog";
728 if (grep { $_ eq $input_params{'action'} } @wants_base) {
729 $input_params{'hash_base'} ||= $refname;
731 $input_params{'hash'} ||= $refname;
735 # next, handle the 'parent' part, if present
736 if (defined $parentrefname) {
737 # a missing pathspec defaults to the 'current' filename, allowing e.g.
738 # someproject/blobdiff/oldrev..newrev:/filename
739 if ($parentpathname) {
740 $parentpathname =~ s
,^/+,,;
741 $parentpathname =~ s
,/$,,;
742 $input_params{'file_parent'} ||= $parentpathname;
744 $input_params{'file_parent'} ||= $input_params{'file_name'};
746 # we assume that hash_parent_base is wanted if a path was specified,
747 # or if the action wants hash_base instead of hash
748 if (defined $input_params{'file_parent'} ||
749 grep { $_ eq $input_params{'action'} } @wants_base) {
750 $input_params{'hash_parent_base'} ||= $parentrefname;
752 $input_params{'hash_parent'} ||= $parentrefname;
756 # for the snapshot action, we allow URLs in the form
757 # $project/snapshot/$hash.ext
758 # where .ext determines the snapshot and gets removed from the
759 # passed $refname to provide the $hash.
761 # To be able to tell that $refname includes the format extension, we
762 # require the following two conditions to be satisfied:
763 # - the hash input parameter MUST have been set from the $refname part
764 # of the URL (i.e. they must be equal)
765 # - the snapshot format MUST NOT have been defined already (e.g. from
767 # It's also useless to try any matching unless $refname has a dot,
768 # so we check for that too
769 if (defined $input_params{'action'} &&
770 $input_params{'action'} eq 'snapshot' &&
771 defined $refname && index($refname, '.') != -1 &&
772 $refname eq $input_params{'hash'} &&
773 !defined $input_params{'snapshot_format'}) {
774 # We loop over the known snapshot formats, checking for
775 # extensions. Allowed extensions are both the defined suffix
776 # (which includes the initial dot already) and the snapshot
777 # format key itself, with a prepended dot
778 while (my ($fmt, $opt) = each %known_snapshot_formats) {
780 unless ($hash =~ s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) {
784 # a valid suffix was found, so set the snapshot format
785 # and reset the hash parameter
786 $input_params{'snapshot_format'} = $fmt;
787 $input_params{'hash'} = $hash;
788 # we also set the format suffix to the one requested
789 # in the URL: this way a request for e.g. .tgz returns
790 # a .tgz instead of a .tar.gz
791 $known_snapshot_formats{$fmt}{'suffix'} = $sfx;
796 evaluate_path_info
();
798 our $action = $input_params{'action'};
799 if (defined $action) {
800 if (!validate_action
($action)) {
801 die_error
(400, "Invalid action parameter");
805 # parameters which are pathnames
806 our $project = $input_params{'project'};
807 if (defined $project) {
808 if (!validate_project
($project)) {
810 die_error
(404, "No such project");
814 our $file_name = $input_params{'file_name'};
815 if (defined $file_name) {
816 if (!validate_pathname
($file_name)) {
817 die_error
(400, "Invalid file parameter");
821 our $file_parent = $input_params{'file_parent'};
822 if (defined $file_parent) {
823 if (!validate_pathname
($file_parent)) {
824 die_error
(400, "Invalid file parent parameter");
828 # parameters which are refnames
829 our $hash = $input_params{'hash'};
831 if (!validate_refname
($hash)) {
832 die_error
(400, "Invalid hash parameter");
836 our $hash_parent = $input_params{'hash_parent'};
837 if (defined $hash_parent) {
838 if (!validate_refname
($hash_parent)) {
839 die_error
(400, "Invalid hash parent parameter");
843 our $hash_base = $input_params{'hash_base'};
844 if (defined $hash_base) {
845 if (!validate_refname
($hash_base)) {
846 die_error
(400, "Invalid hash base parameter");
850 our @extra_options = @{$input_params{'extra_options'}};
851 # @extra_options is always defined, since it can only be (currently) set from
852 # CGI, and $cgi->param() returns the empty array in array context if the param
854 foreach my $opt (@extra_options) {
855 if (not exists $allowed_options{$opt}) {
856 die_error
(400, "Invalid option parameter");
858 if (not grep(/^$action$/, @{$allowed_options{$opt}})) {
859 die_error
(400, "Invalid option parameter for this action");
863 our $hash_parent_base = $input_params{'hash_parent_base'};
864 if (defined $hash_parent_base) {
865 if (!validate_refname
($hash_parent_base)) {
866 die_error
(400, "Invalid hash parent base parameter");
871 our $page = $input_params{'page'};
873 if ($page =~ m/[^0-9]/) {
874 die_error
(400, "Invalid page parameter");
878 our $searchtype = $input_params{'searchtype'};
879 if (defined $searchtype) {
880 if ($searchtype =~ m/[^a-z]/) {
881 die_error
(400, "Invalid searchtype parameter");
885 our $search_use_regexp = $input_params{'search_use_regexp'};
887 our $searchtext = $input_params{'searchtext'};
889 if (defined $searchtext) {
890 if (length($searchtext) < 2) {
891 die_error
(403, "At least two characters are required for search parameter");
893 $search_regexp = $search_use_regexp ? $searchtext : quotemeta $searchtext;
896 # path to the current git repository
898 $git_dir = "$projectroot/$project" if $project;
900 # list of supported snapshot formats
901 our @snapshot_fmts = gitweb_get_feature
('snapshot');
902 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
904 # check that the avatar feature is set to a known provider name,
905 # and for each provider check if the dependencies are satisfied.
906 # if the provider name is invalid or the dependencies are not met,
907 # reset $git_avatar to the empty string.
908 our ($git_avatar) = gitweb_get_feature
('avatar');
909 if ($git_avatar eq 'gravatar') {
910 $git_avatar = '' unless (eval { require Digest
::MD5
; 1; });
911 } elsif ($git_avatar eq 'picon') {
918 if (!defined $action) {
920 $action = git_get_type
($hash);
921 } elsif (defined $hash_base && defined $file_name) {
922 $action = git_get_type
("$hash_base:$file_name");
923 } elsif (defined $project) {
926 $action = 'project_list';
929 if (!defined($actions{$action})) {
930 die_error
(400, "Unknown action");
932 if ($action !~ m/^(?:opml|project_list|project_index)$/ &&
934 die_error
(400, "Project needed");
936 $actions{$action}->();
939 ## ======================================================================
944 # default is to use -absolute url() i.e. $my_uri
945 my $href = $params{-full
} ? $my_url : $my_uri;
947 $params{'project'} = $project unless exists $params{'project'};
949 if ($params{-replay
}) {
950 while (my ($name, $symbol) = each %cgi_param_mapping) {
951 if (!exists $params{$name}) {
952 $params{$name} = $input_params{$name};
957 my $use_pathinfo = gitweb_check_feature
('pathinfo');
958 if ($use_pathinfo and defined $params{'project'}) {
959 # try to put as many parameters as possible in PATH_INFO:
962 # - hash_parent or hash_parent_base:/file_parent
963 # - hash or hash_base:/filename
964 # - the snapshot_format as an appropriate suffix
966 # When the script is the root DirectoryIndex for the domain,
967 # $href here would be something like http://gitweb.example.com/
968 # Thus, we strip any trailing / from $href, to spare us double
969 # slashes in the final URL
972 # Then add the project name, if present
973 $href .= "/".esc_url
($params{'project'});
974 delete $params{'project'};
976 # since we destructively absorb parameters, we keep this
977 # boolean that remembers if we're handling a snapshot
978 my $is_snapshot = $params{'action'} eq 'snapshot';
980 # Summary just uses the project path URL, any other action is
982 if (defined $params{'action'}) {
983 $href .= "/".esc_url
($params{'action'}) unless $params{'action'} eq 'summary';
984 delete $params{'action'};
987 # Next, we put hash_parent_base:/file_parent..hash_base:/file_name,
988 # stripping nonexistent or useless pieces
989 $href .= "/" if ($params{'hash_base'} || $params{'hash_parent_base'}
990 || $params{'hash_parent'} || $params{'hash'});
991 if (defined $params{'hash_base'}) {
992 if (defined $params{'hash_parent_base'}) {
993 $href .= esc_url
($params{'hash_parent_base'});
994 # skip the file_parent if it's the same as the file_name
995 if (defined $params{'file_parent'}) {
996 if (defined $params{'file_name'} && $params{'file_parent'} eq $params{'file_name'}) {
997 delete $params{'file_parent'};
998 } elsif ($params{'file_parent'} !~ /\.\./) {
999 $href .= ":/".esc_url
($params{'file_parent'});
1000 delete $params{'file_parent'};
1004 delete $params{'hash_parent'};
1005 delete $params{'hash_parent_base'};
1006 } elsif (defined $params{'hash_parent'}) {
1007 $href .= esc_url
($params{'hash_parent'}). "..";
1008 delete $params{'hash_parent'};
1011 $href .= esc_url
($params{'hash_base'});
1012 if (defined $params{'file_name'} && $params{'file_name'} !~ /\.\./) {
1013 $href .= ":/".esc_url
($params{'file_name'});
1014 delete $params{'file_name'};
1016 delete $params{'hash'};
1017 delete $params{'hash_base'};
1018 } elsif (defined $params{'hash'}) {
1019 $href .= esc_url
($params{'hash'});
1020 delete $params{'hash'};
1023 # If the action was a snapshot, we can absorb the
1024 # snapshot_format parameter too
1026 my $fmt = $params{'snapshot_format'};
1027 # snapshot_format should always be defined when href()
1028 # is called, but just in case some code forgets, we
1029 # fall back to the default
1030 $fmt ||= $snapshot_fmts[0];
1031 $href .= $known_snapshot_formats{$fmt}{'suffix'};
1032 delete $params{'snapshot_format'};
1036 # now encode the parameters explicitly
1038 for (my $i = 0; $i < @cgi_param_mapping; $i += 2) {
1039 my ($name, $symbol) = ($cgi_param_mapping[$i], $cgi_param_mapping[$i+1]);
1040 if (defined $params{$name}) {
1041 if (ref($params{$name}) eq "ARRAY") {
1042 foreach my $par (@{$params{$name}}) {
1043 push @result, $symbol . "=" . esc_param
($par);
1046 push @result, $symbol . "=" . esc_param
($params{$name});
1050 $href .= "?" . join(';', @result) if scalar @result;
1056 ## ======================================================================
1057 ## validation, quoting/unquoting and escaping
1059 sub validate_action
{
1060 my $input = shift || return undef;
1061 return undef unless exists $actions{$input};
1065 sub validate_project
{
1066 my $input = shift || return undef;
1067 if (!validate_pathname
($input) ||
1068 !(-d
"$projectroot/$input") ||
1069 !check_export_ok
("$projectroot/$input") ||
1070 ($strict_export && !project_in_list
($input))) {
1077 sub validate_pathname
{
1078 my $input = shift || return undef;
1080 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
1081 # at the beginning, at the end, and between slashes.
1082 # also this catches doubled slashes
1083 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
1086 # no null characters
1087 if ($input =~ m!\0!) {
1093 sub validate_refname
{
1094 my $input = shift || return undef;
1096 # textual hashes are O.K.
1097 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
1100 # it must be correct pathname
1101 $input = validate_pathname
($input)
1103 # restrictions on ref name according to git-check-ref-format
1104 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
1110 # decode sequences of octets in utf8 into Perl's internal form,
1111 # which is utf-8 with utf8 flag set if needed. gitweb writes out
1112 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
1115 if (utf8
::valid
($str)) {
1119 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
1123 # quote unsafe chars, but keep the slash, even when it's not
1124 # correct, but quoted slashes look too horrible in bookmarks
1127 $str =~ s/([^A-Za-z0-9\-_.~()\/:@ ]+)/CGI
::escape
($1)/eg
;
1132 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
1135 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
1141 # replace invalid utf8 character with SUBSTITUTION sequence
1146 $str = to_utf8
($str);
1147 $str = $cgi->escapeHTML($str);
1148 if ($opts{'-nbsp'}) {
1149 $str =~ s/ / /g;
1151 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
1155 # quote control characters and escape filename to HTML
1160 $str = to_utf8
($str);
1161 $str = $cgi->escapeHTML($str);
1162 if ($opts{'-nbsp'}) {
1163 $str =~ s/ / /g;
1165 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
1169 # Make control characters "printable", using character escape codes (CEC)
1173 my %es = ( # character escape codes, aka escape sequences
1174 "\t" => '\t', # tab (HT)
1175 "\n" => '\n', # line feed (LF)
1176 "\r" => '\r', # carrige return (CR)
1177 "\f" => '\f', # form feed (FF)
1178 "\b" => '\b', # backspace (BS)
1179 "\a" => '\a', # alarm (bell) (BEL)
1180 "\e" => '\e', # escape (ESC)
1181 "\013" => '\v', # vertical tab (VT)
1182 "\000" => '\0', # nul character (NUL)
1184 my $chr = ( (exists $es{$cntrl})
1186 : sprintf('\%2x', ord($cntrl)) );
1187 if ($opts{-nohtml
}) {
1190 return "<span class=\"cntrl\">$chr</span>";
1194 # Alternatively use unicode control pictures codepoints,
1195 # Unicode "printable representation" (PR)
1200 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
1201 if ($opts{-nohtml
}) {
1204 return "<span class=\"cntrl\">$chr</span>";
1208 # git may return quoted and escaped filenames
1214 my %es = ( # character escape codes, aka escape sequences
1215 't' => "\t", # tab (HT, TAB)
1216 'n' => "\n", # newline (NL)
1217 'r' => "\r", # return (CR)
1218 'f' => "\f", # form feed (FF)
1219 'b' => "\b", # backspace (BS)
1220 'a' => "\a", # alarm (bell) (BEL)
1221 'e' => "\e", # escape (ESC)
1222 'v' => "\013", # vertical tab (VT)
1225 if ($seq =~ m/^[0-7]{1,3}$/) {
1226 # octal char sequence
1227 return chr(oct($seq));
1228 } elsif (exists $es{$seq}) {
1229 # C escape sequence, aka character escape code
1232 # quoted ordinary character
1236 if ($str =~ m/^"(.*)"$/) {
1239 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
1244 # escape tabs (convert tabs to spaces)
1248 while ((my $pos = index($line, "\t")) != -1) {
1249 if (my $count = (8 - ($pos % 8))) {
1250 my $spaces = ' ' x
$count;
1251 $line =~ s/\t/$spaces/;
1258 sub project_in_list
{
1259 my $project = shift;
1260 my @list = git_get_projects_list
();
1261 return @list && scalar(grep { $_->{'path'} eq $project } @list);
1264 ## ----------------------------------------------------------------------
1265 ## HTML aware string manipulation
1267 # Try to chop given string on a word boundary between position
1268 # $len and $len+$add_len. If there is no word boundary there,
1269 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
1270 # (marking chopped part) would be longer than given string.
1274 my $add_len = shift || 10;
1275 my $where = shift || 'right'; # 'left' | 'center' | 'right'
1277 # Make sure perl knows it is utf8 encoded so we don't
1278 # cut in the middle of a utf8 multibyte char.
1279 $str = to_utf8
($str);
1281 # allow only $len chars, but don't cut a word if it would fit in $add_len
1282 # if it doesn't fit, cut it if it's still longer than the dots we would add
1283 # remove chopped character entities entirely
1285 # when chopping in the middle, distribute $len into left and right part
1286 # return early if chopping wouldn't make string shorter
1287 if ($where eq 'center') {
1288 return $str if ($len + 5 >= length($str)); # filler is length 5
1291 return $str if ($len + 4 >= length($str)); # filler is length 4
1294 # regexps: ending and beginning with word part up to $add_len
1295 my $endre = qr/.{$len}\w{0,$add_len}/;
1296 my $begre = qr/\w{0,$add_len}.{$len}/;
1298 if ($where eq 'left') {
1299 $str =~ m/^(.*?)($begre)$/;
1300 my ($lead, $body) = ($1, $2);
1301 if (length($lead) > 4) {
1302 $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
1305 return "$lead$body";
1307 } elsif ($where eq 'center') {
1308 $str =~ m/^($endre)(.*)$/;
1309 my ($left, $str) = ($1, $2);
1310 $str =~ m/^(.*?)($begre)$/;
1311 my ($mid, $right) = ($1, $2);
1312 if (length($mid) > 5) {
1313 $left =~ s/&[^;]*$//;
1314 $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
1317 return "$left$mid$right";
1320 $str =~ m/^($endre)(.*)$/;
1323 if (length($tail) > 4) {
1324 $body =~ s/&[^;]*$//;
1327 return "$body$tail";
1331 # takes the same arguments as chop_str, but also wraps a <span> around the
1332 # result with a title attribute if it does get chopped. Additionally, the
1333 # string is HTML-escaped.
1334 sub chop_and_escape_str
{
1337 my $chopped = chop_str
(@_);
1338 if ($chopped eq $str) {
1339 return esc_html
($chopped);
1341 $str =~ s/[[:cntrl:]]/?/g;
1342 return $cgi->span({-title
=>$str}, esc_html
($chopped));
1346 ## ----------------------------------------------------------------------
1347 ## functions returning short strings
1349 # CSS class for given age value (in seconds)
1353 if (!defined $age) {
1355 } elsif ($age < 60*60*2) {
1357 } elsif ($age < 60*60*24*2) {
1364 # convert age in seconds to "nn units ago" string
1369 if ($age > 60*60*24*365*2) {
1370 $age_str = (int $age/60/60/24/365);
1371 $age_str .= " years ago";
1372 } elsif ($age > 60*60*24*(365/12)*2) {
1373 $age_str = int $age/60/60/24/(365/12);
1374 $age_str .= " months ago";
1375 } elsif ($age > 60*60*24*7*2) {
1376 $age_str = int $age/60/60/24/7;
1377 $age_str .= " weeks ago";
1378 } elsif ($age > 60*60*24*2) {
1379 $age_str = int $age/60/60/24;
1380 $age_str .= " days ago";
1381 } elsif ($age > 60*60*2) {
1382 $age_str = int $age/60/60;
1383 $age_str .= " hours ago";
1384 } elsif ($age > 60*2) {
1385 $age_str = int $age/60;
1386 $age_str .= " min ago";
1387 } elsif ($age > 2) {
1388 $age_str = int $age;
1389 $age_str .= " sec ago";
1391 $age_str .= " right now";
1397 S_IFINVALID
=> 0030000,
1398 S_IFGITLINK
=> 0160000,
1401 # submodule/subproject, a commit object reference
1405 return (($mode & S_IFMT
) == S_IFGITLINK
)
1408 # convert file mode in octal to symbolic file mode string
1410 my $mode = oct shift;
1412 if (S_ISGITLINK
($mode)) {
1413 return 'm---------';
1414 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1415 return 'drwxr-xr-x';
1416 } elsif (S_ISLNK
($mode)) {
1417 return 'lrwxrwxrwx';
1418 } elsif (S_ISREG
($mode)) {
1419 # git cares only about the executable bit
1420 if ($mode & S_IXUSR
) {
1421 return '-rwxr-xr-x';
1423 return '-rw-r--r--';
1426 return '----------';
1430 # convert file mode in octal to file type string
1434 if ($mode !~ m/^[0-7]+$/) {
1440 if (S_ISGITLINK
($mode)) {
1442 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1444 } elsif (S_ISLNK
($mode)) {
1446 } elsif (S_ISREG
($mode)) {
1453 # convert file mode in octal to file type description string
1454 sub file_type_long
{
1457 if ($mode !~ m/^[0-7]+$/) {
1463 if (S_ISGITLINK
($mode)) {
1465 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1467 } elsif (S_ISLNK
($mode)) {
1469 } elsif (S_ISREG
($mode)) {
1470 if ($mode & S_IXUSR
) {
1471 return "executable";
1481 ## ----------------------------------------------------------------------
1482 ## functions returning short HTML fragments, or transforming HTML fragments
1483 ## which don't belong to other sections
1485 # format line of commit message.
1486 sub format_log_line_html
{
1489 $line = esc_html
($line, -nbsp
=>1);
1490 $line =~ s
{\b([0-9a-fA-F
]{8,40})\b}{
1491 $cgi->a({-href
=> href
(action
=>"object", hash
=>$1),
1492 -class => "text"}, $1);
1498 # format marker of refs pointing to given object
1500 # the destination action is chosen based on object type and current context:
1501 # - for annotated tags, we choose the tag view unless it's the current view
1502 # already, in which case we go to shortlog view
1503 # - for other refs, we keep the current view if we're in history, shortlog or
1504 # log view, and select shortlog otherwise
1505 sub format_ref_marker
{
1506 my ($refs, $id) = @_;
1509 if (defined $refs->{$id}) {
1510 foreach my $ref (@{$refs->{$id}}) {
1511 # this code exploits the fact that non-lightweight tags are the
1512 # only indirect objects, and that they are the only objects for which
1513 # we want to use tag instead of shortlog as action
1514 my ($type, $name) = qw();
1515 my $indirect = ($ref =~ s/\^\{\}$//);
1516 # e.g. tags/v2.6.11 or heads/next
1517 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1526 $class .= " indirect" if $indirect;
1528 my $dest_action = "shortlog";
1531 $dest_action = "tag" unless $action eq "tag";
1532 } elsif ($action =~ /^(history|(short)?log)$/) {
1533 $dest_action = $action;
1537 $dest .= "refs/" unless $ref =~ m
!^refs
/!;
1540 my $link = $cgi->a({
1542 action
=>$dest_action,
1546 $markers .= " <span class=\"$class\" title=\"$ref\">" .
1552 return ' <span class="refs">'. $markers . '</span>';
1558 # format, perhaps shortened and with markers, title line
1559 sub format_subject_html
{
1560 my ($long, $short, $href, $extra) = @_;
1561 $extra = '' unless defined($extra);
1563 if (length($short) < length($long)) {
1564 $long =~ s/[[:cntrl:]]/?/g;
1565 return $cgi->a({-href
=> $href, -class => "list subject",
1566 -title
=> to_utf8
($long)},
1567 esc_html
($short)) . $extra;
1569 return $cgi->a({-href
=> $href, -class => "list subject"},
1570 esc_html
($long)) . $extra;
1574 # Rather than recomputing the url for an email multiple times, we cache it
1575 # after the first hit. This gives a visible benefit in views where the avatar
1576 # for the same email is used repeatedly (e.g. shortlog).
1577 # The cache is shared by all avatar engines (currently gravatar only), which
1578 # are free to use it as preferred. Since only one avatar engine is used for any
1579 # given page, there's no risk for cache conflicts.
1580 our %avatar_cache = ();
1582 # Compute the picon url for a given email, by using the picon search service over at
1583 # http://www.cs.indiana.edu/picons/search.html
1585 my $email = lc shift;
1586 if (!$avatar_cache{$email}) {
1587 my ($user, $domain) = split('@', $email);
1588 $avatar_cache{$email} =
1589 "http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/" .
1591 "users+domains+unknown/up/single";
1593 return $avatar_cache{$email};
1596 # Compute the gravatar url for a given email, if it's not in the cache already.
1597 # Gravatar stores only the part of the URL before the size, since that's the
1598 # one computationally more expensive. This also allows reuse of the cache for
1599 # different sizes (for this particular engine).
1601 my $email = lc shift;
1603 $avatar_cache{$email} ||=
1604 "http://www.gravatar.com/avatar/" .
1605 Digest
::MD5
::md5_hex
($email) . "?s=";
1606 return $avatar_cache{$email} . $size;
1609 # Insert an avatar for the given $email at the given $size if the feature
1611 sub git_get_avatar
{
1612 my ($email, %opts) = @_;
1613 my $pre_white = ($opts{-pad_before
} ? " " : "");
1614 my $post_white = ($opts{-pad_after
} ? " " : "");
1615 $opts{-size
} ||= 'default';
1616 my $size = $avatar_size{$opts{-size
}} || $avatar_size{'default'};
1618 if ($git_avatar eq 'gravatar') {
1619 $url = gravatar_url
($email, $size);
1620 } elsif ($git_avatar eq 'picon') {
1621 $url = picon_url
($email);
1623 # Other providers can be added by extending the if chain, defining $url
1624 # as needed. If no variant puts something in $url, we assume avatars
1625 # are completely disabled/unavailable.
1628 "<img width=\"$size\" " .
1629 "class=\"avatar\" " .
1638 sub format_search_author
{
1639 my ($author, $searchtype, $displaytext) = @_;
1640 my $have_search = gitweb_check_feature
('search');
1644 if ($searchtype eq 'author') {
1645 $performed = "authored";
1646 } elsif ($searchtype eq 'committer') {
1647 $performed = "committed";
1650 return $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
1651 searchtext
=>$author,
1652 searchtype
=>$searchtype), class=>"list",
1653 title
=>"Search for commits $performed by $author"},
1657 return $displaytext;
1661 # format the author name of the given commit with the given tag
1662 # the author name is chopped and escaped according to the other
1663 # optional parameters (see chop_str).
1664 sub format_author_html
{
1667 my $author = chop_and_escape_str
($co->{'author_name'}, @_);
1668 return "<$tag class=\"author\">" .
1669 format_search_author
($co->{'author_name'}, "author",
1670 git_get_avatar
($co->{'author_email'}, -pad_after
=> 1) .
1675 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1676 sub format_git_diff_header_line
{
1678 my $diffinfo = shift;
1679 my ($from, $to) = @_;
1681 if ($diffinfo->{'nparents'}) {
1683 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1684 if ($to->{'href'}) {
1685 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1686 esc_path
($to->{'file'}));
1687 } else { # file was deleted (no href)
1688 $line .= esc_path
($to->{'file'});
1692 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1693 if ($from->{'href'}) {
1694 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1695 'a/' . esc_path
($from->{'file'}));
1696 } else { # file was added (no href)
1697 $line .= 'a/' . esc_path
($from->{'file'});
1700 if ($to->{'href'}) {
1701 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1702 'b/' . esc_path
($to->{'file'}));
1703 } else { # file was deleted
1704 $line .= 'b/' . esc_path
($to->{'file'});
1708 return "<div class=\"diff header\">$line</div>\n";
1711 # format extended diff header line, before patch itself
1712 sub format_extended_diff_header_line
{
1714 my $diffinfo = shift;
1715 my ($from, $to) = @_;
1718 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1719 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1720 esc_path
($from->{'file'}));
1722 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1723 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1724 esc_path
($to->{'file'}));
1726 # match single <mode>
1727 if ($line =~ m/\s(\d{6})$/) {
1728 $line .= '<span class="info"> (' .
1729 file_type_long
($1) .
1733 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1734 # can match only for combined diff
1736 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1737 if ($from->{'href'}[$i]) {
1738 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1740 substr($diffinfo->{'from_id'}[$i],0,7));
1745 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1748 if ($to->{'href'}) {
1749 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1750 substr($diffinfo->{'to_id'},0,7));
1755 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1756 # can match only for ordinary diff
1757 my ($from_link, $to_link);
1758 if ($from->{'href'}) {
1759 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1760 substr($diffinfo->{'from_id'},0,7));
1762 $from_link = '0' x
7;
1764 if ($to->{'href'}) {
1765 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1766 substr($diffinfo->{'to_id'},0,7));
1770 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1771 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1774 return $line . "<br/>\n";
1777 # format from-file/to-file diff header
1778 sub format_diff_from_to_header
{
1779 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1784 #assert($line =~ m/^---/) if DEBUG;
1785 # no extra formatting for "^--- /dev/null"
1786 if (! $diffinfo->{'nparents'}) {
1787 # ordinary (single parent) diff
1788 if ($line =~ m!^--- "?a/!) {
1789 if ($from->{'href'}) {
1791 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1792 esc_path
($from->{'file'}));
1795 esc_path
($from->{'file'});
1798 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1801 # combined diff (merge commit)
1802 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1803 if ($from->{'href'}[$i]) {
1805 $cgi->a({-href
=>href
(action
=>"blobdiff",
1806 hash_parent
=>$diffinfo->{'from_id'}[$i],
1807 hash_parent_base
=>$parents[$i],
1808 file_parent
=>$from->{'file'}[$i],
1809 hash
=>$diffinfo->{'to_id'},
1811 file_name
=>$to->{'file'}),
1813 -title
=>"diff" . ($i+1)},
1816 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1817 esc_path
($from->{'file'}[$i]));
1819 $line = '--- /dev/null';
1821 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1826 #assert($line =~ m/^\+\+\+/) if DEBUG;
1827 # no extra formatting for "^+++ /dev/null"
1828 if ($line =~ m!^\+\+\+ "?b/!) {
1829 if ($to->{'href'}) {
1831 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1832 esc_path
($to->{'file'}));
1835 esc_path
($to->{'file'});
1838 $result .= qq
!<div
class="diff to_file">$line</div
>\n!;
1843 # create note for patch simplified by combined diff
1844 sub format_diff_cc_simplified
{
1845 my ($diffinfo, @parents) = @_;
1848 $result .= "<div class=\"diff header\">" .
1850 if (!is_deleted
($diffinfo)) {
1851 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1853 hash
=>$diffinfo->{'to_id'},
1854 file_name
=>$diffinfo->{'to_file'}),
1856 esc_path
($diffinfo->{'to_file'}));
1858 $result .= esc_path
($diffinfo->{'to_file'});
1860 $result .= "</div>\n" . # class="diff header"
1861 "<div class=\"diff nodifferences\">" .
1863 "</div>\n"; # class="diff nodifferences"
1868 # format patch (diff) line (not to be used for diff headers)
1869 sub format_diff_line
{
1871 my ($from, $to) = @_;
1872 my $diff_class = "";
1876 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1878 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
1879 if ($line =~ m/^\@{3}/) {
1880 $diff_class = " chunk_header";
1881 } elsif ($line =~ m/^\\/) {
1882 $diff_class = " incomplete";
1883 } elsif ($prefix =~ tr/+/+/) {
1884 $diff_class = " add";
1885 } elsif ($prefix =~ tr/-/-/) {
1886 $diff_class = " rem";
1889 # assume ordinary diff
1890 my $char = substr($line, 0, 1);
1892 $diff_class = " add";
1893 } elsif ($char eq '-') {
1894 $diff_class = " rem";
1895 } elsif ($char eq '@') {
1896 $diff_class = " chunk_header";
1897 } elsif ($char eq "\\") {
1898 $diff_class = " incomplete";
1901 $line = untabify
($line);
1902 if ($from && $to && $line =~ m/^\@{2} /) {
1903 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1904 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1906 $from_lines = 0 unless defined $from_lines;
1907 $to_lines = 0 unless defined $to_lines;
1909 if ($from->{'href'}) {
1910 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1911 -class=>"list"}, $from_text);
1913 if ($to->{'href'}) {
1914 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1915 -class=>"list"}, $to_text);
1917 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1918 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1919 return "<div class=\"diff$diff_class\">$line</div>\n";
1920 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1921 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1922 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1924 @from_text = split(' ', $ranges);
1925 for (my $i = 0; $i < @from_text; ++$i) {
1926 ($from_start[$i], $from_nlines[$i]) =
1927 (split(',', substr($from_text[$i], 1)), 0);
1930 $to_text = pop @from_text;
1931 $to_start = pop @from_start;
1932 $to_nlines = pop @from_nlines;
1934 $line = "<span class=\"chunk_info\">$prefix ";
1935 for (my $i = 0; $i < @from_text; ++$i) {
1936 if ($from->{'href'}[$i]) {
1937 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1938 -class=>"list"}, $from_text[$i]);
1940 $line .= $from_text[$i];
1944 if ($to->{'href'}) {
1945 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1946 -class=>"list"}, $to_text);
1950 $line .= " $prefix</span>" .
1951 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1952 return "<div class=\"diff$diff_class\">$line</div>\n";
1954 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1957 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1958 # linked. Pass the hash of the tree/commit to snapshot.
1959 sub format_snapshot_links
{
1961 my $num_fmts = @snapshot_fmts;
1962 if ($num_fmts > 1) {
1963 # A parenthesized list of links bearing format names.
1964 # e.g. "snapshot (_tar.gz_ _zip_)"
1965 return "snapshot (" . join(' ', map
1972 }, $known_snapshot_formats{$_}{'display'})
1973 , @snapshot_fmts) . ")";
1974 } elsif ($num_fmts == 1) {
1975 # A single "snapshot" link whose tooltip bears the format name.
1977 my ($fmt) = @snapshot_fmts;
1983 snapshot_format
=>$fmt
1985 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1987 } else { # $num_fmts == 0
1992 ## ......................................................................
1993 ## functions returning values to be passed, perhaps after some
1994 ## transformation, to other functions; e.g. returning arguments to href()
1996 # returns hash to be passed to href to generate gitweb URL
1997 # in -title key it returns description of link
1999 my $format = shift || 'Atom';
2000 my %res = (action
=> lc($format));
2002 # feed links are possible only for project views
2003 return unless (defined $project);
2004 # some views should link to OPML, or to generic project feed,
2005 # or don't have specific feed yet (so they should use generic)
2006 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
2009 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
2010 # from tag links; this also makes possible to detect branch links
2011 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
2012 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
2015 # find log type for feed description (title)
2017 if (defined $file_name) {
2018 $type = "history of $file_name";
2019 $type .= "/" if ($action eq 'tree');
2020 $type .= " on '$branch'" if (defined $branch);
2022 $type = "log of $branch" if (defined $branch);
2025 $res{-title
} = $type;
2026 $res{'hash'} = (defined $branch ? "refs/heads/$branch" : undef);
2027 $res{'file_name'} = $file_name;
2032 ## ----------------------------------------------------------------------
2033 ## git utility subroutines, invoking git commands
2035 # returns path to the core git executable and the --git-dir parameter as list
2037 $number_of_git_cmds++;
2038 return $GIT, '--git-dir='.$git_dir;
2041 # quote the given arguments for passing them to the shell
2042 # quote_command("command", "arg 1", "arg with ' and ! characters")
2043 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
2044 # Try to avoid using this function wherever possible.
2047 map { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ );
2050 # get HEAD ref of given project as hash
2051 sub git_get_head_hash
{
2052 return git_get_full_hash
(shift, 'HEAD');
2055 sub git_get_full_hash
{
2056 return git_get_hash
(@_);
2059 sub git_get_short_hash
{
2060 return git_get_hash
(@_, '--short=7');
2064 my ($project, $hash, @options) = @_;
2065 my $o_git_dir = $git_dir;
2067 $git_dir = "$projectroot/$project";
2068 if (open my $fd, '-|', git_cmd
(), 'rev-parse',
2069 '--verify', '-q', @options, $hash) {
2071 chomp $retval if defined $retval;
2074 if (defined $o_git_dir) {
2075 $git_dir = $o_git_dir;
2080 # get type of given object
2084 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
2086 close $fd or return;
2091 # repository configuration
2092 our $config_file = '';
2095 # store multiple values for single key as anonymous array reference
2096 # single values stored directly in the hash, not as [ <value> ]
2097 sub hash_set_multi
{
2098 my ($hash, $key, $value) = @_;
2100 if (!exists $hash->{$key}) {
2101 $hash->{$key} = $value;
2102 } elsif (!ref $hash->{$key}) {
2103 $hash->{$key} = [ $hash->{$key}, $value ];
2105 push @{$hash->{$key}}, $value;
2109 # return hash of git project configuration
2110 # optionally limited to some section, e.g. 'gitweb'
2111 sub git_parse_project_config
{
2112 my $section_regexp = shift;
2117 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
2120 while (my $keyval = <$fh>) {
2122 my ($key, $value) = split(/\n/, $keyval, 2);
2124 hash_set_multi
(\
%config, $key, $value)
2125 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
2132 # convert config value to boolean: 'true' or 'false'
2133 # no value, number > 0, 'true' and 'yes' values are true
2134 # rest of values are treated as false (never as error)
2135 sub config_to_bool
{
2138 return 1 if !defined $val; # section.key
2140 # strip leading and trailing whitespace
2144 return (($val =~ /^\d+$/ && $val) || # section.key = 1
2145 ($val =~ /^(?:true|yes)$/i)); # section.key = true
2148 # convert config value to simple decimal number
2149 # an optional value suffix of 'k', 'm', or 'g' will cause the value
2150 # to be multiplied by 1024, 1048576, or 1073741824
2154 # strip leading and trailing whitespace
2158 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
2160 # unknown unit is treated as 1
2161 return $num * ($unit eq 'g' ? 1073741824 :
2162 $unit eq 'm' ? 1048576 :
2163 $unit eq 'k' ? 1024 : 1);
2168 # convert config value to array reference, if needed
2169 sub config_to_multi
{
2172 return ref($val) ? $val : (defined($val) ? [ $val ] : []);
2175 sub git_get_project_config
{
2176 my ($key, $type) = @_;
2179 return unless ($key);
2180 $key =~ s/^gitweb\.//;
2181 return if ($key =~ m/\W/);
2184 if (defined $type) {
2187 unless ($type eq 'bool' || $type eq 'int');
2191 if (!defined $config_file ||
2192 $config_file ne "$git_dir/config") {
2193 %config = git_parse_project_config
('gitweb');
2194 $config_file = "$git_dir/config";
2197 # check if config variable (key) exists
2198 return unless exists $config{"gitweb.$key"};
2201 if (!defined $type) {
2202 return $config{"gitweb.$key"};
2203 } elsif ($type eq 'bool') {
2204 # backward compatibility: 'git config --bool' returns true/false
2205 return config_to_bool
($config{"gitweb.$key"}) ? 'true' : 'false';
2206 } elsif ($type eq 'int') {
2207 return config_to_int
($config{"gitweb.$key"});
2209 return $config{"gitweb.$key"};
2212 # get hash of given path at given ref
2213 sub git_get_hash_by_path
{
2215 my $path = shift || return undef;
2220 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
2221 or die_error
(500, "Open git-ls-tree failed");
2223 close $fd or return undef;
2225 if (!defined $line) {
2226 # there is no tree or hash given by $path at $base
2230 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2231 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
2232 if (defined $type && $type ne $2) {
2233 # type doesn't match
2239 # get path of entry with given hash at given tree-ish (ref)
2240 # used to get 'from' filename for combined diff (merge commit) for renames
2241 sub git_get_path_by_hash
{
2242 my $base = shift || return;
2243 my $hash = shift || return;
2247 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
2249 while (my $line = <$fd>) {
2252 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
2253 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
2254 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
2263 ## ......................................................................
2264 ## git utility functions, directly accessing git repository
2266 sub git_get_project_description
{
2269 $git_dir = "$projectroot/$path";
2270 open my $fd, '<', "$git_dir/description"
2271 or return git_get_project_config
('description');
2274 if (defined $descr) {
2280 sub git_get_project_ctags
{
2284 $git_dir = "$projectroot/$path";
2285 opendir my $dh, "$git_dir/ctags"
2287 foreach (grep { -f
$_ } map { "$git_dir/ctags/$_" } readdir($dh)) {
2288 open my $ct, '<', $_ or next;
2292 my $ctag = $_; $ctag =~ s
#.*/##;
2293 $ctags->{$ctag} = $val;
2299 sub git_populate_project_tagcloud
{
2302 # First, merge different-cased tags; tags vote on casing
2304 foreach (keys %$ctags) {
2305 $ctags_lc{lc $_}->{count
} += $ctags->{$_};
2306 if (not $ctags_lc{lc $_}->{topcount
}
2307 or $ctags_lc{lc $_}->{topcount
} < $ctags->{$_}) {
2308 $ctags_lc{lc $_}->{topcount
} = $ctags->{$_};
2309 $ctags_lc{lc $_}->{topname
} = $_;
2314 if (eval { require HTML
::TagCloud
; 1; }) {
2315 $cloud = HTML
::TagCloud-
>new;
2316 foreach (sort keys %ctags_lc) {
2317 # Pad the title with spaces so that the cloud looks
2319 my $title = $ctags_lc{$_}->{topname
};
2320 $title =~ s/ / /g;
2321 $title =~ s/^/ /g;
2322 $title =~ s/$/ /g;
2323 $cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count
});
2326 $cloud = \
%ctags_lc;
2331 sub git_show_project_tagcloud
{
2332 my ($cloud, $count) = @_;
2333 print STDERR
ref($cloud)."..\n";
2334 if (ref $cloud eq 'HTML::TagCloud') {
2335 return $cloud->html_and_css($count);
2337 my @tags = sort { $cloud->{$a}->{count
} <=> $cloud->{$b}->{count
} } keys %$cloud;
2338 return '<p align="center">' . join (', ', map {
2339 "<a href=\"$home_link?by_tag=$_\">$cloud->{$_}->{topname}</a>"
2340 } splice(@tags, 0, $count)) . '</p>';
2344 sub git_get_project_url_list
{
2347 $git_dir = "$projectroot/$path";
2348 open my $fd, '<', "$git_dir/cloneurl"
2349 or return wantarray ?
2350 @{ config_to_multi
(git_get_project_config
('url')) } :
2351 config_to_multi
(git_get_project_config
('url'));
2352 my @git_project_url_list = map { chomp; $_ } <$fd>;
2355 return wantarray ? @git_project_url_list : \
@git_project_url_list;
2358 sub git_get_projects_list
{
2363 $filter =~ s/\.git$//;
2365 my $check_forks = gitweb_check_feature
('forks');
2367 if (-d
$projects_list) {
2368 # search in directory
2369 my $dir = $projects_list . ($filter ? "/$filter" : '');
2370 # remove the trailing "/"
2372 my $pfxlen = length("$dir");
2373 my $pfxdepth = ($dir =~ tr!/!!);
2376 follow_fast
=> 1, # follow symbolic links
2377 follow_skip
=> 2, # ignore duplicates
2378 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
2380 # skip project-list toplevel, if we get it.
2381 return if (m!^[/.]$!);
2382 # only directories can be git repositories
2383 return unless (-d
$_);
2384 # don't traverse too deep (Find is super slow on os x)
2385 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
2386 $File::Find
::prune
= 1;
2390 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
2391 # we check related file in $projectroot
2392 my $path = ($filter ? "$filter/" : '') . $subdir;
2393 if (check_export_ok
("$projectroot/$path")) {
2394 push @list, { path
=> $path };
2395 $File::Find
::prune
= 1;
2400 } elsif (-f
$projects_list) {
2401 # read from file(url-encoded):
2402 # 'git%2Fgit.git Linus+Torvalds'
2403 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2404 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2406 open my $fd, '<', $projects_list or return;
2408 while (my $line = <$fd>) {
2410 my ($path, $owner) = split ' ', $line;
2411 $path = unescape
($path);
2412 $owner = unescape
($owner);
2413 if (!defined $path) {
2416 if ($filter ne '') {
2417 # looking for forks;
2418 my $pfx = substr($path, 0, length($filter));
2419 if ($pfx ne $filter) {
2422 my $sfx = substr($path, length($filter));
2423 if ($sfx !~ /^\/.*\
.git
$/) {
2426 } elsif ($check_forks) {
2428 foreach my $filter (keys %paths) {
2429 # looking for forks;
2430 my $pfx = substr($path, 0, length($filter));
2431 if ($pfx ne $filter) {
2434 my $sfx = substr($path, length($filter));
2435 if ($sfx !~ /^\/.*\
.git
$/) {
2438 # is a fork, don't include it in
2443 if (check_export_ok
("$projectroot/$path")) {
2446 owner
=> to_utf8
($owner),
2449 (my $forks_path = $path) =~ s/\.git$//;
2450 $paths{$forks_path}++;
2458 our $gitweb_project_owner = undef;
2459 sub git_get_project_list_from_file
{
2461 return if (defined $gitweb_project_owner);
2463 $gitweb_project_owner = {};
2464 # read from file (url-encoded):
2465 # 'git%2Fgit.git Linus+Torvalds'
2466 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
2467 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
2468 if (-f
$projects_list) {
2469 open(my $fd, '<', $projects_list);
2470 while (my $line = <$fd>) {
2472 my ($pr, $ow) = split ' ', $line;
2473 $pr = unescape
($pr);
2474 $ow = unescape
($ow);
2475 $gitweb_project_owner->{$pr} = to_utf8
($ow);
2481 sub git_get_project_owner
{
2482 my $project = shift;
2485 return undef unless $project;
2486 $git_dir = "$projectroot/$project";
2488 if (!defined $gitweb_project_owner) {
2489 git_get_project_list_from_file
();
2492 if (exists $gitweb_project_owner->{$project}) {
2493 $owner = $gitweb_project_owner->{$project};
2495 if (!defined $owner){
2496 $owner = git_get_project_config
('owner');
2498 if (!defined $owner) {
2499 $owner = get_file_owner
("$git_dir");
2505 sub git_get_last_activity
{
2509 $git_dir = "$projectroot/$path";
2510 open($fd, "-|", git_cmd
(), 'for-each-ref',
2511 '--format=%(committer)',
2512 '--sort=-committerdate',
2514 'refs/heads') or return;
2515 my $most_recent = <$fd>;
2516 close $fd or return;
2517 if (defined $most_recent &&
2518 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
2520 my $age = time - $timestamp;
2521 return ($age, age_string
($age));
2523 return (undef, undef);
2526 sub git_get_references
{
2527 my $type = shift || "";
2529 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
2530 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
2531 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
2532 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
2535 while (my $line = <$fd>) {
2537 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
2538 if (defined $refs{$1}) {
2539 push @{$refs{$1}}, $2;
2545 close $fd or return;
2549 sub git_get_rev_name_tags
{
2550 my $hash = shift || return undef;
2552 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
2554 my $name_rev = <$fd>;
2557 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
2560 # catches also '$hash undefined' output
2565 ## ----------------------------------------------------------------------
2566 ## parse to hash functions
2570 my $tz = shift || "-0000";
2573 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
2574 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
2575 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
2576 $date{'hour'} = $hour;
2577 $date{'minute'} = $min;
2578 $date{'mday'} = $mday;
2579 $date{'day'} = $days[$wday];
2580 $date{'month'} = $months[$mon];
2581 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2582 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2583 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2584 $mday, $months[$mon], $hour ,$min;
2585 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2586 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2588 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2589 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2590 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2591 $date{'hour_local'} = $hour;
2592 $date{'minute_local'} = $min;
2593 $date{'tz_local'} = $tz;
2594 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2595 1900+$year, $mon+1, $mday,
2596 $hour, $min, $sec, $tz);
2605 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
2606 $tag{'id'} = $tag_id;
2607 while (my $line = <$fd>) {
2609 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2610 $tag{'object'} = $1;
2611 } elsif ($line =~ m/^type (.+)$/) {
2613 } elsif ($line =~ m/^tag (.+)$/) {
2615 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2616 $tag{'author'} = $1;
2617 $tag{'author_epoch'} = $2;
2618 $tag{'author_tz'} = $3;
2619 if ($tag{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2620 $tag{'author_name'} = $1;
2621 $tag{'author_email'} = $2;
2623 $tag{'author_name'} = $tag{'author'};
2625 } elsif ($line =~ m/--BEGIN/) {
2626 push @comment, $line;
2628 } elsif ($line eq "") {
2632 push @comment, <$fd>;
2633 $tag{'comment'} = \
@comment;
2634 close $fd or return;
2635 if (!defined $tag{'name'}) {
2641 sub parse_commit_text
{
2642 my ($commit_text, $withparents) = @_;
2643 my @commit_lines = split '\n', $commit_text;
2646 pop @commit_lines; # Remove '\0'
2648 if (! @commit_lines) {
2652 my $header = shift @commit_lines;
2653 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2656 ($co{'id'}, my @parents) = split ' ', $header;
2657 while (my $line = shift @commit_lines) {
2658 last if $line eq "\n";
2659 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2661 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2663 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2664 $co{'author'} = to_utf8
($1);
2665 $co{'author_epoch'} = $2;
2666 $co{'author_tz'} = $3;
2667 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2668 $co{'author_name'} = $1;
2669 $co{'author_email'} = $2;
2671 $co{'author_name'} = $co{'author'};
2673 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2674 $co{'committer'} = to_utf8
($1);
2675 $co{'committer_epoch'} = $2;
2676 $co{'committer_tz'} = $3;
2677 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2678 $co{'committer_name'} = $1;
2679 $co{'committer_email'} = $2;
2681 $co{'committer_name'} = $co{'committer'};
2685 if (!defined $co{'tree'}) {
2688 $co{'parents'} = \
@parents;
2689 $co{'parent'} = $parents[0];
2691 foreach my $title (@commit_lines) {
2694 $co{'title'} = chop_str
($title, 80, 5);
2695 # remove leading stuff of merges to make the interesting part visible
2696 if (length($title) > 50) {
2697 $title =~ s/^Automatic //;
2698 $title =~ s/^merge (of|with) /Merge ... /i;
2699 if (length($title) > 50) {
2700 $title =~ s/(http|rsync):\/\///;
2702 if (length($title) > 50) {
2703 $title =~ s/(master|www|rsync)\.//;
2705 if (length($title) > 50) {
2706 $title =~ s/kernel.org:?//;
2708 if (length($title) > 50) {
2709 $title =~ s/\/pub\/scm//;
2712 $co{'title_short'} = chop_str
($title, 50, 5);
2716 if (! defined $co{'title'} || $co{'title'} eq "") {
2717 $co{'title'} = $co{'title_short'} = '(no commit message)';
2719 # remove added spaces
2720 foreach my $line (@commit_lines) {
2723 $co{'comment'} = \
@commit_lines;
2725 my $age = time - $co{'committer_epoch'};
2727 $co{'age_string'} = age_string
($age);
2728 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2729 if ($age > 60*60*24*7*2) {
2730 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2731 $co{'age_string_age'} = $co{'age_string'};
2733 $co{'age_string_date'} = $co{'age_string'};
2734 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2740 my ($commit_id) = @_;
2745 open my $fd, "-|", git_cmd
(), "rev-list",
2751 or die_error
(500, "Open git-rev-list failed");
2752 %co = parse_commit_text
(<$fd>, 1);
2759 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2767 open my $fd, "-|", git_cmd
(), "rev-list",
2770 ("--max-count=" . $maxcount),
2771 ("--skip=" . $skip),
2775 ($filename ? ($filename) : ())
2776 or die_error
(500, "Open git-rev-list failed");
2777 while (my $line = <$fd>) {
2778 my %co = parse_commit_text
($line);
2783 return wantarray ? @cos : \
@cos;
2786 # parse line of git-diff-tree "raw" output
2787 sub parse_difftree_raw_line
{
2791 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2792 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2793 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2794 $res{'from_mode'} = $1;
2795 $res{'to_mode'} = $2;
2796 $res{'from_id'} = $3;
2798 $res{'status'} = $5;
2799 $res{'similarity'} = $6;
2800 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2801 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2803 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2806 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2807 # combined diff (for merge commit)
2808 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2809 $res{'nparents'} = length($1);
2810 $res{'from_mode'} = [ split(' ', $2) ];
2811 $res{'to_mode'} = pop @{$res{'from_mode'}};
2812 $res{'from_id'} = [ split(' ', $3) ];
2813 $res{'to_id'} = pop @{$res{'from_id'}};
2814 $res{'status'} = [ split('', $4) ];
2815 $res{'to_file'} = unquote
($5);
2817 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2818 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2819 $res{'commit'} = $1;
2822 return wantarray ? %res : \
%res;
2825 # wrapper: return parsed line of git-diff-tree "raw" output
2826 # (the argument might be raw line, or parsed info)
2827 sub parsed_difftree_line
{
2828 my $line_or_ref = shift;
2830 if (ref($line_or_ref) eq "HASH") {
2831 # pre-parsed (or generated by hand)
2832 return $line_or_ref;
2834 return parse_difftree_raw_line
($line_or_ref);
2838 # parse line of git-ls-tree output
2839 sub parse_ls_tree_line
{
2845 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa 16717 panic.c'
2846 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40}) +(-|[0-9]+)\t(.+)$/s;
2855 $res{'name'} = unquote
($5);
2858 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2859 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2867 $res{'name'} = unquote
($4);
2871 return wantarray ? %res : \
%res;
2874 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2875 sub parse_from_to_diffinfo
{
2876 my ($diffinfo, $from, $to, @parents) = @_;
2878 if ($diffinfo->{'nparents'}) {
2880 $from->{'file'} = [];
2881 $from->{'href'} = [];
2882 fill_from_file_info
($diffinfo, @parents)
2883 unless exists $diffinfo->{'from_file'};
2884 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2885 $from->{'file'}[$i] =
2886 defined $diffinfo->{'from_file'}[$i] ?
2887 $diffinfo->{'from_file'}[$i] :
2888 $diffinfo->{'to_file'};
2889 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2890 $from->{'href'}[$i] = href
(action
=>"blob",
2891 hash_base
=>$parents[$i],
2892 hash
=>$diffinfo->{'from_id'}[$i],
2893 file_name
=>$from->{'file'}[$i]);
2895 $from->{'href'}[$i] = undef;
2899 # ordinary (not combined) diff
2900 $from->{'file'} = $diffinfo->{'from_file'};
2901 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2902 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2903 hash
=>$diffinfo->{'from_id'},
2904 file_name
=>$from->{'file'});
2906 delete $from->{'href'};
2910 $to->{'file'} = $diffinfo->{'to_file'};
2911 if (!is_deleted
($diffinfo)) { # file exists in result
2912 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2913 hash
=>$diffinfo->{'to_id'},
2914 file_name
=>$to->{'file'});
2916 delete $to->{'href'};
2920 ## ......................................................................
2921 ## parse to array of hashes functions
2923 sub git_get_heads_list
{
2927 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2928 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
2929 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2932 while (my $line = <$fd>) {
2936 my ($refinfo, $committerinfo) = split(/\0/, $line);
2937 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2938 my ($committer, $epoch, $tz) =
2939 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2940 $ref_item{'fullname'} = $name;
2941 $name =~ s!^refs/heads/!!;
2943 $ref_item{'name'} = $name;
2944 $ref_item{'id'} = $hash;
2945 $ref_item{'title'} = $title || '(no commit message)';
2946 $ref_item{'epoch'} = $epoch;
2948 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2950 $ref_item{'age'} = "unknown";
2953 push @headslist, \
%ref_item;
2957 return wantarray ? @headslist : \
@headslist;
2960 sub git_get_tags_list
{
2964 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2965 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
2966 '--format=%(objectname) %(objecttype) %(refname) '.
2967 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2970 while (my $line = <$fd>) {
2974 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2975 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2976 my ($creator, $epoch, $tz) =
2977 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2978 $ref_item{'fullname'} = $name;
2979 $name =~ s!^refs/tags/!!;
2981 $ref_item{'type'} = $type;
2982 $ref_item{'id'} = $id;
2983 $ref_item{'name'} = $name;
2984 if ($type eq "tag") {
2985 $ref_item{'subject'} = $title;
2986 $ref_item{'reftype'} = $reftype;
2987 $ref_item{'refid'} = $refid;
2989 $ref_item{'reftype'} = $type;
2990 $ref_item{'refid'} = $id;
2993 if ($type eq "tag" || $type eq "commit") {
2994 $ref_item{'epoch'} = $epoch;
2996 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2998 $ref_item{'age'} = "unknown";
3002 push @tagslist, \
%ref_item;
3006 return wantarray ? @tagslist : \
@tagslist;
3009 ## ----------------------------------------------------------------------
3010 ## filesystem-related functions
3012 sub get_file_owner
{
3015 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
3016 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
3017 if (!defined $gcos) {
3021 $owner =~ s/[,;].*$//;
3022 return to_utf8
($owner);
3025 # assume that file exists
3027 my $filename = shift;
3029 open my $fd, '<', $filename;
3030 print map { to_utf8
($_) } <$fd>;
3034 ## ......................................................................
3035 ## mimetype related functions
3037 sub mimetype_guess_file
{
3038 my $filename = shift;
3039 my $mimemap = shift;
3040 -r
$mimemap or return undef;
3043 open(my $mh, '<', $mimemap) or return undef;
3045 next if m/^#/; # skip comments
3046 my ($mimetype, $exts) = split(/\t+/);
3047 if (defined $exts) {
3048 my @exts = split(/\s+/, $exts);
3049 foreach my $ext (@exts) {
3050 $mimemap{$ext} = $mimetype;
3056 $filename =~ /\.([^.]*)$/;
3057 return $mimemap{$1};
3060 sub mimetype_guess
{
3061 my $filename = shift;
3063 $filename =~ /\./ or return undef;
3065 if ($mimetypes_file) {
3066 my $file = $mimetypes_file;
3067 if ($file !~ m!^/!) { # if it is relative path
3068 # it is relative to project
3069 $file = "$projectroot/$project/$file";
3071 $mime = mimetype_guess_file
($filename, $file);
3073 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
3079 my $filename = shift;
3082 my $mime = mimetype_guess
($filename);
3083 $mime and return $mime;
3087 return $default_blob_plain_mimetype unless $fd;
3090 return 'text/plain';
3091 } elsif (! $filename) {
3092 return 'application/octet-stream';
3093 } elsif ($filename =~ m/\.png$/i) {
3095 } elsif ($filename =~ m/\.gif$/i) {
3097 } elsif ($filename =~ m/\.jpe?g$/i) {
3098 return 'image/jpeg';
3100 return 'application/octet-stream';
3104 sub blob_contenttype
{
3105 my ($fd, $file_name, $type) = @_;
3107 $type ||= blob_mimetype
($fd, $file_name);
3108 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
3109 $type .= "; charset=$default_text_plain_charset";
3115 ## ======================================================================
3116 ## functions printing HTML: header, footer, error page
3118 sub git_header_html
{
3119 my $status = shift || "200 OK";
3120 my $expires = shift;
3122 my $title = "$site_name";
3123 if (defined $project) {
3124 $title .= " - " . to_utf8
($project);
3125 if (defined $action) {
3126 $title .= "/$action";
3127 if (defined $file_name) {
3128 $title .= " - " . esc_path
($file_name);
3129 if ($action eq "tree" && $file_name !~ m
|/$|) {
3136 # require explicit support from the UA if we are to send the page as
3137 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
3138 # we have to do this because MSIE sometimes globs '*/*', pretending to
3139 # support xhtml+xml but choking when it gets what it asked for.
3140 if (defined $cgi->http('HTTP_ACCEPT') &&
3141 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
3142 $cgi->Accept('application/xhtml+xml') != 0) {
3143 $content_type = 'application/xhtml+xml';
3145 $content_type = 'text/html';
3147 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
3148 -status
=> $status, -expires
=> $expires);
3149 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
3151 <?xml version="1.0" encoding="utf-8"?>
3152 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3153 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
3154 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
3155 <!-- git core binaries version $git_version -->
3157 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
3158 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
3159 <meta name="robots" content="index, nofollow"/>
3160 <title>$title</title>
3162 # the stylesheet, favicon etc urls won't work correctly with path_info
3163 # unless we set the appropriate base URL
3164 if ($ENV{'PATH_INFO'}) {
3165 print "<base href=\"".esc_url
($base_url)."\" />\n";
3167 # print out each stylesheet that exist, providing backwards capability
3168 # for those people who defined $stylesheet in a config file
3169 if (defined $stylesheet) {
3170 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
3172 foreach my $stylesheet (@stylesheets) {
3173 next unless $stylesheet;
3174 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
3177 if (defined $project) {
3178 my %href_params = get_feed_info
();
3179 if (!exists $href_params{'-title'}) {
3180 $href_params{'-title'} = 'log';
3183 foreach my $format qw(RSS Atom) {
3184 my $type = lc($format);
3186 '-rel' => 'alternate',
3187 '-title' => "$project - $href_params{'-title'} - $format feed",
3188 '-type' => "application/$type+xml"
3191 $href_params{'action'} = $type;
3192 $link_attr{'-href'} = href
(%href_params);
3194 "rel=\"$link_attr{'-rel'}\" ".
3195 "title=\"$link_attr{'-title'}\" ".
3196 "href=\"$link_attr{'-href'}\" ".
3197 "type=\"$link_attr{'-type'}\" ".
3200 $href_params{'extra_options'} = '--no-merges';
3201 $link_attr{'-href'} = href
(%href_params);
3202 $link_attr{'-title'} .= ' (no merges)';
3204 "rel=\"$link_attr{'-rel'}\" ".
3205 "title=\"$link_attr{'-title'}\" ".
3206 "href=\"$link_attr{'-href'}\" ".
3207 "type=\"$link_attr{'-type'}\" ".
3212 printf('<link rel="alternate" title="%s projects list" '.
3213 'href="%s" type="text/plain; charset=utf-8" />'."\n",
3214 $site_name, href
(project
=>undef, action
=>"project_index"));
3215 printf('<link rel="alternate" title="%s projects feeds" '.
3216 'href="%s" type="text/x-opml" />'."\n",
3217 $site_name, href
(project
=>undef, action
=>"opml"));
3219 if (defined $favicon) {
3220 print qq(<link rel="shortcut icon" href="$favicon" type="image/png" />\n);
3226 if (-f
$site_header) {
3227 insert_file
($site_header);
3230 print "<div class=\"page_header\">\n" .
3231 $cgi->a({-href
=> esc_url
($logo_url),
3232 -title
=> $logo_label},
3233 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
3234 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
3235 if (defined $project) {
3236 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
3237 if (defined $action) {
3244 my $have_search = gitweb_check_feature
('search');
3245 if (defined $project && $have_search) {
3246 if (!defined $searchtext) {
3250 if (defined $hash_base) {
3251 $search_hash = $hash_base;
3252 } elsif (defined $hash) {
3253 $search_hash = $hash;
3255 $search_hash = "HEAD";
3257 my $action = $my_uri;
3258 my $use_pathinfo = gitweb_check_feature
('pathinfo');
3259 if ($use_pathinfo) {
3260 $action .= "/".esc_url
($project);
3262 print $cgi->startform(-method => "get", -action
=> $action) .
3263 "<div class=\"search\">\n" .
3265 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
3266 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
3267 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
3268 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
3269 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
3270 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
3272 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
3273 "<span title=\"Extended regular expression\">" .
3274 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
3275 -checked
=> $search_use_regexp) .
3278 $cgi->end_form() . "\n";
3282 sub git_footer_html
{
3283 my $feed_class = 'rss_logo';
3285 print "<div class=\"page_footer\">\n";
3286 if (defined $project) {
3287 my $descr = git_get_project_description
($project);
3288 if (defined $descr) {
3289 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
3292 my %href_params = get_feed_info
();
3293 if (!%href_params) {
3294 $feed_class .= ' generic';
3296 $href_params{'-title'} ||= 'log';
3298 foreach my $format qw(RSS Atom) {
3299 $href_params{'action'} = lc($format);
3300 print $cgi->a({-href
=> href
(%href_params),
3301 -title
=> "$href_params{'-title'} $format feed",
3302 -class => $feed_class}, $format)."\n";
3306 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
3307 -class => $feed_class}, "OPML") . " ";
3308 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
3309 -class => $feed_class}, "TXT") . "\n";
3311 print "</div>\n"; # class="page_footer"
3313 if (defined $t0 && gitweb_check_feature
('timed')) {
3314 print "<div id=\"generating_info\">\n";
3315 print 'This page took '.
3316 '<span id="generating_time" class="time_span">'.
3317 Time
::HiRes
::tv_interval
($t0, [Time
::HiRes
::gettimeofday
()]).
3320 '<span id="generating_cmd">'.
3321 $number_of_git_cmds.
3322 '</span> git commands '.
3324 print "</div>\n"; # class="page_footer"
3327 if (-f
$site_footer) {
3328 insert_file
($site_footer);
3331 print qq
!<script type
="text/javascript" src
="$javascript"></script
>\n!;
3332 if ($action eq 'blame_incremental') {
3333 print qq
!<script type
="text/javascript">\n!.
3334 qq
!startBlame
("!. href(action=>"blame_data
", -replay=>1) .qq!",\n!.
3335 qq
! "!. href() .qq!");\n!.
3337 } elsif (gitweb_check_feature
('javascript-actions')) {
3338 print qq
!<script type
="text/javascript">\n!.
3339 qq
!window
.onload
= fixLinks
;\n!.
3347 # die_error(<http_status_code>, <error_message>)
3348 # Example: die_error(404, 'Hash not found')
3349 # By convention, use the following status codes (as defined in RFC 2616):
3350 # 400: Invalid or missing CGI parameters, or
3351 # requested object exists but has wrong type.
3352 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
3353 # this server or project.
3354 # 404: Requested object/revision/project doesn't exist.
3355 # 500: The server isn't configured properly, or
3356 # an internal error occurred (e.g. failed assertions caused by bugs), or
3357 # an unknown error occurred (e.g. the git binary died unexpectedly).
3359 my $status = shift || 500;
3360 my $error = shift || "Internal server error";
3362 my %http_responses = (400 => '400 Bad Request',
3363 403 => '403 Forbidden',
3364 404 => '404 Not Found',
3365 500 => '500 Internal Server Error');
3366 git_header_html
($http_responses{$status});
3368 <div class="page_body">
3378 ## ----------------------------------------------------------------------
3379 ## functions printing or outputting HTML: navigation
3381 sub git_print_page_nav
{
3382 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
3383 $extra = '' if !defined $extra; # pager or formats
3385 my @navs = qw(summary shortlog log commit commitdiff tree);
3387 @navs = grep { $_ ne $suppress } @navs;
3390 my %arg = map { $_ => {action
=>$_} } @navs;
3391 if (defined $head) {
3392 for (qw(commit commitdiff)) {
3393 $arg{$_}{'hash'} = $head;
3395 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
3396 for (qw(shortlog log)) {
3397 $arg{$_}{'hash'} = $head;
3402 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
3403 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
3405 my @actions = gitweb_get_feature
('actions');
3408 'n' => $project, # project name
3409 'f' => $git_dir, # project path within filesystem
3410 'h' => $treehead || '', # current hash ('h' parameter)
3411 'b' => $treebase || '', # hash base ('hb' parameter)
3414 my ($label, $link, $pos) = splice(@actions,0,3);
3416 @navs = map { $_ eq $pos ? ($_, $label) : $_ } @navs;
3418 $link =~ s/%([%nfhb])/$repl{$1}/g;
3419 $arg{$label}{'_href'} = $link;
3422 print "<div class=\"page_nav\">\n" .
3424 map { $_ eq $current ?
3425 $_ : $cgi->a({-href
=> ($arg{$_}{_href
} ? $arg{$_}{_href
} : href
(%{$arg{$_}}))}, "$_")
3427 print "<br/>\n$extra<br/>\n" .
3431 sub format_paging_nav
{
3432 my ($action, $page, $has_next_link) = @_;
3438 $cgi->a({-href
=> href
(-replay
=>1, page
=>undef)}, "first") .
3440 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
3441 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3443 $paging_nav .= "first ⋅ prev";
3446 if ($has_next_link) {
3447 $paging_nav .= " ⋅ " .
3448 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
3449 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3451 $paging_nav .= " ⋅ next";
3457 ## ......................................................................
3458 ## functions printing or outputting HTML: div
3460 sub git_print_header_div
{
3461 my ($action, $title, $hash, $hash_base) = @_;
3464 $args{'action'} = $action;
3465 $args{'hash'} = $hash if $hash;
3466 $args{'hash_base'} = $hash_base if $hash_base;
3468 print "<div class=\"header\">\n" .
3469 $cgi->a({-href
=> href
(%args), -class => "title"},
3470 $title ? $title : $action) .
3474 sub print_local_time
{
3476 if ($date{'hour_local'} < 6) {
3477 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3478 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3480 printf(" (%02d:%02d %s)",
3481 $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'});
3485 # Outputs the author name and date in long form
3486 sub git_print_authorship
{
3489 my $tag = $opts{-tag
} || 'div';
3490 my $author = $co->{'author_name'};
3492 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
3493 print "<$tag class=\"author_date\">" .
3494 format_search_author
($author, "author", esc_html
($author)) .
3496 print_local_time
(%ad) if ($opts{-localtime});
3497 print "]" . git_get_avatar
($co->{'author_email'}, -pad_before
=> 1)
3501 # Outputs table rows containing the full author or committer information,
3502 # in the format expected for 'commit' view (& similia).
3503 # Parameters are a commit hash reference, followed by the list of people
3504 # to output information for. If the list is empty it defalts to both
3505 # author and committer.
3506 sub git_print_authorship_rows
{
3508 # too bad we can't use @people = @_ || ('author', 'committer')
3510 @people = ('author', 'committer') unless @people;
3511 foreach my $who (@people) {
3512 my %wd = parse_date
($co->{"${who}_epoch"}, $co->{"${who}_tz"});
3513 print "<tr><td>$who</td><td>" .
3514 format_search_author
($co->{"${who}_name"}, $who,
3515 esc_html
($co->{"${who}_name"})) . " " .
3516 format_search_author
($co->{"${who}_email"}, $who,
3517 esc_html
("<" . $co->{"${who}_email"} . ">")) .
3518 "</td><td rowspan=\"2\">" .
3519 git_get_avatar
($co->{"${who}_email"}, -size
=> 'double') .
3522 "<td></td><td> $wd{'rfc2822'}";
3523 print_local_time
(%wd);
3529 sub git_print_page_path
{
3535 print "<div class=\"page_path\">";
3536 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
3537 -title
=> 'tree root'}, to_utf8
("[$project]"));
3539 if (defined $name) {
3540 my @dirname = split '/', $name;
3541 my $basename = pop @dirname;
3544 foreach my $dir (@dirname) {
3545 $fullname .= ($fullname ? '/' : '') . $dir;
3546 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
3548 -title
=> $fullname}, esc_path
($dir));
3551 if (defined $type && $type eq 'blob') {
3552 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
3554 -title
=> $name}, esc_path
($basename));
3555 } elsif (defined $type && $type eq 'tree') {
3556 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
3558 -title
=> $name}, esc_path
($basename));
3561 print esc_path
($basename);
3564 print "<br/></div>\n";
3571 if ($opts{'-remove_title'}) {
3572 # remove title, i.e. first line of log
3575 # remove leading empty lines
3576 while (defined $log->[0] && $log->[0] eq "") {
3583 foreach my $line (@$log) {
3584 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
3587 if (! $opts{'-remove_signoff'}) {
3588 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
3591 # remove signoff lines
3598 # print only one empty line
3599 # do not print empty line after signoff
3601 next if ($empty || $signoff);
3607 print format_log_line_html
($line) . "<br/>\n";
3610 if ($opts{'-final_empty_line'}) {
3611 # end with single empty line
3612 print "<br/>\n" unless $empty;
3616 # return link target (what link points to)
3617 sub git_get_link_target
{
3622 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3626 $link_target = <$fd>;
3631 return $link_target;
3634 # given link target, and the directory (basedir) the link is in,
3635 # return target of link relative to top directory (top tree);
3636 # return undef if it is not possible (including absolute links).
3637 sub normalize_link_target
{
3638 my ($link_target, $basedir) = @_;
3640 # absolute symlinks (beginning with '/') cannot be normalized
3641 return if (substr($link_target, 0, 1) eq '/');
3643 # normalize link target to path from top (root) tree (dir)
3646 $path = $basedir . '/' . $link_target;
3648 # we are in top (root) tree (dir)
3649 $path = $link_target;
3652 # remove //, /./, and /../
3654 foreach my $part (split('/', $path)) {
3655 # discard '.' and ''
3656 next if (!$part || $part eq '.');
3658 if ($part eq '..') {
3662 # link leads outside repository (outside top dir)
3666 push @path_parts, $part;
3669 $path = join('/', @path_parts);
3674 # print tree entry (row of git_tree), but without encompassing <tr> element
3675 sub git_print_tree_entry
{
3676 my ($t, $basedir, $hash_base, $have_blame) = @_;
3679 $base_key{'hash_base'} = $hash_base if defined $hash_base;
3681 # The format of a table row is: mode list link. Where mode is
3682 # the mode of the entry, list is the name of the entry, an href,
3683 # and link is the action links of the entry.
3685 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
3686 if (exists $t->{'size'}) {
3687 print "<td class=\"size\">$t->{'size'}</td>\n";
3689 if ($t->{'type'} eq "blob") {
3690 print "<td class=\"list\">" .
3691 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3692 file_name
=>"$basedir$t->{'name'}", %base_key),
3693 -class => "list"}, esc_path
($t->{'name'}));
3694 if (S_ISLNK
(oct $t->{'mode'})) {
3695 my $link_target = git_get_link_target
($t->{'hash'});
3697 my $norm_target = normalize_link_target
($link_target, $basedir);
3698 if (defined $norm_target) {
3700 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
3701 file_name
=>$norm_target),
3702 -title
=> $norm_target}, esc_path
($link_target));
3704 print " -> " . esc_path
($link_target);
3709 print "<td class=\"link\">";
3710 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3711 file_name
=>"$basedir$t->{'name'}", %base_key)},
3715 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
3716 file_name
=>"$basedir$t->{'name'}", %base_key)},
3719 if (defined $hash_base) {
3721 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3722 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
3726 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
3727 file_name
=>"$basedir$t->{'name'}")},
3731 } elsif ($t->{'type'} eq "tree") {
3732 print "<td class=\"list\">";
3733 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3734 file_name
=>"$basedir$t->{'name'}",
3736 esc_path
($t->{'name'}));
3738 print "<td class=\"link\">";
3739 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3740 file_name
=>"$basedir$t->{'name'}",
3743 if (defined $hash_base) {
3745 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3746 file_name
=>"$basedir$t->{'name'}")},
3751 # unknown object: we can only present history for it
3752 # (this includes 'commit' object, i.e. submodule support)
3753 print "<td class=\"list\">" .
3754 esc_path
($t->{'name'}) .
3756 print "<td class=\"link\">";
3757 if (defined $hash_base) {
3758 print $cgi->a({-href
=> href
(action
=>"history",
3759 hash_base
=>$hash_base,
3760 file_name
=>"$basedir$t->{'name'}")},
3767 ## ......................................................................
3768 ## functions printing large fragments of HTML
3770 # get pre-image filenames for merge (combined) diff
3771 sub fill_from_file_info
{
3772 my ($diff, @parents) = @_;
3774 $diff->{'from_file'} = [ ];
3775 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
3776 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3777 if ($diff->{'status'}[$i] eq 'R' ||
3778 $diff->{'status'}[$i] eq 'C') {
3779 $diff->{'from_file'}[$i] =
3780 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
3787 # is current raw difftree line of file deletion
3789 my $diffinfo = shift;
3791 return $diffinfo->{'to_id'} eq ('0' x
40);
3794 # does patch correspond to [previous] difftree raw line
3795 # $diffinfo - hashref of parsed raw diff format
3796 # $patchinfo - hashref of parsed patch diff format
3797 # (the same keys as in $diffinfo)
3798 sub is_patch_split
{
3799 my ($diffinfo, $patchinfo) = @_;
3801 return defined $diffinfo && defined $patchinfo
3802 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3806 sub git_difftree_body
{
3807 my ($difftree, $hash, @parents) = @_;
3808 my ($parent) = $parents[0];
3809 my $have_blame = gitweb_check_feature
('blame');
3810 print "<div class=\"list_head\">\n";
3811 if ($#{$difftree} > 10) {
3812 print(($#{$difftree} + 1) . " files changed:\n");
3816 print "<table class=\"" .
3817 (@parents > 1 ? "combined " : "") .
3820 # header only for combined diff in 'commitdiff' view
3821 my $has_header = @$difftree && @parents > 1 && $action eq 'commitdiff';
3824 print "<thead><tr>\n" .
3825 "<th></th><th></th>\n"; # filename, patchN link
3826 for (my $i = 0; $i < @parents; $i++) {
3827 my $par = $parents[$i];
3829 $cgi->a({-href
=> href
(action
=>"commitdiff",
3830 hash
=>$hash, hash_parent
=>$par),
3831 -title
=> 'commitdiff to parent number ' .
3832 ($i+1) . ': ' . substr($par,0,7)},
3836 print "</tr></thead>\n<tbody>\n";
3841 foreach my $line (@{$difftree}) {
3842 my $diff = parsed_difftree_line
($line);
3845 print "<tr class=\"dark\">\n";
3847 print "<tr class=\"light\">\n";
3851 if (exists $diff->{'nparents'}) { # combined diff
3853 fill_from_file_info
($diff, @parents)
3854 unless exists $diff->{'from_file'};
3856 if (!is_deleted
($diff)) {
3857 # file exists in the result (child) commit
3859 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3860 file_name
=>$diff->{'to_file'},
3862 -class => "list"}, esc_path
($diff->{'to_file'})) .
3866 esc_path
($diff->{'to_file'}) .
3870 if ($action eq 'commitdiff') {
3873 print "<td class=\"link\">" .
3874 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3879 my $has_history = 0;
3880 my $not_deleted = 0;
3881 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3882 my $hash_parent = $parents[$i];
3883 my $from_hash = $diff->{'from_id'}[$i];
3884 my $from_path = $diff->{'from_file'}[$i];
3885 my $status = $diff->{'status'}[$i];
3887 $has_history ||= ($status ne 'A');
3888 $not_deleted ||= ($status ne 'D');
3890 if ($status eq 'A') {
3891 print "<td class=\"link\" align=\"right\"> | </td>\n";
3892 } elsif ($status eq 'D') {
3893 print "<td class=\"link\">" .
3894 $cgi->a({-href
=> href
(action
=>"blob",
3897 file_name
=>$from_path)},
3901 if ($diff->{'to_id'} eq $from_hash) {
3902 print "<td class=\"link nochange\">";
3904 print "<td class=\"link\">";
3906 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3907 hash
=>$diff->{'to_id'},
3908 hash_parent
=>$from_hash,
3910 hash_parent_base
=>$hash_parent,
3911 file_name
=>$diff->{'to_file'},
3912 file_parent
=>$from_path)},
3918 print "<td class=\"link\">";
3920 print $cgi->a({-href
=> href
(action
=>"blob",
3921 hash
=>$diff->{'to_id'},
3922 file_name
=>$diff->{'to_file'},
3925 print " | " if ($has_history);
3928 print $cgi->a({-href
=> href
(action
=>"history",
3929 file_name
=>$diff->{'to_file'},
3936 next; # instead of 'else' clause, to avoid extra indent
3938 # else ordinary diff
3940 my ($to_mode_oct, $to_mode_str, $to_file_type);
3941 my ($from_mode_oct, $from_mode_str, $from_file_type);
3942 if ($diff->{'to_mode'} ne ('0' x
6)) {
3943 $to_mode_oct = oct $diff->{'to_mode'};
3944 if (S_ISREG
($to_mode_oct)) { # only for regular file
3945 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3947 $to_file_type = file_type
($diff->{'to_mode'});
3949 if ($diff->{'from_mode'} ne ('0' x
6)) {
3950 $from_mode_oct = oct $diff->{'from_mode'};
3951 if (S_ISREG
($to_mode_oct)) { # only for regular file
3952 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3954 $from_file_type = file_type
($diff->{'from_mode'});
3957 if ($diff->{'status'} eq "A") { # created
3958 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3959 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3960 $mode_chng .= "]</span>";
3962 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3963 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3964 -class => "list"}, esc_path
($diff->{'file'}));
3966 print "<td>$mode_chng</td>\n";
3967 print "<td class=\"link\">";
3968 if ($action eq 'commitdiff') {
3971 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3974 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3975 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3979 } elsif ($diff->{'status'} eq "D") { # deleted
3980 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3982 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3983 hash_base
=>$parent, file_name
=>$diff->{'file'}),
3984 -class => "list"}, esc_path
($diff->{'file'}));
3986 print "<td>$mode_chng</td>\n";
3987 print "<td class=\"link\">";
3988 if ($action eq 'commitdiff') {
3991 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3994 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3995 hash_base
=>$parent, file_name
=>$diff->{'file'})},
3998 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3999 file_name
=>$diff->{'file'})},
4002 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
4003 file_name
=>$diff->{'file'})},
4007 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
4008 my $mode_chnge = "";
4009 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
4010 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
4011 if ($from_file_type ne $to_file_type) {
4012 $mode_chnge .= " from $from_file_type to $to_file_type";
4014 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
4015 if ($from_mode_str && $to_mode_str) {
4016 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
4017 } elsif ($to_mode_str) {
4018 $mode_chnge .= " mode: $to_mode_str";
4021 $mode_chnge .= "]</span>\n";
4024 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4025 hash_base
=>$hash, file_name
=>$diff->{'file'}),
4026 -class => "list"}, esc_path
($diff->{'file'}));
4028 print "<td>$mode_chnge</td>\n";
4029 print "<td class=\"link\">";
4030 if ($action eq 'commitdiff') {
4033 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
4035 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
4036 # "commit" view and modified file (not onlu mode changed)
4037 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4038 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
4039 hash_base
=>$hash, hash_parent_base
=>$parent,
4040 file_name
=>$diff->{'file'})},
4044 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4045 hash_base
=>$hash, file_name
=>$diff->{'file'})},
4048 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
4049 file_name
=>$diff->{'file'})},
4052 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
4053 file_name
=>$diff->{'file'})},
4057 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
4058 my %status_name = ('R' => 'moved', 'C' => 'copied');
4059 my $nstatus = $status_name{$diff->{'status'}};
4061 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
4062 # mode also for directories, so we cannot use $to_mode_str
4063 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
4066 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
4067 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
4068 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
4069 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
4070 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
4071 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
4072 -class => "list"}, esc_path
($diff->{'from_file'})) .
4073 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
4074 "<td class=\"link\">";
4075 if ($action eq 'commitdiff') {
4078 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
4080 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
4081 # "commit" view and modified file (not only pure rename or copy)
4082 print $cgi->a({-href
=> href
(action
=>"blobdiff",
4083 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
4084 hash_base
=>$hash, hash_parent_base
=>$parent,
4085 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
4089 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
4090 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
4093 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
4094 file_name
=>$diff->{'to_file'})},
4097 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
4098 file_name
=>$diff->{'to_file'})},
4102 } # we should not encounter Unmerged (U) or Unknown (X) status
4105 print "</tbody>" if $has_header;
4109 sub git_patchset_body
{
4110 my ($fd, $difftree, $hash, @hash_parents) = @_;
4111 my ($hash_parent) = $hash_parents[0];
4113 my $is_combined = (@hash_parents > 1);
4115 my $patch_number = 0;
4121 print "<div class=\"patchset\">\n";
4123 # skip to first patch
4124 while ($patch_line = <$fd>) {
4127 last if ($patch_line =~ m/^diff /);
4131 while ($patch_line) {
4133 # parse "git diff" header line
4134 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
4135 # $1 is from_name, which we do not use
4136 $to_name = unquote
($2);
4137 $to_name =~ s!^b/!!;
4138 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
4139 # $1 is 'cc' or 'combined', which we do not use
4140 $to_name = unquote
($2);
4145 # check if current patch belong to current raw line
4146 # and parse raw git-diff line if needed
4147 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
4148 # this is continuation of a split patch
4149 print "<div class=\"patch cont\">\n";
4151 # advance raw git-diff output if needed
4152 $patch_idx++ if defined $diffinfo;
4154 # read and prepare patch information
4155 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4157 # compact combined diff output can have some patches skipped
4158 # find which patch (using pathname of result) we are at now;
4160 while ($to_name ne $diffinfo->{'to_file'}) {
4161 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4162 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4163 "</div>\n"; # class="patch"
4168 last if $patch_idx > $#$difftree;
4169 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4173 # modifies %from, %to hashes
4174 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
4176 # this is first patch for raw difftree line with $patch_idx index
4177 # we index @$difftree array from 0, but number patches from 1
4178 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
4182 #assert($patch_line =~ m/^diff /) if DEBUG;
4183 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
4185 # print "git diff" header
4186 print format_git_diff_header_line
($patch_line, $diffinfo,
4189 # print extended diff header
4190 print "<div class=\"diff extended_header\">\n";
4192 while ($patch_line = <$fd>) {
4195 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
4197 print format_extended_diff_header_line
($patch_line, $diffinfo,
4200 print "</div>\n"; # class="diff extended_header"
4202 # from-file/to-file diff header
4203 if (! $patch_line) {
4204 print "</div>\n"; # class="patch"
4207 next PATCH
if ($patch_line =~ m/^diff /);
4208 #assert($patch_line =~ m/^---/) if DEBUG;
4210 my $last_patch_line = $patch_line;
4211 $patch_line = <$fd>;
4213 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
4215 print format_diff_from_to_header
($last_patch_line, $patch_line,
4216 $diffinfo, \
%from, \
%to,
4221 while ($patch_line = <$fd>) {
4224 next PATCH
if ($patch_line =~ m/^diff /);
4226 print format_diff_line
($patch_line, \
%from, \
%to);
4230 print "</div>\n"; # class="patch"
4233 # for compact combined (--cc) format, with chunk and patch simpliciaction
4234 # patchset might be empty, but there might be unprocessed raw lines
4235 for (++$patch_idx if $patch_number > 0;
4236 $patch_idx < @$difftree;
4238 # read and prepare patch information
4239 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
4241 # generate anchor for "patch" links in difftree / whatchanged part
4242 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
4243 format_diff_cc_simplified
($diffinfo, @hash_parents) .
4244 "</div>\n"; # class="patch"
4249 if ($patch_number == 0) {
4250 if (@hash_parents > 1) {
4251 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
4253 print "<div class=\"diff nodifferences\">No differences found</div>\n";
4257 print "</div>\n"; # class="patchset"
4260 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4262 # fills project list info (age, description, owner, forks) for each
4263 # project in the list, removing invalid projects from returned list
4264 # NOTE: modifies $projlist, but does not remove entries from it
4265 sub fill_project_list_info
{
4266 my ($projlist, $check_forks) = @_;
4269 my $show_ctags = gitweb_check_feature
('ctags');
4271 foreach my $pr (@$projlist) {
4272 my (@activity) = git_get_last_activity
($pr->{'path'});
4273 unless (@activity) {
4276 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
4277 if (!defined $pr->{'descr'}) {
4278 my $descr = git_get_project_description
($pr->{'path'}) || "";
4279 $descr = to_utf8
($descr);
4280 $pr->{'descr_long'} = $descr;
4281 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
4283 if (!defined $pr->{'owner'}) {
4284 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
4287 my $pname = $pr->{'path'};
4288 if (($pname =~ s/\.git$//) &&
4289 ($pname !~ /\/$/) &&
4290 (-d
"$projectroot/$pname")) {
4291 $pr->{'forks'} = "-d $projectroot/$pname";
4296 $show_ctags and $pr->{'ctags'} = git_get_project_ctags
($pr->{'path'});
4297 push @projects, $pr;
4303 # print 'sort by' <th> element, generating 'sort by $name' replay link
4304 # if that order is not selected
4306 my ($name, $order, $header) = @_;
4307 $header ||= ucfirst($name);
4309 if ($order eq $name) {
4310 print "<th>$header</th>\n";
4313 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
4314 -class => "header"}, $header) .
4319 sub git_project_list_body
{
4320 # actually uses global variable $project
4321 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
4323 my $check_forks = gitweb_check_feature
('forks');
4324 my @projects = fill_project_list_info
($projlist, $check_forks);
4326 $order ||= $default_projects_order;
4327 $from = 0 unless defined $from;
4328 $to = $#projects if (!defined $to || $#projects < $to);
4331 project
=> { key
=> 'path', type
=> 'str' },
4332 descr
=> { key
=> 'descr_long', type
=> 'str' },
4333 owner
=> { key
=> 'owner', type
=> 'str' },
4334 age
=> { key
=> 'age', type
=> 'num' }
4336 my $oi = $order_info{$order};
4337 if ($oi->{'type'} eq 'str') {
4338 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
4340 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
4343 my $show_ctags = gitweb_check_feature
('ctags');
4346 foreach my $p (@projects) {
4347 foreach my $ct (keys %{$p->{'ctags'}}) {
4348 $ctags{$ct} += $p->{'ctags'}->{$ct};
4351 my $cloud = git_populate_project_tagcloud
(\
%ctags);
4352 print git_show_project_tagcloud
($cloud, 64);
4355 print "<table class=\"project_list\">\n";
4356 unless ($no_header) {
4359 print "<th></th>\n";
4361 print_sort_th
('project', $order, 'Project');
4362 print_sort_th
('descr', $order, 'Description');
4363 print_sort_th
('owner', $order, 'Owner');
4364 print_sort_th
('age', $order, 'Last Change');
4365 print "<th></th>\n" . # for links
4369 my $tagfilter = $cgi->param('by_tag');
4370 for (my $i = $from; $i <= $to; $i++) {
4371 my $pr = $projects[$i];
4373 next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}};
4374 next if $searchtext and not $pr->{'path'} =~ /$searchtext/
4375 and not $pr->{'descr_long'} =~ /$searchtext/;
4376 # Weed out forks or non-matching entries of search
4378 my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s
#\.git$#/#;
4379 $forkbase="^$forkbase" if $forkbase;
4380 next if not $searchtext and not $tagfilter and $show_ctags
4381 and $pr->{'path'} =~ m
#$forkbase.*/.*#; # regexp-safe
4385 print "<tr class=\"dark\">\n";
4387 print "<tr class=\"light\">\n";
4392 if ($pr->{'forks'}) {
4393 print "<!-- $pr->{'forks'} -->\n";
4394 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
4398 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4399 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
4400 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
4401 -class => "list", -title
=> $pr->{'descr_long'}},
4402 esc_html
($pr->{'descr'})) . "</td>\n" .
4403 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
4404 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
4405 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
4406 "<td class=\"link\">" .
4407 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
4408 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
4409 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
4410 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
4411 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
4415 if (defined $extra) {
4418 print "<td></td>\n";
4420 print "<td colspan=\"5\">$extra</td>\n" .
4427 # uses global variable $project
4428 my ($commitlist, $from, $to, $refs, $extra) = @_;
4430 $from = 0 unless defined $from;
4431 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4433 for (my $i = 0; $i <= $to; $i++) {
4434 my %co = %{$commitlist->[$i]};
4436 my $commit = $co{'id'};
4437 my $ref = format_ref_marker
($refs, $commit);
4438 my %ad = parse_date
($co{'author_epoch'});
4439 git_print_header_div
('commit',
4440 "<span class=\"age\">$co{'age_string'}</span>" .
4441 esc_html
($co{'title'}) . $ref,
4443 print "<div class=\"title_text\">\n" .
4444 "<div class=\"log_link\">\n" .
4445 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4447 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4449 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4452 git_print_authorship
(\
%co, -tag
=> 'span');
4453 print "<br/>\n</div>\n";
4455 print "<div class=\"log_body\">\n";
4456 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4460 print "<div class=\"page_nav\">\n";
4466 sub git_shortlog_body
{
4467 # uses global variable $project
4468 my ($commitlist, $from, $to, $refs, $extra) = @_;
4470 $from = 0 unless defined $from;
4471 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4473 print "<table class=\"shortlog\">\n";
4475 for (my $i = $from; $i <= $to; $i++) {
4476 my %co = %{$commitlist->[$i]};
4477 my $commit = $co{'id'};
4478 my $ref = format_ref_marker
($refs, $commit);
4480 print "<tr class=\"dark\">\n";
4482 print "<tr class=\"light\">\n";
4485 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
4486 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4487 format_author_html
('td', \
%co, 10) . "<td>";
4488 print format_subject_html
($co{'title'}, $co{'title_short'},
4489 href
(action
=>"commit", hash
=>$commit), $ref);
4491 "<td class=\"link\">" .
4492 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
4493 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
4494 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
4495 my $snapshot_links = format_snapshot_links
($commit);
4496 if (defined $snapshot_links) {
4497 print " | " . $snapshot_links;
4502 if (defined $extra) {
4504 "<td colspan=\"4\">$extra</td>\n" .
4510 sub git_history_body
{
4511 # Warning: assumes constant type (blob or tree) during history
4512 my ($commitlist, $from, $to, $refs, $extra,
4513 $file_name, $file_hash, $ftype) = @_;
4515 $from = 0 unless defined $from;
4516 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
4518 print "<table class=\"history\">\n";
4520 for (my $i = $from; $i <= $to; $i++) {
4521 my %co = %{$commitlist->[$i]};
4525 my $commit = $co{'id'};
4527 my $ref = format_ref_marker
($refs, $commit);
4530 print "<tr class=\"dark\">\n";
4532 print "<tr class=\"light\">\n";
4535 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4536 # shortlog: format_author_html('td', \%co, 10)
4537 format_author_html
('td', \
%co, 15, 3) . "<td>";
4538 # originally git_history used chop_str($co{'title'}, 50)
4539 print format_subject_html
($co{'title'}, $co{'title_short'},
4540 href
(action
=>"commit", hash
=>$commit), $ref);
4542 "<td class=\"link\">" .
4543 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
4544 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
4546 if ($ftype eq 'blob') {
4547 my $blob_current = $file_hash;
4548 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
4549 if (defined $blob_current && defined $blob_parent &&
4550 $blob_current ne $blob_parent) {
4552 $cgi->a({-href
=> href
(action
=>"blobdiff",
4553 hash
=>$blob_current, hash_parent
=>$blob_parent,
4554 hash_base
=>$hash_base, hash_parent_base
=>$commit,
4555 file_name
=>$file_name)},
4562 if (defined $extra) {
4564 "<td colspan=\"4\">$extra</td>\n" .
4571 # uses global variable $project
4572 my ($taglist, $from, $to, $extra) = @_;
4573 $from = 0 unless defined $from;
4574 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
4576 print "<table class=\"tags\">\n";
4578 for (my $i = $from; $i <= $to; $i++) {
4579 my $entry = $taglist->[$i];
4581 my $comment = $tag{'subject'};
4583 if (defined $comment) {
4584 $comment_short = chop_str
($comment, 30, 5);
4587 print "<tr class=\"dark\">\n";
4589 print "<tr class=\"light\">\n";
4592 if (defined $tag{'age'}) {
4593 print "<td><i>$tag{'age'}</i></td>\n";
4595 print "<td></td>\n";
4598 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
4599 -class => "list name"}, esc_html
($tag{'name'})) .
4602 if (defined $comment) {
4603 print format_subject_html
($comment, $comment_short,
4604 href
(action
=>"tag", hash
=>$tag{'id'}));
4607 "<td class=\"selflink\">";
4608 if ($tag{'type'} eq "tag") {
4609 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
4614 "<td class=\"link\">" . " | " .
4615 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
4616 if ($tag{'reftype'} eq "commit") {
4617 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
4618 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
4619 } elsif ($tag{'reftype'} eq "blob") {
4620 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
4625 if (defined $extra) {
4627 "<td colspan=\"5\">$extra</td>\n" .
4633 sub git_heads_body
{
4634 # uses global variable $project
4635 my ($headlist, $head, $from, $to, $extra) = @_;
4636 $from = 0 unless defined $from;
4637 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
4639 print "<table class=\"heads\">\n";
4641 for (my $i = $from; $i <= $to; $i++) {
4642 my $entry = $headlist->[$i];
4644 my $curr = $ref{'id'} eq $head;
4646 print "<tr class=\"dark\">\n";
4648 print "<tr class=\"light\">\n";
4651 print "<td><i>$ref{'age'}</i></td>\n" .
4652 ($curr ? "<td class=\"current_head\">" : "<td>") .
4653 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
4654 -class => "list name"},esc_html
($ref{'name'})) .
4656 "<td class=\"link\">" .
4657 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
4658 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
4659 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
4663 if (defined $extra) {
4665 "<td colspan=\"3\">$extra</td>\n" .
4671 sub git_search_grep_body
{
4672 my ($commitlist, $from, $to, $extra) = @_;
4673 $from = 0 unless defined $from;
4674 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
4676 print "<table class=\"commit_search\">\n";
4678 for (my $i = $from; $i <= $to; $i++) {
4679 my %co = %{$commitlist->[$i]};
4683 my $commit = $co{'id'};
4685 print "<tr class=\"dark\">\n";
4687 print "<tr class=\"light\">\n";
4690 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4691 format_author_html
('td', \
%co, 15, 5) .
4693 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4694 -class => "list subject"},
4695 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
4696 my $comment = $co{'comment'};
4697 foreach my $line (@$comment) {
4698 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
4699 my ($lead, $match, $trail) = ($1, $2, $3);
4700 $match = chop_str
($match, 70, 5, 'center');
4701 my $contextlen = int((80 - length($match))/2);
4702 $contextlen = 30 if ($contextlen > 30);
4703 $lead = chop_str
($lead, $contextlen, 10, 'left');
4704 $trail = chop_str
($trail, $contextlen, 10, 'right');
4706 $lead = esc_html
($lead);
4707 $match = esc_html
($match);
4708 $trail = esc_html
($trail);
4710 print "$lead<span class=\"match\">$match</span>$trail<br />";
4714 "<td class=\"link\">" .
4715 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4717 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
4719 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4723 if (defined $extra) {
4725 "<td colspan=\"3\">$extra</td>\n" .
4731 ## ======================================================================
4732 ## ======================================================================
4735 sub git_project_list
{
4736 my $order = $input_params{'order'};
4737 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4738 die_error
(400, "Unknown order parameter");
4741 my @list = git_get_projects_list
();
4743 die_error
(404, "No projects found");
4747 if (-f
$home_text) {
4748 print "<div class=\"index_include\">\n";
4749 insert_file
($home_text);
4752 print $cgi->startform(-method => "get") .
4753 "<p class=\"projsearch\">Search:\n" .
4754 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
4756 $cgi->end_form() . "\n";
4757 git_project_list_body
(\
@list, $order);
4762 my $order = $input_params{'order'};
4763 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4764 die_error
(400, "Unknown order parameter");
4767 my @list = git_get_projects_list
($project);
4769 die_error
(404, "No forks found");
4773 git_print_page_nav
('','');
4774 git_print_header_div
('summary', "$project forks");
4775 git_project_list_body
(\
@list, $order);
4779 sub git_project_index
{
4780 my @projects = git_get_projects_list
($project);
4783 -type
=> 'text/plain',
4784 -charset
=> 'utf-8',
4785 -content_disposition
=> 'inline; filename="index.aux"');
4787 foreach my $pr (@projects) {
4788 if (!exists $pr->{'owner'}) {
4789 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
4792 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
4793 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
4794 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4795 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4799 print "$path $owner\n";
4804 my $descr = git_get_project_description
($project) || "none";
4805 my %co = parse_commit
("HEAD");
4806 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
4807 my $head = $co{'id'};
4809 my $owner = git_get_project_owner
($project);
4811 my $refs = git_get_references
();
4812 # These get_*_list functions return one more to allow us to see if
4813 # there are more ...
4814 my @taglist = git_get_tags_list
(16);
4815 my @headlist = git_get_heads_list
(16);
4817 my $check_forks = gitweb_check_feature
('forks');
4820 @forklist = git_get_projects_list
($project);
4824 git_print_page_nav
('summary','', $head);
4826 print "<div class=\"title\"> </div>\n";
4827 print "<table class=\"projects_list\">\n" .
4828 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
4829 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
4830 if (defined $cd{'rfc2822'}) {
4831 print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4834 # use per project git URL list in $projectroot/$project/cloneurl
4835 # or make project git URL from git base URL and project name
4836 my $url_tag = "URL";
4837 my @url_list = git_get_project_url_list
($project);
4838 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4839 foreach my $git_url (@url_list) {
4840 next unless $git_url;
4841 print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";
4846 my $show_ctags = gitweb_check_feature
('ctags');
4848 my $ctags = git_get_project_ctags
($project);
4849 my $cloud = git_populate_project_tagcloud
($ctags);
4850 print "<tr id=\"metadata_ctags\"><td>Content tags:<br />";
4851 print "</td>\n<td>" unless %$ctags;
4852 print "<form action=\"$show_ctags\" method=\"post\"><input type=\"hidden\" name=\"p\" value=\"$project\" />Add: <input type=\"text\" name=\"t\" size=\"8\" /></form>";
4853 print "</td>\n<td>" if %$ctags;
4854 print git_show_project_tagcloud
($cloud, 48);
4860 # If XSS prevention is on, we don't include README.html.
4861 # TODO: Allow a readme in some safe format.
4862 if (!$prevent_xss && -s
"$projectroot/$project/README.html") {
4863 print "<div class=\"title\">readme</div>\n" .
4864 "<div class=\"readme\">\n";
4865 insert_file
("$projectroot/$project/README.html");
4866 print "\n</div>\n"; # class="readme"
4869 # we need to request one more than 16 (0..15) to check if
4871 my @commitlist = $head ? parse_commits
($head, 17) : ();
4873 git_print_header_div
('shortlog');
4874 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
4875 $#commitlist <= 15 ? undef :
4876 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
4880 git_print_header_div
('tags');
4881 git_tags_body
(\
@taglist, 0, 15,
4882 $#taglist <= 15 ? undef :
4883 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
4887 git_print_header_div
('heads');
4888 git_heads_body
(\
@headlist, $head, 0, 15,
4889 $#headlist <= 15 ? undef :
4890 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
4894 git_print_header_div
('forks');
4895 git_project_list_body
(\
@forklist, 'age', 0, 15,
4896 $#forklist <= 15 ? undef :
4897 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
4905 my $head = git_get_head_hash
($project);
4907 git_print_page_nav
('','', $head,undef,$head);
4908 my %tag = parse_tag
($hash);
4911 die_error
(404, "Unknown tag object");
4914 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
4915 print "<div class=\"title_text\">\n" .
4916 "<table class=\"object_header\">\n" .
4918 "<td>object</td>\n" .
4919 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4920 $tag{'object'}) . "</td>\n" .
4921 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4922 $tag{'type'}) . "</td>\n" .
4924 if (defined($tag{'author'})) {
4925 git_print_authorship_rows
(\
%tag, 'author');
4927 print "</table>\n\n" .
4929 print "<div class=\"page_body\">";
4930 my $comment = $tag{'comment'};
4931 foreach my $line (@$comment) {
4933 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4939 sub git_blame_common
{
4940 my $format = shift || 'porcelain';
4941 if ($format eq 'porcelain' && $cgi->param('js')) {
4942 $format = 'incremental';
4943 $action = 'blame_incremental'; # for page title etc
4947 gitweb_check_feature
('blame')
4948 or die_error
(403, "Blame view not allowed");
4951 die_error
(400, "No file name given") unless $file_name;
4952 $hash_base ||= git_get_head_hash
($project);
4953 die_error
(404, "Couldn't find base commit") unless $hash_base;
4954 my %co = parse_commit
($hash_base)
4955 or die_error
(404, "Commit not found");
4957 if (!defined $hash) {
4958 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4959 or die_error
(404, "Error looking up file");
4961 $ftype = git_get_type
($hash);
4962 if ($ftype !~ "blob") {
4963 die_error
(400, "Object is not a blob");
4968 if ($format eq 'incremental') {
4969 # get file contents (as base)
4970 open $fd, "-|", git_cmd
(), 'cat-file', 'blob', $hash
4971 or die_error
(500, "Open git-cat-file failed");
4972 } elsif ($format eq 'data') {
4973 # run git-blame --incremental
4974 open $fd, "-|", git_cmd
(), "blame", "--incremental",
4975 $hash_base, "--", $file_name
4976 or die_error
(500, "Open git-blame --incremental failed");
4978 # run git-blame --porcelain
4979 open $fd, "-|", git_cmd
(), "blame", '-p',
4980 $hash_base, '--', $file_name
4981 or die_error
(500, "Open git-blame --porcelain failed");
4984 # incremental blame data returns early
4985 if ($format eq 'data') {
4987 -type
=>"text/plain", -charset
=> "utf-8",
4988 -status
=> "200 OK");
4989 local $| = 1; # output autoflush
4992 or print "ERROR $!\n";
4995 if (defined $t0 && gitweb_check_feature
('timed')) {
4997 Time
::HiRes
::tv_interval
($t0, [Time
::HiRes
::gettimeofday
()]).
4998 ' '.$number_of_git_cmds;
5008 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
5011 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5014 $cgi->a({-href
=> href
(action
=>$action, file_name
=>$file_name)},
5016 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5017 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5018 git_print_page_path
($file_name, $ftype, $hash_base);
5021 if ($format eq 'incremental') {
5022 print "<noscript>\n<div class=\"error\"><center><b>\n".
5023 "This page requires JavaScript to run.\n Use ".
5024 $cgi->a({-href
=> href
(action
=>'blame',javascript
=>0,-replay
=>1)},
5027 "</b></center></div>\n</noscript>\n";
5029 print qq
!<div id
="progress_bar" style
="width: 100%; background-color: yellow"></div
>\n!;
5032 print qq
!<div
class="page_body">\n!;
5033 print qq
!<div id
="progress_info">... / ...</div
>\n!
5034 if ($format eq 'incremental');
5035 print qq
!<table id
="blame_table" class="blame" width
="100%">\n!.
5036 #qq!<col width="5.5em" /><col width="2.5em" /><col width="*" />\n!.
5038 qq
!<tr
><th
>Commit
</th><th>Line</th
><th
>Data
</th></tr
>\n!.
5042 my @rev_color = qw(light dark);
5043 my $num_colors = scalar(@rev_color);
5044 my $current_color = 0;
5046 if ($format eq 'incremental') {
5047 my $color_class = $rev_color[$current_color];
5052 while (my $line = <$fd>) {
5056 print qq
!<tr id
="l$linenr" class="$color_class">!.
5057 qq
!<td
class="sha1"><a href
=""> </a></td
>!.
5058 qq
!<td
class="linenr">!.
5059 qq
!<a
class="linenr" href
="">$linenr</a></td
>!;
5060 print qq
!<td
class="pre">! . esc_html
($line) . "</td>\n";
5064 } else { # porcelain, i.e. ordinary blame
5065 my %metainfo = (); # saves information about commits
5069 while (my $line = <$fd>) {
5071 # the header: <SHA-1> <src lineno> <dst lineno> [<lines in group>]
5072 # no <lines in group> for subsequent lines in group of lines
5073 my ($full_rev, $orig_lineno, $lineno, $group_size) =
5074 ($line =~ /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/);
5075 if (!exists $metainfo{$full_rev}) {
5076 $metainfo{$full_rev} = { 'nprevious' => 0 };
5078 my $meta = $metainfo{$full_rev};
5080 while ($data = <$fd>) {
5082 last if ($data =~ s/^\t//); # contents of line
5083 if ($data =~ /^(\S+)(?: (.*))?$/) {
5084 $meta->{$1} = $2 unless exists $meta->{$1};
5086 if ($data =~ /^previous /) {
5087 $meta->{'nprevious'}++;
5090 my $short_rev = substr($full_rev, 0, 8);
5091 my $author = $meta->{'author'};
5093 parse_date
($meta->{'author-time'}, $meta->{'author-tz'});
5094 my $date = $date{'iso-tz'};
5096 $current_color = ($current_color + 1) % $num_colors;
5098 my $tr_class = $rev_color[$current_color];
5099 $tr_class .= ' boundary' if (exists $meta->{'boundary'});
5100 $tr_class .= ' no-previous' if ($meta->{'nprevious'} == 0);
5101 $tr_class .= ' multiple-previous' if ($meta->{'nprevious'} > 1);
5102 print "<tr id=\"l$lineno\" class=\"$tr_class\">\n";
5104 print "<td class=\"sha1\"";
5105 print " title=\"". esc_html
($author) . ", $date\"";
5106 print " rowspan=\"$group_size\"" if ($group_size > 1);
5108 print $cgi->a({-href
=> href
(action
=>"commit",
5110 file_name
=>$file_name)},
5111 esc_html
($short_rev));
5112 if ($group_size >= 2) {
5113 my @author_initials = ($author =~ /\b([[:upper:]])\B/g);
5114 if (@author_initials) {
5116 esc_html
(join('', @author_initials));
5122 # 'previous' <sha1 of parent commit> <filename at commit>
5123 if (exists $meta->{'previous'} &&
5124 $meta->{'previous'} =~ /^([a-fA-F0-9]{40}) (.*)$/) {
5125 $meta->{'parent'} = $1;
5126 $meta->{'file_parent'} = unquote
($2);
5129 exists($meta->{'parent'}) ?
5130 $meta->{'parent'} : $full_rev;
5131 my $linenr_filename =
5132 exists($meta->{'file_parent'}) ?
5133 $meta->{'file_parent'} : unquote
($meta->{'filename'});
5134 my $blamed = href
(action
=> 'blame',
5135 file_name
=> $linenr_filename,
5136 hash_base
=> $linenr_commit);
5137 print "<td class=\"linenr\">";
5138 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
5139 -class => "linenr" },
5142 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
5150 "</table>\n"; # class="blame"
5151 print "</div>\n"; # class="blame_body"
5153 or print "Reading blob failed\n";
5162 sub git_blame_incremental
{
5163 git_blame_common
('incremental');
5166 sub git_blame_data
{
5167 git_blame_common
('data');
5171 my $head = git_get_head_hash
($project);
5173 git_print_page_nav
('','', $head,undef,$head);
5174 git_print_header_div
('summary', $project);
5176 my @tagslist = git_get_tags_list
();
5178 git_tags_body
(\
@tagslist);
5184 my $head = git_get_head_hash
($project);
5186 git_print_page_nav
('','', $head,undef,$head);
5187 git_print_header_div
('summary', $project);
5189 my @headslist = git_get_heads_list
();
5191 git_heads_body
(\
@headslist, $head);
5196 sub git_blob_plain
{
5200 if (!defined $hash) {
5201 if (defined $file_name) {
5202 my $base = $hash_base || git_get_head_hash
($project);
5203 $hash = git_get_hash_by_path
($base, $file_name, "blob")
5204 or die_error
(404, "Cannot find file");
5206 die_error
(400, "No file name defined");
5208 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5209 # blobs defined by non-textual hash id's can be cached
5213 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
5214 or die_error
(500, "Open git-cat-file blob '$hash' failed");
5216 # content-type (can include charset)
5217 $type = blob_contenttype
($fd, $file_name, $type);
5219 # "save as" filename, even when no $file_name is given
5220 my $save_as = "$hash";
5221 if (defined $file_name) {
5222 $save_as = $file_name;
5223 } elsif ($type =~ m/^text\//) {
5227 # With XSS prevention on, blobs of all types except a few known safe
5228 # ones are served with "Content-Disposition: attachment" to make sure
5229 # they don't run in our security domain. For certain image types,
5230 # blob view writes an <img> tag referring to blob_plain view, and we
5231 # want to be sure not to break that by serving the image as an
5232 # attachment (though Firefox 3 doesn't seem to care).
5233 my $sandbox = $prevent_xss &&
5234 $type !~ m!^(?:text/plain|image/(?:gif|png|jpeg))$!;
5238 -expires
=> $expires,
5239 -content_disposition
=>
5240 ($sandbox ? 'attachment' : 'inline')
5241 . '; filename="' . $save_as . '"');
5243 binmode STDOUT
, ':raw';
5245 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5252 if (!defined $hash) {
5253 if (defined $file_name) {
5254 my $base = $hash_base || git_get_head_hash
($project);
5255 $hash = git_get_hash_by_path
($base, $file_name, "blob")
5256 or die_error
(404, "Cannot find file");
5258 die_error
(400, "No file name defined");
5260 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5261 # blobs defined by non-textual hash id's can be cached
5265 my $have_blame = gitweb_check_feature
('blame');
5266 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
5267 or die_error
(500, "Couldn't cat $file_name, $hash");
5268 my $mimetype = blob_mimetype
($fd, $file_name);
5269 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
5271 return git_blob_plain
($mimetype);
5273 # we can have blame only for text/* mimetype
5274 $have_blame &&= ($mimetype =~ m!^text/!);
5276 git_header_html
(undef, $expires);
5277 my $formats_nav = '';
5278 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5279 if (defined $file_name) {
5282 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
5287 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5290 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5293 $cgi->a({-href
=> href
(action
=>"blob",
5294 hash_base
=>"HEAD", file_name
=>$file_name)},
5298 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
5301 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5302 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5304 print "<div class=\"page_nav\">\n" .
5305 "<br/><br/></div>\n" .
5306 "<div class=\"title\">$hash</div>\n";
5308 git_print_page_path
($file_name, "blob", $hash_base);
5309 print "<div class=\"page_body\">\n";
5310 if ($mimetype =~ m!^image/!) {
5311 print qq
!<img type
="$mimetype"!;
5313 print qq
! alt
="$file_name" title
="$file_name"!;
5316 href(action=>"blob_plain
", hash=>$hash,
5317 hash_base=>$hash_base, file_name=>$file_name) .
5321 while (my $line = <$fd>) {
5324 $line = untabify
($line);
5325 printf "<div class=\"pre\"><a id=\"l%i\" href=\"" . href
(-replay
=> 1)
5326 . "#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
5327 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
5331 or print "Reading blob failed.\n";
5337 if (!defined $hash_base) {
5338 $hash_base = "HEAD";
5340 if (!defined $hash) {
5341 if (defined $file_name) {
5342 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
5347 die_error
(404, "No such tree") unless defined($hash);
5349 my $show_sizes = gitweb_check_feature
('show-sizes');
5350 my $have_blame = gitweb_check_feature
('blame');
5355 open my $fd, "-|", git_cmd
(), "ls-tree", '-z',
5356 ($show_sizes ? '-l' : ()), @extra_options, $hash
5357 or die_error
(500, "Open git-ls-tree failed");
5358 @entries = map { chomp; $_ } <$fd>;
5360 or die_error
(404, "Reading tree failed");
5363 my $refs = git_get_references
();
5364 my $ref = format_ref_marker
($refs, $hash_base);
5367 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5369 if (defined $file_name) {
5371 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
5373 $cgi->a({-href
=> href
(action
=>"tree",
5374 hash_base
=>"HEAD", file_name
=>$file_name)},
5377 my $snapshot_links = format_snapshot_links
($hash);
5378 if (defined $snapshot_links) {
5379 # FIXME: Should be available when we have no hash base as well.
5380 push @views_nav, $snapshot_links;
5382 git_print_page_nav
('tree','', $hash_base, undef, undef,
5383 join(' | ', @views_nav));
5384 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
5387 print "<div class=\"page_nav\">\n";
5388 print "<br/><br/></div>\n";
5389 print "<div class=\"title\">$hash</div>\n";
5391 if (defined $file_name) {
5392 $basedir = $file_name;
5393 if ($basedir ne '' && substr($basedir, -1) ne '/') {
5396 git_print_page_path
($file_name, 'tree', $hash_base);
5398 print "<div class=\"page_body\">\n";
5399 print "<table class=\"tree\">\n";
5401 # '..' (top directory) link if possible
5402 if (defined $hash_base &&
5403 defined $file_name && $file_name =~ m![^/]+$!) {
5405 print "<tr class=\"dark\">\n";
5407 print "<tr class=\"light\">\n";
5411 my $up = $file_name;
5412 $up =~ s!/?[^/]+$!!;
5413 undef $up unless $up;
5414 # based on git_print_tree_entry
5415 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
5416 print '<td class="size"> </td>'."\n" if $show_sizes;
5417 print '<td class="list">';
5418 print $cgi->a({-href
=> href
(action
=>"tree",
5419 hash_base
=>$hash_base,
5423 print "<td class=\"link\"></td>\n";
5427 foreach my $line (@entries) {
5428 my %t = parse_ls_tree_line
($line, -z
=> 1, -l
=> $show_sizes);
5431 print "<tr class=\"dark\">\n";
5433 print "<tr class=\"light\">\n";
5437 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
5441 print "</table>\n" .
5447 my ($project, $hash) = @_;
5449 # path/to/project.git -> project
5450 # path/to/project/.git -> project
5451 my $name = to_utf8
($project);
5452 $name =~ s
,([^/])/*\
.git
$,$1,;
5453 $name = basename
($name);
5455 $name =~ s/[[:cntrl:]]/?/g;
5458 if ($hash =~ /^[0-9a-fA-F]+$/) {
5459 # shorten SHA-1 hash
5460 my $full_hash = git_get_full_hash
($project, $hash);
5461 if ($full_hash =~ /^$hash/ && length($hash) > 7) {
5462 $ver = git_get_short_hash
($project, $hash);
5464 } elsif ($hash =~ m!^refs/tags/(.*)$!) {
5465 # tags don't need shortened SHA-1 hash
5468 # branches and other need shortened SHA-1 hash
5469 if ($hash =~ m!^refs/(?:heads|remotes)/(.*)$!) {
5472 $ver .= '-' . git_get_short_hash
($project, $hash);
5474 # in case of hierarchical branch names
5477 # name = project-version_string
5478 $name = "$name-$ver";
5480 return wantarray ? ($name, $name) : $name;
5484 my $format = $input_params{'snapshot_format'};
5485 if (!@snapshot_fmts) {
5486 die_error
(403, "Snapshots not allowed");
5488 # default to first supported snapshot format
5489 $format ||= $snapshot_fmts[0];
5490 if ($format !~ m/^[a-z0-9]+$/) {
5491 die_error
(400, "Invalid snapshot format parameter");
5492 } elsif (!exists($known_snapshot_formats{$format})) {
5493 die_error
(400, "Unknown snapshot format");
5494 } elsif ($known_snapshot_formats{$format}{'disabled'}) {
5495 die_error
(403, "Snapshot format not allowed");
5496 } elsif (!grep($_ eq $format, @snapshot_fmts)) {
5497 die_error
(403, "Unsupported snapshot format");
5500 my $type = git_get_type
("$hash^{}");
5502 die_error
(404, 'Object does not exist');
5503 } elsif ($type eq 'blob') {
5504 die_error
(400, 'Object is not a tree-ish');
5507 my ($name, $prefix) = snapshot_name
($project, $hash);
5508 my $filename = "$name$known_snapshot_formats{$format}{'suffix'}";
5509 my $cmd = quote_command
(
5510 git_cmd
(), 'archive',
5511 "--format=$known_snapshot_formats{$format}{'format'}",
5512 "--prefix=$prefix/", $hash);
5513 if (exists $known_snapshot_formats{$format}{'compressor'}) {
5514 $cmd .= ' | ' . quote_command
(@{$known_snapshot_formats{$format}{'compressor'}});
5517 $filename =~ s/(["\\])/\\$1/g;
5519 -type
=> $known_snapshot_formats{$format}{'type'},
5520 -content_disposition
=> 'inline; filename="' . $filename . '"',
5521 -status
=> '200 OK');
5523 open my $fd, "-|", $cmd
5524 or die_error
(500, "Execute git-archive failed");
5525 binmode STDOUT
, ':raw';
5527 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
5531 sub git_log_generic
{
5532 my ($fmt_name, $body_subr, $base, $parent, $file_name, $file_hash) = @_;
5534 my $head = git_get_head_hash
($project);
5535 if (!defined $base) {
5538 if (!defined $page) {
5541 my $refs = git_get_references
();
5543 my $commit_hash = $base;
5544 if (defined $parent) {
5545 $commit_hash = "$parent..$base";
5548 parse_commits
($commit_hash, 101, (100 * $page),
5549 defined $file_name ? ($file_name, "--full-history") : ());
5552 if (!defined $file_hash && defined $file_name) {
5553 # some commits could have deleted file in question,
5554 # and not have it in tree, but one of them has to have it
5555 for (my $i = 0; $i < @commitlist; $i++) {
5556 $file_hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
5557 last if defined $file_hash;
5560 if (defined $file_hash) {
5561 $ftype = git_get_type
($file_hash);
5563 if (defined $file_name && !defined $ftype) {
5564 die_error
(500, "Unknown type of object");
5567 if (defined $file_name) {
5568 %co = parse_commit
($base)
5569 or die_error
(404, "Unknown commit object");
5573 my $paging_nav = format_paging_nav
($fmt_name, $page, $#commitlist >= 100);
5575 if ($#commitlist >= 100) {
5577 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5578 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5580 my $patch_max = gitweb_get_feature
('patches');
5581 if ($patch_max && !defined $file_name) {
5582 if ($patch_max < 0 || @commitlist <= $patch_max) {
5583 $paging_nav .= " ⋅ " .
5584 $cgi->a({-href
=> href
(action
=>"patches", -replay
=>1)},
5590 git_print_page_nav
($fmt_name,'', $hash,$hash,$hash, $paging_nav);
5591 if (defined $file_name) {
5592 git_print_header_div
('commit', esc_html
($co{'title'}), $base);
5594 git_print_header_div
('summary', $project)
5596 git_print_page_path
($file_name, $ftype, $hash_base)
5597 if (defined $file_name);
5599 $body_subr->(\
@commitlist, 0, 99, $refs, $next_link,
5600 $file_name, $file_hash, $ftype);
5606 git_log_generic
('log', \
&git_log_body
,
5607 $hash, $hash_parent);
5611 $hash ||= $hash_base || "HEAD";
5612 my %co = parse_commit
($hash)
5613 or die_error
(404, "Unknown commit object");
5615 my $parent = $co{'parent'};
5616 my $parents = $co{'parents'}; # listref
5618 # we need to prepare $formats_nav before any parameter munging
5620 if (!defined $parent) {
5622 $formats_nav .= '(initial)';
5623 } elsif (@$parents == 1) {
5624 # single parent commit
5627 $cgi->a({-href
=> href
(action
=>"commit",
5629 esc_html
(substr($parent, 0, 7))) .
5636 $cgi->a({-href
=> href
(action
=>"commit",
5638 esc_html
(substr($_, 0, 7)));
5642 if (gitweb_check_feature
('patches') && @$parents <= 1) {
5643 $formats_nav .= " | " .
5644 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
5648 if (!defined $parent) {
5652 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
5654 (@$parents <= 1 ? $parent : '-c'),
5656 or die_error
(500, "Open git-diff-tree failed");
5657 @difftree = map { chomp; $_ } <$fd>;
5658 close $fd or die_error
(404, "Reading git-diff-tree failed");
5660 # non-textual hash id's can be cached
5662 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5665 my $refs = git_get_references
();
5666 my $ref = format_ref_marker
($refs, $co{'id'});
5668 git_header_html
(undef, $expires);
5669 git_print_page_nav
('commit', '',
5670 $hash, $co{'tree'}, $hash,
5673 if (defined $co{'parent'}) {
5674 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
5676 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
5678 print "<div class=\"title_text\">\n" .
5679 "<table class=\"object_header\">\n";
5680 git_print_authorship_rows
(\
%co);
5681 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
5684 "<td class=\"sha1\">" .
5685 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
5686 class => "list"}, $co{'tree'}) .
5688 "<td class=\"link\">" .
5689 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
5691 my $snapshot_links = format_snapshot_links
($hash);
5692 if (defined $snapshot_links) {
5693 print " | " . $snapshot_links;
5698 foreach my $par (@$parents) {
5701 "<td class=\"sha1\">" .
5702 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
5703 class => "list"}, $par) .
5705 "<td class=\"link\">" .
5706 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
5708 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
5715 print "<div class=\"page_body\">\n";
5716 git_print_log
($co{'comment'});
5719 git_difftree_body
(\
@difftree, $hash, @$parents);
5725 # object is defined by:
5726 # - hash or hash_base alone
5727 # - hash_base and file_name
5730 # - hash or hash_base alone
5731 if ($hash || ($hash_base && !defined $file_name)) {
5732 my $object_id = $hash || $hash_base;
5734 open my $fd, "-|", quote_command
(
5735 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
5736 or die_error
(404, "Object does not exist");
5740 or die_error
(404, "Object does not exist");
5742 # - hash_base and file_name
5743 } elsif ($hash_base && defined $file_name) {
5744 $file_name =~ s
,/+$,,;
5746 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
5747 or die_error
(404, "Base object does not exist");
5749 # here errors should not hapen
5750 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
5751 or die_error
(500, "Open git-ls-tree failed");
5755 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
5756 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
5757 die_error
(404, "File or directory for given base does not exist");
5762 die_error
(400, "Not enough information to find object");
5765 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
5766 hash
=>$hash, hash_base
=>$hash_base,
5767 file_name
=>$file_name),
5768 -status
=> '302 Found');
5772 my $format = shift || 'html';
5779 # preparing $fd and %diffinfo for git_patchset_body
5781 if (defined $hash_base && defined $hash_parent_base) {
5782 if (defined $file_name) {
5784 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5785 $hash_parent_base, $hash_base,
5786 "--", (defined $file_parent ? $file_parent : ()), $file_name
5787 or die_error
(500, "Open git-diff-tree failed");
5788 @difftree = map { chomp; $_ } <$fd>;
5790 or die_error
(404, "Reading git-diff-tree failed");
5792 or die_error
(404, "Blob diff not found");
5794 } elsif (defined $hash &&
5795 $hash =~ /[0-9a-fA-F]{40}/) {
5796 # try to find filename from $hash
5798 # read filtered raw output
5799 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5800 $hash_parent_base, $hash_base, "--"
5801 or die_error
(500, "Open git-diff-tree failed");
5803 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
5805 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
5806 map { chomp; $_ } <$fd>;
5808 or die_error
(404, "Reading git-diff-tree failed");
5810 or die_error
(404, "Blob diff not found");
5813 die_error
(400, "Missing one of the blob diff parameters");
5816 if (@difftree > 1) {
5817 die_error
(400, "Ambiguous blob diff specification");
5820 %diffinfo = parse_difftree_raw_line
($difftree[0]);
5821 $file_parent ||= $diffinfo{'from_file'} || $file_name;
5822 $file_name ||= $diffinfo{'to_file'};
5824 $hash_parent ||= $diffinfo{'from_id'};
5825 $hash ||= $diffinfo{'to_id'};
5827 # non-textual hash id's can be cached
5828 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
5829 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
5834 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5835 '-p', ($format eq 'html' ? "--full-index" : ()),
5836 $hash_parent_base, $hash_base,
5837 "--", (defined $file_parent ? $file_parent : ()), $file_name
5838 or die_error
(500, "Open git-diff-tree failed");
5841 # old/legacy style URI -- not generated anymore since 1.4.3.
5843 die_error
('404 Not Found', "Missing one of the blob diff parameters")
5847 if ($format eq 'html') {
5849 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
5851 git_header_html
(undef, $expires);
5852 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
5853 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
5854 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5856 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
5857 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
5859 if (defined $file_name) {
5860 git_print_page_path
($file_name, "blob", $hash_base);
5862 print "<div class=\"page_path\"></div>\n";
5865 } elsif ($format eq 'plain') {
5867 -type
=> 'text/plain',
5868 -charset
=> 'utf-8',
5869 -expires
=> $expires,
5870 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
5872 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5875 die_error
(400, "Unknown blobdiff format");
5879 if ($format eq 'html') {
5880 print "<div class=\"page_body\">\n";
5882 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
5885 print "</div>\n"; # class="page_body"
5889 while (my $line = <$fd>) {
5890 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
5891 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
5895 last if $line =~ m!^\+\+\+!;
5903 sub git_blobdiff_plain
{
5904 git_blobdiff
('plain');
5907 sub git_commitdiff
{
5909 my $format = $params{-format
} || 'html';
5911 my ($patch_max) = gitweb_get_feature
('patches');
5912 if ($format eq 'patch') {
5913 die_error
(403, "Patch view not allowed") unless $patch_max;
5916 $hash ||= $hash_base || "HEAD";
5917 my %co = parse_commit
($hash)
5918 or die_error
(404, "Unknown commit object");
5920 # choose format for commitdiff for merge
5921 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
5922 $hash_parent = '--cc';
5924 # we need to prepare $formats_nav before almost any parameter munging
5926 if ($format eq 'html') {
5928 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
5930 if ($patch_max && @{$co{'parents'}} <= 1) {
5931 $formats_nav .= " | " .
5932 $cgi->a({-href
=> href
(action
=>"patch", -replay
=>1)},
5936 if (defined $hash_parent &&
5937 $hash_parent ne '-c' && $hash_parent ne '--cc') {
5938 # commitdiff with two commits given
5939 my $hash_parent_short = $hash_parent;
5940 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5941 $hash_parent_short = substr($hash_parent, 0, 7);
5945 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
5946 if ($co{'parents'}[$i] eq $hash_parent) {
5947 $formats_nav .= ' parent ' . ($i+1);
5951 $formats_nav .= ': ' .
5952 $cgi->a({-href
=> href
(action
=>"commitdiff",
5953 hash
=>$hash_parent)},
5954 esc_html
($hash_parent_short)) .
5956 } elsif (!$co{'parent'}) {
5958 $formats_nav .= ' (initial)';
5959 } elsif (scalar @{$co{'parents'}} == 1) {
5960 # single parent commit
5963 $cgi->a({-href
=> href
(action
=>"commitdiff",
5964 hash
=>$co{'parent'})},
5965 esc_html
(substr($co{'parent'}, 0, 7))) .
5969 if ($hash_parent eq '--cc') {
5970 $formats_nav .= ' | ' .
5971 $cgi->a({-href
=> href
(action
=>"commitdiff",
5972 hash
=>$hash, hash_parent
=>'-c')},
5974 } else { # $hash_parent eq '-c'
5975 $formats_nav .= ' | ' .
5976 $cgi->a({-href
=> href
(action
=>"commitdiff",
5977 hash
=>$hash, hash_parent
=>'--cc')},
5983 $cgi->a({-href
=> href
(action
=>"commitdiff",
5985 esc_html
(substr($_, 0, 7)));
5986 } @{$co{'parents'}} ) .
5991 my $hash_parent_param = $hash_parent;
5992 if (!defined $hash_parent_param) {
5993 # --cc for multiple parents, --root for parentless
5994 $hash_parent_param =
5995 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
6001 if ($format eq 'html') {
6002 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6003 "--no-commit-id", "--patch-with-raw", "--full-index",
6004 $hash_parent_param, $hash, "--"
6005 or die_error
(500, "Open git-diff-tree failed");
6007 while (my $line = <$fd>) {
6009 # empty line ends raw part of diff-tree output
6011 push @difftree, scalar parse_difftree_raw_line
($line);
6014 } elsif ($format eq 'plain') {
6015 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6016 '-p', $hash_parent_param, $hash, "--"
6017 or die_error
(500, "Open git-diff-tree failed");
6018 } elsif ($format eq 'patch') {
6019 # For commit ranges, we limit the output to the number of
6020 # patches specified in the 'patches' feature.
6021 # For single commits, we limit the output to a single patch,
6022 # diverging from the git-format-patch default.
6023 my @commit_spec = ();
6025 if ($patch_max > 0) {
6026 push @commit_spec, "-$patch_max";
6028 push @commit_spec, '-n', "$hash_parent..$hash";
6030 if ($params{-single
}) {
6031 push @commit_spec, '-1';
6033 if ($patch_max > 0) {
6034 push @commit_spec, "-$patch_max";
6036 push @commit_spec, "-n";
6038 push @commit_spec, '--root', $hash;
6040 open $fd, "-|", git_cmd
(), "format-patch", '--encoding=utf8',
6041 '--stdout', @commit_spec
6042 or die_error
(500, "Open git-format-patch failed");
6044 die_error
(400, "Unknown commitdiff format");
6047 # non-textual hash id's can be cached
6049 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
6053 # write commit message
6054 if ($format eq 'html') {
6055 my $refs = git_get_references
();
6056 my $ref = format_ref_marker
($refs, $co{'id'});
6058 git_header_html
(undef, $expires);
6059 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
6060 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
6061 print "<div class=\"title_text\">\n" .
6062 "<table class=\"object_header\">\n";
6063 git_print_authorship_rows
(\
%co);
6066 print "<div class=\"page_body\">\n";
6067 if (@{$co{'comment'}} > 1) {
6068 print "<div class=\"log\">\n";
6069 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
6070 print "</div>\n"; # class="log"
6073 } elsif ($format eq 'plain') {
6074 my $refs = git_get_references
("tags");
6075 my $tagname = git_get_rev_name_tags
($hash);
6076 my $filename = basename
($project) . "-$hash.patch";
6079 -type
=> 'text/plain',
6080 -charset
=> 'utf-8',
6081 -expires
=> $expires,
6082 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
6083 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
6084 print "From: " . to_utf8
($co{'author'}) . "\n";
6085 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
6086 print "Subject: " . to_utf8
($co{'title'}) . "\n";
6088 print "X-Git-Tag: $tagname\n" if $tagname;
6089 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
6091 foreach my $line (@{$co{'comment'}}) {
6092 print to_utf8
($line) . "\n";
6095 } elsif ($format eq 'patch') {
6096 my $filename = basename
($project) . "-$hash.patch";
6099 -type
=> 'text/plain',
6100 -charset
=> 'utf-8',
6101 -expires
=> $expires,
6102 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
6106 if ($format eq 'html') {
6107 my $use_parents = !defined $hash_parent ||
6108 $hash_parent eq '-c' || $hash_parent eq '--cc';
6109 git_difftree_body
(\
@difftree, $hash,
6110 $use_parents ? @{$co{'parents'}} : $hash_parent);
6113 git_patchset_body
($fd, \
@difftree, $hash,
6114 $use_parents ? @{$co{'parents'}} : $hash_parent);
6116 print "</div>\n"; # class="page_body"
6119 } elsif ($format eq 'plain') {
6123 or print "Reading git-diff-tree failed\n";
6124 } elsif ($format eq 'patch') {
6128 or print "Reading git-format-patch failed\n";
6132 sub git_commitdiff_plain
{
6133 git_commitdiff
(-format
=> 'plain');
6136 # format-patch-style patches
6138 git_commitdiff
(-format
=> 'patch', -single
=> 1);
6142 git_commitdiff
(-format
=> 'patch');
6146 git_log_generic
('history', \
&git_history_body
,
6147 $hash_base, $hash_parent_base,
6152 gitweb_check_feature
('search') or die_error
(403, "Search is disabled");
6153 if (!defined $searchtext) {
6154 die_error
(400, "Text field is empty");
6156 if (!defined $hash) {
6157 $hash = git_get_head_hash
($project);
6159 my %co = parse_commit
($hash);
6161 die_error
(404, "Unknown commit object");
6163 if (!defined $page) {
6167 $searchtype ||= 'commit';
6168 if ($searchtype eq 'pickaxe') {
6169 # pickaxe may take all resources of your box and run for several minutes
6170 # with every query - so decide by yourself how public you make this feature
6171 gitweb_check_feature
('pickaxe')
6172 or die_error
(403, "Pickaxe is disabled");
6174 if ($searchtype eq 'grep') {
6175 gitweb_check_feature
('grep')[0]
6176 or die_error
(403, "Grep is disabled");
6181 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
6183 if ($searchtype eq 'commit') {
6184 $greptype = "--grep=";
6185 } elsif ($searchtype eq 'author') {
6186 $greptype = "--author=";
6187 } elsif ($searchtype eq 'committer') {
6188 $greptype = "--committer=";
6190 $greptype .= $searchtext;
6191 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
6192 $greptype, '--regexp-ignore-case',
6193 $search_use_regexp ? '--extended-regexp' : '--fixed-strings');
6195 my $paging_nav = '';
6198 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
6199 searchtext
=>$searchtext,
6200 searchtype
=>$searchtype)},
6202 $paging_nav .= " ⋅ " .
6203 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
6204 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
6206 $paging_nav .= "first";
6207 $paging_nav .= " ⋅ prev";
6210 if ($#commitlist >= 100) {
6212 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
6213 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
6214 $paging_nav .= " ⋅ $next_link";
6216 $paging_nav .= " ⋅ next";
6219 if ($#commitlist >= 100) {
6222 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
6223 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6224 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
6227 if ($searchtype eq 'pickaxe') {
6228 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
6229 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6231 print "<table class=\"pickaxe search\">\n";
6234 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
6235 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
6236 ($search_use_regexp ? '--pickaxe-regex' : ());
6239 while (my $line = <$fd>) {
6243 my %set = parse_difftree_raw_line
($line);
6244 if (defined $set{'commit'}) {
6245 # finish previous commit
6248 "<td class=\"link\">" .
6249 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
6251 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
6257 print "<tr class=\"dark\">\n";
6259 print "<tr class=\"light\">\n";
6262 %co = parse_commit
($set{'commit'});
6263 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
6264 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
6265 "<td><i>$author</i></td>\n" .
6267 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
6268 -class => "list subject"},
6269 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
6270 } elsif (defined $set{'to_id'}) {
6271 next if ($set{'to_id'} =~ m/^0{40}$/);
6273 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
6274 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
6276 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
6282 # finish last commit (warning: repetition!)
6285 "<td class=\"link\">" .
6286 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
6288 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
6296 if ($searchtype eq 'grep') {
6297 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
6298 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
6300 print "<table class=\"grep_search\">\n";
6304 open my $fd, "-|", git_cmd
(), 'grep', '-n',
6305 $search_use_regexp ? ('-E', '-i') : '-F',
6306 $searchtext, $co{'tree'};
6308 while (my $line = <$fd>) {
6310 my ($file, $lno, $ltext, $binary);
6311 last if ($matches++ > 1000);
6312 if ($line =~ /^Binary file (.+) matches$/) {
6316 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
6318 if ($file ne $lastfile) {
6319 $lastfile and print "</td></tr>\n";
6321 print "<tr class=\"dark\">\n";
6323 print "<tr class=\"light\">\n";
6325 print "<td class=\"list\">".
6326 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6327 file_name
=>"$file"),
6328 -class => "list"}, esc_path
($file));
6329 print "</td><td>\n";
6333 print "<div class=\"binary\">Binary file</div>\n";
6335 $ltext = untabify
($ltext);
6336 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
6337 $ltext = esc_html
($1, -nbsp
=>1);
6338 $ltext .= '<span class="match">';
6339 $ltext .= esc_html
($2, -nbsp
=>1);
6340 $ltext .= '</span>';
6341 $ltext .= esc_html
($3, -nbsp
=>1);
6343 $ltext = esc_html
($ltext, -nbsp
=>1);
6345 print "<div class=\"pre\">" .
6346 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
6347 file_name
=>"$file").'#l'.$lno,
6348 -class => "linenr"}, sprintf('%4i', $lno))
6349 . ' ' . $ltext . "</div>\n";
6353 print "</td></tr>\n";
6354 if ($matches > 1000) {
6355 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
6358 print "<div class=\"diff nodifferences\">No matches found</div>\n";
6367 sub git_search_help
{
6369 git_print_page_nav
('','', $hash,$hash,$hash);
6371 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
6372 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
6373 the pattern entered is recognized as the POSIX extended
6374 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
6377 <dt><b>commit</b></dt>
6378 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
6380 my $have_grep = gitweb_check_feature
('grep');
6383 <dt><b>grep</b></dt>
6384 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
6385 a different one) are searched for the given pattern. On large trees, this search can take
6386 a while and put some strain on the server, so please use it with some consideration. Note that
6387 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
6388 case-sensitive.</dd>
6392 <dt><b>author</b></dt>
6393 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
6394 <dt><b>committer</b></dt>
6395 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
6397 my $have_pickaxe = gitweb_check_feature
('pickaxe');
6398 if ($have_pickaxe) {
6400 <dt><b>pickaxe</b></dt>
6401 <dd>All commits that caused the string to appear or disappear from any file (changes that
6402 added, removed or "modified" the string) will be listed. This search can take a while and
6403 takes a lot of strain on the server, so please use it wisely. Note that since you may be
6404 interested even in changes just changing the case as well, this search is case sensitive.</dd>
6412 git_log_generic
('shortlog', \
&git_shortlog_body
,
6413 $hash, $hash_parent);
6416 ## ......................................................................
6417 ## feeds (RSS, Atom; OPML)
6420 my $format = shift || 'atom';
6421 my $have_blame = gitweb_check_feature
('blame');
6423 # Atom: http://www.atomenabled.org/developers/syndication/
6424 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
6425 if ($format ne 'rss' && $format ne 'atom') {
6426 die_error
(400, "Unknown web feed format");
6429 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
6430 my $head = $hash || 'HEAD';
6431 my @commitlist = parse_commits
($head, 150, 0, $file_name);
6435 my $content_type = "application/$format+xml";
6436 if (defined $cgi->http('HTTP_ACCEPT') &&
6437 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
6438 # browser (feed reader) prefers text/xml
6439 $content_type = 'text/xml';
6441 if (defined($commitlist[0])) {
6442 %latest_commit = %{$commitlist[0]};
6443 my $latest_epoch = $latest_commit{'committer_epoch'};
6444 %latest_date = parse_date
($latest_epoch);
6445 my $if_modified = $cgi->http('IF_MODIFIED_SINCE');
6446 if (defined $if_modified) {
6448 if (eval { require HTTP
::Date
; 1; }) {
6449 $since = HTTP
::Date
::str2time
($if_modified);
6450 } elsif (eval { require Time
::ParseDate
; 1; }) {
6451 $since = Time
::ParseDate
::parsedate
($if_modified, GMT
=> 1);
6453 if (defined $since && $latest_epoch <= $since) {
6455 -type
=> $content_type,
6456 -charset
=> 'utf-8',
6457 -last_modified
=> $latest_date{'rfc2822'},
6458 -status
=> '304 Not Modified');
6463 -type
=> $content_type,
6464 -charset
=> 'utf-8',
6465 -last_modified
=> $latest_date{'rfc2822'});
6468 -type
=> $content_type,
6469 -charset
=> 'utf-8');
6472 # Optimization: skip generating the body if client asks only
6473 # for Last-Modified date.
6474 return if ($cgi->request_method() eq 'HEAD');
6477 my $title = "$site_name - $project/$action";
6478 my $feed_type = 'log';
6479 if (defined $hash) {
6480 $title .= " - '$hash'";
6481 $feed_type = 'branch log';
6482 if (defined $file_name) {
6483 $title .= " :: $file_name";
6484 $feed_type = 'history';
6486 } elsif (defined $file_name) {
6487 $title .= " - $file_name";
6488 $feed_type = 'history';
6490 $title .= " $feed_type";
6491 my $descr = git_get_project_description
($project);
6492 if (defined $descr) {
6493 $descr = esc_html
($descr);
6495 $descr = "$project " .
6496 ($format eq 'rss' ? 'RSS' : 'Atom') .
6499 my $owner = git_get_project_owner
($project);
6500 $owner = esc_html
($owner);
6504 if (defined $file_name) {
6505 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
6506 } elsif (defined $hash) {
6507 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
6509 $alt_url = href
(-full
=>1, action
=>"summary");
6511 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
6512 if ($format eq 'rss') {
6514 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
6517 print "<title>$title</title>\n" .
6518 "<link>$alt_url</link>\n" .
6519 "<description>$descr</description>\n" .
6520 "<language>en</language>\n" .
6521 # project owner is responsible for 'editorial' content
6522 "<managingEditor>$owner</managingEditor>\n";
6523 if (defined $logo || defined $favicon) {
6524 # prefer the logo to the favicon, since RSS
6525 # doesn't allow both
6526 my $img = esc_url
($logo || $favicon);
6528 "<url>$img</url>\n" .
6529 "<title>$title</title>\n" .
6530 "<link>$alt_url</link>\n" .
6534 print "<pubDate>$latest_date{'rfc2822'}</pubDate>\n";
6535 print "<lastBuildDate>$latest_date{'rfc2822'}</lastBuildDate>\n";
6537 print "<generator>gitweb v.$version/$git_version</generator>\n";
6538 } elsif ($format eq 'atom') {
6540 <feed xmlns="http://www.w3.org/2005/Atom">
6542 print "<title>$title</title>\n" .
6543 "<subtitle>$descr</subtitle>\n" .
6544 '<link rel="alternate" type="text/html" href="' .
6545 $alt_url . '" />' . "\n" .
6546 '<link rel="self" type="' . $content_type . '" href="' .
6547 $cgi->self_url() . '" />' . "\n" .
6548 "<id>" . href
(-full
=>1) . "</id>\n" .
6549 # use project owner for feed author
6550 "<author><name>$owner</name></author>\n";
6551 if (defined $favicon) {
6552 print "<icon>" . esc_url
($favicon) . "</icon>\n";
6554 if (defined $logo_url) {
6555 # not twice as wide as tall: 72 x 27 pixels
6556 print "<logo>" . esc_url
($logo) . "</logo>\n";
6558 if (! %latest_date) {
6559 # dummy date to keep the feed valid until commits trickle in:
6560 print "<updated>1970-01-01T00:00:00Z</updated>\n";
6562 print "<updated>$latest_date{'iso-8601'}</updated>\n";
6564 print "<generator version='$version/$git_version'>gitweb</generator>\n";
6568 for (my $i = 0; $i <= $#commitlist; $i++) {
6569 my %co = %{$commitlist[$i]};
6570 my $commit = $co{'id'};
6571 # we read 150, we always show 30 and the ones more recent than 48 hours
6572 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
6575 my %cd = parse_date
($co{'author_epoch'});
6577 # get list of changed files
6578 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
6579 $co{'parent'} || "--root",
6580 $co{'id'}, "--", (defined $file_name ? $file_name : ())
6582 my @difftree = map { chomp; $_ } <$fd>;
6586 # print element (entry, item)
6587 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
6588 if ($format eq 'rss') {
6590 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
6591 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
6592 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
6593 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
6594 "<link>$co_url</link>\n" .
6595 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
6596 "<content:encoded>" .
6598 } elsif ($format eq 'atom') {
6600 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
6601 "<updated>$cd{'iso-8601'}</updated>\n" .
6603 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
6604 if ($co{'author_email'}) {
6605 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
6607 print "</author>\n" .
6608 # use committer for contributor
6610 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
6611 if ($co{'committer_email'}) {
6612 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
6614 print "</contributor>\n" .
6615 "<published>$cd{'iso-8601'}</published>\n" .
6616 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
6617 "<id>$co_url</id>\n" .
6618 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
6619 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
6621 my $comment = $co{'comment'};
6623 foreach my $line (@$comment) {
6624 $line = esc_html
($line);
6627 print "</pre><ul>\n";
6628 foreach my $difftree_line (@difftree) {
6629 my %difftree = parse_difftree_raw_line
($difftree_line);
6630 next if !$difftree{'from_id'};
6632 my $file = $difftree{'file'} || $difftree{'to_file'};
6636 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
6637 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
6638 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
6639 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
6640 -title
=> "diff"}, 'D');
6642 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
6643 file_name
=>$file, hash_base
=>$commit),
6644 -title
=> "blame"}, 'B');
6646 # if this is not a feed of a file history
6647 if (!defined $file_name || $file_name ne $file) {
6648 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
6649 file_name
=>$file, hash
=>$commit),
6650 -title
=> "history"}, 'H');
6652 $file = esc_path
($file);
6656 if ($format eq 'rss') {
6657 print "</ul>]]>\n" .
6658 "</content:encoded>\n" .
6660 } elsif ($format eq 'atom') {
6661 print "</ul>\n</div>\n" .
6668 if ($format eq 'rss') {
6669 print "</channel>\n</rss>\n";
6670 } elsif ($format eq 'atom') {
6684 my @list = git_get_projects_list
();
6687 -type
=> 'text/xml',
6688 -charset
=> 'utf-8',
6689 -content_disposition
=> 'inline; filename="opml.xml"');
6692 <?xml version="1.0" encoding="utf-8"?>
6693 <opml version="1.0">
6695 <title>$site_name OPML Export</title>
6698 <outline text="git RSS feeds">
6701 foreach my $pr (@list) {
6703 my $head = git_get_head_hash
($proj{'path'});
6704 if (!defined $head) {
6707 $git_dir = "$projectroot/$proj{'path'}";
6708 my %co = parse_commit
($head);
6713 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
6714 my $rss = href
('project' => $proj{'path'}, 'action' => 'rss', -full
=> 1);
6715 my $html = href
('project' => $proj{'path'}, 'action' => 'summary', -full
=> 1);
6716 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";