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 # core git executable to use
31 # this can just be "git" if your webserver has a sensible PATH
32 our $GIT = "++GIT_BINDIR++/git";
34 # absolute fs-path which will be prepended to the project path
35 #our $projectroot = "/pub/scm";
36 our $projectroot = "++GITWEB_PROJECTROOT++";
38 # target of the home link on top of all pages
39 our $home_link = $my_uri || "/";
41 # string of the home link on top of all pages
42 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
44 # name of your site or organization to appear in page titles
45 # replace this with something more descriptive for clearer bookmarks
46 our $site_name = "++GITWEB_SITENAME++"
47 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
49 # filename of html text to include at top of each page
50 our $site_header = "++GITWEB_SITE_HEADER++";
51 # html text to include at home page
52 our $home_text = "++GITWEB_HOMETEXT++";
53 # filename of html text to include at bottom of each page
54 our $site_footer = "++GITWEB_SITE_FOOTER++";
57 our @stylesheets = ("++GITWEB_CSS++");
58 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
59 our $stylesheet = undef;
61 # URI of GIT logo (72x27 size)
62 our $logo = "++GITWEB_LOGO++";
63 # URI of GIT favicon, assumed to be image/png type
64 our $favicon = "++GITWEB_FAVICON++";
66 # URI and label (title) of GIT logo link
67 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
68 #our $logo_label = "git documentation";
69 our $logo_url = "http://git.or.cz/";
70 our $logo_label = "git homepage";
72 # source of projects list
73 our $projects_list = "++GITWEB_LIST++";
75 # default order of projects list
76 # valid values are none, project, descr, owner, and age
77 our $default_projects_order = "project";
79 # show repository only if this file exists
80 # (only effective if this variable evaluates to true)
81 our $export_ok = "++GITWEB_EXPORT_OK++";
83 # only allow viewing of repositories also shown on the overview page
84 our $strict_export = "++GITWEB_STRICT_EXPORT++";
86 # list of git base URLs used for URL to where fetch project from,
87 # i.e. full URL is "$git_base_url/$project"
88 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
90 # default blob_plain mimetype and default charset for text/plain blob
91 our $default_blob_plain_mimetype = 'text/plain';
92 our $default_text_plain_charset = undef;
94 # file to use for guessing MIME types before trying /etc/mime.types
95 # (relative to the current git repository)
96 our $mimetypes_file = undef;
98 # assume this charset if line contains non-UTF-8 characters;
99 # it should be valid encoding (see Encoding::Supported(3pm) for list),
100 # for which encoding all byte sequences are valid, for example
101 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
102 # could be even 'utf-8' for the old behavior)
103 our $fallback_encoding = 'latin1';
105 # You define site-wide feature defaults here; override them with
106 # $GITWEB_CONFIG as necessary.
109 # 'sub' => feature-sub (subroutine),
110 # 'override' => allow-override (boolean),
111 # 'default' => [ default options...] (array reference)}
113 # if feature is overridable (it means that allow-override has true value),
114 # then feature-sub will be called with default options as parameters;
115 # return value of feature-sub indicates if to enable specified feature
117 # if there is no 'sub' key (no feature-sub), then feature cannot be
120 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
122 # Enable the 'blame' blob view, showing the last commit that modified
123 # each line in the file. This can be very CPU-intensive.
125 # To enable system wide have in $GITWEB_CONFIG
126 # $feature{'blame'}{'default'} = [1];
127 # To have project specific config enable override in $GITWEB_CONFIG
128 # $feature{'blame'}{'override'} = 1;
129 # and in project config gitweb.blame = 0|1;
131 'sub' => \
&feature_blame
,
135 # Enable the 'snapshot' link, providing a compressed tarball of any
136 # tree. This can potentially generate high traffic if you have large
139 # To disable system wide have in $GITWEB_CONFIG
140 # $feature{'snapshot'}{'default'} = [undef];
141 # To have project specific config enable override in $GITWEB_CONFIG
142 # $feature{'snapshot'}{'override'} = 1;
143 # and in project config gitweb.snapshot = none|gzip|bzip2|zip;
145 'sub' => \
&feature_snapshot
,
147 # => [content-encoding, suffix, program]
148 'default' => ['x-gzip', 'gz', 'gzip']},
150 # Enable text search, which will list the commits which match author,
151 # committer or commit text to a given string. Enabled by default.
152 # Project specific override is not supported.
157 # Enable grep search, which will list the files in currently selected
158 # tree containing the given string. Enabled by default. This can be
159 # potentially CPU-intensive, of course.
161 # To enable system wide have in $GITWEB_CONFIG
162 # $feature{'grep'}{'default'} = [1];
163 # To have project specific config enable override in $GITWEB_CONFIG
164 # $feature{'grep'}{'override'} = 1;
165 # and in project config gitweb.grep = 0|1;
170 # Enable the pickaxe search, which will list the commits that modified
171 # a given string in a file. This can be practical and quite faster
172 # alternative to 'blame', but still potentially CPU-intensive.
174 # To enable system wide have in $GITWEB_CONFIG
175 # $feature{'pickaxe'}{'default'} = [1];
176 # To have project specific config enable override in $GITWEB_CONFIG
177 # $feature{'pickaxe'}{'override'} = 1;
178 # and in project config gitweb.pickaxe = 0|1;
180 'sub' => \
&feature_pickaxe
,
184 # Make gitweb use an alternative format of the URLs which can be
185 # more readable and natural-looking: project name is embedded
186 # directly in the path and the query string contains other
187 # auxiliary information. All gitweb installations recognize
188 # URL in either format; this configures in which formats gitweb
191 # To enable system wide have in $GITWEB_CONFIG
192 # $feature{'pathinfo'}{'default'} = [1];
193 # Project specific override is not supported.
195 # Note that you will need to change the default location of CSS,
196 # favicon, logo and possibly other files to an absolute URL. Also,
197 # if gitweb.cgi serves as your indexfile, you will need to force
198 # $my_uri to contain the script name in your $GITWEB_CONFIG.
203 # Make gitweb consider projects in project root subdirectories
204 # to be forks of existing projects. Given project $projname.git,
205 # projects matching $projname/*.git will not be shown in the main
206 # projects list, instead a '+' mark will be added to $projname
207 # there and a 'forks' view will be enabled for the project, listing
208 # all the forks. If project list is taken from a file, forks have
209 # to be listed after the main project.
211 # To enable system wide have in $GITWEB_CONFIG
212 # $feature{'forks'}{'default'} = [1];
213 # Project specific override is not supported.
219 sub gitweb_check_feature
{
221 return unless exists $feature{$name};
222 my ($sub, $override, @defaults) = (
223 $feature{$name}{'sub'},
224 $feature{$name}{'override'},
225 @{$feature{$name}{'default'}});
226 if (!$override) { return @defaults; }
228 warn "feature $name is not overrideable";
231 return $sub->(@defaults);
235 my ($val) = git_get_project_config
('blame', '--bool');
237 if ($val eq 'true') {
239 } elsif ($val eq 'false') {
246 sub feature_snapshot
{
247 my ($ctype, $suffix, $command) = @_;
249 my ($val) = git_get_project_config
('snapshot');
251 if ($val eq 'gzip') {
252 return ('x-gzip', 'gz', 'gzip');
253 } elsif ($val eq 'bzip2') {
254 return ('x-bzip2', 'bz2', 'bzip2');
255 } elsif ($val eq 'zip') {
256 return ('x-zip', 'zip', '');
257 } elsif ($val eq 'none') {
261 return ($ctype, $suffix, $command);
264 sub gitweb_have_snapshot
{
265 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
266 my $have_snapshot = (defined $ctype && defined $suffix);
268 return $have_snapshot;
272 my ($val) = git_get_project_config
('grep', '--bool');
274 if ($val eq 'true') {
276 } elsif ($val eq 'false') {
283 sub feature_pickaxe
{
284 my ($val) = git_get_project_config
('pickaxe', '--bool');
286 if ($val eq 'true') {
288 } elsif ($val eq 'false') {
295 # checking HEAD file with -e is fragile if the repository was
296 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
298 sub check_head_link
{
300 my $headfile = "$dir/HEAD";
301 return ((-e
$headfile) ||
302 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
305 sub check_export_ok
{
307 return (check_head_link
($dir) &&
308 (!$export_ok || -e
"$dir/$export_ok"));
311 # rename detection options for git-diff and git-diff-tree
312 # - default is '-M', with the cost proportional to
313 # (number of removed files) * (number of new files).
314 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
315 # (number of changed files + number of removed files) * (number of new files)
316 # - even more costly is '-C', '--find-copies-harder' with cost
317 # (number of files in the original tree) * (number of new files)
318 # - one might want to include '-B' option, e.g. '-B', '-M'
319 our @diff_opts = ('-M'); # taken from git_commit
321 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
322 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
324 # version of the core git binary
325 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
327 $projects_list ||= $projectroot;
329 # ======================================================================
330 # input validation and dispatch
331 our $action = $cgi->param('a');
332 if (defined $action) {
333 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
334 die_error
(undef, "Invalid action parameter");
338 # parameters which are pathnames
339 our $project = $cgi->param('p');
340 if (defined $project) {
341 if (!validate_pathname
($project) ||
342 !(-d
"$projectroot/$project") ||
343 !check_head_link
("$projectroot/$project") ||
344 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
345 ($strict_export && !project_in_list
($project))) {
347 die_error
(undef, "No such project");
351 our $file_name = $cgi->param('f');
352 if (defined $file_name) {
353 if (!validate_pathname
($file_name)) {
354 die_error
(undef, "Invalid file parameter");
358 our $file_parent = $cgi->param('fp');
359 if (defined $file_parent) {
360 if (!validate_pathname
($file_parent)) {
361 die_error
(undef, "Invalid file parent parameter");
365 # parameters which are refnames
366 our $hash = $cgi->param('h');
368 if (!validate_refname
($hash)) {
369 die_error
(undef, "Invalid hash parameter");
373 our $hash_parent = $cgi->param('hp');
374 if (defined $hash_parent) {
375 if (!validate_refname
($hash_parent)) {
376 die_error
(undef, "Invalid hash parent parameter");
380 our $hash_base = $cgi->param('hb');
381 if (defined $hash_base) {
382 if (!validate_refname
($hash_base)) {
383 die_error
(undef, "Invalid hash base parameter");
387 our $hash_parent_base = $cgi->param('hpb');
388 if (defined $hash_parent_base) {
389 if (!validate_refname
($hash_parent_base)) {
390 die_error
(undef, "Invalid hash parent base parameter");
395 our $page = $cgi->param('pg');
397 if ($page =~ m/[^0-9]/) {
398 die_error
(undef, "Invalid page parameter");
402 our $searchtype = $cgi->param('st');
403 if (defined $searchtype) {
404 if ($searchtype =~ m/[^a-z]/) {
405 die_error
(undef, "Invalid searchtype parameter");
409 our $searchtext = $cgi->param('s');
411 if (defined $searchtext) {
412 if ($searchtype ne 'grep' and $searchtype ne 'pickaxe' and $searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\
@ ]/) {
413 die_error
(undef, "Invalid search parameter");
415 if (length($searchtext) < 2) {
416 die_error
(undef, "At least two characters are required for search parameter");
418 $search_regexp = quotemeta $searchtext;
421 # now read PATH_INFO and use it as alternative to parameters
422 sub evaluate_path_info
{
423 return if defined $project;
424 my $path_info = $ENV{"PATH_INFO"};
425 return if !$path_info;
426 $path_info =~ s
,^/+,,;
427 return if !$path_info;
428 # find which part of PATH_INFO is project
429 $project = $path_info;
431 while ($project && !check_head_link
("$projectroot/$project")) {
432 $project =~ s
,/*[^/]*$,,;
435 $project = validate_pathname
($project);
437 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
438 ($strict_export && !project_in_list
($project))) {
442 # do not change any parameters if an action is given using the query string
444 $path_info =~ s
,^$project/*,,;
445 my ($refname, $pathname) = split(/:/, $path_info, 2);
446 if (defined $pathname) {
447 # we got "project.git/branch:filename" or "project.git/branch:dir/"
448 # we could use git_get_type(branch:pathname), but it needs $git_dir
449 $pathname =~ s
,^/+,,;
450 if (!$pathname || substr($pathname, -1) eq "/") {
454 $action ||= "blob_plain";
456 $hash_base ||= validate_refname
($refname);
457 $file_name ||= validate_pathname
($pathname);
458 } elsif (defined $refname) {
459 # we got "project.git/branch"
460 $action ||= "shortlog";
461 $hash ||= validate_refname
($refname);
464 evaluate_path_info
();
466 # path to the current git repository
468 $git_dir = "$projectroot/$project" if $project;
472 "blame" => \
&git_blame2
,
473 "blobdiff" => \
&git_blobdiff
,
474 "blobdiff_plain" => \
&git_blobdiff_plain
,
475 "blob" => \
&git_blob
,
476 "blob_plain" => \
&git_blob_plain
,
477 "commitdiff" => \
&git_commitdiff
,
478 "commitdiff_plain" => \
&git_commitdiff_plain
,
479 "commit" => \
&git_commit
,
480 "forks" => \
&git_forks
,
481 "heads" => \
&git_heads
,
482 "history" => \
&git_history
,
485 "atom" => \
&git_atom
,
486 "search" => \
&git_search
,
487 "search_help" => \
&git_search_help
,
488 "shortlog" => \
&git_shortlog
,
489 "summary" => \
&git_summary
,
491 "tags" => \
&git_tags
,
492 "tree" => \
&git_tree
,
493 "snapshot" => \
&git_snapshot
,
494 "object" => \
&git_object
,
495 # those below don't need $project
496 "opml" => \
&git_opml
,
497 "project_list" => \
&git_project_list
,
498 "project_index" => \
&git_project_index
,
501 if (!defined $action) {
503 $action = git_get_type
($hash);
504 } elsif (defined $hash_base && defined $file_name) {
505 $action = git_get_type
("$hash_base:$file_name");
506 } elsif (defined $project) {
509 $action = 'project_list';
512 if (!defined($actions{$action})) {
513 die_error
(undef, "Unknown action");
515 if ($action !~ m/^(opml|project_list|project_index)$/ &&
517 die_error
(undef, "Project needed");
519 $actions{$action}->();
522 ## ======================================================================
527 # default is to use -absolute url() i.e. $my_uri
528 my $href = $params{-full
} ? $my_url : $my_uri;
530 # XXX: Warning: If you touch this, check the search form for updating,
541 hash_parent_base
=> "hpb",
547 my %mapping = @mapping;
549 $params{'project'} = $project unless exists $params{'project'};
551 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
553 # use PATH_INFO for project name
554 $href .= "/$params{'project'}" if defined $params{'project'};
555 delete $params{'project'};
557 # Summary just uses the project path URL
558 if (defined $params{'action'} && $params{'action'} eq 'summary') {
559 delete $params{'action'};
563 # now encode the parameters explicitly
565 for (my $i = 0; $i < @mapping; $i += 2) {
566 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
567 if (defined $params{$name}) {
568 push @result, $symbol . "=" . esc_param
($params{$name});
571 $href .= "?" . join(';', @result) if scalar @result;
577 ## ======================================================================
578 ## validation, quoting/unquoting and escaping
580 sub validate_pathname
{
581 my $input = shift || return undef;
583 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
584 # at the beginning, at the end, and between slashes.
585 # also this catches doubled slashes
586 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
590 if ($input =~ m!\0!) {
596 sub validate_refname
{
597 my $input = shift || return undef;
599 # textual hashes are O.K.
600 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
603 # it must be correct pathname
604 $input = validate_pathname
($input)
606 # restrictions on ref name according to git-check-ref-format
607 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
613 # decode sequences of octets in utf8 into Perl's internal form,
614 # which is utf-8 with utf8 flag set if needed. gitweb writes out
615 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
619 eval { $res = decode_utf8
($str, Encode
::FB_CROAK
); };
623 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
627 # quote unsafe chars, but keep the slash, even when it's not
628 # correct, but quoted slashes look too horrible in bookmarks
631 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
637 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
640 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
646 # replace invalid utf8 character with SUBSTITUTION sequence
651 $str = to_utf8
($str);
652 $str = $cgi->escapeHTML($str);
653 if ($opts{'-nbsp'}) {
654 $str =~ s/ / /g;
656 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
660 # quote control characters and escape filename to HTML
665 $str = to_utf8
($str);
666 $str = $cgi->escapeHTML($str);
667 if ($opts{'-nbsp'}) {
668 $str =~ s/ / /g;
670 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
674 # Make control characters "printable", using character escape codes (CEC)
677 my %es = ( # character escape codes, aka escape sequences
678 "\t" => '\t', # tab (HT)
679 "\n" => '\n', # line feed (LF)
680 "\r" => '\r', # carrige return (CR)
681 "\f" => '\f', # form feed (FF)
682 "\b" => '\b', # backspace (BS)
683 "\a" => '\a', # alarm (bell) (BEL)
684 "\e" => '\e', # escape (ESC)
685 "\013" => '\v', # vertical tab (VT)
686 "\000" => '\0', # nul character (NUL)
688 my $chr = ( (exists $es{$cntrl})
690 : sprintf('\%03o', ord($cntrl)) );
691 return "<span class=\"cntrl\">$chr</span>";
694 # Alternatively use unicode control pictures codepoints,
695 # Unicode "printable representation" (PR)
698 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
699 return "<span class=\"cntrl\">$chr</span>";
702 # git may return quoted and escaped filenames
708 my %es = ( # character escape codes, aka escape sequences
709 't' => "\t", # tab (HT, TAB)
710 'n' => "\n", # newline (NL)
711 'r' => "\r", # return (CR)
712 'f' => "\f", # form feed (FF)
713 'b' => "\b", # backspace (BS)
714 'a' => "\a", # alarm (bell) (BEL)
715 'e' => "\e", # escape (ESC)
716 'v' => "\013", # vertical tab (VT)
719 if ($seq =~ m/^[0-7]{1,3}$/) {
720 # octal char sequence
721 return chr(oct($seq));
722 } elsif (exists $es{$seq}) {
723 # C escape sequence, aka character escape code
726 # quoted ordinary character
730 if ($str =~ m/^"(.*)"$/) {
733 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
738 # escape tabs (convert tabs to spaces)
742 while ((my $pos = index($line, "\t")) != -1) {
743 if (my $count = (8 - ($pos % 8))) {
744 my $spaces = ' ' x
$count;
745 $line =~ s/\t/$spaces/;
752 sub project_in_list
{
754 my @list = git_get_projects_list
();
755 return @list && scalar(grep { $_->{'path'} eq $project } @list);
758 ## ----------------------------------------------------------------------
759 ## HTML aware string manipulation
764 my $add_len = shift || 10;
766 # allow only $len chars, but don't cut a word if it would fit in $add_len
767 # if it doesn't fit, cut it if it's still longer than the dots we would add
768 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@]{0,$add_len})(.*)/;
771 if (length($tail) > 4) {
773 $body =~ s/&[^;]*$//; # remove chopped character entities
778 ## ----------------------------------------------------------------------
779 ## functions returning short strings
781 # CSS class for given age value (in seconds)
787 } elsif ($age < 60*60*2) {
789 } elsif ($age < 60*60*24*2) {
796 # convert age in seconds to "nn units ago" string
801 if ($age > 60*60*24*365*2) {
802 $age_str = (int $age/60/60/24/365);
803 $age_str .= " years ago";
804 } elsif ($age > 60*60*24*(365/12)*2) {
805 $age_str = int $age/60/60/24/(365/12);
806 $age_str .= " months ago";
807 } elsif ($age > 60*60*24*7*2) {
808 $age_str = int $age/60/60/24/7;
809 $age_str .= " weeks ago";
810 } elsif ($age > 60*60*24*2) {
811 $age_str = int $age/60/60/24;
812 $age_str .= " days ago";
813 } elsif ($age > 60*60*2) {
814 $age_str = int $age/60/60;
815 $age_str .= " hours ago";
816 } elsif ($age > 60*2) {
817 $age_str = int $age/60;
818 $age_str .= " min ago";
821 $age_str .= " sec ago";
823 $age_str .= " right now";
828 # convert file mode in octal to symbolic file mode string
830 my $mode = oct shift;
832 if (S_ISDIR
($mode & S_IFMT
)) {
834 } elsif (S_ISLNK
($mode)) {
836 } elsif (S_ISREG
($mode)) {
837 # git cares only about the executable bit
838 if ($mode & S_IXUSR
) {
848 # convert file mode in octal to file type string
852 if ($mode !~ m/^[0-7]+$/) {
858 if (S_ISDIR
($mode & S_IFMT
)) {
860 } elsif (S_ISLNK
($mode)) {
862 } elsif (S_ISREG
($mode)) {
869 # convert file mode in octal to file type description string
873 if ($mode !~ m/^[0-7]+$/) {
879 if (S_ISDIR
($mode & S_IFMT
)) {
881 } elsif (S_ISLNK
($mode)) {
883 } elsif (S_ISREG
($mode)) {
884 if ($mode & S_IXUSR
) {
895 ## ----------------------------------------------------------------------
896 ## functions returning short HTML fragments, or transforming HTML fragments
897 ## which don't belong to other sections
899 # format line of commit message.
900 sub format_log_line_html
{
903 $line = esc_html
($line, -nbsp
=>1);
904 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
907 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
908 -class => "text"}, $hash_text);
909 $line =~ s/$hash_text/$link/;
914 # format marker of refs pointing to given object
915 sub format_ref_marker
{
916 my ($refs, $id) = @_;
919 if (defined $refs->{$id}) {
920 foreach my $ref (@{$refs->{$id}}) {
921 my ($type, $name) = qw();
922 # e.g. tags/v2.6.11 or heads/next
923 if ($ref =~ m!^(.*?)s?/(.*)$!) {
931 $markers .= " <span class=\"$type\" title=\"$ref\">" .
932 esc_html
($name) . "</span>";
937 return ' <span class="refs">'. $markers . '</span>';
943 # format, perhaps shortened and with markers, title line
944 sub format_subject_html
{
945 my ($long, $short, $href, $extra) = @_;
946 $extra = '' unless defined($extra);
948 if (length($short) < length($long)) {
949 return $cgi->a({-href
=> $href, -class => "list subject",
950 -title
=> to_utf8
($long)},
951 esc_html
($short) . $extra);
953 return $cgi->a({-href
=> $href, -class => "list subject"},
954 esc_html
($long) . $extra);
958 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
959 sub format_git_diff_header_line
{
961 my $diffinfo = shift;
962 my ($from, $to) = @_;
964 if ($diffinfo->{'nparents'}) {
966 $line =~ s!^(diff (.*?) )"?.*$!$1!;
968 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
969 esc_path
($to->{'file'}));
970 } else { # file was deleted (no href)
971 $line .= esc_path
($to->{'file'});
975 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
976 if ($from->{'href'}) {
977 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
978 'a/' . esc_path
($from->{'file'}));
979 } else { # file was added (no href)
980 $line .= 'a/' . esc_path
($from->{'file'});
984 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
985 'b/' . esc_path
($to->{'file'}));
986 } else { # file was deleted
987 $line .= 'b/' . esc_path
($to->{'file'});
991 return "<div class=\"diff header\">$line</div>\n";
994 # format extended diff header line, before patch itself
995 sub format_extended_diff_header_line
{
997 my $diffinfo = shift;
998 my ($from, $to) = @_;
1001 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1002 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1003 esc_path
($from->{'file'}));
1005 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1006 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1007 esc_path
($to->{'file'}));
1009 # match single <mode>
1010 if ($line =~ m/\s(\d{6})$/) {
1011 $line .= '<span class="info"> (' .
1012 file_type_long
($1) .
1016 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1017 # can match only for combined diff
1019 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1020 if ($from->{'href'}[$i]) {
1021 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1023 substr($diffinfo->{'from_id'}[$i],0,7));
1028 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1031 if ($to->{'href'}) {
1032 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1033 substr($diffinfo->{'to_id'},0,7));
1038 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1039 # can match only for ordinary diff
1040 my ($from_link, $to_link);
1041 if ($from->{'href'}) {
1042 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1043 substr($diffinfo->{'from_id'},0,7));
1045 $from_link = '0' x
7;
1047 if ($to->{'href'}) {
1048 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1049 substr($diffinfo->{'to_id'},0,7));
1053 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1054 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1057 return $line . "<br/>\n";
1060 # format from-file/to-file diff header
1061 sub format_diff_from_to_header
{
1062 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1067 #assert($line =~ m/^---/) if DEBUG;
1068 # no extra formatting for "^--- /dev/null"
1069 if (! $diffinfo->{'nparents'}) {
1070 # ordinary (single parent) diff
1071 if ($line =~ m!^--- "?a/!) {
1072 if ($from->{'href'}) {
1074 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1075 esc_path
($from->{'file'}));
1078 esc_path
($from->{'file'});
1081 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1084 # combined diff (merge commit)
1085 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1086 if ($from->{'href'}[$i]) {
1088 $cgi->a({-href
=>href
(action
=>"blobdiff",
1089 hash_parent
=>$diffinfo->{'from_id'}[$i],
1090 hash_parent_base
=>$parents[$i],
1091 file_parent
=>$from->{'file'}[$i],
1092 hash
=>$diffinfo->{'to_id'},
1094 file_name
=>$to->{'file'}),
1096 -title
=>"diff" . ($i+1)},
1099 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1100 esc_path
($from->{'file'}[$i]));
1102 $line = '--- /dev/null';
1104 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1109 #assert($line =~ m/^\+\+\+/) if DEBUG;
1110 # no extra formatting for "^+++ /dev/null"
1111 if ($line =~ m!^\+\+\+ "?b/!) {
1112 if ($to->{'href'}) {
1114 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1115 esc_path
($to->{'file'}));
1118 esc_path
($to->{'file'});
1121 $result .= qq
!<div
class="diff to_file">$line</div
>\n!;
1126 # format patch (diff) line (not to be used for diff headers)
1127 sub format_diff_line
{
1129 my ($from, $to) = @_;
1130 my $diff_class = "";
1134 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1136 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
1137 if ($line =~ m/^\@{3}/) {
1138 $diff_class = " chunk_header";
1139 } elsif ($line =~ m/^\\/) {
1140 $diff_class = " incomplete";
1141 } elsif ($prefix =~ tr/+/+/) {
1142 $diff_class = " add";
1143 } elsif ($prefix =~ tr/-/-/) {
1144 $diff_class = " rem";
1147 # assume ordinary diff
1148 my $char = substr($line, 0, 1);
1150 $diff_class = " add";
1151 } elsif ($char eq '-') {
1152 $diff_class = " rem";
1153 } elsif ($char eq '@') {
1154 $diff_class = " chunk_header";
1155 } elsif ($char eq "\\") {
1156 $diff_class = " incomplete";
1159 $line = untabify
($line);
1160 if ($from && $to && $line =~ m/^\@{2} /) {
1161 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1162 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1164 $from_lines = 0 unless defined $from_lines;
1165 $to_lines = 0 unless defined $to_lines;
1167 if ($from->{'href'}) {
1168 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1169 -class=>"list"}, $from_text);
1171 if ($to->{'href'}) {
1172 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1173 -class=>"list"}, $to_text);
1175 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1176 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1177 return "<div class=\"diff$diff_class\">$line</div>\n";
1178 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1179 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1180 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1182 @from_text = split(' ', $ranges);
1183 for (my $i = 0; $i < @from_text; ++$i) {
1184 ($from_start[$i], $from_nlines[$i]) =
1185 (split(',', substr($from_text[$i], 1)), 0);
1188 $to_text = pop @from_text;
1189 $to_start = pop @from_start;
1190 $to_nlines = pop @from_nlines;
1192 $line = "<span class=\"chunk_info\">$prefix ";
1193 for (my $i = 0; $i < @from_text; ++$i) {
1194 if ($from->{'href'}[$i]) {
1195 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1196 -class=>"list"}, $from_text[$i]);
1198 $line .= $from_text[$i];
1202 if ($to->{'href'}) {
1203 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1204 -class=>"list"}, $to_text);
1208 $line .= " $prefix</span>" .
1209 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1210 return "<div class=\"diff$diff_class\">$line</div>\n";
1212 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1215 ## ----------------------------------------------------------------------
1216 ## git utility subroutines, invoking git commands
1218 # returns path to the core git executable and the --git-dir parameter as list
1220 return $GIT, '--git-dir='.$git_dir;
1223 # returns path to the core git executable and the --git-dir parameter as string
1225 return join(' ', git_cmd
());
1228 # get HEAD ref of given project as hash
1229 sub git_get_head_hash
{
1230 my $project = shift;
1231 my $o_git_dir = $git_dir;
1233 $git_dir = "$projectroot/$project";
1234 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1237 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1241 if (defined $o_git_dir) {
1242 $git_dir = $o_git_dir;
1247 # get type of given object
1251 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1253 close $fd or return;
1258 sub git_get_project_config
{
1259 my ($key, $type) = @_;
1261 return unless ($key);
1262 $key =~ s/^gitweb\.//;
1263 return if ($key =~ m/\W/);
1265 my @x = (git_cmd
(), 'config');
1266 if (defined $type) { push @x, $type; }
1268 push @x, "gitweb.$key";
1274 # get hash of given path at given ref
1275 sub git_get_hash_by_path
{
1277 my $path = shift || return undef;
1282 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1283 or die_error
(undef, "Open git-ls-tree failed");
1285 close $fd or return undef;
1287 if (!defined $line) {
1288 # there is no tree or hash given by $path at $base
1292 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1293 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1294 if (defined $type && $type ne $2) {
1295 # type doesn't match
1301 # get path of entry with given hash at given tree-ish (ref)
1302 # used to get 'from' filename for combined diff (merge commit) for renames
1303 sub git_get_path_by_hash
{
1304 my $base = shift || return;
1305 my $hash = shift || return;
1309 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1311 while (my $line = <$fd>) {
1314 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1315 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1316 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1325 ## ......................................................................
1326 ## git utility functions, directly accessing git repository
1328 sub git_get_project_description
{
1331 open my $fd, "$projectroot/$path/description" or return undef;
1334 if (defined $descr) {
1340 sub git_get_project_url_list
{
1343 open my $fd, "$projectroot/$path/cloneurl" or return;
1344 my @git_project_url_list = map { chomp; $_ } <$fd>;
1347 return wantarray ? @git_project_url_list : \
@git_project_url_list;
1350 sub git_get_projects_list
{
1355 $filter =~ s/\.git$//;
1357 my ($check_forks) = gitweb_check_feature
('forks');
1359 if (-d
$projects_list) {
1360 # search in directory
1361 my $dir = $projects_list . ($filter ? "/$filter" : '');
1362 # remove the trailing "/"
1364 my $pfxlen = length("$dir");
1367 follow_fast
=> 1, # follow symbolic links
1368 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1370 # skip project-list toplevel, if we get it.
1371 return if (m!^[/.]$!);
1372 # only directories can be git repositories
1373 return unless (-d
$_);
1375 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1376 # we check related file in $projectroot
1377 if ($check_forks and $subdir =~ m
#/.#) {
1378 $File::Find
::prune
= 1;
1379 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1380 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
1381 $File::Find
::prune
= 1;
1386 } elsif (-f
$projects_list) {
1387 # read from file(url-encoded):
1388 # 'git%2Fgit.git Linus+Torvalds'
1389 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1390 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1392 open my ($fd), $projects_list or return;
1394 while (my $line = <$fd>) {
1396 my ($path, $owner) = split ' ', $line;
1397 $path = unescape
($path);
1398 $owner = unescape
($owner);
1399 if (!defined $path) {
1402 if ($filter ne '') {
1403 # looking for forks;
1404 my $pfx = substr($path, 0, length($filter));
1405 if ($pfx ne $filter) {
1408 my $sfx = substr($path, length($filter));
1409 if ($sfx !~ /^\/.*\
.git
$/) {
1412 } elsif ($check_forks) {
1414 foreach my $filter (keys %paths) {
1415 # looking for forks;
1416 my $pfx = substr($path, 0, length($filter));
1417 if ($pfx ne $filter) {
1420 my $sfx = substr($path, length($filter));
1421 if ($sfx !~ /^\/.*\
.git
$/) {
1424 # is a fork, don't include it in
1429 if (check_export_ok
("$projectroot/$path")) {
1432 owner
=> to_utf8
($owner),
1435 (my $forks_path = $path) =~ s/\.git$//;
1436 $paths{$forks_path}++;
1444 sub git_get_project_owner
{
1445 my $project = shift;
1448 return undef unless $project;
1450 # read from file (url-encoded):
1451 # 'git%2Fgit.git Linus+Torvalds'
1452 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1453 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1454 if (-f
$projects_list) {
1455 open (my $fd , $projects_list);
1456 while (my $line = <$fd>) {
1458 my ($pr, $ow) = split ' ', $line;
1459 $pr = unescape
($pr);
1460 $ow = unescape
($ow);
1461 if ($pr eq $project) {
1462 $owner = to_utf8
($ow);
1468 if (!defined $owner) {
1469 $owner = get_file_owner
("$projectroot/$project");
1475 sub git_get_last_activity
{
1479 $git_dir = "$projectroot/$path";
1480 open($fd, "-|", git_cmd
(), 'for-each-ref',
1481 '--format=%(committer)',
1482 '--sort=-committerdate',
1484 'refs/heads') or return;
1485 my $most_recent = <$fd>;
1486 close $fd or return;
1487 if (defined $most_recent &&
1488 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1490 my $age = time - $timestamp;
1491 return ($age, age_string
($age));
1495 sub git_get_references
{
1496 my $type = shift || "";
1498 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1499 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1500 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1501 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
1504 while (my $line = <$fd>) {
1506 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1507 if (defined $refs{$1}) {
1508 push @{$refs{$1}}, $2;
1514 close $fd or return;
1518 sub git_get_rev_name_tags
{
1519 my $hash = shift || return undef;
1521 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1523 my $name_rev = <$fd>;
1526 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1529 # catches also '$hash undefined' output
1534 ## ----------------------------------------------------------------------
1535 ## parse to hash functions
1539 my $tz = shift || "-0000";
1542 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1543 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1544 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1545 $date{'hour'} = $hour;
1546 $date{'minute'} = $min;
1547 $date{'mday'} = $mday;
1548 $date{'day'} = $days[$wday];
1549 $date{'month'} = $months[$mon];
1550 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1551 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1552 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1553 $mday, $months[$mon], $hour ,$min;
1554 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1555 1900+$year, $mon, $mday, $hour ,$min, $sec;
1557 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1558 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1559 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1560 $date{'hour_local'} = $hour;
1561 $date{'minute_local'} = $min;
1562 $date{'tz_local'} = $tz;
1563 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1564 1900+$year, $mon+1, $mday,
1565 $hour, $min, $sec, $tz);
1574 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1575 $tag{'id'} = $tag_id;
1576 while (my $line = <$fd>) {
1578 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1579 $tag{'object'} = $1;
1580 } elsif ($line =~ m/^type (.+)$/) {
1582 } elsif ($line =~ m/^tag (.+)$/) {
1584 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1585 $tag{'author'} = $1;
1588 } elsif ($line =~ m/--BEGIN/) {
1589 push @comment, $line;
1591 } elsif ($line eq "") {
1595 push @comment, <$fd>;
1596 $tag{'comment'} = \
@comment;
1597 close $fd or return;
1598 if (!defined $tag{'name'}) {
1604 sub parse_commit_text
{
1605 my ($commit_text, $withparents) = @_;
1606 my @commit_lines = split '\n', $commit_text;
1609 pop @commit_lines; # Remove '\0'
1611 if (! @commit_lines) {
1615 my $header = shift @commit_lines;
1616 if ($header !~ m/^[0-9a-fA-F]{40}/) {
1619 ($co{'id'}, my @parents) = split ' ', $header;
1620 while (my $line = shift @commit_lines) {
1621 last if $line eq "\n";
1622 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1624 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1626 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1628 $co{'author_epoch'} = $2;
1629 $co{'author_tz'} = $3;
1630 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1631 $co{'author_name'} = $1;
1632 $co{'author_email'} = $2;
1634 $co{'author_name'} = $co{'author'};
1636 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1637 $co{'committer'} = $1;
1638 $co{'committer_epoch'} = $2;
1639 $co{'committer_tz'} = $3;
1640 $co{'committer_name'} = $co{'committer'};
1641 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
1642 $co{'committer_name'} = $1;
1643 $co{'committer_email'} = $2;
1645 $co{'committer_name'} = $co{'committer'};
1649 if (!defined $co{'tree'}) {
1652 $co{'parents'} = \
@parents;
1653 $co{'parent'} = $parents[0];
1655 foreach my $title (@commit_lines) {
1658 $co{'title'} = chop_str
($title, 80, 5);
1659 # remove leading stuff of merges to make the interesting part visible
1660 if (length($title) > 50) {
1661 $title =~ s/^Automatic //;
1662 $title =~ s/^merge (of|with) /Merge ... /i;
1663 if (length($title) > 50) {
1664 $title =~ s/(http|rsync):\/\///;
1666 if (length($title) > 50) {
1667 $title =~ s/(master|www|rsync)\.//;
1669 if (length($title) > 50) {
1670 $title =~ s/kernel.org:?//;
1672 if (length($title) > 50) {
1673 $title =~ s/\/pub\/scm//;
1676 $co{'title_short'} = chop_str
($title, 50, 5);
1680 if ($co{'title'} eq "") {
1681 $co{'title'} = $co{'title_short'} = '(no commit message)';
1683 # remove added spaces
1684 foreach my $line (@commit_lines) {
1687 $co{'comment'} = \
@commit_lines;
1689 my $age = time - $co{'committer_epoch'};
1691 $co{'age_string'} = age_string
($age);
1692 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1693 if ($age > 60*60*24*7*2) {
1694 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1695 $co{'age_string_age'} = $co{'age_string'};
1697 $co{'age_string_date'} = $co{'age_string'};
1698 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1704 my ($commit_id) = @_;
1709 open my $fd, "-|", git_cmd
(), "rev-list",
1715 or die_error
(undef, "Open git-rev-list failed");
1716 %co = parse_commit_text
(<$fd>, 1);
1723 my ($commit_id, $maxcount, $skip, $arg, $filename) = @_;
1731 open my $fd, "-|", git_cmd
(), "rev-list",
1733 ($arg ? ($arg) : ()),
1734 ("--max-count=" . $maxcount),
1735 ("--skip=" . $skip),
1738 ($filename ? ($filename) : ())
1739 or die_error
(undef, "Open git-rev-list failed");
1740 while (my $line = <$fd>) {
1741 my %co = parse_commit_text
($line);
1746 return wantarray ? @cos : \
@cos;
1749 # parse ref from ref_file, given by ref_id, with given type
1751 my $ref_file = shift;
1753 my $type = shift || git_get_type
($ref_id);
1756 $ref_item{'type'} = $type;
1757 $ref_item{'id'} = $ref_id;
1758 $ref_item{'epoch'} = 0;
1759 $ref_item{'age'} = "unknown";
1760 if ($type eq "tag") {
1761 my %tag = parse_tag
($ref_id);
1762 $ref_item{'comment'} = $tag{'comment'};
1763 if ($tag{'type'} eq "commit") {
1764 my %co = parse_commit
($tag{'object'});
1765 $ref_item{'epoch'} = $co{'committer_epoch'};
1766 $ref_item{'age'} = $co{'age_string'};
1767 } elsif (defined($tag{'epoch'})) {
1768 my $age = time - $tag{'epoch'};
1769 $ref_item{'epoch'} = $tag{'epoch'};
1770 $ref_item{'age'} = age_string
($age);
1772 $ref_item{'reftype'} = $tag{'type'};
1773 $ref_item{'name'} = $tag{'name'};
1774 $ref_item{'refid'} = $tag{'object'};
1775 } elsif ($type eq "commit"){
1776 my %co = parse_commit
($ref_id);
1777 $ref_item{'reftype'} = "commit";
1778 $ref_item{'name'} = $ref_file;
1779 $ref_item{'title'} = $co{'title'};
1780 $ref_item{'refid'} = $ref_id;
1781 $ref_item{'epoch'} = $co{'committer_epoch'};
1782 $ref_item{'age'} = $co{'age_string'};
1784 $ref_item{'reftype'} = $type;
1785 $ref_item{'name'} = $ref_file;
1786 $ref_item{'refid'} = $ref_id;
1792 # parse line of git-diff-tree "raw" output
1793 sub parse_difftree_raw_line
{
1797 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1798 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1799 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1800 $res{'from_mode'} = $1;
1801 $res{'to_mode'} = $2;
1802 $res{'from_id'} = $3;
1804 $res{'status'} = $5;
1805 $res{'similarity'} = $6;
1806 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1807 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1809 $res{'file'} = unquote
($7);
1812 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
1813 # combined diff (for merge commit)
1814 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
1815 $res{'nparents'} = length($1);
1816 $res{'from_mode'} = [ split(' ', $2) ];
1817 $res{'to_mode'} = pop @{$res{'from_mode'}};
1818 $res{'from_id'} = [ split(' ', $3) ];
1819 $res{'to_id'} = pop @{$res{'from_id'}};
1820 $res{'status'} = [ split('', $4) ];
1821 $res{'to_file'} = unquote
($5);
1823 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1824 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1825 $res{'commit'} = $1;
1828 return wantarray ? %res : \
%res;
1831 # parse line of git-ls-tree output
1832 sub parse_ls_tree_line
($;%) {
1837 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1838 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
1846 $res{'name'} = unquote
($4);
1849 return wantarray ? %res : \
%res;
1852 # generates _two_ hashes, references to which are passed as 2 and 3 argument
1853 sub parse_from_to_diffinfo
{
1854 my ($diffinfo, $from, $to, @parents) = @_;
1856 if ($diffinfo->{'nparents'}) {
1858 $from->{'file'} = [];
1859 $from->{'href'} = [];
1860 fill_from_file_info
($diffinfo, @parents)
1861 unless exists $diffinfo->{'from_file'};
1862 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1863 $from->{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'};
1864 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
1865 $from->{'href'}[$i] = href
(action
=>"blob",
1866 hash_base
=>$parents[$i],
1867 hash
=>$diffinfo->{'from_id'}[$i],
1868 file_name
=>$from->{'file'}[$i]);
1870 $from->{'href'}[$i] = undef;
1874 $from->{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
1875 if ($diffinfo->{'status'} ne "A") { # not new (added) file
1876 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
1877 hash
=>$diffinfo->{'from_id'},
1878 file_name
=>$from->{'file'});
1880 delete $from->{'href'};
1884 $to->{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
1885 if (!is_deleted
($diffinfo)) { # file exists in result
1886 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
1887 hash
=>$diffinfo->{'to_id'},
1888 file_name
=>$to->{'file'});
1890 delete $to->{'href'};
1894 ## ......................................................................
1895 ## parse to array of hashes functions
1897 sub git_get_heads_list
{
1901 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1902 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
1903 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
1906 while (my $line = <$fd>) {
1910 my ($refinfo, $committerinfo) = split(/\0/, $line);
1911 my ($hash, $name, $title) = split(' ', $refinfo, 3);
1912 my ($committer, $epoch, $tz) =
1913 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
1914 $name =~ s!^refs/heads/!!;
1916 $ref_item{'name'} = $name;
1917 $ref_item{'id'} = $hash;
1918 $ref_item{'title'} = $title || '(no commit message)';
1919 $ref_item{'epoch'} = $epoch;
1921 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1923 $ref_item{'age'} = "unknown";
1926 push @headslist, \
%ref_item;
1930 return wantarray ? @headslist : \
@headslist;
1933 sub git_get_tags_list
{
1937 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1938 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
1939 '--format=%(objectname) %(objecttype) %(refname) '.
1940 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
1943 while (my $line = <$fd>) {
1947 my ($refinfo, $creatorinfo) = split(/\0/, $line);
1948 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
1949 my ($creator, $epoch, $tz) =
1950 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
1951 $name =~ s!^refs/tags/!!;
1953 $ref_item{'type'} = $type;
1954 $ref_item{'id'} = $id;
1955 $ref_item{'name'} = $name;
1956 if ($type eq "tag") {
1957 $ref_item{'subject'} = $title;
1958 $ref_item{'reftype'} = $reftype;
1959 $ref_item{'refid'} = $refid;
1961 $ref_item{'reftype'} = $type;
1962 $ref_item{'refid'} = $id;
1965 if ($type eq "tag" || $type eq "commit") {
1966 $ref_item{'epoch'} = $epoch;
1968 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1970 $ref_item{'age'} = "unknown";
1974 push @tagslist, \
%ref_item;
1978 return wantarray ? @tagslist : \
@tagslist;
1981 ## ----------------------------------------------------------------------
1982 ## filesystem-related functions
1984 sub get_file_owner
{
1987 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1988 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1989 if (!defined $gcos) {
1993 $owner =~ s/[,;].*$//;
1994 return to_utf8
($owner);
1997 ## ......................................................................
1998 ## mimetype related functions
2000 sub mimetype_guess_file
{
2001 my $filename = shift;
2002 my $mimemap = shift;
2003 -r
$mimemap or return undef;
2006 open(MIME
, $mimemap) or return undef;
2008 next if m/^#/; # skip comments
2009 my ($mime, $exts) = split(/\t+/);
2010 if (defined $exts) {
2011 my @exts = split(/\s+/, $exts);
2012 foreach my $ext (@exts) {
2013 $mimemap{$ext} = $mime;
2019 $filename =~ /\.([^.]*)$/;
2020 return $mimemap{$1};
2023 sub mimetype_guess
{
2024 my $filename = shift;
2026 $filename =~ /\./ or return undef;
2028 if ($mimetypes_file) {
2029 my $file = $mimetypes_file;
2030 if ($file !~ m!^/!) { # if it is relative path
2031 # it is relative to project
2032 $file = "$projectroot/$project/$file";
2034 $mime = mimetype_guess_file
($filename, $file);
2036 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2042 my $filename = shift;
2045 my $mime = mimetype_guess
($filename);
2046 $mime and return $mime;
2050 return $default_blob_plain_mimetype unless $fd;
2053 return 'text/plain' .
2054 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
2055 } elsif (! $filename) {
2056 return 'application/octet-stream';
2057 } elsif ($filename =~ m/\.png$/i) {
2059 } elsif ($filename =~ m/\.gif$/i) {
2061 } elsif ($filename =~ m/\.jpe?g$/i) {
2062 return 'image/jpeg';
2064 return 'application/octet-stream';
2068 ## ======================================================================
2069 ## functions printing HTML: header, footer, error page
2071 sub git_header_html
{
2072 my $status = shift || "200 OK";
2073 my $expires = shift;
2075 my $title = "$site_name";
2076 if (defined $project) {
2077 $title .= " - " . to_utf8
($project);
2078 if (defined $action) {
2079 $title .= "/$action";
2080 if (defined $file_name) {
2081 $title .= " - " . esc_path
($file_name);
2082 if ($action eq "tree" && $file_name !~ m
|/$|) {
2089 # require explicit support from the UA if we are to send the page as
2090 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2091 # we have to do this because MSIE sometimes globs '*/*', pretending to
2092 # support xhtml+xml but choking when it gets what it asked for.
2093 if (defined $cgi->http('HTTP_ACCEPT') &&
2094 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2095 $cgi->Accept('application/xhtml+xml') != 0) {
2096 $content_type = 'application/xhtml+xml';
2098 $content_type = 'text/html';
2100 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2101 -status
=> $status, -expires
=> $expires);
2102 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
2104 <?xml version="1.0" encoding="utf-8"?>
2105 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2106 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2107 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2108 <!-- git core binaries version $git_version -->
2110 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2111 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2112 <meta name="robots" content="index, nofollow"/>
2113 <title>$title</title>
2115 # print out each stylesheet that exist
2116 if (defined $stylesheet) {
2117 #provides backwards capability for those people who define style sheet in a config file
2118 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2120 foreach my $stylesheet (@stylesheets) {
2121 next unless $stylesheet;
2122 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2125 if (defined $project) {
2126 printf('<link rel="alternate" title="%s log RSS feed" '.
2127 'href="%s" type="application/rss+xml" />'."\n",
2128 esc_param
($project), href
(action
=>"rss"));
2129 printf('<link rel="alternate" title="%s log Atom feed" '.
2130 'href="%s" type="application/atom+xml" />'."\n",
2131 esc_param
($project), href
(action
=>"atom"));
2133 printf('<link rel="alternate" title="%s projects list" '.
2134 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
2135 $site_name, href
(project
=>undef, action
=>"project_index"));
2136 printf('<link rel="alternate" title="%s projects feeds" '.
2137 'href="%s" type="text/x-opml"/>'."\n",
2138 $site_name, href
(project
=>undef, action
=>"opml"));
2140 if (defined $favicon) {
2141 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
2147 if (-f
$site_header) {
2148 open (my $fd, $site_header);
2153 print "<div class=\"page_header\">\n" .
2154 $cgi->a({-href
=> esc_url
($logo_url),
2155 -title
=> $logo_label},
2156 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
2157 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
2158 if (defined $project) {
2159 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
2160 if (defined $action) {
2167 my ($have_search) = gitweb_check_feature
('search');
2168 if ((defined $project) && ($have_search)) {
2169 if (!defined $searchtext) {
2173 if (defined $hash_base) {
2174 $search_hash = $hash_base;
2175 } elsif (defined $hash) {
2176 $search_hash = $hash;
2178 $search_hash = "HEAD";
2180 $cgi->param("a", "search");
2181 $cgi->param("h", $search_hash);
2182 $cgi->param("p", $project);
2183 print $cgi->startform(-method => "get", -action
=> $my_uri) .
2184 "<div class=\"search\">\n" .
2185 $cgi->hidden(-name
=> "p") . "\n" .
2186 $cgi->hidden(-name
=> "a") . "\n" .
2187 $cgi->hidden(-name
=> "h") . "\n" .
2188 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
2189 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2190 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
2192 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
2194 $cgi->end_form() . "\n";
2198 sub git_footer_html
{
2199 print "<div class=\"page_footer\">\n";
2200 if (defined $project) {
2201 my $descr = git_get_project_description
($project);
2202 if (defined $descr) {
2203 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
2205 print $cgi->a({-href
=> href
(action
=>"rss"),
2206 -class => "rss_logo"}, "RSS") . " ";
2207 print $cgi->a({-href
=> href
(action
=>"atom"),
2208 -class => "rss_logo"}, "Atom") . "\n";
2210 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
2211 -class => "rss_logo"}, "OPML") . " ";
2212 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
2213 -class => "rss_logo"}, "TXT") . "\n";
2217 if (-f
$site_footer) {
2218 open (my $fd, $site_footer);
2228 my $status = shift || "403 Forbidden";
2229 my $error = shift || "Malformed query, file missing or permission denied";
2231 git_header_html
($status);
2233 <div class="page_body">
2243 ## ----------------------------------------------------------------------
2244 ## functions printing or outputting HTML: navigation
2246 sub git_print_page_nav
{
2247 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2248 $extra = '' if !defined $extra; # pager or formats
2250 my @navs = qw(summary shortlog log commit commitdiff tree);
2252 @navs = grep { $_ ne $suppress } @navs;
2255 my %arg = map { $_ => {action
=>$_} } @navs;
2256 if (defined $head) {
2257 for (qw(commit commitdiff)) {
2258 $arg{$_}{'hash'} = $head;
2260 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2261 for (qw(shortlog log)) {
2262 $arg{$_}{'hash'} = $head;
2266 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2267 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2269 print "<div class=\"page_nav\">\n" .
2271 map { $_ eq $current ?
2272 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
2274 print "<br/>\n$extra<br/>\n" .
2278 sub format_paging_nav
{
2279 my ($action, $hash, $head, $page, $nrevs) = @_;
2283 if ($hash ne $head || $page) {
2284 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2286 $paging_nav .= "HEAD";
2290 $paging_nav .= " ⋅ " .
2291 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
2292 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2294 $paging_nav .= " ⋅ prev";
2297 if ($nrevs >= (100 * ($page+1)-1)) {
2298 $paging_nav .= " ⋅ " .
2299 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
2300 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2302 $paging_nav .= " ⋅ next";
2308 ## ......................................................................
2309 ## functions printing or outputting HTML: div
2311 sub git_print_header_div
{
2312 my ($action, $title, $hash, $hash_base) = @_;
2315 $args{'action'} = $action;
2316 $args{'hash'} = $hash if $hash;
2317 $args{'hash_base'} = $hash_base if $hash_base;
2319 print "<div class=\"header\">\n" .
2320 $cgi->a({-href
=> href
(%args), -class => "title"},
2321 $title ? $title : $action) .
2325 #sub git_print_authorship (\%) {
2326 sub git_print_authorship
{
2329 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2330 print "<div class=\"author_date\">" .
2331 esc_html
($co->{'author_name'}) .
2333 if ($ad{'hour_local'} < 6) {
2334 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2335 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2337 printf(" (%02d:%02d %s)",
2338 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2343 sub git_print_page_path
{
2349 print "<div class=\"page_path\">";
2350 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2351 -title
=> 'tree root'}, to_utf8
("[$project]"));
2353 if (defined $name) {
2354 my @dirname = split '/', $name;
2355 my $basename = pop @dirname;
2358 foreach my $dir (@dirname) {
2359 $fullname .= ($fullname ? '/' : '') . $dir;
2360 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2362 -title
=> $fullname}, esc_path
($dir));
2365 if (defined $type && $type eq 'blob') {
2366 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2368 -title
=> $name}, esc_path
($basename));
2369 } elsif (defined $type && $type eq 'tree') {
2370 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2372 -title
=> $name}, esc_path
($basename));
2375 print esc_path
($basename);
2378 print "<br/></div>\n";
2381 # sub git_print_log (\@;%) {
2382 sub git_print_log
($;%) {
2386 if ($opts{'-remove_title'}) {
2387 # remove title, i.e. first line of log
2390 # remove leading empty lines
2391 while (defined $log->[0] && $log->[0] eq "") {
2398 foreach my $line (@$log) {
2399 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2402 if (! $opts{'-remove_signoff'}) {
2403 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2406 # remove signoff lines
2413 # print only one empty line
2414 # do not print empty line after signoff
2416 next if ($empty || $signoff);
2422 print format_log_line_html
($line) . "<br/>\n";
2425 if ($opts{'-final_empty_line'}) {
2426 # end with single empty line
2427 print "<br/>\n" unless $empty;
2431 # return link target (what link points to)
2432 sub git_get_link_target
{
2437 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2441 $link_target = <$fd>;
2446 return $link_target;
2449 # given link target, and the directory (basedir) the link is in,
2450 # return target of link relative to top directory (top tree);
2451 # return undef if it is not possible (including absolute links).
2452 sub normalize_link_target
{
2453 my ($link_target, $basedir, $hash_base) = @_;
2455 # we can normalize symlink target only if $hash_base is provided
2456 return unless $hash_base;
2458 # absolute symlinks (beginning with '/') cannot be normalized
2459 return if (substr($link_target, 0, 1) eq '/');
2461 # normalize link target to path from top (root) tree (dir)
2464 $path = $basedir . '/' . $link_target;
2466 # we are in top (root) tree (dir)
2467 $path = $link_target;
2470 # remove //, /./, and /../
2472 foreach my $part (split('/', $path)) {
2473 # discard '.' and ''
2474 next if (!$part || $part eq '.');
2476 if ($part eq '..') {
2480 # link leads outside repository (outside top dir)
2484 push @path_parts, $part;
2487 $path = join('/', @path_parts);
2492 # print tree entry (row of git_tree), but without encompassing <tr> element
2493 sub git_print_tree_entry
{
2494 my ($t, $basedir, $hash_base, $have_blame) = @_;
2497 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2499 # The format of a table row is: mode list link. Where mode is
2500 # the mode of the entry, list is the name of the entry, an href,
2501 # and link is the action links of the entry.
2503 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2504 if ($t->{'type'} eq "blob") {
2505 print "<td class=\"list\">" .
2506 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2507 file_name
=>"$basedir$t->{'name'}", %base_key),
2508 -class => "list"}, esc_path
($t->{'name'}));
2509 if (S_ISLNK
(oct $t->{'mode'})) {
2510 my $link_target = git_get_link_target
($t->{'hash'});
2512 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2513 if (defined $norm_target) {
2515 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2516 file_name
=>$norm_target),
2517 -title
=> $norm_target}, esc_path
($link_target));
2519 print " -> " . esc_path
($link_target);
2524 print "<td class=\"link\">";
2525 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2526 file_name
=>"$basedir$t->{'name'}", %base_key)},
2530 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2531 file_name
=>"$basedir$t->{'name'}", %base_key)},
2534 if (defined $hash_base) {
2536 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2537 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2541 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2542 file_name
=>"$basedir$t->{'name'}")},
2546 } elsif ($t->{'type'} eq "tree") {
2547 print "<td class=\"list\">";
2548 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2549 file_name
=>"$basedir$t->{'name'}", %base_key)},
2550 esc_path
($t->{'name'}));
2552 print "<td class=\"link\">";
2553 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2554 file_name
=>"$basedir$t->{'name'}", %base_key)},
2556 if (defined $hash_base) {
2558 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2559 file_name
=>"$basedir$t->{'name'}")},
2566 ## ......................................................................
2567 ## functions printing large fragments of HTML
2569 sub fill_from_file_info
{
2570 my ($diff, @parents) = @_;
2572 $diff->{'from_file'} = [ ];
2573 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
2574 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2575 if ($diff->{'status'}[$i] eq 'R' ||
2576 $diff->{'status'}[$i] eq 'C') {
2577 $diff->{'from_file'}[$i] =
2578 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
2585 # parameters can be strings, or references to arrays of strings
2589 if (ref($a) eq "ARRAY" && ref($b) eq "ARRAY" && @$a == @$b) {
2590 for (my $i = 0; $i < @$a; ++$i) {
2591 return 0 unless ($a->[$i] eq $b->[$i]);
2594 } elsif (!ref($a) && !ref($b)) {
2602 my $diffinfo = shift;
2604 return $diffinfo->{'to_id'} eq ('0' x
40);
2607 sub git_difftree_body
{
2608 my ($difftree, $hash, @parents) = @_;
2609 my ($parent) = $parents[0];
2610 my ($have_blame) = gitweb_check_feature
('blame');
2611 print "<div class=\"list_head\">\n";
2612 if ($#{$difftree} > 10) {
2613 print(($#{$difftree} + 1) . " files changed:\n");
2617 print "<table class=\"" .
2618 (@parents > 1 ? "combined " : "") .
2621 # header only for combined diff in 'commitdiff' view
2622 my $has_header = @parents > 1 && $action eq 'commitdiff';
2625 print "<thead><tr>\n" .
2626 "<th></th><th></th>\n"; # filename, patchN link
2627 for (my $i = 0; $i < @parents; $i++) {
2628 my $par = $parents[$i];
2630 $cgi->a({-href
=> href
(action
=>"commitdiff",
2631 hash
=>$hash, hash_parent
=>$par),
2632 -title
=> 'commitdiff to parent number ' .
2633 ($i+1) . ': ' . substr($par,0,7)},
2637 print "</tr></thead>\n<tbody>\n";
2642 foreach my $line (@{$difftree}) {
2644 if (ref($line) eq "HASH") {
2645 # pre-parsed (or generated by hand)
2648 $diff = parse_difftree_raw_line
($line);
2652 print "<tr class=\"dark\">\n";
2654 print "<tr class=\"light\">\n";
2658 if (exists $diff->{'nparents'}) { # combined diff
2660 fill_from_file_info
($diff, @parents)
2661 unless exists $diff->{'from_file'};
2663 if (!is_deleted
($diff)) {
2664 # file exists in the result (child) commit
2666 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2667 file_name
=>$diff->{'to_file'},
2669 -class => "list"}, esc_path
($diff->{'to_file'})) .
2673 esc_path
($diff->{'to_file'}) .
2677 if ($action eq 'commitdiff') {
2680 print "<td class=\"link\">" .
2681 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2686 my $has_history = 0;
2687 my $not_deleted = 0;
2688 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2689 my $hash_parent = $parents[$i];
2690 my $from_hash = $diff->{'from_id'}[$i];
2691 my $from_path = $diff->{'from_file'}[$i];
2692 my $status = $diff->{'status'}[$i];
2694 $has_history ||= ($status ne 'A');
2695 $not_deleted ||= ($status ne 'D');
2697 if ($status eq 'A') {
2698 print "<td class=\"link\" align=\"right\"> | </td>\n";
2699 } elsif ($status eq 'D') {
2700 print "<td class=\"link\">" .
2701 $cgi->a({-href
=> href
(action
=>"blob",
2704 file_name
=>$from_path)},
2708 if ($diff->{'to_id'} eq $from_hash) {
2709 print "<td class=\"link nochange\">";
2711 print "<td class=\"link\">";
2713 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2714 hash
=>$diff->{'to_id'},
2715 hash_parent
=>$from_hash,
2717 hash_parent_base
=>$hash_parent,
2718 file_name
=>$diff->{'to_file'},
2719 file_parent
=>$from_path)},
2725 print "<td class=\"link\">";
2727 print $cgi->a({-href
=> href
(action
=>"blob",
2728 hash
=>$diff->{'to_id'},
2729 file_name
=>$diff->{'to_file'},
2732 print " | " if ($has_history);
2735 print $cgi->a({-href
=> href
(action
=>"history",
2736 file_name
=>$diff->{'to_file'},
2743 next; # instead of 'else' clause, to avoid extra indent
2745 # else ordinary diff
2747 my ($to_mode_oct, $to_mode_str, $to_file_type);
2748 my ($from_mode_oct, $from_mode_str, $from_file_type);
2749 if ($diff->{'to_mode'} ne ('0' x
6)) {
2750 $to_mode_oct = oct $diff->{'to_mode'};
2751 if (S_ISREG
($to_mode_oct)) { # only for regular file
2752 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
2754 $to_file_type = file_type
($diff->{'to_mode'});
2756 if ($diff->{'from_mode'} ne ('0' x
6)) {
2757 $from_mode_oct = oct $diff->{'from_mode'};
2758 if (S_ISREG
($to_mode_oct)) { # only for regular file
2759 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
2761 $from_file_type = file_type
($diff->{'from_mode'});
2764 if ($diff->{'status'} eq "A") { # created
2765 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
2766 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
2767 $mode_chng .= "]</span>";
2769 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2770 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2771 -class => "list"}, esc_path
($diff->{'file'}));
2773 print "<td>$mode_chng</td>\n";
2774 print "<td class=\"link\">";
2775 if ($action eq 'commitdiff') {
2778 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2781 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2782 hash_base
=>$hash, file_name
=>$diff->{'file'})},
2786 } elsif ($diff->{'status'} eq "D") { # deleted
2787 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
2789 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2790 hash_base
=>$parent, file_name
=>$diff->{'file'}),
2791 -class => "list"}, esc_path
($diff->{'file'}));
2793 print "<td>$mode_chng</td>\n";
2794 print "<td class=\"link\">";
2795 if ($action eq 'commitdiff') {
2798 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2801 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2802 hash_base
=>$parent, file_name
=>$diff->{'file'})},
2805 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2806 file_name
=>$diff->{'file'})},
2809 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2810 file_name
=>$diff->{'file'})},
2814 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
2815 my $mode_chnge = "";
2816 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2817 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
2818 if ($from_file_type ne $to_file_type) {
2819 $mode_chnge .= " from $from_file_type to $to_file_type";
2821 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
2822 if ($from_mode_str && $to_mode_str) {
2823 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
2824 } elsif ($to_mode_str) {
2825 $mode_chnge .= " mode: $to_mode_str";
2828 $mode_chnge .= "]</span>\n";
2831 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2832 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2833 -class => "list"}, esc_path
($diff->{'file'}));
2835 print "<td>$mode_chnge</td>\n";
2836 print "<td class=\"link\">";
2837 if ($action eq 'commitdiff') {
2840 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2842 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
2843 # "commit" view and modified file (not onlu mode changed)
2844 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2845 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
2846 hash_base
=>$hash, hash_parent_base
=>$parent,
2847 file_name
=>$diff->{'file'})},
2851 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2852 hash_base
=>$hash, file_name
=>$diff->{'file'})},
2855 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2856 file_name
=>$diff->{'file'})},
2859 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2860 file_name
=>$diff->{'file'})},
2864 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
2865 my %status_name = ('R' => 'moved', 'C' => 'copied');
2866 my $nstatus = $status_name{$diff->{'status'}};
2868 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2869 # mode also for directories, so we cannot use $to_mode_str
2870 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
2873 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2874 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
2875 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
2876 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
2877 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
2878 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
2879 -class => "list"}, esc_path
($diff->{'from_file'})) .
2880 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
2881 "<td class=\"link\">";
2882 if ($action eq 'commitdiff') {
2885 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2887 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
2888 # "commit" view and modified file (not only pure rename or copy)
2889 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2890 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
2891 hash_base
=>$hash, hash_parent_base
=>$parent,
2892 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
2896 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2897 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
2900 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2901 file_name
=>$diff->{'to_file'})},
2904 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2905 file_name
=>$diff->{'to_file'})},
2909 } # we should not encounter Unmerged (U) or Unknown (X) status
2912 print "</tbody>" if $has_header;
2916 sub git_patchset_body
{
2917 my ($fd, $difftree, $hash, @hash_parents) = @_;
2918 my ($hash_parent) = $hash_parents[0];
2921 my $patch_number = 0;
2926 print "<div class=\"patchset\">\n";
2928 # skip to first patch
2929 while ($patch_line = <$fd>) {
2932 last if ($patch_line =~ m/^diff /);
2936 while ($patch_line) {
2938 my ($from_id, $to_id);
2941 #assert($patch_line =~ m/^diff /) if DEBUG;
2942 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
2944 push @diff_header, $patch_line;
2946 # extended diff header
2948 while ($patch_line = <$fd>) {
2951 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
2953 if ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2956 } elsif ($patch_line =~ m/^index ((?:[0-9a-fA-F]{40},)+[0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2957 $from_id = [ split(',', $1) ];
2961 push @diff_header, $patch_line;
2963 my $last_patch_line = $patch_line;
2965 # check if current patch belong to current raw line
2966 # and parse raw git-diff line if needed
2967 if (defined $diffinfo &&
2968 defined $from_id && defined $to_id &&
2969 from_ids_eq
($diffinfo->{'from_id'}, $from_id) &&
2970 $diffinfo->{'to_id'} eq $to_id) {
2971 # this is continuation of a split patch
2972 print "<div class=\"patch cont\">\n";
2974 # advance raw git-diff output if needed
2975 $patch_idx++ if defined $diffinfo;
2977 # read and prepare patch information
2978 if (ref($difftree->[$patch_idx]) eq "HASH") {
2979 # pre-parsed (or generated by hand)
2980 $diffinfo = $difftree->[$patch_idx];
2982 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
2984 # modifies %from, %to hashes
2985 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
2986 if ($diffinfo->{'nparents'}) {
2990 fill_from_file_info
($diffinfo, @hash_parents)
2991 unless exists $diffinfo->{'from_file'};
2992 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
2993 $from{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'};
2994 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
2995 $from{'href'}[$i] = href
(action
=>"blob",
2996 hash_base
=>$hash_parents[$i],
2997 hash
=>$diffinfo->{'from_id'}[$i],
2998 file_name
=>$from{'file'}[$i]);
3000 $from{'href'}[$i] = undef;
3004 $from{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
3005 if ($diffinfo->{'status'} ne "A") { # not new (added) file
3006 $from{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
3007 hash
=>$diffinfo->{'from_id'},
3008 file_name
=>$from{'file'});
3010 delete $from{'href'};
3014 $to{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
3015 if (!is_deleted
($diffinfo)) { # file exists in result
3016 $to{'href'} = href
(action
=>"blob", hash_base
=>$hash,
3017 hash
=>$diffinfo->{'to_id'},
3018 file_name
=>$to{'file'});
3022 # this is first patch for raw difftree line with $patch_idx index
3023 # we index @$difftree array from 0, but number patches from 1
3024 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3027 # print "git diff" header
3028 $patch_line = shift @diff_header;
3029 print format_git_diff_header_line
($patch_line, $diffinfo,
3032 # print extended diff header
3033 print "<div class=\"diff extended_header\">\n" if (@diff_header > 0);
3035 foreach $patch_line (@diff_header) {
3036 print format_extended_diff_header_line
($patch_line, $diffinfo,
3039 print "</div>\n" if (@diff_header > 0); # class="diff extended_header"
3041 # from-file/to-file diff header
3042 $patch_line = $last_patch_line;
3043 if (! $patch_line) {
3044 print "</div>\n"; # class="patch"
3047 next PATCH
if ($patch_line =~ m/^diff /);
3048 #assert($patch_line =~ m/^---/) if DEBUG;
3049 #assert($patch_line eq $last_patch_line) if DEBUG;
3051 $patch_line = <$fd>;
3053 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3055 print format_diff_from_to_header
($last_patch_line, $patch_line,
3056 $diffinfo, \
%from, \
%to,
3061 while ($patch_line = <$fd>) {
3064 next PATCH
if ($patch_line =~ m/^diff /);
3066 print format_diff_line
($patch_line, \
%from, \
%to);
3070 print "</div>\n"; # class="patch"
3073 if ($patch_number == 0) {
3074 if (@hash_parents > 1) {
3075 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3077 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3081 print "</div>\n"; # class="patchset"
3084 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3086 sub git_project_list_body
{
3087 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3089 my ($check_forks) = gitweb_check_feature
('forks');
3092 foreach my $pr (@$projlist) {
3093 my (@aa) = git_get_last_activity
($pr->{'path'});
3097 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
3098 if (!defined $pr->{'descr'}) {
3099 my $descr = git_get_project_description
($pr->{'path'}) || "";
3100 $pr->{'descr_long'} = to_utf8
($descr);
3101 $pr->{'descr'} = chop_str
($descr, 25, 5);
3103 if (!defined $pr->{'owner'}) {
3104 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
3107 my $pname = $pr->{'path'};
3108 if (($pname =~ s/\.git$//) &&
3109 ($pname !~ /\/$/) &&
3110 (-d
"$projectroot/$pname")) {
3111 $pr->{'forks'} = "-d $projectroot/$pname";
3117 push @projects, $pr;
3120 $order ||= $default_projects_order;
3121 $from = 0 unless defined $from;
3122 $to = $#projects if (!defined $to || $#projects < $to);
3124 print "<table class=\"project_list\">\n";
3125 unless ($no_header) {
3128 print "<th></th>\n";
3130 if ($order eq "project") {
3131 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
3132 print "<th>Project</th>\n";
3135 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
3136 -class => "header"}, "Project") .
3139 if ($order eq "descr") {
3140 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
3141 print "<th>Description</th>\n";
3144 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
3145 -class => "header"}, "Description") .
3148 if ($order eq "owner") {
3149 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
3150 print "<th>Owner</th>\n";
3153 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
3154 -class => "header"}, "Owner") .
3157 if ($order eq "age") {
3158 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
3159 print "<th>Last Change</th>\n";
3162 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
3163 -class => "header"}, "Last Change") .
3166 print "<th></th>\n" .
3170 for (my $i = $from; $i <= $to; $i++) {
3171 my $pr = $projects[$i];
3173 print "<tr class=\"dark\">\n";
3175 print "<tr class=\"light\">\n";
3180 if ($pr->{'forks'}) {
3181 print "<!-- $pr->{'forks'} -->\n";
3182 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3186 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3187 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3188 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3189 -class => "list", -title
=> $pr->{'descr_long'}},
3190 esc_html
($pr->{'descr'})) . "</td>\n" .
3191 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
3192 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3193 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
3194 "<td class=\"link\">" .
3195 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3196 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3197 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3198 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3199 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3203 if (defined $extra) {
3206 print "<td></td>\n";
3208 print "<td colspan=\"5\">$extra</td>\n" .
3214 sub git_shortlog_body
{
3215 # uses global variable $project
3216 my ($commitlist, $from, $to, $refs, $extra) = @_;
3218 my $have_snapshot = gitweb_have_snapshot
();
3220 $from = 0 unless defined $from;
3221 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3223 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
3225 for (my $i = $from; $i <= $to; $i++) {
3226 my %co = %{$commitlist->[$i]};
3227 my $commit = $co{'id'};
3228 my $ref = format_ref_marker
($refs, $commit);
3230 print "<tr class=\"dark\">\n";
3232 print "<tr class=\"light\">\n";
3235 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3236 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3237 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
3239 print format_subject_html
($co{'title'}, $co{'title_short'},
3240 href
(action
=>"commit", hash
=>$commit), $ref);
3242 "<td class=\"link\">" .
3243 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3244 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3245 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3246 if ($have_snapshot) {
3247 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
3252 if (defined $extra) {
3254 "<td colspan=\"4\">$extra</td>\n" .
3260 sub git_history_body
{
3261 # Warning: assumes constant type (blob or tree) during history
3262 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3264 $from = 0 unless defined $from;
3265 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3267 print "<table class=\"history\" cellspacing=\"0\">\n";
3269 for (my $i = $from; $i <= $to; $i++) {
3270 my %co = %{$commitlist->[$i]};
3274 my $commit = $co{'id'};
3276 my $ref = format_ref_marker
($refs, $commit);
3279 print "<tr class=\"dark\">\n";
3281 print "<tr class=\"light\">\n";
3284 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3285 # shortlog uses chop_str($co{'author_name'}, 10)
3286 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
3288 # originally git_history used chop_str($co{'title'}, 50)
3289 print format_subject_html
($co{'title'}, $co{'title_short'},
3290 href
(action
=>"commit", hash
=>$commit), $ref);
3292 "<td class=\"link\">" .
3293 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3294 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3296 if ($ftype eq 'blob') {
3297 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3298 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3299 if (defined $blob_current && defined $blob_parent &&
3300 $blob_current ne $blob_parent) {
3302 $cgi->a({-href
=> href
(action
=>"blobdiff",
3303 hash
=>$blob_current, hash_parent
=>$blob_parent,
3304 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3305 file_name
=>$file_name)},
3312 if (defined $extra) {
3314 "<td colspan=\"4\">$extra</td>\n" .
3321 # uses global variable $project
3322 my ($taglist, $from, $to, $extra) = @_;
3323 $from = 0 unless defined $from;
3324 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3326 print "<table class=\"tags\" cellspacing=\"0\">\n";
3328 for (my $i = $from; $i <= $to; $i++) {
3329 my $entry = $taglist->[$i];
3331 my $comment = $tag{'subject'};
3333 if (defined $comment) {
3334 $comment_short = chop_str
($comment, 30, 5);
3337 print "<tr class=\"dark\">\n";
3339 print "<tr class=\"light\">\n";
3342 if (defined $tag{'age'}) {
3343 print "<td><i>$tag{'age'}</i></td>\n";
3345 print "<td></td>\n";
3348 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3349 -class => "list name"}, esc_html
($tag{'name'})) .
3352 if (defined $comment) {
3353 print format_subject_html
($comment, $comment_short,
3354 href
(action
=>"tag", hash
=>$tag{'id'}));
3357 "<td class=\"selflink\">";
3358 if ($tag{'type'} eq "tag") {
3359 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3364 "<td class=\"link\">" . " | " .
3365 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3366 if ($tag{'reftype'} eq "commit") {
3367 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
3368 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
3369 } elsif ($tag{'reftype'} eq "blob") {
3370 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3375 if (defined $extra) {
3377 "<td colspan=\"5\">$extra</td>\n" .
3383 sub git_heads_body
{
3384 # uses global variable $project
3385 my ($headlist, $head, $from, $to, $extra) = @_;
3386 $from = 0 unless defined $from;
3387 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3389 print "<table class=\"heads\" cellspacing=\"0\">\n";
3391 for (my $i = $from; $i <= $to; $i++) {
3392 my $entry = $headlist->[$i];
3394 my $curr = $ref{'id'} eq $head;
3396 print "<tr class=\"dark\">\n";
3398 print "<tr class=\"light\">\n";
3401 print "<td><i>$ref{'age'}</i></td>\n" .
3402 ($curr ? "<td class=\"current_head\">" : "<td>") .
3403 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
3404 -class => "list name"},esc_html
($ref{'name'})) .
3406 "<td class=\"link\">" .
3407 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
3408 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
3409 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
3413 if (defined $extra) {
3415 "<td colspan=\"3\">$extra</td>\n" .
3421 sub git_search_grep_body
{
3422 my ($commitlist, $from, $to, $extra) = @_;
3423 $from = 0 unless defined $from;
3424 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3426 print "<table class=\"grep\" cellspacing=\"0\">\n";
3428 for (my $i = $from; $i <= $to; $i++) {
3429 my %co = %{$commitlist->[$i]};
3433 my $commit = $co{'id'};
3435 print "<tr class=\"dark\">\n";
3437 print "<tr class=\"light\">\n";
3440 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3441 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3443 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3444 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3445 my $comment = $co{'comment'};
3446 foreach my $line (@$comment) {
3447 if ($line =~ m/^(.*)($search_regexp)(.*)$/i) {
3448 my $lead = esc_html
($1) || "";
3449 $lead = chop_str
($lead, 30, 10);
3450 my $match = esc_html
($2) || "";
3451 my $trail = esc_html
($3) || "";
3452 $trail = chop_str
($trail, 30, 10);
3453 my $text = "$lead<span class=\"match\">$match</span>$trail";
3454 print chop_str
($text, 80, 5) . "<br/>\n";
3458 "<td class=\"link\">" .
3459 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3461 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3465 if (defined $extra) {
3467 "<td colspan=\"3\">$extra</td>\n" .
3473 ## ======================================================================
3474 ## ======================================================================
3477 sub git_project_list
{
3478 my $order = $cgi->param('o');
3479 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3480 die_error
(undef, "Unknown order parameter");
3483 my @list = git_get_projects_list
();
3485 die_error
(undef, "No projects found");
3489 if (-f
$home_text) {
3490 print "<div class=\"index_include\">\n";
3491 open (my $fd, $home_text);
3496 git_project_list_body
(\
@list, $order);
3501 my $order = $cgi->param('o');
3502 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3503 die_error
(undef, "Unknown order parameter");
3506 my @list = git_get_projects_list
($project);
3508 die_error
(undef, "No forks found");
3512 git_print_page_nav
('','');
3513 git_print_header_div
('summary', "$project forks");
3514 git_project_list_body
(\
@list, $order);
3518 sub git_project_index
{
3519 my @projects = git_get_projects_list
($project);
3522 -type
=> 'text/plain',
3523 -charset
=> 'utf-8',
3524 -content_disposition
=> 'inline; filename="index.aux"');
3526 foreach my $pr (@projects) {
3527 if (!exists $pr->{'owner'}) {
3528 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}");
3531 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3532 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3533 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3534 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3538 print "$path $owner\n";
3543 my $descr = git_get_project_description
($project) || "none";
3544 my %co = parse_commit
("HEAD");
3545 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
3546 my $head = $co{'id'};
3548 my $owner = git_get_project_owner
($project);
3550 my $refs = git_get_references
();
3551 # These get_*_list functions return one more to allow us to see if
3552 # there are more ...
3553 my @taglist = git_get_tags_list
(16);
3554 my @headlist = git_get_heads_list
(16);
3556 my ($check_forks) = gitweb_check_feature
('forks');
3559 @forklist = git_get_projects_list
($project);
3563 git_print_page_nav
('summary','', $head);
3565 print "<div class=\"title\"> </div>\n";
3566 print "<table cellspacing=\"0\">\n" .
3567 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3568 "<tr><td>owner</td><td>$owner</td></tr>\n";
3569 if (defined $cd{'rfc2822'}) {
3570 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3573 # use per project git URL list in $projectroot/$project/cloneurl
3574 # or make project git URL from git base URL and project name
3575 my $url_tag = "URL";
3576 my @url_list = git_get_project_url_list
($project);
3577 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3578 foreach my $git_url (@url_list) {
3579 next unless $git_url;
3580 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3585 if (-s
"$projectroot/$project/README.html") {
3586 if (open my $fd, "$projectroot/$project/README.html") {
3587 print "<div class=\"title\">readme</div>\n";
3588 print $_ while (<$fd>);
3593 # we need to request one more than 16 (0..15) to check if
3595 my @commitlist = $head ? parse_commits
($head, 17) : ();
3597 git_print_header_div
('shortlog');
3598 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
3599 $#commitlist <= 15 ? undef :
3600 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
3604 git_print_header_div
('tags');
3605 git_tags_body
(\
@taglist, 0, 15,
3606 $#taglist <= 15 ? undef :
3607 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
3611 git_print_header_div
('heads');
3612 git_heads_body
(\
@headlist, $head, 0, 15,
3613 $#headlist <= 15 ? undef :
3614 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
3618 git_print_header_div
('forks');
3619 git_project_list_body
(\
@forklist, undef, 0, 15,
3620 $#forklist <= 15 ? undef :
3621 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
3629 my $head = git_get_head_hash
($project);
3631 git_print_page_nav
('','', $head,undef,$head);
3632 my %tag = parse_tag
($hash);
3635 die_error
(undef, "Unknown tag object");
3638 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
3639 print "<div class=\"title_text\">\n" .
3640 "<table cellspacing=\"0\">\n" .
3642 "<td>object</td>\n" .
3643 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3644 $tag{'object'}) . "</td>\n" .
3645 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3646 $tag{'type'}) . "</td>\n" .
3648 if (defined($tag{'author'})) {
3649 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
3650 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
3651 print "<tr><td></td><td>" . $ad{'rfc2822'} .
3652 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
3655 print "</table>\n\n" .
3657 print "<div class=\"page_body\">";
3658 my $comment = $tag{'comment'};
3659 foreach my $line (@$comment) {
3661 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
3671 my ($have_blame) = gitweb_check_feature
('blame');
3673 die_error
('403 Permission denied', "Permission denied");
3675 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3676 $hash_base ||= git_get_head_hash
($project);
3677 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3678 my %co = parse_commit
($hash_base)
3679 or die_error
(undef, "Reading commit failed");
3680 if (!defined $hash) {
3681 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3682 or die_error
(undef, "Error looking up file");
3684 $ftype = git_get_type
($hash);
3685 if ($ftype !~ "blob") {
3686 die_error
('400 Bad Request', "Object is not a blob");
3688 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
3689 $file_name, $hash_base)
3690 or die_error
(undef, "Open git-blame failed");
3693 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3696 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3699 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3701 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3702 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3703 git_print_page_path
($file_name, $ftype, $hash_base);
3704 my @rev_color = (qw(light2 dark2));
3705 my $num_colors = scalar(@rev_color);
3706 my $current_color = 0;
3709 <div class="page_body">
3710 <table class="blame">
3711 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
3716 last unless defined $_;
3717 my ($full_rev, $orig_lineno, $lineno, $group_size) =
3718 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
3719 if (!exists $metainfo{$full_rev}) {
3720 $metainfo{$full_rev} = {};
3722 my $meta = $metainfo{$full_rev};
3725 if (/^(\S+) (.*)$/) {
3731 my $rev = substr($full_rev, 0, 8);
3732 my $author = $meta->{'author'};
3733 my %date = parse_date
($meta->{'author-time'},
3734 $meta->{'author-tz'});
3735 my $date = $date{'iso-tz'};
3737 $current_color = ++$current_color % $num_colors;
3739 print "<tr class=\"$rev_color[$current_color]\">\n";
3741 print "<td class=\"sha1\"";
3742 print " title=\"". esc_html
($author) . ", $date\"";
3743 print " rowspan=\"$group_size\"" if ($group_size > 1);
3745 print $cgi->a({-href
=> href
(action
=>"commit",
3747 file_name
=>$file_name)},
3751 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
3752 or die_error
(undef, "Open git-rev-parse failed");
3753 my $parent_commit = <$dd>;
3755 chomp($parent_commit);
3756 my $blamed = href
(action
=> 'blame',
3757 file_name
=> $meta->{'filename'},
3758 hash_base
=> $parent_commit);
3759 print "<td class=\"linenr\">";
3760 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
3762 -class => "linenr" },
3765 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
3771 or print "Reading blob failed\n";
3778 my ($have_blame) = gitweb_check_feature
('blame');
3780 die_error
('403 Permission denied', "Permission denied");
3782 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3783 $hash_base ||= git_get_head_hash
($project);
3784 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3785 my %co = parse_commit
($hash_base)
3786 or die_error
(undef, "Reading commit failed");
3787 if (!defined $hash) {
3788 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3789 or die_error
(undef, "Error lookup file");
3791 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
3792 or die_error
(undef, "Open git-annotate failed");
3795 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3798 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3801 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3803 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3804 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3805 git_print_page_path
($file_name, 'blob', $hash_base);
3806 print "<div class=\"page_body\">\n";
3808 <table class="blame">
3817 my @line_class = (qw(light dark));
3818 my $line_class_len = scalar (@line_class);
3819 my $line_class_num = $#line_class;
3820 while (my $line = <$fd>) {
3832 $line_class_num = ($line_class_num + 1) % $line_class_len;
3834 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
3841 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
3844 $short_rev = substr ($long_rev, 0, 8);
3845 $age = time () - $time;
3846 $age_str = age_string
($age);
3847 $age_str =~ s/ / /g;
3848 $age_class = age_class
($age);
3849 $author = esc_html
($author);
3850 $author =~ s/ / /g;
3852 $data = untabify
($data);
3853 $data = esc_html
($data);
3856 <tr class="$line_class[$line_class_num]">
3857 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
3858 <td class="$age_class">$age_str</td>
3860 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
3861 <td class="pre">$data</td>
3864 } # while (my $line = <$fd>)
3865 print "</table>\n\n";
3867 or print "Reading blob failed.\n";
3873 my $head = git_get_head_hash
($project);
3875 git_print_page_nav
('','', $head,undef,$head);
3876 git_print_header_div
('summary', $project);
3878 my @tagslist = git_get_tags_list
();
3880 git_tags_body
(\
@tagslist);
3886 my $head = git_get_head_hash
($project);
3888 git_print_page_nav
('','', $head,undef,$head);
3889 git_print_header_div
('summary', $project);
3891 my @headslist = git_get_heads_list
();
3893 git_heads_body
(\
@headslist, $head);
3898 sub git_blob_plain
{
3901 if (!defined $hash) {
3902 if (defined $file_name) {
3903 my $base = $hash_base || git_get_head_hash
($project);
3904 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3905 or die_error
(undef, "Error lookup file");
3907 die_error
(undef, "No file name defined");
3909 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3910 # blobs defined by non-textual hash id's can be cached
3915 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3916 or die_error
(undef, "Couldn't cat $file_name, $hash");
3918 $type ||= blob_mimetype
($fd, $file_name);
3920 # save as filename, even when no $file_name is given
3921 my $save_as = "$hash";
3922 if (defined $file_name) {
3923 $save_as = $file_name;
3924 } elsif ($type =~ m/^text\//) {
3931 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
3933 binmode STDOUT
, ':raw';
3935 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3943 if (!defined $hash) {
3944 if (defined $file_name) {
3945 my $base = $hash_base || git_get_head_hash
($project);
3946 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3947 or die_error
(undef, "Error lookup file");
3949 die_error
(undef, "No file name defined");
3951 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3952 # blobs defined by non-textual hash id's can be cached
3956 my ($have_blame) = gitweb_check_feature
('blame');
3957 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3958 or die_error
(undef, "Couldn't cat $file_name, $hash");
3959 my $mimetype = blob_mimetype
($fd, $file_name);
3960 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
3962 return git_blob_plain
($mimetype);
3964 # we can have blame only for text/* mimetype
3965 $have_blame &&= ($mimetype =~ m!^text/!);
3967 git_header_html
(undef, $expires);
3968 my $formats_nav = '';
3969 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3970 if (defined $file_name) {
3973 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
3974 hash
=>$hash, file_name
=>$file_name)},
3979 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3980 hash
=>$hash, file_name
=>$file_name)},
3983 $cgi->a({-href
=> href
(action
=>"blob_plain",
3984 hash
=>$hash, file_name
=>$file_name)},
3987 $cgi->a({-href
=> href
(action
=>"blob",
3988 hash_base
=>"HEAD", file_name
=>$file_name)},
3992 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
3994 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3995 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3997 print "<div class=\"page_nav\">\n" .
3998 "<br/><br/></div>\n" .
3999 "<div class=\"title\">$hash</div>\n";
4001 git_print_page_path
($file_name, "blob", $hash_base);
4002 print "<div class=\"page_body\">\n";
4003 if ($mimetype =~ m!^text/!) {
4005 while (my $line = <$fd>) {
4008 $line = untabify
($line);
4009 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4010 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4012 } elsif ($mimetype =~ m!^image/!) {
4013 print qq
!<img type
="$mimetype"!;
4015 print qq
! alt
="$file_name" title
="$file_name"!;
4018 href(action=>"blob_plain
", hash=>$hash,
4019 hash_base=>$hash_base, file_name=>$file_name) .
4023 or print "Reading blob failed.\n";
4029 my $have_snapshot = gitweb_have_snapshot
();
4031 if (!defined $hash_base) {
4032 $hash_base = "HEAD";
4034 if (!defined $hash) {
4035 if (defined $file_name) {
4036 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4042 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4043 or die_error
(undef, "Open git-ls-tree failed");
4044 my @entries = map { chomp; $_ } <$fd>;
4045 close $fd or die_error
(undef, "Reading tree failed");
4048 my $refs = git_get_references
();
4049 my $ref = format_ref_marker
($refs, $hash_base);
4052 my ($have_blame) = gitweb_check_feature
('blame');
4053 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4055 if (defined $file_name) {
4057 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4058 hash
=>$hash, file_name
=>$file_name)},
4060 $cgi->a({-href
=> href
(action
=>"tree",
4061 hash_base
=>"HEAD", file_name
=>$file_name)},
4064 if ($have_snapshot) {
4065 # FIXME: Should be available when we have no hash base as well.
4067 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
4070 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4071 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4074 print "<div class=\"page_nav\">\n";
4075 print "<br/><br/></div>\n";
4076 print "<div class=\"title\">$hash</div>\n";
4078 if (defined $file_name) {
4079 $basedir = $file_name;
4080 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4084 git_print_page_path
($file_name, 'tree', $hash_base);
4085 print "<div class=\"page_body\">\n";
4086 print "<table cellspacing=\"0\">\n";
4088 # '..' (top directory) link if possible
4089 if (defined $hash_base &&
4090 defined $file_name && $file_name =~ m![^/]+$!) {
4092 print "<tr class=\"dark\">\n";
4094 print "<tr class=\"light\">\n";
4098 my $up = $file_name;
4099 $up =~ s!/?[^/]+$!!;
4100 undef $up unless $up;
4101 # based on git_print_tree_entry
4102 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4103 print '<td class="list">';
4104 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4108 print "<td class=\"link\"></td>\n";
4112 foreach my $line (@entries) {
4113 my %t = parse_ls_tree_line
($line, -z
=> 1);
4116 print "<tr class=\"dark\">\n";
4118 print "<tr class=\"light\">\n";
4122 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4126 print "</table>\n" .
4132 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
4133 my $have_snapshot = (defined $ctype && defined $suffix);
4134 if (!$have_snapshot) {
4135 die_error
('403 Permission denied', "Permission denied");
4138 if (!defined $hash) {
4139 $hash = git_get_head_hash
($project);
4142 my $git = git_cmd_str
();
4143 my $name = $project;
4144 $name =~ s/\047/\047\\\047\047/g;
4145 my $filename = to_utf8
(basename
($project));
4147 if ($suffix eq 'zip') {
4148 $filename .= "-$hash.$suffix";
4149 $cmd = "$git archive --format=zip --prefix=\'$name\'/ $hash";
4151 $filename .= "-$hash.tar.$suffix";
4152 $cmd = "$git archive --format=tar --prefix=\'$name\'/ $hash | $command";
4156 -type
=> "application/$ctype",
4157 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4158 -status
=> '200 OK');
4160 open my $fd, "-|", $cmd
4161 or die_error
(undef, "Execute git-archive failed");
4162 binmode STDOUT
, ':raw';
4164 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4170 my $head = git_get_head_hash
($project);
4171 if (!defined $hash) {
4174 if (!defined $page) {
4177 my $refs = git_get_references
();
4179 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4181 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
4184 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4187 my %co = parse_commit
($hash);
4189 git_print_header_div
('summary', $project);
4190 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4192 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
4193 for (my $i = 0; $i <= $to; $i++) {
4194 my %co = %{$commitlist[$i]};
4196 my $commit = $co{'id'};
4197 my $ref = format_ref_marker
($refs, $commit);
4198 my %ad = parse_date
($co{'author_epoch'});
4199 git_print_header_div
('commit',
4200 "<span class=\"age\">$co{'age_string'}</span>" .
4201 esc_html
($co{'title'}) . $ref,
4203 print "<div class=\"title_text\">\n" .
4204 "<div class=\"log_link\">\n" .
4205 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4207 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4209 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4212 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4215 print "<div class=\"log_body\">\n";
4216 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4219 if ($#commitlist >= 100) {
4220 print "<div class=\"page_nav\">\n";
4221 print $cgi->a({-href
=> href
(action
=>"log", hash
=>$hash, page
=>$page+1),
4222 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4229 $hash ||= $hash_base || "HEAD";
4230 my %co = parse_commit
($hash);
4232 die_error
(undef, "Unknown commit object");
4234 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4235 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4237 my $parent = $co{'parent'};
4238 my $parents = $co{'parents'}; # listref
4240 # we need to prepare $formats_nav before any parameter munging
4242 if (!defined $parent) {
4244 $formats_nav .= '(initial)';
4245 } elsif (@$parents == 1) {
4246 # single parent commit
4249 $cgi->a({-href
=> href
(action
=>"commit",
4251 esc_html
(substr($parent, 0, 7))) .
4258 $cgi->a({-href
=> href
(action
=>"commit",
4260 esc_html
(substr($_, 0, 7)));
4265 if (!defined $parent) {
4269 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4271 (@$parents <= 1 ? $parent : '-c'),
4273 or die_error
(undef, "Open git-diff-tree failed");
4274 @difftree = map { chomp; $_ } <$fd>;
4275 close $fd or die_error
(undef, "Reading git-diff-tree failed");
4277 # non-textual hash id's can be cached
4279 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4282 my $refs = git_get_references
();
4283 my $ref = format_ref_marker
($refs, $co{'id'});
4285 my $have_snapshot = gitweb_have_snapshot
();
4287 git_header_html
(undef, $expires);
4288 git_print_page_nav
('commit', '',
4289 $hash, $co{'tree'}, $hash,
4292 if (defined $co{'parent'}) {
4293 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4295 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4297 print "<div class=\"title_text\">\n" .
4298 "<table cellspacing=\"0\">\n";
4299 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4301 "<td></td><td> $ad{'rfc2822'}";
4302 if ($ad{'hour_local'} < 6) {
4303 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4304 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4306 printf(" (%02d:%02d %s)",
4307 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4311 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4312 print "<tr><td></td><td> $cd{'rfc2822'}" .
4313 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4315 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4318 "<td class=\"sha1\">" .
4319 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4320 class => "list"}, $co{'tree'}) .
4322 "<td class=\"link\">" .
4323 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4325 if ($have_snapshot) {
4327 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
4332 foreach my $par (@$parents) {
4335 "<td class=\"sha1\">" .
4336 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4337 class => "list"}, $par) .
4339 "<td class=\"link\">" .
4340 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4342 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4349 print "<div class=\"page_body\">\n";
4350 git_print_log
($co{'comment'});
4353 git_difftree_body
(\
@difftree, $hash, @$parents);
4359 # object is defined by:
4360 # - hash or hash_base alone
4361 # - hash_base and file_name
4364 # - hash or hash_base alone
4365 if ($hash || ($hash_base && !defined $file_name)) {
4366 my $object_id = $hash || $hash_base;
4368 my $git_command = git_cmd_str
();
4369 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
4370 or die_error
('404 Not Found', "Object does not exist");
4374 or die_error
('404 Not Found', "Object does not exist");
4376 # - hash_base and file_name
4377 } elsif ($hash_base && defined $file_name) {
4378 $file_name =~ s
,/+$,,;
4380 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4381 or die_error
('404 Not Found', "Base object does not exist");
4383 # here errors should not hapen
4384 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4385 or die_error
(undef, "Open git-ls-tree failed");
4389 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4390 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4391 die_error
('404 Not Found', "File or directory for given base does not exist");
4396 die_error
('404 Not Found', "Not enough information to find object");
4399 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4400 hash
=>$hash, hash_base
=>$hash_base,
4401 file_name
=>$file_name),
4402 -status
=> '302 Found');
4406 my $format = shift || 'html';
4413 # preparing $fd and %diffinfo for git_patchset_body
4415 if (defined $hash_base && defined $hash_parent_base) {
4416 if (defined $file_name) {
4418 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4419 $hash_parent_base, $hash_base,
4420 "--", (defined $file_parent ? $file_parent : ()), $file_name
4421 or die_error
(undef, "Open git-diff-tree failed");
4422 @difftree = map { chomp; $_ } <$fd>;
4424 or die_error
(undef, "Reading git-diff-tree failed");
4426 or die_error
('404 Not Found', "Blob diff not found");
4428 } elsif (defined $hash &&
4429 $hash =~ /[0-9a-fA-F]{40}/) {
4430 # try to find filename from $hash
4432 # read filtered raw output
4433 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4434 $hash_parent_base, $hash_base, "--"
4435 or die_error
(undef, "Open git-diff-tree failed");
4437 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4439 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4440 map { chomp; $_ } <$fd>;
4442 or die_error
(undef, "Reading git-diff-tree failed");
4444 or die_error
('404 Not Found', "Blob diff not found");
4447 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4450 if (@difftree > 1) {
4451 die_error
('404 Not Found', "Ambiguous blob diff specification");
4454 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4455 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
4456 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
4458 $hash_parent ||= $diffinfo{'from_id'};
4459 $hash ||= $diffinfo{'to_id'};
4461 # non-textual hash id's can be cached
4462 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4463 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4468 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4469 '-p', ($format eq 'html' ? "--full-index" : ()),
4470 $hash_parent_base, $hash_base,
4471 "--", (defined $file_parent ? $file_parent : ()), $file_name
4472 or die_error
(undef, "Open git-diff-tree failed");
4475 # old/legacy style URI
4476 if (!%diffinfo && # if new style URI failed
4477 defined $hash && defined $hash_parent) {
4478 # fake git-diff-tree raw output
4479 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4480 $diffinfo{'from_id'} = $hash_parent;
4481 $diffinfo{'to_id'} = $hash;
4482 if (defined $file_name) {
4483 if (defined $file_parent) {
4484 $diffinfo{'status'} = '2';
4485 $diffinfo{'from_file'} = $file_parent;
4486 $diffinfo{'to_file'} = $file_name;
4487 } else { # assume not renamed
4488 $diffinfo{'status'} = '1';
4489 $diffinfo{'from_file'} = $file_name;
4490 $diffinfo{'to_file'} = $file_name;
4492 } else { # no filename given
4493 $diffinfo{'status'} = '2';
4494 $diffinfo{'from_file'} = $hash_parent;
4495 $diffinfo{'to_file'} = $hash;
4498 # non-textual hash id's can be cached
4499 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4500 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4505 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4506 '-p', ($format eq 'html' ? "--full-index" : ()),
4507 $hash_parent, $hash, "--"
4508 or die_error
(undef, "Open git-diff failed");
4510 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4515 if ($format eq 'html') {
4517 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
4518 hash
=>$hash, hash_parent
=>$hash_parent,
4519 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
4520 file_name
=>$file_name, file_parent
=>$file_parent)},
4522 git_header_html
(undef, $expires);
4523 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4524 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4525 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4527 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4528 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4530 if (defined $file_name) {
4531 git_print_page_path
($file_name, "blob", $hash_base);
4533 print "<div class=\"page_path\"></div>\n";
4536 } elsif ($format eq 'plain') {
4538 -type
=> 'text/plain',
4539 -charset
=> 'utf-8',
4540 -expires
=> $expires,
4541 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4543 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4546 die_error
(undef, "Unknown blobdiff format");
4550 if ($format eq 'html') {
4551 print "<div class=\"page_body\">\n";
4553 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4556 print "</div>\n"; # class="page_body"
4560 while (my $line = <$fd>) {
4561 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4562 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4566 last if $line =~ m!^\+\+\+!;
4574 sub git_blobdiff_plain
{
4575 git_blobdiff
('plain');
4578 sub git_commitdiff
{
4579 my $format = shift || 'html';
4580 $hash ||= $hash_base || "HEAD";
4581 my %co = parse_commit
($hash);
4583 die_error
(undef, "Unknown commit object");
4586 # we need to prepare $formats_nav before any parameter munging
4588 if ($format eq 'html') {
4590 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
4591 hash
=>$hash, hash_parent
=>$hash_parent)},
4594 if (defined $hash_parent) {
4595 # commitdiff with two commits given
4596 my $hash_parent_short = $hash_parent;
4597 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4598 $hash_parent_short = substr($hash_parent, 0, 7);
4602 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
4603 if ($co{'parents'}[$i] eq $hash_parent) {
4604 $formats_nav .= ' parent ' . ($i+1);
4608 $formats_nav .= ': ' .
4609 $cgi->a({-href
=> href
(action
=>"commitdiff",
4610 hash
=>$hash_parent)},
4611 esc_html
($hash_parent_short)) .
4613 } elsif (!$co{'parent'}) {
4615 $formats_nav .= ' (initial)';
4616 } elsif (scalar @{$co{'parents'}} == 1) {
4617 # single parent commit
4620 $cgi->a({-href
=> href
(action
=>"commitdiff",
4621 hash
=>$co{'parent'})},
4622 esc_html
(substr($co{'parent'}, 0, 7))) .
4629 $cgi->a({-href
=> href
(action
=>"commitdiff",
4631 esc_html
(substr($_, 0, 7)));
4632 } @{$co{'parents'}} ) .
4637 my $hash_parent_param = $hash_parent;
4638 if (!defined $hash_parent) {
4639 $hash_parent_param =
4640 @{$co{'parents'}} > 1 ? '-c' : $co{'parent'} || '--root';
4646 if ($format eq 'html') {
4647 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4648 "--no-commit-id", "--patch-with-raw", "--full-index",
4649 $hash_parent_param, $hash, "--"
4650 or die_error
(undef, "Open git-diff-tree failed");
4652 while (my $line = <$fd>) {
4654 # empty line ends raw part of diff-tree output
4656 push @difftree, scalar parse_difftree_raw_line
($line);
4659 } elsif ($format eq 'plain') {
4660 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4661 '-p', $hash_parent_param, $hash, "--"
4662 or die_error
(undef, "Open git-diff-tree failed");
4665 die_error
(undef, "Unknown commitdiff format");
4668 # non-textual hash id's can be cached
4670 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4674 # write commit message
4675 if ($format eq 'html') {
4676 my $refs = git_get_references
();
4677 my $ref = format_ref_marker
($refs, $co{'id'});
4679 git_header_html
(undef, $expires);
4680 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
4681 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
4682 git_print_authorship
(\
%co);
4683 print "<div class=\"page_body\">\n";
4684 if (@{$co{'comment'}} > 1) {
4685 print "<div class=\"log\">\n";
4686 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
4687 print "</div>\n"; # class="log"
4690 } elsif ($format eq 'plain') {
4691 my $refs = git_get_references
("tags");
4692 my $tagname = git_get_rev_name_tags
($hash);
4693 my $filename = basename
($project) . "-$hash.patch";
4696 -type
=> 'text/plain',
4697 -charset
=> 'utf-8',
4698 -expires
=> $expires,
4699 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
4700 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4703 Date: $ad{'rfc2822'} ($ad{'tz_local'})
4704 Subject: $co{'title'}
4706 print "X-Git-Tag: $tagname\n" if $tagname;
4707 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4709 foreach my $line (@{$co{'comment'}}) {
4716 if ($format eq 'html') {
4717 git_difftree_body
(\
@difftree, $hash, $hash_parent || @{$co{'parents'}});
4720 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent || @{$co{'parents'}});
4722 print "</div>\n"; # class="page_body"
4725 } elsif ($format eq 'plain') {
4729 or print "Reading git-diff-tree failed\n";
4733 sub git_commitdiff_plain
{
4734 git_commitdiff
('plain');
4738 if (!defined $hash_base) {
4739 $hash_base = git_get_head_hash
($project);
4741 if (!defined $page) {
4745 my %co = parse_commit
($hash_base);
4747 die_error
(undef, "Unknown commit object");
4750 my $refs = git_get_references
();
4751 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
4753 if (!defined $hash && defined $file_name) {
4754 $hash = git_get_hash_by_path
($hash_base, $file_name);
4756 if (defined $hash) {
4757 $ftype = git_get_type
($hash);
4760 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), "--full-history", $file_name);
4762 my $paging_nav = '';
4765 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4766 file_name
=>$file_name)},
4768 $paging_nav .= " ⋅ " .
4769 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4770 file_name
=>$file_name, page
=>$page-1),
4771 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4773 $paging_nav .= "first";
4774 $paging_nav .= " ⋅ prev";
4776 if ($#commitlist >= 100) {
4777 $paging_nav .= " ⋅ " .
4778 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4779 file_name
=>$file_name, page
=>$page+1),
4780 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4782 $paging_nav .= " ⋅ next";
4785 if ($#commitlist >= 100) {
4787 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4788 file_name
=>$file_name, page
=>$page+1),
4789 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4793 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
4794 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4795 git_print_page_path
($file_name, $ftype, $hash_base);
4797 git_history_body
(\
@commitlist, 0, 99,
4798 $refs, $hash_base, $ftype, $next_link);
4804 my ($have_search) = gitweb_check_feature
('search');
4805 if (!$have_search) {
4806 die_error
('403 Permission denied', "Permission denied");
4808 if (!defined $searchtext) {
4809 die_error
(undef, "Text field empty");
4811 if (!defined $hash) {
4812 $hash = git_get_head_hash
($project);
4814 my %co = parse_commit
($hash);
4816 die_error
(undef, "Unknown commit object");
4818 if (!defined $page) {
4822 $searchtype ||= 'commit';
4823 if ($searchtype eq 'pickaxe') {
4824 # pickaxe may take all resources of your box and run for several minutes
4825 # with every query - so decide by yourself how public you make this feature
4826 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4827 if (!$have_pickaxe) {
4828 die_error
('403 Permission denied', "Permission denied");
4831 if ($searchtype eq 'grep') {
4832 my ($have_grep) = gitweb_check_feature
('grep');
4834 die_error
('403 Permission denied', "Permission denied");
4840 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
4842 if ($searchtype eq 'commit') {
4843 $greptype = "--grep=";
4844 } elsif ($searchtype eq 'author') {
4845 $greptype = "--author=";
4846 } elsif ($searchtype eq 'committer') {
4847 $greptype = "--committer=";
4849 $greptype .= $search_regexp;
4850 my @commitlist = parse_commits
($hash, 101, (100 * $page), $greptype);
4852 my $paging_nav = '';
4855 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4856 searchtext
=>$searchtext, searchtype
=>$searchtype)},
4858 $paging_nav .= " ⋅ " .
4859 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4860 searchtext
=>$searchtext, searchtype
=>$searchtype,
4862 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4864 $paging_nav .= "first";
4865 $paging_nav .= " ⋅ prev";
4867 if ($#commitlist >= 100) {
4868 $paging_nav .= " ⋅ " .
4869 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4870 searchtext
=>$searchtext, searchtype
=>$searchtype,
4872 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4874 $paging_nav .= " ⋅ next";
4877 if ($#commitlist >= 100) {
4879 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4880 searchtext
=>$searchtext, searchtype
=>$searchtype,
4882 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4885 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
4886 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4887 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
4890 if ($searchtype eq 'pickaxe') {
4891 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
4892 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4894 print "<table cellspacing=\"0\">\n";
4897 my $git_command = git_cmd_str
();
4898 my $searchqtext = $searchtext;
4899 $searchqtext =~ s/'/'\\''/;
4900 open my $fd, "-|", "$git_command rev-list $hash | " .
4901 "$git_command diff-tree -r --stdin -S\'$searchqtext\'";
4904 while (my $line = <$fd>) {
4905 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
4908 $set{'from_id'} = $3;
4910 $set{'id'} = $set{'to_id'};
4911 if ($set{'id'} =~ m/0{40}/) {
4912 $set{'id'} = $set{'from_id'};
4914 if ($set{'id'} =~ m/0{40}/) {
4918 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
4921 print "<tr class=\"dark\">\n";
4923 print "<tr class=\"light\">\n";
4926 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4927 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
4929 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4930 -class => "list subject"},
4931 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
4932 while (my $setref = shift @files) {
4934 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
4935 hash
=>$set{'id'}, file_name
=>$set{'file'}),
4937 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
4941 "<td class=\"link\">" .
4942 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4944 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4948 %co = parse_commit
($1);
4956 if ($searchtype eq 'grep') {
4957 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
4958 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4960 print "<table cellspacing=\"0\">\n";
4964 open my $fd, "-|", git_cmd
(), 'grep', '-n', '-i', '-E', $searchtext, $co{'tree'};
4966 while (my $line = <$fd>) {
4968 my ($file, $lno, $ltext, $binary);
4969 last if ($matches++ > 1000);
4970 if ($line =~ /^Binary file (.+) matches$/) {
4974 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
4976 if ($file ne $lastfile) {
4977 $lastfile and print "</td></tr>\n";
4979 print "<tr class=\"dark\">\n";
4981 print "<tr class=\"light\">\n";
4983 print "<td class=\"list\">".
4984 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
4985 file_name
=>"$file"),
4986 -class => "list"}, esc_path
($file));
4987 print "</td><td>\n";
4991 print "<div class=\"binary\">Binary file</div>\n";
4993 $ltext = untabify
($ltext);
4994 if ($ltext =~ m/^(.*)($searchtext)(.*)$/i) {
4995 $ltext = esc_html
($1, -nbsp
=>1);
4996 $ltext .= '<span class="match">';
4997 $ltext .= esc_html
($2, -nbsp
=>1);
4998 $ltext .= '</span>';
4999 $ltext .= esc_html
($3, -nbsp
=>1);
5001 $ltext = esc_html
($ltext, -nbsp
=>1);
5003 print "<div class=\"pre\">" .
5004 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5005 file_name
=>"$file").'#l'.$lno,
5006 -class => "linenr"}, sprintf('%4i', $lno))
5007 . ' ' . $ltext . "</div>\n";
5011 print "</td></tr>\n";
5012 if ($matches > 1000) {
5013 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5016 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5025 sub git_search_help
{
5027 git_print_page_nav
('','', $hash,$hash,$hash);
5030 <dt><b>commit</b></dt>
5031 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
5033 my ($have_grep) = gitweb_check_feature
('grep');
5036 <dt><b>grep</b></dt>
5037 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5038 a different one) are searched for the given
5039 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a>
5040 (POSIX extended) and the matches are listed. On large
5041 trees, this search can take a while and put some strain on the server, so please use it with
5042 some consideration.</dd>
5046 <dt><b>author</b></dt>
5047 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
5048 <dt><b>committer</b></dt>
5049 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
5051 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5052 if ($have_pickaxe) {
5054 <dt><b>pickaxe</b></dt>
5055 <dd>All commits that caused the string to appear or disappear from any file (changes that
5056 added, removed or "modified" the string) will be listed. This search can take a while and
5057 takes a lot of strain on the server, so please use it wisely.</dd>
5065 my $head = git_get_head_hash
($project);
5066 if (!defined $hash) {
5069 if (!defined $page) {
5072 my $refs = git_get_references
();
5074 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5076 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, (100 * ($page+1)));
5078 if ($#commitlist >= 100) {
5080 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
5081 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5085 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
5086 git_print_header_div
('summary', $project);
5088 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
5093 ## ......................................................................
5094 ## feeds (RSS, Atom; OPML)
5097 my $format = shift || 'atom';
5098 my ($have_blame) = gitweb_check_feature
('blame');
5100 # Atom: http://www.atomenabled.org/developers/syndication/
5101 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5102 if ($format ne 'rss' && $format ne 'atom') {
5103 die_error
(undef, "Unknown web feed format");
5106 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5107 my $head = $hash || 'HEAD';
5108 my @commitlist = parse_commits
($head, 150);
5112 my $content_type = "application/$format+xml";
5113 if (defined $cgi->http('HTTP_ACCEPT') &&
5114 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5115 # browser (feed reader) prefers text/xml
5116 $content_type = 'text/xml';
5118 if (defined($commitlist[0])) {
5119 %latest_commit = %{$commitlist[0]};
5120 %latest_date = parse_date
($latest_commit{'author_epoch'});
5122 -type
=> $content_type,
5123 -charset
=> 'utf-8',
5124 -last_modified
=> $latest_date{'rfc2822'});
5127 -type
=> $content_type,
5128 -charset
=> 'utf-8');
5131 # Optimization: skip generating the body if client asks only
5132 # for Last-Modified date.
5133 return if ($cgi->request_method() eq 'HEAD');
5136 my $title = "$site_name - $project/$action";
5137 my $feed_type = 'log';
5138 if (defined $hash) {
5139 $title .= " - '$hash'";
5140 $feed_type = 'branch log';
5141 if (defined $file_name) {
5142 $title .= " :: $file_name";
5143 $feed_type = 'history';
5145 } elsif (defined $file_name) {
5146 $title .= " - $file_name";
5147 $feed_type = 'history';
5149 $title .= " $feed_type";
5150 my $descr = git_get_project_description
($project);
5151 if (defined $descr) {
5152 $descr = esc_html
($descr);
5154 $descr = "$project " .
5155 ($format eq 'rss' ? 'RSS' : 'Atom') .
5158 my $owner = git_get_project_owner
($project);
5159 $owner = esc_html
($owner);
5163 if (defined $file_name) {
5164 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
5165 } elsif (defined $hash) {
5166 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5168 $alt_url = href
(-full
=>1, action
=>"summary");
5170 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
5171 if ($format eq 'rss') {
5173 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5176 print "<title>$title</title>\n" .
5177 "<link>$alt_url</link>\n" .
5178 "<description>$descr</description>\n" .
5179 "<language>en</language>\n";
5180 } elsif ($format eq 'atom') {
5182 <feed xmlns="http://www.w3.org/2005/Atom">
5184 print "<title>$title</title>\n" .
5185 "<subtitle>$descr</subtitle>\n" .
5186 '<link rel="alternate" type="text/html" href="' .
5187 $alt_url . '" />' . "\n" .
5188 '<link rel="self" type="' . $content_type . '" href="' .
5189 $cgi->self_url() . '" />' . "\n" .
5190 "<id>" . href
(-full
=>1) . "</id>\n" .
5191 # use project owner for feed author
5192 "<author><name>$owner</name></author>\n";
5193 if (defined $favicon) {
5194 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5196 if (defined $logo_url) {
5197 # not twice as wide as tall: 72 x 27 pixels
5198 print "<logo>" . esc_url
($logo) . "</logo>\n";
5200 if (! %latest_date) {
5201 # dummy date to keep the feed valid until commits trickle in:
5202 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5204 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5209 for (my $i = 0; $i <= $#commitlist; $i++) {
5210 my %co = %{$commitlist[$i]};
5211 my $commit = $co{'id'};
5212 # we read 150, we always show 30 and the ones more recent than 48 hours
5213 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5216 my %cd = parse_date
($co{'author_epoch'});
5218 # get list of changed files
5219 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5220 $co{'parent'} || "--root",
5221 $co{'id'}, "--", (defined $file_name ? $file_name : ())
5223 my @difftree = map { chomp; $_ } <$fd>;
5227 # print element (entry, item)
5228 my $co_url = href
(-full
=>1, action
=>"commit", hash
=>$commit);
5229 if ($format eq 'rss') {
5231 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
5232 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
5233 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5234 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5235 "<link>$co_url</link>\n" .
5236 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
5237 "<content:encoded>" .
5239 } elsif ($format eq 'atom') {
5241 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
5242 "<updated>$cd{'iso-8601'}</updated>\n" .
5244 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
5245 if ($co{'author_email'}) {
5246 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
5248 print "</author>\n" .
5249 # use committer for contributor
5251 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
5252 if ($co{'committer_email'}) {
5253 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
5255 print "</contributor>\n" .
5256 "<published>$cd{'iso-8601'}</published>\n" .
5257 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5258 "<id>$co_url</id>\n" .
5259 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
5260 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5262 my $comment = $co{'comment'};
5264 foreach my $line (@$comment) {
5265 $line = esc_html
($line);
5268 print "</pre><ul>\n";
5269 foreach my $difftree_line (@difftree) {
5270 my %difftree = parse_difftree_raw_line
($difftree_line);
5271 next if !$difftree{'from_id'};
5273 my $file = $difftree{'file'} || $difftree{'to_file'};
5277 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
5278 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
5279 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
5280 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
5281 -title
=> "diff"}, 'D');
5283 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
5284 file_name
=>$file, hash_base
=>$commit),
5285 -title
=> "blame"}, 'B');
5287 # if this is not a feed of a file history
5288 if (!defined $file_name || $file_name ne $file) {
5289 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
5290 file_name
=>$file, hash
=>$commit),
5291 -title
=> "history"}, 'H');
5293 $file = esc_path
($file);
5297 if ($format eq 'rss') {
5298 print "</ul>]]>\n" .
5299 "</content:encoded>\n" .
5301 } elsif ($format eq 'atom') {
5302 print "</ul>\n</div>\n" .
5309 if ($format eq 'rss') {
5310 print "</channel>\n</rss>\n";
5311 } elsif ($format eq 'atom') {
5325 my @list = git_get_projects_list
();
5327 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5329 <?xml version="1.0" encoding="utf-8"?>
5330 <opml version="1.0">
5332 <title>$site_name OPML Export</title>
5335 <outline text="git RSS feeds">
5338 foreach my $pr (@list) {
5340 my $head = git_get_head_hash
($proj{'path'});
5341 if (!defined $head) {
5344 $git_dir = "$projectroot/$proj{'path'}";
5345 my %co = parse_commit
($head);
5350 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5351 my $rss = "$my_url?p=$proj{'path'};a=rss";
5352 my $html = "$my_url?p=$proj{'path'};a=summary";
5353 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";