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 binmode STDOUT
, ':utf8';
21 our $version = "++GIT_VERSION++";
22 our $my_url = $cgi->url();
23 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 # location for temporary files needed for diffs
35 our $git_temp = "/tmp/gitweb";
37 # target of the home link on top of all pages
38 our $home_link = $my_uri;
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++" || $ENV{'SERVER_NAME'} || "Untitled";
44 # html text to include at home page
45 our $home_text = "++GITWEB_HOMETEXT++";
47 # URI of default stylesheet
48 our $stylesheet = "++GITWEB_CSS++";
50 our $logo = "++GITWEB_LOGO++";
52 # source of projects list
53 our $projects_list = "++GITWEB_LIST++";
55 # default blob_plain mimetype and default charset for text/plain blob
56 our $default_blob_plain_mimetype = 'text/plain';
57 our $default_text_plain_charset = undef;
59 # file to use for guessing MIME types before trying /etc/mime.types
60 # (relative to the current git repository)
61 our $mimetypes_file = undef;
63 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
64 require $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
66 # version of the core git binary
67 our $git_version = qx($GIT --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
69 $projects_list ||= $projectroot;
71 mkdir($git_temp, 0700) || die_error
(undef, "Couldn't mkdir $git_temp");
74 # ======================================================================
75 # input validation and dispatch
76 our $action = $cgi->param('a');
77 if (defined $action) {
78 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
79 die_error
(undef, "Invalid action parameter");
81 # action which does not check rest of parameters
82 if ($action eq "opml") {
88 our $project = ($cgi->param('p') || $ENV{'PATH_INFO'});
89 $project =~ s
|^/||; $project =~ s|/$||;
90 if (defined $project && $project) {
91 if (!validate_input
($project)) {
92 die_error
(undef, "Invalid project parameter");
94 if (!(-d
"$projectroot/$project")) {
95 die_error
(undef, "No such directory");
97 if (!(-e
"$projectroot/$project/HEAD")) {
98 die_error
(undef, "No such project");
100 $rss_link = "<link rel=\"alternate\" title=\"" . esc_param
($project) . " log\" href=\"" .
101 "$my_uri?" . esc_param
("p=$project;a=rss") . "\" type=\"application/rss+xml\"/>";
102 $ENV{'GIT_DIR'} = "$projectroot/$project";
108 our $file_name = $cgi->param('f');
109 if (defined $file_name) {
110 if (!validate_input
($file_name)) {
111 die_error
(undef, "Invalid file parameter");
115 our $hash = $cgi->param('h');
117 if (!validate_input
($hash)) {
118 die_error
(undef, "Invalid hash parameter");
122 our $hash_parent = $cgi->param('hp');
123 if (defined $hash_parent) {
124 if (!validate_input
($hash_parent)) {
125 die_error
(undef, "Invalid hash parent parameter");
129 our $hash_base = $cgi->param('hb');
130 if (defined $hash_base) {
131 if (!validate_input
($hash_base)) {
132 die_error
(undef, "Invalid hash base parameter");
136 our $page = $cgi->param('pg');
138 if ($page =~ m/[^0-9]$/) {
139 die_error
(undef, "Invalid page parameter");
143 our $searchtext = $cgi->param('s');
144 if (defined $searchtext) {
145 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
146 die_error
(undef, "Invalid search parameter");
148 $searchtext = quotemeta $searchtext;
153 "blame" => \
&git_blame2
,
154 "blobdiff" => \
&git_blobdiff
,
155 "blobdiff_plain" => \
&git_blobdiff_plain
,
156 "blob" => \
&git_blob
,
157 "blob_plain" => \
&git_blob_plain
,
158 "commitdiff" => \
&git_commitdiff
,
159 "commitdiff_plain" => \
&git_commitdiff_plain
,
160 "commit" => \
&git_commit
,
161 "heads" => \
&git_heads
,
162 "history" => \
&git_history
,
165 "search" => \
&git_search
,
166 "shortlog" => \
&git_shortlog
,
167 "summary" => \
&git_summary
,
169 "tags" => \
&git_tags
,
170 "tree" => \
&git_tree
,
173 $action = 'summary' if (!defined($action));
174 if (!defined($actions{$action})) {
175 die_error
(undef, "Unknown action");
177 $actions{$action}->();
180 ## ======================================================================
181 ## validation, quoting/unquoting and escaping
186 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
189 if ($input =~ m/(^|\/)(|\
.|\
.\
.)($|\
/)/) {
192 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\
-\
+\#\
~\
%]/) {
198 # quote unsafe chars, but keep the slash, even when it's not
199 # correct, but quoted slashes look too horrible in bookmarks
202 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
208 # replace invalid utf8 character with SUBSTITUTION sequence
211 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
212 $str = escapeHTML
($str);
213 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
217 # git may return quoted and escaped filenames
220 if ($str =~ m/^"(.*)"$/) {
222 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
227 ## ----------------------------------------------------------------------
228 ## HTML aware string manipulation
233 my $add_len = shift || 10;
235 # allow only $len chars, but don't cut a word if it would fit in $add_len
236 # if it doesn't fit, cut it if it's still longer than the dots we would add
237 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
240 if (length($tail) > 4) {
242 $body =~ s/&[^;]*$//; # remove chopped character entities
247 ## ----------------------------------------------------------------------
248 ## functions returning short strings
250 # CSS class for given age value (in seconds)
254 if ($age < 60*60*2) {
256 } elsif ($age < 60*60*24*2) {
263 # convert age in seconds to "nn units ago" string
268 if ($age > 60*60*24*365*2) {
269 $age_str = (int $age/60/60/24/365);
270 $age_str .= " years ago";
271 } elsif ($age > 60*60*24*(365/12)*2) {
272 $age_str = int $age/60/60/24/(365/12);
273 $age_str .= " months ago";
274 } elsif ($age > 60*60*24*7*2) {
275 $age_str = int $age/60/60/24/7;
276 $age_str .= " weeks ago";
277 } elsif ($age > 60*60*24*2) {
278 $age_str = int $age/60/60/24;
279 $age_str .= " days ago";
280 } elsif ($age > 60*60*2) {
281 $age_str = int $age/60/60;
282 $age_str .= " hours ago";
283 } elsif ($age > 60*2) {
284 $age_str = int $age/60;
285 $age_str .= " min ago";
288 $age_str .= " sec ago";
290 $age_str .= " right now";
295 # convert file mode in octal to symbolic file mode string
297 my $mode = oct shift;
299 if (S_ISDIR
($mode & S_IFMT
)) {
301 } elsif (S_ISLNK
($mode)) {
303 } elsif (S_ISREG
($mode)) {
304 # git cares only about the executable bit
305 if ($mode & S_IXUSR
) {
315 # convert file mode in octal to file type string
317 my $mode = oct shift;
319 if (S_ISDIR
($mode & S_IFMT
)) {
321 } elsif (S_ISLNK
($mode)) {
323 } elsif (S_ISREG
($mode)) {
330 ## ----------------------------------------------------------------------
331 ## functions returning short HTML fragments, or transforming HTML fragments
332 ## which don't beling to other sections
334 # format line of commit message or tag comment
335 sub format_log_line_html
{
338 $line = esc_html
($line);
339 $line =~ s/ / /g;
340 if ($line =~ m/([0-9a-fA-F]{40})/) {
342 if (git_get_type
($hash_text) eq "commit") {
343 my $link = $cgi->a({-class => "text", -href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_text")}, $hash_text);
344 $line =~ s/$hash_text/$link/;
350 # format marker of refs pointing to given object
351 sub git_get_referencing
{
352 my ($refs, $id) = @_;
354 if (defined $refs->{$id}) {
355 return ' <span class="tag">' . esc_html
($refs->{$id}) . '</span>';
361 ## ----------------------------------------------------------------------
362 ## git utility subroutines, invoking git commands
364 # get HEAD ref of given project as hash
367 my $oENV = $ENV{'GIT_DIR'};
369 $ENV{'GIT_DIR'} = "$projectroot/$project";
370 if (open my $fd, "-|", $GIT, "rev-parse", "--verify", "HEAD") {
373 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
378 $ENV{'GIT_DIR'} = $oENV;
383 # get type of given object
387 open my $fd, "-|", $GIT, "cat-file", '-t', $hash or return;
394 sub git_get_project_config
{
397 return unless ($key);
398 $key =~ s/^gitweb\.//;
399 return if ($key =~ m/\W/);
401 my $val = qx($GIT repo
-config
--get gitweb
.$key);
405 sub git_get_project_config_bool
{
406 my $val = git_get_project_config
(@_);
407 if ($val and $val =~ m/true|yes|on/) {
410 return; # implicit false
413 # get hash of given path at given ref
414 sub git_get_hash_by_path
{
416 my $path = shift || return undef;
420 open my $fd, "-|", $GIT, "ls-tree", $base, "--", $path
421 or die_error
(undef, "Open git-ls-tree failed");
423 close $fd or return undef;
425 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
426 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
430 ## ......................................................................
431 ## git utility functions, directly accessing git repository
433 # assumes that PATH is not symref
437 open my $fd, "$projectroot/$path" or return undef;
441 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
446 sub git_read_description
{
449 open my $fd, "$projectroot/$path/description" or return undef;
456 sub git_read_projects
{
459 if (-d
$projects_list) {
460 # search in directory
461 my $dir = $projects_list;
462 opendir my ($dh), $dir or return undef;
463 while (my $dir = readdir($dh)) {
464 if (-e
"$projectroot/$dir/HEAD") {
472 } elsif (-f
$projects_list) {
473 # read from file(url-encoded):
474 # 'git%2Fgit.git Linus+Torvalds'
475 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
476 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
477 open my ($fd), $projects_list or return undef;
478 while (my $line = <$fd>) {
480 my ($path, $owner) = split ' ', $line;
481 $path = unescape
($path);
482 $owner = unescape
($owner);
483 if (!defined $path) {
486 if (-e
"$projectroot/$path/HEAD") {
489 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
496 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
501 my $type = shift || "";
503 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
504 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
505 open my $fd, "$projectroot/$project/info/refs" or return;
506 while (my $line = <$fd>) {
508 # attention: for $type == "" it saves only last path part of ref name
509 # e.g. from 'refs/heads/jn/gitweb' it would leave only 'gitweb'
510 if ($line =~ m/^([0-9a-fA-F]{40})\t.*$type\/([^\
^]+)/) {
511 if (defined $refs{$1}) {
512 $refs{$1} .= " / $2";
522 ## ----------------------------------------------------------------------
523 ## parse to hash functions
527 my $tz = shift || "-0000";
530 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
531 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
532 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
533 $date{'hour'} = $hour;
534 $date{'minute'} = $min;
535 $date{'mday'} = $mday;
536 $date{'day'} = $days[$wday];
537 $date{'month'} = $months[$mon];
538 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
539 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
541 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
542 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
543 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
544 $date{'hour_local'} = $hour;
545 $date{'minute_local'} = $min;
546 $date{'tz_local'} = $tz;
555 open my $fd, "-|", $GIT, "cat-file", "tag", $tag_id or return;
556 $tag{'id'} = $tag_id;
557 while (my $line = <$fd>) {
559 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
561 } elsif ($line =~ m/^type (.+)$/) {
563 } elsif ($line =~ m/^tag (.+)$/) {
565 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
569 } elsif ($line =~ m/--BEGIN/) {
570 push @comment, $line;
572 } elsif ($line eq "") {
576 push @comment, <$fd>;
577 $tag{'comment'} = \
@comment;
579 if (!defined $tag{'name'}) {
585 sub git_read_commit
{
586 my $commit_id = shift;
587 my $commit_text = shift;
592 if (defined $commit_text) {
593 @commit_lines = @
$commit_text;
596 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", "--max-count=1", $commit_id or return;
597 @commit_lines = split '\n', <$fd>;
602 my $header = shift @commit_lines;
603 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
606 ($co{'id'}, my @parents) = split ' ', $header;
607 $co{'parents'} = \
@parents;
608 $co{'parent'} = $parents[0];
609 while (my $line = shift @commit_lines) {
610 last if $line eq "\n";
611 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
613 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
615 $co{'author_epoch'} = $2;
616 $co{'author_tz'} = $3;
617 if ($co{'author'} =~ m/^([^<]+) </) {
618 $co{'author_name'} = $1;
620 $co{'author_name'} = $co{'author'};
622 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
623 $co{'committer'} = $1;
624 $co{'committer_epoch'} = $2;
625 $co{'committer_tz'} = $3;
626 $co{'committer_name'} = $co{'committer'};
627 $co{'committer_name'} =~ s/ <.*//;
630 if (!defined $co{'tree'}) {
634 foreach my $title (@commit_lines) {
637 $co{'title'} = chop_str
($title, 80, 5);
638 # remove leading stuff of merges to make the interesting part visible
639 if (length($title) > 50) {
640 $title =~ s/^Automatic //;
641 $title =~ s/^merge (of|with) /Merge ... /i;
642 if (length($title) > 50) {
643 $title =~ s/(http|rsync):\/\///;
645 if (length($title) > 50) {
646 $title =~ s/(master|www|rsync)\.//;
648 if (length($title) > 50) {
649 $title =~ s/kernel.org:?//;
651 if (length($title) > 50) {
652 $title =~ s/\/pub\/scm//;
655 $co{'title_short'} = chop_str
($title, 50, 5);
659 # remove added spaces
660 foreach my $line (@commit_lines) {
663 $co{'comment'} = \
@commit_lines;
665 my $age = time - $co{'committer_epoch'};
667 $co{'age_string'} = age_string
($age);
668 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
669 if ($age > 60*60*24*7*2) {
670 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
671 $co{'age_string_age'} = $co{'age_string'};
673 $co{'age_string_date'} = $co{'age_string'};
674 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
679 ## ......................................................................
680 ## parse to array of hashes functions
687 my $pfxlen = length("$projectroot/$project/$ref_dir");
688 File
::Find
::find
(sub {
691 push @refs, substr($File::Find
::name
, $pfxlen + 1);
693 }, "$projectroot/$project/$ref_dir");
695 foreach my $ref_file (@refs) {
696 my $ref_id = git_read_hash
("$project/$ref_dir/$ref_file");
697 my $type = git_get_type
($ref_id) || next;
700 $ref_item{'type'} = $type;
701 $ref_item{'id'} = $ref_id;
702 $ref_item{'epoch'} = 0;
703 $ref_item{'age'} = "unknown";
704 if ($type eq "tag") {
705 my %tag = git_read_tag
($ref_id);
706 $ref_item{'comment'} = $tag{'comment'};
707 if ($tag{'type'} eq "commit") {
708 %co = git_read_commit
($tag{'object'});
709 $ref_item{'epoch'} = $co{'committer_epoch'};
710 $ref_item{'age'} = $co{'age_string'};
711 } elsif (defined($tag{'epoch'})) {
712 my $age = time - $tag{'epoch'};
713 $ref_item{'epoch'} = $tag{'epoch'};
714 $ref_item{'age'} = age_string
($age);
716 $ref_item{'reftype'} = $tag{'type'};
717 $ref_item{'name'} = $tag{'name'};
718 $ref_item{'refid'} = $tag{'object'};
719 } elsif ($type eq "commit"){
720 %co = git_read_commit
($ref_id);
721 $ref_item{'reftype'} = "commit";
722 $ref_item{'name'} = $ref_file;
723 $ref_item{'title'} = $co{'title'};
724 $ref_item{'refid'} = $ref_id;
725 $ref_item{'epoch'} = $co{'committer_epoch'};
726 $ref_item{'age'} = $co{'age_string'};
728 $ref_item{'reftype'} = $type;
729 $ref_item{'name'} = $ref_file;
730 $ref_item{'refid'} = $ref_id;
733 push @reflist, \
%ref_item;
736 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
740 ## ----------------------------------------------------------------------
741 ## filesystem-related functions
746 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
747 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
748 if (!defined $gcos) {
752 $owner =~ s/[,;].*$//;
753 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
756 ## ......................................................................
757 ## mimetype related functions
759 sub mimetype_guess_file
{
760 my $filename = shift;
762 -r
$mimemap or return undef;
765 open(MIME
, $mimemap) or return undef;
767 my ($mime, $exts) = split(/\t+/);
769 my @exts = split(/\s+/, $exts);
770 foreach my $ext (@exts) {
771 $mimemap{$ext} = $mime;
777 $filename =~ /\.(.*?)$/;
782 my $filename = shift;
784 $filename =~ /\./ or return undef;
786 if ($mimetypes_file) {
787 my $file = $mimetypes_file;
788 #$file =~ m#^/# or $file = "$projectroot/$path/$file";
789 $mime = mimetype_guess_file
($filename, $file);
791 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
795 sub git_blob_plain_mimetype
{
797 my $filename = shift;
800 my $mime = mimetype_guess
($filename);
801 $mime and return $mime;
805 return $default_blob_plain_mimetype unless $fd;
808 return 'text/plain' .
809 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
810 } elsif (! $filename) {
811 return 'application/octet-stream';
812 } elsif ($filename =~ m/\.png$/i) {
814 } elsif ($filename =~ m/\.gif$/i) {
816 } elsif ($filename =~ m/\.jpe?g$/i) {
819 return 'application/octet-stream';
823 ## ======================================================================
824 ## functions printing HTML: header, footer, error page
826 sub git_header_html
{
827 my $status = shift || "200 OK";
830 my $title = "$site_name git";
831 if (defined $project) {
832 $title .= " - $project";
833 if (defined $action) {
834 $title .= "/$action";
835 if (defined $file_name) {
836 $title .= " - $file_name";
837 if ($action eq "tree" && $file_name !~ m
|/$|) {
844 # require explicit support from the UA if we are to send the page as
845 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
846 # we have to do this because MSIE sometimes globs '*/*', pretending to
847 # support xhtml+xml but choking when it gets what it asked for.
848 if ($cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ && $cgi->Accept('application/xhtml
+xml
') != 0) {
849 $content_type = 'application
/xhtml
+xml
';
851 $content_type = 'text
/html
';
853 print $cgi->header(-type=>$content_type, -charset => 'utf
-8', -status=> $status, -expires => $expires);
855 <?xml version="1.0" encoding="utf-8"?>
856 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
857 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
858 <!-- git web interface v$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
859 <!-- git core binaries version $git_version -->
861 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
862 <meta name="robots" content="index, nofollow"/>
863 <title>$title</title>
864 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
869 print "<div class=\"page_header\">\n" .
870 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
871 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
873 print $cgi->a({-href
=> esc_param
($home_link)}, "projects") . " / ";
874 if (defined $project) {
875 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, esc_html
($project));
876 if (defined $action) {
880 if (!defined $searchtext) {
884 if (defined $hash_base) {
885 $search_hash = $hash_base;
886 } elsif (defined $hash) {
887 $search_hash = $hash;
889 $search_hash = "HEAD";
891 $cgi->param("a", "search");
892 $cgi->param("h", $search_hash);
893 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
894 "<div class=\"search\">\n" .
895 $cgi->hidden(-name
=> "p") . "\n" .
896 $cgi->hidden(-name
=> "a") . "\n" .
897 $cgi->hidden(-name
=> "h") . "\n" .
898 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
900 $cgi->end_form() . "\n";
905 sub git_footer_html
{
906 print "<div class=\"page_footer\">\n";
907 if (defined $project) {
908 my $descr = git_read_description
($project);
909 if (defined $descr) {
910 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
912 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=rss"), -class => "rss_logo"}, "RSS") . "\n";
914 print $cgi->a({-href
=> "$my_uri?" . esc_param
("a=opml"), -class => "rss_logo"}, "OPML") . "\n";
922 my $status = shift || "403 Forbidden";
923 my $error = shift || "Malformed query, file missing or permission denied";
925 git_header_html
($status);
926 print "<div class=\"page_body\">\n" .
928 "$status - $error\n" .
935 ## ----------------------------------------------------------------------
936 ## functions printing or outputting HTML: navigation
939 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
940 $extra = '' if !defined $extra; # pager or formats
942 my @navs = qw(summary shortlog log commit commitdiff tree);
944 @navs = grep { $_ ne $suppress } @navs;
947 my %arg = map { $_, ''} @navs;
949 for (qw(commit commitdiff)) {
950 $arg{$_} = ";h=$head";
952 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
953 for (qw(shortlog log)) {
954 $arg{$_} = ";h=$head";
958 $arg{tree
} .= ";h=$treehead" if defined $treehead;
959 $arg{tree
} .= ";hb=$treebase" if defined $treebase;
961 print "<div class=\"page_nav\">\n" .
965 : $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$_$arg{$_}")}, "$_")
968 print "<br/>\n$extra<br/>\n" .
972 sub git_get_paging_nav
{
973 my ($action, $hash, $head, $page, $nrevs) = @_;
977 if ($hash ne $head || $page) {
978 $paging_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$action")}, "HEAD");
980 $paging_nav .= "HEAD";
984 $paging_nav .= " ⋅ " .
985 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$action;h=$hash;pg=" . ($page-1)),
986 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
988 $paging_nav .= " ⋅ prev";
991 if ($nrevs >= (100 * ($page+1)-1)) {
992 $paging_nav .= " ⋅ " .
993 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$action;h=$hash;pg=" . ($page+1)),
994 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
996 $paging_nav .= " ⋅ next";
1002 ## ......................................................................
1003 ## functions printing or outputting HTML: div
1005 sub git_header_div
{
1006 my ($action, $title, $hash, $hash_base) = @_;
1009 $rest .= ";h=$hash" if $hash;
1010 $rest .= ";hb=$hash_base" if $hash_base;
1012 print "<div class=\"header\">\n" .
1013 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$action$rest"),
1014 -class => "title"}, $title ?
$title : $action) . "\n" .
1018 sub git_print_page_path
{
1022 if (!defined $name) {
1023 print "<div class=\"page_path\"><b>/</b></div>\n";
1024 } elsif (defined $type && $type eq 'blob') {
1025 print "<div class=\"page_path\"><b>" .
1026 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;f=$file_name")}, esc_html
($name)) . "</b><br/></div>\n";
1028 print "<div class=\"page_path\"><b>" . esc_html
($name) . "</b><br/></div>\n";
1032 ## ......................................................................
1033 ## functions printing large fragments of HTML
1035 sub git_shortlog_body
{
1036 # uses global variable $project
1037 my ($revlist, $from, $to, $refs, $extra) = @_;
1038 $from = 0 unless defined $from;
1039 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1041 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
1043 for (my $i = $from; $i <= $to; $i++) {
1044 my $commit = $revlist->[$i];
1045 #my $ref = defined $refs ? git_get_referencing($refs, $commit) : '';
1046 my $ref = git_get_referencing
($refs, $commit);
1047 my %co = git_read_commit
($commit);
1048 my %ad = date_str
($co{'author_epoch'});
1050 print "<tr class=\"dark\">\n";
1052 print "<tr class=\"light\">\n";
1055 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1056 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1057 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
1059 if (length($co{'title_short'}) < length($co{'title'})) {
1060 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"),
1061 -class => "list", -title
=> "$co{'title'}"},
1062 "<b>" . esc_html
($co{'title_short'}) . "$ref</b>");
1064 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"),
1066 "<b>" . esc_html
($co{'title'}) . "$ref</b>");
1069 "<td class=\"link\">" .
1070 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") . " | " .
1071 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1075 if (defined $extra) {
1077 "<td colspan=\"4\">$extra</td>\n" .
1084 # uses global variable $project
1085 my ($taglist, $from, $to, $extra) = @_;
1086 $from = 0 unless defined $from;
1087 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1089 print "<table class=\"tags\" cellspacing=\"0\">\n";
1091 for (my $i = $from; $i <= $to; $i++) {
1092 my $entry = $taglist->[$i];
1094 my $comment_lines = $tag{'comment'};
1095 my $comment = shift @
$comment_lines;
1097 if (defined $comment) {
1098 $comment_short = chop_str
($comment, 30, 5);
1101 print "<tr class=\"dark\">\n";
1103 print "<tr class=\"light\">\n";
1106 print "<td><i>$tag{'age'}</i></td>\n" .
1108 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"),
1109 -class => "list"}, "<b>" . esc_html
($tag{'name'}) . "</b>") .
1112 if (defined $comment) {
1113 if (length($comment_short) < length($comment)) {
1114 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}"),
1115 -class => "list", -title
=> $comment}, $comment_short);
1117 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}"),
1118 -class => "list"}, $comment);
1122 "<td class=\"selflink\">";
1123 if ($tag{'type'} eq "tag") {
1124 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, "tag");
1129 "<td class=\"link\">" . " | " .
1130 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1131 if ($tag{'reftype'} eq "commit") {
1132 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1133 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'refid'}")}, "log");
1134 } elsif ($tag{'reftype'} eq "blob") {
1135 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$tag{'refid'}")}, "raw");
1140 if (defined $extra) {
1142 "<td colspan=\"5\">$extra</td>\n" .
1148 sub git_heads_body
{
1149 # uses global variable $project
1150 my ($taglist, $head, $from, $to, $extra) = @_;
1151 $from = 0 unless defined $from;
1152 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1154 print "<table class=\"heads\" cellspacing=\"0\">\n";
1156 for (my $i = $from; $i <= $to; $i++) {
1157 my $entry = $taglist->[$i];
1159 my $curr = $tag{'id'} eq $head;
1161 print "<tr class=\"dark\">\n";
1163 print "<tr class=\"light\">\n";
1166 print "<td><i>$tag{'age'}</i></td>\n" .
1167 ($tag{'id'} eq $head ?
"<td class=\"current_head\">" : "<td>") .
1168 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}"),
1169 -class => "list"}, "<b>" . esc_html
($tag{'name'}) . "</b>") .
1171 "<td class=\"link\">" .
1172 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") . " | " .
1173 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'name'}")}, "log") .
1177 if (defined $extra) {
1179 "<td colspan=\"3\">$extra</td>\n" .
1185 ## ----------------------------------------------------------------------
1186 ## functions printing large fragments, format as one of arguments
1188 sub git_diff_print
{
1190 my $from_name = shift;
1192 my $to_name = shift;
1193 my $format = shift || "html";
1195 my $from_tmp = "/dev/null";
1196 my $to_tmp = "/dev/null";
1199 # create tmp from-file
1200 if (defined $from) {
1201 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
1202 open my $fd2, "> $from_tmp";
1203 open my $fd, "-|", $GIT, "cat-file", "blob", $from;
1210 # create tmp to-file
1212 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
1213 open my $fd2, "> $to_tmp";
1214 open my $fd, "-|", $GIT, "cat-file", "blob", $to;
1221 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
1222 if ($format eq "plain") {
1227 while (my $line = <$fd>) {
1229 my $char = substr($line, 0, 1);
1230 my $diff_class = "";
1232 $diff_class = " add";
1233 } elsif ($char eq "-") {
1234 $diff_class = " rem";
1235 } elsif ($char eq "@") {
1236 $diff_class = " chunk_header";
1237 } elsif ($char eq "\\") {
1241 while ((my $pos = index($line, "\t")) != -1) {
1242 if (my $count = (8 - (($pos-1) % 8))) {
1243 my $spaces = ' ' x
$count;
1244 $line =~ s/\t/$spaces/;
1247 print "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
1252 if (defined $from) {
1261 ## ======================================================================
1262 ## ======================================================================
1265 sub git_project_list
{
1266 my $order = $cgi->param('o');
1267 if (defined $order && $order !~ m/project|descr|owner|age/) {
1268 die_error
(undef, "Unknown order parameter");
1271 my @list = git_read_projects
();
1274 die_error
(undef, "No projects found");
1276 foreach my $pr (@list) {
1277 my $head = git_read_head
($pr->{'path'});
1278 if (!defined $head) {
1281 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
1282 my %co = git_read_commit
($head);
1286 $pr->{'commit'} = \
%co;
1287 if (!defined $pr->{'descr'}) {
1288 my $descr = git_read_description
($pr->{'path'}) || "";
1289 $pr->{'descr'} = chop_str
($descr, 25, 5);
1291 if (!defined $pr->{'owner'}) {
1292 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
1294 push @projects, $pr;
1298 if (-f
$home_text) {
1299 print "<div class=\"index_include\">\n";
1300 open (my $fd, $home_text);
1305 print "<table class=\"project_list\">\n" .
1307 $order ||= "project";
1308 if ($order eq "project") {
1309 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
1310 print "<th>Project</th>\n";
1313 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=project"),
1314 -class => "header"}, "Project") .
1317 if ($order eq "descr") {
1318 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
1319 print "<th>Description</th>\n";
1322 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=descr"),
1323 -class => "header"}, "Description") .
1326 if ($order eq "owner") {
1327 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
1328 print "<th>Owner</th>\n";
1331 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=owner"),
1332 -class => "header"}, "Owner") .
1335 if ($order eq "age") {
1336 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
1337 print "<th>Last Change</th>\n";
1340 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=age"),
1341 -class => "header"}, "Last Change") .
1344 print "<th></th>\n" .
1347 foreach my $pr (@projects) {
1349 print "<tr class=\"dark\">\n";
1351 print "<tr class=\"light\">\n";
1354 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=summary"),
1355 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
1356 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
1357 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
1358 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" .
1359 $pr->{'commit'}{'age_string'} . "</td>\n" .
1360 "<td class=\"link\">" .
1361 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=summary")}, "summary") . " | " .
1362 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=shortlog")}, "shortlog") . " | " .
1363 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=log")}, "log") .
1372 my $descr = git_read_description
($project) || "none";
1373 my $head = git_read_head
($project);
1374 my %co = git_read_commit
($head);
1375 my %cd = date_str
($co{'committer_epoch'}, $co{'committer_tz'});
1378 if (-f
$projects_list) {
1379 open (my $fd , $projects_list);
1380 while (my $line = <$fd>) {
1382 my ($pr, $ow) = split ' ', $line;
1383 $pr = unescape
($pr);
1384 $ow = unescape
($ow);
1385 if ($pr eq $project) {
1386 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
1392 if (!defined $owner) {
1393 $owner = get_file_owner
("$projectroot/$project");
1396 my $refs = read_info_ref
();
1398 git_page_nav
('summary','', $head);
1400 print "<div class=\"title\"> </div>\n";
1401 print "<table cellspacing=\"0\">\n" .
1402 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
1403 "<tr><td>owner</td><td>$owner</td></tr>\n" .
1404 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
1407 open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_read_head
($project)
1408 or die_error
(undef, "Open git-rev-list failed");
1409 my @revlist = map { chomp; $_ } <$fd>;
1411 git_header_div
('shortlog');
1412 git_shortlog_body
(\
@revlist, 0, 15, $refs,
1413 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "..."));
1415 my $taglist = git_read_refs
("refs/tags");
1416 if (defined @
$taglist) {
1417 git_header_div
('tags');
1418 git_tags_body
($taglist, 0, 15,
1419 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tags")}, "..."));
1422 my $headlist = git_read_refs
("refs/heads");
1423 if (defined @
$headlist) {
1424 git_header_div
('heads');
1425 git_heads_body
($headlist, $head, 0, 15,
1426 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=heads")}, "..."));
1433 my $head = git_read_head
($project);
1435 git_page_nav
('','', $head,undef,$head);
1436 my %tag = git_read_tag
($hash);
1437 git_header_div
('commit', esc_html
($tag{'name'}), $hash);
1438 print "<div class=\"title_text\">\n" .
1439 "<table cellspacing=\"0\">\n" .
1441 "<td>object</td>\n" .
1442 "<td>" . $cgi->a({-class => "list", -href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'object'}) . "</td>\n" .
1443 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'type'}) . "</td>\n" .
1445 if (defined($tag{'author'})) {
1446 my %ad = date_str
($tag{'epoch'}, $tag{'tz'});
1447 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
1448 print "<tr><td></td><td>" . $ad{'rfc2822'} . sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) . "</td></tr>\n";
1450 print "</table>\n\n" .
1452 print "<div class=\"page_body\">";
1453 my $comment = $tag{'comment'};
1454 foreach my $line (@
$comment) {
1455 print esc_html
($line) . "<br/>\n";
1464 die_error
(undef, "Permission denied") if (!git_get_project_config_bool
('blame'));
1465 die_error
('404 Not Found', "File name not defined") if (!$file_name);
1466 $hash_base ||= git_read_head
($project);
1467 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
1468 my %co = git_read_commit
($hash_base)
1469 or die_error
(undef, "Reading commit failed");
1470 if (!defined $hash) {
1471 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
1472 or die_error
(undef, "Error looking up file");
1474 $ftype = git_get_type
($hash);
1475 if ($ftype !~ "blob") {
1476 die_error
("400 Bad Request", "Object is not a blob");
1478 open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base)
1479 or die_error
(undef, "Open git-blame failed");
1482 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") .
1483 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;f=$file_name")}, "head");
1484 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1485 git_header_div
('commit', esc_html
($co{'title'}), $hash_base);
1486 git_print_page_path
($file_name, $ftype);
1487 my @rev_color = (qw(light dark));
1488 my $num_colors = scalar(@rev_color);
1489 my $current_color = 0;
1491 print "<div class=\"page_body\">\n";
1492 print "<table class=\"blame\">\n";
1493 print "<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n";
1495 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
1497 my $rev = substr($full_rev, 0, 8);
1501 if (!defined $last_rev) {
1502 $last_rev = $full_rev;
1503 } elsif ($last_rev ne $full_rev) {
1504 $last_rev = $full_rev;
1505 $current_color = ++$current_color % $num_colors;
1507 print "<tr class=\"$rev_color[$current_color]\">\n";
1508 print "<td class=\"sha1\">" .
1509 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$full_rev;f=$file_name")}, esc_html
($rev)) . "</td>\n";
1510 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" . esc_html
($lineno) . "</a></td>\n";
1511 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
1516 close $fd or print "Reading blob failed\n";
1522 die_error
('403 Permission denied', "Permission denied") if (!git_get_project_config_bool
('blame'));
1523 die_error
('404 Not Found', "File name not defined") if (!$file_name);
1524 $hash_base ||= git_read_head
($project);
1525 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
1526 my %co = git_read_commit
($hash_base)
1527 or die_error
(undef, "Reading commit failed");
1528 if (!defined $hash) {
1529 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
1530 or die_error
(undef, "Error lookup file");
1532 open ($fd, "-|", $GIT, "annotate", '-l', '-t', '-r', $file_name, $hash_base)
1533 or die_error
(undef, "Open git-annotate failed");
1536 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") .
1537 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;f=$file_name")}, "head");
1538 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1539 git_header_div
('commit', esc_html
($co{'title'}), $hash_base);
1540 git_print_page_path
($file_name, 'blob');
1541 print "<div class=\"page_body\">\n";
1543 <table class="blame">
1552 my @line_class = (qw(light dark));
1553 my $line_class_len = scalar (@line_class);
1554 my $line_class_num = $#line_class;
1555 while (my $line = <$fd>) {
1567 $line_class_num = ($line_class_num + 1) % $line_class_len;
1569 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) \+\d\d\d\d\t(\d+)\)(.*)$/) {
1576 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
1579 $short_rev = substr ($long_rev, 0, 8);
1580 $age = time () - $time;
1581 $age_str = age_string
($age);
1582 $age_str =~ s/ / /g;
1583 $age_class = age_class
($age);
1584 $author = esc_html
($author);
1585 $author =~ s/ / /g;
1587 while ((my $pos = index($data, "\t")) != -1) {
1588 if (my $count = (8 - ($pos % 8))) {
1589 my $spaces = ' ' x
$count;
1590 $data =~ s/\t/$spaces/;
1593 $data = esc_html
($data);
1596 <tr class="$line_class[$line_class_num]">
1597 <td class="sha1"><a href="$my_uri?${\esc_param ("p=$project;a=commit;h=$long_rev")}" class="text">$short_rev..</a></td>
1598 <td class="$age_class">$age_str</td>
1600 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
1601 <td class="pre">$data</td>
1604 } # while (my $line = <$fd>)
1605 print "</table>\n\n";
1606 close $fd or print "Reading blob failed.\n";
1612 my $head = git_read_head
($project);
1614 git_page_nav
('','', $head,undef,$head);
1615 git_header_div
('summary', $project);
1617 my $taglist = git_read_refs
("refs/tags");
1618 if (defined @
$taglist) {
1619 git_tags_body
($taglist);
1625 my $head = git_read_head
($project);
1627 git_page_nav
('','', $head,undef,$head);
1628 git_header_div
('summary', $project);
1630 my $taglist = git_read_refs
("refs/heads");
1632 if (defined @
$taglist) {
1633 git_heads_body
($taglist, $head);
1638 sub git_blob_plain
{
1639 if (!defined $hash) {
1640 if (defined $file_name) {
1641 my $base = $hash_base || git_read_head
($project);
1642 $hash = git_get_hash_by_path
($base, $file_name, "blob")
1643 or die_error
(undef, "Error lookup file");
1645 die_error
(undef, "No file name defined");
1649 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
1650 or die_error
(undef, "Couldn't cat $file_name, $hash");
1652 $type ||= git_blob_plain_mimetype
($fd, $file_name);
1654 # save as filename, even when no $file_name is given
1655 my $save_as = "$hash";
1656 if (defined $file_name) {
1657 $save_as = $file_name;
1658 } elsif ($type =~ m/^text\//) {
1662 print $cgi->header(-type
=> "$type", '-content-disposition' => "inline; filename=\"$save_as\"");
1664 binmode STDOUT
, ':raw';
1666 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
1672 if (!defined $hash) {
1673 if (defined $file_name) {
1674 my $base = $hash_base || git_read_head
($project);
1675 $hash = git_get_hash_by_path
($base, $file_name, "blob")
1676 or die_error
(undef, "Error lookup file");
1678 die_error
(undef, "No file name defined");
1681 my $have_blame = git_get_project_config_bool
('blame');
1682 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
1683 or die_error
(undef, "Couldn't cat $file_name, $hash");
1684 my $mimetype = git_blob_plain_mimetype
($fd, $file_name);
1685 if ($mimetype !~ m/^text\//) {
1687 return git_blob_plain
($mimetype);
1690 my $formats_nav = '';
1691 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
1692 if (defined $file_name) {
1694 $formats_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;h=$hash;hb=$hash_base;f=$file_name")}, "blame") . " | ";
1697 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$hash;f=$file_name")}, "plain") .
1698 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;hb=HEAD;f=$file_name")}, "head");
1700 $formats_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$hash")}, "plain");
1702 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1703 git_header_div
('commit', esc_html
($co{'title'}), $hash_base);
1705 print "<div class=\"page_nav\">\n" .
1706 "<br/><br/></div>\n" .
1707 "<div class=\"title\">$hash</div>\n";
1709 git_print_page_path
($file_name, "blob");
1710 print "<div class=\"page_body\">\n";
1712 while (my $line = <$fd>) {
1715 while ((my $pos = index($line, "\t")) != -1) {
1716 if (my $count = (8 - ($pos % 8))) {
1717 my $spaces = ' ' x
$count;
1718 $line =~ s/\t/$spaces/;
1721 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", $nr, $nr, $nr, esc_html
($line);
1723 close $fd or print "Reading blob failed.\n";
1729 if (!defined $hash) {
1730 $hash = git_read_head
($project);
1731 if (defined $file_name) {
1732 my $base = $hash_base || $hash;
1733 $hash = git_get_hash_by_path
($base, $file_name, "tree");
1735 if (!defined $hash_base) {
1740 open my $fd, "-|", $GIT, "ls-tree", '-z', $hash
1741 or die_error
(undef, "Open git-ls-tree failed");
1742 my @entries = map { chomp; $_ } <$fd>;
1743 close $fd or die_error
(undef, "Reading tree failed");
1746 my $refs = read_info_ref
();
1747 my $ref = git_get_referencing
($refs, $hash_base);
1751 my $have_blame = git_get_project_config_bool
('blame');
1752 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
1753 $base_key = ";hb=$hash_base";
1754 git_page_nav
('tree','', $hash_base);
1755 git_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
1757 print "<div class=\"page_nav\">\n";
1758 print "<br/><br/></div>\n";
1759 print "<div class=\"title\">$hash</div>\n";
1761 if (defined $file_name) {
1762 $base = esc_html
("$file_name/");
1764 git_print_page_path
($file_name, 'tree');
1765 print "<div class=\"page_body\">\n";
1766 print "<table cellspacing=\"0\">\n";
1768 foreach my $line (@entries) {
1769 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1770 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1774 my $t_name = validate_input
($4);
1776 print "<tr class=\"dark\">\n";
1778 print "<tr class=\"light\">\n";
1781 print "<td class=\"mode\">" . mode_str
($t_mode) . "</td>\n";
1782 if ($t_type eq "blob") {
1783 print "<td class=\"list\">" .
1784 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name"), -class => "list"}, esc_html
($t_name)) .
1786 "<td class=\"link\">" .
1787 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name")}, "blob");
1789 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;h=$t_hash$base_key;f=$base$t_name")}, "blame");
1791 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;h=$t_hash;hb=$hash_base;f=$base$t_name")}, "history") .
1792 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$t_hash;f=$base$t_name")}, "raw") .
1794 } elsif ($t_type eq "tree") {
1795 print "<td class=\"list\">" .
1796 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, esc_html
($t_name)) .
1798 "<td class=\"link\">" .
1799 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, "tree") .
1800 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;hb=$hash_base;f=$base$t_name")}, "history") .
1805 print "</table>\n" .
1811 my $head = git_read_head
($project);
1812 if (!defined $hash) {
1815 if (!defined $page) {
1818 my $refs = read_info_ref
();
1820 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
1821 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
1822 or die_error
(undef, "Open git-rev-list failed");
1823 my @revlist = map { chomp; $_ } <$fd>;
1826 my $paging_nav = git_get_paging_nav
('log', $hash, $head, $page, $#revlist);
1829 git_page_nav
('log','', $hash,undef,undef, $paging_nav);
1832 my %co = git_read_commit
($hash);
1834 git_header_div
('summary', $project);
1835 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
1837 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
1838 my $commit = $revlist[$i];
1839 my $ref = git_get_referencing
($refs, $commit);
1840 my %co = git_read_commit
($commit);
1842 my %ad = date_str
($co{'author_epoch'});
1843 git_header_div
('commit',
1844 "<span class=\"age\">$co{'age_string'}</span>" .
1845 esc_html
($co{'title'}) . $ref,
1847 print "<div class=\"title_text\">\n" .
1848 "<div class=\"log_link\">\n" .
1849 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
1850 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1853 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
1855 "<div class=\"log_body\">\n";
1856 my $comment = $co{'comment'};
1858 foreach my $line (@
$comment) {
1859 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1870 print format_log_line_html
($line) . "<br/>\n";
1881 my %co = git_read_commit
($hash);
1883 die_error
(undef, "Unknown commit object");
1885 my %ad = date_str
($co{'author_epoch'}, $co{'author_tz'});
1886 my %cd = date_str
($co{'committer_epoch'}, $co{'committer_tz'});
1888 my $parent = $co{'parent'};
1889 if (!defined $parent) {
1892 open my $fd, "-|", $GIT, "diff-tree", '-r', '-M', $parent, $hash
1893 or die_error
(undef, "Open git-diff-tree failed");
1894 my @difftree = map { chomp; $_ } <$fd>;
1895 close $fd or die_error
(undef, "Reading git-diff-tree failed");
1897 # non-textual hash id's can be cached
1899 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
1902 my $refs = read_info_ref
();
1903 my $ref = git_get_referencing
($refs, $co{'id'});
1904 my $formats_nav = '';
1905 if (defined $file_name && defined $co{'parent'}) {
1906 my $parent = $co{'parent'};
1907 $formats_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;hb=$parent;f=$file_name")}, "blame");
1909 git_header_html
(undef, $expires);
1910 git_page_nav
('commit', defined $co{'parent'} ?
'' : 'commitdiff',
1911 $hash, $co{'tree'}, $hash,
1914 if (defined $co{'parent'}) {
1915 git_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
1917 git_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
1919 print "<div class=\"title_text\">\n" .
1920 "<table cellspacing=\"0\">\n";
1921 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
1923 "<td></td><td> $ad{'rfc2822'}";
1924 if ($ad{'hour_local'} < 6) {
1925 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1927 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1931 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
1932 print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
1933 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
1936 "<td class=\"sha1\">" .
1937 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash"), class => "list"}, $co{'tree'}) .
1939 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
1942 my $parents = $co{'parents'};
1943 foreach my $par (@
$parents) {
1946 "<td class=\"sha1\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$par"), class => "list"}, $par) . "</td>" .
1947 "<td class=\"link\">" .
1948 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$par")}, "commit") .
1949 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash;hp=$par")}, "commitdiff") .
1955 print "<div class=\"page_body\">\n";
1956 my $comment = $co{'comment'};
1959 foreach my $line (@
$comment) {
1960 # print only one empty line
1962 if ($empty || $signed) {
1969 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1971 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1974 print format_log_line_html
($line) . "<br/>\n";
1978 print "<div class=\"list_head\">\n";
1979 if ($#difftree > 10) {
1980 print(($#difftree + 1) . " files changed:\n");
1983 print "<table class=\"diff_tree\">\n";
1985 foreach my $line (@difftree) {
1986 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1987 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1988 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
1996 my $similarity = $6;
1997 my $file = validate_input
(unquote
($7));
1999 print "<tr class=\"dark\">\n";
2001 print "<tr class=\"light\">\n";
2004 if ($status eq "A") {
2006 if (S_ISREG
(oct $to_mode)) {
2007 $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
2010 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file"), -class => "list"}, esc_html
($file)) . "</td>\n" .
2011 "<td><span class=\"file_status new\">[new " . file_type
($to_mode) . "$mode_chng]</span></td>\n" .
2012 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob") . "</td>\n";
2013 } elsif ($status eq "D") {
2015 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file"), -class => "list"}, esc_html
($file)) . "</td>\n" .
2016 "<td><span class=\"file_status deleted\">[deleted " . file_type
($from_mode). "]</span></td>\n" .
2017 "<td class=\"link\">" .
2018 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, "blob") .
2019 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;hb=$hash;f=$file")}, "history") .
2021 } elsif ($status eq "M" || $status eq "T") {
2022 my $mode_chnge = "";
2023 if ($from_mode != $to_mode) {
2024 $mode_chnge = " <span class=\"file_status mode_chnge\">[changed";
2025 if (((oct $from_mode) & S_IFMT
) != ((oct $to_mode) & S_IFMT
)) {
2026 $mode_chnge .= " from " . file_type
($from_mode) . " to " . file_type
($to_mode);
2028 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
2029 if (S_ISREG
($from_mode) && S_ISREG
($to_mode)) {
2030 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
2031 } elsif (S_ISREG
($to_mode)) {
2032 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
2035 $mode_chnge .= "]</span>\n";
2038 if ($to_id ne $from_id) {
2039 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file"), -class => "list"}, esc_html
($file));
2041 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file"), -class => "list"}, esc_html
($file));
2044 "<td>$mode_chnge</td>\n" .
2045 "<td class=\"link\">";
2046 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob");
2047 if ($to_id ne $from_id) {
2048 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file")}, "diff");
2050 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;hb=$hash;f=$file")}, "history") . "\n";
2052 } elsif ($status eq "R") {
2053 my ($from_file, $to_file) = split "\t", $file;
2055 if ($from_mode != $to_mode) {
2056 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
2059 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file"), -class => "list"}, esc_html
($to_file)) . "</td>\n" .
2060 "<td><span class=\"file_status moved\">[moved from " .
2061 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$from_file"), -class => "list"}, esc_html
($from_file)) .
2062 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
2063 "<td class=\"link\">" .
2064 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file")}, "blob");
2065 if ($to_id ne $from_id) {
2066 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file")}, "diff");
2077 mkdir($git_temp, 0700);
2079 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
2081 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff_plain;h=$hash;hp=$hash_parent")}, "plain");
2082 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2083 git_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2085 print "<div class=\"page_nav\">\n" .
2086 "<br/><br/></div>\n" .
2087 "<div class=\"title\">$hash vs $hash_parent</div>\n";
2089 git_print_page_path
($file_name, "blob");
2090 print "<div class=\"page_body\">\n" .
2091 "<div class=\"diff_info\">blob:" .
2092 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name")}, $hash_parent) .
2094 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, $hash) .
2096 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
2101 sub git_blobdiff_plain
{
2102 mkdir($git_temp, 0700);
2103 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8');
2104 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
2107 sub git_commitdiff
{
2108 mkdir($git_temp, 0700);
2109 my %co = git_read_commit
($hash);
2111 die_error
(undef, "Unknown commit object");
2113 if (!defined $hash_parent) {
2114 $hash_parent = $co{'parent'};
2116 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2117 or die_error
(undef, "Open git-diff-tree failed");
2118 my @difftree = map { chomp; $_ } <$fd>;
2119 close $fd or die_error
(undef, "Reading git-diff-tree failed");
2121 # non-textual hash id's can be cached
2123 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2126 my $refs = read_info_ref
();
2127 my $ref = git_get_referencing
($refs, $co{'id'});
2129 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent")}, "plain");
2130 git_header_html
(undef, $expires);
2131 git_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
2132 git_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
2133 print "<div class=\"page_body\">\n";
2134 my $comment = $co{'comment'};
2137 my @log = @
$comment;
2138 # remove first and empty lines after that
2140 while (defined $log[0] && $log[0] eq "") {
2143 foreach my $line (@log) {
2144 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2155 print format_log_line_html
($line) . "<br/>\n";
2158 foreach my $line (@difftree) {
2159 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2160 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2161 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2167 my $file = validate_input
(unquote
($6));
2168 if ($status eq "A") {
2169 print "<div class=\"diff_info\">" . file_type
($to_mode) . ":" .
2170 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id) . "(new)" .
2172 git_diff_print
(undef, "/dev/null", $to_id, "b/$file");
2173 } elsif ($status eq "D") {
2174 print "<div class=\"diff_info\">" . file_type
($from_mode) . ":" .
2175 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) . "(deleted)" .
2177 git_diff_print
($from_id, "a/$file", undef, "/dev/null");
2178 } elsif ($status eq "M") {
2179 if ($from_id ne $to_id) {
2180 print "<div class=\"diff_info\">" .
2181 file_type
($from_mode) . ":" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) .
2183 file_type
($to_mode) . ":" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id);
2185 git_diff_print
($from_id, "a/$file", $to_id, "b/$file");
2194 sub git_commitdiff_plain
{
2195 mkdir($git_temp, 0700);
2196 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2197 or die_error
(undef, "Open git-diff-tree failed");
2198 my @difftree = map { chomp; $_ } <$fd>;
2199 close $fd or die_error
(undef, "Reading diff-tree failed");
2201 # try to figure out the next tag after this commit
2203 my $refs = read_info_ref
("tags");
2204 open $fd, "-|", $GIT, "rev-list", "HEAD";
2205 my @commits = map { chomp; $_ } <$fd>;
2207 foreach my $commit (@commits) {
2208 if (defined $refs->{$commit}) {
2209 $tagname = $refs->{$commit}
2211 if ($commit eq $hash) {
2216 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8', '-content-disposition' => "inline; filename=\"git-$hash.patch\"");
2217 my %co = git_read_commit
($hash);
2218 my %ad = date_str
($co{'author_epoch'}, $co{'author_tz'});
2219 my $comment = $co{'comment'};
2220 print "From: $co{'author'}\n" .
2221 "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
2222 "Subject: $co{'title'}\n";
2223 if (defined $tagname) {
2224 print "X-Git-Tag: $tagname\n";
2226 print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
2229 foreach my $line (@
$comment) {;
2234 foreach my $line (@difftree) {
2235 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2240 if ($status eq "A") {
2241 git_diff_print
(undef, "/dev/null", $to_id, "b/$file", "plain");
2242 } elsif ($status eq "D") {
2243 git_diff_print
($from_id, "a/$file", undef, "/dev/null", "plain");
2244 } elsif ($status eq "M") {
2245 git_diff_print
($from_id, "a/$file", $to_id, "b/$file", "plain");
2251 if (!defined $hash_base) {
2252 $hash_base = git_read_head
($project);
2255 my %co = git_read_commit
($hash_base);
2257 die_error
(undef, "Unknown commit object");
2259 my $refs = read_info_ref
();
2261 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base);
2262 git_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2263 if (!defined $hash && defined $file_name) {
2264 $hash = git_get_hash_by_path
($hash_base, $file_name);
2266 if (defined $hash) {
2267 $ftype = git_get_type
($hash);
2269 git_print_page_path
($file_name, $ftype);
2272 $GIT, "rev-list", "--full-history", $hash_base, "--", $file_name;
2273 print "<table cellspacing=\"0\">\n";
2275 while (my $line = <$fd>) {
2276 if ($line =~ m/^([0-9a-fA-F]{40})/){
2278 my %co = git_read_commit
($commit);
2282 my $ref = git_get_referencing
($refs, $commit);
2284 print "<tr class=\"dark\">\n";
2286 print "<tr class=\"light\">\n";
2289 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2290 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2291 "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list"}, "<b>" .
2292 esc_html
(chop_str
($co{'title'}, 50)) . "$ref</b>") . "</td>\n" .
2293 "<td class=\"link\">" .
2294 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
2295 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2296 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$ftype;hb=$commit;f=$file_name")}, $ftype);
2297 my $blob = git_get_hash_by_path
($hash_base, $file_name);
2298 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2299 if (defined $blob && defined $blob_parent && $blob ne $blob_parent) {
2301 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=$file_name")},
2314 if (!defined $searchtext) {
2315 die_error
(undef, "Text field empty");
2317 if (!defined $hash) {
2318 $hash = git_read_head
($project);
2320 my %co = git_read_commit
($hash);
2322 die_error
(undef, "Unknown commit object");
2324 # pickaxe may take all resources of your box and run for several minutes
2325 # with every query - so decide by yourself how public you make this feature :)
2326 my $commit_search = 1;
2327 my $author_search = 0;
2328 my $committer_search = 0;
2329 my $pickaxe_search = 0;
2330 if ($searchtext =~ s/^author\\://i) {
2332 } elsif ($searchtext =~ s/^committer\\://i) {
2333 $committer_search = 1;
2334 } elsif ($searchtext =~ s/^pickaxe\\://i) {
2336 $pickaxe_search = 1;
2339 git_page_nav
('','', $hash,$co{'tree'},$hash);
2340 git_header_div
('commit', esc_html
($co{'title'}), $hash);
2342 print "<table cellspacing=\"0\">\n";
2344 if ($commit_search) {
2346 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", $hash or next;
2347 while (my $commit_text = <$fd>) {
2348 if (!grep m/$searchtext/i, $commit_text) {
2351 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
2354 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
2357 my @commit_lines = split "\n", $commit_text;
2358 my %co = git_read_commit
(undef, \
@commit_lines);
2363 print "<tr class=\"dark\">\n";
2365 print "<tr class=\"light\">\n";
2368 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2369 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2371 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" . esc_html
(chop_str
($co{'title'}, 50)) . "</b><br/>");
2372 my $comment = $co{'comment'};
2373 foreach my $line (@
$comment) {
2374 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2375 my $lead = esc_html
($1) || "";
2376 $lead = chop_str
($lead, 30, 10);
2377 my $match = esc_html
($2) || "";
2378 my $trail = esc_html
($3) || "";
2379 $trail = chop_str
($trail, 30, 10);
2380 my $text = "$lead<span class=\"match\">$match</span>$trail";
2381 print chop_str
($text, 80, 5) . "<br/>\n";
2385 "<td class=\"link\">" .
2386 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2387 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2394 if ($pickaxe_search) {
2396 open my $fd, "-|", "$GIT rev-list $hash | $GIT diff-tree -r --stdin -S\'$searchtext\'";
2399 while (my $line = <$fd>) {
2400 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2403 $set{'from_id'} = $3;
2405 $set{'id'} = $set{'to_id'};
2406 if ($set{'id'} =~ m/0{40}/) {
2407 $set{'id'} = $set{'from_id'};
2409 if ($set{'id'} =~ m/0{40}/) {
2413 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
2416 print "<tr class=\"dark\">\n";
2418 print "<tr class=\"light\">\n";
2421 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2422 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2424 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" .
2425 esc_html
(chop_str
($co{'title'}, 50)) . "</b><br/>");
2426 while (my $setref = shift @files) {
2428 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}"), class => "list"},
2429 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
2433 "<td class=\"link\">" .
2434 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2435 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2439 %co = git_read_commit
($1);
2449 my $head = git_read_head
($project);
2450 if (!defined $hash) {
2453 if (!defined $page) {
2456 my $refs = read_info_ref
();
2458 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2459 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2460 or die_error
(undef, "Open git-rev-list failed");
2461 my @revlist = map { chomp; $_ } <$fd>;
2464 my $paging_nav = git_get_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
2466 if ($#revlist >= (100 * ($page+1)-1)) {
2468 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)),
2469 -title
=> "Alt-n"}, "next");
2474 git_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
2475 git_header_div
('summary', $project);
2477 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
2482 ## ......................................................................
2483 ## feeds (RSS, OPML)
2486 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
2487 open my $fd, "-|", $GIT, "rev-list", "--max-count=150", git_read_head
($project)
2488 or die_error
(undef, "Open git-rev-list failed");
2489 my @revlist = map { chomp; $_ } <$fd>;
2490 close $fd or die_error
(undef, "Reading git-rev-list failed");
2491 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
2492 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
2493 "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
2494 print "<channel>\n";
2495 print "<title>$project</title>\n".
2496 "<link>" . esc_html
("$my_url?p=$project;a=summary") . "</link>\n".
2497 "<description>$project log</description>\n".
2498 "<language>en</language>\n";
2500 for (my $i = 0; $i <= $#revlist; $i++) {
2501 my $commit = $revlist[$i];
2502 my %co = git_read_commit
($commit);
2503 # we read 150, we always show 30 and the ones more recent than 48 hours
2504 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
2507 my %cd = date_str
($co{'committer_epoch'});
2508 open $fd, "-|", $GIT, "diff-tree", '-r', $co{'parent'}, $co{'id'} or next;
2509 my @difftree = map { chomp; $_ } <$fd>;
2513 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
2515 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
2516 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
2517 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
2518 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
2519 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
2520 "<content:encoded>" .
2522 my $comment = $co{'comment'};
2523 foreach my $line (@
$comment) {
2524 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
2525 print "$line<br/>\n";
2528 foreach my $line (@difftree) {
2529 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
2532 my $file = validate_input
(unquote
($7));
2533 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
2534 print "$file<br/>\n";
2537 "</content:encoded>\n" .
2540 print "</channel></rss>";
2544 my @list = git_read_projects
();
2546 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
2547 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
2548 "<opml version=\"1.0\">\n".
2550 " <title>$site_name Git OPML Export</title>\n".
2553 "<outline text=\"git RSS feeds\">\n";
2555 foreach my $pr (@list) {
2557 my $head = git_read_head
($proj{'path'});
2558 if (!defined $head) {
2561 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
2562 my %co = git_read_commit
($head);
2567 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
2568 my $rss = "$my_url?p=$proj{'path'};a=rss";
2569 my $html = "$my_url?p=$proj{'path'};a=summary";
2570 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
2572 print "</outline>\n".