3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI
qw(:standard :escapeHTML -nosticky);
13 use CGI
::Util
qw(unescape);
14 use CGI
::Carp
qw(fatalsToBrowser);
18 use File
::Basename
qw(basename);
19 binmode STDOUT
, ':utf8';
22 CGI-
>compile() if $ENV{'MOD_PERL'};
26 our $version = "++GIT_VERSION++";
27 our $my_url = $cgi->url();
28 our $my_uri = $cgi->url(-absolute
=> 1);
30 # core git executable to use
31 # this can just be "git" if your webserver has a sensible PATH
32 our $GIT = "++GIT_BINDIR++/git";
34 # absolute fs-path which will be prepended to the project path
35 #our $projectroot = "/pub/scm";
36 our $projectroot = "++GITWEB_PROJECTROOT++";
38 # target of the home link on top of all pages
39 our $home_link = $my_uri || "/";
41 # string of the home link on top of all pages
42 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
44 # name of your site or organization to appear in page titles
45 # replace this with something more descriptive for clearer bookmarks
46 our $site_name = "++GITWEB_SITENAME++"
47 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
49 # filename of html text to include at top of each page
50 our $site_header = "++GITWEB_SITE_HEADER++";
51 # html text to include at home page
52 our $home_text = "++GITWEB_HOMETEXT++";
53 # filename of html text to include at bottom of each page
54 our $site_footer = "++GITWEB_SITE_FOOTER++";
57 our @stylesheets = ("++GITWEB_CSS++");
58 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
59 our $stylesheet = undef;
61 # URI of GIT logo (72x27 size)
62 our $logo = "++GITWEB_LOGO++";
63 # URI of GIT favicon, assumed to be image/png type
64 our $favicon = "++GITWEB_FAVICON++";
66 # URI and label (title) of GIT logo link
67 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
68 #our $logo_label = "git documentation";
69 our $logo_url = "http://git.or.cz/";
70 our $logo_label = "git homepage";
72 # source of projects list
73 our $projects_list = "++GITWEB_LIST++";
75 # default order of projects list
76 # valid values are none, project, descr, owner, and age
77 our $default_projects_order = "project";
79 # show repository only if this file exists
80 # (only effective if this variable evaluates to true)
81 our $export_ok = "++GITWEB_EXPORT_OK++";
83 # only allow viewing of repositories also shown on the overview page
84 our $strict_export = "++GITWEB_STRICT_EXPORT++";
86 # list of git base URLs used for URL to where fetch project from,
87 # i.e. full URL is "$git_base_url/$project"
88 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
90 # default blob_plain mimetype and default charset for text/plain blob
91 our $default_blob_plain_mimetype = 'text/plain';
92 our $default_text_plain_charset = undef;
94 # file to use for guessing MIME types before trying /etc/mime.types
95 # (relative to the current git repository)
96 our $mimetypes_file = undef;
98 # assume this charset if line contains non-UTF-8 characters;
99 # it should be valid encoding (see Encoding::Supported(3pm) for list),
100 # for which encoding all byte sequences are valid, for example
101 # 'iso-8859-1' aka 'latin1' (it is decoded without checking, so it
102 # could be even 'utf-8' for the old behavior)
103 our $fallback_encoding = 'latin1';
105 # You define site-wide feature defaults here; override them with
106 # $GITWEB_CONFIG as necessary.
109 # 'sub' => feature-sub (subroutine),
110 # 'override' => allow-override (boolean),
111 # 'default' => [ default options...] (array reference)}
113 # if feature is overridable (it means that allow-override has true value),
114 # then feature-sub will be called with default options as parameters;
115 # return value of feature-sub indicates if to enable specified feature
117 # if there is no 'sub' key (no feature-sub), then feature cannot be
120 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
122 # Enable the 'blame' blob view, showing the last commit that modified
123 # each line in the file. This can be very CPU-intensive.
125 # To enable system wide have in $GITWEB_CONFIG
126 # $feature{'blame'}{'default'} = [1];
127 # To have project specific config enable override in $GITWEB_CONFIG
128 # $feature{'blame'}{'override'} = 1;
129 # and in project config gitweb.blame = 0|1;
131 'sub' => \
&feature_blame
,
135 # Enable the 'snapshot' link, providing a compressed tarball of any
136 # tree. This can potentially generate high traffic if you have large
139 # To disable system wide have in $GITWEB_CONFIG
140 # $feature{'snapshot'}{'default'} = [undef];
141 # To have project specific config enable override in $GITWEB_CONFIG
142 # $feature{'snapshot'}{'override'} = 1;
143 # and in project config gitweb.snapshot = none|gzip|bzip2|zip;
145 'sub' => \
&feature_snapshot
,
147 # => [content-encoding, suffix, program]
148 'default' => ['x-gzip', 'gz', 'gzip']},
150 # Enable text search, which will list the commits which match author,
151 # committer or commit text to a given string. Enabled by default.
152 # Project specific override is not supported.
157 # Enable grep search, which will list the files in currently selected
158 # tree containing the given string. Enabled by default. This can be
159 # potentially CPU-intensive, of course.
161 # To enable system wide have in $GITWEB_CONFIG
162 # $feature{'grep'}{'default'} = [1];
163 # To have project specific config enable override in $GITWEB_CONFIG
164 # $feature{'grep'}{'override'} = 1;
165 # and in project config gitweb.grep = 0|1;
170 # Enable the pickaxe search, which will list the commits that modified
171 # a given string in a file. This can be practical and quite faster
172 # alternative to 'blame', but still potentially CPU-intensive.
174 # To enable system wide have in $GITWEB_CONFIG
175 # $feature{'pickaxe'}{'default'} = [1];
176 # To have project specific config enable override in $GITWEB_CONFIG
177 # $feature{'pickaxe'}{'override'} = 1;
178 # and in project config gitweb.pickaxe = 0|1;
180 'sub' => \
&feature_pickaxe
,
184 # Make gitweb use an alternative format of the URLs which can be
185 # more readable and natural-looking: project name is embedded
186 # directly in the path and the query string contains other
187 # auxiliary information. All gitweb installations recognize
188 # URL in either format; this configures in which formats gitweb
191 # To enable system wide have in $GITWEB_CONFIG
192 # $feature{'pathinfo'}{'default'} = [1];
193 # Project specific override is not supported.
195 # Note that you will need to change the default location of CSS,
196 # favicon, logo and possibly other files to an absolute URL. Also,
197 # if gitweb.cgi serves as your indexfile, you will need to force
198 # $my_uri to contain the script name in your $GITWEB_CONFIG.
203 # Make gitweb consider projects in project root subdirectories
204 # to be forks of existing projects. Given project $projname.git,
205 # projects matching $projname/*.git will not be shown in the main
206 # projects list, instead a '+' mark will be added to $projname
207 # there and a 'forks' view will be enabled for the project, listing
208 # all the forks. If project list is taken from a file, forks have
209 # to be listed after the main project.
211 # To enable system wide have in $GITWEB_CONFIG
212 # $feature{'forks'}{'default'} = [1];
213 # Project specific override is not supported.
219 sub gitweb_check_feature
{
221 return unless exists $feature{$name};
222 my ($sub, $override, @defaults) = (
223 $feature{$name}{'sub'},
224 $feature{$name}{'override'},
225 @{$feature{$name}{'default'}});
226 if (!$override) { return @defaults; }
228 warn "feature $name is not overrideable";
231 return $sub->(@defaults);
235 my ($val) = git_get_project_config
('blame', '--bool');
237 if ($val eq 'true') {
239 } elsif ($val eq 'false') {
246 sub feature_snapshot
{
247 my ($ctype, $suffix, $command) = @_;
249 my ($val) = git_get_project_config
('snapshot');
251 if ($val eq 'gzip') {
252 return ('x-gzip', 'gz', 'gzip');
253 } elsif ($val eq 'bzip2') {
254 return ('x-bzip2', 'bz2', 'bzip2');
255 } elsif ($val eq 'zip') {
256 return ('x-zip', 'zip', '');
257 } elsif ($val eq 'none') {
261 return ($ctype, $suffix, $command);
264 sub gitweb_have_snapshot
{
265 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
266 my $have_snapshot = (defined $ctype && defined $suffix);
268 return $have_snapshot;
272 my ($val) = git_get_project_config
('grep', '--bool');
274 if ($val eq 'true') {
276 } elsif ($val eq 'false') {
283 sub feature_pickaxe
{
284 my ($val) = git_get_project_config
('pickaxe', '--bool');
286 if ($val eq 'true') {
288 } elsif ($val eq 'false') {
295 # checking HEAD file with -e is fragile if the repository was
296 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
298 sub check_head_link
{
300 my $headfile = "$dir/HEAD";
301 return ((-e
$headfile) ||
302 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
305 sub check_export_ok
{
307 return (check_head_link
($dir) &&
308 (!$export_ok || -e
"$dir/$export_ok"));
311 # rename detection options for git-diff and git-diff-tree
312 # - default is '-M', with the cost proportional to
313 # (number of removed files) * (number of new files).
314 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
315 # (number of changed files + number of removed files) * (number of new files)
316 # - even more costly is '-C', '--find-copies-harder' with cost
317 # (number of files in the original tree) * (number of new files)
318 # - one might want to include '-B' option, e.g. '-B', '-M'
319 our @diff_opts = ('-M'); # taken from git_commit
321 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
322 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
324 # version of the core git binary
325 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
327 $projects_list ||= $projectroot;
329 # ======================================================================
330 # input validation and dispatch
331 our $action = $cgi->param('a');
332 if (defined $action) {
333 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
334 die_error
(undef, "Invalid action parameter");
338 # parameters which are pathnames
339 our $project = $cgi->param('p');
340 if (defined $project) {
341 if (!validate_pathname
($project) ||
342 !(-d
"$projectroot/$project") ||
343 !check_head_link
("$projectroot/$project") ||
344 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
345 ($strict_export && !project_in_list
($project))) {
347 die_error
(undef, "No such project");
351 our $file_name = $cgi->param('f');
352 if (defined $file_name) {
353 if (!validate_pathname
($file_name)) {
354 die_error
(undef, "Invalid file parameter");
358 our $file_parent = $cgi->param('fp');
359 if (defined $file_parent) {
360 if (!validate_pathname
($file_parent)) {
361 die_error
(undef, "Invalid file parent parameter");
365 # parameters which are refnames
366 our $hash = $cgi->param('h');
368 if (!validate_refname
($hash)) {
369 die_error
(undef, "Invalid hash parameter");
373 our $hash_parent = $cgi->param('hp');
374 if (defined $hash_parent) {
375 if (!validate_refname
($hash_parent)) {
376 die_error
(undef, "Invalid hash parent parameter");
380 our $hash_base = $cgi->param('hb');
381 if (defined $hash_base) {
382 if (!validate_refname
($hash_base)) {
383 die_error
(undef, "Invalid hash base parameter");
387 our $hash_parent_base = $cgi->param('hpb');
388 if (defined $hash_parent_base) {
389 if (!validate_refname
($hash_parent_base)) {
390 die_error
(undef, "Invalid hash parent base parameter");
395 our $page = $cgi->param('pg');
397 if ($page =~ m/[^0-9]/) {
398 die_error
(undef, "Invalid page parameter");
402 our $searchtype = $cgi->param('st');
403 if (defined $searchtype) {
404 if ($searchtype =~ m/[^a-z]/) {
405 die_error
(undef, "Invalid searchtype parameter");
409 our $searchtext = $cgi->param('s');
411 if (defined $searchtext) {
412 if ($searchtype ne 'grep' and $searchtype ne 'pickaxe' and $searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\
@ ]/) {
413 die_error
(undef, "Invalid search parameter");
415 if (length($searchtext) < 2) {
416 die_error
(undef, "At least two characters are required for search parameter");
418 $search_regexp = quotemeta $searchtext;
421 # now read PATH_INFO and use it as alternative to parameters
422 sub evaluate_path_info
{
423 return if defined $project;
424 my $path_info = $ENV{"PATH_INFO"};
425 return if !$path_info;
426 $path_info =~ s
,^/+,,;
427 return if !$path_info;
428 # find which part of PATH_INFO is project
429 $project = $path_info;
431 while ($project && !check_head_link
("$projectroot/$project")) {
432 $project =~ s
,/*[^/]*$,,;
435 $project = validate_pathname
($project);
437 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
438 ($strict_export && !project_in_list
($project))) {
442 # do not change any parameters if an action is given using the query string
444 $path_info =~ s
,^$project/*,,;
445 my ($refname, $pathname) = split(/:/, $path_info, 2);
446 if (defined $pathname) {
447 # we got "project.git/branch:filename" or "project.git/branch:dir/"
448 # we could use git_get_type(branch:pathname), but it needs $git_dir
449 $pathname =~ s
,^/+,,;
450 if (!$pathname || substr($pathname, -1) eq "/") {
454 $action ||= "blob_plain";
456 $hash_base ||= validate_refname
($refname);
457 $file_name ||= validate_pathname
($pathname);
458 } elsif (defined $refname) {
459 # we got "project.git/branch"
460 $action ||= "shortlog";
461 $hash ||= validate_refname
($refname);
464 evaluate_path_info
();
466 # path to the current git repository
468 $git_dir = "$projectroot/$project" if $project;
472 "blame" => \
&git_blame2
,
473 "blobdiff" => \
&git_blobdiff
,
474 "blobdiff_plain" => \
&git_blobdiff_plain
,
475 "blob" => \
&git_blob
,
476 "blob_plain" => \
&git_blob_plain
,
477 "commitdiff" => \
&git_commitdiff
,
478 "commitdiff_plain" => \
&git_commitdiff_plain
,
479 "commit" => \
&git_commit
,
480 "forks" => \
&git_forks
,
481 "heads" => \
&git_heads
,
482 "history" => \
&git_history
,
485 "atom" => \
&git_atom
,
486 "search" => \
&git_search
,
487 "search_help" => \
&git_search_help
,
488 "shortlog" => \
&git_shortlog
,
489 "summary" => \
&git_summary
,
491 "tags" => \
&git_tags
,
492 "tree" => \
&git_tree
,
493 "snapshot" => \
&git_snapshot
,
494 "object" => \
&git_object
,
495 # those below don't need $project
496 "opml" => \
&git_opml
,
497 "project_list" => \
&git_project_list
,
498 "project_index" => \
&git_project_index
,
501 if (!defined $action) {
503 $action = git_get_type
($hash);
504 } elsif (defined $hash_base && defined $file_name) {
505 $action = git_get_type
("$hash_base:$file_name");
506 } elsif (defined $project) {
509 $action = 'project_list';
512 if (!defined($actions{$action})) {
513 die_error
(undef, "Unknown action");
515 if ($action !~ m/^(opml|project_list|project_index)$/ &&
517 die_error
(undef, "Project needed");
519 $actions{$action}->();
522 ## ======================================================================
527 # default is to use -absolute url() i.e. $my_uri
528 my $href = $params{-full
} ? $my_url : $my_uri;
530 # XXX: Warning: If you touch this, check the search form for updating,
541 hash_parent_base
=> "hpb",
547 my %mapping = @mapping;
549 $params{'project'} = $project unless exists $params{'project'};
551 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
553 # use PATH_INFO for project name
554 $href .= "/$params{'project'}" if defined $params{'project'};
555 delete $params{'project'};
557 # Summary just uses the project path URL
558 if (defined $params{'action'} && $params{'action'} eq 'summary') {
559 delete $params{'action'};
563 # now encode the parameters explicitly
565 for (my $i = 0; $i < @mapping; $i += 2) {
566 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
567 if (defined $params{$name}) {
568 push @result, $symbol . "=" . esc_param
($params{$name});
571 $href .= "?" . join(';', @result) if scalar @result;
577 ## ======================================================================
578 ## validation, quoting/unquoting and escaping
580 sub validate_pathname
{
581 my $input = shift || return undef;
583 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
584 # at the beginning, at the end, and between slashes.
585 # also this catches doubled slashes
586 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
590 if ($input =~ m!\0!) {
596 sub validate_refname
{
597 my $input = shift || return undef;
599 # textual hashes are O.K.
600 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
603 # it must be correct pathname
604 $input = validate_pathname
($input)
606 # restrictions on ref name according to git-check-ref-format
607 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
613 # decode sequences of octets in utf8 into Perl's internal form,
614 # which is utf-8 with utf8 flag set if needed. gitweb writes out
615 # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning
619 eval { $res = decode_utf8
($str, Encode
::FB_CROAK
); };
623 return decode
($fallback_encoding, $str, Encode
::FB_DEFAULT
);
627 # quote unsafe chars, but keep the slash, even when it's not
628 # correct, but quoted slashes look too horrible in bookmarks
631 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
637 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
640 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
646 # replace invalid utf8 character with SUBSTITUTION sequence
651 $str = to_utf8
($str);
652 $str = $cgi->escapeHTML($str);
653 if ($opts{'-nbsp'}) {
654 $str =~ s/ / /g;
656 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
660 # quote control characters and escape filename to HTML
665 $str = to_utf8
($str);
666 $str = $cgi->escapeHTML($str);
667 if ($opts{'-nbsp'}) {
668 $str =~ s/ / /g;
670 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
674 # Make control characters "printable", using character escape codes (CEC)
677 my %es = ( # character escape codes, aka escape sequences
678 "\t" => '\t', # tab (HT)
679 "\n" => '\n', # line feed (LF)
680 "\r" => '\r', # carrige return (CR)
681 "\f" => '\f', # form feed (FF)
682 "\b" => '\b', # backspace (BS)
683 "\a" => '\a', # alarm (bell) (BEL)
684 "\e" => '\e', # escape (ESC)
685 "\013" => '\v', # vertical tab (VT)
686 "\000" => '\0', # nul character (NUL)
688 my $chr = ( (exists $es{$cntrl})
690 : sprintf('\%03o', ord($cntrl)) );
691 return "<span class=\"cntrl\">$chr</span>";
694 # Alternatively use unicode control pictures codepoints,
695 # Unicode "printable representation" (PR)
698 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
699 return "<span class=\"cntrl\">$chr</span>";
702 # git may return quoted and escaped filenames
708 my %es = ( # character escape codes, aka escape sequences
709 't' => "\t", # tab (HT, TAB)
710 'n' => "\n", # newline (NL)
711 'r' => "\r", # return (CR)
712 'f' => "\f", # form feed (FF)
713 'b' => "\b", # backspace (BS)
714 'a' => "\a", # alarm (bell) (BEL)
715 'e' => "\e", # escape (ESC)
716 'v' => "\013", # vertical tab (VT)
719 if ($seq =~ m/^[0-7]{1,3}$/) {
720 # octal char sequence
721 return chr(oct($seq));
722 } elsif (exists $es{$seq}) {
723 # C escape sequence, aka character escape code
726 # quoted ordinary character
730 if ($str =~ m/^"(.*)"$/) {
733 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
738 # escape tabs (convert tabs to spaces)
742 while ((my $pos = index($line, "\t")) != -1) {
743 if (my $count = (8 - ($pos % 8))) {
744 my $spaces = ' ' x
$count;
745 $line =~ s/\t/$spaces/;
752 sub project_in_list
{
754 my @list = git_get_projects_list
();
755 return @list && scalar(grep { $_->{'path'} eq $project } @list);
758 ## ----------------------------------------------------------------------
759 ## HTML aware string manipulation
764 my $add_len = shift || 10;
766 # allow only $len chars, but don't cut a word if it would fit in $add_len
767 # if it doesn't fit, cut it if it's still longer than the dots we would add
768 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@]{0,$add_len})(.*)/;
771 if (length($tail) > 4) {
773 $body =~ s/&[^;]*$//; # remove chopped character entities
778 ## ----------------------------------------------------------------------
779 ## functions returning short strings
781 # CSS class for given age value (in seconds)
787 } elsif ($age < 60*60*2) {
789 } elsif ($age < 60*60*24*2) {
796 # convert age in seconds to "nn units ago" string
801 if ($age > 60*60*24*365*2) {
802 $age_str = (int $age/60/60/24/365);
803 $age_str .= " years ago";
804 } elsif ($age > 60*60*24*(365/12)*2) {
805 $age_str = int $age/60/60/24/(365/12);
806 $age_str .= " months ago";
807 } elsif ($age > 60*60*24*7*2) {
808 $age_str = int $age/60/60/24/7;
809 $age_str .= " weeks ago";
810 } elsif ($age > 60*60*24*2) {
811 $age_str = int $age/60/60/24;
812 $age_str .= " days ago";
813 } elsif ($age > 60*60*2) {
814 $age_str = int $age/60/60;
815 $age_str .= " hours ago";
816 } elsif ($age > 60*2) {
817 $age_str = int $age/60;
818 $age_str .= " min ago";
821 $age_str .= " sec ago";
823 $age_str .= " right now";
828 # convert file mode in octal to symbolic file mode string
830 my $mode = oct shift;
832 if (S_ISDIR
($mode & S_IFMT
)) {
834 } elsif (S_ISLNK
($mode)) {
836 } elsif (S_ISREG
($mode)) {
837 # git cares only about the executable bit
838 if ($mode & S_IXUSR
) {
848 # convert file mode in octal to file type string
852 if ($mode !~ m/^[0-7]+$/) {
858 if (S_ISDIR
($mode & S_IFMT
)) {
860 } elsif (S_ISLNK
($mode)) {
862 } elsif (S_ISREG
($mode)) {
869 # convert file mode in octal to file type description string
873 if ($mode !~ m/^[0-7]+$/) {
879 if (S_ISDIR
($mode & S_IFMT
)) {
881 } elsif (S_ISLNK
($mode)) {
883 } elsif (S_ISREG
($mode)) {
884 if ($mode & S_IXUSR
) {
895 ## ----------------------------------------------------------------------
896 ## functions returning short HTML fragments, or transforming HTML fragments
897 ## which don't belong to other sections
899 # format line of commit message.
900 sub format_log_line_html
{
903 $line = esc_html
($line, -nbsp
=>1);
904 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
907 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
908 -class => "text"}, $hash_text);
909 $line =~ s/$hash_text/$link/;
914 # format marker of refs pointing to given object
915 sub format_ref_marker
{
916 my ($refs, $id) = @_;
919 if (defined $refs->{$id}) {
920 foreach my $ref (@{$refs->{$id}}) {
921 my ($type, $name) = qw();
922 # e.g. tags/v2.6.11 or heads/next
923 if ($ref =~ m!^(.*?)s?/(.*)$!) {
931 $markers .= " <span class=\"$type\" title=\"$ref\">" .
932 esc_html
($name) . "</span>";
937 return ' <span class="refs">'. $markers . '</span>';
943 # format, perhaps shortened and with markers, title line
944 sub format_subject_html
{
945 my ($long, $short, $href, $extra) = @_;
946 $extra = '' unless defined($extra);
948 if (length($short) < length($long)) {
949 return $cgi->a({-href
=> $href, -class => "list subject",
950 -title
=> to_utf8
($long)},
951 esc_html
($short) . $extra);
953 return $cgi->a({-href
=> $href, -class => "list subject"},
954 esc_html
($long) . $extra);
958 # format git diff header line, i.e. "diff --(git|combined|cc) ..."
959 sub format_git_diff_header_line
{
961 my $diffinfo = shift;
962 my ($from, $to) = @_;
964 if ($diffinfo->{'nparents'}) {
966 $line =~ s!^(diff (.*?) )"?.*$!$1!;
968 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
969 esc_path
($to->{'file'}));
970 } else { # file was deleted (no href)
971 $line .= esc_path
($to->{'file'});
975 $line =~ s!^(diff (.*?) )"?a/.*$!$1!;
976 if ($from->{'href'}) {
977 $line .= $cgi->a({-href
=> $from->{'href'}, -class => "path"},
978 'a/' . esc_path
($from->{'file'}));
979 } else { # file was added (no href)
980 $line .= 'a/' . esc_path
($from->{'file'});
984 $line .= $cgi->a({-href
=> $to->{'href'}, -class => "path"},
985 'b/' . esc_path
($to->{'file'}));
986 } else { # file was deleted
987 $line .= 'b/' . esc_path
($to->{'file'});
991 return "<div class=\"diff header\">$line</div>\n";
994 # format extended diff header line, before patch itself
995 sub format_extended_diff_header_line
{
997 my $diffinfo = shift;
998 my ($from, $to) = @_;
1001 if ($line =~ s!^((copy|rename) from ).*$!$1! && $from->{'href'}) {
1002 $line .= $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1003 esc_path
($from->{'file'}));
1005 if ($line =~ s!^((copy|rename) to ).*$!$1! && $to->{'href'}) {
1006 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1007 esc_path
($to->{'file'}));
1009 # match single <mode>
1010 if ($line =~ m/\s(\d{6})$/) {
1011 $line .= '<span class="info"> (' .
1012 file_type_long
($1) .
1016 if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
1017 # can match only for combined diff
1019 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1020 if ($from->{'href'}[$i]) {
1021 $line .= $cgi->a({-href
=>$from->{'href'}[$i],
1023 substr($diffinfo->{'from_id'}[$i],0,7));
1028 $line .= ',' if ($i < $diffinfo->{'nparents'} - 1);
1031 if ($to->{'href'}) {
1032 $line .= $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1033 substr($diffinfo->{'to_id'},0,7));
1038 } elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
1039 # can match only for ordinary diff
1040 my ($from_link, $to_link);
1041 if ($from->{'href'}) {
1042 $from_link = $cgi->a({-href
=>$from->{'href'}, -class=>"hash"},
1043 substr($diffinfo->{'from_id'},0,7));
1045 $from_link = '0' x
7;
1047 if ($to->{'href'}) {
1048 $to_link = $cgi->a({-href
=>$to->{'href'}, -class=>"hash"},
1049 substr($diffinfo->{'to_id'},0,7));
1053 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
1054 $line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
1057 return $line . "<br/>\n";
1060 # format from-file/to-file diff header
1061 sub format_diff_from_to_header
{
1062 my ($from_line, $to_line, $diffinfo, $from, $to, @parents) = @_;
1067 #assert($line =~ m/^---/) if DEBUG;
1068 # no extra formatting for "^--- /dev/null"
1069 if (! $diffinfo->{'nparents'}) {
1070 # ordinary (single parent) diff
1071 if ($line =~ m!^--- "?a/!) {
1072 if ($from->{'href'}) {
1074 $cgi->a({-href
=>$from->{'href'}, -class=>"path"},
1075 esc_path
($from->{'file'}));
1078 esc_path
($from->{'file'});
1081 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1084 # combined diff (merge commit)
1085 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1086 if ($from->{'href'}[$i]) {
1088 $cgi->a({-href
=>href
(action
=>"blobdiff",
1089 hash_parent
=>$diffinfo->{'from_id'}[$i],
1090 hash_parent_base
=>$parents[$i],
1091 file_parent
=>$from->{'file'}[$i],
1092 hash
=>$diffinfo->{'to_id'},
1094 file_name
=>$to->{'file'}),
1096 -title
=>"diff" . ($i+1)},
1099 $cgi->a({-href
=>$from->{'href'}[$i], -class=>"path"},
1100 esc_path
($from->{'file'}[$i]));
1102 $line = '--- /dev/null';
1104 $result .= qq
!<div
class="diff from_file">$line</div
>\n!;
1109 #assert($line =~ m/^\+\+\+/) if DEBUG;
1110 # no extra formatting for "^+++ /dev/null"
1111 if ($line =~ m!^\+\+\+ "?b/!) {
1112 if ($to->{'href'}) {
1114 $cgi->a({-href
=>$to->{'href'}, -class=>"path"},
1115 esc_path
($to->{'file'}));
1118 esc_path
($to->{'file'});
1121 $result .= qq
!<div
class="diff to_file">$line</div
>\n!;
1126 # create note for patch simplified by combined diff
1127 sub format_diff_cc_simplified
{
1128 my ($diffinfo, @parents) = @_;
1131 $result .= "<div class=\"diff header\">" .
1133 if (!is_deleted
($diffinfo)) {
1134 $result .= $cgi->a({-href
=> href
(action
=>"blob",
1136 hash
=>$diffinfo->{'to_id'},
1137 file_name
=>$diffinfo->{'to_file'}),
1139 esc_path
($diffinfo->{'to_file'}));
1141 $result .= esc_path
($diffinfo->{'to_file'});
1143 $result .= "</div>\n" . # class="diff header"
1144 "<div class=\"diff nodifferences\">" .
1146 "</div>\n"; # class="diff nodifferences"
1151 # format patch (diff) line (not to be used for diff headers)
1152 sub format_diff_line
{
1154 my ($from, $to) = @_;
1155 my $diff_class = "";
1159 if ($from && $to && ref($from->{'href'}) eq "ARRAY") {
1161 my $prefix = substr($line, 0, scalar @{$from->{'href'}});
1162 if ($line =~ m/^\@{3}/) {
1163 $diff_class = " chunk_header";
1164 } elsif ($line =~ m/^\\/) {
1165 $diff_class = " incomplete";
1166 } elsif ($prefix =~ tr/+/+/) {
1167 $diff_class = " add";
1168 } elsif ($prefix =~ tr/-/-/) {
1169 $diff_class = " rem";
1172 # assume ordinary diff
1173 my $char = substr($line, 0, 1);
1175 $diff_class = " add";
1176 } elsif ($char eq '-') {
1177 $diff_class = " rem";
1178 } elsif ($char eq '@') {
1179 $diff_class = " chunk_header";
1180 } elsif ($char eq "\\") {
1181 $diff_class = " incomplete";
1184 $line = untabify
($line);
1185 if ($from && $to && $line =~ m/^\@{2} /) {
1186 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
1187 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
1189 $from_lines = 0 unless defined $from_lines;
1190 $to_lines = 0 unless defined $to_lines;
1192 if ($from->{'href'}) {
1193 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
1194 -class=>"list"}, $from_text);
1196 if ($to->{'href'}) {
1197 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1198 -class=>"list"}, $to_text);
1200 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
1201 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1202 return "<div class=\"diff$diff_class\">$line</div>\n";
1203 } elsif ($from && $to && $line =~ m/^\@{3}/) {
1204 my ($prefix, $ranges, $section) = $line =~ m/^(\@+) (.*?) \@+(.*)$/;
1205 my (@from_text, @from_start, @from_nlines, $to_text, $to_start, $to_nlines);
1207 @from_text = split(' ', $ranges);
1208 for (my $i = 0; $i < @from_text; ++$i) {
1209 ($from_start[$i], $from_nlines[$i]) =
1210 (split(',', substr($from_text[$i], 1)), 0);
1213 $to_text = pop @from_text;
1214 $to_start = pop @from_start;
1215 $to_nlines = pop @from_nlines;
1217 $line = "<span class=\"chunk_info\">$prefix ";
1218 for (my $i = 0; $i < @from_text; ++$i) {
1219 if ($from->{'href'}[$i]) {
1220 $line .= $cgi->a({-href
=>"$from->{'href'}[$i]#l$from_start[$i]",
1221 -class=>"list"}, $from_text[$i]);
1223 $line .= $from_text[$i];
1227 if ($to->{'href'}) {
1228 $line .= $cgi->a({-href
=>"$to->{'href'}#l$to_start",
1229 -class=>"list"}, $to_text);
1233 $line .= " $prefix</span>" .
1234 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
1235 return "<div class=\"diff$diff_class\">$line</div>\n";
1237 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
1240 ## ----------------------------------------------------------------------
1241 ## git utility subroutines, invoking git commands
1243 # returns path to the core git executable and the --git-dir parameter as list
1245 return $GIT, '--git-dir='.$git_dir;
1248 # returns path to the core git executable and the --git-dir parameter as string
1250 return join(' ', git_cmd
());
1253 # get HEAD ref of given project as hash
1254 sub git_get_head_hash
{
1255 my $project = shift;
1256 my $o_git_dir = $git_dir;
1258 $git_dir = "$projectroot/$project";
1259 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
1262 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
1266 if (defined $o_git_dir) {
1267 $git_dir = $o_git_dir;
1272 # get type of given object
1276 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
1278 close $fd or return;
1283 sub git_get_project_config
{
1284 my ($key, $type) = @_;
1286 return unless ($key);
1287 $key =~ s/^gitweb\.//;
1288 return if ($key =~ m/\W/);
1290 my @x = (git_cmd
(), 'config');
1291 if (defined $type) { push @x, $type; }
1293 push @x, "gitweb.$key";
1299 # get hash of given path at given ref
1300 sub git_get_hash_by_path
{
1302 my $path = shift || return undef;
1307 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1308 or die_error
(undef, "Open git-ls-tree failed");
1310 close $fd or return undef;
1312 if (!defined $line) {
1313 # there is no tree or hash given by $path at $base
1317 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1318 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1319 if (defined $type && $type ne $2) {
1320 # type doesn't match
1326 # get path of entry with given hash at given tree-ish (ref)
1327 # used to get 'from' filename for combined diff (merge commit) for renames
1328 sub git_get_path_by_hash
{
1329 my $base = shift || return;
1330 my $hash = shift || return;
1334 open my $fd, "-|", git_cmd
(), "ls-tree", '-r', '-t', '-z', $base
1336 while (my $line = <$fd>) {
1339 #'040000 tree 595596a6a9117ddba9fe379b6b012b558bac8423 gitweb'
1340 #'100644 blob e02e90f0429be0d2a69b76571101f20b8f75530f gitweb/README'
1341 if ($line =~ m/(?:[0-9]+) (?:.+) $hash\t(.+)$/) {
1350 ## ......................................................................
1351 ## git utility functions, directly accessing git repository
1353 sub git_get_project_description
{
1356 open my $fd, "$projectroot/$path/description" or return undef;
1359 if (defined $descr) {
1365 sub git_get_project_url_list
{
1368 open my $fd, "$projectroot/$path/cloneurl" or return;
1369 my @git_project_url_list = map { chomp; $_ } <$fd>;
1372 return wantarray ? @git_project_url_list : \
@git_project_url_list;
1375 sub git_get_projects_list
{
1380 $filter =~ s/\.git$//;
1382 my ($check_forks) = gitweb_check_feature
('forks');
1384 if (-d
$projects_list) {
1385 # search in directory
1386 my $dir = $projects_list . ($filter ? "/$filter" : '');
1387 # remove the trailing "/"
1389 my $pfxlen = length("$dir");
1392 follow_fast
=> 1, # follow symbolic links
1393 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1395 # skip project-list toplevel, if we get it.
1396 return if (m!^[/.]$!);
1397 # only directories can be git repositories
1398 return unless (-d
$_);
1400 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1401 # we check related file in $projectroot
1402 if ($check_forks and $subdir =~ m
#/.#) {
1403 $File::Find
::prune
= 1;
1404 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1405 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
1406 $File::Find
::prune
= 1;
1411 } elsif (-f
$projects_list) {
1412 # read from file(url-encoded):
1413 # 'git%2Fgit.git Linus+Torvalds'
1414 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1415 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1417 open my ($fd), $projects_list or return;
1419 while (my $line = <$fd>) {
1421 my ($path, $owner) = split ' ', $line;
1422 $path = unescape
($path);
1423 $owner = unescape
($owner);
1424 if (!defined $path) {
1427 if ($filter ne '') {
1428 # looking for forks;
1429 my $pfx = substr($path, 0, length($filter));
1430 if ($pfx ne $filter) {
1433 my $sfx = substr($path, length($filter));
1434 if ($sfx !~ /^\/.*\
.git
$/) {
1437 } elsif ($check_forks) {
1439 foreach my $filter (keys %paths) {
1440 # looking for forks;
1441 my $pfx = substr($path, 0, length($filter));
1442 if ($pfx ne $filter) {
1445 my $sfx = substr($path, length($filter));
1446 if ($sfx !~ /^\/.*\
.git
$/) {
1449 # is a fork, don't include it in
1454 if (check_export_ok
("$projectroot/$path")) {
1457 owner
=> to_utf8
($owner),
1460 (my $forks_path = $path) =~ s/\.git$//;
1461 $paths{$forks_path}++;
1469 our $gitweb_project_owner = undef;
1470 sub git_get_project_list_from_file
{
1472 return if (defined $gitweb_project_owner);
1474 $gitweb_project_owner = {};
1475 # read from file (url-encoded):
1476 # 'git%2Fgit.git Linus+Torvalds'
1477 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1478 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1479 if (-f
$projects_list) {
1480 open (my $fd , $projects_list);
1481 while (my $line = <$fd>) {
1483 my ($pr, $ow) = split ' ', $line;
1484 $pr = unescape
($pr);
1485 $ow = unescape
($ow);
1486 $gitweb_project_owner->{$pr} = to_utf8
($ow);
1492 sub git_get_project_owner
{
1493 my $project = shift;
1496 return undef unless $project;
1498 if (!defined $gitweb_project_owner) {
1499 git_get_project_list_from_file
();
1502 if (exists $gitweb_project_owner->{$project}) {
1503 $owner = $gitweb_project_owner->{$project};
1505 if (!defined $owner) {
1506 $owner = get_file_owner
("$projectroot/$project");
1512 sub git_get_last_activity
{
1516 $git_dir = "$projectroot/$path";
1517 open($fd, "-|", git_cmd
(), 'for-each-ref',
1518 '--format=%(committer)',
1519 '--sort=-committerdate',
1521 'refs/heads') or return;
1522 my $most_recent = <$fd>;
1523 close $fd or return;
1524 if (defined $most_recent &&
1525 $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1527 my $age = time - $timestamp;
1528 return ($age, age_string
($age));
1530 return (undef, undef);
1533 sub git_get_references
{
1534 my $type = shift || "";
1536 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1537 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1538 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1539 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
1542 while (my $line = <$fd>) {
1544 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1545 if (defined $refs{$1}) {
1546 push @{$refs{$1}}, $2;
1552 close $fd or return;
1556 sub git_get_rev_name_tags
{
1557 my $hash = shift || return undef;
1559 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1561 my $name_rev = <$fd>;
1564 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1567 # catches also '$hash undefined' output
1572 ## ----------------------------------------------------------------------
1573 ## parse to hash functions
1577 my $tz = shift || "-0000";
1580 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1581 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1582 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1583 $date{'hour'} = $hour;
1584 $date{'minute'} = $min;
1585 $date{'mday'} = $mday;
1586 $date{'day'} = $days[$wday];
1587 $date{'month'} = $months[$mon];
1588 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1589 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1590 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1591 $mday, $months[$mon], $hour ,$min;
1592 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1593 1900+$year, $mon, $mday, $hour ,$min, $sec;
1595 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1596 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1597 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1598 $date{'hour_local'} = $hour;
1599 $date{'minute_local'} = $min;
1600 $date{'tz_local'} = $tz;
1601 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1602 1900+$year, $mon+1, $mday,
1603 $hour, $min, $sec, $tz);
1612 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1613 $tag{'id'} = $tag_id;
1614 while (my $line = <$fd>) {
1616 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1617 $tag{'object'} = $1;
1618 } elsif ($line =~ m/^type (.+)$/) {
1620 } elsif ($line =~ m/^tag (.+)$/) {
1622 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1623 $tag{'author'} = $1;
1626 } elsif ($line =~ m/--BEGIN/) {
1627 push @comment, $line;
1629 } elsif ($line eq "") {
1633 push @comment, <$fd>;
1634 $tag{'comment'} = \
@comment;
1635 close $fd or return;
1636 if (!defined $tag{'name'}) {
1642 sub parse_commit_text
{
1643 my ($commit_text, $withparents) = @_;
1644 my @commit_lines = split '\n', $commit_text;
1647 pop @commit_lines; # Remove '\0'
1649 if (! @commit_lines) {
1653 my $header = shift @commit_lines;
1654 if ($header !~ m/^[0-9a-fA-F]{40}/) {
1657 ($co{'id'}, my @parents) = split ' ', $header;
1658 while (my $line = shift @commit_lines) {
1659 last if $line eq "\n";
1660 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1662 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1664 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1666 $co{'author_epoch'} = $2;
1667 $co{'author_tz'} = $3;
1668 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1669 $co{'author_name'} = $1;
1670 $co{'author_email'} = $2;
1672 $co{'author_name'} = $co{'author'};
1674 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1675 $co{'committer'} = $1;
1676 $co{'committer_epoch'} = $2;
1677 $co{'committer_tz'} = $3;
1678 $co{'committer_name'} = $co{'committer'};
1679 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
1680 $co{'committer_name'} = $1;
1681 $co{'committer_email'} = $2;
1683 $co{'committer_name'} = $co{'committer'};
1687 if (!defined $co{'tree'}) {
1690 $co{'parents'} = \
@parents;
1691 $co{'parent'} = $parents[0];
1693 foreach my $title (@commit_lines) {
1696 $co{'title'} = chop_str
($title, 80, 5);
1697 # remove leading stuff of merges to make the interesting part visible
1698 if (length($title) > 50) {
1699 $title =~ s/^Automatic //;
1700 $title =~ s/^merge (of|with) /Merge ... /i;
1701 if (length($title) > 50) {
1702 $title =~ s/(http|rsync):\/\///;
1704 if (length($title) > 50) {
1705 $title =~ s/(master|www|rsync)\.//;
1707 if (length($title) > 50) {
1708 $title =~ s/kernel.org:?//;
1710 if (length($title) > 50) {
1711 $title =~ s/\/pub\/scm//;
1714 $co{'title_short'} = chop_str
($title, 50, 5);
1718 if ($co{'title'} eq "") {
1719 $co{'title'} = $co{'title_short'} = '(no commit message)';
1721 # remove added spaces
1722 foreach my $line (@commit_lines) {
1725 $co{'comment'} = \
@commit_lines;
1727 my $age = time - $co{'committer_epoch'};
1729 $co{'age_string'} = age_string
($age);
1730 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1731 if ($age > 60*60*24*7*2) {
1732 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1733 $co{'age_string_age'} = $co{'age_string'};
1735 $co{'age_string_date'} = $co{'age_string'};
1736 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1742 my ($commit_id) = @_;
1747 open my $fd, "-|", git_cmd
(), "rev-list",
1753 or die_error
(undef, "Open git-rev-list failed");
1754 %co = parse_commit_text
(<$fd>, 1);
1761 my ($commit_id, $maxcount, $skip, $arg, $filename) = @_;
1769 open my $fd, "-|", git_cmd
(), "rev-list",
1771 ($arg ? ($arg) : ()),
1772 ("--max-count=" . $maxcount),
1773 ("--skip=" . $skip),
1776 ($filename ? ($filename) : ())
1777 or die_error
(undef, "Open git-rev-list failed");
1778 while (my $line = <$fd>) {
1779 my %co = parse_commit_text
($line);
1784 return wantarray ? @cos : \
@cos;
1787 # parse ref from ref_file, given by ref_id, with given type
1789 my $ref_file = shift;
1791 my $type = shift || git_get_type
($ref_id);
1794 $ref_item{'type'} = $type;
1795 $ref_item{'id'} = $ref_id;
1796 $ref_item{'epoch'} = 0;
1797 $ref_item{'age'} = "unknown";
1798 if ($type eq "tag") {
1799 my %tag = parse_tag
($ref_id);
1800 $ref_item{'comment'} = $tag{'comment'};
1801 if ($tag{'type'} eq "commit") {
1802 my %co = parse_commit
($tag{'object'});
1803 $ref_item{'epoch'} = $co{'committer_epoch'};
1804 $ref_item{'age'} = $co{'age_string'};
1805 } elsif (defined($tag{'epoch'})) {
1806 my $age = time - $tag{'epoch'};
1807 $ref_item{'epoch'} = $tag{'epoch'};
1808 $ref_item{'age'} = age_string
($age);
1810 $ref_item{'reftype'} = $tag{'type'};
1811 $ref_item{'name'} = $tag{'name'};
1812 $ref_item{'refid'} = $tag{'object'};
1813 } elsif ($type eq "commit"){
1814 my %co = parse_commit
($ref_id);
1815 $ref_item{'reftype'} = "commit";
1816 $ref_item{'name'} = $ref_file;
1817 $ref_item{'title'} = $co{'title'};
1818 $ref_item{'refid'} = $ref_id;
1819 $ref_item{'epoch'} = $co{'committer_epoch'};
1820 $ref_item{'age'} = $co{'age_string'};
1822 $ref_item{'reftype'} = $type;
1823 $ref_item{'name'} = $ref_file;
1824 $ref_item{'refid'} = $ref_id;
1830 # parse line of git-diff-tree "raw" output
1831 sub parse_difftree_raw_line
{
1835 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1836 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1837 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1838 $res{'from_mode'} = $1;
1839 $res{'to_mode'} = $2;
1840 $res{'from_id'} = $3;
1842 $res{'status'} = $5;
1843 $res{'similarity'} = $6;
1844 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1845 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1847 $res{'file'} = unquote
($7);
1850 # '::100755 100755 100755 60e79ca1b01bc8b057abe17ddab484699a7f5fdb 94067cc5f73388f33722d52ae02f44692bc07490 94067cc5f73388f33722d52ae02f44692bc07490 MR git-gui/git-gui.sh'
1851 # combined diff (for merge commit)
1852 elsif ($line =~ s/^(::+)((?:[0-7]{6} )+)((?:[0-9a-fA-F]{40} )+)([a-zA-Z]+)\t(.*)$//) {
1853 $res{'nparents'} = length($1);
1854 $res{'from_mode'} = [ split(' ', $2) ];
1855 $res{'to_mode'} = pop @{$res{'from_mode'}};
1856 $res{'from_id'} = [ split(' ', $3) ];
1857 $res{'to_id'} = pop @{$res{'from_id'}};
1858 $res{'status'} = [ split('', $4) ];
1859 $res{'to_file'} = unquote
($5);
1861 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1862 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1863 $res{'commit'} = $1;
1866 return wantarray ? %res : \
%res;
1869 # parse line of git-ls-tree output
1870 sub parse_ls_tree_line
($;%) {
1875 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1876 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
1884 $res{'name'} = unquote
($4);
1887 return wantarray ? %res : \
%res;
1890 # generates _two_ hashes, references to which are passed as 2 and 3 argument
1891 sub parse_from_to_diffinfo
{
1892 my ($diffinfo, $from, $to, @parents) = @_;
1894 if ($diffinfo->{'nparents'}) {
1896 $from->{'file'} = [];
1897 $from->{'href'} = [];
1898 fill_from_file_info
($diffinfo, @parents)
1899 unless exists $diffinfo->{'from_file'};
1900 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
1901 $from->{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'};
1902 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
1903 $from->{'href'}[$i] = href
(action
=>"blob",
1904 hash_base
=>$parents[$i],
1905 hash
=>$diffinfo->{'from_id'}[$i],
1906 file_name
=>$from->{'file'}[$i]);
1908 $from->{'href'}[$i] = undef;
1912 $from->{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
1913 if ($diffinfo->{'status'} ne "A") { # not new (added) file
1914 $from->{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
1915 hash
=>$diffinfo->{'from_id'},
1916 file_name
=>$from->{'file'});
1918 delete $from->{'href'};
1922 $to->{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
1923 if (!is_deleted
($diffinfo)) { # file exists in result
1924 $to->{'href'} = href
(action
=>"blob", hash_base
=>$hash,
1925 hash
=>$diffinfo->{'to_id'},
1926 file_name
=>$to->{'file'});
1928 delete $to->{'href'};
1932 ## ......................................................................
1933 ## parse to array of hashes functions
1935 sub git_get_heads_list
{
1939 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1940 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
1941 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
1944 while (my $line = <$fd>) {
1948 my ($refinfo, $committerinfo) = split(/\0/, $line);
1949 my ($hash, $name, $title) = split(' ', $refinfo, 3);
1950 my ($committer, $epoch, $tz) =
1951 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
1952 $name =~ s!^refs/heads/!!;
1954 $ref_item{'name'} = $name;
1955 $ref_item{'id'} = $hash;
1956 $ref_item{'title'} = $title || '(no commit message)';
1957 $ref_item{'epoch'} = $epoch;
1959 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1961 $ref_item{'age'} = "unknown";
1964 push @headslist, \
%ref_item;
1968 return wantarray ? @headslist : \
@headslist;
1971 sub git_get_tags_list
{
1975 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1976 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
1977 '--format=%(objectname) %(objecttype) %(refname) '.
1978 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
1981 while (my $line = <$fd>) {
1985 my ($refinfo, $creatorinfo) = split(/\0/, $line);
1986 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
1987 my ($creator, $epoch, $tz) =
1988 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
1989 $name =~ s!^refs/tags/!!;
1991 $ref_item{'type'} = $type;
1992 $ref_item{'id'} = $id;
1993 $ref_item{'name'} = $name;
1994 if ($type eq "tag") {
1995 $ref_item{'subject'} = $title;
1996 $ref_item{'reftype'} = $reftype;
1997 $ref_item{'refid'} = $refid;
1999 $ref_item{'reftype'} = $type;
2000 $ref_item{'refid'} = $id;
2003 if ($type eq "tag" || $type eq "commit") {
2004 $ref_item{'epoch'} = $epoch;
2006 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
2008 $ref_item{'age'} = "unknown";
2012 push @tagslist, \
%ref_item;
2016 return wantarray ? @tagslist : \
@tagslist;
2019 ## ----------------------------------------------------------------------
2020 ## filesystem-related functions
2022 sub get_file_owner
{
2025 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
2026 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
2027 if (!defined $gcos) {
2031 $owner =~ s/[,;].*$//;
2032 return to_utf8
($owner);
2035 ## ......................................................................
2036 ## mimetype related functions
2038 sub mimetype_guess_file
{
2039 my $filename = shift;
2040 my $mimemap = shift;
2041 -r
$mimemap or return undef;
2044 open(MIME
, $mimemap) or return undef;
2046 next if m/^#/; # skip comments
2047 my ($mime, $exts) = split(/\t+/);
2048 if (defined $exts) {
2049 my @exts = split(/\s+/, $exts);
2050 foreach my $ext (@exts) {
2051 $mimemap{$ext} = $mime;
2057 $filename =~ /\.([^.]*)$/;
2058 return $mimemap{$1};
2061 sub mimetype_guess
{
2062 my $filename = shift;
2064 $filename =~ /\./ or return undef;
2066 if ($mimetypes_file) {
2067 my $file = $mimetypes_file;
2068 if ($file !~ m!^/!) { # if it is relative path
2069 # it is relative to project
2070 $file = "$projectroot/$project/$file";
2072 $mime = mimetype_guess_file
($filename, $file);
2074 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
2080 my $filename = shift;
2083 my $mime = mimetype_guess
($filename);
2084 $mime and return $mime;
2088 return $default_blob_plain_mimetype unless $fd;
2091 return 'text/plain' .
2092 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
2093 } elsif (! $filename) {
2094 return 'application/octet-stream';
2095 } elsif ($filename =~ m/\.png$/i) {
2097 } elsif ($filename =~ m/\.gif$/i) {
2099 } elsif ($filename =~ m/\.jpe?g$/i) {
2100 return 'image/jpeg';
2102 return 'application/octet-stream';
2106 ## ======================================================================
2107 ## functions printing HTML: header, footer, error page
2109 sub git_header_html
{
2110 my $status = shift || "200 OK";
2111 my $expires = shift;
2113 my $title = "$site_name";
2114 if (defined $project) {
2115 $title .= " - " . to_utf8
($project);
2116 if (defined $action) {
2117 $title .= "/$action";
2118 if (defined $file_name) {
2119 $title .= " - " . esc_path
($file_name);
2120 if ($action eq "tree" && $file_name !~ m
|/$|) {
2127 # require explicit support from the UA if we are to send the page as
2128 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
2129 # we have to do this because MSIE sometimes globs '*/*', pretending to
2130 # support xhtml+xml but choking when it gets what it asked for.
2131 if (defined $cgi->http('HTTP_ACCEPT') &&
2132 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
2133 $cgi->Accept('application/xhtml+xml') != 0) {
2134 $content_type = 'application/xhtml+xml';
2136 $content_type = 'text/html';
2138 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
2139 -status
=> $status, -expires
=> $expires);
2140 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
2142 <?xml version="1.0" encoding="utf-8"?>
2143 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2144 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
2145 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
2146 <!-- git core binaries version $git_version -->
2148 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
2149 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
2150 <meta name="robots" content="index, nofollow"/>
2151 <title>$title</title>
2153 # print out each stylesheet that exist
2154 if (defined $stylesheet) {
2155 #provides backwards capability for those people who define style sheet in a config file
2156 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2158 foreach my $stylesheet (@stylesheets) {
2159 next unless $stylesheet;
2160 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
2163 if (defined $project) {
2164 printf('<link rel="alternate" title="%s log RSS feed" '.
2165 'href="%s" type="application/rss+xml" />'."\n",
2166 esc_param
($project), href
(action
=>"rss"));
2167 printf('<link rel="alternate" title="%s log Atom feed" '.
2168 'href="%s" type="application/atom+xml" />'."\n",
2169 esc_param
($project), href
(action
=>"atom"));
2171 printf('<link rel="alternate" title="%s projects list" '.
2172 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
2173 $site_name, href
(project
=>undef, action
=>"project_index"));
2174 printf('<link rel="alternate" title="%s projects feeds" '.
2175 'href="%s" type="text/x-opml"/>'."\n",
2176 $site_name, href
(project
=>undef, action
=>"opml"));
2178 if (defined $favicon) {
2179 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
2185 if (-f
$site_header) {
2186 open (my $fd, $site_header);
2191 print "<div class=\"page_header\">\n" .
2192 $cgi->a({-href
=> esc_url
($logo_url),
2193 -title
=> $logo_label},
2194 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
2195 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
2196 if (defined $project) {
2197 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
2198 if (defined $action) {
2205 my ($have_search) = gitweb_check_feature
('search');
2206 if ((defined $project) && ($have_search)) {
2207 if (!defined $searchtext) {
2211 if (defined $hash_base) {
2212 $search_hash = $hash_base;
2213 } elsif (defined $hash) {
2214 $search_hash = $hash;
2216 $search_hash = "HEAD";
2218 my $action = $my_uri;
2219 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
2220 if ($use_pathinfo) {
2221 $action .= "/$project";
2223 $cgi->param("p", $project);
2225 $cgi->param("a", "search");
2226 $cgi->param("h", $search_hash);
2227 print $cgi->startform(-method => "get", -action
=> $action) .
2228 "<div class=\"search\">\n" .
2229 (!$use_pathinfo && $cgi->hidden(-name
=> "p") . "\n") .
2230 $cgi->hidden(-name
=> "a") . "\n" .
2231 $cgi->hidden(-name
=> "h") . "\n" .
2232 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
2233 -values => ['commit', 'grep', 'author', 'committer', 'pickaxe']) .
2234 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
2236 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
2238 $cgi->end_form() . "\n";
2242 sub git_footer_html
{
2243 print "<div class=\"page_footer\">\n";
2244 if (defined $project) {
2245 my $descr = git_get_project_description
($project);
2246 if (defined $descr) {
2247 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
2249 print $cgi->a({-href
=> href
(action
=>"rss"),
2250 -class => "rss_logo"}, "RSS") . " ";
2251 print $cgi->a({-href
=> href
(action
=>"atom"),
2252 -class => "rss_logo"}, "Atom") . "\n";
2254 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
2255 -class => "rss_logo"}, "OPML") . " ";
2256 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
2257 -class => "rss_logo"}, "TXT") . "\n";
2261 if (-f
$site_footer) {
2262 open (my $fd, $site_footer);
2272 my $status = shift || "403 Forbidden";
2273 my $error = shift || "Malformed query, file missing or permission denied";
2275 git_header_html
($status);
2277 <div class="page_body">
2287 ## ----------------------------------------------------------------------
2288 ## functions printing or outputting HTML: navigation
2290 sub git_print_page_nav
{
2291 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
2292 $extra = '' if !defined $extra; # pager or formats
2294 my @navs = qw(summary shortlog log commit commitdiff tree);
2296 @navs = grep { $_ ne $suppress } @navs;
2299 my %arg = map { $_ => {action
=>$_} } @navs;
2300 if (defined $head) {
2301 for (qw(commit commitdiff)) {
2302 $arg{$_}{'hash'} = $head;
2304 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
2305 for (qw(shortlog log)) {
2306 $arg{$_}{'hash'} = $head;
2310 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
2311 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
2313 print "<div class=\"page_nav\">\n" .
2315 map { $_ eq $current ?
2316 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
2318 print "<br/>\n$extra<br/>\n" .
2322 sub format_paging_nav
{
2323 my ($action, $hash, $head, $page, $nrevs) = @_;
2327 if ($hash ne $head || $page) {
2328 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
2330 $paging_nav .= "HEAD";
2334 $paging_nav .= " ⋅ " .
2335 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
2336 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2338 $paging_nav .= " ⋅ prev";
2341 if ($nrevs >= (100 * ($page+1)-1)) {
2342 $paging_nav .= " ⋅ " .
2343 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
2344 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2346 $paging_nav .= " ⋅ next";
2352 ## ......................................................................
2353 ## functions printing or outputting HTML: div
2355 sub git_print_header_div
{
2356 my ($action, $title, $hash, $hash_base) = @_;
2359 $args{'action'} = $action;
2360 $args{'hash'} = $hash if $hash;
2361 $args{'hash_base'} = $hash_base if $hash_base;
2363 print "<div class=\"header\">\n" .
2364 $cgi->a({-href
=> href
(%args), -class => "title"},
2365 $title ? $title : $action) .
2369 #sub git_print_authorship (\%) {
2370 sub git_print_authorship
{
2373 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
2374 print "<div class=\"author_date\">" .
2375 esc_html
($co->{'author_name'}) .
2377 if ($ad{'hour_local'} < 6) {
2378 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2379 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2381 printf(" (%02d:%02d %s)",
2382 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2387 sub git_print_page_path
{
2393 print "<div class=\"page_path\">";
2394 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
2395 -title
=> 'tree root'}, to_utf8
("[$project]"));
2397 if (defined $name) {
2398 my @dirname = split '/', $name;
2399 my $basename = pop @dirname;
2402 foreach my $dir (@dirname) {
2403 $fullname .= ($fullname ? '/' : '') . $dir;
2404 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2406 -title
=> $fullname}, esc_path
($dir));
2409 if (defined $type && $type eq 'blob') {
2410 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2412 -title
=> $name}, esc_path
($basename));
2413 } elsif (defined $type && $type eq 'tree') {
2414 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2416 -title
=> $name}, esc_path
($basename));
2419 print esc_path
($basename);
2422 print "<br/></div>\n";
2425 # sub git_print_log (\@;%) {
2426 sub git_print_log
($;%) {
2430 if ($opts{'-remove_title'}) {
2431 # remove title, i.e. first line of log
2434 # remove leading empty lines
2435 while (defined $log->[0] && $log->[0] eq "") {
2442 foreach my $line (@$log) {
2443 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2446 if (! $opts{'-remove_signoff'}) {
2447 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2450 # remove signoff lines
2457 # print only one empty line
2458 # do not print empty line after signoff
2460 next if ($empty || $signoff);
2466 print format_log_line_html
($line) . "<br/>\n";
2469 if ($opts{'-final_empty_line'}) {
2470 # end with single empty line
2471 print "<br/>\n" unless $empty;
2475 # return link target (what link points to)
2476 sub git_get_link_target
{
2481 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2485 $link_target = <$fd>;
2490 return $link_target;
2493 # given link target, and the directory (basedir) the link is in,
2494 # return target of link relative to top directory (top tree);
2495 # return undef if it is not possible (including absolute links).
2496 sub normalize_link_target
{
2497 my ($link_target, $basedir, $hash_base) = @_;
2499 # we can normalize symlink target only if $hash_base is provided
2500 return unless $hash_base;
2502 # absolute symlinks (beginning with '/') cannot be normalized
2503 return if (substr($link_target, 0, 1) eq '/');
2505 # normalize link target to path from top (root) tree (dir)
2508 $path = $basedir . '/' . $link_target;
2510 # we are in top (root) tree (dir)
2511 $path = $link_target;
2514 # remove //, /./, and /../
2516 foreach my $part (split('/', $path)) {
2517 # discard '.' and ''
2518 next if (!$part || $part eq '.');
2520 if ($part eq '..') {
2524 # link leads outside repository (outside top dir)
2528 push @path_parts, $part;
2531 $path = join('/', @path_parts);
2536 # print tree entry (row of git_tree), but without encompassing <tr> element
2537 sub git_print_tree_entry
{
2538 my ($t, $basedir, $hash_base, $have_blame) = @_;
2541 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2543 # The format of a table row is: mode list link. Where mode is
2544 # the mode of the entry, list is the name of the entry, an href,
2545 # and link is the action links of the entry.
2547 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2548 if ($t->{'type'} eq "blob") {
2549 print "<td class=\"list\">" .
2550 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2551 file_name
=>"$basedir$t->{'name'}", %base_key),
2552 -class => "list"}, esc_path
($t->{'name'}));
2553 if (S_ISLNK
(oct $t->{'mode'})) {
2554 my $link_target = git_get_link_target
($t->{'hash'});
2556 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2557 if (defined $norm_target) {
2559 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2560 file_name
=>$norm_target),
2561 -title
=> $norm_target}, esc_path
($link_target));
2563 print " -> " . esc_path
($link_target);
2568 print "<td class=\"link\">";
2569 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2570 file_name
=>"$basedir$t->{'name'}", %base_key)},
2574 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2575 file_name
=>"$basedir$t->{'name'}", %base_key)},
2578 if (defined $hash_base) {
2580 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2581 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2585 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2586 file_name
=>"$basedir$t->{'name'}")},
2590 } elsif ($t->{'type'} eq "tree") {
2591 print "<td class=\"list\">";
2592 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2593 file_name
=>"$basedir$t->{'name'}", %base_key)},
2594 esc_path
($t->{'name'}));
2596 print "<td class=\"link\">";
2597 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2598 file_name
=>"$basedir$t->{'name'}", %base_key)},
2600 if (defined $hash_base) {
2602 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2603 file_name
=>"$basedir$t->{'name'}")},
2610 ## ......................................................................
2611 ## functions printing large fragments of HTML
2613 sub fill_from_file_info
{
2614 my ($diff, @parents) = @_;
2616 $diff->{'from_file'} = [ ];
2617 $diff->{'from_file'}[$diff->{'nparents'} - 1] = undef;
2618 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2619 if ($diff->{'status'}[$i] eq 'R' ||
2620 $diff->{'status'}[$i] eq 'C') {
2621 $diff->{'from_file'}[$i] =
2622 git_get_path_by_hash
($parents[$i], $diff->{'from_id'}[$i]);
2629 # parameters can be strings, or references to arrays of strings
2633 if (ref($a) eq "ARRAY" && ref($b) eq "ARRAY" && @$a == @$b) {
2634 for (my $i = 0; $i < @$a; ++$i) {
2635 return 0 unless ($a->[$i] eq $b->[$i]);
2638 } elsif (!ref($a) && !ref($b)) {
2646 my $diffinfo = shift;
2648 return $diffinfo->{'to_id'} eq ('0' x
40);
2651 sub git_difftree_body
{
2652 my ($difftree, $hash, @parents) = @_;
2653 my ($parent) = $parents[0];
2654 my ($have_blame) = gitweb_check_feature
('blame');
2655 print "<div class=\"list_head\">\n";
2656 if ($#{$difftree} > 10) {
2657 print(($#{$difftree} + 1) . " files changed:\n");
2661 print "<table class=\"" .
2662 (@parents > 1 ? "combined " : "") .
2665 # header only for combined diff in 'commitdiff' view
2666 my $has_header = @parents > 1 && $action eq 'commitdiff';
2669 print "<thead><tr>\n" .
2670 "<th></th><th></th>\n"; # filename, patchN link
2671 for (my $i = 0; $i < @parents; $i++) {
2672 my $par = $parents[$i];
2674 $cgi->a({-href
=> href
(action
=>"commitdiff",
2675 hash
=>$hash, hash_parent
=>$par),
2676 -title
=> 'commitdiff to parent number ' .
2677 ($i+1) . ': ' . substr($par,0,7)},
2681 print "</tr></thead>\n<tbody>\n";
2686 foreach my $line (@{$difftree}) {
2688 if (ref($line) eq "HASH") {
2689 # pre-parsed (or generated by hand)
2692 $diff = parse_difftree_raw_line
($line);
2696 print "<tr class=\"dark\">\n";
2698 print "<tr class=\"light\">\n";
2702 if (exists $diff->{'nparents'}) { # combined diff
2704 fill_from_file_info
($diff, @parents)
2705 unless exists $diff->{'from_file'};
2707 if (!is_deleted
($diff)) {
2708 # file exists in the result (child) commit
2710 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2711 file_name
=>$diff->{'to_file'},
2713 -class => "list"}, esc_path
($diff->{'to_file'})) .
2717 esc_path
($diff->{'to_file'}) .
2721 if ($action eq 'commitdiff') {
2724 print "<td class=\"link\">" .
2725 $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2730 my $has_history = 0;
2731 my $not_deleted = 0;
2732 for (my $i = 0; $i < $diff->{'nparents'}; $i++) {
2733 my $hash_parent = $parents[$i];
2734 my $from_hash = $diff->{'from_id'}[$i];
2735 my $from_path = $diff->{'from_file'}[$i];
2736 my $status = $diff->{'status'}[$i];
2738 $has_history ||= ($status ne 'A');
2739 $not_deleted ||= ($status ne 'D');
2741 if ($status eq 'A') {
2742 print "<td class=\"link\" align=\"right\"> | </td>\n";
2743 } elsif ($status eq 'D') {
2744 print "<td class=\"link\">" .
2745 $cgi->a({-href
=> href
(action
=>"blob",
2748 file_name
=>$from_path)},
2752 if ($diff->{'to_id'} eq $from_hash) {
2753 print "<td class=\"link nochange\">";
2755 print "<td class=\"link\">";
2757 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2758 hash
=>$diff->{'to_id'},
2759 hash_parent
=>$from_hash,
2761 hash_parent_base
=>$hash_parent,
2762 file_name
=>$diff->{'to_file'},
2763 file_parent
=>$from_path)},
2769 print "<td class=\"link\">";
2771 print $cgi->a({-href
=> href
(action
=>"blob",
2772 hash
=>$diff->{'to_id'},
2773 file_name
=>$diff->{'to_file'},
2776 print " | " if ($has_history);
2779 print $cgi->a({-href
=> href
(action
=>"history",
2780 file_name
=>$diff->{'to_file'},
2787 next; # instead of 'else' clause, to avoid extra indent
2789 # else ordinary diff
2791 my ($to_mode_oct, $to_mode_str, $to_file_type);
2792 my ($from_mode_oct, $from_mode_str, $from_file_type);
2793 if ($diff->{'to_mode'} ne ('0' x
6)) {
2794 $to_mode_oct = oct $diff->{'to_mode'};
2795 if (S_ISREG
($to_mode_oct)) { # only for regular file
2796 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
2798 $to_file_type = file_type
($diff->{'to_mode'});
2800 if ($diff->{'from_mode'} ne ('0' x
6)) {
2801 $from_mode_oct = oct $diff->{'from_mode'};
2802 if (S_ISREG
($to_mode_oct)) { # only for regular file
2803 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
2805 $from_file_type = file_type
($diff->{'from_mode'});
2808 if ($diff->{'status'} eq "A") { # created
2809 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
2810 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
2811 $mode_chng .= "]</span>";
2813 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2814 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2815 -class => "list"}, esc_path
($diff->{'file'}));
2817 print "<td>$mode_chng</td>\n";
2818 print "<td class=\"link\">";
2819 if ($action eq 'commitdiff') {
2822 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2825 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2826 hash_base
=>$hash, file_name
=>$diff->{'file'})},
2830 } elsif ($diff->{'status'} eq "D") { # deleted
2831 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
2833 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2834 hash_base
=>$parent, file_name
=>$diff->{'file'}),
2835 -class => "list"}, esc_path
($diff->{'file'}));
2837 print "<td>$mode_chng</td>\n";
2838 print "<td class=\"link\">";
2839 if ($action eq 'commitdiff') {
2842 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2845 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'from_id'},
2846 hash_base
=>$parent, file_name
=>$diff->{'file'})},
2849 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2850 file_name
=>$diff->{'file'})},
2853 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2854 file_name
=>$diff->{'file'})},
2858 } elsif ($diff->{'status'} eq "M" || $diff->{'status'} eq "T") { # modified, or type changed
2859 my $mode_chnge = "";
2860 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2861 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
2862 if ($from_file_type ne $to_file_type) {
2863 $mode_chnge .= " from $from_file_type to $to_file_type";
2865 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
2866 if ($from_mode_str && $to_mode_str) {
2867 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
2868 } elsif ($to_mode_str) {
2869 $mode_chnge .= " mode: $to_mode_str";
2872 $mode_chnge .= "]</span>\n";
2875 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2876 hash_base
=>$hash, file_name
=>$diff->{'file'}),
2877 -class => "list"}, esc_path
($diff->{'file'}));
2879 print "<td>$mode_chnge</td>\n";
2880 print "<td class=\"link\">";
2881 if ($action eq 'commitdiff') {
2884 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2886 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
2887 # "commit" view and modified file (not onlu mode changed)
2888 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2889 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
2890 hash_base
=>$hash, hash_parent_base
=>$parent,
2891 file_name
=>$diff->{'file'})},
2895 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2896 hash_base
=>$hash, file_name
=>$diff->{'file'})},
2899 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2900 file_name
=>$diff->{'file'})},
2903 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2904 file_name
=>$diff->{'file'})},
2908 } elsif ($diff->{'status'} eq "R" || $diff->{'status'} eq "C") { # renamed or copied
2909 my %status_name = ('R' => 'moved', 'C' => 'copied');
2910 my $nstatus = $status_name{$diff->{'status'}};
2912 if ($diff->{'from_mode'} != $diff->{'to_mode'}) {
2913 # mode also for directories, so we cannot use $to_mode_str
2914 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
2917 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2918 hash
=>$diff->{'to_id'}, file_name
=>$diff->{'to_file'}),
2919 -class => "list"}, esc_path
($diff->{'to_file'})) . "</td>\n" .
2920 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
2921 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
2922 hash
=>$diff->{'from_id'}, file_name
=>$diff->{'from_file'}),
2923 -class => "list"}, esc_path
($diff->{'from_file'})) .
2924 " with " . (int $diff->{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
2925 "<td class=\"link\">";
2926 if ($action eq 'commitdiff') {
2929 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2931 } elsif ($diff->{'to_id'} ne $diff->{'from_id'}) {
2932 # "commit" view and modified file (not only pure rename or copy)
2933 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2934 hash
=>$diff->{'to_id'}, hash_parent
=>$diff->{'from_id'},
2935 hash_base
=>$hash, hash_parent_base
=>$parent,
2936 file_name
=>$diff->{'to_file'}, file_parent
=>$diff->{'from_file'})},
2940 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff->{'to_id'},
2941 hash_base
=>$parent, file_name
=>$diff->{'to_file'})},
2944 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2945 file_name
=>$diff->{'to_file'})},
2948 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2949 file_name
=>$diff->{'to_file'})},
2953 } # we should not encounter Unmerged (U) or Unknown (X) status
2956 print "</tbody>" if $has_header;
2960 sub git_patchset_body
{
2961 my ($fd, $difftree, $hash, @hash_parents) = @_;
2962 my ($hash_parent) = $hash_parents[0];
2965 my $patch_number = 0;
2970 print "<div class=\"patchset\">\n";
2972 # skip to first patch
2973 while ($patch_line = <$fd>) {
2976 last if ($patch_line =~ m/^diff /);
2980 while ($patch_line) {
2982 my ($from_id, $to_id);
2985 #assert($patch_line =~ m/^diff /) if DEBUG;
2986 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
2988 push @diff_header, $patch_line;
2990 # extended diff header
2992 while ($patch_line = <$fd>) {
2995 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
2997 if ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
3000 } elsif ($patch_line =~ m/^index ((?:[0-9a-fA-F]{40},)+[0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
3001 $from_id = [ split(',', $1) ];
3005 push @diff_header, $patch_line;
3007 my $last_patch_line = $patch_line;
3009 # check if current patch belong to current raw line
3010 # and parse raw git-diff line if needed
3011 if (defined $diffinfo &&
3012 defined $from_id && defined $to_id &&
3013 from_ids_eq
($diffinfo->{'from_id'}, $from_id) &&
3014 $diffinfo->{'to_id'} eq $to_id) {
3015 # this is continuation of a split patch
3016 print "<div class=\"patch cont\">\n";
3018 # advance raw git-diff output if needed
3019 $patch_idx++ if defined $diffinfo;
3021 # compact combined diff output can have some patches skipped
3022 # find which patch (using pathname of result) we are at now
3024 if ($diff_header[0] =~ m!^diff --cc "?(.*)"?$!) {
3029 # read and prepare patch information
3030 if (ref($difftree->[$patch_idx]) eq "HASH") {
3031 # pre-parsed (or generated by hand)
3032 $diffinfo = $difftree->[$patch_idx];
3034 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
3037 # check if current raw line has no patch (it got simplified)
3038 if (defined $to_name && $to_name ne $diffinfo->{'to_file'}) {
3039 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3040 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3041 "</div>\n"; # class="patch"
3046 } until (!defined $to_name || $to_name eq $diffinfo->{'to_file'} ||
3047 $patch_idx > $#$difftree);
3048 # modifies %from, %to hashes
3049 parse_from_to_diffinfo
($diffinfo, \
%from, \
%to, @hash_parents);
3050 if ($diffinfo->{'nparents'}) {
3054 fill_from_file_info
($diffinfo, @hash_parents)
3055 unless exists $diffinfo->{'from_file'};
3056 for (my $i = 0; $i < $diffinfo->{'nparents'}; $i++) {
3057 $from{'file'}[$i] = $diffinfo->{'from_file'}[$i] || $diffinfo->{'to_file'};
3058 if ($diffinfo->{'status'}[$i] ne "A") { # not new (added) file
3059 $from{'href'}[$i] = href
(action
=>"blob",
3060 hash_base
=>$hash_parents[$i],
3061 hash
=>$diffinfo->{'from_id'}[$i],
3062 file_name
=>$from{'file'}[$i]);
3064 $from{'href'}[$i] = undef;
3068 $from{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
3069 if ($diffinfo->{'status'} ne "A") { # not new (added) file
3070 $from{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
3071 hash
=>$diffinfo->{'from_id'},
3072 file_name
=>$from{'file'});
3074 delete $from{'href'};
3078 $to{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
3079 if (!is_deleted
($diffinfo)) { # file exists in result
3080 $to{'href'} = href
(action
=>"blob", hash_base
=>$hash,
3081 hash
=>$diffinfo->{'to_id'},
3082 file_name
=>$to{'file'});
3086 # this is first patch for raw difftree line with $patch_idx index
3087 # we index @$difftree array from 0, but number patches from 1
3088 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
3091 # print "git diff" header
3092 $patch_line = shift @diff_header;
3093 print format_git_diff_header_line
($patch_line, $diffinfo,
3096 # print extended diff header
3097 print "<div class=\"diff extended_header\">\n" if (@diff_header > 0);
3099 foreach $patch_line (@diff_header) {
3100 print format_extended_diff_header_line
($patch_line, $diffinfo,
3103 print "</div>\n" if (@diff_header > 0); # class="diff extended_header"
3105 # from-file/to-file diff header
3106 $patch_line = $last_patch_line;
3107 if (! $patch_line) {
3108 print "</div>\n"; # class="patch"
3111 next PATCH
if ($patch_line =~ m/^diff /);
3112 #assert($patch_line =~ m/^---/) if DEBUG;
3113 #assert($patch_line eq $last_patch_line) if DEBUG;
3115 $patch_line = <$fd>;
3117 #assert($patch_line =~ m/^\+\+\+/) if DEBUG;
3119 print format_diff_from_to_header
($last_patch_line, $patch_line,
3120 $diffinfo, \
%from, \
%to,
3125 while ($patch_line = <$fd>) {
3128 next PATCH
if ($patch_line =~ m/^diff /);
3130 print format_diff_line
($patch_line, \
%from, \
%to);
3134 print "</div>\n"; # class="patch"
3137 # for compact combined (--cc) format, with chunk and patch simpliciaction
3138 # patchset might be empty, but there might be unprocessed raw lines
3139 for ($patch_idx++ if $patch_number > 0;
3140 $patch_idx < @$difftree;
3142 # read and prepare patch information
3143 if (ref($difftree->[$patch_idx]) eq "HASH") {
3144 # pre-parsed (or generated by hand)
3145 $diffinfo = $difftree->[$patch_idx];
3147 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
3150 # generate anchor for "patch" links in difftree / whatchanged part
3151 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n" .
3152 format_diff_cc_simplified
($diffinfo, @hash_parents) .
3153 "</div>\n"; # class="patch"
3158 if ($patch_number == 0) {
3159 if (@hash_parents > 1) {
3160 print "<div class=\"diff nodifferences\">Trivial merge</div>\n";
3162 print "<div class=\"diff nodifferences\">No differences found</div>\n";
3166 print "</div>\n"; # class="patchset"
3169 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3171 sub git_project_list_body
{
3172 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
3174 my ($check_forks) = gitweb_check_feature
('forks');
3177 foreach my $pr (@$projlist) {
3178 my (@aa) = git_get_last_activity
($pr->{'path'});
3182 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
3183 if (!defined $pr->{'descr'}) {
3184 my $descr = git_get_project_description
($pr->{'path'}) || "";
3185 $pr->{'descr_long'} = to_utf8
($descr);
3186 $pr->{'descr'} = chop_str
($descr, 25, 5);
3188 if (!defined $pr->{'owner'}) {
3189 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}") || "";
3192 my $pname = $pr->{'path'};
3193 if (($pname =~ s/\.git$//) &&
3194 ($pname !~ /\/$/) &&
3195 (-d
"$projectroot/$pname")) {
3196 $pr->{'forks'} = "-d $projectroot/$pname";
3202 push @projects, $pr;
3205 $order ||= $default_projects_order;
3206 $from = 0 unless defined $from;
3207 $to = $#projects if (!defined $to || $#projects < $to);
3209 print "<table class=\"project_list\">\n";
3210 unless ($no_header) {
3213 print "<th></th>\n";
3215 if ($order eq "project") {
3216 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
3217 print "<th>Project</th>\n";
3220 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
3221 -class => "header"}, "Project") .
3224 if ($order eq "descr") {
3225 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
3226 print "<th>Description</th>\n";
3229 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
3230 -class => "header"}, "Description") .
3233 if ($order eq "owner") {
3234 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
3235 print "<th>Owner</th>\n";
3238 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
3239 -class => "header"}, "Owner") .
3242 if ($order eq "age") {
3243 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
3244 print "<th>Last Change</th>\n";
3247 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
3248 -class => "header"}, "Last Change") .
3251 print "<th></th>\n" .
3255 for (my $i = $from; $i <= $to; $i++) {
3256 my $pr = $projects[$i];
3258 print "<tr class=\"dark\">\n";
3260 print "<tr class=\"light\">\n";
3265 if ($pr->{'forks'}) {
3266 print "<!-- $pr->{'forks'} -->\n";
3267 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
3271 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3272 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
3273 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
3274 -class => "list", -title
=> $pr->{'descr_long'}},
3275 esc_html
($pr->{'descr'})) . "</td>\n" .
3276 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
3277 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
3278 (defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .
3279 "<td class=\"link\">" .
3280 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
3281 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
3282 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
3283 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
3284 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
3288 if (defined $extra) {
3291 print "<td></td>\n";
3293 print "<td colspan=\"5\">$extra</td>\n" .
3299 sub git_shortlog_body
{
3300 # uses global variable $project
3301 my ($commitlist, $from, $to, $refs, $extra) = @_;
3303 my $have_snapshot = gitweb_have_snapshot
();
3305 $from = 0 unless defined $from;
3306 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3308 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
3310 for (my $i = $from; $i <= $to; $i++) {
3311 my %co = %{$commitlist->[$i]};
3312 my $commit = $co{'id'};
3313 my $ref = format_ref_marker
($refs, $commit);
3315 print "<tr class=\"dark\">\n";
3317 print "<tr class=\"light\">\n";
3320 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
3321 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3322 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
3324 print format_subject_html
($co{'title'}, $co{'title_short'},
3325 href
(action
=>"commit", hash
=>$commit), $ref);
3327 "<td class=\"link\">" .
3328 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
3329 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
3330 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
3331 if ($have_snapshot) {
3332 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
3337 if (defined $extra) {
3339 "<td colspan=\"4\">$extra</td>\n" .
3345 sub git_history_body
{
3346 # Warning: assumes constant type (blob or tree) during history
3347 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
3349 $from = 0 unless defined $from;
3350 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
3352 print "<table class=\"history\" cellspacing=\"0\">\n";
3354 for (my $i = $from; $i <= $to; $i++) {
3355 my %co = %{$commitlist->[$i]};
3359 my $commit = $co{'id'};
3361 my $ref = format_ref_marker
($refs, $commit);
3364 print "<tr class=\"dark\">\n";
3366 print "<tr class=\"light\">\n";
3369 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3370 # shortlog uses chop_str($co{'author_name'}, 10)
3371 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
3373 # originally git_history used chop_str($co{'title'}, 50)
3374 print format_subject_html
($co{'title'}, $co{'title_short'},
3375 href
(action
=>"commit", hash
=>$commit), $ref);
3377 "<td class=\"link\">" .
3378 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
3379 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
3381 if ($ftype eq 'blob') {
3382 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
3383 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
3384 if (defined $blob_current && defined $blob_parent &&
3385 $blob_current ne $blob_parent) {
3387 $cgi->a({-href
=> href
(action
=>"blobdiff",
3388 hash
=>$blob_current, hash_parent
=>$blob_parent,
3389 hash_base
=>$hash_base, hash_parent_base
=>$commit,
3390 file_name
=>$file_name)},
3397 if (defined $extra) {
3399 "<td colspan=\"4\">$extra</td>\n" .
3406 # uses global variable $project
3407 my ($taglist, $from, $to, $extra) = @_;
3408 $from = 0 unless defined $from;
3409 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
3411 print "<table class=\"tags\" cellspacing=\"0\">\n";
3413 for (my $i = $from; $i <= $to; $i++) {
3414 my $entry = $taglist->[$i];
3416 my $comment = $tag{'subject'};
3418 if (defined $comment) {
3419 $comment_short = chop_str
($comment, 30, 5);
3422 print "<tr class=\"dark\">\n";
3424 print "<tr class=\"light\">\n";
3427 if (defined $tag{'age'}) {
3428 print "<td><i>$tag{'age'}</i></td>\n";
3430 print "<td></td>\n";
3433 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
3434 -class => "list name"}, esc_html
($tag{'name'})) .
3437 if (defined $comment) {
3438 print format_subject_html
($comment, $comment_short,
3439 href
(action
=>"tag", hash
=>$tag{'id'}));
3442 "<td class=\"selflink\">";
3443 if ($tag{'type'} eq "tag") {
3444 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
3449 "<td class=\"link\">" . " | " .
3450 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
3451 if ($tag{'reftype'} eq "commit") {
3452 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
3453 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
3454 } elsif ($tag{'reftype'} eq "blob") {
3455 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
3460 if (defined $extra) {
3462 "<td colspan=\"5\">$extra</td>\n" .
3468 sub git_heads_body
{
3469 # uses global variable $project
3470 my ($headlist, $head, $from, $to, $extra) = @_;
3471 $from = 0 unless defined $from;
3472 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
3474 print "<table class=\"heads\" cellspacing=\"0\">\n";
3476 for (my $i = $from; $i <= $to; $i++) {
3477 my $entry = $headlist->[$i];
3479 my $curr = $ref{'id'} eq $head;
3481 print "<tr class=\"dark\">\n";
3483 print "<tr class=\"light\">\n";
3486 print "<td><i>$ref{'age'}</i></td>\n" .
3487 ($curr ? "<td class=\"current_head\">" : "<td>") .
3488 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
3489 -class => "list name"},esc_html
($ref{'name'})) .
3491 "<td class=\"link\">" .
3492 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
3493 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
3494 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
3498 if (defined $extra) {
3500 "<td colspan=\"3\">$extra</td>\n" .
3506 sub git_search_grep_body
{
3507 my ($commitlist, $from, $to, $extra) = @_;
3508 $from = 0 unless defined $from;
3509 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
3511 print "<table class=\"grep\" cellspacing=\"0\">\n";
3513 for (my $i = $from; $i <= $to; $i++) {
3514 my %co = %{$commitlist->[$i]};
3518 my $commit = $co{'id'};
3520 print "<tr class=\"dark\">\n";
3522 print "<tr class=\"light\">\n";
3525 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3526 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3528 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3529 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3530 my $comment = $co{'comment'};
3531 foreach my $line (@$comment) {
3532 if ($line =~ m/^(.*)($search_regexp)(.*)$/i) {
3533 my $lead = esc_html
($1) || "";
3534 $lead = chop_str
($lead, 30, 10);
3535 my $match = esc_html
($2) || "";
3536 my $trail = esc_html
($3) || "";
3537 $trail = chop_str
($trail, 30, 10);
3538 my $text = "$lead<span class=\"match\">$match</span>$trail";
3539 print chop_str
($text, 80, 5) . "<br/>\n";
3543 "<td class=\"link\">" .
3544 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3546 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3550 if (defined $extra) {
3552 "<td colspan=\"3\">$extra</td>\n" .
3558 ## ======================================================================
3559 ## ======================================================================
3562 sub git_project_list
{
3563 my $order = $cgi->param('o');
3564 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3565 die_error
(undef, "Unknown order parameter");
3568 my @list = git_get_projects_list
();
3570 die_error
(undef, "No projects found");
3574 if (-f
$home_text) {
3575 print "<div class=\"index_include\">\n";
3576 open (my $fd, $home_text);
3581 git_project_list_body
(\
@list, $order);
3586 my $order = $cgi->param('o');
3587 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3588 die_error
(undef, "Unknown order parameter");
3591 my @list = git_get_projects_list
($project);
3593 die_error
(undef, "No forks found");
3597 git_print_page_nav
('','');
3598 git_print_header_div
('summary', "$project forks");
3599 git_project_list_body
(\
@list, $order);
3603 sub git_project_index
{
3604 my @projects = git_get_projects_list
($project);
3607 -type
=> 'text/plain',
3608 -charset
=> 'utf-8',
3609 -content_disposition
=> 'inline; filename="index.aux"');
3611 foreach my $pr (@projects) {
3612 if (!exists $pr->{'owner'}) {
3613 $pr->{'owner'} = git_get_project_owner
("$pr->{'path'}");
3616 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3617 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3618 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3619 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3623 print "$path $owner\n";
3628 my $descr = git_get_project_description
($project) || "none";
3629 my %co = parse_commit
("HEAD");
3630 my %cd = %co ? parse_date
($co{'committer_epoch'}, $co{'committer_tz'}) : ();
3631 my $head = $co{'id'};
3633 my $owner = git_get_project_owner
($project);
3635 my $refs = git_get_references
();
3636 # These get_*_list functions return one more to allow us to see if
3637 # there are more ...
3638 my @taglist = git_get_tags_list
(16);
3639 my @headlist = git_get_heads_list
(16);
3641 my ($check_forks) = gitweb_check_feature
('forks');
3644 @forklist = git_get_projects_list
($project);
3648 git_print_page_nav
('summary','', $head);
3650 print "<div class=\"title\"> </div>\n";
3651 print "<table cellspacing=\"0\">\n" .
3652 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3653 "<tr><td>owner</td><td>$owner</td></tr>\n";
3654 if (defined $cd{'rfc2822'}) {
3655 print "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3658 # use per project git URL list in $projectroot/$project/cloneurl
3659 # or make project git URL from git base URL and project name
3660 my $url_tag = "URL";
3661 my @url_list = git_get_project_url_list
($project);
3662 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3663 foreach my $git_url (@url_list) {
3664 next unless $git_url;
3665 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3670 if (-s
"$projectroot/$project/README.html") {
3671 if (open my $fd, "$projectroot/$project/README.html") {
3672 print "<div class=\"title\">readme</div>\n";
3673 print $_ while (<$fd>);
3678 # we need to request one more than 16 (0..15) to check if
3680 my @commitlist = $head ? parse_commits
($head, 17) : ();
3682 git_print_header_div
('shortlog');
3683 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
3684 $#commitlist <= 15 ? undef :
3685 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
3689 git_print_header_div
('tags');
3690 git_tags_body
(\
@taglist, 0, 15,
3691 $#taglist <= 15 ? undef :
3692 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
3696 git_print_header_div
('heads');
3697 git_heads_body
(\
@headlist, $head, 0, 15,
3698 $#headlist <= 15 ? undef :
3699 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
3703 git_print_header_div
('forks');
3704 git_project_list_body
(\
@forklist, undef, 0, 15,
3705 $#forklist <= 15 ? undef :
3706 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
3714 my $head = git_get_head_hash
($project);
3716 git_print_page_nav
('','', $head,undef,$head);
3717 my %tag = parse_tag
($hash);
3720 die_error
(undef, "Unknown tag object");
3723 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
3724 print "<div class=\"title_text\">\n" .
3725 "<table cellspacing=\"0\">\n" .
3727 "<td>object</td>\n" .
3728 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3729 $tag{'object'}) . "</td>\n" .
3730 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3731 $tag{'type'}) . "</td>\n" .
3733 if (defined($tag{'author'})) {
3734 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
3735 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
3736 print "<tr><td></td><td>" . $ad{'rfc2822'} .
3737 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
3740 print "</table>\n\n" .
3742 print "<div class=\"page_body\">";
3743 my $comment = $tag{'comment'};
3744 foreach my $line (@$comment) {
3746 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
3756 my ($have_blame) = gitweb_check_feature
('blame');
3758 die_error
('403 Permission denied', "Permission denied");
3760 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3761 $hash_base ||= git_get_head_hash
($project);
3762 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3763 my %co = parse_commit
($hash_base)
3764 or die_error
(undef, "Reading commit failed");
3765 if (!defined $hash) {
3766 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3767 or die_error
(undef, "Error looking up file");
3769 $ftype = git_get_type
($hash);
3770 if ($ftype !~ "blob") {
3771 die_error
('400 Bad Request', "Object is not a blob");
3773 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
3774 $file_name, $hash_base)
3775 or die_error
(undef, "Open git-blame failed");
3778 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3781 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3784 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3786 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3787 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3788 git_print_page_path
($file_name, $ftype, $hash_base);
3789 my @rev_color = (qw(light2 dark2));
3790 my $num_colors = scalar(@rev_color);
3791 my $current_color = 0;
3794 <div class="page_body">
3795 <table class="blame">
3796 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
3801 last unless defined $_;
3802 my ($full_rev, $orig_lineno, $lineno, $group_size) =
3803 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
3804 if (!exists $metainfo{$full_rev}) {
3805 $metainfo{$full_rev} = {};
3807 my $meta = $metainfo{$full_rev};
3810 if (/^(\S+) (.*)$/) {
3816 my $rev = substr($full_rev, 0, 8);
3817 my $author = $meta->{'author'};
3818 my %date = parse_date
($meta->{'author-time'},
3819 $meta->{'author-tz'});
3820 my $date = $date{'iso-tz'};
3822 $current_color = ++$current_color % $num_colors;
3824 print "<tr class=\"$rev_color[$current_color]\">\n";
3826 print "<td class=\"sha1\"";
3827 print " title=\"". esc_html
($author) . ", $date\"";
3828 print " rowspan=\"$group_size\"" if ($group_size > 1);
3830 print $cgi->a({-href
=> href
(action
=>"commit",
3832 file_name
=>$file_name)},
3836 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
3837 or die_error
(undef, "Open git-rev-parse failed");
3838 my $parent_commit = <$dd>;
3840 chomp($parent_commit);
3841 my $blamed = href
(action
=> 'blame',
3842 file_name
=> $meta->{'filename'},
3843 hash_base
=> $parent_commit);
3844 print "<td class=\"linenr\">";
3845 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
3847 -class => "linenr" },
3850 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
3856 or print "Reading blob failed\n";
3863 my ($have_blame) = gitweb_check_feature
('blame');
3865 die_error
('403 Permission denied', "Permission denied");
3867 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3868 $hash_base ||= git_get_head_hash
($project);
3869 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3870 my %co = parse_commit
($hash_base)
3871 or die_error
(undef, "Reading commit failed");
3872 if (!defined $hash) {
3873 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3874 or die_error
(undef, "Error lookup file");
3876 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
3877 or die_error
(undef, "Open git-annotate failed");
3880 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3883 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3886 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3888 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3889 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3890 git_print_page_path
($file_name, 'blob', $hash_base);
3891 print "<div class=\"page_body\">\n";
3893 <table class="blame">
3902 my @line_class = (qw(light dark));
3903 my $line_class_len = scalar (@line_class);
3904 my $line_class_num = $#line_class;
3905 while (my $line = <$fd>) {
3917 $line_class_num = ($line_class_num + 1) % $line_class_len;
3919 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
3926 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
3929 $short_rev = substr ($long_rev, 0, 8);
3930 $age = time () - $time;
3931 $age_str = age_string
($age);
3932 $age_str =~ s/ / /g;
3933 $age_class = age_class
($age);
3934 $author = esc_html
($author);
3935 $author =~ s/ / /g;
3937 $data = untabify
($data);
3938 $data = esc_html
($data);
3941 <tr class="$line_class[$line_class_num]">
3942 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
3943 <td class="$age_class">$age_str</td>
3945 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
3946 <td class="pre">$data</td>
3949 } # while (my $line = <$fd>)
3950 print "</table>\n\n";
3952 or print "Reading blob failed.\n";
3958 my $head = git_get_head_hash
($project);
3960 git_print_page_nav
('','', $head,undef,$head);
3961 git_print_header_div
('summary', $project);
3963 my @tagslist = git_get_tags_list
();
3965 git_tags_body
(\
@tagslist);
3971 my $head = git_get_head_hash
($project);
3973 git_print_page_nav
('','', $head,undef,$head);
3974 git_print_header_div
('summary', $project);
3976 my @headslist = git_get_heads_list
();
3978 git_heads_body
(\
@headslist, $head);
3983 sub git_blob_plain
{
3986 if (!defined $hash) {
3987 if (defined $file_name) {
3988 my $base = $hash_base || git_get_head_hash
($project);
3989 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3990 or die_error
(undef, "Error lookup file");
3992 die_error
(undef, "No file name defined");
3994 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3995 # blobs defined by non-textual hash id's can be cached
4000 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4001 or die_error
(undef, "Couldn't cat $file_name, $hash");
4003 $type ||= blob_mimetype
($fd, $file_name);
4005 # save as filename, even when no $file_name is given
4006 my $save_as = "$hash";
4007 if (defined $file_name) {
4008 $save_as = $file_name;
4009 } elsif ($type =~ m/^text\//) {
4016 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
4018 binmode STDOUT
, ':raw';
4020 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4028 if (!defined $hash) {
4029 if (defined $file_name) {
4030 my $base = $hash_base || git_get_head_hash
($project);
4031 $hash = git_get_hash_by_path
($base, $file_name, "blob")
4032 or die_error
(undef, "Error lookup file");
4034 die_error
(undef, "No file name defined");
4036 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4037 # blobs defined by non-textual hash id's can be cached
4041 my ($have_blame) = gitweb_check_feature
('blame');
4042 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
4043 or die_error
(undef, "Couldn't cat $file_name, $hash");
4044 my $mimetype = blob_mimetype
($fd, $file_name);
4045 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
4047 return git_blob_plain
($mimetype);
4049 # we can have blame only for text/* mimetype
4050 $have_blame &&= ($mimetype =~ m!^text/!);
4052 git_header_html
(undef, $expires);
4053 my $formats_nav = '';
4054 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4055 if (defined $file_name) {
4058 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
4059 hash
=>$hash, file_name
=>$file_name)},
4064 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4065 hash
=>$hash, file_name
=>$file_name)},
4068 $cgi->a({-href
=> href
(action
=>"blob_plain",
4069 hash
=>$hash, file_name
=>$file_name)},
4072 $cgi->a({-href
=> href
(action
=>"blob",
4073 hash_base
=>"HEAD", file_name
=>$file_name)},
4077 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
4079 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4080 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4082 print "<div class=\"page_nav\">\n" .
4083 "<br/><br/></div>\n" .
4084 "<div class=\"title\">$hash</div>\n";
4086 git_print_page_path
($file_name, "blob", $hash_base);
4087 print "<div class=\"page_body\">\n";
4088 if ($mimetype =~ m!^text/!) {
4090 while (my $line = <$fd>) {
4093 $line = untabify
($line);
4094 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
4095 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
4097 } elsif ($mimetype =~ m!^image/!) {
4098 print qq
!<img type
="$mimetype"!;
4100 print qq
! alt
="$file_name" title
="$file_name"!;
4103 href(action=>"blob_plain
", hash=>$hash,
4104 hash_base=>$hash_base, file_name=>$file_name) .
4108 or print "Reading blob failed.\n";
4114 my $have_snapshot = gitweb_have_snapshot
();
4116 if (!defined $hash_base) {
4117 $hash_base = "HEAD";
4119 if (!defined $hash) {
4120 if (defined $file_name) {
4121 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
4127 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
4128 or die_error
(undef, "Open git-ls-tree failed");
4129 my @entries = map { chomp; $_ } <$fd>;
4130 close $fd or die_error
(undef, "Reading tree failed");
4133 my $refs = git_get_references
();
4134 my $ref = format_ref_marker
($refs, $hash_base);
4137 my ($have_blame) = gitweb_check_feature
('blame');
4138 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4140 if (defined $file_name) {
4142 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
4143 hash
=>$hash, file_name
=>$file_name)},
4145 $cgi->a({-href
=> href
(action
=>"tree",
4146 hash_base
=>"HEAD", file_name
=>$file_name)},
4149 if ($have_snapshot) {
4150 # FIXME: Should be available when we have no hash base as well.
4152 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
4155 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
4156 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
4159 print "<div class=\"page_nav\">\n";
4160 print "<br/><br/></div>\n";
4161 print "<div class=\"title\">$hash</div>\n";
4163 if (defined $file_name) {
4164 $basedir = $file_name;
4165 if ($basedir ne '' && substr($basedir, -1) ne '/') {
4169 git_print_page_path
($file_name, 'tree', $hash_base);
4170 print "<div class=\"page_body\">\n";
4171 print "<table cellspacing=\"0\">\n";
4173 # '..' (top directory) link if possible
4174 if (defined $hash_base &&
4175 defined $file_name && $file_name =~ m![^/]+$!) {
4177 print "<tr class=\"dark\">\n";
4179 print "<tr class=\"light\">\n";
4183 my $up = $file_name;
4184 $up =~ s!/?[^/]+$!!;
4185 undef $up unless $up;
4186 # based on git_print_tree_entry
4187 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
4188 print '<td class="list">';
4189 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
4193 print "<td class=\"link\"></td>\n";
4197 foreach my $line (@entries) {
4198 my %t = parse_ls_tree_line
($line, -z
=> 1);
4201 print "<tr class=\"dark\">\n";
4203 print "<tr class=\"light\">\n";
4207 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
4211 print "</table>\n" .
4217 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
4218 my $have_snapshot = (defined $ctype && defined $suffix);
4219 if (!$have_snapshot) {
4220 die_error
('403 Permission denied', "Permission denied");
4223 if (!defined $hash) {
4224 $hash = git_get_head_hash
($project);
4227 my $git = git_cmd_str
();
4228 my $name = $project;
4229 $name =~ s
,([^/])/*\
.git
$,$1,;
4230 $name = basename
($name);
4231 my $filename = to_utf8
($name);
4232 $name =~ s/\047/\047\\\047\047/g;
4234 if ($suffix eq 'zip') {
4235 $filename .= "-$hash.$suffix";
4236 $cmd = "$git archive --format=zip --prefix=\'$name\'/ $hash";
4238 $filename .= "-$hash.tar.$suffix";
4239 $cmd = "$git archive --format=tar --prefix=\'$name\'/ $hash | $command";
4243 -type
=> "application/$ctype",
4244 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
4245 -status
=> '200 OK');
4247 open my $fd, "-|", $cmd
4248 or die_error
(undef, "Execute git-archive failed");
4249 binmode STDOUT
, ':raw';
4251 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
4257 my $head = git_get_head_hash
($project);
4258 if (!defined $hash) {
4261 if (!defined $page) {
4264 my $refs = git_get_references
();
4266 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4268 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
4271 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
4274 my %co = parse_commit
($hash);
4276 git_print_header_div
('summary', $project);
4277 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
4279 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
4280 for (my $i = 0; $i <= $to; $i++) {
4281 my %co = %{$commitlist[$i]};
4283 my $commit = $co{'id'};
4284 my $ref = format_ref_marker
($refs, $commit);
4285 my %ad = parse_date
($co{'author_epoch'});
4286 git_print_header_div
('commit',
4287 "<span class=\"age\">$co{'age_string'}</span>" .
4288 esc_html
($co{'title'}) . $ref,
4290 print "<div class=\"title_text\">\n" .
4291 "<div class=\"log_link\">\n" .
4292 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
4294 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
4296 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
4299 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
4302 print "<div class=\"log_body\">\n";
4303 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
4306 if ($#commitlist >= 100) {
4307 print "<div class=\"page_nav\">\n";
4308 print $cgi->a({-href
=> href
(action
=>"log", hash
=>$hash, page
=>$page+1),
4309 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4316 $hash ||= $hash_base || "HEAD";
4317 my %co = parse_commit
($hash);
4319 die_error
(undef, "Unknown commit object");
4321 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4322 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
4324 my $parent = $co{'parent'};
4325 my $parents = $co{'parents'}; # listref
4327 # we need to prepare $formats_nav before any parameter munging
4329 if (!defined $parent) {
4331 $formats_nav .= '(initial)';
4332 } elsif (@$parents == 1) {
4333 # single parent commit
4336 $cgi->a({-href
=> href
(action
=>"commit",
4338 esc_html
(substr($parent, 0, 7))) .
4345 $cgi->a({-href
=> href
(action
=>"commit",
4347 esc_html
(substr($_, 0, 7)));
4352 if (!defined $parent) {
4356 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
4358 (@$parents <= 1 ? $parent : '-c'),
4360 or die_error
(undef, "Open git-diff-tree failed");
4361 @difftree = map { chomp; $_ } <$fd>;
4362 close $fd or die_error
(undef, "Reading git-diff-tree failed");
4364 # non-textual hash id's can be cached
4366 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4369 my $refs = git_get_references
();
4370 my $ref = format_ref_marker
($refs, $co{'id'});
4372 my $have_snapshot = gitweb_have_snapshot
();
4374 git_header_html
(undef, $expires);
4375 git_print_page_nav
('commit', '',
4376 $hash, $co{'tree'}, $hash,
4379 if (defined $co{'parent'}) {
4380 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
4382 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
4384 print "<div class=\"title_text\">\n" .
4385 "<table cellspacing=\"0\">\n";
4386 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
4388 "<td></td><td> $ad{'rfc2822'}";
4389 if ($ad{'hour_local'} < 6) {
4390 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
4391 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4393 printf(" (%02d:%02d %s)",
4394 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
4398 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
4399 print "<tr><td></td><td> $cd{'rfc2822'}" .
4400 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
4402 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
4405 "<td class=\"sha1\">" .
4406 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
4407 class => "list"}, $co{'tree'}) .
4409 "<td class=\"link\">" .
4410 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
4412 if ($have_snapshot) {
4414 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
4419 foreach my $par (@$parents) {
4422 "<td class=\"sha1\">" .
4423 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
4424 class => "list"}, $par) .
4426 "<td class=\"link\">" .
4427 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
4429 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
4436 print "<div class=\"page_body\">\n";
4437 git_print_log
($co{'comment'});
4440 git_difftree_body
(\
@difftree, $hash, @$parents);
4446 # object is defined by:
4447 # - hash or hash_base alone
4448 # - hash_base and file_name
4451 # - hash or hash_base alone
4452 if ($hash || ($hash_base && !defined $file_name)) {
4453 my $object_id = $hash || $hash_base;
4455 my $git_command = git_cmd_str
();
4456 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
4457 or die_error
('404 Not Found', "Object does not exist");
4461 or die_error
('404 Not Found', "Object does not exist");
4463 # - hash_base and file_name
4464 } elsif ($hash_base && defined $file_name) {
4465 $file_name =~ s
,/+$,,;
4467 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
4468 or die_error
('404 Not Found', "Base object does not exist");
4470 # here errors should not hapen
4471 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
4472 or die_error
(undef, "Open git-ls-tree failed");
4476 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
4477 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
4478 die_error
('404 Not Found', "File or directory for given base does not exist");
4483 die_error
('404 Not Found', "Not enough information to find object");
4486 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
4487 hash
=>$hash, hash_base
=>$hash_base,
4488 file_name
=>$file_name),
4489 -status
=> '302 Found');
4493 my $format = shift || 'html';
4500 # preparing $fd and %diffinfo for git_patchset_body
4502 if (defined $hash_base && defined $hash_parent_base) {
4503 if (defined $file_name) {
4505 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4506 $hash_parent_base, $hash_base,
4507 "--", (defined $file_parent ? $file_parent : ()), $file_name
4508 or die_error
(undef, "Open git-diff-tree failed");
4509 @difftree = map { chomp; $_ } <$fd>;
4511 or die_error
(undef, "Reading git-diff-tree failed");
4513 or die_error
('404 Not Found', "Blob diff not found");
4515 } elsif (defined $hash &&
4516 $hash =~ /[0-9a-fA-F]{40}/) {
4517 # try to find filename from $hash
4519 # read filtered raw output
4520 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4521 $hash_parent_base, $hash_base, "--"
4522 or die_error
(undef, "Open git-diff-tree failed");
4524 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
4526 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
4527 map { chomp; $_ } <$fd>;
4529 or die_error
(undef, "Reading git-diff-tree failed");
4531 or die_error
('404 Not Found', "Blob diff not found");
4534 die_error
('404 Not Found', "Missing one of the blob diff parameters");
4537 if (@difftree > 1) {
4538 die_error
('404 Not Found', "Ambiguous blob diff specification");
4541 %diffinfo = parse_difftree_raw_line
($difftree[0]);
4542 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
4543 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
4545 $hash_parent ||= $diffinfo{'from_id'};
4546 $hash ||= $diffinfo{'to_id'};
4548 # non-textual hash id's can be cached
4549 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
4550 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
4555 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4556 '-p', ($format eq 'html' ? "--full-index" : ()),
4557 $hash_parent_base, $hash_base,
4558 "--", (defined $file_parent ? $file_parent : ()), $file_name
4559 or die_error
(undef, "Open git-diff-tree failed");
4562 # old/legacy style URI
4563 if (!%diffinfo && # if new style URI failed
4564 defined $hash && defined $hash_parent) {
4565 # fake git-diff-tree raw output
4566 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
4567 $diffinfo{'from_id'} = $hash_parent;
4568 $diffinfo{'to_id'} = $hash;
4569 if (defined $file_name) {
4570 if (defined $file_parent) {
4571 $diffinfo{'status'} = '2';
4572 $diffinfo{'from_file'} = $file_parent;
4573 $diffinfo{'to_file'} = $file_name;
4574 } else { # assume not renamed
4575 $diffinfo{'status'} = '1';
4576 $diffinfo{'from_file'} = $file_name;
4577 $diffinfo{'to_file'} = $file_name;
4579 } else { # no filename given
4580 $diffinfo{'status'} = '2';
4581 $diffinfo{'from_file'} = $hash_parent;
4582 $diffinfo{'to_file'} = $hash;
4585 # non-textual hash id's can be cached
4586 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
4587 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4592 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4593 '-p', ($format eq 'html' ? "--full-index" : ()),
4594 $hash_parent, $hash, "--"
4595 or die_error
(undef, "Open git-diff failed");
4597 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4602 if ($format eq 'html') {
4604 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
4605 hash
=>$hash, hash_parent
=>$hash_parent,
4606 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
4607 file_name
=>$file_name, file_parent
=>$file_parent)},
4609 git_header_html
(undef, $expires);
4610 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4611 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4612 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4614 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4615 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4617 if (defined $file_name) {
4618 git_print_page_path
($file_name, "blob", $hash_base);
4620 print "<div class=\"page_path\"></div>\n";
4623 } elsif ($format eq 'plain') {
4625 -type
=> 'text/plain',
4626 -charset
=> 'utf-8',
4627 -expires
=> $expires,
4628 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4630 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4633 die_error
(undef, "Unknown blobdiff format");
4637 if ($format eq 'html') {
4638 print "<div class=\"page_body\">\n";
4640 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4643 print "</div>\n"; # class="page_body"
4647 while (my $line = <$fd>) {
4648 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4649 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4653 last if $line =~ m!^\+\+\+!;
4661 sub git_blobdiff_plain
{
4662 git_blobdiff
('plain');
4665 sub git_commitdiff
{
4666 my $format = shift || 'html';
4667 $hash ||= $hash_base || "HEAD";
4668 my %co = parse_commit
($hash);
4670 die_error
(undef, "Unknown commit object");
4673 # choose format for commitdiff for merge
4674 if (! defined $hash_parent && @{$co{'parents'}} > 1) {
4675 $hash_parent = '--cc';
4677 # we need to prepare $formats_nav before almost any parameter munging
4679 if ($format eq 'html') {
4681 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
4682 hash
=>$hash, hash_parent
=>$hash_parent)},
4685 if (defined $hash_parent &&
4686 $hash_parent ne '-c' && $hash_parent ne '--cc') {
4687 # commitdiff with two commits given
4688 my $hash_parent_short = $hash_parent;
4689 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4690 $hash_parent_short = substr($hash_parent, 0, 7);
4694 for (my $i = 0; $i < @{$co{'parents'}}; $i++) {
4695 if ($co{'parents'}[$i] eq $hash_parent) {
4696 $formats_nav .= ' parent ' . ($i+1);
4700 $formats_nav .= ': ' .
4701 $cgi->a({-href
=> href
(action
=>"commitdiff",
4702 hash
=>$hash_parent)},
4703 esc_html
($hash_parent_short)) .
4705 } elsif (!$co{'parent'}) {
4707 $formats_nav .= ' (initial)';
4708 } elsif (scalar @{$co{'parents'}} == 1) {
4709 # single parent commit
4712 $cgi->a({-href
=> href
(action
=>"commitdiff",
4713 hash
=>$co{'parent'})},
4714 esc_html
(substr($co{'parent'}, 0, 7))) .
4718 if ($hash_parent eq '--cc') {
4719 $formats_nav .= ' | ' .
4720 $cgi->a({-href
=> href
(action
=>"commitdiff",
4721 hash
=>$hash, hash_parent
=>'-c')},
4723 } else { # $hash_parent eq '-c'
4724 $formats_nav .= ' | ' .
4725 $cgi->a({-href
=> href
(action
=>"commitdiff",
4726 hash
=>$hash, hash_parent
=>'--cc')},
4732 $cgi->a({-href
=> href
(action
=>"commitdiff",
4734 esc_html
(substr($_, 0, 7)));
4735 } @{$co{'parents'}} ) .
4740 my $hash_parent_param = $hash_parent;
4741 if (!defined $hash_parent_param) {
4742 # --cc for multiple parents, --root for parentless
4743 $hash_parent_param =
4744 @{$co{'parents'}} > 1 ? '--cc' : $co{'parent'} || '--root';
4750 if ($format eq 'html') {
4751 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4752 "--no-commit-id", "--patch-with-raw", "--full-index",
4753 $hash_parent_param, $hash, "--"
4754 or die_error
(undef, "Open git-diff-tree failed");
4756 while (my $line = <$fd>) {
4758 # empty line ends raw part of diff-tree output
4760 push @difftree, scalar parse_difftree_raw_line
($line);
4763 } elsif ($format eq 'plain') {
4764 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4765 '-p', $hash_parent_param, $hash, "--"
4766 or die_error
(undef, "Open git-diff-tree failed");
4769 die_error
(undef, "Unknown commitdiff format");
4772 # non-textual hash id's can be cached
4774 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4778 # write commit message
4779 if ($format eq 'html') {
4780 my $refs = git_get_references
();
4781 my $ref = format_ref_marker
($refs, $co{'id'});
4783 git_header_html
(undef, $expires);
4784 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
4785 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
4786 git_print_authorship
(\
%co);
4787 print "<div class=\"page_body\">\n";
4788 if (@{$co{'comment'}} > 1) {
4789 print "<div class=\"log\">\n";
4790 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
4791 print "</div>\n"; # class="log"
4794 } elsif ($format eq 'plain') {
4795 my $refs = git_get_references
("tags");
4796 my $tagname = git_get_rev_name_tags
($hash);
4797 my $filename = basename
($project) . "-$hash.patch";
4800 -type
=> 'text/plain',
4801 -charset
=> 'utf-8',
4802 -expires
=> $expires,
4803 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
4804 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4807 Date: $ad{'rfc2822'} ($ad{'tz_local'})
4808 Subject: $co{'title'}
4810 print "X-Git-Tag: $tagname\n" if $tagname;
4811 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4813 foreach my $line (@{$co{'comment'}}) {
4820 if ($format eq 'html') {
4821 my $use_parents = !defined $hash_parent ||
4822 $hash_parent eq '-c' || $hash_parent eq '--cc';
4823 git_difftree_body
(\
@difftree, $hash,
4824 $use_parents ? @{$co{'parents'}} : $hash_parent);
4827 git_patchset_body
($fd, \
@difftree, $hash,
4828 $use_parents ? @{$co{'parents'}} : $hash_parent);
4830 print "</div>\n"; # class="page_body"
4833 } elsif ($format eq 'plain') {
4837 or print "Reading git-diff-tree failed\n";
4841 sub git_commitdiff_plain
{
4842 git_commitdiff
('plain');
4846 if (!defined $hash_base) {
4847 $hash_base = git_get_head_hash
($project);
4849 if (!defined $page) {
4853 my %co = parse_commit
($hash_base);
4855 die_error
(undef, "Unknown commit object");
4858 my $refs = git_get_references
();
4859 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
4861 if (!defined $hash && defined $file_name) {
4862 $hash = git_get_hash_by_path
($hash_base, $file_name);
4864 if (defined $hash) {
4865 $ftype = git_get_type
($hash);
4868 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), "--full-history", $file_name);
4870 my $paging_nav = '';
4873 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4874 file_name
=>$file_name)},
4876 $paging_nav .= " ⋅ " .
4877 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4878 file_name
=>$file_name, page
=>$page-1),
4879 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4881 $paging_nav .= "first";
4882 $paging_nav .= " ⋅ prev";
4884 if ($#commitlist >= 100) {
4885 $paging_nav .= " ⋅ " .
4886 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4887 file_name
=>$file_name, page
=>$page+1),
4888 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4890 $paging_nav .= " ⋅ next";
4893 if ($#commitlist >= 100) {
4895 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4896 file_name
=>$file_name, page
=>$page+1),
4897 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4901 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
4902 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4903 git_print_page_path
($file_name, $ftype, $hash_base);
4905 git_history_body
(\
@commitlist, 0, 99,
4906 $refs, $hash_base, $ftype, $next_link);
4912 my ($have_search) = gitweb_check_feature
('search');
4913 if (!$have_search) {
4914 die_error
('403 Permission denied', "Permission denied");
4916 if (!defined $searchtext) {
4917 die_error
(undef, "Text field empty");
4919 if (!defined $hash) {
4920 $hash = git_get_head_hash
($project);
4922 my %co = parse_commit
($hash);
4924 die_error
(undef, "Unknown commit object");
4926 if (!defined $page) {
4930 $searchtype ||= 'commit';
4931 if ($searchtype eq 'pickaxe') {
4932 # pickaxe may take all resources of your box and run for several minutes
4933 # with every query - so decide by yourself how public you make this feature
4934 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4935 if (!$have_pickaxe) {
4936 die_error
('403 Permission denied', "Permission denied");
4939 if ($searchtype eq 'grep') {
4940 my ($have_grep) = gitweb_check_feature
('grep');
4942 die_error
('403 Permission denied', "Permission denied");
4948 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
4950 if ($searchtype eq 'commit') {
4951 $greptype = "--grep=";
4952 } elsif ($searchtype eq 'author') {
4953 $greptype = "--author=";
4954 } elsif ($searchtype eq 'committer') {
4955 $greptype = "--committer=";
4957 $greptype .= $search_regexp;
4958 my @commitlist = parse_commits
($hash, 101, (100 * $page), $greptype);
4960 my $paging_nav = '';
4963 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4964 searchtext
=>$searchtext, searchtype
=>$searchtype)},
4966 $paging_nav .= " ⋅ " .
4967 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4968 searchtext
=>$searchtext, searchtype
=>$searchtype,
4970 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4972 $paging_nav .= "first";
4973 $paging_nav .= " ⋅ prev";
4975 if ($#commitlist >= 100) {
4976 $paging_nav .= " ⋅ " .
4977 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4978 searchtext
=>$searchtext, searchtype
=>$searchtype,
4980 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4982 $paging_nav .= " ⋅ next";
4985 if ($#commitlist >= 100) {
4987 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4988 searchtext
=>$searchtext, searchtype
=>$searchtype,
4990 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4993 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
4994 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4995 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
4998 if ($searchtype eq 'pickaxe') {
4999 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5000 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5002 print "<table cellspacing=\"0\">\n";
5005 my $git_command = git_cmd_str
();
5006 my $searchqtext = $searchtext;
5007 $searchqtext =~ s/'/'\\''/;
5008 open my $fd, "-|", "$git_command rev-list $hash | " .
5009 "$git_command diff-tree -r --stdin -S\'$searchqtext\'";
5012 while (my $line = <$fd>) {
5013 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
5016 $set{'from_id'} = $3;
5018 $set{'id'} = $set{'to_id'};
5019 if ($set{'id'} =~ m/0{40}/) {
5020 $set{'id'} = $set{'from_id'};
5022 if ($set{'id'} =~ m/0{40}/) {
5026 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
5029 print "<tr class=\"dark\">\n";
5031 print "<tr class=\"light\">\n";
5034 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
5035 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
5037 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
5038 -class => "list subject"},
5039 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
5040 while (my $setref = shift @files) {
5042 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
5043 hash
=>$set{'id'}, file_name
=>$set{'file'}),
5045 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
5049 "<td class=\"link\">" .
5050 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
5052 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
5056 %co = parse_commit
($1);
5064 if ($searchtype eq 'grep') {
5065 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
5066 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
5068 print "<table cellspacing=\"0\">\n";
5072 open my $fd, "-|", git_cmd
(), 'grep', '-n', '-i', '-E', $searchtext, $co{'tree'};
5074 while (my $line = <$fd>) {
5076 my ($file, $lno, $ltext, $binary);
5077 last if ($matches++ > 1000);
5078 if ($line =~ /^Binary file (.+) matches$/) {
5082 (undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5084 if ($file ne $lastfile) {
5085 $lastfile and print "</td></tr>\n";
5087 print "<tr class=\"dark\">\n";
5089 print "<tr class=\"light\">\n";
5091 print "<td class=\"list\">".
5092 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5093 file_name
=>"$file"),
5094 -class => "list"}, esc_path
($file));
5095 print "</td><td>\n";
5099 print "<div class=\"binary\">Binary file</div>\n";
5101 $ltext = untabify
($ltext);
5102 if ($ltext =~ m/^(.*)($searchtext)(.*)$/i) {
5103 $ltext = esc_html
($1, -nbsp
=>1);
5104 $ltext .= '<span class="match">';
5105 $ltext .= esc_html
($2, -nbsp
=>1);
5106 $ltext .= '</span>';
5107 $ltext .= esc_html
($3, -nbsp
=>1);
5109 $ltext = esc_html
($ltext, -nbsp
=>1);
5111 print "<div class=\"pre\">" .
5112 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$co{'hash'},
5113 file_name
=>"$file").'#l'.$lno,
5114 -class => "linenr"}, sprintf('%4i', $lno))
5115 . ' ' . $ltext . "</div>\n";
5119 print "</td></tr>\n";
5120 if ($matches > 1000) {
5121 print "<div class=\"diff nodifferences\">Too many matches, listing trimmed</div>\n";
5124 print "<div class=\"diff nodifferences\">No matches found</div>\n";
5133 sub git_search_help
{
5135 git_print_page_nav
('','', $hash,$hash,$hash);
5138 <dt><b>commit</b></dt>
5139 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
5141 my ($have_grep) = gitweb_check_feature
('grep');
5144 <dt><b>grep</b></dt>
5145 <dd>All files in the currently selected tree (HEAD unless you are explicitly browsing
5146 a different one) are searched for the given
5147 <a href="http://en.wikipedia.org/wiki/Regular_expression">regular expression</a>
5148 (POSIX extended) and the matches are listed. On large
5149 trees, this search can take a while and put some strain on the server, so please use it with
5150 some consideration.</dd>
5154 <dt><b>author</b></dt>
5155 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
5156 <dt><b>committer</b></dt>
5157 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
5159 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
5160 if ($have_pickaxe) {
5162 <dt><b>pickaxe</b></dt>
5163 <dd>All commits that caused the string to appear or disappear from any file (changes that
5164 added, removed or "modified" the string) will be listed. This search can take a while and
5165 takes a lot of strain on the server, so please use it wisely.</dd>
5173 my $head = git_get_head_hash
($project);
5174 if (!defined $hash) {
5177 if (!defined $page) {
5180 my $refs = git_get_references
();
5182 my @commitlist = parse_commits
($hash, 101, (100 * $page));
5184 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, (100 * ($page+1)));
5186 if ($#commitlist >= 100) {
5188 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
5189 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
5193 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
5194 git_print_header_div
('summary', $project);
5196 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
5201 ## ......................................................................
5202 ## feeds (RSS, Atom; OPML)
5205 my $format = shift || 'atom';
5206 my ($have_blame) = gitweb_check_feature
('blame');
5208 # Atom: http://www.atomenabled.org/developers/syndication/
5209 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
5210 if ($format ne 'rss' && $format ne 'atom') {
5211 die_error
(undef, "Unknown web feed format");
5214 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
5215 my $head = $hash || 'HEAD';
5216 my @commitlist = parse_commits
($head, 150);
5220 my $content_type = "application/$format+xml";
5221 if (defined $cgi->http('HTTP_ACCEPT') &&
5222 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
5223 # browser (feed reader) prefers text/xml
5224 $content_type = 'text/xml';
5226 if (defined($commitlist[0])) {
5227 %latest_commit = %{$commitlist[0]};
5228 %latest_date = parse_date
($latest_commit{'author_epoch'});
5230 -type
=> $content_type,
5231 -charset
=> 'utf-8',
5232 -last_modified
=> $latest_date{'rfc2822'});
5235 -type
=> $content_type,
5236 -charset
=> 'utf-8');
5239 # Optimization: skip generating the body if client asks only
5240 # for Last-Modified date.
5241 return if ($cgi->request_method() eq 'HEAD');
5244 my $title = "$site_name - $project/$action";
5245 my $feed_type = 'log';
5246 if (defined $hash) {
5247 $title .= " - '$hash'";
5248 $feed_type = 'branch log';
5249 if (defined $file_name) {
5250 $title .= " :: $file_name";
5251 $feed_type = 'history';
5253 } elsif (defined $file_name) {
5254 $title .= " - $file_name";
5255 $feed_type = 'history';
5257 $title .= " $feed_type";
5258 my $descr = git_get_project_description
($project);
5259 if (defined $descr) {
5260 $descr = esc_html
($descr);
5262 $descr = "$project " .
5263 ($format eq 'rss' ? 'RSS' : 'Atom') .
5266 my $owner = git_get_project_owner
($project);
5267 $owner = esc_html
($owner);
5271 if (defined $file_name) {
5272 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
5273 } elsif (defined $hash) {
5274 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
5276 $alt_url = href
(-full
=>1, action
=>"summary");
5278 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
5279 if ($format eq 'rss') {
5281 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
5284 print "<title>$title</title>\n" .
5285 "<link>$alt_url</link>\n" .
5286 "<description>$descr</description>\n" .
5287 "<language>en</language>\n";
5288 } elsif ($format eq 'atom') {
5290 <feed xmlns="http://www.w3.org/2005/Atom">
5292 print "<title>$title</title>\n" .
5293 "<subtitle>$descr</subtitle>\n" .
5294 '<link rel="alternate" type="text/html" href="' .
5295 $alt_url . '" />' . "\n" .
5296 '<link rel="self" type="' . $content_type . '" href="' .
5297 $cgi->self_url() . '" />' . "\n" .
5298 "<id>" . href
(-full
=>1) . "</id>\n" .
5299 # use project owner for feed author
5300 "<author><name>$owner</name></author>\n";
5301 if (defined $favicon) {
5302 print "<icon>" . esc_url
($favicon) . "</icon>\n";
5304 if (defined $logo_url) {
5305 # not twice as wide as tall: 72 x 27 pixels
5306 print "<logo>" . esc_url
($logo) . "</logo>\n";
5308 if (! %latest_date) {
5309 # dummy date to keep the feed valid until commits trickle in:
5310 print "<updated>1970-01-01T00:00:00Z</updated>\n";
5312 print "<updated>$latest_date{'iso-8601'}</updated>\n";
5317 for (my $i = 0; $i <= $#commitlist; $i++) {
5318 my %co = %{$commitlist[$i]};
5319 my $commit = $co{'id'};
5320 # we read 150, we always show 30 and the ones more recent than 48 hours
5321 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
5324 my %cd = parse_date
($co{'author_epoch'});
5326 # get list of changed files
5327 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
5328 $co{'parent'} || "--root",
5329 $co{'id'}, "--", (defined $file_name ? $file_name : ())
5331 my @difftree = map { chomp; $_ } <$fd>;
5335 # print element (entry, item)
5336 my $co_url = href
(-full
=>1, action
=>"commit", hash
=>$commit);
5337 if ($format eq 'rss') {
5339 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
5340 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
5341 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
5342 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
5343 "<link>$co_url</link>\n" .
5344 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
5345 "<content:encoded>" .
5347 } elsif ($format eq 'atom') {
5349 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
5350 "<updated>$cd{'iso-8601'}</updated>\n" .
5352 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
5353 if ($co{'author_email'}) {
5354 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
5356 print "</author>\n" .
5357 # use committer for contributor
5359 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
5360 if ($co{'committer_email'}) {
5361 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
5363 print "</contributor>\n" .
5364 "<published>$cd{'iso-8601'}</published>\n" .
5365 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
5366 "<id>$co_url</id>\n" .
5367 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
5368 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
5370 my $comment = $co{'comment'};
5372 foreach my $line (@$comment) {
5373 $line = esc_html
($line);
5376 print "</pre><ul>\n";
5377 foreach my $difftree_line (@difftree) {
5378 my %difftree = parse_difftree_raw_line
($difftree_line);
5379 next if !$difftree{'from_id'};
5381 my $file = $difftree{'file'} || $difftree{'to_file'};
5385 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
5386 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
5387 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
5388 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
5389 -title
=> "diff"}, 'D');
5391 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
5392 file_name
=>$file, hash_base
=>$commit),
5393 -title
=> "blame"}, 'B');
5395 # if this is not a feed of a file history
5396 if (!defined $file_name || $file_name ne $file) {
5397 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
5398 file_name
=>$file, hash
=>$commit),
5399 -title
=> "history"}, 'H');
5401 $file = esc_path
($file);
5405 if ($format eq 'rss') {
5406 print "</ul>]]>\n" .
5407 "</content:encoded>\n" .
5409 } elsif ($format eq 'atom') {
5410 print "</ul>\n</div>\n" .
5417 if ($format eq 'rss') {
5418 print "</channel>\n</rss>\n";
5419 } elsif ($format eq 'atom') {
5433 my @list = git_get_projects_list
();
5435 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
5437 <?xml version="1.0" encoding="utf-8"?>
5438 <opml version="1.0">
5440 <title>$site_name OPML Export</title>
5443 <outline text="git RSS feeds">
5446 foreach my $pr (@list) {
5448 my $head = git_get_head_hash
($proj{'path'});
5449 if (!defined $head) {
5452 $git_dir = "$projectroot/$proj{'path'}";
5453 my %co = parse_commit
($head);
5458 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
5459 my $rss = "$my_url?p=$proj{'path'};a=rss";
5460 my $html = "$my_url?p=$proj{'path'};a=summary";
5461 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";