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
("Couldn't mkdir $git_temp");
74 # input validation and dispatch
75 our $action = $cgi->param('a');
76 if (defined $action) {
77 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
79 die_error
(undef, "Invalid action parameter.");
81 if ($action eq "opml") {
87 our $project = ($cgi->param('p') || $ENV{'PATH_INFO'});
88 if (defined $project) {
89 $project =~ s
|^/||; $project =~ s|/$||;
90 $project = validate_input
($project);
91 if (!defined($project)) {
92 die_error
(undef, "Invalid project parameter.");
94 if (!(-d
"$projectroot/$project")) {
96 die_error
(undef, "No such directory.");
98 if (!(-e
"$projectroot/$project/HEAD")) {
100 die_error
(undef, "No such project.");
102 $rss_link = "<link rel=\"alternate\" title=\"" . esc_param
($project) . " log\" href=\"" .
103 "$my_uri?" . esc_param
("p=$project;a=rss") . "\" type=\"application/rss+xml\"/>";
104 $ENV{'GIT_DIR'} = "$projectroot/$project";
110 our $file_name = $cgi->param('f');
111 if (defined $file_name) {
112 $file_name = validate_input
($file_name);
113 if (!defined($file_name)) {
114 die_error
(undef, "Invalid file parameter.");
118 our $hash = $cgi->param('h');
120 $hash = validate_input
($hash);
121 if (!defined($hash)) {
122 die_error
(undef, "Invalid hash parameter.");
126 our $hash_parent = $cgi->param('hp');
127 if (defined $hash_parent) {
128 $hash_parent = validate_input
($hash_parent);
129 if (!defined($hash_parent)) {
130 die_error
(undef, "Invalid hash parent parameter.");
134 our $hash_base = $cgi->param('hb');
135 if (defined $hash_base) {
136 $hash_base = validate_input
($hash_base);
137 if (!defined($hash_base)) {
138 die_error
(undef, "Invalid hash base parameter.");
142 our $page = $cgi->param('pg');
144 if ($page =~ m/[^0-9]$/) {
146 die_error
(undef, "Invalid page parameter.");
150 our $searchtext = $cgi->param('s');
151 if (defined $searchtext) {
152 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
154 die_error
(undef, "Invalid search parameter.");
156 $searchtext = quotemeta $searchtext;
161 "blame" => \
&git_blame2
,
162 "blobdiff" => \
&git_blobdiff
,
163 "blobdiff_plain" => \
&git_blobdiff_plain
,
164 "blob" => \
&git_blob
,
165 "blob_plain" => \
&git_blob_plain
,
166 "commitdiff" => \
&git_commitdiff
,
167 "commitdiff_plain" => \
&git_commitdiff_plain
,
168 "commit" => \
&git_commit
,
169 "heads" => \
&git_heads
,
170 "history" => \
&git_history
,
173 "search" => \
&git_search
,
174 "shortlog" => \
&git_shortlog
,
175 "summary" => \
&git_summary
,
177 "tags" => \
&git_tags
,
178 "tree" => \
&git_tree
,
181 $action = 'summary' if (!defined($action));
182 if (!defined($actions{$action})) {
184 die_error
(undef, "Unknown action.");
186 $actions{$action}->();
189 ## ======================================================================
190 ## validation, quoting/unquoting and escaping
195 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
198 if ($input =~ m/(^|\/)(|\
.|\
.\
.)($|\
/)/) {
201 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\
-\
+\#\
~\
%]/) {
207 # quote unsafe chars, but keep the slash, even when it's not
208 # correct, but quoted slashes look too horrible in bookmarks
211 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
217 # replace invalid utf8 character with SUBSTITUTION sequence
220 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
221 $str = escapeHTML
($str);
222 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
226 # git may return quoted and escaped filenames
229 if ($str =~ m/^"(.*)"$/) {
231 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
236 ## ----------------------------------------------------------------------
237 ## HTML aware string manipulation
242 my $add_len = shift || 10;
244 # allow only $len chars, but don't cut a word if it would fit in $add_len
245 # if it doesn't fit, cut it if it's still longer than the dots we would add
246 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
249 if (length($tail) > 4) {
251 $body =~ s/&[^;]*$//; # remove chopped character entities
256 ## ----------------------------------------------------------------------
257 ## functions returning short strings
259 # CSS class for given age value (in seconds)
263 if ($age < 60*60*2) {
265 } elsif ($age < 60*60*24*2) {
272 # convert age in seconds to "nn units ago" string
277 if ($age > 60*60*24*365*2) {
278 $age_str = (int $age/60/60/24/365);
279 $age_str .= " years ago";
280 } elsif ($age > 60*60*24*(365/12)*2) {
281 $age_str = int $age/60/60/24/(365/12);
282 $age_str .= " months ago";
283 } elsif ($age > 60*60*24*7*2) {
284 $age_str = int $age/60/60/24/7;
285 $age_str .= " weeks ago";
286 } elsif ($age > 60*60*24*2) {
287 $age_str = int $age/60/60/24;
288 $age_str .= " days ago";
289 } elsif ($age > 60*60*2) {
290 $age_str = int $age/60/60;
291 $age_str .= " hours ago";
292 } elsif ($age > 60*2) {
293 $age_str = int $age/60;
294 $age_str .= " min ago";
297 $age_str .= " sec ago";
299 $age_str .= " right now";
304 # convert file mode in octal to symbolic file mode string
306 my $mode = oct shift;
308 if (S_ISDIR
($mode & S_IFMT
)) {
310 } elsif (S_ISLNK
($mode)) {
312 } elsif (S_ISREG
($mode)) {
313 # git cares only about the executable bit
314 if ($mode & S_IXUSR
) {
324 # convert file mode in octal to file type string
326 my $mode = oct shift;
328 if (S_ISDIR
($mode & S_IFMT
)) {
330 } elsif (S_ISLNK
($mode)) {
332 } elsif (S_ISREG
($mode)) {
339 ## ----------------------------------------------------------------------
340 ## functions returning short HTML fragments, or transforming HTML fragments
341 ## which don't beling to other sections
343 # format line of commit message or tag comment
344 sub format_log_line_html
{
347 $line = esc_html
($line);
348 $line =~ s/ / /g;
349 if ($line =~ m/([0-9a-fA-F]{40})/) {
351 if (git_get_type
($hash_text) eq "commit") {
352 my $link = $cgi->a({-class => "text", -href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_text")}, $hash_text);
353 $line =~ s/$hash_text/$link/;
359 # format marker of refs pointing to given object
360 sub git_get_referencing
{
361 my ($refs, $id) = @_;
363 if (defined $refs->{$id}) {
364 return ' <span class="tag">' . esc_html
($refs->{$id}) . '</span>';
370 ## ----------------------------------------------------------------------
371 ## git utility subroutines, invoking git commands
373 # get HEAD ref of given project as hash
376 my $oENV = $ENV{'GIT_DIR'};
378 $ENV{'GIT_DIR'} = "$projectroot/$project";
379 if (open my $fd, "-|", $GIT, "rev-parse", "--verify", "HEAD") {
382 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
387 $ENV{'GIT_DIR'} = $oENV;
392 # get type of given object
396 open my $fd, "-|", $GIT, "cat-file", '-t', $hash or return;
403 sub git_get_project_config
{
406 return unless ($key);
407 $key =~ s/^gitweb\.//;
408 return if ($key =~ m/\W/);
410 my $val = qx($GIT repo
-config
--get gitweb
.$key);
414 sub git_get_project_config_bool
{
415 my $val = git_get_project_config
(@_);
416 if ($val and $val =~ m/true|yes|on/) {
419 return; # implicit false
422 # get hash of given path at given ref
423 sub git_get_hash_by_path
{
425 my $path = shift || return undef;
429 open my $fd, "-|", $GIT, "ls-tree", $base, "--", $path
430 or die_error
(undef, "Open git-ls-tree failed.");
432 close $fd or return undef;
434 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
435 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
439 ## ......................................................................
440 ## git utility functions, directly accessing git repository
442 # assumes that PATH is not symref
446 open my $fd, "$projectroot/$path" or return undef;
450 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
455 sub git_read_description
{
458 open my $fd, "$projectroot/$path/description" or return undef;
465 sub git_read_projects
{
468 if (-d
$projects_list) {
469 # search in directory
470 my $dir = $projects_list;
471 opendir my ($dh), $dir or return undef;
472 while (my $dir = readdir($dh)) {
473 if (-e
"$projectroot/$dir/HEAD") {
481 } elsif (-f
$projects_list) {
482 # read from file(url-encoded):
483 # 'git%2Fgit.git Linus+Torvalds'
484 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
485 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
486 open my ($fd), $projects_list or return undef;
487 while (my $line = <$fd>) {
489 my ($path, $owner) = split ' ', $line;
490 $path = unescape
($path);
491 $owner = unescape
($owner);
492 if (!defined $path) {
495 if (-e
"$projectroot/$path/HEAD") {
498 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
505 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
510 my $type = shift || "";
512 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
513 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
514 open my $fd, "$projectroot/$project/info/refs" or return;
515 while (my $line = <$fd>) {
517 # attention: for $type == "" it saves only last path part of ref name
518 # e.g. from 'refs/heads/jn/gitweb' it would leave only 'gitweb'
519 if ($line =~ m/^([0-9a-fA-F]{40})\t.*$type\/([^\
^]+)/) {
520 if (defined $refs{$1}) {
521 $refs{$1} .= " / $2";
531 ## ----------------------------------------------------------------------
532 ## parse to hash functions
536 my $tz = shift || "-0000";
539 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
540 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
541 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
542 $date{'hour'} = $hour;
543 $date{'minute'} = $min;
544 $date{'mday'} = $mday;
545 $date{'day'} = $days[$wday];
546 $date{'month'} = $months[$mon];
547 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
548 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
550 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
551 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
552 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
553 $date{'hour_local'} = $hour;
554 $date{'minute_local'} = $min;
555 $date{'tz_local'} = $tz;
564 open my $fd, "-|", $GIT, "cat-file", "tag", $tag_id or return;
565 $tag{'id'} = $tag_id;
566 while (my $line = <$fd>) {
568 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
570 } elsif ($line =~ m/^type (.+)$/) {
572 } elsif ($line =~ m/^tag (.+)$/) {
574 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
578 } elsif ($line =~ m/--BEGIN/) {
579 push @comment, $line;
581 } elsif ($line eq "") {
585 push @comment, <$fd>;
586 $tag{'comment'} = \
@comment;
588 if (!defined $tag{'name'}) {
594 sub git_read_commit
{
595 my $commit_id = shift;
596 my $commit_text = shift;
601 if (defined $commit_text) {
602 @commit_lines = @
$commit_text;
605 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", "--max-count=1", $commit_id or return;
606 @commit_lines = split '\n', <$fd>;
611 my $header = shift @commit_lines;
612 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
615 ($co{'id'}, my @parents) = split ' ', $header;
616 $co{'parents'} = \
@parents;
617 $co{'parent'} = $parents[0];
618 while (my $line = shift @commit_lines) {
619 last if $line eq "\n";
620 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
622 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
624 $co{'author_epoch'} = $2;
625 $co{'author_tz'} = $3;
626 if ($co{'author'} =~ m/^([^<]+) </) {
627 $co{'author_name'} = $1;
629 $co{'author_name'} = $co{'author'};
631 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
632 $co{'committer'} = $1;
633 $co{'committer_epoch'} = $2;
634 $co{'committer_tz'} = $3;
635 $co{'committer_name'} = $co{'committer'};
636 $co{'committer_name'} =~ s/ <.*//;
639 if (!defined $co{'tree'}) {
643 foreach my $title (@commit_lines) {
646 $co{'title'} = chop_str
($title, 80, 5);
647 # remove leading stuff of merges to make the interesting part visible
648 if (length($title) > 50) {
649 $title =~ s/^Automatic //;
650 $title =~ s/^merge (of|with) /Merge ... /i;
651 if (length($title) > 50) {
652 $title =~ s/(http|rsync):\/\///;
654 if (length($title) > 50) {
655 $title =~ s/(master|www|rsync)\.//;
657 if (length($title) > 50) {
658 $title =~ s/kernel.org:?//;
660 if (length($title) > 50) {
661 $title =~ s/\/pub\/scm//;
664 $co{'title_short'} = chop_str
($title, 50, 5);
668 # remove added spaces
669 foreach my $line (@commit_lines) {
672 $co{'comment'} = \
@commit_lines;
674 my $age = time - $co{'committer_epoch'};
676 $co{'age_string'} = age_string
($age);
677 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
678 if ($age > 60*60*24*7*2) {
679 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
680 $co{'age_string_age'} = $co{'age_string'};
682 $co{'age_string_date'} = $co{'age_string'};
683 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
688 ## ......................................................................
689 ## parse to array of hashes functions
696 my $pfxlen = length("$projectroot/$project/$ref_dir");
697 File
::Find
::find
(sub {
700 push @refs, substr($File::Find
::name
, $pfxlen + 1);
702 }, "$projectroot/$project/$ref_dir");
704 foreach my $ref_file (@refs) {
705 my $ref_id = git_read_hash
("$project/$ref_dir/$ref_file");
706 my $type = git_get_type
($ref_id) || next;
709 $ref_item{'type'} = $type;
710 $ref_item{'id'} = $ref_id;
711 $ref_item{'epoch'} = 0;
712 $ref_item{'age'} = "unknown";
713 if ($type eq "tag") {
714 my %tag = git_read_tag
($ref_id);
715 $ref_item{'comment'} = $tag{'comment'};
716 if ($tag{'type'} eq "commit") {
717 %co = git_read_commit
($tag{'object'});
718 $ref_item{'epoch'} = $co{'committer_epoch'};
719 $ref_item{'age'} = $co{'age_string'};
720 } elsif (defined($tag{'epoch'})) {
721 my $age = time - $tag{'epoch'};
722 $ref_item{'epoch'} = $tag{'epoch'};
723 $ref_item{'age'} = age_string
($age);
725 $ref_item{'reftype'} = $tag{'type'};
726 $ref_item{'name'} = $tag{'name'};
727 $ref_item{'refid'} = $tag{'object'};
728 } elsif ($type eq "commit"){
729 %co = git_read_commit
($ref_id);
730 $ref_item{'reftype'} = "commit";
731 $ref_item{'name'} = $ref_file;
732 $ref_item{'title'} = $co{'title'};
733 $ref_item{'refid'} = $ref_id;
734 $ref_item{'epoch'} = $co{'committer_epoch'};
735 $ref_item{'age'} = $co{'age_string'};
737 $ref_item{'reftype'} = $type;
738 $ref_item{'name'} = $ref_file;
739 $ref_item{'refid'} = $ref_id;
742 push @reflist, \
%ref_item;
745 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
749 ## ----------------------------------------------------------------------
750 ## filesystem-related functions
755 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
756 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
757 if (!defined $gcos) {
761 $owner =~ s/[,;].*$//;
762 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
765 ## ......................................................................
766 ## mimetype related functions
768 sub mimetype_guess_file
{
769 my $filename = shift;
771 -r
$mimemap or return undef;
774 open(MIME
, $mimemap) or return undef;
776 my ($mime, $exts) = split(/\t+/);
778 my @exts = split(/\s+/, $exts);
779 foreach my $ext (@exts) {
780 $mimemap{$ext} = $mime;
786 $filename =~ /\.(.*?)$/;
791 my $filename = shift;
793 $filename =~ /\./ or return undef;
795 if ($mimetypes_file) {
796 my $file = $mimetypes_file;
797 #$file =~ m#^/# or $file = "$projectroot/$path/$file";
798 $mime = mimetype_guess_file
($filename, $file);
800 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
804 sub git_blob_plain_mimetype
{
806 my $filename = shift;
809 my $mime = mimetype_guess
($filename);
810 $mime and return $mime;
814 return $default_blob_plain_mimetype unless $fd;
817 return 'text/plain' .
818 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
819 } elsif (! $filename) {
820 return 'application/octet-stream';
821 } elsif ($filename =~ m/\.png$/i) {
823 } elsif ($filename =~ m/\.gif$/i) {
825 } elsif ($filename =~ m/\.jpe?g$/i) {
828 return 'application/octet-stream';
832 ## ======================================================================
833 ## functions printing HTML: header, footer, error page
835 sub git_header_html
{
836 my $status = shift || "200 OK";
839 my $title = "$site_name git";
840 if (defined $project) {
841 $title .= " - $project";
842 if (defined $action) {
843 $title .= "/$action";
844 if (defined $file_name) {
845 $title .= " - $file_name";
846 if ($action eq "tree" && $file_name !~ m
|/$|) {
853 # require explicit support from the UA if we are to send the page as
854 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
855 # we have to do this because MSIE sometimes globs '*/*', pretending to
856 # support xhtml+xml but choking when it gets what it asked for.
857 if ($cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ && $cgi->Accept('application/xhtml
+xml
') != 0) {
858 $content_type = 'application
/xhtml
+xml
';
860 $content_type = 'text
/html
';
862 print $cgi->header(-type=>$content_type, -charset => 'utf
-8', -status=> $status, -expires => $expires);
864 <?xml version="1.0" encoding="utf-8"?>
865 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
866 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
867 <!-- git web interface v$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
868 <!-- git core binaries version $git_version -->
870 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
871 <meta name="robots" content="index, nofollow"/>
872 <title>$title</title>
873 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
878 print "<div class=\"page_header\">\n" .
879 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
880 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
882 print $cgi->a({-href
=> esc_param
($home_link)}, "projects") . " / ";
883 if (defined $project) {
884 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, esc_html
($project));
885 if (defined $action) {
889 if (!defined $searchtext) {
893 if (defined $hash_base) {
894 $search_hash = $hash_base;
895 } elsif (defined $hash) {
896 $search_hash = $hash;
898 $search_hash = "HEAD";
900 $cgi->param("a", "search");
901 $cgi->param("h", $search_hash);
902 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
903 "<div class=\"search\">\n" .
904 $cgi->hidden(-name
=> "p") . "\n" .
905 $cgi->hidden(-name
=> "a") . "\n" .
906 $cgi->hidden(-name
=> "h") . "\n" .
907 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
909 $cgi->end_form() . "\n";
914 sub git_footer_html
{
915 print "<div class=\"page_footer\">\n";
916 if (defined $project) {
917 my $descr = git_read_description
($project);
918 if (defined $descr) {
919 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
921 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=rss"), -class => "rss_logo"}, "RSS") . "\n";
923 print $cgi->a({-href
=> "$my_uri?" . esc_param
("a=opml"), -class => "rss_logo"}, "OPML") . "\n";
931 my $status = shift || "403 Forbidden";
932 my $error = shift || "Malformed query, file missing or permission denied";
934 git_header_html
($status);
935 print "<div class=\"page_body\">\n" .
937 "$status - $error\n" .
944 ## ----------------------------------------------------------------------
945 ## functions printing or outputting HTML: navigation
948 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
949 $extra = '' if !defined $extra; # pager or formats
951 my @navs = qw(summary shortlog log commit commitdiff tree);
953 @navs = grep { $_ ne $suppress } @navs;
956 my %arg = map { $_, ''} @navs;
958 for (qw(commit commitdiff)) {
959 $arg{$_} = ";h=$head";
961 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
962 for (qw(shortlog log)) {
963 $arg{$_} = ";h=$head";
967 $arg{tree
} .= ";h=$treehead" if defined $treehead;
968 $arg{tree
} .= ";hb=$treebase" if defined $treebase;
970 print "<div class=\"page_nav\">\n" .
974 : $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$_$arg{$_}")}, "$_")
977 print "<br/>\n$extra<br/>\n" .
981 sub git_get_paging_nav
{
982 my ($action, $hash, $head, $page, $nrevs) = @_;
986 if ($hash ne $head || $page) {
987 $paging_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$action")}, "HEAD");
989 $paging_nav .= "HEAD";
993 $paging_nav .= " ⋅ " .
994 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$action;h=$hash;pg=" . ($page-1)),
995 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
997 $paging_nav .= " ⋅ prev";
1000 if ($nrevs >= (100 * ($page+1)-1)) {
1001 $paging_nav .= " ⋅ " .
1002 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$action;h=$hash;pg=" . ($page+1)),
1003 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1005 $paging_nav .= " ⋅ next";
1011 ## ......................................................................
1012 ## functions printing or outputting HTML: div
1014 sub git_header_div
{
1015 my ($action, $title, $hash, $hash_base) = @_;
1018 $rest .= ";h=$hash" if $hash;
1019 $rest .= ";hb=$hash_base" if $hash_base;
1021 print "<div class=\"header\">\n" .
1022 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$action$rest"),
1023 -class => "title"}, $title ?
$title : $action) . "\n" .
1027 sub git_print_page_path
{
1031 if (!defined $name) {
1032 print "<div class=\"page_path\"><b>/</b></div>\n";
1033 } elsif (defined $type && $type eq 'blob') {
1034 print "<div class=\"page_path\"><b>" .
1035 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;f=$file_name")}, esc_html
($name)) . "</b><br/></div>\n";
1037 print "<div class=\"page_path\"><b>" . esc_html
($name) . "</b><br/></div>\n";
1041 ## ......................................................................
1042 ## functions printing large fragments of HTML
1044 sub git_shortlog_body
{
1045 # uses global variable $project
1046 my ($revlist, $from, $to, $refs, $extra) = @_;
1047 $from = 0 unless defined $from;
1048 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1050 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
1052 for (my $i = $from; $i <= $to; $i++) {
1053 my $commit = $revlist->[$i];
1054 #my $ref = defined $refs ? git_get_referencing($refs, $commit) : '';
1055 my $ref = git_get_referencing
($refs, $commit);
1056 my %co = git_read_commit
($commit);
1057 my %ad = date_str
($co{'author_epoch'});
1059 print "<tr class=\"dark\">\n";
1061 print "<tr class=\"light\">\n";
1064 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1065 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1066 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
1068 if (length($co{'title_short'}) < length($co{'title'})) {
1069 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"),
1070 -class => "list", -title
=> "$co{'title'}"},
1071 "<b>" . esc_html
($co{'title_short'}) . "$ref</b>");
1073 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"),
1075 "<b>" . esc_html
($co{'title'}) . "$ref</b>");
1078 "<td class=\"link\">" .
1079 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") . " | " .
1080 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1084 if (defined $extra) {
1086 "<td colspan=\"4\">$extra</td>\n" .
1093 # uses global variable $project
1094 my ($taglist, $from, $to, $extra) = @_;
1095 $from = 0 unless defined $from;
1096 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1098 print "<table class=\"tags\" cellspacing=\"0\">\n";
1100 for (my $i = $from; $i <= $to; $i++) {
1101 my $entry = $taglist->[$i];
1103 my $comment_lines = $tag{'comment'};
1104 my $comment = shift @
$comment_lines;
1106 if (defined $comment) {
1107 $comment_short = chop_str
($comment, 30, 5);
1110 print "<tr class=\"dark\">\n";
1112 print "<tr class=\"light\">\n";
1115 print "<td><i>$tag{'age'}</i></td>\n" .
1117 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"),
1118 -class => "list"}, "<b>" . esc_html
($tag{'name'}) . "</b>") .
1121 if (defined $comment) {
1122 if (length($comment_short) < length($comment)) {
1123 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}"),
1124 -class => "list", -title
=> $comment}, $comment_short);
1126 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}"),
1127 -class => "list"}, $comment);
1131 "<td class=\"selflink\">";
1132 if ($tag{'type'} eq "tag") {
1133 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, "tag");
1138 "<td class=\"link\">" . " | " .
1139 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1140 if ($tag{'reftype'} eq "commit") {
1141 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1142 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'refid'}")}, "log");
1143 } elsif ($tag{'reftype'} eq "blob") {
1144 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$tag{'refid'}")}, "raw");
1149 if (defined $extra) {
1151 "<td colspan=\"5\">$extra</td>\n" .
1157 sub git_heads_body
{
1158 # uses global variable $project
1159 my ($taglist, $head, $from, $to, $extra) = @_;
1160 $from = 0 unless defined $from;
1161 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1163 print "<table class=\"heads\" cellspacing=\"0\">\n";
1165 for (my $i = $from; $i <= $to; $i++) {
1166 my $entry = $taglist->[$i];
1168 my $curr = $tag{'id'} eq $head;
1170 print "<tr class=\"dark\">\n";
1172 print "<tr class=\"light\">\n";
1175 print "<td><i>$tag{'age'}</i></td>\n" .
1176 ($tag{'id'} eq $head ?
"<td class=\"current_head\">" : "<td>") .
1177 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}"),
1178 -class => "list"}, "<b>" . esc_html
($tag{'name'}) . "</b>") .
1180 "<td class=\"link\">" .
1181 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") . " | " .
1182 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'name'}")}, "log") .
1186 if (defined $extra) {
1188 "<td colspan=\"3\">$extra</td>\n" .
1194 ## ----------------------------------------------------------------------
1195 ## functions printing large fragments, format as one of arguments
1197 sub git_diff_print
{
1199 my $from_name = shift;
1201 my $to_name = shift;
1202 my $format = shift || "html";
1204 my $from_tmp = "/dev/null";
1205 my $to_tmp = "/dev/null";
1208 # create tmp from-file
1209 if (defined $from) {
1210 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
1211 open my $fd2, "> $from_tmp";
1212 open my $fd, "-|", $GIT, "cat-file", "blob", $from;
1219 # create tmp to-file
1221 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
1222 open my $fd2, "> $to_tmp";
1223 open my $fd, "-|", $GIT, "cat-file", "blob", $to;
1230 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
1231 if ($format eq "plain") {
1236 while (my $line = <$fd>) {
1238 my $char = substr($line, 0, 1);
1239 my $diff_class = "";
1241 $diff_class = " add";
1242 } elsif ($char eq "-") {
1243 $diff_class = " rem";
1244 } elsif ($char eq "@") {
1245 $diff_class = " chunk_header";
1246 } elsif ($char eq "\\") {
1250 while ((my $pos = index($line, "\t")) != -1) {
1251 if (my $count = (8 - (($pos-1) % 8))) {
1252 my $spaces = ' ' x
$count;
1253 $line =~ s/\t/$spaces/;
1256 print "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
1261 if (defined $from) {
1270 ## ======================================================================
1271 ## ======================================================================
1274 sub git_project_list
{
1275 my $order = $cgi->param('o');
1276 if (defined $order && $order !~ m/project|descr|owner|age/) {
1277 die_error
(undef, "Invalid order parameter '$order'.");
1280 my @list = git_read_projects
();
1283 die_error
(undef, "No projects found.");
1285 foreach my $pr (@list) {
1286 my $head = git_read_head
($pr->{'path'});
1287 if (!defined $head) {
1290 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
1291 my %co = git_read_commit
($head);
1295 $pr->{'commit'} = \
%co;
1296 if (!defined $pr->{'descr'}) {
1297 my $descr = git_read_description
($pr->{'path'}) || "";
1298 $pr->{'descr'} = chop_str
($descr, 25, 5);
1300 if (!defined $pr->{'owner'}) {
1301 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
1303 push @projects, $pr;
1307 if (-f
$home_text) {
1308 print "<div class=\"index_include\">\n";
1309 open (my $fd, $home_text);
1314 print "<table class=\"project_list\">\n" .
1316 $order ||= "project";
1317 if ($order eq "project") {
1318 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
1319 print "<th>Project</th>\n";
1322 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=project"),
1323 -class => "header"}, "Project") .
1326 if ($order eq "descr") {
1327 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
1328 print "<th>Description</th>\n";
1331 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=descr"),
1332 -class => "header"}, "Description") .
1335 if ($order eq "owner") {
1336 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
1337 print "<th>Owner</th>\n";
1340 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=owner"),
1341 -class => "header"}, "Owner") .
1344 if ($order eq "age") {
1345 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
1346 print "<th>Last Change</th>\n";
1349 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=age"),
1350 -class => "header"}, "Last Change") .
1353 print "<th></th>\n" .
1356 foreach my $pr (@projects) {
1358 print "<tr class=\"dark\">\n";
1360 print "<tr class=\"light\">\n";
1363 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=summary"),
1364 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
1365 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
1366 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
1367 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" .
1368 $pr->{'commit'}{'age_string'} . "</td>\n" .
1369 "<td class=\"link\">" .
1370 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=summary")}, "summary") . " | " .
1371 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=shortlog")}, "shortlog") . " | " .
1372 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=log")}, "log") .
1381 my $descr = git_read_description
($project) || "none";
1382 my $head = git_read_head
($project);
1383 my %co = git_read_commit
($head);
1384 my %cd = date_str
($co{'committer_epoch'}, $co{'committer_tz'});
1387 if (-f
$projects_list) {
1388 open (my $fd , $projects_list);
1389 while (my $line = <$fd>) {
1391 my ($pr, $ow) = split ' ', $line;
1392 $pr = unescape
($pr);
1393 $ow = unescape
($ow);
1394 if ($pr eq $project) {
1395 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
1401 if (!defined $owner) {
1402 $owner = get_file_owner
("$projectroot/$project");
1405 my $refs = read_info_ref
();
1407 git_page_nav
('summary','', $head);
1409 print "<div class=\"title\"> </div>\n";
1410 print "<table cellspacing=\"0\">\n" .
1411 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
1412 "<tr><td>owner</td><td>$owner</td></tr>\n" .
1413 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
1416 open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_read_head
($project)
1417 or die_error
(undef, "Open git-rev-list failed.");
1418 my @revlist = map { chomp; $_ } <$fd>;
1420 git_header_div
('shortlog');
1421 git_shortlog_body
(\
@revlist, 0, 15, $refs,
1422 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "..."));
1424 my $taglist = git_read_refs
("refs/tags");
1425 if (defined @
$taglist) {
1426 git_header_div
('tags');
1427 git_tags_body
($taglist, 0, 15,
1428 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tags")}, "..."));
1431 my $headlist = git_read_refs
("refs/heads");
1432 if (defined @
$headlist) {
1433 git_header_div
('heads');
1434 git_heads_body
($headlist, $head, 0, 15,
1435 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=heads")}, "..."));
1442 my $head = git_read_head
($project);
1444 git_page_nav
('','', $head,undef,$head);
1445 my %tag = git_read_tag
($hash);
1446 git_header_div
('commit', esc_html
($tag{'name'}), $hash);
1447 print "<div class=\"title_text\">\n" .
1448 "<table cellspacing=\"0\">\n" .
1450 "<td>object</td>\n" .
1451 "<td>" . $cgi->a({-class => "list", -href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'object'}) . "</td>\n" .
1452 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'type'}) . "</td>\n" .
1454 if (defined($tag{'author'})) {
1455 my %ad = date_str
($tag{'epoch'}, $tag{'tz'});
1456 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
1457 print "<tr><td></td><td>" . $ad{'rfc2822'} . sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) . "</td></tr>\n";
1459 print "</table>\n\n" .
1461 print "<div class=\"page_body\">";
1462 my $comment = $tag{'comment'};
1463 foreach my $line (@
$comment) {
1464 print esc_html
($line) . "<br/>\n";
1473 die_error
(undef, "Permission denied.") if (!git_get_project_config_bool
('blame'));
1474 die_error
('404 Not Found', "File name not defined") if (!$file_name);
1475 $hash_base ||= git_read_head
($project);
1476 die_error
(undef, "Reading commit failed") unless ($hash_base);
1477 my %co = git_read_commit
($hash_base)
1478 or die_error
(undef, "Reading commit failed");
1479 if (!defined $hash) {
1480 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
1481 or die_error
(undef, "Error looking up file");
1483 $ftype = git_get_type
($hash);
1484 if ($ftype !~ "blob") {
1485 die_error
("400 Bad Request", "object is not a blob");
1487 open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base)
1488 or die_error
(undef, "Open git-blame failed.");
1491 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") .
1492 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;f=$file_name")}, "head");
1493 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1494 git_header_div
('commit', esc_html
($co{'title'}), $hash_base);
1495 git_print_page_path
($file_name, $ftype);
1496 my @rev_color = (qw(light dark));
1497 my $num_colors = scalar(@rev_color);
1498 my $current_color = 0;
1500 print "<div class=\"page_body\">\n";
1501 print "<table class=\"blame\">\n";
1502 print "<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n";
1504 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
1506 my $rev = substr($full_rev, 0, 8);
1510 if (!defined $last_rev) {
1511 $last_rev = $full_rev;
1512 } elsif ($last_rev ne $full_rev) {
1513 $last_rev = $full_rev;
1514 $current_color = ++$current_color % $num_colors;
1516 print "<tr class=\"$rev_color[$current_color]\">\n";
1517 print "<td class=\"sha1\">" .
1518 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$full_rev;f=$file_name")}, esc_html
($rev)) . "</td>\n";
1519 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" . esc_html
($lineno) . "</a></td>\n";
1520 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
1525 close $fd or print "Reading blob failed\n";
1531 die_error
('403 Permission denied', "Permission denied.") if (!git_get_project_config_bool
('blame'));
1532 die_error
('404 Not Found', "What file will it be, master?") if (!$file_name);
1533 $hash_base ||= git_read_head
($project);
1534 die_error
(undef, "Reading commit failed.") unless ($hash_base);
1535 my %co = git_read_commit
($hash_base)
1536 or die_error
(undef, "Reading commit failed.");
1537 if (!defined $hash) {
1538 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
1539 or die_error
(undef, "Error lookup file.");
1541 open ($fd, "-|", $GIT, "annotate", '-l', '-t', '-r', $file_name, $hash_base)
1542 or die_error
(undef, "Open git-annotate failed.");
1545 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") .
1546 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;f=$file_name")}, "head");
1547 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1548 git_header_div
('commit', esc_html
($co{'title'}), $hash_base);
1549 git_print_page_path
($file_name, 'blob');
1550 print "<div class=\"page_body\">\n";
1552 <table class="blame">
1561 my @line_class = (qw(light dark));
1562 my $line_class_len = scalar (@line_class);
1563 my $line_class_num = $#line_class;
1564 while (my $line = <$fd>) {
1576 $line_class_num = ($line_class_num + 1) % $line_class_len;
1578 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) \+\d\d\d\d\t(\d+)\)(.*)$/) {
1585 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
1588 $short_rev = substr ($long_rev, 0, 8);
1589 $age = time () - $time;
1590 $age_str = age_string
($age);
1591 $age_str =~ s/ / /g;
1592 $age_class = age_class
($age);
1593 $author = esc_html
($author);
1594 $author =~ s/ / /g;
1596 while ((my $pos = index($data, "\t")) != -1) {
1597 if (my $count = (8 - ($pos % 8))) {
1598 my $spaces = ' ' x
$count;
1599 $data =~ s/\t/$spaces/;
1602 $data = esc_html
($data);
1605 <tr class="$line_class[$line_class_num]">
1606 <td class="sha1"><a href="$my_uri?${\esc_param ("p=$project;a=commit;h=$long_rev")}" class="text">$short_rev..</a></td>
1607 <td class="$age_class">$age_str</td>
1609 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
1610 <td class="pre">$data</td>
1613 } # while (my $line = <$fd>)
1614 print "</table>\n\n";
1615 close $fd or print "Reading blob failed.\n";
1621 my $head = git_read_head
($project);
1623 git_page_nav
('','', $head,undef,$head);
1624 git_header_div
('summary', $project);
1626 my $taglist = git_read_refs
("refs/tags");
1627 if (defined @
$taglist) {
1628 git_tags_body
($taglist);
1634 my $head = git_read_head
($project);
1636 git_page_nav
('','', $head,undef,$head);
1637 git_header_div
('summary', $project);
1639 my $taglist = git_read_refs
("refs/heads");
1641 if (defined @
$taglist) {
1642 git_heads_body
($taglist, $head);
1647 sub git_blob_plain
{
1648 if (!defined $hash) {
1649 if (defined $file_name) {
1650 my $base = $hash_base || git_read_head
($project);
1651 $hash = git_get_hash_by_path
($base, $file_name, "blob")
1652 or die_error
(undef, "Error lookup file.");
1654 die_error
(undef, "No file name defined.");
1658 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
1659 or die_error
("Couldn't cat $file_name, $hash");
1661 $type ||= git_blob_plain_mimetype
($fd, $file_name);
1663 # save as filename, even when no $file_name is given
1664 my $save_as = "$hash";
1665 if (defined $file_name) {
1666 $save_as = $file_name;
1667 } elsif ($type =~ m/^text\//) {
1671 print $cgi->header(-type
=> "$type", '-content-disposition' => "inline; filename=\"$save_as\"");
1673 binmode STDOUT
, ':raw';
1675 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
1681 if (!defined $hash) {
1682 if (defined $file_name) {
1683 my $base = $hash_base || git_read_head
($project);
1684 $hash = git_get_hash_by_path
($base, $file_name, "blob")
1685 or die_error
(undef, "Error lookup file.");
1687 die_error
(undef, "No file name defined.");
1690 my $have_blame = git_get_project_config_bool
('blame');
1691 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
1692 or die_error
(undef, "Couldn't cat $file_name, $hash.");
1693 my $mimetype = git_blob_plain_mimetype
($fd, $file_name);
1694 if ($mimetype !~ m/^text\//) {
1696 return git_blob_plain
($mimetype);
1699 my $formats_nav = '';
1700 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
1701 if (defined $file_name) {
1703 $formats_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;h=$hash;hb=$hash_base;f=$file_name")}, "blame") . " | ";
1706 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$hash;f=$file_name")}, "plain") .
1707 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;hb=HEAD;f=$file_name")}, "head");
1709 $formats_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$hash")}, "plain");
1711 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1712 git_header_div
('commit', esc_html
($co{'title'}), $hash_base);
1714 print "<div class=\"page_nav\">\n" .
1715 "<br/><br/></div>\n" .
1716 "<div class=\"title\">$hash</div>\n";
1718 git_print_page_path
($file_name, "blob");
1719 print "<div class=\"page_body\">\n";
1721 while (my $line = <$fd>) {
1724 while ((my $pos = index($line, "\t")) != -1) {
1725 if (my $count = (8 - ($pos % 8))) {
1726 my $spaces = ' ' x
$count;
1727 $line =~ s/\t/$spaces/;
1730 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", $nr, $nr, $nr, esc_html
($line);
1732 close $fd or print "Reading blob failed.\n";
1738 if (!defined $hash) {
1739 $hash = git_read_head
($project);
1740 if (defined $file_name) {
1741 my $base = $hash_base || $hash;
1742 $hash = git_get_hash_by_path
($base, $file_name, "tree");
1744 if (!defined $hash_base) {
1749 open my $fd, "-|", $GIT, "ls-tree", '-z', $hash
1750 or die_error
(undef, "Open git-ls-tree failed.");
1751 my @entries = map { chomp; $_ } <$fd>;
1752 close $fd or die_error
(undef, "Reading tree failed.");
1755 my $refs = read_info_ref
();
1756 my $ref = git_get_referencing
($refs, $hash_base);
1760 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
1761 $base_key = ";hb=$hash_base";
1762 git_page_nav
('tree','', $hash_base);
1763 git_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
1765 print "<div class=\"page_nav\">\n";
1766 print "<br/><br/></div>\n";
1767 print "<div class=\"title\">$hash</div>\n";
1769 if (defined $file_name) {
1770 $base = esc_html
("$file_name/");
1772 git_print_page_path
($file_name, 'tree');
1773 print "<div class=\"page_body\">\n";
1774 print "<table cellspacing=\"0\">\n";
1776 foreach my $line (@entries) {
1777 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1778 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1782 my $t_name = validate_input
($4);
1784 print "<tr class=\"dark\">\n";
1786 print "<tr class=\"light\">\n";
1789 print "<td class=\"mode\">" . mode_str
($t_mode) . "</td>\n";
1790 if ($t_type eq "blob") {
1791 print "<td class=\"list\">" .
1792 $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)) .
1794 "<td class=\"link\">" .
1795 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name")}, "blob") .
1796 # " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$t_hash$base_key;f=$base$t_name")}, "blame") .
1797 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;h=$t_hash;hb=$hash_base;f=$base$t_name")}, "history") .
1798 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$t_hash;f=$base$t_name")}, "raw") .
1800 } elsif ($t_type eq "tree") {
1801 print "<td class=\"list\">" .
1802 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, esc_html
($t_name)) .
1804 "<td class=\"link\">" .
1805 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, "tree") .
1806 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;hb=$hash_base;f=$base$t_name")}, "history") .
1811 print "</table>\n" .
1817 my $head = git_read_head
($project);
1818 if (!defined $hash) {
1821 if (!defined $page) {
1824 my $refs = read_info_ref
();
1826 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
1827 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
1828 or die_error
(undef, "Open git-rev-list failed.");
1829 my @revlist = map { chomp; $_ } <$fd>;
1832 my $paging_nav = git_get_paging_nav
('log', $hash, $head, $page, $#revlist);
1835 git_page_nav
('log','', $hash,undef,undef, $paging_nav);
1838 my %co = git_read_commit
($hash);
1840 git_header_div
('summary', $project);
1841 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
1843 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
1844 my $commit = $revlist[$i];
1845 my $ref = git_get_referencing
($refs, $commit);
1846 my %co = git_read_commit
($commit);
1848 my %ad = date_str
($co{'author_epoch'});
1849 git_header_div
('commit',
1850 "<span class=\"age\">$co{'age_string'}</span>" .
1851 esc_html
($co{'title'}) . $ref,
1853 print "<div class=\"title_text\">\n" .
1854 "<div class=\"log_link\">\n" .
1855 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
1856 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1859 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
1861 "<div class=\"log_body\">\n";
1862 my $comment = $co{'comment'};
1864 foreach my $line (@
$comment) {
1865 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1876 print format_log_line_html
($line) . "<br/>\n";
1887 my %co = git_read_commit
($hash);
1889 die_error
(undef, "Unknown commit object.");
1891 my %ad = date_str
($co{'author_epoch'}, $co{'author_tz'});
1892 my %cd = date_str
($co{'committer_epoch'}, $co{'committer_tz'});
1894 my $parent = $co{'parent'};
1895 if (!defined $parent) {
1898 open my $fd, "-|", $GIT, "diff-tree", '-r', '-M', $parent, $hash
1899 or die_error
(undef, "Open git-diff-tree failed.");
1900 my @difftree = map { chomp; $_ } <$fd>;
1901 close $fd or die_error
(undef, "Reading git-diff-tree failed.");
1903 # non-textual hash id's can be cached
1905 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
1908 my $refs = read_info_ref
();
1909 my $ref = git_get_referencing
($refs, $co{'id'});
1910 my $formats_nav = '';
1911 if (defined $file_name && defined $co{'parent'}) {
1912 my $parent = $co{'parent'};
1913 $formats_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;hb=$parent;f=$file_name")}, "blame");
1915 git_header_html
(undef, $expires);
1916 git_page_nav
('commit', defined $co{'parent'} ?
'' : 'commitdiff',
1917 $hash, $co{'tree'}, $hash,
1920 if (defined $co{'parent'}) {
1921 git_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
1923 git_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
1925 print "<div class=\"title_text\">\n" .
1926 "<table cellspacing=\"0\">\n";
1927 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
1929 "<td></td><td> $ad{'rfc2822'}";
1930 if ($ad{'hour_local'} < 6) {
1931 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1933 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1937 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
1938 print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
1939 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
1942 "<td class=\"sha1\">" .
1943 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash"), class => "list"}, $co{'tree'}) .
1945 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
1948 my $parents = $co{'parents'};
1949 foreach my $par (@
$parents) {
1952 "<td class=\"sha1\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$par"), class => "list"}, $par) . "</td>" .
1953 "<td class=\"link\">" .
1954 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$par")}, "commit") .
1955 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash;hp=$par")}, "commitdiff") .
1961 print "<div class=\"page_body\">\n";
1962 my $comment = $co{'comment'};
1965 foreach my $line (@
$comment) {
1966 # print only one empty line
1968 if ($empty || $signed) {
1975 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1977 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1980 print format_log_line_html
($line) . "<br/>\n";
1984 print "<div class=\"list_head\">\n";
1985 if ($#difftree > 10) {
1986 print(($#difftree + 1) . " files changed:\n");
1989 print "<table class=\"diff_tree\">\n";
1991 foreach my $line (@difftree) {
1992 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1993 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1994 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
2002 my $similarity = $6;
2003 my $file = validate_input
(unquote
($7));
2005 print "<tr class=\"dark\">\n";
2007 print "<tr class=\"light\">\n";
2010 if ($status eq "A") {
2012 if (S_ISREG
(oct $to_mode)) {
2013 $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
2016 $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" .
2017 "<td><span class=\"file_status new\">[new " . file_type
($to_mode) . "$mode_chng]</span></td>\n" .
2018 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob") . "</td>\n";
2019 } elsif ($status eq "D") {
2021 $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" .
2022 "<td><span class=\"file_status deleted\">[deleted " . file_type
($from_mode). "]</span></td>\n" .
2023 "<td class=\"link\">" .
2024 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, "blob") .
2025 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;hb=$hash;f=$file")}, "history") .
2027 } elsif ($status eq "M" || $status eq "T") {
2028 my $mode_chnge = "";
2029 if ($from_mode != $to_mode) {
2030 $mode_chnge = " <span class=\"file_status mode_chnge\">[changed";
2031 if (((oct $from_mode) & S_IFMT
) != ((oct $to_mode) & S_IFMT
)) {
2032 $mode_chnge .= " from " . file_type
($from_mode) . " to " . file_type
($to_mode);
2034 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
2035 if (S_ISREG
($from_mode) && S_ISREG
($to_mode)) {
2036 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
2037 } elsif (S_ISREG
($to_mode)) {
2038 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
2041 $mode_chnge .= "]</span>\n";
2044 if ($to_id ne $from_id) {
2045 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));
2047 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file"), -class => "list"}, esc_html
($file));
2050 "<td>$mode_chnge</td>\n" .
2051 "<td class=\"link\">";
2052 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob");
2053 if ($to_id ne $from_id) {
2054 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file")}, "diff");
2056 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;hb=$hash;f=$file")}, "history") . "\n";
2058 } elsif ($status eq "R") {
2059 my ($from_file, $to_file) = split "\t", $file;
2061 if ($from_mode != $to_mode) {
2062 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
2065 $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" .
2066 "<td><span class=\"file_status moved\">[moved from " .
2067 $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)) .
2068 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
2069 "<td class=\"link\">" .
2070 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file")}, "blob");
2071 if ($to_id ne $from_id) {
2072 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file")}, "diff");
2083 mkdir($git_temp, 0700);
2085 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
2087 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff_plain;h=$hash;hp=$hash_parent")}, "plain");
2088 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2089 git_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2091 print "<div class=\"page_nav\">\n" .
2092 "<br/><br/></div>\n" .
2093 "<div class=\"title\">$hash vs $hash_parent</div>\n";
2095 git_print_page_path
($file_name, "blob");
2096 print "<div class=\"page_body\">\n" .
2097 "<div class=\"diff_info\">blob:" .
2098 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name")}, $hash_parent) .
2100 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, $hash) .
2102 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
2107 sub git_blobdiff_plain
{
2108 mkdir($git_temp, 0700);
2109 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8');
2110 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
2113 sub git_commitdiff
{
2114 mkdir($git_temp, 0700);
2115 my %co = git_read_commit
($hash);
2117 die_error
(undef, "Unknown commit object.");
2119 if (!defined $hash_parent) {
2120 $hash_parent = $co{'parent'};
2122 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2123 or die_error
(undef, "Open git-diff-tree failed.");
2124 my @difftree = map { chomp; $_ } <$fd>;
2125 close $fd or die_error
(undef, "Reading diff-tree failed.");
2127 # non-textual hash id's can be cached
2129 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2132 my $refs = read_info_ref
();
2133 my $ref = git_get_referencing
($refs, $co{'id'});
2135 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent")}, "plain");
2136 git_header_html
(undef, $expires);
2137 git_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
2138 git_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
2139 print "<div class=\"page_body\">\n";
2140 my $comment = $co{'comment'};
2143 my @log = @
$comment;
2144 # remove first and empty lines after that
2146 while (defined $log[0] && $log[0] eq "") {
2149 foreach my $line (@log) {
2150 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2161 print format_log_line_html
($line) . "<br/>\n";
2164 foreach my $line (@difftree) {
2165 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2166 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2167 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2173 my $file = validate_input
(unquote
($6));
2174 if ($status eq "A") {
2175 print "<div class=\"diff_info\">" . file_type
($to_mode) . ":" .
2176 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id) . "(new)" .
2178 git_diff_print
(undef, "/dev/null", $to_id, "b/$file");
2179 } elsif ($status eq "D") {
2180 print "<div class=\"diff_info\">" . file_type
($from_mode) . ":" .
2181 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) . "(deleted)" .
2183 git_diff_print
($from_id, "a/$file", undef, "/dev/null");
2184 } elsif ($status eq "M") {
2185 if ($from_id ne $to_id) {
2186 print "<div class=\"diff_info\">" .
2187 file_type
($from_mode) . ":" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) .
2189 file_type
($to_mode) . ":" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id);
2191 git_diff_print
($from_id, "a/$file", $to_id, "b/$file");
2200 sub git_commitdiff_plain
{
2201 mkdir($git_temp, 0700);
2202 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2203 or die_error
(undef, "Open git-diff-tree failed.");
2204 my @difftree = map { chomp; $_ } <$fd>;
2205 close $fd or die_error
(undef, "Reading diff-tree failed.");
2207 # try to figure out the next tag after this commit
2209 my $refs = read_info_ref
("tags");
2210 open $fd, "-|", $GIT, "rev-list", "HEAD";
2211 my @commits = map { chomp; $_ } <$fd>;
2213 foreach my $commit (@commits) {
2214 if (defined $refs->{$commit}) {
2215 $tagname = $refs->{$commit}
2217 if ($commit eq $hash) {
2222 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8', '-content-disposition' => "inline; filename=\"git-$hash.patch\"");
2223 my %co = git_read_commit
($hash);
2224 my %ad = date_str
($co{'author_epoch'}, $co{'author_tz'});
2225 my $comment = $co{'comment'};
2226 print "From: $co{'author'}\n" .
2227 "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
2228 "Subject: $co{'title'}\n";
2229 if (defined $tagname) {
2230 print "X-Git-Tag: $tagname\n";
2232 print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
2235 foreach my $line (@
$comment) {;
2240 foreach my $line (@difftree) {
2241 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2246 if ($status eq "A") {
2247 git_diff_print
(undef, "/dev/null", $to_id, "b/$file", "plain");
2248 } elsif ($status eq "D") {
2249 git_diff_print
($from_id, "a/$file", undef, "/dev/null", "plain");
2250 } elsif ($status eq "M") {
2251 git_diff_print
($from_id, "a/$file", $to_id, "b/$file", "plain");
2257 if (!defined $hash_base) {
2258 $hash_base = git_read_head
($project);
2261 my %co = git_read_commit
($hash_base);
2263 die_error
(undef, "Unknown commit object.");
2265 my $refs = read_info_ref
();
2267 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base);
2268 git_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2269 if (!defined $hash && defined $file_name) {
2270 $hash = git_get_hash_by_path
($hash_base, $file_name);
2272 if (defined $hash) {
2273 $ftype = git_get_type
($hash);
2275 git_print_page_path
($file_name, $ftype);
2278 $GIT, "rev-list", "--full-history", $hash_base, "--", $file_name;
2279 print "<table cellspacing=\"0\">\n";
2281 while (my $line = <$fd>) {
2282 if ($line =~ m/^([0-9a-fA-F]{40})/){
2284 my %co = git_read_commit
($commit);
2288 my $ref = git_get_referencing
($refs, $commit);
2290 print "<tr class=\"dark\">\n";
2292 print "<tr class=\"light\">\n";
2295 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2296 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2297 "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list"}, "<b>" .
2298 esc_html
(chop_str
($co{'title'}, 50)) . "$ref</b>") . "</td>\n" .
2299 "<td class=\"link\">" .
2300 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
2301 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2302 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$ftype;hb=$commit;f=$file_name")}, $ftype);
2303 my $blob = git_get_hash_by_path
($hash_base, $file_name);
2304 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2305 if (defined $blob && defined $blob_parent && $blob ne $blob_parent) {
2307 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=$file_name")},
2320 if (!defined $searchtext) {
2321 die_error
("", "Text field empty.");
2323 if (!defined $hash) {
2324 $hash = git_read_head
($project);
2326 my %co = git_read_commit
($hash);
2328 die_error
(undef, "Unknown commit object.");
2330 # pickaxe may take all resources of your box and run for several minutes
2331 # with every query - so decide by yourself how public you make this feature :)
2332 my $commit_search = 1;
2333 my $author_search = 0;
2334 my $committer_search = 0;
2335 my $pickaxe_search = 0;
2336 if ($searchtext =~ s/^author\\://i) {
2338 } elsif ($searchtext =~ s/^committer\\://i) {
2339 $committer_search = 1;
2340 } elsif ($searchtext =~ s/^pickaxe\\://i) {
2342 $pickaxe_search = 1;
2345 git_page_nav
('','', $hash,$co{'tree'},$hash);
2346 git_header_div
('commit', esc_html
($co{'title'}), $hash);
2348 print "<table cellspacing=\"0\">\n";
2350 if ($commit_search) {
2352 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", $hash or next;
2353 while (my $commit_text = <$fd>) {
2354 if (!grep m/$searchtext/i, $commit_text) {
2357 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
2360 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
2363 my @commit_lines = split "\n", $commit_text;
2364 my %co = git_read_commit
(undef, \
@commit_lines);
2369 print "<tr class=\"dark\">\n";
2371 print "<tr class=\"light\">\n";
2374 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2375 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2377 $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/>");
2378 my $comment = $co{'comment'};
2379 foreach my $line (@
$comment) {
2380 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2381 my $lead = esc_html
($1) || "";
2382 $lead = chop_str
($lead, 30, 10);
2383 my $match = esc_html
($2) || "";
2384 my $trail = esc_html
($3) || "";
2385 $trail = chop_str
($trail, 30, 10);
2386 my $text = "$lead<span class=\"match\">$match</span>$trail";
2387 print chop_str
($text, 80, 5) . "<br/>\n";
2391 "<td class=\"link\">" .
2392 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2393 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2400 if ($pickaxe_search) {
2402 open my $fd, "-|", "$GIT rev-list $hash | $GIT diff-tree -r --stdin -S\'$searchtext\'";
2405 while (my $line = <$fd>) {
2406 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2409 $set{'from_id'} = $3;
2411 $set{'id'} = $set{'to_id'};
2412 if ($set{'id'} =~ m/0{40}/) {
2413 $set{'id'} = $set{'from_id'};
2415 if ($set{'id'} =~ m/0{40}/) {
2419 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
2422 print "<tr class=\"dark\">\n";
2424 print "<tr class=\"light\">\n";
2427 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2428 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2430 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" .
2431 esc_html
(chop_str
($co{'title'}, 50)) . "</b><br/>");
2432 while (my $setref = shift @files) {
2434 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}"), class => "list"},
2435 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
2439 "<td class=\"link\">" .
2440 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2441 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2445 %co = git_read_commit
($1);
2455 my $head = git_read_head
($project);
2456 if (!defined $hash) {
2459 if (!defined $page) {
2462 my $refs = read_info_ref
();
2464 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2465 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2466 or die_error
(undef, "Open git-rev-list failed.");
2467 my @revlist = map { chomp; $_ } <$fd>;
2470 my $paging_nav = git_get_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
2472 if ($#revlist >= (100 * ($page+1)-1)) {
2474 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)),
2475 -title
=> "Alt-n"}, "next");
2480 git_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
2481 git_header_div
('summary', $project);
2483 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
2488 ## ......................................................................
2489 ## feeds (RSS, OPML)
2492 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
2493 open my $fd, "-|", $GIT, "rev-list", "--max-count=150", git_read_head
($project)
2494 or die_error
(undef, "Open git-rev-list failed.");
2495 my @revlist = map { chomp; $_ } <$fd>;
2496 close $fd or die_error
(undef, "Reading rev-list failed.");
2497 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
2498 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
2499 "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
2500 print "<channel>\n";
2501 print "<title>$project</title>\n".
2502 "<link>" . esc_html
("$my_url?p=$project;a=summary") . "</link>\n".
2503 "<description>$project log</description>\n".
2504 "<language>en</language>\n";
2506 for (my $i = 0; $i <= $#revlist; $i++) {
2507 my $commit = $revlist[$i];
2508 my %co = git_read_commit
($commit);
2509 # we read 150, we always show 30 and the ones more recent than 48 hours
2510 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
2513 my %cd = date_str
($co{'committer_epoch'});
2514 open $fd, "-|", $GIT, "diff-tree", '-r', $co{'parent'}, $co{'id'} or next;
2515 my @difftree = map { chomp; $_ } <$fd>;
2519 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
2521 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
2522 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
2523 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
2524 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
2525 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
2526 "<content:encoded>" .
2528 my $comment = $co{'comment'};
2529 foreach my $line (@
$comment) {
2530 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
2531 print "$line<br/>\n";
2534 foreach my $line (@difftree) {
2535 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
2538 my $file = validate_input
(unquote
($7));
2539 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
2540 print "$file<br/>\n";
2543 "</content:encoded>\n" .
2546 print "</channel></rss>";
2550 my @list = git_read_projects
();
2552 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
2553 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
2554 "<opml version=\"1.0\">\n".
2556 " <title>$site_name Git OPML Export</title>\n".
2559 "<outline text=\"git RSS feeds\">\n";
2561 foreach my $pr (@list) {
2563 my $head = git_read_head
($proj{'path'});
2564 if (!defined $head) {
2567 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
2568 my %co = git_read_commit
($head);
2573 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
2574 my $rss = "$my_url?p=$proj{'path'};a=rss";
2575 my $html = "$my_url?p=$proj{'path'};a=summary";
2576 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
2578 print "</outline>\n".