3 # gitweb.pl - simple web interface to track changes in git repositories
5 # (C) 2005, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke <ch@gierke.de>
8 # This program is licensed under the GPL v2, or a later version
12 use CGI
qw(:standard :escapeHTML -nosticky);
13 use CGI
::Util
qw(unescape);
14 use CGI
::Carp
qw(fatalsToBrowser);
19 my $my_url = $cgi->url();
20 my $my_uri = $cgi->url(-absolute
=> 1);
23 # absolute fs-path which will be prepended to the project path
24 my $projectroot = "/pub/scm";
26 # location of the git-core binaries
27 my $gitbin = "/usr/bin";
29 # location for temporary files needed for diffs
30 my $git_temp = "/tmp/gitweb";
32 # target of the home link on top of all pages
33 my $home_link = $my_uri;
35 # html text to include at home page
36 my $home_text = "indextext.html";
38 # source of projects list
39 #my $projects_list = $projectroot;
40 my $projects_list = "index/index.aux";
42 # input validation and dispatch
43 my $action = $cgi->param('a');
44 if (defined $action) {
45 if ($action =~ m/[^0-9a-zA-Z\.\-_]+/) {
47 die_error
(undef, "Invalid action parameter.");
49 if ($action eq "git-logo.png") {
57 my $project = $cgi->param('p');
58 if (defined $project) {
59 if ($project =~ m/(^|\/)(|\
.|\
.\
.)($|\
/)/) {
61 die_error
(undef, "Non-canonical project parameter.");
63 if ($project =~ m/[^a-zA-Z0-9_\.\/\
-\
+\#\
~]/) {
65 die_error
(undef, "Invalid character in project parameter.");
67 if (!(-d
"$projectroot/$project")) {
69 die_error
(undef, "No such directory.");
71 if (!(-e
"$projectroot/$project/HEAD")) {
73 die_error
(undef, "No such project.");
75 $rss_link = "<link rel=\"alternate\" title=\"$project log\" href=\"$my_uri?p=$project;a=rss\" type=\"application/rss+xml\"/>";
76 $ENV{'GIT_OBJECT_DIRECTORY'} = "$projectroot/$project/objects";
82 my $file_name = $cgi->param('f');
83 if (defined $file_name) {
84 if ($file_name =~ m/(^|\/)(|\
.|\
.\
.)($|\
/)/) {
86 die_error
(undef, "Non-canonical file parameter.");
88 if ($file_name =~ m/[^a-zA-Z0-9_\.\/\
-\
+\#\
~\
:\
!]/) {
90 die_error
(undef, "Invalid character in file parameter.");
94 my $hash = $cgi->param('h');
95 if (defined $hash && !($hash =~ m/^[0-9a-fA-F]{40}$/)) {
97 die_error
(undef, "Invalid hash parameter.");
100 my $hash_parent = $cgi->param('hp');
101 if (defined $hash_parent && !($hash_parent =~ m/^[0-9a-fA-F]{40}$/)) {
103 die_error
(undef, "Invalid hash_parent parameter.");
106 my $hash_base = $cgi->param('hb');
107 if (defined $hash_base && !($hash_base =~ m/^[0-9a-fA-F]{40}$/)) {
109 die_error
(undef, "Invalid parent hash parameter.");
112 my $time_back = $cgi->param('t');
113 if (defined $time_back) {
114 if ($time_back =~ m/^[^0-9]+$/) {
116 die_error
(undef, "Invalid time parameter.");
121 my $searchtext = $cgi->param('s');
122 if (defined $searchtext) {
123 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
125 die_error
(undef, "Invalid search parameter.");
127 $searchtext = quotemeta $searchtext;
130 if ($action eq "summary") {
133 } elsif ($action eq "branches") {
136 } elsif ($action eq "tags") {
139 } elsif ($action eq "blob") {
142 } elsif ($action eq "blob_plain") {
145 } elsif ($action eq "tree") {
148 } elsif ($action eq "rss") {
151 } elsif ($action eq "commit") {
154 } elsif ($action eq "log") {
157 } elsif ($action eq "blobdiff") {
160 } elsif ($action eq "blobdiff_plain") {
161 git_blobdiff_plain
();
163 } elsif ($action eq "commitdiff") {
166 } elsif ($action eq "commitdiff_plain") {
167 git_commitdiff_plain
();
169 } elsif ($action eq "history") {
172 } elsif ($action eq "search") {
175 } elsif ($action eq "shortlog") {
180 die_error
(undef, "Unknown action.");
184 sub git_header_html
{
185 my $status = shift || "200 OK";
188 if (defined $project) {
189 $title .= " - $project";
190 if (defined $action) {
191 $title .= "/$action";
194 print $cgi->header(-type
=>'text/html', -charset
=> 'utf-8', -status
=> $status);
196 <?xml version="1.0" encoding="utf-8"?>
197 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
198 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
199 <!-- git web interface v$version, (C) 2005, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke <ch\@gierke.de> -->
201 <title>$title</title>
203 <style type="text/css">
204 body { font-family: sans-serif; font-size: 12px; margin:0px; border:solid #d9d8d1; border-width:1px; margin:10px; }
206 a:hover, a:visited, a:active { color:#880000; }
207 div.page_header { height:25px; padding:8px; font-size:18px; font-weight:bold; background-color:#d9d8d1; }
208 div.page_header a:visited { color:#0000cc; }
209 div.page_header a:hover { color:#880000; }
210 div.page_nav { padding:8px; }
211 div.page_nav a:visited { color:#0000cc; }
212 div.page_path { padding:8px; border:solid #d9d8d1; border-width:0px 0px 1px}
213 div.page_footer { height:17px; padding:4px 8px; background-color: #d9d8d1; }
214 div.page_footer_text { float:left; color:#555555; font-style:italic; }
215 div.page_body { padding:8px; }
217 display:block; padding:6px 8px;
218 font-weight:bold; background-color:#edece6; text-decoration:none; color:#000000;
220 a.title:hover { background-color: #d9d8d1; }
221 div.title_text { padding:6px 0px; border: solid #d9d8d1; border-width:0px 0px 1px; }
222 div.log_body { padding:8px 8px 8px 150px; }
223 span.age { position:relative; float:left; width:142px; font-style:italic; }
226 font-size:10px; font-family:sans-serif; font-style:normal;
227 position:relative; float:left; width:136px;
229 div.list_head { padding:6px 8px 4px; border:solid #d9d8d1; border-width:1px 0px 0px; font-style:italic; }
230 a.list { text-decoration:none; color:#000000; }
231 a.list:hover { color:#880000; }
232 table { padding:8px 4px; }
233 th { padding:2px 5px; font-size:12px; text-align:left; }
234 td { padding:2px 5px; font-size:12px; vertical-align:top; }
235 td.link { padding:2px 5px; font-family:sans-serif; font-size:10px; }
236 div.pre { font-family:monospace; font-size:12px; white-space:pre; }
237 div.diff_info { font-family:monospace; color:#000099; background-color:#edece6; font-style:italic; }
238 div.index_include { border:solid #d9d8d1; border-width:0px 0px 1px; padding:12px 8px; }
239 input.search { margin:4px 8px; position:absolute; top:56px; right:12px }
240 a.rss_logo { float:right; padding:3px 0px; width:35px; line-height:10px;
241 border:1px solid; border-color:#fcc7a5 #7d3302 #3e1a01 #ff954e;
242 color:#ffffff; background-color:#ff6600;
243 font-weight:bold; font-family:sans-serif; font-size:10px;
244 text-align:center; text-decoration:none;
246 a.rss_logo:hover { background-color:#ee5500; }
251 print "<div class=\"page_header\">\n" .
252 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\">" .
253 "<img src=\"$my_uri?a=git-logo.png\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
255 print $cgi->a({-href
=> $home_link}, "projects") . " / ";
256 if (defined $project) {
257 print $cgi->a({-href
=> "$my_uri?p=$project;a=summary"}, escapeHTML
($project));
258 if (defined $action) {
262 if (!defined $searchtext) {
265 $cgi->param("a", "search");
266 # post search form, but fake get parameter in browser
267 #print $cgi->startform(-name => "search", -action => "$my_uri",
268 # -onsubmit => "document.search.action='?p=$project;a=search;s='+document.search.s.value") .
269 # $cgi->hidden(-name => "p") . "\n" .
270 # $cgi->hidden(-name => "a") . "\n" .
271 # $cgi->textfield(-name => "s", -value => $searchtext, -class => "search") .
272 # $cgi->end_form() . "\n";
277 sub git_footer_html
{
278 print "<div class=\"page_footer\">\n";
279 if (defined $project) {
280 my $descr = git_read_description
($project);
281 if (defined $descr) {
282 print "<div class=\"page_footer_text\">" . escapeHTML
($descr) . "</div>\n";
284 print $cgi->a({-href
=> "$my_uri?p=$project;a=rss", -class => "rss_logo"}, "RSS") . "\n";
292 my $status = shift || "403 Forbidden";
293 my $error = shift || "Malformed query, file missing or permission denied";
295 git_header_html
($status);
296 print "<div class=\"page_body\">\n" .
298 "$status - $error\n" .
308 open my $fd, "-|", "$gitbin/git-cat-file -t $hash" or return;
318 open my $fd, "$projectroot/$path" or return undef;
322 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
327 sub git_read_description
{
330 open my $fd, "$projectroot/$path/description" or return undef;
341 open my $fd, "-|", "$gitbin/git-cat-file tag $tag_id" or return;
342 while (my $line = <$fd>) {
344 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
346 } elsif ($line =~ m/^type (.+)$/) {
348 } elsif ($line =~ m/^tag (.+)$/) {
353 if (!defined $tag{'name'}) {
359 sub git_read_commit
{
360 my $commit_id = shift;
361 my $commit_text = shift;
367 if (defined $commit_text) {
368 @commit_lines = @
$commit_text;
370 open my $fd, "-|", "$gitbin/git-cat-file commit $commit_id" or return;
371 @commit_lines = map { chomp; $_ } <$fd>;
374 while (my $line = shift @commit_lines) {
375 last if $line eq "\n";
376 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
378 } elsif ($line =~ m/^parent ([0-9a-fA-F]{40})$/) {
380 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
382 $co{'author_epoch'} = $2;
383 $co{'author_tz'} = $3;
384 if ($co{'author'} =~ m/^([^<]+) </) {
385 $co{'author_name'} = $1;
387 $co{'author_name'} = $co{'author'};
389 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
390 $co{'committer'} = $1;
391 $co{'committer_epoch'} = $2;
392 $co{'committer_tz'} = $3;
393 $co{'committer_name'} = $co{'committer'};
394 $co{'committer_name'} =~ s/ <.*//;
397 if (!defined $co{'tree'}) {
400 $co{'id'} = $commit_id;
401 $co{'parents'} = \
@parents;
402 $co{'parent'} = $parents[0];
403 $co{'comment'} = \
@commit_lines;
404 foreach my $title (@commit_lines) {
406 $co{'title'} = chop_str
($title, 80);
407 # remove leading stuff of merges to make the interesting part visible
408 if (length($title) > 50) {
409 $title =~ s/^Automatic //;
410 $title =~ s/^merge (of|with) /Merge ... /i;
411 if (length($title) > 50) {
412 $title =~ s/(http|rsync):\/\///;
414 if (length($title) > 50) {
415 $title =~ s/(master|www|rsync)\.//;
417 if (length($title) > 50) {
418 $title =~ s/kernel.org:?//;
420 if (length($title) > 50) {
421 $title =~ s/\/pub\/scm//;
424 $co{'title_short'} = chop_str
($title, 50);
429 my $age = time - $co{'committer_epoch'};
431 if ($age > 60*60*24*365*2) {
432 $co{'age_string'} = (int $age/60/60/24/365);
433 $co{'age_string'} .= " years ago";
434 } elsif ($age > 60*60*24*(365/12)*2) {
435 $co{'age_string'} = int $age/60/60/24/(365/12);
436 $co{'age_string'} .= " months ago";
437 } elsif ($age > 60*60*24*7*2) {
438 $co{'age_string'} = int $age/60/60/24/7;
439 $co{'age_string'} .= " weeks ago";
440 } elsif ($age > 60*60*24*2) {
441 $co{'age_string'} = int $age/60/60/24;
442 $co{'age_string'} .= " days ago";
443 } elsif ($age > 60*60*2) {
444 $co{'age_string'} = int $age/60/60;
445 $co{'age_string'} .= " hours ago";
446 } elsif ($age > 60*2) {
447 $co{'age_string'} = int $age/60;
448 $co{'age_string'} .= " min ago";
450 $co{'age_string'} = int $age;
451 $co{'age_string'} .= " sec ago";
453 $co{'age_string'} .= " right now";
460 my $from_name = shift;
463 my $format = shift || "html";
465 my $from_tmp = "/dev/null";
466 my $to_tmp = "/dev/null";
469 # create tmp from-file
471 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
472 open my $fd2, "> $from_tmp";
473 open my $fd, "-|", "$gitbin/git-cat-file blob $from";
482 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
483 open my $fd2, "> $to_tmp";
484 open my $fd, "-|", "$gitbin/git-cat-file blob $to";
491 open my $fd, "-|", "/usr/bin/diff -u -p -L $from_name -L $to_name $from_tmp $to_tmp";
492 if ($format eq "plain") {
497 while (my $line = <$fd>) {
499 my $char = substr($line, 0, 1);
502 $color = " style=\"color:#008800;\"";
503 } elsif ($char eq "-") {
504 $color = " style=\"color:#cc0000;\"";
505 } elsif ($char eq "@") {
506 $color = " style=\"color:#990099;\"";
507 } elsif ($char eq "\\") {
511 while ((my $pos = index($line, "\t")) != -1) {
512 if (my $count = (8 - (($pos-1) % 8))) {
513 my $spaces = ' ' x
$count;
514 $line =~ s/\t/$spaces/;
517 print "<div class=\"pre\"$color>" . escapeHTML
($line) . "</div>\n";
531 my $mode = oct shift;
533 if (S_ISDIR
($mode & S_IFMT
)) {
535 } elsif (S_ISLNK
($mode)) {
537 } elsif (S_ISREG
($mode)) {
538 # git cares only about the executable bit
539 if ($mode & S_IXUSR
) {
552 my $add_len = shift || 10;
554 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})/;
556 if ($chopped ne $str) {
563 my $mode = oct shift;
565 if (S_ISDIR
($mode & S_IFMT
)) {
567 } elsif (S_ISLNK
($mode)) {
569 } elsif (S_ISREG
($mode)) {
578 my $tz = shift || "-0000";
581 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
582 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
583 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
584 $date{'hour'} = $hour;
585 $date{'minute'} = $min;
586 $date{'mday'} = $mday;
587 $date{'day'} = $days[$wday];
588 $date{'month'} = $months[$mon];
589 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
590 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
592 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
593 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
594 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
595 $date{'hour_local'} = $hour;
596 $date{'minute_local'} = $min;
597 $date{'tz_local'} = $tz;
601 # git-logo (cached in browser for one day)
603 print $cgi->header(-type
=> 'image/png', -expires
=> '+1d');
604 # cat git-logo.png | hexdump -e '16/1 " %02x" "\n"' | sed 's/ /\\x/g'
605 print "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52" .
606 "\x00\x00\x00\x48\x00\x00\x00\x1b\x04\x03\x00\x00\x00\x2d\xd9\xd4" .
607 "\x2d\x00\x00\x00\x18\x50\x4c\x54\x45\xff\xff\xff\x60\x60\x5d\xb0" .
608 "\xaf\xaa\x00\x80\x00\xce\xcd\xc7\xc0\x00\x00\xe8\xe8\xe6\xf7\xf7" .
609 "\xf6\x95\x0c\xa7\x47\x00\x00\x00\x73\x49\x44\x41\x54\x28\xcf\x63" .
610 "\x48\x67\x20\x04\x4a\x5c\x18\x0a\x08\x2a\x62\x53\x61\x20\x02\x08" .
611 "\x0d\x69\x45\xac\xa1\xa1\x01\x30\x0c\x93\x60\x36\x26\x52\x91\xb1" .
612 "\x01\x11\xd6\xe1\x55\x64\x6c\x6c\xcc\x6c\x6c\x0c\xa2\x0c\x70\x2a" .
613 "\x62\x06\x2a\xc1\x62\x1d\xb3\x01\x02\x53\xa4\x08\xe8\x00\x03\x18" .
614 "\x26\x56\x11\xd4\xe1\x20\x97\x1b\xe0\xb4\x0e\x35\x24\x71\x29\x82" .
615 "\x99\x30\xb8\x93\x0a\x11\xb9\x45\x88\xc1\x8d\xa0\xa2\x44\x21\x06" .
616 "\x27\x41\x82\x40\x85\xc1\x45\x89\x20\x70\x01\x00\xa4\x3d\x21\xc5" .
617 "\x12\x1c\x9a\xfe\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\x82";
623 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
624 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
625 if (!defined $gcos) {
629 $owner =~ s/[,;].*$//;
633 sub git_project_list
{
636 if (-d
$projects_list) {
637 # search in directory
638 my $dir = $projects_list;
639 opendir my $dh, $dir or return undef;
640 while (my $dir = readdir($dh)) {
641 if (-e
"$projectroot/$dir/HEAD") {
649 } elsif (-f
$projects_list) {
650 # read from file(url-encoded):
651 # 'git%2Fgit.git Linus+Torvalds'
652 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
653 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
654 open my $fd , $projects_list or return undef;
655 while (my $line = <$fd>) {
657 my ($path, $owner) = split ' ', $line;
658 $path = unescape
($path);
659 $owner = unescape
($owner);
660 if (!defined $path) {
663 if (-e
"$projectroot/$path/HEAD") {
675 die_error
(undef, "No project found.");
677 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
681 print "<div class=\"index_include\">\n";
682 open (my $fd, $home_text);
687 print "<table cellspacing=\"0\">\n" .
689 "<th>Project</th>\n" .
690 "<th>Description</th>\n" .
692 "<th>last change</th>\n" .
696 foreach my $pr (@list) {
698 my $head = git_read_hash
("$proj{'path'}/HEAD");
699 if (!defined $head) {
702 $ENV{'GIT_OBJECT_DIRECTORY'} = "$projectroot/$proj{'path'}/objects";
703 my %co = git_read_commit
($head);
707 my $descr = git_read_description
($proj{'path'}) || "";
708 $descr = chop_str
($descr, 25, 5);
709 # get directory owner if not already specified
710 if (!defined $proj{'owner'}) {
711 $proj{'owner'} = get_file_owner
("$projectroot/$proj{'path'}") || "";
714 print "<tr style=\"background-color:#f6f5ed\">\n";
719 print "<td>" . $cgi->a({-href
=> "$my_uri?p=$proj{'path'};a=summary", -class => "list"}, escapeHTML
($proj{'path'})) . "</td>\n" .
720 "<td>$descr</td>\n" .
721 "<td><i>" . chop_str
($proj{'owner'}, 15) . "</i></td>\n";
723 if ($co{'age'} < 60*60*2) {
724 $colored_age = "<span style =\"color: #009900;\"><b><i>$co{'age_string'}</i></b></span>";
725 } elsif ($co{'age'} < 60*60*24*2) {
726 $colored_age = "<span style =\"color: #009900;\"><i>$co{'age_string'}</i></span>";
728 $colored_age = "<i>$co{'age_string'}</i>";
730 print "<td>$colored_age</td>\n" .
731 "<td class=\"link\">" .
732 $cgi->a({-href
=> "$my_uri?p=$proj{'path'};a=summary"}, "summary") .
733 " | " . $cgi->a({-href
=> "$my_uri?p=$proj{'path'};a=shortlog"}, "shortlog") .
734 " | " . $cgi->a({-href
=> "$my_uri?p=$proj{'path'};a=log"}, "log") .
746 opendir my $dh, "$projectroot/$project/$ref_dir";
747 my @refs = grep !m/^\./, readdir $dh;
749 foreach my $ref_file (@refs) {
750 my $ref_id = git_read_hash
("$project/$ref_dir/$ref_file");
751 my $type = git_get_type
($ref_id) || next;
754 if ($type eq "tag") {
755 my %tag = git_read_tag
($ref_id);
756 if ($tag{'type'} eq "commit") {
757 %co = git_read_commit
($tag{'object'});
759 $ref_item{'type'} = $tag{'type'};
760 $ref_item{'name'} = $tag{'name'};
761 $ref_item{'id'} = $tag{'object'};
762 } elsif ($type eq "commit"){
763 %co = git_read_commit
($ref_id);
764 $ref_item{'type'} = "commit";
765 $ref_item{'name'} = $ref_file;
766 $ref_item{'title'} = $co{'title'};
767 $ref_item{'id'} = $ref_id;
769 $ref_item{'epoch'} = $co{'committer_epoch'} || 0;
770 $ref_item{'age'} = $co{'age_string'} || "unknown";
772 push @reflist, \
%ref_item;
775 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
780 my $descr = git_read_description
($project) || "none";
781 my $head = git_read_hash
("$project/HEAD");
782 my %co = git_read_commit
($head);
783 my %cd = date_str
($co{'committer_epoch'}, $co{'committer_tz'});
786 if (-f
$projects_list) {
787 open (my $fd , $projects_list);
788 while (my $line = <$fd>) {
790 my ($pr, $ow) = split ' ', $line;
793 if ($pr eq $project) {
800 if (!defined $owner) {
801 $owner = get_file_owner
("$projectroot/$project");
805 print "<div class=\"page_nav\">\n" .
807 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=shortlog"}, "shortlog") .
808 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=log"}, "log") .
809 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$head"}, "commit") .
810 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=commitdiff;h=$head"}, "commitdiff") .
811 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=tree"}, "tree") .
814 print "<div class=\"title\"> </div>\n";
815 print "<table cellspacing=\"0\">\n" .
816 "<tr><td>description</td><td>" . escapeHTML
($descr) . "</td></tr>\n" .
817 "<tr><td>owner</td><td>$owner</td></tr>\n" .
818 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
820 open my $fd, "-|", "$gitbin/git-rev-list --max-count=17 " . git_read_hash
("$project/HEAD") or die_error
(undef, "Open failed.");
821 my (@revlist) = map { chomp; $_ } <$fd>;
824 $cgi->a({-href
=> "$my_uri?p=$project;a=shortlog", -class => "title"}, "shortlog") .
827 print "<table cellspacing=\"0\">\n";
829 foreach my $commit (@revlist) {
830 my %co = git_read_commit
($commit);
831 my %ad = date_str
($co{'author_epoch'});
833 print "<tr style=\"background-color:#f6f5ed\">\n";
839 print "<td><i>$co{'age_string'}</i></td>\n" .
840 "<td><i>" . escapeHTML
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
842 $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$commit", -class => "list"},
843 "<b>" . escapeHTML
($co{'title_short'}) . "</b>") .
845 "<td class=\"link\">" .
846 $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
847 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=commitdiff;h=$commit"}, "commitdiff") .
851 print "<td>" . $cgi->a({-href
=> "$my_uri?p=$project;a=shortlog"}, "...") . "</td>\n" .
858 my $taglist = git_read_refs
("refs/tags");
859 if (defined @
$taglist) {
861 $cgi->a({-href
=> "$my_uri?p=$project;a=tags", -class => "title"}, "tags") .
864 print "<table cellspacing=\"0\">\n";
866 foreach my $entry (@
$taglist) {
869 print "<tr style=\"background-color:#f6f5ed\">\n";
875 print "<td><i>$tag{'age'}</i></td>\n" .
877 $cgi->a({-href
=> "$my_uri?p=$project;a=$tag{'type'};h=$tag{'id'}", -class => "list"}, "<b>" .
878 escapeHTML
($tag{'name'}) . "</b>") .
880 "<td class=\"link\">" .
881 $cgi->a({-href
=> "$my_uri?p=$project;a=$tag{'type'};h=$tag{'id'}"}, $tag{'type'});
882 if ($tag{'type'} eq "commit") {
883 print " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=shortlog;h=$tag{'id'}"}, "shortlog") .
884 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=log;h=$tag{'id'}"}, "log");
889 print "<td>" . $cgi->a({-href
=> "$my_uri?p=$project;a=tags"}, "...") . "</td>\n" .
897 my $branchlist = git_read_refs
("refs/heads");
898 if (defined @
$branchlist) {
900 $cgi->a({-href
=> "$my_uri?p=$project;a=branches", -class => "title"}, "branches") .
903 print "<table cellspacing=\"0\">\n";
905 foreach my $entry (@
$branchlist) {
908 print "<tr style=\"background-color:#f6f5ed\">\n";
914 print "<td><i>$tag{'age'}</i></td>\n" .
916 $cgi->a({-href
=> "$my_uri?p=$project;a=shortlog;h=$tag{'id'}", -class => "list"},
917 "<b>" . escapeHTML
($tag{'name'}) . "</b>") .
919 "<td class=\"link\">" .
920 $cgi->a({-href
=> "$my_uri?p=$project;a=shortlog;h=$tag{'id'}"}, "shortlog") .
921 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=log;h=$tag{'id'}"}, "log") .
925 print "<td>" . $cgi->a({-href
=> "$my_uri?p=$project;a=branches"}, "...") . "</td>\n" .
936 my $head = git_read_hash
("$project/HEAD");
938 print "<div class=\"page_nav\">\n" .
939 $cgi->a({-href
=> "$my_uri?p=$project;a=summary"}, "summary") .
940 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=shortlog"}, "shortlog") .
941 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=log"}, "log") .
942 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$head"}, "commit") .
943 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=commitdiff;h=$head"}, "commitdiff") .
944 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=tree;hb=$head"}, "tree") . "<br/>\n" .
947 my $taglist = git_read_refs
("refs/tags");
949 $cgi->a({-href
=> "$my_uri?p=$project;a=summary", -class => "title"}, " ") .
951 print "<table cellspacing=\"0\">\n";
953 if (defined @
$taglist) {
954 foreach my $entry (@
$taglist) {
957 print "<tr style=\"background-color:#f6f5ed\">\n";
962 print "<td><i>$tag{'age'}</i></td>\n" .
964 $cgi->a({-href
=> "$my_uri?p=$project;a=log;h=$tag{'id'}", -class => "list"},
965 "<b>" . escapeHTML
($tag{'name'}) . "</b>") .
967 "<td class=\"link\">" .
968 $cgi->a({-href
=> "$my_uri?p=$project;a=$tag{'type'};h=$tag{'id'}"}, $tag{'type'});
969 if ($tag{'type'} eq "commit") {
970 print " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=shortlog;h=$tag{'id'}"}, "shortlog") .
971 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=log;h=$tag{'id'}"}, "log");
982 my $head = git_read_hash
("$project/HEAD");
984 print "<div class=\"page_nav\">\n" .
985 $cgi->a({-href
=> "$my_uri?p=$project;a=summary"}, "summary") .
986 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=shortlog"}, "shortlog") .
987 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=log"}, "log") .
988 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$head"}, "commit") .
989 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=commitdiff;h=$head"}, "commitdiff") .
990 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=tree;hb=$head"}, "tree") . "<br/>\n" .
993 my $taglist = git_read_refs
("refs/heads");
995 $cgi->a({-href
=> "$my_uri?p=$project;a=summary", -class => "title"}, " ") .
997 print "<table cellspacing=\"0\">\n";
999 if (defined @
$taglist) {
1000 foreach my $entry (@
$taglist) {
1003 print "<tr style=\"background-color:#f6f5ed\">\n";
1008 print "<td><i>$tag{'age'}</i></td>\n" .
1010 $cgi->a({-href
=> "$my_uri?p=$project;a=log;h=$tag{'id'}", -class => "list"}, "<b>" . escapeHTML
($tag{'name'}) . "</b>") .
1012 "<td class=\"link\">" .
1013 $cgi->a({-href
=> "$my_uri?p=$project;a=shortlog;h=$tag{'id'}"}, "shortog") .
1014 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=log;h=$tag{'id'}"}, "log") .
1023 sub git_get_hash_by_path
{
1025 my $path = shift || return undef;
1028 my @parts = split '/', $path;
1029 while (my $part = shift @parts) {
1030 open my $fd, "-|", "$gitbin/git-ls-tree $tree" or die_error
(undef, "Open git-ls-tree failed.");
1031 my (@entries) = map { chomp; $_ } <$fd>;
1032 close $fd or return undef;
1033 foreach my $line (@entries) {
1034 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1035 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1040 if ($t_name eq $part) {
1044 if ($t_type eq "tree") {
1054 if (!defined $hash && defined $file_name) {
1055 my $base = $hash_base || git_read_hash
("$project/HEAD");
1056 $hash = git_get_hash_by_path
($base, $file_name, "blob");
1058 open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or die_error
(undef, "Open failed.");
1059 my $base = $file_name || "";
1061 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
1062 print "<div class=\"page_nav\">\n" .
1063 $cgi->a({-href
=> "$my_uri?p=$project;a=summary"}, "summary") .
1064 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=shortlog"}, "shortlog") .
1065 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=log"}, "log") .
1066 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$hash_base"}, "commit") .
1067 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=commitdiff;h=$hash_base"}, "commitdiff") .
1068 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash_base"}, "tree") . "<br/>\n";
1069 print $cgi->a({-href
=> "$my_uri?p=$project;a=blob_plain;h=$hash"}, "plain") . "<br/>\n" .
1072 $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$hash_base", -class => "title"}, escapeHTML
($co{'title'})) .
1075 print "<div class=\"page_nav\">\n" .
1076 "<br/><br/></div>\n" .
1077 "<div class=\"title\">$hash</div>\n";
1079 if (defined $file_name) {
1080 print "<div class=\"page_path\"><b>$file_name</b></div>\n";
1082 print "<div class=\"page_body\">\n";
1084 while (my $line = <$fd>) {
1087 while ((my $pos = index($line, "\t")) != -1) {
1088 if (my $count = (8 - ($pos % 8))) {
1089 my $spaces = ' ' x
$count;
1090 $line =~ s/\t/$spaces/;
1093 printf "<div class=\"pre\"><span style=\"color:#999999;\">%4i</span> %s</div>\n", $nr, escapeHTML
($line);
1095 close $fd or print "Reading blob failed.\n";
1100 sub git_blob_plain
{
1101 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8');
1102 open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or return;
1110 if (!defined $hash) {
1111 $hash = git_read_hash
("$project/HEAD");
1112 if (defined $file_name) {
1113 my $base = $hash_base || git_read_hash
("$project/HEAD");
1114 $hash = git_get_hash_by_path
($base, $file_name, "tree");
1116 if (!defined $hash_base) {
1117 $hash_base = git_read_hash
("$project/HEAD");
1120 open my $fd, "-|", "$gitbin/git-ls-tree $hash" or die_error
(undef, "Open git-ls-tree failed.");
1121 my (@entries) = map { chomp; $_ } <$fd>;
1122 close $fd or die_error
(undef, "Reading tree failed.");
1128 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
1129 $base_key = ";hb=$hash_base";
1130 print "<div class=\"page_nav\">\n" .
1131 $cgi->a({-href
=> "$my_uri?p=$project;a=summary"}, "summary") .
1132 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=shortlog;h=$hash_base"}, "shortlog") .
1133 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=log;h=$hash_base"}, "log") .
1134 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$hash_base"}, "commit") .
1135 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=commitdiff;h=$hash_base"}, "commitdiff") .
1140 $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$hash_base", -class => "title"}, escapeHTML
($co{'title'})) . "\n" .
1143 print "<div class=\"page_nav\">\n";
1144 print "<br/><br/></div>\n";
1145 print "<div class=\"title\">$hash</div>\n";
1147 if (defined $file_name) {
1148 $base = "$file_name/";
1149 print "<div class=\"page_path\"><b>/$file_name</b></div>\n";
1151 print "<div class=\"page_path\"><b>/</b></div>\n";
1153 print "<div class=\"page_body\">\n";
1154 print "<table cellspacing=\"0\">\n";
1156 foreach my $line (@entries) {
1157 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1158 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1163 $file_key = ";f=$base$t_name";
1165 print "<tr style=\"background-color:#f6f5ed\">\n";
1170 print "<td style=\"font-family:monospace\">" . mode_str
($t_mode) . "</td>\n";
1171 if ($t_type eq "blob") {
1172 print "<td class=\"list\">" .
1173 $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$t_hash" . $base_key . $file_key, -class => "list"}, $t_name) .
1175 print "<td class=\"link\">" .
1176 $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$t_hash" . $base_key . $file_key}, "blob") .
1177 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=history;h=$hash_base" . $file_key}, "history") .
1179 } elsif ($t_type eq "tree") {
1180 print "<td class=\"list\">" .
1181 $cgi->a({-href
=> "$my_uri?p=$project;a=tree;h=$t_hash" . $base_key . $file_key}, $t_name) .
1187 print "</table>\n" .
1193 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
1194 open my $fd, "-|", "$gitbin/git-rev-list --max-count=20 " . git_read_hash
("$project/HEAD") or die_error
(undef, "Open failed.");
1195 my (@revlist) = map { chomp; $_ } <$fd>;
1196 close $fd or die_error
(undef, "Reading rev-list failed.");
1198 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
1199 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1200 "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
1201 print "<channel>\n";
1202 print "<title>$project</title>\n".
1203 "<link>" . escapeHTML
("$my_url/$project/log") . "</link>\n".
1204 "<description>$project log</description>\n".
1205 "<language>en</language>\n";
1207 foreach my $commit (@revlist) {
1208 my %co = git_read_commit
($commit);
1209 my %cd = date_str
($co{'committer_epoch'});
1212 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . escapeHTML
($co{'title'}) .
1214 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
1215 "<link>" . escapeHTML
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
1216 "<description>" . escapeHTML
($co{'title'}) . "</description>\n" .
1217 "<content:encoded>" .
1219 my $comment = $co{'comment'};
1220 foreach my $line (@
$comment) {
1221 print "$line<br/>\n";
1224 "</content:encoded>\n" .
1227 print "</channel></rss>";
1231 my $head = git_read_hash
("$project/HEAD");
1232 if (!defined $hash) {
1235 my $limit_option = "";
1236 if (!defined $time_back) {
1237 $limit_option = "--max-count=100";
1238 } elsif ($time_back > 0) {
1239 my $date = time - $time_back*24*60*60;
1240 $limit_option = "--max-age=$date";
1242 open my $fd, "-|", "$gitbin/git-rev-list $limit_option $hash" or die_error
(undef, "Open failed.");
1243 my (@revlist) = map { chomp; $_ } <$fd>;
1244 close $fd or die_error
(undef, "Reading rev-list failed.");
1247 print "<div class=\"page_nav\">\n";
1248 print $cgi->a({-href
=> "$my_uri?p=$project;a=summary"}, "summary") .
1249 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=shortlog;h=$hash"}, "shortlog") .
1251 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$hash"}, "commit") .
1252 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff") .
1253 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=tree;h=$hash;hb=$hash"}, "tree") . "<br/>\n";
1254 if ($hash ne $head) {
1255 print $cgi->a({-href
=> "$my_uri?p=$project;a=log"}, "HEAD") . " ⋅ ";
1257 print $cgi->a({-href
=> "$my_uri?p=$project;a=log;h=$hash"}, "100") .
1258 " ⋅ " . $cgi->a({-href
=> "$my_uri?p=$project;a=log;t=1;h=$hash"}, "day") .
1259 " ⋅ " .$cgi->a({-href
=> "$my_uri?p=$project;a=log;t=7;h=$hash"}, "week") .
1260 " ⋅ " . $cgi->a({-href
=> "$my_uri?p=$project;a=log;t=31;h=$hash"}, "month") .
1261 " ⋅ " . $cgi->a({-href
=> "$my_uri?p=$project;a=log;t=365;h=$hash"}, "year") .
1262 " ⋅ " . $cgi->a({-href
=> "$my_uri?p=$project;a=log;t=0;h=$hash"}, "all");
1267 $cgi->a({-href
=> "$my_uri?p=$project;a=summary", -class => "title"}, " ") .
1269 my %co = git_read_commit
($hash);
1270 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
1272 foreach my $commit (@revlist) {
1273 my %co = git_read_commit
($commit);
1275 my %ad = date_str
($co{'author_epoch'});
1277 $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$commit", -class => "title"},
1278 "<span class=\"age\">$co{'age_string'}</span>" . escapeHTML
($co{'title'})) . "\n" .
1280 print "<div class=\"title_text\">\n" .
1281 "<div class=\"log_link\">\n" .
1282 $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
1283 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=commitdiff;h=$commit"}, "commitdiff") .
1286 "<i>" . escapeHTML
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
1288 "<div class=\"log_body\">\n";
1289 my $comment = $co{'comment'};
1291 foreach my $line (@
$comment) {
1292 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1303 print escapeHTML
($line) . "<br/>\n";
1314 my %co = git_read_commit
($hash);
1316 die_error
(undef, "Unknown commit object.");
1318 my %ad = date_str
($co{'author_epoch'}, $co{'author_tz'});
1319 my %cd = date_str
($co{'committer_epoch'}, $co{'committer_tz'});
1323 if (!defined $co{'parent'}) {
1326 open my $fd, "-|", "$gitbin/git-diff-tree -r -M $root $co{'parent'} $hash" or die_error
(undef, "Open failed.");
1327 @difftree = map { chomp; $_ } <$fd>;
1328 close $fd or die_error
(undef, "Reading diff-tree failed.");
1330 print "<div class=\"page_nav\">\n" .
1331 $cgi->a({-href
=> "$my_uri?p=$project;a=summary"}, "summary") .
1332 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=shortlog;h=$hash"}, "shortlog") .
1333 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=log;h=$hash"}, "log") .
1335 if (defined $co{'parent'}) {
1336 print " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff");
1338 print " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, "tree") . "\n" .
1339 "<br/><br/></div>\n";
1340 if (defined $co{'parent'}) {
1342 $cgi->a({-href
=> "$my_uri?p=$project;a=commitdiff;h=$hash", -class => "title"}, escapeHTML
($co{'title'})) . "\n" .
1346 $cgi->a({-href
=> "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash", -class => "title"}, escapeHTML
($co{'title'})) . "\n" .
1349 print "<div class=\"title_text\">\n" .
1350 "<table cellspacing=\"0\">\n";
1351 print "<tr><td>author</td><td>" . escapeHTML
($co{'author'}) . "</td></tr>\n".
1353 "<td></td><td> $ad{'rfc2822'}";
1354 if ($ad{'hour_local'} < 6) {
1355 printf(" (<span style=\"color: #cc0000;\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1357 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1361 print "<tr><td>committer</td><td>" . escapeHTML
($co{'committer'}) . "</td></tr>\n";
1362 print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
1363 print "<tr><td>commit</td><td style=\"font-family:monospace\">$hash</td></tr>\n";
1366 "<td style=\"font-family:monospace\">" .
1367 $cgi->a({-href
=> "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash", class => "list"}, $co{'tree'}) .
1369 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, "tree") .
1372 my $parents = $co{'parents'};
1373 foreach my $par (@
$parents) {
1376 "<td style=\"font-family:monospace\">" . $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$par", class => "list"}, $par) . "</td>" .
1377 "<td class=\"link\">" .
1378 $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$par"}, "commit") .
1379 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=commitdiff;h=$hash;hp=$par"}, "commitdiff") .
1385 print "<div class=\"page_body\">\n";
1386 my $comment = $co{'comment'};
1389 foreach my $line (@
$comment) {
1390 # print only one empty line
1392 if ($empty || $signed) {
1399 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1401 print "<span style=\"color: #888888\">" . escapeHTML
($line) . "</span><br/>\n";
1404 print escapeHTML
($line) . "<br/>\n";
1408 print "<div class=\"list_head\">\n";
1409 if ($#difftree > 10) {
1410 print(($#difftree + 1) . " files changed:\n");
1413 print "<table cellspacing=\"0\">\n";
1415 foreach my $line (@difftree) {
1416 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1417 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1418 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/;
1424 my $percentage = int $6;
1426 #print "$line ($status)<br/>\n";
1428 print "<tr style=\"background-color:#f6f5ed\">\n";
1433 if ($status eq "N") {
1435 if (S_ISREG
(oct $to_mode)) {
1436 $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
1439 $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$to_id;hp=$hash;f=$file", -class => "list"}, escapeHTML
($file)) . "</td>\n" .
1440 "<td><span style=\"color: #008000;\">[new " . file_type
($to_mode) . "$mode_chng]</span></td>\n" .
1441 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file"}, "blob") . "</td>\n";
1442 } elsif ($status eq "D") {
1444 $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file", -class => "list"}, escapeHTML
($file)) . "</td>\n" .
1445 "<td><span style=\"color: #c00000;\">[deleted " . file_type
($from_mode). "]</span></td>\n" .
1446 "<td class=\"link\">" .
1447 $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file"}, "blob") .
1448 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=history;h=$hash;f=$file"}, "history") .
1450 } elsif ($status eq "M" || $status eq "T") {
1451 my $mode_chnge = "";
1452 if ($from_mode != $to_mode) {
1453 $mode_chnge = " <span style=\"color: #777777;\">[changed";
1454 if (((oct $from_mode) & S_IFMT
) != ((oct $to_mode) & S_IFMT
)) {
1455 $mode_chnge .= " from " . file_type
($from_mode) . " to " . file_type
($to_mode);
1457 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
1458 if (S_ISREG
($from_mode) && S_ISREG
($to_mode)) {
1459 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
1460 } elsif (S_ISREG
($to_mode)) {
1461 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
1464 $mode_chnge .= "]</span>\n";
1467 if ($to_id ne $from_id) {
1468 print $cgi->a({-href
=> "$my_uri?p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file", -class => "list"}, escapeHTML
($file));
1470 print $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file", -class => "list"}, escapeHTML
($file));
1473 "<td>$mode_chnge</td>\n" .
1474 "<td class=\"link\">";
1475 print $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file"}, "blob");
1476 if ($to_id ne $from_id) {
1477 print " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file"}, "diff");
1479 print " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=history;h=$hash;f=$file"}, "history") . "\n";
1481 } elsif ($status eq "R") {
1482 my ($from_file, $to_file) = split "\t", $file;
1484 if ($from_mode != $to_mode) {
1485 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
1488 $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file", -class => "list"}, escapeHTML
($to_file)) . "</td>\n" .
1489 "<td><span style=\"color: #777777;\">[moved from " .
1490 $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$from_file", -class => "list"}, escapeHTML
($from_file)) .
1491 " with $percentage% similarity$mode_chng]</span></td>\n" .
1492 "<td class=\"link\">" .
1493 $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file"}, "blob");
1494 if ($to_id ne $from_id) {
1495 print " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file"}, "diff");
1506 mkdir($git_temp, 0700);
1508 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
1509 print "<div class=\"page_nav\">\n" .
1510 $cgi->a({-href
=> "$my_uri?p=$project;a=summary"}, "summary") .
1511 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=shortlog"}, "shortlog") .
1512 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=log"}, "log") .
1513 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$hash_base"}, "commit") .
1514 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=commitdiff;h=$hash_base"}, "commitdiff") .
1515 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash_base"}, "tree") .
1517 print $cgi->a({-href
=> "$my_uri?p=$project;a=blobdiff_plain;h=$hash;hp=$hash_parent"}, "plain") .
1520 $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$hash_base", -class => "title"}, escapeHTML
($co{'title'})) . "\n" .
1523 print "<div class=\"page_nav\">\n" .
1524 "<br/><br/></div>\n" .
1525 "<div class=\"title\">$hash vs $hash_parent</div>\n";
1527 if (defined $file_name) {
1528 print "<div class=\"page_path\"><b>/$file_name</b></div>\n";
1530 print "<div class=\"page_body\">\n" .
1531 "<div class=\"diff_info\">blob:" .
1532 $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name"}, $hash_parent) .
1534 $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name"}, $hash) .
1536 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
1541 sub git_blobdiff_plain
{
1542 mkdir($git_temp, 0700);
1543 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8');
1544 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
1547 sub git_commitdiff
{
1548 mkdir($git_temp, 0700);
1549 my %co = git_read_commit
($hash);
1551 die_error
(undef, "Unknown commit object.");
1553 if (!defined $hash_parent) {
1554 $hash_parent = $co{'parent'};
1556 open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error
(undef, "Open failed.");
1557 my (@difftree) = map { chomp; $_ } <$fd>;
1558 close $fd or die_error
(undef, "Reading diff-tree failed.");
1561 print "<div class=\"page_nav\">\n" .
1562 $cgi->a({-href
=> "$my_uri?p=$project;a=summary"}, "summary") .
1563 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=shortlog;h=$hash"}, "shortlog") .
1564 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=log;h=$hash"}, "log") .
1565 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$hash"}, "commit") .
1567 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, "tree") . "<br/>\n";
1568 print $cgi->a({-href
=> "$my_uri?p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent"}, "plain") . "\n" .
1571 $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$hash", -class => "title"}, escapeHTML
($co{'title'})) . "\n" .
1573 print "<div class=\"page_body\">\n";
1574 my $comment = $co{'comment'};
1577 my @log = @
$comment;
1578 # remove first and empty lines after that
1580 while (defined $log[0] && $log[0] eq "") {
1583 foreach my $line (@log) {
1584 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1595 print escapeHTML
($line) . "<br/>\n";
1598 foreach my $line (@difftree) {
1599 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1600 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1601 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
1608 if ($status eq "N") {
1609 print "<div class=\"diff_info\">" . file_type
($to_mode) . ":" .
1610 $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file"}, $to_id) . "(new)" .
1612 git_diff_print
(undef, "/dev/null", $to_id, "b/$file");
1613 } elsif ($status eq "D") {
1614 print "<div class=\"diff_info\">" . file_type
($from_mode) . ":" .
1615 $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file"}, $from_id) . "(deleted)" .
1617 git_diff_print
($from_id, "a/$file", undef, "/dev/null");
1618 } elsif ($status eq "M") {
1619 if ($from_id ne $to_id) {
1620 print "<div class=\"diff_info\">" .
1621 file_type
($from_mode) . ":" . $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file"}, $from_id) .
1623 file_type
($to_mode) . ":" . $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file"}, $to_id);
1625 git_diff_print
($from_id, "a/$file", $to_id, "b/$file");
1634 sub git_commitdiff_plain
{
1635 mkdir($git_temp, 0700);
1636 open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error
(undef, "Open failed.");
1637 my (@difftree) = map { chomp; $_ } <$fd>;
1638 close $fd or die_error
(undef, "Reading diff-tree failed.");
1640 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8');
1641 foreach my $line (@difftree) {
1642 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
1647 if ($status eq "N") {
1648 git_diff_print
(undef, "/dev/null", $to_id, "b/$file", "plain");
1649 } elsif ($status eq "D") {
1650 git_diff_print
($from_id, "a/$file", undef, "/dev/null", "plain");
1651 } elsif ($status eq "M") {
1652 git_diff_print
($from_id, "a/$file", $to_id, "b/$file", "plain");
1658 if (!defined $hash) {
1659 $hash = git_read_hash
("$project/HEAD");
1661 my %co = git_read_commit
($hash);
1663 die_error
(undef, "Unknown commit object.");
1666 print "<div class=\"page_nav\">\n" .
1667 $cgi->a({-href
=> "$my_uri?p=$project;a=summary"}, "summary") .
1668 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=shortlog"}, "shortlog") .
1669 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=log"}, "log") .
1670 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$hash"}, "commit") .
1671 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff") .
1672 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, "tree") .
1676 $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$hash", -class => "title"}, escapeHTML
($co{'title'})) . "\n" .
1678 print "<div class=\"page_path\"><b>/$file_name</b><br/></div>\n";
1680 open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin $file_name";
1682 print "<table cellspacing=\"0\">\n";
1684 while (my $line = <$fd>) {
1685 if ($line =~ m/^([0-9a-fA-F]{40}) /){
1689 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/ && (defined $commit)) {
1690 my %co = git_read_commit
($commit);
1695 print "<tr style=\"background-color:#f6f5ed\">\n";
1700 print "<td><i>$co{'age_string'}</i></td>\n" .
1701 "<td><i>" . escapeHTML
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
1702 "<td>" . $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$commit", -class => "list"}, "<b>" .
1703 escapeHTML
(chop_str
($co{'title'}, 50)) . "</b>") . "</td>\n" .
1704 "<td class=\"link\">" .
1705 $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
1706 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=blob;hb=$commit;f=$file_name"}, "blob");
1707 my $blob = git_get_hash_by_path
($hash, $file_name);
1708 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
1709 if (defined $blob && defined $blob_parent && $blob ne $blob_parent) {
1710 print " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=$file_name"}, "diff to current");
1723 if (!defined $searchtext) {
1724 die_error
("", "Text field empty.");
1726 if (!defined $hash) {
1727 $hash = git_read_hash
("$project/HEAD");
1729 my %co = git_read_commit
($hash);
1731 die_error
(undef, "Unknown commit object.");
1734 print "<div class=\"page_nav\">\n" .
1735 $cgi->a({-href
=> "$my_uri?p=$project;a=summary;h=$hash"}, "summary") .
1736 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=shortlog"}, "shortlog") .
1737 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=log;h=$hash"}, "log") .
1738 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$hash"}, "commit") .
1739 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff") .
1740 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, "tree") .
1745 $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$hash", -class => "title"}, escapeHTML
($co{'title'})) . "\n" .
1747 print "<table cellspacing=\"0\">\n";
1749 open my $fd, "-|", "$gitbin/git-rev-list --header $hash";
1751 while (my $commit_text = <$fd>) {
1752 if (!grep m/$searchtext/, $commit_text) {
1755 my @commit_lines = split "\n", $commit_text;
1756 my $commit = shift @commit_lines;
1757 my %co = git_read_commit
($commit, \
@commit_lines);
1762 print "<tr style=\"background-color:#f6f5ed\">\n";
1767 print "<td><i>$co{'age_string'}</i></td>\n" .
1768 "<td><i>" . escapeHTML
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
1770 $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$commit", -class => "list"}, "<b>" . escapeHTML
(chop_str
($co{'title'}, 50)) . "</b><br/>");
1771 my $comment = $co{'comment'};
1772 foreach my $line (@
$comment) {
1773 if ($line =~ m/^(.*)($searchtext)(.*)$/) {
1774 my $lead = escapeHTML
($1) || "";
1775 $lead = chop_str
($lead, 30, 10);
1776 my $match = escapeHTML
($2) || "";
1777 my $trail = escapeHTML
($3) || "";
1778 $trail = chop_str
($trail, 30, 10);
1779 my $text = "$lead<span style=\"color:#e00000\">$match</span>$trail";
1780 print chop_str
($text, 80, 5) . "<br/>\n";
1784 "<td class=\"link\">" .
1785 $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
1786 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$commit"}, "tree");
1793 open $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin -S$searchtext";
1796 while (my $line = <$fd>) {
1797 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
1800 $set{'from_id'} = $3;
1802 $set{'id'} = $set{'to_id'};
1803 if ($set{'id'} =~ m/0{40}/) {
1804 $set{'id'} = $set{'from_id'};
1806 if ($set{'id'} =~ m/0{40}/) {
1810 } elsif ($line =~ m/^([0-9a-fA-F]{40}) /){
1813 print "<tr style=\"background-color:#f6f5ed\">\n";
1818 print "<td><i>$co{'age_string'}</i></td>\n" .
1819 "<td><i>" . escapeHTML
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
1821 $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$co{'id'}", -class => "list"}, "<b>" .
1822 escapeHTML
(chop_str
($co{'title'}, 50)) . "</b><br/>");
1823 while (my $setref = shift @files) {
1825 print $cgi->a({-href
=> "$my_uri?p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}", class => "list"},
1826 escapeHTML
($set{'file'})) . "<br/>\n";
1829 "<td class=\"link\">" .
1830 $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$co{'id'}"}, "commit") .
1831 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}"}, "tree");
1835 %co = git_read_commit
($1);
1844 my $head = git_read_hash
("$project/HEAD");
1845 if (!defined $hash) {
1850 print "<div class=\"page_nav\">\n" .
1851 $cgi->a({-href
=> "$my_uri?p=$project;a=summary"}, "summary") .
1853 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=log;h=$hash"}, "log") .
1854 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$hash"}, "commit") .
1855 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff") .
1856 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=tree;h=$hash;hb=$hash"}, "tree") . "<br/>\n";
1857 if ($hash ne $head) {
1858 print $cgi->a({-href
=> "$my_uri?p=$project;a=shortlog"}, "HEAD") . " ⋅ ";
1860 print $cgi->a({-href
=> "$my_uri?p=$project;a=shortlog;h=$hash"}, "100") .
1861 " ⋅ " . $cgi->a({-href
=> "$my_uri?p=$project;a=shortlog;t=1;h=$hash"}, "day") .
1862 " ⋅ " .$cgi->a({-href
=> "$my_uri?p=$project;a=shortlog;t=7;h=$hash"}, "week") .
1863 " ⋅ " . $cgi->a({-href
=> "$my_uri?p=$project;a=shortlog;t=31;h=$hash"}, "month") .
1864 " ⋅ " . $cgi->a({-href
=> "$my_uri?p=$project;a=shortlog;t=365;h=$hash"}, "year") .
1865 " ⋅ " . $cgi->a({-href
=> "$my_uri?p=$project;a=shortlog;t=0;h=$hash"}, "all") .
1869 if (defined $time_back) {
1871 $limit = sprintf(" --max-age=%i", time - 60*60*24*$time_back);
1874 $limit = " --max-count=100";
1876 open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error
(undef, "Open failed.");
1877 my (@revlist) = map { chomp; $_ } <$fd>;
1880 $cgi->a({-href
=> "$my_uri?p=$project;a=summary", -class => "title"}, " ") .
1882 print "<table cellspacing=\"0\">\n";
1884 my %co = git_read_commit
($hash);
1885 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
1888 foreach my $commit (@revlist) {
1889 my %co = git_read_commit
($commit);
1890 my %ad = date_str
($co{'author_epoch'});
1892 print "<tr style=\"background-color:#f6f5ed\">\n";
1897 print "<td><i>$co{'age_string'}</i></td>\n" .
1898 "<td><i>" . escapeHTML
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
1899 "<td>" . $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$commit", -class => "list"}, "<b>" .
1900 escapeHTML
($co{'title_short'}) . "</b>") . "</td>\n" .
1901 "<td class=\"link\">" .
1902 $cgi->a({-href
=> "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
1903 " | " . $cgi->a({-href
=> "$my_uri?p=$project;a=commitdiff;h=$commit"}, "commitdiff") .