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 my $my_url = $cgi->url();
22 my $my_uri = $cgi->url(-absolute
=> 1);
25 # absolute fs-path which will be prepended to the project path
26 #my $projectroot = "/pub/scm";
27 my $projectroot = "/home/kay/public_html/pub/scm";
29 # location of the git-core binaries
30 my $gitbin = "/usr/bin";
32 # location for temporary files needed for diffs
33 my $git_temp = "/tmp/gitweb";
35 # target of the home link on top of all pages
36 my $home_link = $my_uri;
38 # html text to include at home page
39 my $home_text = "indextext.html";
41 # URI of default stylesheet
42 my $stylesheet = "gitweb.css";
44 # source of projects list
45 #my $projects_list = $projectroot;
46 my $projects_list = "index/index.aux";
48 # default blob_plain mimetype and default charset for text/plain blob
49 my $default_blob_plain_mimetype = 'text/plain';
50 my $default_text_plain_charset = 'utf-8'; # can be undefined
52 # input validation and dispatch
53 my $action = $cgi->param('a');
54 if (defined $action) {
55 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
57 die_error
(undef, "Invalid action parameter.");
59 if ($action eq "git-logo.png") {
62 } elsif ($action eq "opml") {
68 my $order = $cgi->param('o');
70 if ($order =~ m/[^0-9a-zA-Z_]/) {
72 die_error
(undef, "Invalid order parameter.");
76 my $project = $cgi->param('p');
77 if (defined $project) {
78 $project = validate_input
($project);
79 if (!defined($project)) {
80 die_error
(undef, "Invalid project parameter.");
82 if (!(-d
"$projectroot/$project")) {
84 die_error
(undef, "No such directory.");
86 if (!(-e
"$projectroot/$project/HEAD")) {
88 die_error
(undef, "No such project.");
90 $rss_link = "<link rel=\"alternate\" title=\"" . esc_param
($project) . " log\" href=\"" .
91 "$my_uri?" . esc_param
("p=$project;a=rss") . "\" type=\"application/rss+xml\"/>";
92 $ENV{'GIT_DIR'} = "$projectroot/$project";
98 my $file_name = $cgi->param('f');
99 if (defined $file_name) {
100 $file_name = validate_input
($file_name);
101 if (!defined($file_name)) {
102 die_error
(undef, "Invalid file parameter.");
106 my $hash = $cgi->param('h');
108 $hash = validate_input
($hash);
109 if (!defined($hash)) {
110 die_error
(undef, "Invalid hash parameter.");
114 my $hash_parent = $cgi->param('hp');
115 if (defined $hash_parent) {
116 $hash_parent = validate_input
($hash_parent);
117 if (!defined($hash_parent)) {
118 die_error
(undef, "Invalid hash parent parameter.");
122 my $hash_base = $cgi->param('hb');
123 if (defined $hash_base) {
124 $hash_base = validate_input
($hash_base);
125 if (!defined($hash_base)) {
126 die_error
(undef, "Invalid hash base parameter.");
130 my $page = $cgi->param('pg');
132 if ($page =~ m/[^0-9]$/) {
134 die_error
(undef, "Invalid page parameter.");
138 my $searchtext = $cgi->param('s');
139 if (defined $searchtext) {
140 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
142 die_error
(undef, "Invalid search parameter.");
144 $searchtext = quotemeta $searchtext;
150 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
153 if ($input =~ m/(^|\/)(|\
.|\
.\
.)($|\
/)/) {
156 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\
-\
+\#\
~\
%]/) {
162 if (!defined $action || $action eq "summary") {
165 } elsif ($action eq "heads") {
168 } elsif ($action eq "tags") {
171 } elsif ($action eq "blob") {
174 } elsif ($action eq "blob_plain") {
177 } elsif ($action eq "tree") {
180 } elsif ($action eq "rss") {
183 } elsif ($action eq "commit") {
186 } elsif ($action eq "log") {
189 } elsif ($action eq "blobdiff") {
192 } elsif ($action eq "blobdiff_plain") {
193 git_blobdiff_plain
();
195 } elsif ($action eq "commitdiff") {
198 } elsif ($action eq "commitdiff_plain") {
199 git_commitdiff_plain
();
201 } elsif ($action eq "history") {
204 } elsif ($action eq "search") {
207 } elsif ($action eq "shortlog") {
210 } elsif ($action eq "tag") {
213 } elsif ($action eq "blame") {
218 die_error
(undef, "Unknown action.");
222 # quote unsafe chars, but keep the slash, even when it's not
223 # correct, but quoted slashes look too horrible in bookmarks
226 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
232 # replace invalid utf8 character with SUBSTITUTION sequence
235 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
236 $str = escapeHTML
($str);
240 # git may return quoted and escaped filenames
243 if ($str =~ m/^"(.*)"$/) {
245 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
250 sub git_header_html
{
251 my $status = shift || "200 OK";
255 if (defined $project) {
256 $title .= " - $project";
257 if (defined $action) {
258 $title .= "/$action";
261 print $cgi->header(-type
=>'text/html', -charset
=> 'utf-8', -status
=> $status, -expires
=> $expires);
263 <?xml version="1.0" encoding="utf-8"?>
264 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
265 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
266 <!-- git web interface v$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
268 <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
269 <meta name="robots" content="index, nofollow"/>
270 <link rel="stylesheet" href="$stylesheet"/>
271 <title>$title</title>
276 print "<div class=\"page_header\">\n" .
277 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
278 "<img src=\"$my_uri?" . esc_param
("a=git-logo.png") . "\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
280 print $cgi->a({-href
=> esc_param
($home_link)}, "projects") . " / ";
281 if (defined $project) {
282 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, esc_html
($project));
283 if (defined $action) {
287 if (!defined $searchtext) {
292 $search_hash = $hash;
294 $search_hash = "HEAD";
296 $cgi->param("a", "search");
297 $cgi->param("h", $search_hash);
298 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
299 "<div class=\"search\">\n" .
300 $cgi->hidden(-name
=> "p") . "\n" .
301 $cgi->hidden(-name
=> "a") . "\n" .
302 $cgi->hidden(-name
=> "h") . "\n" .
303 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
305 $cgi->end_form() . "\n";
310 sub git_footer_html
{
311 print "<div class=\"page_footer\">\n";
312 if (defined $project) {
313 my $descr = git_read_description
($project);
314 if (defined $descr) {
315 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
317 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=rss"), -class => "rss_logo"}, "RSS") . "\n";
319 print $cgi->a({-href
=> "$my_uri?" . esc_param
("a=opml"), -class => "rss_logo"}, "OPML") . "\n";
327 my $status = shift || "403 Forbidden";
328 my $error = shift || "Malformed query, file missing or permission denied";
330 git_header_html
($status);
331 print "<div class=\"page_body\">\n" .
333 "$status - $error\n" .
343 open my $fd, "-|", "$gitbin/git-cat-file -t $hash" or return;
352 my $oENV = $ENV{'GIT_DIR'};
354 $ENV{'GIT_DIR'} = "$projectroot/$project";
355 if (open my $fd, "-|", "$gitbin/git-rev-parse", "--verify", "HEAD") {
358 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
363 $ENV{'GIT_DIR'} = $oENV;
371 open my $fd, "$projectroot/$path" or return undef;
375 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
380 sub git_read_description
{
383 open my $fd, "$projectroot/$path/description" or return undef;
395 open my $fd, "-|", "$gitbin/git-cat-file tag $tag_id" or return;
396 $tag{'id'} = $tag_id;
397 while (my $line = <$fd>) {
399 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
401 } elsif ($line =~ m/^type (.+)$/) {
403 } elsif ($line =~ m/^tag (.+)$/) {
405 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
409 } elsif ($line =~ m/--BEGIN/) {
410 push @comment, $line;
412 } elsif ($line eq "") {
416 push @comment, <$fd>;
417 $tag{'comment'} = \
@comment;
419 if (!defined $tag{'name'}) {
429 if ($age > 60*60*24*365*2) {
430 $age_str = (int $age/60/60/24/365);
431 $age_str .= " years ago";
432 } elsif ($age > 60*60*24*(365/12)*2) {
433 $age_str = int $age/60/60/24/(365/12);
434 $age_str .= " months ago";
435 } elsif ($age > 60*60*24*7*2) {
436 $age_str = int $age/60/60/24/7;
437 $age_str .= " weeks ago";
438 } elsif ($age > 60*60*24*2) {
439 $age_str = int $age/60/60/24;
440 $age_str .= " days ago";
441 } elsif ($age > 60*60*2) {
442 $age_str = int $age/60/60;
443 $age_str .= " hours ago";
444 } elsif ($age > 60*2) {
445 $age_str = int $age/60;
446 $age_str .= " min ago";
449 $age_str .= " sec ago";
451 $age_str .= " right now";
456 sub git_read_commit
{
457 my $commit_id = shift;
458 my $commit_text = shift;
463 if (defined $commit_text) {
464 @commit_lines = @
$commit_text;
467 open my $fd, "-|", "$gitbin/git-rev-list --header --parents --max-count=1 $commit_id" or return;
468 @commit_lines = split '\n', <$fd>;
473 my $header = shift @commit_lines;
474 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
477 ($co{'id'}, my @parents) = split ' ', $header;
478 $co{'parents'} = \
@parents;
479 $co{'parent'} = $parents[0];
480 while (my $line = shift @commit_lines) {
481 last if $line eq "\n";
482 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
484 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
486 $co{'author_epoch'} = $2;
487 $co{'author_tz'} = $3;
488 if ($co{'author'} =~ m/^([^<]+) </) {
489 $co{'author_name'} = $1;
491 $co{'author_name'} = $co{'author'};
493 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
494 $co{'committer'} = $1;
495 $co{'committer_epoch'} = $2;
496 $co{'committer_tz'} = $3;
497 $co{'committer_name'} = $co{'committer'};
498 $co{'committer_name'} =~ s/ <.*//;
501 if (!defined $co{'tree'}) {
505 foreach my $title (@commit_lines) {
508 $co{'title'} = chop_str
($title, 80, 5);
509 # remove leading stuff of merges to make the interesting part visible
510 if (length($title) > 50) {
511 $title =~ s/^Automatic //;
512 $title =~ s/^merge (of|with) /Merge ... /i;
513 if (length($title) > 50) {
514 $title =~ s/(http|rsync):\/\///;
516 if (length($title) > 50) {
517 $title =~ s/(master|www|rsync)\.//;
519 if (length($title) > 50) {
520 $title =~ s/kernel.org:?//;
522 if (length($title) > 50) {
523 $title =~ s/\/pub\/scm//;
526 $co{'title_short'} = chop_str
($title, 50, 5);
530 # remove added spaces
531 foreach my $line (@commit_lines) {
534 $co{'comment'} = \
@commit_lines;
536 my $age = time - $co{'committer_epoch'};
538 $co{'age_string'} = age_string
($age);
539 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
540 if ($age > 60*60*24*7*2) {
541 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
542 $co{'age_string_age'} = $co{'age_string'};
544 $co{'age_string_date'} = $co{'age_string'};
545 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
552 my $from_name = shift;
555 my $format = shift || "html";
557 my $from_tmp = "/dev/null";
558 my $to_tmp = "/dev/null";
561 # create tmp from-file
563 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
564 open my $fd2, "> $from_tmp";
565 open my $fd, "-|", "$gitbin/git-cat-file blob $from";
574 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
575 open my $fd2, "> $to_tmp";
576 open my $fd, "-|", "$gitbin/git-cat-file blob $to";
583 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
584 if ($format eq "plain") {
589 while (my $line = <$fd>) {
591 my $char = substr($line, 0, 1);
594 $color = " style=\"color:#008800;\"";
595 } elsif ($char eq "-") {
596 $color = " style=\"color:#cc0000;\"";
597 } elsif ($char eq "@") {
598 $color = " style=\"color:#990099;\"";
599 } elsif ($char eq "\\") {
603 while ((my $pos = index($line, "\t")) != -1) {
604 if (my $count = (8 - (($pos-1) % 8))) {
605 my $spaces = ' ' x
$count;
606 $line =~ s/\t/$spaces/;
609 print "<div class=\"pre\"$color>" . esc_html
($line) . "</div>\n";
623 my $mode = oct shift;
625 if (S_ISDIR
($mode & S_IFMT
)) {
627 } elsif (S_ISLNK
($mode)) {
629 } elsif (S_ISREG
($mode)) {
630 # git cares only about the executable bit
631 if ($mode & S_IXUSR
) {
644 my $add_len = shift || 10;
646 # allow only $len chars, but don't cut a word if it would fit in $add_len
647 # if it doesn't fit, cut it if it's still longer than the dots we would add
648 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
651 if (length($tail) > 4) {
658 my $mode = oct shift;
660 if (S_ISDIR
($mode & S_IFMT
)) {
662 } elsif (S_ISLNK
($mode)) {
664 } elsif (S_ISREG
($mode)) {
671 sub format_log_line_html
{
674 $line = esc_html
($line);
675 $line =~ s/ / /g;
676 if ($line =~ m/([0-9a-fA-F]{40})/) {
678 if (git_get_type
($hash_text) eq "commit") {
679 my $link = $cgi->a({-class => "text", -href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_text")}, $hash_text);
680 $line =~ s/$hash_text/$link/;
688 my $tz = shift || "-0000";
691 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
692 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
693 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
694 $date{'hour'} = $hour;
695 $date{'minute'} = $min;
696 $date{'mday'} = $mday;
697 $date{'day'} = $days[$wday];
698 $date{'month'} = $months[$mon];
699 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
700 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
702 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
703 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
704 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
705 $date{'hour_local'} = $hour;
706 $date{'minute_local'} = $min;
707 $date{'tz_local'} = $tz;
711 # git-logo (cached in browser for one day)
713 binmode STDOUT
, ':raw';
714 print $cgi->header(-type
=> 'image/png', -expires
=> '+1d');
715 # cat git-logo.png | hexdump -e '16/1 " %02x" "\n"' | sed 's/ /\\x/g'
716 print "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52" .
717 "\x00\x00\x00\x48\x00\x00\x00\x1b\x04\x03\x00\x00\x00\x2d\xd9\xd4" .
718 "\x2d\x00\x00\x00\x18\x50\x4c\x54\x45\xff\xff\xff\x60\x60\x5d\xb0" .
719 "\xaf\xaa\x00\x80\x00\xce\xcd\xc7\xc0\x00\x00\xe8\xe8\xe6\xf7\xf7" .
720 "\xf6\x95\x0c\xa7\x47\x00\x00\x00\x73\x49\x44\x41\x54\x28\xcf\x63" .
721 "\x48\x67\x20\x04\x4a\x5c\x18\x0a\x08\x2a\x62\x53\x61\x20\x02\x08" .
722 "\x0d\x69\x45\xac\xa1\xa1\x01\x30\x0c\x93\x60\x36\x26\x52\x91\xb1" .
723 "\x01\x11\xd6\xe1\x55\x64\x6c\x6c\xcc\x6c\x6c\x0c\xa2\x0c\x70\x2a" .
724 "\x62\x06\x2a\xc1\x62\x1d\xb3\x01\x02\x53\xa4\x08\xe8\x00\x03\x18" .
725 "\x26\x56\x11\xd4\xe1\x20\x97\x1b\xe0\xb4\x0e\x35\x24\x71\x29\x82" .
726 "\x99\x30\xb8\x93\x0a\x11\xb9\x45\x88\xc1\x8d\xa0\xa2\x44\x21\x06" .
727 "\x27\x41\x82\x40\x85\xc1\x45\x89\x20\x70\x01\x00\xa4\x3d\x21\xc5" .
728 "\x12\x1c\x9a\xfe\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\x82";
734 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
735 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
736 if (!defined $gcos) {
740 $owner =~ s/[,;].*$//;
741 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
744 sub git_read_projects
{
747 if (-d
$projects_list) {
748 # search in directory
749 my $dir = $projects_list;
750 opendir my $dh, $dir or return undef;
751 while (my $dir = readdir($dh)) {
752 if (-e
"$projectroot/$dir/HEAD") {
760 } elsif (-f
$projects_list) {
761 # read from file(url-encoded):
762 # 'git%2Fgit.git Linus+Torvalds'
763 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
764 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
765 open my $fd , $projects_list or return undef;
766 while (my $line = <$fd>) {
768 my ($path, $owner) = split ' ', $line;
769 $path = unescape
($path);
770 $owner = unescape
($owner);
771 if (!defined $path) {
774 if (-e
"$projectroot/$path/HEAD") {
777 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
784 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
788 sub git_get_project_config
{
791 return unless ($key);
792 $key =~ s/^gitweb\.//;
793 return if ($key =~ m/\W/);
795 my $val = qx(git
-repo
-config
--get gitweb
.$key);
799 sub git_get_project_config_bool
{
800 my $val = git_get_project_config
(@_);
801 if ($val and $val =~ m/true|yes|on/) {
804 return; # implicit false
807 sub git_project_list
{
808 my @list = git_read_projects
();
811 die_error
(undef, "No project found.");
813 foreach my $pr (@list) {
814 my $head = git_read_head
($pr->{'path'});
815 if (!defined $head) {
818 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
819 my %co = git_read_commit
($head);
823 $pr->{'commit'} = \
%co;
824 if (!defined $pr->{'descr'}) {
825 my $descr = git_read_description
($pr->{'path'}) || "";
826 $pr->{'descr'} = chop_str
($descr, 25, 5);
828 if (!defined $pr->{'owner'}) {
829 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
835 print "<div class=\"index_include\">\n";
836 open (my $fd, $home_text);
841 print "<table cellspacing=\"0\">\n" .
843 if (!defined($order) || (defined($order) && ($order eq "project"))) {
844 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
845 print "<th>Project</th>\n";
847 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=project")}, "Project") . "</th>\n";
849 if (defined($order) && ($order eq "descr")) {
850 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
851 print "<th>Description</th>\n";
853 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=descr")}, "Description") . "</th>\n";
855 if (defined($order) && ($order eq "owner")) {
856 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
857 print "<th>Owner</th>\n";
859 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=owner")}, "Owner") . "</th>\n";
861 if (defined($order) && ($order eq "age")) {
862 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
863 print "<th>Last Change</th>\n";
865 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=age")}, "Last Change") . "</th>\n";
867 print "<th></th>\n" .
870 foreach my $pr (@projects) {
872 print "<tr class=\"dark\">\n";
874 print "<tr class=\"light\">\n";
877 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=summary"), -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
878 "<td>$pr->{'descr'}</td>\n" .
879 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
881 if ($pr->{'commit'}{'age'} < 60*60*2) {
882 $colored_age = "<span style =\"color: #009900;\"><b><i>$pr->{'commit'}{'age_string'}</i></b></span>";
883 } elsif ($pr->{'commit'}{'age'} < 60*60*24*2) {
884 $colored_age = "<span style =\"color: #009900;\"><i>$pr->{'commit'}{'age_string'}</i></span>";
886 $colored_age = "<i>$pr->{'commit'}{'age_string'}</i>";
888 print "<td>$colored_age</td>\n" .
889 "<td class=\"link\">" .
890 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=summary")}, "summary") .
891 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=shortlog")}, "shortlog") .
892 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=log")}, "log") .
901 my $type = shift || "";
903 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
904 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
905 open my $fd, "$projectroot/$project/info/refs" or return;
906 while (my $line = <$fd>) {
908 if ($line =~ m/^([0-9a-fA-F]{40})\t.*$type\/([^\
^]+)/) {
909 if (defined $refs{$1}) {
910 $refs{$1} .= " / $2";
925 opendir my $dh, "$projectroot/$project/$ref_dir";
926 while (my $dir = readdir($dh)) {
927 if ($dir =~ m/^\./) {
930 if (-d
"$projectroot/$project/$ref_dir/$dir") {
931 opendir my $dh2, "$projectroot/$project/$ref_dir/$dir";
932 my @subdirs = grep !m/^\./, readdir $dh2;
934 foreach my $subdir (@subdirs) {
935 push @refs, "$dir/$subdir"
942 foreach my $ref_file (@refs) {
943 my $ref_id = git_read_hash
("$project/$ref_dir/$ref_file");
944 my $type = git_get_type
($ref_id) || next;
947 $ref_item{'type'} = $type;
948 $ref_item{'id'} = $ref_id;
949 $ref_item{'epoch'} = 0;
950 $ref_item{'age'} = "unknown";
951 if ($type eq "tag") {
952 my %tag = git_read_tag
($ref_id);
953 $ref_item{'comment'} = $tag{'comment'};
954 if ($tag{'type'} eq "commit") {
955 %co = git_read_commit
($tag{'object'});
956 $ref_item{'epoch'} = $co{'committer_epoch'};
957 $ref_item{'age'} = $co{'age_string'};
958 } elsif (defined($tag{'epoch'})) {
959 my $age = time - $tag{'epoch'};
960 $ref_item{'epoch'} = $tag{'epoch'};
961 $ref_item{'age'} = age_string
($age);
963 $ref_item{'reftype'} = $tag{'type'};
964 $ref_item{'name'} = $tag{'name'};
965 $ref_item{'refid'} = $tag{'object'};
966 } elsif ($type eq "commit"){
967 %co = git_read_commit
($ref_id);
968 $ref_item{'reftype'} = "commit";
969 $ref_item{'name'} = $ref_file;
970 $ref_item{'title'} = $co{'title'};
971 $ref_item{'refid'} = $ref_id;
972 $ref_item{'epoch'} = $co{'committer_epoch'};
973 $ref_item{'age'} = $co{'age_string'};
976 push @reflist, \
%ref_item;
979 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
984 my $descr = git_read_description
($project) || "none";
985 my $head = git_read_head
($project);
986 my %co = git_read_commit
($head);
987 my %cd = date_str
($co{'committer_epoch'}, $co{'committer_tz'});
990 if (-f
$projects_list) {
991 open (my $fd , $projects_list);
992 while (my $line = <$fd>) {
994 my ($pr, $ow) = split ' ', $line;
997 if ($pr eq $project) {
998 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
1004 if (!defined $owner) {
1005 $owner = get_file_owner
("$projectroot/$project");
1008 my $refs = read_info_ref
();
1010 print "<div class=\"page_nav\">\n" .
1012 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1013 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1014 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$head")}, "commit") .
1015 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1016 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree")}, "tree") .
1019 print "<div class=\"title\"> </div>\n";
1020 print "<table cellspacing=\"0\">\n" .
1021 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
1022 "<tr><td>owner</td><td>$owner</td></tr>\n" .
1023 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
1025 open my $fd, "-|", "$gitbin/git-rev-list --max-count=17 " . git_read_head
($project) or die_error
(undef, "Open failed.");
1026 my (@revlist) = map { chomp; $_ } <$fd>;
1029 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog"), -class => "title"}, "shortlog") .
1032 print "<table cellspacing=\"0\">\n";
1034 foreach my $commit (@revlist) {
1035 my %co = git_read_commit
($commit);
1036 my %ad = date_str
($co{'author_epoch'});
1038 print "<tr class=\"dark\">\n";
1040 print "<tr class=\"light\">\n";
1045 if (defined $refs->{$commit}) {
1046 $ref = " <span class=\"tag\">" . esc_html
($refs->{$commit}) . "</span>";
1048 print "<td><i>$co{'age_string'}</i></td>\n" .
1049 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
1051 if (length($co{'title_short'}) < length($co{'title'})) {
1052 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list", -title
=> "$co{'title'}"},
1053 "<b>" . esc_html
($co{'title_short'}) . "$ref</b>");
1055 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list"},
1056 "<b>" . esc_html
($co{'title'}) . "$ref</b>");
1059 "<td class=\"link\">" .
1060 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
1061 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1065 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "...") . "</td>\n" .
1072 my $taglist = git_read_refs
("refs/tags");
1073 if (defined @
$taglist) {
1075 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tags"), -class => "title"}, "tags") .
1078 print "<table cellspacing=\"0\">\n";
1080 foreach my $entry (@
$taglist) {
1082 my $comment_lines = $tag{'comment'};
1083 my $comment = shift @
$comment_lines;
1084 if (defined($comment)) {
1085 $comment = chop_str
($comment, 30, 5);
1088 print "<tr class=\"dark\">\n";
1090 print "<tr class=\"light\">\n";
1094 print "<td><i>$tag{'age'}</i></td>\n" .
1096 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), -class => "list"},
1097 "<b>" . esc_html
($tag{'name'}) . "</b>") .
1100 if (defined($comment)) {
1101 print $cgi->a({-class => "list", -href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, $comment);
1104 "<td class=\"link\">";
1105 if ($tag{'type'} eq "tag") {
1106 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
1108 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1109 if ($tag{'reftype'} eq "commit") {
1110 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1111 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'refid'}")}, "log");
1116 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tags")}, "...") . "</td>\n" .
1124 my $headlist = git_read_refs
("refs/heads");
1125 if (defined @
$headlist) {
1127 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=heads"), -class => "title"}, "heads") .
1130 print "<table cellspacing=\"0\">\n";
1132 foreach my $entry (@
$headlist) {
1135 print "<tr class=\"dark\">\n";
1137 print "<tr class=\"light\">\n";
1141 print "<td><i>$tag{'age'}</i></td>\n" .
1143 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}"), -class => "list"},
1144 "<b>" . esc_html
($tag{'name'}) . "</b>") .
1146 "<td class=\"link\">" .
1147 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1148 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'name'}")}, "log") .
1152 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=heads")}, "...") . "</td>\n" .
1163 my $head = git_read_head
($project);
1165 print "<div class=\"page_nav\">\n" .
1166 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1167 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1168 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1169 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$head")}, "commit") .
1170 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1171 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1174 my %tag = git_read_tag
($hash);
1176 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html
($tag{'name'})) . "\n" .
1178 print "<div class=\"title_text\">\n" .
1179 "<table cellspacing=\"0\">\n" .
1181 "<td>object</td>\n" .
1182 "<td>" . $cgi->a({-class => "list", -href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'object'}) . "</td>\n" .
1183 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'type'}) . "</td>\n" .
1185 if (defined($tag{'author'})) {
1186 my %ad = date_str
($tag{'epoch'}, $tag{'tz'});
1187 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
1188 print "<tr><td></td><td>" . $ad{'rfc2822'} . sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) . "</td></tr>\n";
1190 print "</table>\n\n" .
1192 print "<div class=\"page_body\">";
1193 my $comment = $tag{'comment'};
1194 foreach my $line (@
$comment) {
1195 print esc_html
($line) . "<br/>\n";
1203 die_error
('403 Permission denied', "Permission denied.") if (!git_get_project_config_bool
('blame'));
1204 die_error
('404 Not Found', "What file will it be, master?") if (!$file_name);
1205 $hash_base ||= git_read_head
($project);
1206 die_error
(undef, "Reading commit failed.") unless ($hash_base);
1207 my %co = git_read_commit
($hash_base)
1208 or die_error
(undef, "Reading commit failed.");
1209 if (!defined $hash) {
1210 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
1211 or die_error
(undef, "Error lookup file.");
1213 open ($fd, "-|", "$gitbin/git-annotate", '-l', '-t', '-r', $file_name, $hash_base)
1214 or die_error
(undef, "Open failed.");
1216 print "<div class=\"page_nav\">\n" .
1217 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1218 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1219 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1220 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base")}, "commit") .
1221 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1222 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") . "<br/>\n";
1223 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") .
1224 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;f=$file_name")}, "head") . "<br/>\n";
1227 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html
($co{'title'})) .
1229 print "<div class=\"page_path\"><b>" . esc_html
($file_name) . "</b></div>\n";
1230 print "<div class=\"page_body\">\n";
1232 <table style="border-collapse: collapse;">
1241 my @line_class = (qw(light dark));
1242 my $line_class_len = scalar (@line_class);
1243 my $line_class_num = $#line_class;
1244 while (my $line = <$fd>) {
1256 $line_class_num = ($line_class_num + 1) % $line_class_len;
1258 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) \+\d\d\d\d\t(\d+)\)(.*)$/) {
1265 print qq( <tr
><td colspan
="5" style
="color: red; background-color: yellow;">Unable to parse
: $line</td></tr
>\n);
1268 $short_rev = substr ($long_rev, 0, 8);
1269 $age = time () - $time;
1270 $age_str = age_string
($age);
1271 $age_str =~ s/ / /g;
1272 $age_style = 'font-style: italic;';
1273 $age_style .= ' color: #009900; background: transparent;' if ($age < 60*60*24*2);
1274 $age_style .= ' font-weight: bold;' if ($age < 60*60*2);
1275 $author = esc_html
($author);
1276 $author =~ s/ / /g;
1278 while ((my $pos = index($data, "\t")) != -1) {
1279 if (my $count = (8 - ($pos % 8))) {
1280 my $spaces = ' ' x
$count;
1281 $data =~ s/\t/$spaces/;
1284 $data = esc_html
($data);
1285 $data =~ s/ / /g;
1288 <tr class="$line_class[$line_class_num]">
1289 <td style="font-family: monospace;"><a href="$my_uri?${\esc_param ("p=$project;a=commit;h=$long_rev")}" class="text">$short_rev..</a></td>
1290 <td style="$age_style">$age_str</td>
1292 <td style="text-align: right;"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
1293 <td style="font-family: monospace;">$data</td>
1296 } # while (my $line = <$fd>)
1297 print "</table>\n\n";
1298 close $fd or print "Reading blob failed.\n";
1304 my $head = git_read_head
($project);
1306 print "<div class=\"page_nav\">\n" .
1307 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1308 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1309 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1310 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$head")}, "commit") .
1311 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1312 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1315 my $taglist = git_read_refs
("refs/tags");
1317 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary"), -class => "title"}, " ") .
1319 print "<table cellspacing=\"0\">\n";
1321 if (defined @
$taglist) {
1322 foreach my $entry (@
$taglist) {
1324 my $comment_lines = $tag{'comment'};
1325 my $comment = shift @
$comment_lines;
1326 if (defined($comment)) {
1327 $comment = chop_str
($comment, 30, 5);
1330 print "<tr class=\"dark\">\n";
1332 print "<tr class=\"light\">\n";
1335 print "<td><i>$tag{'age'}</i></td>\n" .
1337 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), -class => "list"},
1338 "<b>" . esc_html
($tag{'name'}) . "</b>") .
1341 if (defined($comment)) {
1342 print $cgi->a({-class => "list", -href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, $comment);
1345 "<td class=\"link\">";
1346 if ($tag{'type'} eq "tag") {
1347 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
1349 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1350 if ($tag{'reftype'} eq "commit") {
1351 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1352 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'refid'}")}, "log");
1363 my $head = git_read_head
($project);
1365 print "<div class=\"page_nav\">\n" .
1366 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1367 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1368 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1369 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$head")}, "commit") .
1370 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1371 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1374 my $taglist = git_read_refs
("refs/heads");
1376 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary"), -class => "title"}, " ") .
1378 print "<table cellspacing=\"0\">\n";
1380 if (defined @
$taglist) {
1381 foreach my $entry (@
$taglist) {
1384 print "<tr class=\"dark\">\n";
1386 print "<tr class=\"light\">\n";
1389 print "<td><i>$tag{'age'}</i></td>\n" .
1391 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}"), -class => "list"}, "<b>" . esc_html
($tag{'name'}) . "</b>") .
1393 "<td class=\"link\">" .
1394 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1395 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'name'}")}, "log") .
1404 sub git_get_hash_by_path
{
1406 my $path = shift || return undef;
1409 my @parts = split '/', $path;
1410 while (my $part = shift @parts) {
1411 open my $fd, "-|", "$gitbin/git-ls-tree $tree" or die_error
(undef, "Open git-ls-tree failed.");
1412 my (@entries) = map { chomp; $_ } <$fd>;
1413 close $fd or return undef;
1414 foreach my $line (@entries) {
1415 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1416 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1420 my $t_name = validate_input
(unquote
($4));
1421 if ($t_name eq $part) {
1425 if ($t_type eq "tree") {
1435 if (!defined $hash && defined $file_name) {
1436 my $base = $hash_base || git_read_head
($project);
1437 $hash = git_get_hash_by_path
($base, $file_name, "blob") || die_error
(undef, "Error lookup file.");
1439 my $have_blame = git_get_project_config_bool
('blame');
1440 open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or die_error
(undef, "Open failed.");
1442 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
1443 print "<div class=\"page_nav\">\n" .
1444 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1445 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1446 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1447 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base")}, "commit") .
1448 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1449 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") . "<br/>\n";
1450 if (defined $file_name) {
1452 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;h=$hash;hb=$hash_base;f=$file_name")}, "blame") . " | ";
1454 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$hash;f=$file_name")}, "plain") .
1455 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;hb=HEAD;f=$file_name")}, "head") . "<br/>\n";
1457 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$hash")}, "plain") . "<br/>\n";
1461 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html
($co{'title'})) .
1464 print "<div class=\"page_nav\">\n" .
1465 "<br/><br/></div>\n" .
1466 "<div class=\"title\">$hash</div>\n";
1468 if (defined $file_name) {
1469 print "<div class=\"page_path\"><b>" . esc_html
($file_name) . "</b></div>\n";
1471 print "<div class=\"page_body\">\n";
1473 while (my $line = <$fd>) {
1476 while ((my $pos = index($line, "\t")) != -1) {
1477 if (my $count = (8 - ($pos % 8))) {
1478 my $spaces = ' ' x
$count;
1479 $line =~ s/\t/$spaces/;
1482 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", $nr, $nr, $nr, esc_html
($line);
1484 close $fd or print "Reading blob failed.\n";
1489 sub git_blob_plain_mimetype
{
1491 my $filename = shift;
1494 return $default_blob_plain_mimetype unless $fd;
1497 return 'text/plain' .
1498 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
1499 } elsif (! $filename) {
1500 return 'application/octet-stream';
1501 } elsif ($filename =~ m/\.png$/i) {
1503 } elsif ($filename =~ m/\.gif$/i) {
1505 } elsif ($filename =~ m/\.jpe?g$/i) {
1506 return 'image/jpeg';
1508 return 'application/octet-stream';
1512 sub git_blob_plain
{
1513 open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or return;
1514 my $type = git_blob_plain_mimetype
($fd, $file_name);
1516 # save as filename, even when no $file_name is given
1517 my $save_as = "$hash";
1518 if (defined $file_name) {
1519 $save_as = $file_name;
1520 } elsif ($type =~ m/^text\//) {
1524 print $cgi->header(-type
=> "$type", '-content-disposition' => "inline; filename=\"$save_as\"");
1526 binmode STDOUT
, ':raw' unless $type =~ m/^text\//;
1528 binmode STDOUT
, ':utf8' unless $type =~ m/^text\//;
1534 if (!defined $hash) {
1535 $hash = git_read_head
($project);
1536 if (defined $file_name) {
1537 my $base = $hash_base || $hash;
1538 $hash = git_get_hash_by_path
($base, $file_name, "tree");
1540 if (!defined $hash_base) {
1545 open my $fd, "-|", "$gitbin/git-ls-tree -z $hash" or die_error
(undef, "Open git-ls-tree failed.");
1546 chomp (my (@entries) = <$fd>);
1547 close $fd or die_error
(undef, "Reading tree failed.");
1550 my $refs = read_info_ref
();
1552 if (defined $refs->{$hash_base}) {
1553 $ref = " <span class=\"tag\">" . esc_html
($refs->{$hash_base}) . "</span>";
1558 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
1559 $base_key = ";hb=$hash_base";
1560 print "<div class=\"page_nav\">\n" .
1561 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1562 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash_base")}, "shortlog") .
1563 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash_base")}, "log") .
1564 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base")}, "commit") .
1565 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1570 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html
($co{'title'}) . $ref) . "\n" .
1573 print "<div class=\"page_nav\">\n";
1574 print "<br/><br/></div>\n";
1575 print "<div class=\"title\">$hash</div>\n";
1577 if (defined $file_name) {
1578 $base = esc_html
("$file_name/");
1579 print "<div class=\"page_path\"><b>/" . esc_html
($file_name) . "</b></div>\n";
1581 print "<div class=\"page_path\"><b>/</b></div>\n";
1583 print "<div class=\"page_body\">\n";
1584 print "<table cellspacing=\"0\">\n";
1586 foreach my $line (@entries) {
1587 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1588 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1592 my $t_name = validate_input
($4);
1594 print "<tr class=\"dark\">\n";
1596 print "<tr class=\"light\">\n";
1599 print "<td style=\"font-family:monospace\">" . mode_str
($t_mode) . "</td>\n";
1600 if ($t_type eq "blob") {
1601 print "<td class=\"list\">" .
1602 $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)) .
1604 "<td class=\"link\">" .
1605 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name")}, "blob") .
1606 # " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$t_hash$base_key;f=$base$t_name")}, "blame") .
1607 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;h=$hash_base;f=$base$t_name")}, "history") .
1609 } elsif ($t_type eq "tree") {
1610 print "<td class=\"list\">" .
1611 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, esc_html
($t_name)) .
1613 "<td class=\"link\">" .
1614 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, "tree") .
1619 print "</table>\n" .
1625 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
1626 open my $fd, "-|", "$gitbin/git-rev-list --max-count=150 " . git_read_head
($project) or die_error
(undef, "Open failed.");
1627 my (@revlist) = map { chomp; $_ } <$fd>;
1628 close $fd or die_error
(undef, "Reading rev-list failed.");
1629 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
1630 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1631 "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
1632 print "<channel>\n";
1633 print "<title>$project</title>\n".
1634 "<link>" . esc_html
("$my_url?p=$project;a=summary") . "</link>\n".
1635 "<description>$project log</description>\n".
1636 "<language>en</language>\n";
1638 for (my $i = 0; $i <= $#revlist; $i++) {
1639 my $commit = $revlist[$i];
1640 my %co = git_read_commit
($commit);
1641 # we read 150, we always show 30 and the ones more recent than 48 hours
1642 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
1645 my %cd = date_str
($co{'committer_epoch'});
1646 open $fd, "-|", "$gitbin/git-diff-tree -r $co{'parent'} $co{'id'}" or next;
1647 my @difftree = map { chomp; $_ } <$fd>;
1651 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
1653 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
1654 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
1655 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
1656 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
1657 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
1658 "<content:encoded>" .
1660 my $comment = $co{'comment'};
1661 foreach my $line (@
$comment) {
1662 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
1663 print "$line<br/>\n";
1666 foreach my $line (@difftree) {
1667 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
1670 my $file = validate_input
(unquote
($7));
1671 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
1672 print "$file<br/>\n";
1675 "</content:encoded>\n" .
1678 print "</channel></rss>";
1682 my @list = git_read_projects
();
1684 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
1685 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1686 "<opml version=\"1.0\">\n".
1688 " <title>Git OPML Export</title>\n".
1691 "<outline text=\"git RSS feeds\">\n";
1693 foreach my $pr (@list) {
1695 my $head = git_read_head
($proj{'path'});
1696 if (!defined $head) {
1699 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
1700 my %co = git_read_commit
($head);
1705 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
1706 my $rss = "$my_url?p=$proj{'path'};a=rss";
1707 my $html = "$my_url?p=$proj{'path'};a=summary";
1708 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
1710 print "</outline>\n".
1716 my $head = git_read_head
($project);
1717 if (!defined $hash) {
1720 if (!defined $page) {
1723 my $refs = read_info_ref
();
1725 print "<div class=\"page_nav\">\n";
1726 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1727 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash")}, "shortlog") .
1729 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash")}, "commit") .
1730 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
1731 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$hash;hb=$hash")}, "tree") . "<br/>\n";
1733 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
1734 open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error
(undef, "Open failed.");
1735 my (@revlist) = map { chomp; $_ } <$fd>;
1738 if ($hash ne $head || $page) {
1739 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "HEAD");
1745 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash;pg=" . ($page-1)), -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1747 print " ⋅ prev";
1749 if ($#revlist >= (100 * ($page+1)-1)) {
1751 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash;pg=" . ($page+1)), -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1753 print " ⋅ next";
1759 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary"), -class => "title"}, " ") .
1761 my %co = git_read_commit
($hash);
1762 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
1764 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
1765 my $commit = $revlist[$i];
1767 if (defined $refs->{$commit}) {
1768 $ref = " <span class=\"tag\">" . esc_html
($refs->{$commit}) . "</span>";
1770 my %co = git_read_commit
($commit);
1772 my %ad = date_str
($co{'author_epoch'});
1774 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "title"},
1775 "<span class=\"age\">$co{'age_string'}</span>" . esc_html
($co{'title'}) . $ref) . "\n";
1777 print "<div class=\"title_text\">\n" .
1778 "<div class=\"log_link\">\n" .
1779 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
1780 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1783 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
1785 "<div class=\"log_body\">\n";
1786 my $comment = $co{'comment'};
1788 foreach my $line (@
$comment) {
1789 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1800 print format_log_line_html
($line) . "<br/>\n";
1811 my %co = git_read_commit
($hash);
1813 die_error
(undef, "Unknown commit object.");
1815 my %ad = date_str
($co{'author_epoch'}, $co{'author_tz'});
1816 my %cd = date_str
($co{'committer_epoch'}, $co{'committer_tz'});
1820 my $parent = $co{'parent'};
1821 if (!defined $parent) {
1825 open my $fd, "-|", "$gitbin/git-diff-tree -r -M $root $parent $hash" or die_error
(undef, "Open failed.");
1826 @difftree = map { chomp; $_ } <$fd>;
1827 close $fd or die_error
(undef, "Reading diff-tree failed.");
1829 # non-textual hash id's can be cached
1831 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
1834 my $refs = read_info_ref
();
1836 if (defined $refs->{$co{'id'}}) {
1837 $ref = " <span class=\"tag\">" . esc_html
($refs->{$co{'id'}}) . "</span>";
1839 git_header_html
(undef, $expires);
1840 print "<div class=\"page_nav\">\n" .
1841 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1842 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash")}, "shortlog") .
1843 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash")}, "log") .
1845 if (defined $co{'parent'}) {
1846 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash")}, "commitdiff");
1848 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") . "\n" .
1849 "<br/><br/></div>\n";
1850 if (defined $co{'parent'}) {
1852 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash"), -class => "title"}, esc_html
($co{'title'}) . $ref) . "\n" .
1856 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash"), -class => "title"}, esc_html
($co{'title'})) . "\n" .
1859 print "<div class=\"title_text\">\n" .
1860 "<table cellspacing=\"0\">\n";
1861 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
1863 "<td></td><td> $ad{'rfc2822'}";
1864 if ($ad{'hour_local'} < 6) {
1865 printf(" (<span style=\"color: #cc0000;\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1867 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1871 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
1872 print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
1873 print "<tr><td>commit</td><td style=\"font-family:monospace\">$co{'id'}</td></tr>\n";
1876 "<td style=\"font-family:monospace\">" .
1877 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash"), class => "list"}, $co{'tree'}) .
1879 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
1882 my $parents = $co{'parents'};
1883 foreach my $par (@
$parents) {
1886 "<td style=\"font-family:monospace\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$par"), class => "list"}, $par) . "</td>" .
1887 "<td class=\"link\">" .
1888 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$par")}, "commit") .
1889 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash;hp=$par")}, "commitdiff") .
1895 print "<div class=\"page_body\">\n";
1896 my $comment = $co{'comment'};
1899 foreach my $line (@
$comment) {
1900 # print only one empty line
1902 if ($empty || $signed) {
1909 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1911 print "<span style=\"color: #888888\">" . esc_html
($line) . "</span><br/>\n";
1914 print format_log_line_html
($line) . "<br/>\n";
1918 print "<div class=\"list_head\">\n";
1919 if ($#difftree > 10) {
1920 print(($#difftree + 1) . " files changed:\n");
1923 print "<table cellspacing=\"0\">\n";
1925 foreach my $line (@difftree) {
1926 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1927 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1928 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
1936 my $similarity = $6;
1937 my $file = validate_input
(unquote
($7));
1939 print "<tr class=\"dark\">\n";
1941 print "<tr class=\"light\">\n";
1944 if ($status eq "A") {
1946 if (S_ISREG
(oct $to_mode)) {
1947 $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
1950 $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" .
1951 "<td><span style=\"color: #008000;\">[new " . file_type
($to_mode) . "$mode_chng]</span></td>\n" .
1952 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob") . "</td>\n";
1953 } elsif ($status eq "D") {
1955 $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" .
1956 "<td><span style=\"color: #c00000;\">[deleted " . file_type
($from_mode). "]</span></td>\n" .
1957 "<td class=\"link\">" .
1958 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, "blob") .
1959 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;h=$hash;f=$file")}, "history") .
1961 } elsif ($status eq "M" || $status eq "T") {
1962 my $mode_chnge = "";
1963 if ($from_mode != $to_mode) {
1964 $mode_chnge = " <span style=\"color: #777777;\">[changed";
1965 if (((oct $from_mode) & S_IFMT
) != ((oct $to_mode) & S_IFMT
)) {
1966 $mode_chnge .= " from " . file_type
($from_mode) . " to " . file_type
($to_mode);
1968 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
1969 if (S_ISREG
($from_mode) && S_ISREG
($to_mode)) {
1970 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
1971 } elsif (S_ISREG
($to_mode)) {
1972 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
1975 $mode_chnge .= "]</span>\n";
1978 if ($to_id ne $from_id) {
1979 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));
1981 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file"), -class => "list"}, esc_html
($file));
1984 "<td>$mode_chnge</td>\n" .
1985 "<td class=\"link\">";
1986 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob");
1987 if ($to_id ne $from_id) {
1988 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file")}, "diff");
1990 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;h=$hash;f=$file")}, "history") . "\n";
1992 } elsif ($status eq "R") {
1993 my ($from_file, $to_file) = split "\t", $file;
1995 if ($from_mode != $to_mode) {
1996 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
1999 $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" .
2000 "<td><span style=\"color: #777777;\">[moved from " .
2001 $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)) .
2002 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
2003 "<td class=\"link\">" .
2004 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file")}, "blob");
2005 if ($to_id ne $from_id) {
2006 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file")}, "diff");
2017 mkdir($git_temp, 0700);
2019 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
2020 print "<div class=\"page_nav\">\n" .
2021 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
2022 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
2023 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
2024 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base")}, "commit") .
2025 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
2026 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") .
2028 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff_plain;h=$hash;hp=$hash_parent")}, "plain") .
2031 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html
($co{'title'})) . "\n" .
2034 print "<div class=\"page_nav\">\n" .
2035 "<br/><br/></div>\n" .
2036 "<div class=\"title\">$hash vs $hash_parent</div>\n";
2038 if (defined $file_name) {
2039 print "<div class=\"page_path\"><b>/" . esc_html
($file_name) . "</b></div>\n";
2041 print "<div class=\"page_body\">\n" .
2042 "<div class=\"diff_info\">blob:" .
2043 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name")}, $hash_parent) .
2045 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, $hash) .
2047 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
2052 sub git_blobdiff_plain
{
2053 mkdir($git_temp, 0700);
2054 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8');
2055 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
2058 sub git_commitdiff
{
2059 mkdir($git_temp, 0700);
2060 my %co = git_read_commit
($hash);
2062 die_error
(undef, "Unknown commit object.");
2064 if (!defined $hash_parent) {
2065 $hash_parent = $co{'parent'};
2067 open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error
(undef, "Open failed.");
2068 my (@difftree) = map { chomp; $_ } <$fd>;
2069 close $fd or die_error
(undef, "Reading diff-tree failed.");
2071 # non-textual hash id's can be cached
2073 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2076 my $refs = read_info_ref
();
2078 if (defined $refs->{$co{'id'}}) {
2079 $ref = " <span class=\"tag\">" . esc_html
($refs->{$co{'id'}}) . "</span>";
2081 git_header_html
(undef, $expires);
2082 print "<div class=\"page_nav\">\n" .
2083 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
2084 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash")}, "shortlog") .
2085 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash")}, "log") .
2086 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash")}, "commit") .
2088 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") . "<br/>\n";
2089 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent")}, "plain") . "\n" .
2092 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html
($co{'title'}) . $ref) . "\n" .
2094 print "<div class=\"page_body\">\n";
2095 my $comment = $co{'comment'};
2098 my @log = @
$comment;
2099 # remove first and empty lines after that
2101 while (defined $log[0] && $log[0] eq "") {
2104 foreach my $line (@log) {
2105 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2116 print format_log_line_html
($line) . "<br/>\n";
2119 foreach my $line (@difftree) {
2120 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2121 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2122 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2128 my $file = validate_input
(unquote
($6));
2129 if ($status eq "A") {
2130 print "<div class=\"diff_info\">" . file_type
($to_mode) . ":" .
2131 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id) . "(new)" .
2133 git_diff_print
(undef, "/dev/null", $to_id, "b/$file");
2134 } elsif ($status eq "D") {
2135 print "<div class=\"diff_info\">" . file_type
($from_mode) . ":" .
2136 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) . "(deleted)" .
2138 git_diff_print
($from_id, "a/$file", undef, "/dev/null");
2139 } elsif ($status eq "M") {
2140 if ($from_id ne $to_id) {
2141 print "<div class=\"diff_info\">" .
2142 file_type
($from_mode) . ":" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) .
2144 file_type
($to_mode) . ":" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id);
2146 git_diff_print
($from_id, "a/$file", $to_id, "b/$file");
2155 sub git_commitdiff_plain
{
2156 mkdir($git_temp, 0700);
2157 open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error
(undef, "Open failed.");
2158 my (@difftree) = map { chomp; $_ } <$fd>;
2159 close $fd or die_error
(undef, "Reading diff-tree failed.");
2161 # try to figure out the next tag after this commit
2163 my $refs = read_info_ref
("tags");
2164 open $fd, "-|", "$gitbin/git-rev-list HEAD";
2165 chomp (my (@commits) = <$fd>);
2167 foreach my $commit (@commits) {
2168 if (defined $refs->{$commit}) {
2169 $tagname = $refs->{$commit}
2171 if ($commit eq $hash) {
2176 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8', '-content-disposition' => "inline; filename=\"git-$hash.patch\"");
2177 my %co = git_read_commit
($hash);
2178 my %ad = date_str
($co{'author_epoch'}, $co{'author_tz'});
2179 my $comment = $co{'comment'};
2180 print "From: $co{'author'}\n" .
2181 "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
2182 "Subject: $co{'title'}\n";
2183 if (defined $tagname) {
2184 print "X-Git-Tag: $tagname\n";
2186 print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
2189 foreach my $line (@
$comment) {;
2194 foreach my $line (@difftree) {
2195 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2200 if ($status eq "A") {
2201 git_diff_print
(undef, "/dev/null", $to_id, "b/$file", "plain");
2202 } elsif ($status eq "D") {
2203 git_diff_print
($from_id, "a/$file", undef, "/dev/null", "plain");
2204 } elsif ($status eq "M") {
2205 git_diff_print
($from_id, "a/$file", $to_id, "b/$file", "plain");
2211 if (!defined $hash) {
2212 $hash = git_read_head
($project);
2214 my %co = git_read_commit
($hash);
2216 die_error
(undef, "Unknown commit object.");
2218 my $refs = read_info_ref
();
2220 print "<div class=\"page_nav\">\n" .
2221 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
2222 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
2223 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
2224 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash")}, "commit") .
2225 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2226 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
2230 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html
($co{'title'})) . "\n" .
2232 print "<div class=\"page_path\"><b>/" . esc_html
($file_name) . "</b><br/></div>\n";
2234 open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin -- \'$file_name\'";
2236 print "<table cellspacing=\"0\">\n";
2238 while (my $line = <$fd>) {
2239 if ($line =~ m/^([0-9a-fA-F]{40})/){
2243 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/ && (defined $commit)) {
2244 my %co = git_read_commit
($commit);
2249 if (defined $refs->{$commit}) {
2250 $ref = " <span class=\"tag\">" . esc_html
($refs->{$commit}) . "</span>";
2253 print "<tr class=\"dark\">\n";
2255 print "<tr class=\"light\">\n";
2258 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2259 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2260 "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list"}, "<b>" .
2261 esc_html
(chop_str
($co{'title'}, 50)) . "$ref</b>") . "</td>\n" .
2262 "<td class=\"link\">" .
2263 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
2264 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2265 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;hb=$commit;f=$file_name")}, "blob");
2266 my $blob = git_get_hash_by_path
($hash, $file_name);
2267 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2268 if (defined $blob && defined $blob_parent && $blob ne $blob_parent) {
2270 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=$file_name")},
2284 if (!defined $searchtext) {
2285 die_error
("", "Text field empty.");
2287 if (!defined $hash) {
2288 $hash = git_read_head
($project);
2290 my %co = git_read_commit
($hash);
2292 die_error
(undef, "Unknown commit object.");
2294 # pickaxe may take all resources of your box and run for several minutes
2295 # with every query - so decide by yourself how public you make this feature :)
2296 my $commit_search = 1;
2297 my $author_search = 0;
2298 my $committer_search = 0;
2299 my $pickaxe_search = 0;
2300 if ($searchtext =~ s/^author\\://i) {
2302 } elsif ($searchtext =~ s/^committer\\://i) {
2303 $committer_search = 1;
2304 } elsif ($searchtext =~ s/^pickaxe\\://i) {
2306 $pickaxe_search = 1;
2309 print "<div class=\"page_nav\">\n" .
2310 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary;h=$hash")}, "summary") .
2311 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
2312 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash")}, "log") .
2313 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash")}, "commit") .
2314 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2315 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
2320 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html
($co{'title'})) . "\n" .
2322 print "<table cellspacing=\"0\">\n";
2324 if ($commit_search) {
2326 open my $fd, "-|", "$gitbin/git-rev-list --header --parents $hash" or next;
2327 while (my $commit_text = <$fd>) {
2328 if (!grep m/$searchtext/i, $commit_text) {
2331 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
2334 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
2337 my @commit_lines = split "\n", $commit_text;
2338 my %co = git_read_commit
(undef, \
@commit_lines);
2343 print "<tr class=\"dark\">\n";
2345 print "<tr class=\"light\">\n";
2348 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2349 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2351 $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/>");
2352 my $comment = $co{'comment'};
2353 foreach my $line (@
$comment) {
2354 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2355 my $lead = esc_html
($1) || "";
2356 $lead = chop_str
($lead, 30, 10);
2357 my $match = esc_html
($2) || "";
2358 my $trail = esc_html
($3) || "";
2359 $trail = chop_str
($trail, 30, 10);
2360 my $text = "$lead<span style=\"color:#e00000\">$match</span>$trail";
2361 print chop_str
($text, 80, 5) . "<br/>\n";
2365 "<td class=\"link\">" .
2366 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2367 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2374 if ($pickaxe_search) {
2376 open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin -S\'$searchtext\'";
2379 while (my $line = <$fd>) {
2380 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2383 $set{'from_id'} = $3;
2385 $set{'id'} = $set{'to_id'};
2386 if ($set{'id'} =~ m/0{40}/) {
2387 $set{'id'} = $set{'from_id'};
2389 if ($set{'id'} =~ m/0{40}/) {
2393 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
2396 print "<tr class=\"dark\">\n";
2398 print "<tr class=\"light\">\n";
2401 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2402 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2404 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" .
2405 esc_html
(chop_str
($co{'title'}, 50)) . "</b><br/>");
2406 while (my $setref = shift @files) {
2408 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}"), class => "list"},
2409 "<span style=\"color:#e00000\">" . esc_html
($set{'file'}) . "</span>") .
2413 "<td class=\"link\">" .
2414 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2415 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2419 %co = git_read_commit
($1);
2429 my $head = git_read_head
($project);
2430 if (!defined $hash) {
2433 if (!defined $page) {
2436 my $refs = read_info_ref
();
2438 print "<div class=\"page_nav\">\n" .
2439 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
2441 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash")}, "log") .
2442 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash")}, "commit") .
2443 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2444 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$hash;hb=$hash")}, "tree") . "<br/>\n";
2446 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2447 open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error
(undef, "Open failed.");
2448 my (@revlist) = map { chomp; $_ } <$fd>;
2451 if ($hash ne $head || $page) {
2452 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "HEAD");
2458 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash;pg=" . ($page-1)), -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2460 print " ⋅ prev";
2462 if ($#revlist >= (100 * ($page+1)-1)) {
2464 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)), -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2466 print " ⋅ next";
2471 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary"), -class => "title"}, " ") .
2473 print "<table cellspacing=\"0\">\n";
2475 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2476 my $commit = $revlist[$i];
2478 if (defined $refs->{$commit}) {
2479 $ref = " <span class=\"tag\">" . esc_html
($refs->{$commit}) . "</span>";
2481 my %co = git_read_commit
($commit);
2482 my %ad = date_str
($co{'author_epoch'});
2484 print "<tr class=\"dark\">\n";
2486 print "<tr class=\"light\">\n";
2489 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2490 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
2492 if (length($co{'title_short'}) < length($co{'title'})) {
2493 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list", -title
=> "$co{'title'}"},
2494 "<b>" . esc_html
($co{'title_short'}) . "$ref</b>");
2496 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list"},
2497 "<b>" . esc_html
($co{'title_short'}) . "$ref</b>");
2500 "<td class=\"link\">" .
2501 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
2502 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2506 if ($#revlist >= (100 * ($page+1)-1)) {
2509 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)), -title
=> "Alt-n"}, "next") .