3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI
qw(:standard :escapeHTML -nosticky);
13 use CGI
::Util
qw(unescape);
14 use CGI
::Carp
qw(fatalsToBrowser);
18 use File
::Basename
qw(basename);
19 binmode STDOUT
, ':utf8';
22 CGI-
>compile() if $ENV{'MOD_PERL'};
26 our $version = "++GIT_VERSION++";
27 our $my_url = $cgi->url();
28 our $my_uri = $cgi->url(-absolute
=> 1);
30 # core git executable to use
31 # this can just be "git" if your webserver has a sensible PATH
32 our $GIT = "++GIT_BINDIR++/git";
34 # absolute fs-path which will be prepended to the project path
35 #our $projectroot = "/pub/scm";
36 our $projectroot = "++GITWEB_PROJECTROOT++";
38 # target of the home link on top of all pages
39 our $home_link = $my_uri || "/";
41 # string of the home link on top of all pages
42 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
44 # name of your site or organization to appear in page titles
45 # replace this with something more descriptive for clearer bookmarks
46 our $site_name = "++GITWEB_SITENAME++"
47 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
49 # filename of html text to include at top of each page
50 our $site_header = "++GITWEB_SITE_HEADER++";
51 # html text to include at home page
52 our $home_text = "++GITWEB_HOMETEXT++";
53 # filename of html text to include at bottom of each page
54 our $site_footer = "++GITWEB_SITE_FOOTER++";
57 our @stylesheets = ("++GITWEB_CSS++");
58 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
59 our $stylesheet = undef;
61 # URI of GIT logo (72x27 size)
62 our $logo = "++GITWEB_LOGO++";
63 # URI of GIT favicon, assumed to be image/png type
64 our $favicon = "++GITWEB_FAVICON++";
66 # URI and label (title) of GIT logo link
67 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
68 #our $logo_label = "git documentation";
69 our $logo_url = "http://git.or.cz/";
70 our $logo_label = "git homepage";
72 # source of projects list
73 our $projects_list = "++GITWEB_LIST++";
75 # show repository only if this file exists
76 # (only effective if this variable evaluates to true)
77 our $export_ok = "++GITWEB_EXPORT_OK++";
79 # only allow viewing of repositories also shown on the overview page
80 our $strict_export = "++GITWEB_STRICT_EXPORT++";
82 # list of git base URLs used for URL to where fetch project from,
83 # i.e. full URL is "$git_base_url/$project"
84 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
86 # default blob_plain mimetype and default charset for text/plain blob
87 our $default_blob_plain_mimetype = 'text/plain';
88 our $default_text_plain_charset = undef;
90 # file to use for guessing MIME types before trying /etc/mime.types
91 # (relative to the current git repository)
92 our $mimetypes_file = undef;
94 # You define site-wide feature defaults here; override them with
95 # $GITWEB_CONFIG as necessary.
98 # 'sub' => feature-sub (subroutine),
99 # 'override' => allow-override (boolean),
100 # 'default' => [ default options...] (array reference)}
102 # if feature is overridable (it means that allow-override has true value,
103 # then feature-sub will be called with default options as parameters;
104 # return value of feature-sub indicates if to enable specified feature
106 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
108 # Enable the 'blame' blob view, showing the last commit that modified
109 # each line in the file. This can be very CPU-intensive.
111 # To enable system wide have in $GITWEB_CONFIG
112 # $feature{'blame'}{'default'} = [1];
113 # To have project specific config enable override in $GITWEB_CONFIG
114 # $feature{'blame'}{'override'} = 1;
115 # and in project config gitweb.blame = 0|1;
117 'sub' => \
&feature_blame
,
121 # Enable the 'snapshot' link, providing a compressed tarball of any
122 # tree. This can potentially generate high traffic if you have large
125 # To disable system wide have in $GITWEB_CONFIG
126 # $feature{'snapshot'}{'default'} = [undef];
127 # To have project specific config enable override in $GITWEB_CONFIG
128 # $feature{'snapshot'}{'override'} = 1;
129 # and in project config gitweb.snapshot = none|gzip|bzip2;
131 'sub' => \
&feature_snapshot
,
133 # => [content-encoding, suffix, program]
134 'default' => ['x-gzip', 'gz', 'gzip']},
136 # Enable text search, which will list the commits which match author,
137 # committer or commit text to a given string. Enabled by default.
142 # Enable the pickaxe search, which will list the commits that modified
143 # a given string in a file. This can be practical and quite faster
144 # alternative to 'blame', but still potentially CPU-intensive.
146 # To enable system wide have in $GITWEB_CONFIG
147 # $feature{'pickaxe'}{'default'} = [1];
148 # To have project specific config enable override in $GITWEB_CONFIG
149 # $feature{'pickaxe'}{'override'} = 1;
150 # and in project config gitweb.pickaxe = 0|1;
152 'sub' => \
&feature_pickaxe
,
156 # Make gitweb use an alternative format of the URLs which can be
157 # more readable and natural-looking: project name is embedded
158 # directly in the path and the query string contains other
159 # auxiliary information. All gitweb installations recognize
160 # URL in either format; this configures in which formats gitweb
163 # To enable system wide have in $GITWEB_CONFIG
164 # $feature{'pathinfo'}{'default'} = [1];
165 # Project specific override is not supported.
167 # Note that you will need to change the default location of CSS,
168 # favicon, logo and possibly other files to an absolute URL. Also,
169 # if gitweb.cgi serves as your indexfile, you will need to force
170 # $my_uri to contain the script name in your $GITWEB_CONFIG.
175 # Make gitweb consider projects in project root subdirectories
176 # to be forks of existing projects. Given project $projname.git,
177 # projects matching $projname/*.git will not be shown in the main
178 # projects list, instead a '+' mark will be added to $projname
179 # there and a 'forks' view will be enabled for the project, listing
180 # all the forks. If project list is taken from a file, forks have
181 # to be listed after the main project.
183 # To enable system wide have in $GITWEB_CONFIG
184 # $feature{'forks'}{'default'} = [1];
185 # Project specific override is not supported.
191 sub gitweb_check_feature
{
193 return unless exists $feature{$name};
194 my ($sub, $override, @defaults) = (
195 $feature{$name}{'sub'},
196 $feature{$name}{'override'},
197 @{$feature{$name}{'default'}});
198 if (!$override) { return @defaults; }
200 warn "feature $name is not overrideable";
203 return $sub->(@defaults);
207 my ($val) = git_get_project_config
('blame', '--bool');
209 if ($val eq 'true') {
211 } elsif ($val eq 'false') {
218 sub feature_snapshot
{
219 my ($ctype, $suffix, $command) = @_;
221 my ($val) = git_get_project_config
('snapshot');
223 if ($val eq 'gzip') {
224 return ('x-gzip', 'gz', 'gzip');
225 } elsif ($val eq 'bzip2') {
226 return ('x-bzip2', 'bz2', 'bzip2');
227 } elsif ($val eq 'none') {
231 return ($ctype, $suffix, $command);
234 sub gitweb_have_snapshot
{
235 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
236 my $have_snapshot = (defined $ctype && defined $suffix);
238 return $have_snapshot;
241 sub feature_pickaxe
{
242 my ($val) = git_get_project_config
('pickaxe', '--bool');
244 if ($val eq 'true') {
246 } elsif ($val eq 'false') {
253 # checking HEAD file with -e is fragile if the repository was
254 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
256 sub check_head_link
{
258 my $headfile = "$dir/HEAD";
259 return ((-e
$headfile) ||
260 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
263 sub check_export_ok
{
265 return (check_head_link
($dir) &&
266 (!$export_ok || -e
"$dir/$export_ok"));
269 # rename detection options for git-diff and git-diff-tree
270 # - default is '-M', with the cost proportional to
271 # (number of removed files) * (number of new files).
272 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
273 # (number of changed files + number of removed files) * (number of new files)
274 # - even more costly is '-C', '--find-copies-harder' with cost
275 # (number of files in the original tree) * (number of new files)
276 # - one might want to include '-B' option, e.g. '-B', '-M'
277 our @diff_opts = ('-M'); # taken from git_commit
279 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
280 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
282 # version of the core git binary
283 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
285 $projects_list ||= $projectroot;
287 # ======================================================================
288 # input validation and dispatch
289 our $action = $cgi->param('a');
290 if (defined $action) {
291 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
292 die_error
(undef, "Invalid action parameter");
296 # parameters which are pathnames
297 our $project = $cgi->param('p');
298 if (defined $project) {
299 if (!validate_pathname
($project) ||
300 !(-d
"$projectroot/$project") ||
301 !check_head_link
("$projectroot/$project") ||
302 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
303 ($strict_export && !project_in_list
($project))) {
305 die_error
(undef, "No such project");
309 our $file_name = $cgi->param('f');
310 if (defined $file_name) {
311 if (!validate_pathname
($file_name)) {
312 die_error
(undef, "Invalid file parameter");
316 our $file_parent = $cgi->param('fp');
317 if (defined $file_parent) {
318 if (!validate_pathname
($file_parent)) {
319 die_error
(undef, "Invalid file parent parameter");
323 # parameters which are refnames
324 our $hash = $cgi->param('h');
326 if (!validate_refname
($hash)) {
327 die_error
(undef, "Invalid hash parameter");
331 our $hash_parent = $cgi->param('hp');
332 if (defined $hash_parent) {
333 if (!validate_refname
($hash_parent)) {
334 die_error
(undef, "Invalid hash parent parameter");
338 our $hash_base = $cgi->param('hb');
339 if (defined $hash_base) {
340 if (!validate_refname
($hash_base)) {
341 die_error
(undef, "Invalid hash base parameter");
345 our $hash_parent_base = $cgi->param('hpb');
346 if (defined $hash_parent_base) {
347 if (!validate_refname
($hash_parent_base)) {
348 die_error
(undef, "Invalid hash parent base parameter");
353 our $page = $cgi->param('pg');
355 if ($page =~ m/[^0-9]/) {
356 die_error
(undef, "Invalid page parameter");
360 our $searchtext = $cgi->param('s');
361 if (defined $searchtext) {
362 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\
@ ]/) {
363 die_error
(undef, "Invalid search parameter");
365 if (length($searchtext) < 2) {
366 die_error
(undef, "At least two characters are required for search parameter");
368 $searchtext = quotemeta $searchtext;
371 our $searchtype = $cgi->param('st');
372 if (defined $searchtype) {
373 if ($searchtype =~ m/[^a-z]/) {
374 die_error
(undef, "Invalid searchtype parameter");
378 # now read PATH_INFO and use it as alternative to parameters
379 sub evaluate_path_info
{
380 return if defined $project;
381 my $path_info = $ENV{"PATH_INFO"};
382 return if !$path_info;
383 $path_info =~ s
,^/+,,;
384 return if !$path_info;
385 # find which part of PATH_INFO is project
386 $project = $path_info;
388 while ($project && !check_head_link
("$projectroot/$project")) {
389 $project =~ s
,/*[^/]*$,,;
392 $project = validate_pathname
($project);
394 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
395 ($strict_export && !project_in_list
($project))) {
399 # do not change any parameters if an action is given using the query string
401 $path_info =~ s
,^$project/*,,;
402 my ($refname, $pathname) = split(/:/, $path_info, 2);
403 if (defined $pathname) {
404 # we got "project.git/branch:filename" or "project.git/branch:dir/"
405 # we could use git_get_type(branch:pathname), but it needs $git_dir
406 $pathname =~ s
,^/+,,;
407 if (!$pathname || substr($pathname, -1) eq "/") {
411 $action ||= "blob_plain";
413 $hash_base ||= validate_refname
($refname);
414 $file_name ||= validate_pathname
($pathname);
415 } elsif (defined $refname) {
416 # we got "project.git/branch"
417 $action ||= "shortlog";
418 $hash ||= validate_refname
($refname);
421 evaluate_path_info
();
423 # path to the current git repository
425 $git_dir = "$projectroot/$project" if $project;
429 "blame" => \
&git_blame2
,
430 "blobdiff" => \
&git_blobdiff
,
431 "blobdiff_plain" => \
&git_blobdiff_plain
,
432 "blob" => \
&git_blob
,
433 "blob_plain" => \
&git_blob_plain
,
434 "commitdiff" => \
&git_commitdiff
,
435 "commitdiff_plain" => \
&git_commitdiff_plain
,
436 "commit" => \
&git_commit
,
437 "forks" => \
&git_forks
,
438 "heads" => \
&git_heads
,
439 "history" => \
&git_history
,
442 "atom" => \
&git_atom
,
443 "search" => \
&git_search
,
444 "search_help" => \
&git_search_help
,
445 "shortlog" => \
&git_shortlog
,
446 "summary" => \
&git_summary
,
448 "tags" => \
&git_tags
,
449 "tree" => \
&git_tree
,
450 "snapshot" => \
&git_snapshot
,
451 "object" => \
&git_object
,
452 # those below don't need $project
453 "opml" => \
&git_opml
,
454 "project_list" => \
&git_project_list
,
455 "project_index" => \
&git_project_index
,
458 if (defined $project) {
459 $action ||= 'summary';
461 $action ||= 'project_list';
463 if (!defined($actions{$action})) {
464 die_error
(undef, "Unknown action");
466 if ($action !~ m/^(opml|project_list|project_index)$/ &&
468 die_error
(undef, "Project needed");
470 $actions{$action}->();
473 ## ======================================================================
478 # default is to use -absolute url() i.e. $my_uri
479 my $href = $params{-full
} ? $my_url : $my_uri;
481 # XXX: Warning: If you touch this, check the search form for updating,
492 hash_parent_base
=> "hpb",
498 my %mapping = @mapping;
500 $params{'project'} = $project unless exists $params{'project'};
502 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
504 # use PATH_INFO for project name
505 $href .= "/$params{'project'}" if defined $params{'project'};
506 delete $params{'project'};
508 # Summary just uses the project path URL
509 if (defined $params{'action'} && $params{'action'} eq 'summary') {
510 delete $params{'action'};
514 # now encode the parameters explicitly
516 for (my $i = 0; $i < @mapping; $i += 2) {
517 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
518 if (defined $params{$name}) {
519 push @result, $symbol . "=" . esc_param
($params{$name});
522 $href .= "?" . join(';', @result) if scalar @result;
528 ## ======================================================================
529 ## validation, quoting/unquoting and escaping
531 sub validate_pathname
{
532 my $input = shift || return undef;
534 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
535 # at the beginning, at the end, and between slashes.
536 # also this catches doubled slashes
537 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
541 if ($input =~ m!\0!) {
547 sub validate_refname
{
548 my $input = shift || return undef;
550 # textual hashes are O.K.
551 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
554 # it must be correct pathname
555 $input = validate_pathname
($input)
557 # restrictions on ref name according to git-check-ref-format
558 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
564 # very thin wrapper for decode("utf8", $str, Encode::FB_DEFAULT);
567 return decode
("utf8", $str, Encode
::FB_DEFAULT
);
570 # quote unsafe chars, but keep the slash, even when it's not
571 # correct, but quoted slashes look too horrible in bookmarks
574 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
580 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
583 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
589 # replace invalid utf8 character with SUBSTITUTION sequence
594 $str = to_utf8
($str);
595 $str = $cgi->escapeHTML($str);
596 if ($opts{'-nbsp'}) {
597 $str =~ s/ / /g;
599 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
603 # quote control characters and escape filename to HTML
608 $str = to_utf8
($str);
609 $str = $cgi->escapeHTML($str);
610 if ($opts{'-nbsp'}) {
611 $str =~ s/ / /g;
613 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
617 # Make control characters "printable", using character escape codes (CEC)
620 my %es = ( # character escape codes, aka escape sequences
621 "\t" => '\t', # tab (HT)
622 "\n" => '\n', # line feed (LF)
623 "\r" => '\r', # carrige return (CR)
624 "\f" => '\f', # form feed (FF)
625 "\b" => '\b', # backspace (BS)
626 "\a" => '\a', # alarm (bell) (BEL)
627 "\e" => '\e', # escape (ESC)
628 "\013" => '\v', # vertical tab (VT)
629 "\000" => '\0', # nul character (NUL)
631 my $chr = ( (exists $es{$cntrl})
633 : sprintf('\%03o', ord($cntrl)) );
634 return "<span class=\"cntrl\">$chr</span>";
637 # Alternatively use unicode control pictures codepoints,
638 # Unicode "printable representation" (PR)
641 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
642 return "<span class=\"cntrl\">$chr</span>";
645 # git may return quoted and escaped filenames
651 my %es = ( # character escape codes, aka escape sequences
652 't' => "\t", # tab (HT, TAB)
653 'n' => "\n", # newline (NL)
654 'r' => "\r", # return (CR)
655 'f' => "\f", # form feed (FF)
656 'b' => "\b", # backspace (BS)
657 'a' => "\a", # alarm (bell) (BEL)
658 'e' => "\e", # escape (ESC)
659 'v' => "\013", # vertical tab (VT)
662 if ($seq =~ m/^[0-7]{1,3}$/) {
663 # octal char sequence
664 return chr(oct($seq));
665 } elsif (exists $es{$seq}) {
666 # C escape sequence, aka character escape code
669 # quoted ordinary character
673 if ($str =~ m/^"(.*)"$/) {
676 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
681 # escape tabs (convert tabs to spaces)
685 while ((my $pos = index($line, "\t")) != -1) {
686 if (my $count = (8 - ($pos % 8))) {
687 my $spaces = ' ' x
$count;
688 $line =~ s/\t/$spaces/;
695 sub project_in_list
{
697 my @list = git_get_projects_list
();
698 return @list && scalar(grep { $_->{'path'} eq $project } @list);
701 ## ----------------------------------------------------------------------
702 ## HTML aware string manipulation
707 my $add_len = shift || 10;
709 # allow only $len chars, but don't cut a word if it would fit in $add_len
710 # if it doesn't fit, cut it if it's still longer than the dots we would add
711 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@]{0,$add_len})(.*)/;
714 if (length($tail) > 4) {
716 $body =~ s/&[^;]*$//; # remove chopped character entities
721 ## ----------------------------------------------------------------------
722 ## functions returning short strings
724 # CSS class for given age value (in seconds)
728 if ($age < 60*60*2) {
730 } elsif ($age < 60*60*24*2) {
737 # convert age in seconds to "nn units ago" string
742 if ($age > 60*60*24*365*2) {
743 $age_str = (int $age/60/60/24/365);
744 $age_str .= " years ago";
745 } elsif ($age > 60*60*24*(365/12)*2) {
746 $age_str = int $age/60/60/24/(365/12);
747 $age_str .= " months ago";
748 } elsif ($age > 60*60*24*7*2) {
749 $age_str = int $age/60/60/24/7;
750 $age_str .= " weeks ago";
751 } elsif ($age > 60*60*24*2) {
752 $age_str = int $age/60/60/24;
753 $age_str .= " days ago";
754 } elsif ($age > 60*60*2) {
755 $age_str = int $age/60/60;
756 $age_str .= " hours ago";
757 } elsif ($age > 60*2) {
758 $age_str = int $age/60;
759 $age_str .= " min ago";
762 $age_str .= " sec ago";
764 $age_str .= " right now";
769 # convert file mode in octal to symbolic file mode string
771 my $mode = oct shift;
773 if (S_ISDIR
($mode & S_IFMT
)) {
775 } elsif (S_ISLNK
($mode)) {
777 } elsif (S_ISREG
($mode)) {
778 # git cares only about the executable bit
779 if ($mode & S_IXUSR
) {
789 # convert file mode in octal to file type string
793 if ($mode !~ m/^[0-7]+$/) {
799 if (S_ISDIR
($mode & S_IFMT
)) {
801 } elsif (S_ISLNK
($mode)) {
803 } elsif (S_ISREG
($mode)) {
810 # convert file mode in octal to file type description string
814 if ($mode !~ m/^[0-7]+$/) {
820 if (S_ISDIR
($mode & S_IFMT
)) {
822 } elsif (S_ISLNK
($mode)) {
824 } elsif (S_ISREG
($mode)) {
825 if ($mode & S_IXUSR
) {
836 ## ----------------------------------------------------------------------
837 ## functions returning short HTML fragments, or transforming HTML fragments
838 ## which don't belong to other sections
840 # format line of commit message.
841 sub format_log_line_html
{
844 $line = esc_html
($line, -nbsp
=>1);
845 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
848 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
849 -class => "text"}, $hash_text);
850 $line =~ s/$hash_text/$link/;
855 # format marker of refs pointing to given object
856 sub format_ref_marker
{
857 my ($refs, $id) = @_;
860 if (defined $refs->{$id}) {
861 foreach my $ref (@{$refs->{$id}}) {
862 my ($type, $name) = qw();
863 # e.g. tags/v2.6.11 or heads/next
864 if ($ref =~ m!^(.*?)s?/(.*)$!) {
872 $markers .= " <span class=\"$type\" title=\"$ref\">" .
873 esc_html
($name) . "</span>";
878 return ' <span class="refs">'. $markers . '</span>';
884 # format, perhaps shortened and with markers, title line
885 sub format_subject_html
{
886 my ($long, $short, $href, $extra) = @_;
887 $extra = '' unless defined($extra);
889 if (length($short) < length($long)) {
890 return $cgi->a({-href
=> $href, -class => "list subject",
891 -title
=> to_utf8
($long)},
892 esc_html
($short) . $extra);
894 return $cgi->a({-href
=> $href, -class => "list subject"},
895 esc_html
($long) . $extra);
899 # format patch (diff) line (rather not to be used for diff headers)
900 sub format_diff_line
{
902 my ($from, $to) = @_;
903 my $char = substr($line, 0, 1);
909 $diff_class = " add";
910 } elsif ($char eq "-") {
911 $diff_class = " rem";
912 } elsif ($char eq "@") {
913 $diff_class = " chunk_header";
914 } elsif ($char eq "\\") {
915 $diff_class = " incomplete";
917 $line = untabify
($line);
918 if ($from && $to && $line =~ m/^\@{2} /) {
919 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
920 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
922 $from_lines = 0 unless defined $from_lines;
923 $to_lines = 0 unless defined $to_lines;
925 if ($from->{'href'}) {
926 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
927 -class=>"list"}, $from_text);
930 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
931 -class=>"list"}, $to_text);
933 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
934 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
935 return "<div class=\"diff$diff_class\">$line</div>\n";
937 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
940 ## ----------------------------------------------------------------------
941 ## git utility subroutines, invoking git commands
943 # returns path to the core git executable and the --git-dir parameter as list
945 return $GIT, '--git-dir='.$git_dir;
948 # returns path to the core git executable and the --git-dir parameter as string
950 return join(' ', git_cmd
());
953 # get HEAD ref of given project as hash
954 sub git_get_head_hash
{
956 my $o_git_dir = $git_dir;
958 $git_dir = "$projectroot/$project";
959 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
962 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
966 if (defined $o_git_dir) {
967 $git_dir = $o_git_dir;
972 # get type of given object
976 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
983 sub git_get_project_config
{
984 my ($key, $type) = @_;
986 return unless ($key);
987 $key =~ s/^gitweb\.//;
988 return if ($key =~ m/\W/);
990 my @x = (git_cmd
(), 'config');
991 if (defined $type) { push @x, $type; }
993 push @x, "gitweb.$key";
999 # get hash of given path at given ref
1000 sub git_get_hash_by_path
{
1002 my $path = shift || return undef;
1007 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
1008 or die_error
(undef, "Open git-ls-tree failed");
1010 close $fd or return undef;
1012 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1013 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1014 if (defined $type && $type ne $2) {
1015 # type doesn't match
1021 ## ......................................................................
1022 ## git utility functions, directly accessing git repository
1024 sub git_get_project_description
{
1027 open my $fd, "$projectroot/$path/description" or return undef;
1034 sub git_get_project_url_list
{
1037 open my $fd, "$projectroot/$path/cloneurl" or return;
1038 my @git_project_url_list = map { chomp; $_ } <$fd>;
1041 return wantarray ? @git_project_url_list : \
@git_project_url_list;
1044 sub git_get_projects_list
{
1049 $filter =~ s/\.git$//;
1051 my ($check_forks) = gitweb_check_feature
('forks');
1053 if (-d
$projects_list) {
1054 # search in directory
1055 my $dir = $projects_list . ($filter ? "/$filter" : '');
1056 # remove the trailing "/"
1058 my $pfxlen = length("$dir");
1061 follow_fast
=> 1, # follow symbolic links
1062 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1064 # skip project-list toplevel, if we get it.
1065 return if (m!^[/.]$!);
1066 # only directories can be git repositories
1067 return unless (-d
$_);
1069 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1070 # we check related file in $projectroot
1071 if ($check_forks and $subdir =~ m
#/.#) {
1072 $File::Find
::prune
= 1;
1073 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1074 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
1075 $File::Find
::prune
= 1;
1080 } elsif (-f
$projects_list) {
1081 # read from file(url-encoded):
1082 # 'git%2Fgit.git Linus+Torvalds'
1083 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1084 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1086 open my ($fd), $projects_list or return;
1088 while (my $line = <$fd>) {
1090 my ($path, $owner) = split ' ', $line;
1091 $path = unescape
($path);
1092 $owner = unescape
($owner);
1093 if (!defined $path) {
1096 if ($filter ne '') {
1097 # looking for forks;
1098 my $pfx = substr($path, 0, length($filter));
1099 if ($pfx ne $filter) {
1102 my $sfx = substr($path, length($filter));
1103 if ($sfx !~ /^\/.*\
.git
$/) {
1106 } elsif ($check_forks) {
1108 foreach my $filter (keys %paths) {
1109 # looking for forks;
1110 my $pfx = substr($path, 0, length($filter));
1111 if ($pfx ne $filter) {
1114 my $sfx = substr($path, length($filter));
1115 if ($sfx !~ /^\/.*\
.git
$/) {
1118 # is a fork, don't include it in
1123 if (check_export_ok
("$projectroot/$path")) {
1126 owner
=> to_utf8
($owner),
1129 (my $forks_path = $path) =~ s/\.git$//;
1130 $paths{$forks_path}++;
1135 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
1139 sub git_get_project_owner
{
1140 my $project = shift;
1143 return undef unless $project;
1145 # read from file (url-encoded):
1146 # 'git%2Fgit.git Linus+Torvalds'
1147 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1148 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1149 if (-f
$projects_list) {
1150 open (my $fd , $projects_list);
1151 while (my $line = <$fd>) {
1153 my ($pr, $ow) = split ' ', $line;
1154 $pr = unescape
($pr);
1155 $ow = unescape
($ow);
1156 if ($pr eq $project) {
1157 $owner = to_utf8
($ow);
1163 if (!defined $owner) {
1164 $owner = get_file_owner
("$projectroot/$project");
1170 sub git_get_last_activity
{
1174 $git_dir = "$projectroot/$path";
1175 open($fd, "-|", git_cmd
(), 'for-each-ref',
1176 '--format=%(committer)',
1177 '--sort=-committerdate',
1179 'refs/heads') or return;
1180 my $most_recent = <$fd>;
1181 close $fd or return;
1182 if ($most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1184 my $age = time - $timestamp;
1185 return ($age, age_string
($age));
1189 sub git_get_references
{
1190 my $type = shift || "";
1192 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1193 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1194 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1195 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
1198 while (my $line = <$fd>) {
1200 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1201 if (defined $refs{$1}) {
1202 push @{$refs{$1}}, $2;
1208 close $fd or return;
1212 sub git_get_rev_name_tags
{
1213 my $hash = shift || return undef;
1215 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1217 my $name_rev = <$fd>;
1220 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1223 # catches also '$hash undefined' output
1228 ## ----------------------------------------------------------------------
1229 ## parse to hash functions
1233 my $tz = shift || "-0000";
1236 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1237 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1238 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1239 $date{'hour'} = $hour;
1240 $date{'minute'} = $min;
1241 $date{'mday'} = $mday;
1242 $date{'day'} = $days[$wday];
1243 $date{'month'} = $months[$mon];
1244 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1245 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1246 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1247 $mday, $months[$mon], $hour ,$min;
1248 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1249 1900+$year, $mon, $mday, $hour ,$min, $sec;
1251 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1252 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1253 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1254 $date{'hour_local'} = $hour;
1255 $date{'minute_local'} = $min;
1256 $date{'tz_local'} = $tz;
1257 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1258 1900+$year, $mon+1, $mday,
1259 $hour, $min, $sec, $tz);
1268 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1269 $tag{'id'} = $tag_id;
1270 while (my $line = <$fd>) {
1272 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1273 $tag{'object'} = $1;
1274 } elsif ($line =~ m/^type (.+)$/) {
1276 } elsif ($line =~ m/^tag (.+)$/) {
1278 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1279 $tag{'author'} = $1;
1282 } elsif ($line =~ m/--BEGIN/) {
1283 push @comment, $line;
1285 } elsif ($line eq "") {
1289 push @comment, <$fd>;
1290 $tag{'comment'} = \
@comment;
1291 close $fd or return;
1292 if (!defined $tag{'name'}) {
1298 sub parse_commit_text
{
1299 my ($commit_text, $withparents) = @_;
1300 my @commit_lines = split '\n', $commit_text;
1303 pop @commit_lines; # Remove '\0'
1305 my $header = shift @commit_lines;
1306 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
1309 ($co{'id'}, my @parents) = split ' ', $header;
1310 while (my $line = shift @commit_lines) {
1311 last if $line eq "\n";
1312 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1314 } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) {
1316 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1318 $co{'author_epoch'} = $2;
1319 $co{'author_tz'} = $3;
1320 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1321 $co{'author_name'} = $1;
1322 $co{'author_email'} = $2;
1324 $co{'author_name'} = $co{'author'};
1326 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1327 $co{'committer'} = $1;
1328 $co{'committer_epoch'} = $2;
1329 $co{'committer_tz'} = $3;
1330 $co{'committer_name'} = $co{'committer'};
1331 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
1332 $co{'committer_name'} = $1;
1333 $co{'committer_email'} = $2;
1335 $co{'committer_name'} = $co{'committer'};
1339 if (!defined $co{'tree'}) {
1342 $co{'parents'} = \
@parents;
1343 $co{'parent'} = $parents[0];
1345 foreach my $title (@commit_lines) {
1348 $co{'title'} = chop_str
($title, 80, 5);
1349 # remove leading stuff of merges to make the interesting part visible
1350 if (length($title) > 50) {
1351 $title =~ s/^Automatic //;
1352 $title =~ s/^merge (of|with) /Merge ... /i;
1353 if (length($title) > 50) {
1354 $title =~ s/(http|rsync):\/\///;
1356 if (length($title) > 50) {
1357 $title =~ s/(master|www|rsync)\.//;
1359 if (length($title) > 50) {
1360 $title =~ s/kernel.org:?//;
1362 if (length($title) > 50) {
1363 $title =~ s/\/pub\/scm//;
1366 $co{'title_short'} = chop_str
($title, 50, 5);
1370 if ($co{'title'} eq "") {
1371 $co{'title'} = $co{'title_short'} = '(no commit message)';
1373 # remove added spaces
1374 foreach my $line (@commit_lines) {
1377 $co{'comment'} = \
@commit_lines;
1379 my $age = time - $co{'committer_epoch'};
1381 $co{'age_string'} = age_string
($age);
1382 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1383 if ($age > 60*60*24*7*2) {
1384 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1385 $co{'age_string_age'} = $co{'age_string'};
1387 $co{'age_string_date'} = $co{'age_string'};
1388 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1394 my ($commit_id) = @_;
1399 open my $fd, "-|", git_cmd
(), "rev-list",
1405 or die_error
(undef, "Open git-rev-list failed");
1406 %co = parse_commit_text
(<$fd>, 1);
1413 my ($commit_id, $maxcount, $skip, $arg, $filename) = @_;
1421 open my $fd, "-|", git_cmd
(), "rev-list",
1423 ($arg ? ($arg) : ()),
1424 ("--max-count=" . $maxcount),
1425 ("--skip=" . $skip),
1428 ($filename ? ($filename) : ())
1429 or die_error
(undef, "Open git-rev-list failed");
1430 while (my $line = <$fd>) {
1431 my %co = parse_commit_text
($line);
1436 return wantarray ? @cos : \
@cos;
1439 # parse ref from ref_file, given by ref_id, with given type
1441 my $ref_file = shift;
1443 my $type = shift || git_get_type
($ref_id);
1446 $ref_item{'type'} = $type;
1447 $ref_item{'id'} = $ref_id;
1448 $ref_item{'epoch'} = 0;
1449 $ref_item{'age'} = "unknown";
1450 if ($type eq "tag") {
1451 my %tag = parse_tag
($ref_id);
1452 $ref_item{'comment'} = $tag{'comment'};
1453 if ($tag{'type'} eq "commit") {
1454 my %co = parse_commit
($tag{'object'});
1455 $ref_item{'epoch'} = $co{'committer_epoch'};
1456 $ref_item{'age'} = $co{'age_string'};
1457 } elsif (defined($tag{'epoch'})) {
1458 my $age = time - $tag{'epoch'};
1459 $ref_item{'epoch'} = $tag{'epoch'};
1460 $ref_item{'age'} = age_string
($age);
1462 $ref_item{'reftype'} = $tag{'type'};
1463 $ref_item{'name'} = $tag{'name'};
1464 $ref_item{'refid'} = $tag{'object'};
1465 } elsif ($type eq "commit"){
1466 my %co = parse_commit
($ref_id);
1467 $ref_item{'reftype'} = "commit";
1468 $ref_item{'name'} = $ref_file;
1469 $ref_item{'title'} = $co{'title'};
1470 $ref_item{'refid'} = $ref_id;
1471 $ref_item{'epoch'} = $co{'committer_epoch'};
1472 $ref_item{'age'} = $co{'age_string'};
1474 $ref_item{'reftype'} = $type;
1475 $ref_item{'name'} = $ref_file;
1476 $ref_item{'refid'} = $ref_id;
1482 # parse line of git-diff-tree "raw" output
1483 sub parse_difftree_raw_line
{
1487 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1488 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1489 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1490 $res{'from_mode'} = $1;
1491 $res{'to_mode'} = $2;
1492 $res{'from_id'} = $3;
1494 $res{'status'} = $5;
1495 $res{'similarity'} = $6;
1496 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1497 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1499 $res{'file'} = unquote
($7);
1502 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1503 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1504 $res{'commit'} = $1;
1507 return wantarray ? %res : \
%res;
1510 # parse line of git-ls-tree output
1511 sub parse_ls_tree_line
($;%) {
1516 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1517 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
1525 $res{'name'} = unquote
($4);
1528 return wantarray ? %res : \
%res;
1531 ## ......................................................................
1532 ## parse to array of hashes functions
1534 sub git_get_heads_list
{
1538 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1539 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
1540 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
1543 while (my $line = <$fd>) {
1547 my ($refinfo, $committerinfo) = split(/\0/, $line);
1548 my ($hash, $name, $title) = split(' ', $refinfo, 3);
1549 my ($committer, $epoch, $tz) =
1550 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
1551 $name =~ s!^refs/heads/!!;
1553 $ref_item{'name'} = $name;
1554 $ref_item{'id'} = $hash;
1555 $ref_item{'title'} = $title || '(no commit message)';
1556 $ref_item{'epoch'} = $epoch;
1558 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1560 $ref_item{'age'} = "unknown";
1563 push @headslist, \
%ref_item;
1567 return wantarray ? @headslist : \
@headslist;
1570 sub git_get_tags_list
{
1574 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1575 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
1576 '--format=%(objectname) %(objecttype) %(refname) '.
1577 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
1580 while (my $line = <$fd>) {
1584 my ($refinfo, $creatorinfo) = split(/\0/, $line);
1585 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
1586 my ($creator, $epoch, $tz) =
1587 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
1588 $name =~ s!^refs/tags/!!;
1590 $ref_item{'type'} = $type;
1591 $ref_item{'id'} = $id;
1592 $ref_item{'name'} = $name;
1593 if ($type eq "tag") {
1594 $ref_item{'subject'} = $title;
1595 $ref_item{'reftype'} = $reftype;
1596 $ref_item{'refid'} = $refid;
1598 $ref_item{'reftype'} = $type;
1599 $ref_item{'refid'} = $id;
1602 if ($type eq "tag" || $type eq "commit") {
1603 $ref_item{'epoch'} = $epoch;
1605 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1607 $ref_item{'age'} = "unknown";
1611 push @tagslist, \
%ref_item;
1615 return wantarray ? @tagslist : \
@tagslist;
1618 ## ----------------------------------------------------------------------
1619 ## filesystem-related functions
1621 sub get_file_owner
{
1624 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1625 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1626 if (!defined $gcos) {
1630 $owner =~ s/[,;].*$//;
1631 return to_utf8
($owner);
1634 ## ......................................................................
1635 ## mimetype related functions
1637 sub mimetype_guess_file
{
1638 my $filename = shift;
1639 my $mimemap = shift;
1640 -r
$mimemap or return undef;
1643 open(MIME
, $mimemap) or return undef;
1645 next if m/^#/; # skip comments
1646 my ($mime, $exts) = split(/\t+/);
1647 if (defined $exts) {
1648 my @exts = split(/\s+/, $exts);
1649 foreach my $ext (@exts) {
1650 $mimemap{$ext} = $mime;
1656 $filename =~ /\.([^.]*)$/;
1657 return $mimemap{$1};
1660 sub mimetype_guess
{
1661 my $filename = shift;
1663 $filename =~ /\./ or return undef;
1665 if ($mimetypes_file) {
1666 my $file = $mimetypes_file;
1667 if ($file !~ m!^/!) { # if it is relative path
1668 # it is relative to project
1669 $file = "$projectroot/$project/$file";
1671 $mime = mimetype_guess_file
($filename, $file);
1673 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1679 my $filename = shift;
1682 my $mime = mimetype_guess
($filename);
1683 $mime and return $mime;
1687 return $default_blob_plain_mimetype unless $fd;
1690 return 'text/plain' .
1691 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1692 } elsif (! $filename) {
1693 return 'application/octet-stream';
1694 } elsif ($filename =~ m/\.png$/i) {
1696 } elsif ($filename =~ m/\.gif$/i) {
1698 } elsif ($filename =~ m/\.jpe?g$/i) {
1699 return 'image/jpeg';
1701 return 'application/octet-stream';
1705 ## ======================================================================
1706 ## functions printing HTML: header, footer, error page
1708 sub git_header_html
{
1709 my $status = shift || "200 OK";
1710 my $expires = shift;
1712 my $title = "$site_name";
1713 if (defined $project) {
1714 $title .= " - " . to_utf8
($project);
1715 if (defined $action) {
1716 $title .= "/$action";
1717 if (defined $file_name) {
1718 $title .= " - " . esc_path
($file_name);
1719 if ($action eq "tree" && $file_name !~ m
|/$|) {
1726 # require explicit support from the UA if we are to send the page as
1727 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1728 # we have to do this because MSIE sometimes globs '*/*', pretending to
1729 # support xhtml+xml but choking when it gets what it asked for.
1730 if (defined $cgi->http('HTTP_ACCEPT') &&
1731 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1732 $cgi->Accept('application/xhtml+xml') != 0) {
1733 $content_type = 'application/xhtml+xml';
1735 $content_type = 'text/html';
1737 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1738 -status
=> $status, -expires
=> $expires);
1739 my $mod_perl_version = $ENV{'MOD_PERL'} ? " $ENV{'MOD_PERL'}" : '';
1741 <?xml version="1.0" encoding="utf-8"?>
1742 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1743 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1744 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1745 <!-- git core binaries version $git_version -->
1747 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1748 <meta name="generator" content="gitweb/$version git/$git_version$mod_perl_version"/>
1749 <meta name="robots" content="index, nofollow"/>
1750 <title>$title</title>
1752 # print out each stylesheet that exist
1753 if (defined $stylesheet) {
1754 #provides backwards capability for those people who define style sheet in a config file
1755 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1757 foreach my $stylesheet (@stylesheets) {
1758 next unless $stylesheet;
1759 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1762 if (defined $project) {
1763 printf('<link rel="alternate" title="%s log RSS feed" '.
1764 'href="%s" type="application/rss+xml" />'."\n",
1765 esc_param
($project), href
(action
=>"rss"));
1766 printf('<link rel="alternate" title="%s log Atom feed" '.
1767 'href="%s" type="application/atom+xml" />'."\n",
1768 esc_param
($project), href
(action
=>"atom"));
1770 printf('<link rel="alternate" title="%s projects list" '.
1771 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1772 $site_name, href
(project
=>undef, action
=>"project_index"));
1773 printf('<link rel="alternate" title="%s projects feeds" '.
1774 'href="%s" type="text/x-opml"/>'."\n",
1775 $site_name, href
(project
=>undef, action
=>"opml"));
1777 if (defined $favicon) {
1778 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
1784 if (-f
$site_header) {
1785 open (my $fd, $site_header);
1790 print "<div class=\"page_header\">\n" .
1791 $cgi->a({-href
=> esc_url
($logo_url),
1792 -title
=> $logo_label},
1793 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
1794 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1795 if (defined $project) {
1796 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1797 if (defined $action) {
1802 my ($have_search) = gitweb_check_feature
('search');
1803 if ((defined $project) && ($have_search)) {
1804 if (!defined $searchtext) {
1808 if (defined $hash_base) {
1809 $search_hash = $hash_base;
1810 } elsif (defined $hash) {
1811 $search_hash = $hash;
1813 $search_hash = "HEAD";
1815 $cgi->param("a", "search");
1816 $cgi->param("h", $search_hash);
1817 $cgi->param("p", $project);
1818 print $cgi->startform(-method => "get", -action
=> $my_uri) .
1819 "<div class=\"search\">\n" .
1820 $cgi->hidden(-name
=> "p") . "\n" .
1821 $cgi->hidden(-name
=> "a") . "\n" .
1822 $cgi->hidden(-name
=> "h") . "\n" .
1823 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
1824 -values => ['commit', 'author', 'committer', 'pickaxe']) .
1825 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
1827 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1829 $cgi->end_form() . "\n";
1834 sub git_footer_html
{
1835 print "<div class=\"page_footer\">\n";
1836 if (defined $project) {
1837 my $descr = git_get_project_description
($project);
1838 if (defined $descr) {
1839 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1841 print $cgi->a({-href
=> href
(action
=>"rss"),
1842 -class => "rss_logo"}, "RSS") . " ";
1843 print $cgi->a({-href
=> href
(action
=>"atom"),
1844 -class => "rss_logo"}, "Atom") . "\n";
1846 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1847 -class => "rss_logo"}, "OPML") . " ";
1848 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1849 -class => "rss_logo"}, "TXT") . "\n";
1853 if (-f
$site_footer) {
1854 open (my $fd, $site_footer);
1864 my $status = shift || "403 Forbidden";
1865 my $error = shift || "Malformed query, file missing or permission denied";
1867 git_header_html
($status);
1869 <div class="page_body">
1879 ## ----------------------------------------------------------------------
1880 ## functions printing or outputting HTML: navigation
1882 sub git_print_page_nav
{
1883 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1884 $extra = '' if !defined $extra; # pager or formats
1886 my @navs = qw(summary shortlog log commit commitdiff tree);
1888 @navs = grep { $_ ne $suppress } @navs;
1891 my %arg = map { $_ => {action
=>$_} } @navs;
1892 if (defined $head) {
1893 for (qw(commit commitdiff)) {
1894 $arg{$_}{'hash'} = $head;
1896 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1897 for (qw(shortlog log)) {
1898 $arg{$_}{'hash'} = $head;
1902 $arg{'tree'}{'hash'} = $treehead if defined $treehead;
1903 $arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
1905 print "<div class=\"page_nav\">\n" .
1907 map { $_ eq $current ?
1908 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1910 print "<br/>\n$extra<br/>\n" .
1914 sub format_paging_nav
{
1915 my ($action, $hash, $head, $page, $nrevs) = @_;
1919 if ($hash ne $head || $page) {
1920 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1922 $paging_nav .= "HEAD";
1926 $paging_nav .= " ⋅ " .
1927 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1928 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1930 $paging_nav .= " ⋅ prev";
1933 if ($nrevs >= (100 * ($page+1)-1)) {
1934 $paging_nav .= " ⋅ " .
1935 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1936 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1938 $paging_nav .= " ⋅ next";
1944 ## ......................................................................
1945 ## functions printing or outputting HTML: div
1947 sub git_print_header_div
{
1948 my ($action, $title, $hash, $hash_base) = @_;
1951 $args{'action'} = $action;
1952 $args{'hash'} = $hash if $hash;
1953 $args{'hash_base'} = $hash_base if $hash_base;
1955 print "<div class=\"header\">\n" .
1956 $cgi->a({-href
=> href
(%args), -class => "title"},
1957 $title ? $title : $action) .
1961 #sub git_print_authorship (\%) {
1962 sub git_print_authorship
{
1965 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
1966 print "<div class=\"author_date\">" .
1967 esc_html
($co->{'author_name'}) .
1969 if ($ad{'hour_local'} < 6) {
1970 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1971 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1973 printf(" (%02d:%02d %s)",
1974 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1979 sub git_print_page_path
{
1985 print "<div class=\"page_path\">";
1986 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
1987 -title
=> 'tree root'}, to_utf8
("[$project]"));
1989 if (defined $name) {
1990 my @dirname = split '/', $name;
1991 my $basename = pop @dirname;
1994 foreach my $dir (@dirname) {
1995 $fullname .= ($fullname ? '/' : '') . $dir;
1996 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
1998 -title
=> $fullname}, esc_path
($dir));
2001 if (defined $type && $type eq 'blob') {
2002 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
2004 -title
=> $name}, esc_path
($basename));
2005 } elsif (defined $type && $type eq 'tree') {
2006 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
2008 -title
=> $name}, esc_path
($basename));
2011 print esc_path
($basename);
2014 print "<br/></div>\n";
2017 # sub git_print_log (\@;%) {
2018 sub git_print_log
($;%) {
2022 if ($opts{'-remove_title'}) {
2023 # remove title, i.e. first line of log
2026 # remove leading empty lines
2027 while (defined $log->[0] && $log->[0] eq "") {
2034 foreach my $line (@$log) {
2035 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2038 if (! $opts{'-remove_signoff'}) {
2039 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2042 # remove signoff lines
2049 # print only one empty line
2050 # do not print empty line after signoff
2052 next if ($empty || $signoff);
2058 print format_log_line_html
($line) . "<br/>\n";
2061 if ($opts{'-final_empty_line'}) {
2062 # end with single empty line
2063 print "<br/>\n" unless $empty;
2067 # return link target (what link points to)
2068 sub git_get_link_target
{
2073 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2077 $link_target = <$fd>;
2082 return $link_target;
2085 # given link target, and the directory (basedir) the link is in,
2086 # return target of link relative to top directory (top tree);
2087 # return undef if it is not possible (including absolute links).
2088 sub normalize_link_target
{
2089 my ($link_target, $basedir, $hash_base) = @_;
2091 # we can normalize symlink target only if $hash_base is provided
2092 return unless $hash_base;
2094 # absolute symlinks (beginning with '/') cannot be normalized
2095 return if (substr($link_target, 0, 1) eq '/');
2097 # normalize link target to path from top (root) tree (dir)
2100 $path = $basedir . '/' . $link_target;
2102 # we are in top (root) tree (dir)
2103 $path = $link_target;
2106 # remove //, /./, and /../
2108 foreach my $part (split('/', $path)) {
2109 # discard '.' and ''
2110 next if (!$part || $part eq '.');
2112 if ($part eq '..') {
2116 # link leads outside repository (outside top dir)
2120 push @path_parts, $part;
2123 $path = join('/', @path_parts);
2128 # print tree entry (row of git_tree), but without encompassing <tr> element
2129 sub git_print_tree_entry
{
2130 my ($t, $basedir, $hash_base, $have_blame) = @_;
2133 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2135 # The format of a table row is: mode list link. Where mode is
2136 # the mode of the entry, list is the name of the entry, an href,
2137 # and link is the action links of the entry.
2139 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2140 if ($t->{'type'} eq "blob") {
2141 print "<td class=\"list\">" .
2142 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2143 file_name
=>"$basedir$t->{'name'}", %base_key),
2144 -class => "list"}, esc_path
($t->{'name'}));
2145 if (S_ISLNK
(oct $t->{'mode'})) {
2146 my $link_target = git_get_link_target
($t->{'hash'});
2148 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2149 if (defined $norm_target) {
2151 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2152 file_name
=>$norm_target),
2153 -title
=> $norm_target}, esc_path
($link_target));
2155 print " -> " . esc_path
($link_target);
2160 print "<td class=\"link\">";
2161 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2162 file_name
=>"$basedir$t->{'name'}", %base_key)},
2166 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2167 file_name
=>"$basedir$t->{'name'}", %base_key)},
2170 if (defined $hash_base) {
2172 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2173 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2177 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2178 file_name
=>"$basedir$t->{'name'}")},
2182 } elsif ($t->{'type'} eq "tree") {
2183 print "<td class=\"list\">";
2184 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2185 file_name
=>"$basedir$t->{'name'}", %base_key)},
2186 esc_path
($t->{'name'}));
2188 print "<td class=\"link\">";
2189 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2190 file_name
=>"$basedir$t->{'name'}", %base_key)},
2192 if (defined $hash_base) {
2194 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2195 file_name
=>"$basedir$t->{'name'}")},
2202 ## ......................................................................
2203 ## functions printing large fragments of HTML
2205 sub git_difftree_body
{
2206 my ($difftree, $hash, $parent) = @_;
2207 my ($have_blame) = gitweb_check_feature
('blame');
2208 print "<div class=\"list_head\">\n";
2209 if ($#{$difftree} > 10) {
2210 print(($#{$difftree} + 1) . " files changed:\n");
2214 print "<table class=\"diff_tree\">\n";
2217 foreach my $line (@{$difftree}) {
2218 my %diff = parse_difftree_raw_line
($line);
2221 print "<tr class=\"dark\">\n";
2223 print "<tr class=\"light\">\n";
2227 my ($to_mode_oct, $to_mode_str, $to_file_type);
2228 my ($from_mode_oct, $from_mode_str, $from_file_type);
2229 if ($diff{'to_mode'} ne ('0' x
6)) {
2230 $to_mode_oct = oct $diff{'to_mode'};
2231 if (S_ISREG
($to_mode_oct)) { # only for regular file
2232 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
2234 $to_file_type = file_type
($diff{'to_mode'});
2236 if ($diff{'from_mode'} ne ('0' x
6)) {
2237 $from_mode_oct = oct $diff{'from_mode'};
2238 if (S_ISREG
($to_mode_oct)) { # only for regular file
2239 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
2241 $from_file_type = file_type
($diff{'from_mode'});
2244 if ($diff{'status'} eq "A") { # created
2245 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
2246 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
2247 $mode_chng .= "]</span>";
2249 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2250 hash_base
=>$hash, file_name
=>$diff{'file'}),
2251 -class => "list"}, esc_path
($diff{'file'}));
2253 print "<td>$mode_chng</td>\n";
2254 print "<td class=\"link\">";
2255 if ($action eq 'commitdiff') {
2258 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2261 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2262 hash_base
=>$hash, file_name
=>$diff{'file'})},
2266 } elsif ($diff{'status'} eq "D") { # deleted
2267 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
2269 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
2270 hash_base
=>$parent, file_name
=>$diff{'file'}),
2271 -class => "list"}, esc_path
($diff{'file'}));
2273 print "<td>$mode_chng</td>\n";
2274 print "<td class=\"link\">";
2275 if ($action eq 'commitdiff') {
2278 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2281 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
2282 hash_base
=>$parent, file_name
=>$diff{'file'})},
2285 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2286 file_name
=>$diff{'file'})},
2289 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2290 file_name
=>$diff{'file'})},
2294 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
2295 my $mode_chnge = "";
2296 if ($diff{'from_mode'} != $diff{'to_mode'}) {
2297 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
2298 if ($from_file_type ne $to_file_type) {
2299 $mode_chnge .= " from $from_file_type to $to_file_type";
2301 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
2302 if ($from_mode_str && $to_mode_str) {
2303 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
2304 } elsif ($to_mode_str) {
2305 $mode_chnge .= " mode: $to_mode_str";
2308 $mode_chnge .= "]</span>\n";
2311 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2312 hash_base
=>$hash, file_name
=>$diff{'file'}),
2313 -class => "list"}, esc_path
($diff{'file'}));
2315 print "<td>$mode_chnge</td>\n";
2316 print "<td class=\"link\">";
2317 if ($action eq 'commitdiff') {
2320 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2322 } elsif ($diff{'to_id'} ne $diff{'from_id'}) {
2323 # "commit" view and modified file (not onlu mode changed)
2324 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2325 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
2326 hash_base
=>$hash, hash_parent_base
=>$parent,
2327 file_name
=>$diff{'file'})},
2331 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2332 hash_base
=>$hash, file_name
=>$diff{'file'})},
2335 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2336 file_name
=>$diff{'file'})},
2339 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2340 file_name
=>$diff{'file'})},
2344 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
2345 my %status_name = ('R' => 'moved', 'C' => 'copied');
2346 my $nstatus = $status_name{$diff{'status'}};
2348 if ($diff{'from_mode'} != $diff{'to_mode'}) {
2349 # mode also for directories, so we cannot use $to_mode_str
2350 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
2353 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2354 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
2355 -class => "list"}, esc_path
($diff{'to_file'})) . "</td>\n" .
2356 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
2357 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
2358 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
2359 -class => "list"}, esc_path
($diff{'from_file'})) .
2360 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
2361 "<td class=\"link\">";
2362 if ($action eq 'commitdiff') {
2365 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2367 } elsif ($diff{'to_id'} ne $diff{'from_id'}) {
2368 # "commit" view and modified file (not only pure rename or copy)
2369 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2370 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
2371 hash_base
=>$hash, hash_parent_base
=>$parent,
2372 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
2376 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2377 hash_base
=>$parent, file_name
=>$diff{'to_file'})},
2380 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2381 file_name
=>$diff{'to_file'})},
2384 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2385 file_name
=>$diff{'to_file'})},
2389 } # we should not encounter Unmerged (U) or Unknown (X) status
2395 sub git_patchset_body
{
2396 my ($fd, $difftree, $hash, $hash_parent) = @_;
2403 print "<div class=\"patchset\">\n";
2405 # skip to first patch
2406 while ($patch_line = <$fd>) {
2409 last if ($patch_line =~ m/^diff /);
2413 while ($patch_line) {
2415 my ($from_id, $to_id);
2418 #assert($patch_line =~ m/^diff /) if DEBUG;
2419 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
2420 push @diff_header, $patch_line;
2422 # extended diff header
2424 while ($patch_line = <$fd>) {
2427 last EXTENDED_HEADER
if ($patch_line =~ m/^--- |^diff /);
2429 if ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2434 push @diff_header, $patch_line;
2436 my $last_patch_line = $patch_line;
2438 # check if current patch belong to current raw line
2439 # and parse raw git-diff line if needed
2440 if (defined $diffinfo &&
2441 $diffinfo->{'from_id'} eq $from_id &&
2442 $diffinfo->{'to_id'} eq $to_id) {
2443 # this is split patch
2444 print "<div class=\"patch cont\">\n";
2446 # advance raw git-diff output if needed
2447 $patch_idx++ if defined $diffinfo;
2449 # read and prepare patch information
2450 if (ref($difftree->[$patch_idx]) eq "HASH") {
2451 # pre-parsed (or generated by hand)
2452 $diffinfo = $difftree->[$patch_idx];
2454 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
2456 $from{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
2457 $to{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
2458 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2459 $from{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2460 hash
=>$diffinfo->{'from_id'},
2461 file_name
=>$from{'file'});
2463 delete $from{'href'};
2465 if ($diffinfo->{'status'} ne "D") { # not deleted file
2466 $to{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2467 hash
=>$diffinfo->{'to_id'},
2468 file_name
=>$to{'file'});
2472 # this is first patch for raw difftree line with $patch_idx index
2473 # we index @$difftree array from 0, but number patches from 1
2474 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
2477 # print "git diff" header
2478 $patch_line = shift @diff_header;
2479 $patch_line =~ s!^(diff (.*?) )"?a/.*$!$1!;
2480 if ($from{'href'}) {
2481 $patch_line .= $cgi->a({-href
=> $from{'href'}, -class => "path"},
2482 'a/' . esc_path
($from{'file'}));
2483 } else { # file was added
2484 $patch_line .= 'a/' . esc_path
($from{'file'});
2488 $patch_line .= $cgi->a({-href
=> $to{'href'}, -class => "path"},
2489 'b/' . esc_path
($to{'file'}));
2490 } else { # file was deleted
2491 $patch_line .= 'b/' . esc_path
($to{'file'});
2493 print "<div class=\"diff header\">$patch_line</div>\n";
2495 # print extended diff header
2496 print "<div class=\"diff extended_header\">\n" if (@diff_header > 0);
2498 foreach $patch_line (@diff_header) {
2500 if ($patch_line =~ s!^((copy|rename) from ).*$!$1! && $from{'href'}) {
2501 $patch_line .= $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2502 esc_path
($from{'file'}));
2504 if ($patch_line =~ s!^((copy|rename) to ).*$!$1! && $to{'href'}) {
2505 $patch_line .= $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2506 esc_path
($to{'file'}));
2509 if ($patch_line =~ m/\s(\d{6})$/) {
2510 $patch_line .= '<span class="info"> (' .
2511 file_type_long
($1) .
2515 if ($patch_line =~ m/^index/) {
2516 my ($from_link, $to_link);
2517 if ($from{'href'}) {
2518 $from_link = $cgi->a({-href
=>$from{'href'}, -class=>"hash"},
2519 substr($diffinfo->{'from_id'},0,7));
2521 $from_link = '0' x
7;
2524 $to_link = $cgi->a({-href
=>$to{'href'}, -class=>"hash"},
2525 substr($diffinfo->{'to_id'},0,7));
2530 # my ($from_hash, $to_hash) =
2531 # ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/);
2532 # my ($from_id, $to_id) =
2533 # ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2534 # ($from_hash eq $from_id) && ($to_hash eq $to_id);
2536 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2537 $patch_line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
2539 print $patch_line . "<br/>\n";
2541 print "</div>\n" if (@diff_header > 0); # class="diff extended_header"
2543 # from-file/to-file diff header
2544 $patch_line = $last_patch_line;
2545 if (! $patch_line) {
2546 print "</div>\n"; # class="patch"
2549 next PATCH
if ($patch_line =~ m/^diff /);
2550 #assert($patch_line =~ m/^---/) if DEBUG;
2551 if ($from{'href'} && $patch_line =~ m!^--- "?a/!) {
2552 $patch_line = '--- a/' .
2553 $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2554 esc_path
($from{'file'}));
2556 print "<div class=\"diff from_file\">$patch_line</div>\n";
2558 $patch_line = <$fd>;
2561 #assert($patch_line =~ m/^+++/) if DEBUG;
2562 if ($to{'href'} && $patch_line =~ m!^\+\+\+ "?b/!) {
2563 $patch_line = '+++ b/' .
2564 $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2565 esc_path
($to{'file'}));
2567 print "<div class=\"diff to_file\">$patch_line</div>\n";
2571 while ($patch_line = <$fd>) {
2574 next PATCH
if ($patch_line =~ m/^diff /);
2576 print format_diff_line
($patch_line, \
%from, \
%to);
2580 print "</div>\n"; # class="patch"
2583 print "</div>\n"; # class="patchset"
2586 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2588 sub git_project_list_body
{
2589 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
2591 my ($check_forks) = gitweb_check_feature
('forks');
2594 foreach my $pr (@$projlist) {
2595 my (@aa) = git_get_last_activity
($pr->{'path'});
2599 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
2600 if (!defined $pr->{'descr'}) {
2601 my $descr = git_get_project_description
($pr->{'path'}) || "";
2602 $pr->{'descr_long'} = to_utf8
($descr);
2603 $pr->{'descr'} = chop_str
($descr, 25, 5);
2605 if (!defined $pr->{'owner'}) {
2606 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2609 my $pname = $pr->{'path'};
2610 if (($pname =~ s/\.git$//) &&
2611 ($pname !~ /\/$/) &&
2612 (-d
"$projectroot/$pname")) {
2613 $pr->{'forks'} = "-d $projectroot/$pname";
2619 push @projects, $pr;
2622 $order ||= "project";
2623 $from = 0 unless defined $from;
2624 $to = $#projects if (!defined $to || $#projects < $to);
2626 print "<table class=\"project_list\">\n";
2627 unless ($no_header) {
2630 print "<th></th>\n";
2632 if ($order eq "project") {
2633 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2634 print "<th>Project</th>\n";
2637 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2638 -class => "header"}, "Project") .
2641 if ($order eq "descr") {
2642 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2643 print "<th>Description</th>\n";
2646 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2647 -class => "header"}, "Description") .
2650 if ($order eq "owner") {
2651 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2652 print "<th>Owner</th>\n";
2655 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2656 -class => "header"}, "Owner") .
2659 if ($order eq "age") {
2660 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
2661 print "<th>Last Change</th>\n";
2664 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
2665 -class => "header"}, "Last Change") .
2668 print "<th></th>\n" .
2672 for (my $i = $from; $i <= $to; $i++) {
2673 my $pr = $projects[$i];
2675 print "<tr class=\"dark\">\n";
2677 print "<tr class=\"light\">\n";
2682 if ($pr->{'forks'}) {
2683 print "<!-- $pr->{'forks'} -->\n";
2684 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
2688 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2689 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2690 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2691 -class => "list", -title
=> $pr->{'descr_long'}},
2692 esc_html
($pr->{'descr'})) . "</td>\n" .
2693 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2694 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
2695 $pr->{'age_string'} . "</td>\n" .
2696 "<td class=\"link\">" .
2697 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2698 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2699 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
2700 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
2701 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
2705 if (defined $extra) {
2708 print "<td></td>\n";
2710 print "<td colspan=\"5\">$extra</td>\n" .
2716 sub git_shortlog_body
{
2717 # uses global variable $project
2718 my ($commitlist, $from, $to, $refs, $extra) = @_;
2720 my $have_snapshot = gitweb_have_snapshot
();
2722 $from = 0 unless defined $from;
2723 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
2725 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
2727 for (my $i = $from; $i <= $to; $i++) {
2728 my %co = %{$commitlist->[$i]};
2729 my $commit = $co{'id'};
2730 my $ref = format_ref_marker
($refs, $commit);
2732 print "<tr class=\"dark\">\n";
2734 print "<tr class=\"light\">\n";
2737 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
2738 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2739 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
2741 print format_subject_html
($co{'title'}, $co{'title_short'},
2742 href
(action
=>"commit", hash
=>$commit), $ref);
2744 "<td class=\"link\">" .
2745 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
2746 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
2747 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
2748 if ($have_snapshot) {
2749 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
2754 if (defined $extra) {
2756 "<td colspan=\"4\">$extra</td>\n" .
2762 sub git_history_body
{
2763 # Warning: assumes constant type (blob or tree) during history
2764 my ($commitlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
2766 $from = 0 unless defined $from;
2767 $to = $#{$commitlist} unless (defined $to && $to <= $#{$commitlist});
2769 print "<table class=\"history\" cellspacing=\"0\">\n";
2771 for (my $i = $from; $i <= $to; $i++) {
2772 my %co = %{$commitlist->[$i]};
2776 my $commit = $co{'id'};
2778 my $ref = format_ref_marker
($refs, $commit);
2781 print "<tr class=\"dark\">\n";
2783 print "<tr class=\"light\">\n";
2786 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2787 # shortlog uses chop_str($co{'author_name'}, 10)
2788 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2790 # originally git_history used chop_str($co{'title'}, 50)
2791 print format_subject_html
($co{'title'}, $co{'title_short'},
2792 href
(action
=>"commit", hash
=>$commit), $ref);
2794 "<td class=\"link\">" .
2795 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
2796 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
2798 if ($ftype eq 'blob') {
2799 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
2800 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2801 if (defined $blob_current && defined $blob_parent &&
2802 $blob_current ne $blob_parent) {
2804 $cgi->a({-href
=> href
(action
=>"blobdiff",
2805 hash
=>$blob_current, hash_parent
=>$blob_parent,
2806 hash_base
=>$hash_base, hash_parent_base
=>$commit,
2807 file_name
=>$file_name)},
2814 if (defined $extra) {
2816 "<td colspan=\"4\">$extra</td>\n" .
2823 # uses global variable $project
2824 my ($taglist, $from, $to, $extra) = @_;
2825 $from = 0 unless defined $from;
2826 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2828 print "<table class=\"tags\" cellspacing=\"0\">\n";
2830 for (my $i = $from; $i <= $to; $i++) {
2831 my $entry = $taglist->[$i];
2833 my $comment = $tag{'subject'};
2835 if (defined $comment) {
2836 $comment_short = chop_str
($comment, 30, 5);
2839 print "<tr class=\"dark\">\n";
2841 print "<tr class=\"light\">\n";
2844 if (defined $tag{'age'}) {
2845 print "<td><i>$tag{'age'}</i></td>\n";
2847 print "<td></td>\n";
2850 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
2851 -class => "list name"}, esc_html
($tag{'name'})) .
2854 if (defined $comment) {
2855 print format_subject_html
($comment, $comment_short,
2856 href
(action
=>"tag", hash
=>$tag{'id'}));
2859 "<td class=\"selflink\">";
2860 if ($tag{'type'} eq "tag") {
2861 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
2866 "<td class=\"link\">" . " | " .
2867 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
2868 if ($tag{'reftype'} eq "commit") {
2869 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
2870 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
2871 } elsif ($tag{'reftype'} eq "blob") {
2872 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
2877 if (defined $extra) {
2879 "<td colspan=\"5\">$extra</td>\n" .
2885 sub git_heads_body
{
2886 # uses global variable $project
2887 my ($headlist, $head, $from, $to, $extra) = @_;
2888 $from = 0 unless defined $from;
2889 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
2891 print "<table class=\"heads\" cellspacing=\"0\">\n";
2893 for (my $i = $from; $i <= $to; $i++) {
2894 my $entry = $headlist->[$i];
2896 my $curr = $ref{'id'} eq $head;
2898 print "<tr class=\"dark\">\n";
2900 print "<tr class=\"light\">\n";
2903 print "<td><i>$ref{'age'}</i></td>\n" .
2904 ($curr ? "<td class=\"current_head\">" : "<td>") .
2905 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
2906 -class => "list name"},esc_html
($ref{'name'})) .
2908 "<td class=\"link\">" .
2909 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
2910 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
2911 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
2915 if (defined $extra) {
2917 "<td colspan=\"3\">$extra</td>\n" .
2923 sub git_search_grep_body
{
2924 my ($commitlist, $from, $to, $extra) = @_;
2925 $from = 0 unless defined $from;
2926 $to = $#{$commitlist} if (!defined $to || $#{$commitlist} < $to);
2928 print "<table class=\"grep\" cellspacing=\"0\">\n";
2930 for (my $i = $from; $i <= $to; $i++) {
2931 my %co = %{$commitlist->[$i]};
2935 my $commit = $co{'id'};
2937 print "<tr class=\"dark\">\n";
2939 print "<tr class=\"light\">\n";
2942 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2943 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2945 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
2946 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
2947 my $comment = $co{'comment'};
2948 foreach my $line (@$comment) {
2949 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2950 my $lead = esc_html
($1) || "";
2951 $lead = chop_str
($lead, 30, 10);
2952 my $match = esc_html
($2) || "";
2953 my $trail = esc_html
($3) || "";
2954 $trail = chop_str
($trail, 30, 10);
2955 my $text = "$lead<span class=\"match\">$match</span>$trail";
2956 print chop_str
($text, 80, 5) . "<br/>\n";
2960 "<td class=\"link\">" .
2961 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
2963 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
2967 if (defined $extra) {
2969 "<td colspan=\"3\">$extra</td>\n" .
2975 ## ======================================================================
2976 ## ======================================================================
2979 sub git_project_list
{
2980 my $order = $cgi->param('o');
2981 if (defined $order && $order !~ m/project|descr|owner|age/) {
2982 die_error
(undef, "Unknown order parameter");
2985 my @list = git_get_projects_list
();
2987 die_error
(undef, "No projects found");
2991 if (-f
$home_text) {
2992 print "<div class=\"index_include\">\n";
2993 open (my $fd, $home_text);
2998 git_project_list_body
(\
@list, $order);
3003 my $order = $cgi->param('o');
3004 if (defined $order && $order !~ m/project|descr|owner|age/) {
3005 die_error
(undef, "Unknown order parameter");
3008 my @list = git_get_projects_list
($project);
3010 die_error
(undef, "No forks found");
3014 git_print_page_nav
('','');
3015 git_print_header_div
('summary', "$project forks");
3016 git_project_list_body
(\
@list, $order);
3020 sub git_project_index
{
3021 my @projects = git_get_projects_list
($project);
3024 -type
=> 'text/plain',
3025 -charset
=> 'utf-8',
3026 -content_disposition
=> 'inline; filename="index.aux"');
3028 foreach my $pr (@projects) {
3029 if (!exists $pr->{'owner'}) {
3030 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}");
3033 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
3034 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
3035 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3036 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
3040 print "$path $owner\n";
3045 my $descr = git_get_project_description
($project) || "none";
3046 my %co = parse_commit
("HEAD");
3047 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
3048 my $head = $co{'id'};
3050 my $owner = git_get_project_owner
($project);
3052 my $refs = git_get_references
();
3053 # These get_*_list functions return one more to allow us to see if
3054 # there are more ...
3055 my @taglist = git_get_tags_list
(16);
3056 my @headlist = git_get_heads_list
(16);
3058 my ($check_forks) = gitweb_check_feature
('forks');
3061 @forklist = git_get_projects_list
($project);
3065 git_print_page_nav
('summary','', $head);
3067 print "<div class=\"title\"> </div>\n";
3068 print "<table cellspacing=\"0\">\n" .
3069 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
3070 "<tr><td>owner</td><td>$owner</td></tr>\n" .
3071 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
3072 # use per project git URL list in $projectroot/$project/cloneurl
3073 # or make project git URL from git base URL and project name
3074 my $url_tag = "URL";
3075 my @url_list = git_get_project_url_list
($project);
3076 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
3077 foreach my $git_url (@url_list) {
3078 next unless $git_url;
3079 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
3084 if (-s
"$projectroot/$project/README.html") {
3085 if (open my $fd, "$projectroot/$project/README.html") {
3086 print "<div class=\"title\">readme</div>\n";
3087 print $_ while (<$fd>);
3092 # we need to request one more than 16 (0..15) to check if
3094 my @commitlist = parse_commits
($head, 17);
3095 git_print_header_div
('shortlog');
3096 git_shortlog_body
(\
@commitlist, 0, 15, $refs,
3097 $#commitlist <= 15 ? undef :
3098 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
3101 git_print_header_div
('tags');
3102 git_tags_body
(\
@taglist, 0, 15,
3103 $#taglist <= 15 ? undef :
3104 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
3108 git_print_header_div
('heads');
3109 git_heads_body
(\
@headlist, $head, 0, 15,
3110 $#headlist <= 15 ? undef :
3111 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
3115 git_print_header_div
('forks');
3116 git_project_list_body
(\
@forklist, undef, 0, 15,
3117 $#forklist <= 15 ? undef :
3118 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
3126 my $head = git_get_head_hash
($project);
3128 git_print_page_nav
('','', $head,undef,$head);
3129 my %tag = parse_tag
($hash);
3130 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
3131 print "<div class=\"title_text\">\n" .
3132 "<table cellspacing=\"0\">\n" .
3134 "<td>object</td>\n" .
3135 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3136 $tag{'object'}) . "</td>\n" .
3137 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3138 $tag{'type'}) . "</td>\n" .
3140 if (defined($tag{'author'})) {
3141 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
3142 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
3143 print "<tr><td></td><td>" . $ad{'rfc2822'} .
3144 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
3147 print "</table>\n\n" .
3149 print "<div class=\"page_body\">";
3150 my $comment = $tag{'comment'};
3151 foreach my $line (@$comment) {
3153 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
3163 my ($have_blame) = gitweb_check_feature
('blame');
3165 die_error
('403 Permission denied', "Permission denied");
3167 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3168 $hash_base ||= git_get_head_hash
($project);
3169 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3170 my %co = parse_commit
($hash_base)
3171 or die_error
(undef, "Reading commit failed");
3172 if (!defined $hash) {
3173 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3174 or die_error
(undef, "Error looking up file");
3176 $ftype = git_get_type
($hash);
3177 if ($ftype !~ "blob") {
3178 die_error
('400 Bad Request', "Object is not a blob");
3180 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
3181 $file_name, $hash_base)
3182 or die_error
(undef, "Open git-blame failed");
3185 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3188 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3191 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3193 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3194 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3195 git_print_page_path
($file_name, $ftype, $hash_base);
3196 my @rev_color = (qw(light2 dark2));
3197 my $num_colors = scalar(@rev_color);
3198 my $current_color = 0;
3201 <div class="page_body">
3202 <table class="blame">
3203 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
3208 last unless defined $_;
3209 my ($full_rev, $orig_lineno, $lineno, $group_size) =
3210 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
3211 if (!exists $metainfo{$full_rev}) {
3212 $metainfo{$full_rev} = {};
3214 my $meta = $metainfo{$full_rev};
3217 if (/^(\S+) (.*)$/) {
3223 my $rev = substr($full_rev, 0, 8);
3224 my $author = $meta->{'author'};
3225 my %date = parse_date
($meta->{'author-time'},
3226 $meta->{'author-tz'});
3227 my $date = $date{'iso-tz'};
3229 $current_color = ++$current_color % $num_colors;
3231 print "<tr class=\"$rev_color[$current_color]\">\n";
3233 print "<td class=\"sha1\"";
3234 print " title=\"". esc_html
($author) . ", $date\"";
3235 print " rowspan=\"$group_size\"" if ($group_size > 1);
3237 print $cgi->a({-href
=> href
(action
=>"commit",
3239 file_name
=>$file_name)},
3243 open (my $dd, "-|", git_cmd
(), "rev-parse", "$full_rev^")
3244 or die_error
(undef, "Open git-rev-parse failed");
3245 my $parent_commit = <$dd>;
3247 chomp($parent_commit);
3248 my $blamed = href
(action
=> 'blame',
3249 file_name
=> $meta->{'filename'},
3250 hash_base
=> $parent_commit);
3251 print "<td class=\"linenr\">";
3252 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
3254 -class => "linenr" },
3257 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
3263 or print "Reading blob failed\n";
3270 my ($have_blame) = gitweb_check_feature
('blame');
3272 die_error
('403 Permission denied', "Permission denied");
3274 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3275 $hash_base ||= git_get_head_hash
($project);
3276 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3277 my %co = parse_commit
($hash_base)
3278 or die_error
(undef, "Reading commit failed");
3279 if (!defined $hash) {
3280 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3281 or die_error
(undef, "Error lookup file");
3283 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
3284 or die_error
(undef, "Open git-annotate failed");
3287 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3290 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3293 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3295 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3296 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3297 git_print_page_path
($file_name, 'blob', $hash_base);
3298 print "<div class=\"page_body\">\n";
3300 <table class="blame">
3309 my @line_class = (qw(light dark));
3310 my $line_class_len = scalar (@line_class);
3311 my $line_class_num = $#line_class;
3312 while (my $line = <$fd>) {
3324 $line_class_num = ($line_class_num + 1) % $line_class_len;
3326 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
3333 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
3336 $short_rev = substr ($long_rev, 0, 8);
3337 $age = time () - $time;
3338 $age_str = age_string
($age);
3339 $age_str =~ s/ / /g;
3340 $age_class = age_class
($age);
3341 $author = esc_html
($author);
3342 $author =~ s/ / /g;
3344 $data = untabify
($data);
3345 $data = esc_html
($data);
3348 <tr class="$line_class[$line_class_num]">
3349 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
3350 <td class="$age_class">$age_str</td>
3352 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
3353 <td class="pre">$data</td>
3356 } # while (my $line = <$fd>)
3357 print "</table>\n\n";
3359 or print "Reading blob failed.\n";
3365 my $head = git_get_head_hash
($project);
3367 git_print_page_nav
('','', $head,undef,$head);
3368 git_print_header_div
('summary', $project);
3370 my @tagslist = git_get_tags_list
();
3372 git_tags_body
(\
@tagslist);
3378 my $head = git_get_head_hash
($project);
3380 git_print_page_nav
('','', $head,undef,$head);
3381 git_print_header_div
('summary', $project);
3383 my @headslist = git_get_heads_list
();
3385 git_heads_body
(\
@headslist, $head);
3390 sub git_blob_plain
{
3393 if (!defined $hash) {
3394 if (defined $file_name) {
3395 my $base = $hash_base || git_get_head_hash
($project);
3396 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3397 or die_error
(undef, "Error lookup file");
3399 die_error
(undef, "No file name defined");
3401 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3402 # blobs defined by non-textual hash id's can be cached
3407 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3408 or die_error
(undef, "Couldn't cat $file_name, $hash");
3410 $type ||= blob_mimetype
($fd, $file_name);
3412 # save as filename, even when no $file_name is given
3413 my $save_as = "$hash";
3414 if (defined $file_name) {
3415 $save_as = $file_name;
3416 } elsif ($type =~ m/^text\//) {
3423 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
3425 binmode STDOUT
, ':raw';
3427 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3435 if (!defined $hash) {
3436 if (defined $file_name) {
3437 my $base = $hash_base || git_get_head_hash
($project);
3438 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3439 or die_error
(undef, "Error lookup file");
3441 die_error
(undef, "No file name defined");
3443 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3444 # blobs defined by non-textual hash id's can be cached
3448 my ($have_blame) = gitweb_check_feature
('blame');
3449 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3450 or die_error
(undef, "Couldn't cat $file_name, $hash");
3451 my $mimetype = blob_mimetype
($fd, $file_name);
3452 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
3454 return git_blob_plain
($mimetype);
3456 # we can have blame only for text/* mimetype
3457 $have_blame &&= ($mimetype =~ m!^text/!);
3459 git_header_html
(undef, $expires);
3460 my $formats_nav = '';
3461 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3462 if (defined $file_name) {
3465 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
3466 hash
=>$hash, file_name
=>$file_name)},
3471 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3472 hash
=>$hash, file_name
=>$file_name)},
3475 $cgi->a({-href
=> href
(action
=>"blob_plain",
3476 hash
=>$hash, file_name
=>$file_name)},
3479 $cgi->a({-href
=> href
(action
=>"blob",
3480 hash_base
=>"HEAD", file_name
=>$file_name)},
3484 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
3486 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3487 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3489 print "<div class=\"page_nav\">\n" .
3490 "<br/><br/></div>\n" .
3491 "<div class=\"title\">$hash</div>\n";
3493 git_print_page_path
($file_name, "blob", $hash_base);
3494 print "<div class=\"page_body\">\n";
3495 if ($mimetype =~ m!^text/!) {
3497 while (my $line = <$fd>) {
3500 $line = untabify
($line);
3501 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
3502 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
3504 } elsif ($mimetype =~ m!^image/!) {
3505 print qq
!<img type
="$mimetype"!;
3507 print qq
! alt
="$file_name" title
="$file_name"!;
3510 href(action=>"blob_plain
", hash=>$hash,
3511 hash_base=>$hash_base, file_name=>$file_name) .
3515 or print "Reading blob failed.\n";
3521 my $have_snapshot = gitweb_have_snapshot
();
3523 if (!defined $hash_base) {
3524 $hash_base = "HEAD";
3526 if (!defined $hash) {
3527 if (defined $file_name) {
3528 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
3534 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
3535 or die_error
(undef, "Open git-ls-tree failed");
3536 my @entries = map { chomp; $_ } <$fd>;
3537 close $fd or die_error
(undef, "Reading tree failed");
3540 my $refs = git_get_references
();
3541 my $ref = format_ref_marker
($refs, $hash_base);
3544 my ($have_blame) = gitweb_check_feature
('blame');
3545 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3547 if (defined $file_name) {
3549 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3550 hash
=>$hash, file_name
=>$file_name)},
3552 $cgi->a({-href
=> href
(action
=>"tree",
3553 hash_base
=>"HEAD", file_name
=>$file_name)},
3556 if ($have_snapshot) {
3557 # FIXME: Should be available when we have no hash base as well.
3559 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
3562 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
3563 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
3566 print "<div class=\"page_nav\">\n";
3567 print "<br/><br/></div>\n";
3568 print "<div class=\"title\">$hash</div>\n";
3570 if (defined $file_name) {
3571 $basedir = $file_name;
3572 if ($basedir ne '' && substr($basedir, -1) ne '/') {
3576 git_print_page_path
($file_name, 'tree', $hash_base);
3577 print "<div class=\"page_body\">\n";
3578 print "<table cellspacing=\"0\">\n";
3580 # '..' (top directory) link if possible
3581 if (defined $hash_base &&
3582 defined $file_name && $file_name =~ m![^/]+$!) {
3584 print "<tr class=\"dark\">\n";
3586 print "<tr class=\"light\">\n";
3590 my $up = $file_name;
3591 $up =~ s!/?[^/]+$!!;
3592 undef $up unless $up;
3593 # based on git_print_tree_entry
3594 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
3595 print '<td class="list">';
3596 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
3600 print "<td class=\"link\"></td>\n";
3604 foreach my $line (@entries) {
3605 my %t = parse_ls_tree_line
($line, -z
=> 1);
3608 print "<tr class=\"dark\">\n";
3610 print "<tr class=\"light\">\n";
3614 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
3618 print "</table>\n" .
3624 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
3625 my $have_snapshot = (defined $ctype && defined $suffix);
3626 if (!$have_snapshot) {
3627 die_error
('403 Permission denied', "Permission denied");
3630 if (!defined $hash) {
3631 $hash = git_get_head_hash
($project);
3634 my $filename = to_utf8
(basename
($project)) . "-$hash.tar.$suffix";
3637 -type
=> "application/$ctype",
3638 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
3639 -status
=> '200 OK');
3641 my $git = git_cmd_str
();
3642 my $name = $project;
3643 $name =~ s/\047/\047\\\047\047/g;
3645 "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
3646 or die_error
(undef, "Execute git-tar-tree failed");
3647 binmode STDOUT
, ':raw';
3649 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3655 my $head = git_get_head_hash
($project);
3656 if (!defined $hash) {
3659 if (!defined $page) {
3662 my $refs = git_get_references
();
3664 my @commitlist = parse_commits
($hash, 101, (100 * $page));
3666 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, (100 * ($page+1)));
3669 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
3672 my %co = parse_commit
($hash);
3674 git_print_header_div
('summary', $project);
3675 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
3677 my $to = ($#commitlist >= 99) ? (99) : ($#commitlist);
3678 for (my $i = 0; $i <= $to; $i++) {
3679 my %co = %{$commitlist[$i]};
3681 my $commit = $co{'id'};
3682 my $ref = format_ref_marker
($refs, $commit);
3683 my %ad = parse_date
($co{'author_epoch'});
3684 git_print_header_div
('commit',
3685 "<span class=\"age\">$co{'age_string'}</span>" .
3686 esc_html
($co{'title'}) . $ref,
3688 print "<div class=\"title_text\">\n" .
3689 "<div class=\"log_link\">\n" .
3690 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
3692 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
3694 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
3697 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
3700 print "<div class=\"log_body\">\n";
3701 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
3704 if ($#commitlist >= 100) {
3705 print "<div class=\"page_nav\">\n";
3706 print $cgi->a({-href
=> href
(action
=>"log", hash
=>$hash, page
=>$page+1),
3707 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3714 $hash ||= $hash_base || "HEAD";
3715 my %co = parse_commit
($hash);
3717 die_error
(undef, "Unknown commit object");
3719 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3720 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
3722 my $parent = $co{'parent'};
3723 my $parents = $co{'parents'}; # listref
3725 # we need to prepare $formats_nav before any parameter munging
3727 if (!defined $parent) {
3729 $formats_nav .= '(initial)';
3730 } elsif (@$parents == 1) {
3731 # single parent commit
3734 $cgi->a({-href
=> href
(action
=>"commit",
3736 esc_html
(substr($parent, 0, 7))) .
3743 $cgi->a({-href
=> href
(action
=>"commit",
3745 esc_html
(substr($_, 0, 7)));
3750 if (!defined $parent) {
3754 if (@$parents <= 1) {
3755 # difftree output is not printed for merges
3756 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
3757 @diff_opts, $parent, $hash, "--"
3758 or die_error
(undef, "Open git-diff-tree failed");
3759 @difftree = map { chomp; $_ } <$fd>;
3760 close $fd or die_error
(undef, "Reading git-diff-tree failed");
3763 # non-textual hash id's can be cached
3765 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3768 my $refs = git_get_references
();
3769 my $ref = format_ref_marker
($refs, $co{'id'});
3771 my $have_snapshot = gitweb_have_snapshot
();
3773 git_header_html
(undef, $expires);
3774 git_print_page_nav
('commit', '',
3775 $hash, $co{'tree'}, $hash,
3778 if (defined $co{'parent'}) {
3779 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
3781 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
3783 print "<div class=\"title_text\">\n" .
3784 "<table cellspacing=\"0\">\n";
3785 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
3787 "<td></td><td> $ad{'rfc2822'}";
3788 if ($ad{'hour_local'} < 6) {
3789 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3790 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3792 printf(" (%02d:%02d %s)",
3793 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3797 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
3798 print "<tr><td></td><td> $cd{'rfc2822'}" .
3799 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
3801 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
3804 "<td class=\"sha1\">" .
3805 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
3806 class => "list"}, $co{'tree'}) .
3808 "<td class=\"link\">" .
3809 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
3811 if ($have_snapshot) {
3813 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
3818 foreach my $par (@$parents) {
3821 "<td class=\"sha1\">" .
3822 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
3823 class => "list"}, $par) .
3825 "<td class=\"link\">" .
3826 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
3828 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
3835 print "<div class=\"page_body\">\n";
3836 git_print_log
($co{'comment'});
3839 if (@$parents <= 1) {
3840 # do not output difftree/whatchanged for merges
3841 git_difftree_body
(\
@difftree, $hash, $parent);
3848 # object is defined by:
3849 # - hash or hash_base alone
3850 # - hash_base and file_name
3853 # - hash or hash_base alone
3854 if ($hash || ($hash_base && !defined $file_name)) {
3855 my $object_id = $hash || $hash_base;
3857 my $git_command = git_cmd_str
();
3858 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
3859 or die_error
('404 Not Found', "Object does not exist");
3863 or die_error
('404 Not Found', "Object does not exist");
3865 # - hash_base and file_name
3866 } elsif ($hash_base && defined $file_name) {
3867 $file_name =~ s
,/+$,,;
3869 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
3870 or die_error
('404 Not Found', "Base object does not exist");
3872 # here errors should not hapen
3873 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
3874 or die_error
(undef, "Open git-ls-tree failed");
3878 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
3879 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
3880 die_error
('404 Not Found', "File or directory for given base does not exist");
3885 die_error
('404 Not Found', "Not enough information to find object");
3888 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
3889 hash
=>$hash, hash_base
=>$hash_base,
3890 file_name
=>$file_name),
3891 -status
=> '302 Found');
3895 my $format = shift || 'html';
3902 # preparing $fd and %diffinfo for git_patchset_body
3904 if (defined $hash_base && defined $hash_parent_base) {
3905 if (defined $file_name) {
3907 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3908 $hash_parent_base, $hash_base,
3909 "--", (defined $file_parent ? $file_parent : ()), $file_name
3910 or die_error
(undef, "Open git-diff-tree failed");
3911 @difftree = map { chomp; $_ } <$fd>;
3913 or die_error
(undef, "Reading git-diff-tree failed");
3915 or die_error
('404 Not Found', "Blob diff not found");
3917 } elsif (defined $hash &&
3918 $hash =~ /[0-9a-fA-F]{40}/) {
3919 # try to find filename from $hash
3921 # read filtered raw output
3922 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3923 $hash_parent_base, $hash_base, "--"
3924 or die_error
(undef, "Open git-diff-tree failed");
3926 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
3928 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
3929 map { chomp; $_ } <$fd>;
3931 or die_error
(undef, "Reading git-diff-tree failed");
3933 or die_error
('404 Not Found', "Blob diff not found");
3936 die_error
('404 Not Found', "Missing one of the blob diff parameters");
3939 if (@difftree > 1) {
3940 die_error
('404 Not Found', "Ambiguous blob diff specification");
3943 %diffinfo = parse_difftree_raw_line
($difftree[0]);
3944 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
3945 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
3947 $hash_parent ||= $diffinfo{'from_id'};
3948 $hash ||= $diffinfo{'to_id'};
3950 # non-textual hash id's can be cached
3951 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
3952 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
3957 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3958 '-p', ($format eq 'html' ? "--full-index" : ()),
3959 $hash_parent_base, $hash_base,
3960 "--", (defined $file_parent ? $file_parent : ()), $file_name
3961 or die_error
(undef, "Open git-diff-tree failed");
3964 # old/legacy style URI
3965 if (!%diffinfo && # if new style URI failed
3966 defined $hash && defined $hash_parent) {
3967 # fake git-diff-tree raw output
3968 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
3969 $diffinfo{'from_id'} = $hash_parent;
3970 $diffinfo{'to_id'} = $hash;
3971 if (defined $file_name) {
3972 if (defined $file_parent) {
3973 $diffinfo{'status'} = '2';
3974 $diffinfo{'from_file'} = $file_parent;
3975 $diffinfo{'to_file'} = $file_name;
3976 } else { # assume not renamed
3977 $diffinfo{'status'} = '1';
3978 $diffinfo{'from_file'} = $file_name;
3979 $diffinfo{'to_file'} = $file_name;
3981 } else { # no filename given
3982 $diffinfo{'status'} = '2';
3983 $diffinfo{'from_file'} = $hash_parent;
3984 $diffinfo{'to_file'} = $hash;
3987 # non-textual hash id's can be cached
3988 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
3989 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3994 open $fd, "-|", git_cmd
(), "diff", @diff_opts,
3995 '-p', ($format eq 'html' ? "--full-index" : ()),
3996 $hash_parent, $hash, "--"
3997 or die_error
(undef, "Open git-diff failed");
3999 die_error
('404 Not Found', "Missing one of the blob diff parameters")
4004 if ($format eq 'html') {
4006 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
4007 hash
=>$hash, hash_parent
=>$hash_parent,
4008 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
4009 file_name
=>$file_name, file_parent
=>$file_parent)},
4011 git_header_html
(undef, $expires);
4012 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
4013 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
4014 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4016 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
4017 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
4019 if (defined $file_name) {
4020 git_print_page_path
($file_name, "blob", $hash_base);
4022 print "<div class=\"page_path\"></div>\n";
4025 } elsif ($format eq 'plain') {
4027 -type
=> 'text/plain',
4028 -charset
=> 'utf-8',
4029 -expires
=> $expires,
4030 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
4032 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4035 die_error
(undef, "Unknown blobdiff format");
4039 if ($format eq 'html') {
4040 print "<div class=\"page_body\">\n";
4042 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
4045 print "</div>\n"; # class="page_body"
4049 while (my $line = <$fd>) {
4050 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
4051 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
4055 last if $line =~ m!^\+\+\+!;
4063 sub git_blobdiff_plain
{
4064 git_blobdiff
('plain');
4067 sub git_commitdiff
{
4068 my $format = shift || 'html';
4069 $hash ||= $hash_base || "HEAD";
4070 my %co = parse_commit
($hash);
4072 die_error
(undef, "Unknown commit object");
4075 # we need to prepare $formats_nav before any parameter munging
4077 if ($format eq 'html') {
4079 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
4080 hash
=>$hash, hash_parent
=>$hash_parent)},
4083 if (defined $hash_parent) {
4084 # commitdiff with two commits given
4085 my $hash_parent_short = $hash_parent;
4086 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
4087 $hash_parent_short = substr($hash_parent, 0, 7);
4091 $cgi->a({-href
=> href
(action
=>"commitdiff",
4092 hash
=>$hash_parent)},
4093 esc_html
($hash_parent_short)) .
4095 } elsif (!$co{'parent'}) {
4097 $formats_nav .= ' (initial)';
4098 } elsif (scalar @{$co{'parents'}} == 1) {
4099 # single parent commit
4102 $cgi->a({-href
=> href
(action
=>"commitdiff",
4103 hash
=>$co{'parent'})},
4104 esc_html
(substr($co{'parent'}, 0, 7))) .
4111 $cgi->a({-href
=> href
(action
=>"commitdiff",
4113 esc_html
(substr($_, 0, 7)));
4114 } @{$co{'parents'}} ) .
4119 if (!defined $hash_parent) {
4120 $hash_parent = $co{'parent'} || '--root';
4126 if ($format eq 'html') {
4127 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4128 "--no-commit-id", "--patch-with-raw", "--full-index",
4129 $hash_parent, $hash, "--"
4130 or die_error
(undef, "Open git-diff-tree failed");
4132 while (my $line = <$fd>) {
4134 # empty line ends raw part of diff-tree output
4136 push @difftree, $line;
4139 } elsif ($format eq 'plain') {
4140 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4141 '-p', $hash_parent, $hash, "--"
4142 or die_error
(undef, "Open git-diff-tree failed");
4145 die_error
(undef, "Unknown commitdiff format");
4148 # non-textual hash id's can be cached
4150 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4154 # write commit message
4155 if ($format eq 'html') {
4156 my $refs = git_get_references
();
4157 my $ref = format_ref_marker
($refs, $co{'id'});
4159 git_header_html
(undef, $expires);
4160 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
4161 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
4162 git_print_authorship
(\
%co);
4163 print "<div class=\"page_body\">\n";
4164 if (@{$co{'comment'}} > 1) {
4165 print "<div class=\"log\">\n";
4166 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
4167 print "</div>\n"; # class="log"
4170 } elsif ($format eq 'plain') {
4171 my $refs = git_get_references
("tags");
4172 my $tagname = git_get_rev_name_tags
($hash);
4173 my $filename = basename
($project) . "-$hash.patch";
4176 -type
=> 'text/plain',
4177 -charset
=> 'utf-8',
4178 -expires
=> $expires,
4179 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
4180 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4183 Date: $ad{'rfc2822'} ($ad{'tz_local'})
4184 Subject: $co{'title'}
4186 print "X-Git-Tag: $tagname\n" if $tagname;
4187 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4189 foreach my $line (@{$co{'comment'}}) {
4196 if ($format eq 'html') {
4197 git_difftree_body
(\
@difftree, $hash, $hash_parent);
4200 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
4202 print "</div>\n"; # class="page_body"
4205 } elsif ($format eq 'plain') {
4209 or print "Reading git-diff-tree failed\n";
4213 sub git_commitdiff_plain
{
4214 git_commitdiff
('plain');
4218 if (!defined $hash_base) {
4219 $hash_base = git_get_head_hash
($project);
4221 if (!defined $page) {
4225 my %co = parse_commit
($hash_base);
4227 die_error
(undef, "Unknown commit object");
4230 my $refs = git_get_references
();
4231 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
4233 if (!defined $hash && defined $file_name) {
4234 $hash = git_get_hash_by_path
($hash_base, $file_name);
4236 if (defined $hash) {
4237 $ftype = git_get_type
($hash);
4240 my @commitlist = parse_commits
($hash_base, 101, (100 * $page), "--full-history", $file_name);
4242 my $paging_nav = '';
4245 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4246 file_name
=>$file_name)},
4248 $paging_nav .= " ⋅ " .
4249 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4250 file_name
=>$file_name, page
=>$page-1),
4251 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4253 $paging_nav .= "first";
4254 $paging_nav .= " ⋅ prev";
4256 if ($#commitlist >= 100) {
4257 $paging_nav .= " ⋅ " .
4258 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4259 file_name
=>$file_name, page
=>$page+1),
4260 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4262 $paging_nav .= " ⋅ next";
4265 if ($#commitlist >= 100) {
4267 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4268 file_name
=>$file_name, page
=>$page+1),
4269 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4273 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
4274 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4275 git_print_page_path
($file_name, $ftype, $hash_base);
4277 git_history_body
(\
@commitlist, 0, 99,
4278 $refs, $hash_base, $ftype, $next_link);
4284 my ($have_search) = gitweb_check_feature
('search');
4285 if (!$have_search) {
4286 die_error
('403 Permission denied', "Permission denied");
4288 if (!defined $searchtext) {
4289 die_error
(undef, "Text field empty");
4291 if (!defined $hash) {
4292 $hash = git_get_head_hash
($project);
4294 my %co = parse_commit
($hash);
4296 die_error
(undef, "Unknown commit object");
4298 if (!defined $page) {
4302 $searchtype ||= 'commit';
4303 if ($searchtype eq 'pickaxe') {
4304 # pickaxe may take all resources of your box and run for several minutes
4305 # with every query - so decide by yourself how public you make this feature
4306 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4307 if (!$have_pickaxe) {
4308 die_error
('403 Permission denied', "Permission denied");
4314 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
4316 if ($searchtype eq 'commit') {
4317 $greptype = "--grep=";
4318 } elsif ($searchtype eq 'author') {
4319 $greptype = "--author=";
4320 } elsif ($searchtype eq 'committer') {
4321 $greptype = "--committer=";
4323 $greptype .= $searchtext;
4324 my @commitlist = parse_commits
($hash, 101, (100 * $page), $greptype);
4326 my $paging_nav = '';
4329 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4330 searchtext
=>$searchtext, searchtype
=>$searchtype)},
4332 $paging_nav .= " ⋅ " .
4333 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4334 searchtext
=>$searchtext, searchtype
=>$searchtype,
4336 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4338 $paging_nav .= "first";
4339 $paging_nav .= " ⋅ prev";
4341 if ($#commitlist >= 100) {
4342 $paging_nav .= " ⋅ " .
4343 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4344 searchtext
=>$searchtext, searchtype
=>$searchtype,
4346 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4348 $paging_nav .= " ⋅ next";
4351 if ($#commitlist >= 100) {
4353 $cgi->a({-href
=> href
(action
=>"search", hash
=>$hash,
4354 searchtext
=>$searchtext, searchtype
=>$searchtype,
4356 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4359 git_print_page_nav
('','', $hash,$co{'tree'},$hash, $paging_nav);
4360 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4361 git_search_grep_body
(\
@commitlist, 0, 99, $next_link);
4364 if ($searchtype eq 'pickaxe') {
4365 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
4366 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4368 print "<table cellspacing=\"0\">\n";
4371 my $git_command = git_cmd_str
();
4372 open my $fd, "-|", "$git_command rev-list $hash | " .
4373 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
4376 while (my $line = <$fd>) {
4377 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
4380 $set{'from_id'} = $3;
4382 $set{'id'} = $set{'to_id'};
4383 if ($set{'id'} =~ m/0{40}/) {
4384 $set{'id'} = $set{'from_id'};
4386 if ($set{'id'} =~ m/0{40}/) {
4390 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
4393 print "<tr class=\"dark\">\n";
4395 print "<tr class=\"light\">\n";
4398 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4399 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
4401 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4402 -class => "list subject"},
4403 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
4404 while (my $setref = shift @files) {
4406 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
4407 hash
=>$set{'id'}, file_name
=>$set{'file'}),
4409 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
4413 "<td class=\"link\">" .
4414 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4416 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4420 %co = parse_commit
($1);
4430 sub git_search_help
{
4432 git_print_page_nav
('','', $hash,$hash,$hash);
4435 <dt><b>commit</b></dt>
4436 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
4437 <dt><b>author</b></dt>
4438 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
4439 <dt><b>committer</b></dt>
4440 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
4442 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4443 if ($have_pickaxe) {
4445 <dt><b>pickaxe</b></dt>
4446 <dd>All commits that caused the string to appear or disappear from any file (changes that
4447 added, removed or "modified" the string) will be listed. This search can take a while and
4448 takes a lot of strain on the server, so please use it wisely.</dd>
4456 my $head = git_get_head_hash
($project);
4457 if (!defined $hash) {
4460 if (!defined $page) {
4463 my $refs = git_get_references
();
4465 my @commitlist = parse_commits
($hash, 101, (100 * $page));
4467 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, (100 * ($page+1)));
4469 if ($#commitlist >= 100) {
4471 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
4472 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4476 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
4477 git_print_header_div
('summary', $project);
4479 git_shortlog_body
(\
@commitlist, 0, 99, $refs, $next_link);
4484 ## ......................................................................
4485 ## feeds (RSS, Atom; OPML)
4488 my $format = shift || 'atom';
4489 my ($have_blame) = gitweb_check_feature
('blame');
4491 # Atom: http://www.atomenabled.org/developers/syndication/
4492 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
4493 if ($format ne 'rss' && $format ne 'atom') {
4494 die_error
(undef, "Unknown web feed format");
4497 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
4498 my $head = $hash || 'HEAD';
4499 my @commitlist = parse_commits
($head, 150);
4503 my $content_type = "application/$format+xml";
4504 if (defined $cgi->http('HTTP_ACCEPT') &&
4505 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
4506 # browser (feed reader) prefers text/xml
4507 $content_type = 'text/xml';
4509 if (defined($commitlist[0])) {
4510 %latest_commit = %{$commitlist[0]};
4511 %latest_date = parse_date
($latest_commit{'author_epoch'});
4513 -type
=> $content_type,
4514 -charset
=> 'utf-8',
4515 -last_modified
=> $latest_date{'rfc2822'});
4518 -type
=> $content_type,
4519 -charset
=> 'utf-8');
4522 # Optimization: skip generating the body if client asks only
4523 # for Last-Modified date.
4524 return if ($cgi->request_method() eq 'HEAD');
4527 my $title = "$site_name - $project/$action";
4528 my $feed_type = 'log';
4529 if (defined $hash) {
4530 $title .= " - '$hash'";
4531 $feed_type = 'branch log';
4532 if (defined $file_name) {
4533 $title .= " :: $file_name";
4534 $feed_type = 'history';
4536 } elsif (defined $file_name) {
4537 $title .= " - $file_name";
4538 $feed_type = 'history';
4540 $title .= " $feed_type";
4541 my $descr = git_get_project_description
($project);
4542 if (defined $descr) {
4543 $descr = esc_html
($descr);
4545 $descr = "$project " .
4546 ($format eq 'rss' ? 'RSS' : 'Atom') .
4549 my $owner = git_get_project_owner
($project);
4550 $owner = esc_html
($owner);
4554 if (defined $file_name) {
4555 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
4556 } elsif (defined $hash) {
4557 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
4559 $alt_url = href
(-full
=>1, action
=>"summary");
4561 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
4562 if ($format eq 'rss') {
4564 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
4567 print "<title>$title</title>\n" .
4568 "<link>$alt_url</link>\n" .
4569 "<description>$descr</description>\n" .
4570 "<language>en</language>\n";
4571 } elsif ($format eq 'atom') {
4573 <feed xmlns="http://www.w3.org/2005/Atom">
4575 print "<title>$title</title>\n" .
4576 "<subtitle>$descr</subtitle>\n" .
4577 '<link rel="alternate" type="text/html" href="' .
4578 $alt_url . '" />' . "\n" .
4579 '<link rel="self" type="' . $content_type . '" href="' .
4580 $cgi->self_url() . '" />' . "\n" .
4581 "<id>" . href
(-full
=>1) . "</id>\n" .
4582 # use project owner for feed author
4583 "<author><name>$owner</name></author>\n";
4584 if (defined $favicon) {
4585 print "<icon>" . esc_url
($favicon) . "</icon>\n";
4587 if (defined $logo_url) {
4588 # not twice as wide as tall: 72 x 27 pixels
4589 print "<logo>" . esc_url
($logo) . "</logo>\n";
4591 if (! %latest_date) {
4592 # dummy date to keep the feed valid until commits trickle in:
4593 print "<updated>1970-01-01T00:00:00Z</updated>\n";
4595 print "<updated>$latest_date{'iso-8601'}</updated>\n";
4600 for (my $i = 0; $i <= $#commitlist; $i++) {
4601 my %co = %{$commitlist[$i]};
4602 my $commit = $co{'id'};
4603 # we read 150, we always show 30 and the ones more recent than 48 hours
4604 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
4607 my %cd = parse_date
($co{'author_epoch'});
4609 # get list of changed files
4610 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4611 $co{'parent'}, $co{'id'}, "--", (defined $file_name ? $file_name : ())
4613 my @difftree = map { chomp; $_ } <$fd>;
4617 # print element (entry, item)
4618 my $co_url = href
(-full
=>1, action
=>"commit", hash
=>$commit);
4619 if ($format eq 'rss') {
4621 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
4622 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
4623 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
4624 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
4625 "<link>$co_url</link>\n" .
4626 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
4627 "<content:encoded>" .
4629 } elsif ($format eq 'atom') {
4631 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
4632 "<updated>$cd{'iso-8601'}</updated>\n" .
4634 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
4635 if ($co{'author_email'}) {
4636 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
4638 print "</author>\n" .
4639 # use committer for contributor
4641 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
4642 if ($co{'committer_email'}) {
4643 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
4645 print "</contributor>\n" .
4646 "<published>$cd{'iso-8601'}</published>\n" .
4647 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
4648 "<id>$co_url</id>\n" .
4649 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
4650 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
4652 my $comment = $co{'comment'};
4654 foreach my $line (@$comment) {
4655 $line = esc_html
($line);
4658 print "</pre><ul>\n";
4659 foreach my $difftree_line (@difftree) {
4660 my %difftree = parse_difftree_raw_line
($difftree_line);
4661 next if !$difftree{'from_id'};
4663 my $file = $difftree{'file'} || $difftree{'to_file'};
4667 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
4668 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
4669 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
4670 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
4671 -title
=> "diff"}, 'D');
4673 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
4674 file_name
=>$file, hash_base
=>$commit),
4675 -title
=> "blame"}, 'B');
4677 # if this is not a feed of a file history
4678 if (!defined $file_name || $file_name ne $file) {
4679 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
4680 file_name
=>$file, hash
=>$commit),
4681 -title
=> "history"}, 'H');
4683 $file = esc_path
($file);
4687 if ($format eq 'rss') {
4688 print "</ul>]]>\n" .
4689 "</content:encoded>\n" .
4691 } elsif ($format eq 'atom') {
4692 print "</ul>\n</div>\n" .
4699 if ($format eq 'rss') {
4700 print "</channel>\n</rss>\n";
4701 } elsif ($format eq 'atom') {
4715 my @list = git_get_projects_list
();
4717 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
4719 <?xml version="1.0" encoding="utf-8"?>
4720 <opml version="1.0">
4722 <title>$site_name OPML Export</title>
4725 <outline text="git RSS feeds">
4728 foreach my $pr (@list) {
4730 my $head = git_get_head_hash
($proj{'path'});
4731 if (!defined $head) {
4734 $git_dir = "$projectroot/$proj{'path'}";
4735 my %co = parse_commit
($head);
4740 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
4741 my $rss = "$my_url?p=$proj{'path'};a=rss";
4742 my $html = "$my_url?p=$proj{'path'};a=summary";
4743 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";