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 our $version = "++GIT_VERSION++";
23 our $my_url = $cgi->url();
24 our $my_uri = $cgi->url(-absolute
=> 1);
26 # core git executable to use
27 # this can just be "git" if your webserver has a sensible PATH
28 our $GIT = "++GIT_BINDIR++/git";
30 # absolute fs-path which will be prepended to the project path
31 #our $projectroot = "/pub/scm";
32 our $projectroot = "++GITWEB_PROJECTROOT++";
34 # target of the home link on top of all pages
35 our $home_link = $my_uri || "/";
37 # string of the home link on top of all pages
38 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
40 # name of your site or organization to appear in page titles
41 # replace this with something more descriptive for clearer bookmarks
42 our $site_name = "++GITWEB_SITENAME++"
43 || ($ENV{'SERVER_NAME'} || "Untitled") . " Git";
45 # filename of html text to include at top of each page
46 our $site_header = "++GITWEB_SITE_HEADER++";
47 # html text to include at home page
48 our $home_text = "++GITWEB_HOMETEXT++";
49 # filename of html text to include at bottom of each page
50 our $site_footer = "++GITWEB_SITE_FOOTER++";
53 our @stylesheets = ("++GITWEB_CSS++");
54 # URI of a single stylesheet, which can be overridden in GITWEB_CONFIG.
55 our $stylesheet = undef;
57 # URI of GIT logo (72x27 size)
58 our $logo = "++GITWEB_LOGO++";
59 # URI of GIT favicon, assumed to be image/png type
60 our $favicon = "++GITWEB_FAVICON++";
62 # URI and label (title) of GIT logo link
63 #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/";
64 #our $logo_label = "git documentation";
65 our $logo_url = "http://git.or.cz/";
66 our $logo_label = "git homepage";
68 # source of projects list
69 our $projects_list = "++GITWEB_LIST++";
71 # show repository only if this file exists
72 # (only effective if this variable evaluates to true)
73 our $export_ok = "++GITWEB_EXPORT_OK++";
75 # only allow viewing of repositories also shown on the overview page
76 our $strict_export = "++GITWEB_STRICT_EXPORT++";
78 # list of git base URLs used for URL to where fetch project from,
79 # i.e. full URL is "$git_base_url/$project"
80 our @git_base_url_list = grep { $_ ne '' } ("++GITWEB_BASE_URL++");
82 # default blob_plain mimetype and default charset for text/plain blob
83 our $default_blob_plain_mimetype = 'text/plain';
84 our $default_text_plain_charset = undef;
86 # file to use for guessing MIME types before trying /etc/mime.types
87 # (relative to the current git repository)
88 our $mimetypes_file = undef;
90 # You define site-wide feature defaults here; override them with
91 # $GITWEB_CONFIG as necessary.
94 # 'sub' => feature-sub (subroutine),
95 # 'override' => allow-override (boolean),
96 # 'default' => [ default options...] (array reference)}
98 # if feature is overridable (it means that allow-override has true value,
99 # then feature-sub will be called with default options as parameters;
100 # return value of feature-sub indicates if to enable specified feature
102 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
104 # Enable the 'blame' blob view, showing the last commit that modified
105 # each line in the file. This can be very CPU-intensive.
107 # To enable system wide have in $GITWEB_CONFIG
108 # $feature{'blame'}{'default'} = [1];
109 # To have project specific config enable override in $GITWEB_CONFIG
110 # $feature{'blame'}{'override'} = 1;
111 # and in project config gitweb.blame = 0|1;
113 'sub' => \
&feature_blame
,
117 # Enable the 'snapshot' link, providing a compressed tarball of any
118 # tree. This can potentially generate high traffic if you have large
121 # To disable system wide have in $GITWEB_CONFIG
122 # $feature{'snapshot'}{'default'} = [undef];
123 # To have project specific config enable override in $GITWEB_CONFIG
124 # $feature{'snapshot'}{'override'} = 1;
125 # and in project config gitweb.snapshot = none|gzip|bzip2;
127 'sub' => \
&feature_snapshot
,
129 # => [content-encoding, suffix, program]
130 'default' => ['x-gzip', 'gz', 'gzip']},
132 # Enable the pickaxe search, which will list the commits that modified
133 # a given string in a file. This can be practical and quite faster
134 # alternative to 'blame', but still potentially CPU-intensive.
136 # To enable system wide have in $GITWEB_CONFIG
137 # $feature{'pickaxe'}{'default'} = [1];
138 # To have project specific config enable override in $GITWEB_CONFIG
139 # $feature{'pickaxe'}{'override'} = 1;
140 # and in project config gitweb.pickaxe = 0|1;
142 'sub' => \
&feature_pickaxe
,
146 # Make gitweb use an alternative format of the URLs which can be
147 # more readable and natural-looking: project name is embedded
148 # directly in the path and the query string contains other
149 # auxiliary information. All gitweb installations recognize
150 # URL in either format; this configures in which formats gitweb
153 # To enable system wide have in $GITWEB_CONFIG
154 # $feature{'pathinfo'}{'default'} = [1];
155 # Project specific override is not supported.
157 # Note that you will need to change the default location of CSS,
158 # favicon, logo and possibly other files to an absolute URL. Also,
159 # if gitweb.cgi serves as your indexfile, you will need to force
160 # $my_uri to contain the script name in your $GITWEB_CONFIG.
165 # Make gitweb consider projects in project root subdirectories
166 # to be forks of existing projects. Given project $projname.git,
167 # projects matching $projname/*.git will not be shown in the main
168 # projects list, instead a '+' mark will be added to $projname
169 # there and a 'forks' view will be enabled for the project, listing
170 # all the forks. This feature is supported only if project list
171 # is taken from a directory, not file.
173 # To enable system wide have in $GITWEB_CONFIG
174 # $feature{'forks'}{'default'} = [1];
175 # Project specific override is not supported.
181 sub gitweb_check_feature
{
183 return unless exists $feature{$name};
184 my ($sub, $override, @defaults) = (
185 $feature{$name}{'sub'},
186 $feature{$name}{'override'},
187 @{$feature{$name}{'default'}});
188 if (!$override) { return @defaults; }
190 warn "feature $name is not overrideable";
193 return $sub->(@defaults);
197 my ($val) = git_get_project_config
('blame', '--bool');
199 if ($val eq 'true') {
201 } elsif ($val eq 'false') {
208 sub feature_snapshot
{
209 my ($ctype, $suffix, $command) = @_;
211 my ($val) = git_get_project_config
('snapshot');
213 if ($val eq 'gzip') {
214 return ('x-gzip', 'gz', 'gzip');
215 } elsif ($val eq 'bzip2') {
216 return ('x-bzip2', 'bz2', 'bzip2');
217 } elsif ($val eq 'none') {
221 return ($ctype, $suffix, $command);
224 sub gitweb_have_snapshot
{
225 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
226 my $have_snapshot = (defined $ctype && defined $suffix);
228 return $have_snapshot;
231 sub feature_pickaxe
{
232 my ($val) = git_get_project_config
('pickaxe', '--bool');
234 if ($val eq 'true') {
236 } elsif ($val eq 'false') {
243 # checking HEAD file with -e is fragile if the repository was
244 # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed
246 sub check_head_link
{
248 my $headfile = "$dir/HEAD";
249 return ((-e
$headfile) ||
250 (-l
$headfile && readlink($headfile) =~ /^refs\/heads\
//));
253 sub check_export_ok
{
255 return (check_head_link
($dir) &&
256 (!$export_ok || -e
"$dir/$export_ok"));
259 # rename detection options for git-diff and git-diff-tree
260 # - default is '-M', with the cost proportional to
261 # (number of removed files) * (number of new files).
262 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
263 # (number of changed files + number of removed files) * (number of new files)
264 # - even more costly is '-C', '--find-copies-harder' with cost
265 # (number of files in the original tree) * (number of new files)
266 # - one might want to include '-B' option, e.g. '-B', '-M'
267 our @diff_opts = ('-M'); # taken from git_commit
269 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
270 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
272 # version of the core git binary
273 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
275 $projects_list ||= $projectroot;
277 # ======================================================================
278 # input validation and dispatch
279 our $action = $cgi->param('a');
280 if (defined $action) {
281 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
282 die_error
(undef, "Invalid action parameter");
286 # parameters which are pathnames
287 our $project = $cgi->param('p');
288 if (defined $project) {
289 if (!validate_pathname
($project) ||
290 !(-d
"$projectroot/$project") ||
291 !check_head_link
("$projectroot/$project") ||
292 ($export_ok && !(-e
"$projectroot/$project/$export_ok")) ||
293 ($strict_export && !project_in_list
($project))) {
295 die_error
(undef, "No such project");
299 our $file_name = $cgi->param('f');
300 if (defined $file_name) {
301 if (!validate_pathname
($file_name)) {
302 die_error
(undef, "Invalid file parameter");
306 our $file_parent = $cgi->param('fp');
307 if (defined $file_parent) {
308 if (!validate_pathname
($file_parent)) {
309 die_error
(undef, "Invalid file parent parameter");
313 # parameters which are refnames
314 our $hash = $cgi->param('h');
316 if (!validate_refname
($hash)) {
317 die_error
(undef, "Invalid hash parameter");
321 our $hash_parent = $cgi->param('hp');
322 if (defined $hash_parent) {
323 if (!validate_refname
($hash_parent)) {
324 die_error
(undef, "Invalid hash parent parameter");
328 our $hash_base = $cgi->param('hb');
329 if (defined $hash_base) {
330 if (!validate_refname
($hash_base)) {
331 die_error
(undef, "Invalid hash base parameter");
335 our $hash_parent_base = $cgi->param('hpb');
336 if (defined $hash_parent_base) {
337 if (!validate_refname
($hash_parent_base)) {
338 die_error
(undef, "Invalid hash parent base parameter");
343 our $page = $cgi->param('pg');
345 if ($page =~ m/[^0-9]/) {
346 die_error
(undef, "Invalid page parameter");
350 our $searchtext = $cgi->param('s');
351 if (defined $searchtext) {
352 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\
@ ]/) {
353 die_error
(undef, "Invalid search parameter");
355 if (length($searchtext) < 2) {
356 die_error
(undef, "At least two characters are required for search parameter");
358 $searchtext = quotemeta $searchtext;
361 our $searchtype = $cgi->param('st');
362 if (defined $searchtype) {
363 if ($searchtype =~ m/[^a-z]/) {
364 die_error
(undef, "Invalid searchtype parameter");
368 # now read PATH_INFO and use it as alternative to parameters
369 sub evaluate_path_info
{
370 return if defined $project;
371 my $path_info = $ENV{"PATH_INFO"};
372 return if !$path_info;
373 $path_info =~ s
,^/+,,;
374 return if !$path_info;
375 # find which part of PATH_INFO is project
376 $project = $path_info;
378 while ($project && !check_head_link
("$projectroot/$project")) {
379 $project =~ s
,/*[^/]*$,,;
382 $project = validate_pathname
($project);
384 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
385 ($strict_export && !project_in_list
($project))) {
389 # do not change any parameters if an action is given using the query string
391 $path_info =~ s
,^$project/*,,;
392 my ($refname, $pathname) = split(/:/, $path_info, 2);
393 if (defined $pathname) {
394 # we got "project.git/branch:filename" or "project.git/branch:dir/"
395 # we could use git_get_type(branch:pathname), but it needs $git_dir
396 $pathname =~ s
,^/+,,;
397 if (!$pathname || substr($pathname, -1) eq "/") {
401 $action ||= "blob_plain";
403 $hash_base ||= validate_refname
($refname);
404 $file_name ||= validate_pathname
($pathname);
405 } elsif (defined $refname) {
406 # we got "project.git/branch"
407 $action ||= "shortlog";
408 $hash ||= validate_refname
($refname);
411 evaluate_path_info
();
413 # path to the current git repository
415 $git_dir = "$projectroot/$project" if $project;
419 "blame" => \
&git_blame2
,
420 "blobdiff" => \
&git_blobdiff
,
421 "blobdiff_plain" => \
&git_blobdiff_plain
,
422 "blob" => \
&git_blob
,
423 "blob_plain" => \
&git_blob_plain
,
424 "commitdiff" => \
&git_commitdiff
,
425 "commitdiff_plain" => \
&git_commitdiff_plain
,
426 "commit" => \
&git_commit
,
427 "forks" => \
&git_forks
,
428 "heads" => \
&git_heads
,
429 "history" => \
&git_history
,
432 "atom" => \
&git_atom
,
433 "search" => \
&git_search
,
434 "search_help" => \
&git_search_help
,
435 "shortlog" => \
&git_shortlog
,
436 "summary" => \
&git_summary
,
438 "tags" => \
&git_tags
,
439 "tree" => \
&git_tree
,
440 "snapshot" => \
&git_snapshot
,
441 "object" => \
&git_object
,
442 # those below don't need $project
443 "opml" => \
&git_opml
,
444 "project_list" => \
&git_project_list
,
445 "project_index" => \
&git_project_index
,
448 if (defined $project) {
449 $action ||= 'summary';
451 $action ||= 'project_list';
453 if (!defined($actions{$action})) {
454 die_error
(undef, "Unknown action");
456 if ($action !~ m/^(opml|project_list|project_index)$/ &&
458 die_error
(undef, "Project needed");
460 $actions{$action}->();
463 ## ======================================================================
468 # default is to use -absolute url() i.e. $my_uri
469 my $href = $params{-full
} ? $my_url : $my_uri;
471 # XXX: Warning: If you touch this, check the search form for updating,
482 hash_parent_base
=> "hpb",
488 my %mapping = @mapping;
490 $params{'project'} = $project unless exists $params{'project'};
492 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
494 # use PATH_INFO for project name
495 $href .= "/$params{'project'}" if defined $params{'project'};
496 delete $params{'project'};
498 # Summary just uses the project path URL
499 if (defined $params{'action'} && $params{'action'} eq 'summary') {
500 delete $params{'action'};
504 # now encode the parameters explicitly
506 for (my $i = 0; $i < @mapping; $i += 2) {
507 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
508 if (defined $params{$name}) {
509 push @result, $symbol . "=" . esc_param
($params{$name});
512 $href .= "?" . join(';', @result) if scalar @result;
518 ## ======================================================================
519 ## validation, quoting/unquoting and escaping
521 sub validate_pathname
{
522 my $input = shift || return undef;
524 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
525 # at the beginning, at the end, and between slashes.
526 # also this catches doubled slashes
527 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
531 if ($input =~ m!\0!) {
537 sub validate_refname
{
538 my $input = shift || return undef;
540 # textual hashes are O.K.
541 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
544 # it must be correct pathname
545 $input = validate_pathname
($input)
547 # restrictions on ref name according to git-check-ref-format
548 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
554 # very thin wrapper for decode("utf8", $str, Encode::FB_DEFAULT);
557 return decode
("utf8", $str, Encode
::FB_DEFAULT
);
560 # quote unsafe chars, but keep the slash, even when it's not
561 # correct, but quoted slashes look too horrible in bookmarks
564 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
570 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
573 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
579 # replace invalid utf8 character with SUBSTITUTION sequence
584 $str = to_utf8
($str);
585 $str = escapeHTML
($str);
586 if ($opts{'-nbsp'}) {
587 $str =~ s/ / /g;
589 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
593 # quote control characters and escape filename to HTML
598 $str = to_utf8
($str);
599 $str = escapeHTML
($str);
600 if ($opts{'-nbsp'}) {
601 $str =~ s/ / /g;
603 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
607 # Make control characters "printable", using character escape codes (CEC)
610 my %es = ( # character escape codes, aka escape sequences
611 "\t" => '\t', # tab (HT)
612 "\n" => '\n', # line feed (LF)
613 "\r" => '\r', # carrige return (CR)
614 "\f" => '\f', # form feed (FF)
615 "\b" => '\b', # backspace (BS)
616 "\a" => '\a', # alarm (bell) (BEL)
617 "\e" => '\e', # escape (ESC)
618 "\013" => '\v', # vertical tab (VT)
619 "\000" => '\0', # nul character (NUL)
621 my $chr = ( (exists $es{$cntrl})
623 : sprintf('\%03o', ord($cntrl)) );
624 return "<span class=\"cntrl\">$chr</span>";
627 # Alternatively use unicode control pictures codepoints,
628 # Unicode "printable representation" (PR)
631 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
632 return "<span class=\"cntrl\">$chr</span>";
635 # git may return quoted and escaped filenames
641 my %es = ( # character escape codes, aka escape sequences
642 't' => "\t", # tab (HT, TAB)
643 'n' => "\n", # newline (NL)
644 'r' => "\r", # return (CR)
645 'f' => "\f", # form feed (FF)
646 'b' => "\b", # backspace (BS)
647 'a' => "\a", # alarm (bell) (BEL)
648 'e' => "\e", # escape (ESC)
649 'v' => "\013", # vertical tab (VT)
652 if ($seq =~ m/^[0-7]{1,3}$/) {
653 # octal char sequence
654 return chr(oct($seq));
655 } elsif (exists $es{$seq}) {
656 # C escape sequence, aka character escape code
659 # quoted ordinary character
663 if ($str =~ m/^"(.*)"$/) {
666 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
671 # escape tabs (convert tabs to spaces)
675 while ((my $pos = index($line, "\t")) != -1) {
676 if (my $count = (8 - ($pos % 8))) {
677 my $spaces = ' ' x
$count;
678 $line =~ s/\t/$spaces/;
685 sub project_in_list
{
687 my @list = git_get_projects_list
();
688 return @list && scalar(grep { $_->{'path'} eq $project } @list);
691 ## ----------------------------------------------------------------------
692 ## HTML aware string manipulation
697 my $add_len = shift || 10;
699 # allow only $len chars, but don't cut a word if it would fit in $add_len
700 # if it doesn't fit, cut it if it's still longer than the dots we would add
701 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@]{0,$add_len})(.*)/;
704 if (length($tail) > 4) {
706 $body =~ s/&[^;]*$//; # remove chopped character entities
711 ## ----------------------------------------------------------------------
712 ## functions returning short strings
714 # CSS class for given age value (in seconds)
718 if ($age < 60*60*2) {
720 } elsif ($age < 60*60*24*2) {
727 # convert age in seconds to "nn units ago" string
732 if ($age > 60*60*24*365*2) {
733 $age_str = (int $age/60/60/24/365);
734 $age_str .= " years ago";
735 } elsif ($age > 60*60*24*(365/12)*2) {
736 $age_str = int $age/60/60/24/(365/12);
737 $age_str .= " months ago";
738 } elsif ($age > 60*60*24*7*2) {
739 $age_str = int $age/60/60/24/7;
740 $age_str .= " weeks ago";
741 } elsif ($age > 60*60*24*2) {
742 $age_str = int $age/60/60/24;
743 $age_str .= " days ago";
744 } elsif ($age > 60*60*2) {
745 $age_str = int $age/60/60;
746 $age_str .= " hours ago";
747 } elsif ($age > 60*2) {
748 $age_str = int $age/60;
749 $age_str .= " min ago";
752 $age_str .= " sec ago";
754 $age_str .= " right now";
759 # convert file mode in octal to symbolic file mode string
761 my $mode = oct shift;
763 if (S_ISDIR
($mode & S_IFMT
)) {
765 } elsif (S_ISLNK
($mode)) {
767 } elsif (S_ISREG
($mode)) {
768 # git cares only about the executable bit
769 if ($mode & S_IXUSR
) {
779 # convert file mode in octal to file type string
783 if ($mode !~ m/^[0-7]+$/) {
789 if (S_ISDIR
($mode & S_IFMT
)) {
791 } elsif (S_ISLNK
($mode)) {
793 } elsif (S_ISREG
($mode)) {
800 # convert file mode in octal to file type description string
804 if ($mode !~ m/^[0-7]+$/) {
810 if (S_ISDIR
($mode & S_IFMT
)) {
812 } elsif (S_ISLNK
($mode)) {
814 } elsif (S_ISREG
($mode)) {
815 if ($mode & S_IXUSR
) {
826 ## ----------------------------------------------------------------------
827 ## functions returning short HTML fragments, or transforming HTML fragments
828 ## which don't beling to other sections
830 # format line of commit message.
831 sub format_log_line_html
{
834 $line = esc_html
($line, -nbsp
=>1);
835 if ($line =~ m/([0-9a-fA-F]{8,40})/) {
838 $cgi->a({-href
=> href
(action
=>"object", hash
=>$hash_text),
839 -class => "text"}, $hash_text);
840 $line =~ s/$hash_text/$link/;
845 # format marker of refs pointing to given object
846 sub format_ref_marker
{
847 my ($refs, $id) = @_;
850 if (defined $refs->{$id}) {
851 foreach my $ref (@{$refs->{$id}}) {
852 my ($type, $name) = qw();
853 # e.g. tags/v2.6.11 or heads/next
854 if ($ref =~ m!^(.*?)s?/(.*)$!) {
862 $markers .= " <span class=\"$type\" title=\"$ref\">" .
863 esc_html
($name) . "</span>";
868 return ' <span class="refs">'. $markers . '</span>';
874 # format, perhaps shortened and with markers, title line
875 sub format_subject_html
{
876 my ($long, $short, $href, $extra) = @_;
877 $extra = '' unless defined($extra);
879 if (length($short) < length($long)) {
880 return $cgi->a({-href
=> $href, -class => "list subject",
881 -title
=> to_utf8
($long)},
882 esc_html
($short) . $extra);
884 return $cgi->a({-href
=> $href, -class => "list subject"},
885 esc_html
($long) . $extra);
889 # format patch (diff) line (rather not to be used for diff headers)
890 sub format_diff_line
{
892 my ($from, $to) = @_;
893 my $char = substr($line, 0, 1);
899 $diff_class = " add";
900 } elsif ($char eq "-") {
901 $diff_class = " rem";
902 } elsif ($char eq "@") {
903 $diff_class = " chunk_header";
904 } elsif ($char eq "\\") {
905 $diff_class = " incomplete";
907 $line = untabify
($line);
908 if ($from && $to && $line =~ m/^\@{2} /) {
909 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
910 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
912 $from_lines = 0 unless defined $from_lines;
913 $to_lines = 0 unless defined $to_lines;
915 if ($from->{'href'}) {
916 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
917 -class=>"list"}, $from_text);
920 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
921 -class=>"list"}, $to_text);
923 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
924 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
925 return "<div class=\"diff$diff_class\">$line</div>\n";
927 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
930 ## ----------------------------------------------------------------------
931 ## git utility subroutines, invoking git commands
933 # returns path to the core git executable and the --git-dir parameter as list
935 return $GIT, '--git-dir='.$git_dir;
938 # returns path to the core git executable and the --git-dir parameter as string
940 return join(' ', git_cmd
());
943 # get HEAD ref of given project as hash
944 sub git_get_head_hash
{
946 my $o_git_dir = $git_dir;
948 $git_dir = "$projectroot/$project";
949 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
952 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
956 if (defined $o_git_dir) {
957 $git_dir = $o_git_dir;
962 # get type of given object
966 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
973 sub git_get_project_config
{
974 my ($key, $type) = @_;
976 return unless ($key);
977 $key =~ s/^gitweb\.//;
978 return if ($key =~ m/\W/);
980 my @x = (git_cmd
(), 'repo-config');
981 if (defined $type) { push @x, $type; }
983 push @x, "gitweb.$key";
989 # get hash of given path at given ref
990 sub git_get_hash_by_path
{
992 my $path = shift || return undef;
997 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
998 or die_error
(undef, "Open git-ls-tree failed");
1000 close $fd or return undef;
1002 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1003 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1004 if (defined $type && $type ne $2) {
1005 # type doesn't match
1011 ## ......................................................................
1012 ## git utility functions, directly accessing git repository
1014 sub git_get_project_description
{
1017 open my $fd, "$projectroot/$path/description" or return undef;
1024 sub git_get_project_url_list
{
1027 open my $fd, "$projectroot/$path/cloneurl" or return;
1028 my @git_project_url_list = map { chomp; $_ } <$fd>;
1031 return wantarray ? @git_project_url_list : \
@git_project_url_list;
1034 sub git_get_projects_list
{
1039 $filter =~ s/\.git$//;
1041 if (-d
$projects_list) {
1042 # search in directory
1043 my $dir = $projects_list . ($filter ? "/$filter" : '');
1044 # remove the trailing "/"
1046 my $pfxlen = length("$dir");
1048 my ($check_forks) = gitweb_check_feature
('forks');
1051 follow_fast
=> 1, # follow symbolic links
1052 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1054 # skip project-list toplevel, if we get it.
1055 return if (m!^[/.]$!);
1056 # only directories can be git repositories
1057 return unless (-d
$_);
1059 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1060 # we check related file in $projectroot
1061 if ($check_forks and $subdir =~ m
#/.#) {
1062 $File::Find
::prune
= 1;
1063 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1064 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
1065 $File::Find
::prune
= 1;
1070 } elsif (-f
$projects_list) {
1071 # read from file(url-encoded):
1072 # 'git%2Fgit.git Linus+Torvalds'
1073 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1074 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1075 open my ($fd), $projects_list or return;
1076 while (my $line = <$fd>) {
1078 my ($path, $owner) = split ' ', $line;
1079 $path = unescape
($path);
1080 $owner = unescape
($owner);
1081 if (!defined $path) {
1084 if ($filter ne '') {
1085 # looking for forks;
1086 my $pfx = substr($path, 0, length($filter));
1087 if ($pfx ne $filter) {
1090 my $sfx = substr($path, length($filter));
1091 if ($sfx !~ /^\/.*\
.git
$/) {
1095 if (check_export_ok
("$projectroot/$path")) {
1098 owner
=> to_utf8
($owner),
1105 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
1109 sub git_get_project_owner
{
1110 my $project = shift;
1113 return undef unless $project;
1115 # read from file (url-encoded):
1116 # 'git%2Fgit.git Linus+Torvalds'
1117 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1118 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1119 if (-f
$projects_list) {
1120 open (my $fd , $projects_list);
1121 while (my $line = <$fd>) {
1123 my ($pr, $ow) = split ' ', $line;
1124 $pr = unescape
($pr);
1125 $ow = unescape
($ow);
1126 if ($pr eq $project) {
1127 $owner = to_utf8
($ow);
1133 if (!defined $owner) {
1134 $owner = get_file_owner
("$projectroot/$project");
1140 sub git_get_last_activity
{
1144 $git_dir = "$projectroot/$path";
1145 open($fd, "-|", git_cmd
(), 'for-each-ref',
1146 '--format=%(committer)',
1147 '--sort=-committerdate',
1149 'refs/heads') or return;
1150 my $most_recent = <$fd>;
1151 close $fd or return;
1152 if ($most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1154 my $age = time - $timestamp;
1155 return ($age, age_string
($age));
1159 sub git_get_references
{
1160 my $type = shift || "";
1162 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1163 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1164 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1165 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
1168 while (my $line = <$fd>) {
1170 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1171 if (defined $refs{$1}) {
1172 push @{$refs{$1}}, $2;
1178 close $fd or return;
1182 sub git_get_rev_name_tags
{
1183 my $hash = shift || return undef;
1185 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1187 my $name_rev = <$fd>;
1190 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1193 # catches also '$hash undefined' output
1198 ## ----------------------------------------------------------------------
1199 ## parse to hash functions
1203 my $tz = shift || "-0000";
1206 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1207 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1208 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1209 $date{'hour'} = $hour;
1210 $date{'minute'} = $min;
1211 $date{'mday'} = $mday;
1212 $date{'day'} = $days[$wday];
1213 $date{'month'} = $months[$mon];
1214 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1215 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1216 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1217 $mday, $months[$mon], $hour ,$min;
1218 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1219 1900+$year, $mon, $mday, $hour ,$min, $sec;
1221 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1222 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1223 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1224 $date{'hour_local'} = $hour;
1225 $date{'minute_local'} = $min;
1226 $date{'tz_local'} = $tz;
1227 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1228 1900+$year, $mon+1, $mday,
1229 $hour, $min, $sec, $tz);
1238 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1239 $tag{'id'} = $tag_id;
1240 while (my $line = <$fd>) {
1242 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1243 $tag{'object'} = $1;
1244 } elsif ($line =~ m/^type (.+)$/) {
1246 } elsif ($line =~ m/^tag (.+)$/) {
1248 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1249 $tag{'author'} = $1;
1252 } elsif ($line =~ m/--BEGIN/) {
1253 push @comment, $line;
1255 } elsif ($line eq "") {
1259 push @comment, <$fd>;
1260 $tag{'comment'} = \
@comment;
1261 close $fd or return;
1262 if (!defined $tag{'name'}) {
1269 my $commit_id = shift;
1270 my $commit_text = shift;
1275 if (defined $commit_text) {
1276 @commit_lines = @$commit_text;
1279 open my $fd, "-|", git_cmd
(), "rev-list",
1280 "--header", "--parents", "--max-count=1",
1283 @commit_lines = split '\n', <$fd>;
1284 close $fd or return;
1287 my $header = shift @commit_lines;
1288 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
1291 ($co{'id'}, my @parents) = split ' ', $header;
1292 $co{'parents'} = \
@parents;
1293 $co{'parent'} = $parents[0];
1294 while (my $line = shift @commit_lines) {
1295 last if $line eq "\n";
1296 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1298 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1300 $co{'author_epoch'} = $2;
1301 $co{'author_tz'} = $3;
1302 if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) {
1303 $co{'author_name'} = $1;
1304 $co{'author_email'} = $2;
1306 $co{'author_name'} = $co{'author'};
1308 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1309 $co{'committer'} = $1;
1310 $co{'committer_epoch'} = $2;
1311 $co{'committer_tz'} = $3;
1312 $co{'committer_name'} = $co{'committer'};
1313 if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) {
1314 $co{'committer_name'} = $1;
1315 $co{'committer_email'} = $2;
1317 $co{'committer_name'} = $co{'committer'};
1321 if (!defined $co{'tree'}) {
1325 foreach my $title (@commit_lines) {
1328 $co{'title'} = chop_str
($title, 80, 5);
1329 # remove leading stuff of merges to make the interesting part visible
1330 if (length($title) > 50) {
1331 $title =~ s/^Automatic //;
1332 $title =~ s/^merge (of|with) /Merge ... /i;
1333 if (length($title) > 50) {
1334 $title =~ s/(http|rsync):\/\///;
1336 if (length($title) > 50) {
1337 $title =~ s/(master|www|rsync)\.//;
1339 if (length($title) > 50) {
1340 $title =~ s/kernel.org:?//;
1342 if (length($title) > 50) {
1343 $title =~ s/\/pub\/scm//;
1346 $co{'title_short'} = chop_str
($title, 50, 5);
1350 if ($co{'title'} eq "") {
1351 $co{'title'} = $co{'title_short'} = '(no commit message)';
1353 # remove added spaces
1354 foreach my $line (@commit_lines) {
1357 $co{'comment'} = \
@commit_lines;
1359 my $age = time - $co{'committer_epoch'};
1361 $co{'age_string'} = age_string
($age);
1362 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1363 if ($age > 60*60*24*7*2) {
1364 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1365 $co{'age_string_age'} = $co{'age_string'};
1367 $co{'age_string_date'} = $co{'age_string'};
1368 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1373 # parse ref from ref_file, given by ref_id, with given type
1375 my $ref_file = shift;
1377 my $type = shift || git_get_type
($ref_id);
1380 $ref_item{'type'} = $type;
1381 $ref_item{'id'} = $ref_id;
1382 $ref_item{'epoch'} = 0;
1383 $ref_item{'age'} = "unknown";
1384 if ($type eq "tag") {
1385 my %tag = parse_tag
($ref_id);
1386 $ref_item{'comment'} = $tag{'comment'};
1387 if ($tag{'type'} eq "commit") {
1388 my %co = parse_commit
($tag{'object'});
1389 $ref_item{'epoch'} = $co{'committer_epoch'};
1390 $ref_item{'age'} = $co{'age_string'};
1391 } elsif (defined($tag{'epoch'})) {
1392 my $age = time - $tag{'epoch'};
1393 $ref_item{'epoch'} = $tag{'epoch'};
1394 $ref_item{'age'} = age_string
($age);
1396 $ref_item{'reftype'} = $tag{'type'};
1397 $ref_item{'name'} = $tag{'name'};
1398 $ref_item{'refid'} = $tag{'object'};
1399 } elsif ($type eq "commit"){
1400 my %co = parse_commit
($ref_id);
1401 $ref_item{'reftype'} = "commit";
1402 $ref_item{'name'} = $ref_file;
1403 $ref_item{'title'} = $co{'title'};
1404 $ref_item{'refid'} = $ref_id;
1405 $ref_item{'epoch'} = $co{'committer_epoch'};
1406 $ref_item{'age'} = $co{'age_string'};
1408 $ref_item{'reftype'} = $type;
1409 $ref_item{'name'} = $ref_file;
1410 $ref_item{'refid'} = $ref_id;
1416 # parse line of git-diff-tree "raw" output
1417 sub parse_difftree_raw_line
{
1421 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1422 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1423 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1424 $res{'from_mode'} = $1;
1425 $res{'to_mode'} = $2;
1426 $res{'from_id'} = $3;
1428 $res{'status'} = $5;
1429 $res{'similarity'} = $6;
1430 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1431 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1433 $res{'file'} = unquote
($7);
1436 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1437 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1438 $res{'commit'} = $1;
1441 return wantarray ? %res : \
%res;
1444 # parse line of git-ls-tree output
1445 sub parse_ls_tree_line
($;%) {
1450 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1451 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
1459 $res{'name'} = unquote
($4);
1462 return wantarray ? %res : \
%res;
1465 ## ......................................................................
1466 ## parse to array of hashes functions
1468 sub git_get_heads_list
{
1472 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1473 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
1474 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
1477 while (my $line = <$fd>) {
1481 my ($refinfo, $committerinfo) = split(/\0/, $line);
1482 my ($hash, $name, $title) = split(' ', $refinfo, 3);
1483 my ($committer, $epoch, $tz) =
1484 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
1485 $name =~ s!^refs/heads/!!;
1487 $ref_item{'name'} = $name;
1488 $ref_item{'id'} = $hash;
1489 $ref_item{'title'} = $title || '(no commit message)';
1490 $ref_item{'epoch'} = $epoch;
1492 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1494 $ref_item{'age'} = "unknown";
1497 push @headslist, \
%ref_item;
1501 return wantarray ? @headslist : \
@headslist;
1504 sub git_get_tags_list
{
1508 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1509 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
1510 '--format=%(objectname) %(objecttype) %(refname) '.
1511 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
1514 while (my $line = <$fd>) {
1518 my ($refinfo, $creatorinfo) = split(/\0/, $line);
1519 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
1520 my ($creator, $epoch, $tz) =
1521 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
1522 $name =~ s!^refs/tags/!!;
1524 $ref_item{'type'} = $type;
1525 $ref_item{'id'} = $id;
1526 $ref_item{'name'} = $name;
1527 if ($type eq "tag") {
1528 $ref_item{'subject'} = $title;
1529 $ref_item{'reftype'} = $reftype;
1530 $ref_item{'refid'} = $refid;
1532 $ref_item{'reftype'} = $type;
1533 $ref_item{'refid'} = $id;
1536 if ($type eq "tag" || $type eq "commit") {
1537 $ref_item{'epoch'} = $epoch;
1539 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1541 $ref_item{'age'} = "unknown";
1545 push @tagslist, \
%ref_item;
1549 return wantarray ? @tagslist : \
@tagslist;
1552 ## ----------------------------------------------------------------------
1553 ## filesystem-related functions
1555 sub get_file_owner
{
1558 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1559 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1560 if (!defined $gcos) {
1564 $owner =~ s/[,;].*$//;
1565 return to_utf8
($owner);
1568 ## ......................................................................
1569 ## mimetype related functions
1571 sub mimetype_guess_file
{
1572 my $filename = shift;
1573 my $mimemap = shift;
1574 -r
$mimemap or return undef;
1577 open(MIME
, $mimemap) or return undef;
1579 next if m/^#/; # skip comments
1580 my ($mime, $exts) = split(/\t+/);
1581 if (defined $exts) {
1582 my @exts = split(/\s+/, $exts);
1583 foreach my $ext (@exts) {
1584 $mimemap{$ext} = $mime;
1590 $filename =~ /\.([^.]*)$/;
1591 return $mimemap{$1};
1594 sub mimetype_guess
{
1595 my $filename = shift;
1597 $filename =~ /\./ or return undef;
1599 if ($mimetypes_file) {
1600 my $file = $mimetypes_file;
1601 if ($file !~ m!^/!) { # if it is relative path
1602 # it is relative to project
1603 $file = "$projectroot/$project/$file";
1605 $mime = mimetype_guess_file
($filename, $file);
1607 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1613 my $filename = shift;
1616 my $mime = mimetype_guess
($filename);
1617 $mime and return $mime;
1621 return $default_blob_plain_mimetype unless $fd;
1624 return 'text/plain' .
1625 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1626 } elsif (! $filename) {
1627 return 'application/octet-stream';
1628 } elsif ($filename =~ m/\.png$/i) {
1630 } elsif ($filename =~ m/\.gif$/i) {
1632 } elsif ($filename =~ m/\.jpe?g$/i) {
1633 return 'image/jpeg';
1635 return 'application/octet-stream';
1639 ## ======================================================================
1640 ## functions printing HTML: header, footer, error page
1642 sub git_header_html
{
1643 my $status = shift || "200 OK";
1644 my $expires = shift;
1646 my $title = "$site_name";
1647 if (defined $project) {
1648 $title .= " - $project";
1649 if (defined $action) {
1650 $title .= "/$action";
1651 if (defined $file_name) {
1652 $title .= " - " . esc_path
($file_name);
1653 if ($action eq "tree" && $file_name !~ m
|/$|) {
1660 # require explicit support from the UA if we are to send the page as
1661 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1662 # we have to do this because MSIE sometimes globs '*/*', pretending to
1663 # support xhtml+xml but choking when it gets what it asked for.
1664 if (defined $cgi->http('HTTP_ACCEPT') &&
1665 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1666 $cgi->Accept('application/xhtml+xml') != 0) {
1667 $content_type = 'application/xhtml+xml';
1669 $content_type = 'text/html';
1671 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1672 -status
=> $status, -expires
=> $expires);
1674 <?xml version="1.0" encoding="utf-8"?>
1675 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1676 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1677 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1678 <!-- git core binaries version $git_version -->
1680 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1681 <meta name="generator" content="gitweb/$version git/$git_version"/>
1682 <meta name="robots" content="index, nofollow"/>
1683 <title>$title</title>
1685 # print out each stylesheet that exist
1686 if (defined $stylesheet) {
1687 #provides backwards capability for those people who define style sheet in a config file
1688 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1690 foreach my $stylesheet (@stylesheets) {
1691 next unless $stylesheet;
1692 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1695 if (defined $project) {
1696 printf('<link rel="alternate" title="%s log RSS feed" '.
1697 'href="%s" type="application/rss+xml" />'."\n",
1698 esc_param
($project), href
(action
=>"rss"));
1699 printf('<link rel="alternate" title="%s log Atom feed" '.
1700 'href="%s" type="application/atom+xml" />'."\n",
1701 esc_param
($project), href
(action
=>"atom"));
1703 printf('<link rel="alternate" title="%s projects list" '.
1704 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1705 $site_name, href
(project
=>undef, action
=>"project_index"));
1706 printf('<link rel="alternate" title="%s projects feeds" '.
1707 'href="%s" type="text/x-opml"/>'."\n",
1708 $site_name, href
(project
=>undef, action
=>"opml"));
1710 if (defined $favicon) {
1711 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
1717 if (-f
$site_header) {
1718 open (my $fd, $site_header);
1723 print "<div class=\"page_header\">\n" .
1724 $cgi->a({-href
=> esc_url
($logo_url),
1725 -title
=> $logo_label},
1726 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
1727 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1728 if (defined $project) {
1729 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1730 if (defined $action) {
1734 if (!defined $searchtext) {
1738 if (defined $hash_base) {
1739 $search_hash = $hash_base;
1740 } elsif (defined $hash) {
1741 $search_hash = $hash;
1743 $search_hash = "HEAD";
1745 $cgi->param("a", "search");
1746 $cgi->param("h", $search_hash);
1747 $cgi->param("p", $project);
1748 print $cgi->startform(-method => "get", -action
=> $my_uri) .
1749 "<div class=\"search\">\n" .
1750 $cgi->hidden(-name
=> "p") . "\n" .
1751 $cgi->hidden(-name
=> "a") . "\n" .
1752 $cgi->hidden(-name
=> "h") . "\n" .
1753 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
1754 -values => ['commit', 'author', 'committer', 'pickaxe']) .
1755 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
1757 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1759 $cgi->end_form() . "\n";
1764 sub git_footer_html
{
1765 print "<div class=\"page_footer\">\n";
1766 if (defined $project) {
1767 my $descr = git_get_project_description
($project);
1768 if (defined $descr) {
1769 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1771 print $cgi->a({-href
=> href
(action
=>"rss"),
1772 -class => "rss_logo"}, "RSS") . " ";
1773 print $cgi->a({-href
=> href
(action
=>"atom"),
1774 -class => "rss_logo"}, "Atom") . "\n";
1776 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1777 -class => "rss_logo"}, "OPML") . " ";
1778 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1779 -class => "rss_logo"}, "TXT") . "\n";
1783 if (-f
$site_footer) {
1784 open (my $fd, $site_footer);
1794 my $status = shift || "403 Forbidden";
1795 my $error = shift || "Malformed query, file missing or permission denied";
1797 git_header_html
($status);
1799 <div class="page_body">
1809 ## ----------------------------------------------------------------------
1810 ## functions printing or outputting HTML: navigation
1812 sub git_print_page_nav
{
1813 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1814 $extra = '' if !defined $extra; # pager or formats
1816 my @navs = qw(summary shortlog log commit commitdiff tree);
1818 @navs = grep { $_ ne $suppress } @navs;
1821 my %arg = map { $_ => {action
=>$_} } @navs;
1822 if (defined $head) {
1823 for (qw(commit commitdiff)) {
1824 $arg{$_}{hash
} = $head;
1826 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1827 for (qw(shortlog log)) {
1828 $arg{$_}{hash
} = $head;
1832 $arg{tree
}{hash
} = $treehead if defined $treehead;
1833 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1835 print "<div class=\"page_nav\">\n" .
1837 map { $_ eq $current ?
1838 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1840 print "<br/>\n$extra<br/>\n" .
1844 sub format_paging_nav
{
1845 my ($action, $hash, $head, $page, $nrevs) = @_;
1849 if ($hash ne $head || $page) {
1850 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1852 $paging_nav .= "HEAD";
1856 $paging_nav .= " ⋅ " .
1857 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1858 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1860 $paging_nav .= " ⋅ prev";
1863 if ($nrevs >= (100 * ($page+1)-1)) {
1864 $paging_nav .= " ⋅ " .
1865 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1866 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1868 $paging_nav .= " ⋅ next";
1874 ## ......................................................................
1875 ## functions printing or outputting HTML: div
1877 sub git_print_header_div
{
1878 my ($action, $title, $hash, $hash_base) = @_;
1881 $args{action
} = $action;
1882 $args{hash
} = $hash if $hash;
1883 $args{hash_base
} = $hash_base if $hash_base;
1885 print "<div class=\"header\">\n" .
1886 $cgi->a({-href
=> href
(%args), -class => "title"},
1887 $title ? $title : $action) .
1891 #sub git_print_authorship (\%) {
1892 sub git_print_authorship
{
1895 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
1896 print "<div class=\"author_date\">" .
1897 esc_html
($co->{'author_name'}) .
1899 if ($ad{'hour_local'} < 6) {
1900 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1901 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1903 printf(" (%02d:%02d %s)",
1904 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1909 sub git_print_page_path
{
1915 print "<div class=\"page_path\">";
1916 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
1917 -title
=> 'tree root'}, "[$project]");
1919 if (defined $name) {
1920 my @dirname = split '/', $name;
1921 my $basename = pop @dirname;
1924 foreach my $dir (@dirname) {
1925 $fullname .= ($fullname ? '/' : '') . $dir;
1926 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
1928 -title
=> esc_html
($fullname)}, esc_path
($dir));
1931 if (defined $type && $type eq 'blob') {
1932 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1934 -title
=> esc_html
($name)}, esc_path
($basename));
1935 } elsif (defined $type && $type eq 'tree') {
1936 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
1938 -title
=> esc_html
($name)}, esc_path
($basename));
1941 print esc_path
($basename);
1944 print "<br/></div>\n";
1947 # sub git_print_log (\@;%) {
1948 sub git_print_log
($;%) {
1952 if ($opts{'-remove_title'}) {
1953 # remove title, i.e. first line of log
1956 # remove leading empty lines
1957 while (defined $log->[0] && $log->[0] eq "") {
1964 foreach my $line (@$log) {
1965 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1968 if (! $opts{'-remove_signoff'}) {
1969 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1972 # remove signoff lines
1979 # print only one empty line
1980 # do not print empty line after signoff
1982 next if ($empty || $signoff);
1988 print format_log_line_html
($line) . "<br/>\n";
1991 if ($opts{'-final_empty_line'}) {
1992 # end with single empty line
1993 print "<br/>\n" unless $empty;
1997 # return link target (what link points to)
1998 sub git_get_link_target
{
2003 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2007 $link_target = <$fd>;
2012 return $link_target;
2015 # given link target, and the directory (basedir) the link is in,
2016 # return target of link relative to top directory (top tree);
2017 # return undef if it is not possible (including absolute links).
2018 sub normalize_link_target
{
2019 my ($link_target, $basedir, $hash_base) = @_;
2021 # we can normalize symlink target only if $hash_base is provided
2022 return unless $hash_base;
2024 # absolute symlinks (beginning with '/') cannot be normalized
2025 return if (substr($link_target, 0, 1) eq '/');
2027 # normalize link target to path from top (root) tree (dir)
2030 $path = $basedir . '/' . $link_target;
2032 # we are in top (root) tree (dir)
2033 $path = $link_target;
2036 # remove //, /./, and /../
2038 foreach my $part (split('/', $path)) {
2039 # discard '.' and ''
2040 next if (!$part || $part eq '.');
2042 if ($part eq '..') {
2046 # link leads outside repository (outside top dir)
2050 push @path_parts, $part;
2053 $path = join('/', @path_parts);
2058 # print tree entry (row of git_tree), but without encompassing <tr> element
2059 sub git_print_tree_entry
{
2060 my ($t, $basedir, $hash_base, $have_blame) = @_;
2063 $base_key{'hash_base'} = $hash_base if defined $hash_base;
2065 # The format of a table row is: mode list link. Where mode is
2066 # the mode of the entry, list is the name of the entry, an href,
2067 # and link is the action links of the entry.
2069 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
2070 if ($t->{'type'} eq "blob") {
2071 print "<td class=\"list\">" .
2072 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2073 file_name
=>"$basedir$t->{'name'}", %base_key),
2074 -class => "list"}, esc_path
($t->{'name'}));
2075 if (S_ISLNK
(oct $t->{'mode'})) {
2076 my $link_target = git_get_link_target
($t->{'hash'});
2078 my $norm_target = normalize_link_target
($link_target, $basedir, $hash_base);
2079 if (defined $norm_target) {
2081 $cgi->a({-href
=> href
(action
=>"object", hash_base
=>$hash_base,
2082 file_name
=>$norm_target),
2083 -title
=> $norm_target}, esc_path
($link_target));
2085 print " -> " . esc_path
($link_target);
2090 print "<td class=\"link\">";
2091 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2092 file_name
=>"$basedir$t->{'name'}", %base_key)},
2096 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2097 file_name
=>"$basedir$t->{'name'}", %base_key)},
2100 if (defined $hash_base) {
2102 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2103 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2107 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2108 file_name
=>"$basedir$t->{'name'}")},
2112 } elsif ($t->{'type'} eq "tree") {
2113 print "<td class=\"list\">";
2114 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2115 file_name
=>"$basedir$t->{'name'}", %base_key)},
2116 esc_path
($t->{'name'}));
2118 print "<td class=\"link\">";
2119 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2120 file_name
=>"$basedir$t->{'name'}", %base_key)},
2122 if (defined $hash_base) {
2124 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2125 file_name
=>"$basedir$t->{'name'}")},
2132 ## ......................................................................
2133 ## functions printing large fragments of HTML
2135 sub git_difftree_body
{
2136 my ($difftree, $hash, $parent) = @_;
2137 my ($have_blame) = gitweb_check_feature
('blame');
2138 print "<div class=\"list_head\">\n";
2139 if ($#{$difftree} > 10) {
2140 print(($#{$difftree} + 1) . " files changed:\n");
2144 print "<table class=\"diff_tree\">\n";
2147 foreach my $line (@{$difftree}) {
2148 my %diff = parse_difftree_raw_line
($line);
2151 print "<tr class=\"dark\">\n";
2153 print "<tr class=\"light\">\n";
2157 my ($to_mode_oct, $to_mode_str, $to_file_type);
2158 my ($from_mode_oct, $from_mode_str, $from_file_type);
2159 if ($diff{'to_mode'} ne ('0' x
6)) {
2160 $to_mode_oct = oct $diff{'to_mode'};
2161 if (S_ISREG
($to_mode_oct)) { # only for regular file
2162 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
2164 $to_file_type = file_type
($diff{'to_mode'});
2166 if ($diff{'from_mode'} ne ('0' x
6)) {
2167 $from_mode_oct = oct $diff{'from_mode'};
2168 if (S_ISREG
($to_mode_oct)) { # only for regular file
2169 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
2171 $from_file_type = file_type
($diff{'from_mode'});
2174 if ($diff{'status'} eq "A") { # created
2175 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
2176 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
2177 $mode_chng .= "]</span>";
2179 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2180 hash_base
=>$hash, file_name
=>$diff{'file'}),
2181 -class => "list"}, esc_path
($diff{'file'}));
2183 print "<td>$mode_chng</td>\n";
2184 print "<td class=\"link\">";
2185 if ($action eq 'commitdiff') {
2188 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2191 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2192 hash_base
=>$hash, file_name
=>$diff{'file'})},
2196 } elsif ($diff{'status'} eq "D") { # deleted
2197 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
2199 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
2200 hash_base
=>$parent, file_name
=>$diff{'file'}),
2201 -class => "list"}, esc_path
($diff{'file'}));
2203 print "<td>$mode_chng</td>\n";
2204 print "<td class=\"link\">";
2205 if ($action eq 'commitdiff') {
2208 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2211 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
2212 hash_base
=>$parent, file_name
=>$diff{'file'})},
2215 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2216 file_name
=>$diff{'file'})},
2219 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2220 file_name
=>$diff{'file'})},
2224 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
2225 my $mode_chnge = "";
2226 if ($diff{'from_mode'} != $diff{'to_mode'}) {
2227 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
2228 if ($from_file_type != $to_file_type) {
2229 $mode_chnge .= " from $from_file_type to $to_file_type";
2231 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
2232 if ($from_mode_str && $to_mode_str) {
2233 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
2234 } elsif ($to_mode_str) {
2235 $mode_chnge .= " mode: $to_mode_str";
2238 $mode_chnge .= "]</span>\n";
2241 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2242 hash_base
=>$hash, file_name
=>$diff{'file'}),
2243 -class => "list"}, esc_path
($diff{'file'}));
2245 print "<td>$mode_chnge</td>\n";
2246 print "<td class=\"link\">";
2247 if ($action eq 'commitdiff') {
2250 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2252 } elsif ($diff{'to_id'} ne $diff{'from_id'}) {
2253 # "commit" view and modified file (not onlu mode changed)
2254 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2255 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
2256 hash_base
=>$hash, hash_parent_base
=>$parent,
2257 file_name
=>$diff{'file'})},
2261 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2262 hash_base
=>$hash, file_name
=>$diff{'file'})},
2265 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2266 file_name
=>$diff{'file'})},
2269 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2270 file_name
=>$diff{'file'})},
2274 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
2275 my %status_name = ('R' => 'moved', 'C' => 'copied');
2276 my $nstatus = $status_name{$diff{'status'}};
2278 if ($diff{'from_mode'} != $diff{'to_mode'}) {
2279 # mode also for directories, so we cannot use $to_mode_str
2280 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
2283 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2284 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
2285 -class => "list"}, esc_path
($diff{'to_file'})) . "</td>\n" .
2286 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
2287 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
2288 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
2289 -class => "list"}, esc_path
($diff{'from_file'})) .
2290 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
2291 "<td class=\"link\">";
2292 if ($action eq 'commitdiff') {
2295 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2297 } elsif ($diff{'to_id'} ne $diff{'from_id'}) {
2298 # "commit" view and modified file (not only pure rename or copy)
2299 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2300 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
2301 hash_base
=>$hash, hash_parent_base
=>$parent,
2302 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
2306 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2307 hash_base
=>$parent, file_name
=>$diff{'to_file'})},
2310 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2311 file_name
=>$diff{'to_file'})},
2314 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2315 file_name
=>$diff{'to_file'})},
2319 } # we should not encounter Unmerged (U) or Unknown (X) status
2325 sub git_patchset_body
{
2326 my ($fd, $difftree, $hash, $hash_parent) = @_;
2332 my ($from_id, $to_id);
2334 print "<div class=\"patchset\">\n";
2336 # skip to first patch
2337 while ($patch_line = <$fd>) {
2340 last if ($patch_line =~ m/^diff /);
2344 while ($patch_line) {
2348 #assert($patch_line =~ m/^diff /) if DEBUG;
2349 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
2350 push @diff_header, $patch_line;
2352 # extended diff header
2354 while ($patch_line = <$fd>) {
2357 last EXTENDED_HEADER
if ($patch_line =~ m/^--- /);
2359 if ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2364 push @diff_header, $patch_line;
2366 #last PATCH unless $patch_line;
2367 my $last_patch_line = $patch_line;
2369 # check if current patch belong to current raw line
2370 # and parse raw git-diff line if needed
2371 if (defined $diffinfo &&
2372 $diffinfo->{'from_id'} eq $from_id &&
2373 $diffinfo->{'to_id'} eq $to_id) {
2374 # this is split patch
2375 print "<div class=\"patch cont\">\n";
2377 # advance raw git-diff output if needed
2378 $patch_idx++ if defined $diffinfo;
2380 # read and prepare patch information
2381 if (ref($difftree->[$patch_idx]) eq "HASH") {
2382 # pre-parsed (or generated by hand)
2383 $diffinfo = $difftree->[$patch_idx];
2385 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
2387 $from{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
2388 $to{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
2389 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2390 $from{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2391 hash
=>$diffinfo->{'from_id'},
2392 file_name
=>$from{'file'});
2394 if ($diffinfo->{'status'} ne "D") { # not deleted file
2395 $to{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2396 hash
=>$diffinfo->{'to_id'},
2397 file_name
=>$to{'file'});
2399 # this is first patch for raw difftree line with $patch_idx index
2400 # we index @$difftree array from 0, but number patches from 1
2401 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
2404 # print "git diff" header
2405 $patch_line = shift @diff_header;
2406 $patch_line =~ s!^(diff (.*?) )"?a/.*$!$1!;
2407 if ($from{'href'}) {
2408 $patch_line .= $cgi->a({-href
=> $from{'href'}, -class => "path"},
2409 'a/' . esc_path
($from{'file'}));
2410 } else { # file was added
2411 $patch_line .= 'a/' . esc_path
($from{'file'});
2415 $patch_line .= $cgi->a({-href
=> $to{'href'}, -class => "path"},
2416 'b/' . esc_path
($to{'file'}));
2417 } else { # file was deleted
2418 $patch_line .= 'b/' . esc_path
($to{'file'});
2420 print "<div class=\"diff header\">$patch_line</div>\n";
2422 # print extended diff header
2423 print "<div class=\"diff extended_header\">\n" if (@diff_header > 0);
2425 foreach $patch_line (@diff_header) {
2427 if ($patch_line =~ s!^((copy|rename) from ).*$!$1! && $from{'href'}) {
2428 $patch_line .= $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2429 esc_path
($from{'file'}));
2431 if ($patch_line =~ s!^((copy|rename) to ).*$!$1! && $to{'href'}) {
2432 $patch_line = $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2433 esc_path
($to{'file'}));
2436 if ($patch_line =~ m/\s(\d{6})$/) {
2437 $patch_line .= '<span class="info"> (' .
2438 file_type_long
($1) .
2442 if ($patch_line =~ m/^index/) {
2443 my ($from_link, $to_link);
2444 if ($from{'href'}) {
2445 $from_link = $cgi->a({-href
=>$from{'href'}, -class=>"hash"},
2446 substr($diffinfo->{'from_id'},0,7));
2448 $from_link = '0' x
7;
2451 $to_link = $cgi->a({-href
=>$to{'href'}, -class=>"hash"},
2452 substr($diffinfo->{'to_id'},0,7));
2457 # my ($from_hash, $to_hash) =
2458 # ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/);
2459 # my ($from_id, $to_id) =
2460 # ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2461 # ($from_hash eq $from_id) && ($to_hash eq $to_id);
2463 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2464 $patch_line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
2466 print $patch_line . "<br/>\n";
2468 print "</div>\n" if (@diff_header > 0); # class="diff extended_header"
2470 # from-file/to-file diff header
2471 $patch_line = $last_patch_line;
2472 #assert($patch_line =~ m/^---/) if DEBUG;
2473 if ($from{'href'}) {
2474 $patch_line = '--- a/' .
2475 $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2476 esc_path
($from{'file'}));
2478 print "<div class=\"diff from_file\">$patch_line</div>\n";
2480 $patch_line = <$fd>;
2481 #last PATCH unless $patch_line;
2484 #assert($patch_line =~ m/^+++/) if DEBUG;
2486 $patch_line = '+++ b/' .
2487 $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2488 esc_path
($to{'file'}));
2490 print "<div class=\"diff to_file\">$patch_line</div>\n";
2494 while ($patch_line = <$fd>) {
2497 next PATCH
if ($patch_line =~ m/^diff /);
2499 print format_diff_line
($patch_line, \
%from, \
%to);
2503 print "</div>\n"; # class="patch"
2506 print "</div>\n"; # class="patchset"
2509 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2511 sub git_project_list_body
{
2512 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
2514 my ($check_forks) = gitweb_check_feature
('forks');
2517 foreach my $pr (@$projlist) {
2518 my (@aa) = git_get_last_activity
($pr->{'path'});
2522 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
2523 if (!defined $pr->{'descr'}) {
2524 my $descr = git_get_project_description
($pr->{'path'}) || "";
2525 $pr->{'descr_long'} = to_utf8
($descr);
2526 $pr->{'descr'} = chop_str
($descr, 25, 5);
2528 if (!defined $pr->{'owner'}) {
2529 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2532 my $pname = $pr->{'path'};
2533 if (($pname =~ s/\.git$//) &&
2534 ($pname !~ /\/$/) &&
2535 (-d
"$projectroot/$pname")) {
2536 $pr->{'forks'} = "-d $projectroot/$pname";
2542 push @projects, $pr;
2545 $order ||= "project";
2546 $from = 0 unless defined $from;
2547 $to = $#projects if (!defined $to || $#projects < $to);
2549 print "<table class=\"project_list\">\n";
2550 unless ($no_header) {
2553 print "<th></th>\n";
2555 if ($order eq "project") {
2556 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2557 print "<th>Project</th>\n";
2560 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2561 -class => "header"}, "Project") .
2564 if ($order eq "descr") {
2565 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2566 print "<th>Description</th>\n";
2569 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2570 -class => "header"}, "Description") .
2573 if ($order eq "owner") {
2574 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2575 print "<th>Owner</th>\n";
2578 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2579 -class => "header"}, "Owner") .
2582 if ($order eq "age") {
2583 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
2584 print "<th>Last Change</th>\n";
2587 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
2588 -class => "header"}, "Last Change") .
2591 print "<th></th>\n" .
2595 for (my $i = $from; $i <= $to; $i++) {
2596 my $pr = $projects[$i];
2598 print "<tr class=\"dark\">\n";
2600 print "<tr class=\"light\">\n";
2605 if ($pr->{'forks'}) {
2606 print "<!-- $pr->{'forks'} -->\n";
2607 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
2611 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2612 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2613 "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2614 -class => "list", -title
=> $pr->{'descr_long'}},
2615 esc_html
($pr->{'descr'})) . "</td>\n" .
2616 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2617 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
2618 $pr->{'age_string'} . "</td>\n" .
2619 "<td class=\"link\">" .
2620 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2621 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2622 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
2623 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
2624 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
2628 if (defined $extra) {
2631 print "<td></td>\n";
2633 print "<td colspan=\"5\">$extra</td>\n" .
2639 sub git_shortlog_body
{
2640 # uses global variable $project
2641 my ($revlist, $from, $to, $refs, $extra) = @_;
2643 my $have_snapshot = gitweb_have_snapshot
();
2645 $from = 0 unless defined $from;
2646 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
2648 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
2650 for (my $i = $from; $i <= $to; $i++) {
2651 my $commit = $revlist->[$i];
2652 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
2653 my $ref = format_ref_marker
($refs, $commit);
2654 my %co = parse_commit
($commit);
2656 print "<tr class=\"dark\">\n";
2658 print "<tr class=\"light\">\n";
2661 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
2662 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2663 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
2665 print format_subject_html
($co{'title'}, $co{'title_short'},
2666 href
(action
=>"commit", hash
=>$commit), $ref);
2668 "<td class=\"link\">" .
2669 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
2670 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
2671 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
2672 if ($have_snapshot) {
2673 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
2678 if (defined $extra) {
2680 "<td colspan=\"4\">$extra</td>\n" .
2686 sub git_history_body
{
2687 # Warning: assumes constant type (blob or tree) during history
2688 my ($revlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
2690 $from = 0 unless defined $from;
2691 $to = $#{$revlist} unless (defined $to && $to <= $#{$revlist});
2693 print "<table class=\"history\" cellspacing=\"0\">\n";
2695 for (my $i = $from; $i <= $to; $i++) {
2696 if ($revlist->[$i] !~ m/^([0-9a-fA-F]{40})/) {
2701 my %co = parse_commit
($commit);
2706 my $ref = format_ref_marker
($refs, $commit);
2709 print "<tr class=\"dark\">\n";
2711 print "<tr class=\"light\">\n";
2714 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2715 # shortlog uses chop_str($co{'author_name'}, 10)
2716 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2718 # originally git_history used chop_str($co{'title'}, 50)
2719 print format_subject_html
($co{'title'}, $co{'title_short'},
2720 href
(action
=>"commit", hash
=>$commit), $ref);
2722 "<td class=\"link\">" .
2723 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
2724 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
2726 if ($ftype eq 'blob') {
2727 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
2728 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2729 if (defined $blob_current && defined $blob_parent &&
2730 $blob_current ne $blob_parent) {
2732 $cgi->a({-href
=> href
(action
=>"blobdiff",
2733 hash
=>$blob_current, hash_parent
=>$blob_parent,
2734 hash_base
=>$hash_base, hash_parent_base
=>$commit,
2735 file_name
=>$file_name)},
2742 if (defined $extra) {
2744 "<td colspan=\"4\">$extra</td>\n" .
2751 # uses global variable $project
2752 my ($taglist, $from, $to, $extra) = @_;
2753 $from = 0 unless defined $from;
2754 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2756 print "<table class=\"tags\" cellspacing=\"0\">\n";
2758 for (my $i = $from; $i <= $to; $i++) {
2759 my $entry = $taglist->[$i];
2761 my $comment = $tag{'subject'};
2763 if (defined $comment) {
2764 $comment_short = chop_str
($comment, 30, 5);
2767 print "<tr class=\"dark\">\n";
2769 print "<tr class=\"light\">\n";
2772 print "<td><i>$tag{'age'}</i></td>\n" .
2774 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
2775 -class => "list name"}, esc_html
($tag{'name'})) .
2778 if (defined $comment) {
2779 print format_subject_html
($comment, $comment_short,
2780 href
(action
=>"tag", hash
=>$tag{'id'}));
2783 "<td class=\"selflink\">";
2784 if ($tag{'type'} eq "tag") {
2785 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
2790 "<td class=\"link\">" . " | " .
2791 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
2792 if ($tag{'reftype'} eq "commit") {
2793 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
2794 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
2795 } elsif ($tag{'reftype'} eq "blob") {
2796 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
2801 if (defined $extra) {
2803 "<td colspan=\"5\">$extra</td>\n" .
2809 sub git_heads_body
{
2810 # uses global variable $project
2811 my ($headlist, $head, $from, $to, $extra) = @_;
2812 $from = 0 unless defined $from;
2813 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
2815 print "<table class=\"heads\" cellspacing=\"0\">\n";
2817 for (my $i = $from; $i <= $to; $i++) {
2818 my $entry = $headlist->[$i];
2820 my $curr = $ref{'id'} eq $head;
2822 print "<tr class=\"dark\">\n";
2824 print "<tr class=\"light\">\n";
2827 print "<td><i>$ref{'age'}</i></td>\n" .
2828 ($curr ? "<td class=\"current_head\">" : "<td>") .
2829 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
2830 -class => "list name"},esc_html
($ref{'name'})) .
2832 "<td class=\"link\">" .
2833 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
2834 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
2835 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
2839 if (defined $extra) {
2841 "<td colspan=\"3\">$extra</td>\n" .
2847 ## ======================================================================
2848 ## ======================================================================
2851 sub git_project_list
{
2852 my $order = $cgi->param('o');
2853 if (defined $order && $order !~ m/project|descr|owner|age/) {
2854 die_error
(undef, "Unknown order parameter");
2857 my @list = git_get_projects_list
();
2859 die_error
(undef, "No projects found");
2863 if (-f
$home_text) {
2864 print "<div class=\"index_include\">\n";
2865 open (my $fd, $home_text);
2870 git_project_list_body
(\
@list, $order);
2875 my $order = $cgi->param('o');
2876 if (defined $order && $order !~ m/project|descr|owner|age/) {
2877 die_error
(undef, "Unknown order parameter");
2880 my @list = git_get_projects_list
($project);
2882 die_error
(undef, "No forks found");
2886 git_print_page_nav
('','');
2887 git_print_header_div
('summary', "$project forks");
2888 git_project_list_body
(\
@list, $order);
2892 sub git_project_index
{
2893 my @projects = git_get_projects_list
($project);
2896 -type
=> 'text/plain',
2897 -charset
=> 'utf-8',
2898 -content_disposition
=> 'inline; filename="index.aux"');
2900 foreach my $pr (@projects) {
2901 if (!exists $pr->{'owner'}) {
2902 $pr->{'owner'} = get_file_owner
("$projectroot/$project");
2905 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
2906 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
2907 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2908 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2912 print "$path $owner\n";
2917 my $descr = git_get_project_description
($project) || "none";
2918 my %co = parse_commit
("HEAD");
2919 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2920 my $head = $co{'id'};
2922 my $owner = git_get_project_owner
($project);
2924 my $refs = git_get_references
();
2925 # These get_*_list functions return one more to allow us to see if
2926 # there are more ...
2927 my @taglist = git_get_tags_list
(16);
2928 my @headlist = git_get_heads_list
(16);
2930 my ($check_forks) = gitweb_check_feature
('forks');
2933 @forklist = git_get_projects_list
($project);
2937 git_print_page_nav
('summary','', $head);
2939 print "<div class=\"title\"> </div>\n";
2940 print "<table cellspacing=\"0\">\n" .
2941 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
2942 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2943 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2944 # use per project git URL list in $projectroot/$project/cloneurl
2945 # or make project git URL from git base URL and project name
2946 my $url_tag = "URL";
2947 my @url_list = git_get_project_url_list
($project);
2948 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2949 foreach my $git_url (@url_list) {
2950 next unless $git_url;
2951 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2956 if (-s
"$projectroot/$project/README.html") {
2957 if (open my $fd, "$projectroot/$project/README.html") {
2958 print "<div class=\"title\">readme</div>\n";
2959 print $_ while (<$fd>);
2964 # we need to request one more than 16 (0..15) to check if
2966 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=17",
2968 or die_error
(undef, "Open git-rev-list failed");
2969 my @revlist = map { chomp; $_ } <$fd>;
2971 git_print_header_div
('shortlog');
2972 git_shortlog_body
(\
@revlist, 0, 15, $refs,
2973 $#revlist <= 15 ? undef :
2974 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
2977 git_print_header_div
('tags');
2978 git_tags_body
(\
@taglist, 0, 15,
2979 $#taglist <= 15 ? undef :
2980 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
2984 git_print_header_div
('heads');
2985 git_heads_body
(\
@headlist, $head, 0, 15,
2986 $#headlist <= 15 ? undef :
2987 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
2991 git_print_header_div
('forks');
2992 git_project_list_body
(\
@forklist, undef, 0, 15,
2993 $#forklist <= 15 ? undef :
2994 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
3002 my $head = git_get_head_hash
($project);
3004 git_print_page_nav
('','', $head,undef,$head);
3005 my %tag = parse_tag
($hash);
3006 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
3007 print "<div class=\"title_text\">\n" .
3008 "<table cellspacing=\"0\">\n" .
3010 "<td>object</td>\n" .
3011 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3012 $tag{'object'}) . "</td>\n" .
3013 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
3014 $tag{'type'}) . "</td>\n" .
3016 if (defined($tag{'author'})) {
3017 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
3018 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
3019 print "<tr><td></td><td>" . $ad{'rfc2822'} .
3020 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
3023 print "</table>\n\n" .
3025 print "<div class=\"page_body\">";
3026 my $comment = $tag{'comment'};
3027 foreach my $line (@$comment) {
3029 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
3039 my ($have_blame) = gitweb_check_feature
('blame');
3041 die_error
('403 Permission denied', "Permission denied");
3043 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3044 $hash_base ||= git_get_head_hash
($project);
3045 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3046 my %co = parse_commit
($hash_base)
3047 or die_error
(undef, "Reading commit failed");
3048 if (!defined $hash) {
3049 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3050 or die_error
(undef, "Error looking up file");
3052 $ftype = git_get_type
($hash);
3053 if ($ftype !~ "blob") {
3054 die_error
("400 Bad Request", "Object is not a blob");
3056 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
3057 $file_name, $hash_base)
3058 or die_error
(undef, "Open git-blame failed");
3061 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3064 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3067 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3069 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3070 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3071 git_print_page_path
($file_name, $ftype, $hash_base);
3072 my @rev_color = (qw(light2 dark2));
3073 my $num_colors = scalar(@rev_color);
3074 my $current_color = 0;
3077 <div class="page_body">
3078 <table class="blame">
3079 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
3084 last unless defined $_;
3085 my ($full_rev, $orig_lineno, $lineno, $group_size) =
3086 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
3087 if (!exists $metainfo{$full_rev}) {
3088 $metainfo{$full_rev} = {};
3090 my $meta = $metainfo{$full_rev};
3093 if (/^(\S+) (.*)$/) {
3099 my $rev = substr($full_rev, 0, 8);
3100 my $author = $meta->{'author'};
3101 my %date = parse_date
($meta->{'author-time'},
3102 $meta->{'author-tz'});
3103 my $date = $date{'iso-tz'};
3105 $current_color = ++$current_color % $num_colors;
3107 print "<tr class=\"$rev_color[$current_color]\">\n";
3109 print "<td class=\"sha1\"";
3110 print " title=\"". esc_html
($author) . ", $date\"";
3111 print " rowspan=\"$group_size\"" if ($group_size > 1);
3113 print $cgi->a({-href
=> href
(action
=>"commit",
3115 file_name
=>$file_name)},
3119 my $blamed = href
(action
=> 'blame',
3120 file_name
=> $meta->{'filename'},
3121 hash_base
=> $full_rev);
3122 print "<td class=\"linenr\">";
3123 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
3125 -class => "linenr" },
3128 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
3134 or print "Reading blob failed\n";
3141 my ($have_blame) = gitweb_check_feature
('blame');
3143 die_error
('403 Permission denied', "Permission denied");
3145 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3146 $hash_base ||= git_get_head_hash
($project);
3147 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3148 my %co = parse_commit
($hash_base)
3149 or die_error
(undef, "Reading commit failed");
3150 if (!defined $hash) {
3151 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3152 or die_error
(undef, "Error lookup file");
3154 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
3155 or die_error
(undef, "Open git-annotate failed");
3158 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3161 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3164 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3166 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3167 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3168 git_print_page_path
($file_name, 'blob', $hash_base);
3169 print "<div class=\"page_body\">\n";
3171 <table class="blame">
3180 my @line_class = (qw(light dark));
3181 my $line_class_len = scalar (@line_class);
3182 my $line_class_num = $#line_class;
3183 while (my $line = <$fd>) {
3195 $line_class_num = ($line_class_num + 1) % $line_class_len;
3197 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
3204 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
3207 $short_rev = substr ($long_rev, 0, 8);
3208 $age = time () - $time;
3209 $age_str = age_string
($age);
3210 $age_str =~ s/ / /g;
3211 $age_class = age_class
($age);
3212 $author = esc_html
($author);
3213 $author =~ s/ / /g;
3215 $data = untabify
($data);
3216 $data = esc_html
($data);
3219 <tr class="$line_class[$line_class_num]">
3220 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
3221 <td class="$age_class">$age_str</td>
3223 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
3224 <td class="pre">$data</td>
3227 } # while (my $line = <$fd>)
3228 print "</table>\n\n";
3230 or print "Reading blob failed.\n";
3236 my $head = git_get_head_hash
($project);
3238 git_print_page_nav
('','', $head,undef,$head);
3239 git_print_header_div
('summary', $project);
3241 my @tagslist = git_get_tags_list
();
3243 git_tags_body
(\
@tagslist);
3249 my $head = git_get_head_hash
($project);
3251 git_print_page_nav
('','', $head,undef,$head);
3252 git_print_header_div
('summary', $project);
3254 my @headslist = git_get_heads_list
();
3256 git_heads_body
(\
@headslist, $head);
3261 sub git_blob_plain
{
3264 if (!defined $hash) {
3265 if (defined $file_name) {
3266 my $base = $hash_base || git_get_head_hash
($project);
3267 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3268 or die_error
(undef, "Error lookup file");
3270 die_error
(undef, "No file name defined");
3272 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3273 # blobs defined by non-textual hash id's can be cached
3278 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3279 or die_error
(undef, "Couldn't cat $file_name, $hash");
3281 $type ||= blob_mimetype
($fd, $file_name);
3283 # save as filename, even when no $file_name is given
3284 my $save_as = "$hash";
3285 if (defined $file_name) {
3286 $save_as = $file_name;
3287 } elsif ($type =~ m/^text\//) {
3294 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
3296 binmode STDOUT
, ':raw';
3298 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3306 if (!defined $hash) {
3307 if (defined $file_name) {
3308 my $base = $hash_base || git_get_head_hash
($project);
3309 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3310 or die_error
(undef, "Error lookup file");
3312 die_error
(undef, "No file name defined");
3314 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3315 # blobs defined by non-textual hash id's can be cached
3319 my ($have_blame) = gitweb_check_feature
('blame');
3320 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3321 or die_error
(undef, "Couldn't cat $file_name, $hash");
3322 my $mimetype = blob_mimetype
($fd, $file_name);
3323 if ($mimetype !~ m!^(?:text/|image/(?:gif|png|jpeg)$)!) {
3325 return git_blob_plain
($mimetype);
3327 # we can have blame only for text/* mimetype
3328 $have_blame &&= ($mimetype =~ m!^text/!);
3330 git_header_html
(undef, $expires);
3331 my $formats_nav = '';
3332 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3333 if (defined $file_name) {
3336 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
3337 hash
=>$hash, file_name
=>$file_name)},
3342 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3343 hash
=>$hash, file_name
=>$file_name)},
3346 $cgi->a({-href
=> href
(action
=>"blob_plain",
3347 hash
=>$hash, file_name
=>$file_name)},
3350 $cgi->a({-href
=> href
(action
=>"blob",
3351 hash_base
=>"HEAD", file_name
=>$file_name)},
3355 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
3357 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3358 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3360 print "<div class=\"page_nav\">\n" .
3361 "<br/><br/></div>\n" .
3362 "<div class=\"title\">$hash</div>\n";
3364 git_print_page_path
($file_name, "blob", $hash_base);
3365 print "<div class=\"page_body\">\n";
3366 if ($mimetype =~ m!^text/!) {
3368 while (my $line = <$fd>) {
3371 $line = untabify
($line);
3372 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
3373 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
3375 } elsif ($mimetype =~ m!^image/!) {
3376 print qq
!<img type
="$mimetype"!;
3378 print qq
! alt
="$file_name" title
="$file_name"!;
3381 href(action=>"blob_plain
", hash=>$hash,
3382 hash_base=>$hash_base, file_name=>$file_name) .
3386 or print "Reading blob failed.\n";
3392 my $have_snapshot = gitweb_have_snapshot
();
3394 if (!defined $hash_base) {
3395 $hash_base = "HEAD";
3397 if (!defined $hash) {
3398 if (defined $file_name) {
3399 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
3405 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
3406 or die_error
(undef, "Open git-ls-tree failed");
3407 my @entries = map { chomp; $_ } <$fd>;
3408 close $fd or die_error
(undef, "Reading tree failed");
3411 my $refs = git_get_references
();
3412 my $ref = format_ref_marker
($refs, $hash_base);
3415 my ($have_blame) = gitweb_check_feature
('blame');
3416 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3418 if (defined $file_name) {
3420 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3421 hash
=>$hash, file_name
=>$file_name)},
3423 $cgi->a({-href
=> href
(action
=>"tree",
3424 hash_base
=>"HEAD", file_name
=>$file_name)},
3427 if ($have_snapshot) {
3428 # FIXME: Should be available when we have no hash base as well.
3430 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
3433 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
3434 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
3437 print "<div class=\"page_nav\">\n";
3438 print "<br/><br/></div>\n";
3439 print "<div class=\"title\">$hash</div>\n";
3441 if (defined $file_name) {
3442 $basedir = $file_name;
3443 if ($basedir ne '' && substr($basedir, -1) ne '/') {
3447 git_print_page_path
($file_name, 'tree', $hash_base);
3448 print "<div class=\"page_body\">\n";
3449 print "<table cellspacing=\"0\">\n";
3451 # '..' (top directory) link if possible
3452 if (defined $hash_base &&
3453 defined $file_name && $file_name =~ m![^/]+$!) {
3455 print "<tr class=\"dark\">\n";
3457 print "<tr class=\"light\">\n";
3461 my $up = $file_name;
3462 $up =~ s!/?[^/]+$!!;
3463 undef $up unless $up;
3464 # based on git_print_tree_entry
3465 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
3466 print '<td class="list">';
3467 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
3471 print "<td class=\"link\"></td>\n";
3475 foreach my $line (@entries) {
3476 my %t = parse_ls_tree_line
($line, -z
=> 1);
3479 print "<tr class=\"dark\">\n";
3481 print "<tr class=\"light\">\n";
3485 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
3489 print "</table>\n" .
3495 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
3496 my $have_snapshot = (defined $ctype && defined $suffix);
3497 if (!$have_snapshot) {
3498 die_error
('403 Permission denied', "Permission denied");
3501 if (!defined $hash) {
3502 $hash = git_get_head_hash
($project);
3505 my $filename = basename
($project) . "-$hash.tar.$suffix";
3508 -type
=> "application/$ctype",
3509 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
3510 -status
=> '200 OK');
3512 my $git = git_cmd_str
();
3513 my $name = $project;
3514 $name =~ s/\047/\047\\\047\047/g;
3516 "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
3517 or die_error
(undef, "Execute git-tar-tree failed.");
3518 binmode STDOUT
, ':raw';
3520 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3526 my $head = git_get_head_hash
($project);
3527 if (!defined $hash) {
3530 if (!defined $page) {
3533 my $refs = git_get_references
();
3535 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3536 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash, "--"
3537 or die_error
(undef, "Open git-rev-list failed");
3538 my @revlist = map { chomp; $_ } <$fd>;
3541 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
3544 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
3547 my %co = parse_commit
($hash);
3549 git_print_header_div
('summary', $project);
3550 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
3552 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
3553 my $commit = $revlist[$i];
3554 my $ref = format_ref_marker
($refs, $commit);
3555 my %co = parse_commit
($commit);
3557 my %ad = parse_date
($co{'author_epoch'});
3558 git_print_header_div
('commit',
3559 "<span class=\"age\">$co{'age_string'}</span>" .
3560 esc_html
($co{'title'}) . $ref,
3562 print "<div class=\"title_text\">\n" .
3563 "<div class=\"log_link\">\n" .
3564 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
3566 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
3568 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
3571 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
3574 print "<div class=\"log_body\">\n";
3575 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
3582 $hash ||= $hash_base || "HEAD";
3583 my %co = parse_commit
($hash);
3585 die_error
(undef, "Unknown commit object");
3587 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3588 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
3590 my $parent = $co{'parent'};
3591 my $parents = $co{'parents'}; # listref
3593 # we need to prepare $formats_nav before any parameter munging
3595 if (!defined $parent) {
3597 $formats_nav .= '(initial)';
3598 } elsif (@$parents == 1) {
3599 # single parent commit
3602 $cgi->a({-href
=> href
(action
=>"commit",
3604 esc_html
(substr($parent, 0, 7))) .
3611 $cgi->a({-href
=> href
(action
=>"commitdiff",
3613 esc_html
(substr($_, 0, 7)));
3618 if (!defined $parent) {
3622 if (@$parents <= 1) {
3623 # difftree output is not printed for merges
3624 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
3625 @diff_opts, $parent, $hash, "--"
3626 or die_error
(undef, "Open git-diff-tree failed");
3627 @difftree = map { chomp; $_ } <$fd>;
3628 close $fd or die_error
(undef, "Reading git-diff-tree failed");
3631 # non-textual hash id's can be cached
3633 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3636 my $refs = git_get_references
();
3637 my $ref = format_ref_marker
($refs, $co{'id'});
3639 my $have_snapshot = gitweb_have_snapshot
();
3641 git_header_html
(undef, $expires);
3642 git_print_page_nav
('commit', '',
3643 $hash, $co{'tree'}, $hash,
3646 if (defined $co{'parent'}) {
3647 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
3649 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
3651 print "<div class=\"title_text\">\n" .
3652 "<table cellspacing=\"0\">\n";
3653 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
3655 "<td></td><td> $ad{'rfc2822'}";
3656 if ($ad{'hour_local'} < 6) {
3657 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3658 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3660 printf(" (%02d:%02d %s)",
3661 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3665 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
3666 print "<tr><td></td><td> $cd{'rfc2822'}" .
3667 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
3669 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
3672 "<td class=\"sha1\">" .
3673 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
3674 class => "list"}, $co{'tree'}) .
3676 "<td class=\"link\">" .
3677 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
3679 if ($have_snapshot) {
3681 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
3686 foreach my $par (@$parents) {
3689 "<td class=\"sha1\">" .
3690 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
3691 class => "list"}, $par) .
3693 "<td class=\"link\">" .
3694 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
3696 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
3703 print "<div class=\"page_body\">\n";
3704 git_print_log
($co{'comment'});
3707 if (@$parents <= 1) {
3708 # do not output difftree/whatchanged for merges
3709 git_difftree_body
(\
@difftree, $hash, $parent);
3716 # object is defined by:
3717 # - hash or hash_base alone
3718 # - hash_base and file_name
3721 # - hash or hash_base alone
3722 if ($hash || ($hash_base && !defined $file_name)) {
3723 my $object_id = $hash || $hash_base;
3725 my $git_command = git_cmd_str
();
3726 open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null"
3727 or die_error
('404 Not Found', "Object does not exist");
3731 or die_error
('404 Not Found', "Object does not exist");
3733 # - hash_base and file_name
3734 } elsif ($hash_base && defined $file_name) {
3735 $file_name =~ s
,/+$,,;
3737 system(git_cmd
(), "cat-file", '-e', $hash_base) == 0
3738 or die_error
('404 Not Found', "Base object does not exist");
3740 # here errors should not hapen
3741 open my $fd, "-|", git_cmd
(), "ls-tree", $hash_base, "--", $file_name
3742 or die_error
(undef, "Open git-ls-tree failed");
3746 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
3747 unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) {
3748 die_error
('404 Not Found', "File or directory for given base does not exist");
3753 die_error
('404 Not Found', "Not enough information to find object");
3756 print $cgi->redirect(-uri
=> href
(action
=>$type, -full
=>1,
3757 hash
=>$hash, hash_base
=>$hash_base,
3758 file_name
=>$file_name),
3759 -status
=> '302 Found');
3763 my $format = shift || 'html';
3770 # preparing $fd and %diffinfo for git_patchset_body
3772 if (defined $hash_base && defined $hash_parent_base) {
3773 if (defined $file_name) {
3775 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3776 $hash_parent_base, $hash_base,
3778 or die_error
(undef, "Open git-diff-tree failed");
3779 @difftree = map { chomp; $_ } <$fd>;
3781 or die_error
(undef, "Reading git-diff-tree failed");
3783 or die_error
('404 Not Found', "Blob diff not found");
3785 } elsif (defined $hash &&
3786 $hash =~ /[0-9a-fA-F]{40}/) {
3787 # try to find filename from $hash
3789 # read filtered raw output
3790 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3791 $hash_parent_base, $hash_base, "--"
3792 or die_error
(undef, "Open git-diff-tree failed");
3794 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
3796 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
3797 map { chomp; $_ } <$fd>;
3799 or die_error
(undef, "Reading git-diff-tree failed");
3801 or die_error
('404 Not Found', "Blob diff not found");
3804 die_error
('404 Not Found', "Missing one of the blob diff parameters");
3807 if (@difftree > 1) {
3808 die_error
('404 Not Found', "Ambiguous blob diff specification");
3811 %diffinfo = parse_difftree_raw_line
($difftree[0]);
3812 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
3813 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
3815 $hash_parent ||= $diffinfo{'from_id'};
3816 $hash ||= $diffinfo{'to_id'};
3818 # non-textual hash id's can be cached
3819 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
3820 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
3825 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3826 '-p', $hash_parent_base, $hash_base,
3828 or die_error
(undef, "Open git-diff-tree failed");
3831 # old/legacy style URI
3832 if (!%diffinfo && # if new style URI failed
3833 defined $hash && defined $hash_parent) {
3834 # fake git-diff-tree raw output
3835 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
3836 $diffinfo{'from_id'} = $hash_parent;
3837 $diffinfo{'to_id'} = $hash;
3838 if (defined $file_name) {
3839 if (defined $file_parent) {
3840 $diffinfo{'status'} = '2';
3841 $diffinfo{'from_file'} = $file_parent;
3842 $diffinfo{'to_file'} = $file_name;
3843 } else { # assume not renamed
3844 $diffinfo{'status'} = '1';
3845 $diffinfo{'from_file'} = $file_name;
3846 $diffinfo{'to_file'} = $file_name;
3848 } else { # no filename given
3849 $diffinfo{'status'} = '2';
3850 $diffinfo{'from_file'} = $hash_parent;
3851 $diffinfo{'to_file'} = $hash;
3854 # non-textual hash id's can be cached
3855 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
3856 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3861 open $fd, "-|", git_cmd
(), "diff", '-p', @diff_opts,
3862 $hash_parent, $hash, "--"
3863 or die_error
(undef, "Open git-diff failed");
3865 die_error
('404 Not Found', "Missing one of the blob diff parameters")
3870 if ($format eq 'html') {
3872 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
3873 hash
=>$hash, hash_parent
=>$hash_parent,
3874 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
3875 file_name
=>$file_name, file_parent
=>$file_parent)},
3877 git_header_html
(undef, $expires);
3878 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3879 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3880 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3882 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
3883 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
3885 if (defined $file_name) {
3886 git_print_page_path
($file_name, "blob", $hash_base);
3888 print "<div class=\"page_path\"></div>\n";
3891 } elsif ($format eq 'plain') {
3893 -type
=> 'text/plain',
3894 -charset
=> 'utf-8',
3895 -expires
=> $expires,
3896 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
3898 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3901 die_error
(undef, "Unknown blobdiff format");
3905 if ($format eq 'html') {
3906 print "<div class=\"page_body\">\n";
3908 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
3911 print "</div>\n"; # class="page_body"
3915 while (my $line = <$fd>) {
3916 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
3917 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
3921 last if $line =~ m!^\+\+\+!;
3929 sub git_blobdiff_plain
{
3930 git_blobdiff
('plain');
3933 sub git_commitdiff
{
3934 my $format = shift || 'html';
3935 $hash ||= $hash_base || "HEAD";
3936 my %co = parse_commit
($hash);
3938 die_error
(undef, "Unknown commit object");
3941 # we need to prepare $formats_nav before any parameter munging
3943 if ($format eq 'html') {
3945 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
3946 hash
=>$hash, hash_parent
=>$hash_parent)},
3949 if (defined $hash_parent) {
3950 # commitdiff with two commits given
3951 my $hash_parent_short = $hash_parent;
3952 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3953 $hash_parent_short = substr($hash_parent, 0, 7);
3957 $cgi->a({-href
=> href
(action
=>"commitdiff",
3958 hash
=>$hash_parent)},
3959 esc_html
($hash_parent_short)) .
3961 } elsif (!$co{'parent'}) {
3963 $formats_nav .= ' (initial)';
3964 } elsif (scalar @{$co{'parents'}} == 1) {
3965 # single parent commit
3968 $cgi->a({-href
=> href
(action
=>"commitdiff",
3969 hash
=>$co{'parent'})},
3970 esc_html
(substr($co{'parent'}, 0, 7))) .
3977 $cgi->a({-href
=> href
(action
=>"commitdiff",
3979 esc_html
(substr($_, 0, 7)));
3980 } @{$co{'parents'}} ) .
3985 if (!defined $hash_parent) {
3986 $hash_parent = $co{'parent'} || '--root';
3992 if ($format eq 'html') {
3993 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3994 "--no-commit-id", "--patch-with-raw", "--full-index",
3995 $hash_parent, $hash, "--"
3996 or die_error
(undef, "Open git-diff-tree failed");
3998 while (my $line = <$fd>) {
4000 # empty line ends raw part of diff-tree output
4002 push @difftree, $line;
4005 } elsif ($format eq 'plain') {
4006 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4007 '-p', $hash_parent, $hash, "--"
4008 or die_error
(undef, "Open git-diff-tree failed");
4011 die_error
(undef, "Unknown commitdiff format");
4014 # non-textual hash id's can be cached
4016 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
4020 # write commit message
4021 if ($format eq 'html') {
4022 my $refs = git_get_references
();
4023 my $ref = format_ref_marker
($refs, $co{'id'});
4025 git_header_html
(undef, $expires);
4026 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
4027 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
4028 git_print_authorship
(\
%co);
4029 print "<div class=\"page_body\">\n";
4030 if (@{$co{'comment'}} > 1) {
4031 print "<div class=\"log\">\n";
4032 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
4033 print "</div>\n"; # class="log"
4036 } elsif ($format eq 'plain') {
4037 my $refs = git_get_references
("tags");
4038 my $tagname = git_get_rev_name_tags
($hash);
4039 my $filename = basename
($project) . "-$hash.patch";
4042 -type
=> 'text/plain',
4043 -charset
=> 'utf-8',
4044 -expires
=> $expires,
4045 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
4046 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
4049 Date: $ad{'rfc2822'} ($ad{'tz_local'})
4050 Subject: $co{'title'}
4052 print "X-Git-Tag: $tagname\n" if $tagname;
4053 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
4055 foreach my $line (@{$co{'comment'}}) {
4062 if ($format eq 'html') {
4063 git_difftree_body
(\
@difftree, $hash, $hash_parent);
4066 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
4068 print "</div>\n"; # class="page_body"
4071 } elsif ($format eq 'plain') {
4075 or print "Reading git-diff-tree failed\n";
4079 sub git_commitdiff_plain
{
4080 git_commitdiff
('plain');
4084 if (!defined $hash_base) {
4085 $hash_base = git_get_head_hash
($project);
4087 if (!defined $page) {
4091 my %co = parse_commit
($hash_base);
4093 die_error
(undef, "Unknown commit object");
4096 my $refs = git_get_references
();
4097 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
4099 if (!defined $hash && defined $file_name) {
4100 $hash = git_get_hash_by_path
($hash_base, $file_name);
4102 if (defined $hash) {
4103 $ftype = git_get_type
($hash);
4107 git_cmd
(), "rev-list", $limit, "--full-history", $hash_base, "--", $file_name
4108 or die_error
(undef, "Open git-rev-list-failed");
4109 my @revlist = map { chomp; $_ } <$fd>;
4111 or die_error
(undef, "Reading git-rev-list failed");
4113 my $paging_nav = '';
4116 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4117 file_name
=>$file_name)},
4119 $paging_nav .= " ⋅ " .
4120 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4121 file_name
=>$file_name, page
=>$page-1),
4122 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
4124 $paging_nav .= "first";
4125 $paging_nav .= " ⋅ prev";
4127 if ($#revlist >= (100 * ($page+1)-1)) {
4128 $paging_nav .= " ⋅ " .
4129 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4130 file_name
=>$file_name, page
=>$page+1),
4131 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
4133 $paging_nav .= " ⋅ next";
4136 if ($#revlist >= (100 * ($page+1)-1)) {
4138 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
4139 file_name
=>$file_name, page
=>$page+1),
4140 -title
=> "Alt-n"}, "next");
4144 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
4145 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
4146 git_print_page_path
($file_name, $ftype, $hash_base);
4148 git_history_body
(\
@revlist, ($page * 100), $#revlist,
4149 $refs, $hash_base, $ftype, $next_link);
4155 if (!defined $searchtext) {
4156 die_error
(undef, "Text field empty");
4158 if (!defined $hash) {
4159 $hash = git_get_head_hash
($project);
4161 my %co = parse_commit
($hash);
4163 die_error
(undef, "Unknown commit object");
4166 $searchtype ||= 'commit';
4167 if ($searchtype eq 'pickaxe') {
4168 # pickaxe may take all resources of your box and run for several minutes
4169 # with every query - so decide by yourself how public you make this feature
4170 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4171 if (!$have_pickaxe) {
4172 die_error
('403 Permission denied', "Permission denied");
4177 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
4178 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
4180 print "<table cellspacing=\"0\">\n";
4182 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
4184 if ($searchtype eq 'commit') {
4185 $greptype = "--grep=";
4186 } elsif ($searchtype eq 'author') {
4187 $greptype = "--author=";
4188 } elsif ($searchtype eq 'committer') {
4189 $greptype = "--committer=";
4192 open my $fd, "-|", git_cmd
(), "rev-list",
4193 "--header", "--parents", ($greptype . $searchtext),
4196 while (my $commit_text = <$fd>) {
4197 my @commit_lines = split "\n", $commit_text;
4198 my %co = parse_commit
(undef, \
@commit_lines);
4203 print "<tr class=\"dark\">\n";
4205 print "<tr class=\"light\">\n";
4208 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4209 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
4211 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
4212 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
4213 my $comment = $co{'comment'};
4214 foreach my $line (@$comment) {
4215 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
4216 my $lead = esc_html
($1) || "";
4217 $lead = chop_str
($lead, 30, 10);
4218 my $match = esc_html
($2) || "";
4219 my $trail = esc_html
($3) || "";
4220 $trail = chop_str
($trail, 30, 10);
4221 my $text = "$lead<span class=\"match\">$match</span>$trail";
4222 print chop_str
($text, 80, 5) . "<br/>\n";
4226 "<td class=\"link\">" .
4227 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4229 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4236 if ($searchtype eq 'pickaxe') {
4238 my $git_command = git_cmd_str
();
4239 open my $fd, "-|", "$git_command rev-list $hash | " .
4240 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
4243 while (my $line = <$fd>) {
4244 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
4247 $set{'from_id'} = $3;
4249 $set{'id'} = $set{'to_id'};
4250 if ($set{'id'} =~ m/0{40}/) {
4251 $set{'id'} = $set{'from_id'};
4253 if ($set{'id'} =~ m/0{40}/) {
4257 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
4260 print "<tr class=\"dark\">\n";
4262 print "<tr class=\"light\">\n";
4265 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4266 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
4268 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4269 -class => "list subject"},
4270 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
4271 while (my $setref = shift @files) {
4273 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
4274 hash
=>$set{'id'}, file_name
=>$set{'file'}),
4276 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
4280 "<td class=\"link\">" .
4281 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4283 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4287 %co = parse_commit
($1);
4296 sub git_search_help
{
4298 git_print_page_nav
('','', $hash,$hash,$hash);
4301 <dt><b>commit</b></dt>
4302 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
4303 <dt><b>author</b></dt>
4304 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
4305 <dt><b>committer</b></dt>
4306 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
4308 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4309 if ($have_pickaxe) {
4311 <dt><b>pickaxe</b></dt>
4312 <dd>All commits that caused the string to appear or disappear from any file (changes that
4313 added, removed or "modified" the string) will be listed. This search can take a while and
4314 takes a lot of strain on the server, so please use it wisely.</dd>
4322 my $head = git_get_head_hash
($project);
4323 if (!defined $hash) {
4326 if (!defined $page) {
4329 my $refs = git_get_references
();
4331 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
4332 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash, "--"
4333 or die_error
(undef, "Open git-rev-list failed");
4334 my @revlist = map { chomp; $_ } <$fd>;
4337 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
4339 if ($#revlist >= (100 * ($page+1)-1)) {
4341 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
4342 -title
=> "Alt-n"}, "next");
4347 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
4348 git_print_header_div
('summary', $project);
4350 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
4355 ## ......................................................................
4356 ## feeds (RSS, Atom; OPML)
4359 my $format = shift || 'atom';
4360 my ($have_blame) = gitweb_check_feature
('blame');
4362 # Atom: http://www.atomenabled.org/developers/syndication/
4363 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
4364 if ($format ne 'rss' && $format ne 'atom') {
4365 die_error
(undef, "Unknown web feed format");
4368 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
4369 my $head = $hash || 'HEAD';
4370 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=150",
4371 $head, "--", (defined $file_name ? $file_name : ())
4372 or die_error
(undef, "Open git-rev-list failed");
4373 my @revlist = map { chomp; $_ } <$fd>;
4374 close $fd or die_error
(undef, "Reading git-rev-list failed");
4378 my $content_type = "application/$format+xml";
4379 if (defined $cgi->http('HTTP_ACCEPT') &&
4380 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
4381 # browser (feed reader) prefers text/xml
4382 $content_type = 'text/xml';
4384 if (defined($revlist[0])) {
4385 %latest_commit = parse_commit
($revlist[0]);
4386 %latest_date = parse_date
($latest_commit{'author_epoch'});
4388 -type
=> $content_type,
4389 -charset
=> 'utf-8',
4390 -last_modified
=> $latest_date{'rfc2822'});
4393 -type
=> $content_type,
4394 -charset
=> 'utf-8');
4397 # Optimization: skip generating the body if client asks only
4398 # for Last-Modified date.
4399 return if ($cgi->request_method() eq 'HEAD');
4402 my $title = "$site_name - $project/$action";
4403 my $feed_type = 'log';
4404 if (defined $hash) {
4405 $title .= " - '$hash'";
4406 $feed_type = 'branch log';
4407 if (defined $file_name) {
4408 $title .= " :: $file_name";
4409 $feed_type = 'history';
4411 } elsif (defined $file_name) {
4412 $title .= " - $file_name";
4413 $feed_type = 'history';
4415 $title .= " $feed_type";
4416 my $descr = git_get_project_description
($project);
4417 if (defined $descr) {
4418 $descr = esc_html
($descr);
4420 $descr = "$project " .
4421 ($format eq 'rss' ? 'RSS' : 'Atom') .
4424 my $owner = git_get_project_owner
($project);
4425 $owner = esc_html
($owner);
4429 if (defined $file_name) {
4430 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
4431 } elsif (defined $hash) {
4432 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
4434 $alt_url = href
(-full
=>1, action
=>"summary");
4436 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
4437 if ($format eq 'rss') {
4439 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
4442 print "<title>$title</title>\n" .
4443 "<link>$alt_url</link>\n" .
4444 "<description>$descr</description>\n" .
4445 "<language>en</language>\n";
4446 } elsif ($format eq 'atom') {
4448 <feed xmlns="http://www.w3.org/2005/Atom">
4450 print "<title>$title</title>\n" .
4451 "<subtitle>$descr</subtitle>\n" .
4452 '<link rel="alternate" type="text/html" href="' .
4453 $alt_url . '" />' . "\n" .
4454 '<link rel="self" type="' . $content_type . '" href="' .
4455 $cgi->self_url() . '" />' . "\n" .
4456 "<id>" . href
(-full
=>1) . "</id>\n" .
4457 # use project owner for feed author
4458 "<author><name>$owner</name></author>\n";
4459 if (defined $favicon) {
4460 print "<icon>" . esc_url
($favicon) . "</icon>\n";
4462 if (defined $logo_url) {
4463 # not twice as wide as tall: 72 x 27 pixels
4464 print "<logo>" . esc_url
($logo) . "</logo>\n";
4466 if (! %latest_date) {
4467 # dummy date to keep the feed valid until commits trickle in:
4468 print "<updated>1970-01-01T00:00:00Z</updated>\n";
4470 print "<updated>$latest_date{'iso-8601'}</updated>\n";
4475 for (my $i = 0; $i <= $#revlist; $i++) {
4476 my $commit = $revlist[$i];
4477 my %co = parse_commit
($commit);
4478 # we read 150, we always show 30 and the ones more recent than 48 hours
4479 if (($i >= 20) && ((time - $co{'author_epoch'}) > 48*60*60)) {
4482 my %cd = parse_date
($co{'author_epoch'});
4484 # get list of changed files
4485 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4486 $co{'parent'}, $co{'id'}, "--", (defined $file_name ? $file_name : ())
4488 my @difftree = map { chomp; $_ } <$fd>;
4492 # print element (entry, item)
4493 my $co_url = href
(-full
=>1, action
=>"commit", hash
=>$commit);
4494 if ($format eq 'rss') {
4496 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
4497 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
4498 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
4499 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
4500 "<link>$co_url</link>\n" .
4501 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
4502 "<content:encoded>" .
4504 } elsif ($format eq 'atom') {
4506 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
4507 "<updated>$cd{'iso-8601'}</updated>\n" .
4509 " <name>" . esc_html
($co{'author_name'}) . "</name>\n";
4510 if ($co{'author_email'}) {
4511 print " <email>" . esc_html
($co{'author_email'}) . "</email>\n";
4513 print "</author>\n" .
4514 # use committer for contributor
4516 " <name>" . esc_html
($co{'committer_name'}) . "</name>\n";
4517 if ($co{'committer_email'}) {
4518 print " <email>" . esc_html
($co{'committer_email'}) . "</email>\n";
4520 print "</contributor>\n" .
4521 "<published>$cd{'iso-8601'}</published>\n" .
4522 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
4523 "<id>$co_url</id>\n" .
4524 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
4525 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
4527 my $comment = $co{'comment'};
4529 foreach my $line (@$comment) {
4530 $line = esc_html
($line);
4533 print "</pre><ul>\n";
4534 foreach my $difftree_line (@difftree) {
4535 my %difftree = parse_difftree_raw_line
($difftree_line);
4536 next if !$difftree{'from_id'};
4538 my $file = $difftree{'file'} || $difftree{'to_file'};
4542 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
4543 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
4544 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
4545 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
4546 -title
=> "diff"}, 'D');
4548 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
4549 file_name
=>$file, hash_base
=>$commit),
4550 -title
=> "blame"}, 'B');
4552 # if this is not a feed of a file history
4553 if (!defined $file_name || $file_name ne $file) {
4554 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
4555 file_name
=>$file, hash
=>$commit),
4556 -title
=> "history"}, 'H');
4558 $file = esc_path
($file);
4562 if ($format eq 'rss') {
4563 print "</ul>]]>\n" .
4564 "</content:encoded>\n" .
4566 } elsif ($format eq 'atom') {
4567 print "</ul>\n</div>\n" .
4574 if ($format eq 'rss') {
4575 print "</channel>\n</rss>\n";
4576 } elsif ($format eq 'atom') {
4590 my @list = git_get_projects_list
();
4592 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
4594 <?xml version="1.0" encoding="utf-8"?>
4595 <opml version="1.0">
4597 <title>$site_name OPML Export</title>
4600 <outline text="git RSS feeds">
4603 foreach my $pr (@list) {
4605 my $head = git_get_head_hash
($proj{'path'});
4606 if (!defined $head) {
4609 $git_dir = "$projectroot/$proj{'path'}";
4610 my %co = parse_commit
($head);
4615 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
4616 my $rss = "$my_url?p=$proj{'path'};a=rss";
4617 my $html = "$my_url?p=$proj{'path'};a=summary";
4618 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";