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);
17 binmode STDOUT
, ':utf8';
21 our $my_url = $cgi->url();
22 our $my_uri = $cgi->url(-absolute
=> 1);
25 # core git executable to use
26 # this can just be "git" if your webserver has a sensible PATH
27 our $GIT = "/usr/bin/git";
29 # absolute fs-path which will be prepended to the project path
30 #our $projectroot = "/pub/scm";
31 our $projectroot = "/home/kay/public_html/pub/scm";
33 # version of the core git binary
34 our $git_version = qx($GIT --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
36 # location for temporary files needed for diffs
37 our $git_temp = "/tmp/gitweb";
39 mkdir($git_temp, 0700) || die_error
("Couldn't mkdir $git_temp");
42 # target of the home link on top of all pages
43 our $home_link = $my_uri;
45 # name of your site or organization to appear in page titles
46 # replace this with something more descriptive for clearer bookmarks
47 our $site_name = $ENV{'SERVER_NAME'} || "Untitled";
49 # html text to include at home page
50 our $home_text = "indextext.html";
52 # URI of default stylesheet
53 our $stylesheet = "gitweb.css";
55 # source of projects list
56 #our $projects_list = $projectroot;
57 our $projects_list = "index/index.aux";
59 # default blob_plain mimetype and default charset for text/plain blob
60 our $default_blob_plain_mimetype = 'text/plain';
61 our $default_text_plain_charset = undef;
63 # file to use for guessing MIME types before trying /etc/mime.types
64 # (relative to the current git repository)
65 our $mimetypes_file = undef;
67 # input validation and dispatch
68 our $action = $cgi->param('a');
69 if (defined $action) {
70 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
72 die_error
(undef, "Invalid action parameter.");
74 if ($action eq "git-logo.png") {
77 } elsif ($action eq "opml") {
83 our $order = $cgi->param('o');
85 if ($order =~ m/[^0-9a-zA-Z_]/) {
87 die_error
(undef, "Invalid order parameter.");
91 our $project = ($cgi->param('p') || $ENV{'PATH_INFO'});
92 if (defined $project) {
93 $project =~ s
|^/||; $project =~ s|/$||;
94 $project = validate_input
($project);
95 if (!defined($project)) {
96 die_error
(undef, "Invalid project parameter.");
98 if (!(-d
"$projectroot/$project")) {
100 die_error
(undef, "No such directory.");
102 if (!(-e
"$projectroot/$project/HEAD")) {
104 die_error
(undef, "No such project.");
106 $rss_link = "<link rel=\"alternate\" title=\"" . esc_param
($project) . " log\" href=\"" .
107 "$my_uri?" . esc_param
("p=$project;a=rss") . "\" type=\"application/rss+xml\"/>";
108 $ENV{'GIT_DIR'} = "$projectroot/$project";
114 our $file_name = $cgi->param('f');
115 if (defined $file_name) {
116 $file_name = validate_input
($file_name);
117 if (!defined($file_name)) {
118 die_error
(undef, "Invalid file parameter.");
122 our $hash = $cgi->param('h');
124 $hash = validate_input
($hash);
125 if (!defined($hash)) {
126 die_error
(undef, "Invalid hash parameter.");
130 our $hash_parent = $cgi->param('hp');
131 if (defined $hash_parent) {
132 $hash_parent = validate_input
($hash_parent);
133 if (!defined($hash_parent)) {
134 die_error
(undef, "Invalid hash parent parameter.");
138 our $hash_base = $cgi->param('hb');
139 if (defined $hash_base) {
140 $hash_base = validate_input
($hash_base);
141 if (!defined($hash_base)) {
142 die_error
(undef, "Invalid hash base parameter.");
146 our $page = $cgi->param('pg');
148 if ($page =~ m/[^0-9]$/) {
150 die_error
(undef, "Invalid page parameter.");
154 our $searchtext = $cgi->param('s');
155 if (defined $searchtext) {
156 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
158 die_error
(undef, "Invalid search parameter.");
160 $searchtext = quotemeta $searchtext;
166 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
169 if ($input =~ m/(^|\/)(|\
.|\
.\
.)($|\
/)/) {
172 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\
-\
+\#\
~\
%]/) {
178 if (!defined $action || $action eq "summary") {
181 } elsif ($action eq "heads") {
184 } elsif ($action eq "tags") {
187 } elsif ($action eq "blob") {
190 } elsif ($action eq "blob_plain") {
193 } elsif ($action eq "tree") {
196 } elsif ($action eq "rss") {
199 } elsif ($action eq "commit") {
202 } elsif ($action eq "log") {
205 } elsif ($action eq "blobdiff") {
208 } elsif ($action eq "blobdiff_plain") {
209 git_blobdiff_plain
();
211 } elsif ($action eq "commitdiff") {
214 } elsif ($action eq "commitdiff_plain") {
215 git_commitdiff_plain
();
217 } elsif ($action eq "history") {
220 } elsif ($action eq "search") {
223 } elsif ($action eq "shortlog") {
226 } elsif ($action eq "tag") {
229 } elsif ($action eq "blame") {
234 die_error
(undef, "Unknown action.");
238 # quote unsafe chars, but keep the slash, even when it's not
239 # correct, but quoted slashes look too horrible in bookmarks
242 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
248 # replace invalid utf8 character with SUBSTITUTION sequence
251 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
252 $str = escapeHTML
($str);
253 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
257 # git may return quoted and escaped filenames
260 if ($str =~ m/^"(.*)"$/) {
262 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
267 # CSS class for given age value (in seconds)
271 if ($age < 60*60*2) {
273 } elsif ($age < 60*60*24*2) {
280 sub git_header_html
{
281 my $status = shift || "200 OK";
284 my $title = "$site_name git";
285 if (defined $project) {
286 $title .= " - $project";
287 if (defined $action) {
288 $title .= "/$action";
289 if (defined $file_name) {
290 $title .= " - $file_name";
291 if ($action eq "tree" && $file_name !~ m
|/$|) {
298 # require explicit support from the UA if we are to send the page as
299 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
300 # we have to do this because MSIE sometimes globs '*/*', pretending to
301 # support xhtml+xml but choking when it gets what it asked for.
302 if ($cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ && $cgi->Accept('application/xhtml
+xml
') != 0) {
303 $content_type = 'application
/xhtml
+xml
';
305 $content_type = 'text
/html
';
307 print $cgi->header(-type=>$content_type, -charset => 'utf
-8', -status=> $status, -expires => $expires);
309 <?xml version="1.0" encoding="utf-8"?>
310 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
311 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
312 <!-- git web interface v$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
313 <!-- git core binaries version $git_version -->
315 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
316 <meta name="robots" content="index, nofollow"/>
317 <title>$title</title>
318 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
323 print "<div class=\"page_header\">\n" .
324 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
325 "<img src=\"$my_uri?" . esc_param
("a=git-logo.png") . "\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
327 print $cgi->a({-href
=> esc_param
($home_link)}, "projects") . " / ";
328 if (defined $project) {
329 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, esc_html
($project));
330 if (defined $action) {
334 if (!defined $searchtext) {
338 if (defined $hash_base) {
339 $search_hash = $hash_base;
340 } elsif (defined $hash) {
341 $search_hash = $hash;
343 $search_hash = "HEAD";
345 $cgi->param("a", "search");
346 $cgi->param("h", $search_hash);
347 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
348 "<div class=\"search\">\n" .
349 $cgi->hidden(-name
=> "p") . "\n" .
350 $cgi->hidden(-name
=> "a") . "\n" .
351 $cgi->hidden(-name
=> "h") . "\n" .
352 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
354 $cgi->end_form() . "\n";
359 sub git_footer_html
{
360 print "<div class=\"page_footer\">\n";
361 if (defined $project) {
362 my $descr = git_read_description
($project);
363 if (defined $descr) {
364 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
366 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=rss"), -class => "rss_logo"}, "RSS") . "\n";
368 print $cgi->a({-href
=> "$my_uri?" . esc_param
("a=opml"), -class => "rss_logo"}, "OPML") . "\n";
376 my $status = shift || "403 Forbidden";
377 my $error = shift || "Malformed query, file missing or permission denied";
379 git_header_html
($status);
380 print "<div class=\"page_body\">\n" .
382 "$status - $error\n" .
390 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
391 $extra = '' if !defined $extra; # pager or formats
393 my @navs = qw(summary shortlog log commit commitdiff tree);
395 @navs = grep { $_ ne $suppress } @navs;
398 my %arg = map { $_, ''} @navs;
400 for (qw(commit commitdiff)) {
401 $arg{$_} = ";h=$head";
403 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
404 for (qw(shortlog log)) {
405 $arg{$_} = ";h=$head";
409 $arg{tree
} .= ";h=$treehead" if defined $treehead;
410 $arg{tree
} .= ";hb=$treebase" if defined $treebase;
412 print "<div class=\"page_nav\">\n" .
416 : $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$_$arg{$_}")}, "$_")
419 print "<br/>\n$extra<br/>\n" .
424 my ($action, $title, $hash, $hash_base) = @_;
427 $rest .= ";h=$hash" if $hash;
428 $rest .= ";hb=$hash_base" if $hash_base;
430 print "<div class=\"header\">\n" .
431 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$action$rest"),
432 -class => "title"}, $title ?
$title : $action) . "\n" .
436 sub git_get_paging_nav
{
437 my ($action, $hash, $head, $page, $nrevs) = @_;
441 if ($hash ne $head || $page) {
442 $paging_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$action")}, "HEAD");
444 $paging_nav .= "HEAD";
448 $paging_nav .= " ⋅ " .
449 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$action;h=$hash;pg=" . ($page-1)),
450 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
452 $paging_nav .= " ⋅ prev";
455 if ($nrevs >= (100 * ($page+1)-1)) {
456 $paging_nav .= " ⋅ " .
457 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$action;h=$hash;pg=" . ($page+1)),
458 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
460 $paging_nav .= " ⋅ next";
469 open my $fd, "-|", $GIT, "cat-file", '-t', $hash or return;
478 my $oENV = $ENV{'GIT_DIR'};
480 $ENV{'GIT_DIR'} = "$projectroot/$project";
481 if (open my $fd, "-|", $GIT, "rev-parse", "--verify", "HEAD") {
484 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
489 $ENV{'GIT_DIR'} = $oENV;
497 open my $fd, "$projectroot/$path" or return undef;
501 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
506 sub git_read_description
{
509 open my $fd, "$projectroot/$path/description" or return undef;
521 open my $fd, "-|", $GIT, "cat-file", "tag", $tag_id or return;
522 $tag{'id'} = $tag_id;
523 while (my $line = <$fd>) {
525 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
527 } elsif ($line =~ m/^type (.+)$/) {
529 } elsif ($line =~ m/^tag (.+)$/) {
531 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
535 } elsif ($line =~ m/--BEGIN/) {
536 push @comment, $line;
538 } elsif ($line eq "") {
542 push @comment, <$fd>;
543 $tag{'comment'} = \
@comment;
545 if (!defined $tag{'name'}) {
555 if ($age > 60*60*24*365*2) {
556 $age_str = (int $age/60/60/24/365);
557 $age_str .= " years ago";
558 } elsif ($age > 60*60*24*(365/12)*2) {
559 $age_str = int $age/60/60/24/(365/12);
560 $age_str .= " months ago";
561 } elsif ($age > 60*60*24*7*2) {
562 $age_str = int $age/60/60/24/7;
563 $age_str .= " weeks ago";
564 } elsif ($age > 60*60*24*2) {
565 $age_str = int $age/60/60/24;
566 $age_str .= " days ago";
567 } elsif ($age > 60*60*2) {
568 $age_str = int $age/60/60;
569 $age_str .= " hours ago";
570 } elsif ($age > 60*2) {
571 $age_str = int $age/60;
572 $age_str .= " min ago";
575 $age_str .= " sec ago";
577 $age_str .= " right now";
582 sub git_read_commit
{
583 my $commit_id = shift;
584 my $commit_text = shift;
589 if (defined $commit_text) {
590 @commit_lines = @
$commit_text;
593 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", "--max-count=1", $commit_id or return;
594 @commit_lines = split '\n', <$fd>;
599 my $header = shift @commit_lines;
600 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
603 ($co{'id'}, my @parents) = split ' ', $header;
604 $co{'parents'} = \
@parents;
605 $co{'parent'} = $parents[0];
606 while (my $line = shift @commit_lines) {
607 last if $line eq "\n";
608 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
610 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
612 $co{'author_epoch'} = $2;
613 $co{'author_tz'} = $3;
614 if ($co{'author'} =~ m/^([^<]+) </) {
615 $co{'author_name'} = $1;
617 $co{'author_name'} = $co{'author'};
619 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
620 $co{'committer'} = $1;
621 $co{'committer_epoch'} = $2;
622 $co{'committer_tz'} = $3;
623 $co{'committer_name'} = $co{'committer'};
624 $co{'committer_name'} =~ s/ <.*//;
627 if (!defined $co{'tree'}) {
631 foreach my $title (@commit_lines) {
634 $co{'title'} = chop_str
($title, 80, 5);
635 # remove leading stuff of merges to make the interesting part visible
636 if (length($title) > 50) {
637 $title =~ s/^Automatic //;
638 $title =~ s/^merge (of|with) /Merge ... /i;
639 if (length($title) > 50) {
640 $title =~ s/(http|rsync):\/\///;
642 if (length($title) > 50) {
643 $title =~ s/(master|www|rsync)\.//;
645 if (length($title) > 50) {
646 $title =~ s/kernel.org:?//;
648 if (length($title) > 50) {
649 $title =~ s/\/pub\/scm//;
652 $co{'title_short'} = chop_str
($title, 50, 5);
656 # remove added spaces
657 foreach my $line (@commit_lines) {
660 $co{'comment'} = \
@commit_lines;
662 my $age = time - $co{'committer_epoch'};
664 $co{'age_string'} = age_string
($age);
665 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
666 if ($age > 60*60*24*7*2) {
667 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
668 $co{'age_string_age'} = $co{'age_string'};
670 $co{'age_string_date'} = $co{'age_string'};
671 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
678 my $from_name = shift;
681 my $format = shift || "html";
683 my $from_tmp = "/dev/null";
684 my $to_tmp = "/dev/null";
687 # create tmp from-file
689 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
690 open my $fd2, "> $from_tmp";
691 open my $fd, "-|", $GIT, "cat-file", "blob", $from;
700 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
701 open my $fd2, "> $to_tmp";
702 open my $fd, "-|", $GIT, "cat-file", "blob", $to;
709 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
710 if ($format eq "plain") {
715 while (my $line = <$fd>) {
717 my $char = substr($line, 0, 1);
720 $diff_class = " add";
721 } elsif ($char eq "-") {
722 $diff_class = " rem";
723 } elsif ($char eq "@") {
724 $diff_class = " chunk_header";
725 } elsif ($char eq "\\") {
729 while ((my $pos = index($line, "\t")) != -1) {
730 if (my $count = (8 - (($pos-1) % 8))) {
731 my $spaces = ' ' x
$count;
732 $line =~ s/\t/$spaces/;
735 print "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
749 my $mode = oct shift;
751 if (S_ISDIR
($mode & S_IFMT
)) {
753 } elsif (S_ISLNK
($mode)) {
755 } elsif (S_ISREG
($mode)) {
756 # git cares only about the executable bit
757 if ($mode & S_IXUSR
) {
770 my $add_len = shift || 10;
772 # allow only $len chars, but don't cut a word if it would fit in $add_len
773 # if it doesn't fit, cut it if it's still longer than the dots we would add
774 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
777 if (length($tail) > 4) {
779 $body =~ s/&[^;]$//; # remove chopped character entities
785 my $mode = oct shift;
787 if (S_ISDIR
($mode & S_IFMT
)) {
789 } elsif (S_ISLNK
($mode)) {
791 } elsif (S_ISREG
($mode)) {
798 sub format_log_line_html
{
801 $line = esc_html
($line);
802 $line =~ s/ / /g;
803 if ($line =~ m/([0-9a-fA-F]{40})/) {
805 if (git_get_type
($hash_text) eq "commit") {
806 my $link = $cgi->a({-class => "text", -href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_text")}, $hash_text);
807 $line =~ s/$hash_text/$link/;
815 my $tz = shift || "-0000";
818 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
819 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
820 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
821 $date{'hour'} = $hour;
822 $date{'minute'} = $min;
823 $date{'mday'} = $mday;
824 $date{'day'} = $days[$wday];
825 $date{'month'} = $months[$mon];
826 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
827 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
829 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
830 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
831 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
832 $date{'hour_local'} = $hour;
833 $date{'minute_local'} = $min;
834 $date{'tz_local'} = $tz;
838 # git-logo (cached in browser for one day)
840 binmode STDOUT
, ':raw';
841 print $cgi->header(-type
=> 'image/png', -expires
=> '+1d');
842 # cat git-logo.png | hexdump -e '16/1 " %02x" "\n"' | sed 's/ /\\x/g'
843 print "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52" .
844 "\x00\x00\x00\x48\x00\x00\x00\x1b\x04\x03\x00\x00\x00\x2d\xd9\xd4" .
845 "\x2d\x00\x00\x00\x18\x50\x4c\x54\x45\xff\xff\xff\x60\x60\x5d\xb0" .
846 "\xaf\xaa\x00\x80\x00\xce\xcd\xc7\xc0\x00\x00\xe8\xe8\xe6\xf7\xf7" .
847 "\xf6\x95\x0c\xa7\x47\x00\x00\x00\x73\x49\x44\x41\x54\x28\xcf\x63" .
848 "\x48\x67\x20\x04\x4a\x5c\x18\x0a\x08\x2a\x62\x53\x61\x20\x02\x08" .
849 "\x0d\x69\x45\xac\xa1\xa1\x01\x30\x0c\x93\x60\x36\x26\x52\x91\xb1" .
850 "\x01\x11\xd6\xe1\x55\x64\x6c\x6c\xcc\x6c\x6c\x0c\xa2\x0c\x70\x2a" .
851 "\x62\x06\x2a\xc1\x62\x1d\xb3\x01\x02\x53\xa4\x08\xe8\x00\x03\x18" .
852 "\x26\x56\x11\xd4\xe1\x20\x97\x1b\xe0\xb4\x0e\x35\x24\x71\x29\x82" .
853 "\x99\x30\xb8\x93\x0a\x11\xb9\x45\x88\xc1\x8d\xa0\xa2\x44\x21\x06" .
854 "\x27\x41\x82\x40\x85\xc1\x45\x89\x20\x70\x01\x00\xa4\x3d\x21\xc5" .
855 "\x12\x1c\x9a\xfe\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\x82";
861 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
862 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
863 if (!defined $gcos) {
867 $owner =~ s/[,;].*$//;
868 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
871 sub git_read_projects
{
874 if (-d
$projects_list) {
875 # search in directory
876 my $dir = $projects_list;
877 opendir my ($dh), $dir or return undef;
878 while (my $dir = readdir($dh)) {
879 if (-e
"$projectroot/$dir/HEAD") {
887 } elsif (-f
$projects_list) {
888 # read from file(url-encoded):
889 # 'git%2Fgit.git Linus+Torvalds'
890 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
891 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
892 open my ($fd), $projects_list or return undef;
893 while (my $line = <$fd>) {
895 my ($path, $owner) = split ' ', $line;
896 $path = unescape
($path);
897 $owner = unescape
($owner);
898 if (!defined $path) {
901 if (-e
"$projectroot/$path/HEAD") {
904 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
911 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
915 sub git_get_project_config
{
918 return unless ($key);
919 $key =~ s/^gitweb\.//;
920 return if ($key =~ m/\W/);
922 my $val = qx($GIT repo
-config
--get gitweb
.$key);
926 sub git_get_project_config_bool
{
927 my $val = git_get_project_config
(@_);
928 if ($val and $val =~ m/true|yes|on/) {
931 return; # implicit false
934 sub git_project_list
{
935 my @list = git_read_projects
();
938 die_error
(undef, "No project found.");
940 foreach my $pr (@list) {
941 my $head = git_read_head
($pr->{'path'});
942 if (!defined $head) {
945 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
946 my %co = git_read_commit
($head);
950 $pr->{'commit'} = \
%co;
951 if (!defined $pr->{'descr'}) {
952 my $descr = git_read_description
($pr->{'path'}) || "";
953 $pr->{'descr'} = chop_str
($descr, 25, 5);
955 if (!defined $pr->{'owner'}) {
956 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
962 print "<div class=\"index_include\">\n";
963 open (my $fd, $home_text);
968 print "<table class=\"project_list\">\n" .
970 if (!defined($order) || (defined($order) && ($order eq "project"))) {
971 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
972 print "<th>Project</th>\n";
974 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=project")}, "Project") . "</th>\n";
976 if (defined($order) && ($order eq "descr")) {
977 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
978 print "<th>Description</th>\n";
980 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=descr")}, "Description") . "</th>\n";
982 if (defined($order) && ($order eq "owner")) {
983 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
984 print "<th>Owner</th>\n";
986 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=owner")}, "Owner") . "</th>\n";
988 if (defined($order) && ($order eq "age")) {
989 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
990 print "<th>Last Change</th>\n";
992 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=age")}, "Last Change") . "</th>\n";
994 print "<th></th>\n" .
997 foreach my $pr (@projects) {
999 print "<tr class=\"dark\">\n";
1001 print "<tr class=\"light\">\n";
1004 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=summary"), -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
1005 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
1006 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
1007 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" . $pr->{'commit'}{'age_string'} . "</td>\n" .
1008 "<td class=\"link\">" .
1009 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=summary")}, "summary") .
1010 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=shortlog")}, "shortlog") .
1011 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=log")}, "log") .
1020 my $type = shift || "";
1022 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1023 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1024 open my $fd, "$projectroot/$project/info/refs" or return;
1025 while (my $line = <$fd>) {
1027 # attention: for $type == "" it saves only last path part of ref name
1028 # e.g. from 'refs/heads/jn/gitweb' it would leave only 'gitweb'
1029 if ($line =~ m/^([0-9a-fA-F]{40})\t.*$type\/([^\
^]+)/) {
1030 if (defined $refs{$1}) {
1031 $refs{$1} .= " / $2";
1037 close $fd or return;
1041 sub git_get_referencing
{
1042 my ($refs, $id) = @_;
1044 if (defined $refs->{$id}) {
1045 return ' <span class="tag">' . esc_html
($refs->{$id}) . '</span>';
1052 my $ref_dir = shift;
1056 opendir my $dh, "$projectroot/$project/$ref_dir";
1057 while (my $dir = readdir($dh)) {
1058 if ($dir =~ m/^\./) {
1061 if (-d
"$projectroot/$project/$ref_dir/$dir") {
1062 opendir my $dh2, "$projectroot/$project/$ref_dir/$dir";
1063 my @subdirs = grep !m/^\./, readdir $dh2;
1065 foreach my $subdir (@subdirs) {
1066 push @refs, "$dir/$subdir"
1073 foreach my $ref_file (@refs) {
1074 my $ref_id = git_read_hash
("$project/$ref_dir/$ref_file");
1075 my $type = git_get_type
($ref_id) || next;
1078 $ref_item{'type'} = $type;
1079 $ref_item{'id'} = $ref_id;
1080 $ref_item{'epoch'} = 0;
1081 $ref_item{'age'} = "unknown";
1082 if ($type eq "tag") {
1083 my %tag = git_read_tag
($ref_id);
1084 $ref_item{'comment'} = $tag{'comment'};
1085 if ($tag{'type'} eq "commit") {
1086 %co = git_read_commit
($tag{'object'});
1087 $ref_item{'epoch'} = $co{'committer_epoch'};
1088 $ref_item{'age'} = $co{'age_string'};
1089 } elsif (defined($tag{'epoch'})) {
1090 my $age = time - $tag{'epoch'};
1091 $ref_item{'epoch'} = $tag{'epoch'};
1092 $ref_item{'age'} = age_string
($age);
1094 $ref_item{'reftype'} = $tag{'type'};
1095 $ref_item{'name'} = $tag{'name'};
1096 $ref_item{'refid'} = $tag{'object'};
1097 } elsif ($type eq "commit"){
1098 %co = git_read_commit
($ref_id);
1099 $ref_item{'reftype'} = "commit";
1100 $ref_item{'name'} = $ref_file;
1101 $ref_item{'title'} = $co{'title'};
1102 $ref_item{'refid'} = $ref_id;
1103 $ref_item{'epoch'} = $co{'committer_epoch'};
1104 $ref_item{'age'} = $co{'age_string'};
1106 $ref_item{'reftype'} = $type;
1107 $ref_item{'name'} = $ref_file;
1108 $ref_item{'refid'} = $ref_id;
1111 push @reflist, \
%ref_item;
1114 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1118 sub git_shortlog_body
{
1119 # uses global variable $project
1120 my ($revlist, $from, $to, $refs, $extra) = @_;
1121 $from = 0 unless defined $from;
1122 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1124 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
1126 for (my $i = $from; $i <= $to; $i++) {
1127 my $commit = $revlist->[$i];
1128 #my $ref = defined $refs ? git_get_referencing($refs, $commit) : '';
1129 my $ref = git_get_referencing
($refs, $commit);
1130 my %co = git_read_commit
($commit);
1131 my %ad = date_str
($co{'author_epoch'});
1133 print "<tr class=\"dark\">\n";
1135 print "<tr class=\"light\">\n";
1138 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1139 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1140 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
1142 if (length($co{'title_short'}) < length($co{'title'})) {
1143 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"),
1144 -class => "list", -title
=> "$co{'title'}"},
1145 "<b>" . esc_html
($co{'title_short'}) . "$ref</b>");
1147 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"),
1149 "<b>" . esc_html
($co{'title'}) . "$ref</b>");
1152 "<td class=\"link\">" .
1153 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") . " | " .
1154 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1158 if (defined $extra) {
1160 "<td colspan=\"4\">$extra</td>\n" .
1167 # uses global variable $project
1168 my ($taglist, $from, $to, $extra) = @_;
1169 $from = 0 unless defined $from;
1170 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1172 print "<table class=\"tags\" cellspacing=\"0\">\n";
1174 for (my $i = $from; $i <= $to; $i++) {
1175 my $entry = $taglist->[$i];
1177 my $comment_lines = $tag{'comment'};
1178 my $comment = shift @
$comment_lines;
1180 if (defined $comment) {
1181 $comment_short = chop_str
($comment, 30, 5);
1184 print "<tr class=\"dark\">\n";
1186 print "<tr class=\"light\">\n";
1189 print "<td><i>$tag{'age'}</i></td>\n" .
1191 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"),
1192 -class => "list"}, "<b>" . esc_html
($tag{'name'}) . "</b>") .
1195 if (defined $comment) {
1196 if (length($comment_short) < length($comment)) {
1197 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}"),
1198 -class => "list", -title
=> $comment}, $comment_short);
1200 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}"),
1201 -class => "list"}, $comment);
1205 "<td class=\"selflink\">";
1206 if ($tag{'type'} eq "tag") {
1207 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, "tag");
1212 "<td class=\"link\">" . " | " .
1213 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1214 if ($tag{'reftype'} eq "commit") {
1215 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1216 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'refid'}")}, "log");
1217 } elsif ($tag{'reftype'} eq "blob") {
1218 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$tag{'refid'}")}, "raw");
1223 if (defined $extra) {
1225 "<td colspan=\"5\">$extra</td>\n" .
1231 sub git_heads_body
{
1232 # uses global variable $project
1233 my ($taglist, $head, $from, $to, $extra) = @_;
1234 $from = 0 unless defined $from;
1235 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1237 print "<table class=\"heads\" cellspacing=\"0\">\n";
1239 for (my $i = $from; $i <= $to; $i++) {
1240 my $entry = $taglist->[$i];
1242 my $curr = $tag{'id'} eq $head;
1244 print "<tr class=\"dark\">\n";
1246 print "<tr class=\"light\">\n";
1249 print "<td><i>$tag{'age'}</i></td>\n" .
1250 ($tag{'id'} eq $head ?
"<td class=\"current_head\">" : "<td>") .
1251 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}"),
1252 -class => "list"}, "<b>" . esc_html
($tag{'name'}) . "</b>") .
1254 "<td class=\"link\">" .
1255 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") . " | " .
1256 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'name'}")}, "log") .
1260 if (defined $extra) {
1262 "<td colspan=\"3\">$extra</td>\n" .
1269 my $descr = git_read_description
($project) || "none";
1270 my $head = git_read_head
($project);
1271 my %co = git_read_commit
($head);
1272 my %cd = date_str
($co{'committer_epoch'}, $co{'committer_tz'});
1275 if (-f
$projects_list) {
1276 open (my $fd , $projects_list);
1277 while (my $line = <$fd>) {
1279 my ($pr, $ow) = split ' ', $line;
1280 $pr = unescape
($pr);
1281 $ow = unescape
($ow);
1282 if ($pr eq $project) {
1283 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
1289 if (!defined $owner) {
1290 $owner = get_file_owner
("$projectroot/$project");
1293 my $refs = read_info_ref
();
1295 git_page_nav
('summary','', $head);
1297 print "<div class=\"title\"> </div>\n";
1298 print "<table cellspacing=\"0\">\n" .
1299 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
1300 "<tr><td>owner</td><td>$owner</td></tr>\n" .
1301 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
1304 open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_read_head
($project)
1305 or die_error
(undef, "Open git-rev-list failed.");
1306 my @revlist = map { chomp; $_ } <$fd>;
1308 git_header_div
('shortlog');
1309 git_shortlog_body
(\
@revlist, 0, 15, $refs,
1310 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "..."));
1312 my $taglist = git_read_refs
("refs/tags");
1313 if (defined @
$taglist) {
1314 git_header_div
('tags');
1315 git_tags_body
($taglist, 0, 15,
1316 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tags")}, "..."));
1319 my $headlist = git_read_refs
("refs/heads");
1320 if (defined @
$headlist) {
1321 git_header_div
('heads');
1322 git_heads_body
($taglist, $head, 0, 15,
1323 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=heads")}, "..."));
1329 sub git_print_page_path
{
1333 if (!defined $name) {
1334 print "<div class=\"page_path\"><b>/</b></div>\n";
1335 } elsif ($type =~ "blob") {
1336 print "<div class=\"page_path\"><b>" .
1337 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;f=$file_name")}, esc_html
($name)) . "</b><br/></div>\n";
1339 print "<div class=\"page_path\"><b>" . esc_html
($name) . "</b><br/></div>\n";
1344 my $head = git_read_head
($project);
1346 git_page_nav
('','', $head,undef,$head);
1347 my %tag = git_read_tag
($hash);
1348 git_header_div
('commit', esc_html
($tag{'name'}), $hash);
1349 print "<div class=\"title_text\">\n" .
1350 "<table cellspacing=\"0\">\n" .
1352 "<td>object</td>\n" .
1353 "<td>" . $cgi->a({-class => "list", -href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'object'}) . "</td>\n" .
1354 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'type'}) . "</td>\n" .
1356 if (defined($tag{'author'})) {
1357 my %ad = date_str
($tag{'epoch'}, $tag{'tz'});
1358 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
1359 print "<tr><td></td><td>" . $ad{'rfc2822'} . sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) . "</td></tr>\n";
1361 print "</table>\n\n" .
1363 print "<div class=\"page_body\">";
1364 my $comment = $tag{'comment'};
1365 foreach my $line (@
$comment) {
1366 print esc_html
($line) . "<br/>\n";
1375 die_error
(undef, "Permission denied.") if (!git_get_project_config_bool
('blame'));
1376 die_error
('404 Not Found', "File name not defined") if (!$file_name);
1377 $hash_base ||= git_read_head
($project);
1378 die_error
(undef, "Reading commit failed") unless ($hash_base);
1379 my %co = git_read_commit
($hash_base)
1380 or die_error
(undef, "Reading commit failed");
1381 if (!defined $hash) {
1382 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
1383 or die_error
(undef, "Error looking up file");
1385 $ftype = git_get_type
($hash);
1386 if ($ftype !~ "blob") {
1387 die_error
("400 Bad Request", "object is not a blob");
1389 open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base)
1390 or die_error
(undef, "Open git-blame failed.");
1393 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") .
1394 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;f=$file_name")}, "head");
1395 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1396 git_header_div
('commit', esc_html
($co{'title'}), $hash_base);
1397 git_print_page_path
($file_name, $ftype);
1398 my @rev_color = (qw(light dark));
1399 my $num_colors = scalar(@rev_color);
1400 my $current_color = 0;
1402 print "<div class=\"page_body\">\n";
1403 print "<table class=\"blame\">\n";
1404 print "<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n";
1406 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
1408 my $rev = substr($full_rev, 0, 8);
1412 if (!defined $last_rev) {
1413 $last_rev = $full_rev;
1414 } elsif ($last_rev ne $full_rev) {
1415 $last_rev = $full_rev;
1416 $current_color = ++$current_color % $num_colors;
1418 print "<tr class=\"$rev_color[$current_color]\">\n";
1419 print "<td class=\"sha1\">" .
1420 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$full_rev;f=$file_name")}, esc_html
($rev)) . "</td>\n";
1421 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" . esc_html
($lineno) . "</a></td>\n";
1422 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
1427 close $fd or print "Reading blob failed\n";
1433 die_error
('403 Permission denied', "Permission denied.") if (!git_get_project_config_bool
('blame'));
1434 die_error
('404 Not Found', "What file will it be, master?") if (!$file_name);
1435 $hash_base ||= git_read_head
($project);
1436 die_error
(undef, "Reading commit failed.") unless ($hash_base);
1437 my %co = git_read_commit
($hash_base)
1438 or die_error
(undef, "Reading commit failed.");
1439 if (!defined $hash) {
1440 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
1441 or die_error
(undef, "Error lookup file.");
1443 open ($fd, "-|", $GIT, "annotate", '-l', '-t', '-r', $file_name, $hash_base)
1444 or die_error
(undef, "Open git-annotate failed.");
1447 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") .
1448 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;f=$file_name")}, "head");
1449 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1450 git_header_div
('commit', esc_html
($co{'title'}), $hash_base);
1451 git_print_page_path
($file_name);
1452 print "<div class=\"page_body\">\n";
1454 <table class="blame">
1463 my @line_class = (qw(light dark));
1464 my $line_class_len = scalar (@line_class);
1465 my $line_class_num = $#line_class;
1466 while (my $line = <$fd>) {
1478 $line_class_num = ($line_class_num + 1) % $line_class_len;
1480 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) \+\d\d\d\d\t(\d+)\)(.*)$/) {
1487 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
1490 $short_rev = substr ($long_rev, 0, 8);
1491 $age = time () - $time;
1492 $age_str = age_string
($age);
1493 $age_str =~ s/ / /g;
1494 $age_class = age_class
($age);
1495 $author = esc_html
($author);
1496 $author =~ s/ / /g;
1498 while ((my $pos = index($data, "\t")) != -1) {
1499 if (my $count = (8 - ($pos % 8))) {
1500 my $spaces = ' ' x
$count;
1501 $data =~ s/\t/$spaces/;
1504 $data = esc_html
($data);
1507 <tr class="$line_class[$line_class_num]">
1508 <td class="sha1"><a href="$my_uri?${\esc_param ("p=$project;a=commit;h=$long_rev")}" class="text">$short_rev..</a></td>
1509 <td class="$age_class">$age_str</td>
1511 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
1512 <td class="pre">$data</td>
1515 } # while (my $line = <$fd>)
1516 print "</table>\n\n";
1517 close $fd or print "Reading blob failed.\n";
1523 my $head = git_read_head
($project);
1525 git_page_nav
('','', $head,undef,$head);
1526 git_header_div
('summary', $project);
1528 my $taglist = git_read_refs
("refs/tags");
1529 if (defined @
$taglist) {
1530 git_tags_body
($taglist);
1536 my $head = git_read_head
($project);
1538 git_page_nav
('','', $head,undef,$head);
1539 git_header_div
('summary', $project);
1541 my $taglist = git_read_refs
("refs/heads");
1543 if (defined @
$taglist) {
1544 git_heads_body
($taglist, $head);
1549 sub git_get_hash_by_path
{
1551 my $path = shift || return undef;
1555 open my $fd, "-|", $GIT, "ls-tree", $base, "--", $path
1556 or die_error
(undef, "Open git-ls-tree failed.");
1558 close $fd or return undef;
1560 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1561 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1565 sub mimetype_guess_file
{
1566 my $filename = shift;
1567 my $mimemap = shift;
1568 -r
$mimemap or return undef;
1571 open(MIME
, $mimemap) or return undef;
1573 my ($mime, $exts) = split(/\t+/);
1574 my @exts = split(/\s+/, $exts);
1575 foreach my $ext (@exts) {
1576 $mimemap{$ext} = $mime;
1581 $filename =~ /\.(.*?)$/;
1582 return $mimemap{$1};
1585 sub mimetype_guess
{
1586 my $filename = shift;
1588 $filename =~ /\./ or return undef;
1590 if ($mimetypes_file) {
1591 my $file = $mimetypes_file;
1592 #$file =~ m#^/# or $file = "$projectroot/$path/$file";
1593 $mime = mimetype_guess_file
($filename, $file);
1595 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1599 sub git_blob_plain_mimetype
{
1601 my $filename = shift;
1604 my $mime = mimetype_guess
($filename);
1605 $mime and return $mime;
1609 return $default_blob_plain_mimetype unless $fd;
1612 return 'text/plain' .
1613 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
1614 } elsif (! $filename) {
1615 return 'application/octet-stream';
1616 } elsif ($filename =~ m/\.png$/i) {
1618 } elsif ($filename =~ m/\.gif$/i) {
1620 } elsif ($filename =~ m/\.jpe?g$/i) {
1621 return 'image/jpeg';
1623 return 'application/octet-stream';
1627 sub git_blob_plain
{
1628 if (!defined $hash) {
1629 if (defined $file_name) {
1630 my $base = $hash_base || git_read_head
($project);
1631 $hash = git_get_hash_by_path
($base, $file_name, "blob")
1632 or die_error
(undef, "Error lookup file.");
1634 die_error
(undef, "No file name defined.");
1638 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
1639 or die_error
("Couldn't cat $file_name, $hash");
1641 $type ||= git_blob_plain_mimetype
($fd, $file_name);
1643 # save as filename, even when no $file_name is given
1644 my $save_as = "$hash";
1645 if (defined $file_name) {
1646 $save_as = $file_name;
1647 } elsif ($type =~ m/^text\//) {
1651 print $cgi->header(-type
=> "$type", '-content-disposition' => "inline; filename=\"$save_as\"");
1653 binmode STDOUT
, ':raw';
1655 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
1661 if (!defined $hash) {
1662 if (defined $file_name) {
1663 my $base = $hash_base || git_read_head
($project);
1664 $hash = git_get_hash_by_path
($base, $file_name, "blob")
1665 or die_error
(undef, "Error lookup file.");
1667 die_error
(undef, "No file name defined.");
1670 my $have_blame = git_get_project_config_bool
('blame');
1671 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
1672 or die_error
(undef, "Couldn't cat $file_name, $hash.");
1673 my $mimetype = git_blob_plain_mimetype
($fd, $file_name);
1674 if ($mimetype !~ m/^text\//) {
1676 return git_blob_plain
($mimetype);
1679 my $formats_nav = '';
1680 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
1681 if (defined $file_name) {
1683 $formats_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;h=$hash;hb=$hash_base;f=$file_name")}, "blame") . " | ";
1686 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$hash;f=$file_name")}, "plain") .
1687 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;hb=HEAD;f=$file_name")}, "head");
1689 $formats_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$hash")}, "plain");
1691 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1692 git_header_div
('commit', esc_html
($co{'title'}), $hash_base);
1694 print "<div class=\"page_nav\">\n" .
1695 "<br/><br/></div>\n" .
1696 "<div class=\"title\">$hash</div>\n";
1698 git_print_page_path
($file_name, "blob");
1699 print "<div class=\"page_body\">\n";
1701 while (my $line = <$fd>) {
1704 while ((my $pos = index($line, "\t")) != -1) {
1705 if (my $count = (8 - ($pos % 8))) {
1706 my $spaces = ' ' x
$count;
1707 $line =~ s/\t/$spaces/;
1710 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", $nr, $nr, $nr, esc_html
($line);
1712 close $fd or print "Reading blob failed.\n";
1718 if (!defined $hash) {
1719 $hash = git_read_head
($project);
1720 if (defined $file_name) {
1721 my $base = $hash_base || $hash;
1722 $hash = git_get_hash_by_path
($base, $file_name, "tree");
1724 if (!defined $hash_base) {
1729 open my $fd, "-|", $GIT, "ls-tree", '-z', $hash
1730 or die_error
(undef, "Open git-ls-tree failed.");
1731 my @entries = map { chomp; $_ } <$fd>;
1732 close $fd or die_error
(undef, "Reading tree failed.");
1735 my $refs = read_info_ref
();
1736 my $ref = git_get_referencing
($refs, $hash_base);
1740 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
1741 $base_key = ";hb=$hash_base";
1742 git_page_nav
('tree','', $hash_base);
1743 git_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
1745 print "<div class=\"page_nav\">\n";
1746 print "<br/><br/></div>\n";
1747 print "<div class=\"title\">$hash</div>\n";
1749 if (defined $file_name) {
1750 $base = esc_html
("$file_name/");
1752 git_print_page_path
($file_name);
1753 print "<div class=\"page_body\">\n";
1754 print "<table cellspacing=\"0\">\n";
1756 foreach my $line (@entries) {
1757 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1758 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1762 my $t_name = validate_input
($4);
1764 print "<tr class=\"dark\">\n";
1766 print "<tr class=\"light\">\n";
1769 print "<td class=\"mode\">" . mode_str
($t_mode) . "</td>\n";
1770 if ($t_type eq "blob") {
1771 print "<td class=\"list\">" .
1772 $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)) .
1774 "<td class=\"link\">" .
1775 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name")}, "blob") .
1776 # " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$t_hash$base_key;f=$base$t_name")}, "blame") .
1777 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;h=$t_hash;hb=$hash_base;f=$base$t_name")}, "history") .
1778 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$t_hash;f=$base$t_name")}, "raw") .
1780 } elsif ($t_type eq "tree") {
1781 print "<td class=\"list\">" .
1782 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, esc_html
($t_name)) .
1784 "<td class=\"link\">" .
1785 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, "tree") .
1786 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;hb=$hash_base;f=$base$t_name")}, "history") .
1791 print "</table>\n" .
1797 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
1798 open my $fd, "-|", $GIT, "rev-list", "--max-count=150", git_read_head
($project)
1799 or die_error
(undef, "Open git-rev-list failed.");
1800 my @revlist = map { chomp; $_ } <$fd>;
1801 close $fd or die_error
(undef, "Reading rev-list failed.");
1802 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
1803 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1804 "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
1805 print "<channel>\n";
1806 print "<title>$project</title>\n".
1807 "<link>" . esc_html
("$my_url?p=$project;a=summary") . "</link>\n".
1808 "<description>$project log</description>\n".
1809 "<language>en</language>\n";
1811 for (my $i = 0; $i <= $#revlist; $i++) {
1812 my $commit = $revlist[$i];
1813 my %co = git_read_commit
($commit);
1814 # we read 150, we always show 30 and the ones more recent than 48 hours
1815 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
1818 my %cd = date_str
($co{'committer_epoch'});
1819 open $fd, "-|", $GIT, "diff-tree", '-r', $co{'parent'}, $co{'id'} or next;
1820 my @difftree = map { chomp; $_ } <$fd>;
1824 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
1826 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
1827 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
1828 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
1829 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
1830 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
1831 "<content:encoded>" .
1833 my $comment = $co{'comment'};
1834 foreach my $line (@
$comment) {
1835 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
1836 print "$line<br/>\n";
1839 foreach my $line (@difftree) {
1840 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
1843 my $file = validate_input
(unquote
($7));
1844 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
1845 print "$file<br/>\n";
1848 "</content:encoded>\n" .
1851 print "</channel></rss>";
1855 my @list = git_read_projects
();
1857 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
1858 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1859 "<opml version=\"1.0\">\n".
1861 " <title>$site_name Git OPML Export</title>\n".
1864 "<outline text=\"git RSS feeds\">\n";
1866 foreach my $pr (@list) {
1868 my $head = git_read_head
($proj{'path'});
1869 if (!defined $head) {
1872 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
1873 my %co = git_read_commit
($head);
1878 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
1879 my $rss = "$my_url?p=$proj{'path'};a=rss";
1880 my $html = "$my_url?p=$proj{'path'};a=summary";
1881 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
1883 print "</outline>\n".
1889 my $head = git_read_head
($project);
1890 if (!defined $hash) {
1893 if (!defined $page) {
1896 my $refs = read_info_ref
();
1898 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
1899 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
1900 or die_error
(undef, "Open git-rev-list failed.");
1901 my @revlist = map { chomp; $_ } <$fd>;
1904 my $paging_nav = git_get_paging_nav
('log', $hash, $head, $page, $#revlist);
1907 git_page_nav
('log','', $hash,undef,undef, $paging_nav);
1910 my %co = git_read_commit
($hash);
1912 git_header_div
('summary', $project);
1913 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
1915 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
1916 my $commit = $revlist[$i];
1917 my $ref = git_get_referencing
($refs, $commit);
1918 my %co = git_read_commit
($commit);
1920 my %ad = date_str
($co{'author_epoch'});
1921 git_header_div
('commit',
1922 "<span class=\"age\">$co{'age_string'}</span>" .
1923 esc_html
($co{'title'}) . $ref,
1925 print "<div class=\"title_text\">\n" .
1926 "<div class=\"log_link\">\n" .
1927 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
1928 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1931 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
1933 "<div class=\"log_body\">\n";
1934 my $comment = $co{'comment'};
1936 foreach my $line (@
$comment) {
1937 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1948 print format_log_line_html
($line) . "<br/>\n";
1959 my %co = git_read_commit
($hash);
1961 die_error
(undef, "Unknown commit object.");
1963 my %ad = date_str
($co{'author_epoch'}, $co{'author_tz'});
1964 my %cd = date_str
($co{'committer_epoch'}, $co{'committer_tz'});
1966 my $parent = $co{'parent'};
1967 if (!defined $parent) {
1970 open my $fd, "-|", $GIT, "diff-tree", '-r', '-M', $parent, $hash
1971 or die_error
(undef, "Open git-diff-tree failed.");
1972 my @difftree = map { chomp; $_ } <$fd>;
1973 close $fd or die_error
(undef, "Reading git-diff-tree failed.");
1975 # non-textual hash id's can be cached
1977 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
1980 my $refs = read_info_ref
();
1981 my $ref = git_get_referencing
($refs, $co{'id'});
1982 my $formats_nav = '';
1983 if (defined $file_name && defined $co{'parent'}) {
1984 my $parent = $co{'parent'};
1985 $formats_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;hb=$parent;f=$file_name")}, "blame");
1987 git_header_html
(undef, $expires);
1988 git_page_nav
('commit', defined $co{'parent'} ?
'' : 'commitdiff',
1989 $hash, $co{'tree'}, $hash,
1992 if (defined $co{'parent'}) {
1993 git_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
1995 git_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
1997 print "<div class=\"title_text\">\n" .
1998 "<table cellspacing=\"0\">\n";
1999 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
2001 "<td></td><td> $ad{'rfc2822'}";
2002 if ($ad{'hour_local'} < 6) {
2003 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2005 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2009 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
2010 print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
2011 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
2014 "<td class=\"sha1\">" .
2015 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash"), class => "list"}, $co{'tree'}) .
2017 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
2020 my $parents = $co{'parents'};
2021 foreach my $par (@
$parents) {
2024 "<td class=\"sha1\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$par"), class => "list"}, $par) . "</td>" .
2025 "<td class=\"link\">" .
2026 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$par")}, "commit") .
2027 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash;hp=$par")}, "commitdiff") .
2033 print "<div class=\"page_body\">\n";
2034 my $comment = $co{'comment'};
2037 foreach my $line (@
$comment) {
2038 # print only one empty line
2040 if ($empty || $signed) {
2047 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2049 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2052 print format_log_line_html
($line) . "<br/>\n";
2056 print "<div class=\"list_head\">\n";
2057 if ($#difftree > 10) {
2058 print(($#difftree + 1) . " files changed:\n");
2061 print "<table class=\"diff_tree\">\n";
2063 foreach my $line (@difftree) {
2064 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2065 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2066 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
2074 my $similarity = $6;
2075 my $file = validate_input
(unquote
($7));
2077 print "<tr class=\"dark\">\n";
2079 print "<tr class=\"light\">\n";
2082 if ($status eq "A") {
2084 if (S_ISREG
(oct $to_mode)) {
2085 $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
2088 $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" .
2089 "<td><span class=\"file_status new\">[new " . file_type
($to_mode) . "$mode_chng]</span></td>\n" .
2090 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob") . "</td>\n";
2091 } elsif ($status eq "D") {
2093 $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" .
2094 "<td><span class=\"file_status deleted\">[deleted " . file_type
($from_mode). "]</span></td>\n" .
2095 "<td class=\"link\">" .
2096 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, "blob") .
2097 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;hb=$hash;f=$file")}, "history") .
2099 } elsif ($status eq "M" || $status eq "T") {
2100 my $mode_chnge = "";
2101 if ($from_mode != $to_mode) {
2102 $mode_chnge = " <span class=\"file_status mode_chnge\">[changed";
2103 if (((oct $from_mode) & S_IFMT
) != ((oct $to_mode) & S_IFMT
)) {
2104 $mode_chnge .= " from " . file_type
($from_mode) . " to " . file_type
($to_mode);
2106 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
2107 if (S_ISREG
($from_mode) && S_ISREG
($to_mode)) {
2108 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
2109 } elsif (S_ISREG
($to_mode)) {
2110 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
2113 $mode_chnge .= "]</span>\n";
2116 if ($to_id ne $from_id) {
2117 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));
2119 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file"), -class => "list"}, esc_html
($file));
2122 "<td>$mode_chnge</td>\n" .
2123 "<td class=\"link\">";
2124 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob");
2125 if ($to_id ne $from_id) {
2126 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file")}, "diff");
2128 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;hb=$hash;f=$file")}, "history") . "\n";
2130 } elsif ($status eq "R") {
2131 my ($from_file, $to_file) = split "\t", $file;
2133 if ($from_mode != $to_mode) {
2134 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
2137 $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" .
2138 "<td><span class=\"file_status moved\">[moved from " .
2139 $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)) .
2140 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
2141 "<td class=\"link\">" .
2142 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file")}, "blob");
2143 if ($to_id ne $from_id) {
2144 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file")}, "diff");
2155 mkdir($git_temp, 0700);
2157 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
2159 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff_plain;h=$hash;hp=$hash_parent")}, "plain");
2160 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2161 git_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2163 print "<div class=\"page_nav\">\n" .
2164 "<br/><br/></div>\n" .
2165 "<div class=\"title\">$hash vs $hash_parent</div>\n";
2167 git_print_page_path
($file_name, "blob");
2168 print "<div class=\"page_body\">\n" .
2169 "<div class=\"diff_info\">blob:" .
2170 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name")}, $hash_parent) .
2172 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, $hash) .
2174 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
2179 sub git_blobdiff_plain
{
2180 mkdir($git_temp, 0700);
2181 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8');
2182 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
2185 sub git_commitdiff
{
2186 mkdir($git_temp, 0700);
2187 my %co = git_read_commit
($hash);
2189 die_error
(undef, "Unknown commit object.");
2191 if (!defined $hash_parent) {
2192 $hash_parent = $co{'parent'};
2194 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2195 or die_error
(undef, "Open git-diff-tree failed.");
2196 my @difftree = map { chomp; $_ } <$fd>;
2197 close $fd or die_error
(undef, "Reading diff-tree failed.");
2199 # non-textual hash id's can be cached
2201 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2204 my $refs = read_info_ref
();
2205 my $ref = git_get_referencing
($refs, $co{'id'});
2207 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent")}, "plain");
2208 git_header_html
(undef, $expires);
2209 git_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
2210 git_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
2211 print "<div class=\"page_body\">\n";
2212 my $comment = $co{'comment'};
2215 my @log = @
$comment;
2216 # remove first and empty lines after that
2218 while (defined $log[0] && $log[0] eq "") {
2221 foreach my $line (@log) {
2222 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2233 print format_log_line_html
($line) . "<br/>\n";
2236 foreach my $line (@difftree) {
2237 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2238 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2239 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2245 my $file = validate_input
(unquote
($6));
2246 if ($status eq "A") {
2247 print "<div class=\"diff_info\">" . file_type
($to_mode) . ":" .
2248 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id) . "(new)" .
2250 git_diff_print
(undef, "/dev/null", $to_id, "b/$file");
2251 } elsif ($status eq "D") {
2252 print "<div class=\"diff_info\">" . file_type
($from_mode) . ":" .
2253 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) . "(deleted)" .
2255 git_diff_print
($from_id, "a/$file", undef, "/dev/null");
2256 } elsif ($status eq "M") {
2257 if ($from_id ne $to_id) {
2258 print "<div class=\"diff_info\">" .
2259 file_type
($from_mode) . ":" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) .
2261 file_type
($to_mode) . ":" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id);
2263 git_diff_print
($from_id, "a/$file", $to_id, "b/$file");
2272 sub git_commitdiff_plain
{
2273 mkdir($git_temp, 0700);
2274 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2275 or die_error
(undef, "Open git-diff-tree failed.");
2276 my @difftree = map { chomp; $_ } <$fd>;
2277 close $fd or die_error
(undef, "Reading diff-tree failed.");
2279 # try to figure out the next tag after this commit
2281 my $refs = read_info_ref
("tags");
2282 open $fd, "-|", $GIT, "rev-list", "HEAD";
2283 my @commits = map { chomp; $_ } <$fd>;
2285 foreach my $commit (@commits) {
2286 if (defined $refs->{$commit}) {
2287 $tagname = $refs->{$commit}
2289 if ($commit eq $hash) {
2294 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8', '-content-disposition' => "inline; filename=\"git-$hash.patch\"");
2295 my %co = git_read_commit
($hash);
2296 my %ad = date_str
($co{'author_epoch'}, $co{'author_tz'});
2297 my $comment = $co{'comment'};
2298 print "From: $co{'author'}\n" .
2299 "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
2300 "Subject: $co{'title'}\n";
2301 if (defined $tagname) {
2302 print "X-Git-Tag: $tagname\n";
2304 print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
2307 foreach my $line (@
$comment) {;
2312 foreach my $line (@difftree) {
2313 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2318 if ($status eq "A") {
2319 git_diff_print
(undef, "/dev/null", $to_id, "b/$file", "plain");
2320 } elsif ($status eq "D") {
2321 git_diff_print
($from_id, "a/$file", undef, "/dev/null", "plain");
2322 } elsif ($status eq "M") {
2323 git_diff_print
($from_id, "a/$file", $to_id, "b/$file", "plain");
2329 if (!defined $hash_base) {
2330 $hash_base = git_read_head
($project);
2333 my %co = git_read_commit
($hash_base);
2335 die_error
(undef, "Unknown commit object.");
2337 my $refs = read_info_ref
();
2339 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base);
2340 git_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2341 if (!defined $hash && defined $file_name) {
2342 $hash = git_get_hash_by_path
($hash_base, $file_name);
2344 if (defined $hash) {
2345 $ftype = git_get_type
($hash);
2347 git_print_page_path
($file_name, $ftype);
2350 $GIT, "rev-list", "--full-history", $hash_base, "--", $file_name;
2351 print "<table cellspacing=\"0\">\n";
2353 while (my $line = <$fd>) {
2354 if ($line =~ m/^([0-9a-fA-F]{40})/){
2356 my %co = git_read_commit
($commit);
2360 my $ref = git_get_referencing
($refs, $commit);
2362 print "<tr class=\"dark\">\n";
2364 print "<tr class=\"light\">\n";
2367 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2368 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2369 "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list"}, "<b>" .
2370 esc_html
(chop_str
($co{'title'}, 50)) . "$ref</b>") . "</td>\n" .
2371 "<td class=\"link\">" .
2372 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
2373 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2374 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;hb=$commit;f=$file_name")}, "blob");
2375 my $blob = git_get_hash_by_path
($hash_base, $file_name);
2376 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2377 if (defined $blob && defined $blob_parent && $blob ne $blob_parent) {
2379 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=$file_name")},
2392 if (!defined $searchtext) {
2393 die_error
("", "Text field empty.");
2395 if (!defined $hash) {
2396 $hash = git_read_head
($project);
2398 my %co = git_read_commit
($hash);
2400 die_error
(undef, "Unknown commit object.");
2402 # pickaxe may take all resources of your box and run for several minutes
2403 # with every query - so decide by yourself how public you make this feature :)
2404 my $commit_search = 1;
2405 my $author_search = 0;
2406 my $committer_search = 0;
2407 my $pickaxe_search = 0;
2408 if ($searchtext =~ s/^author\\://i) {
2410 } elsif ($searchtext =~ s/^committer\\://i) {
2411 $committer_search = 1;
2412 } elsif ($searchtext =~ s/^pickaxe\\://i) {
2414 $pickaxe_search = 1;
2417 git_page_nav
('','', $hash,$co{'tree'},$hash);
2418 git_header_div
('commit', esc_html
($co{'title'}), $hash);
2420 print "<table cellspacing=\"0\">\n";
2422 if ($commit_search) {
2424 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", $hash or next;
2425 while (my $commit_text = <$fd>) {
2426 if (!grep m/$searchtext/i, $commit_text) {
2429 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
2432 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
2435 my @commit_lines = split "\n", $commit_text;
2436 my %co = git_read_commit
(undef, \
@commit_lines);
2441 print "<tr class=\"dark\">\n";
2443 print "<tr class=\"light\">\n";
2446 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2447 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2449 $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/>");
2450 my $comment = $co{'comment'};
2451 foreach my $line (@
$comment) {
2452 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2453 my $lead = esc_html
($1) || "";
2454 $lead = chop_str
($lead, 30, 10);
2455 my $match = esc_html
($2) || "";
2456 my $trail = esc_html
($3) || "";
2457 $trail = chop_str
($trail, 30, 10);
2458 my $text = "$lead<span class=\"match\">$match</span>$trail";
2459 print chop_str
($text, 80, 5) . "<br/>\n";
2463 "<td class=\"link\">" .
2464 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2465 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2472 if ($pickaxe_search) {
2474 open my $fd, "-|", "$GIT rev-list $hash | $GIT diff-tree -r --stdin -S\'$searchtext\'";
2477 while (my $line = <$fd>) {
2478 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2481 $set{'from_id'} = $3;
2483 $set{'id'} = $set{'to_id'};
2484 if ($set{'id'} =~ m/0{40}/) {
2485 $set{'id'} = $set{'from_id'};
2487 if ($set{'id'} =~ m/0{40}/) {
2491 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
2494 print "<tr class=\"dark\">\n";
2496 print "<tr class=\"light\">\n";
2499 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2500 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2502 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" .
2503 esc_html
(chop_str
($co{'title'}, 50)) . "</b><br/>");
2504 while (my $setref = shift @files) {
2506 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}"), class => "list"},
2507 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
2511 "<td class=\"link\">" .
2512 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2513 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2517 %co = git_read_commit
($1);
2527 my $head = git_read_head
($project);
2528 if (!defined $hash) {
2531 if (!defined $page) {
2534 my $refs = read_info_ref
();
2536 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2537 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2538 or die_error
(undef, "Open git-rev-list failed.");
2539 my @revlist = map { chomp; $_ } <$fd>;
2542 my $paging_nav = git_get_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
2544 if ($#revlist >= (100 * ($page+1)-1)) {
2546 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)),
2547 -title
=> "Alt-n"}, "next");
2552 git_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
2553 git_header_div
('summary', $project);
2555 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);