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 # input validation and dispatch
49 my $action = $cgi->param('a');
50 if (defined $action) {
51 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
53 die_error
(undef, "Invalid action parameter.");
55 if ($action eq "git-logo.png") {
58 } elsif ($action eq "opml") {
64 my $order = $cgi->param('o');
66 if ($order =~ m/[^0-9a-zA-Z_]/) {
68 die_error
(undef, "Invalid order parameter.");
72 my $project = $cgi->param('p');
73 if (defined $project) {
74 $project = validate_input
($project);
75 if (!defined($project)) {
76 die_error
(undef, "Invalid project parameter.");
78 if (!(-d
"$projectroot/$project")) {
80 die_error
(undef, "No such directory.");
82 if (!(-e
"$projectroot/$project/HEAD")) {
84 die_error
(undef, "No such project.");
86 $rss_link = "<link rel=\"alternate\" title=\"" . esc_param
($project) . " log\" href=\"" .
87 "$my_uri?" . esc_param
("p=$project;a=rss") . "\" type=\"application/rss+xml\"/>";
88 $ENV{'GIT_DIR'} = "$projectroot/$project";
94 my $file_name = $cgi->param('f');
95 if (defined $file_name) {
96 $file_name = validate_input
($file_name);
97 if (!defined($file_name)) {
98 die_error
(undef, "Invalid file parameter.");
102 my $hash = $cgi->param('h');
104 $hash = validate_input
($hash);
105 if (!defined($hash)) {
106 die_error
(undef, "Invalid hash parameter.");
110 my $hash_parent = $cgi->param('hp');
111 if (defined $hash_parent) {
112 $hash_parent = validate_input
($hash_parent);
113 if (!defined($hash_parent)) {
114 die_error
(undef, "Invalid hash parent parameter.");
118 my $hash_base = $cgi->param('hb');
119 if (defined $hash_base) {
120 $hash_base = validate_input
($hash_base);
121 if (!defined($hash_base)) {
122 die_error
(undef, "Invalid hash base parameter.");
126 my $page = $cgi->param('pg');
128 if ($page =~ m/[^0-9]$/) {
130 die_error
(undef, "Invalid page parameter.");
134 my $searchtext = $cgi->param('s');
135 if (defined $searchtext) {
136 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\
@ ]/) {
138 die_error
(undef, "Invalid search parameter.");
140 $searchtext = quotemeta $searchtext;
146 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
149 if ($input =~ m/(^|\/)(|\
.|\
.\
.)($|\
/)/) {
152 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\
-\
+\#\
~\
%]/) {
158 if (!defined $action || $action eq "summary") {
161 } elsif ($action eq "heads") {
164 } elsif ($action eq "tags") {
167 } elsif ($action eq "blob") {
170 } elsif ($action eq "blob_plain") {
173 } elsif ($action eq "tree") {
176 } elsif ($action eq "rss") {
179 } elsif ($action eq "commit") {
182 } elsif ($action eq "log") {
185 } elsif ($action eq "blobdiff") {
188 } elsif ($action eq "blobdiff_plain") {
189 git_blobdiff_plain
();
191 } elsif ($action eq "commitdiff") {
194 } elsif ($action eq "commitdiff_plain") {
195 git_commitdiff_plain
();
197 } elsif ($action eq "history") {
200 } elsif ($action eq "search") {
203 } elsif ($action eq "shortlog") {
206 } elsif ($action eq "tag") {
209 } elsif ($action eq "blame") {
214 die_error
(undef, "Unknown action.");
218 # quote unsafe chars, but keep the slash, even when it's not
219 # correct, but quoted slashes look too horrible in bookmarks
222 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
228 # replace invalid utf8 character with SUBSTITUTION sequence
231 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
232 $str = escapeHTML
($str);
236 # git may return quoted and escaped filenames
239 if ($str =~ m/^"(.*)"$/) {
241 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
246 sub git_header_html
{
247 my $status = shift || "200 OK";
251 if (defined $project) {
252 $title .= " - $project";
253 if (defined $action) {
254 $title .= "/$action";
257 print $cgi->header(-type
=>'text/html', -charset
=> 'utf-8', -status
=> $status, -expires
=> $expires);
259 <?xml version="1.0" encoding="utf-8"?>
260 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
261 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
262 <!-- git web interface v$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
264 <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
265 <meta name="robots" content="index, nofollow"/>
266 <link rel="stylesheet" href="$stylesheet"/>
267 <title>$title</title>
272 print "<div class=\"page_header\">\n" .
273 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
274 "<img src=\"$my_uri?" . esc_param
("a=git-logo.png") . "\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
276 print $cgi->a({-href
=> esc_param
($home_link)}, "projects") . " / ";
277 if (defined $project) {
278 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, esc_html
($project));
279 if (defined $action) {
283 if (!defined $searchtext) {
288 $search_hash = $hash;
290 $search_hash = "HEAD";
292 $cgi->param("a", "search");
293 $cgi->param("h", $search_hash);
294 print $cgi->startform(-method => "get", -action
=> $my_uri) .
295 "<div class=\"search\">\n" .
296 $cgi->hidden(-name
=> "p") . "\n" .
297 $cgi->hidden(-name
=> "a") . "\n" .
298 $cgi->hidden(-name
=> "h") . "\n" .
299 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
301 $cgi->end_form() . "\n";
306 sub git_footer_html
{
307 print "<div class=\"page_footer\">\n";
308 if (defined $project) {
309 my $descr = git_read_description
($project);
310 if (defined $descr) {
311 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
313 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=rss"), -class => "rss_logo"}, "RSS") . "\n";
315 print $cgi->a({-href
=> "$my_uri?" . esc_param
("a=opml"), -class => "rss_logo"}, "OPML") . "\n";
323 my $status = shift || "403 Forbidden";
324 my $error = shift || "Malformed query, file missing or permission denied";
326 git_header_html
($status);
327 print "<div class=\"page_body\">\n" .
329 "$status - $error\n" .
339 open my $fd, "-|", "$gitbin/git-cat-file -t $hash" or return;
348 my $oENV = $ENV{'GIT_DIR'};
350 $ENV{'GIT_DIR'} = "$projectroot/$project";
351 if (open my $fd, "-|", "$gitbin/git-rev-parse", "--verify", "HEAD") {
354 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
359 $ENV{'GIT_DIR'} = $oENV;
367 open my $fd, "$projectroot/$path" or return undef;
371 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
376 sub git_read_description
{
379 open my $fd, "$projectroot/$path/description" or return undef;
391 open my $fd, "-|", "$gitbin/git-cat-file tag $tag_id" or return;
392 $tag{'id'} = $tag_id;
393 while (my $line = <$fd>) {
395 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
397 } elsif ($line =~ m/^type (.+)$/) {
399 } elsif ($line =~ m/^tag (.+)$/) {
401 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
405 } elsif ($line =~ m/--BEGIN/) {
406 push @comment, $line;
408 } elsif ($line eq "") {
412 push @comment, <$fd>;
413 $tag{'comment'} = \
@comment;
415 if (!defined $tag{'name'}) {
425 if ($age > 60*60*24*365*2) {
426 $age_str = (int $age/60/60/24/365);
427 $age_str .= " years ago";
428 } elsif ($age > 60*60*24*(365/12)*2) {
429 $age_str = int $age/60/60/24/(365/12);
430 $age_str .= " months ago";
431 } elsif ($age > 60*60*24*7*2) {
432 $age_str = int $age/60/60/24/7;
433 $age_str .= " weeks ago";
434 } elsif ($age > 60*60*24*2) {
435 $age_str = int $age/60/60/24;
436 $age_str .= " days ago";
437 } elsif ($age > 60*60*2) {
438 $age_str = int $age/60/60;
439 $age_str .= " hours ago";
440 } elsif ($age > 60*2) {
441 $age_str = int $age/60;
442 $age_str .= " min ago";
445 $age_str .= " sec ago";
447 $age_str .= " right now";
452 sub git_read_commit
{
453 my $commit_id = shift;
454 my $commit_text = shift;
459 if (defined $commit_text) {
460 @commit_lines = @$commit_text;
463 open my $fd, "-|", "$gitbin/git-rev-list --header --parents --max-count=1 $commit_id" or return;
464 @commit_lines = split '\n', <$fd>;
469 my $header = shift @commit_lines;
470 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
473 ($co{'id'}, my @parents) = split ' ', $header;
474 $co{'parents'} = \
@parents;
475 $co{'parent'} = $parents[0];
476 while (my $line = shift @commit_lines) {
477 last if $line eq "\n";
478 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
480 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
482 $co{'author_epoch'} = $2;
483 $co{'author_tz'} = $3;
484 if ($co{'author'} =~ m/^([^<]+) </) {
485 $co{'author_name'} = $1;
487 $co{'author_name'} = $co{'author'};
489 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
490 $co{'committer'} = $1;
491 $co{'committer_epoch'} = $2;
492 $co{'committer_tz'} = $3;
493 $co{'committer_name'} = $co{'committer'};
494 $co{'committer_name'} =~ s/ <.*//;
497 if (!defined $co{'tree'}) {
501 foreach my $title (@commit_lines) {
504 $co{'title'} = chop_str
($title, 80, 5);
505 # remove leading stuff of merges to make the interesting part visible
506 if (length($title) > 50) {
507 $title =~ s/^Automatic //;
508 $title =~ s/^merge (of|with) /Merge ... /i;
509 if (length($title) > 50) {
510 $title =~ s/(http|rsync):\/\///;
512 if (length($title) > 50) {
513 $title =~ s/(master|www|rsync)\.//;
515 if (length($title) > 50) {
516 $title =~ s/kernel.org:?//;
518 if (length($title) > 50) {
519 $title =~ s/\/pub\/scm//;
522 $co{'title_short'} = chop_str
($title, 50, 5);
526 # remove added spaces
527 foreach my $line (@commit_lines) {
530 $co{'comment'} = \
@commit_lines;
532 my $age = time - $co{'committer_epoch'};
534 $co{'age_string'} = age_string
($age);
535 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
536 if ($age > 60*60*24*7*2) {
537 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
538 $co{'age_string_age'} = $co{'age_string'};
540 $co{'age_string_date'} = $co{'age_string'};
541 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
548 my $from_name = shift;
551 my $format = shift || "html";
553 my $from_tmp = "/dev/null";
554 my $to_tmp = "/dev/null";
557 # create tmp from-file
559 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
560 open my $fd2, "> $from_tmp";
561 open my $fd, "-|", "$gitbin/git-cat-file blob $from";
570 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
571 open my $fd2, "> $to_tmp";
572 open my $fd, "-|", "$gitbin/git-cat-file blob $to";
579 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
580 if ($format eq "plain") {
585 while (my $line = <$fd>) {
587 my $char = substr($line, 0, 1);
590 $color = " style=\"color:#008800;\"";
591 } elsif ($char eq "-") {
592 $color = " style=\"color:#cc0000;\"";
593 } elsif ($char eq "@") {
594 $color = " style=\"color:#990099;\"";
595 } elsif ($char eq "\\") {
599 while ((my $pos = index($line, "\t")) != -1) {
600 if (my $count = (8 - (($pos-1) % 8))) {
601 my $spaces = ' ' x
$count;
602 $line =~ s/\t/$spaces/;
605 print "<div class=\"pre\"$color>" . esc_html
($line) . "</div>\n";
619 my $mode = oct shift;
621 if (S_ISDIR
($mode & S_IFMT
)) {
623 } elsif (S_ISLNK
($mode)) {
625 } elsif (S_ISREG
($mode)) {
626 # git cares only about the executable bit
627 if ($mode & S_IXUSR
) {
640 my $add_len = shift || 10;
642 # allow only $len chars, but don't cut a word if it would fit in $add_len
643 # if it doesn't fit, cut it if it's still longer than the dots we would add
644 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@]{0,$add_len})(.*)/;
647 if (length($tail) > 4) {
654 my $mode = oct shift;
656 if (S_ISDIR
($mode & S_IFMT
)) {
658 } elsif (S_ISLNK
($mode)) {
660 } elsif (S_ISREG
($mode)) {
667 sub format_log_line_html
{
670 $line = esc_html
($line);
671 $line =~ s/ / /g;
672 if ($line =~ m/([0-9a-fA-F]{40})/) {
674 if (git_get_type
($hash_text) eq "commit") {
675 my $link = $cgi->a({-class => "text", -href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_text")}, $hash_text);
676 $line =~ s/$hash_text/$link/;
684 my $tz = shift || "-0000";
687 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
688 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
689 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
690 $date{'hour'} = $hour;
691 $date{'minute'} = $min;
692 $date{'mday'} = $mday;
693 $date{'day'} = $days[$wday];
694 $date{'month'} = $months[$mon];
695 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
696 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
698 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
699 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
700 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
701 $date{'hour_local'} = $hour;
702 $date{'minute_local'} = $min;
703 $date{'tz_local'} = $tz;
707 # git-logo (cached in browser for one day)
709 binmode STDOUT
, ':raw';
710 print $cgi->header(-type
=> 'image/png', -expires
=> '+1d');
711 # cat git-logo.png | hexdump -e '16/1 " %02x" "\n"' | sed 's/ /\\x/g'
712 print "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52" .
713 "\x00\x00\x00\x48\x00\x00\x00\x1b\x04\x03\x00\x00\x00\x2d\xd9\xd4" .
714 "\x2d\x00\x00\x00\x18\x50\x4c\x54\x45\xff\xff\xff\x60\x60\x5d\xb0" .
715 "\xaf\xaa\x00\x80\x00\xce\xcd\xc7\xc0\x00\x00\xe8\xe8\xe6\xf7\xf7" .
716 "\xf6\x95\x0c\xa7\x47\x00\x00\x00\x73\x49\x44\x41\x54\x28\xcf\x63" .
717 "\x48\x67\x20\x04\x4a\x5c\x18\x0a\x08\x2a\x62\x53\x61\x20\x02\x08" .
718 "\x0d\x69\x45\xac\xa1\xa1\x01\x30\x0c\x93\x60\x36\x26\x52\x91\xb1" .
719 "\x01\x11\xd6\xe1\x55\x64\x6c\x6c\xcc\x6c\x6c\x0c\xa2\x0c\x70\x2a" .
720 "\x62\x06\x2a\xc1\x62\x1d\xb3\x01\x02\x53\xa4\x08\xe8\x00\x03\x18" .
721 "\x26\x56\x11\xd4\xe1\x20\x97\x1b\xe0\xb4\x0e\x35\x24\x71\x29\x82" .
722 "\x99\x30\xb8\x93\x0a\x11\xb9\x45\x88\xc1\x8d\xa0\xa2\x44\x21\x06" .
723 "\x27\x41\x82\x40\x85\xc1\x45\x89\x20\x70\x01\x00\xa4\x3d\x21\xc5" .
724 "\x12\x1c\x9a\xfe\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\x82";
730 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
731 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
732 if (!defined $gcos) {
736 $owner =~ s/[,;].*$//;
737 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
740 sub git_read_projects
{
743 if (-d
$projects_list) {
744 # search in directory
745 my $dir = $projects_list;
746 opendir my $dh, $dir or return undef;
747 while (my $dir = readdir($dh)) {
748 if (-e
"$projectroot/$dir/HEAD") {
756 } elsif (-f
$projects_list) {
757 # read from file(url-encoded):
758 # 'git%2Fgit.git Linus+Torvalds'
759 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
760 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
761 open my $fd , $projects_list or return undef;
762 while (my $line = <$fd>) {
764 my ($path, $owner) = split ' ', $line;
765 $path = unescape
($path);
766 $owner = unescape
($owner);
767 if (!defined $path) {
770 if (-e
"$projectroot/$path/HEAD") {
773 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
780 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
784 sub git_get_project_config
{
787 return unless ($key);
788 $key =~ s/^gitweb\.//;
789 return if ($key =~ m/\W/);
791 my $val = qx(git-repo-config --get gitweb.$key);
795 sub git_get_project_config_bool
{
796 my $val = git_get_project_config
(@_);
797 if ($val and $val =~ m/true|yes|on/) {
800 return; # implicit false
803 sub git_project_list
{
804 my @list = git_read_projects
();
807 die_error
(undef, "No project found.");
809 foreach my $pr (@list) {
810 my $head = git_read_head
($pr->{'path'});
811 if (!defined $head) {
814 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
815 my %co = git_read_commit
($head);
819 $pr->{'commit'} = \
%co;
820 if (!defined $pr->{'descr'}) {
821 my $descr = git_read_description
($pr->{'path'}) || "";
822 $pr->{'descr'} = chop_str
($descr, 25, 5);
824 if (!defined $pr->{'owner'}) {
825 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
831 print "<div class=\"index_include\">\n";
832 open (my $fd, $home_text);
837 print "<table cellspacing=\"0\">\n" .
839 if (!defined($order) || (defined($order) && ($order eq "project"))) {
840 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
841 print "<th>Project</th>\n";
843 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=project")}, "Project") . "</th>\n";
845 if (defined($order) && ($order eq "descr")) {
846 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
847 print "<th>Description</th>\n";
849 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=descr")}, "Description") . "</th>\n";
851 if (defined($order) && ($order eq "owner")) {
852 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
853 print "<th>Owner</th>\n";
855 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=owner")}, "Owner") . "</th>\n";
857 if (defined($order) && ($order eq "age")) {
858 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
859 print "<th>Last Change</th>\n";
861 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=age")}, "Last Change") . "</th>\n";
863 print "<th></th>\n" .
866 foreach my $pr (@projects) {
868 print "<tr class=\"dark\">\n";
870 print "<tr class=\"light\">\n";
873 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=summary"), -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
874 "<td>$pr->{'descr'}</td>\n" .
875 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
877 if ($pr->{'commit'}{'age'} < 60*60*2) {
878 $colored_age = "<span style =\"color: #009900;\"><b><i>$pr->{'commit'}{'age_string'}</i></b></span>";
879 } elsif ($pr->{'commit'}{'age'} < 60*60*24*2) {
880 $colored_age = "<span style =\"color: #009900;\"><i>$pr->{'commit'}{'age_string'}</i></span>";
882 $colored_age = "<i>$pr->{'commit'}{'age_string'}</i>";
884 print "<td>$colored_age</td>\n" .
885 "<td class=\"link\">" .
886 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=summary")}, "summary") .
887 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=shortlog")}, "shortlog") .
888 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=log")}, "log") .
897 my $type = shift || "";
899 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
900 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
901 open my $fd, "$projectroot/$project/info/refs" or return;
902 while (my $line = <$fd>) {
904 if ($line =~ m/^([0-9a-fA-F]{40})\t.*$type\/([^\
^]+)/) {
905 if (defined $refs{$1}) {
906 $refs{$1} .= " / $2";
921 opendir my $dh, "$projectroot/$project/$ref_dir";
922 while (my $dir = readdir($dh)) {
923 if ($dir =~ m/^\./) {
926 if (-d
"$projectroot/$project/$ref_dir/$dir") {
927 opendir my $dh2, "$projectroot/$project/$ref_dir/$dir";
928 my @subdirs = grep !m/^\./, readdir $dh2;
930 foreach my $subdir (@subdirs) {
931 push @refs, "$dir/$subdir"
938 foreach my $ref_file (@refs) {
939 my $ref_id = git_read_hash
("$project/$ref_dir/$ref_file");
940 my $type = git_get_type
($ref_id) || next;
943 $ref_item{'type'} = $type;
944 $ref_item{'id'} = $ref_id;
945 $ref_item{'epoch'} = 0;
946 $ref_item{'age'} = "unknown";
947 if ($type eq "tag") {
948 my %tag = git_read_tag
($ref_id);
949 $ref_item{'comment'} = $tag{'comment'};
950 if ($tag{'type'} eq "commit") {
951 %co = git_read_commit
($tag{'object'});
952 $ref_item{'epoch'} = $co{'committer_epoch'};
953 $ref_item{'age'} = $co{'age_string'};
954 } elsif (defined($tag{'epoch'})) {
955 my $age = time - $tag{'epoch'};
956 $ref_item{'epoch'} = $tag{'epoch'};
957 $ref_item{'age'} = age_string
($age);
959 $ref_item{'reftype'} = $tag{'type'};
960 $ref_item{'name'} = $tag{'name'};
961 $ref_item{'refid'} = $tag{'object'};
962 } elsif ($type eq "commit"){
963 %co = git_read_commit
($ref_id);
964 $ref_item{'reftype'} = "commit";
965 $ref_item{'name'} = $ref_file;
966 $ref_item{'title'} = $co{'title'};
967 $ref_item{'refid'} = $ref_id;
968 $ref_item{'epoch'} = $co{'committer_epoch'};
969 $ref_item{'age'} = $co{'age_string'};
972 push @reflist, \
%ref_item;
975 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
980 my $descr = git_read_description
($project) || "none";
981 my $head = git_read_head
($project);
982 my %co = git_read_commit
($head);
983 my %cd = date_str
($co{'committer_epoch'}, $co{'committer_tz'});
986 if (-f
$projects_list) {
987 open (my $fd , $projects_list);
988 while (my $line = <$fd>) {
990 my ($pr, $ow) = split ' ', $line;
993 if ($pr eq $project) {
994 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
1000 if (!defined $owner) {
1001 $owner = get_file_owner
("$projectroot/$project");
1004 my $refs = read_info_ref
();
1006 print "<div class=\"page_nav\">\n" .
1008 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1009 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1010 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$head")}, "commit") .
1011 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1012 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree")}, "tree") .
1015 print "<div class=\"title\"> </div>\n";
1016 print "<table cellspacing=\"0\">\n" .
1017 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
1018 "<tr><td>owner</td><td>$owner</td></tr>\n" .
1019 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
1021 open my $fd, "-|", "$gitbin/git-rev-list --max-count=17 " . git_read_head
($project) or die_error
(undef, "Open failed.");
1022 my (@revlist) = map { chomp; $_ } <$fd>;
1025 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog"), -class => "title"}, "shortlog") .
1028 print "<table cellspacing=\"0\">\n";
1030 foreach my $commit (@revlist) {
1031 my %co = git_read_commit
($commit);
1032 my %ad = date_str
($co{'author_epoch'});
1034 print "<tr class=\"dark\">\n";
1036 print "<tr class=\"light\">\n";
1041 if (defined $refs->{$commit}) {
1042 $ref = " <span class=\"tag\">" . esc_html
($refs->{$commit}) . "</span>";
1044 print "<td><i>$co{'age_string'}</i></td>\n" .
1045 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
1047 if (length($co{'title_short'}) < length($co{'title'})) {
1048 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list", -title
=> "$co{'title'}"},
1049 "<b>" . esc_html
($co{'title_short'}) . "$ref</b>");
1051 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list"},
1052 "<b>" . esc_html
($co{'title'}) . "$ref</b>");
1055 "<td class=\"link\">" .
1056 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
1057 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1061 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "...") . "</td>\n" .
1068 my $taglist = git_read_refs
("refs/tags");
1069 if (defined @$taglist) {
1071 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tags"), -class => "title"}, "tags") .
1074 print "<table cellspacing=\"0\">\n";
1076 foreach my $entry (@$taglist) {
1078 my $comment_lines = $tag{'comment'};
1079 my $comment = shift @$comment_lines;
1080 if (defined($comment)) {
1081 $comment = chop_str
($comment, 30, 5);
1084 print "<tr class=\"dark\">\n";
1086 print "<tr class=\"light\">\n";
1090 print "<td><i>$tag{'age'}</i></td>\n" .
1092 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), -class => "list"},
1093 "<b>" . esc_html
($tag{'name'}) . "</b>") .
1096 if (defined($comment)) {
1097 print $cgi->a({-class => "list", -href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, $comment);
1100 "<td class=\"link\">";
1101 if ($tag{'type'} eq "tag") {
1102 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
1104 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1105 if ($tag{'reftype'} eq "commit") {
1106 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1107 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'refid'}")}, "log");
1112 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tags")}, "...") . "</td>\n" .
1120 my $headlist = git_read_refs
("refs/heads");
1121 if (defined @$headlist) {
1123 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=heads"), -class => "title"}, "heads") .
1126 print "<table cellspacing=\"0\">\n";
1128 foreach my $entry (@$headlist) {
1131 print "<tr class=\"dark\">\n";
1133 print "<tr class=\"light\">\n";
1137 print "<td><i>$tag{'age'}</i></td>\n" .
1139 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}"), -class => "list"},
1140 "<b>" . esc_html
($tag{'name'}) . "</b>") .
1142 "<td class=\"link\">" .
1143 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1144 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'name'}")}, "log") .
1148 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=heads")}, "...") . "</td>\n" .
1159 my $head = git_read_head
($project);
1161 print "<div class=\"page_nav\">\n" .
1162 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1163 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1164 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1165 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$head")}, "commit") .
1166 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1167 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1170 my %tag = git_read_tag
($hash);
1172 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html
($tag{'name'})) . "\n" .
1174 print "<div class=\"title_text\">\n" .
1175 "<table cellspacing=\"0\">\n" .
1177 "<td>object</td>\n" .
1178 "<td>" . $cgi->a({-class => "list", -href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'object'}) . "</td>\n" .
1179 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'type'}) . "</td>\n" .
1181 if (defined($tag{'author'})) {
1182 my %ad = date_str
($tag{'epoch'}, $tag{'tz'});
1183 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
1184 print "<tr><td></td><td>" . $ad{'rfc2822'} . sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) . "</td></tr>\n";
1186 print "</table>\n\n" .
1188 print "<div class=\"page_body\">";
1189 my $comment = $tag{'comment'};
1190 foreach my $line (@$comment) {
1191 print esc_html
($line) . "<br/>\n";
1199 die_error
('403 Permission denied', "Permission denied.") if (!git_get_project_config_bool
('blame'));
1200 die_error
('404 Not Found', "What file will it be, master?") if (!$file_name);
1201 $hash_base ||= git_read_head
($project);
1202 die_error
(undef, "Reading commit failed.") unless ($hash_base);
1203 my %co = git_read_commit
($hash_base)
1204 or die_error
(undef, "Reading commit failed.");
1205 if (!defined $hash) {
1206 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
1207 or die_error
(undef, "Error lookup file.");
1209 open ($fd, "-|", "$gitbin/git-annotate", '-l', '-t', '-r', $file_name, $hash_base)
1210 or die_error
(undef, "Open failed.");
1212 print "<div class=\"page_nav\">\n" .
1213 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1214 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1215 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1216 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base")}, "commit") .
1217 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1218 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") . "<br/>\n";
1219 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") .
1220 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;f=$file_name")}, "head") . "<br/>\n";
1223 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html
($co{'title'})) .
1225 print "<div class=\"page_path\"><b>" . esc_html
($file_name) . "</b></div>\n";
1226 print "<div class=\"page_body\">\n";
1228 <table style="border-collapse: collapse;">
1237 my @line_class = (qw(light dark));
1238 my $line_class_len = scalar (@line_class);
1239 my $line_class_num = $#line_class;
1240 while (my $line = <$fd>) {
1252 $line_class_num = ($line_class_num + 1) % $line_class_len;
1254 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) \+\d\d\d\d\t(\d+)\)(.*)$/) {
1261 print qq( <tr><td colspan="5" style="color: red; background-color: yellow;">Unable to parse: $line</td></tr>\n);
1264 $short_rev = substr ($long_rev, 0, 8);
1265 $age = time () - $time;
1266 $age_str = age_string
($age);
1267 $age_str =~ s/ / /g;
1268 $age_style = 'font-style: italic;';
1269 $age_style .= ' color: #009900; background: transparent;' if ($age < 60*60*24*2);
1270 $age_style .= ' font-weight: bold;' if ($age < 60*60*2);
1271 $author = esc_html
($author);
1272 $author =~ s/ / /g;
1274 while ((my $pos = index($data, "\t")) != -1) {
1275 if (my $count = (8 - ($pos % 8))) {
1276 my $spaces = ' ' x
$count;
1277 $data =~ s/\t/$spaces/;
1280 $data = esc_html
($data);
1281 $data =~ s/ / /g;
1284 <tr class="$line_class[$line_class_num]">
1285 <td style="font-family: monospace;"><a href="$my_uri?${\esc_param ("p=$project;a=commit;h=$long_rev")}" class="text">$short_rev..</a></td>
1286 <td style="$age_style">$age_str</td>
1288 <td style="text-align: right;"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
1289 <td style="font-family: monospace;">$data</td>
1292 } # while (my $line = <$fd>)
1293 print "</table>\n\n";
1294 close $fd or print "Reading blob failed.\n";
1300 my $head = git_read_head
($project);
1302 print "<div class=\"page_nav\">\n" .
1303 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1304 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1305 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1306 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$head")}, "commit") .
1307 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1308 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1311 my $taglist = git_read_refs
("refs/tags");
1313 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary"), -class => "title"}, " ") .
1315 print "<table cellspacing=\"0\">\n";
1317 if (defined @$taglist) {
1318 foreach my $entry (@$taglist) {
1320 my $comment_lines = $tag{'comment'};
1321 my $comment = shift @$comment_lines;
1322 if (defined($comment)) {
1323 $comment = chop_str
($comment, 30, 5);
1326 print "<tr class=\"dark\">\n";
1328 print "<tr class=\"light\">\n";
1331 print "<td><i>$tag{'age'}</i></td>\n" .
1333 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), -class => "list"},
1334 "<b>" . esc_html
($tag{'name'}) . "</b>") .
1337 if (defined($comment)) {
1338 print $cgi->a({-class => "list", -href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, $comment);
1341 "<td class=\"link\">";
1342 if ($tag{'type'} eq "tag") {
1343 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
1345 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1346 if ($tag{'reftype'} eq "commit") {
1347 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1348 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'refid'}")}, "log");
1359 my $head = git_read_head
($project);
1361 print "<div class=\"page_nav\">\n" .
1362 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1363 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1364 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1365 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$head")}, "commit") .
1366 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1367 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1370 my $taglist = git_read_refs
("refs/heads");
1372 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary"), -class => "title"}, " ") .
1374 print "<table cellspacing=\"0\">\n";
1376 if (defined @$taglist) {
1377 foreach my $entry (@$taglist) {
1380 print "<tr class=\"dark\">\n";
1382 print "<tr class=\"light\">\n";
1385 print "<td><i>$tag{'age'}</i></td>\n" .
1387 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}"), -class => "list"}, "<b>" . esc_html
($tag{'name'}) . "</b>") .
1389 "<td class=\"link\">" .
1390 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1391 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'name'}")}, "log") .
1400 sub git_get_hash_by_path
{
1402 my $path = shift || return undef;
1405 my @parts = split '/', $path;
1406 while (my $part = shift @parts) {
1407 open my $fd, "-|", "$gitbin/git-ls-tree $tree" or die_error
(undef, "Open git-ls-tree failed.");
1408 my (@entries) = map { chomp; $_ } <$fd>;
1409 close $fd or return undef;
1410 foreach my $line (@entries) {
1411 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1412 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1416 my $t_name = validate_input
(unquote
($4));
1417 if ($t_name eq $part) {
1421 if ($t_type eq "tree") {
1431 if (!defined $hash && defined $file_name) {
1432 my $base = $hash_base || git_read_head
($project);
1433 $hash = git_get_hash_by_path
($base, $file_name, "blob") || die_error
(undef, "Error lookup file.");
1435 my $have_blame = git_get_project_config_bool
('blame');
1436 open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or die_error
(undef, "Open failed.");
1438 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
1439 print "<div class=\"page_nav\">\n" .
1440 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1441 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1442 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1443 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base")}, "commit") .
1444 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1445 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") . "<br/>\n";
1446 if (defined $file_name) {
1448 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;h=$hash;hb=$hash_base;f=$file_name")}, "blame") . " | ";
1450 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$hash;f=$file_name")}, "plain") .
1451 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;hb=HEAD;f=$file_name")}, "head") . "<br/>\n";
1453 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$hash")}, "plain") . "<br/>\n";
1457 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html
($co{'title'})) .
1460 print "<div class=\"page_nav\">\n" .
1461 "<br/><br/></div>\n" .
1462 "<div class=\"title\">$hash</div>\n";
1464 if (defined $file_name) {
1465 print "<div class=\"page_path\"><b>" . esc_html
($file_name) . "</b></div>\n";
1467 print "<div class=\"page_body\">\n";
1469 while (my $line = <$fd>) {
1472 while ((my $pos = index($line, "\t")) != -1) {
1473 if (my $count = (8 - ($pos % 8))) {
1474 my $spaces = ' ' x
$count;
1475 $line =~ s/\t/$spaces/;
1478 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", $nr, $nr, $nr, esc_html
($line);
1480 close $fd or print "Reading blob failed.\n";
1485 sub git_blob_plain
{
1486 my $save_as = "$hash.txt";
1487 if (defined $file_name) {
1488 $save_as = $file_name;
1490 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8', '-content-disposition' => "inline; filename=\"$save_as\"");
1491 open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or return;
1499 if (!defined $hash) {
1500 $hash = git_read_head
($project);
1501 if (defined $file_name) {
1502 my $base = $hash_base || $hash;
1503 $hash = git_get_hash_by_path
($base, $file_name, "tree");
1505 if (!defined $hash_base) {
1510 open my $fd, "-|", "$gitbin/git-ls-tree -z $hash" or die_error
(undef, "Open git-ls-tree failed.");
1511 chomp (my (@entries) = <$fd>);
1512 close $fd or die_error
(undef, "Reading tree failed.");
1515 my $refs = read_info_ref
();
1517 if (defined $refs->{$hash_base}) {
1518 $ref = " <span class=\"tag\">" . esc_html
($refs->{$hash_base}) . "</span>";
1523 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
1524 $base_key = ";hb=$hash_base";
1525 print "<div class=\"page_nav\">\n" .
1526 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1527 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash_base")}, "shortlog") .
1528 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash_base")}, "log") .
1529 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base")}, "commit") .
1530 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1535 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html
($co{'title'}) . $ref) . "\n" .
1538 print "<div class=\"page_nav\">\n";
1539 print "<br/><br/></div>\n";
1540 print "<div class=\"title\">$hash</div>\n";
1542 if (defined $file_name) {
1543 $base = esc_html
("$file_name/");
1544 print "<div class=\"page_path\"><b>/" . esc_html
($file_name) . "</b></div>\n";
1546 print "<div class=\"page_path\"><b>/</b></div>\n";
1548 print "<div class=\"page_body\">\n";
1549 print "<table cellspacing=\"0\">\n";
1551 foreach my $line (@entries) {
1552 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1553 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1557 my $t_name = validate_input
($4);
1559 print "<tr class=\"dark\">\n";
1561 print "<tr class=\"light\">\n";
1564 print "<td style=\"font-family:monospace\">" . mode_str
($t_mode) . "</td>\n";
1565 if ($t_type eq "blob") {
1566 print "<td class=\"list\">" .
1567 $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)) .
1569 "<td class=\"link\">" .
1570 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name")}, "blob") .
1571 # " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$t_hash$base_key;f=$base$t_name")}, "blame") .
1572 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;h=$hash_base;f=$base$t_name")}, "history") .
1574 } elsif ($t_type eq "tree") {
1575 print "<td class=\"list\">" .
1576 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, esc_html
($t_name)) .
1578 "<td class=\"link\">" .
1579 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, "tree") .
1584 print "</table>\n" .
1590 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
1591 open my $fd, "-|", "$gitbin/git-rev-list --max-count=150 " . git_read_head
($project) or die_error
(undef, "Open failed.");
1592 my (@revlist) = map { chomp; $_ } <$fd>;
1593 close $fd or die_error
(undef, "Reading rev-list failed.");
1594 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
1595 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1596 "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
1597 print "<channel>\n";
1598 print "<title>$project</title>\n".
1599 "<link>" . esc_html
("$my_url?p=$project;a=summary") . "</link>\n".
1600 "<description>$project log</description>\n".
1601 "<language>en</language>\n";
1603 for (my $i = 0; $i <= $#revlist; $i++) {
1604 my $commit = $revlist[$i];
1605 my %co = git_read_commit
($commit);
1606 # we read 150, we always show 30 and the ones more recent than 48 hours
1607 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
1610 my %cd = date_str
($co{'committer_epoch'});
1611 open $fd, "-|", "$gitbin/git-diff-tree -r $co{'parent'} $co{'id'}" or next;
1612 my @difftree = map { chomp; $_ } <$fd>;
1616 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
1618 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
1619 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
1620 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
1621 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
1622 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
1623 "<content:encoded>" .
1625 my $comment = $co{'comment'};
1626 foreach my $line (@$comment) {
1627 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
1628 print "$line<br/>\n";
1631 foreach my $line (@difftree) {
1632 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
1635 my $file = validate_input
(unquote
($7));
1636 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
1637 print "$file<br/>\n";
1640 "</content:encoded>\n" .
1643 print "</channel></rss>";
1647 my @list = git_read_projects
();
1649 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
1650 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1651 "<opml version=\"1.0\">\n".
1653 " <title>Git OPML Export</title>\n".
1656 "<outline text=\"git RSS feeds\">\n";
1658 foreach my $pr (@list) {
1660 my $head = git_read_head
($proj{'path'});
1661 if (!defined $head) {
1664 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
1665 my %co = git_read_commit
($head);
1670 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
1671 my $rss = "$my_url?p=$proj{'path'};a=rss";
1672 my $html = "$my_url?p=$proj{'path'};a=summary";
1673 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
1675 print "</outline>\n".
1681 my $head = git_read_head
($project);
1682 if (!defined $hash) {
1685 if (!defined $page) {
1688 my $refs = read_info_ref
();
1690 print "<div class=\"page_nav\">\n";
1691 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1692 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash")}, "shortlog") .
1694 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash")}, "commit") .
1695 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
1696 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$hash;hb=$hash")}, "tree") . "<br/>\n";
1698 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
1699 open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error
(undef, "Open failed.");
1700 my (@revlist) = map { chomp; $_ } <$fd>;
1703 if ($hash ne $head || $page) {
1704 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "HEAD");
1710 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash;pg=" . ($page-1)), -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1712 print " ⋅ prev";
1714 if ($#revlist >= (100 * ($page+1)-1)) {
1716 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash;pg=" . ($page+1)), -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1718 print " ⋅ next";
1724 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary"), -class => "title"}, " ") .
1726 my %co = git_read_commit
($hash);
1727 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
1729 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
1730 my $commit = $revlist[$i];
1732 if (defined $refs->{$commit}) {
1733 $ref = " <span class=\"tag\">" . esc_html
($refs->{$commit}) . "</span>";
1735 my %co = git_read_commit
($commit);
1737 my %ad = date_str
($co{'author_epoch'});
1739 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "title"},
1740 "<span class=\"age\">$co{'age_string'}</span>" . esc_html
($co{'title'}) . $ref) . "\n";
1742 print "<div class=\"title_text\">\n" .
1743 "<div class=\"log_link\">\n" .
1744 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
1745 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1748 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
1750 "<div class=\"log_body\">\n";
1751 my $comment = $co{'comment'};
1753 foreach my $line (@$comment) {
1754 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1765 print format_log_line_html
($line) . "<br/>\n";
1776 my %co = git_read_commit
($hash);
1778 die_error
(undef, "Unknown commit object.");
1780 my %ad = date_str
($co{'author_epoch'}, $co{'author_tz'});
1781 my %cd = date_str
($co{'committer_epoch'}, $co{'committer_tz'});
1785 my $parent = $co{'parent'};
1786 if (!defined $parent) {
1790 open my $fd, "-|", "$gitbin/git-diff-tree -r -M $root $parent $hash" or die_error
(undef, "Open failed.");
1791 @difftree = map { chomp; $_ } <$fd>;
1792 close $fd or die_error
(undef, "Reading diff-tree failed.");
1794 # non-textual hash id's can be cached
1796 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
1799 my $refs = read_info_ref
();
1801 if (defined $refs->{$co{'id'}}) {
1802 $ref = " <span class=\"tag\">" . esc_html
($refs->{$co{'id'}}) . "</span>";
1804 git_header_html
(undef, $expires);
1805 print "<div class=\"page_nav\">\n" .
1806 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1807 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash")}, "shortlog") .
1808 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash")}, "log") .
1810 if (defined $co{'parent'}) {
1811 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash")}, "commitdiff");
1813 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") . "\n" .
1814 "<br/><br/></div>\n";
1815 if (defined $co{'parent'}) {
1817 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash"), -class => "title"}, esc_html
($co{'title'}) . $ref) . "\n" .
1821 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash"), -class => "title"}, esc_html
($co{'title'})) . "\n" .
1824 print "<div class=\"title_text\">\n" .
1825 "<table cellspacing=\"0\">\n";
1826 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
1828 "<td></td><td> $ad{'rfc2822'}";
1829 if ($ad{'hour_local'} < 6) {
1830 printf(" (<span style=\"color: #cc0000;\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1832 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1836 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
1837 print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
1838 print "<tr><td>commit</td><td style=\"font-family:monospace\">$co{'id'}</td></tr>\n";
1841 "<td style=\"font-family:monospace\">" .
1842 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash"), class => "list"}, $co{'tree'}) .
1844 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
1847 my $parents = $co{'parents'};
1848 foreach my $par (@$parents) {
1851 "<td style=\"font-family:monospace\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$par"), class => "list"}, $par) . "</td>" .
1852 "<td class=\"link\">" .
1853 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$par")}, "commit") .
1854 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash;hp=$par")}, "commitdiff") .
1860 print "<div class=\"page_body\">\n";
1861 my $comment = $co{'comment'};
1864 foreach my $line (@$comment) {
1865 # print only one empty line
1867 if ($empty || $signed) {
1874 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1876 print "<span style=\"color: #888888\">" . esc_html
($line) . "</span><br/>\n";
1879 print format_log_line_html
($line) . "<br/>\n";
1883 print "<div class=\"list_head\">\n";
1884 if ($#difftree > 10) {
1885 print(($#difftree + 1) . " files changed:\n");
1888 print "<table cellspacing=\"0\">\n";
1890 foreach my $line (@difftree) {
1891 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1892 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1893 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
1901 my $similarity = $6;
1902 my $file = validate_input
(unquote
($7));
1904 print "<tr class=\"dark\">\n";
1906 print "<tr class=\"light\">\n";
1909 if ($status eq "A") {
1911 if (S_ISREG
(oct $to_mode)) {
1912 $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
1915 $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" .
1916 "<td><span style=\"color: #008000;\">[new " . file_type
($to_mode) . "$mode_chng]</span></td>\n" .
1917 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob") . "</td>\n";
1918 } elsif ($status eq "D") {
1920 $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" .
1921 "<td><span style=\"color: #c00000;\">[deleted " . file_type
($from_mode). "]</span></td>\n" .
1922 "<td class=\"link\">" .
1923 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, "blob") .
1924 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;h=$hash;f=$file")}, "history") .
1926 } elsif ($status eq "M" || $status eq "T") {
1927 my $mode_chnge = "";
1928 if ($from_mode != $to_mode) {
1929 $mode_chnge = " <span style=\"color: #777777;\">[changed";
1930 if (((oct $from_mode) & S_IFMT
) != ((oct $to_mode) & S_IFMT
)) {
1931 $mode_chnge .= " from " . file_type
($from_mode) . " to " . file_type
($to_mode);
1933 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
1934 if (S_ISREG
($from_mode) && S_ISREG
($to_mode)) {
1935 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
1936 } elsif (S_ISREG
($to_mode)) {
1937 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
1940 $mode_chnge .= "]</span>\n";
1943 if ($to_id ne $from_id) {
1944 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));
1946 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file"), -class => "list"}, esc_html
($file));
1949 "<td>$mode_chnge</td>\n" .
1950 "<td class=\"link\">";
1951 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob");
1952 if ($to_id ne $from_id) {
1953 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file")}, "diff");
1955 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;h=$hash;f=$file")}, "history") . "\n";
1957 } elsif ($status eq "R") {
1958 my ($from_file, $to_file) = split "\t", $file;
1960 if ($from_mode != $to_mode) {
1961 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
1964 $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" .
1965 "<td><span style=\"color: #777777;\">[moved from " .
1966 $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)) .
1967 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
1968 "<td class=\"link\">" .
1969 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file")}, "blob");
1970 if ($to_id ne $from_id) {
1971 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file")}, "diff");
1982 mkdir($git_temp, 0700);
1984 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
1985 print "<div class=\"page_nav\">\n" .
1986 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1987 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1988 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1989 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base")}, "commit") .
1990 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1991 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") .
1993 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff_plain;h=$hash;hp=$hash_parent")}, "plain") .
1996 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html
($co{'title'})) . "\n" .
1999 print "<div class=\"page_nav\">\n" .
2000 "<br/><br/></div>\n" .
2001 "<div class=\"title\">$hash vs $hash_parent</div>\n";
2003 if (defined $file_name) {
2004 print "<div class=\"page_path\"><b>/" . esc_html
($file_name) . "</b></div>\n";
2006 print "<div class=\"page_body\">\n" .
2007 "<div class=\"diff_info\">blob:" .
2008 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name")}, $hash_parent) .
2010 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, $hash) .
2012 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
2017 sub git_blobdiff_plain
{
2018 mkdir($git_temp, 0700);
2019 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8');
2020 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
2023 sub git_commitdiff
{
2024 mkdir($git_temp, 0700);
2025 my %co = git_read_commit
($hash);
2027 die_error
(undef, "Unknown commit object.");
2029 if (!defined $hash_parent) {
2030 $hash_parent = $co{'parent'};
2032 open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error
(undef, "Open failed.");
2033 my (@difftree) = map { chomp; $_ } <$fd>;
2034 close $fd or die_error
(undef, "Reading diff-tree failed.");
2036 # non-textual hash id's can be cached
2038 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2041 my $refs = read_info_ref
();
2043 if (defined $refs->{$co{'id'}}) {
2044 $ref = " <span class=\"tag\">" . esc_html
($refs->{$co{'id'}}) . "</span>";
2046 git_header_html
(undef, $expires);
2047 print "<div class=\"page_nav\">\n" .
2048 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
2049 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash")}, "shortlog") .
2050 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash")}, "log") .
2051 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash")}, "commit") .
2053 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") . "<br/>\n";
2054 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent")}, "plain") . "\n" .
2057 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html
($co{'title'}) . $ref) . "\n" .
2059 print "<div class=\"page_body\">\n";
2060 my $comment = $co{'comment'};
2063 my @log = @$comment;
2064 # remove first and empty lines after that
2066 while (defined $log[0] && $log[0] eq "") {
2069 foreach my $line (@log) {
2070 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2081 print format_log_line_html
($line) . "<br/>\n";
2084 foreach my $line (@difftree) {
2085 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2086 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2087 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2093 my $file = validate_input
(unquote
($6));
2094 if ($status eq "A") {
2095 print "<div class=\"diff_info\">" . file_type
($to_mode) . ":" .
2096 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id) . "(new)" .
2098 git_diff_print
(undef, "/dev/null", $to_id, "b/$file");
2099 } elsif ($status eq "D") {
2100 print "<div class=\"diff_info\">" . file_type
($from_mode) . ":" .
2101 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) . "(deleted)" .
2103 git_diff_print
($from_id, "a/$file", undef, "/dev/null");
2104 } elsif ($status eq "M") {
2105 if ($from_id ne $to_id) {
2106 print "<div class=\"diff_info\">" .
2107 file_type
($from_mode) . ":" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) .
2109 file_type
($to_mode) . ":" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id);
2111 git_diff_print
($from_id, "a/$file", $to_id, "b/$file");
2120 sub git_commitdiff_plain
{
2121 mkdir($git_temp, 0700);
2122 open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error
(undef, "Open failed.");
2123 my (@difftree) = map { chomp; $_ } <$fd>;
2124 close $fd or die_error
(undef, "Reading diff-tree failed.");
2126 # try to figure out the next tag after this commit
2128 my $refs = read_info_ref
("tags");
2129 open $fd, "-|", "$gitbin/git-rev-list HEAD";
2130 chomp (my (@commits) = <$fd>);
2132 foreach my $commit (@commits) {
2133 if (defined $refs->{$commit}) {
2134 $tagname = $refs->{$commit}
2136 if ($commit eq $hash) {
2141 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8', '-content-disposition' => "inline; filename=\"git-$hash.patch\"");
2142 my %co = git_read_commit
($hash);
2143 my %ad = date_str
($co{'author_epoch'}, $co{'author_tz'});
2144 my $comment = $co{'comment'};
2145 print "From: $co{'author'}\n" .
2146 "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
2147 "Subject: $co{'title'}\n";
2148 if (defined $tagname) {
2149 print "X-Git-Tag: $tagname\n";
2151 print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
2154 foreach my $line (@$comment) {;
2159 foreach my $line (@difftree) {
2160 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2165 if ($status eq "A") {
2166 git_diff_print
(undef, "/dev/null", $to_id, "b/$file", "plain");
2167 } elsif ($status eq "D") {
2168 git_diff_print
($from_id, "a/$file", undef, "/dev/null", "plain");
2169 } elsif ($status eq "M") {
2170 git_diff_print
($from_id, "a/$file", $to_id, "b/$file", "plain");
2176 if (!defined $hash) {
2177 $hash = git_read_head
($project);
2179 my %co = git_read_commit
($hash);
2181 die_error
(undef, "Unknown commit object.");
2183 my $refs = read_info_ref
();
2185 print "<div class=\"page_nav\">\n" .
2186 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
2187 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
2188 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
2189 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash")}, "commit") .
2190 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2191 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
2195 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html
($co{'title'})) . "\n" .
2197 print "<div class=\"page_path\"><b>/" . esc_html
($file_name) . "</b><br/></div>\n";
2199 open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin -- \'$file_name\'";
2201 print "<table cellspacing=\"0\">\n";
2203 while (my $line = <$fd>) {
2204 if ($line =~ m/^([0-9a-fA-F]{40})/){
2208 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/ && (defined $commit)) {
2209 my %co = git_read_commit
($commit);
2214 if (defined $refs->{$commit}) {
2215 $ref = " <span class=\"tag\">" . esc_html
($refs->{$commit}) . "</span>";
2218 print "<tr class=\"dark\">\n";
2220 print "<tr class=\"light\">\n";
2223 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2224 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2225 "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list"}, "<b>" .
2226 esc_html
(chop_str
($co{'title'}, 50)) . "$ref</b>") . "</td>\n" .
2227 "<td class=\"link\">" .
2228 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
2229 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2230 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;hb=$commit;f=$file_name")}, "blob");
2231 my $blob = git_get_hash_by_path
($hash, $file_name);
2232 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2233 if (defined $blob && defined $blob_parent && $blob ne $blob_parent) {
2235 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=$file_name")},
2249 if (!defined $searchtext) {
2250 die_error
("", "Text field empty.");
2252 if (!defined $hash) {
2253 $hash = git_read_head
($project);
2255 my %co = git_read_commit
($hash);
2257 die_error
(undef, "Unknown commit object.");
2259 # pickaxe may take all resources of your box and run for several minutes
2260 # with every query - so decide by yourself how public you make this feature :)
2261 my $commit_search = 1;
2262 my $author_search = 0;
2263 my $committer_search = 0;
2264 my $pickaxe_search = 0;
2265 if ($searchtext =~ s/^author\\://i) {
2267 } elsif ($searchtext =~ s/^committer\\://i) {
2268 $committer_search = 1;
2269 } elsif ($searchtext =~ s/^pickaxe\\://i) {
2271 $pickaxe_search = 1;
2274 print "<div class=\"page_nav\">\n" .
2275 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary;h=$hash")}, "summary") .
2276 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
2277 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash")}, "log") .
2278 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash")}, "commit") .
2279 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2280 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
2285 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html
($co{'title'})) . "\n" .
2287 print "<table cellspacing=\"0\">\n";
2289 if ($commit_search) {
2291 open my $fd, "-|", "$gitbin/git-rev-list --header --parents $hash" or next;
2292 while (my $commit_text = <$fd>) {
2293 if (!grep m/$searchtext/i, $commit_text) {
2296 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
2299 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
2302 my @commit_lines = split "\n", $commit_text;
2303 my %co = git_read_commit
(undef, \
@commit_lines);
2308 print "<tr class=\"dark\">\n";
2310 print "<tr class=\"light\">\n";
2313 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2314 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2316 $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/>");
2317 my $comment = $co{'comment'};
2318 foreach my $line (@$comment) {
2319 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2320 my $lead = esc_html
($1) || "";
2321 $lead = chop_str
($lead, 30, 10);
2322 my $match = esc_html
($2) || "";
2323 my $trail = esc_html
($3) || "";
2324 $trail = chop_str
($trail, 30, 10);
2325 my $text = "$lead<span style=\"color:#e00000\">$match</span>$trail";
2326 print chop_str
($text, 80, 5) . "<br/>\n";
2330 "<td class=\"link\">" .
2331 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2332 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2339 if ($pickaxe_search) {
2341 open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin -S\'$searchtext\'";
2344 while (my $line = <$fd>) {
2345 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2348 $set{'from_id'} = $3;
2350 $set{'id'} = $set{'to_id'};
2351 if ($set{'id'} =~ m/0{40}/) {
2352 $set{'id'} = $set{'from_id'};
2354 if ($set{'id'} =~ m/0{40}/) {
2358 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
2361 print "<tr class=\"dark\">\n";
2363 print "<tr class=\"light\">\n";
2366 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2367 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2369 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" .
2370 esc_html
(chop_str
($co{'title'}, 50)) . "</b><br/>");
2371 while (my $setref = shift @files) {
2373 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}"), class => "list"},
2374 "<span style=\"color:#e00000\">" . esc_html
($set{'file'}) . "</span>") .
2378 "<td class=\"link\">" .
2379 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2380 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2384 %co = git_read_commit
($1);
2394 my $head = git_read_head
($project);
2395 if (!defined $hash) {
2398 if (!defined $page) {
2401 my $refs = read_info_ref
();
2403 print "<div class=\"page_nav\">\n" .
2404 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
2406 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash")}, "log") .
2407 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash")}, "commit") .
2408 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2409 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$hash;hb=$hash")}, "tree") . "<br/>\n";
2411 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2412 open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error
(undef, "Open failed.");
2413 my (@revlist) = map { chomp; $_ } <$fd>;
2416 if ($hash ne $head || $page) {
2417 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "HEAD");
2423 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash;pg=" . ($page-1)), -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2425 print " ⋅ prev";
2427 if ($#revlist >= (100 * ($page+1)-1)) {
2429 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)), -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2431 print " ⋅ next";
2436 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary"), -class => "title"}, " ") .
2438 print "<table cellspacing=\"0\">\n";
2440 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2441 my $commit = $revlist[$i];
2443 if (defined $refs->{$commit}) {
2444 $ref = " <span class=\"tag\">" . esc_html
($refs->{$commit}) . "</span>";
2446 my %co = git_read_commit
($commit);
2447 my %ad = date_str
($co{'author_epoch'});
2449 print "<tr class=\"dark\">\n";
2451 print "<tr class=\"light\">\n";
2454 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2455 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
2457 if (length($co{'title_short'}) < length($co{'title'})) {
2458 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list", -title
=> "$co{'title'}"},
2459 "<b>" . esc_html
($co{'title_short'}) . "$ref</b>");
2461 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list"},
2462 "<b>" . esc_html
($co{'title_short'}) . "$ref</b>");
2465 "<td class=\"link\">" .
2466 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
2467 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2471 if ($#revlist >= (100 * ($page+1)-1)) {
2474 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)), -title
=> "Alt-n"}, "next") .