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 $page = $cgi->param('pg');
114 if ($page =~ m/^[^0-9]+$/) {
116 die_error(undef, "Invalid page 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 if (!defined $page) {
1239 print "<div class=\"page_nav\">\n";
1240 print $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
1241 " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash"}, "shortlog") .
1243 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") .
1244 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff") .
1245 " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$hash;hb=$hash"}, "tree") . "<br/>\n";
1247 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
1248 open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error(undef, "Open failed.");
1249 my (@revlist) = map { chomp; $_ } <$fd>;
1252 if ($hash ne $head || $page) {
1253 print $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "HEAD");
1258 print " ⋅ " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash;pg=" . ($page-1), -accesskey => "p"}, "prev");
1260 print " ⋅ prev";
1262 if ($#revlist >= (100 * ($page+1)-1)) {
1263 print " ⋅ " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash;pg=" . ($page+1), -accesskey => "n"}, "next");
1265 print " ⋅ next";
1271 $cgi->a({-href => "$my_uri?p=$project;a=summary", -class => "title"}, " ") .
1273 my %co = git_read_commit($hash);
1274 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
1276 foreach my $commit (@revlist) {
1277 my %co = git_read_commit($commit);
1279 my %ad = date_str($co{'author_epoch'});
1281 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit", -class => "title"},
1282 "<span class=\"age\">$co{'age_string'}</span>" . escapeHTML($co{'title'})) . "\n" .
1284 print "<div class=\"title_text\">\n" .
1285 "<div class=\"log_link\">\n" .
1286 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
1287 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$commit"}, "commitdiff") .
1290 "<i>" . escapeHTML($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
1292 "<div class=\"log_body\">\n";
1293 my $comment = $co{'comment'};
1295 foreach my $line (@$comment) {
1296 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1307 print escapeHTML($line) . "<br/>\n";
1318 my %co = git_read_commit($hash);
1320 die_error(undef, "Unknown commit object.");
1322 my %ad = date_str($co{'author_epoch'}, $co{'author_tz'});
1323 my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'});
1327 if (!defined $co{'parent'}) {
1330 open my $fd, "-|", "$gitbin/git-diff-tree -r -M $root $co{'parent'} $hash" or die_error(undef, "Open failed.");
1331 @difftree = map { chomp; $_ } <$fd>;
1332 close $fd or die_error(undef, "Reading diff-tree failed.");
1334 print "<div class=\"page_nav\">\n" .
1335 $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
1336 " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash"}, "shortlog") .
1337 " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$hash"}, "log") .
1339 if (defined $co{'parent'}) {
1340 print " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff");
1342 print " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, "tree") . "\n" .
1343 "<br/><br/></div>\n";
1344 if (defined $co{'parent'}) {
1346 $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1350 $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1353 print "<div class=\"title_text\">\n" .
1354 "<table cellspacing=\"0\">\n";
1355 print "<tr><td>author</td><td>" . escapeHTML($co{'author'}) . "</td></tr>\n".
1357 "<td></td><td> $ad{'rfc2822'}";
1358 if ($ad{'hour_local'} < 6) {
1359 printf(" (<span style=\"color: #cc0000;\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1361 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1365 print "<tr><td>committer</td><td>" . escapeHTML($co{'committer'}) . "</td></tr>\n";
1366 print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
1367 print "<tr><td>commit</td><td style=\"font-family:monospace\">$hash</td></tr>\n";
1370 "<td style=\"font-family:monospace\">" .
1371 $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash", class => "list"}, $co{'tree'}) .
1373 "<td class=\"link\">" . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, "tree") .
1376 my $parents = $co{'parents'};
1377 foreach my $par (@$parents) {
1380 "<td style=\"font-family:monospace\">" . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$par", class => "list"}, $par) . "</td>" .
1381 "<td class=\"link\">" .
1382 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$par"}, "commit") .
1383 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash;hp=$par"}, "commitdiff") .
1389 print "<div class=\"page_body\">\n";
1390 my $comment = $co{'comment'};
1393 foreach my $line (@$comment) {
1394 # print only one empty line
1396 if ($empty || $signed) {
1403 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1405 print "<span style=\"color: #888888\">" . escapeHTML($line) . "</span><br/>\n";
1408 print escapeHTML($line) . "<br/>\n";
1412 print "<div class=\"list_head\">\n";
1413 if ($#difftree > 10) {
1414 print(($#difftree + 1) . " files changed:\n");
1417 print "<table cellspacing=\"0\">\n";
1419 foreach my $line (@difftree) {
1420 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1421 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1422 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/;
1428 my $similarity = $6;
1430 #print "$line ($status)<br/>\n";
1432 print "<tr style=\"background-color:#f6f5ed\">\n";
1437 if ($status eq "N") {
1439 if (S_ISREG(oct $to_mode)) {
1440 $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
1443 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hp=$hash;f=$file", -class => "list"}, escapeHTML($file)) . "</td>\n" .
1444 "<td><span style=\"color: #008000;\">[new " . file_type($to_mode) . "$mode_chng]</span></td>\n" .
1445 "<td class=\"link\">" . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file"}, "blob") . "</td>\n";
1446 } elsif ($status eq "D") {
1448 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file", -class => "list"}, escapeHTML($file)) . "</td>\n" .
1449 "<td><span style=\"color: #c00000;\">[deleted " . file_type($from_mode). "]</span></td>\n" .
1450 "<td class=\"link\">" .
1451 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file"}, "blob") .
1452 " | " . $cgi->a({-href => "$my_uri?p=$project;a=history;h=$hash;f=$file"}, "history") .
1454 } elsif ($status eq "M" || $status eq "T") {
1455 my $mode_chnge = "";
1456 if ($from_mode != $to_mode) {
1457 $mode_chnge = " <span style=\"color: #777777;\">[changed";
1458 if (((oct $from_mode) & S_IFMT) != ((oct $to_mode) & S_IFMT)) {
1459 $mode_chnge .= " from " . file_type($from_mode) . " to " . file_type($to_mode);
1461 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
1462 if (S_ISREG($from_mode) && S_ISREG($to_mode)) {
1463 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
1464 } elsif (S_ISREG($to_mode)) {
1465 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
1468 $mode_chnge .= "]</span>\n";
1471 if ($to_id ne $from_id) {
1472 print $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file", -class => "list"}, escapeHTML($file));
1474 print $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file", -class => "list"}, escapeHTML($file));
1477 "<td>$mode_chnge</td>\n" .
1478 "<td class=\"link\">";
1479 print $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file"}, "blob");
1480 if ($to_id ne $from_id) {
1481 print " | " . $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file"}, "diff");
1483 print " | " . $cgi->a({-href => "$my_uri?p=$project;a=history;h=$hash;f=$file"}, "history") . "\n";
1485 } elsif ($status eq "R") {
1486 my ($from_file, $to_file) = split "\t", $file;
1488 if ($from_mode != $to_mode) {
1489 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
1492 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file", -class => "list"}, escapeHTML($to_file)) . "</td>\n" .
1493 "<td><span style=\"color: #777777;\">[moved from " .
1494 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$from_file", -class => "list"}, escapeHTML($from_file)) .
1495 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
1496 "<td class=\"link\">" .
1497 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file"}, "blob");
1498 if ($to_id ne $from_id) {
1499 print " | " . $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file"}, "diff");
1510 mkdir($git_temp, 0700);
1512 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
1513 print "<div class=\"page_nav\">\n" .
1514 $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
1515 " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "shortlog") .
1516 " | " . $cgi->a({-href => "$my_uri?p=$project;a=log"}, "log") .
1517 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base"}, "commit") .
1518 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash_base"}, "commitdiff") .
1519 " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash_base"}, "tree") .
1521 print $cgi->a({-href => "$my_uri?p=$project;a=blobdiff_plain;h=$hash;hp=$hash_parent"}, "plain") .
1524 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash_base", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1527 print "<div class=\"page_nav\">\n" .
1528 "<br/><br/></div>\n" .
1529 "<div class=\"title\">$hash vs $hash_parent</div>\n";
1531 if (defined $file_name) {
1532 print "<div class=\"page_path\"><b>/$file_name</b></div>\n";
1534 print "<div class=\"page_body\">\n" .
1535 "<div class=\"diff_info\">blob:" .
1536 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name"}, $hash_parent) .
1538 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name"}, $hash) .
1540 git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
1545 sub git_blobdiff_plain {
1546 mkdir($git_temp, 0700);
1547 print $cgi->header(-type => "text/plain", -charset => 'utf-8');
1548 git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
1551 sub git_commitdiff {
1552 mkdir($git_temp, 0700);
1553 my %co = git_read_commit($hash);
1555 die_error(undef, "Unknown commit object.");
1557 if (!defined $hash_parent) {
1558 $hash_parent = $co{'parent'};
1560 open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error(undef, "Open failed.");
1561 my (@difftree) = map { chomp; $_ } <$fd>;
1562 close $fd or die_error(undef, "Reading diff-tree failed.");
1565 print "<div class=\"page_nav\">\n" .
1566 $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
1567 " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash"}, "shortlog") .
1568 " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$hash"}, "log") .
1569 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") .
1571 " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, "tree") . "<br/>\n";
1572 print $cgi->a({-href => "$my_uri?p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent"}, "plain") . "\n" .
1575 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1577 print "<div class=\"page_body\">\n";
1578 my $comment = $co{'comment'};
1581 my @log = @$comment;
1582 # remove first and empty lines after that
1584 while (defined $log[0] && $log[0] eq "") {
1587 foreach my $line (@log) {
1588 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1599 print escapeHTML($line) . "<br/>\n";
1602 foreach my $line (@difftree) {
1603 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1604 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1605 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
1612 if ($status eq "N") {
1613 print "<div class=\"diff_info\">" . file_type($to_mode) . ":" .
1614 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file"}, $to_id) . "(new)" .
1616 git_diff_print(undef, "/dev/null", $to_id, "b/$file");
1617 } elsif ($status eq "D") {
1618 print "<div class=\"diff_info\">" . file_type($from_mode) . ":" .
1619 $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file"}, $from_id) . "(deleted)" .
1621 git_diff_print($from_id, "a/$file", undef, "/dev/null");
1622 } elsif ($status eq "M") {
1623 if ($from_id ne $to_id) {
1624 print "<div class=\"diff_info\">" .
1625 file_type($from_mode) . ":" . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$from_id;hb=$hash;f=$file"}, $from_id) .
1627 file_type($to_mode) . ":" . $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$to_id;hb=$hash;f=$file"}, $to_id);
1629 git_diff_print($from_id, "a/$file", $to_id, "b/$file");
1638 sub git_commitdiff_plain {
1639 mkdir($git_temp, 0700);
1640 open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error(undef, "Open failed.");
1641 my (@difftree) = map { chomp; $_ } <$fd>;
1642 close $fd or die_error(undef, "Reading diff-tree failed.");
1644 print $cgi->header(-type => "text/plain", -charset => 'utf-8');
1645 foreach my $line (@difftree) {
1646 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
1651 if ($status eq "N") {
1652 git_diff_print(undef, "/dev/null", $to_id, "b/$file", "plain");
1653 } elsif ($status eq "D") {
1654 git_diff_print($from_id, "a/$file", undef, "/dev/null", "plain");
1655 } elsif ($status eq "M") {
1656 git_diff_print($from_id, "a/$file", $to_id, "b/$file", "plain");
1662 if (!defined $hash) {
1663 $hash = git_read_hash("$project/HEAD");
1665 my %co = git_read_commit($hash);
1667 die_error(undef, "Unknown commit object.");
1670 print "<div class=\"page_nav\">\n" .
1671 $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
1672 " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "shortlog") .
1673 " | " . $cgi->a({-href => "$my_uri?p=$project;a=log"}, "log") .
1674 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") .
1675 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff") .
1676 " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, "tree") .
1680 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1682 print "<div class=\"page_path\"><b>/$file_name</b><br/></div>\n";
1684 open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin $file_name";
1686 print "<table cellspacing=\"0\">\n";
1688 while (my $line = <$fd>) {
1689 if ($line =~ m/^([0-9a-fA-F]{40}) /){
1693 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/ && (defined $commit)) {
1694 my %co = git_read_commit($commit);
1699 print "<tr style=\"background-color:#f6f5ed\">\n";
1704 print "<td><i>$co{'age_string'}</i></td>\n" .
1705 "<td><i>" . escapeHTML(chop_str($co{'author_name'}, 15, 3)) . "</i></td>\n" .
1706 "<td>" . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit", -class => "list"}, "<b>" .
1707 escapeHTML(chop_str($co{'title'}, 50)) . "</b>") . "</td>\n" .
1708 "<td class=\"link\">" .
1709 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
1710 " | " . $cgi->a({-href => "$my_uri?p=$project;a=blob;hb=$commit;f=$file_name"}, "blob");
1711 my $blob = git_get_hash_by_path($hash, $file_name);
1712 my $blob_parent = git_get_hash_by_path($commit, $file_name);
1713 if (defined $blob && defined $blob_parent && $blob ne $blob_parent) {
1714 print " | " . $cgi->a({-href => "$my_uri?p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=$file_name"}, "diff to current");
1727 if (!defined $searchtext) {
1728 die_error("", "Text field empty.");
1730 if (!defined $hash) {
1731 $hash = git_read_hash("$project/HEAD");
1733 my %co = git_read_commit($hash);
1735 die_error(undef, "Unknown commit object.");
1738 print "<div class=\"page_nav\">\n" .
1739 $cgi->a({-href => "$my_uri?p=$project;a=summary;h=$hash"}, "summary") .
1740 " | " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "shortlog") .
1741 " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$hash"}, "log") .
1742 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") .
1743 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff") .
1744 " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$hash"}, "tree") .
1749 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash", -class => "title"}, escapeHTML($co{'title'})) . "\n" .
1751 print "<table cellspacing=\"0\">\n";
1753 open my $fd, "-|", "$gitbin/git-rev-list --header $hash";
1755 while (my $commit_text = <$fd>) {
1756 if (!grep m/$searchtext/, $commit_text) {
1759 my @commit_lines = split "\n", $commit_text;
1760 my $commit = shift @commit_lines;
1761 my %co = git_read_commit($commit, \@commit_lines);
1766 print "<tr style=\"background-color:#f6f5ed\">\n";
1771 print "<td><i>$co{'age_string'}</i></td>\n" .
1772 "<td><i>" . escapeHTML(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
1774 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit", -class => "list"}, "<b>" . escapeHTML(chop_str($co{'title'}, 50)) . "</b><br/>");
1775 my $comment = $co{'comment'};
1776 foreach my $line (@$comment) {
1777 if ($line =~ m/^(.*)($searchtext)(.*)$/) {
1778 my $lead = escapeHTML($1) || "";
1779 $lead = chop_str($lead, 30, 10);
1780 my $match = escapeHTML($2) || "";
1781 my $trail = escapeHTML($3) || "";
1782 $trail = chop_str($trail, 30, 10);
1783 my $text = "$lead<span style=\"color:#e00000\">$match</span>$trail";
1784 print chop_str($text, 80, 5) . "<br/>\n";
1788 "<td class=\"link\">" .
1789 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
1790 " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$commit"}, "tree");
1797 open $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin -S$searchtext";
1800 while (my $line = <$fd>) {
1801 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
1804 $set{'from_id'} = $3;
1806 $set{'id'} = $set{'to_id'};
1807 if ($set{'id'} =~ m/0{40}/) {
1808 $set{'id'} = $set{'from_id'};
1810 if ($set{'id'} =~ m/0{40}/) {
1814 } elsif ($line =~ m/^([0-9a-fA-F]{40}) /){
1817 print "<tr style=\"background-color:#f6f5ed\">\n";
1822 print "<td><i>$co{'age_string'}</i></td>\n" .
1823 "<td><i>" . escapeHTML(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
1825 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$co{'id'}", -class => "list"}, "<b>" .
1826 escapeHTML(chop_str($co{'title'}, 50)) . "</b><br/>");
1827 while (my $setref = shift @files) {
1829 print $cgi->a({-href => "$my_uri?p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}", class => "list"},
1830 escapeHTML($set{'file'})) . "<br/>\n";
1833 "<td class=\"link\">" .
1834 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$co{'id'}"}, "commit") .
1835 " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}"}, "tree");
1839 %co = git_read_commit($1);
1848 my $head = git_read_hash("$project/HEAD");
1849 if (!defined $hash) {
1852 if (!defined $page) {
1856 print "<div class=\"page_nav\">\n" .
1857 $cgi->a({-href => "$my_uri?p=$project;a=summary"}, "summary") .
1859 " | " . $cgi->a({-href => "$my_uri?p=$project;a=log;h=$hash"}, "log") .
1860 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$hash"}, "commit") .
1861 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$hash"}, "commitdiff") .
1862 " | " . $cgi->a({-href => "$my_uri?p=$project;a=tree;h=$hash;hb=$hash"}, "tree") . "<br/>\n";
1864 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
1865 open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error(undef, "Open failed.");
1866 my (@revlist) = map { chomp; $_ } <$fd>;
1869 if ($hash ne $head || $page) {
1870 print $cgi->a({-href => "$my_uri?p=$project;a=shortlog"}, "HEAD");
1875 print " ⋅ " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash;pg=" . ($page-1), -accesskey => "p"}, "prev");
1877 print " ⋅ prev";
1879 if ($#revlist >= (100 * ($page+1)-1)) {
1880 print " ⋅ " . $cgi->a({-href => "$my_uri?p=$project;a=shortlog;h=$hash;pg=" . ($page+1), -accesskey => "n"}, "next");
1882 print " ⋅ next";
1887 $cgi->a({-href => "$my_uri?p=$project;a=summary", -class => "title"}, " ") .
1889 print "<table cellspacing=\"0\">\n";
1891 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
1892 my $commit = $revlist[$i];
1893 my %co = git_read_commit($commit);
1894 my %ad = date_str($co{'author_epoch'});
1896 print "<tr style=\"background-color:#f6f5ed\">\n";
1901 print "<td><i>$co{'age_string'}</i></td>\n" .
1902 "<td><i>" . escapeHTML(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
1903 "<td>" . $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit", -class => "list"}, "<b>" .
1904 escapeHTML($co{'title_short'}) . "</b>") . "</td>\n" .
1905 "<td class=\"link\">" .
1906 $cgi->a({-href => "$my_uri?p=$project;a=commit;h=$commit"}, "commit") .
1907 " | " . $cgi->a({-href => "$my_uri?p=$project;a=commitdiff;h=$commit"}, "commitdiff") .