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{'blame'}{'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 $searchtext = quotemeta $searchtext;
358 our $searchtype = $cgi->param('st');
359 if (defined $searchtype) {
360 if ($searchtype =~ m/[^a-z]/) {
361 die_error
(undef, "Invalid searchtype parameter");
365 # now read PATH_INFO and use it as alternative to parameters
366 sub evaluate_path_info
{
367 return if defined $project;
368 my $path_info = $ENV{"PATH_INFO"};
369 return if !$path_info;
370 $path_info =~ s
,^/+,,;
371 return if !$path_info;
372 # find which part of PATH_INFO is project
373 $project = $path_info;
375 while ($project && !check_head_link
("$projectroot/$project")) {
376 $project =~ s
,/*[^/]*$,,;
379 $project = validate_pathname
($project);
381 ($export_ok && !-e
"$projectroot/$project/$export_ok") ||
382 ($strict_export && !project_in_list
($project))) {
386 # do not change any parameters if an action is given using the query string
388 $path_info =~ s
,^$project/*,,;
389 my ($refname, $pathname) = split(/:/, $path_info, 2);
390 if (defined $pathname) {
391 # we got "project.git/branch:filename" or "project.git/branch:dir/"
392 # we could use git_get_type(branch:pathname), but it needs $git_dir
393 $pathname =~ s
,^/+,,;
394 if (!$pathname || substr($pathname, -1) eq "/") {
398 $action ||= "blob_plain";
400 $hash_base ||= validate_refname
($refname);
401 $file_name ||= validate_pathname
($pathname);
402 } elsif (defined $refname) {
403 # we got "project.git/branch"
404 $action ||= "shortlog";
405 $hash ||= validate_refname
($refname);
408 evaluate_path_info
();
410 # path to the current git repository
412 $git_dir = "$projectroot/$project" if $project;
416 "blame" => \
&git_blame2
,
417 "blobdiff" => \
&git_blobdiff
,
418 "blobdiff_plain" => \
&git_blobdiff_plain
,
419 "blob" => \
&git_blob
,
420 "blob_plain" => \
&git_blob_plain
,
421 "commitdiff" => \
&git_commitdiff
,
422 "commitdiff_plain" => \
&git_commitdiff_plain
,
423 "commit" => \
&git_commit
,
424 "forks" => \
&git_forks
,
425 "heads" => \
&git_heads
,
426 "history" => \
&git_history
,
429 "search" => \
&git_search
,
430 "search_help" => \
&git_search_help
,
431 "shortlog" => \
&git_shortlog
,
432 "summary" => \
&git_summary
,
434 "tags" => \
&git_tags
,
435 "tree" => \
&git_tree
,
436 "snapshot" => \
&git_snapshot
,
437 # those below don't need $project
438 "opml" => \
&git_opml
,
439 "project_list" => \
&git_project_list
,
440 "project_index" => \
&git_project_index
,
443 if (defined $project) {
444 $action ||= 'summary';
446 $action ||= 'project_list';
448 if (!defined($actions{$action})) {
449 die_error
(undef, "Unknown action");
451 if ($action !~ m/^(opml|project_list|project_index)$/ &&
453 die_error
(undef, "Project needed");
455 $actions{$action}->();
458 ## ======================================================================
463 # default is to use -absolute url() i.e. $my_uri
464 my $href = $params{-full
} ? $my_url : $my_uri;
466 # XXX: Warning: If you touch this, check the search form for updating,
477 hash_parent_base
=> "hpb",
483 my %mapping = @mapping;
485 $params{'project'} = $project unless exists $params{'project'};
487 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
489 # use PATH_INFO for project name
490 $href .= "/$params{'project'}" if defined $params{'project'};
491 delete $params{'project'};
493 # Summary just uses the project path URL
494 if (defined $params{'action'} && $params{'action'} eq 'summary') {
495 delete $params{'action'};
499 # now encode the parameters explicitly
501 for (my $i = 0; $i < @mapping; $i += 2) {
502 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
503 if (defined $params{$name}) {
504 push @result, $symbol . "=" . esc_param
($params{$name});
507 $href .= "?" . join(';', @result) if scalar @result;
513 ## ======================================================================
514 ## validation, quoting/unquoting and escaping
516 sub validate_pathname
{
517 my $input = shift || return undef;
519 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
520 # at the beginning, at the end, and between slashes.
521 # also this catches doubled slashes
522 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
526 if ($input =~ m!\0!) {
532 sub validate_refname
{
533 my $input = shift || return undef;
535 # textual hashes are O.K.
536 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
539 # it must be correct pathname
540 $input = validate_pathname
($input)
542 # restrictions on ref name according to git-check-ref-format
543 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
549 # very thin wrapper for decode("utf8", $str, Encode::FB_DEFAULT);
552 return decode
("utf8", $str, Encode
::FB_DEFAULT
);
555 # quote unsafe chars, but keep the slash, even when it's not
556 # correct, but quoted slashes look too horrible in bookmarks
559 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
565 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
568 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
574 # replace invalid utf8 character with SUBSTITUTION sequence
579 $str = to_utf8
($str);
580 $str = escapeHTML
($str);
581 if ($opts{'-nbsp'}) {
582 $str =~ s/ / /g;
584 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
588 # Make control characterss "printable".
591 my %es = ( # character escape codes, aka escape sequences
592 "\t" => '\t', # tab (HT)
593 "\n" => '\n', # line feed (LF)
594 "\r" => '\r', # carrige return (CR)
595 "\f" => '\f', # form feed (FF)
596 "\b" => '\b', # backspace (BS)
597 "\a" => '\a', # alarm (bell) (BEL)
598 "\e" => '\e', # escape (ESC)
599 "\013" => '\v', # vertical tab (VT)
600 "\000" => '\0', # nul character (NUL)
602 my $chr = ( (exists $es{$cntrl})
604 : sprintf('\%03o', ord($cntrl)) );
605 return "<span class=\"cntrl\">$chr</span>";
608 # Alternatively use unicode control pictures codepoints.
611 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
612 return "<span class=\"cntrl\">$chr</span>";
615 # quote control characters and escape filename to HTML
619 $str = esc_html
($str);
620 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
624 # git may return quoted and escaped filenames
630 my %es = ( # character escape codes, aka escape sequences
631 't' => "\t", # tab (HT, TAB)
632 'n' => "\n", # newline (NL)
633 'r' => "\r", # return (CR)
634 'f' => "\f", # form feed (FF)
635 'b' => "\b", # backspace (BS)
636 'a' => "\a", # alarm (bell) (BEL)
637 'e' => "\e", # escape (ESC)
638 'v' => "\013", # vertical tab (VT)
641 if ($seq =~ m/^[0-7]{1,3}$/) {
642 # octal char sequence
643 return chr(oct($seq));
644 } elsif (exists $es{$seq}) {
645 # C escape sequence, aka character escape code
648 # quoted ordinary character
652 if ($str =~ m/^"(.*)"$/) {
655 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
660 # escape tabs (convert tabs to spaces)
664 while ((my $pos = index($line, "\t")) != -1) {
665 if (my $count = (8 - ($pos % 8))) {
666 my $spaces = ' ' x
$count;
667 $line =~ s/\t/$spaces/;
674 sub project_in_list
{
676 my @list = git_get_projects_list
();
677 return @list && scalar(grep { $_->{'path'} eq $project } @list);
680 ## ----------------------------------------------------------------------
681 ## HTML aware string manipulation
686 my $add_len = shift || 10;
688 # allow only $len chars, but don't cut a word if it would fit in $add_len
689 # if it doesn't fit, cut it if it's still longer than the dots we would add
690 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@]{0,$add_len})(.*)/;
693 if (length($tail) > 4) {
695 $body =~ s/&[^;]*$//; # remove chopped character entities
700 ## ----------------------------------------------------------------------
701 ## functions returning short strings
703 # CSS class for given age value (in seconds)
707 if ($age < 60*60*2) {
709 } elsif ($age < 60*60*24*2) {
716 # convert age in seconds to "nn units ago" string
721 if ($age > 60*60*24*365*2) {
722 $age_str = (int $age/60/60/24/365);
723 $age_str .= " years ago";
724 } elsif ($age > 60*60*24*(365/12)*2) {
725 $age_str = int $age/60/60/24/(365/12);
726 $age_str .= " months ago";
727 } elsif ($age > 60*60*24*7*2) {
728 $age_str = int $age/60/60/24/7;
729 $age_str .= " weeks ago";
730 } elsif ($age > 60*60*24*2) {
731 $age_str = int $age/60/60/24;
732 $age_str .= " days ago";
733 } elsif ($age > 60*60*2) {
734 $age_str = int $age/60/60;
735 $age_str .= " hours ago";
736 } elsif ($age > 60*2) {
737 $age_str = int $age/60;
738 $age_str .= " min ago";
741 $age_str .= " sec ago";
743 $age_str .= " right now";
748 # convert file mode in octal to symbolic file mode string
750 my $mode = oct shift;
752 if (S_ISDIR
($mode & S_IFMT
)) {
754 } elsif (S_ISLNK
($mode)) {
756 } elsif (S_ISREG
($mode)) {
757 # git cares only about the executable bit
758 if ($mode & S_IXUSR
) {
768 # convert file mode in octal to file type string
772 if ($mode !~ m/^[0-7]+$/) {
778 if (S_ISDIR
($mode & S_IFMT
)) {
780 } elsif (S_ISLNK
($mode)) {
782 } elsif (S_ISREG
($mode)) {
789 # convert file mode in octal to file type description string
793 if ($mode !~ m/^[0-7]+$/) {
799 if (S_ISDIR
($mode & S_IFMT
)) {
801 } elsif (S_ISLNK
($mode)) {
803 } elsif (S_ISREG
($mode)) {
804 if ($mode & S_IXUSR
) {
815 ## ----------------------------------------------------------------------
816 ## functions returning short HTML fragments, or transforming HTML fragments
817 ## which don't beling to other sections
819 # format line of commit message.
820 sub format_log_line_html
{
823 $line = esc_html
($line, -nbsp
=>1);
824 if ($line =~ m/([0-9a-fA-F]{40})/) {
826 if (git_get_type
($hash_text) eq "commit") {
828 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$hash_text),
829 -class => "text"}, $hash_text);
830 $line =~ s/$hash_text/$link/;
836 # format marker of refs pointing to given object
837 sub format_ref_marker
{
838 my ($refs, $id) = @_;
841 if (defined $refs->{$id}) {
842 foreach my $ref (@{$refs->{$id}}) {
843 my ($type, $name) = qw();
844 # e.g. tags/v2.6.11 or heads/next
845 if ($ref =~ m!^(.*?)s?/(.*)$!) {
853 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
858 return ' <span class="refs">'. $markers . '</span>';
864 # format, perhaps shortened and with markers, title line
865 sub format_subject_html
{
866 my ($long, $short, $href, $extra) = @_;
867 $extra = '' unless defined($extra);
869 if (length($short) < length($long)) {
870 return $cgi->a({-href
=> $href, -class => "list subject",
871 -title
=> to_utf8
($long)},
872 esc_html
($short) . $extra);
874 return $cgi->a({-href
=> $href, -class => "list subject"},
875 esc_html
($long) . $extra);
879 # format patch (diff) line (rather not to be used for diff headers)
880 sub format_diff_line
{
882 my ($from, $to) = @_;
883 my $char = substr($line, 0, 1);
889 $diff_class = " add";
890 } elsif ($char eq "-") {
891 $diff_class = " rem";
892 } elsif ($char eq "@") {
893 $diff_class = " chunk_header";
894 } elsif ($char eq "\\") {
895 $diff_class = " incomplete";
897 $line = untabify
($line);
898 if ($from && $to && $line =~ m/^\@{2} /) {
899 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
900 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
902 $from_lines = 0 unless defined $from_lines;
903 $to_lines = 0 unless defined $to_lines;
905 if ($from->{'href'}) {
906 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
907 -class=>"list"}, $from_text);
910 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
911 -class=>"list"}, $to_text);
913 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
914 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
915 return "<div class=\"diff$diff_class\">$line</div>\n";
917 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
920 ## ----------------------------------------------------------------------
921 ## git utility subroutines, invoking git commands
923 # returns path to the core git executable and the --git-dir parameter as list
925 return $GIT, '--git-dir='.$git_dir;
928 # returns path to the core git executable and the --git-dir parameter as string
930 return join(' ', git_cmd
());
933 # get HEAD ref of given project as hash
934 sub git_get_head_hash
{
936 my $o_git_dir = $git_dir;
938 $git_dir = "$projectroot/$project";
939 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
942 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
946 if (defined $o_git_dir) {
947 $git_dir = $o_git_dir;
952 # get type of given object
956 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
963 sub git_get_project_config
{
964 my ($key, $type) = @_;
966 return unless ($key);
967 $key =~ s/^gitweb\.//;
968 return if ($key =~ m/\W/);
970 my @x = (git_cmd
(), 'repo-config');
971 if (defined $type) { push @x, $type; }
973 push @x, "gitweb.$key";
979 # get hash of given path at given ref
980 sub git_get_hash_by_path
{
982 my $path = shift || return undef;
987 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
988 or die_error
(undef, "Open git-ls-tree failed");
990 close $fd or return undef;
992 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
993 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
994 if (defined $type && $type ne $2) {
1001 ## ......................................................................
1002 ## git utility functions, directly accessing git repository
1004 sub git_get_project_description
{
1007 open my $fd, "$projectroot/$path/description" or return undef;
1014 sub git_get_project_url_list
{
1017 open my $fd, "$projectroot/$path/cloneurl" or return;
1018 my @git_project_url_list = map { chomp; $_ } <$fd>;
1021 return wantarray ? @git_project_url_list : \
@git_project_url_list;
1024 sub git_get_projects_list
{
1029 $filter =~ s/\.git$//;
1031 if (-d
$projects_list) {
1032 # search in directory
1033 my $dir = $projects_list . ($filter ? "/$filter" : '');
1034 # remove the trailing "/"
1036 my $pfxlen = length("$dir");
1038 my ($check_forks) = gitweb_check_feature
('forks');
1041 follow_fast
=> 1, # follow symbolic links
1042 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1044 # skip project-list toplevel, if we get it.
1045 return if (m!^[/.]$!);
1046 # only directories can be git repositories
1047 return unless (-d
$_);
1049 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1050 # we check related file in $projectroot
1051 if ($check_forks and $subdir =~ m
#/.#) {
1052 $File::Find
::prune
= 1;
1053 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1054 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
1055 $File::Find
::prune
= 1;
1060 } elsif (-f
$projects_list) {
1061 # read from file(url-encoded):
1062 # 'git%2Fgit.git Linus+Torvalds'
1063 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1064 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1065 open my ($fd), $projects_list or return;
1066 while (my $line = <$fd>) {
1068 my ($path, $owner) = split ' ', $line;
1069 $path = unescape
($path);
1070 $owner = unescape
($owner);
1071 if (!defined $path) {
1074 if ($filter ne '') {
1075 # looking for forks;
1076 my $pfx = substr($path, 0, length($filter));
1077 if ($pfx ne $filter) {
1080 my $sfx = substr($path, length($filter));
1081 if ($sfx !~ /^\/.*\
.git
$/) {
1085 if (check_export_ok
("$projectroot/$path")) {
1088 owner
=> to_utf8
($owner),
1095 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
1099 sub git_get_project_owner
{
1100 my $project = shift;
1103 return undef unless $project;
1105 # read from file (url-encoded):
1106 # 'git%2Fgit.git Linus+Torvalds'
1107 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1108 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1109 if (-f
$projects_list) {
1110 open (my $fd , $projects_list);
1111 while (my $line = <$fd>) {
1113 my ($pr, $ow) = split ' ', $line;
1114 $pr = unescape
($pr);
1115 $ow = unescape
($ow);
1116 if ($pr eq $project) {
1117 $owner = to_utf8
($ow);
1123 if (!defined $owner) {
1124 $owner = get_file_owner
("$projectroot/$project");
1130 sub git_get_last_activity
{
1134 $git_dir = "$projectroot/$path";
1135 open($fd, "-|", git_cmd
(), 'for-each-ref',
1136 '--format=%(refname) %(committer)',
1137 '--sort=-committerdate',
1138 'refs/heads') or return;
1139 my $most_recent = <$fd>;
1140 close $fd or return;
1141 if ($most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1143 my $age = time - $timestamp;
1144 return ($age, age_string
($age));
1148 sub git_get_references
{
1149 my $type = shift || "";
1151 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1152 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1153 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
1156 while (my $line = <$fd>) {
1158 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?[^\^]+)/) {
1159 if (defined $refs{$1}) {
1160 push @{$refs{$1}}, $2;
1166 close $fd or return;
1170 sub git_get_rev_name_tags
{
1171 my $hash = shift || return undef;
1173 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1175 my $name_rev = <$fd>;
1178 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1181 # catches also '$hash undefined' output
1186 ## ----------------------------------------------------------------------
1187 ## parse to hash functions
1191 my $tz = shift || "-0000";
1194 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1195 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1196 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1197 $date{'hour'} = $hour;
1198 $date{'minute'} = $min;
1199 $date{'mday'} = $mday;
1200 $date{'day'} = $days[$wday];
1201 $date{'month'} = $months[$mon];
1202 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1203 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1204 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1205 $mday, $months[$mon], $hour ,$min;
1207 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1208 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1209 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1210 $date{'hour_local'} = $hour;
1211 $date{'minute_local'} = $min;
1212 $date{'tz_local'} = $tz;
1213 $date{'iso-tz'} = sprintf ("%04d-%02d-%02d %02d:%02d:%02d %s",
1214 1900+$year, $mon+1, $mday,
1215 $hour, $min, $sec, $tz);
1224 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1225 $tag{'id'} = $tag_id;
1226 while (my $line = <$fd>) {
1228 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1229 $tag{'object'} = $1;
1230 } elsif ($line =~ m/^type (.+)$/) {
1232 } elsif ($line =~ m/^tag (.+)$/) {
1234 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1235 $tag{'author'} = $1;
1238 } elsif ($line =~ m/--BEGIN/) {
1239 push @comment, $line;
1241 } elsif ($line eq "") {
1245 push @comment, <$fd>;
1246 $tag{'comment'} = \
@comment;
1247 close $fd or return;
1248 if (!defined $tag{'name'}) {
1255 my $commit_id = shift;
1256 my $commit_text = shift;
1261 if (defined $commit_text) {
1262 @commit_lines = @$commit_text;
1265 open my $fd, "-|", git_cmd
(), "rev-list",
1266 "--header", "--parents", "--max-count=1",
1269 @commit_lines = split '\n', <$fd>;
1270 close $fd or return;
1273 my $header = shift @commit_lines;
1274 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
1277 ($co{'id'}, my @parents) = split ' ', $header;
1278 $co{'parents'} = \
@parents;
1279 $co{'parent'} = $parents[0];
1280 while (my $line = shift @commit_lines) {
1281 last if $line eq "\n";
1282 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1284 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1286 $co{'author_epoch'} = $2;
1287 $co{'author_tz'} = $3;
1288 if ($co{'author'} =~ m/^([^<]+) </) {
1289 $co{'author_name'} = $1;
1291 $co{'author_name'} = $co{'author'};
1293 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1294 $co{'committer'} = $1;
1295 $co{'committer_epoch'} = $2;
1296 $co{'committer_tz'} = $3;
1297 $co{'committer_name'} = $co{'committer'};
1298 $co{'committer_name'} =~ s/ <.*//;
1301 if (!defined $co{'tree'}) {
1305 foreach my $title (@commit_lines) {
1308 $co{'title'} = chop_str
($title, 80, 5);
1309 # remove leading stuff of merges to make the interesting part visible
1310 if (length($title) > 50) {
1311 $title =~ s/^Automatic //;
1312 $title =~ s/^merge (of|with) /Merge ... /i;
1313 if (length($title) > 50) {
1314 $title =~ s/(http|rsync):\/\///;
1316 if (length($title) > 50) {
1317 $title =~ s/(master|www|rsync)\.//;
1319 if (length($title) > 50) {
1320 $title =~ s/kernel.org:?//;
1322 if (length($title) > 50) {
1323 $title =~ s/\/pub\/scm//;
1326 $co{'title_short'} = chop_str
($title, 50, 5);
1330 if ($co{'title'} eq "") {
1331 $co{'title'} = $co{'title_short'} = '(no commit message)';
1333 # remove added spaces
1334 foreach my $line (@commit_lines) {
1337 $co{'comment'} = \
@commit_lines;
1339 my $age = time - $co{'committer_epoch'};
1341 $co{'age_string'} = age_string
($age);
1342 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1343 if ($age > 60*60*24*7*2) {
1344 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1345 $co{'age_string_age'} = $co{'age_string'};
1347 $co{'age_string_date'} = $co{'age_string'};
1348 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1353 # parse ref from ref_file, given by ref_id, with given type
1355 my $ref_file = shift;
1357 my $type = shift || git_get_type
($ref_id);
1360 $ref_item{'type'} = $type;
1361 $ref_item{'id'} = $ref_id;
1362 $ref_item{'epoch'} = 0;
1363 $ref_item{'age'} = "unknown";
1364 if ($type eq "tag") {
1365 my %tag = parse_tag
($ref_id);
1366 $ref_item{'comment'} = $tag{'comment'};
1367 if ($tag{'type'} eq "commit") {
1368 my %co = parse_commit
($tag{'object'});
1369 $ref_item{'epoch'} = $co{'committer_epoch'};
1370 $ref_item{'age'} = $co{'age_string'};
1371 } elsif (defined($tag{'epoch'})) {
1372 my $age = time - $tag{'epoch'};
1373 $ref_item{'epoch'} = $tag{'epoch'};
1374 $ref_item{'age'} = age_string
($age);
1376 $ref_item{'reftype'} = $tag{'type'};
1377 $ref_item{'name'} = $tag{'name'};
1378 $ref_item{'refid'} = $tag{'object'};
1379 } elsif ($type eq "commit"){
1380 my %co = parse_commit
($ref_id);
1381 $ref_item{'reftype'} = "commit";
1382 $ref_item{'name'} = $ref_file;
1383 $ref_item{'title'} = $co{'title'};
1384 $ref_item{'refid'} = $ref_id;
1385 $ref_item{'epoch'} = $co{'committer_epoch'};
1386 $ref_item{'age'} = $co{'age_string'};
1388 $ref_item{'reftype'} = $type;
1389 $ref_item{'name'} = $ref_file;
1390 $ref_item{'refid'} = $ref_id;
1396 # parse line of git-diff-tree "raw" output
1397 sub parse_difftree_raw_line
{
1401 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1402 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1403 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1404 $res{'from_mode'} = $1;
1405 $res{'to_mode'} = $2;
1406 $res{'from_id'} = $3;
1408 $res{'status'} = $5;
1409 $res{'similarity'} = $6;
1410 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1411 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1413 $res{'file'} = unquote
($7);
1416 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1417 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1418 $res{'commit'} = $1;
1421 return wantarray ? %res : \
%res;
1424 # parse line of git-ls-tree output
1425 sub parse_ls_tree_line
($;%) {
1430 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1431 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
1439 $res{'name'} = unquote
($4);
1442 return wantarray ? %res : \
%res;
1445 ## ......................................................................
1446 ## parse to array of hashes functions
1448 sub git_get_heads_list
{
1452 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1453 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
1454 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
1457 while (my $line = <$fd>) {
1461 my ($refinfo, $committerinfo) = split(/\0/, $line);
1462 my ($hash, $name, $title) = split(' ', $refinfo, 3);
1463 my ($committer, $epoch, $tz) =
1464 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
1465 $name =~ s!^refs/heads/!!;
1467 $ref_item{'name'} = $name;
1468 $ref_item{'id'} = $hash;
1469 $ref_item{'title'} = $title || '(no commit message)';
1470 $ref_item{'epoch'} = $epoch;
1472 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1474 $ref_item{'age'} = "unknown";
1477 push @headslist, \
%ref_item;
1481 return wantarray ? @headslist : \
@headslist;
1484 sub git_get_tags_list
{
1488 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1489 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
1490 '--format=%(objectname) %(objecttype) %(refname) '.
1491 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
1494 while (my $line = <$fd>) {
1498 my ($refinfo, $creatorinfo) = split(/\0/, $line);
1499 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
1500 my ($creator, $epoch, $tz) =
1501 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
1502 $name =~ s!^refs/tags/!!;
1504 $ref_item{'type'} = $type;
1505 $ref_item{'id'} = $id;
1506 $ref_item{'name'} = $name;
1507 if ($type eq "tag") {
1508 $ref_item{'subject'} = $title;
1509 $ref_item{'reftype'} = $reftype;
1510 $ref_item{'refid'} = $refid;
1512 $ref_item{'reftype'} = $type;
1513 $ref_item{'refid'} = $id;
1516 if ($type eq "tag" || $type eq "commit") {
1517 $ref_item{'epoch'} = $epoch;
1519 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1521 $ref_item{'age'} = "unknown";
1525 push @tagslist, \
%ref_item;
1529 return wantarray ? @tagslist : \
@tagslist;
1532 ## ----------------------------------------------------------------------
1533 ## filesystem-related functions
1535 sub get_file_owner
{
1538 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1539 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1540 if (!defined $gcos) {
1544 $owner =~ s/[,;].*$//;
1545 return to_utf8
($owner);
1548 ## ......................................................................
1549 ## mimetype related functions
1551 sub mimetype_guess_file
{
1552 my $filename = shift;
1553 my $mimemap = shift;
1554 -r
$mimemap or return undef;
1557 open(MIME
, $mimemap) or return undef;
1559 next if m/^#/; # skip comments
1560 my ($mime, $exts) = split(/\t+/);
1561 if (defined $exts) {
1562 my @exts = split(/\s+/, $exts);
1563 foreach my $ext (@exts) {
1564 $mimemap{$ext} = $mime;
1570 $filename =~ /\.([^.]*)$/;
1571 return $mimemap{$1};
1574 sub mimetype_guess
{
1575 my $filename = shift;
1577 $filename =~ /\./ or return undef;
1579 if ($mimetypes_file) {
1580 my $file = $mimetypes_file;
1581 if ($file !~ m!^/!) { # if it is relative path
1582 # it is relative to project
1583 $file = "$projectroot/$project/$file";
1585 $mime = mimetype_guess_file
($filename, $file);
1587 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1593 my $filename = shift;
1596 my $mime = mimetype_guess
($filename);
1597 $mime and return $mime;
1601 return $default_blob_plain_mimetype unless $fd;
1604 return 'text/plain' .
1605 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1606 } elsif (! $filename) {
1607 return 'application/octet-stream';
1608 } elsif ($filename =~ m/\.png$/i) {
1610 } elsif ($filename =~ m/\.gif$/i) {
1612 } elsif ($filename =~ m/\.jpe?g$/i) {
1613 return 'image/jpeg';
1615 return 'application/octet-stream';
1619 ## ======================================================================
1620 ## functions printing HTML: header, footer, error page
1622 sub git_header_html
{
1623 my $status = shift || "200 OK";
1624 my $expires = shift;
1626 my $title = "$site_name";
1627 if (defined $project) {
1628 $title .= " - $project";
1629 if (defined $action) {
1630 $title .= "/$action";
1631 if (defined $file_name) {
1632 $title .= " - " . esc_path
($file_name);
1633 if ($action eq "tree" && $file_name !~ m
|/$|) {
1640 # require explicit support from the UA if we are to send the page as
1641 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1642 # we have to do this because MSIE sometimes globs '*/*', pretending to
1643 # support xhtml+xml but choking when it gets what it asked for.
1644 if (defined $cgi->http('HTTP_ACCEPT') &&
1645 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1646 $cgi->Accept('application/xhtml+xml') != 0) {
1647 $content_type = 'application/xhtml+xml';
1649 $content_type = 'text/html';
1651 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1652 -status
=> $status, -expires
=> $expires);
1654 <?xml version="1.0" encoding="utf-8"?>
1655 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1656 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1657 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1658 <!-- git core binaries version $git_version -->
1660 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1661 <meta name="generator" content="gitweb/$version git/$git_version"/>
1662 <meta name="robots" content="index, nofollow"/>
1663 <title>$title</title>
1665 # print out each stylesheet that exist
1666 if (defined $stylesheet) {
1667 #provides backwards capability for those people who define style sheet in a config file
1668 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1670 foreach my $stylesheet (@stylesheets) {
1671 next unless $stylesheet;
1672 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1675 if (defined $project) {
1676 printf('<link rel="alternate" title="%s log" '.
1677 'href="%s" type="application/rss+xml"/>'."\n",
1678 esc_param
($project), href
(action
=>"rss"));
1680 printf('<link rel="alternate" title="%s projects list" '.
1681 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1682 $site_name, href
(project
=>undef, action
=>"project_index"));
1683 printf('<link rel="alternate" title="%s projects logs" '.
1684 'href="%s" type="text/x-opml"/>'."\n",
1685 $site_name, href
(project
=>undef, action
=>"opml"));
1687 if (defined $favicon) {
1688 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
1694 if (-f
$site_header) {
1695 open (my $fd, $site_header);
1700 print "<div class=\"page_header\">\n" .
1701 $cgi->a({-href
=> esc_url
($logo_url),
1702 -title
=> $logo_label},
1703 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
1704 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1705 if (defined $project) {
1706 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1707 if (defined $action) {
1711 if (!defined $searchtext) {
1715 if (defined $hash_base) {
1716 $search_hash = $hash_base;
1717 } elsif (defined $hash) {
1718 $search_hash = $hash;
1720 $search_hash = "HEAD";
1722 $cgi->param("a", "search");
1723 $cgi->param("h", $search_hash);
1724 $cgi->param("p", $project);
1725 print $cgi->startform(-method => "get", -action
=> $my_uri) .
1726 "<div class=\"search\">\n" .
1727 $cgi->hidden(-name
=> "p") . "\n" .
1728 $cgi->hidden(-name
=> "a") . "\n" .
1729 $cgi->hidden(-name
=> "h") . "\n" .
1730 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
1731 -values => ['commit', 'author', 'committer', 'pickaxe']) .
1732 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
1734 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1736 $cgi->end_form() . "\n";
1741 sub git_footer_html
{
1742 print "<div class=\"page_footer\">\n";
1743 if (defined $project) {
1744 my $descr = git_get_project_description
($project);
1745 if (defined $descr) {
1746 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1748 print $cgi->a({-href
=> href
(action
=>"rss"),
1749 -class => "rss_logo"}, "RSS") . "\n";
1751 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1752 -class => "rss_logo"}, "OPML") . " ";
1753 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1754 -class => "rss_logo"}, "TXT") . "\n";
1758 if (-f
$site_footer) {
1759 open (my $fd, $site_footer);
1769 my $status = shift || "403 Forbidden";
1770 my $error = shift || "Malformed query, file missing or permission denied";
1772 git_header_html
($status);
1774 <div class="page_body">
1784 ## ----------------------------------------------------------------------
1785 ## functions printing or outputting HTML: navigation
1787 sub git_print_page_nav
{
1788 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1789 $extra = '' if !defined $extra; # pager or formats
1791 my @navs = qw(summary shortlog log commit commitdiff tree);
1793 @navs = grep { $_ ne $suppress } @navs;
1796 my %arg = map { $_ => {action
=>$_} } @navs;
1797 if (defined $head) {
1798 for (qw(commit commitdiff)) {
1799 $arg{$_}{hash
} = $head;
1801 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1802 for (qw(shortlog log)) {
1803 $arg{$_}{hash
} = $head;
1807 $arg{tree
}{hash
} = $treehead if defined $treehead;
1808 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1810 print "<div class=\"page_nav\">\n" .
1812 map { $_ eq $current ?
1813 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1815 print "<br/>\n$extra<br/>\n" .
1819 sub format_paging_nav
{
1820 my ($action, $hash, $head, $page, $nrevs) = @_;
1824 if ($hash ne $head || $page) {
1825 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1827 $paging_nav .= "HEAD";
1831 $paging_nav .= " ⋅ " .
1832 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1833 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1835 $paging_nav .= " ⋅ prev";
1838 if ($nrevs >= (100 * ($page+1)-1)) {
1839 $paging_nav .= " ⋅ " .
1840 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1841 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1843 $paging_nav .= " ⋅ next";
1849 ## ......................................................................
1850 ## functions printing or outputting HTML: div
1852 sub git_print_header_div
{
1853 my ($action, $title, $hash, $hash_base) = @_;
1856 $args{action
} = $action;
1857 $args{hash
} = $hash if $hash;
1858 $args{hash_base
} = $hash_base if $hash_base;
1860 print "<div class=\"header\">\n" .
1861 $cgi->a({-href
=> href
(%args), -class => "title"},
1862 $title ? $title : $action) .
1866 #sub git_print_authorship (\%) {
1867 sub git_print_authorship
{
1870 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
1871 print "<div class=\"author_date\">" .
1872 esc_html
($co->{'author_name'}) .
1874 if ($ad{'hour_local'} < 6) {
1875 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1876 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1878 printf(" (%02d:%02d %s)",
1879 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1884 sub git_print_page_path
{
1890 print "<div class=\"page_path\">";
1891 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
1892 -title
=> 'tree root'}, "[$project]");
1894 if (defined $name) {
1895 my @dirname = split '/', $name;
1896 my $basename = pop @dirname;
1899 foreach my $dir (@dirname) {
1900 $fullname .= ($fullname ? '/' : '') . $dir;
1901 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
1903 -title
=> esc_html
($fullname)}, esc_path
($dir));
1906 if (defined $type && $type eq 'blob') {
1907 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1909 -title
=> esc_html
($name)}, esc_path
($basename));
1910 } elsif (defined $type && $type eq 'tree') {
1911 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
1913 -title
=> esc_html
($name)}, esc_path
($basename));
1916 print esc_path
($basename);
1919 print "<br/></div>\n";
1922 # sub git_print_log (\@;%) {
1923 sub git_print_log
($;%) {
1927 if ($opts{'-remove_title'}) {
1928 # remove title, i.e. first line of log
1931 # remove leading empty lines
1932 while (defined $log->[0] && $log->[0] eq "") {
1939 foreach my $line (@$log) {
1940 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1943 if (! $opts{'-remove_signoff'}) {
1944 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1947 # remove signoff lines
1954 # print only one empty line
1955 # do not print empty line after signoff
1957 next if ($empty || $signoff);
1963 print format_log_line_html
($line) . "<br/>\n";
1966 if ($opts{'-final_empty_line'}) {
1967 # end with single empty line
1968 print "<br/>\n" unless $empty;
1972 # print tree entry (row of git_tree), but without encompassing <tr> element
1973 sub git_print_tree_entry
{
1974 my ($t, $basedir, $hash_base, $have_blame) = @_;
1977 $base_key{hash_base
} = $hash_base if defined $hash_base;
1979 # The format of a table row is: mode list link. Where mode is
1980 # the mode of the entry, list is the name of the entry, an href,
1981 # and link is the action links of the entry.
1983 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
1984 if ($t->{'type'} eq "blob") {
1985 print "<td class=\"list\">" .
1986 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
1987 file_name
=>"$basedir$t->{'name'}", %base_key),
1988 -class => "list"}, esc_path
($t->{'name'})) . "</td>\n";
1989 print "<td class=\"link\">";
1990 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
1991 file_name
=>"$basedir$t->{'name'}", %base_key)},
1995 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
1996 file_name
=>"$basedir$t->{'name'}", %base_key)},
1999 if (defined $hash_base) {
2001 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2002 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2006 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2007 file_name
=>"$basedir$t->{'name'}")},
2011 } elsif ($t->{'type'} eq "tree") {
2012 print "<td class=\"list\">";
2013 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2014 file_name
=>"$basedir$t->{'name'}", %base_key)},
2015 esc_path
($t->{'name'}));
2017 print "<td class=\"link\">";
2018 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2019 file_name
=>"$basedir$t->{'name'}", %base_key)},
2021 if (defined $hash_base) {
2023 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2024 file_name
=>"$basedir$t->{'name'}")},
2031 ## ......................................................................
2032 ## functions printing large fragments of HTML
2034 sub git_difftree_body
{
2035 my ($difftree, $hash, $parent) = @_;
2036 my ($have_blame) = gitweb_check_feature
('blame');
2037 print "<div class=\"list_head\">\n";
2038 if ($#{$difftree} > 10) {
2039 print(($#{$difftree} + 1) . " files changed:\n");
2043 print "<table class=\"diff_tree\">\n";
2046 foreach my $line (@{$difftree}) {
2047 my %diff = parse_difftree_raw_line
($line);
2050 print "<tr class=\"dark\">\n";
2052 print "<tr class=\"light\">\n";
2056 my ($to_mode_oct, $to_mode_str, $to_file_type);
2057 my ($from_mode_oct, $from_mode_str, $from_file_type);
2058 if ($diff{'to_mode'} ne ('0' x
6)) {
2059 $to_mode_oct = oct $diff{'to_mode'};
2060 if (S_ISREG
($to_mode_oct)) { # only for regular file
2061 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
2063 $to_file_type = file_type
($diff{'to_mode'});
2065 if ($diff{'from_mode'} ne ('0' x
6)) {
2066 $from_mode_oct = oct $diff{'from_mode'};
2067 if (S_ISREG
($to_mode_oct)) { # only for regular file
2068 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
2070 $from_file_type = file_type
($diff{'from_mode'});
2073 if ($diff{'status'} eq "A") { # created
2074 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
2075 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
2076 $mode_chng .= "]</span>";
2078 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2079 hash_base
=>$hash, file_name
=>$diff{'file'}),
2080 -class => "list"}, esc_path
($diff{'file'}));
2082 print "<td>$mode_chng</td>\n";
2083 print "<td class=\"link\">";
2084 if ($action eq 'commitdiff') {
2087 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2091 } elsif ($diff{'status'} eq "D") { # deleted
2092 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
2094 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
2095 hash_base
=>$parent, file_name
=>$diff{'file'}),
2096 -class => "list"}, esc_path
($diff{'file'}));
2098 print "<td>$mode_chng</td>\n";
2099 print "<td class=\"link\">";
2100 if ($action eq 'commitdiff') {
2103 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2106 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
2107 hash_base
=>$parent, file_name
=>$diff{'file'})},
2110 print $cgi->a({-href
=>
2111 href
(action
=>"blame",
2113 file_name
=>$diff{'file'})},
2116 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2117 file_name
=>$diff{'file'})},
2121 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
2122 my $mode_chnge = "";
2123 if ($diff{'from_mode'} != $diff{'to_mode'}) {
2124 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
2125 if ($from_file_type != $to_file_type) {
2126 $mode_chnge .= " from $from_file_type to $to_file_type";
2128 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
2129 if ($from_mode_str && $to_mode_str) {
2130 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
2131 } elsif ($to_mode_str) {
2132 $mode_chnge .= " mode: $to_mode_str";
2135 $mode_chnge .= "]</span>\n";
2138 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2139 hash_base
=>$hash, file_name
=>$diff{'file'}),
2140 -class => "list"}, esc_path
($diff{'file'}));
2142 print "<td>$mode_chnge</td>\n";
2143 print "<td class=\"link\">";
2144 if ($action eq 'commitdiff') {
2147 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2149 } elsif ($diff{'to_id'} ne $diff{'from_id'}) {
2150 # "commit" view and modified file (not onlu mode changed)
2151 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2152 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
2153 hash_base
=>$hash, hash_parent_base
=>$parent,
2154 file_name
=>$diff{'file'})},
2158 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2159 hash_base
=>$hash, file_name
=>$diff{'file'})},
2162 print $cgi->a({-href
=> href
(action
=>"blame",
2164 file_name
=>$diff{'file'})},
2167 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2168 file_name
=>$diff{'file'})},
2172 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
2173 my %status_name = ('R' => 'moved', 'C' => 'copied');
2174 my $nstatus = $status_name{$diff{'status'}};
2176 if ($diff{'from_mode'} != $diff{'to_mode'}) {
2177 # mode also for directories, so we cannot use $to_mode_str
2178 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
2181 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2182 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
2183 -class => "list"}, esc_path
($diff{'to_file'})) . "</td>\n" .
2184 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
2185 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
2186 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
2187 -class => "list"}, esc_path
($diff{'from_file'})) .
2188 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
2189 "<td class=\"link\">";
2190 if ($action eq 'commitdiff') {
2193 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2195 } elsif ($diff{'to_id'} ne $diff{'from_id'}) {
2196 # "commit" view and modified file (not only pure rename or copy)
2197 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2198 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
2199 hash_base
=>$hash, hash_parent_base
=>$parent,
2200 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
2204 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
2205 hash_base
=>$parent, file_name
=>$diff{'from_file'})},
2208 print $cgi->a({-href
=> href
(action
=>"blame",
2210 file_name
=>$diff{'to_file'})},
2213 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2214 file_name
=>$diff{'from_file'})},
2218 } # we should not encounter Unmerged (U) or Unknown (X) status
2224 sub git_patchset_body
{
2225 my ($fd, $difftree, $hash, $hash_parent) = @_;
2231 my ($from_id, $to_id);
2233 print "<div class=\"patchset\">\n";
2235 # skip to first patch
2236 while ($patch_line = <$fd>) {
2239 last if ($patch_line =~ m/^diff /);
2243 while ($patch_line) {
2247 #assert($patch_line =~ m/^diff /) if DEBUG;
2248 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
2249 push @diff_header, $patch_line;
2251 # extended diff header
2253 while ($patch_line = <$fd>) {
2256 last EXTENDED_HEADER
if ($patch_line =~ m/^--- /);
2258 if ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2263 push @diff_header, $patch_line;
2265 #last PATCH unless $patch_line;
2266 my $last_patch_line = $patch_line;
2268 # check if current patch belong to current raw line
2269 # and parse raw git-diff line if needed
2270 if (defined $diffinfo &&
2271 $diffinfo->{'from_id'} eq $from_id &&
2272 $diffinfo->{'to_id'} eq $to_id) {
2273 # this is split patch
2274 print "<div class=\"patch cont\">\n";
2276 # advance raw git-diff output if needed
2277 $patch_idx++ if defined $diffinfo;
2279 # read and prepare patch information
2280 if (ref($difftree->[$patch_idx]) eq "HASH") {
2281 # pre-parsed (or generated by hand)
2282 $diffinfo = $difftree->[$patch_idx];
2284 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
2286 $from{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
2287 $to{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
2288 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2289 $from{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2290 hash
=>$diffinfo->{'from_id'},
2291 file_name
=>$from{'file'});
2293 if ($diffinfo->{'status'} ne "D") { # not deleted file
2294 $to{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2295 hash
=>$diffinfo->{'to_id'},
2296 file_name
=>$to{'file'});
2298 # this is first patch for raw difftree line with $patch_idx index
2299 # we index @$difftree array from 0, but number patches from 1
2300 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
2303 # print "git diff" header
2304 $patch_line = shift @diff_header;
2305 $patch_line =~ s!^(diff (.*?) )"?a/.*$!$1!;
2306 if ($from{'href'}) {
2307 $patch_line .= $cgi->a({-href
=> $from{'href'}, -class => "path"},
2308 'a/' . esc_path
($from{'file'}));
2309 } else { # file was added
2310 $patch_line .= 'a/' . esc_path
($from{'file'});
2314 $patch_line .= $cgi->a({-href
=> $to{'href'}, -class => "path"},
2315 'b/' . esc_path
($to{'file'}));
2316 } else { # file was deleted
2317 $patch_line .= 'b/' . esc_path
($to{'file'});
2319 print "<div class=\"diff header\">$patch_line</div>\n";
2321 # print extended diff header
2322 print "<div class=\"diff extended_header\">\n" if (@diff_header > 0);
2324 foreach $patch_line (@diff_header) {
2326 if ($patch_line =~ s!^((copy|rename) from ).*$!$1! && $from{'href'}) {
2327 $patch_line .= $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2328 esc_path
($from{'file'}));
2330 if ($patch_line =~ s!^((copy|rename) to ).*$!$1! && $to{'href'}) {
2331 $patch_line = $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2332 esc_path
($to{'file'}));
2335 if ($patch_line =~ m/\s(\d{6})$/) {
2336 $patch_line .= '<span class="info"> (' .
2337 file_type_long
($1) .
2341 if ($patch_line =~ m/^index/) {
2342 my ($from_link, $to_link);
2343 if ($from{'href'}) {
2344 $from_link = $cgi->a({-href
=>$from{'href'}, -class=>"hash"},
2345 substr($diffinfo->{'from_id'},0,7));
2347 $from_link = '0' x
7;
2350 $to_link = $cgi->a({-href
=>$to{'href'}, -class=>"hash"},
2351 substr($diffinfo->{'to_id'},0,7));
2356 # my ($from_hash, $to_hash) =
2357 # ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/);
2358 # my ($from_id, $to_id) =
2359 # ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2360 # ($from_hash eq $from_id) && ($to_hash eq $to_id);
2362 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2363 $patch_line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
2365 print $patch_line . "<br/>\n";
2367 print "</div>\n" if (@diff_header > 0); # class="diff extended_header"
2369 # from-file/to-file diff header
2370 $patch_line = $last_patch_line;
2371 #assert($patch_line =~ m/^---/) if DEBUG;
2372 if ($from{'href'}) {
2373 $patch_line = '--- a/' .
2374 $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2375 esc_path
($from{'file'}));
2377 print "<div class=\"diff from_file\">$patch_line</div>\n";
2379 $patch_line = <$fd>;
2380 #last PATCH unless $patch_line;
2383 #assert($patch_line =~ m/^+++/) if DEBUG;
2385 $patch_line = '+++ b/' .
2386 $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2387 esc_path
($to{'file'}));
2389 print "<div class=\"diff to_file\">$patch_line</div>\n";
2393 while ($patch_line = <$fd>) {
2396 next PATCH
if ($patch_line =~ m/^diff /);
2398 print format_diff_line
($patch_line, \
%from, \
%to);
2402 print "</div>\n"; # class="patch"
2405 print "</div>\n"; # class="patchset"
2408 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2410 sub git_project_list_body
{
2411 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
2413 my ($check_forks) = gitweb_check_feature
('forks');
2416 foreach my $pr (@$projlist) {
2417 my (@aa) = git_get_last_activity
($pr->{'path'});
2421 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
2422 if (!defined $pr->{'descr'}) {
2423 my $descr = git_get_project_description
($pr->{'path'}) || "";
2424 $pr->{'descr'} = chop_str
($descr, 25, 5);
2426 if (!defined $pr->{'owner'}) {
2427 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2430 my $pname = $pr->{'path'};
2431 if (($pname =~ s/\.git$//) &&
2432 ($pname !~ /\/$/) &&
2433 (-d
"$projectroot/$pname")) {
2434 $pr->{'forks'} = "-d $projectroot/$pname";
2440 push @projects, $pr;
2443 $order ||= "project";
2444 $from = 0 unless defined $from;
2445 $to = $#projects if (!defined $to || $#projects < $to);
2447 print "<table class=\"project_list\">\n";
2448 unless ($no_header) {
2451 print "<th></th>\n";
2453 if ($order eq "project") {
2454 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2455 print "<th>Project</th>\n";
2458 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2459 -class => "header"}, "Project") .
2462 if ($order eq "descr") {
2463 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2464 print "<th>Description</th>\n";
2467 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2468 -class => "header"}, "Description") .
2471 if ($order eq "owner") {
2472 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2473 print "<th>Owner</th>\n";
2476 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2477 -class => "header"}, "Owner") .
2480 if ($order eq "age") {
2481 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
2482 print "<th>Last Change</th>\n";
2485 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
2486 -class => "header"}, "Last Change") .
2489 print "<th></th>\n" .
2493 for (my $i = $from; $i <= $to; $i++) {
2494 my $pr = $projects[$i];
2496 print "<tr class=\"dark\">\n";
2498 print "<tr class=\"light\">\n";
2503 if ($pr->{'forks'}) {
2504 print "<!-- $pr->{'forks'} -->\n";
2505 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
2509 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2510 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2511 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
2512 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2513 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
2514 $pr->{'age_string'} . "</td>\n" .
2515 "<td class=\"link\">" .
2516 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2517 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2518 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
2519 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
2520 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
2524 if (defined $extra) {
2527 print "<td></td>\n";
2529 print "<td colspan=\"5\">$extra</td>\n" .
2535 sub git_shortlog_body
{
2536 # uses global variable $project
2537 my ($revlist, $from, $to, $refs, $extra) = @_;
2539 $from = 0 unless defined $from;
2540 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
2542 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
2544 for (my $i = $from; $i <= $to; $i++) {
2545 my $commit = $revlist->[$i];
2546 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
2547 my $ref = format_ref_marker
($refs, $commit);
2548 my %co = parse_commit
($commit);
2550 print "<tr class=\"dark\">\n";
2552 print "<tr class=\"light\">\n";
2555 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
2556 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2557 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
2559 print format_subject_html
($co{'title'}, $co{'title_short'},
2560 href
(action
=>"commit", hash
=>$commit), $ref);
2562 "<td class=\"link\">" .
2563 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
2564 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
2565 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
2566 if (gitweb_have_snapshot
()) {
2567 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
2572 if (defined $extra) {
2574 "<td colspan=\"4\">$extra</td>\n" .
2580 sub git_history_body
{
2581 # Warning: assumes constant type (blob or tree) during history
2582 my ($revlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
2584 $from = 0 unless defined $from;
2585 $to = $#{$revlist} unless (defined $to && $to <= $#{$revlist});
2587 print "<table class=\"history\" cellspacing=\"0\">\n";
2589 for (my $i = $from; $i <= $to; $i++) {
2590 if ($revlist->[$i] !~ m/^([0-9a-fA-F]{40})/) {
2595 my %co = parse_commit
($commit);
2600 my $ref = format_ref_marker
($refs, $commit);
2603 print "<tr class=\"dark\">\n";
2605 print "<tr class=\"light\">\n";
2608 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2609 # shortlog uses chop_str($co{'author_name'}, 10)
2610 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2612 # originally git_history used chop_str($co{'title'}, 50)
2613 print format_subject_html
($co{'title'}, $co{'title_short'},
2614 href
(action
=>"commit", hash
=>$commit), $ref);
2616 "<td class=\"link\">" .
2617 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
2618 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
2620 if ($ftype eq 'blob') {
2621 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
2622 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2623 if (defined $blob_current && defined $blob_parent &&
2624 $blob_current ne $blob_parent) {
2626 $cgi->a({-href
=> href
(action
=>"blobdiff",
2627 hash
=>$blob_current, hash_parent
=>$blob_parent,
2628 hash_base
=>$hash_base, hash_parent_base
=>$commit,
2629 file_name
=>$file_name)},
2636 if (defined $extra) {
2638 "<td colspan=\"4\">$extra</td>\n" .
2645 # uses global variable $project
2646 my ($taglist, $from, $to, $extra) = @_;
2647 $from = 0 unless defined $from;
2648 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2650 print "<table class=\"tags\" cellspacing=\"0\">\n";
2652 for (my $i = $from; $i <= $to; $i++) {
2653 my $entry = $taglist->[$i];
2655 my $comment = $tag{'subject'};
2657 if (defined $comment) {
2658 $comment_short = chop_str
($comment, 30, 5);
2661 print "<tr class=\"dark\">\n";
2663 print "<tr class=\"light\">\n";
2666 print "<td><i>$tag{'age'}</i></td>\n" .
2668 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
2669 -class => "list name"}, esc_html
($tag{'name'})) .
2672 if (defined $comment) {
2673 print format_subject_html
($comment, $comment_short,
2674 href
(action
=>"tag", hash
=>$tag{'id'}));
2677 "<td class=\"selflink\">";
2678 if ($tag{'type'} eq "tag") {
2679 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
2684 "<td class=\"link\">" . " | " .
2685 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
2686 if ($tag{'reftype'} eq "commit") {
2687 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
2688 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
2689 } elsif ($tag{'reftype'} eq "blob") {
2690 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
2695 if (defined $extra) {
2697 "<td colspan=\"5\">$extra</td>\n" .
2703 sub git_heads_body
{
2704 # uses global variable $project
2705 my ($headlist, $head, $from, $to, $extra) = @_;
2706 $from = 0 unless defined $from;
2707 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
2709 print "<table class=\"heads\" cellspacing=\"0\">\n";
2711 for (my $i = $from; $i <= $to; $i++) {
2712 my $entry = $headlist->[$i];
2714 my $curr = $ref{'id'} eq $head;
2716 print "<tr class=\"dark\">\n";
2718 print "<tr class=\"light\">\n";
2721 print "<td><i>$ref{'age'}</i></td>\n" .
2722 ($curr ? "<td class=\"current_head\">" : "<td>") .
2723 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
2724 -class => "list name"},esc_html
($ref{'name'})) .
2726 "<td class=\"link\">" .
2727 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
2728 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
2729 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
2733 if (defined $extra) {
2735 "<td colspan=\"3\">$extra</td>\n" .
2741 ## ======================================================================
2742 ## ======================================================================
2745 sub git_project_list
{
2746 my $order = $cgi->param('o');
2747 if (defined $order && $order !~ m/project|descr|owner|age/) {
2748 die_error
(undef, "Unknown order parameter");
2751 my @list = git_get_projects_list
();
2753 die_error
(undef, "No projects found");
2757 if (-f
$home_text) {
2758 print "<div class=\"index_include\">\n";
2759 open (my $fd, $home_text);
2764 git_project_list_body
(\
@list, $order);
2769 my $order = $cgi->param('o');
2770 if (defined $order && $order !~ m/project|descr|owner|age/) {
2771 die_error
(undef, "Unknown order parameter");
2774 my @list = git_get_projects_list
($project);
2776 die_error
(undef, "No forks found");
2780 git_print_page_nav
('','');
2781 git_print_header_div
('summary', "$project forks");
2782 git_project_list_body
(\
@list, $order);
2786 sub git_project_index
{
2787 my @projects = git_get_projects_list
($project);
2790 -type
=> 'text/plain',
2791 -charset
=> 'utf-8',
2792 -content_disposition
=> 'inline; filename="index.aux"');
2794 foreach my $pr (@projects) {
2795 if (!exists $pr->{'owner'}) {
2796 $pr->{'owner'} = get_file_owner
("$projectroot/$project");
2799 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
2800 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
2801 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2802 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2806 print "$path $owner\n";
2811 my $descr = git_get_project_description
($project) || "none";
2812 my $head = git_get_head_hash
($project);
2813 my %co = parse_commit
($head);
2814 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2816 my $owner = git_get_project_owner
($project);
2818 my $refs = git_get_references
();
2819 my @taglist = git_get_tags_list
(15);
2820 my @headlist = git_get_heads_list
(15);
2822 my ($check_forks) = gitweb_check_feature
('forks');
2825 @forklist = git_get_projects_list
($project);
2829 git_print_page_nav
('summary','', $head);
2831 print "<div class=\"title\"> </div>\n";
2832 print "<table cellspacing=\"0\">\n" .
2833 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
2834 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2835 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2836 # use per project git URL list in $projectroot/$project/cloneurl
2837 # or make project git URL from git base URL and project name
2838 my $url_tag = "URL";
2839 my @url_list = git_get_project_url_list
($project);
2840 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2841 foreach my $git_url (@url_list) {
2842 next unless $git_url;
2843 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2848 if (-s
"$projectroot/$project/README.html") {
2849 if (open my $fd, "$projectroot/$project/README.html") {
2850 print "<div class=\"title\">readme</div>\n";
2851 print $_ while (<$fd>);
2856 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=17",
2857 git_get_head_hash
($project), "--"
2858 or die_error
(undef, "Open git-rev-list failed");
2859 my @revlist = map { chomp; $_ } <$fd>;
2861 git_print_header_div
('shortlog');
2862 git_shortlog_body
(\
@revlist, 0, 15, $refs,
2863 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
2866 git_print_header_div
('tags');
2867 git_tags_body
(\
@taglist, 0, 15,
2868 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
2872 git_print_header_div
('heads');
2873 git_heads_body
(\
@headlist, $head, 0, 15,
2874 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
2878 git_print_header_div
('forks');
2879 git_project_list_body
(\
@forklist, undef, 0, 15,
2880 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
2888 my $head = git_get_head_hash
($project);
2890 git_print_page_nav
('','', $head,undef,$head);
2891 my %tag = parse_tag
($hash);
2892 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
2893 print "<div class=\"title_text\">\n" .
2894 "<table cellspacing=\"0\">\n" .
2896 "<td>object</td>\n" .
2897 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2898 $tag{'object'}) . "</td>\n" .
2899 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2900 $tag{'type'}) . "</td>\n" .
2902 if (defined($tag{'author'})) {
2903 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
2904 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
2905 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2906 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2909 print "</table>\n\n" .
2911 print "<div class=\"page_body\">";
2912 my $comment = $tag{'comment'};
2913 foreach my $line (@$comment) {
2915 print esc_html
($line) . "<br/>\n";
2925 my ($have_blame) = gitweb_check_feature
('blame');
2927 die_error
('403 Permission denied', "Permission denied");
2929 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2930 $hash_base ||= git_get_head_hash
($project);
2931 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2932 my %co = parse_commit
($hash_base)
2933 or die_error
(undef, "Reading commit failed");
2934 if (!defined $hash) {
2935 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2936 or die_error
(undef, "Error looking up file");
2938 $ftype = git_get_type
($hash);
2939 if ($ftype !~ "blob") {
2940 die_error
("400 Bad Request", "Object is not a blob");
2942 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
2943 $file_name, $hash_base)
2944 or die_error
(undef, "Open git-blame failed");
2947 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2950 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2953 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2955 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2956 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2957 git_print_page_path
($file_name, $ftype, $hash_base);
2958 my @rev_color = (qw(light2 dark2));
2959 my $num_colors = scalar(@rev_color);
2960 my $current_color = 0;
2963 <div class="page_body">
2964 <table class="blame">
2965 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2970 last unless defined $_;
2971 my ($full_rev, $orig_lineno, $lineno, $group_size) =
2972 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
2973 if (!exists $metainfo{$full_rev}) {
2974 $metainfo{$full_rev} = {};
2976 my $meta = $metainfo{$full_rev};
2979 if (/^(\S+) (.*)$/) {
2985 my $rev = substr($full_rev, 0, 8);
2986 my $author = $meta->{'author'};
2987 my %date = parse_date
($meta->{'author-time'},
2988 $meta->{'author-tz'});
2989 my $date = $date{'iso-tz'};
2991 $current_color = ++$current_color % $num_colors;
2993 print "<tr class=\"$rev_color[$current_color]\">\n";
2995 print "<td class=\"sha1\"";
2996 print " title=\"". esc_html
($author) . ", $date\"";
2997 print " rowspan=\"$group_size\"" if ($group_size > 1);
2999 print $cgi->a({-href
=> href
(action
=>"commit",
3001 file_name
=>$file_name)},
3005 my $blamed = href
(action
=> 'blame',
3006 file_name
=> $meta->{'filename'},
3007 hash_base
=> $full_rev);
3008 print "<td class=\"linenr\">";
3009 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
3011 -class => "linenr" },
3014 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
3020 or print "Reading blob failed\n";
3027 my ($have_blame) = gitweb_check_feature
('blame');
3029 die_error
('403 Permission denied', "Permission denied");
3031 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3032 $hash_base ||= git_get_head_hash
($project);
3033 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3034 my %co = parse_commit
($hash_base)
3035 or die_error
(undef, "Reading commit failed");
3036 if (!defined $hash) {
3037 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3038 or die_error
(undef, "Error lookup file");
3040 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
3041 or die_error
(undef, "Open git-annotate failed");
3044 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3047 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3050 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3052 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3053 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3054 git_print_page_path
($file_name, 'blob', $hash_base);
3055 print "<div class=\"page_body\">\n";
3057 <table class="blame">
3066 my @line_class = (qw(light dark));
3067 my $line_class_len = scalar (@line_class);
3068 my $line_class_num = $#line_class;
3069 while (my $line = <$fd>) {
3081 $line_class_num = ($line_class_num + 1) % $line_class_len;
3083 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
3090 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
3093 $short_rev = substr ($long_rev, 0, 8);
3094 $age = time () - $time;
3095 $age_str = age_string
($age);
3096 $age_str =~ s/ / /g;
3097 $age_class = age_class
($age);
3098 $author = esc_html
($author);
3099 $author =~ s/ / /g;
3101 $data = untabify
($data);
3102 $data = esc_html
($data);
3105 <tr class="$line_class[$line_class_num]">
3106 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
3107 <td class="$age_class">$age_str</td>
3109 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
3110 <td class="pre">$data</td>
3113 } # while (my $line = <$fd>)
3114 print "</table>\n\n";
3116 or print "Reading blob failed.\n";
3122 my $head = git_get_head_hash
($project);
3124 git_print_page_nav
('','', $head,undef,$head);
3125 git_print_header_div
('summary', $project);
3127 my @tagslist = git_get_tags_list
();
3129 git_tags_body
(\
@tagslist);
3135 my $head = git_get_head_hash
($project);
3137 git_print_page_nav
('','', $head,undef,$head);
3138 git_print_header_div
('summary', $project);
3140 my @headslist = git_get_heads_list
();
3142 git_heads_body
(\
@headslist, $head);
3147 sub git_blob_plain
{
3150 if (!defined $hash) {
3151 if (defined $file_name) {
3152 my $base = $hash_base || git_get_head_hash
($project);
3153 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3154 or die_error
(undef, "Error lookup file");
3156 die_error
(undef, "No file name defined");
3158 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3159 # blobs defined by non-textual hash id's can be cached
3164 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3165 or die_error
(undef, "Couldn't cat $file_name, $hash");
3167 $type ||= blob_mimetype
($fd, $file_name);
3169 # save as filename, even when no $file_name is given
3170 my $save_as = "$hash";
3171 if (defined $file_name) {
3172 $save_as = $file_name;
3173 } elsif ($type =~ m/^text\//) {
3180 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
3182 binmode STDOUT
, ':raw';
3184 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3192 if (!defined $hash) {
3193 if (defined $file_name) {
3194 my $base = $hash_base || git_get_head_hash
($project);
3195 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3196 or die_error
(undef, "Error lookup file");
3198 die_error
(undef, "No file name defined");
3200 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3201 # blobs defined by non-textual hash id's can be cached
3205 my ($have_blame) = gitweb_check_feature
('blame');
3206 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3207 or die_error
(undef, "Couldn't cat $file_name, $hash");
3208 my $mimetype = blob_mimetype
($fd, $file_name);
3209 if ($mimetype !~ m/^text\//) {
3211 return git_blob_plain
($mimetype);
3213 git_header_html
(undef, $expires);
3214 my $formats_nav = '';
3215 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3216 if (defined $file_name) {
3219 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
3220 hash
=>$hash, file_name
=>$file_name)},
3225 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3226 hash
=>$hash, file_name
=>$file_name)},
3229 $cgi->a({-href
=> href
(action
=>"blob_plain",
3230 hash
=>$hash, file_name
=>$file_name)},
3233 $cgi->a({-href
=> href
(action
=>"blob",
3234 hash_base
=>"HEAD", file_name
=>$file_name)},
3238 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
3240 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3241 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3243 print "<div class=\"page_nav\">\n" .
3244 "<br/><br/></div>\n" .
3245 "<div class=\"title\">$hash</div>\n";
3247 git_print_page_path
($file_name, "blob", $hash_base);
3248 print "<div class=\"page_body\">\n";
3250 while (my $line = <$fd>) {
3253 $line = untabify
($line);
3254 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
3255 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
3258 or print "Reading blob failed.\n";
3264 my $have_snapshot = gitweb_have_snapshot
();
3266 if (!defined $hash_base) {
3267 $hash_base = "HEAD";
3269 if (!defined $hash) {
3270 if (defined $file_name) {
3271 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
3277 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
3278 or die_error
(undef, "Open git-ls-tree failed");
3279 my @entries = map { chomp; $_ } <$fd>;
3280 close $fd or die_error
(undef, "Reading tree failed");
3283 my $refs = git_get_references
();
3284 my $ref = format_ref_marker
($refs, $hash_base);
3287 my ($have_blame) = gitweb_check_feature
('blame');
3288 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3290 if (defined $file_name) {
3292 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3293 hash
=>$hash, file_name
=>$file_name)},
3295 $cgi->a({-href
=> href
(action
=>"tree",
3296 hash_base
=>"HEAD", file_name
=>$file_name)},
3299 if ($have_snapshot) {
3300 # FIXME: Should be available when we have no hash base as well.
3302 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
3305 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
3306 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
3309 print "<div class=\"page_nav\">\n";
3310 print "<br/><br/></div>\n";
3311 print "<div class=\"title\">$hash</div>\n";
3313 if (defined $file_name) {
3314 $basedir = $file_name;
3315 if ($basedir ne '' && substr($basedir, -1) ne '/') {
3319 git_print_page_path
($file_name, 'tree', $hash_base);
3320 print "<div class=\"page_body\">\n";
3321 print "<table cellspacing=\"0\">\n";
3323 # '..' (top directory) link if possible
3324 if (defined $hash_base &&
3325 defined $file_name && $file_name =~ m![^/]+$!) {
3327 print "<tr class=\"dark\">\n";
3329 print "<tr class=\"light\">\n";
3333 my $up = $file_name;
3334 $up =~ s!/?[^/]+$!!;
3335 undef $up unless $up;
3336 # based on git_print_tree_entry
3337 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
3338 print '<td class="list">';
3339 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
3343 print "<td class=\"link\"></td>\n";
3347 foreach my $line (@entries) {
3348 my %t = parse_ls_tree_line
($line, -z
=> 1);
3351 print "<tr class=\"dark\">\n";
3353 print "<tr class=\"light\">\n";
3357 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
3361 print "</table>\n" .
3367 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
3368 my $have_snapshot = (defined $ctype && defined $suffix);
3369 if (!$have_snapshot) {
3370 die_error
('403 Permission denied', "Permission denied");
3373 if (!defined $hash) {
3374 $hash = git_get_head_hash
($project);
3377 my $filename = basename
($project) . "-$hash.tar.$suffix";
3380 -type
=> 'application/x-tar',
3381 -content_encoding
=> $ctype,
3382 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
3383 -status
=> '200 OK');
3385 my $git = git_cmd_str
();
3386 my $name = $project;
3387 $name =~ s/\047/\047\\\047\047/g;
3389 "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
3390 or die_error
(undef, "Execute git-tar-tree failed.");
3391 binmode STDOUT
, ':raw';
3393 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3399 my $head = git_get_head_hash
($project);
3400 if (!defined $hash) {
3403 if (!defined $page) {
3406 my $refs = git_get_references
();
3408 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3409 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash, "--"
3410 or die_error
(undef, "Open git-rev-list failed");
3411 my @revlist = map { chomp; $_ } <$fd>;
3414 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
3417 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
3420 my %co = parse_commit
($hash);
3422 git_print_header_div
('summary', $project);
3423 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
3425 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
3426 my $commit = $revlist[$i];
3427 my $ref = format_ref_marker
($refs, $commit);
3428 my %co = parse_commit
($commit);
3430 my %ad = parse_date
($co{'author_epoch'});
3431 git_print_header_div
('commit',
3432 "<span class=\"age\">$co{'age_string'}</span>" .
3433 esc_html
($co{'title'}) . $ref,
3435 print "<div class=\"title_text\">\n" .
3436 "<div class=\"log_link\">\n" .
3437 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
3439 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
3441 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
3444 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
3447 print "<div class=\"log_body\">\n";
3448 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
3455 $hash ||= $hash_base || "HEAD";
3456 my %co = parse_commit
($hash);
3458 die_error
(undef, "Unknown commit object");
3460 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3461 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
3463 my $parent = $co{'parent'};
3464 if (!defined $parent) {
3467 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
3468 @diff_opts, $parent, $hash, "--"
3469 or die_error
(undef, "Open git-diff-tree failed");
3470 my @difftree = map { chomp; $_ } <$fd>;
3471 close $fd or die_error
(undef, "Reading git-diff-tree failed");
3473 # non-textual hash id's can be cached
3475 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3478 my $refs = git_get_references
();
3479 my $ref = format_ref_marker
($refs, $co{'id'});
3481 my $have_snapshot = gitweb_have_snapshot
();
3484 if (defined $file_name && defined $co{'parent'}) {
3486 $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)},
3489 git_header_html
(undef, $expires);
3490 git_print_page_nav
('commit', '',
3491 $hash, $co{'tree'}, $hash,
3492 join (' | ', @views_nav));
3494 if (defined $co{'parent'}) {
3495 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
3497 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
3499 print "<div class=\"title_text\">\n" .
3500 "<table cellspacing=\"0\">\n";
3501 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
3503 "<td></td><td> $ad{'rfc2822'}";
3504 if ($ad{'hour_local'} < 6) {
3505 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3506 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3508 printf(" (%02d:%02d %s)",
3509 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3513 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
3514 print "<tr><td></td><td> $cd{'rfc2822'}" .
3515 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
3517 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
3520 "<td class=\"sha1\">" .
3521 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
3522 class => "list"}, $co{'tree'}) .
3524 "<td class=\"link\">" .
3525 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
3527 if ($have_snapshot) {
3529 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
3533 my $parents = $co{'parents'};
3534 foreach my $par (@$parents) {
3537 "<td class=\"sha1\">" .
3538 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
3539 class => "list"}, $par) .
3541 "<td class=\"link\">" .
3542 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
3544 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
3551 print "<div class=\"page_body\">\n";
3552 git_print_log
($co{'comment'});
3555 git_difftree_body
(\
@difftree, $hash, $parent);
3561 my $format = shift || 'html';
3568 # preparing $fd and %diffinfo for git_patchset_body
3570 if (defined $hash_base && defined $hash_parent_base) {
3571 if (defined $file_name) {
3573 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3574 $hash_parent_base, $hash_base,
3576 or die_error
(undef, "Open git-diff-tree failed");
3577 @difftree = map { chomp; $_ } <$fd>;
3579 or die_error
(undef, "Reading git-diff-tree failed");
3581 or die_error
('404 Not Found', "Blob diff not found");
3583 } elsif (defined $hash &&
3584 $hash =~ /[0-9a-fA-F]{40}/) {
3585 # try to find filename from $hash
3587 # read filtered raw output
3588 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3589 $hash_parent_base, $hash_base, "--"
3590 or die_error
(undef, "Open git-diff-tree failed");
3592 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
3594 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
3595 map { chomp; $_ } <$fd>;
3597 or die_error
(undef, "Reading git-diff-tree failed");
3599 or die_error
('404 Not Found', "Blob diff not found");
3602 die_error
('404 Not Found', "Missing one of the blob diff parameters");
3605 if (@difftree > 1) {
3606 die_error
('404 Not Found', "Ambiguous blob diff specification");
3609 %diffinfo = parse_difftree_raw_line
($difftree[0]);
3610 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
3611 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
3613 $hash_parent ||= $diffinfo{'from_id'};
3614 $hash ||= $diffinfo{'to_id'};
3616 # non-textual hash id's can be cached
3617 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
3618 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
3623 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3624 '-p', $hash_parent_base, $hash_base,
3626 or die_error
(undef, "Open git-diff-tree failed");
3629 # old/legacy style URI
3630 if (!%diffinfo && # if new style URI failed
3631 defined $hash && defined $hash_parent) {
3632 # fake git-diff-tree raw output
3633 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
3634 $diffinfo{'from_id'} = $hash_parent;
3635 $diffinfo{'to_id'} = $hash;
3636 if (defined $file_name) {
3637 if (defined $file_parent) {
3638 $diffinfo{'status'} = '2';
3639 $diffinfo{'from_file'} = $file_parent;
3640 $diffinfo{'to_file'} = $file_name;
3641 } else { # assume not renamed
3642 $diffinfo{'status'} = '1';
3643 $diffinfo{'from_file'} = $file_name;
3644 $diffinfo{'to_file'} = $file_name;
3646 } else { # no filename given
3647 $diffinfo{'status'} = '2';
3648 $diffinfo{'from_file'} = $hash_parent;
3649 $diffinfo{'to_file'} = $hash;
3652 # non-textual hash id's can be cached
3653 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
3654 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3659 open $fd, "-|", git_cmd
(), "diff", '-p', @diff_opts,
3660 $hash_parent, $hash, "--"
3661 or die_error
(undef, "Open git-diff failed");
3663 die_error
('404 Not Found', "Missing one of the blob diff parameters")
3668 if ($format eq 'html') {
3670 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
3671 hash
=>$hash, hash_parent
=>$hash_parent,
3672 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
3673 file_name
=>$file_name, file_parent
=>$file_parent)},
3675 git_header_html
(undef, $expires);
3676 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3677 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3678 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3680 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
3681 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
3683 if (defined $file_name) {
3684 git_print_page_path
($file_name, "blob", $hash_base);
3686 print "<div class=\"page_path\"></div>\n";
3689 } elsif ($format eq 'plain') {
3691 -type
=> 'text/plain',
3692 -charset
=> 'utf-8',
3693 -expires
=> $expires,
3694 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
3696 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3699 die_error
(undef, "Unknown blobdiff format");
3703 if ($format eq 'html') {
3704 print "<div class=\"page_body\">\n";
3706 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
3709 print "</div>\n"; # class="page_body"
3713 while (my $line = <$fd>) {
3714 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
3715 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
3719 last if $line =~ m!^\+\+\+!;
3727 sub git_blobdiff_plain
{
3728 git_blobdiff
('plain');
3731 sub git_commitdiff
{
3732 my $format = shift || 'html';
3733 $hash ||= $hash_base || "HEAD";
3734 my %co = parse_commit
($hash);
3736 die_error
(undef, "Unknown commit object");
3739 # we need to prepare $formats_nav before any parameter munging
3741 if ($format eq 'html') {
3743 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
3744 hash
=>$hash, hash_parent
=>$hash_parent)},
3747 if (defined $hash_parent) {
3748 # commitdiff with two commits given
3749 my $hash_parent_short = $hash_parent;
3750 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3751 $hash_parent_short = substr($hash_parent, 0, 7);
3755 $cgi->a({-href
=> href
(action
=>"commitdiff",
3756 hash
=>$hash_parent)},
3757 esc_html
($hash_parent_short)) .
3759 } elsif (!$co{'parent'}) {
3761 $formats_nav .= ' (initial)';
3762 } elsif (scalar @{$co{'parents'}} == 1) {
3763 # single parent commit
3766 $cgi->a({-href
=> href
(action
=>"commitdiff",
3767 hash
=>$co{'parent'})},
3768 esc_html
(substr($co{'parent'}, 0, 7))) .
3775 $cgi->a({-href
=> href
(action
=>"commitdiff",
3777 esc_html
(substr($_, 0, 7)));
3778 } @{$co{'parents'}} ) .
3783 if (!defined $hash_parent) {
3784 $hash_parent = $co{'parent'} || '--root';
3790 if ($format eq 'html') {
3791 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3792 "--no-commit-id", "--patch-with-raw", "--full-index",
3793 $hash_parent, $hash, "--"
3794 or die_error
(undef, "Open git-diff-tree failed");
3796 while (my $line = <$fd>) {
3798 # empty line ends raw part of diff-tree output
3800 push @difftree, $line;
3803 } elsif ($format eq 'plain') {
3804 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3805 '-p', $hash_parent, $hash, "--"
3806 or die_error
(undef, "Open git-diff-tree failed");
3809 die_error
(undef, "Unknown commitdiff format");
3812 # non-textual hash id's can be cached
3814 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3818 # write commit message
3819 if ($format eq 'html') {
3820 my $refs = git_get_references
();
3821 my $ref = format_ref_marker
($refs, $co{'id'});
3823 git_header_html
(undef, $expires);
3824 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
3825 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
3826 git_print_authorship
(\
%co);
3827 print "<div class=\"page_body\">\n";
3828 if (@{$co{'comment'}} > 1) {
3829 print "<div class=\"log\">\n";
3830 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
3831 print "</div>\n"; # class="log"
3834 } elsif ($format eq 'plain') {
3835 my $refs = git_get_references
("tags");
3836 my $tagname = git_get_rev_name_tags
($hash);
3837 my $filename = basename
($project) . "-$hash.patch";
3840 -type
=> 'text/plain',
3841 -charset
=> 'utf-8',
3842 -expires
=> $expires,
3843 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
3844 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3847 Date: $ad{'rfc2822'} ($ad{'tz_local'})
3848 Subject: $co{'title'}
3850 print "X-Git-Tag: $tagname\n" if $tagname;
3851 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3853 foreach my $line (@{$co{'comment'}}) {
3860 if ($format eq 'html') {
3861 git_difftree_body
(\
@difftree, $hash, $hash_parent);
3864 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
3866 print "</div>\n"; # class="page_body"
3869 } elsif ($format eq 'plain') {
3873 or print "Reading git-diff-tree failed\n";
3877 sub git_commitdiff_plain
{
3878 git_commitdiff
('plain');
3882 if (!defined $hash_base) {
3883 $hash_base = git_get_head_hash
($project);
3885 if (!defined $page) {
3889 my %co = parse_commit
($hash_base);
3891 die_error
(undef, "Unknown commit object");
3894 my $refs = git_get_references
();
3895 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3897 if (!defined $hash && defined $file_name) {
3898 $hash = git_get_hash_by_path
($hash_base, $file_name);
3900 if (defined $hash) {
3901 $ftype = git_get_type
($hash);
3905 git_cmd
(), "rev-list", $limit, "--full-history", $hash_base, "--", $file_name
3906 or die_error
(undef, "Open git-rev-list-failed");
3907 my @revlist = map { chomp; $_ } <$fd>;
3909 or die_error
(undef, "Reading git-rev-list failed");
3911 my $paging_nav = '';
3914 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3915 file_name
=>$file_name)},
3917 $paging_nav .= " ⋅ " .
3918 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3919 file_name
=>$file_name, page
=>$page-1),
3920 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3922 $paging_nav .= "first";
3923 $paging_nav .= " ⋅ prev";
3925 if ($#revlist >= (100 * ($page+1)-1)) {
3926 $paging_nav .= " ⋅ " .
3927 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3928 file_name
=>$file_name, page
=>$page+1),
3929 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3931 $paging_nav .= " ⋅ next";
3934 if ($#revlist >= (100 * ($page+1)-1)) {
3936 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3937 file_name
=>$file_name, page
=>$page+1),
3938 -title
=> "Alt-n"}, "next");
3942 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
3943 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3944 git_print_page_path
($file_name, $ftype, $hash_base);
3946 git_history_body
(\
@revlist, ($page * 100), $#revlist,
3947 $refs, $hash_base, $ftype, $next_link);
3953 if (!defined $searchtext) {
3954 die_error
(undef, "Text field empty");
3956 if (!defined $hash) {
3957 $hash = git_get_head_hash
($project);
3959 my %co = parse_commit
($hash);
3961 die_error
(undef, "Unknown commit object");
3964 $searchtype ||= 'commit';
3965 if ($searchtype eq 'pickaxe') {
3966 # pickaxe may take all resources of your box and run for several minutes
3967 # with every query - so decide by yourself how public you make this feature
3968 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
3969 if (!$have_pickaxe) {
3970 die_error
('403 Permission denied', "Permission denied");
3975 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
3976 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
3978 print "<table cellspacing=\"0\">\n";
3980 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
3982 open my $fd, "-|", git_cmd
(), "rev-list",
3983 "--header", "--parents", $hash, "--"
3985 while (my $commit_text = <$fd>) {
3986 if (!grep m/$searchtext/i, $commit_text) {
3989 if ($searchtype eq 'author' && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3992 if ($searchtype eq 'committer' && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3995 my @commit_lines = split "\n", $commit_text;
3996 my %co = parse_commit
(undef, \
@commit_lines);
4001 print "<tr class=\"dark\">\n";
4003 print "<tr class=\"light\">\n";
4006 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4007 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
4009 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
4010 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
4011 my $comment = $co{'comment'};
4012 foreach my $line (@$comment) {
4013 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
4014 my $lead = esc_html
($1) || "";
4015 $lead = chop_str
($lead, 30, 10);
4016 my $match = esc_html
($2) || "";
4017 my $trail = esc_html
($3) || "";
4018 $trail = chop_str
($trail, 30, 10);
4019 my $text = "$lead<span class=\"match\">$match</span>$trail";
4020 print chop_str
($text, 80, 5) . "<br/>\n";
4024 "<td class=\"link\">" .
4025 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4027 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4034 if ($searchtype eq 'pickaxe') {
4036 my $git_command = git_cmd_str
();
4037 open my $fd, "-|", "$git_command rev-list $hash | " .
4038 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
4041 while (my $line = <$fd>) {
4042 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
4045 $set{'from_id'} = $3;
4047 $set{'id'} = $set{'to_id'};
4048 if ($set{'id'} =~ m/0{40}/) {
4049 $set{'id'} = $set{'from_id'};
4051 if ($set{'id'} =~ m/0{40}/) {
4055 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
4058 print "<tr class=\"dark\">\n";
4060 print "<tr class=\"light\">\n";
4063 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4064 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
4066 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4067 -class => "list subject"},
4068 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
4069 while (my $setref = shift @files) {
4071 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
4072 hash
=>$set{'id'}, file_name
=>$set{'file'}),
4074 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
4078 "<td class=\"link\">" .
4079 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4081 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4085 %co = parse_commit
($1);
4094 sub git_search_help
{
4096 git_print_page_nav
('','', $hash,$hash,$hash);
4099 <dt><b>commit</b></dt>
4100 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
4101 <dt><b>author</b></dt>
4102 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
4103 <dt><b>committer</b></dt>
4104 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
4106 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4107 if ($have_pickaxe) {
4109 <dt><b>pickaxe</b></dt>
4110 <dd>All commits that caused the string to appear or disappear from any file (changes that
4111 added, removed or "modified" the string) will be listed. This search can take a while and
4112 takes a lot of strain on the server, so please use it wisely.</dd>
4120 my $head = git_get_head_hash
($project);
4121 if (!defined $hash) {
4124 if (!defined $page) {
4127 my $refs = git_get_references
();
4129 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
4130 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash, "--"
4131 or die_error
(undef, "Open git-rev-list failed");
4132 my @revlist = map { chomp; $_ } <$fd>;
4135 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
4137 if ($#revlist >= (100 * ($page+1)-1)) {
4139 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
4140 -title
=> "Alt-n"}, "next");
4145 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
4146 git_print_header_div
('summary', $project);
4148 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
4153 ## ......................................................................
4154 ## feeds (RSS, OPML)
4157 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
4158 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=150",
4159 git_get_head_hash
($project), "--"
4160 or die_error
(undef, "Open git-rev-list failed");
4161 my @revlist = map { chomp; $_ } <$fd>;
4162 close $fd or die_error
(undef, "Reading git-rev-list failed");
4163 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
4165 <?xml version="1.0" encoding="utf-8"?>
4166 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
4168 <title>$project $my_uri $my_url</title>
4169 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
4170 <description>$project log</description>
4171 <language>en</language>
4174 for (my $i = 0; $i <= $#revlist; $i++) {
4175 my $commit = $revlist[$i];
4176 my %co = parse_commit
($commit);
4177 # we read 150, we always show 30 and the ones more recent than 48 hours
4178 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
4181 my %cd = parse_date
($co{'committer_epoch'});
4182 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4183 $co{'parent'}, $co{'id'}, "--"
4185 my @difftree = map { chomp; $_ } <$fd>;
4190 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
4192 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
4193 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
4194 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
4195 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
4196 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
4197 "<content:encoded>" .
4199 my $comment = $co{'comment'};
4200 foreach my $line (@$comment) {
4201 $line = to_utf8
($line);
4202 print "$line<br/>\n";
4205 foreach my $line (@difftree) {
4206 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
4209 my $file = esc_path
(unquote
($7));
4210 $file = to_utf8
($file);
4211 print "$file<br/>\n";
4214 "</content:encoded>\n" .
4217 print "</channel></rss>";
4221 my @list = git_get_projects_list
();
4223 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
4225 <?xml version="1.0" encoding="utf-8"?>
4226 <opml version="1.0">
4228 <title>$site_name OPML Export</title>
4231 <outline text="git RSS feeds">
4234 foreach my $pr (@list) {
4236 my $head = git_get_head_hash
($proj{'path'});
4237 if (!defined $head) {
4240 $git_dir = "$projectroot/$proj{'path'}";
4241 my %co = parse_commit
($head);
4246 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
4247 my $rss = "$my_url?p=$proj{'path'};a=rss";
4248 my $html = "$my_url?p=$proj{'path'};a=summary";
4249 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";