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 "atom" => \
&git_atom
,
430 "search" => \
&git_search
,
431 "search_help" => \
&git_search_help
,
432 "shortlog" => \
&git_shortlog
,
433 "summary" => \
&git_summary
,
435 "tags" => \
&git_tags
,
436 "tree" => \
&git_tree
,
437 "snapshot" => \
&git_snapshot
,
438 # those below don't need $project
439 "opml" => \
&git_opml
,
440 "project_list" => \
&git_project_list
,
441 "project_index" => \
&git_project_index
,
444 if (defined $project) {
445 $action ||= 'summary';
447 $action ||= 'project_list';
449 if (!defined($actions{$action})) {
450 die_error
(undef, "Unknown action");
452 if ($action !~ m/^(opml|project_list|project_index)$/ &&
454 die_error
(undef, "Project needed");
456 $actions{$action}->();
459 ## ======================================================================
464 # default is to use -absolute url() i.e. $my_uri
465 my $href = $params{-full
} ? $my_url : $my_uri;
467 # XXX: Warning: If you touch this, check the search form for updating,
478 hash_parent_base
=> "hpb",
484 my %mapping = @mapping;
486 $params{'project'} = $project unless exists $params{'project'};
488 my ($use_pathinfo) = gitweb_check_feature
('pathinfo');
490 # use PATH_INFO for project name
491 $href .= "/$params{'project'}" if defined $params{'project'};
492 delete $params{'project'};
494 # Summary just uses the project path URL
495 if (defined $params{'action'} && $params{'action'} eq 'summary') {
496 delete $params{'action'};
500 # now encode the parameters explicitly
502 for (my $i = 0; $i < @mapping; $i += 2) {
503 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
504 if (defined $params{$name}) {
505 push @result, $symbol . "=" . esc_param
($params{$name});
508 $href .= "?" . join(';', @result) if scalar @result;
514 ## ======================================================================
515 ## validation, quoting/unquoting and escaping
517 sub validate_pathname
{
518 my $input = shift || return undef;
520 # no '.' or '..' as elements of path, i.e. no '.' nor '..'
521 # at the beginning, at the end, and between slashes.
522 # also this catches doubled slashes
523 if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
527 if ($input =~ m!\0!) {
533 sub validate_refname
{
534 my $input = shift || return undef;
536 # textual hashes are O.K.
537 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
540 # it must be correct pathname
541 $input = validate_pathname
($input)
543 # restrictions on ref name according to git-check-ref-format
544 if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
550 # very thin wrapper for decode("utf8", $str, Encode::FB_DEFAULT);
553 return decode
("utf8", $str, Encode
::FB_DEFAULT
);
556 # quote unsafe chars, but keep the slash, even when it's not
557 # correct, but quoted slashes look too horrible in bookmarks
560 $str =~ s/([^A-Za-z0-9\-_.~()\/:@])/sprintf
("%%%02X", ord($1))/eg
;
566 # quote unsafe chars in whole URL, so some charactrs cannot be quoted
569 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
575 # replace invalid utf8 character with SUBSTITUTION sequence
580 $str = to_utf8
($str);
581 $str = escapeHTML
($str);
582 if ($opts{'-nbsp'}) {
583 $str =~ s/ / /g;
585 $str =~ s
|([[:cntrl
:]])|(($1 ne "\t") ? quot_cec
($1) : $1)|eg
;
589 # Make control characterss "printable".
592 my %es = ( # character escape codes, aka escape sequences
593 "\t" => '\t', # tab (HT)
594 "\n" => '\n', # line feed (LF)
595 "\r" => '\r', # carrige return (CR)
596 "\f" => '\f', # form feed (FF)
597 "\b" => '\b', # backspace (BS)
598 "\a" => '\a', # alarm (bell) (BEL)
599 "\e" => '\e', # escape (ESC)
600 "\013" => '\v', # vertical tab (VT)
601 "\000" => '\0', # nul character (NUL)
603 my $chr = ( (exists $es{$cntrl})
605 : sprintf('\%03o', ord($cntrl)) );
606 return "<span class=\"cntrl\">$chr</span>";
609 # Alternatively use unicode control pictures codepoints.
612 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
613 return "<span class=\"cntrl\">$chr</span>";
616 # quote control characters and escape filename to HTML
620 $str = esc_html
($str);
621 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
625 # git may return quoted and escaped filenames
631 my %es = ( # character escape codes, aka escape sequences
632 't' => "\t", # tab (HT, TAB)
633 'n' => "\n", # newline (NL)
634 'r' => "\r", # return (CR)
635 'f' => "\f", # form feed (FF)
636 'b' => "\b", # backspace (BS)
637 'a' => "\a", # alarm (bell) (BEL)
638 'e' => "\e", # escape (ESC)
639 'v' => "\013", # vertical tab (VT)
642 if ($seq =~ m/^[0-7]{1,3}$/) {
643 # octal char sequence
644 return chr(oct($seq));
645 } elsif (exists $es{$seq}) {
646 # C escape sequence, aka character escape code
649 # quoted ordinary character
653 if ($str =~ m/^"(.*)"$/) {
656 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
661 # escape tabs (convert tabs to spaces)
665 while ((my $pos = index($line, "\t")) != -1) {
666 if (my $count = (8 - ($pos % 8))) {
667 my $spaces = ' ' x
$count;
668 $line =~ s/\t/$spaces/;
675 sub project_in_list
{
677 my @list = git_get_projects_list
();
678 return @list && scalar(grep { $_->{'path'} eq $project } @list);
681 ## ----------------------------------------------------------------------
682 ## HTML aware string manipulation
687 my $add_len = shift || 10;
689 # allow only $len chars, but don't cut a word if it would fit in $add_len
690 # if it doesn't fit, cut it if it's still longer than the dots we would add
691 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@]{0,$add_len})(.*)/;
694 if (length($tail) > 4) {
696 $body =~ s/&[^;]*$//; # remove chopped character entities
701 ## ----------------------------------------------------------------------
702 ## functions returning short strings
704 # CSS class for given age value (in seconds)
708 if ($age < 60*60*2) {
710 } elsif ($age < 60*60*24*2) {
717 # convert age in seconds to "nn units ago" string
722 if ($age > 60*60*24*365*2) {
723 $age_str = (int $age/60/60/24/365);
724 $age_str .= " years ago";
725 } elsif ($age > 60*60*24*(365/12)*2) {
726 $age_str = int $age/60/60/24/(365/12);
727 $age_str .= " months ago";
728 } elsif ($age > 60*60*24*7*2) {
729 $age_str = int $age/60/60/24/7;
730 $age_str .= " weeks ago";
731 } elsif ($age > 60*60*24*2) {
732 $age_str = int $age/60/60/24;
733 $age_str .= " days ago";
734 } elsif ($age > 60*60*2) {
735 $age_str = int $age/60/60;
736 $age_str .= " hours ago";
737 } elsif ($age > 60*2) {
738 $age_str = int $age/60;
739 $age_str .= " min ago";
742 $age_str .= " sec ago";
744 $age_str .= " right now";
749 # convert file mode in octal to symbolic file mode string
751 my $mode = oct shift;
753 if (S_ISDIR
($mode & S_IFMT
)) {
755 } elsif (S_ISLNK
($mode)) {
757 } elsif (S_ISREG
($mode)) {
758 # git cares only about the executable bit
759 if ($mode & S_IXUSR
) {
769 # convert file mode in octal to file type string
773 if ($mode !~ m/^[0-7]+$/) {
779 if (S_ISDIR
($mode & S_IFMT
)) {
781 } elsif (S_ISLNK
($mode)) {
783 } elsif (S_ISREG
($mode)) {
790 # convert file mode in octal to file type description string
794 if ($mode !~ m/^[0-7]+$/) {
800 if (S_ISDIR
($mode & S_IFMT
)) {
802 } elsif (S_ISLNK
($mode)) {
804 } elsif (S_ISREG
($mode)) {
805 if ($mode & S_IXUSR
) {
816 ## ----------------------------------------------------------------------
817 ## functions returning short HTML fragments, or transforming HTML fragments
818 ## which don't beling to other sections
820 # format line of commit message.
821 sub format_log_line_html
{
824 $line = esc_html
($line, -nbsp
=>1);
825 if ($line =~ m/([0-9a-fA-F]{40})/) {
827 if (git_get_type
($hash_text) eq "commit") {
829 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$hash_text),
830 -class => "text"}, $hash_text);
831 $line =~ s/$hash_text/$link/;
837 # format marker of refs pointing to given object
838 sub format_ref_marker
{
839 my ($refs, $id) = @_;
842 if (defined $refs->{$id}) {
843 foreach my $ref (@{$refs->{$id}}) {
844 my ($type, $name) = qw();
845 # e.g. tags/v2.6.11 or heads/next
846 if ($ref =~ m!^(.*?)s?/(.*)$!) {
854 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
859 return ' <span class="refs">'. $markers . '</span>';
865 # format, perhaps shortened and with markers, title line
866 sub format_subject_html
{
867 my ($long, $short, $href, $extra) = @_;
868 $extra = '' unless defined($extra);
870 if (length($short) < length($long)) {
871 return $cgi->a({-href
=> $href, -class => "list subject",
872 -title
=> to_utf8
($long)},
873 esc_html
($short) . $extra);
875 return $cgi->a({-href
=> $href, -class => "list subject"},
876 esc_html
($long) . $extra);
880 # format patch (diff) line (rather not to be used for diff headers)
881 sub format_diff_line
{
883 my ($from, $to) = @_;
884 my $char = substr($line, 0, 1);
890 $diff_class = " add";
891 } elsif ($char eq "-") {
892 $diff_class = " rem";
893 } elsif ($char eq "@") {
894 $diff_class = " chunk_header";
895 } elsif ($char eq "\\") {
896 $diff_class = " incomplete";
898 $line = untabify
($line);
899 if ($from && $to && $line =~ m/^\@{2} /) {
900 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
901 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
903 $from_lines = 0 unless defined $from_lines;
904 $to_lines = 0 unless defined $to_lines;
906 if ($from->{'href'}) {
907 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
908 -class=>"list"}, $from_text);
911 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
912 -class=>"list"}, $to_text);
914 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
915 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
916 return "<div class=\"diff$diff_class\">$line</div>\n";
918 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
921 ## ----------------------------------------------------------------------
922 ## git utility subroutines, invoking git commands
924 # returns path to the core git executable and the --git-dir parameter as list
926 return $GIT, '--git-dir='.$git_dir;
929 # returns path to the core git executable and the --git-dir parameter as string
931 return join(' ', git_cmd
());
934 # get HEAD ref of given project as hash
935 sub git_get_head_hash
{
937 my $o_git_dir = $git_dir;
939 $git_dir = "$projectroot/$project";
940 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
943 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
947 if (defined $o_git_dir) {
948 $git_dir = $o_git_dir;
953 # get type of given object
957 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
964 sub git_get_project_config
{
965 my ($key, $type) = @_;
967 return unless ($key);
968 $key =~ s/^gitweb\.//;
969 return if ($key =~ m/\W/);
971 my @x = (git_cmd
(), 'repo-config');
972 if (defined $type) { push @x, $type; }
974 push @x, "gitweb.$key";
980 # get hash of given path at given ref
981 sub git_get_hash_by_path
{
983 my $path = shift || return undef;
988 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
989 or die_error
(undef, "Open git-ls-tree failed");
991 close $fd or return undef;
993 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
994 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
995 if (defined $type && $type ne $2) {
1002 ## ......................................................................
1003 ## git utility functions, directly accessing git repository
1005 sub git_get_project_description
{
1008 open my $fd, "$projectroot/$path/description" or return undef;
1015 sub git_get_project_url_list
{
1018 open my $fd, "$projectroot/$path/cloneurl" or return;
1019 my @git_project_url_list = map { chomp; $_ } <$fd>;
1022 return wantarray ? @git_project_url_list : \
@git_project_url_list;
1025 sub git_get_projects_list
{
1030 $filter =~ s/\.git$//;
1032 if (-d
$projects_list) {
1033 # search in directory
1034 my $dir = $projects_list . ($filter ? "/$filter" : '');
1035 # remove the trailing "/"
1037 my $pfxlen = length("$dir");
1039 my ($check_forks) = gitweb_check_feature
('forks');
1042 follow_fast
=> 1, # follow symbolic links
1043 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1045 # skip project-list toplevel, if we get it.
1046 return if (m!^[/.]$!);
1047 # only directories can be git repositories
1048 return unless (-d
$_);
1050 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1051 # we check related file in $projectroot
1052 if ($check_forks and $subdir =~ m
#/.#) {
1053 $File::Find
::prune
= 1;
1054 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1055 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
1056 $File::Find
::prune
= 1;
1061 } elsif (-f
$projects_list) {
1062 # read from file(url-encoded):
1063 # 'git%2Fgit.git Linus+Torvalds'
1064 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1065 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1066 open my ($fd), $projects_list or return;
1067 while (my $line = <$fd>) {
1069 my ($path, $owner) = split ' ', $line;
1070 $path = unescape
($path);
1071 $owner = unescape
($owner);
1072 if (!defined $path) {
1075 if ($filter ne '') {
1076 # looking for forks;
1077 my $pfx = substr($path, 0, length($filter));
1078 if ($pfx ne $filter) {
1081 my $sfx = substr($path, length($filter));
1082 if ($sfx !~ /^\/.*\
.git
$/) {
1086 if (check_export_ok
("$projectroot/$path")) {
1089 owner
=> to_utf8
($owner),
1096 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
1100 sub git_get_project_owner
{
1101 my $project = shift;
1104 return undef unless $project;
1106 # read from file (url-encoded):
1107 # 'git%2Fgit.git Linus+Torvalds'
1108 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1109 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1110 if (-f
$projects_list) {
1111 open (my $fd , $projects_list);
1112 while (my $line = <$fd>) {
1114 my ($pr, $ow) = split ' ', $line;
1115 $pr = unescape
($pr);
1116 $ow = unescape
($ow);
1117 if ($pr eq $project) {
1118 $owner = to_utf8
($ow);
1124 if (!defined $owner) {
1125 $owner = get_file_owner
("$projectroot/$project");
1131 sub git_get_last_activity
{
1135 $git_dir = "$projectroot/$path";
1136 open($fd, "-|", git_cmd
(), 'for-each-ref',
1137 '--format=%(refname) %(committer)',
1138 '--sort=-committerdate',
1139 'refs/heads') or return;
1140 my $most_recent = <$fd>;
1141 close $fd or return;
1142 if ($most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1144 my $age = time - $timestamp;
1145 return ($age, age_string
($age));
1149 sub git_get_references
{
1150 my $type = shift || "";
1152 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1153 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1154 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
1157 while (my $line = <$fd>) {
1159 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?[^\^]+)/) {
1160 if (defined $refs{$1}) {
1161 push @{$refs{$1}}, $2;
1167 close $fd or return;
1171 sub git_get_rev_name_tags
{
1172 my $hash = shift || return undef;
1174 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1176 my $name_rev = <$fd>;
1179 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1182 # catches also '$hash undefined' output
1187 ## ----------------------------------------------------------------------
1188 ## parse to hash functions
1192 my $tz = shift || "-0000";
1195 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1196 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1197 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1198 $date{'hour'} = $hour;
1199 $date{'minute'} = $min;
1200 $date{'mday'} = $mday;
1201 $date{'day'} = $days[$wday];
1202 $date{'month'} = $months[$mon];
1203 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1204 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1205 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1206 $mday, $months[$mon], $hour ,$min;
1207 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1208 1900+$year, $mon, $mday, $hour ,$min, $sec;
1210 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1211 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1212 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1213 $date{'hour_local'} = $hour;
1214 $date{'minute_local'} = $min;
1215 $date{'tz_local'} = $tz;
1216 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1217 1900+$year, $mon+1, $mday,
1218 $hour, $min, $sec, $tz);
1227 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1228 $tag{'id'} = $tag_id;
1229 while (my $line = <$fd>) {
1231 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1232 $tag{'object'} = $1;
1233 } elsif ($line =~ m/^type (.+)$/) {
1235 } elsif ($line =~ m/^tag (.+)$/) {
1237 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1238 $tag{'author'} = $1;
1241 } elsif ($line =~ m/--BEGIN/) {
1242 push @comment, $line;
1244 } elsif ($line eq "") {
1248 push @comment, <$fd>;
1249 $tag{'comment'} = \
@comment;
1250 close $fd or return;
1251 if (!defined $tag{'name'}) {
1258 my $commit_id = shift;
1259 my $commit_text = shift;
1264 if (defined $commit_text) {
1265 @commit_lines = @$commit_text;
1268 open my $fd, "-|", git_cmd
(), "rev-list",
1269 "--header", "--parents", "--max-count=1",
1272 @commit_lines = split '\n', <$fd>;
1273 close $fd or return;
1276 my $header = shift @commit_lines;
1277 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
1280 ($co{'id'}, my @parents) = split ' ', $header;
1281 $co{'parents'} = \
@parents;
1282 $co{'parent'} = $parents[0];
1283 while (my $line = shift @commit_lines) {
1284 last if $line eq "\n";
1285 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1287 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1289 $co{'author_epoch'} = $2;
1290 $co{'author_tz'} = $3;
1291 if ($co{'author'} =~ m/^([^<]+) </) {
1292 $co{'author_name'} = $1;
1294 $co{'author_name'} = $co{'author'};
1296 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1297 $co{'committer'} = $1;
1298 $co{'committer_epoch'} = $2;
1299 $co{'committer_tz'} = $3;
1300 $co{'committer_name'} = $co{'committer'};
1301 $co{'committer_name'} =~ s/ <.*//;
1304 if (!defined $co{'tree'}) {
1308 foreach my $title (@commit_lines) {
1311 $co{'title'} = chop_str
($title, 80, 5);
1312 # remove leading stuff of merges to make the interesting part visible
1313 if (length($title) > 50) {
1314 $title =~ s/^Automatic //;
1315 $title =~ s/^merge (of|with) /Merge ... /i;
1316 if (length($title) > 50) {
1317 $title =~ s/(http|rsync):\/\///;
1319 if (length($title) > 50) {
1320 $title =~ s/(master|www|rsync)\.//;
1322 if (length($title) > 50) {
1323 $title =~ s/kernel.org:?//;
1325 if (length($title) > 50) {
1326 $title =~ s/\/pub\/scm//;
1329 $co{'title_short'} = chop_str
($title, 50, 5);
1333 if ($co{'title'} eq "") {
1334 $co{'title'} = $co{'title_short'} = '(no commit message)';
1336 # remove added spaces
1337 foreach my $line (@commit_lines) {
1340 $co{'comment'} = \
@commit_lines;
1342 my $age = time - $co{'committer_epoch'};
1344 $co{'age_string'} = age_string
($age);
1345 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1346 if ($age > 60*60*24*7*2) {
1347 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1348 $co{'age_string_age'} = $co{'age_string'};
1350 $co{'age_string_date'} = $co{'age_string'};
1351 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1356 # parse ref from ref_file, given by ref_id, with given type
1358 my $ref_file = shift;
1360 my $type = shift || git_get_type
($ref_id);
1363 $ref_item{'type'} = $type;
1364 $ref_item{'id'} = $ref_id;
1365 $ref_item{'epoch'} = 0;
1366 $ref_item{'age'} = "unknown";
1367 if ($type eq "tag") {
1368 my %tag = parse_tag
($ref_id);
1369 $ref_item{'comment'} = $tag{'comment'};
1370 if ($tag{'type'} eq "commit") {
1371 my %co = parse_commit
($tag{'object'});
1372 $ref_item{'epoch'} = $co{'committer_epoch'};
1373 $ref_item{'age'} = $co{'age_string'};
1374 } elsif (defined($tag{'epoch'})) {
1375 my $age = time - $tag{'epoch'};
1376 $ref_item{'epoch'} = $tag{'epoch'};
1377 $ref_item{'age'} = age_string
($age);
1379 $ref_item{'reftype'} = $tag{'type'};
1380 $ref_item{'name'} = $tag{'name'};
1381 $ref_item{'refid'} = $tag{'object'};
1382 } elsif ($type eq "commit"){
1383 my %co = parse_commit
($ref_id);
1384 $ref_item{'reftype'} = "commit";
1385 $ref_item{'name'} = $ref_file;
1386 $ref_item{'title'} = $co{'title'};
1387 $ref_item{'refid'} = $ref_id;
1388 $ref_item{'epoch'} = $co{'committer_epoch'};
1389 $ref_item{'age'} = $co{'age_string'};
1391 $ref_item{'reftype'} = $type;
1392 $ref_item{'name'} = $ref_file;
1393 $ref_item{'refid'} = $ref_id;
1399 # parse line of git-diff-tree "raw" output
1400 sub parse_difftree_raw_line
{
1404 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1405 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1406 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1407 $res{'from_mode'} = $1;
1408 $res{'to_mode'} = $2;
1409 $res{'from_id'} = $3;
1411 $res{'status'} = $5;
1412 $res{'similarity'} = $6;
1413 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1414 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1416 $res{'file'} = unquote
($7);
1419 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1420 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1421 $res{'commit'} = $1;
1424 return wantarray ? %res : \
%res;
1427 # parse line of git-ls-tree output
1428 sub parse_ls_tree_line
($;%) {
1433 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1434 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
1442 $res{'name'} = unquote
($4);
1445 return wantarray ? %res : \
%res;
1448 ## ......................................................................
1449 ## parse to array of hashes functions
1451 sub git_get_heads_list
{
1455 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1456 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
1457 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
1460 while (my $line = <$fd>) {
1464 my ($refinfo, $committerinfo) = split(/\0/, $line);
1465 my ($hash, $name, $title) = split(' ', $refinfo, 3);
1466 my ($committer, $epoch, $tz) =
1467 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
1468 $name =~ s!^refs/heads/!!;
1470 $ref_item{'name'} = $name;
1471 $ref_item{'id'} = $hash;
1472 $ref_item{'title'} = $title || '(no commit message)';
1473 $ref_item{'epoch'} = $epoch;
1475 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1477 $ref_item{'age'} = "unknown";
1480 push @headslist, \
%ref_item;
1484 return wantarray ? @headslist : \
@headslist;
1487 sub git_get_tags_list
{
1491 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1492 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
1493 '--format=%(objectname) %(objecttype) %(refname) '.
1494 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
1497 while (my $line = <$fd>) {
1501 my ($refinfo, $creatorinfo) = split(/\0/, $line);
1502 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
1503 my ($creator, $epoch, $tz) =
1504 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
1505 $name =~ s!^refs/tags/!!;
1507 $ref_item{'type'} = $type;
1508 $ref_item{'id'} = $id;
1509 $ref_item{'name'} = $name;
1510 if ($type eq "tag") {
1511 $ref_item{'subject'} = $title;
1512 $ref_item{'reftype'} = $reftype;
1513 $ref_item{'refid'} = $refid;
1515 $ref_item{'reftype'} = $type;
1516 $ref_item{'refid'} = $id;
1519 if ($type eq "tag" || $type eq "commit") {
1520 $ref_item{'epoch'} = $epoch;
1522 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1524 $ref_item{'age'} = "unknown";
1528 push @tagslist, \
%ref_item;
1532 return wantarray ? @tagslist : \
@tagslist;
1535 ## ----------------------------------------------------------------------
1536 ## filesystem-related functions
1538 sub get_file_owner
{
1541 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1542 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1543 if (!defined $gcos) {
1547 $owner =~ s/[,;].*$//;
1548 return to_utf8
($owner);
1551 ## ......................................................................
1552 ## mimetype related functions
1554 sub mimetype_guess_file
{
1555 my $filename = shift;
1556 my $mimemap = shift;
1557 -r
$mimemap or return undef;
1560 open(MIME
, $mimemap) or return undef;
1562 next if m/^#/; # skip comments
1563 my ($mime, $exts) = split(/\t+/);
1564 if (defined $exts) {
1565 my @exts = split(/\s+/, $exts);
1566 foreach my $ext (@exts) {
1567 $mimemap{$ext} = $mime;
1573 $filename =~ /\.([^.]*)$/;
1574 return $mimemap{$1};
1577 sub mimetype_guess
{
1578 my $filename = shift;
1580 $filename =~ /\./ or return undef;
1582 if ($mimetypes_file) {
1583 my $file = $mimetypes_file;
1584 if ($file !~ m!^/!) { # if it is relative path
1585 # it is relative to project
1586 $file = "$projectroot/$project/$file";
1588 $mime = mimetype_guess_file
($filename, $file);
1590 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1596 my $filename = shift;
1599 my $mime = mimetype_guess
($filename);
1600 $mime and return $mime;
1604 return $default_blob_plain_mimetype unless $fd;
1607 return 'text/plain' .
1608 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1609 } elsif (! $filename) {
1610 return 'application/octet-stream';
1611 } elsif ($filename =~ m/\.png$/i) {
1613 } elsif ($filename =~ m/\.gif$/i) {
1615 } elsif ($filename =~ m/\.jpe?g$/i) {
1616 return 'image/jpeg';
1618 return 'application/octet-stream';
1622 ## ======================================================================
1623 ## functions printing HTML: header, footer, error page
1625 sub git_header_html
{
1626 my $status = shift || "200 OK";
1627 my $expires = shift;
1629 my $title = "$site_name";
1630 if (defined $project) {
1631 $title .= " - $project";
1632 if (defined $action) {
1633 $title .= "/$action";
1634 if (defined $file_name) {
1635 $title .= " - " . esc_path
($file_name);
1636 if ($action eq "tree" && $file_name !~ m
|/$|) {
1643 # require explicit support from the UA if we are to send the page as
1644 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1645 # we have to do this because MSIE sometimes globs '*/*', pretending to
1646 # support xhtml+xml but choking when it gets what it asked for.
1647 if (defined $cgi->http('HTTP_ACCEPT') &&
1648 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1649 $cgi->Accept('application/xhtml+xml') != 0) {
1650 $content_type = 'application/xhtml+xml';
1652 $content_type = 'text/html';
1654 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1655 -status
=> $status, -expires
=> $expires);
1657 <?xml version="1.0" encoding="utf-8"?>
1658 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1659 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1660 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1661 <!-- git core binaries version $git_version -->
1663 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1664 <meta name="generator" content="gitweb/$version git/$git_version"/>
1665 <meta name="robots" content="index, nofollow"/>
1666 <title>$title</title>
1668 # print out each stylesheet that exist
1669 if (defined $stylesheet) {
1670 #provides backwards capability for those people who define style sheet in a config file
1671 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1673 foreach my $stylesheet (@stylesheets) {
1674 next unless $stylesheet;
1675 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1678 if (defined $project) {
1679 printf('<link rel="alternate" title="%s log RSS feed" '.
1680 'href="%s" type="application/rss+xml" />'."\n",
1681 esc_param
($project), href
(action
=>"rss"));
1682 printf('<link rel="alternate" title="%s log Atom feed" '.
1683 'href="%s" type="application/atom+xml" />'."\n",
1684 esc_param
($project), href
(action
=>"atom"));
1686 printf('<link rel="alternate" title="%s projects list" '.
1687 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1688 $site_name, href
(project
=>undef, action
=>"project_index"));
1689 printf('<link rel="alternate" title="%s projects feeds" '.
1690 'href="%s" type="text/x-opml"/>'."\n",
1691 $site_name, href
(project
=>undef, action
=>"opml"));
1693 if (defined $favicon) {
1694 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
1700 if (-f
$site_header) {
1701 open (my $fd, $site_header);
1706 print "<div class=\"page_header\">\n" .
1707 $cgi->a({-href
=> esc_url
($logo_url),
1708 -title
=> $logo_label},
1709 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
1710 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1711 if (defined $project) {
1712 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1713 if (defined $action) {
1717 if (!defined $searchtext) {
1721 if (defined $hash_base) {
1722 $search_hash = $hash_base;
1723 } elsif (defined $hash) {
1724 $search_hash = $hash;
1726 $search_hash = "HEAD";
1728 $cgi->param("a", "search");
1729 $cgi->param("h", $search_hash);
1730 $cgi->param("p", $project);
1731 print $cgi->startform(-method => "get", -action
=> $my_uri) .
1732 "<div class=\"search\">\n" .
1733 $cgi->hidden(-name
=> "p") . "\n" .
1734 $cgi->hidden(-name
=> "a") . "\n" .
1735 $cgi->hidden(-name
=> "h") . "\n" .
1736 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
1737 -values => ['commit', 'author', 'committer', 'pickaxe']) .
1738 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
1740 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1742 $cgi->end_form() . "\n";
1747 sub git_footer_html
{
1748 print "<div class=\"page_footer\">\n";
1749 if (defined $project) {
1750 my $descr = git_get_project_description
($project);
1751 if (defined $descr) {
1752 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1754 print $cgi->a({-href
=> href
(action
=>"rss"),
1755 -class => "rss_logo"}, "RSS") . " ";
1756 print $cgi->a({-href
=> href
(action
=>"atom"),
1757 -class => "rss_logo"}, "Atom") . "\n";
1759 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1760 -class => "rss_logo"}, "OPML") . " ";
1761 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1762 -class => "rss_logo"}, "TXT") . "\n";
1766 if (-f
$site_footer) {
1767 open (my $fd, $site_footer);
1777 my $status = shift || "403 Forbidden";
1778 my $error = shift || "Malformed query, file missing or permission denied";
1780 git_header_html
($status);
1782 <div class="page_body">
1792 ## ----------------------------------------------------------------------
1793 ## functions printing or outputting HTML: navigation
1795 sub git_print_page_nav
{
1796 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1797 $extra = '' if !defined $extra; # pager or formats
1799 my @navs = qw(summary shortlog log commit commitdiff tree);
1801 @navs = grep { $_ ne $suppress } @navs;
1804 my %arg = map { $_ => {action
=>$_} } @navs;
1805 if (defined $head) {
1806 for (qw(commit commitdiff)) {
1807 $arg{$_}{hash
} = $head;
1809 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1810 for (qw(shortlog log)) {
1811 $arg{$_}{hash
} = $head;
1815 $arg{tree
}{hash
} = $treehead if defined $treehead;
1816 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1818 print "<div class=\"page_nav\">\n" .
1820 map { $_ eq $current ?
1821 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1823 print "<br/>\n$extra<br/>\n" .
1827 sub format_paging_nav
{
1828 my ($action, $hash, $head, $page, $nrevs) = @_;
1832 if ($hash ne $head || $page) {
1833 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1835 $paging_nav .= "HEAD";
1839 $paging_nav .= " ⋅ " .
1840 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1841 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1843 $paging_nav .= " ⋅ prev";
1846 if ($nrevs >= (100 * ($page+1)-1)) {
1847 $paging_nav .= " ⋅ " .
1848 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1849 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1851 $paging_nav .= " ⋅ next";
1857 ## ......................................................................
1858 ## functions printing or outputting HTML: div
1860 sub git_print_header_div
{
1861 my ($action, $title, $hash, $hash_base) = @_;
1864 $args{action
} = $action;
1865 $args{hash
} = $hash if $hash;
1866 $args{hash_base
} = $hash_base if $hash_base;
1868 print "<div class=\"header\">\n" .
1869 $cgi->a({-href
=> href
(%args), -class => "title"},
1870 $title ? $title : $action) .
1874 #sub git_print_authorship (\%) {
1875 sub git_print_authorship
{
1878 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
1879 print "<div class=\"author_date\">" .
1880 esc_html
($co->{'author_name'}) .
1882 if ($ad{'hour_local'} < 6) {
1883 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1884 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1886 printf(" (%02d:%02d %s)",
1887 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1892 sub git_print_page_path
{
1898 print "<div class=\"page_path\">";
1899 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
1900 -title
=> 'tree root'}, "[$project]");
1902 if (defined $name) {
1903 my @dirname = split '/', $name;
1904 my $basename = pop @dirname;
1907 foreach my $dir (@dirname) {
1908 $fullname .= ($fullname ? '/' : '') . $dir;
1909 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
1911 -title
=> esc_html
($fullname)}, esc_path
($dir));
1914 if (defined $type && $type eq 'blob') {
1915 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1917 -title
=> esc_html
($name)}, esc_path
($basename));
1918 } elsif (defined $type && $type eq 'tree') {
1919 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
1921 -title
=> esc_html
($name)}, esc_path
($basename));
1924 print esc_path
($basename);
1927 print "<br/></div>\n";
1930 # sub git_print_log (\@;%) {
1931 sub git_print_log
($;%) {
1935 if ($opts{'-remove_title'}) {
1936 # remove title, i.e. first line of log
1939 # remove leading empty lines
1940 while (defined $log->[0] && $log->[0] eq "") {
1947 foreach my $line (@$log) {
1948 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1951 if (! $opts{'-remove_signoff'}) {
1952 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1955 # remove signoff lines
1962 # print only one empty line
1963 # do not print empty line after signoff
1965 next if ($empty || $signoff);
1971 print format_log_line_html
($line) . "<br/>\n";
1974 if ($opts{'-final_empty_line'}) {
1975 # end with single empty line
1976 print "<br/>\n" unless $empty;
1980 # print tree entry (row of git_tree), but without encompassing <tr> element
1981 sub git_print_tree_entry
{
1982 my ($t, $basedir, $hash_base, $have_blame) = @_;
1985 $base_key{hash_base
} = $hash_base if defined $hash_base;
1987 # The format of a table row is: mode list link. Where mode is
1988 # the mode of the entry, list is the name of the entry, an href,
1989 # and link is the action links of the entry.
1991 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
1992 if ($t->{'type'} eq "blob") {
1993 print "<td class=\"list\">" .
1994 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
1995 file_name
=>"$basedir$t->{'name'}", %base_key),
1996 -class => "list"}, esc_path
($t->{'name'})) . "</td>\n";
1997 print "<td class=\"link\">";
1998 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
1999 file_name
=>"$basedir$t->{'name'}", %base_key)},
2003 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2004 file_name
=>"$basedir$t->{'name'}", %base_key)},
2007 if (defined $hash_base) {
2009 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2010 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2014 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2015 file_name
=>"$basedir$t->{'name'}")},
2019 } elsif ($t->{'type'} eq "tree") {
2020 print "<td class=\"list\">";
2021 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2022 file_name
=>"$basedir$t->{'name'}", %base_key)},
2023 esc_path
($t->{'name'}));
2025 print "<td class=\"link\">";
2026 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2027 file_name
=>"$basedir$t->{'name'}", %base_key)},
2029 if (defined $hash_base) {
2031 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2032 file_name
=>"$basedir$t->{'name'}")},
2039 ## ......................................................................
2040 ## functions printing large fragments of HTML
2042 sub git_difftree_body
{
2043 my ($difftree, $hash, $parent) = @_;
2044 my ($have_blame) = gitweb_check_feature
('blame');
2045 print "<div class=\"list_head\">\n";
2046 if ($#{$difftree} > 10) {
2047 print(($#{$difftree} + 1) . " files changed:\n");
2051 print "<table class=\"diff_tree\">\n";
2054 foreach my $line (@{$difftree}) {
2055 my %diff = parse_difftree_raw_line
($line);
2058 print "<tr class=\"dark\">\n";
2060 print "<tr class=\"light\">\n";
2064 my ($to_mode_oct, $to_mode_str, $to_file_type);
2065 my ($from_mode_oct, $from_mode_str, $from_file_type);
2066 if ($diff{'to_mode'} ne ('0' x
6)) {
2067 $to_mode_oct = oct $diff{'to_mode'};
2068 if (S_ISREG
($to_mode_oct)) { # only for regular file
2069 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
2071 $to_file_type = file_type
($diff{'to_mode'});
2073 if ($diff{'from_mode'} ne ('0' x
6)) {
2074 $from_mode_oct = oct $diff{'from_mode'};
2075 if (S_ISREG
($to_mode_oct)) { # only for regular file
2076 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
2078 $from_file_type = file_type
($diff{'from_mode'});
2081 if ($diff{'status'} eq "A") { # created
2082 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
2083 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
2084 $mode_chng .= "]</span>";
2086 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2087 hash_base
=>$hash, file_name
=>$diff{'file'}),
2088 -class => "list"}, esc_path
($diff{'file'}));
2090 print "<td>$mode_chng</td>\n";
2091 print "<td class=\"link\">";
2092 if ($action eq 'commitdiff') {
2095 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2098 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2099 hash_base
=>$hash, file_name
=>$diff{'file'})},
2103 } elsif ($diff{'status'} eq "D") { # deleted
2104 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
2106 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
2107 hash_base
=>$parent, file_name
=>$diff{'file'}),
2108 -class => "list"}, esc_path
($diff{'file'}));
2110 print "<td>$mode_chng</td>\n";
2111 print "<td class=\"link\">";
2112 if ($action eq 'commitdiff') {
2115 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2118 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
2119 hash_base
=>$parent, file_name
=>$diff{'file'})},
2122 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2123 file_name
=>$diff{'file'})},
2126 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2127 file_name
=>$diff{'file'})},
2131 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
2132 my $mode_chnge = "";
2133 if ($diff{'from_mode'} != $diff{'to_mode'}) {
2134 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
2135 if ($from_file_type != $to_file_type) {
2136 $mode_chnge .= " from $from_file_type to $to_file_type";
2138 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
2139 if ($from_mode_str && $to_mode_str) {
2140 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
2141 } elsif ($to_mode_str) {
2142 $mode_chnge .= " mode: $to_mode_str";
2145 $mode_chnge .= "]</span>\n";
2148 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2149 hash_base
=>$hash, file_name
=>$diff{'file'}),
2150 -class => "list"}, esc_path
($diff{'file'}));
2152 print "<td>$mode_chnge</td>\n";
2153 print "<td class=\"link\">";
2154 if ($action eq 'commitdiff') {
2157 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2159 } elsif ($diff{'to_id'} ne $diff{'from_id'}) {
2160 # "commit" view and modified file (not onlu mode changed)
2161 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2162 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
2163 hash_base
=>$hash, hash_parent_base
=>$parent,
2164 file_name
=>$diff{'file'})},
2168 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2169 hash_base
=>$hash, file_name
=>$diff{'file'})},
2172 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2173 file_name
=>$diff{'file'})},
2176 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2177 file_name
=>$diff{'file'})},
2181 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
2182 my %status_name = ('R' => 'moved', 'C' => 'copied');
2183 my $nstatus = $status_name{$diff{'status'}};
2185 if ($diff{'from_mode'} != $diff{'to_mode'}) {
2186 # mode also for directories, so we cannot use $to_mode_str
2187 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
2190 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2191 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
2192 -class => "list"}, esc_path
($diff{'to_file'})) . "</td>\n" .
2193 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
2194 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
2195 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
2196 -class => "list"}, esc_path
($diff{'from_file'})) .
2197 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
2198 "<td class=\"link\">";
2199 if ($action eq 'commitdiff') {
2202 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2204 } elsif ($diff{'to_id'} ne $diff{'from_id'}) {
2205 # "commit" view and modified file (not only pure rename or copy)
2206 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2207 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
2208 hash_base
=>$hash, hash_parent_base
=>$parent,
2209 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
2213 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2214 hash_base
=>$parent, file_name
=>$diff{'to_file'})},
2217 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2218 file_name
=>$diff{'to_file'})},
2221 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2222 file_name
=>$diff{'to_file'})},
2226 } # we should not encounter Unmerged (U) or Unknown (X) status
2232 sub git_patchset_body
{
2233 my ($fd, $difftree, $hash, $hash_parent) = @_;
2239 my ($from_id, $to_id);
2241 print "<div class=\"patchset\">\n";
2243 # skip to first patch
2244 while ($patch_line = <$fd>) {
2247 last if ($patch_line =~ m/^diff /);
2251 while ($patch_line) {
2255 #assert($patch_line =~ m/^diff /) if DEBUG;
2256 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
2257 push @diff_header, $patch_line;
2259 # extended diff header
2261 while ($patch_line = <$fd>) {
2264 last EXTENDED_HEADER
if ($patch_line =~ m/^--- /);
2266 if ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2271 push @diff_header, $patch_line;
2273 #last PATCH unless $patch_line;
2274 my $last_patch_line = $patch_line;
2276 # check if current patch belong to current raw line
2277 # and parse raw git-diff line if needed
2278 if (defined $diffinfo &&
2279 $diffinfo->{'from_id'} eq $from_id &&
2280 $diffinfo->{'to_id'} eq $to_id) {
2281 # this is split patch
2282 print "<div class=\"patch cont\">\n";
2284 # advance raw git-diff output if needed
2285 $patch_idx++ if defined $diffinfo;
2287 # read and prepare patch information
2288 if (ref($difftree->[$patch_idx]) eq "HASH") {
2289 # pre-parsed (or generated by hand)
2290 $diffinfo = $difftree->[$patch_idx];
2292 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
2294 $from{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
2295 $to{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
2296 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2297 $from{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2298 hash
=>$diffinfo->{'from_id'},
2299 file_name
=>$from{'file'});
2301 if ($diffinfo->{'status'} ne "D") { # not deleted file
2302 $to{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2303 hash
=>$diffinfo->{'to_id'},
2304 file_name
=>$to{'file'});
2306 # this is first patch for raw difftree line with $patch_idx index
2307 # we index @$difftree array from 0, but number patches from 1
2308 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
2311 # print "git diff" header
2312 $patch_line = shift @diff_header;
2313 $patch_line =~ s!^(diff (.*?) )"?a/.*$!$1!;
2314 if ($from{'href'}) {
2315 $patch_line .= $cgi->a({-href
=> $from{'href'}, -class => "path"},
2316 'a/' . esc_path
($from{'file'}));
2317 } else { # file was added
2318 $patch_line .= 'a/' . esc_path
($from{'file'});
2322 $patch_line .= $cgi->a({-href
=> $to{'href'}, -class => "path"},
2323 'b/' . esc_path
($to{'file'}));
2324 } else { # file was deleted
2325 $patch_line .= 'b/' . esc_path
($to{'file'});
2327 print "<div class=\"diff header\">$patch_line</div>\n";
2329 # print extended diff header
2330 print "<div class=\"diff extended_header\">\n" if (@diff_header > 0);
2332 foreach $patch_line (@diff_header) {
2334 if ($patch_line =~ s!^((copy|rename) from ).*$!$1! && $from{'href'}) {
2335 $patch_line .= $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2336 esc_path
($from{'file'}));
2338 if ($patch_line =~ s!^((copy|rename) to ).*$!$1! && $to{'href'}) {
2339 $patch_line = $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2340 esc_path
($to{'file'}));
2343 if ($patch_line =~ m/\s(\d{6})$/) {
2344 $patch_line .= '<span class="info"> (' .
2345 file_type_long
($1) .
2349 if ($patch_line =~ m/^index/) {
2350 my ($from_link, $to_link);
2351 if ($from{'href'}) {
2352 $from_link = $cgi->a({-href
=>$from{'href'}, -class=>"hash"},
2353 substr($diffinfo->{'from_id'},0,7));
2355 $from_link = '0' x
7;
2358 $to_link = $cgi->a({-href
=>$to{'href'}, -class=>"hash"},
2359 substr($diffinfo->{'to_id'},0,7));
2364 # my ($from_hash, $to_hash) =
2365 # ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/);
2366 # my ($from_id, $to_id) =
2367 # ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2368 # ($from_hash eq $from_id) && ($to_hash eq $to_id);
2370 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2371 $patch_line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
2373 print $patch_line . "<br/>\n";
2375 print "</div>\n" if (@diff_header > 0); # class="diff extended_header"
2377 # from-file/to-file diff header
2378 $patch_line = $last_patch_line;
2379 #assert($patch_line =~ m/^---/) if DEBUG;
2380 if ($from{'href'}) {
2381 $patch_line = '--- a/' .
2382 $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2383 esc_path
($from{'file'}));
2385 print "<div class=\"diff from_file\">$patch_line</div>\n";
2387 $patch_line = <$fd>;
2388 #last PATCH unless $patch_line;
2391 #assert($patch_line =~ m/^+++/) if DEBUG;
2393 $patch_line = '+++ b/' .
2394 $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2395 esc_path
($to{'file'}));
2397 print "<div class=\"diff to_file\">$patch_line</div>\n";
2401 while ($patch_line = <$fd>) {
2404 next PATCH
if ($patch_line =~ m/^diff /);
2406 print format_diff_line
($patch_line, \
%from, \
%to);
2410 print "</div>\n"; # class="patch"
2413 print "</div>\n"; # class="patchset"
2416 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2418 sub git_project_list_body
{
2419 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
2421 my ($check_forks) = gitweb_check_feature
('forks');
2424 foreach my $pr (@$projlist) {
2425 my (@aa) = git_get_last_activity
($pr->{'path'});
2429 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
2430 if (!defined $pr->{'descr'}) {
2431 my $descr = git_get_project_description
($pr->{'path'}) || "";
2432 $pr->{'descr'} = chop_str
($descr, 25, 5);
2434 if (!defined $pr->{'owner'}) {
2435 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2438 my $pname = $pr->{'path'};
2439 if (($pname =~ s/\.git$//) &&
2440 ($pname !~ /\/$/) &&
2441 (-d
"$projectroot/$pname")) {
2442 $pr->{'forks'} = "-d $projectroot/$pname";
2448 push @projects, $pr;
2451 $order ||= "project";
2452 $from = 0 unless defined $from;
2453 $to = $#projects if (!defined $to || $#projects < $to);
2455 print "<table class=\"project_list\">\n";
2456 unless ($no_header) {
2459 print "<th></th>\n";
2461 if ($order eq "project") {
2462 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2463 print "<th>Project</th>\n";
2466 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2467 -class => "header"}, "Project") .
2470 if ($order eq "descr") {
2471 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2472 print "<th>Description</th>\n";
2475 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2476 -class => "header"}, "Description") .
2479 if ($order eq "owner") {
2480 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2481 print "<th>Owner</th>\n";
2484 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2485 -class => "header"}, "Owner") .
2488 if ($order eq "age") {
2489 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
2490 print "<th>Last Change</th>\n";
2493 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
2494 -class => "header"}, "Last Change") .
2497 print "<th></th>\n" .
2501 for (my $i = $from; $i <= $to; $i++) {
2502 my $pr = $projects[$i];
2504 print "<tr class=\"dark\">\n";
2506 print "<tr class=\"light\">\n";
2511 if ($pr->{'forks'}) {
2512 print "<!-- $pr->{'forks'} -->\n";
2513 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
2517 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2518 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2519 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
2520 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2521 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
2522 $pr->{'age_string'} . "</td>\n" .
2523 "<td class=\"link\">" .
2524 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2525 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2526 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
2527 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
2528 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
2532 if (defined $extra) {
2535 print "<td></td>\n";
2537 print "<td colspan=\"5\">$extra</td>\n" .
2543 sub git_shortlog_body
{
2544 # uses global variable $project
2545 my ($revlist, $from, $to, $refs, $extra) = @_;
2547 $from = 0 unless defined $from;
2548 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
2550 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
2552 for (my $i = $from; $i <= $to; $i++) {
2553 my $commit = $revlist->[$i];
2554 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
2555 my $ref = format_ref_marker
($refs, $commit);
2556 my %co = parse_commit
($commit);
2558 print "<tr class=\"dark\">\n";
2560 print "<tr class=\"light\">\n";
2563 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
2564 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2565 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
2567 print format_subject_html
($co{'title'}, $co{'title_short'},
2568 href
(action
=>"commit", hash
=>$commit), $ref);
2570 "<td class=\"link\">" .
2571 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
2572 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
2573 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
2574 if (gitweb_have_snapshot
()) {
2575 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
2580 if (defined $extra) {
2582 "<td colspan=\"4\">$extra</td>\n" .
2588 sub git_history_body
{
2589 # Warning: assumes constant type (blob or tree) during history
2590 my ($revlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
2592 $from = 0 unless defined $from;
2593 $to = $#{$revlist} unless (defined $to && $to <= $#{$revlist});
2595 print "<table class=\"history\" cellspacing=\"0\">\n";
2597 for (my $i = $from; $i <= $to; $i++) {
2598 if ($revlist->[$i] !~ m/^([0-9a-fA-F]{40})/) {
2603 my %co = parse_commit
($commit);
2608 my $ref = format_ref_marker
($refs, $commit);
2611 print "<tr class=\"dark\">\n";
2613 print "<tr class=\"light\">\n";
2616 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2617 # shortlog uses chop_str($co{'author_name'}, 10)
2618 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2620 # originally git_history used chop_str($co{'title'}, 50)
2621 print format_subject_html
($co{'title'}, $co{'title_short'},
2622 href
(action
=>"commit", hash
=>$commit), $ref);
2624 "<td class=\"link\">" .
2625 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
2626 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
2628 if ($ftype eq 'blob') {
2629 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
2630 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2631 if (defined $blob_current && defined $blob_parent &&
2632 $blob_current ne $blob_parent) {
2634 $cgi->a({-href
=> href
(action
=>"blobdiff",
2635 hash
=>$blob_current, hash_parent
=>$blob_parent,
2636 hash_base
=>$hash_base, hash_parent_base
=>$commit,
2637 file_name
=>$file_name)},
2644 if (defined $extra) {
2646 "<td colspan=\"4\">$extra</td>\n" .
2653 # uses global variable $project
2654 my ($taglist, $from, $to, $extra) = @_;
2655 $from = 0 unless defined $from;
2656 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2658 print "<table class=\"tags\" cellspacing=\"0\">\n";
2660 for (my $i = $from; $i <= $to; $i++) {
2661 my $entry = $taglist->[$i];
2663 my $comment = $tag{'subject'};
2665 if (defined $comment) {
2666 $comment_short = chop_str
($comment, 30, 5);
2669 print "<tr class=\"dark\">\n";
2671 print "<tr class=\"light\">\n";
2674 print "<td><i>$tag{'age'}</i></td>\n" .
2676 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
2677 -class => "list name"}, esc_html
($tag{'name'})) .
2680 if (defined $comment) {
2681 print format_subject_html
($comment, $comment_short,
2682 href
(action
=>"tag", hash
=>$tag{'id'}));
2685 "<td class=\"selflink\">";
2686 if ($tag{'type'} eq "tag") {
2687 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
2692 "<td class=\"link\">" . " | " .
2693 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
2694 if ($tag{'reftype'} eq "commit") {
2695 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
2696 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
2697 } elsif ($tag{'reftype'} eq "blob") {
2698 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
2703 if (defined $extra) {
2705 "<td colspan=\"5\">$extra</td>\n" .
2711 sub git_heads_body
{
2712 # uses global variable $project
2713 my ($headlist, $head, $from, $to, $extra) = @_;
2714 $from = 0 unless defined $from;
2715 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
2717 print "<table class=\"heads\" cellspacing=\"0\">\n";
2719 for (my $i = $from; $i <= $to; $i++) {
2720 my $entry = $headlist->[$i];
2722 my $curr = $ref{'id'} eq $head;
2724 print "<tr class=\"dark\">\n";
2726 print "<tr class=\"light\">\n";
2729 print "<td><i>$ref{'age'}</i></td>\n" .
2730 ($curr ? "<td class=\"current_head\">" : "<td>") .
2731 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
2732 -class => "list name"},esc_html
($ref{'name'})) .
2734 "<td class=\"link\">" .
2735 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
2736 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
2737 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
2741 if (defined $extra) {
2743 "<td colspan=\"3\">$extra</td>\n" .
2749 ## ======================================================================
2750 ## ======================================================================
2753 sub git_project_list
{
2754 my $order = $cgi->param('o');
2755 if (defined $order && $order !~ m/project|descr|owner|age/) {
2756 die_error
(undef, "Unknown order parameter");
2759 my @list = git_get_projects_list
();
2761 die_error
(undef, "No projects found");
2765 if (-f
$home_text) {
2766 print "<div class=\"index_include\">\n";
2767 open (my $fd, $home_text);
2772 git_project_list_body
(\
@list, $order);
2777 my $order = $cgi->param('o');
2778 if (defined $order && $order !~ m/project|descr|owner|age/) {
2779 die_error
(undef, "Unknown order parameter");
2782 my @list = git_get_projects_list
($project);
2784 die_error
(undef, "No forks found");
2788 git_print_page_nav
('','');
2789 git_print_header_div
('summary', "$project forks");
2790 git_project_list_body
(\
@list, $order);
2794 sub git_project_index
{
2795 my @projects = git_get_projects_list
($project);
2798 -type
=> 'text/plain',
2799 -charset
=> 'utf-8',
2800 -content_disposition
=> 'inline; filename="index.aux"');
2802 foreach my $pr (@projects) {
2803 if (!exists $pr->{'owner'}) {
2804 $pr->{'owner'} = get_file_owner
("$projectroot/$project");
2807 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
2808 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
2809 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2810 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2814 print "$path $owner\n";
2819 my $descr = git_get_project_description
($project) || "none";
2820 my $head = git_get_head_hash
($project);
2821 my %co = parse_commit
($head);
2822 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2824 my $owner = git_get_project_owner
($project);
2826 my $refs = git_get_references
();
2827 my @taglist = git_get_tags_list
(15);
2828 my @headlist = git_get_heads_list
(15);
2830 my ($check_forks) = gitweb_check_feature
('forks');
2833 @forklist = git_get_projects_list
($project);
2837 git_print_page_nav
('summary','', $head);
2839 print "<div class=\"title\"> </div>\n";
2840 print "<table cellspacing=\"0\">\n" .
2841 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
2842 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2843 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2844 # use per project git URL list in $projectroot/$project/cloneurl
2845 # or make project git URL from git base URL and project name
2846 my $url_tag = "URL";
2847 my @url_list = git_get_project_url_list
($project);
2848 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2849 foreach my $git_url (@url_list) {
2850 next unless $git_url;
2851 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2856 if (-s
"$projectroot/$project/README.html") {
2857 if (open my $fd, "$projectroot/$project/README.html") {
2858 print "<div class=\"title\">readme</div>\n";
2859 print $_ while (<$fd>);
2864 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=17",
2865 git_get_head_hash
($project), "--"
2866 or die_error
(undef, "Open git-rev-list failed");
2867 my @revlist = map { chomp; $_ } <$fd>;
2869 git_print_header_div
('shortlog');
2870 git_shortlog_body
(\
@revlist, 0, 15, $refs,
2871 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
2874 git_print_header_div
('tags');
2875 git_tags_body
(\
@taglist, 0, 15,
2876 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
2880 git_print_header_div
('heads');
2881 git_heads_body
(\
@headlist, $head, 0, 15,
2882 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
2886 git_print_header_div
('forks');
2887 git_project_list_body
(\
@forklist, undef, 0, 15,
2888 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
2896 my $head = git_get_head_hash
($project);
2898 git_print_page_nav
('','', $head,undef,$head);
2899 my %tag = parse_tag
($hash);
2900 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
2901 print "<div class=\"title_text\">\n" .
2902 "<table cellspacing=\"0\">\n" .
2904 "<td>object</td>\n" .
2905 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2906 $tag{'object'}) . "</td>\n" .
2907 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2908 $tag{'type'}) . "</td>\n" .
2910 if (defined($tag{'author'})) {
2911 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
2912 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
2913 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2914 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2917 print "</table>\n\n" .
2919 print "<div class=\"page_body\">";
2920 my $comment = $tag{'comment'};
2921 foreach my $line (@$comment) {
2923 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
2933 my ($have_blame) = gitweb_check_feature
('blame');
2935 die_error
('403 Permission denied', "Permission denied");
2937 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2938 $hash_base ||= git_get_head_hash
($project);
2939 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2940 my %co = parse_commit
($hash_base)
2941 or die_error
(undef, "Reading commit failed");
2942 if (!defined $hash) {
2943 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2944 or die_error
(undef, "Error looking up file");
2946 $ftype = git_get_type
($hash);
2947 if ($ftype !~ "blob") {
2948 die_error
("400 Bad Request", "Object is not a blob");
2950 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
2951 $file_name, $hash_base)
2952 or die_error
(undef, "Open git-blame failed");
2955 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2958 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2961 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2963 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2964 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2965 git_print_page_path
($file_name, $ftype, $hash_base);
2966 my @rev_color = (qw(light2 dark2));
2967 my $num_colors = scalar(@rev_color);
2968 my $current_color = 0;
2971 <div class="page_body">
2972 <table class="blame">
2973 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2978 last unless defined $_;
2979 my ($full_rev, $orig_lineno, $lineno, $group_size) =
2980 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
2981 if (!exists $metainfo{$full_rev}) {
2982 $metainfo{$full_rev} = {};
2984 my $meta = $metainfo{$full_rev};
2987 if (/^(\S+) (.*)$/) {
2993 my $rev = substr($full_rev, 0, 8);
2994 my $author = $meta->{'author'};
2995 my %date = parse_date
($meta->{'author-time'},
2996 $meta->{'author-tz'});
2997 my $date = $date{'iso-tz'};
2999 $current_color = ++$current_color % $num_colors;
3001 print "<tr class=\"$rev_color[$current_color]\">\n";
3003 print "<td class=\"sha1\"";
3004 print " title=\"". esc_html
($author) . ", $date\"";
3005 print " rowspan=\"$group_size\"" if ($group_size > 1);
3007 print $cgi->a({-href
=> href
(action
=>"commit",
3009 file_name
=>$file_name)},
3013 my $blamed = href
(action
=> 'blame',
3014 file_name
=> $meta->{'filename'},
3015 hash_base
=> $full_rev);
3016 print "<td class=\"linenr\">";
3017 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
3019 -class => "linenr" },
3022 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
3028 or print "Reading blob failed\n";
3035 my ($have_blame) = gitweb_check_feature
('blame');
3037 die_error
('403 Permission denied', "Permission denied");
3039 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3040 $hash_base ||= git_get_head_hash
($project);
3041 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3042 my %co = parse_commit
($hash_base)
3043 or die_error
(undef, "Reading commit failed");
3044 if (!defined $hash) {
3045 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3046 or die_error
(undef, "Error lookup file");
3048 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
3049 or die_error
(undef, "Open git-annotate failed");
3052 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3055 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3058 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3060 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3061 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3062 git_print_page_path
($file_name, 'blob', $hash_base);
3063 print "<div class=\"page_body\">\n";
3065 <table class="blame">
3074 my @line_class = (qw(light dark));
3075 my $line_class_len = scalar (@line_class);
3076 my $line_class_num = $#line_class;
3077 while (my $line = <$fd>) {
3089 $line_class_num = ($line_class_num + 1) % $line_class_len;
3091 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
3098 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
3101 $short_rev = substr ($long_rev, 0, 8);
3102 $age = time () - $time;
3103 $age_str = age_string
($age);
3104 $age_str =~ s/ / /g;
3105 $age_class = age_class
($age);
3106 $author = esc_html
($author);
3107 $author =~ s/ / /g;
3109 $data = untabify
($data);
3110 $data = esc_html
($data);
3113 <tr class="$line_class[$line_class_num]">
3114 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
3115 <td class="$age_class">$age_str</td>
3117 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
3118 <td class="pre">$data</td>
3121 } # while (my $line = <$fd>)
3122 print "</table>\n\n";
3124 or print "Reading blob failed.\n";
3130 my $head = git_get_head_hash
($project);
3132 git_print_page_nav
('','', $head,undef,$head);
3133 git_print_header_div
('summary', $project);
3135 my @tagslist = git_get_tags_list
();
3137 git_tags_body
(\
@tagslist);
3143 my $head = git_get_head_hash
($project);
3145 git_print_page_nav
('','', $head,undef,$head);
3146 git_print_header_div
('summary', $project);
3148 my @headslist = git_get_heads_list
();
3150 git_heads_body
(\
@headslist, $head);
3155 sub git_blob_plain
{
3158 if (!defined $hash) {
3159 if (defined $file_name) {
3160 my $base = $hash_base || git_get_head_hash
($project);
3161 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3162 or die_error
(undef, "Error lookup file");
3164 die_error
(undef, "No file name defined");
3166 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3167 # blobs defined by non-textual hash id's can be cached
3172 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3173 or die_error
(undef, "Couldn't cat $file_name, $hash");
3175 $type ||= blob_mimetype
($fd, $file_name);
3177 # save as filename, even when no $file_name is given
3178 my $save_as = "$hash";
3179 if (defined $file_name) {
3180 $save_as = $file_name;
3181 } elsif ($type =~ m/^text\//) {
3188 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
3190 binmode STDOUT
, ':raw';
3192 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3200 if (!defined $hash) {
3201 if (defined $file_name) {
3202 my $base = $hash_base || git_get_head_hash
($project);
3203 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3204 or die_error
(undef, "Error lookup file");
3206 die_error
(undef, "No file name defined");
3208 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3209 # blobs defined by non-textual hash id's can be cached
3213 my ($have_blame) = gitweb_check_feature
('blame');
3214 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3215 or die_error
(undef, "Couldn't cat $file_name, $hash");
3216 my $mimetype = blob_mimetype
($fd, $file_name);
3217 if ($mimetype !~ m/^text\//) {
3219 return git_blob_plain
($mimetype);
3221 git_header_html
(undef, $expires);
3222 my $formats_nav = '';
3223 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3224 if (defined $file_name) {
3227 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
3228 hash
=>$hash, file_name
=>$file_name)},
3233 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3234 hash
=>$hash, file_name
=>$file_name)},
3237 $cgi->a({-href
=> href
(action
=>"blob_plain",
3238 hash
=>$hash, file_name
=>$file_name)},
3241 $cgi->a({-href
=> href
(action
=>"blob",
3242 hash_base
=>"HEAD", file_name
=>$file_name)},
3246 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
3248 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3249 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3251 print "<div class=\"page_nav\">\n" .
3252 "<br/><br/></div>\n" .
3253 "<div class=\"title\">$hash</div>\n";
3255 git_print_page_path
($file_name, "blob", $hash_base);
3256 print "<div class=\"page_body\">\n";
3258 while (my $line = <$fd>) {
3261 $line = untabify
($line);
3262 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
3263 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
3266 or print "Reading blob failed.\n";
3272 my $have_snapshot = gitweb_have_snapshot
();
3274 if (!defined $hash_base) {
3275 $hash_base = "HEAD";
3277 if (!defined $hash) {
3278 if (defined $file_name) {
3279 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
3285 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
3286 or die_error
(undef, "Open git-ls-tree failed");
3287 my @entries = map { chomp; $_ } <$fd>;
3288 close $fd or die_error
(undef, "Reading tree failed");
3291 my $refs = git_get_references
();
3292 my $ref = format_ref_marker
($refs, $hash_base);
3295 my ($have_blame) = gitweb_check_feature
('blame');
3296 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3298 if (defined $file_name) {
3300 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3301 hash
=>$hash, file_name
=>$file_name)},
3303 $cgi->a({-href
=> href
(action
=>"tree",
3304 hash_base
=>"HEAD", file_name
=>$file_name)},
3307 if ($have_snapshot) {
3308 # FIXME: Should be available when we have no hash base as well.
3310 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
3313 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
3314 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
3317 print "<div class=\"page_nav\">\n";
3318 print "<br/><br/></div>\n";
3319 print "<div class=\"title\">$hash</div>\n";
3321 if (defined $file_name) {
3322 $basedir = $file_name;
3323 if ($basedir ne '' && substr($basedir, -1) ne '/') {
3327 git_print_page_path
($file_name, 'tree', $hash_base);
3328 print "<div class=\"page_body\">\n";
3329 print "<table cellspacing=\"0\">\n";
3331 # '..' (top directory) link if possible
3332 if (defined $hash_base &&
3333 defined $file_name && $file_name =~ m![^/]+$!) {
3335 print "<tr class=\"dark\">\n";
3337 print "<tr class=\"light\">\n";
3341 my $up = $file_name;
3342 $up =~ s!/?[^/]+$!!;
3343 undef $up unless $up;
3344 # based on git_print_tree_entry
3345 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
3346 print '<td class="list">';
3347 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
3351 print "<td class=\"link\"></td>\n";
3355 foreach my $line (@entries) {
3356 my %t = parse_ls_tree_line
($line, -z
=> 1);
3359 print "<tr class=\"dark\">\n";
3361 print "<tr class=\"light\">\n";
3365 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
3369 print "</table>\n" .
3375 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
3376 my $have_snapshot = (defined $ctype && defined $suffix);
3377 if (!$have_snapshot) {
3378 die_error
('403 Permission denied', "Permission denied");
3381 if (!defined $hash) {
3382 $hash = git_get_head_hash
($project);
3385 my $filename = basename
($project) . "-$hash.tar.$suffix";
3388 -type
=> 'application/x-tar',
3389 -content_encoding
=> $ctype,
3390 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
3391 -status
=> '200 OK');
3393 my $git = git_cmd_str
();
3394 my $name = $project;
3395 $name =~ s/\047/\047\\\047\047/g;
3397 "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
3398 or die_error
(undef, "Execute git-tar-tree failed.");
3399 binmode STDOUT
, ':raw';
3401 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3407 my $head = git_get_head_hash
($project);
3408 if (!defined $hash) {
3411 if (!defined $page) {
3414 my $refs = git_get_references
();
3416 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3417 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash, "--"
3418 or die_error
(undef, "Open git-rev-list failed");
3419 my @revlist = map { chomp; $_ } <$fd>;
3422 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
3425 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
3428 my %co = parse_commit
($hash);
3430 git_print_header_div
('summary', $project);
3431 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
3433 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
3434 my $commit = $revlist[$i];
3435 my $ref = format_ref_marker
($refs, $commit);
3436 my %co = parse_commit
($commit);
3438 my %ad = parse_date
($co{'author_epoch'});
3439 git_print_header_div
('commit',
3440 "<span class=\"age\">$co{'age_string'}</span>" .
3441 esc_html
($co{'title'}) . $ref,
3443 print "<div class=\"title_text\">\n" .
3444 "<div class=\"log_link\">\n" .
3445 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
3447 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
3449 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
3452 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
3455 print "<div class=\"log_body\">\n";
3456 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
3463 $hash ||= $hash_base || "HEAD";
3464 my %co = parse_commit
($hash);
3466 die_error
(undef, "Unknown commit object");
3468 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3469 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
3471 my $parent = $co{'parent'};
3472 if (!defined $parent) {
3475 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
3476 @diff_opts, $parent, $hash, "--"
3477 or die_error
(undef, "Open git-diff-tree failed");
3478 my @difftree = map { chomp; $_ } <$fd>;
3479 close $fd or die_error
(undef, "Reading git-diff-tree failed");
3481 # non-textual hash id's can be cached
3483 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3486 my $refs = git_get_references
();
3487 my $ref = format_ref_marker
($refs, $co{'id'});
3489 my $have_snapshot = gitweb_have_snapshot
();
3492 if (defined $file_name && defined $co{'parent'}) {
3494 $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)},
3497 git_header_html
(undef, $expires);
3498 git_print_page_nav
('commit', '',
3499 $hash, $co{'tree'}, $hash,
3500 join (' | ', @views_nav));
3502 if (defined $co{'parent'}) {
3503 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
3505 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
3507 print "<div class=\"title_text\">\n" .
3508 "<table cellspacing=\"0\">\n";
3509 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
3511 "<td></td><td> $ad{'rfc2822'}";
3512 if ($ad{'hour_local'} < 6) {
3513 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3514 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3516 printf(" (%02d:%02d %s)",
3517 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3521 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
3522 print "<tr><td></td><td> $cd{'rfc2822'}" .
3523 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
3525 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
3528 "<td class=\"sha1\">" .
3529 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
3530 class => "list"}, $co{'tree'}) .
3532 "<td class=\"link\">" .
3533 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
3535 if ($have_snapshot) {
3537 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
3541 my $parents = $co{'parents'};
3542 foreach my $par (@$parents) {
3545 "<td class=\"sha1\">" .
3546 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
3547 class => "list"}, $par) .
3549 "<td class=\"link\">" .
3550 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
3552 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
3559 print "<div class=\"page_body\">\n";
3560 git_print_log
($co{'comment'});
3563 git_difftree_body
(\
@difftree, $hash, $parent);
3569 my $format = shift || 'html';
3576 # preparing $fd and %diffinfo for git_patchset_body
3578 if (defined $hash_base && defined $hash_parent_base) {
3579 if (defined $file_name) {
3581 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3582 $hash_parent_base, $hash_base,
3584 or die_error
(undef, "Open git-diff-tree failed");
3585 @difftree = map { chomp; $_ } <$fd>;
3587 or die_error
(undef, "Reading git-diff-tree failed");
3589 or die_error
('404 Not Found', "Blob diff not found");
3591 } elsif (defined $hash &&
3592 $hash =~ /[0-9a-fA-F]{40}/) {
3593 # try to find filename from $hash
3595 # read filtered raw output
3596 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3597 $hash_parent_base, $hash_base, "--"
3598 or die_error
(undef, "Open git-diff-tree failed");
3600 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
3602 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
3603 map { chomp; $_ } <$fd>;
3605 or die_error
(undef, "Reading git-diff-tree failed");
3607 or die_error
('404 Not Found', "Blob diff not found");
3610 die_error
('404 Not Found', "Missing one of the blob diff parameters");
3613 if (@difftree > 1) {
3614 die_error
('404 Not Found', "Ambiguous blob diff specification");
3617 %diffinfo = parse_difftree_raw_line
($difftree[0]);
3618 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
3619 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
3621 $hash_parent ||= $diffinfo{'from_id'};
3622 $hash ||= $diffinfo{'to_id'};
3624 # non-textual hash id's can be cached
3625 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
3626 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
3631 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3632 '-p', $hash_parent_base, $hash_base,
3634 or die_error
(undef, "Open git-diff-tree failed");
3637 # old/legacy style URI
3638 if (!%diffinfo && # if new style URI failed
3639 defined $hash && defined $hash_parent) {
3640 # fake git-diff-tree raw output
3641 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
3642 $diffinfo{'from_id'} = $hash_parent;
3643 $diffinfo{'to_id'} = $hash;
3644 if (defined $file_name) {
3645 if (defined $file_parent) {
3646 $diffinfo{'status'} = '2';
3647 $diffinfo{'from_file'} = $file_parent;
3648 $diffinfo{'to_file'} = $file_name;
3649 } else { # assume not renamed
3650 $diffinfo{'status'} = '1';
3651 $diffinfo{'from_file'} = $file_name;
3652 $diffinfo{'to_file'} = $file_name;
3654 } else { # no filename given
3655 $diffinfo{'status'} = '2';
3656 $diffinfo{'from_file'} = $hash_parent;
3657 $diffinfo{'to_file'} = $hash;
3660 # non-textual hash id's can be cached
3661 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
3662 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3667 open $fd, "-|", git_cmd
(), "diff", '-p', @diff_opts,
3668 $hash_parent, $hash, "--"
3669 or die_error
(undef, "Open git-diff failed");
3671 die_error
('404 Not Found', "Missing one of the blob diff parameters")
3676 if ($format eq 'html') {
3678 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
3679 hash
=>$hash, hash_parent
=>$hash_parent,
3680 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
3681 file_name
=>$file_name, file_parent
=>$file_parent)},
3683 git_header_html
(undef, $expires);
3684 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3685 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3686 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3688 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
3689 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
3691 if (defined $file_name) {
3692 git_print_page_path
($file_name, "blob", $hash_base);
3694 print "<div class=\"page_path\"></div>\n";
3697 } elsif ($format eq 'plain') {
3699 -type
=> 'text/plain',
3700 -charset
=> 'utf-8',
3701 -expires
=> $expires,
3702 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
3704 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3707 die_error
(undef, "Unknown blobdiff format");
3711 if ($format eq 'html') {
3712 print "<div class=\"page_body\">\n";
3714 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
3717 print "</div>\n"; # class="page_body"
3721 while (my $line = <$fd>) {
3722 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
3723 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
3727 last if $line =~ m!^\+\+\+!;
3735 sub git_blobdiff_plain
{
3736 git_blobdiff
('plain');
3739 sub git_commitdiff
{
3740 my $format = shift || 'html';
3741 $hash ||= $hash_base || "HEAD";
3742 my %co = parse_commit
($hash);
3744 die_error
(undef, "Unknown commit object");
3747 # we need to prepare $formats_nav before any parameter munging
3749 if ($format eq 'html') {
3751 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
3752 hash
=>$hash, hash_parent
=>$hash_parent)},
3755 if (defined $hash_parent) {
3756 # commitdiff with two commits given
3757 my $hash_parent_short = $hash_parent;
3758 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3759 $hash_parent_short = substr($hash_parent, 0, 7);
3763 $cgi->a({-href
=> href
(action
=>"commitdiff",
3764 hash
=>$hash_parent)},
3765 esc_html
($hash_parent_short)) .
3767 } elsif (!$co{'parent'}) {
3769 $formats_nav .= ' (initial)';
3770 } elsif (scalar @{$co{'parents'}} == 1) {
3771 # single parent commit
3774 $cgi->a({-href
=> href
(action
=>"commitdiff",
3775 hash
=>$co{'parent'})},
3776 esc_html
(substr($co{'parent'}, 0, 7))) .
3783 $cgi->a({-href
=> href
(action
=>"commitdiff",
3785 esc_html
(substr($_, 0, 7)));
3786 } @{$co{'parents'}} ) .
3791 if (!defined $hash_parent) {
3792 $hash_parent = $co{'parent'} || '--root';
3798 if ($format eq 'html') {
3799 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3800 "--no-commit-id", "--patch-with-raw", "--full-index",
3801 $hash_parent, $hash, "--"
3802 or die_error
(undef, "Open git-diff-tree failed");
3804 while (my $line = <$fd>) {
3806 # empty line ends raw part of diff-tree output
3808 push @difftree, $line;
3811 } elsif ($format eq 'plain') {
3812 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3813 '-p', $hash_parent, $hash, "--"
3814 or die_error
(undef, "Open git-diff-tree failed");
3817 die_error
(undef, "Unknown commitdiff format");
3820 # non-textual hash id's can be cached
3822 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3826 # write commit message
3827 if ($format eq 'html') {
3828 my $refs = git_get_references
();
3829 my $ref = format_ref_marker
($refs, $co{'id'});
3831 git_header_html
(undef, $expires);
3832 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
3833 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
3834 git_print_authorship
(\
%co);
3835 print "<div class=\"page_body\">\n";
3836 if (@{$co{'comment'}} > 1) {
3837 print "<div class=\"log\">\n";
3838 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
3839 print "</div>\n"; # class="log"
3842 } elsif ($format eq 'plain') {
3843 my $refs = git_get_references
("tags");
3844 my $tagname = git_get_rev_name_tags
($hash);
3845 my $filename = basename
($project) . "-$hash.patch";
3848 -type
=> 'text/plain',
3849 -charset
=> 'utf-8',
3850 -expires
=> $expires,
3851 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
3852 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3855 Date: $ad{'rfc2822'} ($ad{'tz_local'})
3856 Subject: $co{'title'}
3858 print "X-Git-Tag: $tagname\n" if $tagname;
3859 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3861 foreach my $line (@{$co{'comment'}}) {
3868 if ($format eq 'html') {
3869 git_difftree_body
(\
@difftree, $hash, $hash_parent);
3872 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
3874 print "</div>\n"; # class="page_body"
3877 } elsif ($format eq 'plain') {
3881 or print "Reading git-diff-tree failed\n";
3885 sub git_commitdiff_plain
{
3886 git_commitdiff
('plain');
3890 if (!defined $hash_base) {
3891 $hash_base = git_get_head_hash
($project);
3893 if (!defined $page) {
3897 my %co = parse_commit
($hash_base);
3899 die_error
(undef, "Unknown commit object");
3902 my $refs = git_get_references
();
3903 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3905 if (!defined $hash && defined $file_name) {
3906 $hash = git_get_hash_by_path
($hash_base, $file_name);
3908 if (defined $hash) {
3909 $ftype = git_get_type
($hash);
3913 git_cmd
(), "rev-list", $limit, "--full-history", $hash_base, "--", $file_name
3914 or die_error
(undef, "Open git-rev-list-failed");
3915 my @revlist = map { chomp; $_ } <$fd>;
3917 or die_error
(undef, "Reading git-rev-list failed");
3919 my $paging_nav = '';
3922 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3923 file_name
=>$file_name)},
3925 $paging_nav .= " ⋅ " .
3926 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3927 file_name
=>$file_name, page
=>$page-1),
3928 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3930 $paging_nav .= "first";
3931 $paging_nav .= " ⋅ prev";
3933 if ($#revlist >= (100 * ($page+1)-1)) {
3934 $paging_nav .= " ⋅ " .
3935 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3936 file_name
=>$file_name, page
=>$page+1),
3937 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3939 $paging_nav .= " ⋅ next";
3942 if ($#revlist >= (100 * ($page+1)-1)) {
3944 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3945 file_name
=>$file_name, page
=>$page+1),
3946 -title
=> "Alt-n"}, "next");
3950 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
3951 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3952 git_print_page_path
($file_name, $ftype, $hash_base);
3954 git_history_body
(\
@revlist, ($page * 100), $#revlist,
3955 $refs, $hash_base, $ftype, $next_link);
3961 if (!defined $searchtext) {
3962 die_error
(undef, "Text field empty");
3964 if (!defined $hash) {
3965 $hash = git_get_head_hash
($project);
3967 my %co = parse_commit
($hash);
3969 die_error
(undef, "Unknown commit object");
3972 $searchtype ||= 'commit';
3973 if ($searchtype eq 'pickaxe') {
3974 # pickaxe may take all resources of your box and run for several minutes
3975 # with every query - so decide by yourself how public you make this feature
3976 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
3977 if (!$have_pickaxe) {
3978 die_error
('403 Permission denied', "Permission denied");
3983 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
3984 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
3986 print "<table cellspacing=\"0\">\n";
3988 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
3990 open my $fd, "-|", git_cmd
(), "rev-list",
3991 "--header", "--parents", $hash, "--"
3993 while (my $commit_text = <$fd>) {
3994 if (!grep m/$searchtext/i, $commit_text) {
3997 if ($searchtype eq 'author' && !grep m/\nauthor .*$searchtext/i, $commit_text) {
4000 if ($searchtype eq 'committer' && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
4003 my @commit_lines = split "\n", $commit_text;
4004 my %co = parse_commit
(undef, \
@commit_lines);
4009 print "<tr class=\"dark\">\n";
4011 print "<tr class=\"light\">\n";
4014 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4015 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
4017 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
4018 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
4019 my $comment = $co{'comment'};
4020 foreach my $line (@$comment) {
4021 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
4022 my $lead = esc_html
($1) || "";
4023 $lead = chop_str
($lead, 30, 10);
4024 my $match = esc_html
($2) || "";
4025 my $trail = esc_html
($3) || "";
4026 $trail = chop_str
($trail, 30, 10);
4027 my $text = "$lead<span class=\"match\">$match</span>$trail";
4028 print chop_str
($text, 80, 5) . "<br/>\n";
4032 "<td class=\"link\">" .
4033 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4035 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4042 if ($searchtype eq 'pickaxe') {
4044 my $git_command = git_cmd_str
();
4045 open my $fd, "-|", "$git_command rev-list $hash | " .
4046 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
4049 while (my $line = <$fd>) {
4050 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
4053 $set{'from_id'} = $3;
4055 $set{'id'} = $set{'to_id'};
4056 if ($set{'id'} =~ m/0{40}/) {
4057 $set{'id'} = $set{'from_id'};
4059 if ($set{'id'} =~ m/0{40}/) {
4063 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
4066 print "<tr class=\"dark\">\n";
4068 print "<tr class=\"light\">\n";
4071 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4072 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
4074 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4075 -class => "list subject"},
4076 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
4077 while (my $setref = shift @files) {
4079 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
4080 hash
=>$set{'id'}, file_name
=>$set{'file'}),
4082 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
4086 "<td class=\"link\">" .
4087 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4089 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4093 %co = parse_commit
($1);
4102 sub git_search_help
{
4104 git_print_page_nav
('','', $hash,$hash,$hash);
4107 <dt><b>commit</b></dt>
4108 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
4109 <dt><b>author</b></dt>
4110 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
4111 <dt><b>committer</b></dt>
4112 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
4114 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4115 if ($have_pickaxe) {
4117 <dt><b>pickaxe</b></dt>
4118 <dd>All commits that caused the string to appear or disappear from any file (changes that
4119 added, removed or "modified" the string) will be listed. This search can take a while and
4120 takes a lot of strain on the server, so please use it wisely.</dd>
4128 my $head = git_get_head_hash
($project);
4129 if (!defined $hash) {
4132 if (!defined $page) {
4135 my $refs = git_get_references
();
4137 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
4138 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash, "--"
4139 or die_error
(undef, "Open git-rev-list failed");
4140 my @revlist = map { chomp; $_ } <$fd>;
4143 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
4145 if ($#revlist >= (100 * ($page+1)-1)) {
4147 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
4148 -title
=> "Alt-n"}, "next");
4153 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
4154 git_print_header_div
('summary', $project);
4156 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
4161 ## ......................................................................
4162 ## feeds (RSS, Atom; OPML)
4165 my $format = shift || 'atom';
4166 my ($have_blame) = gitweb_check_feature
('blame');
4168 # Atom: http://www.atomenabled.org/developers/syndication/
4169 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
4170 if ($format ne 'rss' && $format ne 'atom') {
4171 die_error
(undef, "Unknown web feed format");
4174 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
4175 my $head = $hash || 'HEAD';
4176 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=150",
4177 $head, "--", (defined $file_name ? $file_name : ())
4178 or die_error
(undef, "Open git-rev-list failed");
4179 my @revlist = map { chomp; $_ } <$fd>;
4180 close $fd or die_error
(undef, "Reading git-rev-list failed");
4184 my $content_type = "application/$format+xml";
4185 if (defined $cgi->http('HTTP_ACCEPT') &&
4186 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
4187 # browser (feed reader) prefers text/xml
4188 $content_type = 'text/xml';
4190 if (defined($revlist[0])) {
4191 %latest_commit = parse_commit
($revlist[0]);
4192 %latest_date = parse_date
($latest_commit{'committer_epoch'});
4194 -type
=> $content_type,
4195 -charset
=> 'utf-8',
4196 -last_modified
=> $latest_date{'rfc2822'});
4199 -type
=> $content_type,
4200 -charset
=> 'utf-8');
4203 # Optimization: skip generating the body if client asks only
4204 # for Last-Modified date.
4205 return if ($cgi->request_method() eq 'HEAD');
4208 my $title = "$site_name - $project/$action";
4209 my $feed_type = 'log';
4210 if (defined $hash) {
4211 $title .= " - '$hash'";
4212 $feed_type = 'branch log';
4213 if (defined $file_name) {
4214 $title .= " :: $file_name";
4215 $feed_type = 'history';
4217 } elsif (defined $file_name) {
4218 $title .= " - $file_name";
4219 $feed_type = 'history';
4221 $title .= " $feed_type";
4222 my $descr = git_get_project_description
($project);
4223 if (defined $descr) {
4224 $descr = esc_html
($descr);
4226 $descr = "$project " .
4227 ($format eq 'rss' ? 'RSS' : 'Atom') .
4230 my $owner = git_get_project_owner
($project);
4231 $owner = esc_html
($owner);
4235 if (defined $file_name) {
4236 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
4237 } elsif (defined $hash) {
4238 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
4240 $alt_url = href
(-full
=>1, action
=>"summary");
4242 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
4243 if ($format eq 'rss') {
4245 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
4248 print "<title>$title</title>\n" .
4249 "<link>$alt_url</link>\n" .
4250 "<description>$descr</description>\n" .
4251 "<language>en</language>\n";
4252 } elsif ($format eq 'atom') {
4254 <feed xmlns="http://www.w3.org/2005/Atom">
4256 print "<title>$title</title>\n" .
4257 "<subtitle>$descr</subtitle>\n" .
4258 '<link rel="alternate" type="text/html" href="' .
4259 $alt_url . '" />' . "\n" .
4260 '<link rel="self" type="' . $content_type . '" href="' .
4261 $cgi->self_url() . '" />' . "\n" .
4262 "<id>" . href
(-full
=>1) . "</id>\n" .
4263 # use project owner for feed author
4264 "<author><name>$owner</name></author>\n";
4265 if (defined $favicon) {
4266 print "<icon>" . esc_url
($favicon) . "</icon>\n";
4268 if (defined $logo_url) {
4269 # not twice as wide as tall: 72 x 27 pixels
4270 print "<logo>" . esc_url
($logo_url) . "</logo>\n";
4272 if (! %latest_date) {
4273 # dummy date to keep the feed valid until commits trickle in:
4274 print "<updated>1970-01-01T00:00:00Z</updated>\n";
4276 print "<updated>$latest_date{'iso-8601'}</updated>\n";
4281 for (my $i = 0; $i <= $#revlist; $i++) {
4282 my $commit = $revlist[$i];
4283 my %co = parse_commit
($commit);
4284 # we read 150, we always show 30 and the ones more recent than 48 hours
4285 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
4288 my %cd = parse_date
($co{'committer_epoch'});
4290 # get list of changed files
4291 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4292 $co{'parent'}, $co{'id'}, "--", (defined $file_name ? $file_name : ())
4294 my @difftree = map { chomp; $_ } <$fd>;
4298 # print element (entry, item)
4299 my $co_url = href
(-full
=>1, action
=>"commit", hash
=>$commit);
4300 if ($format eq 'rss') {
4302 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
4303 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
4304 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
4305 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
4306 "<link>$co_url</link>\n" .
4307 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
4308 "<content:encoded>" .
4310 } elsif ($format eq 'atom') {
4312 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
4313 "<updated>$cd{'iso-8601'}</updated>\n" .
4314 "<author><name>" . esc_html
($co{'author_name'}) . "</name></author>\n" .
4315 # use committer for contributor
4316 "<contributor><name>" . esc_html
($co{'committer_name'}) . "</name></contributor>\n" .
4317 "<published>$cd{'iso-8601'}</published>\n" .
4318 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
4319 "<id>$co_url</id>\n" .
4320 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
4321 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
4323 my $comment = $co{'comment'};
4325 foreach my $line (@$comment) {
4326 $line = esc_html
($line);
4329 print "</pre><ul>\n";
4330 foreach my $difftree_line (@difftree) {
4331 my %difftree = parse_difftree_raw_line
($difftree_line);
4332 next if !$difftree{'from_id'};
4334 my $file = $difftree{'file'} || $difftree{'to_file'};
4338 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
4339 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
4340 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
4341 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
4342 -title
=> "diff"}, 'D');
4344 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
4345 file_name
=>$file, hash_base
=>$commit),
4346 -title
=> "blame"}, 'B');
4348 # if this is not a feed of a file history
4349 if (!defined $file_name || $file_name ne $file) {
4350 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
4351 file_name
=>$file, hash
=>$commit),
4352 -title
=> "history"}, 'H');
4354 $file = esc_path
($file);
4358 if ($format eq 'rss') {
4359 print "</ul>]]>\n" .
4360 "</content:encoded>\n" .
4362 } elsif ($format eq 'atom') {
4363 print "</ul>\n</div>\n" .
4370 if ($format eq 'rss') {
4371 print "</channel>\n</rss>\n";
4372 } elsif ($format eq 'atom') {
4386 my @list = git_get_projects_list
();
4388 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
4390 <?xml version="1.0" encoding="utf-8"?>
4391 <opml version="1.0">
4393 <title>$site_name OPML Export</title>
4396 <outline text="git RSS feeds">
4399 foreach my $pr (@list) {
4401 my $head = git_get_head_hash
($proj{'path'});
4402 if (!defined $head) {
4405 $git_dir = "$projectroot/$proj{'path'}";
4406 my %co = parse_commit
($head);
4411 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
4412 my $rss = "$my_url?p=$proj{'path'};a=rss";
4413 my $html = "$my_url?p=$proj{'path'};a=summary";
4414 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";