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;
60 # URI of GIT logo (72x27 size)
61 our $logo = "++GITWEB_LOGO++";
62 # URI of GIT favicon, assumed to be image/png type
63 our $favicon = "++GITWEB_FAVICON++";
65 # URI and label (title) of GIT logo link
66 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
67 #our $logo_label = "git documentation";
68 our $logo_url = "http://git.or.cz/";
69 our $logo_label = "git homepage";
71 # source of projects list
72 our $projects_list = "++GITWEB_LIST++";
74 # default order of projects list
75 # valid values are none, project, descr, owner, and age
76 our $default_projects_order = "project";
78 # show repository only if this file exists
79 # (only effective if this variable evaluates to true)
80 our $export_ok = "++GITWEB_EXPORT_OK++";
82 # only allow viewing of repositories also shown on the overview page
83 our $strict_export = "++GITWEB_STRICT_EXPORT++";
85 # list of git base URLs used for URL to where fetch project from,
86 # i.e. full URL is "$git_base_url/$project"
87 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
89 # default blob_plain mimetype and default charset for text/plain blob
90 our $default_blob_plain_mimetype = 'text/plain';
91 our $default_text_plain_charset = undef;
93 # file to use for guessing MIME types before trying /etc/mime.types
94 # (relative to the current git repository)
95 our $mimetypes_file = undef;
97 # You define site-wide feature defaults here; override them with
98 # $GITWEB_CONFIG as necessary.
101 # 'sub' => feature-sub (subroutine),
102 # 'override' => allow-override (boolean),
103 # 'default' => [ default options...] (array reference)}
105 # if feature is overridable (it means that allow-override has true value,
106 # then feature-sub will be called with default options as parameters;
107 # return value of feature-sub indicates if to enable specified feature
109 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
111 # Enable the 'blame' blob view, showing the last commit that modified
112 # each line in the file. This can be very CPU-intensive.
114 # To enable system wide have in $GITWEB_CONFIG
115 # $feature{'blame'}{'default'} = [1];
116 # To have project specific config enable override in $GITWEB_CONFIG
117 # $feature{'blame'}{'override'} = 1;
118 # and in project config gitweb.blame = 0|1;
120 'sub' => \
&feature_blame
,
124 # Enable the 'snapshot' link, providing a compressed tarball of any
125 # tree. This can potentially generate high traffic if you have large
128 # To disable system wide have in $GITWEB_CONFIG
129 # $feature{'snapshot'}{'default'} = [undef];
130 # To have project specific config enable override in $GITWEB_CONFIG
131 # $feature{'snapshot'}{'override'} = 1;
132 # and in project config gitweb.snapshot = none|gzip|bzip2;
134 'sub' => \
&feature_snapshot
,
136 # => [content-encoding, suffix, program]
137 'default' => ['x-gzip', 'gz', 'gzip']},
139 # Enable text search, which will list the commits which match author,
140 # committer or commit text to a given string. Enabled by default.
145 # Enable the pickaxe search, which will list the commits that modified
146 # a given string in a file. This can be practical and quite faster
147 # alternative to 'blame', but still potentially CPU-intensive.
149 # To enable system wide have in $GITWEB_CONFIG
150 # $feature{'pickaxe'}{'default'} = [1];
151 # To have project specific config enable override in $GITWEB_CONFIG
152 # $feature{'pickaxe'}{'override'} = 1;
153 # and in project config gitweb.pickaxe = 0|1;
155 'sub' => \
&feature_pickaxe
,
159 # Make gitweb use an alternative format of the URLs which can be
160 # more readable and natural-looking: project name is embedded
161 # directly in the path and the query string contains other
162 # auxiliary information. All gitweb installations recognize
163 # URL in either format; this configures in which formats gitweb
166 # To enable system wide have in $GITWEB_CONFIG
167 # $feature{'pathinfo'}{'default'} = [1];
168 # Project specific override is not supported.
170 # Note that you will need to change the default location of CSS,
171 # favicon, logo and possibly other files to an absolute URL. Also,
172 # if gitweb.cgi serves as your indexfile, you will need to force
173 # $my_uri to contain the script name in your $GITWEB_CONFIG.
178 # Make gitweb consider projects in project root subdirectories
179 # to be forks of existing projects. Given project $projname.git,
180 # projects matching $projname/*.git will not be shown in the main
181 # projects list, instead a '+' mark will be added to $projname
182 # there and a 'forks' view will be enabled for the project, listing
183 # all the forks. If project list is taken from a file, forks have
184 # to be listed after the main project.
186 # To enable system wide have in $GITWEB_CONFIG
187 # $feature{'forks'}{'default'} = [1];
188 # Project specific override is not supported.
194 sub gitweb_check_feature
{
196 return unless exists $feature{$name};
197 my ($sub, $override, @defaults) = (
198 $feature{$name}{'sub'},
199 $feature{$name}{'override'},
200 @
{$feature{$name}{'default'}});
201 if (!$override) { return @defaults; }
203 warn "feature $name is not overrideable";
206 return $sub->(@defaults);
210 my ($val) = git_get_project_config
('blame', '--bool');
212 if ($val eq 'true') {
214 } elsif ($val eq 'false') {
221 sub feature_snapshot
{
222 my ($ctype, $suffix, $command) = @_;
224 my ($val) = git_get_project_config
('snapshot');
226 if ($val eq 'gzip') {
227 return ('x-gzip', 'gz', 'gzip');
228 } elsif ($val eq 'bzip2') {
229 return ('x-bzip2', 'bz2', 'bzip2');
230 } elsif ($val eq 'none') {
234 return ($ctype, $suffix, $command);
237 sub gitweb_have_snapshot
{
238 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
239 my $have_snapshot = (defined $ctype && defined $suffix);
241 return $have_snapshot;
244 sub feature_pickaxe
{
245 my ($val) = git_get_project_config
('pickaxe', '--bool');
247 if ($val eq 'true') {
249 } elsif ($val eq 'false') {
256 # checking HEAD file with -e is fragile if the repository was
257 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
259 sub check_head_link
{
261 my $headfile = "$dir/HEAD";
262 return ((-e
$headfile) ||
263 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
266 sub check_export_ok
{
268 return (check_head_link
($dir) &&
269 (!$export_ok || -e
"$dir/$export_ok"));
272 # rename detection options for git-diff and git-diff-tree
273 # - default is '-M', with the cost proportional to
274 # (number of removed files) * (number of new files).
275 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
276 # (number of changed files + number of removed files) * (number of new files)
277 # - even more costly is '-C', '--find-copies-harder' with cost
278 # (number of files in the original tree) * (number of new files)
279 # - one might want to include '-B' option, e.g. '-B', '-M'
280 our @diff_opts = ('-M'); # taken from git_commit
282 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
283 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
285 # version of the core git binary
286 our $git_version = qx($GIT --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
288 $projects_list ||= $projectroot;
290 # ======================================================================
291 # input validation and dispatch
292 our $action = $cgi->param('a');
293 if (defined $action) {
294 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
295 die_error
(undef, "Invalid action parameter");
299 # parameters which are pathnames
300 our $project = $cgi->param('p');
301 if (defined $project) {
302 if (!validate_pathname
($project) ||
303 !(-d
"$projectroot/$project") ||
304 !check_head_link
("$projectroot/$project") ||
305 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
306 ($strict_export && !project_in_list
($project))) {
308 die_error
(undef, "No such project");
312 our $file_name = $cgi->param('f');
313 if (defined $file_name) {
314 if (!validate_pathname
($file_name)) {
315 die_error
(undef, "Invalid file parameter");
319 our $file_parent = $cgi->param('fp');
320 if (defined $file_parent) {
321 if (!validate_pathname
($file_parent)) {
322 die_error
(undef, "Invalid file parent parameter");
326 # parameters which are refnames
327 our $hash = $cgi->param('h');
329 if (!validate_refname
($hash)) {
330 die_error
(undef, "Invalid hash parameter");
334 our $hash_parent = $cgi->param('hp');
335 if (defined $hash_parent) {
336 if (!validate_refname
($hash_parent)) {
337 die_error
(undef, "Invalid hash parent parameter");
341 our $hash_base = $cgi->param('hb');
342 if (defined $hash_base) {
343 if (!validate_refname
($hash_base)) {
344 die_error
(undef, "Invalid hash base parameter");
348 our $hash_parent_base = $cgi->param('hpb');
349 if (defined $hash_parent_base) {
350 if (!validate_refname
($hash_parent_base)) {
351 die_error
(undef, "Invalid hash parent base parameter");
356 our $page = $cgi->param('pg');
358 if ($page =~ m/[^0-9]/) {
359 die_error
(undef, "Invalid page parameter");
363 our $searchtext = $cgi->param('s');
364 if (defined $searchtext) {
365 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
366 die_error
(undef, "Invalid search parameter");
368 if (length($searchtext) < 2) {
369 die_error
(undef, "At least two characters are required for search parameter");
371 $searchtext = quotemeta $searchtext;
374 our $searchtype = $cgi->param('st');
375 if (defined $searchtype) {
376 if ($searchtype =~ m/[^a-z]/) {
377 die_error
(undef, "Invalid searchtype parameter");
381 # now read PATH_INFO and use it as alternative to parameters
382 sub evaluate_path_info
{
383 return if defined $project;
384 my $path_info = $ENV{"PATH_INFO"};
385 return if !$path_info;
386 $path_info =~ s
,^/+,,;
387 return if !$path_info;
388 # find which part of PATH_INFO is project
389 $project = $path_info;
391 while ($project && !check_head_link
("$projectroot/$project")) {
392 $project =~ s
,/*[^/]*$,,;
395 $project = validate_pathname
($project);
397 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
398 ($strict_export && !project_in_list
($project))) {
402 # do not change any parameters if an action is given using the query string
404 $path_info =~ s
,^$project/*,,;
405 my ($refname, $pathname) = split(/:/, $path_info, 2);
406 if (defined $pathname) {
407 # we got "project.git/branch:filename" or "project.git/branch:dir/"
408 # we could use git_get_type(branch:pathname), but it needs $git_dir
409 $pathname =~ s
,^/+,,;
410 if (!$pathname || substr($pathname, -1) eq "/") {
414 $action ||= "blob_plain";
416 $hash_base ||= validate_refname
($refname);
417 $file_name ||= validate_pathname
($pathname);
418 } elsif (defined $refname) {
419 # we got "project.git/branch"
420 $action ||= "shortlog";
421 $hash ||= validate_refname
($refname);
424 evaluate_path_info
();
426 # path to the current git repository
428 $git_dir = "$projectroot/$project" if $project;
432 "blame" => \
&git_blame2
,
433 "blobdiff" => \
&git_blobdiff
,
434 "blobdiff_plain" => \
&git_blobdiff_plain
,
435 "blob" => \
&git_blob
,
436 "blob_plain" => \
&git_blob_plain
,
437 "commitdiff" => \
&git_commitdiff
,
438 "commitdiff_plain" => \
&git_commitdiff_plain
,
439 "commit" => \
&git_commit
,
440 "forks" => \
&git_forks
,
441 "heads" => \
&git_heads
,
442 "history" => \
&git_history
,
445 "atom" => \
&git_atom
,
446 "search" => \
&git_search
,
447 "search_help" => \
&git_search_help
,
448 "shortlog" => \
&git_shortlog
,
449 "summary" => \
&git_summary
,
451 "tags" => \
&git_tags
,
452 "tree" => \
&git_tree
,
453 "snapshot" => \
&git_snapshot
,
454 "object" => \
&git_object
,
455 # those below don't need $project
456 "opml" => \
&git_opml
,
457 "project_list" => \
&git_project_list
,
458 "project_index" => \
&git_project_index
,
461 if (defined $project) {
462 $action ||= 'summary';
464 $action ||= 'project_list';
466 if (!defined($actions{$action})) {
467 die_error
(undef, "Unknown action");
469 if ($action !~ m/^(opml|project_list|project_index)$/ &&
471 die_error
(undef, "Project needed");
473 $actions{$action}->();
476 ## ======================================================================
481 # default is to use -absolute url() i.e. $my_uri
482 my $href = $params{-full
} ?
$my_url : $my_uri;
484 # XXX: Warning: If you touch this, check the search form for updating,
495 hash_parent_base
=> "hpb",
501 my %mapping = @mapping;
503 $params{'project'} = $project unless exists $params{'project'};
505 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
507 # use PATH_INFO for project name
508 $href .= "/$params{'project'}" if defined $params{'project'};
509 delete $params{'project'};
511 # Summary just uses the project path URL
512 if (defined $params{'action'} && $params{'action'} eq 'summary') {
513 delete $params{'action'};
517 # now encode the parameters explicitly
519 for (my $i = 0; $i < @mapping; $i += 2) {
520 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
521 if (defined $params{$name}) {
522 push @result, $symbol . "=" . esc_param
($params{$name});
525 $href .= "?" . join(';', @result) if scalar @result;
531 ## ======================================================================
532 ## validation, quoting/unquoting and escaping
534 sub validate_pathname
{
535 my $input = shift || return undef;
537 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
538 # at the beginning, at the end, and between slashes.
539 # also this catches doubled slashes
540 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
544 if ($input =~ m!\0!) {
550 sub validate_refname
{
551 my $input = shift || return undef;
553 # textual hashes are O.K.
554 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
557 # it must be correct pathname
558 $input = validate_pathname
($input)
560 # restrictions on ref name according to git-check-ref-format
561 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
567 # very thin wrapper for decode("utf8", $str, Encode::FB_DEFAULT);
570 return decode
("utf8", $str, Encode
::FB_DEFAULT
);
573 # quote unsafe chars, but keep the slash, even when it's not
574 # correct, but quoted slashes look too horrible in bookmarks
577 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
583 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
586 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
592 # replace invalid utf8 character with SUBSTITUTION sequence
597 $str = to_utf8
($str);
598 $str = $cgi->escapeHTML($str);
599 if ($opts{'-nbsp'}) {
600 $str =~ s/ / /g;
602 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
606 # quote control characters and escape filename to HTML
611 $str = to_utf8
($str);
612 $str = $cgi->escapeHTML($str);
613 if ($opts{'-nbsp'}) {
614 $str =~ s/ / /g;
616 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
620 # Make control characters "printable", using character escape codes (CEC)
623 my %es = ( # character escape codes, aka escape sequences
624 "\t" => '\t', # tab (HT)
625 "\n" => '\n', # line feed (LF)
626 "\r" => '\r', # carrige return (CR)
627 "\f" => '\f', # form feed (FF)
628 "\b" => '\b', # backspace (BS)
629 "\a" => '\a', # alarm (bell) (BEL)
630 "\e" => '\e', # escape (ESC)
631 "\013" => '\v', # vertical tab (VT)
632 "\000" => '\0', # nul character (NUL)
634 my $chr = ( (exists $es{$cntrl})
636 : sprintf('\%03o', ord($cntrl)) );
637 return "<span class=\"cntrl\">$chr</span>";
640 # Alternatively use unicode control pictures codepoints,
641 # Unicode "printable representation" (PR)
644 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
645 return "<span class=\"cntrl\">$chr</span>";
648 # git may return quoted and escaped filenames
654 my %es = ( # character escape codes, aka escape sequences
655 't' => "\t", # tab (HT, TAB)
656 'n' => "\n", # newline (NL)
657 'r' => "\r", # return (CR)
658 'f' => "\f", # form feed (FF)
659 'b' => "\b", # backspace (BS)
660 'a' => "\a", # alarm (bell) (BEL)
661 'e' => "\e", # escape (ESC)
662 'v' => "\013", # vertical tab (VT)
665 if ($seq =~ m/^[0-7]{1,3}$/) {
666 # octal char sequence
667 return chr(oct($seq));
668 } elsif (exists $es{$seq}) {
669 # C escape sequence, aka character escape code
672 # quoted ordinary character
676 if ($str =~ m/^"(.*)"$/) {
679 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
684 # escape tabs (convert tabs to spaces)
688 while ((my $pos = index($line, "\t")) != -1) {
689 if (my $count = (8 - ($pos % 8))) {
690 my $spaces = ' ' x
$count;
691 $line =~ s/\t/$spaces/;
698 sub project_in_list
{
700 my @list = git_get_projects_list
();
701 return @list && scalar(grep { $_->{'path'} eq $project } @list);
704 ## ----------------------------------------------------------------------
705 ## HTML aware string manipulation
710 my $add_len = shift || 10;
712 # allow only $len chars, but don't cut a word if it would fit in $add_len
713 # if it doesn't fit, cut it if it's still longer than the dots we would add
714 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
717 if (length($tail) > 4) {
719 $body =~ s/&[^;]*$//; # remove chopped character entities
724 ## ----------------------------------------------------------------------
725 ## functions returning short strings
727 # CSS class for given age value (in seconds)
731 if ($age < 60*60*2) {
733 } elsif ($age < 60*60*24*2) {
740 # convert age in seconds to "nn units ago" string
745 if ($age > 60*60*24*365*2) {
746 $age_str = (int $age/60/60/24/365);
747 $age_str .= " years ago";
748 } elsif ($age > 60*60*24*(365/12)*2) {
749 $age_str = int $age/60/60/24/(365/12);
750 $age_str .= " months ago";
751 } elsif ($age > 60*60*24*7*2) {
752 $age_str = int $age/60/60/24/7;
753 $age_str .= " weeks ago";
754 } elsif ($age > 60*60*24*2) {
755 $age_str = int $age/60/60/24;
756 $age_str .= " days ago";
757 } elsif ($age > 60*60*2) {
758 $age_str = int $age/60/60;
759 $age_str .= " hours ago";
760 } elsif ($age > 60*2) {
761 $age_str = int $age/60;
762 $age_str .= " min ago";
765 $age_str .= " sec ago";
767 $age_str .= " right now";
772 # convert file mode in octal to symbolic file mode string
774 my $mode = oct shift;
776 if (S_ISDIR
($mode & S_IFMT
)) {
778 } elsif (S_ISLNK
($mode)) {
780 } elsif (S_ISREG
($mode)) {
781 # git cares only about the executable bit
782 if ($mode & S_IXUSR
) {
792 # convert file mode in octal to file type string
796 if ($mode !~ m/^[0-7]+$/) {
802 if (S_ISDIR
($mode & S_IFMT
)) {
804 } elsif (S_ISLNK
($mode)) {
806 } elsif (S_ISREG
($mode)) {
813 # convert file mode in octal to file type description string
817 if ($mode !~ m/^[0-7]+$/) {
823 if (S_ISDIR
($mode & S_IFMT
)) {
825 } elsif (S_ISLNK
($mode)) {
827 } elsif (S_ISREG
($mode)) {
828 if ($mode & S_IXUSR
) {
839 ## ----------------------------------------------------------------------
840 ## functions returning short HTML fragments, or transforming HTML fragments
841 ## which don't belong to other sections
843 # format line of commit message.
844 sub format_log_line_html
{
847 $line = esc_html
($line, -nbsp
=>1);
848 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
851 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
852 -class => "text"}, $hash_text);
853 $line =~ s/$hash_text/$link/;
858 # format marker of refs pointing to given object
859 sub format_ref_marker
{
860 my ($refs, $id) = @_;
863 if (defined $refs->{$id}) {
864 foreach my $ref (@
{$refs->{$id}}) {
865 my ($type, $name) = qw();
866 # e.g. tags/v2.6.11 or heads/next
867 if ($ref =~ m!^(.*?)s?/(.*)$!) {
875 $markers .= " <span class=\"$type\" title=\"$ref\">" .
876 esc_html
($name) . "</span>";
881 return ' <span class="refs">'. $markers . '</span>';
887 # format, perhaps shortened and with markers, title line
888 sub format_subject_html
{
889 my ($long, $short, $href, $extra) = @_;
890 $extra = '' unless defined($extra);
892 if (length($short) < length($long)) {
893 return $cgi->a({-href
=> $href, -class => "list subject",
894 -title
=> to_utf8
($long)},
895 esc_html
($short) . $extra);
897 return $cgi->a({-href
=> $href, -class => "list subject"},
898 esc_html
($long) . $extra);
902 # format patch (diff) line (rather not to be used for diff headers)
903 sub format_diff_line
{
905 my ($from, $to) = @_;
906 my $char = substr($line, 0, 1);
912 $diff_class = " add";
913 } elsif ($char eq "-") {
914 $diff_class = " rem";
915 } elsif ($char eq "@") {
916 $diff_class = " chunk_header";
917 } elsif ($char eq "\\") {
918 $diff_class = " incomplete";
920 $line = untabify
($line);
921 if ($from && $to && $line =~ m/^\@{2} /) {
922 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
923 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
925 $from_lines = 0 unless defined $from_lines;
926 $to_lines = 0 unless defined $to_lines;
928 if ($from->{'href'}) {
929 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
930 -class=>"list"}, $from_text);
933 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
934 -class=>"list"}, $to_text);
936 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
937 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
938 return "<div class=\"diff$diff_class\">$line</div>\n";
940 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
943 ## ----------------------------------------------------------------------
944 ## git utility subroutines, invoking git commands
946 # returns path to the core git executable and the --git-dir parameter as list
948 return $GIT, '--git-dir='.$git_dir;
951 # returns path to the core git executable and the --git-dir parameter as string
953 return join(' ', git_cmd
());
956 # get HEAD ref of given project as hash
957 sub git_get_head_hash
{
959 my $o_git_dir = $git_dir;
961 $git_dir = "$projectroot/$project";
962 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
965 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
969 if (defined $o_git_dir) {
970 $git_dir = $o_git_dir;
975 # get type of given object
979 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
986 sub git_get_project_config
{
987 my ($key, $type) = @_;
989 return unless ($key);
990 $key =~ s/^gitweb\.//;
991 return if ($key =~ m/\W/);
993 my @x = (git_cmd
(), 'config');
994 if (defined $type) { push @x, $type; }
996 push @x, "gitweb.$key";
1002 # get hash of given path at given ref
1003 sub git_get_hash_by_path
{
1005 my $path = shift || return undef;
1010 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1011 or die_error
(undef, "Open git-ls-tree failed");
1013 close $fd or return undef;
1015 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1016 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1017 if (defined $type && $type ne $2) {
1018 # type doesn't match
1024 ## ......................................................................
1025 ## git utility functions, directly accessing git repository
1027 sub git_get_project_description
{
1030 open my $fd, "$projectroot/$path/description" or return undef;
1037 sub git_get_project_url_list
{
1040 open my $fd, "$projectroot/$path/cloneurl" or return;
1041 my @git_project_url_list = map { chomp; $_ } <$fd>;
1044 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
1047 sub git_get_projects_list
{
1052 $filter =~ s/\.git$//;
1054 my ($check_forks) = gitweb_check_feature
('forks');
1056 if (-d
$projects_list) {
1057 # search in directory
1058 my $dir = $projects_list . ($filter ?
"/$filter" : '');
1059 # remove the trailing "/"
1061 my $pfxlen = length("$dir");
1064 follow_fast
=> 1, # follow symbolic links
1065 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1067 # skip project-list toplevel, if we get it.
1068 return if (m!^[/.]$!);
1069 # only directories can be git repositories
1070 return unless (-d
$_);
1072 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1073 # we check related file in $projectroot
1074 if ($check_forks and $subdir =~ m
#/.#) {
1075 $File::Find
::prune
= 1;
1076 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1077 push @list, { path
=> ($filter ?
"$filter/" : '') . $subdir };
1078 $File::Find
::prune
= 1;
1083 } elsif (-f
$projects_list) {
1084 # read from file(url-encoded):
1085 # 'git%2Fgit.git Linus+Torvalds'
1086 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1087 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1089 open my ($fd), $projects_list or return;
1091 while (my $line = <$fd>) {
1093 my ($path, $owner) = split ' ', $line;
1094 $path = unescape
($path);
1095 $owner = unescape
($owner);
1096 if (!defined $path) {
1099 if ($filter ne '') {
1100 # looking for forks;
1101 my $pfx = substr($path, 0, length($filter));
1102 if ($pfx ne $filter) {
1105 my $sfx = substr($path, length($filter));
1106 if ($sfx !~ /^\/.*\
.git
$/) {
1109 } elsif ($check_forks) {
1111 foreach my $filter (keys %paths) {
1112 # looking for forks;
1113 my $pfx = substr($path, 0, length($filter));
1114 if ($pfx ne $filter) {
1117 my $sfx = substr($path, length($filter));
1118 if ($sfx !~ /^\/.*\
.git
$/) {
1121 # is a fork, don't include it in
1126 if (check_export_ok
("$projectroot/$path")) {
1129 owner
=> to_utf8
($owner),
1132 (my $forks_path = $path) =~ s/\.git$//;
1133 $paths{$forks_path}++;
1141 sub git_get_project_owner
{
1142 my $project = shift;
1145 return undef unless $project;
1147 # read from file (url-encoded):
1148 # 'git%2Fgit.git Linus+Torvalds'
1149 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1150 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1151 if (-f
$projects_list) {
1152 open (my $fd , $projects_list);
1153 while (my $line = <$fd>) {
1155 my ($pr, $ow) = split ' ', $line;
1156 $pr = unescape
($pr);
1157 $ow = unescape
($ow);
1158 if ($pr eq $project) {
1159 $owner = to_utf8
($ow);
1165 if (!defined $owner) {
1166 $owner = get_file_owner
("$projectroot/$project");
1172 sub git_get_last_activity
{
1176 $git_dir = "$projectroot/$path";
1177 open($fd, "-|", git_cmd
(), 'for-each-ref',
1178 '--format=%(committer)',
1179 '--sort=-committerdate',
1181 'refs/heads') or return;
1182 my $most_recent = <$fd>;
1183 close $fd or return;
1184 if ($most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1186 my $age = time - $timestamp;
1187 return ($age, age_string
($age));
1191 sub git_get_references
{
1192 my $type = shift || "";
1194 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1195 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1196 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1197 ($type ?
("--", "refs/$type") : ()) # use -- <pattern> if $type
1200 while (my $line = <$fd>) {
1202 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1203 if (defined $refs{$1}) {
1204 push @
{$refs{$1}}, $2;
1210 close $fd or return;
1214 sub git_get_rev_name_tags
{
1215 my $hash = shift || return undef;
1217 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1219 my $name_rev = <$fd>;
1222 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1225 # catches also '$hash undefined' output
1230 ## ----------------------------------------------------------------------
1231 ## parse to hash functions
1235 my $tz = shift || "-0000";
1238 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1239 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1240 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1241 $date{'hour'} = $hour;
1242 $date{'minute'} = $min;
1243 $date{'mday'} = $mday;
1244 $date{'day'} = $days[$wday];
1245 $date{'month'} = $months[$mon];
1246 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1247 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1248 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1249 $mday, $months[$mon], $hour ,$min;
1250 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1251 1900+$year, $mon, $mday, $hour ,$min, $sec;
1253 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1254 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1255 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1256 $date{'hour_local'} = $hour;
1257 $date{'minute_local'} = $min;
1258 $date{'tz_local'} = $tz;
1259 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1260 1900+$year, $mon+1, $mday,
1261 $hour, $min, $sec, $tz);
1270 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1271 $tag{'id'} = $tag_id;
1272 while (my $line = <$fd>) {
1274 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1275 $tag{'object'} = $1;
1276 } elsif ($line =~ m/^type (.+)$/) {
1278 } elsif ($line =~ m/^tag (.+)$/) {
1280 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1281 $tag{'author'} = $1;
1284 } elsif ($line =~ m/--BEGIN/) {
1285 push @comment, $line;
1287 } elsif ($line eq "") {
1291 push @comment, <$fd>;
1292 $tag{'comment'} = \
@comment;
1293 close $fd or return;
1294 if (!defined $tag{'name'}) {
1300 sub parse_commit_text
{
1301 my ($commit_text, $withparents) = @_;
1302 my @commit_lines = split '\n', $commit_text;
1305 pop @commit_lines; # Remove '\0'
1307 my $header = shift @commit_lines;
1308 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
1311 ($co{'id'}, my @parents) = split ' ', $header;
1312 while (my $line = shift @commit_lines) {
1313 last if $line eq "\n";
1314 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1316 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1318 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1320 $co{'author_epoch'} = $2;
1321 $co{'author_tz'} = $3;
1322 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1323 $co{'author_name'} = $1;
1324 $co{'author_email'} = $2;
1326 $co{'author_name'} = $co{'author'};
1328 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1329 $co{'committer'} = $1;
1330 $co{'committer_epoch'} = $2;
1331 $co{'committer_tz'} = $3;
1332 $co{'committer_name'} = $co{'committer'};
1333 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
1334 $co{'committer_name'} = $1;
1335 $co{'committer_email'} = $2;
1337 $co{'committer_name'} = $co{'committer'};
1341 if (!defined $co{'tree'}) {
1344 $co{'parents'} = \
@parents;
1345 $co{'parent'} = $parents[0];
1347 foreach my $title (@commit_lines) {
1350 $co{'title'} = chop_str
($title, 80, 5);
1351 # remove leading stuff of merges to make the interesting part visible
1352 if (length($title) > 50) {
1353 $title =~ s/^Automatic //;
1354 $title =~ s/^merge (of|with) /Merge ... /i;
1355 if (length($title) > 50) {
1356 $title =~ s/(http|rsync):\/\///;
1358 if (length($title) > 50) {
1359 $title =~ s/(master|www|rsync)\.//;
1361 if (length($title) > 50) {
1362 $title =~ s/kernel.org:?//;
1364 if (length($title) > 50) {
1365 $title =~ s/\/pub\/scm//;
1368 $co{'title_short'} = chop_str
($title, 50, 5);
1372 if ($co{'title'} eq "") {
1373 $co{'title'} = $co{'title_short'} = '(no commit message)';
1375 # remove added spaces
1376 foreach my $line (@commit_lines) {
1379 $co{'comment'} = \
@commit_lines;
1381 my $age = time - $co{'committer_epoch'};
1383 $co{'age_string'} = age_string
($age);
1384 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1385 if ($age > 60*60*24*7*2) {
1386 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1387 $co{'age_string_age'} = $co{'age_string'};
1389 $co{'age_string_date'} = $co{'age_string'};
1390 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1396 my ($commit_id) = @_;
1401 open my $fd, "-|", git_cmd
(), "rev-list",
1407 or die_error
(undef, "Open git-rev-list failed");
1408 %co = parse_commit_text
(<$fd>, 1);
1415 my ($commit_id, $maxcount, $skip, $arg, $filename) = @_;
1423 open my $fd, "-|", git_cmd
(), "rev-list",
1425 ($arg ?
($arg) : ()),
1426 ("--max-count=" . $maxcount),
1427 ("--skip=" . $skip),
1430 ($filename ?
($filename) : ())
1431 or die_error
(undef, "Open git-rev-list failed");
1432 while (my $line = <$fd>) {
1433 my %co = parse_commit_text
($line);
1438 return wantarray ?
@cos : \
@cos;
1441 # parse ref from ref_file, given by ref_id, with given type
1443 my $ref_file = shift;
1445 my $type = shift || git_get_type
($ref_id);
1448 $ref_item{'type'} = $type;
1449 $ref_item{'id'} = $ref_id;
1450 $ref_item{'epoch'} = 0;
1451 $ref_item{'age'} = "unknown";
1452 if ($type eq "tag") {
1453 my %tag = parse_tag
($ref_id);
1454 $ref_item{'comment'} = $tag{'comment'};
1455 if ($tag{'type'} eq "commit") {
1456 my %co = parse_commit
($tag{'object'});
1457 $ref_item{'epoch'} = $co{'committer_epoch'};
1458 $ref_item{'age'} = $co{'age_string'};
1459 } elsif (defined($tag{'epoch'})) {
1460 my $age = time - $tag{'epoch'};
1461 $ref_item{'epoch'} = $tag{'epoch'};
1462 $ref_item{'age'} = age_string
($age);
1464 $ref_item{'reftype'} = $tag{'type'};
1465 $ref_item{'name'} = $tag{'name'};
1466 $ref_item{'refid'} = $tag{'object'};
1467 } elsif ($type eq "commit"){
1468 my %co = parse_commit
($ref_id);
1469 $ref_item{'reftype'} = "commit";
1470 $ref_item{'name'} = $ref_file;
1471 $ref_item{'title'} = $co{'title'};
1472 $ref_item{'refid'} = $ref_id;
1473 $ref_item{'epoch'} = $co{'committer_epoch'};
1474 $ref_item{'age'} = $co{'age_string'};
1476 $ref_item{'reftype'} = $type;
1477 $ref_item{'name'} = $ref_file;
1478 $ref_item{'refid'} = $ref_id;
1484 # parse line of git-diff-tree "raw" output
1485 sub parse_difftree_raw_line
{
1489 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1490 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1491 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1492 $res{'from_mode'} = $1;
1493 $res{'to_mode'} = $2;
1494 $res{'from_id'} = $3;
1496 $res{'status'} = $5;
1497 $res{'similarity'} = $6;
1498 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1499 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1501 $res{'file'} = unquote
($7);
1504 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1505 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1506 $res{'commit'} = $1;
1509 return wantarray ?
%res : \
%res;
1512 # parse line of git-ls-tree output
1513 sub parse_ls_tree_line
($;%) {
1518 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1519 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
1527 $res{'name'} = unquote
($4);
1530 return wantarray ?
%res : \
%res;
1533 ## ......................................................................
1534 ## parse to array of hashes functions
1536 sub git_get_heads_list
{
1540 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1541 ($limit ?
'--count='.($limit+1) : ()), '--sort=-committerdate',
1542 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
1545 while (my $line = <$fd>) {
1549 my ($refinfo, $committerinfo) = split(/\0/, $line);
1550 my ($hash, $name, $title) = split(' ', $refinfo, 3);
1551 my ($committer, $epoch, $tz) =
1552 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
1553 $name =~ s!^refs/heads/!!;
1555 $ref_item{'name'} = $name;
1556 $ref_item{'id'} = $hash;
1557 $ref_item{'title'} = $title || '(no commit message)';
1558 $ref_item{'epoch'} = $epoch;
1560 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1562 $ref_item{'age'} = "unknown";
1565 push @headslist, \
%ref_item;
1569 return wantarray ?
@headslist : \
@headslist;
1572 sub git_get_tags_list
{
1576 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1577 ($limit ?
'--count='.($limit+1) : ()), '--sort=-creatordate',
1578 '--format=%(objectname) %(objecttype) %(refname) '.
1579 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
1582 while (my $line = <$fd>) {
1586 my ($refinfo, $creatorinfo) = split(/\0/, $line);
1587 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
1588 my ($creator, $epoch, $tz) =
1589 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
1590 $name =~ s!^refs/tags/!!;
1592 $ref_item{'type'} = $type;
1593 $ref_item{'id'} = $id;
1594 $ref_item{'name'} = $name;
1595 if ($type eq "tag") {
1596 $ref_item{'subject'} = $title;
1597 $ref_item{'reftype'} = $reftype;
1598 $ref_item{'refid'} = $refid;
1600 $ref_item{'reftype'} = $type;
1601 $ref_item{'refid'} = $id;
1604 if ($type eq "tag" || $type eq "commit") {
1605 $ref_item{'epoch'} = $epoch;
1607 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1609 $ref_item{'age'} = "unknown";
1613 push @tagslist, \
%ref_item;
1617 return wantarray ?
@tagslist : \
@tagslist;
1620 ## ----------------------------------------------------------------------
1621 ## filesystem-related functions
1623 sub get_file_owner
{
1626 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1627 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1628 if (!defined $gcos) {
1632 $owner =~ s/[,;].*$//;
1633 return to_utf8
($owner);
1636 ## ......................................................................
1637 ## mimetype related functions
1639 sub mimetype_guess_file
{
1640 my $filename = shift;
1641 my $mimemap = shift;
1642 -r
$mimemap or return undef;
1645 open(MIME
, $mimemap) or return undef;
1647 next if m/^#/; # skip comments
1648 my ($mime, $exts) = split(/\t+/);
1649 if (defined $exts) {
1650 my @exts = split(/\s+/, $exts);
1651 foreach my $ext (@exts) {
1652 $mimemap{$ext} = $mime;
1658 $filename =~ /\.([^.]*)$/;
1659 return $mimemap{$1};
1662 sub mimetype_guess
{
1663 my $filename = shift;
1665 $filename =~ /\./ or return undef;
1667 if ($mimetypes_file) {
1668 my $file = $mimetypes_file;
1669 if ($file !~ m!^/!) { # if it is relative path
1670 # it is relative to project
1671 $file = "$projectroot/$project/$file";
1673 $mime = mimetype_guess_file
($filename, $file);
1675 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1681 my $filename = shift;
1684 my $mime = mimetype_guess
($filename);
1685 $mime and return $mime;
1689 return $default_blob_plain_mimetype unless $fd;
1692 return 'text/plain' .
1693 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
1694 } elsif (! $filename) {
1695 return 'application/octet-stream';
1696 } elsif ($filename =~ m/\.png$/i) {
1698 } elsif ($filename =~ m/\.gif$/i) {
1700 } elsif ($filename =~ m/\.jpe?g$/i) {
1701 return 'image/jpeg';
1703 return 'application/octet-stream';
1707 ## ======================================================================
1708 ## functions printing HTML: header, footer, error page
1710 sub git_header_html
{
1711 my $status = shift || "200 OK";
1712 my $expires = shift;
1714 my $title = "$site_name";
1715 if (defined $project) {
1716 $title .= " - " . to_utf8
($project);
1717 if (defined $action) {
1718 $title .= "/$action";
1719 if (defined $file_name) {
1720 $title .= " - " . esc_path
($file_name);
1721 if ($action eq "tree" && $file_name !~ m
|/$|) {
1728 # require explicit support from the UA if we are to send the page as
1729 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1730 # we have to do this because MSIE sometimes globs '*/*', pretending to
1731 # support xhtml+xml but choking when it gets what it asked for.
1732 if (defined $cgi->http('HTTP_ACCEPT') &&
1733 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1734 $cgi->Accept('application/xhtml+xml') != 0) {
1735 $content_type = 'application/xhtml+xml';
1737 $content_type = 'text/html';
1739 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1740 -status
=> $status, -expires
=> $expires);
1741 my $mod_perl_version = $ENV{'MOD_PERL'} ?
" $ENV{'MOD_PERL'}" : '';
1743 <?xml version="1.0" encoding="utf-8"?>
1744 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1745 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1746 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1747 <!-- git core binaries version $git_version -->
1749 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1750 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
1751 <meta name="robots" content="index, nofollow"/>
1752 <title>$title</title>
1754 # print out each stylesheet that exist
1755 if (defined $stylesheet) {
1756 #provides backwards capability for those people who define style sheet in a config file
1757 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1759 foreach my $stylesheet (@stylesheets) {
1760 next unless $stylesheet;
1761 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1764 if (defined $project) {
1765 printf('<link rel="alternate" title="%s log RSS feed" '.
1766 'href="%s" type="application/rss+xml" />'."\n",
1767 esc_param
($project), href
(action
=>"rss"));
1768 printf('<link rel="alternate" title="%s log Atom feed" '.
1769 'href="%s" type="application/atom+xml" />'."\n",
1770 esc_param
($project), href
(action
=>"atom"));
1772 printf('<link rel="alternate" title="%s projects list" '.
1773 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1774 $site_name, href
(project
=>undef, action
=>"project_index"));
1775 printf('<link rel="alternate" title="%s projects feeds" '.
1776 'href="%s" type="text/x-opml"/>'."\n",
1777 $site_name, href
(project
=>undef, action
=>"opml"));
1779 if (defined $favicon) {
1780 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png"/>\n);
1786 if (-f
$site_header) {
1787 open (my $fd, $site_header);
1792 print "<div class=\"page_header\">\n" .
1793 $cgi->a({-href
=> esc_url
($logo_url),
1794 -title
=> $logo_label},
1795 qq(<img src
="$logo" width
="72" height
="27" alt
="git" class="logo"/>));
1796 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1797 if (defined $project) {
1798 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1799 if (defined $action) {
1804 my ($have_search) = gitweb_check_feature
('search');
1805 if ((defined $project) && ($have_search)) {
1806 if (!defined $searchtext) {
1810 if (defined $hash_base) {
1811 $search_hash = $hash_base;
1812 } elsif (defined $hash) {
1813 $search_hash = $hash;
1815 $search_hash = "HEAD";
1817 $cgi->param("a", "search");
1818 $cgi->param("h", $search_hash);
1819 $cgi->param("p", $project);
1820 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
1821 "<div class=\"search\">\n" .
1822 $cgi->hidden(-name
=> "p") . "\n" .
1823 $cgi->hidden(-name
=> "a") . "\n" .
1824 $cgi->hidden(-name
=> "h") . "\n" .
1825 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
1826 -values => ['commit', 'author', 'committer', 'pickaxe']) .
1827 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
1829 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1831 $cgi->end_form() . "\n";
1836 sub git_footer_html
{
1837 print "<div class=\"page_footer\">\n";
1838 if (defined $project) {
1839 my $descr = git_get_project_description
($project);
1840 if (defined $descr) {
1841 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1843 print $cgi->a({-href
=> href
(action
=>"rss"),
1844 -class => "rss_logo"}, "RSS") . " ";
1845 print $cgi->a({-href
=> href
(action
=>"atom"),
1846 -class => "rss_logo"}, "Atom") . "\n";
1848 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1849 -class => "rss_logo"}, "OPML") . " ";
1850 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1851 -class => "rss_logo"}, "TXT") . "\n";
1855 if (-f
$site_footer) {
1856 open (my $fd, $site_footer);
1866 my $status = shift || "403 Forbidden";
1867 my $error = shift || "Malformed query, file missing or permission denied";
1869 git_header_html
($status);
1871 <div class="page_body">
1881 ## ----------------------------------------------------------------------
1882 ## functions printing or outputting HTML: navigation
1884 sub git_print_page_nav
{
1885 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1886 $extra = '' if !defined $extra; # pager or formats
1888 my @navs = qw(summary shortlog log commit commitdiff tree);
1890 @navs = grep { $_ ne $suppress } @navs;
1893 my %arg = map { $_ => {action
=>$_} } @navs;
1894 if (defined $head) {
1895 for (qw(commit commitdiff)) {
1896 $arg{$_}{'hash'} = $head;
1898 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1899 for (qw(shortlog log)) {
1900 $arg{$_}{'hash'} = $head;
1904 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
1905 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
1907 print "<div class=\"page_nav\">\n" .
1909 map { $_ eq $current ?
1910 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1912 print "<br/>\n$extra<br/>\n" .
1916 sub format_paging_nav
{
1917 my ($action, $hash, $head, $page, $nrevs) = @_;
1921 if ($hash ne $head || $page) {
1922 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1924 $paging_nav .= "HEAD";
1928 $paging_nav .= " ⋅ " .
1929 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1930 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1932 $paging_nav .= " ⋅ prev";
1935 if ($nrevs >= (100 * ($page+1)-1)) {
1936 $paging_nav .= " ⋅ " .
1937 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1938 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1940 $paging_nav .= " ⋅ next";
1946 ## ......................................................................
1947 ## functions printing or outputting HTML: div
1949 sub git_print_header_div
{
1950 my ($action, $title, $hash, $hash_base) = @_;
1953 $args{'action'} = $action;
1954 $args{'hash'} = $hash if $hash;
1955 $args{'hash_base'} = $hash_base if $hash_base;
1957 print "<div class=\"header\">\n" .
1958 $cgi->a({-href
=> href
(%args), -class => "title"},
1959 $title ?
$title : $action) .
1963 #sub git_print_authorship (\%) {
1964 sub git_print_authorship
{
1967 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
1968 print "<div class=\"author_date\">" .
1969 esc_html
($co->{'author_name'}) .
1971 if ($ad{'hour_local'} < 6) {
1972 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1973 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1975 printf(" (%02d:%02d %s)",
1976 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1981 sub git_print_page_path
{
1987 print "<div class=\"page_path\">";
1988 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
1989 -title
=> 'tree root'}, to_utf8
("[$project]"));
1991 if (defined $name) {
1992 my @dirname = split '/', $name;
1993 my $basename = pop @dirname;
1996 foreach my $dir (@dirname) {
1997 $fullname .= ($fullname ?
'/' : '') . $dir;
1998 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
2000 -title
=> $fullname}, esc_path
($dir));
2003 if (defined $type && $type eq 'blob') {
2004 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2006 -title
=> $name}, esc_path
($basename));
2007 } elsif (defined $type && $type eq 'tree') {
2008 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2010 -title
=> $name}, esc_path
($basename));
2013 print esc_path
($basename);
2016 print "<br/></div>\n";
2019 # sub git_print_log (\@;%) {
2020 sub git_print_log
($;%) {
2024 if ($opts{'-remove_title'}) {
2025 # remove title, i.e. first line of log
2028 # remove leading empty lines
2029 while (defined $log->[0] && $log->[0] eq "") {
2036 foreach my $line (@
$log) {
2037 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2040 if (! $opts{'-remove_signoff'}) {
2041 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2044 # remove signoff lines
2051 # print only one empty line
2052 # do not print empty line after signoff
2054 next if ($empty || $signoff);
2060 print format_log_line_html
($line) . "<br/>\n";
2063 if ($opts{'-final_empty_line'}) {
2064 # end with single empty line
2065 print "<br/>\n" unless $empty;
2069 # return link target (what link points to)
2070 sub git_get_link_target
{
2075 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2079 $link_target = <$fd>;
2084 return $link_target;
2087 # given link target, and the directory (basedir) the link is in,
2088 # return target of link relative to top directory (top tree);
2089 # return undef if it is not possible (including absolute links).
2090 sub normalize_link_target
{
2091 my ($link_target, $basedir, $hash_base) = @_;
2093 # we can normalize symlink target only if $hash_base is provided
2094 return unless $hash_base;
2096 # absolute symlinks (beginning with '/') cannot be normalized
2097 return if (substr($link_target, 0, 1) eq '/');
2099 # normalize link target to path from top (root) tree (dir)
2102 $path = $basedir . '/' . $link_target;
2104 # we are in top (root) tree (dir)
2105 $path = $link_target;
2108 # remove //, /./, and /../
2110 foreach my $part (split('/', $path)) {
2111 # discard '.' and ''
2112 next if (!$part || $part eq '.');
2114 if ($part eq '..') {
2118 # link leads outside repository (outside top dir)
2122 push @path_parts, $part;
2125 $path = join('/', @path_parts);
2130 # print tree entry (row of git_tree), but without encompassing <tr> element
2131 sub git_print_tree_entry
{
2132 my ($t, $basedir, $hash_base, $have_blame) = @_;
2135 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2137 # The format of a table row is: mode list link. Where mode is
2138 # the mode of the entry, list is the name of the entry, an href,
2139 # and link is the action links of the entry.
2141 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2142 if ($t->{'type'} eq "blob") {
2143 print "<td class=\"list\">" .
2144 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2145 file_name
=>"$basedir$t->{'name'}", %base_key),
2146 -class => "list"}, esc_path
($t->{'name'}));
2147 if (S_ISLNK
(oct $t->{'mode'})) {
2148 my $link_target = git_get_link_target
($t->{'hash'});
2150 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2151 if (defined $norm_target) {
2153 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2154 file_name
=>$norm_target),
2155 -title
=> $norm_target}, esc_path
($link_target));
2157 print " -> " . esc_path
($link_target);
2162 print "<td class=\"link\">";
2163 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2164 file_name
=>"$basedir$t->{'name'}", %base_key)},
2168 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2169 file_name
=>"$basedir$t->{'name'}", %base_key)},
2172 if (defined $hash_base) {
2174 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2175 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2179 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2180 file_name
=>"$basedir$t->{'name'}")},
2184 } elsif ($t->{'type'} eq "tree") {
2185 print "<td class=\"list\">";
2186 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2187 file_name
=>"$basedir$t->{'name'}", %base_key)},
2188 esc_path
($t->{'name'}));
2190 print "<td class=\"link\">";
2191 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2192 file_name
=>"$basedir$t->{'name'}", %base_key)},
2194 if (defined $hash_base) {
2196 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2197 file_name
=>"$basedir$t->{'name'}")},
2204 ## ......................................................................
2205 ## functions printing large fragments of HTML
2207 sub git_difftree_body
{
2208 my ($difftree, $hash, $parent) = @_;
2209 my ($have_blame) = gitweb_check_feature
('blame');
2210 print "<div class=\"list_head\">\n";
2211 if ($#{$difftree} > 10) {
2212 print(($#{$difftree} + 1) . " files changed:\n");
2216 print "<table class=\"diff_tree\">\n";
2219 foreach my $line (@
{$difftree}) {
2220 my %diff = parse_difftree_raw_line
($line);
2223 print "<tr class=\"dark\">\n";
2225 print "<tr class=\"light\">\n";
2229 my ($to_mode_oct, $to_mode_str, $to_file_type);
2230 my ($from_mode_oct, $from_mode_str, $from_file_type);
2231 if ($diff{'to_mode'} ne ('0' x
6)) {
2232 $to_mode_oct = oct $diff{'to_mode'};
2233 if (S_ISREG
($to_mode_oct)) { # only for regular file
2234 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
2236 $to_file_type = file_type
($diff{'to_mode'});
2238 if ($diff{'from_mode'} ne ('0' x
6)) {
2239 $from_mode_oct = oct $diff{'from_mode'};
2240 if (S_ISREG
($to_mode_oct)) { # only for regular file
2241 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
2243 $from_file_type = file_type
($diff{'from_mode'});
2246 if ($diff{'status'} eq "A") { # created
2247 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
2248 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
2249 $mode_chng .= "]</span>";
2251 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2252 hash_base
=>$hash, file_name
=>$diff{'file'}),
2253 -class => "list"}, esc_path
($diff{'file'}));
2255 print "<td>$mode_chng</td>\n";
2256 print "<td class=\"link\">";
2257 if ($action eq 'commitdiff') {
2260 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2263 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2264 hash_base
=>$hash, file_name
=>$diff{'file'})},
2268 } elsif ($diff{'status'} eq "D") { # deleted
2269 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
2271 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
2272 hash_base
=>$parent, file_name
=>$diff{'file'}),
2273 -class => "list"}, esc_path
($diff{'file'}));
2275 print "<td>$mode_chng</td>\n";
2276 print "<td class=\"link\">";
2277 if ($action eq 'commitdiff') {
2280 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2283 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
2284 hash_base
=>$parent, file_name
=>$diff{'file'})},
2287 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2288 file_name
=>$diff{'file'})},
2291 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2292 file_name
=>$diff{'file'})},
2296 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
2297 my $mode_chnge = "";
2298 if ($diff{'from_mode'} != $diff{'to_mode'}) {
2299 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
2300 if ($from_file_type ne $to_file_type) {
2301 $mode_chnge .= " from $from_file_type to $to_file_type";
2303 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
2304 if ($from_mode_str && $to_mode_str) {
2305 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
2306 } elsif ($to_mode_str) {
2307 $mode_chnge .= " mode: $to_mode_str";
2310 $mode_chnge .= "]</span>\n";
2313 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2314 hash_base
=>$hash, file_name
=>$diff{'file'}),
2315 -class => "list"}, esc_path
($diff{'file'}));
2317 print "<td>$mode_chnge</td>\n";
2318 print "<td class=\"link\">";
2319 if ($action eq 'commitdiff') {
2322 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2324 } elsif ($diff{'to_id'} ne $diff{'from_id'}) {
2325 # "commit" view and modified file (not onlu mode changed)
2326 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2327 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
2328 hash_base
=>$hash, hash_parent_base
=>$parent,
2329 file_name
=>$diff{'file'})},
2333 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2334 hash_base
=>$hash, file_name
=>$diff{'file'})},
2337 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2338 file_name
=>$diff{'file'})},
2341 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2342 file_name
=>$diff{'file'})},
2346 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
2347 my %status_name = ('R' => 'moved', 'C' => 'copied');
2348 my $nstatus = $status_name{$diff{'status'}};
2350 if ($diff{'from_mode'} != $diff{'to_mode'}) {
2351 # mode also for directories, so we cannot use $to_mode_str
2352 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
2355 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2356 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
2357 -class => "list"}, esc_path
($diff{'to_file'})) . "</td>\n" .
2358 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
2359 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
2360 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
2361 -class => "list"}, esc_path
($diff{'from_file'})) .
2362 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
2363 "<td class=\"link\">";
2364 if ($action eq 'commitdiff') {
2367 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2369 } elsif ($diff{'to_id'} ne $diff{'from_id'}) {
2370 # "commit" view and modified file (not only pure rename or copy)
2371 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2372 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
2373 hash_base
=>$hash, hash_parent_base
=>$parent,
2374 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
2378 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2379 hash_base
=>$parent, file_name
=>$diff{'to_file'})},
2382 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2383 file_name
=>$diff{'to_file'})},
2386 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2387 file_name
=>$diff{'to_file'})},
2391 } # we should not encounter Unmerged (U) or Unknown (X) status
2397 sub git_patchset_body
{
2398 my ($fd, $difftree, $hash, $hash_parent) = @_;
2401 my $patch_number = 0;
2406 print "<div class=\"patchset\">\n";
2408 # skip to first patch
2409 while ($patch_line = <$fd>) {
2412 last if ($patch_line =~ m/^diff /);
2416 while ($patch_line) {
2418 my ($from_id, $to_id);
2421 #assert($patch_line =~ m/^diff /) if DEBUG;
2422 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
2424 push @diff_header, $patch_line;
2426 # extended diff header
2428 while ($patch_line = <$fd>) {
2431 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
2433 if ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2438 push @diff_header, $patch_line;
2440 my $last_patch_line = $patch_line;
2442 # check if current patch belong to current raw line
2443 # and parse raw git-diff line if needed
2444 if (defined $diffinfo &&
2445 $diffinfo->{'from_id'} eq $from_id &&
2446 $diffinfo->{'to_id'} eq $to_id) {
2447 # this is split patch
2448 print "<div class=\"patch cont\">\n";
2450 # advance raw git-diff output if needed
2451 $patch_idx++ if defined $diffinfo;
2453 # read and prepare patch information
2454 if (ref($difftree->[$patch_idx]) eq "HASH") {
2455 # pre-parsed (or generated by hand)
2456 $diffinfo = $difftree->[$patch_idx];
2458 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
2460 $from{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
2461 $to{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
2462 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2463 $from{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2464 hash
=>$diffinfo->{'from_id'},
2465 file_name
=>$from{'file'});
2467 delete $from{'href'};
2469 if ($diffinfo->{'status'} ne "D") { # not deleted file
2470 $to{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2471 hash
=>$diffinfo->{'to_id'},
2472 file_name
=>$to{'file'});
2476 # this is first patch for raw difftree line with $patch_idx index
2477 # we index @$difftree array from 0, but number patches from 1
2478 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
2481 # print "git diff" header
2482 $patch_line = shift @diff_header;
2483 $patch_line =~ s!^(diff (.*?) )"?a/.*$!$1!;
2484 if ($from{'href'}) {
2485 $patch_line .= $cgi->a({-href
=> $from{'href'}, -class => "path"},
2486 'a/' . esc_path
($from{'file'}));
2487 } else { # file was added
2488 $patch_line .= 'a/' . esc_path
($from{'file'});
2492 $patch_line .= $cgi->a({-href
=> $to{'href'}, -class => "path"},
2493 'b/' . esc_path
($to{'file'}));
2494 } else { # file was deleted
2495 $patch_line .= 'b/' . esc_path
($to{'file'});
2497 print "<div class=\"diff header\">$patch_line</div>\n";
2499 # print extended diff header
2500 print "<div class=\"diff extended_header\">\n" if (@diff_header > 0);
2502 foreach $patch_line (@diff_header) {
2504 if ($patch_line =~ s!^((copy|rename) from ).*$!$1! && $from{'href'}) {
2505 $patch_line .= $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2506 esc_path
($from{'file'}));
2508 if ($patch_line =~ s!^((copy|rename) to ).*$!$1! && $to{'href'}) {
2509 $patch_line .= $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2510 esc_path
($to{'file'}));
2513 if ($patch_line =~ m/\s(\d{6})$/) {
2514 $patch_line .= '<span class="info"> (' .
2515 file_type_long
($1) .
2519 if ($patch_line =~ m/^index/) {
2520 my ($from_link, $to_link);
2521 if ($from{'href'}) {
2522 $from_link = $cgi->a({-href
=>$from{'href'}, -class=>"hash"},
2523 substr($diffinfo->{'from_id'},0,7));
2525 $from_link = '0' x
7;
2528 $to_link = $cgi->a({-href
=>$to{'href'}, -class=>"hash"},
2529 substr($diffinfo->{'to_id'},0,7));
2534 # my ($from_hash, $to_hash) =
2535 # ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/);
2536 # my ($from_id, $to_id) =
2537 # ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2538 # ($from_hash eq $from_id) && ($to_hash eq $to_id);
2540 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2541 $patch_line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
2543 print $patch_line . "<br/>\n";
2545 print "</div>\n" if (@diff_header > 0); # class="diff extended_header"
2547 # from-file/to-file diff header
2548 $patch_line = $last_patch_line;
2549 if (! $patch_line) {
2550 print "</div>\n"; # class="patch"
2553 next PATCH
if ($patch_line =~ m/^diff /);
2554 #assert($patch_line =~ m/^---/) if DEBUG;
2555 if ($from{'href'} && $patch_line =~ m!^--- "?a/!) {
2556 $patch_line = '--- a/' .
2557 $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2558 esc_path
($from{'file'}));
2560 print "<div class=\"diff from_file\">$patch_line</div>\n";
2562 $patch_line = <$fd>;
2565 #assert($patch_line =~ m/^+++/) if DEBUG;
2566 if ($to{'href'} && $patch_line =~ m!^\+\+\+ "?b/!) {
2567 $patch_line = '+++ b/' .
2568 $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2569 esc_path
($to{'file'}));
2571 print "<div class=\"diff to_file\">$patch_line</div>\n";
2575 while ($patch_line = <$fd>) {
2578 next PATCH
if ($patch_line =~ m/^diff /);
2580 print format_diff_line
($patch_line, \
%from, \
%to);
2584 print "</div>\n"; # class="patch"
2586 print "<div class=\"diff nodifferences\">No differences found</div>\n" if (!$patch_number);
2588 print "</div>\n"; # class="patchset"
2591 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2593 sub git_project_list_body
{
2594 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
2596 my ($check_forks) = gitweb_check_feature
('forks');
2599 foreach my $pr (@
$projlist) {
2600 my (@aa) = git_get_last_activity
($pr->{'path'});
2604 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
2605 if (!defined $pr->{'descr'}) {
2606 my $descr = git_get_project_description
($pr->{'path'}) || "";
2607 $pr->{'descr_long'} = to_utf8
($descr);
2608 $pr->{'descr'} = chop_str
($descr, 25, 5);
2610 if (!defined $pr->{'owner'}) {
2611 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2614 my $pname = $pr->{'path'};
2615 if (($pname =~ s/\.git$//) &&
2616 ($pname !~ /\/$/) &&
2617 (-d
"$projectroot/$pname")) {
2618 $pr->{'forks'} = "-d $projectroot/$pname";
2624 push @projects, $pr;
2627 $order ||= $default_projects_order;
2628 $from = 0 unless defined $from;
2629 $to = $#projects if (!defined $to || $#projects < $to);
2631 print "<table class=\"project_list\">\n";
2632 unless ($no_header) {
2635 print "<th></th>\n";
2637 if ($order eq "project") {
2638 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2639 print "<th>Project</th>\n";
2642 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2643 -class => "header"}, "Project") .
2646 if ($order eq "descr") {
2647 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2648 print "<th>Description</th>\n";
2651 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2652 -class => "header"}, "Description") .
2655 if ($order eq "owner") {
2656 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2657 print "<th>Owner</th>\n";
2660 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2661 -class => "header"}, "Owner") .
2664 if ($order eq "age") {
2665 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
2666 print "<th>Last Change</th>\n";
2669 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
2670 -class => "header"}, "Last Change") .
2673 print "<th></th>\n" .
2677 for (my $i = $from; $i <= $to; $i++) {
2678 my $pr = $projects[$i];
2680 print "<tr class=\"dark\">\n";
2682 print "<tr class=\"light\">\n";
2687 if ($pr->{'forks'}) {
2688 print "<!-- $pr->{'forks'} -->\n";
2689 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
2693 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2694 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2695 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2696 -class => "list", -title
=> $pr->{'descr_long'}},
2697 esc_html
($pr->{'descr'})) . "</td>\n" .
2698 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2699 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
2700 $pr->{'age_string'} . "</td>\n" .
2701 "<td class=\"link\">" .
2702 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2703 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2704 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
2705 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
2706 ($pr->{'forks'} ?
" | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
2710 if (defined $extra) {
2713 print "<td></td>\n";
2715 print "<td colspan=\"5\">$extra</td>\n" .
2721 sub git_shortlog_body
{
2722 # uses global variable $project
2723 my ($commitlist, $from, $to, $refs, $extra) = @_;
2725 my $have_snapshot = gitweb_have_snapshot
();
2727 $from = 0 unless defined $from;
2728 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
2730 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
2732 for (my $i = $from; $i <= $to; $i++) {
2733 my %co = %{$commitlist->[$i]};
2734 my $commit = $co{'id'};
2735 my $ref = format_ref_marker
($refs, $commit);
2737 print "<tr class=\"dark\">\n";
2739 print "<tr class=\"light\">\n";
2742 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
2743 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2744 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
2746 print format_subject_html
($co{'title'}, $co{'title_short'},
2747 href
(action
=>"commit", hash
=>$commit), $ref);
2749 "<td class=\"link\">" .
2750 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
2751 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
2752 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
2753 if ($have_snapshot) {
2754 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
2759 if (defined $extra) {
2761 "<td colspan=\"4\">$extra</td>\n" .
2767 sub git_history_body
{
2768 # Warning: assumes constant type (blob or tree) during history
2769 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
2771 $from = 0 unless defined $from;
2772 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
2774 print "<table class=\"history\" cellspacing=\"0\">\n";
2776 for (my $i = $from; $i <= $to; $i++) {
2777 my %co = %{$commitlist->[$i]};
2781 my $commit = $co{'id'};
2783 my $ref = format_ref_marker
($refs, $commit);
2786 print "<tr class=\"dark\">\n";
2788 print "<tr class=\"light\">\n";
2791 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2792 # shortlog uses chop_str($co{'author_name'}, 10)
2793 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2795 # originally git_history used chop_str($co{'title'}, 50)
2796 print format_subject_html
($co{'title'}, $co{'title_short'},
2797 href
(action
=>"commit", hash
=>$commit), $ref);
2799 "<td class=\"link\">" .
2800 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
2801 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
2803 if ($ftype eq 'blob') {
2804 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
2805 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2806 if (defined $blob_current && defined $blob_parent &&
2807 $blob_current ne $blob_parent) {
2809 $cgi->a({-href
=> href
(action
=>"blobdiff",
2810 hash
=>$blob_current, hash_parent
=>$blob_parent,
2811 hash_base
=>$hash_base, hash_parent_base
=>$commit,
2812 file_name
=>$file_name)},
2819 if (defined $extra) {
2821 "<td colspan=\"4\">$extra</td>\n" .
2828 # uses global variable $project
2829 my ($taglist, $from, $to, $extra) = @_;
2830 $from = 0 unless defined $from;
2831 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2833 print "<table class=\"tags\" cellspacing=\"0\">\n";
2835 for (my $i = $from; $i <= $to; $i++) {
2836 my $entry = $taglist->[$i];
2838 my $comment = $tag{'subject'};
2840 if (defined $comment) {
2841 $comment_short = chop_str
($comment, 30, 5);
2844 print "<tr class=\"dark\">\n";
2846 print "<tr class=\"light\">\n";
2849 if (defined $tag{'age'}) {
2850 print "<td><i>$tag{'age'}</i></td>\n";
2852 print "<td></td>\n";
2855 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
2856 -class => "list name"}, esc_html
($tag{'name'})) .
2859 if (defined $comment) {
2860 print format_subject_html
($comment, $comment_short,
2861 href
(action
=>"tag", hash
=>$tag{'id'}));
2864 "<td class=\"selflink\">";
2865 if ($tag{'type'} eq "tag") {
2866 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
2871 "<td class=\"link\">" . " | " .
2872 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
2873 if ($tag{'reftype'} eq "commit") {
2874 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
2875 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
2876 } elsif ($tag{'reftype'} eq "blob") {
2877 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
2882 if (defined $extra) {
2884 "<td colspan=\"5\">$extra</td>\n" .
2890 sub git_heads_body
{
2891 # uses global variable $project
2892 my ($headlist, $head, $from, $to, $extra) = @_;
2893 $from = 0 unless defined $from;
2894 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
2896 print "<table class=\"heads\" cellspacing=\"0\">\n";
2898 for (my $i = $from; $i <= $to; $i++) {
2899 my $entry = $headlist->[$i];
2901 my $curr = $ref{'id'} eq $head;
2903 print "<tr class=\"dark\">\n";
2905 print "<tr class=\"light\">\n";
2908 print "<td><i>$ref{'age'}</i></td>\n" .
2909 ($curr ?
"<td class=\"current_head\">" : "<td>") .
2910 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
2911 -class => "list name"},esc_html
($ref{'name'})) .
2913 "<td class=\"link\">" .
2914 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
2915 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
2916 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
2920 if (defined $extra) {
2922 "<td colspan=\"3\">$extra</td>\n" .
2928 sub git_search_grep_body
{
2929 my ($commitlist, $from, $to, $extra) = @_;
2930 $from = 0 unless defined $from;
2931 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
2933 print "<table class=\"grep\" cellspacing=\"0\">\n";
2935 for (my $i = $from; $i <= $to; $i++) {
2936 my %co = %{$commitlist->[$i]};
2940 my $commit = $co{'id'};
2942 print "<tr class=\"dark\">\n";
2944 print "<tr class=\"light\">\n";
2947 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2948 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2950 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
2951 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
2952 my $comment = $co{'comment'};
2953 foreach my $line (@
$comment) {
2954 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2955 my $lead = esc_html
($1) || "";
2956 $lead = chop_str
($lead, 30, 10);
2957 my $match = esc_html
($2) || "";
2958 my $trail = esc_html
($3) || "";
2959 $trail = chop_str
($trail, 30, 10);
2960 my $text = "$lead<span class=\"match\">$match</span>$trail";
2961 print chop_str
($text, 80, 5) . "<br/>\n";
2965 "<td class=\"link\">" .
2966 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
2968 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
2972 if (defined $extra) {
2974 "<td colspan=\"3\">$extra</td>\n" .
2980 ## ======================================================================
2981 ## ======================================================================
2984 sub git_project_list
{
2985 my $order = $cgi->param('o');
2986 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
2987 die_error
(undef, "Unknown order parameter");
2990 my @list = git_get_projects_list
();
2992 die_error
(undef, "No projects found");
2996 if (-f
$home_text) {
2997 print "<div class=\"index_include\">\n";
2998 open (my $fd, $home_text);
3003 git_project_list_body
(\
@list, $order);
3008 my $order = $cgi->param('o');
3009 if (defined $order && $order !~ m/none|project|descr|owner|age/) {
3010 die_error
(undef, "Unknown order parameter");
3013 my @list = git_get_projects_list
($project);
3015 die_error
(undef, "No forks found");
3019 git_print_page_nav
('','');
3020 git_print_header_div
('summary', "$project forks");
3021 git_project_list_body
(\
@list, $order);
3025 sub git_project_index
{
3026 my @projects = git_get_projects_list
($project);
3029 -type
=> 'text/plain',
3030 -charset
=> 'utf-8',
3031 -content_disposition
=> 'inline; filename="index.aux"');
3033 foreach my $pr (@projects) {
3034 if (!exists $pr->{'owner'}) {
3035 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}");
3038 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3039 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3040 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3041 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3045 print "$path $owner\n";
3050 my $descr = git_get_project_description
($project) || "none";
3051 my %co = parse_commit
("HEAD");
3052 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
3053 my $head = $co{'id'};
3055 my $owner = git_get_project_owner
($project);
3057 my $refs = git_get_references
();
3058 # These get_*_list functions return one more to allow us to see if
3059 # there are more ...
3060 my @taglist = git_get_tags_list
(16);
3061 my @headlist = git_get_heads_list
(16);
3063 my ($check_forks) = gitweb_check_feature
('forks');
3066 @forklist = git_get_projects_list
($project);
3070 git_print_page_nav
('summary','', $head);
3072 print "<div class=\"title\"> </div>\n";
3073 print "<table cellspacing=\"0\">\n" .
3074 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3075 "<tr><td>owner</td><td>$owner</td></tr>\n" .
3076 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3077 # use per project git URL list in $projectroot/$project/cloneurl
3078 # or make project git URL from git base URL and project name
3079 my $url_tag = "URL";
3080 my @url_list = git_get_project_url_list
($project);
3081 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3082 foreach my $git_url (@url_list) {
3083 next unless $git_url;
3084 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3089 if (-s
"$projectroot/$project/README.html") {
3090 if (open my $fd, "$projectroot/$project/README.html") {
3091 print "<div class=\"title\">readme</div>\n";
3092 print $_ while (<$fd>);
3097 # we need to request one more than 16 (0..15) to check if
3099 my @commitlist = parse_commits
($head, 17);
3100 git_print_header_div
('shortlog');
3101 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
3102 $#commitlist <= 15 ?
undef :
3103 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
3106 git_print_header_div
('tags');
3107 git_tags_body
(\
@taglist, 0, 15,
3108 $#taglist <= 15 ?
undef :
3109 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
3113 git_print_header_div
('heads');
3114 git_heads_body
(\
@headlist, $head, 0, 15,
3115 $#headlist <= 15 ?
undef :
3116 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
3120 git_print_header_div
('forks');
3121 git_project_list_body
(\
@forklist, undef, 0, 15,
3122 $#forklist <= 15 ?
undef :
3123 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
3131 my $head = git_get_head_hash
($project);
3133 git_print_page_nav
('','', $head,undef,$head);
3134 my %tag = parse_tag
($hash);
3135 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
3136 print "<div class=\"title_text\">\n" .
3137 "<table cellspacing=\"0\">\n" .
3139 "<td>object</td>\n" .
3140 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3141 $tag{'object'}) . "</td>\n" .
3142 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3143 $tag{'type'}) . "</td>\n" .
3145 if (defined($tag{'author'})) {
3146 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
3147 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
3148 print "<tr><td></td><td>" . $ad{'rfc2822'} .
3149 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
3152 print "</table>\n\n" .
3154 print "<div class=\"page_body\">";
3155 my $comment = $tag{'comment'};
3156 foreach my $line (@
$comment) {
3158 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
3168 my ($have_blame) = gitweb_check_feature
('blame');
3170 die_error
('403 Permission denied', "Permission denied");
3172 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3173 $hash_base ||= git_get_head_hash
($project);
3174 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3175 my %co = parse_commit
($hash_base)
3176 or die_error
(undef, "Reading commit failed");
3177 if (!defined $hash) {
3178 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3179 or die_error
(undef, "Error looking up file");
3181 $ftype = git_get_type
($hash);
3182 if ($ftype !~ "blob") {
3183 die_error
('400 Bad Request', "Object is not a blob");
3185 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
3186 $file_name, $hash_base)
3187 or die_error
(undef, "Open git-blame failed");
3190 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3193 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3196 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3198 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3199 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3200 git_print_page_path
($file_name, $ftype, $hash_base);
3201 my @rev_color = (qw(light2 dark2));
3202 my $num_colors = scalar(@rev_color);
3203 my $current_color = 0;
3206 <div class="page_body">
3207 <table class="blame">
3208 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
3213 last unless defined $_;
3214 my ($full_rev, $orig_lineno, $lineno, $group_size) =
3215 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
3216 if (!exists $metainfo{$full_rev}) {
3217 $metainfo{$full_rev} = {};
3219 my $meta = $metainfo{$full_rev};
3222 if (/^(\S+) (.*)$/) {
3228 my $rev = substr($full_rev, 0, 8);
3229 my $author = $meta->{'author'};
3230 my %date = parse_date
($meta->{'author-time'},
3231 $meta->{'author-tz'});
3232 my $date = $date{'iso-tz'};
3234 $current_color = ++$current_color % $num_colors;
3236 print "<tr class=\"$rev_color[$current_color]\">\n";
3238 print "<td class=\"sha1\"";
3239 print " title=\"". esc_html
($author) . ", $date\"";
3240 print " rowspan=\"$group_size\"" if ($group_size > 1);
3242 print $cgi->a({-href
=> href
(action
=>"commit",
3244 file_name
=>$file_name)},
3248 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
3249 or die_error
(undef, "Open git-rev-parse failed");
3250 my $parent_commit = <$dd>;
3252 chomp($parent_commit);
3253 my $blamed = href
(action
=> 'blame',
3254 file_name
=> $meta->{'filename'},
3255 hash_base
=> $parent_commit);
3256 print "<td class=\"linenr\">";
3257 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
3259 -class => "linenr" },
3262 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
3268 or print "Reading blob failed\n";
3275 my ($have_blame) = gitweb_check_feature
('blame');
3277 die_error
('403 Permission denied', "Permission denied");
3279 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3280 $hash_base ||= git_get_head_hash
($project);
3281 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3282 my %co = parse_commit
($hash_base)
3283 or die_error
(undef, "Reading commit failed");
3284 if (!defined $hash) {
3285 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3286 or die_error
(undef, "Error lookup file");
3288 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
3289 or die_error
(undef, "Open git-annotate failed");
3292 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3295 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3298 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3300 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3301 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3302 git_print_page_path
($file_name, 'blob', $hash_base);
3303 print "<div class=\"page_body\">\n";
3305 <table class="blame">
3314 my @line_class = (qw(light dark));
3315 my $line_class_len = scalar (@line_class);
3316 my $line_class_num = $#line_class;
3317 while (my $line = <$fd>) {
3329 $line_class_num = ($line_class_num + 1) % $line_class_len;
3331 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
3338 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
3341 $short_rev = substr ($long_rev, 0, 8);
3342 $age = time () - $time;
3343 $age_str = age_string
($age);
3344 $age_str =~ s/ / /g;
3345 $age_class = age_class
($age);
3346 $author = esc_html
($author);
3347 $author =~ s/ / /g;
3349 $data = untabify
($data);
3350 $data = esc_html
($data);
3353 <tr class="$line_class[$line_class_num]">
3354 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
3355 <td class="$age_class">$age_str</td>
3357 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
3358 <td class="pre">$data</td>
3361 } # while (my $line = <$fd>)
3362 print "</table>\n\n";
3364 or print "Reading blob failed.\n";
3370 my $head = git_get_head_hash
($project);
3372 git_print_page_nav
('','', $head,undef,$head);
3373 git_print_header_div
('summary', $project);
3375 my @tagslist = git_get_tags_list
();
3377 git_tags_body
(\
@tagslist);
3383 my $head = git_get_head_hash
($project);
3385 git_print_page_nav
('','', $head,undef,$head);
3386 git_print_header_div
('summary', $project);
3388 my @headslist = git_get_heads_list
();
3390 git_heads_body
(\
@headslist, $head);
3395 sub git_blob_plain
{
3398 if (!defined $hash) {
3399 if (defined $file_name) {
3400 my $base = $hash_base || git_get_head_hash
($project);
3401 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3402 or die_error
(undef, "Error lookup file");
3404 die_error
(undef, "No file name defined");
3406 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3407 # blobs defined by non-textual hash id's can be cached
3412 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3413 or die_error
(undef, "Couldn't cat $file_name, $hash");
3415 $type ||= blob_mimetype
($fd, $file_name);
3417 # save as filename, even when no $file_name is given
3418 my $save_as = "$hash";
3419 if (defined $file_name) {
3420 $save_as = $file_name;
3421 } elsif ($type =~ m/^text\//) {
3428 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
3430 binmode STDOUT
, ':raw';
3432 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3440 if (!defined $hash) {
3441 if (defined $file_name) {
3442 my $base = $hash_base || git_get_head_hash
($project);
3443 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3444 or die_error
(undef, "Error lookup file");
3446 die_error
(undef, "No file name defined");
3448 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3449 # blobs defined by non-textual hash id's can be cached
3453 my ($have_blame) = gitweb_check_feature
('blame');
3454 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3455 or die_error
(undef, "Couldn't cat $file_name, $hash");
3456 my $mimetype = blob_mimetype
($fd, $file_name);
3457 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
3459 return git_blob_plain
($mimetype);
3461 # we can have blame only for text/* mimetype
3462 $have_blame &&= ($mimetype =~ m!^text/!);
3464 git_header_html
(undef, $expires);
3465 my $formats_nav = '';
3466 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3467 if (defined $file_name) {
3470 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
3471 hash
=>$hash, file_name
=>$file_name)},
3476 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3477 hash
=>$hash, file_name
=>$file_name)},
3480 $cgi->a({-href
=> href
(action
=>"blob_plain",
3481 hash
=>$hash, file_name
=>$file_name)},
3484 $cgi->a({-href
=> href
(action
=>"blob",
3485 hash_base
=>"HEAD", file_name
=>$file_name)},
3489 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
3491 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3492 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3494 print "<div class=\"page_nav\">\n" .
3495 "<br/><br/></div>\n" .
3496 "<div class=\"title\">$hash</div>\n";
3498 git_print_page_path
($file_name, "blob", $hash_base);
3499 print "<div class=\"page_body\">\n";
3500 if ($mimetype =~ m!^text/!) {
3502 while (my $line = <$fd>) {
3505 $line = untabify
($line);
3506 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
3507 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
3509 } elsif ($mimetype =~ m!^image/!) {
3510 print qq!<img type
="$mimetype"!;
3512 print qq! alt
="$file_name" title
="$file_name"!;
3515 href(action=>"blob_plain
", hash=>$hash,
3516 hash_base=>$hash_base, file_name=>$file_name) .
3520 or print "Reading blob failed.\n";
3526 my $have_snapshot = gitweb_have_snapshot
();
3528 if (!defined $hash_base) {
3529 $hash_base = "HEAD";
3531 if (!defined $hash) {
3532 if (defined $file_name) {
3533 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
3539 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
3540 or die_error
(undef, "Open git-ls-tree failed");
3541 my @entries = map { chomp; $_ } <$fd>;
3542 close $fd or die_error
(undef, "Reading tree failed");
3545 my $refs = git_get_references
();
3546 my $ref = format_ref_marker
($refs, $hash_base);
3549 my ($have_blame) = gitweb_check_feature
('blame');
3550 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3552 if (defined $file_name) {
3554 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3555 hash
=>$hash, file_name
=>$file_name)},
3557 $cgi->a({-href
=> href
(action
=>"tree",
3558 hash_base
=>"HEAD", file_name
=>$file_name)},
3561 if ($have_snapshot) {
3562 # FIXME: Should be available when we have no hash base as well.
3564 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
3567 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
3568 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
3571 print "<div class=\"page_nav\">\n";
3572 print "<br/><br/></div>\n";
3573 print "<div class=\"title\">$hash</div>\n";
3575 if (defined $file_name) {
3576 $basedir = $file_name;
3577 if ($basedir ne '' && substr($basedir, -1) ne '/') {
3581 git_print_page_path
($file_name, 'tree', $hash_base);
3582 print "<div class=\"page_body\">\n";
3583 print "<table cellspacing=\"0\">\n";
3585 # '..' (top directory) link if possible
3586 if (defined $hash_base &&
3587 defined $file_name && $file_name =~ m![^/]+$!) {
3589 print "<tr class=\"dark\">\n";
3591 print "<tr class=\"light\">\n";
3595 my $up = $file_name;
3596 $up =~ s!/?[^/]+$!!;
3597 undef $up unless $up;
3598 # based on git_print_tree_entry
3599 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
3600 print '<td class="list">';
3601 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
3605 print "<td class=\"link\"></td>\n";
3609 foreach my $line (@entries) {
3610 my %t = parse_ls_tree_line
($line, -z
=> 1);
3613 print "<tr class=\"dark\">\n";
3615 print "<tr class=\"light\">\n";
3619 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
3623 print "</table>\n" .
3629 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
3630 my $have_snapshot = (defined $ctype && defined $suffix);
3631 if (!$have_snapshot) {
3632 die_error
('403 Permission denied', "Permission denied");
3635 if (!defined $hash) {
3636 $hash = git_get_head_hash
($project);
3639 my $filename = to_utf8
(basename
($project)) . "-$hash.tar.$suffix";
3642 -type
=> "application/$ctype",
3643 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
3644 -status
=> '200 OK');
3646 my $git = git_cmd_str
();
3647 my $name = $project;
3648 $name =~ s/\047/\047\\\047\047/g;
3650 "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
3651 or die_error
(undef, "Execute git-tar-tree failed");
3652 binmode STDOUT
, ':raw';
3654 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3660 my $head = git_get_head_hash
($project);
3661 if (!defined $hash) {
3664 if (!defined $page) {
3667 my $refs = git_get_references
();
3669 my @commitlist = parse_commits
($hash, 101, (100 * $page));
3671 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
3674 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
3677 my %co = parse_commit
($hash);
3679 git_print_header_div
('summary', $project);
3680 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
3682 my $to = ($#commitlist >= 99) ?
(99) : ($#commitlist);
3683 for (my $i = 0; $i <= $to; $i++) {
3684 my %co = %{$commitlist[$i]};
3686 my $commit = $co{'id'};
3687 my $ref = format_ref_marker
($refs, $commit);
3688 my %ad = parse_date
($co{'author_epoch'});
3689 git_print_header_div
('commit',
3690 "<span class=\"age\">$co{'age_string'}</span>" .
3691 esc_html
($co{'title'}) . $ref,
3693 print "<div class=\"title_text\">\n" .
3694 "<div class=\"log_link\">\n" .
3695 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
3697 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
3699 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
3702 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
3705 print "<div class=\"log_body\">\n";
3706 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
3709 if ($#commitlist >= 100) {
3710 print "<div class=\"page_nav\">\n";
3711 print $cgi->a({-href
=> href
(action
=>"log", hash
=>$hash, page
=>$page+1),
3712 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3719 $hash ||= $hash_base || "HEAD";
3720 my %co = parse_commit
($hash);
3722 die_error
(undef, "Unknown commit object");
3724 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3725 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
3727 my $parent = $co{'parent'};
3728 my $parents = $co{'parents'}; # listref
3730 # we need to prepare $formats_nav before any parameter munging
3732 if (!defined $parent) {
3734 $formats_nav .= '(initial)';
3735 } elsif (@
$parents == 1) {
3736 # single parent commit
3739 $cgi->a({-href
=> href
(action
=>"commit",
3741 esc_html
(substr($parent, 0, 7))) .
3748 $cgi->a({-href
=> href
(action
=>"commit",
3750 esc_html
(substr($_, 0, 7)));
3755 if (!defined $parent) {
3759 if (@
$parents <= 1) {
3760 # difftree output is not printed for merges
3761 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
3762 @diff_opts, $parent, $hash, "--"
3763 or die_error
(undef, "Open git-diff-tree failed");
3764 @difftree = map { chomp; $_ } <$fd>;
3765 close $fd or die_error
(undef, "Reading git-diff-tree failed");
3768 # non-textual hash id's can be cached
3770 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3773 my $refs = git_get_references
();
3774 my $ref = format_ref_marker
($refs, $co{'id'});
3776 my $have_snapshot = gitweb_have_snapshot
();
3778 git_header_html
(undef, $expires);
3779 git_print_page_nav
('commit', '',
3780 $hash, $co{'tree'}, $hash,
3783 if (defined $co{'parent'}) {
3784 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
3786 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
3788 print "<div class=\"title_text\">\n" .
3789 "<table cellspacing=\"0\">\n";
3790 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
3792 "<td></td><td> $ad{'rfc2822'}";
3793 if ($ad{'hour_local'} < 6) {
3794 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3795 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3797 printf(" (%02d:%02d %s)",
3798 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3802 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
3803 print "<tr><td></td><td> $cd{'rfc2822'}" .
3804 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
3806 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
3809 "<td class=\"sha1\">" .
3810 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
3811 class => "list"}, $co{'tree'}) .
3813 "<td class=\"link\">" .
3814 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
3816 if ($have_snapshot) {
3818 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
3823 foreach my $par (@
$parents) {
3826 "<td class=\"sha1\">" .
3827 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
3828 class => "list"}, $par) .
3830 "<td class=\"link\">" .
3831 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
3833 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
3840 print "<div class=\"page_body\">\n";
3841 git_print_log
($co{'comment'});
3844 if (@
$parents <= 1) {
3845 # do not output difftree/whatchanged for merges
3846 git_difftree_body
(\
@difftree, $hash, $parent);
3853 # object is defined by:
3854 # - hash or hash_base alone
3855 # - hash_base and file_name
3858 # - hash or hash_base alone
3859 if ($hash || ($hash_base && !defined $file_name)) {
3860 my $object_id = $hash || $hash_base;
3862 my $git_command = git_cmd_str
();
3863 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
3864 or die_error
('404 Not Found', "Object does not exist");
3868 or die_error
('404 Not Found', "Object does not exist");
3870 # - hash_base and file_name
3871 } elsif ($hash_base && defined $file_name) {
3872 $file_name =~ s
,/+$,,;
3874 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
3875 or die_error
('404 Not Found', "Base object does not exist");
3877 # here errors should not hapen
3878 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
3879 or die_error
(undef, "Open git-ls-tree failed");
3883 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
3884 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
3885 die_error
('404 Not Found', "File or directory for given base does not exist");
3890 die_error
('404 Not Found', "Not enough information to find object");
3893 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
3894 hash
=>$hash, hash_base
=>$hash_base,
3895 file_name
=>$file_name),
3896 -status
=> '302 Found');
3900 my $format = shift || 'html';
3907 # preparing $fd and %diffinfo for git_patchset_body
3909 if (defined $hash_base && defined $hash_parent_base) {
3910 if (defined $file_name) {
3912 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3913 $hash_parent_base, $hash_base,
3914 "--", (defined $file_parent ?
$file_parent : ()), $file_name
3915 or die_error
(undef, "Open git-diff-tree failed");
3916 @difftree = map { chomp; $_ } <$fd>;
3918 or die_error
(undef, "Reading git-diff-tree failed");
3920 or die_error
('404 Not Found', "Blob diff not found");
3922 } elsif (defined $hash &&
3923 $hash =~ /[0-9a-fA-F]{40}/) {
3924 # try to find filename from $hash
3926 # read filtered raw output
3927 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3928 $hash_parent_base, $hash_base, "--"
3929 or die_error
(undef, "Open git-diff-tree failed");
3931 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
3933 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
3934 map { chomp; $_ } <$fd>;
3936 or die_error
(undef, "Reading git-diff-tree failed");
3938 or die_error
('404 Not Found', "Blob diff not found");
3941 die_error
('404 Not Found', "Missing one of the blob diff parameters");
3944 if (@difftree > 1) {
3945 die_error
('404 Not Found', "Ambiguous blob diff specification");
3948 %diffinfo = parse_difftree_raw_line
($difftree[0]);
3949 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
3950 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
3952 $hash_parent ||= $diffinfo{'from_id'};
3953 $hash ||= $diffinfo{'to_id'};
3955 # non-textual hash id's can be cached
3956 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
3957 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
3962 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3963 '-p', ($format eq 'html' ?
"--full-index" : ()),
3964 $hash_parent_base, $hash_base,
3965 "--", (defined $file_parent ?
$file_parent : ()), $file_name
3966 or die_error
(undef, "Open git-diff-tree failed");
3969 # old/legacy style URI
3970 if (!%diffinfo && # if new style URI failed
3971 defined $hash && defined $hash_parent) {
3972 # fake git-diff-tree raw output
3973 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
3974 $diffinfo{'from_id'} = $hash_parent;
3975 $diffinfo{'to_id'} = $hash;
3976 if (defined $file_name) {
3977 if (defined $file_parent) {
3978 $diffinfo{'status'} = '2';
3979 $diffinfo{'from_file'} = $file_parent;
3980 $diffinfo{'to_file'} = $file_name;
3981 } else { # assume not renamed
3982 $diffinfo{'status'} = '1';
3983 $diffinfo{'from_file'} = $file_name;
3984 $diffinfo{'to_file'} = $file_name;
3986 } else { # no filename given
3987 $diffinfo{'status'} = '2';
3988 $diffinfo{'from_file'} = $hash_parent;
3989 $diffinfo{'to_file'} = $hash;
3992 # non-textual hash id's can be cached
3993 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
3994 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3999 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
4000 '-p', ($format eq 'html' ?
"--full-index" : ()),
4001 $hash_parent, $hash, "--"
4002 or die_error
(undef, "Open git-diff failed");
4004 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4009 if ($format eq 'html') {
4011 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
4012 hash
=>$hash, hash_parent
=>$hash_parent,
4013 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
4014 file_name
=>$file_name, file_parent
=>$file_parent)},
4016 git_header_html
(undef, $expires);
4017 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4018 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4019 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4021 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4022 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4024 if (defined $file_name) {
4025 git_print_page_path
($file_name, "blob", $hash_base);
4027 print "<div class=\"page_path\"></div>\n";
4030 } elsif ($format eq 'plain') {
4032 -type
=> 'text/plain',
4033 -charset
=> 'utf-8',
4034 -expires
=> $expires,
4035 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4037 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4040 die_error
(undef, "Unknown blobdiff format");
4044 if ($format eq 'html') {
4045 print "<div class=\"page_body\">\n";
4047 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4050 print "</div>\n"; # class="page_body"
4054 while (my $line = <$fd>) {
4055 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4056 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4060 last if $line =~ m!^\+\+\+!;
4068 sub git_blobdiff_plain
{
4069 git_blobdiff
('plain');
4072 sub git_commitdiff
{
4073 my $format = shift || 'html';
4074 $hash ||= $hash_base || "HEAD";
4075 my %co = parse_commit
($hash);
4077 die_error
(undef, "Unknown commit object");
4080 # we need to prepare $formats_nav before any parameter munging
4082 if ($format eq 'html') {
4084 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
4085 hash
=>$hash, hash_parent
=>$hash_parent)},
4088 if (defined $hash_parent) {
4089 # commitdiff with two commits given
4090 my $hash_parent_short = $hash_parent;
4091 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4092 $hash_parent_short = substr($hash_parent, 0, 7);
4096 $cgi->a({-href
=> href
(action
=>"commitdiff",
4097 hash
=>$hash_parent)},
4098 esc_html
($hash_parent_short)) .
4100 } elsif (!$co{'parent'}) {
4102 $formats_nav .= ' (initial)';
4103 } elsif (scalar @
{$co{'parents'}} == 1) {
4104 # single parent commit
4107 $cgi->a({-href
=> href
(action
=>"commitdiff",
4108 hash
=>$co{'parent'})},
4109 esc_html
(substr($co{'parent'}, 0, 7))) .
4116 $cgi->a({-href
=> href
(action
=>"commitdiff",
4118 esc_html
(substr($_, 0, 7)));
4119 } @
{$co{'parents'}} ) .
4124 if (!defined $hash_parent) {
4125 $hash_parent = $co{'parent'} || '--root';
4131 if ($format eq 'html') {
4132 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4133 "--no-commit-id", "--patch-with-raw", "--full-index",
4134 $hash_parent, $hash, "--"
4135 or die_error
(undef, "Open git-diff-tree failed");
4137 while (my $line = <$fd>) {
4139 # empty line ends raw part of diff-tree output
4141 push @difftree, $line;
4144 } elsif ($format eq 'plain') {
4145 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4146 '-p', $hash_parent, $hash, "--"
4147 or die_error
(undef, "Open git-diff-tree failed");
4150 die_error
(undef, "Unknown commitdiff format");
4153 # non-textual hash id's can be cached
4155 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4159 # write commit message
4160 if ($format eq 'html') {
4161 my $refs = git_get_references
();
4162 my $ref = format_ref_marker
($refs, $co{'id'});
4164 git_header_html
(undef, $expires);
4165 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
4166 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
4167 git_print_authorship
(\
%co);
4168 print "<div class=\"page_body\">\n";
4169 if (@
{$co{'comment'}} > 1) {
4170 print "<div class=\"log\">\n";
4171 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
4172 print "</div>\n"; # class="log"
4175 } elsif ($format eq 'plain') {
4176 my $refs = git_get_references
("tags");
4177 my $tagname = git_get_rev_name_tags
($hash);
4178 my $filename = basename
($project) . "-$hash.patch";
4181 -type
=> 'text/plain',
4182 -charset
=> 'utf-8',
4183 -expires
=> $expires,
4184 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
4185 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4188 Date: $ad{'rfc2822'} ($ad{'tz_local'})
4189 Subject: $co{'title'}
4191 print "X-Git-Tag: $tagname\n" if $tagname;
4192 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4194 foreach my $line (@
{$co{'comment'}}) {
4201 if ($format eq 'html') {
4202 git_difftree_body
(\
@difftree, $hash, $hash_parent);
4205 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
4207 print "</div>\n"; # class="page_body"
4210 } elsif ($format eq 'plain') {
4214 or print "Reading git-diff-tree failed\n";
4218 sub git_commitdiff_plain
{
4219 git_commitdiff
('plain');
4223 if (!defined $hash_base) {
4224 $hash_base = git_get_head_hash
($project);
4226 if (!defined $page) {
4230 my %co = parse_commit
($hash_base);
4232 die_error
(undef, "Unknown commit object");
4235 my $refs = git_get_references
();
4236 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
4238 if (!defined $hash && defined $file_name) {
4239 $hash = git_get_hash_by_path
($hash_base, $file_name);
4241 if (defined $hash) {
4242 $ftype = git_get_type
($hash);
4245 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), "--full-history", $file_name);
4247 my $paging_nav = '';
4250 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4251 file_name
=>$file_name)},
4253 $paging_nav .= " ⋅ " .
4254 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4255 file_name
=>$file_name, page
=>$page-1),
4256 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4258 $paging_nav .= "first";
4259 $paging_nav .= " ⋅ prev";
4261 if ($#commitlist >= 100) {
4262 $paging_nav .= " ⋅ " .
4263 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4264 file_name
=>$file_name, page
=>$page+1),
4265 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4267 $paging_nav .= " ⋅ next";
4270 if ($#commitlist >= 100) {
4272 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4273 file_name
=>$file_name, page
=>$page+1),
4274 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4278 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
4279 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4280 git_print_page_path
($file_name, $ftype, $hash_base);
4282 git_history_body
(\
@commitlist, 0, 99,
4283 $refs, $hash_base, $ftype, $next_link);
4289 my ($have_search) = gitweb_check_feature
('search');
4290 if (!$have_search) {
4291 die_error
('403 Permission denied', "Permission denied");
4293 if (!defined $searchtext) {
4294 die_error
(undef, "Text field empty");
4296 if (!defined $hash) {
4297 $hash = git_get_head_hash
($project);
4299 my %co = parse_commit
($hash);
4301 die_error
(undef, "Unknown commit object");
4303 if (!defined $page) {
4307 $searchtype ||= 'commit';
4308 if ($searchtype eq 'pickaxe') {
4309 # pickaxe may take all resources of your box and run for several minutes
4310 # with every query - so decide by yourself how public you make this feature
4311 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4312 if (!$have_pickaxe) {
4313 die_error
('403 Permission denied', "Permission denied");
4319 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
4321 if ($searchtype eq 'commit') {
4322 $greptype = "--grep=";
4323 } elsif ($searchtype eq 'author') {
4324 $greptype = "--author=";
4325 } elsif ($searchtype eq 'committer') {
4326 $greptype = "--committer=";
4328 $greptype .= $searchtext;
4329 my @commitlist = parse_commits
($hash, 101, (100 * $page), $greptype);
4331 my $paging_nav = '';
4334 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4335 searchtext
=>$searchtext, searchtype
=>$searchtype)},
4337 $paging_nav .= " ⋅ " .
4338 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4339 searchtext
=>$searchtext, searchtype
=>$searchtype,
4341 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4343 $paging_nav .= "first";
4344 $paging_nav .= " ⋅ prev";
4346 if ($#commitlist >= 100) {
4347 $paging_nav .= " ⋅ " .
4348 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4349 searchtext
=>$searchtext, searchtype
=>$searchtype,
4351 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4353 $paging_nav .= " ⋅ next";
4356 if ($#commitlist >= 100) {
4358 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4359 searchtext
=>$searchtext, searchtype
=>$searchtype,
4361 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4364 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
4365 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4366 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
4369 if ($searchtype eq 'pickaxe') {
4370 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
4371 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4373 print "<table cellspacing=\"0\">\n";
4376 my $git_command = git_cmd_str
();
4377 open my $fd, "-|", "$git_command rev-list $hash | " .
4378 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
4381 while (my $line = <$fd>) {
4382 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
4385 $set{'from_id'} = $3;
4387 $set{'id'} = $set{'to_id'};
4388 if ($set{'id'} =~ m/0{40}/) {
4389 $set{'id'} = $set{'from_id'};
4391 if ($set{'id'} =~ m/0{40}/) {
4395 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
4398 print "<tr class=\"dark\">\n";
4400 print "<tr class=\"light\">\n";
4403 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4404 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
4406 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4407 -class => "list subject"},
4408 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
4409 while (my $setref = shift @files) {
4411 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
4412 hash
=>$set{'id'}, file_name
=>$set{'file'}),
4414 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
4418 "<td class=\"link\">" .
4419 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4421 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4425 %co = parse_commit
($1);
4435 sub git_search_help
{
4437 git_print_page_nav
('','', $hash,$hash,$hash);
4440 <dt><b>commit</b></dt>
4441 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
4442 <dt><b>author</b></dt>
4443 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
4444 <dt><b>committer</b></dt>
4445 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
4447 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4448 if ($have_pickaxe) {
4450 <dt><b>pickaxe</b></dt>
4451 <dd>All commits that caused the string to appear or disappear from any file (changes that
4452 added, removed or "modified" the string) will be listed. This search can take a while and
4453 takes a lot of strain on the server, so please use it wisely.</dd>
4461 my $head = git_get_head_hash
($project);
4462 if (!defined $hash) {
4465 if (!defined $page) {
4468 my $refs = git_get_references
();
4470 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4472 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, (100 * ($page+1)));
4474 if ($#commitlist >= 100) {
4476 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
4477 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4481 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
4482 git_print_header_div
('summary', $project);
4484 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
4489 ## ......................................................................
4490 ## feeds (RSS, Atom; OPML)
4493 my $format = shift || 'atom';
4494 my ($have_blame) = gitweb_check_feature
('blame');
4496 # Atom: http://www.atomenabled.org/developers/syndication/
4497 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
4498 if ($format ne 'rss' && $format ne 'atom') {
4499 die_error
(undef, "Unknown web feed format");
4502 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
4503 my $head = $hash || 'HEAD';
4504 my @commitlist = parse_commits
($head, 150);
4508 my $content_type = "application/$format+xml";
4509 if (defined $cgi->http('HTTP_ACCEPT') &&
4510 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
4511 # browser (feed reader) prefers text/xml
4512 $content_type = 'text/xml';
4514 if (defined($commitlist[0])) {
4515 %latest_commit = %{$commitlist[0]};
4516 %latest_date = parse_date
($latest_commit{'author_epoch'});
4518 -type
=> $content_type,
4519 -charset
=> 'utf-8',
4520 -last_modified
=> $latest_date{'rfc2822'});
4523 -type
=> $content_type,
4524 -charset
=> 'utf-8');
4527 # Optimization: skip generating the body if client asks only
4528 # for Last-Modified date.
4529 return if ($cgi->request_method() eq 'HEAD');
4532 my $title = "$site_name - $project/$action";
4533 my $feed_type = 'log';
4534 if (defined $hash) {
4535 $title .= " - '$hash'";
4536 $feed_type = 'branch log';
4537 if (defined $file_name) {
4538 $title .= " :: $file_name";
4539 $feed_type = 'history';
4541 } elsif (defined $file_name) {
4542 $title .= " - $file_name";
4543 $feed_type = 'history';
4545 $title .= " $feed_type";
4546 my $descr = git_get_project_description
($project);
4547 if (defined $descr) {
4548 $descr = esc_html
($descr);
4550 $descr = "$project " .
4551 ($format eq 'rss' ?
'RSS' : 'Atom') .
4554 my $owner = git_get_project_owner
($project);
4555 $owner = esc_html
($owner);
4559 if (defined $file_name) {
4560 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
4561 } elsif (defined $hash) {
4562 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
4564 $alt_url = href
(-full
=>1, action
=>"summary");
4566 print qq!<?xml version
="1.0" encoding
="utf-8"?
>\n!;
4567 if ($format eq 'rss') {
4569 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
4572 print "<title>$title</title>\n" .
4573 "<link>$alt_url</link>\n" .
4574 "<description>$descr</description>\n" .
4575 "<language>en</language>\n";
4576 } elsif ($format eq 'atom') {
4578 <feed xmlns="http://www.w3.org/2005/Atom">
4580 print "<title>$title</title>\n" .
4581 "<subtitle>$descr</subtitle>\n" .
4582 '<link rel="alternate" type="text/html" href="' .
4583 $alt_url . '" />' . "\n" .
4584 '<link rel="self" type="' . $content_type . '" href="' .
4585 $cgi->self_url() . '" />' . "\n" .
4586 "<id>" . href
(-full
=>1) . "</id>\n" .
4587 # use project owner for feed author
4588 "<author><name>$owner</name></author>\n";
4589 if (defined $favicon) {
4590 print "<icon>" . esc_url
($favicon) . "</icon>\n";
4592 if (defined $logo_url) {
4593 # not twice as wide as tall: 72 x 27 pixels
4594 print "<logo>" . esc_url
($logo) . "</logo>\n";
4596 if (! %latest_date) {
4597 # dummy date to keep the feed valid until commits trickle in:
4598 print "<updated>1970-01-01T00:00:00Z</updated>\n";
4600 print "<updated>$latest_date{'iso-8601'}</updated>\n";
4605 for (my $i = 0; $i <= $#commitlist; $i++) {
4606 my %co = %{$commitlist[$i]};
4607 my $commit = $co{'id'};
4608 # we read 150, we always show 30 and the ones more recent than 48 hours
4609 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
4612 my %cd = parse_date
($co{'author_epoch'});
4614 # get list of changed files
4615 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4616 $co{'parent'}, $co{'id'}, "--", (defined $file_name ?
$file_name : ())
4618 my @difftree = map { chomp; $_ } <$fd>;
4622 # print element (entry, item)
4623 my $co_url = href
(-full
=>1, action
=>"commit", hash
=>$commit);
4624 if ($format eq 'rss') {
4626 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
4627 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
4628 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
4629 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
4630 "<link>$co_url</link>\n" .
4631 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
4632 "<content:encoded>" .
4634 } elsif ($format eq 'atom') {
4636 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
4637 "<updated>$cd{'iso-8601'}</updated>\n" .
4639 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
4640 if ($co{'author_email'}) {
4641 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
4643 print "</author>\n" .
4644 # use committer for contributor
4646 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
4647 if ($co{'committer_email'}) {
4648 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
4650 print "</contributor>\n" .
4651 "<published>$cd{'iso-8601'}</published>\n" .
4652 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
4653 "<id>$co_url</id>\n" .
4654 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
4655 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
4657 my $comment = $co{'comment'};
4659 foreach my $line (@
$comment) {
4660 $line = esc_html
($line);
4663 print "</pre><ul>\n";
4664 foreach my $difftree_line (@difftree) {
4665 my %difftree = parse_difftree_raw_line
($difftree_line);
4666 next if !$difftree{'from_id'};
4668 my $file = $difftree{'file'} || $difftree{'to_file'};
4672 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
4673 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
4674 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
4675 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
4676 -title
=> "diff"}, 'D');
4678 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
4679 file_name
=>$file, hash_base
=>$commit),
4680 -title
=> "blame"}, 'B');
4682 # if this is not a feed of a file history
4683 if (!defined $file_name || $file_name ne $file) {
4684 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
4685 file_name
=>$file, hash
=>$commit),
4686 -title
=> "history"}, 'H');
4688 $file = esc_path
($file);
4692 if ($format eq 'rss') {
4693 print "</ul>]]>\n" .
4694 "</content:encoded>\n" .
4696 } elsif ($format eq 'atom') {
4697 print "</ul>\n</div>\n" .
4704 if ($format eq 'rss') {
4705 print "</channel>\n</rss>\n";
4706 } elsif ($format eq 'atom') {
4720 my @list = git_get_projects_list
();
4722 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
4724 <?xml version="1.0" encoding="utf-8"?>
4725 <opml version="1.0">
4727 <title>$site_name OPML Export</title>
4730 <outline text="git RSS feeds">
4733 foreach my $pr (@list) {
4735 my $head = git_get_head_hash
($proj{'path'});
4736 if (!defined $head) {
4739 $git_dir = "$projectroot/$proj{'path'}";
4740 my %co = parse_commit
($head);
4745 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
4746 my $rss = "$my_url?p=$proj{'path'};a=rss";
4747 my $html = "$my_url?p=$proj{'path'};a=summary";
4748 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";