3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI
qw(:standard :escapeHTML -nosticky);
13 use CGI
::Util
qw(unescape);
14 use CGI
::Carp
qw(fatalsToBrowser);
18 use File
::Basename
qw(basename);
19 binmode STDOUT
, ':utf8';
22 CGI
->compile() if $ENV{'MOD_PERL'};
26 our $version = "++GIT_VERSION++";
27 our $my_url = $cgi->url();
28 our $my_uri = $cgi->url(-absolute
=> 1);
30 # if we're called with PATH_INFO, we have to strip that
31 # from the URL to find our real URL
32 if (my $path_info = $ENV{"PATH_INFO"}) {
33 $my_url =~ s
,\Q
$path_info\E
$,,;
34 $my_uri =~ s
,\Q
$path_info\E
$,,;
37 # core git executable to use
38 # this can just be "git" if your webserver has a sensible PATH
39 our $GIT = "++GIT_BINDIR++/git";
41 # absolute fs-path which will be prepended to the project path
42 #our $projectroot = "/pub/scm";
43 our $projectroot = "++GITWEB_PROJECTROOT++";
45 # fs traversing limit for getting project list
46 # the number is relative to the projectroot
47 our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
49 # target of the home link on top of all pages
50 our $home_link = $my_uri || "/";
52 # string of the home link on top of all pages
53 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
55 # name of your site or organization to appear in page titles
56 # replace this with something more descriptive for clearer bookmarks
57 our $site_name = "++GITWEB_SITENAME++"
58 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
60 # filename of html text to include at top of each page
61 our $site_header = "++GITWEB_SITE_HEADER++";
62 # html text to include at home page
63 our $home_text = "++GITWEB_HOMETEXT++";
64 # filename of html text to include at bottom of each page
65 our $site_footer = "++GITWEB_SITE_FOOTER++";
68 our @stylesheets = ("++GITWEB_CSS++");
69 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
70 our $stylesheet = undef;
71 # URI of GIT logo (72x27 size)
72 our $logo = "++GITWEB_LOGO++";
73 # URI of GIT favicon, assumed to be image/png type
74 our $favicon = "++GITWEB_FAVICON++";
76 # URI and label (title) of GIT logo link
77 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
78 #our $logo_label = "git documentation";
79 our $logo_url = "http://git.or.cz/";
80 our $logo_label = "git homepage";
82 # source of projects list
83 our $projects_list = "++GITWEB_LIST++";
85 # the width (in characters) of the projects list "Description" column
86 our $projects_list_description_width = 25;
88 # default order of projects list
89 # valid values are none, project, descr, owner, and age
90 our $default_projects_order = "project";
92 # show repository only if this file exists
93 # (only effective if this variable evaluates to true)
94 our $export_ok = "++GITWEB_EXPORT_OK++";
96 # only allow viewing of repositories also shown on the overview page
97 our $strict_export = "++GITWEB_STRICT_EXPORT++";
99 # list of git base URLs used for URL to where fetch project from,
100 # i.e. full URL is "$git_base_url/$project"
101 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
103 # default blob_plain mimetype and default charset for text/plain blob
104 our $default_blob_plain_mimetype = 'text/plain';
105 our $default_text_plain_charset = undef;
107 # file to use for guessing MIME types before trying /etc/mime.types
108 # (relative to the current git repository)
109 our $mimetypes_file = undef;
111 # assume this charset if line contains non-UTF-8 characters;
112 # it should be valid encoding (see Encoding::Supported(3pm) for list),
113 # for which encoding all byte sequences are valid, for example
114 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
115 # could be even 'utf-8' for the old behavior)
116 our $fallback_encoding = 'latin1';
118 # rename detection options for git-diff and git-diff-tree
119 # - default is '-M', with the cost proportional to
120 # (number of removed files) * (number of new files).
121 # - more costly is '-C' (which implies '-M'), with the cost proportional to
122 # (number of changed files + number of removed files) * (number of new files)
123 # - even more costly is '-C', '--find-copies-harder' with cost
124 # (number of files in the original tree) * (number of new files)
125 # - one might want to include '-B' option, e.g. '-B', '-M'
126 our @diff_opts = ('-M'); # taken from git_commit
128 # information about snapshot formats that gitweb is capable of serving
129 our %known_snapshot_formats = (
131 # 'display' => display name,
132 # 'type' => mime type,
133 # 'suffix' => filename suffix,
134 # 'format' => --format for git-archive,
135 # 'compressor' => [compressor command and arguments]
136 # (array reference, optional)}
139 'display' => 'tar.gz',
140 'type' => 'application/x-gzip',
141 'suffix' => '.tar.gz',
143 'compressor' => ['gzip']},
146 'display' => 'tar.bz2',
147 'type' => 'application/x-bzip2',
148 'suffix' => '.tar.bz2',
150 'compressor' => ['bzip2']},
154 'type' => 'application/x-zip',
159 # Aliases so we understand old gitweb.snapshot values in repository
161 our %known_snapshot_format_aliases = (
165 # backward compatibility: legacy gitweb config support
166 'x-gzip' => undef, 'gz' => undef,
167 'x-bzip2' => undef, 'bz2' => undef,
168 'x-zip' => undef, '' => undef,
171 # You define site-wide feature defaults here; override them with
172 # $GITWEB_CONFIG as necessary.
175 # 'sub' => feature-sub (subroutine),
176 # 'override' => allow-override (boolean),
177 # 'default' => [ default options...] (array reference)}
179 # if feature is overridable (it means that allow-override has true value),
180 # then feature-sub will be called with default options as parameters;
181 # return value of feature-sub indicates if to enable specified feature
183 # if there is no 'sub' key (no feature-sub), then feature cannot be
186 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
188 # Enable the 'blame' blob view, showing the last commit that modified
189 # each line in the file. This can be very CPU-intensive.
191 # To enable system wide have in $GITWEB_CONFIG
192 # $feature{'blame'}{'default'} = [1];
193 # To have project specific config enable override in $GITWEB_CONFIG
194 # $feature{'blame'}{'override'} = 1;
195 # and in project config gitweb.blame = 0|1;
197 'sub' => \
&feature_blame
,
201 # Enable the 'snapshot' link, providing a compressed archive of any
202 # tree. This can potentially generate high traffic if you have large
205 # Value is a list of formats defined in %known_snapshot_formats that
207 # To disable system wide have in $GITWEB_CONFIG
208 # $feature{'snapshot'}{'default'} = [];
209 # To have project specific config enable override in $GITWEB_CONFIG
210 # $feature{'snapshot'}{'override'} = 1;
211 # and in project config, a comma-separated list of formats or "none"
212 # to disable. Example: gitweb.snapshot = tbz2,zip;
214 'sub' => \
&feature_snapshot
,
216 'default' => ['tgz']},
218 # Enable text search, which will list the commits which match author,
219 # committer or commit text to a given string. Enabled by default.
220 # Project specific override is not supported.
225 # Enable grep search, which will list the files in currently selected
226 # tree containing the given string. Enabled by default. This can be
227 # potentially CPU-intensive, of course.
229 # To enable system wide have in $GITWEB_CONFIG
230 # $feature{'grep'}{'default'} = [1];
231 # To have project specific config enable override in $GITWEB_CONFIG
232 # $feature{'grep'}{'override'} = 1;
233 # and in project config gitweb.grep = 0|1;
238 # Enable the pickaxe search, which will list the commits that modified
239 # a given string in a file. This can be practical and quite faster
240 # alternative to 'blame', but still potentially CPU-intensive.
242 # To enable system wide have in $GITWEB_CONFIG
243 # $feature{'pickaxe'}{'default'} = [1];
244 # To have project specific config enable override in $GITWEB_CONFIG
245 # $feature{'pickaxe'}{'override'} = 1;
246 # and in project config gitweb.pickaxe = 0|1;
248 'sub' => \
&feature_pickaxe
,
252 # Make gitweb use an alternative format of the URLs which can be
253 # more readable and natural-looking: project name is embedded
254 # directly in the path and the query string contains other
255 # auxiliary information. All gitweb installations recognize
256 # URL in either format; this configures in which formats gitweb
259 # To enable system wide have in $GITWEB_CONFIG
260 # $feature{'pathinfo'}{'default'} = [1];
261 # Project specific override is not supported.
263 # Note that you will need to change the default location of CSS,
264 # favicon, logo and possibly other files to an absolute URL. Also,
265 # if gitweb.cgi serves as your indexfile, you will need to force
266 # $my_uri to contain the script name in your $GITWEB_CONFIG.
271 # Make gitweb consider projects in project root subdirectories
272 # to be forks of existing projects. Given project $projname.git,
273 # projects matching $projname/*.git will not be shown in the main
274 # projects list, instead a '+' mark will be added to $projname
275 # there and a 'forks' view will be enabled for the project, listing
276 # all the forks. If project list is taken from a file, forks have
277 # to be listed after the main project.
279 # To enable system wide have in $GITWEB_CONFIG
280 # $feature{'forks'}{'default'} = [1];
281 # Project specific override is not supported.
286 # Insert custom links to the action bar of all project pages.
287 # This enables you mainly to link to third-party scripts integrating
288 # into gitweb; e.g. git-browser for graphical history representation
289 # or custom web-based repository administration interface.
291 # The 'default' value consists of a list of triplets in the form
292 # (label, link, position) where position is the label after which
293 # to inster the link and link is a format string where %n expands
294 # to the project name, %f to the project path within the filesystem,
295 # %h to the current hash (h gitweb parameter) and %b to the current
296 # hash base (hb gitweb parameter).
298 # To enable system wide have in $GITWEB_CONFIG e.g.
299 # $feature{'actions'}{'default'} = [('graphiclog',
300 # '/git-browser/by-commit.html?r=%n', 'summary')];
301 # Project specific override is not supported.
307 sub gitweb_check_feature
{
309 return unless exists $feature{$name};
310 my ($sub, $override, @defaults) = (
311 $feature{$name}{'sub'},
312 $feature{$name}{'override'},
313 @
{$feature{$name}{'default'}});
314 if (!$override) { return @defaults; }
316 warn "feature $name is not overrideable";
319 return $sub->(@defaults);
323 my ($val) = git_get_project_config
('blame', '--bool');
325 if ($val eq 'true') {
327 } elsif ($val eq 'false') {
334 sub feature_snapshot
{
337 my ($val) = git_get_project_config
('snapshot');
340 @fmts = ($val eq 'none' ?
() : split /\s*[,\s]\s*/, $val);
347 my ($val) = git_get_project_config
('grep', '--bool');
349 if ($val eq 'true') {
351 } elsif ($val eq 'false') {
358 sub feature_pickaxe
{
359 my ($val) = git_get_project_config
('pickaxe', '--bool');
361 if ($val eq 'true') {
363 } elsif ($val eq 'false') {
370 # checking HEAD file with -e is fragile if the repository was
371 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
373 sub check_head_link
{
375 my $headfile = "$dir/HEAD";
376 return ((-e
$headfile) ||
377 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
380 sub check_export_ok
{
382 return (check_head_link
($dir) &&
383 (!$export_ok || -e
"$dir/$export_ok"));
386 # process alternate names for backward compatibility
387 # filter out unsupported (unknown) snapshot formats
388 sub filter_snapshot_fmts
{
392 exists $known_snapshot_format_aliases{$_} ?
393 $known_snapshot_format_aliases{$_} : $_} @fmts;
394 @fmts = grep(exists $known_snapshot_formats{$_}, @fmts);
398 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
399 if (-e
$GITWEB_CONFIG) {
402 our $GITWEB_CONFIG_SYSTEM = $ENV{'GITWEB_CONFIG_SYSTEM'} || "++GITWEB_CONFIG_SYSTEM++";
403 do $GITWEB_CONFIG_SYSTEM if -e
$GITWEB_CONFIG_SYSTEM;
406 # version of the core git binary
407 our $git_version = qx("$GIT" --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
409 $projects_list ||= $projectroot;
411 # ======================================================================
412 # input validation and dispatch
413 our $action = $cgi->param('a');
414 if (defined $action) {
415 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
416 die_error
(400, "Invalid action parameter");
420 # parameters which are pathnames
421 our $project = $cgi->param('p');
422 if (defined $project) {
423 if (!validate_pathname
($project) ||
424 !(-d
"$projectroot/$project") ||
425 !check_head_link
("$projectroot/$project") ||
426 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
427 ($strict_export && !project_in_list
($project))) {
429 die_error
(404, "No such project");
433 our $file_name = $cgi->param('f');
434 if (defined $file_name) {
435 if (!validate_pathname
($file_name)) {
436 die_error
(400, "Invalid file parameter");
440 our $file_parent = $cgi->param('fp');
441 if (defined $file_parent) {
442 if (!validate_pathname
($file_parent)) {
443 die_error
(400, "Invalid file parent parameter");
447 # parameters which are refnames
448 our $hash = $cgi->param('h');
450 if (!validate_refname
($hash)) {
451 die_error
(400, "Invalid hash parameter");
455 our $hash_parent = $cgi->param('hp');
456 if (defined $hash_parent) {
457 if (!validate_refname
($hash_parent)) {
458 die_error
(400, "Invalid hash parent parameter");
462 our $hash_base = $cgi->param('hb');
463 if (defined $hash_base) {
464 if (!validate_refname
($hash_base)) {
465 die_error
(400, "Invalid hash base parameter");
469 my %allowed_options = (
470 "--no-merges" => [ qw(rss atom log shortlog history) ],
473 our @extra_options = $cgi->param('opt');
474 if (defined @extra_options) {
475 foreach my $opt (@extra_options) {
476 if (not exists $allowed_options{$opt}) {
477 die_error
(400, "Invalid option parameter");
479 if (not grep(/^$action$/, @
{$allowed_options{$opt}})) {
480 die_error
(400, "Invalid option parameter for this action");
485 our $hash_parent_base = $cgi->param('hpb');
486 if (defined $hash_parent_base) {
487 if (!validate_refname
($hash_parent_base)) {
488 die_error
(400, "Invalid hash parent base parameter");
493 our $page = $cgi->param('pg');
495 if ($page =~ m/[^0-9]/) {
496 die_error
(400, "Invalid page parameter");
500 our $searchtype = $cgi->param('st');
501 if (defined $searchtype) {
502 if ($searchtype =~ m/[^a-z]/) {
503 die_error
(400, "Invalid searchtype parameter");
507 our $search_use_regexp = $cgi->param('sr');
509 our $searchtext = $cgi->param('s');
511 if (defined $searchtext) {
512 if (length($searchtext) < 2) {
513 die_error
(403, "At least two characters are required for search parameter");
515 $search_regexp = $search_use_regexp ?
$searchtext : quotemeta $searchtext;
518 # now read PATH_INFO and use it as alternative to parameters
519 sub evaluate_path_info
{
520 return if defined $project;
521 my $path_info = $ENV{"PATH_INFO"};
522 return if !$path_info;
523 $path_info =~ s
,^/+,,;
524 return if !$path_info;
525 # find which part of PATH_INFO is project
526 $project = $path_info;
528 while ($project && !check_head_link
("$projectroot/$project")) {
529 $project =~ s
,/*[^/]*$,,;
532 $project = validate_pathname
($project);
534 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
535 ($strict_export && !project_in_list
($project))) {
539 # do not change any parameters if an action is given using the query string
541 $path_info =~ s
,^\Q
$project\E
/*,,;
542 my ($refname, $pathname) = split(/:/, $path_info, 2);
543 if (defined $pathname) {
544 # we got "project.git/branch:filename" or "project.git/branch:dir/"
545 # we could use git_get_type(branch:pathname), but it needs $git_dir
546 $pathname =~ s
,^/+,,;
547 if (!$pathname || substr($pathname, -1) eq "/") {
551 $action ||= "blob_plain";
553 $hash_base ||= validate_refname
($refname);
554 $file_name ||= validate_pathname
($pathname);
555 } elsif (defined $refname) {
556 # we got "project.git/branch"
557 $action ||= "shortlog";
558 $hash ||= validate_refname
($refname);
561 evaluate_path_info
();
563 # path to the current git repository
565 $git_dir = "$projectroot/$project" if $project;
569 "blame" => \
&git_blame
,
570 "blobdiff" => \
&git_blobdiff
,
571 "blobdiff_plain" => \
&git_blobdiff_plain
,
572 "blob" => \
&git_blob
,
573 "blob_plain" => \
&git_blob_plain
,
574 "commitdiff" => \
&git_commitdiff
,
575 "commitdiff_plain" => \
&git_commitdiff_plain
,
576 "commit" => \
&git_commit
,
577 "forks" => \
&git_forks
,
578 "heads" => \
&git_heads
,
579 "history" => \
&git_history
,
582 "atom" => \
&git_atom
,
583 "search" => \
&git_search
,
584 "search_help" => \
&git_search_help
,
585 "shortlog" => \
&git_shortlog
,
586 "summary" => \
&git_summary
,
588 "tags" => \
&git_tags
,
589 "tree" => \
&git_tree
,
590 "snapshot" => \
&git_snapshot
,
591 "object" => \
&git_object
,
592 # those below don't need $project
593 "opml" => \
&git_opml
,
594 "project_list" => \
&git_project_list
,
595 "project_index" => \
&git_project_index
,
598 if (!defined $action) {
600 $action = git_get_type
($hash);
601 } elsif (defined $hash_base && defined $file_name) {
602 $action = git_get_type
("$hash_base:$file_name");
603 } elsif (defined $project) {
606 $action = 'project_list';
609 if (!defined($actions{$action})) {
610 die_error
(400, "Unknown action");
612 if ($action !~ m/^(opml|project_list|project_index)$/ &&
614 die_error
(400, "Project needed");
616 $actions{$action}->();
619 ## ======================================================================
624 # default is to use -absolute url() i.e. $my_uri
625 my $href = $params{-full
} ?
$my_url : $my_uri;
627 # XXX: Warning: If you touch this, check the search form for updating,
638 hash_parent_base
=> "hpb",
643 snapshot_format
=> "sf",
644 extra_options
=> "opt",
645 search_use_regexp
=> "sr",
647 my %mapping = @mapping;
649 $params{'project'} = $project unless exists $params{'project'};
651 if ($params{-replay
}) {
652 while (my ($name, $symbol) = each %mapping) {
653 if (!exists $params{$name}) {
654 # to allow for multivalued params we use arrayref form
655 $params{$name} = [ $cgi->param($symbol) ];
660 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
662 # use PATH_INFO for project name
663 $href .= "/".esc_url
($params{'project'}) if defined $params{'project'};
664 delete $params{'project'};
666 # Summary just uses the project path URL
667 if (defined $params{'action'} && $params{'action'} eq 'summary') {
668 delete $params{'action'};
672 # now encode the parameters explicitly
674 for (my $i = 0; $i < @mapping; $i += 2) {
675 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
676 if (defined $params{$name}) {
677 if (ref($params{$name}) eq "ARRAY") {
678 foreach my $par (@
{$params{$name}}) {
679 push @result, $symbol . "=" . esc_param
($par);
682 push @result, $symbol . "=" . esc_param
($params{$name});
686 $href .= "?" . join(';', @result) if scalar @result;
692 ## ======================================================================
693 ## validation, quoting/unquoting and escaping
695 sub validate_pathname
{
696 my $input = shift || return undef;
698 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
699 # at the beginning, at the end, and between slashes.
700 # also this catches doubled slashes
701 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
705 if ($input =~ m!\0!) {
711 sub validate_refname
{
712 my $input = shift || return undef;
714 # textual hashes are O.K.
715 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
718 # it must be correct pathname
719 $input = validate_pathname
($input)
721 # restrictions on ref name according to git-check-ref-format
722 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
728 # decode sequences of octets in utf8 into Perl's internal form,
729 # which is utf-8 with utf8 flag set if needed. gitweb writes out
730 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
733 if (utf8
::valid
($str)) {
737 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
741 # quote unsafe chars, but keep the slash, even when it's not
742 # correct, but quoted slashes look too horrible in bookmarks
745 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
751 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
754 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
760 # replace invalid utf8 character with SUBSTITUTION sequence
765 $str = to_utf8
($str);
766 $str = $cgi->escapeHTML($str);
767 if ($opts{'-nbsp'}) {
768 $str =~ s/ / /g;
770 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
774 # quote control characters and escape filename to HTML
779 $str = to_utf8
($str);
780 $str = $cgi->escapeHTML($str);
781 if ($opts{'-nbsp'}) {
782 $str =~ s/ / /g;
784 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
788 # Make control characters "printable", using character escape codes (CEC)
792 my %es = ( # character escape codes, aka escape sequences
793 "\t" => '\t', # tab (HT)
794 "\n" => '\n', # line feed (LF)
795 "\r" => '\r', # carrige return (CR)
796 "\f" => '\f', # form feed (FF)
797 "\b" => '\b', # backspace (BS)
798 "\a" => '\a', # alarm (bell) (BEL)
799 "\e" => '\e', # escape (ESC)
800 "\013" => '\v', # vertical tab (VT)
801 "\000" => '\0', # nul character (NUL)
803 my $chr = ( (exists $es{$cntrl})
805 : sprintf('\%2x', ord($cntrl)) );
806 if ($opts{-nohtml
}) {
809 return "<span class=\"cntrl\">$chr</span>";
813 # Alternatively use unicode control pictures codepoints,
814 # Unicode "printable representation" (PR)
819 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
820 if ($opts{-nohtml
}) {
823 return "<span class=\"cntrl\">$chr</span>";
827 # git may return quoted and escaped filenames
833 my %es = ( # character escape codes, aka escape sequences
834 't' => "\t", # tab (HT, TAB)
835 'n' => "\n", # newline (NL)
836 'r' => "\r", # return (CR)
837 'f' => "\f", # form feed (FF)
838 'b' => "\b", # backspace (BS)
839 'a' => "\a", # alarm (bell) (BEL)
840 'e' => "\e", # escape (ESC)
841 'v' => "\013", # vertical tab (VT)
844 if ($seq =~ m/^[0-7]{1,3}$/) {
845 # octal char sequence
846 return chr(oct($seq));
847 } elsif (exists $es{$seq}) {
848 # C escape sequence, aka character escape code
851 # quoted ordinary character
855 if ($str =~ m/^"(.*)"$/) {
858 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
863 # escape tabs (convert tabs to spaces)
867 while ((my $pos = index($line, "\t")) != -1) {
868 if (my $count = (8 - ($pos % 8))) {
869 my $spaces = ' ' x
$count;
870 $line =~ s/\t/$spaces/;
877 sub project_in_list
{
879 my @list = git_get_projects_list
();
880 return @list && scalar(grep { $_->{'path'} eq $project } @list);
883 ## ----------------------------------------------------------------------
884 ## HTML aware string manipulation
886 # Try to chop given string on a word boundary between position
887 # $len and $len+$add_len. If there is no word boundary there,
888 # chop at $len+$add_len. Do not chop if chopped part plus ellipsis
889 # (marking chopped part) would be longer than given string.
893 my $add_len = shift || 10;
894 my $where = shift || 'right'; # 'left' | 'center' | 'right'
896 # Make sure perl knows it is utf8 encoded so we don't
897 # cut in the middle of a utf8 multibyte char.
898 $str = to_utf8
($str);
900 # allow only $len chars, but don't cut a word if it would fit in $add_len
901 # if it doesn't fit, cut it if it's still longer than the dots we would add
902 # remove chopped character entities entirely
904 # when chopping in the middle, distribute $len into left and right part
905 # return early if chopping wouldn't make string shorter
906 if ($where eq 'center') {
907 return $str if ($len + 5 >= length($str)); # filler is length 5
910 return $str if ($len + 4 >= length($str)); # filler is length 4
913 # regexps: ending and beginning with word part up to $add_len
914 my $endre = qr/.{$len}\w{0,$add_len}/;
915 my $begre = qr/\w{0,$add_len}.{$len}/;
917 if ($where eq 'left') {
918 $str =~ m/^(.*?)($begre)$/;
919 my ($lead, $body) = ($1, $2);
920 if (length($lead) > 4) {
921 $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
926 } elsif ($where eq 'center') {
927 $str =~ m/^($endre)(.*)$/;
928 my ($left, $str) = ($1, $2);
929 $str =~ m/^(.*?)($begre)$/;
930 my ($mid, $right) = ($1, $2);
931 if (length($mid) > 5) {
932 $left =~ s/&[^;]*$//;
933 $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
936 return "$left$mid$right";
939 $str =~ m/^($endre)(.*)$/;
942 if (length($tail) > 4) {
943 $body =~ s/&[^;]*$//;
950 # takes the same arguments as chop_str, but also wraps a <span> around the
951 # result with a title attribute if it does get chopped. Additionally, the
952 # string is HTML-escaped.
953 sub chop_and_escape_str
{
956 my $chopped = chop_str
(@_);
957 if ($chopped eq $str) {
958 return esc_html
($chopped);
960 $str =~ s/([[:cntrl:]])/?/g;
961 return $cgi->span({-title
=>$str}, esc_html
($chopped));
965 ## ----------------------------------------------------------------------
966 ## functions returning short strings
968 # CSS class for given age value (in seconds)
974 } elsif ($age < 60*60*2) {
976 } elsif ($age < 60*60*24*2) {
983 # convert age in seconds to "nn units ago" string
988 if ($age > 60*60*24*365*2) {
989 $age_str = (int $age/60/60/24/365);
990 $age_str .= " years ago";
991 } elsif ($age > 60*60*24*(365/12)*2) {
992 $age_str = int $age/60/60/24/(365/12);
993 $age_str .= " months ago";
994 } elsif ($age > 60*60*24*7*2) {
995 $age_str = int $age/60/60/24/7;
996 $age_str .= " weeks ago";
997 } elsif ($age > 60*60*24*2) {
998 $age_str = int $age/60/60/24;
999 $age_str .= " days ago";
1000 } elsif ($age > 60*60*2) {
1001 $age_str = int $age/60/60;
1002 $age_str .= " hours ago";
1003 } elsif ($age > 60*2) {
1004 $age_str = int $age/60;
1005 $age_str .= " min ago";
1006 } elsif ($age > 2) {
1007 $age_str = int $age;
1008 $age_str .= " sec ago";
1010 $age_str .= " right now";
1016 S_IFINVALID
=> 0030000,
1017 S_IFGITLINK
=> 0160000,
1020 # submodule/subproject, a commit object reference
1021 sub S_ISGITLINK
($) {
1024 return (($mode & S_IFMT
) == S_IFGITLINK
)
1027 # convert file mode in octal to symbolic file mode string
1029 my $mode = oct shift;
1031 if (S_ISGITLINK
($mode)) {
1032 return 'm---------';
1033 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1034 return 'drwxr-xr-x';
1035 } elsif (S_ISLNK
($mode)) {
1036 return 'lrwxrwxrwx';
1037 } elsif (S_ISREG
($mode)) {
1038 # git cares only about the executable bit
1039 if ($mode & S_IXUSR
) {
1040 return '-rwxr-xr-x';
1042 return '-rw-r--r--';
1045 return '----------';
1049 # convert file mode in octal to file type string
1053 if ($mode !~ m/^[0-7]+$/) {
1059 if (S_ISGITLINK
($mode)) {
1061 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1063 } elsif (S_ISLNK
($mode)) {
1065 } elsif (S_ISREG
($mode)) {
1072 # convert file mode in octal to file type description string
1073 sub file_type_long
{
1076 if ($mode !~ m/^[0-7]+$/) {
1082 if (S_ISGITLINK
($mode)) {
1084 } elsif (S_ISDIR
($mode & S_IFMT
)) {
1086 } elsif (S_ISLNK
($mode)) {
1088 } elsif (S_ISREG
($mode)) {
1089 if ($mode & S_IXUSR
) {
1090 return "executable";
1100 ## ----------------------------------------------------------------------
1101 ## functions returning short HTML fragments, or transforming HTML fragments
1102 ## which don't belong to other sections
1104 # format line of commit message.
1105 sub format_log_line_html
{
1108 $line = esc_html
($line, -nbsp
=>1);
1109 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
1112 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
1113 -class => "text"}, $hash_text);
1114 $line =~ s/$hash_text/$link/;
1119 # format marker of refs pointing to given object
1121 # the destination action is chosen based on object type and current context:
1122 # - for annotated tags, we choose the tag view unless it's the current view
1123 # already, in which case we go to shortlog view
1124 # - for other refs, we keep the current view if we're in history, shortlog or
1125 # log view, and select shortlog otherwise
1126 sub format_ref_marker
{
1127 my ($refs, $id) = @_;
1130 if (defined $refs->{$id}) {
1131 foreach my $ref (@
{$refs->{$id}}) {
1132 # this code exploits the fact that non-lightweight tags are the
1133 # only indirect objects, and that they are the only objects for which
1134 # we want to use tag instead of shortlog as action
1135 my ($type, $name) = qw();
1136 my $indirect = ($ref =~ s/\^\{\}$//);
1137 # e.g. tags/v2.6.11 or heads/next
1138 if ($ref =~ m!^(.*?)s?/(.*)$!) {
1147 $class .= " indirect" if $indirect;
1149 my $dest_action = "shortlog";
1152 $dest_action = "tag" unless $action eq "tag";
1153 } elsif ($action =~ /^(history|(short)?log)$/) {
1154 $dest_action = $action;
1158 $dest .= "refs/" unless $ref =~ m
!^refs
/!;
1161 my $link = $cgi->a({
1163 action
=>$dest_action,
1167 $markers .= " <span class=\"$class\" title=\"$ref\">" .
1173 return ' <span class="refs">'. $markers . '</span>';
1179 # format, perhaps shortened and with markers, title line
1180 sub format_subject_html
{
1181 my ($long, $short, $href, $extra) = @_;
1182 $extra = '' unless defined($extra);
1184 if (length($short) < length($long)) {
1185 return $cgi->a({-href
=> $href, -class => "list subject",
1186 -title
=> to_utf8
($long)},
1187 esc_html
($short) . $extra);
1189 return $cgi->a({-href
=> $href, -class => "list subject"},
1190 esc_html
($long) . $extra);
1194 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
1195 sub format_git_diff_header_line
{
1197 my $diffinfo = shift;
1198 my ($from, $to) = @_;
1200 if ($diffinfo->{'nparents'}) {
1202 $line =~ s!^(diff (.*?) )"?.*$!$1!;
1203 if ($to->{'href'}) {
1204 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1205 esc_path
($to->{'file'}));
1206 } else { # file was deleted (no href)
1207 $line .= esc_path
($to->{'file'});
1211 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
1212 if ($from->{'href'}) {
1213 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
1214 'a/' . esc_path
($from->{'file'}));
1215 } else { # file was added (no href)
1216 $line .= 'a/' . esc_path
($from->{'file'});
1219 if ($to->{'href'}) {
1220 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
1221 'b/' . esc_path
($to->{'file'}));
1222 } else { # file was deleted
1223 $line .= 'b/' . esc_path
($to->{'file'});
1227 return "<div class=\"diff header\">$line</div>\n";
1230 # format extended diff header line, before patch itself
1231 sub format_extended_diff_header_line
{
1233 my $diffinfo = shift;
1234 my ($from, $to) = @_;
1237 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1238 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1239 esc_path
($from->{'file'}));
1241 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1242 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1243 esc_path
($to->{'file'}));
1245 # match single <mode>
1246 if ($line =~ m/\s(\d{6})$/) {
1247 $line .= '<span class="info"> (' .
1248 file_type_long
($1) .
1252 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1253 # can match only for combined diff
1255 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1256 if ($from->{'href'}[$i]) {
1257 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1259 substr($diffinfo->{'from_id'}[$i],0,7));
1264 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1267 if ($to->{'href'}) {
1268 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1269 substr($diffinfo->{'to_id'},0,7));
1274 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1275 # can match only for ordinary diff
1276 my ($from_link, $to_link);
1277 if ($from->{'href'}) {
1278 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1279 substr($diffinfo->{'from_id'},0,7));
1281 $from_link = '0' x
7;
1283 if ($to->{'href'}) {
1284 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1285 substr($diffinfo->{'to_id'},0,7));
1289 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1290 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1293 return $line . "<br/>\n";
1296 # format from-file/to-file diff header
1297 sub format_diff_from_to_header
{
1298 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1303 #assert($line =~ m/^---/) if DEBUG;
1304 # no extra formatting for "^--- /dev/null"
1305 if (! $diffinfo->{'nparents'}) {
1306 # ordinary (single parent) diff
1307 if ($line =~ m!^--- "?a/!) {
1308 if ($from->{'href'}) {
1310 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1311 esc_path
($from->{'file'}));
1314 esc_path
($from->{'file'});
1317 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1320 # combined diff (merge commit)
1321 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1322 if ($from->{'href'}[$i]) {
1324 $cgi->a({-href
=>href
(action
=>"blobdiff",
1325 hash_parent
=>$diffinfo->{'from_id'}[$i],
1326 hash_parent_base
=>$parents[$i],
1327 file_parent
=>$from->{'file'}[$i],
1328 hash
=>$diffinfo->{'to_id'},
1330 file_name
=>$to->{'file'}),
1332 -title
=>"diff" . ($i+1)},
1335 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1336 esc_path
($from->{'file'}[$i]));
1338 $line = '--- /dev/null';
1340 $result .= qq!<div
class="diff from_file">$line</div
>\n!;
1345 #assert($line =~ m/^\+\+\+/) if DEBUG;
1346 # no extra formatting for "^+++ /dev/null"
1347 if ($line =~ m!^\+\+\+ "?b/!) {
1348 if ($to->{'href'}) {
1350 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1351 esc_path
($to->{'file'}));
1354 esc_path
($to->{'file'});
1357 $result .= qq!<div
class="diff to_file">$line</div
>\n!;
1362 # create note for patch simplified by combined diff
1363 sub format_diff_cc_simplified
{
1364 my ($diffinfo, @parents) = @_;
1367 $result .= "<div class=\"diff header\">" .
1369 if (!is_deleted
($diffinfo)) {
1370 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1372 hash
=>$diffinfo->{'to_id'},
1373 file_name
=>$diffinfo->{'to_file'}),
1375 esc_path
($diffinfo->{'to_file'}));
1377 $result .= esc_path
($diffinfo->{'to_file'});
1379 $result .= "</div>\n" . # class="diff header"
1380 "<div class=\"diff nodifferences\">" .
1382 "</div>\n"; # class="diff nodifferences"
1387 # format patch (diff) line (not to be used for diff headers)
1388 sub format_diff_line
{
1390 my ($from, $to) = @_;
1391 my $diff_class = "";
1395 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1397 my $prefix = substr($line, 0, scalar @
{$from->{'href'}});
1398 if ($line =~ m/^\@{3}/) {
1399 $diff_class = " chunk_header";
1400 } elsif ($line =~ m/^\\/) {
1401 $diff_class = " incomplete";
1402 } elsif ($prefix =~ tr/+/+/) {
1403 $diff_class = " add";
1404 } elsif ($prefix =~ tr/-/-/) {
1405 $diff_class = " rem";
1408 # assume ordinary diff
1409 my $char = substr($line, 0, 1);
1411 $diff_class = " add";
1412 } elsif ($char eq '-') {
1413 $diff_class = " rem";
1414 } elsif ($char eq '@') {
1415 $diff_class = " chunk_header";
1416 } elsif ($char eq "\\") {
1417 $diff_class = " incomplete";
1420 $line = untabify
($line);
1421 if ($from && $to && $line =~ m/^\@{2} /) {
1422 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1423 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1425 $from_lines = 0 unless defined $from_lines;
1426 $to_lines = 0 unless defined $to_lines;
1428 if ($from->{'href'}) {
1429 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1430 -class=>"list"}, $from_text);
1432 if ($to->{'href'}) {
1433 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1434 -class=>"list"}, $to_text);
1436 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1437 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1438 return "<div class=\"diff$diff_class\">$line</div>\n";
1439 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1440 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1441 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1443 @from_text = split(' ', $ranges);
1444 for (my $i = 0; $i < @from_text; ++$i) {
1445 ($from_start[$i], $from_nlines[$i]) =
1446 (split(',', substr($from_text[$i], 1)), 0);
1449 $to_text = pop @from_text;
1450 $to_start = pop @from_start;
1451 $to_nlines = pop @from_nlines;
1453 $line = "<span class=\"chunk_info\">$prefix ";
1454 for (my $i = 0; $i < @from_text; ++$i) {
1455 if ($from->{'href'}[$i]) {
1456 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1457 -class=>"list"}, $from_text[$i]);
1459 $line .= $from_text[$i];
1463 if ($to->{'href'}) {
1464 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1465 -class=>"list"}, $to_text);
1469 $line .= " $prefix</span>" .
1470 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1471 return "<div class=\"diff$diff_class\">$line</div>\n";
1473 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1476 # Generates undef or something like "_snapshot_" or "snapshot (_tbz2_ _zip_)",
1477 # linked. Pass the hash of the tree/commit to snapshot.
1478 sub format_snapshot_links
{
1480 my @snapshot_fmts = gitweb_check_feature
('snapshot');
1481 @snapshot_fmts = filter_snapshot_fmts
(@snapshot_fmts);
1482 my $num_fmts = @snapshot_fmts;
1483 if ($num_fmts > 1) {
1484 # A parenthesized list of links bearing format names.
1485 # e.g. "snapshot (_tar.gz_ _zip_)"
1486 return "snapshot (" . join(' ', map
1493 }, $known_snapshot_formats{$_}{'display'})
1494 , @snapshot_fmts) . ")";
1495 } elsif ($num_fmts == 1) {
1496 # A single "snapshot" link whose tooltip bears the format name.
1498 my ($fmt) = @snapshot_fmts;
1504 snapshot_format
=>$fmt
1506 -title
=> "in format: $known_snapshot_formats{$fmt}{'display'}"
1508 } else { # $num_fmts == 0
1513 ## ......................................................................
1514 ## functions returning values to be passed, perhaps after some
1515 ## transformation, to other functions; e.g. returning arguments to href()
1517 # returns hash to be passed to href to generate gitweb URL
1518 # in -title key it returns description of link
1520 my $format = shift || 'Atom';
1521 my %res = (action
=> lc($format));
1523 # feed links are possible only for project views
1524 return unless (defined $project);
1525 # some views should link to OPML, or to generic project feed,
1526 # or don't have specific feed yet (so they should use generic)
1527 return if ($action =~ /^(?:tags|heads|forks|tag|search)$/x);
1530 # branches refs uses 'refs/heads/' prefix (fullname) to differentiate
1531 # from tag links; this also makes possible to detect branch links
1532 if ((defined $hash_base && $hash_base =~ m!^refs/heads/(.*)$!) ||
1533 (defined $hash && $hash =~ m!^refs/heads/(.*)$!)) {
1536 # find log type for feed description (title)
1538 if (defined $file_name) {
1539 $type = "history of $file_name";
1540 $type .= "/" if ($action eq 'tree');
1541 $type .= " on '$branch'" if (defined $branch);
1543 $type = "log of $branch" if (defined $branch);
1546 $res{-title
} = $type;
1547 $res{'hash'} = (defined $branch ?
"refs/heads/$branch" : undef);
1548 $res{'file_name'} = $file_name;
1553 ## ----------------------------------------------------------------------
1554 ## git utility subroutines, invoking git commands
1556 # returns path to the core git executable and the --git-dir parameter as list
1558 return $GIT, '--git-dir='.$git_dir;
1561 # quote the given arguments for passing them to the shell
1562 # quote_command("command", "arg 1", "arg with ' and ! characters")
1563 # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
1564 # Try to avoid using this function wherever possible.
1567 map( { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ ));
1570 # get HEAD ref of given project as hash
1571 sub git_get_head_hash
{
1572 my $project = shift;
1573 my $o_git_dir = $git_dir;
1575 $git_dir = "$projectroot/$project";
1576 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1579 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1583 if (defined $o_git_dir) {
1584 $git_dir = $o_git_dir;
1589 # get type of given object
1593 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1595 close $fd or return;
1600 # repository configuration
1601 our $config_file = '';
1604 # store multiple values for single key as anonymous array reference
1605 # single values stored directly in the hash, not as [ <value> ]
1606 sub hash_set_multi
{
1607 my ($hash, $key, $value) = @_;
1609 if (!exists $hash->{$key}) {
1610 $hash->{$key} = $value;
1611 } elsif (!ref $hash->{$key}) {
1612 $hash->{$key} = [ $hash->{$key}, $value ];
1614 push @
{$hash->{$key}}, $value;
1618 # return hash of git project configuration
1619 # optionally limited to some section, e.g. 'gitweb'
1620 sub git_parse_project_config
{
1621 my $section_regexp = shift;
1626 open my $fh, "-|", git_cmd
(), "config", '-z', '-l',
1629 while (my $keyval = <$fh>) {
1631 my ($key, $value) = split(/\n/, $keyval, 2);
1633 hash_set_multi
(\
%config, $key, $value)
1634 if (!defined $section_regexp || $key =~ /^(?:$section_regexp)\./o);
1641 # convert config value to boolean, 'true' or 'false'
1642 # no value, number > 0, 'true' and 'yes' values are true
1643 # rest of values are treated as false (never as error)
1644 sub config_to_bool
{
1647 # strip leading and trailing whitespace
1651 return (!defined $val || # section.key
1652 ($val =~ /^\d+$/ && $val) || # section.key = 1
1653 ($val =~ /^(?:true|yes)$/i)); # section.key = true
1656 # convert config value to simple decimal number
1657 # an optional value suffix of 'k', 'm', or 'g' will cause the value
1658 # to be multiplied by 1024, 1048576, or 1073741824
1662 # strip leading and trailing whitespace
1666 if (my ($num, $unit) = ($val =~ /^([0-9]*)([kmg])$/i)) {
1668 # unknown unit is treated as 1
1669 return $num * ($unit eq 'g' ?
1073741824 :
1670 $unit eq 'm' ?
1048576 :
1671 $unit eq 'k' ?
1024 : 1);
1676 # convert config value to array reference, if needed
1677 sub config_to_multi
{
1680 return ref($val) ?
$val : (defined($val) ?
[ $val ] : []);
1683 sub git_get_project_config
{
1684 my ($key, $type) = @_;
1687 return unless ($key);
1688 $key =~ s/^gitweb\.//;
1689 return if ($key =~ m/\W/);
1692 if (defined $type) {
1695 unless ($type eq 'bool' || $type eq 'int');
1699 if (!defined $config_file ||
1700 $config_file ne "$git_dir/config") {
1701 %config = git_parse_project_config
('gitweb');
1702 $config_file = "$git_dir/config";
1706 if (!defined $type) {
1707 return $config{"gitweb.$key"};
1708 } elsif ($type eq 'bool') {
1709 # backward compatibility: 'git config --bool' returns true/false
1710 return config_to_bool
($config{"gitweb.$key"}) ?
'true' : 'false';
1711 } elsif ($type eq 'int') {
1712 return config_to_int
($config{"gitweb.$key"});
1714 return $config{"gitweb.$key"};
1717 # get hash of given path at given ref
1718 sub git_get_hash_by_path
{
1720 my $path = shift || return undef;
1725 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1726 or die_error
(500, "Open git-ls-tree failed");
1728 close $fd or return undef;
1730 if (!defined $line) {
1731 # there is no tree or hash given by $path at $base
1735 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1736 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1737 if (defined $type && $type ne $2) {
1738 # type doesn't match
1744 # get path of entry with given hash at given tree-ish (ref)
1745 # used to get 'from' filename for combined diff (merge commit) for renames
1746 sub git_get_path_by_hash
{
1747 my $base = shift || return;
1748 my $hash = shift || return;
1752 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1754 while (my $line = <$fd>) {
1757 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1758 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1759 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1768 ## ......................................................................
1769 ## git utility functions, directly accessing git repository
1771 sub git_get_project_description
{
1774 $git_dir = "$projectroot/$path";
1775 open my $fd, "$git_dir/description"
1776 or return git_get_project_config
('description');
1779 if (defined $descr) {
1785 sub git_get_project_url_list
{
1788 $git_dir = "$projectroot/$path";
1789 open my $fd, "$git_dir/cloneurl"
1790 or return wantarray ?
1791 @
{ config_to_multi
(git_get_project_config
('url')) } :
1792 config_to_multi
(git_get_project_config
('url'));
1793 my @git_project_url_list = map { chomp; $_ } <$fd>;
1796 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
1799 sub git_get_projects_list
{
1804 $filter =~ s/\.git$//;
1806 my ($check_forks) = gitweb_check_feature
('forks');
1808 if (-d
$projects_list) {
1809 # search in directory
1810 my $dir = $projects_list . ($filter ?
"/$filter" : '');
1811 # remove the trailing "/"
1813 my $pfxlen = length("$dir");
1814 my $pfxdepth = ($dir =~ tr!/!!);
1817 follow_fast
=> 1, # follow symbolic links
1818 follow_skip
=> 2, # ignore duplicates
1819 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1821 # skip project-list toplevel, if we get it.
1822 return if (m!^[/.]$!);
1823 # only directories can be git repositories
1824 return unless (-d
$_);
1825 # don't traverse too deep (Find is super slow on os x)
1826 if (($File::Find
::name
=~ tr!/!!) - $pfxdepth > $project_maxdepth) {
1827 $File::Find
::prune
= 1;
1831 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1832 # we check related file in $projectroot
1833 if ($check_forks and $subdir =~ m
#/.#) {
1834 $File::Find
::prune
= 1;
1835 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1836 push @list, { path
=> ($filter ?
"$filter/" : '') . $subdir };
1837 $File::Find
::prune
= 1;
1842 } elsif (-f
$projects_list) {
1843 # read from file(url-encoded):
1844 # 'git%2Fgit.git Linus+Torvalds'
1845 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1846 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1848 open my ($fd), $projects_list or return;
1850 while (my $line = <$fd>) {
1852 my ($path, $owner) = split ' ', $line;
1853 $path = unescape
($path);
1854 $owner = unescape
($owner);
1855 if (!defined $path) {
1858 if ($filter ne '') {
1859 # looking for forks;
1860 my $pfx = substr($path, 0, length($filter));
1861 if ($pfx ne $filter) {
1864 my $sfx = substr($path, length($filter));
1865 if ($sfx !~ /^\/.*\
.git
$/) {
1868 } elsif ($check_forks) {
1870 foreach my $filter (keys %paths) {
1871 # looking for forks;
1872 my $pfx = substr($path, 0, length($filter));
1873 if ($pfx ne $filter) {
1876 my $sfx = substr($path, length($filter));
1877 if ($sfx !~ /^\/.*\
.git
$/) {
1880 # is a fork, don't include it in
1885 if (check_export_ok
("$projectroot/$path")) {
1888 owner
=> to_utf8
($owner),
1891 (my $forks_path = $path) =~ s/\.git$//;
1892 $paths{$forks_path}++;
1900 our $gitweb_project_owner = undef;
1901 sub git_get_project_list_from_file
{
1903 return if (defined $gitweb_project_owner);
1905 $gitweb_project_owner = {};
1906 # read from file (url-encoded):
1907 # 'git%2Fgit.git Linus+Torvalds'
1908 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1909 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1910 if (-f
$projects_list) {
1911 open (my $fd , $projects_list);
1912 while (my $line = <$fd>) {
1914 my ($pr, $ow) = split ' ', $line;
1915 $pr = unescape
($pr);
1916 $ow = unescape
($ow);
1917 $gitweb_project_owner->{$pr} = to_utf8
($ow);
1923 sub git_get_project_owner
{
1924 my $project = shift;
1927 return undef unless $project;
1928 $git_dir = "$projectroot/$project";
1930 if (!defined $gitweb_project_owner) {
1931 git_get_project_list_from_file
();
1934 if (exists $gitweb_project_owner->{$project}) {
1935 $owner = $gitweb_project_owner->{$project};
1937 if (!defined $owner){
1938 $owner = git_get_project_config
('owner');
1940 if (!defined $owner) {
1941 $owner = get_file_owner
("$git_dir");
1947 sub git_get_last_activity
{
1951 $git_dir = "$projectroot/$path";
1952 open($fd, "-|", git_cmd
(), 'for-each-ref',
1953 '--format=%(committer)',
1954 '--sort=-committerdate',
1956 'refs/heads') or return;
1957 my $most_recent = <$fd>;
1958 close $fd or return;
1959 if (defined $most_recent &&
1960 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1962 my $age = time - $timestamp;
1963 return ($age, age_string
($age));
1965 return (undef, undef);
1968 sub git_get_references
{
1969 my $type = shift || "";
1971 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1972 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1973 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1974 ($type ?
("--", "refs/$type") : ()) # use -- <pattern> if $type
1977 while (my $line = <$fd>) {
1979 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type.*)$!) {
1980 if (defined $refs{$1}) {
1981 push @
{$refs{$1}}, $2;
1987 close $fd or return;
1991 sub git_get_rev_name_tags
{
1992 my $hash = shift || return undef;
1994 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1996 my $name_rev = <$fd>;
1999 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
2002 # catches also '$hash undefined' output
2007 ## ----------------------------------------------------------------------
2008 ## parse to hash functions
2012 my $tz = shift || "-0000";
2015 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
2016 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
2017 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
2018 $date{'hour'} = $hour;
2019 $date{'minute'} = $min;
2020 $date{'mday'} = $mday;
2021 $date{'day'} = $days[$wday];
2022 $date{'month'} = $months[$mon];
2023 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
2024 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
2025 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
2026 $mday, $months[$mon], $hour ,$min;
2027 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
2028 1900+$year, 1+$mon, $mday, $hour ,$min, $sec;
2030 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
2031 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
2032 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
2033 $date{'hour_local'} = $hour;
2034 $date{'minute_local'} = $min;
2035 $date{'tz_local'} = $tz;
2036 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
2037 1900+$year, $mon+1, $mday,
2038 $hour, $min, $sec, $tz);
2047 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
2048 $tag{'id'} = $tag_id;
2049 while (my $line = <$fd>) {
2051 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
2052 $tag{'object'} = $1;
2053 } elsif ($line =~ m/^type (.+)$/) {
2055 } elsif ($line =~ m/^tag (.+)$/) {
2057 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
2058 $tag{'author'} = $1;
2061 } elsif ($line =~ m/--BEGIN/) {
2062 push @comment, $line;
2064 } elsif ($line eq "") {
2068 push @comment, <$fd>;
2069 $tag{'comment'} = \
@comment;
2070 close $fd or return;
2071 if (!defined $tag{'name'}) {
2077 sub parse_commit_text
{
2078 my ($commit_text, $withparents) = @_;
2079 my @commit_lines = split '\n', $commit_text;
2082 pop @commit_lines; # Remove '\0'
2084 if (! @commit_lines) {
2088 my $header = shift @commit_lines;
2089 if ($header !~ m/^[0-9a-fA-F]{40}/) {
2092 ($co{'id'}, my @parents) = split ' ', $header;
2093 while (my $line = shift @commit_lines) {
2094 last if $line eq "\n";
2095 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
2097 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
2099 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
2101 $co{'author_epoch'} = $2;
2102 $co{'author_tz'} = $3;
2103 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
2104 $co{'author_name'} = $1;
2105 $co{'author_email'} = $2;
2107 $co{'author_name'} = $co{'author'};
2109 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
2110 $co{'committer'} = $1;
2111 $co{'committer_epoch'} = $2;
2112 $co{'committer_tz'} = $3;
2113 $co{'committer_name'} = $co{'committer'};
2114 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
2115 $co{'committer_name'} = $1;
2116 $co{'committer_email'} = $2;
2118 $co{'committer_name'} = $co{'committer'};
2122 if (!defined $co{'tree'}) {
2125 $co{'parents'} = \
@parents;
2126 $co{'parent'} = $parents[0];
2128 foreach my $title (@commit_lines) {
2131 $co{'title'} = chop_str
($title, 80, 5);
2132 # remove leading stuff of merges to make the interesting part visible
2133 if (length($title) > 50) {
2134 $title =~ s/^Automatic //;
2135 $title =~ s/^merge (of|with) /Merge ... /i;
2136 if (length($title) > 50) {
2137 $title =~ s/(http|rsync):\/\///;
2139 if (length($title) > 50) {
2140 $title =~ s/(master|www|rsync)\.//;
2142 if (length($title) > 50) {
2143 $title =~ s/kernel.org:?//;
2145 if (length($title) > 50) {
2146 $title =~ s/\/pub\/scm//;
2149 $co{'title_short'} = chop_str
($title, 50, 5);
2153 if (! defined $co{'title'} || $co{'title'} eq "") {
2154 $co{'title'} = $co{'title_short'} = '(no commit message)';
2156 # remove added spaces
2157 foreach my $line (@commit_lines) {
2160 $co{'comment'} = \
@commit_lines;
2162 my $age = time - $co{'committer_epoch'};
2164 $co{'age_string'} = age_string
($age);
2165 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
2166 if ($age > 60*60*24*7*2) {
2167 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2168 $co{'age_string_age'} = $co{'age_string'};
2170 $co{'age_string_date'} = $co{'age_string'};
2171 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
2177 my ($commit_id) = @_;
2182 open my $fd, "-|", git_cmd
(), "rev-list",
2188 or die_error
(500, "Open git-rev-list failed");
2189 %co = parse_commit_text
(<$fd>, 1);
2196 my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
2204 open my $fd, "-|", git_cmd
(), "rev-list",
2207 ("--max-count=" . $maxcount),
2208 ("--skip=" . $skip),
2212 ($filename ?
($filename) : ())
2213 or die_error
(500, "Open git-rev-list failed");
2214 while (my $line = <$fd>) {
2215 my %co = parse_commit_text
($line);
2220 return wantarray ?
@cos : \
@cos;
2223 # parse line of git-diff-tree "raw" output
2224 sub parse_difftree_raw_line
{
2228 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2229 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2230 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2231 $res{'from_mode'} = $1;
2232 $res{'to_mode'} = $2;
2233 $res{'from_id'} = $3;
2235 $res{'status'} = $5;
2236 $res{'similarity'} = $6;
2237 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
2238 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
2240 $res{'from_file'} = $res{'to_file'} = $res{'file'} = unquote
($7);
2243 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
2244 # combined diff (for merge commit)
2245 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
2246 $res{'nparents'} = length($1);
2247 $res{'from_mode'} = [ split(' ', $2) ];
2248 $res{'to_mode'} = pop @
{$res{'from_mode'}};
2249 $res{'from_id'} = [ split(' ', $3) ];
2250 $res{'to_id'} = pop @
{$res{'from_id'}};
2251 $res{'status'} = [ split('', $4) ];
2252 $res{'to_file'} = unquote
($5);
2254 # 'c512b523472485aef4fff9e57b229d9d243c967f'
2255 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
2256 $res{'commit'} = $1;
2259 return wantarray ?
%res : \
%res;
2262 # wrapper: return parsed line of git-diff-tree "raw" output
2263 # (the argument might be raw line, or parsed info)
2264 sub parsed_difftree_line
{
2265 my $line_or_ref = shift;
2267 if (ref($line_or_ref) eq "HASH") {
2268 # pre-parsed (or generated by hand)
2269 return $line_or_ref;
2271 return parse_difftree_raw_line
($line_or_ref);
2275 # parse line of git-ls-tree output
2276 sub parse_ls_tree_line
($;%) {
2281 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2282 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2290 $res{'name'} = unquote
($4);
2293 return wantarray ?
%res : \
%res;
2296 # generates _two_ hashes, references to which are passed as 2 and 3 argument
2297 sub parse_from_to_diffinfo
{
2298 my ($diffinfo, $from, $to, @parents) = @_;
2300 if ($diffinfo->{'nparents'}) {
2302 $from->{'file'} = [];
2303 $from->{'href'} = [];
2304 fill_from_file_info
($diffinfo, @parents)
2305 unless exists $diffinfo->{'from_file'};
2306 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2307 $from->{'file'}[$i] =
2308 defined $diffinfo->{'from_file'}[$i] ?
2309 $diffinfo->{'from_file'}[$i] :
2310 $diffinfo->{'to_file'};
2311 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2312 $from->{'href'}[$i] = href
(action
=>"blob",
2313 hash_base
=>$parents[$i],
2314 hash
=>$diffinfo->{'from_id'}[$i],
2315 file_name
=>$from->{'file'}[$i]);
2317 $from->{'href'}[$i] = undef;
2321 # ordinary (not combined) diff
2322 $from->{'file'} = $diffinfo->{'from_file'};
2323 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2324 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2325 hash
=>$diffinfo->{'from_id'},
2326 file_name
=>$from->{'file'});
2328 delete $from->{'href'};
2332 $to->{'file'} = $diffinfo->{'to_file'};
2333 if (!is_deleted
($diffinfo)) { # file exists in result
2334 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2335 hash
=>$diffinfo->{'to_id'},
2336 file_name
=>$to->{'file'});
2338 delete $to->{'href'};
2342 ## ......................................................................
2343 ## parse to array of hashes functions
2345 sub git_get_heads_list
{
2349 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2350 ($limit ?
'--count='.($limit+1) : ()), '--sort=-committerdate',
2351 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
2354 while (my $line = <$fd>) {
2358 my ($refinfo, $committerinfo) = split(/\0/, $line);
2359 my ($hash, $name, $title) = split(' ', $refinfo, 3);
2360 my ($committer, $epoch, $tz) =
2361 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
2362 $ref_item{'fullname'} = $name;
2363 $name =~ s!^refs/heads/!!;
2365 $ref_item{'name'} = $name;
2366 $ref_item{'id'} = $hash;
2367 $ref_item{'title'} = $title || '(no commit message)';
2368 $ref_item{'epoch'} = $epoch;
2370 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2372 $ref_item{'age'} = "unknown";
2375 push @headslist, \
%ref_item;
2379 return wantarray ?
@headslist : \
@headslist;
2382 sub git_get_tags_list
{
2386 open my $fd, '-|', git_cmd
(), 'for-each-ref',
2387 ($limit ?
'--count='.($limit+1) : ()), '--sort=-creatordate',
2388 '--format=%(objectname) %(objecttype) %(refname) '.
2389 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
2392 while (my $line = <$fd>) {
2396 my ($refinfo, $creatorinfo) = split(/\0/, $line);
2397 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
2398 my ($creator, $epoch, $tz) =
2399 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
2400 $ref_item{'fullname'} = $name;
2401 $name =~ s!^refs/tags/!!;
2403 $ref_item{'type'} = $type;
2404 $ref_item{'id'} = $id;
2405 $ref_item{'name'} = $name;
2406 if ($type eq "tag") {
2407 $ref_item{'subject'} = $title;
2408 $ref_item{'reftype'} = $reftype;
2409 $ref_item{'refid'} = $refid;
2411 $ref_item{'reftype'} = $type;
2412 $ref_item{'refid'} = $id;
2415 if ($type eq "tag" || $type eq "commit") {
2416 $ref_item{'epoch'} = $epoch;
2418 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2420 $ref_item{'age'} = "unknown";
2424 push @tagslist, \
%ref_item;
2428 return wantarray ?
@tagslist : \
@tagslist;
2431 ## ----------------------------------------------------------------------
2432 ## filesystem-related functions
2434 sub get_file_owner
{
2437 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2438 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2439 if (!defined $gcos) {
2443 $owner =~ s/[,;].*$//;
2444 return to_utf8
($owner);
2447 ## ......................................................................
2448 ## mimetype related functions
2450 sub mimetype_guess_file
{
2451 my $filename = shift;
2452 my $mimemap = shift;
2453 -r
$mimemap or return undef;
2456 open(MIME
, $mimemap) or return undef;
2458 next if m/^#/; # skip comments
2459 my ($mime, $exts) = split(/\t+/);
2460 if (defined $exts) {
2461 my @exts = split(/\s+/, $exts);
2462 foreach my $ext (@exts) {
2463 $mimemap{$ext} = $mime;
2469 $filename =~ /\.([^.]*)$/;
2470 return $mimemap{$1};
2473 sub mimetype_guess
{
2474 my $filename = shift;
2476 $filename =~ /\./ or return undef;
2478 if ($mimetypes_file) {
2479 my $file = $mimetypes_file;
2480 if ($file !~ m!^/!) { # if it is relative path
2481 # it is relative to project
2482 $file = "$projectroot/$project/$file";
2484 $mime = mimetype_guess_file
($filename, $file);
2486 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2492 my $filename = shift;
2495 my $mime = mimetype_guess
($filename);
2496 $mime and return $mime;
2500 return $default_blob_plain_mimetype unless $fd;
2503 return 'text/plain';
2504 } elsif (! $filename) {
2505 return 'application/octet-stream';
2506 } elsif ($filename =~ m/\.png$/i) {
2508 } elsif ($filename =~ m/\.gif$/i) {
2510 } elsif ($filename =~ m/\.jpe?g$/i) {
2511 return 'image/jpeg';
2513 return 'application/octet-stream';
2517 sub blob_contenttype
{
2518 my ($fd, $file_name, $type) = @_;
2520 $type ||= blob_mimetype
($fd, $file_name);
2521 if ($type eq 'text/plain' && defined $default_text_plain_charset) {
2522 $type .= "; charset=$default_text_plain_charset";
2528 ## ======================================================================
2529 ## functions printing HTML: header, footer, error page
2531 sub git_header_html
{
2532 my $status = shift || "200 OK";
2533 my $expires = shift;
2535 my $title = "$site_name";
2536 if (defined $project) {
2537 $title .= " - " . to_utf8
($project);
2538 if (defined $action) {
2539 $title .= "/$action";
2540 if (defined $file_name) {
2541 $title .= " - " . esc_path
($file_name);
2542 if ($action eq "tree" && $file_name !~ m
|/$|) {
2549 # require explicit support from the UA if we are to send the page as
2550 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2551 # we have to do this because MSIE sometimes globs '*/*', pretending to
2552 # support xhtml+xml but choking when it gets what it asked for.
2553 if (defined $cgi->http('HTTP_ACCEPT') &&
2554 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2555 $cgi->Accept('application/xhtml+xml') != 0) {
2556 $content_type = 'application/xhtml+xml';
2558 $content_type = 'text/html';
2560 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2561 -status
=> $status, -expires
=> $expires);
2562 my $mod_perl_version = $ENV{'MOD_PERL'} ?
" $ENV{'MOD_PERL'}" : '';
2564 <?xml version="1.0" encoding="utf-8"?>
2565 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2566 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2567 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2568 <!-- git core binaries version $git_version -->
2570 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2571 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2572 <meta name="robots" content="index, nofollow"/>
2573 <title>$title</title>
2575 # print out each stylesheet that exist
2576 if (defined $stylesheet) {
2577 #provides backwards capability for those people who define style sheet in a config file
2578 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2580 foreach my $stylesheet (@stylesheets) {
2581 next unless $stylesheet;
2582 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2585 if (defined $project) {
2586 my %href_params = get_feed_info
();
2587 if (!exists $href_params{'-title'}) {
2588 $href_params{'-title'} = 'log';
2591 foreach my $format qw(RSS Atom) {
2592 my $type = lc($format);
2594 '-rel' => 'alternate',
2595 '-title' => "$project - $href_params{'-title'} - $format feed",
2596 '-type' => "application/$type+xml"
2599 $href_params{'action'} = $type;
2600 $link_attr{'-href'} = href
(%href_params);
2602 "rel=\"$link_attr{'-rel'}\" ".
2603 "title=\"$link_attr{'-title'}\" ".
2604 "href=\"$link_attr{'-href'}\" ".
2605 "type=\"$link_attr{'-type'}\" ".
2608 $href_params{'extra_options'} = '--no-merges';
2609 $link_attr{'-href'} = href
(%href_params);
2610 $link_attr{'-title'} .= ' (no merges)';
2612 "rel=\"$link_attr{'-rel'}\" ".
2613 "title=\"$link_attr{'-title'}\" ".
2614 "href=\"$link_attr{'-href'}\" ".
2615 "type=\"$link_attr{'-type'}\" ".
2620 printf('<link rel="alternate" title="%s projects list" '.
2621 'href="%s" type="text/plain; charset=utf-8" />'."\n",
2622 $site_name, href
(project
=>undef, action
=>"project_index"));
2623 printf('<link rel="alternate" title="%s projects feeds" '.
2624 'href="%s" type="text/x-opml" />'."\n",
2625 $site_name, href
(project
=>undef, action
=>"opml"));
2627 if (defined $favicon) {
2628 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png" />\n);
2634 if (-f
$site_header) {
2635 open (my $fd, $site_header);
2640 print "<div class=\"page_header\">\n" .
2641 $cgi->a({-href
=> esc_url
($logo_url),
2642 -title
=> $logo_label},
2643 qq(<img src
="$logo" width
="72" height
="27" alt
="git" class="logo"/>));
2644 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
2645 if (defined $project) {
2646 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
2647 if (defined $action) {
2654 my ($have_search) = gitweb_check_feature
('search');
2655 if (defined $project && $have_search) {
2656 if (!defined $searchtext) {
2660 if (defined $hash_base) {
2661 $search_hash = $hash_base;
2662 } elsif (defined $hash) {
2663 $search_hash = $hash;
2665 $search_hash = "HEAD";
2667 my $action = $my_uri;
2668 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
2669 if ($use_pathinfo) {
2670 $action .= "/".esc_url
($project);
2672 print $cgi->startform(-method
=> "get", -action
=> $action) .
2673 "<div class=\"search\">\n" .
2675 $cgi->input({-name
=>"p", -value
=>$project, -type
=>"hidden"}) . "\n") .
2676 $cgi->input({-name
=>"a", -value
=>"search", -type
=>"hidden"}) . "\n" .
2677 $cgi->input({-name
=>"h", -value
=>$search_hash, -type
=>"hidden"}) . "\n" .
2678 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
2679 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2680 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
2682 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
2683 "<span title=\"Extended regular expression\">" .
2684 $cgi->checkbox(-name
=> 'sr', -value
=> 1, -label
=> 're',
2685 -checked
=> $search_use_regexp) .
2688 $cgi->end_form() . "\n";
2692 sub git_footer_html
{
2693 my $feed_class = 'rss_logo';
2695 print "<div class=\"page_footer\">\n";
2696 if (defined $project) {
2697 my $descr = git_get_project_description
($project);
2698 if (defined $descr) {
2699 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
2702 my %href_params = get_feed_info
();
2703 if (!%href_params) {
2704 $feed_class .= ' generic';
2706 $href_params{'-title'} ||= 'log';
2708 foreach my $format qw(RSS Atom) {
2709 $href_params{'action'} = lc($format);
2710 print $cgi->a({-href
=> href
(%href_params),
2711 -title
=> "$href_params{'-title'} $format feed",
2712 -class => $feed_class}, $format)."\n";
2716 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
2717 -class => $feed_class}, "OPML") . " ";
2718 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
2719 -class => $feed_class}, "TXT") . "\n";
2721 print "</div>\n"; # class="page_footer"
2723 if (-f
$site_footer) {
2724 open (my $fd, $site_footer);
2733 # die_error(<http_status_code>, <error_message>)
2734 # Example: die_error(404, 'Hash not found')
2735 # By convention, use the following status codes (as defined in RFC 2616):
2736 # 400: Invalid or missing CGI parameters, or
2737 # requested object exists but has wrong type.
2738 # 403: Requested feature (like "pickaxe" or "snapshot") not enabled on
2739 # this server or project.
2740 # 404: Requested object/revision/project doesn't exist.
2741 # 500: The server isn't configured properly, or
2742 # an internal error occurred (e.g. failed assertions caused by bugs), or
2743 # an unknown error occurred (e.g. the git binary died unexpectedly).
2745 my $status = shift || 500;
2746 my $error = shift || "Internal server error";
2748 my %http_responses = (400 => '400 Bad Request',
2749 403 => '403 Forbidden',
2750 404 => '404 Not Found',
2751 500 => '500 Internal Server Error');
2752 git_header_html
($http_responses{$status});
2754 <div class="page_body">
2764 ## ----------------------------------------------------------------------
2765 ## functions printing or outputting HTML: navigation
2767 sub git_print_page_nav
{
2768 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2769 $extra = '' if !defined $extra; # pager or formats
2771 my @navs = qw(summary shortlog log commit commitdiff tree);
2773 @navs = grep { $_ ne $suppress } @navs;
2776 my %arg = map { $_ => {action
=>$_} } @navs;
2777 if (defined $head) {
2778 for (qw(commit commitdiff)) {
2779 $arg{$_}{'hash'} = $head;
2781 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2782 for (qw(shortlog log)) {
2783 $arg{$_}{'hash'} = $head;
2788 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2789 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2791 my @actions = gitweb_check_feature
('actions');
2793 my ($label, $link, $pos) = (shift(@actions), shift(@actions), shift(@actions));
2794 @navs = map { $_ eq $pos ?
($_, $label) : $_ } @navs;
2796 $link =~ s
#%n#$project#g;
2797 $link =~ s
#%f#$git_dir#g;
2798 $treehead ?
$link =~ s
#%h#$treehead#g : $link =~ s#%h##g;
2799 $treebase ?
$link =~ s
#%b#$treebase#g : $link =~ s#%b##g;
2800 $arg{$label}{'_href'} = $link;
2803 print "<div class=\"page_nav\">\n" .
2805 map { $_ eq $current ?
2806 $_ : $cgi->a({-href
=> ($arg{$_}{_href
} ?
$arg{$_}{_href
} : href
(%{$arg{$_}}))}, "$_")
2808 print "<br/>\n$extra<br/>\n" .
2812 sub format_paging_nav
{
2813 my ($action, $hash, $head, $page, $has_next_link) = @_;
2817 if ($hash ne $head || $page) {
2818 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2820 $paging_nav .= "HEAD";
2824 $paging_nav .= " ⋅ " .
2825 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
2826 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2828 $paging_nav .= " ⋅ prev";
2831 if ($has_next_link) {
2832 $paging_nav .= " ⋅ " .
2833 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
2834 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2836 $paging_nav .= " ⋅ next";
2842 ## ......................................................................
2843 ## functions printing or outputting HTML: div
2845 sub git_print_header_div
{
2846 my ($action, $title, $hash, $hash_base) = @_;
2849 $args{'action'} = $action;
2850 $args{'hash'} = $hash if $hash;
2851 $args{'hash_base'} = $hash_base if $hash_base;
2853 print "<div class=\"header\">\n" .
2854 $cgi->a({-href
=> href
(%args), -class => "title"},
2855 $title ?
$title : $action) .
2859 #sub git_print_authorship (\%) {
2860 sub git_print_authorship
{
2863 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2864 print "<div class=\"author_date\">" .
2865 esc_html
($co->{'author_name'}) .
2867 if ($ad{'hour_local'} < 6) {
2868 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2869 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2871 printf(" (%02d:%02d %s)",
2872 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2877 sub git_print_page_path
{
2883 print "<div class=\"page_path\">";
2884 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2885 -title
=> 'tree root'}, to_utf8
("[$project]"));
2887 if (defined $name) {
2888 my @dirname = split '/', $name;
2889 my $basename = pop @dirname;
2892 foreach my $dir (@dirname) {
2893 $fullname .= ($fullname ?
'/' : '') . $dir;
2894 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2896 -title
=> $fullname}, esc_path
($dir));
2899 if (defined $type && $type eq 'blob') {
2900 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2902 -title
=> $name}, esc_path
($basename));
2903 } elsif (defined $type && $type eq 'tree') {
2904 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2906 -title
=> $name}, esc_path
($basename));
2909 print esc_path
($basename);
2912 print "<br/></div>\n";
2915 # sub git_print_log (\@;%) {
2916 sub git_print_log
($;%) {
2920 if ($opts{'-remove_title'}) {
2921 # remove title, i.e. first line of log
2924 # remove leading empty lines
2925 while (defined $log->[0] && $log->[0] eq "") {
2932 foreach my $line (@
$log) {
2933 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2936 if (! $opts{'-remove_signoff'}) {
2937 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2940 # remove signoff lines
2947 # print only one empty line
2948 # do not print empty line after signoff
2950 next if ($empty || $signoff);
2956 print format_log_line_html
($line) . "<br/>\n";
2959 if ($opts{'-final_empty_line'}) {
2960 # end with single empty line
2961 print "<br/>\n" unless $empty;
2965 # return link target (what link points to)
2966 sub git_get_link_target
{
2971 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2975 $link_target = <$fd>;
2980 return $link_target;
2983 # given link target, and the directory (basedir) the link is in,
2984 # return target of link relative to top directory (top tree);
2985 # return undef if it is not possible (including absolute links).
2986 sub normalize_link_target
{
2987 my ($link_target, $basedir, $hash_base) = @_;
2989 # we can normalize symlink target only if $hash_base is provided
2990 return unless $hash_base;
2992 # absolute symlinks (beginning with '/') cannot be normalized
2993 return if (substr($link_target, 0, 1) eq '/');
2995 # normalize link target to path from top (root) tree (dir)
2998 $path = $basedir . '/' . $link_target;
3000 # we are in top (root) tree (dir)
3001 $path = $link_target;
3004 # remove //, /./, and /../
3006 foreach my $part (split('/', $path)) {
3007 # discard '.' and ''
3008 next if (!$part || $part eq '.');
3010 if ($part eq '..') {
3014 # link leads outside repository (outside top dir)
3018 push @path_parts, $part;
3021 $path = join('/', @path_parts);
3026 # print tree entry (row of git_tree), but without encompassing <tr> element
3027 sub git_print_tree_entry
{
3028 my ($t, $basedir, $hash_base, $have_blame) = @_;
3031 $base_key{'hash_base'} = $hash_base if defined $hash_base;
3033 # The format of a table row is: mode list link. Where mode is
3034 # the mode of the entry, list is the name of the entry, an href,
3035 # and link is the action links of the entry.
3037 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
3038 if ($t->{'type'} eq "blob") {
3039 print "<td class=\"list\">" .
3040 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3041 file_name
=>"$basedir$t->{'name'}", %base_key),
3042 -class => "list"}, esc_path
($t->{'name'}));
3043 if (S_ISLNK
(oct $t->{'mode'})) {
3044 my $link_target = git_get_link_target
($t->{'hash'});
3046 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
3047 if (defined $norm_target) {
3049 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
3050 file_name
=>$norm_target),
3051 -title
=> $norm_target}, esc_path
($link_target));
3053 print " -> " . esc_path
($link_target);
3058 print "<td class=\"link\">";
3059 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
3060 file_name
=>"$basedir$t->{'name'}", %base_key)},
3064 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
3065 file_name
=>"$basedir$t->{'name'}", %base_key)},
3068 if (defined $hash_base) {
3070 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3071 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
3075 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
3076 file_name
=>"$basedir$t->{'name'}")},
3080 } elsif ($t->{'type'} eq "tree") {
3081 print "<td class=\"list\">";
3082 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3083 file_name
=>"$basedir$t->{'name'}", %base_key)},
3084 esc_path
($t->{'name'}));
3086 print "<td class=\"link\">";
3087 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
3088 file_name
=>"$basedir$t->{'name'}", %base_key)},
3090 if (defined $hash_base) {
3092 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3093 file_name
=>"$basedir$t->{'name'}")},
3098 # unknown object: we can only present history for it
3099 # (this includes 'commit' object, i.e. submodule support)
3100 print "<td class=\"list\">" .
3101 esc_path
($t->{'name'}) .
3103 print "<td class=\"link\">";
3104 if (defined $hash_base) {
3105 print $cgi->a({-href
=> href
(action
=>"history",
3106 hash_base
=>$hash_base,
3107 file_name
=>"$basedir$t->{'name'}")},
3114 ## ......................................................................
3115 ## functions printing large fragments of HTML
3117 # get pre-image filenames for merge (combined) diff
3118 sub fill_from_file_info
{
3119 my ($diff, @parents) = @_;
3121 $diff->{'from_file'} = [ ];
3122 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
3123 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3124 if ($diff->{'status'}[$i] eq 'R' ||
3125 $diff->{'status'}[$i] eq 'C') {
3126 $diff->{'from_file'}[$i] =
3127 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
3134 # is current raw difftree line of file deletion
3136 my $diffinfo = shift;
3138 return $diffinfo->{'to_id'} eq ('0' x
40);
3141 # does patch correspond to [previous] difftree raw line
3142 # $diffinfo - hashref of parsed raw diff format
3143 # $patchinfo - hashref of parsed patch diff format
3144 # (the same keys as in $diffinfo)
3145 sub is_patch_split
{
3146 my ($diffinfo, $patchinfo) = @_;
3148 return defined $diffinfo && defined $patchinfo
3149 && $diffinfo->{'to_file'} eq $patchinfo->{'to_file'};
3153 sub git_difftree_body
{
3154 my ($difftree, $hash, @parents) = @_;
3155 my ($parent) = $parents[0];
3156 my ($have_blame) = gitweb_check_feature
('blame');
3157 print "<div class=\"list_head\">\n";
3158 if ($#{$difftree} > 10) {
3159 print(($#{$difftree} + 1) . " files changed:\n");
3163 print "<table class=\"" .
3164 (@parents > 1 ?
"combined " : "") .
3167 # header only for combined diff in 'commitdiff' view
3168 my $has_header = @
$difftree && @parents > 1 && $action eq 'commitdiff';
3171 print "<thead><tr>\n" .
3172 "<th></th><th></th>\n"; # filename, patchN link
3173 for (my $i = 0; $i < @parents; $i++) {
3174 my $par = $parents[$i];
3176 $cgi->a({-href
=> href
(action
=>"commitdiff",
3177 hash
=>$hash, hash_parent
=>$par),
3178 -title
=> 'commitdiff to parent number ' .
3179 ($i+1) . ': ' . substr($par,0,7)},
3183 print "</tr></thead>\n<tbody>\n";
3188 foreach my $line (@
{$difftree}) {
3189 my $diff = parsed_difftree_line
($line);
3192 print "<tr class=\"dark\">\n";
3194 print "<tr class=\"light\">\n";
3198 if (exists $diff->{'nparents'}) { # combined diff
3200 fill_from_file_info
($diff, @parents)
3201 unless exists $diff->{'from_file'};
3203 if (!is_deleted
($diff)) {
3204 # file exists in the result (child) commit
3206 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3207 file_name
=>$diff->{'to_file'},
3209 -class => "list"}, esc_path
($diff->{'to_file'})) .
3213 esc_path
($diff->{'to_file'}) .
3217 if ($action eq 'commitdiff') {
3220 print "<td class=\"link\">" .
3221 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3226 my $has_history = 0;
3227 my $not_deleted = 0;
3228 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
3229 my $hash_parent = $parents[$i];
3230 my $from_hash = $diff->{'from_id'}[$i];
3231 my $from_path = $diff->{'from_file'}[$i];
3232 my $status = $diff->{'status'}[$i];
3234 $has_history ||= ($status ne 'A');
3235 $not_deleted ||= ($status ne 'D');
3237 if ($status eq 'A') {
3238 print "<td class=\"link\" align=\"right\"> | </td>\n";
3239 } elsif ($status eq 'D') {
3240 print "<td class=\"link\">" .
3241 $cgi->a({-href
=> href
(action
=>"blob",
3244 file_name
=>$from_path)},
3248 if ($diff->{'to_id'} eq $from_hash) {
3249 print "<td class=\"link nochange\">";
3251 print "<td class=\"link\">";
3253 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3254 hash
=>$diff->{'to_id'},
3255 hash_parent
=>$from_hash,
3257 hash_parent_base
=>$hash_parent,
3258 file_name
=>$diff->{'to_file'},
3259 file_parent
=>$from_path)},
3265 print "<td class=\"link\">";
3267 print $cgi->a({-href
=> href
(action
=>"blob",
3268 hash
=>$diff->{'to_id'},
3269 file_name
=>$diff->{'to_file'},
3272 print " | " if ($has_history);
3275 print $cgi->a({-href
=> href
(action
=>"history",
3276 file_name
=>$diff->{'to_file'},
3283 next; # instead of 'else' clause, to avoid extra indent
3285 # else ordinary diff
3287 my ($to_mode_oct, $to_mode_str, $to_file_type);
3288 my ($from_mode_oct, $from_mode_str, $from_file_type);
3289 if ($diff->{'to_mode'} ne ('0' x
6)) {
3290 $to_mode_oct = oct $diff->{'to_mode'};
3291 if (S_ISREG
($to_mode_oct)) { # only for regular file
3292 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
3294 $to_file_type = file_type
($diff->{'to_mode'});
3296 if ($diff->{'from_mode'} ne ('0' x
6)) {
3297 $from_mode_oct = oct $diff->{'from_mode'};
3298 if (S_ISREG
($to_mode_oct)) { # only for regular file
3299 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
3301 $from_file_type = file_type
($diff->{'from_mode'});
3304 if ($diff->{'status'} eq "A") { # created
3305 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
3306 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
3307 $mode_chng .= "]</span>";
3309 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3310 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3311 -class => "list"}, esc_path
($diff->{'file'}));
3313 print "<td>$mode_chng</td>\n";
3314 print "<td class=\"link\">";
3315 if ($action eq 'commitdiff') {
3318 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3321 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3322 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3326 } elsif ($diff->{'status'} eq "D") { # deleted
3327 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
3329 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3330 hash_base
=>$parent, file_name
=>$diff->{'file'}),
3331 -class => "list"}, esc_path
($diff->{'file'}));
3333 print "<td>$mode_chng</td>\n";
3334 print "<td class=\"link\">";
3335 if ($action eq 'commitdiff') {
3338 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
3341 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
3342 hash_base
=>$parent, file_name
=>$diff->{'file'})},
3345 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
3346 file_name
=>$diff->{'file'})},
3349 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
3350 file_name
=>$diff->{'file'})},
3354 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
3355 my $mode_chnge = "";
3356 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3357 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
3358 if ($from_file_type ne $to_file_type) {
3359 $mode_chnge .= " from $from_file_type to $to_file_type";
3361 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
3362 if ($from_mode_str && $to_mode_str) {
3363 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
3364 } elsif ($to_mode_str) {
3365 $mode_chnge .= " mode: $to_mode_str";
3368 $mode_chnge .= "]</span>\n";
3371 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3372 hash_base
=>$hash, file_name
=>$diff->{'file'}),
3373 -class => "list"}, esc_path
($diff->{'file'}));
3375 print "<td>$mode_chnge</td>\n";
3376 print "<td class=\"link\">";
3377 if ($action eq 'commitdiff') {
3380 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3382 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3383 # "commit" view and modified file (not onlu mode changed)
3384 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3385 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3386 hash_base
=>$hash, hash_parent_base
=>$parent,
3387 file_name
=>$diff->{'file'})},
3391 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3392 hash_base
=>$hash, file_name
=>$diff->{'file'})},
3395 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3396 file_name
=>$diff->{'file'})},
3399 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3400 file_name
=>$diff->{'file'})},
3404 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
3405 my %status_name = ('R' => 'moved', 'C' => 'copied');
3406 my $nstatus = $status_name{$diff->{'status'}};
3408 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
3409 # mode also for directories, so we cannot use $to_mode_str
3410 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
3413 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
3414 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
3415 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
3416 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
3417 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
3418 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
3419 -class => "list"}, esc_path
($diff->{'from_file'})) .
3420 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
3421 "<td class=\"link\">";
3422 if ($action eq 'commitdiff') {
3425 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
3427 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
3428 # "commit" view and modified file (not only pure rename or copy)
3429 print $cgi->a({-href
=> href
(action
=>"blobdiff",
3430 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
3431 hash_base
=>$hash, hash_parent_base
=>$parent,
3432 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
3436 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
3437 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
3440 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
3441 file_name
=>$diff->{'to_file'})},
3444 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
3445 file_name
=>$diff->{'to_file'})},
3449 } # we should not encounter Unmerged (U) or Unknown (X) status
3452 print "</tbody>" if $has_header;
3456 sub git_patchset_body
{
3457 my ($fd, $difftree, $hash, @hash_parents) = @_;
3458 my ($hash_parent) = $hash_parents[0];
3460 my $is_combined = (@hash_parents > 1);
3462 my $patch_number = 0;
3468 print "<div class=\"patchset\">\n";
3470 # skip to first patch
3471 while ($patch_line = <$fd>) {
3474 last if ($patch_line =~ m/^diff /);
3478 while ($patch_line) {
3480 # parse "git diff" header line
3481 if ($patch_line =~ m/^diff --git (\"(?:[^\\\"]*(?:\\.[^\\\"]*)*)\"|[^ "]*) (.*)$/) {
3482 # $1 is from_name, which we do not use
3483 $to_name = unquote
($2);
3484 $to_name =~ s!^b/!!;
3485 } elsif ($patch_line =~ m/^diff --(cc|combined) ("?.*"?)$/) {
3486 # $1 is 'cc' or 'combined', which we do not use
3487 $to_name = unquote
($2);
3492 # check if current patch belong to current raw line
3493 # and parse raw git-diff line if needed
3494 if (is_patch_split
($diffinfo, { 'to_file' => $to_name })) {
3495 # this is continuation of a split patch
3496 print "<div class=\"patch cont\">\n";
3498 # advance raw git-diff output if needed
3499 $patch_idx++ if defined $diffinfo;
3501 # read and prepare patch information
3502 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3504 # compact combined diff output can have some patches skipped
3505 # find which patch (using pathname of result) we are at now;
3507 while ($to_name ne $diffinfo->{'to_file'}) {
3508 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3509 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3510 "</div>\n"; # class="patch"
3515 last if $patch_idx > $#$difftree;
3516 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3520 # modifies %from, %to hashes
3521 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
3523 # this is first patch for raw difftree line with $patch_idx index
3524 # we index @$difftree array from 0, but number patches from 1
3525 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3529 #assert($patch_line =~ m/^diff /) if DEBUG;
3530 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
3532 # print "git diff" header
3533 print format_git_diff_header_line
($patch_line, $diffinfo,
3536 # print extended diff header
3537 print "<div class=\"diff extended_header\">\n";
3539 while ($patch_line = <$fd>) {
3542 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
3544 print format_extended_diff_header_line
($patch_line, $diffinfo,
3547 print "</div>\n"; # class="diff extended_header"
3549 # from-file/to-file diff header
3550 if (! $patch_line) {
3551 print "</div>\n"; # class="patch"
3554 next PATCH
if ($patch_line =~ m/^diff /);
3555 #assert($patch_line =~ m/^---/) if DEBUG;
3557 my $last_patch_line = $patch_line;
3558 $patch_line = <$fd>;
3560 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3562 print format_diff_from_to_header
($last_patch_line, $patch_line,
3563 $diffinfo, \
%from, \
%to,
3568 while ($patch_line = <$fd>) {
3571 next PATCH
if ($patch_line =~ m/^diff /);
3573 print format_diff_line
($patch_line, \
%from, \
%to);
3577 print "</div>\n"; # class="patch"
3580 # for compact combined (--cc) format, with chunk and patch simpliciaction
3581 # patchset might be empty, but there might be unprocessed raw lines
3582 for (++$patch_idx if $patch_number > 0;
3583 $patch_idx < @
$difftree;
3585 # read and prepare patch information
3586 $diffinfo = parsed_difftree_line
($difftree->[$patch_idx]);
3588 # generate anchor for "patch" links in difftree / whatchanged part
3589 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3590 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3591 "</div>\n"; # class="patch"
3596 if ($patch_number == 0) {
3597 if (@hash_parents > 1) {
3598 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3600 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3604 print "</div>\n"; # class="patchset"
3607 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3609 # fills project list info (age, description, owner, forks) for each
3610 # project in the list, removing invalid projects from returned list
3611 # NOTE: modifies $projlist, but does not remove entries from it
3612 sub fill_project_list_info
{
3613 my ($projlist, $check_forks) = @_;
3617 foreach my $pr (@
$projlist) {
3618 my (@activity) = git_get_last_activity
($pr->{'path'});
3619 unless (@activity) {
3622 ($pr->{'age'}, $pr->{'age_string'}) = @activity;
3623 if (!defined $pr->{'descr'}) {
3624 my $descr = git_get_project_description
($pr->{'path'}) || "";
3625 $descr = to_utf8
($descr);
3626 $pr->{'descr_long'} = $descr;
3627 $pr->{'descr'} = chop_str
($descr, $projects_list_description_width, 5);
3629 if (!defined $pr->{'owner'}) {
3630 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
3633 my $pname = $pr->{'path'};
3634 if (($pname =~ s/\.git$//) &&
3635 ($pname !~ /\/$/) &&
3636 (-d
"$projectroot/$pname")) {
3637 $pr->{'forks'} = "-d $projectroot/$pname";
3642 push @projects, $pr;
3648 # print 'sort by' <th> element, generating 'sort by $name' replay link
3649 # if that order is not selected
3651 my ($name, $order, $header) = @_;
3652 $header ||= ucfirst($name);
3654 if ($order eq $name) {
3655 print "<th>$header</th>\n";
3658 $cgi->a({-href
=> href
(-replay
=>1, order
=>$name),
3659 -class => "header"}, $header) .
3664 sub git_project_list_body
{
3665 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3667 my ($check_forks) = gitweb_check_feature
('forks');
3668 my @projects = fill_project_list_info
($projlist, $check_forks);
3670 $order ||= $default_projects_order;
3671 $from = 0 unless defined $from;
3672 $to = $#projects if (!defined $to || $#projects < $to);
3675 project
=> { key
=> 'path', type
=> 'str' },
3676 descr
=> { key
=> 'descr_long', type
=> 'str' },
3677 owner
=> { key
=> 'owner', type
=> 'str' },
3678 age
=> { key
=> 'age', type
=> 'num' }
3680 my $oi = $order_info{$order};
3681 if ($oi->{'type'} eq 'str') {
3682 @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects;
3684 @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects;
3687 print "<table class=\"project_list\">\n";
3688 unless ($no_header) {
3691 print "<th></th>\n";
3693 print_sort_th
('project', $order, 'Project');
3694 print_sort_th
('descr', $order, 'Description');
3695 print_sort_th
('owner', $order, 'Owner');
3696 print_sort_th
('age', $order, 'Last Change');
3697 print "<th></th>\n" . # for links
3701 for (my $i = $from; $i <= $to; $i++) {
3702 my $pr = $projects[$i];
3704 print "<tr class=\"dark\">\n";
3706 print "<tr class=\"light\">\n";
3711 if ($pr->{'forks'}) {
3712 print "<!-- $pr->{'forks'} -->\n";
3713 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3717 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3718 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3719 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3720 -class => "list", -title
=> $pr->{'descr_long'}},
3721 esc_html
($pr->{'descr'})) . "</td>\n" .
3722 "<td><i>" . chop_and_escape_str
($pr->{'owner'}, 15) . "</i></td>\n";
3723 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3724 (defined $pr->{'age_string'} ?
$pr->{'age_string'} : "No commits") . "</td>\n" .
3725 "<td class=\"link\">" .
3726 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3727 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3728 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3729 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3730 ($pr->{'forks'} ?
" | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3734 if (defined $extra) {
3737 print "<td></td>\n";
3739 print "<td colspan=\"5\">$extra</td>\n" .
3745 sub git_shortlog_body
{
3746 # uses global variable $project
3747 my ($commitlist, $from, $to, $refs, $extra) = @_;
3749 $from = 0 unless defined $from;
3750 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3752 print "<table class=\"shortlog\">\n";
3754 for (my $i = $from; $i <= $to; $i++) {
3755 my %co = %{$commitlist->[$i]};
3756 my $commit = $co{'id'};
3757 my $ref = format_ref_marker
($refs, $commit);
3759 print "<tr class=\"dark\">\n";
3761 print "<tr class=\"light\">\n";
3764 my $author = chop_and_escape_str
($co{'author_name'}, 10);
3765 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3766 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3767 "<td><i>" . $author . "</i></td>\n" .
3769 print format_subject_html
($co{'title'}, $co{'title_short'},
3770 href
(action
=>"commit", hash
=>$commit), $ref);
3772 "<td class=\"link\">" .
3773 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3774 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3775 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3776 my $snapshot_links = format_snapshot_links
($commit);
3777 if (defined $snapshot_links) {
3778 print " | " . $snapshot_links;
3783 if (defined $extra) {
3785 "<td colspan=\"4\">$extra</td>\n" .
3791 sub git_history_body
{
3792 # Warning: assumes constant type (blob or tree) during history
3793 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3795 $from = 0 unless defined $from;
3796 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3798 print "<table class=\"history\">\n";
3800 for (my $i = $from; $i <= $to; $i++) {
3801 my %co = %{$commitlist->[$i]};
3805 my $commit = $co{'id'};
3807 my $ref = format_ref_marker
($refs, $commit);
3810 print "<tr class=\"dark\">\n";
3812 print "<tr class=\"light\">\n";
3815 # shortlog uses chop_str($co{'author_name'}, 10)
3816 my $author = chop_and_escape_str
($co{'author_name'}, 15, 3);
3817 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3818 "<td><i>" . $author . "</i></td>\n" .
3820 # originally git_history used chop_str($co{'title'}, 50)
3821 print format_subject_html
($co{'title'}, $co{'title_short'},
3822 href
(action
=>"commit", hash
=>$commit), $ref);
3824 "<td class=\"link\">" .
3825 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3826 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3828 if ($ftype eq 'blob') {
3829 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3830 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3831 if (defined $blob_current && defined $blob_parent &&
3832 $blob_current ne $blob_parent) {
3834 $cgi->a({-href
=> href
(action
=>"blobdiff",
3835 hash
=>$blob_current, hash_parent
=>$blob_parent,
3836 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3837 file_name
=>$file_name)},
3844 if (defined $extra) {
3846 "<td colspan=\"4\">$extra</td>\n" .
3853 # uses global variable $project
3854 my ($taglist, $from, $to, $extra) = @_;
3855 $from = 0 unless defined $from;
3856 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3858 print "<table class=\"tags\">\n";
3860 for (my $i = $from; $i <= $to; $i++) {
3861 my $entry = $taglist->[$i];
3863 my $comment = $tag{'subject'};
3865 if (defined $comment) {
3866 $comment_short = chop_str
($comment, 30, 5);
3869 print "<tr class=\"dark\">\n";
3871 print "<tr class=\"light\">\n";
3874 if (defined $tag{'age'}) {
3875 print "<td><i>$tag{'age'}</i></td>\n";
3877 print "<td></td>\n";
3880 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3881 -class => "list name"}, esc_html
($tag{'name'})) .
3884 if (defined $comment) {
3885 print format_subject_html
($comment, $comment_short,
3886 href
(action
=>"tag", hash
=>$tag{'id'}));
3889 "<td class=\"selflink\">";
3890 if ($tag{'type'} eq "tag") {
3891 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3896 "<td class=\"link\">" . " | " .
3897 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3898 if ($tag{'reftype'} eq "commit") {
3899 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'fullname'})}, "shortlog") .
3900 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'fullname'})}, "log");
3901 } elsif ($tag{'reftype'} eq "blob") {
3902 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3907 if (defined $extra) {
3909 "<td colspan=\"5\">$extra</td>\n" .
3915 sub git_heads_body
{
3916 # uses global variable $project
3917 my ($headlist, $head, $from, $to, $extra) = @_;
3918 $from = 0 unless defined $from;
3919 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3921 print "<table class=\"heads\">\n";
3923 for (my $i = $from; $i <= $to; $i++) {
3924 my $entry = $headlist->[$i];
3926 my $curr = $ref{'id'} eq $head;
3928 print "<tr class=\"dark\">\n";
3930 print "<tr class=\"light\">\n";
3933 print "<td><i>$ref{'age'}</i></td>\n" .
3934 ($curr ?
"<td class=\"current_head\">" : "<td>") .
3935 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'}),
3936 -class => "list name"},esc_html
($ref{'name'})) .
3938 "<td class=\"link\">" .
3939 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'fullname'})}, "shortlog") . " | " .
3940 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'fullname'})}, "log") . " | " .
3941 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'fullname'}, hash_base
=>$ref{'name'})}, "tree") .
3945 if (defined $extra) {
3947 "<td colspan=\"3\">$extra</td>\n" .
3953 sub git_search_grep_body
{
3954 my ($commitlist, $from, $to, $extra) = @_;
3955 $from = 0 unless defined $from;
3956 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3958 print "<table class=\"commit_search\">\n";
3960 for (my $i = $from; $i <= $to; $i++) {
3961 my %co = %{$commitlist->[$i]};
3965 my $commit = $co{'id'};
3967 print "<tr class=\"dark\">\n";
3969 print "<tr class=\"light\">\n";
3972 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
3973 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3974 "<td><i>" . $author . "</i></td>\n" .
3976 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3977 -class => "list subject"},
3978 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
3979 my $comment = $co{'comment'};
3980 foreach my $line (@
$comment) {
3981 if ($line =~ m/^(.*?)($search_regexp)(.*)$/i) {
3982 my ($lead, $match, $trail) = ($1, $2, $3);
3983 $match = chop_str
($match, 70, 5, 'center');
3984 my $contextlen = int((80 - length($match))/2);
3985 $contextlen = 30 if ($contextlen > 30);
3986 $lead = chop_str
($lead, $contextlen, 10, 'left');
3987 $trail = chop_str
($trail, $contextlen, 10, 'right');
3989 $lead = esc_html
($lead);
3990 $match = esc_html
($match);
3991 $trail = esc_html
($trail);
3993 print "$lead<span class=\"match\">$match</span>$trail<br />";
3997 "<td class=\"link\">" .
3998 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4000 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$co{'id'})}, "commitdiff") .
4002 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4006 if (defined $extra) {
4008 "<td colspan=\"3\">$extra</td>\n" .
4014 ## ======================================================================
4015 ## ======================================================================
4018 sub git_project_list
{
4019 my $order = $cgi->param('o');
4020 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4021 die_error
(400, "Unknown order parameter");
4024 my @list = git_get_projects_list
();
4026 die_error
(404, "No projects found");
4030 if (-f
$home_text) {
4031 print "<div class=\"index_include\">\n";
4032 open (my $fd, $home_text);
4037 git_project_list_body
(\
@list, $order);
4042 my $order = $cgi->param('o');
4043 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
4044 die_error
(400, "Unknown order parameter");
4047 my @list = git_get_projects_list
($project);
4049 die_error
(404, "No forks found");
4053 git_print_page_nav
('','');
4054 git_print_header_div
('summary', "$project forks");
4055 git_project_list_body
(\
@list, $order);
4059 sub git_project_index
{
4060 my @projects = git_get_projects_list
($project);
4063 -type
=> 'text/plain',
4064 -charset
=> 'utf-8',
4065 -content_disposition
=> 'inline; filename="index.aux"');
4067 foreach my $pr (@projects) {
4068 if (!exists $pr->{'owner'}) {
4069 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
4072 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
4073 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
4074 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4075 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
4079 print "$path $owner\n";
4084 my $descr = git_get_project_description
($project) || "none";
4085 my %co = parse_commit
("HEAD");
4086 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
4087 my $head = $co{'id'};
4089 my $owner = git_get_project_owner
($project);
4091 my $refs = git_get_references
();
4092 # These get_*_list functions return one more to allow us to see if
4093 # there are more ...
4094 my @taglist = git_get_tags_list
(16);
4095 my @headlist = git_get_heads_list
(16);
4097 my ($check_forks) = gitweb_check_feature
('forks');
4100 @forklist = git_get_projects_list
($project);
4104 git_print_page_nav
('summary','', $head);
4106 print "<div class=\"title\"> </div>\n";
4107 print "<table class=\"projects_list\">\n" .
4108 "<tr id=\"metadata_desc\"><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
4109 "<tr id=\"metadata_owner\"><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n";
4110 if (defined $cd{'rfc2822'}) {
4111 print "<tr id=\"metadata_lchange\"><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
4114 # use per project git URL list in $projectroot/$project/cloneurl
4115 # or make project git URL from git base URL and project name
4116 my $url_tag = "URL";
4117 my @url_list = git_get_project_url_list
($project);
4118 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
4119 foreach my $git_url (@url_list) {
4120 next unless $git_url;
4121 print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n";
4126 if (-s
"$projectroot/$project/README.html") {
4127 if (open my $fd, "$projectroot/$project/README.html") {
4128 print "<div class=\"title\">readme</div>\n" .
4129 "<div class=\"readme\">\n";
4130 print $_ while (<$fd>);
4131 print "\n</div>\n"; # class="readme"
4136 # we need to request one more than 16 (0..15) to check if
4138 my @commitlist = $head ? parse_commits
($head, 17) : ();
4140 git_print_header_div
('shortlog');
4141 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
4142 $#commitlist <= 15 ?
undef :
4143 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
4147 git_print_header_div
('tags');
4148 git_tags_body
(\
@taglist, 0, 15,
4149 $#taglist <= 15 ?
undef :
4150 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
4154 git_print_header_div
('heads');
4155 git_heads_body
(\
@headlist, $head, 0, 15,
4156 $#headlist <= 15 ?
undef :
4157 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
4161 git_print_header_div
('forks');
4162 git_project_list_body
(\
@forklist, 'age', 0, 15,
4163 $#forklist <= 15 ?
undef :
4164 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
4172 my $head = git_get_head_hash
($project);
4174 git_print_page_nav
('','', $head,undef,$head);
4175 my %tag = parse_tag
($hash);
4178 die_error
(404, "Unknown tag object");
4181 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
4182 print "<div class=\"title_text\">\n" .
4183 "<table class=\"object_header\">\n" .
4185 "<td>object</td>\n" .
4186 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4187 $tag{'object'}) . "</td>\n" .
4188 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
4189 $tag{'type'}) . "</td>\n" .
4191 if (defined($tag{'author'})) {
4192 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
4193 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
4194 print "<tr><td></td><td>" . $ad{'rfc2822'} .
4195 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
4198 print "</table>\n\n" .
4200 print "<div class=\"page_body\">";
4201 my $comment = $tag{'comment'};
4202 foreach my $line (@
$comment) {
4204 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
4214 gitweb_check_feature
('blame')
4215 or die_error
(403, "Blame view not allowed");
4217 die_error
(400, "No file name given") unless $file_name;
4218 $hash_base ||= git_get_head_hash
($project);
4219 die_error
(404, "Couldn't find base commit") unless ($hash_base);
4220 my %co = parse_commit
($hash_base)
4221 or die_error
(404, "Commit not found");
4222 if (!defined $hash) {
4223 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
4224 or die_error
(404, "Error looking up file");
4226 $ftype = git_get_type
($hash);
4227 if ($ftype !~ "blob") {
4228 die_error
(400, "Object is not a blob");
4230 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
4231 $file_name, $hash_base)
4232 or die_error
(500, "Open git-blame failed");
4235 $cgi->a({-href
=> href
(action
=>"blob", -replay
=>1)},
4238 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4241 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
4243 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4244 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4245 git_print_page_path
($file_name, $ftype, $hash_base);
4246 my @rev_color = (qw(light2 dark2));
4247 my $num_colors = scalar(@rev_color);
4248 my $current_color = 0;
4251 <div class="page_body">
4252 <table class="blame">
4253 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
4258 last unless defined $_;
4259 my ($full_rev, $orig_lineno, $lineno, $group_size) =
4260 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
4261 if (!exists $metainfo{$full_rev}) {
4262 $metainfo{$full_rev} = {};
4264 my $meta = $metainfo{$full_rev};
4267 if (/^(\S+) (.*)$/) {
4273 my $rev = substr($full_rev, 0, 8);
4274 my $author = $meta->{'author'};
4275 my %date = parse_date
($meta->{'author-time'},
4276 $meta->{'author-tz'});
4277 my $date = $date{'iso-tz'};
4279 $current_color = ++$current_color % $num_colors;
4281 print "<tr class=\"$rev_color[$current_color]\">\n";
4283 print "<td class=\"sha1\"";
4284 print " title=\"". esc_html
($author) . ", $date\"";
4285 print " rowspan=\"$group_size\"" if ($group_size > 1);
4287 print $cgi->a({-href
=> href
(action
=>"commit",
4289 file_name
=>$file_name)},
4293 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
4294 or die_error
(500, "Open git-rev-parse failed");
4295 my $parent_commit = <$dd>;
4297 chomp($parent_commit);
4298 my $blamed = href
(action
=> 'blame',
4299 file_name
=> $meta->{'filename'},
4300 hash_base
=> $parent_commit);
4301 print "<td class=\"linenr\">";
4302 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
4304 -class => "linenr" },
4307 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
4313 or print "Reading blob failed\n";
4318 my $head = git_get_head_hash
($project);
4320 git_print_page_nav
('','', $head,undef,$head);
4321 git_print_header_div
('summary', $project);
4323 my @tagslist = git_get_tags_list
();
4325 git_tags_body
(\
@tagslist);
4331 my $head = git_get_head_hash
($project);
4333 git_print_page_nav
('','', $head,undef,$head);
4334 git_print_header_div
('summary', $project);
4336 my @headslist = git_get_heads_list
();
4338 git_heads_body
(\
@headslist, $head);
4343 sub git_blob_plain
{
4347 if (!defined $hash) {
4348 if (defined $file_name) {
4349 my $base = $hash_base || git_get_head_hash
($project);
4350 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4351 or die_error
(404, "Cannot find file");
4353 die_error
(400, "No file name defined");
4355 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4356 # blobs defined by non-textual hash id's can be cached
4360 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4361 or die_error
(500, "Open git-cat-file blob '$hash' failed");
4363 # content-type (can include charset)
4364 $type = blob_contenttype
($fd, $file_name, $type);
4366 # "save as" filename, even when no $file_name is given
4367 my $save_as = "$hash";
4368 if (defined $file_name) {
4369 $save_as = $file_name;
4370 } elsif ($type =~ m/^text\//) {
4376 -expires
=> $expires,
4377 -content_disposition
=> 'inline; filename="' . $save_as . '"');
4379 binmode STDOUT
, ':raw';
4381 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4389 if (!defined $hash) {
4390 if (defined $file_name) {
4391 my $base = $hash_base || git_get_head_hash
($project);
4392 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4393 or die_error
(404, "Cannot find file");
4395 die_error
(400, "No file name defined");
4397 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4398 # blobs defined by non-textual hash id's can be cached
4402 my ($have_blame) = gitweb_check_feature
('blame');
4403 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4404 or die_error
(500, "Couldn't cat $file_name, $hash");
4405 my $mimetype = blob_mimetype
($fd, $file_name);
4406 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)! && -B
$fd) {
4408 return git_blob_plain
($mimetype);
4410 # we can have blame only for text/* mimetype
4411 $have_blame &&= ($mimetype =~ m!^text/!);
4413 git_header_html
(undef, $expires);
4414 my $formats_nav = '';
4415 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4416 if (defined $file_name) {
4419 $cgi->a({-href
=> href
(action
=>"blame", -replay
=>1)},
4424 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4427 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4430 $cgi->a({-href
=> href
(action
=>"blob",
4431 hash_base
=>"HEAD", file_name
=>$file_name)},
4435 $cgi->a({-href
=> href
(action
=>"blob_plain", -replay
=>1)},
4438 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4439 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4441 print "<div class=\"page_nav\">\n" .
4442 "<br/><br/></div>\n" .
4443 "<div class=\"title\">$hash</div>\n";
4445 git_print_page_path
($file_name, "blob", $hash_base);
4446 print "<div class=\"page_body\">\n";
4447 if ($mimetype =~ m!^image/!) {
4448 print qq!<img type
="$mimetype"!;
4450 print qq! alt
="$file_name" title
="$file_name"!;
4453 href(action=>"blob_plain
", hash=>$hash,
4454 hash_base=>$hash_base, file_name=>$file_name) .
4458 while (my $line = <$fd>) {
4461 $line = untabify
($line);
4462 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4463 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4467 or print "Reading blob failed.\n";
4473 if (!defined $hash_base) {
4474 $hash_base = "HEAD";
4476 if (!defined $hash) {
4477 if (defined $file_name) {
4478 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4483 die_error
(404, "No such tree") unless defined($hash);
4485 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4486 or die_error
(500, "Open git-ls-tree failed");
4487 my @entries = map { chomp; $_ } <$fd>;
4488 close $fd or die_error
(404, "Reading tree failed");
4491 my $refs = git_get_references
();
4492 my $ref = format_ref_marker
($refs, $hash_base);
4495 my ($have_blame) = gitweb_check_feature
('blame');
4496 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4498 if (defined $file_name) {
4500 $cgi->a({-href
=> href
(action
=>"history", -replay
=>1)},
4502 $cgi->a({-href
=> href
(action
=>"tree",
4503 hash_base
=>"HEAD", file_name
=>$file_name)},
4506 my $snapshot_links = format_snapshot_links
($hash);
4507 if (defined $snapshot_links) {
4508 # FIXME: Should be available when we have no hash base as well.
4509 push @views_nav, $snapshot_links;
4511 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4512 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4515 print "<div class=\"page_nav\">\n";
4516 print "<br/><br/></div>\n";
4517 print "<div class=\"title\">$hash</div>\n";
4519 if (defined $file_name) {
4520 $basedir = $file_name;
4521 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4524 git_print_page_path
($file_name, 'tree', $hash_base);
4526 print "<div class=\"page_body\">\n";
4527 print "<table class=\"tree\">\n";
4529 # '..' (top directory) link if possible
4530 if (defined $hash_base &&
4531 defined $file_name && $file_name =~ m![^/]+$!) {
4533 print "<tr class=\"dark\">\n";
4535 print "<tr class=\"light\">\n";
4539 my $up = $file_name;
4540 $up =~ s!/?[^/]+$!!;
4541 undef $up unless $up;
4542 # based on git_print_tree_entry
4543 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4544 print '<td class="list">';
4545 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4549 print "<td class=\"link\"></td>\n";
4553 foreach my $line (@entries) {
4554 my %t = parse_ls_tree_line
($line, -z
=> 1);
4557 print "<tr class=\"dark\">\n";
4559 print "<tr class=\"light\">\n";
4563 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4567 print "</table>\n" .
4573 my @supported_fmts = gitweb_check_feature
('snapshot');
4574 @supported_fmts = filter_snapshot_fmts
(@supported_fmts);
4576 my $format = $cgi->param('sf');
4577 if (!@supported_fmts) {
4578 die_error
(403, "Snapshots not allowed");
4580 # default to first supported snapshot format
4581 $format ||= $supported_fmts[0];
4582 if ($format !~ m/^[a-z0-9]+$/) {
4583 die_error
(400, "Invalid snapshot format parameter");
4584 } elsif (!exists($known_snapshot_formats{$format})) {
4585 die_error
(400, "Unknown snapshot format");
4586 } elsif (!grep($_ eq $format, @supported_fmts)) {
4587 die_error
(403, "Unsupported snapshot format");
4590 if (!defined $hash) {
4591 $hash = git_get_head_hash
($project);
4594 my $name = $project;
4595 $name =~ s
,([^/])/*\
.git
$,$1,;
4596 $name = basename
($name);
4597 my $filename = to_utf8
($name);
4598 $name =~ s/\047/\047\\\047\047/g;
4600 $filename .= "-$hash$known_snapshot_formats{$format}{'suffix'}";
4601 $cmd = quote_command
(
4602 git_cmd
(), 'archive',
4603 "--format=$known_snapshot_formats{$format}{'format'}",
4604 "--prefix=$name/", $hash);
4605 if (exists $known_snapshot_formats{$format}{'compressor'}) {
4606 $cmd .= ' | ' . quote_command
(@
{$known_snapshot_formats{$format}{'compressor'}});
4610 -type
=> $known_snapshot_formats{$format}{'type'},
4611 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4612 -status
=> '200 OK');
4614 open my $fd, "-|", $cmd
4615 or die_error
(500, "Execute git-archive failed");
4616 binmode STDOUT
, ':raw';
4618 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4623 my $head = git_get_head_hash
($project);
4624 if (!defined $hash) {
4627 if (!defined $page) {
4630 my $refs = git_get_references
();
4632 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4634 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#commitlist >= 100);
4637 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4640 my %co = parse_commit
($hash);
4642 git_print_header_div
('summary', $project);
4643 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4645 my $to = ($#commitlist >= 99) ?
(99) : ($#commitlist);
4646 for (my $i = 0; $i <= $to; $i++) {
4647 my %co = %{$commitlist[$i]};
4649 my $commit = $co{'id'};
4650 my $ref = format_ref_marker
($refs, $commit);
4651 my %ad = parse_date
($co{'author_epoch'});
4652 git_print_header_div
('commit',
4653 "<span class=\"age\">$co{'age_string'}</span>" .
4654 esc_html
($co{'title'}) . $ref,
4656 print "<div class=\"title_text\">\n" .
4657 "<div class=\"log_link\">\n" .
4658 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4660 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4662 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4665 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4668 print "<div class=\"log_body\">\n";
4669 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4672 if ($#commitlist >= 100) {
4673 print "<div class=\"page_nav\">\n";
4674 print $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
4675 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4682 $hash ||= $hash_base || "HEAD";
4683 my %co = parse_commit
($hash)
4684 or die_error
(404, "Unknown commit object");
4685 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4686 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4688 my $parent = $co{'parent'};
4689 my $parents = $co{'parents'}; # listref
4691 # we need to prepare $formats_nav before any parameter munging
4693 if (!defined $parent) {
4695 $formats_nav .= '(initial)';
4696 } elsif (@
$parents == 1) {
4697 # single parent commit
4700 $cgi->a({-href
=> href
(action
=>"commit",
4702 esc_html
(substr($parent, 0, 7))) .
4709 $cgi->a({-href
=> href
(action
=>"commit",
4711 esc_html
(substr($_, 0, 7)));
4716 if (!defined $parent) {
4720 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4722 (@
$parents <= 1 ?
$parent : '-c'),
4724 or die_error
(500, "Open git-diff-tree failed");
4725 @difftree = map { chomp; $_ } <$fd>;
4726 close $fd or die_error
(404, "Reading git-diff-tree failed");
4728 # non-textual hash id's can be cached
4730 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4733 my $refs = git_get_references
();
4734 my $ref = format_ref_marker
($refs, $co{'id'});
4736 git_header_html
(undef, $expires);
4737 git_print_page_nav
('commit', '',
4738 $hash, $co{'tree'}, $hash,
4741 if (defined $co{'parent'}) {
4742 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4744 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4746 print "<div class=\"title_text\">\n" .
4747 "<table class=\"object_header\">\n";
4748 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4750 "<td></td><td> $ad{'rfc2822'}";
4751 if ($ad{'hour_local'} < 6) {
4752 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4753 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4755 printf(" (%02d:%02d %s)",
4756 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4760 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4761 print "<tr><td></td><td> $cd{'rfc2822'}" .
4762 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4764 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4767 "<td class=\"sha1\">" .
4768 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4769 class => "list"}, $co{'tree'}) .
4771 "<td class=\"link\">" .
4772 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4774 my $snapshot_links = format_snapshot_links
($hash);
4775 if (defined $snapshot_links) {
4776 print " | " . $snapshot_links;
4781 foreach my $par (@
$parents) {
4784 "<td class=\"sha1\">" .
4785 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4786 class => "list"}, $par) .
4788 "<td class=\"link\">" .
4789 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4791 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4798 print "<div class=\"page_body\">\n";
4799 git_print_log
($co{'comment'});
4802 git_difftree_body
(\
@difftree, $hash, @
$parents);
4808 # object is defined by:
4809 # - hash or hash_base alone
4810 # - hash_base and file_name
4813 # - hash or hash_base alone
4814 if ($hash || ($hash_base && !defined $file_name)) {
4815 my $object_id = $hash || $hash_base;
4817 open my $fd, "-|", quote_command
(
4818 git_cmd
(), 'cat-file', '-t', $object_id) . ' 2> /dev/null'
4819 or die_error
(404, "Object does not exist");
4823 or die_error
(404, "Object does not exist");
4825 # - hash_base and file_name
4826 } elsif ($hash_base && defined $file_name) {
4827 $file_name =~ s
,/+$,,;
4829 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4830 or die_error
(404, "Base object does not exist");
4832 # here errors should not hapen
4833 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4834 or die_error
(500, "Open git-ls-tree failed");
4838 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4839 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4840 die_error
(404, "File or directory for given base does not exist");
4845 die_error
(400, "Not enough information to find object");
4848 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4849 hash
=>$hash, hash_base
=>$hash_base,
4850 file_name
=>$file_name),
4851 -status
=> '302 Found');
4855 my $format = shift || 'html';
4862 # preparing $fd and %diffinfo for git_patchset_body
4864 if (defined $hash_base && defined $hash_parent_base) {
4865 if (defined $file_name) {
4867 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4868 $hash_parent_base, $hash_base,
4869 "--", (defined $file_parent ?
$file_parent : ()), $file_name
4870 or die_error
(500, "Open git-diff-tree failed");
4871 @difftree = map { chomp; $_ } <$fd>;
4873 or die_error
(404, "Reading git-diff-tree failed");
4875 or die_error
(404, "Blob diff not found");
4877 } elsif (defined $hash &&
4878 $hash =~ /[0-9a-fA-F]{40}/) {
4879 # try to find filename from $hash
4881 # read filtered raw output
4882 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4883 $hash_parent_base, $hash_base, "--"
4884 or die_error
(500, "Open git-diff-tree failed");
4886 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4888 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4889 map { chomp; $_ } <$fd>;
4891 or die_error
(404, "Reading git-diff-tree failed");
4893 or die_error
(404, "Blob diff not found");
4896 die_error
(400, "Missing one of the blob diff parameters");
4899 if (@difftree > 1) {
4900 die_error
(400, "Ambiguous blob diff specification");
4903 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4904 $file_parent ||= $diffinfo{'from_file'} || $file_name;
4905 $file_name ||= $diffinfo{'to_file'};
4907 $hash_parent ||= $diffinfo{'from_id'};
4908 $hash ||= $diffinfo{'to_id'};
4910 # non-textual hash id's can be cached
4911 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4912 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4917 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4918 '-p', ($format eq 'html' ?
"--full-index" : ()),
4919 $hash_parent_base, $hash_base,
4920 "--", (defined $file_parent ?
$file_parent : ()), $file_name
4921 or die_error
(500, "Open git-diff-tree failed");
4924 # old/legacy style URI
4925 if (!%diffinfo && # if new style URI failed
4926 defined $hash && defined $hash_parent) {
4927 # fake git-diff-tree raw output
4928 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4929 $diffinfo{'from_id'} = $hash_parent;
4930 $diffinfo{'to_id'} = $hash;
4931 if (defined $file_name) {
4932 if (defined $file_parent) {
4933 $diffinfo{'status'} = '2';
4934 $diffinfo{'from_file'} = $file_parent;
4935 $diffinfo{'to_file'} = $file_name;
4936 } else { # assume not renamed
4937 $diffinfo{'status'} = '1';
4938 $diffinfo{'from_file'} = $file_name;
4939 $diffinfo{'to_file'} = $file_name;
4941 } else { # no filename given
4942 $diffinfo{'status'} = '2';
4943 $diffinfo{'from_file'} = $hash_parent;
4944 $diffinfo{'to_file'} = $hash;
4947 # non-textual hash id's can be cached
4948 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4949 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4954 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4955 '-p', ($format eq 'html' ?
"--full-index" : ()),
4956 $hash_parent, $hash, "--"
4957 or die_error
(500, "Open git-diff failed");
4959 die_error
(400, "Missing one of the blob diff parameters")
4964 if ($format eq 'html') {
4966 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", -replay
=>1)},
4968 git_header_html
(undef, $expires);
4969 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4970 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4971 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4973 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4974 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4976 if (defined $file_name) {
4977 git_print_page_path
($file_name, "blob", $hash_base);
4979 print "<div class=\"page_path\"></div>\n";
4982 } elsif ($format eq 'plain') {
4984 -type
=> 'text/plain',
4985 -charset
=> 'utf-8',
4986 -expires
=> $expires,
4987 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4989 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4992 die_error
(400, "Unknown blobdiff format");
4996 if ($format eq 'html') {
4997 print "<div class=\"page_body\">\n";
4999 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
5002 print "</div>\n"; # class="page_body"
5006 while (my $line = <$fd>) {
5007 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
5008 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
5012 last if $line =~ m!^\+\+\+!;
5020 sub git_blobdiff_plain
{
5021 git_blobdiff
('plain');
5024 sub git_commitdiff
{
5025 my $format = shift || 'html';
5026 $hash ||= $hash_base || "HEAD";
5027 my %co = parse_commit
($hash)
5028 or die_error
(404, "Unknown commit object");
5030 # choose format for commitdiff for merge
5031 if (! defined $hash_parent && @
{$co{'parents'}} > 1) {
5032 $hash_parent = '--cc';
5034 # we need to prepare $formats_nav before almost any parameter munging
5036 if ($format eq 'html') {
5038 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", -replay
=>1)},
5041 if (defined $hash_parent &&
5042 $hash_parent ne '-c' && $hash_parent ne '--cc') {
5043 # commitdiff with two commits given
5044 my $hash_parent_short = $hash_parent;
5045 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
5046 $hash_parent_short = substr($hash_parent, 0, 7);
5050 for (my $i = 0; $i < @
{$co{'parents'}}; $i++) {
5051 if ($co{'parents'}[$i] eq $hash_parent) {
5052 $formats_nav .= ' parent ' . ($i+1);
5056 $formats_nav .= ': ' .
5057 $cgi->a({-href
=> href
(action
=>"commitdiff",
5058 hash
=>$hash_parent)},
5059 esc_html
($hash_parent_short)) .
5061 } elsif (!$co{'parent'}) {
5063 $formats_nav .= ' (initial)';
5064 } elsif (scalar @
{$co{'parents'}} == 1) {
5065 # single parent commit
5068 $cgi->a({-href
=> href
(action
=>"commitdiff",
5069 hash
=>$co{'parent'})},
5070 esc_html
(substr($co{'parent'}, 0, 7))) .
5074 if ($hash_parent eq '--cc') {
5075 $formats_nav .= ' | ' .
5076 $cgi->a({-href
=> href
(action
=>"commitdiff",
5077 hash
=>$hash, hash_parent
=>'-c')},
5079 } else { # $hash_parent eq '-c'
5080 $formats_nav .= ' | ' .
5081 $cgi->a({-href
=> href
(action
=>"commitdiff",
5082 hash
=>$hash, hash_parent
=>'--cc')},
5088 $cgi->a({-href
=> href
(action
=>"commitdiff",
5090 esc_html
(substr($_, 0, 7)));
5091 } @
{$co{'parents'}} ) .
5096 my $hash_parent_param = $hash_parent;
5097 if (!defined $hash_parent_param) {
5098 # --cc for multiple parents, --root for parentless
5099 $hash_parent_param =
5100 @
{$co{'parents'}} > 1 ?
'--cc' : $co{'parent'} || '--root';
5106 if ($format eq 'html') {
5107 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5108 "--no-commit-id", "--patch-with-raw", "--full-index",
5109 $hash_parent_param, $hash, "--"
5110 or die_error
(500, "Open git-diff-tree failed");
5112 while (my $line = <$fd>) {
5114 # empty line ends raw part of diff-tree output
5116 push @difftree, scalar parse_difftree_raw_line
($line);
5119 } elsif ($format eq 'plain') {
5120 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5121 '-p', $hash_parent_param, $hash, "--"
5122 or die_error
(500, "Open git-diff-tree failed");
5125 die_error
(400, "Unknown commitdiff format");
5128 # non-textual hash id's can be cached
5130 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
5134 # write commit message
5135 if ($format eq 'html') {
5136 my $refs = git_get_references
();
5137 my $ref = format_ref_marker
($refs, $co{'id'});
5139 git_header_html
(undef, $expires);
5140 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
5141 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
5142 git_print_authorship
(\
%co);
5143 print "<div class=\"page_body\">\n";
5144 if (@
{$co{'comment'}} > 1) {
5145 print "<div class=\"log\">\n";
5146 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
5147 print "</div>\n"; # class="log"
5150 } elsif ($format eq 'plain') {
5151 my $refs = git_get_references
("tags");
5152 my $tagname = git_get_rev_name_tags
($hash);
5153 my $filename = basename
($project) . "-$hash.patch";
5156 -type
=> 'text/plain',
5157 -charset
=> 'utf-8',
5158 -expires
=> $expires,
5159 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
5160 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
5161 print "From: " . to_utf8
($co{'author'}) . "\n";
5162 print "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n";
5163 print "Subject: " . to_utf8
($co{'title'}) . "\n";
5165 print "X-Git-Tag: $tagname\n" if $tagname;
5166 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
5168 foreach my $line (@
{$co{'comment'}}) {
5169 print to_utf8
($line) . "\n";
5175 if ($format eq 'html') {
5176 my $use_parents = !defined $hash_parent ||
5177 $hash_parent eq '-c' || $hash_parent eq '--cc';
5178 git_difftree_body
(\
@difftree, $hash,
5179 $use_parents ? @
{$co{'parents'}} : $hash_parent);
5182 git_patchset_body
($fd, \
@difftree, $hash,
5183 $use_parents ? @
{$co{'parents'}} : $hash_parent);
5185 print "</div>\n"; # class="page_body"
5188 } elsif ($format eq 'plain') {
5192 or print "Reading git-diff-tree failed\n";
5196 sub git_commitdiff_plain
{
5197 git_commitdiff
('plain');
5201 if (!defined $hash_base) {
5202 $hash_base = git_get_head_hash
($project);
5204 if (!defined $page) {
5208 my %co = parse_commit
($hash_base)
5209 or die_error
(404, "Unknown commit object");
5211 my $refs = git_get_references
();
5212 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
5214 my @commitlist = parse_commits
($hash_base, 101, (100 * $page),
5215 $file_name, "--full-history")
5216 or die_error
(404, "No such file or directory on given branch");
5218 if (!defined $hash && defined $file_name) {
5219 # some commits could have deleted file in question,
5220 # and not have it in tree, but one of them has to have it
5221 for (my $i = 0; $i <= @commitlist; $i++) {
5222 $hash = git_get_hash_by_path
($commitlist[$i]{'id'}, $file_name);
5223 last if defined $hash;
5226 if (defined $hash) {
5227 $ftype = git_get_type
($hash);
5229 if (!defined $ftype) {
5230 die_error
(500, "Unknown type of object");
5233 my $paging_nav = '';
5236 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
5237 file_name
=>$file_name)},
5239 $paging_nav .= " ⋅ " .
5240 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5241 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5243 $paging_nav .= "first";
5244 $paging_nav .= " ⋅ prev";
5247 if ($#commitlist >= 100) {
5249 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5250 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5251 $paging_nav .= " ⋅ $next_link";
5253 $paging_nav .= " ⋅ next";
5257 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
5258 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
5259 git_print_page_path
($file_name, $ftype, $hash_base);
5261 git_history_body
(\
@commitlist, 0, 99,
5262 $refs, $hash_base, $ftype, $next_link);
5268 gitweb_check_feature
('search') or die_error
(403, "Search is disabled");
5269 if (!defined $searchtext) {
5270 die_error
(400, "Text field is empty");
5272 if (!defined $hash) {
5273 $hash = git_get_head_hash
($project);
5275 my %co = parse_commit
($hash);
5277 die_error
(404, "Unknown commit object");
5279 if (!defined $page) {
5283 $searchtype ||= 'commit';
5284 if ($searchtype eq 'pickaxe') {
5285 # pickaxe may take all resources of your box and run for several minutes
5286 # with every query - so decide by yourself how public you make this feature
5287 gitweb_check_feature
('pickaxe')
5288 or die_error
(403, "Pickaxe is disabled");
5290 if ($searchtype eq 'grep') {
5291 gitweb_check_feature
('grep')
5292 or die_error
(403, "Grep is disabled");
5297 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
5299 if ($searchtype eq 'commit') {
5300 $greptype = "--grep=";
5301 } elsif ($searchtype eq 'author') {
5302 $greptype = "--author=";
5303 } elsif ($searchtype eq 'committer') {
5304 $greptype = "--committer=";
5306 $greptype .= $searchtext;
5307 my @commitlist = parse_commits
($hash, 101, (100 * $page), undef,
5308 $greptype, '--regexp-ignore-case',
5309 $search_use_regexp ?
'--extended-regexp' : '--fixed-strings');
5311 my $paging_nav = '';
5314 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
5315 searchtext
=>$searchtext,
5316 searchtype
=>$searchtype)},
5318 $paging_nav .= " ⋅ " .
5319 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page-1),
5320 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
5322 $paging_nav .= "first";
5323 $paging_nav .= " ⋅ prev";
5326 if ($#commitlist >= 100) {
5328 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5329 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5330 $paging_nav .= " ⋅ $next_link";
5332 $paging_nav .= " ⋅ next";
5335 if ($#commitlist >= 100) {
5338 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
5339 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5340 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
5343 if ($searchtype eq 'pickaxe') {
5344 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5345 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5347 print "<table class=\"pickaxe search\">\n";
5350 open my $fd, '-|', git_cmd
(), '--no-pager', 'log', @diff_opts,
5351 '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext",
5352 ($search_use_regexp ?
'--pickaxe-regex' : ());
5355 while (my $line = <$fd>) {
5359 my %set = parse_difftree_raw_line
($line);
5360 if (defined $set{'commit'}) {
5361 # finish previous commit
5364 "<td class=\"link\">" .
5365 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5367 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5373 print "<tr class=\"dark\">\n";
5375 print "<tr class=\"light\">\n";
5378 %co = parse_commit
($set{'commit'});
5379 my $author = chop_and_escape_str
($co{'author_name'}, 15, 5);
5380 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5381 "<td><i>$author</i></td>\n" .
5383 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5384 -class => "list subject"},
5385 chop_and_escape_str
($co{'title'}, 50) . "<br/>");
5386 } elsif (defined $set{'to_id'}) {
5387 next if ($set{'to_id'} =~ m/^0{40}$/);
5389 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5390 hash
=>$set{'to_id'}, file_name
=>$set{'to_file'}),
5392 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5398 # finish last commit (warning: repetition!)
5401 "<td class=\"link\">" .
5402 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5404 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5412 if ($searchtype eq 'grep') {
5413 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5414 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5416 print "<table class=\"grep_search\">\n";
5420 open my $fd, "-|", git_cmd
(), 'grep', '-n',
5421 $search_use_regexp ?
('-E', '-i') : '-F',
5422 $searchtext, $co{'tree'};
5424 while (my $line = <$fd>) {
5426 my ($file, $lno, $ltext, $binary);
5427 last if ($matches++ > 1000);
5428 if ($line =~ /^Binary file (.+) matches$/) {
5432 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5434 if ($file ne $lastfile) {
5435 $lastfile and print "</td></tr>\n";
5437 print "<tr class=\"dark\">\n";
5439 print "<tr class=\"light\">\n";
5441 print "<td class=\"list\">".
5442 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5443 file_name
=>"$file"),
5444 -class => "list"}, esc_path
($file));
5445 print "</td><td>\n";
5449 print "<div class=\"binary\">Binary file</div>\n";
5451 $ltext = untabify
($ltext);
5452 if ($ltext =~ m/^(.*)($search_regexp)(.*)$/i) {
5453 $ltext = esc_html
($1, -nbsp
=>1);
5454 $ltext .= '<span class="match">';
5455 $ltext .= esc_html
($2, -nbsp
=>1);
5456 $ltext .= '</span>';
5457 $ltext .= esc_html
($3, -nbsp
=>1);
5459 $ltext = esc_html
($ltext, -nbsp
=>1);
5461 print "<div class=\"pre\">" .
5462 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5463 file_name
=>"$file").'#l'.$lno,
5464 -class => "linenr"}, sprintf('%4i', $lno))
5465 . ' ' . $ltext . "</div>\n";
5469 print "</td></tr>\n";
5470 if ($matches > 1000) {
5471 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5474 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5483 sub git_search_help
{
5485 git_print_page_nav
('','', $hash,$hash,$hash);
5487 <p><strong>Pattern</strong> is by default a normal string that is matched precisely (but without
5488 regard to case, except in the case of pickaxe). However, when you check the <em>re</em> checkbox,
5489 the pattern entered is recognized as the POSIX extended
5490 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a> (also case
5493 <dt><b>commit</b></dt>
5494 <dd>The commit messages and authorship information will be scanned for the given pattern.</dd>
5496 my ($have_grep) = gitweb_check_feature
('grep');
5499 <dt><b>grep</b></dt>
5500 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5501 a different one) are searched for the given pattern. On large trees, this search can take
5502 a while and put some strain on the server, so please use it with some consideration. Note that
5503 due to git-grep peculiarity, currently if regexp mode is turned off, the matches are
5504 case-sensitive.</dd>
5508 <dt><b>author</b></dt>
5509 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given pattern.</dd>
5510 <dt><b>committer</b></dt>
5511 <dd>Name and e-mail of the committer and date of commit will be scanned for the given pattern.</dd>
5513 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5514 if ($have_pickaxe) {
5516 <dt><b>pickaxe</b></dt>
5517 <dd>All commits that caused the string to appear or disappear from any file (changes that
5518 added, removed or "modified" the string) will be listed. This search can take a while and
5519 takes a lot of strain on the server, so please use it wisely. Note that since you may be
5520 interested even in changes just changing the case as well, this search is case sensitive.</dd>
5528 my $head = git_get_head_hash
($project);
5529 if (!defined $hash) {
5532 if (!defined $page) {
5535 my $refs = git_get_references
();
5537 my $commit_hash = $hash;
5538 if (defined $hash_parent) {
5539 $commit_hash = "$hash_parent..$hash";
5541 my @commitlist = parse_commits
($commit_hash, 101, (100 * $page));
5543 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#commitlist >= 100);
5545 if ($#commitlist >= 100) {
5547 $cgi->a({-href
=> href
(-replay
=>1, page
=>$page+1),
5548 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5552 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
5553 git_print_header_div
('summary', $project);
5555 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
5560 ## ......................................................................
5561 ## feeds (RSS, Atom; OPML)
5564 my $format = shift || 'atom';
5565 my ($have_blame) = gitweb_check_feature
('blame');
5567 # Atom: http://www.atomenabled.org/developers/syndication/
5568 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5569 if ($format ne 'rss' && $format ne 'atom') {
5570 die_error
(400, "Unknown web feed format");
5573 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5574 my $head = $hash || 'HEAD';
5575 my @commitlist = parse_commits
($head, 150, 0, $file_name);
5579 my $content_type = "application/$format+xml";
5580 if (defined $cgi->http('HTTP_ACCEPT') &&
5581 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5582 # browser (feed reader) prefers text/xml
5583 $content_type = 'text/xml';
5585 if (defined($commitlist[0])) {
5586 %latest_commit = %{$commitlist[0]};
5587 %latest_date = parse_date
($latest_commit{'author_epoch'});
5589 -type
=> $content_type,
5590 -charset
=> 'utf-8',
5591 -last_modified
=> $latest_date{'rfc2822'});
5594 -type
=> $content_type,
5595 -charset
=> 'utf-8');
5598 # Optimization: skip generating the body if client asks only
5599 # for Last-Modified date.
5600 return if ($cgi->request_method() eq 'HEAD');
5603 my $title = "$site_name - $project/$action";
5604 my $feed_type = 'log';
5605 if (defined $hash) {
5606 $title .= " - '$hash'";
5607 $feed_type = 'branch log';
5608 if (defined $file_name) {
5609 $title .= " :: $file_name";
5610 $feed_type = 'history';
5612 } elsif (defined $file_name) {
5613 $title .= " - $file_name";
5614 $feed_type = 'history';
5616 $title .= " $feed_type";
5617 my $descr = git_get_project_description
($project);
5618 if (defined $descr) {
5619 $descr = esc_html
($descr);
5621 $descr = "$project " .
5622 ($format eq 'rss' ?
'RSS' : 'Atom') .
5625 my $owner = git_get_project_owner
($project);
5626 $owner = esc_html
($owner);
5630 if (defined $file_name) {
5631 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
5632 } elsif (defined $hash) {
5633 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5635 $alt_url = href
(-full
=>1, action
=>"summary");
5637 print qq!<?xml version
="1.0" encoding
="utf-8"?
>\n!;
5638 if ($format eq 'rss') {
5640 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5643 print "<title>$title</title>\n" .
5644 "<link>$alt_url</link>\n" .
5645 "<description>$descr</description>\n" .
5646 "<language>en</language>\n";
5647 } elsif ($format eq 'atom') {
5649 <feed xmlns="http://www.w3.org/2005/Atom">
5651 print "<title>$title</title>\n" .
5652 "<subtitle>$descr</subtitle>\n" .
5653 '<link rel="alternate" type="text/html" href="' .
5654 $alt_url . '" />' . "\n" .
5655 '<link rel="self" type="' . $content_type . '" href="' .
5656 $cgi->self_url() . '" />' . "\n" .
5657 "<id>" . href
(-full
=>1) . "</id>\n" .
5658 # use project owner for feed author
5659 "<author><name>$owner</name></author>\n";
5660 if (defined $favicon) {
5661 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5663 if (defined $logo_url) {
5664 # not twice as wide as tall: 72 x 27 pixels
5665 print "<logo>" . esc_url
($logo) . "</logo>\n";
5667 if (! %latest_date) {
5668 # dummy date to keep the feed valid until commits trickle in:
5669 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5671 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5676 for (my $i = 0; $i <= $#commitlist; $i++) {
5677 my %co = %{$commitlist[$i]};
5678 my $commit = $co{'id'};
5679 # we read 150, we always show 30 and the ones more recent than 48 hours
5680 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5683 my %cd = parse_date
($co{'author_epoch'});
5685 # get list of changed files
5686 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5687 $co{'parent'} || "--root",
5688 $co{'id'}, "--", (defined $file_name ?
$file_name : ())
5690 my @difftree = map { chomp; $_ } <$fd>;
5694 # print element (entry, item)
5695 my $co_url = href
(-full
=>1, action
=>"commitdiff", hash
=>$commit);
5696 if ($format eq 'rss') {
5698 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
5699 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
5700 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5701 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5702 "<link>$co_url</link>\n" .
5703 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
5704 "<content:encoded>" .
5706 } elsif ($format eq 'atom') {
5708 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
5709 "<updated>$cd{'iso-8601'}</updated>\n" .
5711 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
5712 if ($co{'author_email'}) {
5713 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
5715 print "</author>\n" .
5716 # use committer for contributor
5718 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
5719 if ($co{'committer_email'}) {
5720 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
5722 print "</contributor>\n" .
5723 "<published>$cd{'iso-8601'}</published>\n" .
5724 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5725 "<id>$co_url</id>\n" .
5726 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
5727 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5729 my $comment = $co{'comment'};
5731 foreach my $line (@
$comment) {
5732 $line = esc_html
($line);
5735 print "</pre><ul>\n";
5736 foreach my $difftree_line (@difftree) {
5737 my %difftree = parse_difftree_raw_line
($difftree_line);
5738 next if !$difftree{'from_id'};
5740 my $file = $difftree{'file'} || $difftree{'to_file'};
5744 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
5745 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
5746 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
5747 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
5748 -title
=> "diff"}, 'D');
5750 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
5751 file_name
=>$file, hash_base
=>$commit),
5752 -title
=> "blame"}, 'B');
5754 # if this is not a feed of a file history
5755 if (!defined $file_name || $file_name ne $file) {
5756 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
5757 file_name
=>$file, hash
=>$commit),
5758 -title
=> "history"}, 'H');
5760 $file = esc_path
($file);
5764 if ($format eq 'rss') {
5765 print "</ul>]]>\n" .
5766 "</content:encoded>\n" .
5768 } elsif ($format eq 'atom') {
5769 print "</ul>\n</div>\n" .
5776 if ($format eq 'rss') {
5777 print "</channel>\n</rss>\n";
5778 } elsif ($format eq 'atom') {
5792 my @list = git_get_projects_list
();
5794 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5796 <?xml version="1.0" encoding="utf-8"?>
5797 <opml version="1.0">
5799 <title>$site_name OPML Export</title>
5802 <outline text="git RSS feeds">
5805 foreach my $pr (@list) {
5807 my $head = git_get_head_hash
($proj{'path'});
5808 if (!defined $head) {
5811 $git_dir = "$projectroot/$proj{'path'}";
5812 my %co = parse_commit
($head);
5817 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5818 my $rss = "$my_url?p=$proj{'path'};a=rss";
5819 my $html = "$my_url?p=$proj{'path'};a=summary";
5820 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";