3 # gitweb - 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 GPLv2
12 use CGI
qw(:standard :escapeHTML -nosticky);
13 use CGI
::Util
qw(unescape);
14 use CGI
::Carp
qw(fatalsToBrowser);
17 use File
::Temp
qw(tempfile);
18 binmode STDOUT
, ':utf8';
22 my $my_url = $cgi->url();
23 my $my_uri = $cgi->url(-absolute
=> 1);
26 # absolute fs-path which will be prepended to the project path
27 #my $projectroot = "/pub/scm";
28 my $projectroot = "/home/kay/public_html/pub/scm";
30 # location of the git-core binaries
31 my $gitbin = "/usr/bin";
33 # location for temporary files needed for diffs
34 my $git_temp = "/tmp/gitweb";
36 # target of the home link on top of all pages
37 my $home_link = $my_uri;
39 # html text to include at home page
40 my $home_text = "indextext.html";
42 # source of projects list
43 #my $projects_list = $projectroot;
44 my $projects_list = "index/index.aux";
47 my $etagsbin = "etags";
49 my $snapshots_url = "http://git.xmms.se/snapshot.cgi";
50 my $git_base_url = "git://git.xmms.se/xmms2";
72 # custom stuff - mantis/commit tags integration
75 my $href = shift || undef;
76 my $class = shift || "";
82 $class = "class=\"$class\"";
84 $aEnd = "<a $class href=\"$href\">";
86 $a =~ s!BUG\(([0-9]*)\)!$aStart<a href="http://bugs.xmms2.xmms.se/view.php?id=$1">BUG($1)</a>$aEnd!g;
87 $a =~ s!FEATURE\(([0-9]*)\)!$aStart<a href="http://bugs.xmms2.xmms.se/view.php?id=$1">FEATURE($1)</a>$aEnd!g;
88 $a =~ s!RELEASE: (.*)!RELEASE: $aStart<a href="http://wiki.xmms2.xmms.se/index.php/Release:$1">$1</a>$aEnd!g;
94 return committags_real
($a);
96 sub committags_shortlog
($$){
99 return committags_real
($a, $href, "list");
102 # custom stuff - refactored navbar
103 sub git_navbar
($$$$) {
106 my $curSection = shift;
107 my $extraLinks = shift;
109 my $sumLink = $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary");
110 my $slogLink = $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog");
111 my $logLink = $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log");
112 my $comLink = $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$head")}, "commit");
113 my $comdifLink = $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$head")}, "commitdiff");
114 my $treeLink = $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree")}, "tree");
115 my $snapLink = $cgi->a({-href
=> "$snapshots_url?tree=$project&commit=HEAD"}, "latest snapshot");
117 if ($curSection eq "summary") {
118 $sumLink = "summary";
120 elsif ($curSection eq "shortlog") {
121 $slogLink = "shortlog";
123 elsif ($curSection eq "log") {
126 elsif ($curSection eq "commit") {
129 elsif ($curSection eq "commitdiff") {
130 $comdifLink = "commitdiff";
132 elsif ($curSection eq "tree") {
136 my $retVal = "<div class=\"page_nav\">\n" .
141 " | " . $comdifLink .
144 "<br/>$extraLinks<br/>\n" .
149 # input validation and dispatch
150 my $action = $cgi->param('a');
151 if (defined $action) {
152 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
154 die_error
(undef, "Invalid action parameter.");
156 if ($action eq "git-logo.png") {
159 } elsif ($action eq "opml") {
165 my $order = $cgi->param('o');
166 if (defined $order) {
167 if ($order =~ m/[^0-9a-zA-Z_]/) {
169 die_error
(undef, "Invalid order parameter.");
173 my $project = $cgi->param('p');
174 if (defined $project) {
175 $project = validate_input
($project);
176 if (!defined($project)) {
177 die_error
(undef, "Invalid project parameter.");
179 if (!(-d
"$projectroot/$project")) {
181 die_error
(undef, "No such directory.");
183 if (!(-e
"$projectroot/$project/HEAD")) {
185 die_error
(undef, "No such project.");
187 $rss_link = "<link rel=\"alternate\" title=\"" . esc_param
($project) . " log\" href=\"" .
188 "$my_uri?" . esc_param
("p=$project;a=rss") . "\" type=\"application/rss+xml\"/>";
189 $ENV{'GIT_DIR'} = "$projectroot/$project";
195 my $file_name = $cgi->param('f');
196 if (defined $file_name) {
197 $file_name = validate_input
($file_name);
198 if (!defined($file_name)) {
199 die_error
(undef, "Invalid file parameter.");
203 my $hash = $cgi->param('h');
205 $hash = validate_input
($hash);
206 if (!defined($hash)) {
207 die_error
(undef, "Invalid hash parameter.");
211 my $hash_parent = $cgi->param('hp');
212 if (defined $hash_parent) {
213 $hash_parent = validate_input
($hash_parent);
214 if (!defined($hash_parent)) {
215 die_error
(undef, "Invalid hash parent parameter.");
219 my $hash_base = $cgi->param('hb');
220 if (defined $hash_base) {
221 $hash_base = validate_input
($hash_base);
222 if (!defined($hash_base)) {
223 die_error
(undef, "Invalid hash base parameter.");
227 my $page = $cgi->param('pg');
229 if ($page =~ m/[^0-9]$/) {
231 die_error
(undef, "Invalid page parameter.");
235 my $searchtext = $cgi->param('s');
236 if (defined $searchtext) {
237 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
239 die_error
(undef, "Invalid search parameter.");
241 $searchtext = quotemeta $searchtext;
247 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
250 if ($input =~ m/(^|\/)(|\
.|\
.\
.)($|\
/)/) {
253 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\
-\
+\#\
~\
%]/) {
259 if (!defined $action || $action eq "summary") {
262 } elsif ($action eq "heads") {
265 } elsif ($action eq "tags") {
268 } elsif ($action eq "blob") {
271 } elsif ($action eq "blob_plain") {
274 } elsif ($action eq "tree") {
277 } elsif ($action eq "rss") {
280 } elsif ($action eq "commit") {
283 } elsif ($action eq "log") {
286 } elsif ($action eq "blobdiff") {
289 } elsif ($action eq "blobdiff_plain") {
290 git_blobdiff_plain
();
292 } elsif ($action eq "commitdiff") {
295 } elsif ($action eq "commitdiff_plain") {
296 git_commitdiff_plain
();
298 } elsif ($action eq "history") {
301 } elsif ($action eq "search") {
304 } elsif ($action eq "shortlog") {
307 } elsif ($action eq "tag") {
312 die_error
(undef, "Unknown action.");
316 # quote unsafe chars, but keep the slash, even when it's not
317 # correct, but quoted slashes look too horrible in bookmarks
320 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
326 # replace invalid utf8 character with SUBSTITUTION sequence
329 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
330 $str = escapeHTML
($str);
334 # git may return quoted and escaped filenames
337 if ($str =~ m/^"(.*)"$/) {
339 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
344 sub git_header_html
{
345 my $status = shift || "200 OK";
349 if (defined $project) {
350 $title .= " - $project";
351 if (defined $action) {
352 $title .= "/$action";
355 print $cgi->header(-type
=>'text/html', -charset
=> 'utf-8', -status
=> $status, -expires
=> $expires);
357 <?xml version="1.0" encoding="utf-8"?>
358 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
359 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
360 <!-- git web interface v$version, (C) 2005, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke <ch\@gierke.de> -->
362 <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
363 <meta name="robots" content="index, nofollow"/>
364 <title>$title</title>
366 <link rel="stylesheet" type="text/css" href="gitweb-style.css"/>
370 print "<div class=\"page_header\">\n" .
371 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
372 "<img src=\"$my_uri?" . esc_param
("a=git-logo.png") . "\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
374 print $cgi->a({-href
=> esc_param
($home_link)}, "projects") . " / ";
375 if (defined $project) {
376 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, esc_html
($project));
377 if (defined $action) {
381 if (!defined $searchtext) {
386 $search_hash = $hash;
388 $search_hash = "HEAD";
390 $cgi->param("a", "search");
391 $cgi->param("h", $search_hash);
392 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
393 "<div class=\"search\">\n" .
394 $cgi->hidden(-name
=> "p") . "\n" .
395 $cgi->hidden(-name
=> "a") . "\n" .
396 $cgi->hidden(-name
=> "h") . "\n" .
397 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
399 $cgi->end_form() . "\n";
404 sub git_footer_html
{
405 print "<div class=\"page_footer\">\n";
406 if (defined $project) {
407 my $descr = git_read_description
($project);
408 if (defined $descr) {
409 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
411 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=rss"), -class => "rss_logo"}, "RSS") . "\n";
413 print $cgi->a({-href
=> "$my_uri?" . esc_param
("a=opml"), -class => "rss_logo"}, "OPML") . "\n";
421 my $status = shift || "403 Forbidden";
422 my $error = shift || "Malformed query, file missing or permission denied";
424 git_header_html
($status);
425 print "<div class=\"page_body\">\n" .
427 "$status - $error\n" .
437 open my $fd, "-|", "$gitbin/git-cat-file -t $hash" or return;
446 my $oENV = $ENV{'GIT_DIR'};
448 $ENV{'GIT_DIR'} = "$projectroot/$project";
449 if (open my $fd, "-|", "$gitbin/git-rev-parse", "--verify", "HEAD") {
452 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
457 $ENV{'GIT_DIR'} = $oENV;
465 open my $fd, "$projectroot/$path" or return undef;
469 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
476 open my $fd, "$path" or return undef;
483 sub git_read_description
{
485 return git_read_file
("$projectroot/$path/description");
488 sub git_read_category
{
490 return git_read_file
("$projectroot/$path/category");
498 open my $fd, "-|", "$gitbin/git-cat-file tag $tag_id" or return;
499 $tag{'id'} = $tag_id;
500 while (my $line = <$fd>) {
502 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
504 } elsif ($line =~ m/^type (.+)$/) {
506 } elsif ($line =~ m/^tag (.+)$/) {
508 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
512 } elsif ($line =~ m/--BEGIN/) {
513 push @comment, $line;
515 } elsif ($line eq "") {
519 push @comment, <$fd>;
520 $tag{'comment'} = \
@comment;
522 if (!defined $tag{'name'}) {
532 if ($age > 60*60*24*365*2) {
533 $age_str = (int $age/60/60/24/365);
534 $age_str .= " years ago";
535 } elsif ($age > 60*60*24*(365/12)*2) {
536 $age_str = int $age/60/60/24/(365/12);
537 $age_str .= " months ago";
538 } elsif ($age > 60*60*24*7*2) {
539 $age_str = int $age/60/60/24/7;
540 $age_str .= " weeks ago";
541 } elsif ($age > 60*60*24*2) {
542 $age_str = int $age/60/60/24;
543 $age_str .= " days ago";
544 } elsif ($age > 60*60*2) {
545 $age_str = int $age/60/60;
546 $age_str .= " hours ago";
547 } elsif ($age > 60*2) {
548 $age_str = int $age/60;
549 $age_str .= " min ago";
552 $age_str .= " sec ago";
554 $age_str .= " right now";
559 sub git_read_commit
{
560 my $commit_id = shift;
561 my $commit_text = shift;
566 if (defined $commit_text) {
567 @commit_lines = @
$commit_text;
570 open my $fd, "-|", "$gitbin/git-rev-list --header --parents --max-count=1 $commit_id" or return;
571 @commit_lines = split '\n', <$fd>;
576 my $header = shift @commit_lines;
577 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
580 ($co{'id'}, my @parents) = split ' ', $header;
581 $co{'parents'} = \
@parents;
582 $co{'parent'} = $parents[0];
583 while (my $line = shift @commit_lines) {
584 last if $line eq "\n";
585 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
587 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
589 $co{'author_epoch'} = $2;
590 $co{'author_tz'} = $3;
591 if ($co{'author'} =~ m/^([^<]+) </) {
592 $co{'author_name'} = $1;
594 $co{'author_name'} = $co{'author'};
596 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
597 $co{'committer'} = $1;
598 $co{'committer_epoch'} = $2;
599 $co{'committer_tz'} = $3;
600 $co{'committer_name'} = $co{'committer'};
601 $co{'committer_name'} =~ s/ <.*//;
604 if (!defined $co{'tree'}) {
608 foreach my $title (@commit_lines) {
611 $co{'title'} = chop_str
($title, 80, 5);
612 # remove leading stuff of merges to make the interesting part visible
613 if (length($title) > 50) {
614 $title =~ s/^Automatic //;
615 $title =~ s/^merge (of|with) /Merge ... /i;
616 if (length($title) > 50) {
617 $title =~ s/(http|rsync):\/\///;
619 if (length($title) > 50) {
620 $title =~ s/(master|www|rsync)\.//;
622 if (length($title) > 50) {
623 $title =~ s/kernel.org:?//;
625 if (length($title) > 50) {
626 $title =~ s/\/pub\/scm//;
629 $co{'title_short'} = chop_str
($title, 50, 5);
633 # remove added spaces
634 foreach my $line (@commit_lines) {
637 $co{'comment'} = \
@commit_lines;
639 my $age = time - $co{'committer_epoch'};
641 $co{'age_string'} = age_string
($age);
642 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
643 if ($age > 60*60*24*7*2) {
644 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
645 $co{'age_string_age'} = $co{'age_string'};
647 $co{'age_string_date'} = $co{'age_string'};
648 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
655 my $from_name = shift;
658 my $format = shift || "html";
660 my $from_tmp = "/dev/null";
661 my $to_tmp = "/dev/null";
664 # create tmp from-file
666 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
667 open my $fd2, "> $from_tmp";
668 open my $fd, "-|", "$gitbin/git-cat-file blob $from";
677 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
678 open my $fd2, "> $to_tmp";
679 open my $fd, "-|", "$gitbin/git-cat-file blob $to";
686 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
687 if ($format eq "plain") {
692 while (my $line = <$fd>) {
694 my $char = substr($line, 0, 1);
697 $color = " style=\"color:#008800;\"";
698 } elsif ($char eq "-") {
699 $color = " style=\"color:#cc0000;\"";
700 } elsif ($char eq "@") {
701 $color = " style=\"color:#990099;\"";
702 } elsif ($char eq "\\") {
706 while ((my $pos = index($line, "\t")) != -1) {
707 if (my $count = (8 - (($pos-1) % 8))) {
708 my $spaces = ' ' x
$count;
709 $line =~ s/\t/$spaces/;
712 print "<div class=\"pre\"$color>" . esc_html
($line) . "</div>\n";
726 my $mode = oct shift;
728 if (S_ISDIR
($mode & S_IFMT
)) {
730 } elsif (S_ISLNK
($mode)) {
732 } elsif (S_ISREG
($mode)) {
733 # git cares only about the executable bit
734 if ($mode & S_IXUSR
) {
747 my $add_len = shift || 10;
749 # allow only $len chars, but don't cut a word if it would fit in $add_len
750 # if it doesn't fit, cut it if it's still longer than the dots we would add
751 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
754 if (length($tail) > 4) {
761 my $mode = oct shift;
763 if (S_ISDIR
($mode & S_IFMT
)) {
765 } elsif (S_ISLNK
($mode)) {
767 } elsif (S_ISREG
($mode)) {
774 sub format_log_line_html
{
777 $line = esc_html
($line);
778 $line =~ s/ / /g;
779 if ($line =~ m/([0-9a-fA-F]{40})/) {
781 if (git_get_type
($hash_text) eq "commit") {
782 my $link = $cgi->a({-class => "text", -href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_text")}, $hash_text);
783 $line =~ s/$hash_text/$link/;
786 return committags
($line);
791 my $tz = shift || "-0000";
794 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
795 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
796 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
797 $date{'hour'} = $hour;
798 $date{'minute'} = $min;
799 $date{'mday'} = $mday;
800 $date{'day'} = $days[$wday];
801 $date{'month'} = $months[$mon];
802 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
803 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
805 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
806 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
807 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
808 $date{'hour_local'} = $hour;
809 $date{'minute_local'} = $min;
810 $date{'tz_local'} = $tz;
814 # git-logo (cached in browser for one day)
816 binmode STDOUT
, ':raw';
817 print $cgi->header(-type
=> 'image/png', -expires
=> '+1d');
818 # cat git-logo.png | hexdump -e '16/1 " %02x" "\n"' | sed 's/ /\\x/g'
819 print "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52" .
820 "\x00\x00\x00\x48\x00\x00\x00\x1b\x04\x03\x00\x00\x00\x2d\xd9\xd4" .
821 "\x2d\x00\x00\x00\x18\x50\x4c\x54\x45\xff\xff\xff\x60\x60\x5d\xb0" .
822 "\xaf\xaa\x00\x80\x00\xce\xcd\xc7\xc0\x00\x00\xe8\xe8\xe6\xf7\xf7" .
823 "\xf6\x95\x0c\xa7\x47\x00\x00\x00\x73\x49\x44\x41\x54\x28\xcf\x63" .
824 "\x48\x67\x20\x04\x4a\x5c\x18\x0a\x08\x2a\x62\x53\x61\x20\x02\x08" .
825 "\x0d\x69\x45\xac\xa1\xa1\x01\x30\x0c\x93\x60\x36\x26\x52\x91\xb1" .
826 "\x01\x11\xd6\xe1\x55\x64\x6c\x6c\xcc\x6c\x6c\x0c\xa2\x0c\x70\x2a" .
827 "\x62\x06\x2a\xc1\x62\x1d\xb3\x01\x02\x53\xa4\x08\xe8\x00\x03\x18" .
828 "\x26\x56\x11\xd4\xe1\x20\x97\x1b\xe0\xb4\x0e\x35\x24\x71\x29\x82" .
829 "\x99\x30\xb8\x93\x0a\x11\xb9\x45\x88\xc1\x8d\xa0\xa2\x44\x21\x06" .
830 "\x27\x41\x82\x40\x85\xc1\x45\x89\x20\x70\x01\x00\xa4\x3d\x21\xc5" .
831 "\x12\x1c\x9a\xfe\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\x82";
837 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
838 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
839 if (!defined $gcos) {
843 $owner =~ s/[,;].*$//;
847 sub git_read_projects
{
850 if (-d
$projects_list) {
851 # search in directory
852 my $dir = $projects_list;
853 opendir my $dh, $dir or return undef;
854 while (my $dir = readdir($dh)) {
855 if (-e
"$projectroot/$dir/HEAD") {
863 } elsif (-f
$projects_list) {
864 # read from file(url-encoded):
865 # 'git%2Fgit.git Linus+Torvalds'
866 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
867 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
868 open my $fd , $projects_list or return undef;
869 while (my $line = <$fd>) {
871 my ($path, $owner) = split ' ', $line;
872 $path = unescape
($path);
873 $owner = unescape
($owner);
874 if (!defined $path) {
877 if (-e
"$projectroot/$path/HEAD") {
887 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
891 sub git_project_list
{
892 my @list = git_read_projects
();
895 die_error
(undef, "No project found.");
897 foreach my $pr (@list) {
898 my $head = git_read_head
($pr->{'path'});
899 if (!defined $head) {
902 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
903 my %co = git_read_commit
($head);
907 $pr->{'commit'} = \
%co;
908 if (!defined $pr->{'descr'}) {
909 my $descr = git_read_description
($pr->{'path'}) || "";
910 $pr->{'descr'} = chop_str
($descr, 25, 5);
912 if (!defined $pr->{'category'}) {
913 my $cat = git_read_category
($pr->{'path'}) || "Misc";
914 $pr->{'category'} = $cat;
916 if (!defined $pr->{'owner'}) {
917 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
919 if (defined $projects{$pr->{'category'}}) {
920 push @
{$projects{$pr->{'category'}}}, $pr;
924 $projects{$pr->{'category'}} = \
@catList;
929 print "<div class=\"index_include\">\n";
930 open (my $fd, $home_text);
935 print "<table cellspacing=\"0\">\n" .
937 print "<th></th>\n" .
942 foreach my $cat (sort keys %projects) {
943 my @catList = @
{$projects{"$cat"}};
945 if (!defined($order) || (defined($order) && ($order eq "project"))) {
946 @catList = sort {$a->{'path'} cmp $b->{'path'}} @catList;
947 $headRow .= "<th>Project</th>\n";
949 $headRow .= "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=project")}, "Project") . "</th>\n";
951 if (defined($order) && ($order eq "descr")) {
952 @catList = sort {$a->{'descr'} cmp $b->{'descr'}} @catList;
953 $headRow .= "<th>Description</th>\n";
955 $headRow .= "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=descr")}, "Description") . "</th>\n";
957 if (defined($order) && ($order eq "owner")) {
958 @catList = sort {$a->{'owner'} cmp $b->{'owner'}} @catList;
959 $headRow .= "<th>Owner</th>\n";
961 $headRow .= "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=owner")}, "Owner") . "</th>\n";
963 if (defined($order) && ($order eq "age")) {
964 @catList = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @catList;
965 $headRow .= "<th>Last Change</th>\n";
967 $headRow .= "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=age")}, "Last Change") . "</th>\n";
971 print '<tr>'.$headRow.'</tr>';
975 print "<tr><td colspan=\"5\"><b>" . $cat . "</b></td><tr>";
977 foreach my $pr (@catList) {
979 print "<tr class=\"dark\">\n";
981 print "<tr class=\"light\">\n";
984 print "<td style=\"padding-left: 1em;\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=summary"), -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
985 "<td>$pr->{'descr'}</td>\n" .
986 "<td><i>" . chop_str
(esc_html
($pr->{'owner'}), 15) . "</i></td>\n";
988 if ($pr->{'commit'}{'age'} < 60*60*2) {
989 $colored_age = "<span style =\"color: #009900;\"><b><i>$pr->{'commit'}{'age_string'}</i></b></span>";
990 } elsif ($pr->{'commit'}{'age'} < 60*60*24*2) {
991 $colored_age = "<span style =\"color: #009900;\"><i>$pr->{'commit'}{'age_string'}</i></span>";
993 $colored_age = "<i>$pr->{'commit'}{'age_string'}</i>";
995 print "<td>$colored_age</td>\n" .
996 "<td class=\"link\">" .
997 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=summary")}, "summary") .
998 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=shortlog")}, "shortlog") .
999 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=log")}, "log") .
1000 " | " . $cgi->a({-href
=> "$snapshots_url/$pr->{'path'}-snapshot-HEAD.tar.bz2"}, "latest snapshot") .
1010 my $type = shift || "";
1012 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
1013 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
1014 open my $fd, "$projectroot/$project/info/refs" or return;
1015 while (my $line = <$fd>) {
1017 if ($line =~ m/^([0-9a-fA-F]{40})\t.*$type\/([^\
^]+)/) {
1018 if (defined $refs{$1}) {
1019 $refs{$1} .= " / $2";
1025 close $fd or return;
1030 my $ref_dir = shift;
1034 opendir my $dh, "$projectroot/$project/$ref_dir";
1035 while (my $dir = readdir($dh)) {
1036 if ($dir =~ m/^\./) {
1039 if (-d
"$projectroot/$project/$ref_dir/$dir") {
1040 opendir my $dh2, "$projectroot/$project/$ref_dir/$dir";
1041 my @subdirs = grep !m/^\./, readdir $dh2;
1043 foreach my $subdir (@subdirs) {
1044 push @refs, "$dir/$subdir"
1051 foreach my $ref_file (@refs) {
1052 my $ref_id = git_read_hash
("$project/$ref_dir/$ref_file");
1053 my $type = git_get_type
($ref_id) || next;
1056 $ref_item{'type'} = $type;
1057 $ref_item{'id'} = $ref_id;
1058 $ref_item{'epoch'} = 0;
1059 $ref_item{'age'} = "unknown";
1060 if ($type eq "tag") {
1061 my %tag = git_read_tag
($ref_id);
1062 $ref_item{'comment'} = $tag{'comment'};
1063 if ($tag{'type'} eq "commit") {
1064 %co = git_read_commit
($tag{'object'});
1065 $ref_item{'epoch'} = $co{'committer_epoch'};
1066 $ref_item{'age'} = $co{'age_string'};
1067 } elsif (defined($tag{'epoch'})) {
1068 my $age = time - $tag{'epoch'};
1069 $ref_item{'epoch'} = $tag{'epoch'};
1070 $ref_item{'age'} = age_string
($age);
1072 $ref_item{'reftype'} = $tag{'type'};
1073 $ref_item{'name'} = $tag{'name'};
1074 $ref_item{'refid'} = $tag{'object'};
1075 } elsif ($type eq "commit"){
1076 %co = git_read_commit
($ref_id);
1077 $ref_item{'reftype'} = "commit";
1078 $ref_item{'name'} = $ref_file;
1079 $ref_item{'title'} = $co{'title'};
1080 $ref_item{'refid'} = $ref_id;
1081 $ref_item{'epoch'} = $co{'committer_epoch'};
1082 $ref_item{'age'} = $co{'age_string'};
1085 push @reflist, \
%ref_item;
1088 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1093 my $descr = git_read_description
($project) || "none";
1094 my $head = git_read_head
($project);
1095 my %co = git_read_commit
($head);
1096 my %cd = date_str
($co{'committer_epoch'}, $co{'committer_tz'});
1099 if (-f
$projects_list) {
1100 open (my $fd , $projects_list);
1101 while (my $line = <$fd>) {
1103 my ($pr, $ow) = split ' ', $line;
1104 $pr = unescape
($pr);
1105 $ow = unescape
($ow);
1106 if ($pr eq $project) {
1113 if (!defined $owner) {
1114 $owner = get_file_owner
("$projectroot/$project");
1117 my $refs = read_info_ref
();
1119 print git_navbar
($project, $head, "summary", "");
1120 print "<div class=\"title\"> </div>\n";
1121 print "<table cellspacing=\"0\">\n" .
1122 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
1123 "<tr><td>owner</td><td>" . esc_html
($owner) . "</td></tr>\n" .
1124 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
1125 "<tr><td>url</td><td>$git_base_url/$project</td></tr>" .
1127 open my $fd, "-|", "$gitbin/git-rev-list --max-count=17 " . git_read_head
($project) or die_error
(undef, "Open failed.");
1128 my (@revlist) = map { chomp; $_ } <$fd>;
1131 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog"), -class => "title"}, "shortlog") .
1134 print "<table cellspacing=\"0\">\n";
1136 foreach my $commit (@revlist) {
1137 my %co = git_read_commit
($commit);
1138 my %ad = date_str
($co{'author_epoch'});
1140 print "<tr class=\"dark\">\n";
1142 print "<tr class=\"light\">\n";
1147 if (defined $refs->{$commit}) {
1148 $ref = " <span class=\"tag\">" . esc_html
($refs->{$commit}) . "</span>";
1150 print "<td><i>$co{'age_string'}</i></td>\n" .
1151 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
1153 if (length($co{'title_short'}) < length($co{'title'})) {
1154 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list", -title
=> "$co{'title'}"},
1155 "<b>" . committags_shortlog
(esc_html
($co{'title_short'}), ("$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"))) . "$ref</b>");
1157 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list"},
1158 "<b>" . committags_shortlog
(esc_html
($co{'title'}), ("$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"))) . "$ref</b>");
1161 "<td class=\"link\">" .
1162 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
1163 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1164 " | " . $cgi->a({-href
=> "$snapshots_url/$project-snapshot-$commit.tar.bz2"}, "snapshot") .
1168 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "...") . "</td>\n" .
1175 my $taglist = git_read_refs
("refs/tags");
1176 if (defined @
$taglist) {
1178 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tags"), -class => "title"}, "tags") .
1181 print "<table cellspacing=\"0\">\n";
1183 foreach my $entry (@
$taglist) {
1185 my $comment_lines = $tag{'comment'};
1186 my $comment = shift @
$comment_lines;
1187 if (defined($comment)) {
1188 $comment = chop_str
($comment, 30, 5);
1191 print "<tr class=\"dark\">\n";
1193 print "<tr class=\"light\">\n";
1197 print "<td><i>$tag{'age'}</i></td>\n" .
1199 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), -class => "list"},
1200 "<b>" . esc_html
($tag{'name'}) . "</b>") .
1203 if (defined($comment)) {
1204 print $cgi->a({-class => "list", -href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, $comment);
1207 "<td class=\"link\">";
1208 if ($tag{'type'} eq "tag") {
1209 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
1211 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1212 if ($tag{'reftype'} eq "commit") {
1213 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1214 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'refid'}")}, "log") .
1215 " | " . $cgi->a({-href
=> "$snapshots_url/$project-snapshot-$tag{'refid'}.tar.bz2"}, "snapshot");
1220 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tags")}, "...") . "</td>\n" .
1228 my $headlist = git_read_refs
("refs/heads");
1229 if (defined @
$headlist) {
1231 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=heads"), -class => "title"}, "heads") .
1234 print "<table cellspacing=\"0\">\n";
1236 foreach my $entry (@
$headlist) {
1239 print "<tr class=\"dark\">\n";
1241 print "<tr class=\"light\">\n";
1245 print "<td><i>$tag{'age'}</i></td>\n" .
1247 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}"), -class => "list"},
1248 "<b>" . esc_html
($tag{'name'}) . "</b>") .
1250 "<td class=\"link\">" .
1251 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1252 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'name'}")}, "log") .
1256 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=heads")}, "...") . "</td>\n" .
1267 my $head = git_read_head
($project);
1269 print git_navbar
($project, $head, "tag", "");
1270 my %tag = git_read_tag
($hash);
1272 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html
($tag{'name'})) . "\n" .
1274 print "<div class=\"title_text\">\n" .
1275 "<table cellspacing=\"0\">\n" .
1277 "<td>object</td>\n" .
1278 "<td>" . $cgi->a({-class => "list", -href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'object'}) . "</td>\n" .
1279 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'type'}) . "</td>\n" .
1281 if (defined($tag{'author'})) {
1282 my %ad = date_str
($tag{'epoch'}, $tag{'tz'});
1283 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
1284 print "<tr><td></td><td>" . $ad{'rfc2822'} . sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) . "</td></tr>\n";
1286 print "</table>\n\n" .
1288 print "<div class=\"page_body\">";
1289 my $comment = $tag{'comment'};
1290 foreach my $line (@
$comment) {
1291 print esc_html
($line) . "<br/>\n";
1298 my $head = git_read_head
($project);
1300 print git_navbar
($project, $head, "tags", "");
1301 my $taglist = git_read_refs
("refs/tags");
1303 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary"), -class => "title"}, " ") .
1305 print "<table cellspacing=\"0\">\n";
1307 if (defined @
$taglist) {
1308 foreach my $entry (@
$taglist) {
1310 my $comment_lines = $tag{'comment'};
1311 my $comment = shift @
$comment_lines;
1312 if (defined($comment)) {
1313 $comment = chop_str
($comment, 30, 5);
1316 print "<tr class=\"dark\">\n";
1318 print "<tr class=\"light\">\n";
1321 print "<td><i>$tag{'age'}</i></td>\n" .
1323 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), -class => "list"},
1324 "<b>" . esc_html
($tag{'name'}) . "</b>") .
1327 if (defined($comment)) {
1328 print $cgi->a({-class => "list", -href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, $comment);
1331 "<td class=\"link\">";
1332 if ($tag{'type'} eq "tag") {
1333 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
1335 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1336 if ($tag{'reftype'} eq "commit") {
1337 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1338 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'refid'}")}, "log") .
1339 " | " . $cgi->a({-href
=> "$snapshots_url/$project-snapshot-$tag{'refid'}.tar.bz2"}, "snapshot");
1350 my $head = git_read_head
($project);
1352 print git_navbar
($project, $head, "heads", "");
1353 my $taglist = git_read_refs
("refs/heads");
1355 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary"), -class => "title"}, " ") .
1357 print "<table cellspacing=\"0\">\n";
1359 if (defined @
$taglist) {
1360 foreach my $entry (@
$taglist) {
1363 print "<tr class=\"dark\">\n";
1365 print "<tr class=\"light\">\n";
1368 print "<td><i>$tag{'age'}</i></td>\n" .
1370 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}"), -class => "list"}, "<b>" . esc_html
($tag{'name'}) . "</b>") .
1372 "<td class=\"link\">" .
1373 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1374 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'name'}")}, "log") .
1383 sub git_get_hash_by_path
{
1385 my $path = shift || return undef;
1388 my @parts = split '/', $path;
1389 while (my $part = shift @parts) {
1390 open my $fd, "-|", "$gitbin/git-ls-tree $tree" or die_error
(undef, "Open git-ls-tree failed.");
1391 my (@entries) = map { chomp; $_ } <$fd>;
1392 close $fd or return undef;
1393 foreach my $line (@entries) {
1394 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1395 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1399 my $t_name = validate_input
(unquote
($4));
1400 if ($t_name eq $part) {
1404 if ($t_type eq "tree") {
1414 if (!defined $hash && defined $file_name) {
1415 my $base = $hash_base || git_read_head
($project);
1416 $hash = git_get_hash_by_path
($base, $file_name, "blob") || die_error
(undef, "Error lookup file.");
1420 foreach my $key (keys %highlight) {
1421 if ($file_name =~ /$key/) {
1422 $syntax = $highlight{$key};
1431 my ($dpath, $prefix) = $file_name =~ m/(.*\/)?
(.*)$ext/;
1432 my ($tmpfh, $tmpname) = tempfile
($prefix."XXXXXX", SUFFIX
=> $suffix, UNLINK
=> 1, DIR
=> $git_temp) or die_error
(undef, "Could not get tempfile");
1435 my $gcExit = system "$gitbin/git-cat-file blob $hash > $tmpname";
1437 die_error
(undef, "Cannot read blob: git-cat-file returned $gcExit");
1440 if ($etagsbin ne "" and $ext =~ /^\./) {
1441 open my $tmpfd, "-|", "echo '$tmpname' | $etagsbin --filter=yes" or die_error
(undef, "Could not read tags for $file_name");
1443 while (my $line = <$tmpfd>) {
1444 # discard first 2 lines
1449 my ($tag, $location) = $line =~ m/\x7f(.*)\x01(\d+),/;
1450 if (defined $tags{$location}) {
1451 push @
{$tags{$location}}, $tag;
1454 $tags{$location} = [$tag];
1460 open my $fd, "-|", "highlight -t 4 -l -a -f -I --syntax $syntax $tmpname" or die_error
(undef, "Open failed.");
1462 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
1464 if (defined $file_name) {
1465 $plainLink = $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$hash;f=$file_name")}, "plain") .
1466 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;hb=HEAD;f=$file_name")}, "head") . "<br/>\n";
1468 $plainLink = $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$hash")}, "plain") . "<br/>\n";
1470 print git_navbar
($project, $hash_base, "blob", $plainLink);
1472 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html
($co{'title'})) .
1475 print "<div class=\"page_nav\">\n" .
1476 "<br/><br/></div>\n" .
1477 "<div class=\"title\">$hash</div>\n";
1479 if (defined $file_name) {
1480 print "<div class=\"page_path\"><b>" . esc_html
($file_name) . "</b></div>\n";
1482 print "<div class=\"pre\">\n";
1484 while (my $line = <$fd>) {
1487 if ($syntax =~ /txt/) {
1488 $line = "<a name=\"l_$nr\" href=\"#l_$nr\" class=\"linenr\">$nr</a> $line";
1491 $line =~ s/<a name=\"(.+?)\">/<a name=\"$1\" href=\"#$1\" class=\"linenr\">/;
1494 if (defined $tags{$nr}) {
1495 my @tagList = @
{$tags{$nr}};
1496 foreach my $tag (@tagList) {
1497 $line =~ s/$tag/<a name=\"$tag\" href=\"#$tag\">$tag<\/a>/;
1501 printf "%s\n", $line;
1503 close $fd or print "Reading blob failed.\n";
1508 sub git_blob_plain
{
1509 my $save_as = "$hash.txt";
1510 if (defined $file_name) {
1511 $save_as = $file_name;
1513 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8', '-content-disposition' => "inline; filename=\"$save_as\"");
1514 open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or return;
1522 if (!defined $hash) {
1523 $hash = git_read_head
($project);
1524 if (defined $file_name) {
1525 my $base = $hash_base || $hash;
1526 $hash = git_get_hash_by_path
($base, $file_name, "tree");
1528 if (!defined $hash_base) {
1533 open my $fd, "-|", "$gitbin/git-ls-tree -z $hash" or die_error
(undef, "Open git-ls-tree failed.");
1534 chomp (my (@entries) = <$fd>);
1535 close $fd or die_error
(undef, "Reading tree failed.");
1538 my $refs = read_info_ref
();
1540 if (defined $refs->{$hash_base}) {
1541 $ref = " <span class=\"tag\">" . esc_html
($refs->{$hash_base}) . "</span>";
1546 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
1547 $base_key = ";hb=$hash_base";
1548 print git_navbar
($project, $hash_base, "tree", "");
1550 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html
($co{'title'}) . $ref) . "\n" .
1553 print "<div class=\"page_nav\">\n";
1554 print "<br/><br/></div>\n";
1555 print "<div class=\"title\">$hash</div>\n";
1557 if (defined $file_name) {
1558 $base = esc_html
("$file_name/");
1559 print "<div class=\"page_path\"><b>/" . esc_html
($file_name) . "</b></div>\n";
1561 print "<div class=\"page_path\"><b>/</b></div>\n";
1563 print "<div class=\"page_body\">\n";
1564 print "<table cellspacing=\"0\">\n";
1566 foreach my $line (@entries) {
1567 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1568 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1572 my $t_name = validate_input
($4);
1574 print "<tr class=\"dark\">\n";
1576 print "<tr class=\"light\">\n";
1579 print "<td style=\"font-family:monospace\">" . mode_str
($t_mode) . "</td>\n";
1580 if ($t_type eq "blob") {
1581 print "<td class=\"list\">" .
1582 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name"), -class => "list"}, esc_html
($t_name)) .
1584 "<td class=\"link\">" .
1585 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name")}, "blob") .
1586 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;h=$hash_base;f=$base$t_name")}, "history") .
1588 } elsif ($t_type eq "tree") {
1589 print "<td class=\"list\">" .
1590 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, esc_html
($t_name)) .
1592 "<td class=\"link\">" .
1593 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, "tree") .
1598 print "</table>\n" .
1604 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
1605 open my $fd, "-|", "$gitbin/git-rev-list --max-count=150 " . git_read_head
($project) or die_error
(undef, "Open failed.");
1606 my (@revlist) = map { chomp; $_ } <$fd>;
1607 close $fd or die_error
(undef, "Reading rev-list failed.");
1608 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
1609 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1610 "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
1611 print "<channel>\n";
1612 print "<title>$project</title>\n".
1613 "<link>" . esc_html
("$my_url?p=$project;a=summary") . "</link>\n".
1614 "<description>$project log</description>\n".
1615 "<language>en</language>\n";
1617 for (my $i = 0; $i <= $#revlist; $i++) {
1618 my $commit = $revlist[$i];
1619 my %co = git_read_commit
($commit);
1620 # we read 150, we always show 30 and the ones more recent than 48 hours
1621 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
1624 my %cd = date_str
($co{'committer_epoch'});
1625 open $fd, "-|", "$gitbin/git-diff-tree -r $co{'parent'} $co{'id'}" or next;
1626 my @difftree = map { chomp; $_ } <$fd>;
1630 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
1632 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
1633 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
1634 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
1635 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
1636 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
1637 "<content:encoded>" .
1639 my $comment = $co{'comment'};
1640 foreach my $line (@
$comment) {
1641 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
1642 print "$line<br/>\n";
1645 foreach my $line (@difftree) {
1646 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
1649 my $file = validate_input
(unquote
($7));
1650 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
1651 print "$file<br/>\n";
1654 "</content:encoded>\n" .
1657 print "</channel></rss>";
1661 my @list = git_read_projects
();
1663 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
1664 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1665 "<opml version=\"1.0\">\n".
1667 " <title>Git OPML Export</title>\n".
1670 "<outline text=\"git RSS feeds\">\n";
1672 foreach my $pr (@list) {
1674 my $head = git_read_head
($proj{'path'});
1675 if (!defined $head) {
1678 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
1679 my %co = git_read_commit
($head);
1684 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
1685 my $rss = "$my_url?p=$proj{'path'};a=rss";
1686 my $html = "$my_url?p=$proj{'path'};a=summary";
1687 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
1689 print "</outline>\n".
1695 my $head = git_read_head
($project);
1696 if (!defined $hash) {
1699 if (!defined $page) {
1702 my $refs = read_info_ref
();
1705 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
1706 open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error
(undef, "Open failed.");
1707 my (@revlist) = map { chomp; $_ } <$fd>;
1710 if ($hash ne $head || $page) {
1711 $navExtra .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "HEAD");
1713 $navExtra .= "HEAD";
1716 $navExtra .= " ⋅ " .
1717 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash;pg=" . ($page-1)), -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1719 $navExtra .= " ⋅ prev";
1721 if ($#revlist >= (100 * ($page+1)-1)) {
1722 $navExtra .= " ⋅ " .
1723 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash;pg=" . ($page+1)), -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1725 $navExtra .= " ⋅ next";
1727 print git_navbar
($project, $hash, "log", $navExtra);
1730 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary"), -class => "title"}, " ") .
1732 my %co = git_read_commit
($hash);
1733 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
1735 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
1736 my $commit = $revlist[$i];
1738 if (defined $refs->{$commit}) {
1739 $ref = " <span class=\"tag\">" . esc_html
($refs->{$commit}) . "</span>";
1741 my %co = git_read_commit
($commit);
1743 my %ad = date_str
($co{'author_epoch'});
1745 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "title"},
1746 "<span class=\"age\">$co{'age_string'}</span>" . esc_html
($co{'title'}) . $ref) . "\n";
1748 print "<div class=\"title_text\">\n" .
1749 "<div class=\"log_link\">\n" .
1750 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
1751 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1752 " | " . $cgi->a({-href
=> "$snapshots_url/$project-snapshot-$commit.tar.bz2"}, "snapshot") .
1755 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
1757 "<div class=\"log_body\">\n";
1758 my $comment = $co{'comment'};
1760 foreach my $line (@
$comment) {
1761 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1772 print format_log_line_html
($line) . "<br/>\n";
1783 my %co = git_read_commit
($hash);
1785 die_error
(undef, "Unknown commit object.");
1787 my %ad = date_str
($co{'author_epoch'}, $co{'author_tz'});
1788 my %cd = date_str
($co{'committer_epoch'}, $co{'committer_tz'});
1792 my $parent = $co{'parent'};
1793 if (!defined $parent) {
1797 open my $fd, "-|", "$gitbin/git-diff-tree -r -M $root $parent $hash" or die_error
(undef, "Open failed.");
1798 @difftree = map { chomp; $_ } <$fd>;
1799 close $fd or die_error
(undef, "Reading diff-tree failed.");
1801 # non-textual hash id's can be cached
1803 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
1806 my $refs = read_info_ref
();
1808 if (defined $refs->{$co{'id'}}) {
1809 $ref = " <span class=\"tag\">" . esc_html
($refs->{$co{'id'}}) . "</span>";
1811 git_header_html
(undef, $expires);
1812 # git_navbar omitted here - commitdiff link a bit weird o_O
1813 print "<div class=\"page_nav\">\n" .
1814 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1815 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash")}, "shortlog") .
1816 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash")}, "log") .
1818 if (defined $co{'parent'}) {
1819 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash")}, "commitdiff");
1821 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") . "\n" .
1822 "<br/><br/></div>\n";
1823 if (defined $co{'parent'}) {
1825 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash"), -class => "title"}, esc_html
($co{'title'}) . $ref) . "\n" .
1829 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash"), -class => "title"}, esc_html
($co{'title'})) . "\n" .
1832 print "<div class=\"title_text\">\n" .
1833 "<table cellspacing=\"0\">\n";
1834 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
1836 "<td></td><td> $ad{'rfc2822'}";
1837 if ($ad{'hour_local'} < 6) {
1838 printf(" (<span style=\"color: #cc0000;\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1840 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1844 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
1845 print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
1846 print "<tr><td>commit</td><td style=\"font-family:monospace\">$co{'id'}</td></tr>\n";
1849 "<td style=\"font-family:monospace\">" .
1850 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash"), class => "list"}, $co{'tree'}) .
1852 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
1855 my $parents = $co{'parents'};
1856 foreach my $par (@
$parents) {
1859 "<td style=\"font-family:monospace\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$par"), class => "list"}, $par) . "</td>" .
1860 "<td class=\"link\">" .
1861 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$par")}, "commit") .
1862 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash;hp=$par")}, "commitdiff") .
1866 print "<tr><td>snapshot</td>".
1867 "<td><a href=\"$snapshots_url/$project-snapshot-$hash.tar.bz2\">$hash</a></td></tr>";
1870 print "<div class=\"page_body\">\n";
1871 my $comment = $co{'comment'};
1874 foreach my $line (@
$comment) {
1875 # print only one empty line
1877 if ($empty || $signed) {
1884 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1886 print "<span style=\"color: #888888\">" . esc_html
($line) . "</span><br/>\n";
1889 print format_log_line_html
($line) . "<br/>\n";
1893 print "<div class=\"list_head\">\n";
1894 if ($#difftree > 10) {
1895 print(($#difftree + 1) . " files changed:\n");
1898 print "<table cellspacing=\"0\">\n";
1900 foreach my $line (@difftree) {
1901 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1902 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1903 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
1911 my $similarity = $6;
1912 my $file = validate_input
(unquote
($7));
1914 print "<tr class=\"dark\">\n";
1916 print "<tr class=\"light\">\n";
1919 if ($status eq "A") {
1921 if (S_ISREG
(oct $to_mode)) {
1922 $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
1925 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file"), -class => "list"}, esc_html
($file)) . "</td>\n" .
1926 "<td><span style=\"color: #008000;\">[new " . file_type
($to_mode) . "$mode_chng]</span></td>\n" .
1927 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob") . "</td>\n";
1928 } elsif ($status eq "D") {
1930 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file"), -class => "list"}, esc_html
($file)) . "</td>\n" .
1931 "<td><span style=\"color: #c00000;\">[deleted " . file_type
($from_mode). "]</span></td>\n" .
1932 "<td class=\"link\">" .
1933 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, "blob") .
1934 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;h=$hash;f=$file")}, "history") .
1936 } elsif ($status eq "M" || $status eq "T") {
1937 my $mode_chnge = "";
1938 if ($from_mode != $to_mode) {
1939 $mode_chnge = " <span style=\"color: #777777;\">[changed";
1940 if (((oct $from_mode) & S_IFMT
) != ((oct $to_mode) & S_IFMT
)) {
1941 $mode_chnge .= " from " . file_type
($from_mode) . " to " . file_type
($to_mode);
1943 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
1944 if (S_ISREG
($from_mode) && S_ISREG
($to_mode)) {
1945 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
1946 } elsif (S_ISREG
($to_mode)) {
1947 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
1950 $mode_chnge .= "]</span>\n";
1953 if ($to_id ne $from_id) {
1954 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file"), -class => "list"}, esc_html
($file));
1956 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file"), -class => "list"}, esc_html
($file));
1959 "<td>$mode_chnge</td>\n" .
1960 "<td class=\"link\">";
1961 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob");
1962 if ($to_id ne $from_id) {
1963 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file")}, "diff");
1965 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;h=$hash;f=$file")}, "history") . "\n";
1967 } elsif ($status eq "R") {
1968 my ($from_file, $to_file) = split "\t", $file;
1970 if ($from_mode != $to_mode) {
1971 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
1974 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file"), -class => "list"}, esc_html
($to_file)) . "</td>\n" .
1975 "<td><span style=\"color: #777777;\">[moved from " .
1976 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$from_file"), -class => "list"}, esc_html
($from_file)) .
1977 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
1978 "<td class=\"link\">" .
1979 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file")}, "blob");
1980 if ($to_id ne $from_id) {
1981 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file")}, "diff");
1992 mkdir($git_temp, 0700);
1994 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
1995 print git_navbar
($project, $hash_base, "blobdiff", $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff_plain;h=$hash;hp=$hash_parent")}, "plain"));
1997 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html
($co{'title'})) . "\n" .
2000 print "<div class=\"page_nav\">\n" .
2001 "<br/><br/></div>\n" .
2002 "<div class=\"title\">$hash vs $hash_parent</div>\n";
2004 if (defined $file_name) {
2005 print "<div class=\"page_path\"><b>/" . esc_html
($file_name) . "</b></div>\n";
2007 print "<div class=\"page_body\">\n" .
2008 "<div class=\"diff_info\">blob:" .
2009 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name")}, $hash_parent) .
2011 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, $hash) .
2013 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
2018 sub git_blobdiff_plain
{
2019 mkdir($git_temp, 0700);
2020 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8');
2021 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
2024 sub git_commitdiff
{
2025 mkdir($git_temp, 0700);
2026 my %co = git_read_commit
($hash);
2028 die_error
(undef, "Unknown commit object.");
2030 if (!defined $hash_parent) {
2031 $hash_parent = $co{'parent'};
2033 open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error
(undef, "Open failed.");
2034 my (@difftree) = map { chomp; $_ } <$fd>;
2035 close $fd or die_error
(undef, "Reading diff-tree failed.");
2037 # non-textual hash id's can be cached
2039 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2042 my $refs = read_info_ref
();
2044 if (defined $refs->{$co{'id'}}) {
2045 $ref = " <span class=\"tag\">" . esc_html
($refs->{$co{'id'}}) . "</span>";
2047 git_header_html
(undef, $expires);
2048 print git_navbar
($project, $hash, "commitdiff", $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent")}, "plain"));
2049 print "<div class=\"title\">\n" .
2050 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash")}, committags_real
(esc_html
($co{'title'}), "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash"), "title_cdiff") . $ref) . "\n" .
2052 print "<div class=\"page_body\">\n";
2053 my $comment = $co{'comment'};
2056 my @log = @
$comment;
2057 # remove first and empty lines after that
2059 while (defined $log[0] && $log[0] eq "") {
2062 foreach my $line (@log) {
2063 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2074 print format_log_line_html
($line) . "<br/>\n";
2077 foreach my $line (@difftree) {
2078 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2079 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2080 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2086 my $file = validate_input
(unquote
($6));
2087 if ($status eq "A") {
2088 print "<div class=\"diff_info\">" . file_type
($to_mode) . ":" .
2089 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id) . "(new)" .
2091 git_diff_print
(undef, "/dev/null", $to_id, "b/$file");
2092 } elsif ($status eq "D") {
2093 print "<div class=\"diff_info\">" . file_type
($from_mode) . ":" .
2094 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) . "(deleted)" .
2096 git_diff_print
($from_id, "a/$file", undef, "/dev/null");
2097 } elsif ($status eq "M") {
2098 if ($from_id ne $to_id) {
2099 print "<div class=\"diff_info\">" .
2100 file_type
($from_mode) . ":" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) .
2102 file_type
($to_mode) . ":" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id);
2104 git_diff_print
($from_id, "a/$file", $to_id, "b/$file");
2113 sub git_commitdiff_plain
{
2114 mkdir($git_temp, 0700);
2115 open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error
(undef, "Open failed.");
2116 my (@difftree) = map { chomp; $_ } <$fd>;
2117 close $fd or die_error
(undef, "Reading diff-tree failed.");
2119 # try to figure out the next tag after this commit
2121 my $refs = read_info_ref
("tags");
2122 open $fd, "-|", "$gitbin/git-rev-list HEAD";
2123 chomp (my (@commits) = <$fd>);
2125 foreach my $commit (@commits) {
2126 if (defined $refs->{$commit}) {
2127 $tagname = $refs->{$commit}
2129 if ($commit eq $hash) {
2134 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8', '-content-disposition' => "inline; filename=\"git-$hash.patch\"");
2135 my %co = git_read_commit
($hash);
2136 my %ad = date_str
($co{'author_epoch'}, $co{'author_tz'});
2137 my $comment = $co{'comment'};
2138 print "From: $co{'author'}\n" .
2139 "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
2140 "Subject: $co{'title'}\n";
2141 if (defined $tagname) {
2142 print "X-Git-Tag: $tagname\n";
2144 print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
2147 foreach my $line (@
$comment) {;
2152 foreach my $line (@difftree) {
2153 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2158 if ($status eq "A") {
2159 git_diff_print
(undef, "/dev/null", $to_id, "b/$file", "plain");
2160 } elsif ($status eq "D") {
2161 git_diff_print
($from_id, "a/$file", undef, "/dev/null", "plain");
2162 } elsif ($status eq "M") {
2163 git_diff_print
($from_id, "a/$file", $to_id, "b/$file", "plain");
2169 if (!defined $hash) {
2170 $hash = git_read_head
($project);
2172 my %co = git_read_commit
($hash);
2174 die_error
(undef, "Unknown commit object.");
2176 my $refs = read_info_ref
();
2178 print git_navbar
($project, $hash, "history", "");
2180 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash"), -class => "title"}, committags
(esc_html
($co{'title'}))) . "\n" .
2182 print "<div class=\"page_path\"><b>/" . esc_html
($file_name) . "</b><br/></div>\n";
2184 open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin \'$file_name\'";
2186 print "<table cellspacing=\"0\">\n";
2188 while (my $line = <$fd>) {
2189 if ($line =~ m/^([0-9a-fA-F]{40})/){
2193 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/ && (defined $commit)) {
2194 my %co = git_read_commit
($commit);
2199 if (defined $refs->{$commit}) {
2200 $ref = " <span class=\"tag\">" . esc_html
($refs->{$commit}) . "</span>";
2203 print "<tr class=\"dark\">\n";
2205 print "<tr class=\"light\">\n";
2208 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2209 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2210 "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list"}, "<b>" .
2211 committags
(esc_html
(chop_str
($co{'title'}, 50))) . "$ref</b>") . "</td>\n" .
2212 "<td class=\"link\">" .
2213 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
2214 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2215 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;hb=$commit;f=$file_name")}, "blob");
2216 my $blob = git_get_hash_by_path
($hash, $file_name);
2217 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2218 if (defined $blob && defined $blob_parent && $blob ne $blob_parent) {
2220 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=$file_name")},
2234 if (!defined $searchtext) {
2235 die_error
("", "Text field empty.");
2237 if (!defined $hash) {
2238 $hash = git_read_head
($project);
2240 my %co = git_read_commit
($hash);
2242 die_error
(undef, "Unknown commit object.");
2244 # pickaxe may take all resources of your box and run for several minutes
2245 # with every query - so decide by yourself how public you make this feature :)
2246 my $commit_search = 1;
2247 my $author_search = 0;
2248 my $committer_search = 0;
2249 my $pickaxe_search = 0;
2250 if ($searchtext =~ s/^author\\://i) {
2252 } elsif ($searchtext =~ s/^committer\\://i) {
2253 $committer_search = 1;
2254 } elsif ($searchtext =~ s/^pickaxe\\://i) {
2256 $pickaxe_search = 1;
2259 print git_navbar
($project, $hash, "search", "");
2262 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html
($co{'title'})) . "\n" .
2264 print "<table cellspacing=\"0\">\n";
2266 if ($commit_search) {
2268 open my $fd, "-|", "$gitbin/git-rev-list --header --parents $hash" or next;
2269 while (my $commit_text = <$fd>) {
2270 if (!grep m/$searchtext/i, $commit_text) {
2273 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
2276 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
2279 my @commit_lines = split "\n", $commit_text;
2280 my %co = git_read_commit
(undef, \
@commit_lines);
2285 print "<tr class=\"dark\">\n";
2287 print "<tr class=\"light\">\n";
2290 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2291 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2293 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" . esc_html
(chop_str
($co{'title'}, 50)) . "</b><br/>");
2294 my $comment = $co{'comment'};
2295 foreach my $line (@
$comment) {
2296 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2297 my $lead = esc_html
($1) || "";
2298 $lead = chop_str
($lead, 30, 10);
2299 my $match = esc_html
($2) || "";
2300 my $trail = esc_html
($3) || "";
2301 $trail = chop_str
($trail, 30, 10);
2302 my $text = "$lead<span style=\"color:#e00000\">$match</span>$trail";
2303 print chop_str
($text, 80, 5) . "<br/>\n";
2307 "<td class=\"link\">" .
2308 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2309 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2316 if ($pickaxe_search) {
2318 open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin -S\'$searchtext\'";
2321 while (my $line = <$fd>) {
2322 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2325 $set{'from_id'} = $3;
2327 $set{'id'} = $set{'to_id'};
2328 if ($set{'id'} =~ m/0{40}/) {
2329 $set{'id'} = $set{'from_id'};
2331 if ($set{'id'} =~ m/0{40}/) {
2335 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
2338 print "<tr class=\"dark\">\n";
2340 print "<tr class=\"light\">\n";
2343 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2344 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2346 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" .
2347 esc_html
(chop_str
($co{'title'}, 50)) . "</b><br/>");
2348 while (my $setref = shift @files) {
2350 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}"), class => "list"},
2351 "<span style=\"color:#e00000\">" . esc_html
($set{'file'}) . "</span>") .
2355 "<td class=\"link\">" .
2356 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2357 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2361 %co = git_read_commit
($1);
2371 my $head = git_read_head
($project);
2372 if (!defined $hash) {
2375 if (!defined $page) {
2378 my $refs = read_info_ref
();
2381 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2382 open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error
(undef, "Open failed.");
2383 my (@revlist) = map { chomp; $_ } <$fd>;
2387 if ($hash ne $head || $page) {
2388 $navExtra .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "HEAD");
2390 $navExtra .= "HEAD";
2393 $navExtra .= " ⋅ " .
2394 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash;pg=" . ($page-1)), -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2396 $navExtra .= " ⋅ prev";
2398 if ($#revlist >= (100 * ($page+1)-1)) {
2399 $navExtra .= " ⋅ " .
2400 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)), -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2402 $navExtra .= " ⋅ next";
2404 print git_navbar
($project, $hash, "shortlog", $navExtra);
2406 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary"), -class => "title"}, " ") .
2408 print "<table cellspacing=\"0\">\n";
2410 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2411 my $commit = $revlist[$i];
2413 if (defined $refs->{$commit}) {
2414 $ref = " <span class=\"tag\">" . esc_html
($refs->{$commit}) . "</span>";
2416 my %co = git_read_commit
($commit);
2417 my %ad = date_str
($co{'author_epoch'});
2419 print "<tr class=\"dark\">\n";
2421 print "<tr class=\"light\">\n";
2424 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2425 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
2427 if (length($co{'title_short'}) < length($co{'title'})) {
2428 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list", -title
=> "$co{'title'}"},
2429 "<b>" . committags_shortlog
(esc_html
($co{'title_short'}), ("$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"))) . "$ref</b>");
2431 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list"},
2432 "<b>" . committags_shortlog
(esc_html
($co{'title_short'}), ("$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"))) . "$ref</b>");
2435 "<td class=\"link\">" .
2436 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
2437 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2438 " | " . $cgi->a({-href
=> "$snapshots_url/$project-snapshot-$commit.tar.bz2"}, "snapshot") .
2442 if ($#revlist >= (100 * ($page+1)-1)) {
2445 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)), -title
=> "Alt-n"}, "next") .