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 # quote control characters and escape filename to HTML
594 $str = to_utf8
($str);
595 $str = escapeHTML
($str);
596 if ($opts{'-nbsp'}) {
597 $str =~ s/ / /g;
599 $str =~ s
|([[:cntrl
:]])|quot_cec
($1)|eg
;
603 # Make control characters "printable", using character escape codes (CEC)
606 my %es = ( # character escape codes, aka escape sequences
607 "\t" => '\t', # tab (HT)
608 "\n" => '\n', # line feed (LF)
609 "\r" => '\r', # carrige return (CR)
610 "\f" => '\f', # form feed (FF)
611 "\b" => '\b', # backspace (BS)
612 "\a" => '\a', # alarm (bell) (BEL)
613 "\e" => '\e', # escape (ESC)
614 "\013" => '\v', # vertical tab (VT)
615 "\000" => '\0', # nul character (NUL)
617 my $chr = ( (exists $es{$cntrl})
619 : sprintf('\%03o', ord($cntrl)) );
620 return "<span class=\"cntrl\">$chr</span>";
623 # Alternatively use unicode control pictures codepoints,
624 # Unicode "printable representation" (PR)
627 my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
628 return "<span class=\"cntrl\">$chr</span>";
631 # git may return quoted and escaped filenames
637 my %es = ( # character escape codes, aka escape sequences
638 't' => "\t", # tab (HT, TAB)
639 'n' => "\n", # newline (NL)
640 'r' => "\r", # return (CR)
641 'f' => "\f", # form feed (FF)
642 'b' => "\b", # backspace (BS)
643 'a' => "\a", # alarm (bell) (BEL)
644 'e' => "\e", # escape (ESC)
645 'v' => "\013", # vertical tab (VT)
648 if ($seq =~ m/^[0-7]{1,3}$/) {
649 # octal char sequence
650 return chr(oct($seq));
651 } elsif (exists $es{$seq}) {
652 # C escape sequence, aka character escape code
655 # quoted ordinary character
659 if ($str =~ m/^"(.*)"$/) {
662 $str =~ s/\\([^0-7]|[0-7]{1,3})/unq($1)/eg;
667 # escape tabs (convert tabs to spaces)
671 while ((my $pos = index($line, "\t")) != -1) {
672 if (my $count = (8 - ($pos % 8))) {
673 my $spaces = ' ' x
$count;
674 $line =~ s/\t/$spaces/;
681 sub project_in_list
{
683 my @list = git_get_projects_list
();
684 return @list && scalar(grep { $_->{'path'} eq $project } @list);
687 ## ----------------------------------------------------------------------
688 ## HTML aware string manipulation
693 my $add_len = shift || 10;
695 # allow only $len chars, but don't cut a word if it would fit in $add_len
696 # if it doesn't fit, cut it if it's still longer than the dots we would add
697 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@]{0,$add_len})(.*)/;
700 if (length($tail) > 4) {
702 $body =~ s/&[^;]*$//; # remove chopped character entities
707 ## ----------------------------------------------------------------------
708 ## functions returning short strings
710 # CSS class for given age value (in seconds)
714 if ($age < 60*60*2) {
716 } elsif ($age < 60*60*24*2) {
723 # convert age in seconds to "nn units ago" string
728 if ($age > 60*60*24*365*2) {
729 $age_str = (int $age/60/60/24/365);
730 $age_str .= " years ago";
731 } elsif ($age > 60*60*24*(365/12)*2) {
732 $age_str = int $age/60/60/24/(365/12);
733 $age_str .= " months ago";
734 } elsif ($age > 60*60*24*7*2) {
735 $age_str = int $age/60/60/24/7;
736 $age_str .= " weeks ago";
737 } elsif ($age > 60*60*24*2) {
738 $age_str = int $age/60/60/24;
739 $age_str .= " days ago";
740 } elsif ($age > 60*60*2) {
741 $age_str = int $age/60/60;
742 $age_str .= " hours ago";
743 } elsif ($age > 60*2) {
744 $age_str = int $age/60;
745 $age_str .= " min ago";
748 $age_str .= " sec ago";
750 $age_str .= " right now";
755 # convert file mode in octal to symbolic file mode string
757 my $mode = oct shift;
759 if (S_ISDIR
($mode & S_IFMT
)) {
761 } elsif (S_ISLNK
($mode)) {
763 } elsif (S_ISREG
($mode)) {
764 # git cares only about the executable bit
765 if ($mode & S_IXUSR
) {
775 # convert file mode in octal to file type string
779 if ($mode !~ m/^[0-7]+$/) {
785 if (S_ISDIR
($mode & S_IFMT
)) {
787 } elsif (S_ISLNK
($mode)) {
789 } elsif (S_ISREG
($mode)) {
796 # convert file mode in octal to file type description string
800 if ($mode !~ m/^[0-7]+$/) {
806 if (S_ISDIR
($mode & S_IFMT
)) {
808 } elsif (S_ISLNK
($mode)) {
810 } elsif (S_ISREG
($mode)) {
811 if ($mode & S_IXUSR
) {
822 ## ----------------------------------------------------------------------
823 ## functions returning short HTML fragments, or transforming HTML fragments
824 ## which don't beling to other sections
826 # format line of commit message.
827 sub format_log_line_html
{
830 $line = esc_html
($line, -nbsp
=>1);
831 if ($line =~ m/([0-9a-fA-F]{40})/) {
833 if (git_get_type
($hash_text) eq "commit") {
835 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$hash_text),
836 -class => "text"}, $hash_text);
837 $line =~ s/$hash_text/$link/;
843 # format marker of refs pointing to given object
844 sub format_ref_marker
{
845 my ($refs, $id) = @_;
848 if (defined $refs->{$id}) {
849 foreach my $ref (@{$refs->{$id}}) {
850 my ($type, $name) = qw();
851 # e.g. tags/v2.6.11 or heads/next
852 if ($ref =~ m!^(.*?)s?/(.*)$!) {
860 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
865 return ' <span class="refs">'. $markers . '</span>';
871 # format, perhaps shortened and with markers, title line
872 sub format_subject_html
{
873 my ($long, $short, $href, $extra) = @_;
874 $extra = '' unless defined($extra);
876 if (length($short) < length($long)) {
877 return $cgi->a({-href
=> $href, -class => "list subject",
878 -title
=> to_utf8
($long)},
879 esc_html
($short) . $extra);
881 return $cgi->a({-href
=> $href, -class => "list subject"},
882 esc_html
($long) . $extra);
886 # format patch (diff) line (rather not to be used for diff headers)
887 sub format_diff_line
{
889 my ($from, $to) = @_;
890 my $char = substr($line, 0, 1);
896 $diff_class = " add";
897 } elsif ($char eq "-") {
898 $diff_class = " rem";
899 } elsif ($char eq "@") {
900 $diff_class = " chunk_header";
901 } elsif ($char eq "\\") {
902 $diff_class = " incomplete";
904 $line = untabify
($line);
905 if ($from && $to && $line =~ m/^\@{2} /) {
906 my ($from_text, $from_start, $from_lines, $to_text, $to_start, $to_lines, $section) =
907 $line =~ m/^\@{2} (-(\d+)(?:,(\d+))?) (\+(\d+)(?:,(\d+))?) \@{2}(.*)$/;
909 $from_lines = 0 unless defined $from_lines;
910 $to_lines = 0 unless defined $to_lines;
912 if ($from->{'href'}) {
913 $from_text = $cgi->a({-href
=>"$from->{'href'}#l$from_start",
914 -class=>"list"}, $from_text);
917 $to_text = $cgi->a({-href
=>"$to->{'href'}#l$to_start",
918 -class=>"list"}, $to_text);
920 $line = "<span class=\"chunk_info\">@@ $from_text $to_text @@</span>" .
921 "<span class=\"section\">" . esc_html
($section, -nbsp
=>1) . "</span>";
922 return "<div class=\"diff$diff_class\">$line</div>\n";
924 return "<div class=\"diff$diff_class\">" . esc_html
($line, -nbsp
=>1) . "</div>\n";
927 ## ----------------------------------------------------------------------
928 ## git utility subroutines, invoking git commands
930 # returns path to the core git executable and the --git-dir parameter as list
932 return $GIT, '--git-dir='.$git_dir;
935 # returns path to the core git executable and the --git-dir parameter as string
937 return join(' ', git_cmd
());
940 # get HEAD ref of given project as hash
941 sub git_get_head_hash
{
943 my $o_git_dir = $git_dir;
945 $git_dir = "$projectroot/$project";
946 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
949 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
953 if (defined $o_git_dir) {
954 $git_dir = $o_git_dir;
959 # get type of given object
963 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
970 sub git_get_project_config
{
971 my ($key, $type) = @_;
973 return unless ($key);
974 $key =~ s/^gitweb\.//;
975 return if ($key =~ m/\W/);
977 my @x = (git_cmd
(), 'repo-config');
978 if (defined $type) { push @x, $type; }
980 push @x, "gitweb.$key";
986 # get hash of given path at given ref
987 sub git_get_hash_by_path
{
989 my $path = shift || return undef;
994 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
995 or die_error
(undef, "Open git-ls-tree failed");
997 close $fd or return undef;
999 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1000 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
1001 if (defined $type && $type ne $2) {
1002 # type doesn't match
1008 ## ......................................................................
1009 ## git utility functions, directly accessing git repository
1011 sub git_get_project_description
{
1014 open my $fd, "$projectroot/$path/description" or return undef;
1021 sub git_get_project_url_list
{
1024 open my $fd, "$projectroot/$path/cloneurl" or return;
1025 my @git_project_url_list = map { chomp; $_ } <$fd>;
1028 return wantarray ? @git_project_url_list : \
@git_project_url_list;
1031 sub git_get_projects_list
{
1036 $filter =~ s/\.git$//;
1038 if (-d
$projects_list) {
1039 # search in directory
1040 my $dir = $projects_list . ($filter ? "/$filter" : '');
1041 # remove the trailing "/"
1043 my $pfxlen = length("$dir");
1045 my ($check_forks) = gitweb_check_feature
('forks');
1048 follow_fast
=> 1, # follow symbolic links
1049 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
1051 # skip project-list toplevel, if we get it.
1052 return if (m!^[/.]$!);
1053 # only directories can be git repositories
1054 return unless (-d
$_);
1056 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
1057 # we check related file in $projectroot
1058 if ($check_forks and $subdir =~ m
#/.#) {
1059 $File::Find
::prune
= 1;
1060 } elsif (check_export_ok
("$projectroot/$filter/$subdir")) {
1061 push @list, { path
=> ($filter ? "$filter/" : '') . $subdir };
1062 $File::Find
::prune
= 1;
1067 } elsif (-f
$projects_list) {
1068 # read from file(url-encoded):
1069 # 'git%2Fgit.git Linus+Torvalds'
1070 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1071 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1072 open my ($fd), $projects_list or return;
1073 while (my $line = <$fd>) {
1075 my ($path, $owner) = split ' ', $line;
1076 $path = unescape
($path);
1077 $owner = unescape
($owner);
1078 if (!defined $path) {
1081 if ($filter ne '') {
1082 # looking for forks;
1083 my $pfx = substr($path, 0, length($filter));
1084 if ($pfx ne $filter) {
1087 my $sfx = substr($path, length($filter));
1088 if ($sfx !~ /^\/.*\
.git
$/) {
1092 if (check_export_ok
("$projectroot/$path")) {
1095 owner
=> to_utf8
($owner),
1102 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
1106 sub git_get_project_owner
{
1107 my $project = shift;
1110 return undef unless $project;
1112 # read from file (url-encoded):
1113 # 'git%2Fgit.git Linus+Torvalds'
1114 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
1115 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
1116 if (-f
$projects_list) {
1117 open (my $fd , $projects_list);
1118 while (my $line = <$fd>) {
1120 my ($pr, $ow) = split ' ', $line;
1121 $pr = unescape
($pr);
1122 $ow = unescape
($ow);
1123 if ($pr eq $project) {
1124 $owner = to_utf8
($ow);
1130 if (!defined $owner) {
1131 $owner = get_file_owner
("$projectroot/$project");
1137 sub git_get_last_activity
{
1141 $git_dir = "$projectroot/$path";
1142 open($fd, "-|", git_cmd
(), 'for-each-ref',
1143 '--format=%(refname) %(committer)',
1144 '--sort=-committerdate',
1145 'refs/heads') or return;
1146 my $most_recent = <$fd>;
1147 close $fd or return;
1148 if ($most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1150 my $age = time - $timestamp;
1151 return ($age, age_string
($age));
1155 sub git_get_references
{
1156 my $type = shift || "";
1158 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1159 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1160 open my $fd, "-|", git_cmd
(), "show-ref", "--dereference",
1161 ($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
1164 while (my $line = <$fd>) {
1166 if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
1167 if (defined $refs{$1}) {
1168 push @{$refs{$1}}, $2;
1174 close $fd or return;
1178 sub git_get_rev_name_tags
{
1179 my $hash = shift || return undef;
1181 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
1183 my $name_rev = <$fd>;
1186 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
1189 # catches also '$hash undefined' output
1194 ## ----------------------------------------------------------------------
1195 ## parse to hash functions
1199 my $tz = shift || "-0000";
1202 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
1203 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1204 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
1205 $date{'hour'} = $hour;
1206 $date{'minute'} = $min;
1207 $date{'mday'} = $mday;
1208 $date{'day'} = $days[$wday];
1209 $date{'month'} = $months[$mon];
1210 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
1211 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
1212 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
1213 $mday, $months[$mon], $hour ,$min;
1214 $date{'iso-8601'} = sprintf "%04d-%02d-%02dT%02d:%02d:%02dZ",
1215 1900+$year, $mon, $mday, $hour ,$min, $sec;
1217 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
1218 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
1219 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
1220 $date{'hour_local'} = $hour;
1221 $date{'minute_local'} = $min;
1222 $date{'tz_local'} = $tz;
1223 $date{'iso-tz'} = sprintf("%04d-%02d-%02d %02d:%02d:%02d %s",
1224 1900+$year, $mon+1, $mday,
1225 $hour, $min, $sec, $tz);
1234 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
1235 $tag{'id'} = $tag_id;
1236 while (my $line = <$fd>) {
1238 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
1239 $tag{'object'} = $1;
1240 } elsif ($line =~ m/^type (.+)$/) {
1242 } elsif ($line =~ m/^tag (.+)$/) {
1244 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
1245 $tag{'author'} = $1;
1248 } elsif ($line =~ m/--BEGIN/) {
1249 push @comment, $line;
1251 } elsif ($line eq "") {
1255 push @comment, <$fd>;
1256 $tag{'comment'} = \
@comment;
1257 close $fd or return;
1258 if (!defined $tag{'name'}) {
1265 my $commit_id = shift;
1266 my $commit_text = shift;
1271 if (defined $commit_text) {
1272 @commit_lines = @$commit_text;
1275 open my $fd, "-|", git_cmd
(), "rev-list",
1276 "--header", "--parents", "--max-count=1",
1279 @commit_lines = split '\n', <$fd>;
1280 close $fd or return;
1283 my $header = shift @commit_lines;
1284 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
1287 ($co{'id'}, my @parents) = split ' ', $header;
1288 $co{'parents'} = \
@parents;
1289 $co{'parent'} = $parents[0];
1290 while (my $line = shift @commit_lines) {
1291 last if $line eq "\n";
1292 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
1294 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
1296 $co{'author_epoch'} = $2;
1297 $co{'author_tz'} = $3;
1298 if ($co{'author'} =~ m/^([^<]+) </) {
1299 $co{'author_name'} = $1;
1301 $co{'author_name'} = $co{'author'};
1303 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
1304 $co{'committer'} = $1;
1305 $co{'committer_epoch'} = $2;
1306 $co{'committer_tz'} = $3;
1307 $co{'committer_name'} = $co{'committer'};
1308 $co{'committer_name'} =~ s/ <.*//;
1311 if (!defined $co{'tree'}) {
1315 foreach my $title (@commit_lines) {
1318 $co{'title'} = chop_str
($title, 80, 5);
1319 # remove leading stuff of merges to make the interesting part visible
1320 if (length($title) > 50) {
1321 $title =~ s/^Automatic //;
1322 $title =~ s/^merge (of|with) /Merge ... /i;
1323 if (length($title) > 50) {
1324 $title =~ s/(http|rsync):\/\///;
1326 if (length($title) > 50) {
1327 $title =~ s/(master|www|rsync)\.//;
1329 if (length($title) > 50) {
1330 $title =~ s/kernel.org:?//;
1332 if (length($title) > 50) {
1333 $title =~ s/\/pub\/scm//;
1336 $co{'title_short'} = chop_str
($title, 50, 5);
1340 if ($co{'title'} eq "") {
1341 $co{'title'} = $co{'title_short'} = '(no commit message)';
1343 # remove added spaces
1344 foreach my $line (@commit_lines) {
1347 $co{'comment'} = \
@commit_lines;
1349 my $age = time - $co{'committer_epoch'};
1351 $co{'age_string'} = age_string
($age);
1352 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1353 if ($age > 60*60*24*7*2) {
1354 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1355 $co{'age_string_age'} = $co{'age_string'};
1357 $co{'age_string_date'} = $co{'age_string'};
1358 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1363 # parse ref from ref_file, given by ref_id, with given type
1365 my $ref_file = shift;
1367 my $type = shift || git_get_type
($ref_id);
1370 $ref_item{'type'} = $type;
1371 $ref_item{'id'} = $ref_id;
1372 $ref_item{'epoch'} = 0;
1373 $ref_item{'age'} = "unknown";
1374 if ($type eq "tag") {
1375 my %tag = parse_tag
($ref_id);
1376 $ref_item{'comment'} = $tag{'comment'};
1377 if ($tag{'type'} eq "commit") {
1378 my %co = parse_commit
($tag{'object'});
1379 $ref_item{'epoch'} = $co{'committer_epoch'};
1380 $ref_item{'age'} = $co{'age_string'};
1381 } elsif (defined($tag{'epoch'})) {
1382 my $age = time - $tag{'epoch'};
1383 $ref_item{'epoch'} = $tag{'epoch'};
1384 $ref_item{'age'} = age_string
($age);
1386 $ref_item{'reftype'} = $tag{'type'};
1387 $ref_item{'name'} = $tag{'name'};
1388 $ref_item{'refid'} = $tag{'object'};
1389 } elsif ($type eq "commit"){
1390 my %co = parse_commit
($ref_id);
1391 $ref_item{'reftype'} = "commit";
1392 $ref_item{'name'} = $ref_file;
1393 $ref_item{'title'} = $co{'title'};
1394 $ref_item{'refid'} = $ref_id;
1395 $ref_item{'epoch'} = $co{'committer_epoch'};
1396 $ref_item{'age'} = $co{'age_string'};
1398 $ref_item{'reftype'} = $type;
1399 $ref_item{'name'} = $ref_file;
1400 $ref_item{'refid'} = $ref_id;
1406 # parse line of git-diff-tree "raw" output
1407 sub parse_difftree_raw_line
{
1411 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1412 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1413 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1414 $res{'from_mode'} = $1;
1415 $res{'to_mode'} = $2;
1416 $res{'from_id'} = $3;
1418 $res{'status'} = $5;
1419 $res{'similarity'} = $6;
1420 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1421 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1423 $res{'file'} = unquote
($7);
1426 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1427 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1428 $res{'commit'} = $1;
1431 return wantarray ? %res : \
%res;
1434 # parse line of git-ls-tree output
1435 sub parse_ls_tree_line
($;%) {
1440 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1441 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
1449 $res{'name'} = unquote
($4);
1452 return wantarray ? %res : \
%res;
1455 ## ......................................................................
1456 ## parse to array of hashes functions
1458 sub git_get_heads_list
{
1462 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1463 ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate',
1464 '--format=%(objectname) %(refname) %(subject)%00%(committer)',
1467 while (my $line = <$fd>) {
1471 my ($refinfo, $committerinfo) = split(/\0/, $line);
1472 my ($hash, $name, $title) = split(' ', $refinfo, 3);
1473 my ($committer, $epoch, $tz) =
1474 ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/);
1475 $name =~ s!^refs/heads/!!;
1477 $ref_item{'name'} = $name;
1478 $ref_item{'id'} = $hash;
1479 $ref_item{'title'} = $title || '(no commit message)';
1480 $ref_item{'epoch'} = $epoch;
1482 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1484 $ref_item{'age'} = "unknown";
1487 push @headslist, \
%ref_item;
1491 return wantarray ? @headslist : \
@headslist;
1494 sub git_get_tags_list
{
1498 open my $fd, '-|', git_cmd
(), 'for-each-ref',
1499 ($limit ? '--count='.($limit+1) : ()), '--sort=-creatordate',
1500 '--format=%(objectname) %(objecttype) %(refname) '.
1501 '%(*objectname) %(*objecttype) %(subject)%00%(creator)',
1504 while (my $line = <$fd>) {
1508 my ($refinfo, $creatorinfo) = split(/\0/, $line);
1509 my ($id, $type, $name, $refid, $reftype, $title) = split(' ', $refinfo, 6);
1510 my ($creator, $epoch, $tz) =
1511 ($creatorinfo =~ /^(.*) ([0-9]+) (.*)$/);
1512 $name =~ s!^refs/tags/!!;
1514 $ref_item{'type'} = $type;
1515 $ref_item{'id'} = $id;
1516 $ref_item{'name'} = $name;
1517 if ($type eq "tag") {
1518 $ref_item{'subject'} = $title;
1519 $ref_item{'reftype'} = $reftype;
1520 $ref_item{'refid'} = $refid;
1522 $ref_item{'reftype'} = $type;
1523 $ref_item{'refid'} = $id;
1526 if ($type eq "tag" || $type eq "commit") {
1527 $ref_item{'epoch'} = $epoch;
1529 $ref_item{'age'} = age_string
(time - $ref_item{'epoch'});
1531 $ref_item{'age'} = "unknown";
1535 push @tagslist, \
%ref_item;
1539 return wantarray ? @tagslist : \
@tagslist;
1542 ## ----------------------------------------------------------------------
1543 ## filesystem-related functions
1545 sub get_file_owner
{
1548 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1549 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1550 if (!defined $gcos) {
1554 $owner =~ s/[,;].*$//;
1555 return to_utf8
($owner);
1558 ## ......................................................................
1559 ## mimetype related functions
1561 sub mimetype_guess_file
{
1562 my $filename = shift;
1563 my $mimemap = shift;
1564 -r
$mimemap or return undef;
1567 open(MIME
, $mimemap) or return undef;
1569 next if m/^#/; # skip comments
1570 my ($mime, $exts) = split(/\t+/);
1571 if (defined $exts) {
1572 my @exts = split(/\s+/, $exts);
1573 foreach my $ext (@exts) {
1574 $mimemap{$ext} = $mime;
1580 $filename =~ /\.([^.]*)$/;
1581 return $mimemap{$1};
1584 sub mimetype_guess
{
1585 my $filename = shift;
1587 $filename =~ /\./ or return undef;
1589 if ($mimetypes_file) {
1590 my $file = $mimetypes_file;
1591 if ($file !~ m!^/!) { # if it is relative path
1592 # it is relative to project
1593 $file = "$projectroot/$project/$file";
1595 $mime = mimetype_guess_file
($filename, $file);
1597 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1603 my $filename = shift;
1606 my $mime = mimetype_guess
($filename);
1607 $mime and return $mime;
1611 return $default_blob_plain_mimetype unless $fd;
1614 return 'text/plain' .
1615 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1616 } elsif (! $filename) {
1617 return 'application/octet-stream';
1618 } elsif ($filename =~ m/\.png$/i) {
1620 } elsif ($filename =~ m/\.gif$/i) {
1622 } elsif ($filename =~ m/\.jpe?g$/i) {
1623 return 'image/jpeg';
1625 return 'application/octet-stream';
1629 ## ======================================================================
1630 ## functions printing HTML: header, footer, error page
1632 sub git_header_html
{
1633 my $status = shift || "200 OK";
1634 my $expires = shift;
1636 my $title = "$site_name";
1637 if (defined $project) {
1638 $title .= " - $project";
1639 if (defined $action) {
1640 $title .= "/$action";
1641 if (defined $file_name) {
1642 $title .= " - " . esc_path
($file_name);
1643 if ($action eq "tree" && $file_name !~ m
|/$|) {
1650 # require explicit support from the UA if we are to send the page as
1651 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1652 # we have to do this because MSIE sometimes globs '*/*', pretending to
1653 # support xhtml+xml but choking when it gets what it asked for.
1654 if (defined $cgi->http('HTTP_ACCEPT') &&
1655 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1656 $cgi->Accept('application/xhtml+xml') != 0) {
1657 $content_type = 'application/xhtml+xml';
1659 $content_type = 'text/html';
1661 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1662 -status
=> $status, -expires
=> $expires);
1664 <?xml version="1.0" encoding="utf-8"?>
1665 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1666 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1667 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1668 <!-- git core binaries version $git_version -->
1670 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1671 <meta name="generator" content="gitweb/$version git/$git_version"/>
1672 <meta name="robots" content="index, nofollow"/>
1673 <title>$title</title>
1675 # print out each stylesheet that exist
1676 if (defined $stylesheet) {
1677 #provides backwards capability for those people who define style sheet in a config file
1678 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1680 foreach my $stylesheet (@stylesheets) {
1681 next unless $stylesheet;
1682 print '<link rel="stylesheet" type="text/css" href="'.$stylesheet.'"/>'."\n";
1685 if (defined $project) {
1686 printf('<link rel="alternate" title="%s log RSS feed" '.
1687 'href="%s" type="application/rss+xml" />'."\n",
1688 esc_param
($project), href
(action
=>"rss"));
1689 printf('<link rel="alternate" title="%s log Atom feed" '.
1690 'href="%s" type="application/atom+xml" />'."\n",
1691 esc_param
($project), href
(action
=>"atom"));
1693 printf('<link rel="alternate" title="%s projects list" '.
1694 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1695 $site_name, href
(project
=>undef, action
=>"project_index"));
1696 printf('<link rel="alternate" title="%s projects feeds" '.
1697 'href="%s" type="text/x-opml"/>'."\n",
1698 $site_name, href
(project
=>undef, action
=>"opml"));
1700 if (defined $favicon) {
1701 print qq(<link rel="shortcut icon" href="$favicon" type="image/png"/>\n);
1707 if (-f
$site_header) {
1708 open (my $fd, $site_header);
1713 print "<div class=\"page_header\">\n" .
1714 $cgi->a({-href
=> esc_url
($logo_url),
1715 -title
=> $logo_label},
1716 qq(<img src="$logo" width="72" height="27" alt="git" class="logo"/>));
1717 print $cgi->a({-href
=> esc_url
($home_link)}, $home_link_str) . " / ";
1718 if (defined $project) {
1719 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1720 if (defined $action) {
1724 if (!defined $searchtext) {
1728 if (defined $hash_base) {
1729 $search_hash = $hash_base;
1730 } elsif (defined $hash) {
1731 $search_hash = $hash;
1733 $search_hash = "HEAD";
1735 $cgi->param("a", "search");
1736 $cgi->param("h", $search_hash);
1737 $cgi->param("p", $project);
1738 print $cgi->startform(-method => "get", -action
=> $my_uri) .
1739 "<div class=\"search\">\n" .
1740 $cgi->hidden(-name
=> "p") . "\n" .
1741 $cgi->hidden(-name
=> "a") . "\n" .
1742 $cgi->hidden(-name
=> "h") . "\n" .
1743 $cgi->popup_menu(-name
=> 'st', -default => 'commit',
1744 -values => ['commit', 'author', 'committer', 'pickaxe']) .
1745 $cgi->sup($cgi->a({-href
=> href
(action
=>"search_help")}, "?")) .
1747 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1749 $cgi->end_form() . "\n";
1754 sub git_footer_html
{
1755 print "<div class=\"page_footer\">\n";
1756 if (defined $project) {
1757 my $descr = git_get_project_description
($project);
1758 if (defined $descr) {
1759 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1761 print $cgi->a({-href
=> href
(action
=>"rss"),
1762 -class => "rss_logo"}, "RSS") . " ";
1763 print $cgi->a({-href
=> href
(action
=>"atom"),
1764 -class => "rss_logo"}, "Atom") . "\n";
1766 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1767 -class => "rss_logo"}, "OPML") . " ";
1768 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1769 -class => "rss_logo"}, "TXT") . "\n";
1773 if (-f
$site_footer) {
1774 open (my $fd, $site_footer);
1784 my $status = shift || "403 Forbidden";
1785 my $error = shift || "Malformed query, file missing or permission denied";
1787 git_header_html
($status);
1789 <div class="page_body">
1799 ## ----------------------------------------------------------------------
1800 ## functions printing or outputting HTML: navigation
1802 sub git_print_page_nav
{
1803 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1804 $extra = '' if !defined $extra; # pager or formats
1806 my @navs = qw(summary shortlog log commit commitdiff tree);
1808 @navs = grep { $_ ne $suppress } @navs;
1811 my %arg = map { $_ => {action
=>$_} } @navs;
1812 if (defined $head) {
1813 for (qw(commit commitdiff)) {
1814 $arg{$_}{hash
} = $head;
1816 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1817 for (qw(shortlog log)) {
1818 $arg{$_}{hash
} = $head;
1822 $arg{tree
}{hash
} = $treehead if defined $treehead;
1823 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1825 print "<div class=\"page_nav\">\n" .
1827 map { $_ eq $current ?
1828 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1830 print "<br/>\n$extra<br/>\n" .
1834 sub format_paging_nav
{
1835 my ($action, $hash, $head, $page, $nrevs) = @_;
1839 if ($hash ne $head || $page) {
1840 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1842 $paging_nav .= "HEAD";
1846 $paging_nav .= " ⋅ " .
1847 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1848 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1850 $paging_nav .= " ⋅ prev";
1853 if ($nrevs >= (100 * ($page+1)-1)) {
1854 $paging_nav .= " ⋅ " .
1855 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1856 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1858 $paging_nav .= " ⋅ next";
1864 ## ......................................................................
1865 ## functions printing or outputting HTML: div
1867 sub git_print_header_div
{
1868 my ($action, $title, $hash, $hash_base) = @_;
1871 $args{action
} = $action;
1872 $args{hash
} = $hash if $hash;
1873 $args{hash_base
} = $hash_base if $hash_base;
1875 print "<div class=\"header\">\n" .
1876 $cgi->a({-href
=> href
(%args), -class => "title"},
1877 $title ? $title : $action) .
1881 #sub git_print_authorship (\%) {
1882 sub git_print_authorship
{
1885 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
1886 print "<div class=\"author_date\">" .
1887 esc_html
($co->{'author_name'}) .
1889 if ($ad{'hour_local'} < 6) {
1890 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1891 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1893 printf(" (%02d:%02d %s)",
1894 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1899 sub git_print_page_path
{
1905 print "<div class=\"page_path\">";
1906 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hb),
1907 -title
=> 'tree root'}, "[$project]");
1909 if (defined $name) {
1910 my @dirname = split '/', $name;
1911 my $basename = pop @dirname;
1914 foreach my $dir (@dirname) {
1915 $fullname .= ($fullname ? '/' : '') . $dir;
1916 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
1918 -title
=> esc_html
($fullname)}, esc_path
($dir));
1921 if (defined $type && $type eq 'blob') {
1922 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1924 -title
=> esc_html
($name)}, esc_path
($basename));
1925 } elsif (defined $type && $type eq 'tree') {
1926 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
1928 -title
=> esc_html
($name)}, esc_path
($basename));
1931 print esc_path
($basename);
1934 print "<br/></div>\n";
1937 # sub git_print_log (\@;%) {
1938 sub git_print_log
($;%) {
1942 if ($opts{'-remove_title'}) {
1943 # remove title, i.e. first line of log
1946 # remove leading empty lines
1947 while (defined $log->[0] && $log->[0] eq "") {
1954 foreach my $line (@$log) {
1955 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1958 if (! $opts{'-remove_signoff'}) {
1959 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1962 # remove signoff lines
1969 # print only one empty line
1970 # do not print empty line after signoff
1972 next if ($empty || $signoff);
1978 print format_log_line_html
($line) . "<br/>\n";
1981 if ($opts{'-final_empty_line'}) {
1982 # end with single empty line
1983 print "<br/>\n" unless $empty;
1987 # print tree entry (row of git_tree), but without encompassing <tr> element
1988 sub git_print_tree_entry
{
1989 my ($t, $basedir, $hash_base, $have_blame) = @_;
1992 $base_key{hash_base
} = $hash_base if defined $hash_base;
1994 # The format of a table row is: mode list link. Where mode is
1995 # the mode of the entry, list is the name of the entry, an href,
1996 # and link is the action links of the entry.
1998 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
1999 if ($t->{'type'} eq "blob") {
2000 print "<td class=\"list\">" .
2001 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2002 file_name
=>"$basedir$t->{'name'}", %base_key),
2003 -class => "list"}, esc_path
($t->{'name'})) . "</td>\n";
2004 print "<td class=\"link\">";
2005 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
2006 file_name
=>"$basedir$t->{'name'}", %base_key)},
2010 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
2011 file_name
=>"$basedir$t->{'name'}", %base_key)},
2014 if (defined $hash_base) {
2016 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2017 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
2021 $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hash_base,
2022 file_name
=>"$basedir$t->{'name'}")},
2026 } elsif ($t->{'type'} eq "tree") {
2027 print "<td class=\"list\">";
2028 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2029 file_name
=>"$basedir$t->{'name'}", %base_key)},
2030 esc_path
($t->{'name'}));
2032 print "<td class=\"link\">";
2033 print $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
2034 file_name
=>"$basedir$t->{'name'}", %base_key)},
2036 if (defined $hash_base) {
2038 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2039 file_name
=>"$basedir$t->{'name'}")},
2046 ## ......................................................................
2047 ## functions printing large fragments of HTML
2049 sub git_difftree_body
{
2050 my ($difftree, $hash, $parent) = @_;
2051 my ($have_blame) = gitweb_check_feature
('blame');
2052 print "<div class=\"list_head\">\n";
2053 if ($#{$difftree} > 10) {
2054 print(($#{$difftree} + 1) . " files changed:\n");
2058 print "<table class=\"diff_tree\">\n";
2061 foreach my $line (@{$difftree}) {
2062 my %diff = parse_difftree_raw_line
($line);
2065 print "<tr class=\"dark\">\n";
2067 print "<tr class=\"light\">\n";
2071 my ($to_mode_oct, $to_mode_str, $to_file_type);
2072 my ($from_mode_oct, $from_mode_str, $from_file_type);
2073 if ($diff{'to_mode'} ne ('0' x
6)) {
2074 $to_mode_oct = oct $diff{'to_mode'};
2075 if (S_ISREG
($to_mode_oct)) { # only for regular file
2076 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
2078 $to_file_type = file_type
($diff{'to_mode'});
2080 if ($diff{'from_mode'} ne ('0' x
6)) {
2081 $from_mode_oct = oct $diff{'from_mode'};
2082 if (S_ISREG
($to_mode_oct)) { # only for regular file
2083 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
2085 $from_file_type = file_type
($diff{'from_mode'});
2088 if ($diff{'status'} eq "A") { # created
2089 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
2090 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
2091 $mode_chng .= "]</span>";
2093 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2094 hash_base
=>$hash, file_name
=>$diff{'file'}),
2095 -class => "list"}, esc_path
($diff{'file'}));
2097 print "<td>$mode_chng</td>\n";
2098 print "<td class=\"link\">";
2099 if ($action eq 'commitdiff') {
2102 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2105 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2106 hash_base
=>$hash, file_name
=>$diff{'file'})},
2110 } elsif ($diff{'status'} eq "D") { # deleted
2111 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
2113 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
2114 hash_base
=>$parent, file_name
=>$diff{'file'}),
2115 -class => "list"}, esc_path
($diff{'file'}));
2117 print "<td>$mode_chng</td>\n";
2118 print "<td class=\"link\">";
2119 if ($action eq 'commitdiff') {
2122 print $cgi->a({-href
=> "#patch$patchno"}, "patch");
2125 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
2126 hash_base
=>$parent, file_name
=>$diff{'file'})},
2129 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$parent,
2130 file_name
=>$diff{'file'})},
2133 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
2134 file_name
=>$diff{'file'})},
2138 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
2139 my $mode_chnge = "";
2140 if ($diff{'from_mode'} != $diff{'to_mode'}) {
2141 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
2142 if ($from_file_type != $to_file_type) {
2143 $mode_chnge .= " from $from_file_type to $to_file_type";
2145 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
2146 if ($from_mode_str && $to_mode_str) {
2147 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
2148 } elsif ($to_mode_str) {
2149 $mode_chnge .= " mode: $to_mode_str";
2152 $mode_chnge .= "]</span>\n";
2155 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2156 hash_base
=>$hash, file_name
=>$diff{'file'}),
2157 -class => "list"}, esc_path
($diff{'file'}));
2159 print "<td>$mode_chnge</td>\n";
2160 print "<td class=\"link\">";
2161 if ($action eq 'commitdiff') {
2164 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2166 } elsif ($diff{'to_id'} ne $diff{'from_id'}) {
2167 # "commit" view and modified file (not onlu mode changed)
2168 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2169 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
2170 hash_base
=>$hash, hash_parent_base
=>$parent,
2171 file_name
=>$diff{'file'})},
2175 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2176 hash_base
=>$hash, file_name
=>$diff{'file'})},
2179 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2180 file_name
=>$diff{'file'})},
2183 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2184 file_name
=>$diff{'file'})},
2188 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
2189 my %status_name = ('R' => 'moved', 'C' => 'copied');
2190 my $nstatus = $status_name{$diff{'status'}};
2192 if ($diff{'from_mode'} != $diff{'to_mode'}) {
2193 # mode also for directories, so we cannot use $to_mode_str
2194 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
2197 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
2198 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
2199 -class => "list"}, esc_path
($diff{'to_file'})) . "</td>\n" .
2200 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
2201 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
2202 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
2203 -class => "list"}, esc_path
($diff{'from_file'})) .
2204 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
2205 "<td class=\"link\">";
2206 if ($action eq 'commitdiff') {
2209 print $cgi->a({-href
=> "#patch$patchno"}, "patch") .
2211 } elsif ($diff{'to_id'} ne $diff{'from_id'}) {
2212 # "commit" view and modified file (not only pure rename or copy)
2213 print $cgi->a({-href
=> href
(action
=>"blobdiff",
2214 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
2215 hash_base
=>$hash, hash_parent_base
=>$parent,
2216 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
2220 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
2221 hash_base
=>$parent, file_name
=>$diff{'to_file'})},
2224 print $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash,
2225 file_name
=>$diff{'to_file'})},
2228 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash,
2229 file_name
=>$diff{'to_file'})},
2233 } # we should not encounter Unmerged (U) or Unknown (X) status
2239 sub git_patchset_body
{
2240 my ($fd, $difftree, $hash, $hash_parent) = @_;
2246 my ($from_id, $to_id);
2248 print "<div class=\"patchset\">\n";
2250 # skip to first patch
2251 while ($patch_line = <$fd>) {
2254 last if ($patch_line =~ m/^diff /);
2258 while ($patch_line) {
2262 #assert($patch_line =~ m/^diff /) if DEBUG;
2263 #assert($patch_line !~ m!$/$!) if DEBUG; # is chomp-ed
2264 push @diff_header, $patch_line;
2266 # extended diff header
2268 while ($patch_line = <$fd>) {
2271 last EXTENDED_HEADER
if ($patch_line =~ m/^--- /);
2273 if ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/) {
2278 push @diff_header, $patch_line;
2280 #last PATCH unless $patch_line;
2281 my $last_patch_line = $patch_line;
2283 # check if current patch belong to current raw line
2284 # and parse raw git-diff line if needed
2285 if (defined $diffinfo &&
2286 $diffinfo->{'from_id'} eq $from_id &&
2287 $diffinfo->{'to_id'} eq $to_id) {
2288 # this is split patch
2289 print "<div class=\"patch cont\">\n";
2291 # advance raw git-diff output if needed
2292 $patch_idx++ if defined $diffinfo;
2294 # read and prepare patch information
2295 if (ref($difftree->[$patch_idx]) eq "HASH") {
2296 # pre-parsed (or generated by hand)
2297 $diffinfo = $difftree->[$patch_idx];
2299 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
2301 $from{'file'} = $diffinfo->{'from_file'} || $diffinfo->{'file'};
2302 $to{'file'} = $diffinfo->{'to_file'} || $diffinfo->{'file'};
2303 if ($diffinfo->{'status'} ne "A") { # not new (added) file
2304 $from{'href'} = href
(action
=>"blob", hash_base
=>$hash_parent,
2305 hash
=>$diffinfo->{'from_id'},
2306 file_name
=>$from{'file'});
2308 if ($diffinfo->{'status'} ne "D") { # not deleted file
2309 $to{'href'} = href
(action
=>"blob", hash_base
=>$hash,
2310 hash
=>$diffinfo->{'to_id'},
2311 file_name
=>$to{'file'});
2313 # this is first patch for raw difftree line with $patch_idx index
2314 # we index @$difftree array from 0, but number patches from 1
2315 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
2318 # print "git diff" header
2319 $patch_line = shift @diff_header;
2320 $patch_line =~ s!^(diff (.*?) )"?a/.*$!$1!;
2321 if ($from{'href'}) {
2322 $patch_line .= $cgi->a({-href
=> $from{'href'}, -class => "path"},
2323 'a/' . esc_path
($from{'file'}));
2324 } else { # file was added
2325 $patch_line .= 'a/' . esc_path
($from{'file'});
2329 $patch_line .= $cgi->a({-href
=> $to{'href'}, -class => "path"},
2330 'b/' . esc_path
($to{'file'}));
2331 } else { # file was deleted
2332 $patch_line .= 'b/' . esc_path
($to{'file'});
2334 print "<div class=\"diff header\">$patch_line</div>\n";
2336 # print extended diff header
2337 print "<div class=\"diff extended_header\">\n" if (@diff_header > 0);
2339 foreach $patch_line (@diff_header) {
2341 if ($patch_line =~ s!^((copy|rename) from ).*$!$1! && $from{'href'}) {
2342 $patch_line .= $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2343 esc_path
($from{'file'}));
2345 if ($patch_line =~ s!^((copy|rename) to ).*$!$1! && $to{'href'}) {
2346 $patch_line = $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2347 esc_path
($to{'file'}));
2350 if ($patch_line =~ m/\s(\d{6})$/) {
2351 $patch_line .= '<span class="info"> (' .
2352 file_type_long
($1) .
2356 if ($patch_line =~ m/^index/) {
2357 my ($from_link, $to_link);
2358 if ($from{'href'}) {
2359 $from_link = $cgi->a({-href
=>$from{'href'}, -class=>"hash"},
2360 substr($diffinfo->{'from_id'},0,7));
2362 $from_link = '0' x
7;
2365 $to_link = $cgi->a({-href
=>$to{'href'}, -class=>"hash"},
2366 substr($diffinfo->{'to_id'},0,7));
2371 # my ($from_hash, $to_hash) =
2372 # ($patch_line =~ m/^index ([0-9a-fA-F]{40})..([0-9a-fA-F]{40})/);
2373 # my ($from_id, $to_id) =
2374 # ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2375 # ($from_hash eq $from_id) && ($to_hash eq $to_id);
2377 my ($from_id, $to_id) = ($diffinfo->{'from_id'}, $diffinfo->{'to_id'});
2378 $patch_line =~ s!$from_id\.\.$to_id!$from_link..$to_link!;
2380 print $patch_line . "<br/>\n";
2382 print "</div>\n" if (@diff_header > 0); # class="diff extended_header"
2384 # from-file/to-file diff header
2385 $patch_line = $last_patch_line;
2386 #assert($patch_line =~ m/^---/) if DEBUG;
2387 if ($from{'href'}) {
2388 $patch_line = '--- a/' .
2389 $cgi->a({-href
=>$from{'href'}, -class=>"path"},
2390 esc_path
($from{'file'}));
2392 print "<div class=\"diff from_file\">$patch_line</div>\n";
2394 $patch_line = <$fd>;
2395 #last PATCH unless $patch_line;
2398 #assert($patch_line =~ m/^+++/) if DEBUG;
2400 $patch_line = '+++ b/' .
2401 $cgi->a({-href
=>$to{'href'}, -class=>"path"},
2402 esc_path
($to{'file'}));
2404 print "<div class=\"diff to_file\">$patch_line</div>\n";
2408 while ($patch_line = <$fd>) {
2411 next PATCH
if ($patch_line =~ m/^diff /);
2413 print format_diff_line
($patch_line, \
%from, \
%to);
2417 print "</div>\n"; # class="patch"
2420 print "</div>\n"; # class="patchset"
2423 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2425 sub git_project_list_body
{
2426 my ($projlist, $order, $from, $to, $extra, $no_header) = @_;
2428 my ($check_forks) = gitweb_check_feature
('forks');
2431 foreach my $pr (@$projlist) {
2432 my (@aa) = git_get_last_activity
($pr->{'path'});
2436 ($pr->{'age'}, $pr->{'age_string'}) = @aa;
2437 if (!defined $pr->{'descr'}) {
2438 my $descr = git_get_project_description
($pr->{'path'}) || "";
2439 $pr->{'descr'} = chop_str
($descr, 25, 5);
2441 if (!defined $pr->{'owner'}) {
2442 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2445 my $pname = $pr->{'path'};
2446 if (($pname =~ s/\.git$//) &&
2447 ($pname !~ /\/$/) &&
2448 (-d
"$projectroot/$pname")) {
2449 $pr->{'forks'} = "-d $projectroot/$pname";
2455 push @projects, $pr;
2458 $order ||= "project";
2459 $from = 0 unless defined $from;
2460 $to = $#projects if (!defined $to || $#projects < $to);
2462 print "<table class=\"project_list\">\n";
2463 unless ($no_header) {
2466 print "<th></th>\n";
2468 if ($order eq "project") {
2469 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2470 print "<th>Project</th>\n";
2473 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2474 -class => "header"}, "Project") .
2477 if ($order eq "descr") {
2478 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2479 print "<th>Description</th>\n";
2482 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2483 -class => "header"}, "Description") .
2486 if ($order eq "owner") {
2487 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2488 print "<th>Owner</th>\n";
2491 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2492 -class => "header"}, "Owner") .
2495 if ($order eq "age") {
2496 @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
2497 print "<th>Last Change</th>\n";
2500 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
2501 -class => "header"}, "Last Change") .
2504 print "<th></th>\n" .
2508 for (my $i = $from; $i <= $to; $i++) {
2509 my $pr = $projects[$i];
2511 print "<tr class=\"dark\">\n";
2513 print "<tr class=\"light\">\n";
2518 if ($pr->{'forks'}) {
2519 print "<!-- $pr->{'forks'} -->\n";
2520 print $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "+");
2524 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2525 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2526 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
2527 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2528 print "<td class=\"". age_class
($pr->{'age'}) . "\">" .
2529 $pr->{'age_string'} . "</td>\n" .
2530 "<td class=\"link\">" .
2531 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2532 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2533 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") . " | " .
2534 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"tree")}, "tree") .
2535 ($pr->{'forks'} ? " | " . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"forks")}, "forks") : '') .
2539 if (defined $extra) {
2542 print "<td></td>\n";
2544 print "<td colspan=\"5\">$extra</td>\n" .
2550 sub git_shortlog_body
{
2551 # uses global variable $project
2552 my ($revlist, $from, $to, $refs, $extra) = @_;
2554 $from = 0 unless defined $from;
2555 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
2557 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
2559 for (my $i = $from; $i <= $to; $i++) {
2560 my $commit = $revlist->[$i];
2561 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
2562 my $ref = format_ref_marker
($refs, $commit);
2563 my %co = parse_commit
($commit);
2565 print "<tr class=\"dark\">\n";
2567 print "<tr class=\"light\">\n";
2570 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
2571 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2572 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
2574 print format_subject_html
($co{'title'}, $co{'title_short'},
2575 href
(action
=>"commit", hash
=>$commit), $ref);
2577 "<td class=\"link\">" .
2578 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
2579 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
2580 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree");
2581 if (gitweb_have_snapshot
()) {
2582 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
2587 if (defined $extra) {
2589 "<td colspan=\"4\">$extra</td>\n" .
2595 sub git_history_body
{
2596 # Warning: assumes constant type (blob or tree) during history
2597 my ($revlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
2599 $from = 0 unless defined $from;
2600 $to = $#{$revlist} unless (defined $to && $to <= $#{$revlist});
2602 print "<table class=\"history\" cellspacing=\"0\">\n";
2604 for (my $i = $from; $i <= $to; $i++) {
2605 if ($revlist->[$i] !~ m/^([0-9a-fA-F]{40})/) {
2610 my %co = parse_commit
($commit);
2615 my $ref = format_ref_marker
($refs, $commit);
2618 print "<tr class=\"dark\">\n";
2620 print "<tr class=\"light\">\n";
2623 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2624 # shortlog uses chop_str($co{'author_name'}, 10)
2625 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2627 # originally git_history used chop_str($co{'title'}, 50)
2628 print format_subject_html
($co{'title'}, $co{'title_short'},
2629 href
(action
=>"commit", hash
=>$commit), $ref);
2631 "<td class=\"link\">" .
2632 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype) . " | " .
2633 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
2635 if ($ftype eq 'blob') {
2636 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
2637 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2638 if (defined $blob_current && defined $blob_parent &&
2639 $blob_current ne $blob_parent) {
2641 $cgi->a({-href
=> href
(action
=>"blobdiff",
2642 hash
=>$blob_current, hash_parent
=>$blob_parent,
2643 hash_base
=>$hash_base, hash_parent_base
=>$commit,
2644 file_name
=>$file_name)},
2651 if (defined $extra) {
2653 "<td colspan=\"4\">$extra</td>\n" .
2660 # uses global variable $project
2661 my ($taglist, $from, $to, $extra) = @_;
2662 $from = 0 unless defined $from;
2663 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2665 print "<table class=\"tags\" cellspacing=\"0\">\n";
2667 for (my $i = $from; $i <= $to; $i++) {
2668 my $entry = $taglist->[$i];
2670 my $comment = $tag{'subject'};
2672 if (defined $comment) {
2673 $comment_short = chop_str
($comment, 30, 5);
2676 print "<tr class=\"dark\">\n";
2678 print "<tr class=\"light\">\n";
2681 print "<td><i>$tag{'age'}</i></td>\n" .
2683 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
2684 -class => "list name"}, esc_html
($tag{'name'})) .
2687 if (defined $comment) {
2688 print format_subject_html
($comment, $comment_short,
2689 href
(action
=>"tag", hash
=>$tag{'id'}));
2692 "<td class=\"selflink\">";
2693 if ($tag{'type'} eq "tag") {
2694 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
2699 "<td class=\"link\">" . " | " .
2700 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
2701 if ($tag{'reftype'} eq "commit") {
2702 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
2703 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log");
2704 } elsif ($tag{'reftype'} eq "blob") {
2705 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
2710 if (defined $extra) {
2712 "<td colspan=\"5\">$extra</td>\n" .
2718 sub git_heads_body
{
2719 # uses global variable $project
2720 my ($headlist, $head, $from, $to, $extra) = @_;
2721 $from = 0 unless defined $from;
2722 $to = $#{$headlist} if (!defined $to || $#{$headlist} < $to);
2724 print "<table class=\"heads\" cellspacing=\"0\">\n";
2726 for (my $i = $from; $i <= $to; $i++) {
2727 my $entry = $headlist->[$i];
2729 my $curr = $ref{'id'} eq $head;
2731 print "<tr class=\"dark\">\n";
2733 print "<tr class=\"light\">\n";
2736 print "<td><i>$ref{'age'}</i></td>\n" .
2737 ($curr ? "<td class=\"current_head\">" : "<td>") .
2738 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'}),
2739 -class => "list name"},esc_html
($ref{'name'})) .
2741 "<td class=\"link\">" .
2742 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$ref{'name'})}, "shortlog") . " | " .
2743 $cgi->a({-href
=> href
(action
=>"log", hash
=>$ref{'name'})}, "log") . " | " .
2744 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$ref{'name'}, hash_base
=>$ref{'name'})}, "tree") .
2748 if (defined $extra) {
2750 "<td colspan=\"3\">$extra</td>\n" .
2756 ## ======================================================================
2757 ## ======================================================================
2760 sub git_project_list
{
2761 my $order = $cgi->param('o');
2762 if (defined $order && $order !~ m/project|descr|owner|age/) {
2763 die_error
(undef, "Unknown order parameter");
2766 my @list = git_get_projects_list
();
2768 die_error
(undef, "No projects found");
2772 if (-f
$home_text) {
2773 print "<div class=\"index_include\">\n";
2774 open (my $fd, $home_text);
2779 git_project_list_body
(\
@list, $order);
2784 my $order = $cgi->param('o');
2785 if (defined $order && $order !~ m/project|descr|owner|age/) {
2786 die_error
(undef, "Unknown order parameter");
2789 my @list = git_get_projects_list
($project);
2791 die_error
(undef, "No forks found");
2795 git_print_page_nav
('','');
2796 git_print_header_div
('summary', "$project forks");
2797 git_project_list_body
(\
@list, $order);
2801 sub git_project_index
{
2802 my @projects = git_get_projects_list
($project);
2805 -type
=> 'text/plain',
2806 -charset
=> 'utf-8',
2807 -content_disposition
=> 'inline; filename="index.aux"');
2809 foreach my $pr (@projects) {
2810 if (!exists $pr->{'owner'}) {
2811 $pr->{'owner'} = get_file_owner
("$projectroot/$project");
2814 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
2815 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
2816 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2817 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2821 print "$path $owner\n";
2826 my $descr = git_get_project_description
($project) || "none";
2827 my $head = git_get_head_hash
($project);
2828 my %co = parse_commit
($head);
2829 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2831 my $owner = git_get_project_owner
($project);
2833 my $refs = git_get_references
();
2834 my @taglist = git_get_tags_list
(15);
2835 my @headlist = git_get_heads_list
(15);
2837 my ($check_forks) = gitweb_check_feature
('forks');
2840 @forklist = git_get_projects_list
($project);
2844 git_print_page_nav
('summary','', $head);
2846 print "<div class=\"title\"> </div>\n";
2847 print "<table cellspacing=\"0\">\n" .
2848 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
2849 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2850 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2851 # use per project git URL list in $projectroot/$project/cloneurl
2852 # or make project git URL from git base URL and project name
2853 my $url_tag = "URL";
2854 my @url_list = git_get_project_url_list
($project);
2855 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2856 foreach my $git_url (@url_list) {
2857 next unless $git_url;
2858 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2863 if (-s
"$projectroot/$project/README.html") {
2864 if (open my $fd, "$projectroot/$project/README.html") {
2865 print "<div class=\"title\">readme</div>\n";
2866 print $_ while (<$fd>);
2871 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=17",
2872 git_get_head_hash
($project), "--"
2873 or die_error
(undef, "Open git-rev-list failed");
2874 my @revlist = map { chomp; $_ } <$fd>;
2876 git_print_header_div
('shortlog');
2877 git_shortlog_body
(\
@revlist, 0, 15, $refs,
2878 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
2881 git_print_header_div
('tags');
2882 git_tags_body
(\
@taglist, 0, 15,
2883 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
2887 git_print_header_div
('heads');
2888 git_heads_body
(\
@headlist, $head, 0, 15,
2889 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
2893 git_print_header_div
('forks');
2894 git_project_list_body
(\
@forklist, undef, 0, 15,
2895 $cgi->a({-href
=> href
(action
=>"forks")}, "..."),
2903 my $head = git_get_head_hash
($project);
2905 git_print_page_nav
('','', $head,undef,$head);
2906 my %tag = parse_tag
($hash);
2907 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
2908 print "<div class=\"title_text\">\n" .
2909 "<table cellspacing=\"0\">\n" .
2911 "<td>object</td>\n" .
2912 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2913 $tag{'object'}) . "</td>\n" .
2914 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2915 $tag{'type'}) . "</td>\n" .
2917 if (defined($tag{'author'})) {
2918 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
2919 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
2920 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2921 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2924 print "</table>\n\n" .
2926 print "<div class=\"page_body\">";
2927 my $comment = $tag{'comment'};
2928 foreach my $line (@$comment) {
2930 print esc_html
($line, -nbsp
=>1) . "<br/>\n";
2940 my ($have_blame) = gitweb_check_feature
('blame');
2942 die_error
('403 Permission denied', "Permission denied");
2944 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2945 $hash_base ||= git_get_head_hash
($project);
2946 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2947 my %co = parse_commit
($hash_base)
2948 or die_error
(undef, "Reading commit failed");
2949 if (!defined $hash) {
2950 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2951 or die_error
(undef, "Error looking up file");
2953 $ftype = git_get_type
($hash);
2954 if ($ftype !~ "blob") {
2955 die_error
("400 Bad Request", "Object is not a blob");
2957 open ($fd, "-|", git_cmd
(), "blame", '-p', '--',
2958 $file_name, $hash_base)
2959 or die_error
(undef, "Open git-blame failed");
2962 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2965 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2968 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2970 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2971 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2972 git_print_page_path
($file_name, $ftype, $hash_base);
2973 my @rev_color = (qw(light2 dark2));
2974 my $num_colors = scalar(@rev_color);
2975 my $current_color = 0;
2978 <div class="page_body">
2979 <table class="blame">
2980 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2985 last unless defined $_;
2986 my ($full_rev, $orig_lineno, $lineno, $group_size) =
2987 /^([0-9a-f]{40}) (\d+) (\d+)(?: (\d+))?$/;
2988 if (!exists $metainfo{$full_rev}) {
2989 $metainfo{$full_rev} = {};
2991 my $meta = $metainfo{$full_rev};
2994 if (/^(\S+) (.*)$/) {
3000 my $rev = substr($full_rev, 0, 8);
3001 my $author = $meta->{'author'};
3002 my %date = parse_date
($meta->{'author-time'},
3003 $meta->{'author-tz'});
3004 my $date = $date{'iso-tz'};
3006 $current_color = ++$current_color % $num_colors;
3008 print "<tr class=\"$rev_color[$current_color]\">\n";
3010 print "<td class=\"sha1\"";
3011 print " title=\"". esc_html
($author) . ", $date\"";
3012 print " rowspan=\"$group_size\"" if ($group_size > 1);
3014 print $cgi->a({-href
=> href
(action
=>"commit",
3016 file_name
=>$file_name)},
3020 my $blamed = href
(action
=> 'blame',
3021 file_name
=> $meta->{'filename'},
3022 hash_base
=> $full_rev);
3023 print "<td class=\"linenr\">";
3024 print $cgi->a({ -href
=> "$blamed#l$orig_lineno",
3026 -class => "linenr" },
3029 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
3035 or print "Reading blob failed\n";
3042 my ($have_blame) = gitweb_check_feature
('blame');
3044 die_error
('403 Permission denied', "Permission denied");
3046 die_error
('404 Not Found', "File name not defined") if (!$file_name);
3047 $hash_base ||= git_get_head_hash
($project);
3048 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
3049 my %co = parse_commit
($hash_base)
3050 or die_error
(undef, "Reading commit failed");
3051 if (!defined $hash) {
3052 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
3053 or die_error
(undef, "Error lookup file");
3055 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
3056 or die_error
(undef, "Open git-annotate failed");
3059 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3062 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
3065 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
3067 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3068 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3069 git_print_page_path
($file_name, 'blob', $hash_base);
3070 print "<div class=\"page_body\">\n";
3072 <table class="blame">
3081 my @line_class = (qw(light dark));
3082 my $line_class_len = scalar (@line_class);
3083 my $line_class_num = $#line_class;
3084 while (my $line = <$fd>) {
3096 $line_class_num = ($line_class_num + 1) % $line_class_len;
3098 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
3105 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
3108 $short_rev = substr ($long_rev, 0, 8);
3109 $age = time () - $time;
3110 $age_str = age_string
($age);
3111 $age_str =~ s/ / /g;
3112 $age_class = age_class
($age);
3113 $author = esc_html
($author);
3114 $author =~ s/ / /g;
3116 $data = untabify
($data);
3117 $data = esc_html
($data);
3120 <tr class="$line_class[$line_class_num]">
3121 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
3122 <td class="$age_class">$age_str</td>
3124 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
3125 <td class="pre">$data</td>
3128 } # while (my $line = <$fd>)
3129 print "</table>\n\n";
3131 or print "Reading blob failed.\n";
3137 my $head = git_get_head_hash
($project);
3139 git_print_page_nav
('','', $head,undef,$head);
3140 git_print_header_div
('summary', $project);
3142 my @tagslist = git_get_tags_list
();
3144 git_tags_body
(\
@tagslist);
3150 my $head = git_get_head_hash
($project);
3152 git_print_page_nav
('','', $head,undef,$head);
3153 git_print_header_div
('summary', $project);
3155 my @headslist = git_get_heads_list
();
3157 git_heads_body
(\
@headslist, $head);
3162 sub git_blob_plain
{
3165 if (!defined $hash) {
3166 if (defined $file_name) {
3167 my $base = $hash_base || git_get_head_hash
($project);
3168 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3169 or die_error
(undef, "Error lookup file");
3171 die_error
(undef, "No file name defined");
3173 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3174 # blobs defined by non-textual hash id's can be cached
3179 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3180 or die_error
(undef, "Couldn't cat $file_name, $hash");
3182 $type ||= blob_mimetype
($fd, $file_name);
3184 # save as filename, even when no $file_name is given
3185 my $save_as = "$hash";
3186 if (defined $file_name) {
3187 $save_as = $file_name;
3188 } elsif ($type =~ m/^text\//) {
3195 -content_disposition
=> 'inline; filename="' . "$save_as" . '"');
3197 binmode STDOUT
, ':raw';
3199 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3207 if (!defined $hash) {
3208 if (defined $file_name) {
3209 my $base = $hash_base || git_get_head_hash
($project);
3210 $hash = git_get_hash_by_path
($base, $file_name, "blob")
3211 or die_error
(undef, "Error lookup file");
3213 die_error
(undef, "No file name defined");
3215 } elsif ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3216 # blobs defined by non-textual hash id's can be cached
3220 my ($have_blame) = gitweb_check_feature
('blame');
3221 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
3222 or die_error
(undef, "Couldn't cat $file_name, $hash");
3223 my $mimetype = blob_mimetype
($fd, $file_name);
3224 if ($mimetype !~ m/^text\//) {
3226 return git_blob_plain
($mimetype);
3228 git_header_html
(undef, $expires);
3229 my $formats_nav = '';
3230 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3231 if (defined $file_name) {
3234 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
3235 hash
=>$hash, file_name
=>$file_name)},
3240 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3241 hash
=>$hash, file_name
=>$file_name)},
3244 $cgi->a({-href
=> href
(action
=>"blob_plain",
3245 hash
=>$hash, file_name
=>$file_name)},
3248 $cgi->a({-href
=> href
(action
=>"blob",
3249 hash_base
=>"HEAD", file_name
=>$file_name)},
3253 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "raw");
3255 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3256 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3258 print "<div class=\"page_nav\">\n" .
3259 "<br/><br/></div>\n" .
3260 "<div class=\"title\">$hash</div>\n";
3262 git_print_page_path
($file_name, "blob", $hash_base);
3263 print "<div class=\"page_body\">\n";
3265 while (my $line = <$fd>) {
3268 $line = untabify
($line);
3269 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
3270 $nr, $nr, $nr, esc_html
($line, -nbsp
=>1);
3273 or print "Reading blob failed.\n";
3279 my $have_snapshot = gitweb_have_snapshot
();
3281 if (!defined $hash_base) {
3282 $hash_base = "HEAD";
3284 if (!defined $hash) {
3285 if (defined $file_name) {
3286 $hash = git_get_hash_by_path
($hash_base, $file_name, "tree");
3292 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
3293 or die_error
(undef, "Open git-ls-tree failed");
3294 my @entries = map { chomp; $_ } <$fd>;
3295 close $fd or die_error
(undef, "Reading tree failed");
3298 my $refs = git_get_references
();
3299 my $ref = format_ref_marker
($refs, $hash_base);
3302 my ($have_blame) = gitweb_check_feature
('blame');
3303 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3305 if (defined $file_name) {
3307 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
3308 hash
=>$hash, file_name
=>$file_name)},
3310 $cgi->a({-href
=> href
(action
=>"tree",
3311 hash_base
=>"HEAD", file_name
=>$file_name)},
3314 if ($have_snapshot) {
3315 # FIXME: Should be available when we have no hash base as well.
3317 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)},
3320 git_print_page_nav
('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
3321 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
3324 print "<div class=\"page_nav\">\n";
3325 print "<br/><br/></div>\n";
3326 print "<div class=\"title\">$hash</div>\n";
3328 if (defined $file_name) {
3329 $basedir = $file_name;
3330 if ($basedir ne '' && substr($basedir, -1) ne '/') {
3334 git_print_page_path
($file_name, 'tree', $hash_base);
3335 print "<div class=\"page_body\">\n";
3336 print "<table cellspacing=\"0\">\n";
3338 # '..' (top directory) link if possible
3339 if (defined $hash_base &&
3340 defined $file_name && $file_name =~ m![^/]+$!) {
3342 print "<tr class=\"dark\">\n";
3344 print "<tr class=\"light\">\n";
3348 my $up = $file_name;
3349 $up =~ s!/?[^/]+$!!;
3350 undef $up unless $up;
3351 # based on git_print_tree_entry
3352 print '<td class="mode">' . mode_str
('040000') . "</td>\n";
3353 print '<td class="list">';
3354 print $cgi->a({-href
=> href
(action
=>"tree", hash_base
=>$hash_base,
3358 print "<td class=\"link\"></td>\n";
3362 foreach my $line (@entries) {
3363 my %t = parse_ls_tree_line
($line, -z
=> 1);
3366 print "<tr class=\"dark\">\n";
3368 print "<tr class=\"light\">\n";
3372 git_print_tree_entry
(\
%t, $basedir, $hash_base, $have_blame);
3376 print "</table>\n" .
3382 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
3383 my $have_snapshot = (defined $ctype && defined $suffix);
3384 if (!$have_snapshot) {
3385 die_error
('403 Permission denied', "Permission denied");
3388 if (!defined $hash) {
3389 $hash = git_get_head_hash
($project);
3392 my $filename = basename
($project) . "-$hash.tar.$suffix";
3395 -type
=> 'application/x-tar',
3396 -content_encoding
=> $ctype,
3397 -content_disposition
=> 'inline; filename="' . "$filename" . '"',
3398 -status
=> '200 OK');
3400 my $git = git_cmd_str
();
3401 my $name = $project;
3402 $name =~ s/\047/\047\\\047\047/g;
3404 "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
3405 or die_error
(undef, "Execute git-tar-tree failed.");
3406 binmode STDOUT
, ':raw';
3408 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
3414 my $head = git_get_head_hash
($project);
3415 if (!defined $hash) {
3418 if (!defined $page) {
3421 my $refs = git_get_references
();
3423 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3424 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash, "--"
3425 or die_error
(undef, "Open git-rev-list failed");
3426 my @revlist = map { chomp; $_ } <$fd>;
3429 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
3432 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
3435 my %co = parse_commit
($hash);
3437 git_print_header_div
('summary', $project);
3438 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
3440 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
3441 my $commit = $revlist[$i];
3442 my $ref = format_ref_marker
($refs, $commit);
3443 my %co = parse_commit
($commit);
3445 my %ad = parse_date
($co{'author_epoch'});
3446 git_print_header_div
('commit',
3447 "<span class=\"age\">$co{'age_string'}</span>" .
3448 esc_html
($co{'title'}) . $ref,
3450 print "<div class=\"title_text\">\n" .
3451 "<div class=\"log_link\">\n" .
3452 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
3454 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
3456 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$commit, hash_base
=>$commit)}, "tree") .
3459 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
3462 print "<div class=\"log_body\">\n";
3463 git_print_log
($co{'comment'}, -final_empty_line
=> 1);
3470 $hash ||= $hash_base || "HEAD";
3471 my %co = parse_commit
($hash);
3473 die_error
(undef, "Unknown commit object");
3475 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3476 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
3478 my $parent = $co{'parent'};
3479 if (!defined $parent) {
3482 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', "--no-commit-id",
3483 @diff_opts, $parent, $hash, "--"
3484 or die_error
(undef, "Open git-diff-tree failed");
3485 my @difftree = map { chomp; $_ } <$fd>;
3486 close $fd or die_error
(undef, "Reading git-diff-tree failed");
3488 # non-textual hash id's can be cached
3490 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3493 my $refs = git_get_references
();
3494 my $ref = format_ref_marker
($refs, $co{'id'});
3496 my $have_snapshot = gitweb_have_snapshot
();
3499 if (defined $file_name && defined $co{'parent'}) {
3501 $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)},
3504 git_header_html
(undef, $expires);
3505 git_print_page_nav
('commit', '',
3506 $hash, $co{'tree'}, $hash,
3507 join (' | ', @views_nav));
3509 if (defined $co{'parent'}) {
3510 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
3512 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
3514 print "<div class=\"title_text\">\n" .
3515 "<table cellspacing=\"0\">\n";
3516 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
3518 "<td></td><td> $ad{'rfc2822'}";
3519 if ($ad{'hour_local'} < 6) {
3520 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
3521 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3523 printf(" (%02d:%02d %s)",
3524 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
3528 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
3529 print "<tr><td></td><td> $cd{'rfc2822'}" .
3530 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
3532 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
3535 "<td class=\"sha1\">" .
3536 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
3537 class => "list"}, $co{'tree'}) .
3539 "<td class=\"link\">" .
3540 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
3542 if ($have_snapshot) {
3544 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
3548 my $parents = $co{'parents'};
3549 foreach my $par (@$parents) {
3552 "<td class=\"sha1\">" .
3553 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
3554 class => "list"}, $par) .
3556 "<td class=\"link\">" .
3557 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
3559 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
3566 print "<div class=\"page_body\">\n";
3567 git_print_log
($co{'comment'});
3570 git_difftree_body
(\
@difftree, $hash, $parent);
3576 my $format = shift || 'html';
3583 # preparing $fd and %diffinfo for git_patchset_body
3585 if (defined $hash_base && defined $hash_parent_base) {
3586 if (defined $file_name) {
3588 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3589 $hash_parent_base, $hash_base,
3591 or die_error
(undef, "Open git-diff-tree failed");
3592 @difftree = map { chomp; $_ } <$fd>;
3594 or die_error
(undef, "Reading git-diff-tree failed");
3596 or die_error
('404 Not Found', "Blob diff not found");
3598 } elsif (defined $hash &&
3599 $hash =~ /[0-9a-fA-F]{40}/) {
3600 # try to find filename from $hash
3602 # read filtered raw output
3603 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3604 $hash_parent_base, $hash_base, "--"
3605 or die_error
(undef, "Open git-diff-tree failed");
3607 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
3609 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
3610 map { chomp; $_ } <$fd>;
3612 or die_error
(undef, "Reading git-diff-tree failed");
3614 or die_error
('404 Not Found', "Blob diff not found");
3617 die_error
('404 Not Found', "Missing one of the blob diff parameters");
3620 if (@difftree > 1) {
3621 die_error
('404 Not Found', "Ambiguous blob diff specification");
3624 %diffinfo = parse_difftree_raw_line
($difftree[0]);
3625 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
3626 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
3628 $hash_parent ||= $diffinfo{'from_id'};
3629 $hash ||= $diffinfo{'to_id'};
3631 # non-textual hash id's can be cached
3632 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
3633 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
3638 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3639 '-p', $hash_parent_base, $hash_base,
3641 or die_error
(undef, "Open git-diff-tree failed");
3644 # old/legacy style URI
3645 if (!%diffinfo && # if new style URI failed
3646 defined $hash && defined $hash_parent) {
3647 # fake git-diff-tree raw output
3648 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
3649 $diffinfo{'from_id'} = $hash_parent;
3650 $diffinfo{'to_id'} = $hash;
3651 if (defined $file_name) {
3652 if (defined $file_parent) {
3653 $diffinfo{'status'} = '2';
3654 $diffinfo{'from_file'} = $file_parent;
3655 $diffinfo{'to_file'} = $file_name;
3656 } else { # assume not renamed
3657 $diffinfo{'status'} = '1';
3658 $diffinfo{'from_file'} = $file_name;
3659 $diffinfo{'to_file'} = $file_name;
3661 } else { # no filename given
3662 $diffinfo{'status'} = '2';
3663 $diffinfo{'from_file'} = $hash_parent;
3664 $diffinfo{'to_file'} = $hash;
3667 # non-textual hash id's can be cached
3668 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
3669 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3674 open $fd, "-|", git_cmd
(), "diff", '-p', @diff_opts,
3675 $hash_parent, $hash, "--"
3676 or die_error
(undef, "Open git-diff failed");
3678 die_error
('404 Not Found', "Missing one of the blob diff parameters")
3683 if ($format eq 'html') {
3685 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
3686 hash
=>$hash, hash_parent
=>$hash_parent,
3687 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
3688 file_name
=>$file_name, file_parent
=>$file_parent)},
3690 git_header_html
(undef, $expires);
3691 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3692 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3693 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3695 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
3696 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
3698 if (defined $file_name) {
3699 git_print_page_path
($file_name, "blob", $hash_base);
3701 print "<div class=\"page_path\"></div>\n";
3704 } elsif ($format eq 'plain') {
3706 -type
=> 'text/plain',
3707 -charset
=> 'utf-8',
3708 -expires
=> $expires,
3709 -content_disposition
=> 'inline; filename="' . "$file_name" . '.patch"');
3711 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3714 die_error
(undef, "Unknown blobdiff format");
3718 if ($format eq 'html') {
3719 print "<div class=\"page_body\">\n";
3721 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
3724 print "</div>\n"; # class="page_body"
3728 while (my $line = <$fd>) {
3729 $line =~ s!a/($hash|$hash_parent)!'a/'.esc_path($diffinfo{'from_file'})!eg;
3730 $line =~ s!b/($hash|$hash_parent)!'b/'.esc_path($diffinfo{'to_file'})!eg;
3734 last if $line =~ m!^\+\+\+!;
3742 sub git_blobdiff_plain
{
3743 git_blobdiff
('plain');
3746 sub git_commitdiff
{
3747 my $format = shift || 'html';
3748 $hash ||= $hash_base || "HEAD";
3749 my %co = parse_commit
($hash);
3751 die_error
(undef, "Unknown commit object");
3754 # we need to prepare $formats_nav before any parameter munging
3756 if ($format eq 'html') {
3758 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
3759 hash
=>$hash, hash_parent
=>$hash_parent)},
3762 if (defined $hash_parent) {
3763 # commitdiff with two commits given
3764 my $hash_parent_short = $hash_parent;
3765 if ($hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
3766 $hash_parent_short = substr($hash_parent, 0, 7);
3770 $cgi->a({-href
=> href
(action
=>"commitdiff",
3771 hash
=>$hash_parent)},
3772 esc_html
($hash_parent_short)) .
3774 } elsif (!$co{'parent'}) {
3776 $formats_nav .= ' (initial)';
3777 } elsif (scalar @{$co{'parents'}} == 1) {
3778 # single parent commit
3781 $cgi->a({-href
=> href
(action
=>"commitdiff",
3782 hash
=>$co{'parent'})},
3783 esc_html
(substr($co{'parent'}, 0, 7))) .
3790 $cgi->a({-href
=> href
(action
=>"commitdiff",
3792 esc_html
(substr($_, 0, 7)));
3793 } @{$co{'parents'}} ) .
3798 if (!defined $hash_parent) {
3799 $hash_parent = $co{'parent'} || '--root';
3805 if ($format eq 'html') {
3806 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3807 "--no-commit-id", "--patch-with-raw", "--full-index",
3808 $hash_parent, $hash, "--"
3809 or die_error
(undef, "Open git-diff-tree failed");
3811 while (my $line = <$fd>) {
3813 # empty line ends raw part of diff-tree output
3815 push @difftree, $line;
3818 } elsif ($format eq 'plain') {
3819 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3820 '-p', $hash_parent, $hash, "--"
3821 or die_error
(undef, "Open git-diff-tree failed");
3824 die_error
(undef, "Unknown commitdiff format");
3827 # non-textual hash id's can be cached
3829 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3833 # write commit message
3834 if ($format eq 'html') {
3835 my $refs = git_get_references
();
3836 my $ref = format_ref_marker
($refs, $co{'id'});
3838 git_header_html
(undef, $expires);
3839 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
3840 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
3841 git_print_authorship
(\
%co);
3842 print "<div class=\"page_body\">\n";
3843 if (@{$co{'comment'}} > 1) {
3844 print "<div class=\"log\">\n";
3845 git_print_log
($co{'comment'}, -final_empty_line
=> 1, -remove_title
=> 1);
3846 print "</div>\n"; # class="log"
3849 } elsif ($format eq 'plain') {
3850 my $refs = git_get_references
("tags");
3851 my $tagname = git_get_rev_name_tags
($hash);
3852 my $filename = basename
($project) . "-$hash.patch";
3855 -type
=> 'text/plain',
3856 -charset
=> 'utf-8',
3857 -expires
=> $expires,
3858 -content_disposition
=> 'inline; filename="' . "$filename" . '"');
3859 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3862 Date: $ad{'rfc2822'} ($ad{'tz_local'})
3863 Subject: $co{'title'}
3865 print "X-Git-Tag: $tagname\n" if $tagname;
3866 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3868 foreach my $line (@{$co{'comment'}}) {
3875 if ($format eq 'html') {
3876 git_difftree_body
(\
@difftree, $hash, $hash_parent);
3879 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
3881 print "</div>\n"; # class="page_body"
3884 } elsif ($format eq 'plain') {
3888 or print "Reading git-diff-tree failed\n";
3892 sub git_commitdiff_plain
{
3893 git_commitdiff
('plain');
3897 if (!defined $hash_base) {
3898 $hash_base = git_get_head_hash
($project);
3900 if (!defined $page) {
3904 my %co = parse_commit
($hash_base);
3906 die_error
(undef, "Unknown commit object");
3909 my $refs = git_get_references
();
3910 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3912 if (!defined $hash && defined $file_name) {
3913 $hash = git_get_hash_by_path
($hash_base, $file_name);
3915 if (defined $hash) {
3916 $ftype = git_get_type
($hash);
3920 git_cmd
(), "rev-list", $limit, "--full-history", $hash_base, "--", $file_name
3921 or die_error
(undef, "Open git-rev-list-failed");
3922 my @revlist = map { chomp; $_ } <$fd>;
3924 or die_error
(undef, "Reading git-rev-list failed");
3926 my $paging_nav = '';
3929 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3930 file_name
=>$file_name)},
3932 $paging_nav .= " ⋅ " .
3933 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3934 file_name
=>$file_name, page
=>$page-1),
3935 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3937 $paging_nav .= "first";
3938 $paging_nav .= " ⋅ prev";
3940 if ($#revlist >= (100 * ($page+1)-1)) {
3941 $paging_nav .= " ⋅ " .
3942 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3943 file_name
=>$file_name, page
=>$page+1),
3944 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3946 $paging_nav .= " ⋅ next";
3949 if ($#revlist >= (100 * ($page+1)-1)) {
3951 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3952 file_name
=>$file_name, page
=>$page+1),
3953 -title
=> "Alt-n"}, "next");
3957 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
3958 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3959 git_print_page_path
($file_name, $ftype, $hash_base);
3961 git_history_body
(\
@revlist, ($page * 100), $#revlist,
3962 $refs, $hash_base, $ftype, $next_link);
3968 if (!defined $searchtext) {
3969 die_error
(undef, "Text field empty");
3971 if (!defined $hash) {
3972 $hash = git_get_head_hash
($project);
3974 my %co = parse_commit
($hash);
3976 die_error
(undef, "Unknown commit object");
3979 $searchtype ||= 'commit';
3980 if ($searchtype eq 'pickaxe') {
3981 # pickaxe may take all resources of your box and run for several minutes
3982 # with every query - so decide by yourself how public you make this feature
3983 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
3984 if (!$have_pickaxe) {
3985 die_error
('403 Permission denied', "Permission denied");
3990 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
3991 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
3993 print "<table cellspacing=\"0\">\n";
3995 if ($searchtype eq 'commit' or $searchtype eq 'author' or $searchtype eq 'committer') {
3997 open my $fd, "-|", git_cmd
(), "rev-list",
3998 "--header", "--parents", $hash, "--"
4000 while (my $commit_text = <$fd>) {
4001 if (!grep m/$searchtext/i, $commit_text) {
4004 if ($searchtype eq 'author' && !grep m/\nauthor .*$searchtext/i, $commit_text) {
4007 if ($searchtype eq 'committer' && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
4010 my @commit_lines = split "\n", $commit_text;
4011 my %co = parse_commit
(undef, \
@commit_lines);
4016 print "<tr class=\"dark\">\n";
4018 print "<tr class=\"light\">\n";
4021 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4022 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
4024 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
4025 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
4026 my $comment = $co{'comment'};
4027 foreach my $line (@$comment) {
4028 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
4029 my $lead = esc_html
($1) || "";
4030 $lead = chop_str
($lead, 30, 10);
4031 my $match = esc_html
($2) || "";
4032 my $trail = esc_html
($3) || "";
4033 $trail = chop_str
($trail, 30, 10);
4034 my $text = "$lead<span class=\"match\">$match</span>$trail";
4035 print chop_str
($text, 80, 5) . "<br/>\n";
4039 "<td class=\"link\">" .
4040 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4042 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4049 if ($searchtype eq 'pickaxe') {
4051 my $git_command = git_cmd_str
();
4052 open my $fd, "-|", "$git_command rev-list $hash | " .
4053 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
4056 while (my $line = <$fd>) {
4057 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
4060 $set{'from_id'} = $3;
4062 $set{'id'} = $set{'to_id'};
4063 if ($set{'id'} =~ m/0{40}/) {
4064 $set{'id'} = $set{'from_id'};
4066 if ($set{'id'} =~ m/0{40}/) {
4070 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
4073 print "<tr class=\"dark\">\n";
4075 print "<tr class=\"light\">\n";
4078 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
4079 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
4081 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
4082 -class => "list subject"},
4083 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
4084 while (my $setref = shift @files) {
4086 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
4087 hash
=>$set{'id'}, file_name
=>$set{'file'}),
4089 "<span class=\"match\">" . esc_path
($set{'file'}) . "</span>") .
4093 "<td class=\"link\">" .
4094 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
4096 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
4100 %co = parse_commit
($1);
4109 sub git_search_help
{
4111 git_print_page_nav
('','', $hash,$hash,$hash);
4114 <dt><b>commit</b></dt>
4115 <dd>The commit messages and authorship information will be scanned for the given string.</dd>
4116 <dt><b>author</b></dt>
4117 <dd>Name and e-mail of the change author and date of birth of the patch will be scanned for the given string.</dd>
4118 <dt><b>committer</b></dt>
4119 <dd>Name and e-mail of the committer and date of commit will be scanned for the given string.</dd>
4121 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
4122 if ($have_pickaxe) {
4124 <dt><b>pickaxe</b></dt>
4125 <dd>All commits that caused the string to appear or disappear from any file (changes that
4126 added, removed or "modified" the string) will be listed. This search can take a while and
4127 takes a lot of strain on the server, so please use it wisely.</dd>
4135 my $head = git_get_head_hash
($project);
4136 if (!defined $hash) {
4139 if (!defined $page) {
4142 my $refs = git_get_references
();
4144 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
4145 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash, "--"
4146 or die_error
(undef, "Open git-rev-list failed");
4147 my @revlist = map { chomp; $_ } <$fd>;
4150 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
4152 if ($#revlist >= (100 * ($page+1)-1)) {
4154 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
4155 -title
=> "Alt-n"}, "next");
4160 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
4161 git_print_header_div
('summary', $project);
4163 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
4168 ## ......................................................................
4169 ## feeds (RSS, Atom; OPML)
4172 my $format = shift || 'atom';
4173 my ($have_blame) = gitweb_check_feature
('blame');
4175 # Atom: http://www.atomenabled.org/developers/syndication/
4176 # RSS: http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
4177 if ($format ne 'rss' && $format ne 'atom') {
4178 die_error
(undef, "Unknown web feed format");
4181 # log/feed of current (HEAD) branch, log of given branch, history of file/directory
4182 my $head = $hash || 'HEAD';
4183 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=150",
4184 $head, "--", (defined $file_name ? $file_name : ())
4185 or die_error
(undef, "Open git-rev-list failed");
4186 my @revlist = map { chomp; $_ } <$fd>;
4187 close $fd or die_error
(undef, "Reading git-rev-list failed");
4191 my $content_type = "application/$format+xml";
4192 if (defined $cgi->http('HTTP_ACCEPT') &&
4193 $cgi->Accept('text/xml') > $cgi->Accept($content_type)) {
4194 # browser (feed reader) prefers text/xml
4195 $content_type = 'text/xml';
4197 if (defined($revlist[0])) {
4198 %latest_commit = parse_commit
($revlist[0]);
4199 %latest_date = parse_date
($latest_commit{'committer_epoch'});
4201 -type
=> $content_type,
4202 -charset
=> 'utf-8',
4203 -last_modified
=> $latest_date{'rfc2822'});
4206 -type
=> $content_type,
4207 -charset
=> 'utf-8');
4210 # Optimization: skip generating the body if client asks only
4211 # for Last-Modified date.
4212 return if ($cgi->request_method() eq 'HEAD');
4215 my $title = "$site_name - $project/$action";
4216 my $feed_type = 'log';
4217 if (defined $hash) {
4218 $title .= " - '$hash'";
4219 $feed_type = 'branch log';
4220 if (defined $file_name) {
4221 $title .= " :: $file_name";
4222 $feed_type = 'history';
4224 } elsif (defined $file_name) {
4225 $title .= " - $file_name";
4226 $feed_type = 'history';
4228 $title .= " $feed_type";
4229 my $descr = git_get_project_description
($project);
4230 if (defined $descr) {
4231 $descr = esc_html
($descr);
4233 $descr = "$project " .
4234 ($format eq 'rss' ? 'RSS' : 'Atom') .
4237 my $owner = git_get_project_owner
($project);
4238 $owner = esc_html
($owner);
4242 if (defined $file_name) {
4243 $alt_url = href
(-full
=>1, action
=>"history", hash
=>$hash, file_name
=>$file_name);
4244 } elsif (defined $hash) {
4245 $alt_url = href
(-full
=>1, action
=>"log", hash
=>$hash);
4247 $alt_url = href
(-full
=>1, action
=>"summary");
4249 print qq
!<?xml version
="1.0" encoding
="utf-8"?>\n!;
4250 if ($format eq 'rss') {
4252 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
4255 print "<title>$title</title>\n" .
4256 "<link>$alt_url</link>\n" .
4257 "<description>$descr</description>\n" .
4258 "<language>en</language>\n";
4259 } elsif ($format eq 'atom') {
4261 <feed xmlns="http://www.w3.org/2005/Atom">
4263 print "<title>$title</title>\n" .
4264 "<subtitle>$descr</subtitle>\n" .
4265 '<link rel="alternate" type="text/html" href="' .
4266 $alt_url . '" />' . "\n" .
4267 '<link rel="self" type="' . $content_type . '" href="' .
4268 $cgi->self_url() . '" />' . "\n" .
4269 "<id>" . href
(-full
=>1) . "</id>\n" .
4270 # use project owner for feed author
4271 "<author><name>$owner</name></author>\n";
4272 if (defined $favicon) {
4273 print "<icon>" . esc_url
($favicon) . "</icon>\n";
4275 if (defined $logo_url) {
4276 # not twice as wide as tall: 72 x 27 pixels
4277 print "<logo>" . esc_url
($logo_url) . "</logo>\n";
4279 if (! %latest_date) {
4280 # dummy date to keep the feed valid until commits trickle in:
4281 print "<updated>1970-01-01T00:00:00Z</updated>\n";
4283 print "<updated>$latest_date{'iso-8601'}</updated>\n";
4288 for (my $i = 0; $i <= $#revlist; $i++) {
4289 my $commit = $revlist[$i];
4290 my %co = parse_commit
($commit);
4291 # we read 150, we always show 30 and the ones more recent than 48 hours
4292 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
4295 my %cd = parse_date
($co{'committer_epoch'});
4297 # get list of changed files
4298 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
4299 $co{'parent'}, $co{'id'}, "--", (defined $file_name ? $file_name : ())
4301 my @difftree = map { chomp; $_ } <$fd>;
4305 # print element (entry, item)
4306 my $co_url = href
(-full
=>1, action
=>"commit", hash
=>$commit);
4307 if ($format eq 'rss') {
4309 "<title>" . esc_html
($co{'title'}) . "</title>\n" .
4310 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
4311 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
4312 "<guid isPermaLink=\"true\">$co_url</guid>\n" .
4313 "<link>$co_url</link>\n" .
4314 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
4315 "<content:encoded>" .
4317 } elsif ($format eq 'atom') {
4319 "<title type=\"html\">" . esc_html
($co{'title'}) . "</title>\n" .
4320 "<updated>$cd{'iso-8601'}</updated>\n" .
4321 "<author><name>" . esc_html
($co{'author_name'}) . "</name></author>\n" .
4322 # use committer for contributor
4323 "<contributor><name>" . esc_html
($co{'committer_name'}) . "</name></contributor>\n" .
4324 "<published>$cd{'iso-8601'}</published>\n" .
4325 "<link rel=\"alternate\" type=\"text/html\" href=\"$co_url\" />\n" .
4326 "<id>$co_url</id>\n" .
4327 "<content type=\"xhtml\" xml:base=\"" . esc_url
($my_url) . "\">\n" .
4328 "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
4330 my $comment = $co{'comment'};
4332 foreach my $line (@$comment) {
4333 $line = esc_html
($line);
4336 print "</pre><ul>\n";
4337 foreach my $difftree_line (@difftree) {
4338 my %difftree = parse_difftree_raw_line
($difftree_line);
4339 next if !$difftree{'from_id'};
4341 my $file = $difftree{'file'} || $difftree{'to_file'};
4345 $cgi->a({-href
=> href
(-full
=>1, action
=>"blobdiff",
4346 hash
=>$difftree{'to_id'}, hash_parent
=>$difftree{'from_id'},
4347 hash_base
=>$co{'id'}, hash_parent_base
=>$co{'parent'},
4348 file_name
=>$file, file_parent
=>$difftree{'from_file'}),
4349 -title
=> "diff"}, 'D');
4351 print $cgi->a({-href
=> href
(-full
=>1, action
=>"blame",
4352 file_name
=>$file, hash_base
=>$commit),
4353 -title
=> "blame"}, 'B');
4355 # if this is not a feed of a file history
4356 if (!defined $file_name || $file_name ne $file) {
4357 print $cgi->a({-href
=> href
(-full
=>1, action
=>"history",
4358 file_name
=>$file, hash
=>$commit),
4359 -title
=> "history"}, 'H');
4361 $file = esc_path
($file);
4365 if ($format eq 'rss') {
4366 print "</ul>]]>\n" .
4367 "</content:encoded>\n" .
4369 } elsif ($format eq 'atom') {
4370 print "</ul>\n</div>\n" .
4377 if ($format eq 'rss') {
4378 print "</channel>\n</rss>\n";
4379 } elsif ($format eq 'atom') {
4393 my @list = git_get_projects_list
();
4395 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
4397 <?xml version="1.0" encoding="utf-8"?>
4398 <opml version="1.0">
4400 <title>$site_name OPML Export</title>
4403 <outline text="git RSS feeds">
4406 foreach my $pr (@list) {
4408 my $head = git_get_head_hash
($proj{'path'});
4409 if (!defined $head) {
4412 $git_dir = "$projectroot/$proj{'path'}";
4413 my %co = parse_commit
($head);
4418 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
4419 my $rss = "$my_url?p=$proj{'path'};a=rss";
4420 my $html = "$my_url?p=$proj{'path'};a=summary";
4421 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";