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 # show repository only if this file exists
76 # (only effective if this variable evaluates to true)
77 our $export_ok = "++GITWEB_EXPORT_OK++";
79 # only allow viewing of repositories also shown on the overview page
80 our $strict_export = "++GITWEB_STRICT_EXPORT++";
82 # list of git base URLs used for URL to where fetch project from,
83 # i.e. full URL is "$git_base_url/$project"
84 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
86 # default blob_plain mimetype and default charset for text/plain blob
87 our $default_blob_plain_mimetype = 'text/plain';
88 our $default_text_plain_charset = undef;
90 # file to use for guessing MIME types before trying /etc/mime.types
91 # (relative to the current git repository)
92 our $mimetypes_file = undef;
94 # You define site-wide feature defaults here; override them with
95 # $GITWEB_CONFIG as necessary.
98 # 'sub' => feature-sub (subroutine),
99 # 'override' => allow-override (boolean),
100 # 'default' => [ default options...] (array reference)}
102 # if feature is overridable (it means that allow-override has true value,
103 # then feature-sub will be called with default options as parameters;
104 # return value of feature-sub indicates if to enable specified feature
106 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
108 # Enable the 'blame' blob view, showing the last commit that modified
109 # each line in the file. This can be very CPU-intensive.
111 # To enable system wide have in $GITWEB_CONFIG
112 # $feature{'blame'}{'default'} = [1];
113 # To have project specific config enable override in $GITWEB_CONFIG
114 # $feature{'blame'}{'override'} = 1;
115 # and in project config gitweb.blame = 0|1;
117 'sub' => \
&feature_blame
,
121 # Enable the 'snapshot' link, providing a compressed tarball of any
122 # tree. This can potentially generate high traffic if you have large
125 # To disable system wide have in $GITWEB_CONFIG
126 # $feature{'snapshot'}{'default'} = [undef];
127 # To have project specific config enable override in $GITWEB_CONFIG
128 # $feature{'snapshot'}{'override'} = 1;
129 # and in project config gitweb.snapshot = none|gzip|bzip2;
131 'sub' => \
&feature_snapshot
,
133 # => [content-encoding, suffix, program]
134 'default' => ['x-gzip', 'gz', 'gzip']},
136 # Enable text search, which will list the commits which match author,
137 # committer or commit text to a given string. Enabled by default.
142 # Enable the pickaxe search, which will list the commits that modified
143 # a given string in a file. This can be practical and quite faster
144 # alternative to 'blame', but still potentially CPU-intensive.
146 # To enable system wide have in $GITWEB_CONFIG
147 # $feature{'pickaxe'}{'default'} = [1];
148 # To have project specific config enable override in $GITWEB_CONFIG
149 # $feature{'pickaxe'}{'override'} = 1;
150 # and in project config gitweb.pickaxe = 0|1;
152 'sub' => \
&feature_pickaxe
,
156 # Make gitweb use an alternative format of the URLs which can be
157 # more readable and natural-looking: project name is embedded
158 # directly in the path and the query string contains other
159 # auxiliary information. All gitweb installations recognize
160 # URL in either format; this configures in which formats gitweb
163 # To enable system wide have in $GITWEB_CONFIG
164 # $feature{'pathinfo'}{'default'} = [1];
165 # Project specific override is not supported.
167 # Note that you will need to change the default location of CSS,
168 # favicon, logo and possibly other files to an absolute URL. Also,
169 # if gitweb.cgi serves as your indexfile, you will need to force
170 # $my_uri to contain the script name in your $GITWEB_CONFIG.
175 # Make gitweb consider projects in project root subdirectories
176 # to be forks of existing projects. Given project $projname.git,
177 # projects matching $projname/*.git will not be shown in the main
178 # projects list, instead a '+' mark will be added to $projname
179 # there and a 'forks' view will be enabled for the project, listing
180 # all the forks. This feature is supported only if project list
181 # is taken from a directory, not file.
183 # To enable system wide have in $GITWEB_CONFIG
184 # $feature{'forks'}{'default'} = [1];
185 # Project specific override is not supported.
191 sub gitweb_check_feature
{
193 return unless exists $feature{$name};
194 my ($sub, $override, @defaults) = (
195 $feature{$name}{'sub'},
196 $feature{$name}{'override'},
197 @{$feature{$name}{'default'}});
198 if (!$override) { return @defaults; }
200 warn "feature $name is not overrideable";
203 return $sub->(@defaults);
207 my ($val) = git_get_project_config
('blame', '--bool');
209 if ($val eq 'true') {
211 } elsif ($val eq 'false') {
218 sub feature_snapshot
{
219 my ($ctype, $suffix, $command) = @_;
221 my ($val) = git_get_project_config
('snapshot');
223 if ($val eq 'gzip') {
224 return ('x-gzip', 'gz', 'gzip');
225 } elsif ($val eq 'bzip2') {
226 return ('x-bzip2', 'bz2', 'bzip2');
227 } elsif ($val eq 'none') {
231 return ($ctype, $suffix, $command);
234 sub gitweb_have_snapshot
{
235 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
236 my $have_snapshot = (defined $ctype && defined $suffix);
238 return $have_snapshot;
241 sub feature_pickaxe
{
242 my ($val) = git_get_project_config
('pickaxe', '--bool');
244 if ($val eq 'true') {
246 } elsif ($val eq 'false') {
253 # checking HEAD file with -e is fragile if the repository was
254 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
256 sub check_head_link
{
258 my $headfile = "$dir/HEAD";
259 return ((-e
$headfile) ||
260 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
263 sub check_export_ok
{
265 return (check_head_link
($dir) &&
266 (!$export_ok || -e
"$dir/$export_ok"));
269 # rename detection options for git-diff and git-diff-tree
270 # - default is '-M', with the cost proportional to
271 # (number of removed files) * (number of new files).
272 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
273 # (number of changed files + number of removed files) * (number of new files)
274 # - even more costly is '-C', '--find-copies-harder' with cost
275 # (number of files in the original tree) * (number of new files)
276 # - one might want to include '-B' option, e.g. '-B', '-M'
277 our @diff_opts = ('-M'); # taken from git_commit
279 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
280 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
282 # version of the core git binary
283 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
285 $projects_list ||= $projectroot;
287 # ======================================================================
288 # input validation and dispatch
289 our $action = $cgi->param('a');
290 if (defined $action) {
291 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
292 die_error
(undef, "Invalid action parameter");
296 # parameters which are pathnames
297 our $project = $cgi->param('p');
298 if (defined $project) {
299 if (!validate_pathname
($project) ||
300 !(-d
"$projectroot/$project") ||
301 !check_head_link
("$projectroot/$project") ||
302 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
303 ($strict_export && !project_in_list
($project))) {
305 die_error
(undef, "No such project");
309 our $file_name = $cgi->param('f');
310 if (defined $file_name) {
311 if (!validate_pathname
($file_name)) {
312 die_error
(undef, "Invalid file parameter");
316 our $file_parent = $cgi->param('fp');
317 if (defined $file_parent) {
318 if (!validate_pathname
($file_parent)) {
319 die_error
(undef, "Invalid file parent parameter");
323 # parameters which are refnames
324 our $hash = $cgi->param('h');
326 if (!validate_refname
($hash)) {
327 die_error
(undef, "Invalid hash parameter");
331 our $hash_parent = $cgi->param('hp');
332 if (defined $hash_parent) {
333 if (!validate_refname
($hash_parent)) {
334 die_error
(undef, "Invalid hash parent parameter");
338 our $hash_base = $cgi->param('hb');
339 if (defined $hash_base) {
340 if (!validate_refname
($hash_base)) {
341 die_error
(undef, "Invalid hash base parameter");
345 our $hash_parent_base = $cgi->param('hpb');
346 if (defined $hash_parent_base) {
347 if (!validate_refname
($hash_parent_base)) {
348 die_error
(undef, "Invalid hash parent base parameter");
353 our $page = $cgi->param('pg');
355 if ($page =~ m/[^0-9]/) {
356 die_error
(undef, "Invalid page parameter");
360 our $searchtext = $cgi->param('s');
361 if (defined $searchtext) {
362 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\
@ ]/) {
363 die_error
(undef, "Invalid search parameter");
365 if (length($searchtext) < 2) {
366 die_error
(undef, "At least two characters are required for search parameter");
368 $searchtext = quotemeta $searchtext;
371 our $searchtype = $cgi->param('st');
372 if (defined $searchtype) {
373 if ($searchtype =~ m/[^a-z]/) {
374 die_error
(undef, "Invalid searchtype parameter");
378 # now read PATH_INFO and use it as alternative to parameters
379 sub evaluate_path_info
{
380 return if defined $project;
381 my $path_info = $ENV{"PATH_INFO"};
382 return if !$path_info;
383 $path_info =~ s
,^/+,,;
384 return if !$path_info;
385 # find which part of PATH_INFO is project
386 $project = $path_info;
388 while ($project && !check_head_link
("$projectroot/$project")) {
389 $project =~ s
,/*[^/]*$,,;
392 $project = validate_pathname
($project);
394 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
395 ($strict_export && !project_in_list
($project))) {
399 # do not change any parameters if an action is given using the query string
401 $path_info =~ s
,^$project/*,,;
402 my ($refname, $pathname) = split(/:/, $path_info, 2);
403 if (defined $pathname) {
404 # we got "project.git/branch:filename" or "project.git/branch:dir/"
405 # we could use git_get_type(branch:pathname), but it needs $git_dir
406 $pathname =~ s
,^/+,,;
407 if (!$pathname || substr($pathname, -1) eq "/") {
411 $action ||= "blob_plain";
413 $hash_base ||= validate_refname
($refname);
414 $file_name ||= validate_pathname
($pathname);
415 } elsif (defined $refname) {
416 # we got "project.git/branch"
417 $action ||= "shortlog";
418 $hash ||= validate_refname
($refname);
421 evaluate_path_info
();
423 # path to the current git repository
425 $git_dir = "$projectroot/$project" if $project;
429 "blame" => \
&git_blame2
,
430 "blobdiff" => \
&git_blobdiff
,
431 "blobdiff_plain" => \
&git_blobdiff_plain
,
432 "blob" => \
&git_blob
,
433 "blob_plain" => \
&git_blob_plain
,
434 "commitdiff" => \
&git_commitdiff
,
435 "commitdiff_plain" => \
&git_commitdiff_plain
,
436 "commit" => \
&git_commit
,
437 "forks" => \
&git_forks
,
438 "heads" => \
&git_heads
,
439 "history" => \
&git_history
,
442 "atom" => \
&git_atom
,
443 "search" => \
&git_search
,
444 "search_help" => \
&git_search_help
,
445 "shortlog" => \
&git_shortlog
,
446 "summary" => \
&git_summary
,
448 "tags" => \
&git_tags
,
449 "tree" => \
&git_tree
,
450 "snapshot" => \
&git_snapshot
,
451 "object" => \
&git_object
,
452 # those below don't need $project
453 "opml" => \
&git_opml
,
454 "project_list" => \
&git_project_list
,
455 "project_index" => \
&git_project_index
,
458 if (defined $project) {
459 $action ||= 'summary';
461 $action ||= 'project_list';
463 if (!defined($actions{$action})) {
464 die_error
(undef, "Unknown action");
466 if ($action !~ m/^(opml|project_list|project_index)$/ &&
468 die_error
(undef, "Project needed");
470 $actions{$action}->();
473 ## ======================================================================
478 # default is to use -absolute url() i.e. $my_uri
479 my $href = $params{-full
} ? $my_url : $my_uri;
481 # XXX: Warning: If you touch this, check the search form for updating,
492 hash_parent_base
=> "hpb",
498 my %mapping = @mapping;
500 $params{'project'} = $project unless exists $params{'project'};
502 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
504 # use PATH_INFO for project name
505 $href .= "/$params{'project'}" if defined $params{'project'};
506 delete $params{'project'};
508 # Summary just uses the project path URL
509 if (defined $params{'action'} && $params{'action'} eq 'summary') {
510 delete $params{'action'};
514 # now encode the parameters explicitly
516 for (my $i = 0; $i < @mapping; $i += 2) {
517 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
518 if (defined $params{$name}) {
519 push @result, $symbol . "=" . esc_param
($params{$name});
522 $href .= "?" . join(';', @result) if scalar @result;
528 ## ======================================================================
529 ## validation, quoting/unquoting and escaping
531 sub validate_pathname
{
532 my $input = shift || return undef;
534 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
535 # at the beginning, at the end, and between slashes.
536 # also this catches doubled slashes
537 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
541 if ($input =~ m!\0!) {
547 sub validate_refname
{
548 my $input = shift || return undef;
550 # textual hashes are O.K.
551 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
554 # it must be correct pathname
555 $input = validate_pathname
($input)
557 # restrictions on ref name according to git-check-ref-format
558 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
564 # very thin wrapper for decode("utf8", $str, Encode::FB_DEFAULT);
567 return decode
("utf8", $str, Encode
::FB_DEFAULT
);
570 # quote unsafe chars, but keep the slash, even when it's not
571 # correct, but quoted slashes look too horrible in bookmarks
574 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
580 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
583 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
589 # replace invalid utf8 character with SUBSTITUTION sequence
594 $str = to_utf8
($str);
595 $str = escapeHTML
($str);
596 if ($opts{'-nbsp'}) {
597 $str =~ s/ / /g;
599 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
603 # quote control characters and escape filename to HTML
608 $str = to_utf8
($str);
609 $str = escapeHTML
($str);
610 if ($opts{'-nbsp'}) {
611 $str =~ s/ / /g;
613 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
617 # Make control characters "printable", using character escape codes (CEC)
620 my %es = ( # character escape codes, aka escape sequences
621 "\t" => '\t', # tab (HT)
622 "\n" => '\n', # line feed (LF)
623 "\r" => '\r', # carrige return (CR)
624 "\f" => '\f', # form feed (FF)
625 "\b" => '\b', # backspace (BS)
626 "\a" => '\a', # alarm (bell) (BEL)
627 "\e" => '\e', # escape (ESC)
628 "\013" => '\v', # vertical tab (VT)
629 "\000" => '\0', # nul character (NUL)
631 my $chr = ( (exists $es{$cntrl})
633 : sprintf('\%03o', ord($cntrl)) );
634 return "<span class=\"cntrl\">$chr</span>";
637 # Alternatively use unicode control pictures codepoints,
638 # Unicode "printable representation" (PR)
641 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
642 return "<span class=\"cntrl\">$chr</span>";
645 # git may return quoted and escaped filenames
651 my %es = ( # character escape codes, aka escape sequences
652 't' => "\t", # tab (HT, TAB)
653 'n' => "\n", # newline (NL)
654 'r' => "\r", # return (CR)
655 'f' => "\f", # form feed (FF)
656 'b' => "\b", # backspace (BS)
657 'a' => "\a", # alarm (bell) (BEL)
658 'e' => "\e", # escape (ESC)
659 'v' => "\013", # vertical tab (VT)
662 if ($seq =~ m/^[0-7]{1,3}$/) {
663 # octal char sequence
664 return chr(oct($seq));
665 } elsif (exists $es{$seq}) {
666 # C escape sequence, aka character escape code
669 # quoted ordinary character
673 if ($str =~ m/^"(.*)"$/) {
676 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
681 # escape tabs (convert tabs to spaces)
685 while ((my $pos = index($line, "\t")) != -1) {
686 if (my $count = (8 - ($pos % 8))) {
687 my $spaces = ' ' x
$count;
688 $line =~ s/\t/$spaces/;
695 sub project_in_list
{
697 my @list = git_get_projects_list
();
698 return @list && scalar(grep { $_->{'path'} eq $project } @list);
701 ## ----------------------------------------------------------------------
702 ## HTML aware string manipulation
707 my $add_len = shift || 10;
709 # allow only $len chars, but don't cut a word if it would fit in $add_len
710 # if it doesn't fit, cut it if it's still longer than the dots we would add
711 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@]{0,$add_len})(.*)/;
714 if (length($tail) > 4) {
716 $body =~ s/&[^;]*$//; # remove chopped character entities
721 ## ----------------------------------------------------------------------
722 ## functions returning short strings
724 # CSS class for given age value (in seconds)
728 if ($age < 60*60*2) {
730 } elsif ($age < 60*60*24*2) {
737 # convert age in seconds to "nn units ago" string
742 if ($age > 60*60*24*365*2) {
743 $age_str = (int $age/60/60/24/365);
744 $age_str .= " years ago";
745 } elsif ($age > 60*60*24*(365/12)*2) {
746 $age_str = int $age/60/60/24/(365/12);
747 $age_str .= " months ago";
748 } elsif ($age > 60*60*24*7*2) {
749 $age_str = int $age/60/60/24/7;
750 $age_str .= " weeks ago";
751 } elsif ($age > 60*60*24*2) {
752 $age_str = int $age/60/60/24;
753 $age_str .= " days ago";
754 } elsif ($age > 60*60*2) {
755 $age_str = int $age/60/60;
756 $age_str .= " hours ago";
757 } elsif ($age > 60*2) {
758 $age_str = int $age/60;
759 $age_str .= " min ago";
762 $age_str .= " sec ago";
764 $age_str .= " right now";
769 # convert file mode in octal to symbolic file mode string
771 my $mode = oct shift;
773 if (S_ISDIR
($mode & S_IFMT
)) {
775 } elsif (S_ISLNK
($mode)) {
777 } elsif (S_ISREG
($mode)) {
778 # git cares only about the executable bit
779 if ($mode & S_IXUSR
) {
789 # convert file mode in octal to file type string
793 if ($mode !~ m/^[0-7]+$/) {
799 if (S_ISDIR
($mode & S_IFMT
)) {
801 } elsif (S_ISLNK
($mode)) {
803 } elsif (S_ISREG
($mode)) {
810 # convert file mode in octal to file type description string
814 if ($mode !~ m/^[0-7]+$/) {
820 if (S_ISDIR
($mode & S_IFMT
)) {
822 } elsif (S_ISLNK
($mode)) {
824 } elsif (S_ISREG
($mode)) {
825 if ($mode & S_IXUSR
) {
836 ## ----------------------------------------------------------------------
837 ## functions returning short HTML fragments, or transforming HTML fragments
838 ## which don't beling to other sections
840 # format line of commit message.
841 sub format_log_line_html
{
844 $line = esc_html
($line, -nbsp
=>1);
845 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
848 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
849 -class => "text"}, $hash_text);
850 $line =~ s/$hash_text/$link/;
855 # format marker of refs pointing to given object
856 sub format_ref_marker
{
857 my ($refs, $id) = @_;
860 if (defined $refs->{$id}) {
861 foreach my $ref (@{$refs->{$id}}) {
862 my ($type, $name) = qw();
863 # e.g. tags/v2.6.11 or heads/next
864 if ($ref =~ m!^(.*?)s?/(.*)$!) {
872 $markers .= " <span class=\"$type\" title=\"$ref\">" .
873 esc_html
($name) . "</span>";
878 return ' <span class="refs">'. $markers . '</span>';
884 # format, perhaps shortened and with markers, title line
885 sub format_subject_html
{
886 my ($long, $short, $href, $extra) = @_;
887 $extra = '' unless defined($extra);
889 if (length($short) < length($long)) {
890 return $cgi->a({-href
=> $href, -class => "list subject",
891 -title
=> to_utf8
($long)},
892 esc_html
($short) . $extra);
894 return $cgi->a({-href
=> $href, -class => "list subject"},
895 esc_html
($long) . $extra);
899 # format patch (diff) line (rather not to be used for diff headers)
900 sub format_diff_line
{
902 my ($from, $to) = @_;
903 my $char = substr($line, 0, 1);
909 $diff_class = " add";
910 } elsif ($char eq "-") {
911 $diff_class = " rem";
912 } elsif ($char eq "@") {
913 $diff_class = " chunk_header";
914 } elsif ($char eq "\\") {
915 $diff_class = " incomplete";
917 $line = untabify
($line);
918 if ($from && $to && $line =~ m/^\@{2} /) {
919 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
920 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
922 $from_lines = 0 unless defined $from_lines;
923 $to_lines = 0 unless defined $to_lines;
925 if ($from->{'href'}) {
926 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
927 -class=>"list"}, $from_text);
930 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
931 -class=>"list"}, $to_text);
933 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
934 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
935 return "<div class=\"diff$diff_class\">$line</div>\n";
937 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
940 ## ----------------------------------------------------------------------
941 ## git utility subroutines, invoking git commands
943 # returns path to the core git executable and the --git-dir parameter as list
945 return $GIT, '--git-dir='.$git_dir;
948 # returns path to the core git executable and the --git-dir parameter as string
950 return join(' ', git_cmd
());
953 # get HEAD ref of given project as hash
954 sub git_get_head_hash
{
956 my $o_git_dir = $git_dir;
958 $git_dir = "$projectroot/$project";
959 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
962 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
966 if (defined $o_git_dir) {
967 $git_dir = $o_git_dir;
972 # get type of given object
976 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
983 sub git_get_project_config
{
984 my ($key, $type) = @_;
986 return unless ($key);
987 $key =~ s/^gitweb\.//;
988 return if ($key =~ m/\W/);
990 my @x = (git_cmd
(), 'repo-config');
991 if (defined $type) { push @x, $type; }
993 push @x, "gitweb.$key";
999 # get hash of given path at given ref
1000 sub git_get_hash_by_path
{
1002 my $path = shift || return undef;
1007 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1008 or die_error
(undef, "Open git-ls-tree failed");
1010 close $fd or return undef;
1012 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1013 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1014 if (defined $type && $type ne $2) {
1015 # type doesn't match
1021 ## ......................................................................
1022 ## git utility functions, directly accessing git repository
1024 sub git_get_project_description
{
1027 open my $fd, "$projectroot/$path/description" or return undef;
1034 sub git_get_project_url_list
{
1037 open my $fd, "$projectroot/$path/cloneurl" or return;
1038 my @git_project_url_list = map { chomp; $_ } <$fd>;
1041 return wantarray ? @git_project_url_list : \
@git_project_url_list;
1044 sub git_get_projects_list
{
1049 $filter =~ s/\.git$//;
1051 if (-d
$projects_list) {
1052 # search in directory
1053 my $dir = $projects_list . ($filter ? "/$filter" : '');
1054 # remove the trailing "/"
1056 my $pfxlen = length("$dir");
1058 my ($check_forks) = gitweb_check_feature
('forks');
1061 follow_fast
=> 1, # follow symbolic links
1062 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1064 # skip project-list toplevel, if we get it.
1065 return if (m!^[/.]$!);
1066 # only directories can be git repositories
1067 return unless (-d
$_);
1069 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1070 # we check related file in $projectroot
1071 if ($check_forks and $subdir =~ m
#/.#) {
1072 $File::Find
::prune
= 1;
1073 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1074 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
1075 $File::Find
::prune
= 1;
1080 } elsif (-f
$projects_list) {
1081 # read from file(url-encoded):
1082 # 'git%2Fgit.git Linus+Torvalds'
1083 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1084 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1085 open my ($fd), $projects_list or return;
1086 while (my $line = <$fd>) {
1088 my ($path, $owner) = split ' ', $line;
1089 $path = unescape
($path);
1090 $owner = unescape
($owner);
1091 if (!defined $path) {
1094 if ($filter ne '') {
1095 # looking for forks;
1096 my $pfx = substr($path, 0, length($filter));
1097 if ($pfx ne $filter) {
1100 my $sfx = substr($path, length($filter));
1101 if ($sfx !~ /^\/.*\
.git
$/) {
1105 if (check_export_ok
("$projectroot/$path")) {
1108 owner
=> to_utf8
($owner),
1115 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
1119 sub git_get_project_owner
{
1120 my $project = shift;
1123 return undef unless $project;
1125 # read from file (url-encoded):
1126 # 'git%2Fgit.git Linus+Torvalds'
1127 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1128 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1129 if (-f
$projects_list) {
1130 open (my $fd , $projects_list);
1131 while (my $line = <$fd>) {
1133 my ($pr, $ow) = split ' ', $line;
1134 $pr = unescape
($pr);
1135 $ow = unescape
($ow);
1136 if ($pr eq $project) {
1137 $owner = to_utf8
($ow);
1143 if (!defined $owner) {
1144 $owner = get_file_owner
("$projectroot/$project");
1150 sub git_get_last_activity
{
1154 $git_dir = "$projectroot/$path";
1155 open($fd, "-|", git_cmd
(), 'for-each-ref',
1156 '--format=%(committer)',
1157 '--sort=-committerdate',
1159 'refs/heads') or return;
1160 my $most_recent = <$fd>;
1161 close $fd or return;
1162 if ($most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1164 my $age = time - $timestamp;
1165 return ($age, age_string
($age));
1169 sub git_get_references
{
1170 my $type = shift || "";
1172 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1173 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1174 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1175 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
1178 while (my $line = <$fd>) {
1180 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1181 if (defined $refs{$1}) {
1182 push @{$refs{$1}}, $2;
1188 close $fd or return;
1192 sub git_get_rev_name_tags
{
1193 my $hash = shift || return undef;
1195 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1197 my $name_rev = <$fd>;
1200 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1203 # catches also '$hash undefined' output
1208 ## ----------------------------------------------------------------------
1209 ## parse to hash functions
1213 my $tz = shift || "-0000";
1216 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1217 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1218 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1219 $date{'hour'} = $hour;
1220 $date{'minute'} = $min;
1221 $date{'mday'} = $mday;
1222 $date{'day'} = $days[$wday];
1223 $date{'month'} = $months[$mon];
1224 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1225 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1226 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1227 $mday, $months[$mon], $hour ,$min;
1228 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1229 1900+$year, $mon, $mday, $hour ,$min, $sec;
1231 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1232 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1233 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1234 $date{'hour_local'} = $hour;
1235 $date{'minute_local'} = $min;
1236 $date{'tz_local'} = $tz;
1237 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1238 1900+$year, $mon+1, $mday,
1239 $hour, $min, $sec, $tz);
1248 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1249 $tag{'id'} = $tag_id;
1250 while (my $line = <$fd>) {
1252 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1253 $tag{'object'} = $1;
1254 } elsif ($line =~ m/^type (.+)$/) {
1256 } elsif ($line =~ m/^tag (.+)$/) {
1258 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1259 $tag{'author'} = $1;
1262 } elsif ($line =~ m/--BEGIN/) {
1263 push @comment, $line;
1265 } elsif ($line eq "") {
1269 push @comment, <$fd>;
1270 $tag{'comment'} = \
@comment;
1271 close $fd or return;
1272 if (!defined $tag{'name'}) {
1278 sub parse_commit_text
{
1279 my ($commit_text, $withparents) = @_;
1280 my @commit_lines = split '\n', $commit_text;
1283 pop @commit_lines; # Remove '\0'
1285 my $header = shift @commit_lines;
1286 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
1289 ($co{'id'}, my @parents) = split ' ', $header;
1290 while (my $line = shift @commit_lines) {
1291 last if $line eq "\n";
1292 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1294 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1296 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1298 $co{'author_epoch'} = $2;
1299 $co{'author_tz'} = $3;
1300 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1301 $co{'author_name'} = $1;
1302 $co{'author_email'} = $2;
1304 $co{'author_name'} = $co{'author'};
1306 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1307 $co{'committer'} = $1;
1308 $co{'committer_epoch'} = $2;
1309 $co{'committer_tz'} = $3;
1310 $co{'committer_name'} = $co{'committer'};
1311 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
1312 $co{'committer_name'} = $1;
1313 $co{'committer_email'} = $2;
1315 $co{'committer_name'} = $co{'committer'};
1319 if (!defined $co{'tree'}) {
1322 $co{'parents'} = \
@parents;
1323 $co{'parent'} = $parents[0];
1325 foreach my $title (@commit_lines) {
1328 $co{'title'} = chop_str
($title, 80, 5);
1329 # remove leading stuff of merges to make the interesting part visible
1330 if (length($title) > 50) {
1331 $title =~ s/^Automatic //;
1332 $title =~ s/^merge (of|with) /Merge ... /i;
1333 if (length($title) > 50) {
1334 $title =~ s/(http|rsync):\/\///;
1336 if (length($title) > 50) {
1337 $title =~ s/(master|www|rsync)\.//;
1339 if (length($title) > 50) {
1340 $title =~ s/kernel.org:?//;
1342 if (length($title) > 50) {
1343 $title =~ s/\/pub\/scm//;
1346 $co{'title_short'} = chop_str
($title, 50, 5);
1350 if ($co{'title'} eq "") {
1351 $co{'title'} = $co{'title_short'} = '(no commit message)';
1353 # remove added spaces
1354 foreach my $line (@commit_lines) {
1357 $co{'comment'} = \
@commit_lines;
1359 my $age = time - $co{'committer_epoch'};
1361 $co{'age_string'} = age_string
($age);
1362 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1363 if ($age > 60*60*24*7*2) {
1364 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1365 $co{'age_string_age'} = $co{'age_string'};
1367 $co{'age_string_date'} = $co{'age_string'};
1368 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1374 my ($commit_id) = @_;
1379 open my $fd, "-|", git_cmd
(), "rev-list",
1385 or die_error
(undef, "Open git-rev-list failed");
1386 %co = parse_commit_text
(<$fd>, 1);
1393 my ($commit_id, $maxcount, $skip, $arg, $filename) = @_;
1401 open my $fd, "-|", git_cmd
(), "rev-list",
1403 ($arg ? ($arg) : ()),
1404 ("--max-count=" . $maxcount),
1405 ("--skip=" . $skip),
1408 ($filename ? ($filename) : ())
1409 or die_error
(undef, "Open git-rev-list failed");
1410 while (my $line = <$fd>) {
1411 my %co = parse_commit_text
($line);
1416 return wantarray ? @cos : \
@cos;
1419 # parse ref from ref_file, given by ref_id, with given type
1421 my $ref_file = shift;
1423 my $type = shift || git_get_type
($ref_id);
1426 $ref_item{'type'} = $type;
1427 $ref_item{'id'} = $ref_id;
1428 $ref_item{'epoch'} = 0;
1429 $ref_item{'age'} = "unknown";
1430 if ($type eq "tag") {
1431 my %tag = parse_tag
($ref_id);
1432 $ref_item{'comment'} = $tag{'comment'};
1433 if ($tag{'type'} eq "commit") {
1434 my %co = parse_commit
($tag{'object'});
1435 $ref_item{'epoch'} = $co{'committer_epoch'};
1436 $ref_item{'age'} = $co{'age_string'};
1437 } elsif (defined($tag{'epoch'})) {
1438 my $age = time - $tag{'epoch'};
1439 $ref_item{'epoch'} = $tag{'epoch'};
1440 $ref_item{'age'} = age_string
($age);
1442 $ref_item{'reftype'} = $tag{'type'};
1443 $ref_item{'name'} = $tag{'name'};
1444 $ref_item{'refid'} = $tag{'object'};
1445 } elsif ($type eq "commit"){
1446 my %co = parse_commit
($ref_id);
1447 $ref_item{'reftype'} = "commit";
1448 $ref_item{'name'} = $ref_file;
1449 $ref_item{'title'} = $co{'title'};
1450 $ref_item{'refid'} = $ref_id;
1451 $ref_item{'epoch'} = $co{'committer_epoch'};
1452 $ref_item{'age'} = $co{'age_string'};
1454 $ref_item{'reftype'} = $type;
1455 $ref_item{'name'} = $ref_file;
1456 $ref_item{'refid'} = $ref_id;
1462 # parse line of git-diff-tree "raw" output
1463 sub parse_difftree_raw_line
{
1467 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1468 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1469 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1470 $res{'from_mode'} = $1;
1471 $res{'to_mode'} = $2;
1472 $res{'from_id'} = $3;
1474 $res{'status'} = $5;
1475 $res{'similarity'} = $6;
1476 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1477 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1479 $res{'file'} = unquote
($7);
1482 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1483 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1484 $res{'commit'} = $1;
1487 return wantarray ? %res : \
%res;
1490 # parse line of git-ls-tree output
1491 sub parse_ls_tree_line
($;%) {
1496 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1497 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
1505 $res{'name'} = unquote
($4);
1508 return wantarray ? %res : \
%res;
1511 ## ......................................................................
1512 ## parse to array of hashes functions
1514 sub git_get_heads_list
{
1518 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1519 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
1520 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
1523 while (my $line = <$fd>) {
1527 my ($refinfo, $committerinfo) = split(/\0/, $line);
1528 my ($hash, $name, $title) = split(' ', $refinfo, 3);
1529 my ($committer, $epoch, $tz) =
1530 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
1531 $name =~ s!^refs/heads/!!;
1533 $ref_item{'name'} = $name;
1534 $ref_item{'id'} = $hash;
1535 $ref_item{'title'} = $title || '(no commit message)';
1536 $ref_item{'epoch'} = $epoch;
1538 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1540 $ref_item{'age'} = "unknown";
1543 push @headslist, \
%ref_item;
1547 return wantarray ? @headslist : \
@headslist;
1550 sub git_get_tags_list
{
1554 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1555 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
1556 '--format=%(objectname) %(objecttype) %(refname) '.
1557 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
1560 while (my $line = <$fd>) {
1564 my ($refinfo, $creatorinfo) = split(/\0/, $line);
1565 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
1566 my ($creator, $epoch, $tz) =
1567 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
1568 $name =~ s!^refs/tags/!!;
1570 $ref_item{'type'} = $type;
1571 $ref_item{'id'} = $id;
1572 $ref_item{'name'} = $name;
1573 if ($type eq "tag") {
1574 $ref_item{'subject'} = $title;
1575 $ref_item{'reftype'} = $reftype;
1576 $ref_item{'refid'} = $refid;
1578 $ref_item{'reftype'} = $type;
1579 $ref_item{'refid'} = $id;
1582 if ($type eq "tag" || $type eq "commit") {
1583 $ref_item{'epoch'} = $epoch;
1585 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1587 $ref_item{'age'} = "unknown";
1591 push @tagslist, \
%ref_item;
1595 return wantarray ? @tagslist : \
@tagslist;
1598 ## ----------------------------------------------------------------------
1599 ## filesystem-related functions
1601 sub get_file_owner
{
1604 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1605 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1606 if (!defined $gcos) {
1610 $owner =~ s/[,;].*$//;
1611 return to_utf8
($owner);
1614 ## ......................................................................
1615 ## mimetype related functions
1617 sub mimetype_guess_file
{
1618 my $filename = shift;
1619 my $mimemap = shift;
1620 -r
$mimemap or return undef;
1623 open(MIME
, $mimemap) or return undef;
1625 next if m/^#/; # skip comments
1626 my ($mime, $exts) = split(/\t+/);
1627 if (defined $exts) {
1628 my @exts = split(/\s+/, $exts);
1629 foreach my $ext (@exts) {
1630 $mimemap{$ext} = $mime;
1636 $filename =~ /\.([^.]*)$/;
1637 return $mimemap{$1};
1640 sub mimetype_guess
{
1641 my $filename = shift;
1643 $filename =~ /\./ or return undef;
1645 if ($mimetypes_file) {
1646 my $file = $mimetypes_file;
1647 if ($file !~ m!^/!) { # if it is relative path
1648 # it is relative to project
1649 $file = "$projectroot/$project/$file";
1651 $mime = mimetype_guess_file
($filename, $file);
1653 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1659 my $filename = shift;
1662 my $mime = mimetype_guess
($filename);
1663 $mime and return $mime;
1667 return $default_blob_plain_mimetype unless $fd;
1670 return 'text/plain' .
1671 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1672 } elsif (! $filename) {
1673 return 'application/octet-stream';
1674 } elsif ($filename =~ m/\.png$/i) {
1676 } elsif ($filename =~ m/\.gif$/i) {
1678 } elsif ($filename =~ m/\.jpe?g$/i) {
1679 return 'image/jpeg';
1681 return 'application/octet-stream';
1685 ## ======================================================================
1686 ## functions printing HTML: header, footer, error page
1688 sub git_header_html
{
1689 my $status = shift || "200 OK";
1690 my $expires = shift;
1692 my $title = "$site_name";
1693 if (defined $project) {
1694 $title .= " - $project";
1695 if (defined $action) {
1696 $title .= "/$action";
1697 if (defined $file_name) {
1698 $title .= " - " . esc_path
($file_name);
1699 if ($action eq "tree" && $file_name !~ m
|/$|) {
1706 # require explicit support from the UA if we are to send the page as
1707 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1708 # we have to do this because MSIE sometimes globs '*/*', pretending to
1709 # support xhtml+xml but choking when it gets what it asked for.
1710 if (defined $cgi->http('HTTP_ACCEPT') &&
1711 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1712 $cgi->Accept('application/xhtml+xml') != 0) {
1713 $content_type = 'application/xhtml+xml';
1715 $content_type = 'text/html';
1717 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1718 -status
=> $status, -expires
=> $expires);
1719 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
1721 <?xml version="1.0" encoding="utf-8"?>
1722 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1723 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1724 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1725 <!-- git core binaries version $git_version -->
1727 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1728 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
1729 <meta name="robots" content="index, nofollow"/>
1730 <title>$title</title>
1732 # print out each stylesheet that exist
1733 if (defined $stylesheet) {
1734 #provides backwards capability for those people who define style sheet in a config file
1735 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1737 foreach my $stylesheet (@stylesheets) {
1738 next unless $stylesheet;
1739 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1742 if (defined $project) {
1743 printf('<link rel="alternate" title="%s log RSS feed" '.
1744 'href="%s" type="application/rss+xml" />'."\n",
1745 esc_param
($project), href
(action
=>"rss"));
1746 printf('<link rel="alternate" title="%s log Atom feed" '.
1747 'href="%s" type="application/atom+xml" />'."\n",
1748 esc_param
($project), href
(action
=>"atom"));
1750 printf('<link rel="alternate" title="%s projects list" '.
1751 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1752 $site_name, href
(project
=>undef, action
=>"project_index"));
1753 printf('<link rel="alternate" title="%s projects feeds" '.
1754 'href="%s" type="text/x-opml"/>'."\n",
1755 $site_name, href
(project
=>undef, action
=>"opml"));
1757 if (defined $favicon) {
1758 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
1764 if (-f
$site_header) {
1765 open (my $fd, $site_header);
1770 print "<div class=\"page_header\">\n" .
1771 $cgi->a({-href
=> esc_url
($logo_url),
1772 -title
=> $logo_label},
1773 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
1774 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1775 if (defined $project) {
1776 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1777 if (defined $action) {
1782 my ($have_search) = gitweb_check_feature
('search');
1783 if ((defined $project) && ($have_search)) {
1784 if (!defined $searchtext) {
1788 if (defined $hash_base) {
1789 $search_hash = $hash_base;
1790 } elsif (defined $hash) {
1791 $search_hash = $hash;
1793 $search_hash = "HEAD";
1795 $cgi->param("a", "search");
1796 $cgi->param("h", $search_hash);
1797 $cgi->param("p", $project);
1798 print $cgi->startform(-method => "get", -action
=> $my_uri) .
1799 "<div class=\"search\">\n" .
1800 $cgi->hidden(-name
=> "p") . "\n" .
1801 $cgi->hidden(-name
=> "a") . "\n" .
1802 $cgi->hidden(-name
=> "h") . "\n" .
1803 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
1804 -values => ['commit', 'author', 'committer', 'pickaxe']) .
1805 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
1807 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1809 $cgi->end_form() . "\n";
1814 sub git_footer_html
{
1815 print "<div class=\"page_footer\">\n";
1816 if (defined $project) {
1817 my $descr = git_get_project_description
($project);
1818 if (defined $descr) {
1819 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1821 print $cgi->a({-href
=> href
(action
=>"rss"),
1822 -class => "rss_logo"}, "RSS") . " ";
1823 print $cgi->a({-href
=> href
(action
=>"atom"),
1824 -class => "rss_logo"}, "Atom") . "\n";
1826 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1827 -class => "rss_logo"}, "OPML") . " ";
1828 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1829 -class => "rss_logo"}, "TXT") . "\n";
1833 if (-f
$site_footer) {
1834 open (my $fd, $site_footer);
1844 my $status = shift || "403 Forbidden";
1845 my $error = shift || "Malformed query, file missing or permission denied";
1847 git_header_html
($status);
1849 <div class="page_body">
1859 ## ----------------------------------------------------------------------
1860 ## functions printing or outputting HTML: navigation
1862 sub git_print_page_nav
{
1863 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1864 $extra = '' if !defined $extra; # pager or formats
1866 my @navs = qw(summary shortlog log commit commitdiff tree);
1868 @navs = grep { $_ ne $suppress } @navs;
1871 my %arg = map { $_ => {action
=>$_} } @navs;
1872 if (defined $head) {
1873 for (qw(commit commitdiff)) {
1874 $arg{$_}{hash
} = $head;
1876 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1877 for (qw(shortlog log)) {
1878 $arg{$_}{hash
} = $head;
1882 $arg{tree
}{hash
} = $treehead if defined $treehead;
1883 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1885 print "<div class=\"page_nav\">\n" .
1887 map { $_ eq $current ?
1888 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1890 print "<br/>\n$extra<br/>\n" .
1894 sub format_paging_nav
{
1895 my ($action, $hash, $head, $page, $nrevs) = @_;
1899 if ($hash ne $head || $page) {
1900 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1902 $paging_nav .= "HEAD";
1906 $paging_nav .= " ⋅ " .
1907 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1908 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1910 $paging_nav .= " ⋅ prev";
1913 if ($nrevs >= (100 * ($page+1)-1)) {
1914 $paging_nav .= " ⋅ " .
1915 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1916 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1918 $paging_nav .= " ⋅ next";
1924 ## ......................................................................
1925 ## functions printing or outputting HTML: div
1927 sub git_print_header_div
{
1928 my ($action, $title, $hash, $hash_base) = @_;
1931 $args{action
} = $action;
1932 $args{hash
} = $hash if $hash;
1933 $args{hash_base
} = $hash_base if $hash_base;
1935 print "<div class=\"header\">\n" .
1936 $cgi->a({-href
=> href
(%args), -class => "title"},
1937 $title ? $title : $action) .
1941 #sub git_print_authorship (\%) {
1942 sub git_print_authorship
{
1945 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
1946 print "<div class=\"author_date\">" .
1947 esc_html
($co->{'author_name'}) .
1949 if ($ad{'hour_local'} < 6) {
1950 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1951 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1953 printf(" (%02d:%02d %s)",
1954 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1959 sub git_print_page_path
{
1965 print "<div class=\"page_path\">";
1966 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
1967 -title
=> 'tree root'}, "[$project]");
1969 if (defined $name) {
1970 my @dirname = split '/', $name;
1971 my $basename = pop @dirname;
1974 foreach my $dir (@dirname) {
1975 $fullname .= ($fullname ? '/' : '') . $dir;
1976 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
1978 -title
=> esc_html
($fullname)}, esc_path
($dir));
1981 if (defined $type && $type eq 'blob') {
1982 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1984 -title
=> esc_html
($name)}, esc_path
($basename));
1985 } elsif (defined $type && $type eq 'tree') {
1986 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
1988 -title
=> esc_html
($name)}, esc_path
($basename));
1991 print esc_path
($basename);
1994 print "<br/></div>\n";
1997 # sub git_print_log (\@;%) {
1998 sub git_print_log
($;%) {
2002 if ($opts{'-remove_title'}) {
2003 # remove title, i.e. first line of log
2006 # remove leading empty lines
2007 while (defined $log->[0] && $log->[0] eq "") {
2014 foreach my $line (@$log) {
2015 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2018 if (! $opts{'-remove_signoff'}) {
2019 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2022 # remove signoff lines
2029 # print only one empty line
2030 # do not print empty line after signoff
2032 next if ($empty || $signoff);
2038 print format_log_line_html
($line) . "<br/>\n";
2041 if ($opts{'-final_empty_line'}) {
2042 # end with single empty line
2043 print "<br/>\n" unless $empty;
2047 # return link target (what link points to)
2048 sub git_get_link_target
{
2053 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2057 $link_target = <$fd>;
2062 return $link_target;
2065 # given link target, and the directory (basedir) the link is in,
2066 # return target of link relative to top directory (top tree);
2067 # return undef if it is not possible (including absolute links).
2068 sub normalize_link_target
{
2069 my ($link_target, $basedir, $hash_base) = @_;
2071 # we can normalize symlink target only if $hash_base is provided
2072 return unless $hash_base;
2074 # absolute symlinks (beginning with '/') cannot be normalized
2075 return if (substr($link_target, 0, 1) eq '/');
2077 # normalize link target to path from top (root) tree (dir)
2080 $path = $basedir . '/' . $link_target;
2082 # we are in top (root) tree (dir)
2083 $path = $link_target;
2086 # remove //, /./, and /../
2088 foreach my $part (split('/', $path)) {
2089 # discard '.' and ''
2090 next if (!$part || $part eq '.');
2092 if ($part eq '..') {
2096 # link leads outside repository (outside top dir)
2100 push @path_parts, $part;
2103 $path = join('/', @path_parts);
2108 # print tree entry (row of git_tree), but without encompassing <tr> element
2109 sub git_print_tree_entry
{
2110 my ($t, $basedir, $hash_base, $have_blame) = @_;
2113 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2115 # The format of a table row is: mode list link. Where mode is
2116 # the mode of the entry, list is the name of the entry, an href,
2117 # and link is the action links of the entry.
2119 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2120 if ($t->{'type'} eq "blob") {
2121 print "<td class=\"list\">" .
2122 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2123 file_name
=>"$basedir$t->{'name'}", %base_key),
2124 -class => "list"}, esc_path
($t->{'name'}));
2125 if (S_ISLNK
(oct $t->{'mode'})) {
2126 my $link_target = git_get_link_target
($t->{'hash'});
2128 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2129 if (defined $norm_target) {
2131 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2132 file_name
=>$norm_target),
2133 -title
=> $norm_target}, esc_path
($link_target));
2135 print " -> " . esc_path
($link_target);
2140 print "<td class=\"link\">";
2141 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2142 file_name
=>"$basedir$t->{'name'}", %base_key)},
2146 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2147 file_name
=>"$basedir$t->{'name'}", %base_key)},
2150 if (defined $hash_base) {
2152 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2153 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2157 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2158 file_name
=>"$basedir$t->{'name'}")},
2162 } elsif ($t->{'type'} eq "tree") {
2163 print "<td class=\"list\">";
2164 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2165 file_name
=>"$basedir$t->{'name'}", %base_key)},
2166 esc_path
($t->{'name'}));
2168 print "<td class=\"link\">";
2169 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2170 file_name
=>"$basedir$t->{'name'}", %base_key)},
2172 if (defined $hash_base) {
2174 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2175 file_name
=>"$basedir$t->{'name'}")},
2182 ## ......................................................................
2183 ## functions printing large fragments of HTML
2185 sub git_difftree_body
{
2186 my ($difftree, $hash, $parent) = @_;
2187 my ($have_blame) = gitweb_check_feature
('blame');
2188 print "<div class=\"list_head\">\n";
2189 if ($#{$difftree} > 10) {
2190 print(($#{$difftree} + 1) . " files changed:\n");
2194 print "<table class=\"diff_tree\">\n";
2197 foreach my $line (@{$difftree}) {
2198 my %diff = parse_difftree_raw_line
($line);
2201 print "<tr class=\"dark\">\n";
2203 print "<tr class=\"light\">\n";
2207 my ($to_mode_oct, $to_mode_str, $to_file_type);
2208 my ($from_mode_oct, $from_mode_str, $from_file_type);
2209 if ($diff{'to_mode'} ne ('0' x
6)) {
2210 $to_mode_oct = oct $diff{'to_mode'};
2211 if (S_ISREG
($to_mode_oct)) { # only for regular file
2212 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
2214 $to_file_type = file_type
($diff{'to_mode'});
2216 if ($diff{'from_mode'} ne ('0' x
6)) {
2217 $from_mode_oct = oct $diff{'from_mode'};
2218 if (S_ISREG
($to_mode_oct)) { # only for regular file
2219 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
2221 $from_file_type = file_type
($diff{'from_mode'});
2224 if ($diff{'status'} eq "A") { # created
2225 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
2226 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
2227 $mode_chng .= "]</span>";
2229 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2230 hash_base
=>$hash, file_name
=>$diff{'file'}),
2231 -class => "list"}, esc_path
($diff{'file'}));
2233 print "<td>$mode_chng</td>\n";
2234 print "<td class=\"link\">";
2235 if ($action eq 'commitdiff') {
2238 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2241 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2242 hash_base
=>$hash, file_name
=>$diff{'file'})},
2246 } elsif ($diff{'status'} eq "D") { # deleted
2247 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
2249 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
2250 hash_base
=>$parent, file_name
=>$diff{'file'}),
2251 -class => "list"}, esc_path
($diff{'file'}));
2253 print "<td>$mode_chng</td>\n";
2254 print "<td class=\"link\">";
2255 if ($action eq 'commitdiff') {
2258 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2261 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
2262 hash_base
=>$parent, file_name
=>$diff{'file'})},
2265 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2266 file_name
=>$diff{'file'})},
2269 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2270 file_name
=>$diff{'file'})},
2274 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
2275 my $mode_chnge = "";
2276 if ($diff{'from_mode'} != $diff{'to_mode'}) {
2277 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
2278 if ($from_file_type ne $to_file_type) {
2279 $mode_chnge .= " from $from_file_type to $to_file_type";
2281 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
2282 if ($from_mode_str && $to_mode_str) {
2283 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
2284 } elsif ($to_mode_str) {
2285 $mode_chnge .= " mode: $to_mode_str";
2288 $mode_chnge .= "]</span>\n";
2291 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2292 hash_base
=>$hash, file_name
=>$diff{'file'}),
2293 -class => "list"}, esc_path
($diff{'file'}));
2295 print "<td>$mode_chnge</td>\n";
2296 print "<td class=\"link\">";
2297 if ($action eq 'commitdiff') {
2300 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2302 } elsif ($diff{'to_id'} ne $diff{'from_id'}) {
2303 # "commit" view and modified file (not onlu mode changed)
2304 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2305 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
2306 hash_base
=>$hash, hash_parent_base
=>$parent,
2307 file_name
=>$diff{'file'})},
2311 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2312 hash_base
=>$hash, file_name
=>$diff{'file'})},
2315 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2316 file_name
=>$diff{'file'})},
2319 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2320 file_name
=>$diff{'file'})},
2324 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
2325 my %status_name = ('R' => 'moved', 'C' => 'copied');
2326 my $nstatus = $status_name{$diff{'status'}};
2328 if ($diff{'from_mode'} != $diff{'to_mode'}) {
2329 # mode also for directories, so we cannot use $to_mode_str
2330 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
2333 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2334 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
2335 -class => "list"}, esc_path
($diff{'to_file'})) . "</td>\n" .
2336 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
2337 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
2338 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
2339 -class => "list"}, esc_path
($diff{'from_file'})) .
2340 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
2341 "<td class=\"link\">";
2342 if ($action eq 'commitdiff') {
2345 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2347 } elsif ($diff{'to_id'} ne $diff{'from_id'}) {
2348 # "commit" view and modified file (not only pure rename or copy)
2349 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2350 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
2351 hash_base
=>$hash, hash_parent_base
=>$parent,
2352 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
2356 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2357 hash_base
=>$parent, file_name
=>$diff{'to_file'})},
2360 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2361 file_name
=>$diff{'to_file'})},
2364 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2365 file_name
=>$diff{'to_file'})},
2369 } # we should not encounter Unmerged (U) or Unknown (X) status
2375 sub git_patchset_body
{
2376 my ($fd, $difftree, $hash, $hash_parent) = @_;
2382 my ($from_id, $to_id);
2384 print "<div class=\"patchset\">\n";
2386 # skip to first patch
2387 while ($patch_line = <$fd>) {
2390 last if ($patch_line =~ m/^diff /);
2394 while ($patch_line) {
2398 #assert($patch_line =~ m/^diff /) if DEBUG;
2399 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
2400 push @diff_header, $patch_line;
2402 # extended diff header
2404 while ($patch_line = <$fd>) {
2407 last EXTENDED_HEADER
if ($patch_line =~ m/^--- /);
2409 if ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2414 push @diff_header, $patch_line;
2416 #last PATCH unless $patch_line;
2417 my $last_patch_line = $patch_line;
2419 # check if current patch belong to current raw line
2420 # and parse raw git-diff line if needed
2421 if (defined $diffinfo &&
2422 $diffinfo->{'from_id'} eq $from_id &&
2423 $diffinfo->{'to_id'} eq $to_id) {
2424 # this is split patch
2425 print "<div class=\"patch cont\">\n";
2427 # advance raw git-diff output if needed
2428 $patch_idx++ if defined $diffinfo;
2430 # read and prepare patch information
2431 if (ref($difftree->[$patch_idx]) eq "HASH") {
2432 # pre-parsed (or generated by hand)
2433 $diffinfo = $difftree->[$patch_idx];
2435 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
2437 $from{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
2438 $to{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
2439 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2440 $from{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2441 hash
=>$diffinfo->{'from_id'},
2442 file_name
=>$from{'file'});
2444 if ($diffinfo->{'status'} ne "D") { # not deleted file
2445 $to{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2446 hash
=>$diffinfo->{'to_id'},
2447 file_name
=>$to{'file'});
2449 # this is first patch for raw difftree line with $patch_idx index
2450 # we index @$difftree array from 0, but number patches from 1
2451 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
2454 # print "git diff" header
2455 $patch_line = shift @diff_header;
2456 $patch_line =~ s!^(diff (.*?) )"?a/.*$!$1!;
2457 if ($from{'href'}) {
2458 $patch_line .= $cgi->a({-href
=> $from{'href'}, -class => "path"},
2459 'a/' . esc_path
($from{'file'}));
2460 } else { # file was added
2461 $patch_line .= 'a/' . esc_path
($from{'file'});
2465 $patch_line .= $cgi->a({-href
=> $to{'href'}, -class => "path"},
2466 'b/' . esc_path
($to{'file'}));
2467 } else { # file was deleted
2468 $patch_line .= 'b/' . esc_path
($to{'file'});
2470 print "<div class=\"diff header\">$patch_line</div>\n";
2472 # print extended diff header
2473 print "<div class=\"diff extended_header\">\n" if (@diff_header > 0);
2475 foreach $patch_line (@diff_header) {
2477 if ($patch_line =~ s!^((copy|rename) from ).*$!$1! && $from{'href'}) {
2478 $patch_line .= $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2479 esc_path
($from{'file'}));
2481 if ($patch_line =~ s!^((copy|rename) to ).*$!$1! && $to{'href'}) {
2482 $patch_line = $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2483 esc_path
($to{'file'}));
2486 if ($patch_line =~ m/\s(\d{6})$/) {
2487 $patch_line .= '<span class="info"> (' .
2488 file_type_long
($1) .
2492 if ($patch_line =~ m/^index/) {
2493 my ($from_link, $to_link);
2494 if ($from{'href'}) {
2495 $from_link = $cgi->a({-href
=>$from{'href'}, -class=>"hash"},
2496 substr($diffinfo->{'from_id'},0,7));
2498 $from_link = '0' x
7;
2501 $to_link = $cgi->a({-href
=>$to{'href'}, -class=>"hash"},
2502 substr($diffinfo->{'to_id'},0,7));
2507 # my ($from_hash, $to_hash) =
2508 # ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/);
2509 # my ($from_id, $to_id) =
2510 # ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2511 # ($from_hash eq $from_id) && ($to_hash eq $to_id);
2513 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2514 $patch_line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
2516 print $patch_line . "<br/>\n";
2518 print "</div>\n" if (@diff_header > 0); # class="diff extended_header"
2520 # from-file/to-file diff header
2521 $patch_line = $last_patch_line;
2522 #assert($patch_line =~ m/^---/) if DEBUG;
2523 if ($from{'href'}) {
2524 $patch_line = '--- a/' .
2525 $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2526 esc_path
($from{'file'}));
2528 print "<div class=\"diff from_file\">$patch_line</div>\n";
2530 $patch_line = <$fd>;
2531 last PATCH
unless $patch_line;
2534 #assert($patch_line =~ m/^+++/) if DEBUG;
2536 $patch_line = '+++ b/' .
2537 $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2538 esc_path
($to{'file'}));
2540 print "<div class=\"diff to_file\">$patch_line</div>\n";
2544 while ($patch_line = <$fd>) {
2547 next PATCH
if ($patch_line =~ m/^diff /);
2549 print format_diff_line
($patch_line, \
%from, \
%to);
2553 print "</div>\n"; # class="patch"
2556 print "</div>\n"; # class="patchset"
2559 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2561 sub git_project_list_body
{
2562 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
2564 my ($check_forks) = gitweb_check_feature
('forks');
2567 foreach my $pr (@$projlist) {
2568 my (@aa) = git_get_last_activity
($pr->{'path'});
2572 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
2573 if (!defined $pr->{'descr'}) {
2574 my $descr = git_get_project_description
($pr->{'path'}) || "";
2575 $pr->{'descr_long'} = to_utf8
($descr);
2576 $pr->{'descr'} = chop_str
($descr, 25, 5);
2578 if (!defined $pr->{'owner'}) {
2579 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2582 my $pname = $pr->{'path'};
2583 if (($pname =~ s/\.git$//) &&
2584 ($pname !~ /\/$/) &&
2585 (-d
"$projectroot/$pname")) {
2586 $pr->{'forks'} = "-d $projectroot/$pname";
2592 push @projects, $pr;
2595 $order ||= "project";
2596 $from = 0 unless defined $from;
2597 $to = $#projects if (!defined $to || $#projects < $to);
2599 print "<table class=\"project_list\">\n";
2600 unless ($no_header) {
2603 print "<th></th>\n";
2605 if ($order eq "project") {
2606 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2607 print "<th>Project</th>\n";
2610 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2611 -class => "header"}, "Project") .
2614 if ($order eq "descr") {
2615 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2616 print "<th>Description</th>\n";
2619 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2620 -class => "header"}, "Description") .
2623 if ($order eq "owner") {
2624 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2625 print "<th>Owner</th>\n";
2628 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2629 -class => "header"}, "Owner") .
2632 if ($order eq "age") {
2633 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
2634 print "<th>Last Change</th>\n";
2637 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
2638 -class => "header"}, "Last Change") .
2641 print "<th></th>\n" .
2645 for (my $i = $from; $i <= $to; $i++) {
2646 my $pr = $projects[$i];
2648 print "<tr class=\"dark\">\n";
2650 print "<tr class=\"light\">\n";
2655 if ($pr->{'forks'}) {
2656 print "<!-- $pr->{'forks'} -->\n";
2657 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
2661 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2662 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2663 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2664 -class => "list", -title
=> $pr->{'descr_long'}},
2665 esc_html
($pr->{'descr'})) . "</td>\n" .
2666 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2667 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
2668 $pr->{'age_string'} . "</td>\n" .
2669 "<td class=\"link\">" .
2670 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2671 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2672 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
2673 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
2674 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
2678 if (defined $extra) {
2681 print "<td></td>\n";
2683 print "<td colspan=\"5\">$extra</td>\n" .
2689 sub git_shortlog_body
{
2690 # uses global variable $project
2691 my ($commitlist, $from, $to, $refs, $extra) = @_;
2693 my $have_snapshot = gitweb_have_snapshot
();
2695 $from = 0 unless defined $from;
2696 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
2698 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
2700 for (my $i = $from; $i <= $to; $i++) {
2701 my %co = %{$commitlist->[$i]};
2702 my $commit = $co{'id'};
2703 my $ref = format_ref_marker
($refs, $commit);
2705 print "<tr class=\"dark\">\n";
2707 print "<tr class=\"light\">\n";
2710 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
2711 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2712 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
2714 print format_subject_html
($co{'title'}, $co{'title_short'},
2715 href
(action
=>"commit", hash
=>$commit), $ref);
2717 "<td class=\"link\">" .
2718 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
2719 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
2720 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
2721 if ($have_snapshot) {
2722 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
2727 if (defined $extra) {
2729 "<td colspan=\"4\">$extra</td>\n" .
2735 sub git_history_body
{
2736 # Warning: assumes constant type (blob or tree) during history
2737 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
2739 $from = 0 unless defined $from;
2740 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
2742 print "<table class=\"history\" cellspacing=\"0\">\n";
2744 for (my $i = $from; $i <= $to; $i++) {
2745 my %co = %{$commitlist->[$i]};
2749 my $commit = $co{'id'};
2751 my $ref = format_ref_marker
($refs, $commit);
2754 print "<tr class=\"dark\">\n";
2756 print "<tr class=\"light\">\n";
2759 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2760 # shortlog uses chop_str($co{'author_name'}, 10)
2761 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2763 # originally git_history used chop_str($co{'title'}, 50)
2764 print format_subject_html
($co{'title'}, $co{'title_short'},
2765 href
(action
=>"commit", hash
=>$commit), $ref);
2767 "<td class=\"link\">" .
2768 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
2769 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
2771 if ($ftype eq 'blob') {
2772 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
2773 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2774 if (defined $blob_current && defined $blob_parent &&
2775 $blob_current ne $blob_parent) {
2777 $cgi->a({-href
=> href
(action
=>"blobdiff",
2778 hash
=>$blob_current, hash_parent
=>$blob_parent,
2779 hash_base
=>$hash_base, hash_parent_base
=>$commit,
2780 file_name
=>$file_name)},
2787 if (defined $extra) {
2789 "<td colspan=\"4\">$extra</td>\n" .
2796 # uses global variable $project
2797 my ($taglist, $from, $to, $extra) = @_;
2798 $from = 0 unless defined $from;
2799 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2801 print "<table class=\"tags\" cellspacing=\"0\">\n";
2803 for (my $i = $from; $i <= $to; $i++) {
2804 my $entry = $taglist->[$i];
2806 my $comment = $tag{'subject'};
2808 if (defined $comment) {
2809 $comment_short = chop_str
($comment, 30, 5);
2812 print "<tr class=\"dark\">\n";
2814 print "<tr class=\"light\">\n";
2817 print "<td><i>$tag{'age'}</i></td>\n" .
2819 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
2820 -class => "list name"}, esc_html
($tag{'name'})) .
2823 if (defined $comment) {
2824 print format_subject_html
($comment, $comment_short,
2825 href
(action
=>"tag", hash
=>$tag{'id'}));
2828 "<td class=\"selflink\">";
2829 if ($tag{'type'} eq "tag") {
2830 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
2835 "<td class=\"link\">" . " | " .
2836 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
2837 if ($tag{'reftype'} eq "commit") {
2838 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
2839 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
2840 } elsif ($tag{'reftype'} eq "blob") {
2841 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
2846 if (defined $extra) {
2848 "<td colspan=\"5\">$extra</td>\n" .
2854 sub git_heads_body
{
2855 # uses global variable $project
2856 my ($headlist, $head, $from, $to, $extra) = @_;
2857 $from = 0 unless defined $from;
2858 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
2860 print "<table class=\"heads\" cellspacing=\"0\">\n";
2862 for (my $i = $from; $i <= $to; $i++) {
2863 my $entry = $headlist->[$i];
2865 my $curr = $ref{'id'} eq $head;
2867 print "<tr class=\"dark\">\n";
2869 print "<tr class=\"light\">\n";
2872 print "<td><i>$ref{'age'}</i></td>\n" .
2873 ($curr ? "<td class=\"current_head\">" : "<td>") .
2874 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
2875 -class => "list name"},esc_html
($ref{'name'})) .
2877 "<td class=\"link\">" .
2878 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
2879 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
2880 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
2884 if (defined $extra) {
2886 "<td colspan=\"3\">$extra</td>\n" .
2892 sub git_search_grep_body
{
2893 my ($commitlist, $from, $to, $extra) = @_;
2894 $from = 0 unless defined $from;
2895 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
2897 print "<table class=\"grep\" cellspacing=\"0\">\n";
2899 for (my $i = $from; $i <= $to; $i++) {
2900 my %co = %{$commitlist->[$i]};
2904 my $commit = $co{'id'};
2906 print "<tr class=\"dark\">\n";
2908 print "<tr class=\"light\">\n";
2911 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2912 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2914 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
2915 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
2916 my $comment = $co{'comment'};
2917 foreach my $line (@$comment) {
2918 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2919 my $lead = esc_html
($1) || "";
2920 $lead = chop_str
($lead, 30, 10);
2921 my $match = esc_html
($2) || "";
2922 my $trail = esc_html
($3) || "";
2923 $trail = chop_str
($trail, 30, 10);
2924 my $text = "$lead<span class=\"match\">$match</span>$trail";
2925 print chop_str
($text, 80, 5) . "<br/>\n";
2929 "<td class=\"link\">" .
2930 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
2932 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
2936 if (defined $extra) {
2938 "<td colspan=\"3\">$extra</td>\n" .
2944 ## ======================================================================
2945 ## ======================================================================
2948 sub git_project_list
{
2949 my $order = $cgi->param('o');
2950 if (defined $order && $order !~ m/project|descr|owner|age/) {
2951 die_error
(undef, "Unknown order parameter");
2954 my @list = git_get_projects_list
();
2956 die_error
(undef, "No projects found");
2960 if (-f
$home_text) {
2961 print "<div class=\"index_include\">\n";
2962 open (my $fd, $home_text);
2967 git_project_list_body
(\
@list, $order);
2972 my $order = $cgi->param('o');
2973 if (defined $order && $order !~ m/project|descr|owner|age/) {
2974 die_error
(undef, "Unknown order parameter");
2977 my @list = git_get_projects_list
($project);
2979 die_error
(undef, "No forks found");
2983 git_print_page_nav
('','');
2984 git_print_header_div
('summary', "$project forks");
2985 git_project_list_body
(\
@list, $order);
2989 sub git_project_index
{
2990 my @projects = git_get_projects_list
($project);
2993 -type
=> 'text/plain',
2994 -charset
=> 'utf-8',
2995 -content_disposition
=> 'inline; filename="index.aux"');
2997 foreach my $pr (@projects) {
2998 if (!exists $pr->{'owner'}) {
2999 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}");
3002 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3003 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3004 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3005 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3009 print "$path $owner\n";
3014 my $descr = git_get_project_description
($project) || "none";
3015 my %co = parse_commit
("HEAD");
3016 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
3017 my $head = $co{'id'};
3019 my $owner = git_get_project_owner
($project);
3021 my $refs = git_get_references
();
3022 # These get_*_list functions return one more to allow us to see if
3023 # there are more ...
3024 my @taglist = git_get_tags_list
(16);
3025 my @headlist = git_get_heads_list
(16);
3027 my ($check_forks) = gitweb_check_feature
('forks');
3030 @forklist = git_get_projects_list
($project);
3034 git_print_page_nav
('summary','', $head);
3036 print "<div class=\"title\"> </div>\n";
3037 print "<table cellspacing=\"0\">\n" .
3038 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3039 "<tr><td>owner</td><td>$owner</td></tr>\n" .
3040 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3041 # use per project git URL list in $projectroot/$project/cloneurl
3042 # or make project git URL from git base URL and project name
3043 my $url_tag = "URL";
3044 my @url_list = git_get_project_url_list
($project);
3045 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3046 foreach my $git_url (@url_list) {
3047 next unless $git_url;
3048 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3053 if (-s
"$projectroot/$project/README.html") {
3054 if (open my $fd, "$projectroot/$project/README.html") {
3055 print "<div class=\"title\">readme</div>\n";
3056 print $_ while (<$fd>);
3061 # we need to request one more than 16 (0..15) to check if
3063 my @commitlist = parse_commits
($head, 17);
3064 git_print_header_div
('shortlog');
3065 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
3066 $#commitlist <= 15 ? undef :
3067 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
3070 git_print_header_div
('tags');
3071 git_tags_body
(\
@taglist, 0, 15,
3072 $#taglist <= 15 ? undef :
3073 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
3077 git_print_header_div
('heads');
3078 git_heads_body
(\
@headlist, $head, 0, 15,
3079 $#headlist <= 15 ? undef :
3080 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
3084 git_print_header_div
('forks');
3085 git_project_list_body
(\
@forklist, undef, 0, 15,
3086 $#forklist <= 15 ? undef :
3087 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
3095 my $head = git_get_head_hash
($project);
3097 git_print_page_nav
('','', $head,undef,$head);
3098 my %tag = parse_tag
($hash);
3099 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
3100 print "<div class=\"title_text\">\n" .
3101 "<table cellspacing=\"0\">\n" .
3103 "<td>object</td>\n" .
3104 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3105 $tag{'object'}) . "</td>\n" .
3106 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3107 $tag{'type'}) . "</td>\n" .
3109 if (defined($tag{'author'})) {
3110 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
3111 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
3112 print "<tr><td></td><td>" . $ad{'rfc2822'} .
3113 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
3116 print "</table>\n\n" .
3118 print "<div class=\"page_body\">";
3119 my $comment = $tag{'comment'};
3120 foreach my $line (@$comment) {
3122 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
3132 my ($have_blame) = gitweb_check_feature
('blame');
3134 die_error
('403 Permission denied', "Permission denied");
3136 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3137 $hash_base ||= git_get_head_hash
($project);
3138 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3139 my %co = parse_commit
($hash_base)
3140 or die_error
(undef, "Reading commit failed");
3141 if (!defined $hash) {
3142 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3143 or die_error
(undef, "Error looking up file");
3145 $ftype = git_get_type
($hash);
3146 if ($ftype !~ "blob") {
3147 die_error
("400 Bad Request", "Object is not a blob");
3149 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
3150 $file_name, $hash_base)
3151 or die_error
(undef, "Open git-blame failed");
3154 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3157 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3160 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3162 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3163 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3164 git_print_page_path
($file_name, $ftype, $hash_base);
3165 my @rev_color = (qw(light2 dark2));
3166 my $num_colors = scalar(@rev_color);
3167 my $current_color = 0;
3170 <div class="page_body">
3171 <table class="blame">
3172 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
3177 last unless defined $_;
3178 my ($full_rev, $orig_lineno, $lineno, $group_size) =
3179 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
3180 if (!exists $metainfo{$full_rev}) {
3181 $metainfo{$full_rev} = {};
3183 my $meta = $metainfo{$full_rev};
3186 if (/^(\S+) (.*)$/) {
3192 my $rev = substr($full_rev, 0, 8);
3193 my $author = $meta->{'author'};
3194 my %date = parse_date
($meta->{'author-time'},
3195 $meta->{'author-tz'});
3196 my $date = $date{'iso-tz'};
3198 $current_color = ++$current_color % $num_colors;
3200 print "<tr class=\"$rev_color[$current_color]\">\n";
3202 print "<td class=\"sha1\"";
3203 print " title=\"". esc_html
($author) . ", $date\"";
3204 print " rowspan=\"$group_size\"" if ($group_size > 1);
3206 print $cgi->a({-href
=> href
(action
=>"commit",
3208 file_name
=>$file_name)},
3212 my $blamed = href
(action
=> 'blame',
3213 file_name
=> $meta->{'filename'},
3214 hash_base
=> $full_rev);
3215 print "<td class=\"linenr\">";
3216 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
3218 -class => "linenr" },
3221 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
3227 or print "Reading blob failed\n";
3234 my ($have_blame) = gitweb_check_feature
('blame');
3236 die_error
('403 Permission denied', "Permission denied");
3238 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3239 $hash_base ||= git_get_head_hash
($project);
3240 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3241 my %co = parse_commit
($hash_base)
3242 or die_error
(undef, "Reading commit failed");
3243 if (!defined $hash) {
3244 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3245 or die_error
(undef, "Error lookup file");
3247 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
3248 or die_error
(undef, "Open git-annotate failed");
3251 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3254 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3257 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3259 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3260 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3261 git_print_page_path
($file_name, 'blob', $hash_base);
3262 print "<div class=\"page_body\">\n";
3264 <table class="blame">
3273 my @line_class = (qw(light dark));
3274 my $line_class_len = scalar (@line_class);
3275 my $line_class_num = $#line_class;
3276 while (my $line = <$fd>) {
3288 $line_class_num = ($line_class_num + 1) % $line_class_len;
3290 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
3297 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
3300 $short_rev = substr ($long_rev, 0, 8);
3301 $age = time () - $time;
3302 $age_str = age_string
($age);
3303 $age_str =~ s/ / /g;
3304 $age_class = age_class
($age);
3305 $author = esc_html
($author);
3306 $author =~ s/ / /g;
3308 $data = untabify
($data);
3309 $data = esc_html
($data);
3312 <tr class="$line_class[$line_class_num]">
3313 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
3314 <td class="$age_class">$age_str</td>
3316 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
3317 <td class="pre">$data</td>
3320 } # while (my $line = <$fd>)
3321 print "</table>\n\n";
3323 or print "Reading blob failed.\n";
3329 my $head = git_get_head_hash
($project);
3331 git_print_page_nav
('','', $head,undef,$head);
3332 git_print_header_div
('summary', $project);
3334 my @tagslist = git_get_tags_list
();
3336 git_tags_body
(\
@tagslist);
3342 my $head = git_get_head_hash
($project);
3344 git_print_page_nav
('','', $head,undef,$head);
3345 git_print_header_div
('summary', $project);
3347 my @headslist = git_get_heads_list
();
3349 git_heads_body
(\
@headslist, $head);
3354 sub git_blob_plain
{
3357 if (!defined $hash) {
3358 if (defined $file_name) {
3359 my $base = $hash_base || git_get_head_hash
($project);
3360 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3361 or die_error
(undef, "Error lookup file");
3363 die_error
(undef, "No file name defined");
3365 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3366 # blobs defined by non-textual hash id's can be cached
3371 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3372 or die_error
(undef, "Couldn't cat $file_name, $hash");
3374 $type ||= blob_mimetype
($fd, $file_name);
3376 # save as filename, even when no $file_name is given
3377 my $save_as = "$hash";
3378 if (defined $file_name) {
3379 $save_as = $file_name;
3380 } elsif ($type =~ m/^text\//) {
3387 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
3389 binmode STDOUT
, ':raw';
3391 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3399 if (!defined $hash) {
3400 if (defined $file_name) {
3401 my $base = $hash_base || git_get_head_hash
($project);
3402 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3403 or die_error
(undef, "Error lookup file");
3405 die_error
(undef, "No file name defined");
3407 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3408 # blobs defined by non-textual hash id's can be cached
3412 my ($have_blame) = gitweb_check_feature
('blame');
3413 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3414 or die_error
(undef, "Couldn't cat $file_name, $hash");
3415 my $mimetype = blob_mimetype
($fd, $file_name);
3416 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
3418 return git_blob_plain
($mimetype);
3420 # we can have blame only for text/* mimetype
3421 $have_blame &&= ($mimetype =~ m!^text/!);
3423 git_header_html
(undef, $expires);
3424 my $formats_nav = '';
3425 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3426 if (defined $file_name) {
3429 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
3430 hash
=>$hash, file_name
=>$file_name)},
3435 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3436 hash
=>$hash, file_name
=>$file_name)},
3439 $cgi->a({-href
=> href
(action
=>"blob_plain",
3440 hash
=>$hash, file_name
=>$file_name)},
3443 $cgi->a({-href
=> href
(action
=>"blob",
3444 hash_base
=>"HEAD", file_name
=>$file_name)},
3448 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
3450 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3451 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3453 print "<div class=\"page_nav\">\n" .
3454 "<br/><br/></div>\n" .
3455 "<div class=\"title\">$hash</div>\n";
3457 git_print_page_path
($file_name, "blob", $hash_base);
3458 print "<div class=\"page_body\">\n";
3459 if ($mimetype =~ m!^text/!) {
3461 while (my $line = <$fd>) {
3464 $line = untabify
($line);
3465 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
3466 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
3468 } elsif ($mimetype =~ m!^image/!) {
3469 print qq
!<img type
="$mimetype"!;
3471 print qq
! alt
="$file_name" title
="$file_name"!;
3474 href(action=>"blob_plain
", hash=>$hash,
3475 hash_base=>$hash_base, file_name=>$file_name) .
3479 or print "Reading blob failed.\n";
3485 my $have_snapshot = gitweb_have_snapshot
();
3487 if (!defined $hash_base) {
3488 $hash_base = "HEAD";
3490 if (!defined $hash) {
3491 if (defined $file_name) {
3492 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
3498 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
3499 or die_error
(undef, "Open git-ls-tree failed");
3500 my @entries = map { chomp; $_ } <$fd>;
3501 close $fd or die_error
(undef, "Reading tree failed");
3504 my $refs = git_get_references
();
3505 my $ref = format_ref_marker
($refs, $hash_base);
3508 my ($have_blame) = gitweb_check_feature
('blame');
3509 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3511 if (defined $file_name) {
3513 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3514 hash
=>$hash, file_name
=>$file_name)},
3516 $cgi->a({-href
=> href
(action
=>"tree",
3517 hash_base
=>"HEAD", file_name
=>$file_name)},
3520 if ($have_snapshot) {
3521 # FIXME: Should be available when we have no hash base as well.
3523 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
3526 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
3527 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
3530 print "<div class=\"page_nav\">\n";
3531 print "<br/><br/></div>\n";
3532 print "<div class=\"title\">$hash</div>\n";
3534 if (defined $file_name) {
3535 $basedir = $file_name;
3536 if ($basedir ne '' && substr($basedir, -1) ne '/') {
3540 git_print_page_path
($file_name, 'tree', $hash_base);
3541 print "<div class=\"page_body\">\n";
3542 print "<table cellspacing=\"0\">\n";
3544 # '..' (top directory) link if possible
3545 if (defined $hash_base &&
3546 defined $file_name && $file_name =~ m![^/]+$!) {
3548 print "<tr class=\"dark\">\n";
3550 print "<tr class=\"light\">\n";
3554 my $up = $file_name;
3555 $up =~ s!/?[^/]+$!!;
3556 undef $up unless $up;
3557 # based on git_print_tree_entry
3558 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
3559 print '<td class="list">';
3560 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
3564 print "<td class=\"link\"></td>\n";
3568 foreach my $line (@entries) {
3569 my %t = parse_ls_tree_line
($line, -z
=> 1);
3572 print "<tr class=\"dark\">\n";
3574 print "<tr class=\"light\">\n";
3578 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
3582 print "</table>\n" .
3588 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
3589 my $have_snapshot = (defined $ctype && defined $suffix);
3590 if (!$have_snapshot) {
3591 die_error
('403 Permission denied', "Permission denied");
3594 if (!defined $hash) {
3595 $hash = git_get_head_hash
($project);
3598 my $filename = basename
($project) . "-$hash.tar.$suffix";
3601 -type
=> "application/$ctype",
3602 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
3603 -status
=> '200 OK');
3605 my $git = git_cmd_str
();
3606 my $name = $project;
3607 $name =~ s/\047/\047\\\047\047/g;
3609 "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
3610 or die_error
(undef, "Execute git-tar-tree failed.");
3611 binmode STDOUT
, ':raw';
3613 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3619 my $head = git_get_head_hash
($project);
3620 if (!defined $hash) {
3623 if (!defined $page) {
3626 my $refs = git_get_references
();
3628 my @commitlist = parse_commits
($hash, 101, (100 * $page));
3630 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
3633 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
3636 my %co = parse_commit
($hash);
3638 git_print_header_div
('summary', $project);
3639 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
3641 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
3642 for (my $i = 0; $i <= $to; $i++) {
3643 my %co = %{$commitlist[$i]};
3645 my $commit = $co{'id'};
3646 my $ref = format_ref_marker
($refs, $commit);
3647 my %ad = parse_date
($co{'author_epoch'});
3648 git_print_header_div
('commit',
3649 "<span class=\"age\">$co{'age_string'}</span>" .
3650 esc_html
($co{'title'}) . $ref,
3652 print "<div class=\"title_text\">\n" .
3653 "<div class=\"log_link\">\n" .
3654 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
3656 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
3658 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
3661 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
3664 print "<div class=\"log_body\">\n";
3665 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
3668 if ($#commitlist >= 100) {
3669 print "<div class=\"page_nav\">\n";
3670 print $cgi->a({-href
=> href
(action
=>"log", hash
=>$hash, page
=>$page+1),
3671 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3678 $hash ||= $hash_base || "HEAD";
3679 my %co = parse_commit
($hash);
3681 die_error
(undef, "Unknown commit object");
3683 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3684 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
3686 my $parent = $co{'parent'};
3687 my $parents = $co{'parents'}; # listref
3689 # we need to prepare $formats_nav before any parameter munging
3691 if (!defined $parent) {
3693 $formats_nav .= '(initial)';
3694 } elsif (@$parents == 1) {
3695 # single parent commit
3698 $cgi->a({-href
=> href
(action
=>"commit",
3700 esc_html
(substr($parent, 0, 7))) .
3707 $cgi->a({-href
=> href
(action
=>"commitdiff",
3709 esc_html
(substr($_, 0, 7)));
3714 if (!defined $parent) {
3718 if (@$parents <= 1) {
3719 # difftree output is not printed for merges
3720 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
3721 @diff_opts, $parent, $hash, "--"
3722 or die_error
(undef, "Open git-diff-tree failed");
3723 @difftree = map { chomp; $_ } <$fd>;
3724 close $fd or die_error
(undef, "Reading git-diff-tree failed");
3727 # non-textual hash id's can be cached
3729 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3732 my $refs = git_get_references
();
3733 my $ref = format_ref_marker
($refs, $co{'id'});
3735 my $have_snapshot = gitweb_have_snapshot
();
3737 git_header_html
(undef, $expires);
3738 git_print_page_nav
('commit', '',
3739 $hash, $co{'tree'}, $hash,
3742 if (defined $co{'parent'}) {
3743 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
3745 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
3747 print "<div class=\"title_text\">\n" .
3748 "<table cellspacing=\"0\">\n";
3749 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
3751 "<td></td><td> $ad{'rfc2822'}";
3752 if ($ad{'hour_local'} < 6) {
3753 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3754 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3756 printf(" (%02d:%02d %s)",
3757 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3761 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
3762 print "<tr><td></td><td> $cd{'rfc2822'}" .
3763 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
3765 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
3768 "<td class=\"sha1\">" .
3769 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
3770 class => "list"}, $co{'tree'}) .
3772 "<td class=\"link\">" .
3773 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
3775 if ($have_snapshot) {
3777 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
3782 foreach my $par (@$parents) {
3785 "<td class=\"sha1\">" .
3786 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
3787 class => "list"}, $par) .
3789 "<td class=\"link\">" .
3790 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
3792 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
3799 print "<div class=\"page_body\">\n";
3800 git_print_log
($co{'comment'});
3803 if (@$parents <= 1) {
3804 # do not output difftree/whatchanged for merges
3805 git_difftree_body
(\
@difftree, $hash, $parent);
3812 # object is defined by:
3813 # - hash or hash_base alone
3814 # - hash_base and file_name
3817 # - hash or hash_base alone
3818 if ($hash || ($hash_base && !defined $file_name)) {
3819 my $object_id = $hash || $hash_base;
3821 my $git_command = git_cmd_str
();
3822 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
3823 or die_error
('404 Not Found', "Object does not exist");
3827 or die_error
('404 Not Found', "Object does not exist");
3829 # - hash_base and file_name
3830 } elsif ($hash_base && defined $file_name) {
3831 $file_name =~ s
,/+$,,;
3833 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
3834 or die_error
('404 Not Found', "Base object does not exist");
3836 # here errors should not hapen
3837 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
3838 or die_error
(undef, "Open git-ls-tree failed");
3842 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
3843 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
3844 die_error
('404 Not Found', "File or directory for given base does not exist");
3849 die_error
('404 Not Found', "Not enough information to find object");
3852 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
3853 hash
=>$hash, hash_base
=>$hash_base,
3854 file_name
=>$file_name),
3855 -status
=> '302 Found');
3859 my $format = shift || 'html';
3866 # preparing $fd and %diffinfo for git_patchset_body
3868 if (defined $hash_base && defined $hash_parent_base) {
3869 if (defined $file_name) {
3871 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3872 $hash_parent_base, $hash_base,
3874 or die_error
(undef, "Open git-diff-tree failed");
3875 @difftree = map { chomp; $_ } <$fd>;
3877 or die_error
(undef, "Reading git-diff-tree failed");
3879 or die_error
('404 Not Found', "Blob diff not found");
3881 } elsif (defined $hash &&
3882 $hash =~ /[0-9a-fA-F]{40}/) {
3883 # try to find filename from $hash
3885 # read filtered raw output
3886 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3887 $hash_parent_base, $hash_base, "--"
3888 or die_error
(undef, "Open git-diff-tree failed");
3890 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
3892 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
3893 map { chomp; $_ } <$fd>;
3895 or die_error
(undef, "Reading git-diff-tree failed");
3897 or die_error
('404 Not Found', "Blob diff not found");
3900 die_error
('404 Not Found', "Missing one of the blob diff parameters");
3903 if (@difftree > 1) {
3904 die_error
('404 Not Found', "Ambiguous blob diff specification");
3907 %diffinfo = parse_difftree_raw_line
($difftree[0]);
3908 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
3909 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
3911 $hash_parent ||= $diffinfo{'from_id'};
3912 $hash ||= $diffinfo{'to_id'};
3914 # non-textual hash id's can be cached
3915 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
3916 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
3921 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3922 '-p', $hash_parent_base, $hash_base,
3924 or die_error
(undef, "Open git-diff-tree failed");
3927 # old/legacy style URI
3928 if (!%diffinfo && # if new style URI failed
3929 defined $hash && defined $hash_parent) {
3930 # fake git-diff-tree raw output
3931 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
3932 $diffinfo{'from_id'} = $hash_parent;
3933 $diffinfo{'to_id'} = $hash;
3934 if (defined $file_name) {
3935 if (defined $file_parent) {
3936 $diffinfo{'status'} = '2';
3937 $diffinfo{'from_file'} = $file_parent;
3938 $diffinfo{'to_file'} = $file_name;
3939 } else { # assume not renamed
3940 $diffinfo{'status'} = '1';
3941 $diffinfo{'from_file'} = $file_name;
3942 $diffinfo{'to_file'} = $file_name;
3944 } else { # no filename given
3945 $diffinfo{'status'} = '2';
3946 $diffinfo{'from_file'} = $hash_parent;
3947 $diffinfo{'to_file'} = $hash;
3950 # non-textual hash id's can be cached
3951 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
3952 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3957 open $fd, "-|", git_cmd
(), "diff", '-p', @diff_opts,
3958 $hash_parent, $hash, "--"
3959 or die_error
(undef, "Open git-diff failed");
3961 die_error
('404 Not Found', "Missing one of the blob diff parameters")
3966 if ($format eq 'html') {
3968 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
3969 hash
=>$hash, hash_parent
=>$hash_parent,
3970 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
3971 file_name
=>$file_name, file_parent
=>$file_parent)},
3973 git_header_html
(undef, $expires);
3974 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3975 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3976 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3978 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
3979 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
3981 if (defined $file_name) {
3982 git_print_page_path
($file_name, "blob", $hash_base);
3984 print "<div class=\"page_path\"></div>\n";
3987 } elsif ($format eq 'plain') {
3989 -type
=> 'text/plain',
3990 -charset
=> 'utf-8',
3991 -expires
=> $expires,
3992 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
3994 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3997 die_error
(undef, "Unknown blobdiff format");
4001 if ($format eq 'html') {
4002 print "<div class=\"page_body\">\n";
4004 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4007 print "</div>\n"; # class="page_body"
4011 while (my $line = <$fd>) {
4012 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4013 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4017 last if $line =~ m!^\+\+\+!;
4025 sub git_blobdiff_plain
{
4026 git_blobdiff
('plain');
4029 sub git_commitdiff
{
4030 my $format = shift || 'html';
4031 $hash ||= $hash_base || "HEAD";
4032 my %co = parse_commit
($hash);
4034 die_error
(undef, "Unknown commit object");
4037 # we need to prepare $formats_nav before any parameter munging
4039 if ($format eq 'html') {
4041 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
4042 hash
=>$hash, hash_parent
=>$hash_parent)},
4045 if (defined $hash_parent) {
4046 # commitdiff with two commits given
4047 my $hash_parent_short = $hash_parent;
4048 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4049 $hash_parent_short = substr($hash_parent, 0, 7);
4053 $cgi->a({-href
=> href
(action
=>"commitdiff",
4054 hash
=>$hash_parent)},
4055 esc_html
($hash_parent_short)) .
4057 } elsif (!$co{'parent'}) {
4059 $formats_nav .= ' (initial)';
4060 } elsif (scalar @{$co{'parents'}} == 1) {
4061 # single parent commit
4064 $cgi->a({-href
=> href
(action
=>"commitdiff",
4065 hash
=>$co{'parent'})},
4066 esc_html
(substr($co{'parent'}, 0, 7))) .
4073 $cgi->a({-href
=> href
(action
=>"commitdiff",
4075 esc_html
(substr($_, 0, 7)));
4076 } @{$co{'parents'}} ) .
4081 if (!defined $hash_parent) {
4082 $hash_parent = $co{'parent'} || '--root';
4088 if ($format eq 'html') {
4089 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4090 "--no-commit-id", "--patch-with-raw", "--full-index",
4091 $hash_parent, $hash, "--"
4092 or die_error
(undef, "Open git-diff-tree failed");
4094 while (my $line = <$fd>) {
4096 # empty line ends raw part of diff-tree output
4098 push @difftree, $line;
4101 } elsif ($format eq 'plain') {
4102 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4103 '-p', $hash_parent, $hash, "--"
4104 or die_error
(undef, "Open git-diff-tree failed");
4107 die_error
(undef, "Unknown commitdiff format");
4110 # non-textual hash id's can be cached
4112 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4116 # write commit message
4117 if ($format eq 'html') {
4118 my $refs = git_get_references
();
4119 my $ref = format_ref_marker
($refs, $co{'id'});
4121 git_header_html
(undef, $expires);
4122 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
4123 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
4124 git_print_authorship
(\
%co);
4125 print "<div class=\"page_body\">\n";
4126 if (@{$co{'comment'}} > 1) {
4127 print "<div class=\"log\">\n";
4128 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
4129 print "</div>\n"; # class="log"
4132 } elsif ($format eq 'plain') {
4133 my $refs = git_get_references
("tags");
4134 my $tagname = git_get_rev_name_tags
($hash);
4135 my $filename = basename
($project) . "-$hash.patch";
4138 -type
=> 'text/plain',
4139 -charset
=> 'utf-8',
4140 -expires
=> $expires,
4141 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
4142 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4145 Date: $ad{'rfc2822'} ($ad{'tz_local'})
4146 Subject: $co{'title'}
4148 print "X-Git-Tag: $tagname\n" if $tagname;
4149 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4151 foreach my $line (@{$co{'comment'}}) {
4158 if ($format eq 'html') {
4159 git_difftree_body
(\
@difftree, $hash, $hash_parent);
4162 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
4164 print "</div>\n"; # class="page_body"
4167 } elsif ($format eq 'plain') {
4171 or print "Reading git-diff-tree failed\n";
4175 sub git_commitdiff_plain
{
4176 git_commitdiff
('plain');
4180 if (!defined $hash_base) {
4181 $hash_base = git_get_head_hash
($project);
4183 if (!defined $page) {
4187 my %co = parse_commit
($hash_base);
4189 die_error
(undef, "Unknown commit object");
4192 my $refs = git_get_references
();
4193 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
4195 if (!defined $hash && defined $file_name) {
4196 $hash = git_get_hash_by_path
($hash_base, $file_name);
4198 if (defined $hash) {
4199 $ftype = git_get_type
($hash);
4202 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), "--full-history", $file_name);
4204 my $paging_nav = '';
4207 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4208 file_name
=>$file_name)},
4210 $paging_nav .= " ⋅ " .
4211 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4212 file_name
=>$file_name, page
=>$page-1),
4213 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4215 $paging_nav .= "first";
4216 $paging_nav .= " ⋅ prev";
4218 if ($#commitlist >= 100) {
4219 $paging_nav .= " ⋅ " .
4220 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4221 file_name
=>$file_name, page
=>$page+1),
4222 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4224 $paging_nav .= " ⋅ next";
4227 if ($#commitlist >= 100) {
4229 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4230 file_name
=>$file_name, page
=>$page+1),
4231 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4235 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
4236 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4237 git_print_page_path
($file_name, $ftype, $hash_base);
4239 git_history_body
(\
@commitlist, 0, 99,
4240 $refs, $hash_base, $ftype, $next_link);
4246 my ($have_search) = gitweb_check_feature
('search');
4247 if (!$have_search) {
4248 die_error
('403 Permission denied', "Permission denied");
4250 if (!defined $searchtext) {
4251 die_error
(undef, "Text field empty");
4253 if (!defined $hash) {
4254 $hash = git_get_head_hash
($project);
4256 my %co = parse_commit
($hash);
4258 die_error
(undef, "Unknown commit object");
4260 if (!defined $page) {
4264 $searchtype ||= 'commit';
4265 if ($searchtype eq 'pickaxe') {
4266 # pickaxe may take all resources of your box and run for several minutes
4267 # with every query - so decide by yourself how public you make this feature
4268 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4269 if (!$have_pickaxe) {
4270 die_error
('403 Permission denied', "Permission denied");
4276 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
4278 if ($searchtype eq 'commit') {
4279 $greptype = "--grep=";
4280 } elsif ($searchtype eq 'author') {
4281 $greptype = "--author=";
4282 } elsif ($searchtype eq 'committer') {
4283 $greptype = "--committer=";
4285 $greptype .= $searchtext;
4286 my @commitlist = parse_commits
($hash, 101, (100 * $page), $greptype);
4288 my $paging_nav = '';
4291 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4292 searchtext
=>$searchtext, searchtype
=>$searchtype)},
4294 $paging_nav .= " ⋅ " .
4295 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4296 searchtext
=>$searchtext, searchtype
=>$searchtype,
4298 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4300 $paging_nav .= "first";
4301 $paging_nav .= " ⋅ prev";
4303 if ($#commitlist >= 100) {
4304 $paging_nav .= " ⋅ " .
4305 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4306 searchtext
=>$searchtext, searchtype
=>$searchtype,
4308 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4310 $paging_nav .= " ⋅ next";
4313 if ($#commitlist >= 100) {
4315 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4316 searchtext
=>$searchtext, searchtype
=>$searchtype,
4318 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4321 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
4322 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4323 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
4326 if ($searchtype eq 'pickaxe') {
4327 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
4328 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4330 print "<table cellspacing=\"0\">\n";
4333 my $git_command = git_cmd_str
();
4334 open my $fd, "-|", "$git_command rev-list $hash | " .
4335 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
4338 while (my $line = <$fd>) {
4339 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
4342 $set{'from_id'} = $3;
4344 $set{'id'} = $set{'to_id'};
4345 if ($set{'id'} =~ m/0{40}/) {
4346 $set{'id'} = $set{'from_id'};
4348 if ($set{'id'} =~ m/0{40}/) {
4352 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
4355 print "<tr class=\"dark\">\n";
4357 print "<tr class=\"light\">\n";
4360 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4361 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
4363 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4364 -class => "list subject"},
4365 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
4366 while (my $setref = shift @files) {
4368 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
4369 hash
=>$set{'id'}, file_name
=>$set{'file'}),
4371 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
4375 "<td class=\"link\">" .
4376 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4378 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4382 %co = parse_commit
($1);
4392 sub git_search_help
{
4394 git_print_page_nav
('','', $hash,$hash,$hash);
4397 <dt><b>commit</b></dt>
4398 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
4399 <dt><b>author</b></dt>
4400 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
4401 <dt><b>committer</b></dt>
4402 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
4404 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4405 if ($have_pickaxe) {
4407 <dt><b>pickaxe</b></dt>
4408 <dd>All commits that caused the string to appear or disappear from any file (changes that
4409 added, removed or "modified" the string) will be listed. This search can take a while and
4410 takes a lot of strain on the server, so please use it wisely.</dd>
4418 my $head = git_get_head_hash
($project);
4419 if (!defined $hash) {
4422 if (!defined $page) {
4425 my $refs = git_get_references
();
4427 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4429 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, (100 * ($page+1)));
4431 if ($#commitlist >= 100) {
4433 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
4434 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4438 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
4439 git_print_header_div
('summary', $project);
4441 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
4446 ## ......................................................................
4447 ## feeds (RSS, Atom; OPML)
4450 my $format = shift || 'atom';
4451 my ($have_blame) = gitweb_check_feature
('blame');
4453 # Atom: http://www.atomenabled.org/developers/syndication/
4454 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
4455 if ($format ne 'rss' && $format ne 'atom') {
4456 die_error
(undef, "Unknown web feed format");
4459 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
4460 my $head = $hash || 'HEAD';
4461 my @commitlist = parse_commits
($head, 150);
4465 my $content_type = "application/$format+xml";
4466 if (defined $cgi->http('HTTP_ACCEPT') &&
4467 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
4468 # browser (feed reader) prefers text/xml
4469 $content_type = 'text/xml';
4471 if (defined($commitlist[0])) {
4472 %latest_commit = %{$commitlist[0]};
4473 %latest_date = parse_date
($latest_commit{'author_epoch'});
4475 -type
=> $content_type,
4476 -charset
=> 'utf-8',
4477 -last_modified
=> $latest_date{'rfc2822'});
4480 -type
=> $content_type,
4481 -charset
=> 'utf-8');
4484 # Optimization: skip generating the body if client asks only
4485 # for Last-Modified date.
4486 return if ($cgi->request_method() eq 'HEAD');
4489 my $title = "$site_name - $project/$action";
4490 my $feed_type = 'log';
4491 if (defined $hash) {
4492 $title .= " - '$hash'";
4493 $feed_type = 'branch log';
4494 if (defined $file_name) {
4495 $title .= " :: $file_name";
4496 $feed_type = 'history';
4498 } elsif (defined $file_name) {
4499 $title .= " - $file_name";
4500 $feed_type = 'history';
4502 $title .= " $feed_type";
4503 my $descr = git_get_project_description
($project);
4504 if (defined $descr) {
4505 $descr = esc_html
($descr);
4507 $descr = "$project " .
4508 ($format eq 'rss' ? 'RSS' : 'Atom') .
4511 my $owner = git_get_project_owner
($project);
4512 $owner = esc_html
($owner);
4516 if (defined $file_name) {
4517 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
4518 } elsif (defined $hash) {
4519 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
4521 $alt_url = href
(-full
=>1, action
=>"summary");
4523 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
4524 if ($format eq 'rss') {
4526 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
4529 print "<title>$title</title>\n" .
4530 "<link>$alt_url</link>\n" .
4531 "<description>$descr</description>\n" .
4532 "<language>en</language>\n";
4533 } elsif ($format eq 'atom') {
4535 <feed xmlns="http://www.w3.org/2005/Atom">
4537 print "<title>$title</title>\n" .
4538 "<subtitle>$descr</subtitle>\n" .
4539 '<link rel="alternate" type="text/html" href="' .
4540 $alt_url . '" />' . "\n" .
4541 '<link rel="self" type="' . $content_type . '" href="' .
4542 $cgi->self_url() . '" />' . "\n" .
4543 "<id>" . href
(-full
=>1) . "</id>\n" .
4544 # use project owner for feed author
4545 "<author><name>$owner</name></author>\n";
4546 if (defined $favicon) {
4547 print "<icon>" . esc_url
($favicon) . "</icon>\n";
4549 if (defined $logo_url) {
4550 # not twice as wide as tall: 72 x 27 pixels
4551 print "<logo>" . esc_url
($logo) . "</logo>\n";
4553 if (! %latest_date) {
4554 # dummy date to keep the feed valid until commits trickle in:
4555 print "<updated>1970-01-01T00:00:00Z</updated>\n";
4557 print "<updated>$latest_date{'iso-8601'}</updated>\n";
4562 for (my $i = 0; $i <= $#commitlist; $i++) {
4563 my %co = %{$commitlist[$i]};
4564 my $commit = $co{'id'};
4565 # we read 150, we always show 30 and the ones more recent than 48 hours
4566 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
4569 my %cd = parse_date
($co{'author_epoch'});
4571 # get list of changed files
4572 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4573 $co{'parent'}, $co{'id'}, "--", (defined $file_name ? $file_name : ())
4575 my @difftree = map { chomp; $_ } <$fd>;
4579 # print element (entry, item)
4580 my $co_url = href
(-full
=>1, action
=>"commit", hash
=>$commit);
4581 if ($format eq 'rss') {
4583 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
4584 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
4585 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
4586 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
4587 "<link>$co_url</link>\n" .
4588 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
4589 "<content:encoded>" .
4591 } elsif ($format eq 'atom') {
4593 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
4594 "<updated>$cd{'iso-8601'}</updated>\n" .
4596 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
4597 if ($co{'author_email'}) {
4598 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
4600 print "</author>\n" .
4601 # use committer for contributor
4603 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
4604 if ($co{'committer_email'}) {
4605 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
4607 print "</contributor>\n" .
4608 "<published>$cd{'iso-8601'}</published>\n" .
4609 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
4610 "<id>$co_url</id>\n" .
4611 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
4612 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
4614 my $comment = $co{'comment'};
4616 foreach my $line (@$comment) {
4617 $line = esc_html
($line);
4620 print "</pre><ul>\n";
4621 foreach my $difftree_line (@difftree) {
4622 my %difftree = parse_difftree_raw_line
($difftree_line);
4623 next if !$difftree{'from_id'};
4625 my $file = $difftree{'file'} || $difftree{'to_file'};
4629 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
4630 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
4631 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
4632 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
4633 -title
=> "diff"}, 'D');
4635 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
4636 file_name
=>$file, hash_base
=>$commit),
4637 -title
=> "blame"}, 'B');
4639 # if this is not a feed of a file history
4640 if (!defined $file_name || $file_name ne $file) {
4641 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
4642 file_name
=>$file, hash
=>$commit),
4643 -title
=> "history"}, 'H');
4645 $file = esc_path
($file);
4649 if ($format eq 'rss') {
4650 print "</ul>]]>\n" .
4651 "</content:encoded>\n" .
4653 } elsif ($format eq 'atom') {
4654 print "</ul>\n</div>\n" .
4661 if ($format eq 'rss') {
4662 print "</channel>\n</rss>\n";
4663 } elsif ($format eq 'atom') {
4677 my @list = git_get_projects_list
();
4679 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
4681 <?xml version="1.0" encoding="utf-8"?>
4682 <opml version="1.0">
4684 <title>$site_name OPML Export</title>
4687 <outline text="git RSS feeds">
4690 foreach my $pr (@list) {
4692 my $head = git_get_head_hash
($proj{'path'});
4693 if (!defined $head) {
4696 $git_dir = "$projectroot/$proj{'path'}";
4697 my %co = parse_commit
($head);
4702 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
4703 my $rss = "$my_url?p=$proj{'path'};a=rss";
4704 my $html = "$my_url?p=$proj{'path'};a=summary";
4705 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";