3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI
qw(:standard :escapeHTML -nosticky);
13 use CGI
::Util
qw(unescape);
14 use CGI
::Carp
qw(fatalsToBrowser);
17 binmode STDOUT
, ':utf8';
21 my $my_url = $cgi->url();
22 my $my_uri = $cgi->url(-absolute
=> 1);
25 # location of the git-core binaries
26 my $gitbin = "/usr/bin";
28 # absolute fs-path which will be prepended to the project path
29 #my $projectroot = "/pub/scm";
30 my $projectroot = "/home/kay/public_html/pub/scm";
32 # version of the git-core binaries
33 my $git_version = qx($gitbin/git
--version
);
34 if ($git_version =~ m/git version (.*)$/) {
37 $git_version = "unknown";
40 # location for temporary files needed for diffs
41 my $git_temp = "/tmp/gitweb";
43 # target of the home link on top of all pages
44 my $home_link = $my_uri;
46 # html text to include at home page
47 my $home_text = "indextext.html";
49 # URI of default stylesheet
50 my $stylesheet = "gitweb.css";
52 # source of projects list
53 #my $projects_list = $projectroot;
54 my $projects_list = "index/index.aux";
56 # default blob_plain mimetype and default charset for text/plain blob
57 my $default_blob_plain_mimetype = 'text/plain';
58 my $default_text_plain_charset = undef;
60 # file to use for guessing MIME types before trying /etc/mime.types
61 # (relative to the current git repository)
62 my $mimetypes_file = undef;
65 # input validation and dispatch
66 my $action = $cgi->param('a');
67 if (defined $action) {
68 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
70 die_error
(undef, "Invalid action parameter.");
72 if ($action eq "git-logo.png") {
75 } elsif ($action eq "opml") {
81 my $order = $cgi->param('o');
83 if ($order =~ m/[^0-9a-zA-Z_]/) {
85 die_error
(undef, "Invalid order parameter.");
89 my $project = ($cgi->param('p') || $ENV{'PATH_INFO'});
90 if (defined $project) {
91 $project =~ s
|^/||; $project =~ s|/$||;
92 $project = validate_input
($project);
93 if (!defined($project)) {
94 die_error
(undef, "Invalid project parameter.");
96 if (!(-d
"$projectroot/$project")) {
98 die_error
(undef, "No such directory.");
100 if (!(-e
"$projectroot/$project/HEAD")) {
102 die_error
(undef, "No such project.");
104 $rss_link = "<link rel=\"alternate\" title=\"" . esc_param
($project) . " log\" href=\"" .
105 "$my_uri?" . esc_param
("p=$project;a=rss") . "\" type=\"application/rss+xml\"/>";
106 $ENV{'GIT_DIR'} = "$projectroot/$project";
112 my $file_name = $cgi->param('f');
113 if (defined $file_name) {
114 $file_name = validate_input
($file_name);
115 if (!defined($file_name)) {
116 die_error
(undef, "Invalid file parameter.");
120 my $hash = $cgi->param('h');
122 $hash = validate_input
($hash);
123 if (!defined($hash)) {
124 die_error
(undef, "Invalid hash parameter.");
128 my $hash_parent = $cgi->param('hp');
129 if (defined $hash_parent) {
130 $hash_parent = validate_input
($hash_parent);
131 if (!defined($hash_parent)) {
132 die_error
(undef, "Invalid hash parent parameter.");
136 my $hash_base = $cgi->param('hb');
137 if (defined $hash_base) {
138 $hash_base = validate_input
($hash_base);
139 if (!defined($hash_base)) {
140 die_error
(undef, "Invalid hash base parameter.");
144 my $page = $cgi->param('pg');
146 if ($page =~ m/[^0-9]$/) {
148 die_error
(undef, "Invalid page parameter.");
152 my $searchtext = $cgi->param('s');
153 if (defined $searchtext) {
154 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
156 die_error
(undef, "Invalid search parameter.");
158 $searchtext = quotemeta $searchtext;
164 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
167 if ($input =~ m/(^|\/)(|\
.|\
.\
.)($|\
/)/) {
170 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\
-\
+\#\
~\
%]/) {
176 if (!defined $action || $action eq "summary") {
179 } elsif ($action eq "heads") {
182 } elsif ($action eq "tags") {
185 } elsif ($action eq "blob") {
188 } elsif ($action eq "blob_plain") {
191 } elsif ($action eq "tree") {
194 } elsif ($action eq "rss") {
197 } elsif ($action eq "commit") {
200 } elsif ($action eq "log") {
203 } elsif ($action eq "blobdiff") {
206 } elsif ($action eq "blobdiff_plain") {
207 git_blobdiff_plain
();
209 } elsif ($action eq "commitdiff") {
212 } elsif ($action eq "commitdiff_plain") {
213 git_commitdiff_plain
();
215 } elsif ($action eq "history") {
218 } elsif ($action eq "search") {
221 } elsif ($action eq "shortlog") {
224 } elsif ($action eq "tag") {
227 } elsif ($action eq "blame") {
232 die_error
(undef, "Unknown action.");
236 # quote unsafe chars, but keep the slash, even when it's not
237 # correct, but quoted slashes look too horrible in bookmarks
240 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
246 # replace invalid utf8 character with SUBSTITUTION sequence
249 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
250 $str = escapeHTML
($str);
254 # git may return quoted and escaped filenames
257 if ($str =~ m/^"(.*)"$/) {
259 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
264 # CSS class for given age value (in seconds)
268 if ($age < 60*60*2) {
270 } elsif ($age < 60*60*24*2) {
277 sub git_header_html
{
278 my $status = shift || "200 OK";
282 if (defined $project) {
283 $title .= " - $project";
284 if (defined $action) {
285 $title .= "/$action";
286 if (defined $file_name) {
287 $title .= " - $file_name";
288 if ($action eq "tree" && $file_name !~ m
|/$|) {
294 print $cgi->header(-type
=>'text/html', -charset
=> 'utf-8', -status
=> $status, -expires
=> $expires);
296 <?xml version="1.0" encoding="utf-8"?>
297 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
298 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
299 <!-- git web interface v$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
300 <!-- git core binaries version $git_version -->
302 <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
303 <meta name="robots" content="index, nofollow"/>
304 <title>$title</title>
305 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
310 print "<div class=\"page_header\">\n" .
311 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
312 "<img src=\"$my_uri?" . esc_param
("a=git-logo.png") . "\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
314 print $cgi->a({-href
=> esc_param
($home_link)}, "projects") . " / ";
315 if (defined $project) {
316 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, esc_html
($project));
317 if (defined $action) {
321 if (!defined $searchtext) {
325 if (defined $hash_base) {
326 $search_hash = $hash_base;
327 } elsif (defined $hash) {
328 $search_hash = $hash;
330 $search_hash = "HEAD";
332 $cgi->param("a", "search");
333 $cgi->param("h", $search_hash);
334 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
335 "<div class=\"search\">\n" .
336 $cgi->hidden(-name
=> "p") . "\n" .
337 $cgi->hidden(-name
=> "a") . "\n" .
338 $cgi->hidden(-name
=> "h") . "\n" .
339 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
341 $cgi->end_form() . "\n";
346 sub git_footer_html
{
347 print "<div class=\"page_footer\">\n";
348 if (defined $project) {
349 my $descr = git_read_description
($project);
350 if (defined $descr) {
351 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
353 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=rss"), -class => "rss_logo"}, "RSS") . "\n";
355 print $cgi->a({-href
=> "$my_uri?" . esc_param
("a=opml"), -class => "rss_logo"}, "OPML") . "\n";
363 my $status = shift || "403 Forbidden";
364 my $error = shift || "Malformed query, file missing or permission denied";
366 git_header_html
($status);
367 print "<div class=\"page_body\">\n" .
369 "$status - $error\n" .
379 open my $fd, "-|", "$gitbin/git-cat-file -t $hash" or return;
388 my $oENV = $ENV{'GIT_DIR'};
390 $ENV{'GIT_DIR'} = "$projectroot/$project";
391 if (open my $fd, "-|", "$gitbin/git-rev-parse", "--verify", "HEAD") {
394 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
399 $ENV{'GIT_DIR'} = $oENV;
407 open my $fd, "$projectroot/$path" or return undef;
411 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
416 sub git_read_description
{
419 open my $fd, "$projectroot/$path/description" or return undef;
431 open my $fd, "-|", "$gitbin/git-cat-file tag $tag_id" or return;
432 $tag{'id'} = $tag_id;
433 while (my $line = <$fd>) {
435 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
437 } elsif ($line =~ m/^type (.+)$/) {
439 } elsif ($line =~ m/^tag (.+)$/) {
441 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
445 } elsif ($line =~ m/--BEGIN/) {
446 push @comment, $line;
448 } elsif ($line eq "") {
452 push @comment, <$fd>;
453 $tag{'comment'} = \
@comment;
455 if (!defined $tag{'name'}) {
465 if ($age > 60*60*24*365*2) {
466 $age_str = (int $age/60/60/24/365);
467 $age_str .= " years ago";
468 } elsif ($age > 60*60*24*(365/12)*2) {
469 $age_str = int $age/60/60/24/(365/12);
470 $age_str .= " months ago";
471 } elsif ($age > 60*60*24*7*2) {
472 $age_str = int $age/60/60/24/7;
473 $age_str .= " weeks ago";
474 } elsif ($age > 60*60*24*2) {
475 $age_str = int $age/60/60/24;
476 $age_str .= " days ago";
477 } elsif ($age > 60*60*2) {
478 $age_str = int $age/60/60;
479 $age_str .= " hours ago";
480 } elsif ($age > 60*2) {
481 $age_str = int $age/60;
482 $age_str .= " min ago";
485 $age_str .= " sec ago";
487 $age_str .= " right now";
492 sub git_read_commit
{
493 my $commit_id = shift;
494 my $commit_text = shift;
499 if (defined $commit_text) {
500 @commit_lines = @
$commit_text;
503 open my $fd, "-|", "$gitbin/git-rev-list --header --parents --max-count=1 $commit_id" or return;
504 @commit_lines = split '\n', <$fd>;
509 my $header = shift @commit_lines;
510 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
513 ($co{'id'}, my @parents) = split ' ', $header;
514 $co{'parents'} = \
@parents;
515 $co{'parent'} = $parents[0];
516 while (my $line = shift @commit_lines) {
517 last if $line eq "\n";
518 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
520 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
522 $co{'author_epoch'} = $2;
523 $co{'author_tz'} = $3;
524 if ($co{'author'} =~ m/^([^<]+) </) {
525 $co{'author_name'} = $1;
527 $co{'author_name'} = $co{'author'};
529 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
530 $co{'committer'} = $1;
531 $co{'committer_epoch'} = $2;
532 $co{'committer_tz'} = $3;
533 $co{'committer_name'} = $co{'committer'};
534 $co{'committer_name'} =~ s/ <.*//;
537 if (!defined $co{'tree'}) {
541 foreach my $title (@commit_lines) {
544 $co{'title'} = chop_str
($title, 80, 5);
545 # remove leading stuff of merges to make the interesting part visible
546 if (length($title) > 50) {
547 $title =~ s/^Automatic //;
548 $title =~ s/^merge (of|with) /Merge ... /i;
549 if (length($title) > 50) {
550 $title =~ s/(http|rsync):\/\///;
552 if (length($title) > 50) {
553 $title =~ s/(master|www|rsync)\.//;
555 if (length($title) > 50) {
556 $title =~ s/kernel.org:?//;
558 if (length($title) > 50) {
559 $title =~ s/\/pub\/scm//;
562 $co{'title_short'} = chop_str
($title, 50, 5);
566 # remove added spaces
567 foreach my $line (@commit_lines) {
570 $co{'comment'} = \
@commit_lines;
572 my $age = time - $co{'committer_epoch'};
574 $co{'age_string'} = age_string
($age);
575 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
576 if ($age > 60*60*24*7*2) {
577 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
578 $co{'age_string_age'} = $co{'age_string'};
580 $co{'age_string_date'} = $co{'age_string'};
581 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
588 my $from_name = shift;
591 my $format = shift || "html";
593 my $from_tmp = "/dev/null";
594 my $to_tmp = "/dev/null";
597 # create tmp from-file
599 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
600 open my $fd2, "> $from_tmp";
601 open my $fd, "-|", "$gitbin/git-cat-file blob $from";
610 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
611 open my $fd2, "> $to_tmp";
612 open my $fd, "-|", "$gitbin/git-cat-file blob $to";
619 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
620 if ($format eq "plain") {
625 while (my $line = <$fd>) {
627 my $char = substr($line, 0, 1);
630 $diff_class = " add";
631 } elsif ($char eq "-") {
632 $diff_class = " rem";
633 } elsif ($char eq "@") {
634 $diff_class = " chunk_header";
635 } elsif ($char eq "\\") {
639 while ((my $pos = index($line, "\t")) != -1) {
640 if (my $count = (8 - (($pos-1) % 8))) {
641 my $spaces = ' ' x
$count;
642 $line =~ s/\t/$spaces/;
645 print "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
659 my $mode = oct shift;
661 if (S_ISDIR
($mode & S_IFMT
)) {
663 } elsif (S_ISLNK
($mode)) {
665 } elsif (S_ISREG
($mode)) {
666 # git cares only about the executable bit
667 if ($mode & S_IXUSR
) {
680 my $add_len = shift || 10;
682 # allow only $len chars, but don't cut a word if it would fit in $add_len
683 # if it doesn't fit, cut it if it's still longer than the dots we would add
684 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
687 if (length($tail) > 4) {
694 my $mode = oct shift;
696 if (S_ISDIR
($mode & S_IFMT
)) {
698 } elsif (S_ISLNK
($mode)) {
700 } elsif (S_ISREG
($mode)) {
707 sub format_log_line_html
{
710 $line = esc_html
($line);
711 $line =~ s/ / /g;
712 if ($line =~ m/([0-9a-fA-F]{40})/) {
714 if (git_get_type
($hash_text) eq "commit") {
715 my $link = $cgi->a({-class => "text", -href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_text")}, $hash_text);
716 $line =~ s/$hash_text/$link/;
724 my $tz = shift || "-0000";
727 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
728 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
729 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
730 $date{'hour'} = $hour;
731 $date{'minute'} = $min;
732 $date{'mday'} = $mday;
733 $date{'day'} = $days[$wday];
734 $date{'month'} = $months[$mon];
735 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
736 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
738 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
739 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
740 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
741 $date{'hour_local'} = $hour;
742 $date{'minute_local'} = $min;
743 $date{'tz_local'} = $tz;
747 # git-logo (cached in browser for one day)
749 binmode STDOUT
, ':raw';
750 print $cgi->header(-type
=> 'image/png', -expires
=> '+1d');
751 # cat git-logo.png | hexdump -e '16/1 " %02x" "\n"' | sed 's/ /\\x/g'
752 print "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52" .
753 "\x00\x00\x00\x48\x00\x00\x00\x1b\x04\x03\x00\x00\x00\x2d\xd9\xd4" .
754 "\x2d\x00\x00\x00\x18\x50\x4c\x54\x45\xff\xff\xff\x60\x60\x5d\xb0" .
755 "\xaf\xaa\x00\x80\x00\xce\xcd\xc7\xc0\x00\x00\xe8\xe8\xe6\xf7\xf7" .
756 "\xf6\x95\x0c\xa7\x47\x00\x00\x00\x73\x49\x44\x41\x54\x28\xcf\x63" .
757 "\x48\x67\x20\x04\x4a\x5c\x18\x0a\x08\x2a\x62\x53\x61\x20\x02\x08" .
758 "\x0d\x69\x45\xac\xa1\xa1\x01\x30\x0c\x93\x60\x36\x26\x52\x91\xb1" .
759 "\x01\x11\xd6\xe1\x55\x64\x6c\x6c\xcc\x6c\x6c\x0c\xa2\x0c\x70\x2a" .
760 "\x62\x06\x2a\xc1\x62\x1d\xb3\x01\x02\x53\xa4\x08\xe8\x00\x03\x18" .
761 "\x26\x56\x11\xd4\xe1\x20\x97\x1b\xe0\xb4\x0e\x35\x24\x71\x29\x82" .
762 "\x99\x30\xb8\x93\x0a\x11\xb9\x45\x88\xc1\x8d\xa0\xa2\x44\x21\x06" .
763 "\x27\x41\x82\x40\x85\xc1\x45\x89\x20\x70\x01\x00\xa4\x3d\x21\xc5" .
764 "\x12\x1c\x9a\xfe\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\x82";
770 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
771 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
772 if (!defined $gcos) {
776 $owner =~ s/[,;].*$//;
777 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
780 sub git_read_projects
{
783 if (-d
$projects_list) {
784 # search in directory
785 my $dir = $projects_list;
786 opendir my $dh, $dir or return undef;
787 while (my $dir = readdir($dh)) {
788 if (-e
"$projectroot/$dir/HEAD") {
796 } elsif (-f
$projects_list) {
797 # read from file(url-encoded):
798 # 'git%2Fgit.git Linus+Torvalds'
799 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
800 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
801 open my $fd , $projects_list or return undef;
802 while (my $line = <$fd>) {
804 my ($path, $owner) = split ' ', $line;
805 $path = unescape
($path);
806 $owner = unescape
($owner);
807 if (!defined $path) {
810 if (-e
"$projectroot/$path/HEAD") {
813 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
820 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
824 sub git_get_project_config
{
827 return unless ($key);
828 $key =~ s/^gitweb\.//;
829 return if ($key =~ m/\W/);
831 my $val = qx($gitbin/git
-repo
-config
--get gitweb
.$key);
835 sub git_get_project_config_bool
{
836 my $val = git_get_project_config
(@_);
837 if ($val and $val =~ m/true|yes|on/) {
840 return; # implicit false
843 sub git_project_list
{
844 my @list = git_read_projects
();
847 die_error
(undef, "No project found.");
849 foreach my $pr (@list) {
850 my $head = git_read_head
($pr->{'path'});
851 if (!defined $head) {
854 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
855 my %co = git_read_commit
($head);
859 $pr->{'commit'} = \
%co;
860 if (!defined $pr->{'descr'}) {
861 my $descr = git_read_description
($pr->{'path'}) || "";
862 $pr->{'descr'} = chop_str
($descr, 25, 5);
864 if (!defined $pr->{'owner'}) {
865 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
871 print "<div class=\"index_include\">\n";
872 open (my $fd, $home_text);
877 print "<table class=\"project_list\">\n" .
879 if (!defined($order) || (defined($order) && ($order eq "project"))) {
880 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
881 print "<th>Project</th>\n";
883 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=project")}, "Project") . "</th>\n";
885 if (defined($order) && ($order eq "descr")) {
886 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
887 print "<th>Description</th>\n";
889 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=descr")}, "Description") . "</th>\n";
891 if (defined($order) && ($order eq "owner")) {
892 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
893 print "<th>Owner</th>\n";
895 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=owner")}, "Owner") . "</th>\n";
897 if (defined($order) && ($order eq "age")) {
898 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
899 print "<th>Last Change</th>\n";
901 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=age")}, "Last Change") . "</th>\n";
903 print "<th></th>\n" .
906 foreach my $pr (@projects) {
908 print "<tr class=\"dark\">\n";
910 print "<tr class=\"light\">\n";
913 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=summary"), -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
914 "<td>$pr->{'descr'}</td>\n" .
915 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
916 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" . $pr->{'commit'}{'age_string'} . "</td>\n" .
917 "<td class=\"link\">" .
918 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=summary")}, "summary") .
919 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=shortlog")}, "shortlog") .
920 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=log")}, "log") .
929 my $type = shift || "";
931 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
932 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
933 open my $fd, "$projectroot/$project/info/refs" or return;
934 while (my $line = <$fd>) {
936 if ($line =~ m/^([0-9a-fA-F]{40})\t.*$type\/([^\
^]+)/) {
937 if (defined $refs{$1}) {
938 $refs{$1} .= " / $2";
953 opendir my $dh, "$projectroot/$project/$ref_dir";
954 while (my $dir = readdir($dh)) {
955 if ($dir =~ m/^\./) {
958 if (-d
"$projectroot/$project/$ref_dir/$dir") {
959 opendir my $dh2, "$projectroot/$project/$ref_dir/$dir";
960 my @subdirs = grep !m/^\./, readdir $dh2;
962 foreach my $subdir (@subdirs) {
963 push @refs, "$dir/$subdir"
970 foreach my $ref_file (@refs) {
971 my $ref_id = git_read_hash
("$project/$ref_dir/$ref_file");
972 my $type = git_get_type
($ref_id) || next;
975 $ref_item{'type'} = $type;
976 $ref_item{'id'} = $ref_id;
977 $ref_item{'epoch'} = 0;
978 $ref_item{'age'} = "unknown";
979 if ($type eq "tag") {
980 my %tag = git_read_tag
($ref_id);
981 $ref_item{'comment'} = $tag{'comment'};
982 if ($tag{'type'} eq "commit") {
983 %co = git_read_commit
($tag{'object'});
984 $ref_item{'epoch'} = $co{'committer_epoch'};
985 $ref_item{'age'} = $co{'age_string'};
986 } elsif (defined($tag{'epoch'})) {
987 my $age = time - $tag{'epoch'};
988 $ref_item{'epoch'} = $tag{'epoch'};
989 $ref_item{'age'} = age_string
($age);
991 $ref_item{'reftype'} = $tag{'type'};
992 $ref_item{'name'} = $tag{'name'};
993 $ref_item{'refid'} = $tag{'object'};
994 } elsif ($type eq "commit"){
995 %co = git_read_commit
($ref_id);
996 $ref_item{'reftype'} = "commit";
997 $ref_item{'name'} = $ref_file;
998 $ref_item{'title'} = $co{'title'};
999 $ref_item{'refid'} = $ref_id;
1000 $ref_item{'epoch'} = $co{'committer_epoch'};
1001 $ref_item{'age'} = $co{'age_string'};
1004 push @reflist, \
%ref_item;
1007 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1012 my $descr = git_read_description
($project) || "none";
1013 my $head = git_read_head
($project);
1014 my %co = git_read_commit
($head);
1015 my %cd = date_str
($co{'committer_epoch'}, $co{'committer_tz'});
1018 if (-f
$projects_list) {
1019 open (my $fd , $projects_list);
1020 while (my $line = <$fd>) {
1022 my ($pr, $ow) = split ' ', $line;
1023 $pr = unescape
($pr);
1024 $ow = unescape
($ow);
1025 if ($pr eq $project) {
1026 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
1032 if (!defined $owner) {
1033 $owner = get_file_owner
("$projectroot/$project");
1036 my $refs = read_info_ref
();
1038 print "<div class=\"page_nav\">\n" .
1040 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1041 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1042 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$head")}, "commit") .
1043 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1044 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree")}, "tree") .
1047 print "<div class=\"title\"> </div>\n";
1048 print "<table cellspacing=\"0\">\n" .
1049 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
1050 "<tr><td>owner</td><td>$owner</td></tr>\n" .
1051 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
1053 open my $fd, "-|", "$gitbin/git-rev-list --max-count=17 " . git_read_head
($project) or die_error
(undef, "Open failed.");
1054 my (@revlist) = map { chomp; $_ } <$fd>;
1057 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog"), -class => "title"}, "shortlog") .
1060 print "<table cellspacing=\"0\">\n";
1062 foreach my $commit (@revlist) {
1063 my %co = git_read_commit
($commit);
1064 my %ad = date_str
($co{'author_epoch'});
1066 print "<tr class=\"dark\">\n";
1068 print "<tr class=\"light\">\n";
1073 if (defined $refs->{$commit}) {
1074 $ref = " <span class=\"tag\">" . esc_html
($refs->{$commit}) . "</span>";
1076 print "<td><i>$co{'age_string'}</i></td>\n" .
1077 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
1079 if (length($co{'title_short'}) < length($co{'title'})) {
1080 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list", -title
=> "$co{'title'}"},
1081 "<b>" . esc_html
($co{'title_short'}) . "$ref</b>");
1083 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list"},
1084 "<b>" . esc_html
($co{'title'}) . "$ref</b>");
1087 "<td class=\"link\">" .
1088 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
1089 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1093 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "...") . "</td>\n" .
1100 my $taglist = git_read_refs
("refs/tags");
1101 if (defined @
$taglist) {
1103 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tags"), -class => "title"}, "tags") .
1106 print "<table cellspacing=\"0\">\n";
1108 foreach my $entry (@
$taglist) {
1110 my $comment_lines = $tag{'comment'};
1111 my $comment = shift @
$comment_lines;
1112 if (defined($comment)) {
1113 $comment = chop_str
($comment, 30, 5);
1116 print "<tr class=\"dark\">\n";
1118 print "<tr class=\"light\">\n";
1122 print "<td><i>$tag{'age'}</i></td>\n" .
1124 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), -class => "list"},
1125 "<b>" . esc_html
($tag{'name'}) . "</b>") .
1128 if (defined($comment)) {
1129 print $cgi->a({-class => "list", -href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, $comment);
1132 "<td class=\"link\">";
1133 if ($tag{'type'} eq "tag") {
1134 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
1136 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1137 if ($tag{'reftype'} eq "commit") {
1138 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1139 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'refid'}")}, "log");
1144 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tags")}, "...") . "</td>\n" .
1152 my $headlist = git_read_refs
("refs/heads");
1153 if (defined @
$headlist) {
1155 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=heads"), -class => "title"}, "heads") .
1158 print "<table cellspacing=\"0\">\n";
1160 foreach my $entry (@
$headlist) {
1163 print "<tr class=\"dark\">\n";
1165 print "<tr class=\"light\">\n";
1169 print "<td><i>$tag{'age'}</i></td>\n" .
1171 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}"), -class => "list"},
1172 "<b>" . esc_html
($tag{'name'}) . "</b>") .
1174 "<td class=\"link\">" .
1175 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1176 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'name'}")}, "log") .
1180 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=heads")}, "...") . "</td>\n" .
1191 my $head = git_read_head
($project);
1193 print "<div class=\"page_nav\">\n" .
1194 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1195 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1196 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1197 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$head")}, "commit") .
1198 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1199 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1202 my %tag = git_read_tag
($hash);
1204 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html
($tag{'name'})) . "\n" .
1206 print "<div class=\"title_text\">\n" .
1207 "<table cellspacing=\"0\">\n" .
1209 "<td>object</td>\n" .
1210 "<td>" . $cgi->a({-class => "list", -href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'object'}) . "</td>\n" .
1211 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'type'}) . "</td>\n" .
1213 if (defined($tag{'author'})) {
1214 my %ad = date_str
($tag{'epoch'}, $tag{'tz'});
1215 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
1216 print "<tr><td></td><td>" . $ad{'rfc2822'} . sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) . "</td></tr>\n";
1218 print "</table>\n\n" .
1220 print "<div class=\"page_body\">";
1221 my $comment = $tag{'comment'};
1222 foreach my $line (@
$comment) {
1223 print esc_html
($line) . "<br/>\n";
1231 die_error
('403 Permission denied', "Permission denied.") if (!git_get_project_config_bool
('blame'));
1232 die_error
('404 Not Found', "What file will it be, master?") if (!$file_name);
1233 $hash_base ||= git_read_head
($project);
1234 die_error
(undef, "Reading commit failed.") unless ($hash_base);
1235 my %co = git_read_commit
($hash_base)
1236 or die_error
(undef, "Reading commit failed.");
1237 if (!defined $hash) {
1238 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
1239 or die_error
(undef, "Error lookup file.");
1241 open ($fd, "-|", "$gitbin/git-annotate", '-l', '-t', '-r', $file_name, $hash_base)
1242 or die_error
(undef, "Open failed.");
1244 print "<div class=\"page_nav\">\n" .
1245 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1246 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1247 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1248 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base")}, "commit") .
1249 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1250 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") . "<br/>\n";
1251 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") .
1252 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;f=$file_name")}, "head") . "<br/>\n";
1255 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html
($co{'title'})) .
1257 print "<div class=\"page_path\"><b>" . esc_html
($file_name) . "</b></div>\n";
1258 print "<div class=\"page_body\">\n";
1260 <table class="blame">
1269 my @line_class = (qw(light dark));
1270 my $line_class_len = scalar (@line_class);
1271 my $line_class_num = $#line_class;
1272 while (my $line = <$fd>) {
1284 $line_class_num = ($line_class_num + 1) % $line_class_len;
1286 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) \+\d\d\d\d\t(\d+)\)(.*)$/) {
1293 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
1296 $short_rev = substr ($long_rev, 0, 8);
1297 $age = time () - $time;
1298 $age_str = age_string
($age);
1299 $age_str =~ s/ / /g;
1300 $age_class = age_class
($age);
1301 $author = esc_html
($author);
1302 $author =~ s/ / /g;
1304 while ((my $pos = index($data, "\t")) != -1) {
1305 if (my $count = (8 - ($pos % 8))) {
1306 my $spaces = ' ' x
$count;
1307 $data =~ s/\t/$spaces/;
1310 $data = esc_html
($data);
1313 <tr class="$line_class[$line_class_num]">
1314 <td class="sha1"><a href="$my_uri?${\esc_param ("p=$project;a=commit;h=$long_rev")}" class="text">$short_rev..</a></td>
1315 <td class="$age_class">$age_str</td>
1317 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
1318 <td class="pre">$data</td>
1321 } # while (my $line = <$fd>)
1322 print "</table>\n\n";
1323 close $fd or print "Reading blob failed.\n";
1329 my $head = git_read_head
($project);
1331 print "<div class=\"page_nav\">\n" .
1332 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1333 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1334 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1335 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$head")}, "commit") .
1336 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1337 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1340 my $taglist = git_read_refs
("refs/tags");
1342 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary"), -class => "title"}, " ") .
1344 print "<table cellspacing=\"0\">\n";
1346 if (defined @
$taglist) {
1347 foreach my $entry (@
$taglist) {
1349 my $comment_lines = $tag{'comment'};
1350 my $comment = shift @
$comment_lines;
1351 if (defined($comment)) {
1352 $comment = chop_str
($comment, 30, 5);
1355 print "<tr class=\"dark\">\n";
1357 print "<tr class=\"light\">\n";
1360 print "<td><i>$tag{'age'}</i></td>\n" .
1362 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), -class => "list"},
1363 "<b>" . esc_html
($tag{'name'}) . "</b>") .
1366 if (defined($comment)) {
1367 print $cgi->a({-class => "list", -href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, $comment);
1370 "<td class=\"link\">";
1371 if ($tag{'type'} eq "tag") {
1372 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
1374 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1375 if ($tag{'reftype'} eq "commit") {
1376 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1377 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'refid'}")}, "log");
1388 my $head = git_read_head
($project);
1390 print "<div class=\"page_nav\">\n" .
1391 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1392 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1393 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1394 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$head")}, "commit") .
1395 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1396 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1399 my $taglist = git_read_refs
("refs/heads");
1401 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary"), -class => "title"}, " ") .
1403 print "<table cellspacing=\"0\">\n";
1405 if (defined @
$taglist) {
1406 foreach my $entry (@
$taglist) {
1409 print "<tr class=\"dark\">\n";
1411 print "<tr class=\"light\">\n";
1414 print "<td><i>$tag{'age'}</i></td>\n" .
1416 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}"), -class => "list"}, "<b>" . esc_html
($tag{'name'}) . "</b>") .
1418 "<td class=\"link\">" .
1419 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1420 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'name'}")}, "log") .
1429 sub git_get_hash_by_path
{
1431 my $path = shift || return undef;
1434 my @parts = split '/', $path;
1435 while (my $part = shift @parts) {
1436 open my $fd, "-|", "$gitbin/git-ls-tree $tree" or die_error
(undef, "Open git-ls-tree failed.");
1437 my (@entries) = map { chomp; $_ } <$fd>;
1438 close $fd or return undef;
1439 foreach my $line (@entries) {
1440 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1441 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1445 my $t_name = validate_input
(unquote
($4));
1446 if ($t_name eq $part) {
1450 if ($t_type eq "tree") {
1460 if (!defined $hash && defined $file_name) {
1461 my $base = $hash_base || git_read_head
($project);
1462 $hash = git_get_hash_by_path
($base, $file_name, "blob") || die_error
(undef, "Error lookup file.");
1464 my $have_blame = git_get_project_config_bool
('blame');
1465 open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or die_error
(undef, "Open failed.");
1467 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
1468 print "<div class=\"page_nav\">\n" .
1469 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1470 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1471 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1472 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base")}, "commit") .
1473 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1474 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") . "<br/>\n";
1475 if (defined $file_name) {
1477 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;h=$hash;hb=$hash_base;f=$file_name")}, "blame") . " | ";
1479 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$hash;f=$file_name")}, "plain") .
1480 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;hb=HEAD;f=$file_name")}, "head") . "<br/>\n";
1482 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$hash")}, "plain") . "<br/>\n";
1486 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html
($co{'title'})) .
1489 print "<div class=\"page_nav\">\n" .
1490 "<br/><br/></div>\n" .
1491 "<div class=\"title\">$hash</div>\n";
1493 if (defined $file_name) {
1494 print "<div class=\"page_path\"><b>" . esc_html
($file_name) . "</b></div>\n";
1496 print "<div class=\"page_body\">\n";
1498 while (my $line = <$fd>) {
1501 while ((my $pos = index($line, "\t")) != -1) {
1502 if (my $count = (8 - ($pos % 8))) {
1503 my $spaces = ' ' x
$count;
1504 $line =~ s/\t/$spaces/;
1507 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", $nr, $nr, $nr, esc_html
($line);
1509 close $fd or print "Reading blob failed.\n";
1514 sub mimetype_guess_file
{
1515 my $filename = shift;
1516 my $mimemap = shift;
1517 -r
$mimemap or return undef;
1520 open(MIME
, $mimemap) or return undef;
1522 my ($mime, $exts) = split(/\t+/);
1523 my @exts = split(/\s+/, $exts);
1524 foreach my $ext (@exts) {
1525 $mimemap{$ext} = $mime;
1530 $filename =~ /\.(.*?)$/;
1531 return $mimemap{$1};
1534 sub mimetype_guess
{
1535 my $filename = shift;
1537 $filename =~ /\./ or return undef;
1539 if ($mimetypes_file) {
1540 my $file = $mimetypes_file;
1541 #$file =~ m#^/# or $file = "$projectroot/$path/$file";
1542 $mime = mimetype_guess_file
($filename, $file);
1544 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1548 sub git_blob_plain_mimetype
{
1550 my $filename = shift;
1553 return $default_blob_plain_mimetype unless $fd;
1556 my $mime = mimetype_guess
($filename);
1557 $mime and return $mime;
1561 return 'text/plain' .
1562 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
1563 } elsif (! $filename) {
1564 return 'application/octet-stream';
1565 } elsif ($filename =~ m/\.png$/i) {
1567 } elsif ($filename =~ m/\.gif$/i) {
1569 } elsif ($filename =~ m/\.jpe?g$/i) {
1570 return 'image/jpeg';
1572 return 'application/octet-stream';
1576 sub git_blob_plain
{
1577 open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or return;
1578 my $type = git_blob_plain_mimetype
($fd, $file_name);
1580 # save as filename, even when no $file_name is given
1581 my $save_as = "$hash";
1582 if (defined $file_name) {
1583 $save_as = $file_name;
1584 } elsif ($type =~ m/^text\//) {
1588 print $cgi->header(-type
=> "$type", '-content-disposition' => "inline; filename=\"$save_as\"");
1590 binmode STDOUT
, ':raw';
1592 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
1598 if (!defined $hash) {
1599 $hash = git_read_head
($project);
1600 if (defined $file_name) {
1601 my $base = $hash_base || $hash;
1602 $hash = git_get_hash_by_path
($base, $file_name, "tree");
1604 if (!defined $hash_base) {
1609 open my $fd, "-|", "$gitbin/git-ls-tree -z $hash" or die_error
(undef, "Open git-ls-tree failed.");
1610 chomp (my (@entries) = <$fd>);
1611 close $fd or die_error
(undef, "Reading tree failed.");
1614 my $refs = read_info_ref
();
1616 if (defined $refs->{$hash_base}) {
1617 $ref = " <span class=\"tag\">" . esc_html
($refs->{$hash_base}) . "</span>";
1622 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
1623 $base_key = ";hb=$hash_base";
1624 print "<div class=\"page_nav\">\n" .
1625 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1626 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash_base")}, "shortlog") .
1627 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash_base")}, "log") .
1628 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base")}, "commit") .
1629 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1634 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html
($co{'title'}) . $ref) . "\n" .
1637 print "<div class=\"page_nav\">\n";
1638 print "<br/><br/></div>\n";
1639 print "<div class=\"title\">$hash</div>\n";
1641 if (defined $file_name) {
1642 $base = esc_html
("$file_name/");
1643 print "<div class=\"page_path\"><b>/" . esc_html
($file_name) . "</b></div>\n";
1645 print "<div class=\"page_path\"><b>/</b></div>\n";
1647 print "<div class=\"page_body\">\n";
1648 print "<table cellspacing=\"0\">\n";
1650 foreach my $line (@entries) {
1651 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1652 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1656 my $t_name = validate_input
($4);
1658 print "<tr class=\"dark\">\n";
1660 print "<tr class=\"light\">\n";
1663 print "<td class=\"mode\">" . mode_str
($t_mode) . "</td>\n";
1664 if ($t_type eq "blob") {
1665 print "<td class=\"list\">" .
1666 $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)) .
1668 "<td class=\"link\">" .
1669 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name")}, "blob") .
1670 # " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$t_hash$base_key;f=$base$t_name")}, "blame") .
1671 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;h=$hash_base;f=$base$t_name")}, "history") .
1673 } elsif ($t_type eq "tree") {
1674 print "<td class=\"list\">" .
1675 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, esc_html
($t_name)) .
1677 "<td class=\"link\">" .
1678 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, "tree") .
1683 print "</table>\n" .
1689 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
1690 open my $fd, "-|", "$gitbin/git-rev-list --max-count=150 " . git_read_head
($project) or die_error
(undef, "Open failed.");
1691 my (@revlist) = map { chomp; $_ } <$fd>;
1692 close $fd or die_error
(undef, "Reading rev-list failed.");
1693 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
1694 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1695 "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
1696 print "<channel>\n";
1697 print "<title>$project</title>\n".
1698 "<link>" . esc_html
("$my_url?p=$project;a=summary") . "</link>\n".
1699 "<description>$project log</description>\n".
1700 "<language>en</language>\n";
1702 for (my $i = 0; $i <= $#revlist; $i++) {
1703 my $commit = $revlist[$i];
1704 my %co = git_read_commit
($commit);
1705 # we read 150, we always show 30 and the ones more recent than 48 hours
1706 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
1709 my %cd = date_str
($co{'committer_epoch'});
1710 open $fd, "-|", "$gitbin/git-diff-tree -r $co{'parent'} $co{'id'}" or next;
1711 my @difftree = map { chomp; $_ } <$fd>;
1715 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
1717 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
1718 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
1719 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
1720 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
1721 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
1722 "<content:encoded>" .
1724 my $comment = $co{'comment'};
1725 foreach my $line (@
$comment) {
1726 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
1727 print "$line<br/>\n";
1730 foreach my $line (@difftree) {
1731 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
1734 my $file = validate_input
(unquote
($7));
1735 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
1736 print "$file<br/>\n";
1739 "</content:encoded>\n" .
1742 print "</channel></rss>";
1746 my @list = git_read_projects
();
1748 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
1749 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1750 "<opml version=\"1.0\">\n".
1752 " <title>Git OPML Export</title>\n".
1755 "<outline text=\"git RSS feeds\">\n";
1757 foreach my $pr (@list) {
1759 my $head = git_read_head
($proj{'path'});
1760 if (!defined $head) {
1763 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
1764 my %co = git_read_commit
($head);
1769 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
1770 my $rss = "$my_url?p=$proj{'path'};a=rss";
1771 my $html = "$my_url?p=$proj{'path'};a=summary";
1772 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
1774 print "</outline>\n".
1780 my $head = git_read_head
($project);
1781 if (!defined $hash) {
1784 if (!defined $page) {
1787 my $refs = read_info_ref
();
1789 print "<div class=\"page_nav\">\n";
1790 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1791 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash")}, "shortlog") .
1793 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash")}, "commit") .
1794 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
1795 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$hash;hb=$hash")}, "tree") . "<br/>\n";
1797 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
1798 open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error
(undef, "Open failed.");
1799 my (@revlist) = map { chomp; $_ } <$fd>;
1802 if ($hash ne $head || $page) {
1803 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "HEAD");
1809 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash;pg=" . ($page-1)), -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1811 print " ⋅ prev";
1813 if ($#revlist >= (100 * ($page+1)-1)) {
1815 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash;pg=" . ($page+1)), -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1817 print " ⋅ next";
1823 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary"), -class => "title"}, " ") .
1825 my %co = git_read_commit
($hash);
1826 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
1828 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
1829 my $commit = $revlist[$i];
1831 if (defined $refs->{$commit}) {
1832 $ref = " <span class=\"tag\">" . esc_html
($refs->{$commit}) . "</span>";
1834 my %co = git_read_commit
($commit);
1836 my %ad = date_str
($co{'author_epoch'});
1838 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "title"},
1839 "<span class=\"age\">$co{'age_string'}</span>" . esc_html
($co{'title'}) . $ref) . "\n";
1841 print "<div class=\"title_text\">\n" .
1842 "<div class=\"log_link\">\n" .
1843 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
1844 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1847 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
1849 "<div class=\"log_body\">\n";
1850 my $comment = $co{'comment'};
1852 foreach my $line (@
$comment) {
1853 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1864 print format_log_line_html
($line) . "<br/>\n";
1875 my %co = git_read_commit
($hash);
1877 die_error
(undef, "Unknown commit object.");
1879 my %ad = date_str
($co{'author_epoch'}, $co{'author_tz'});
1880 my %cd = date_str
($co{'committer_epoch'}, $co{'committer_tz'});
1884 my $parent = $co{'parent'};
1885 if (!defined $parent) {
1889 open my $fd, "-|", "$gitbin/git-diff-tree -r -M $root $parent $hash" or die_error
(undef, "Open failed.");
1890 @difftree = map { chomp; $_ } <$fd>;
1891 close $fd or die_error
(undef, "Reading diff-tree failed.");
1893 # non-textual hash id's can be cached
1895 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
1898 my $refs = read_info_ref
();
1900 if (defined $refs->{$co{'id'}}) {
1901 $ref = " <span class=\"tag\">" . esc_html
($refs->{$co{'id'}}) . "</span>";
1903 git_header_html
(undef, $expires);
1904 print "<div class=\"page_nav\">\n" .
1905 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1906 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash")}, "shortlog") .
1907 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash")}, "log") .
1909 if (defined $co{'parent'}) {
1910 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash")}, "commitdiff");
1912 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") . "\n" .
1913 "<br/><br/></div>\n";
1914 if (defined $co{'parent'}) {
1916 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash"), -class => "title"}, esc_html
($co{'title'}) . $ref) . "\n" .
1920 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash"), -class => "title"}, esc_html
($co{'title'})) . "\n" .
1923 print "<div class=\"title_text\">\n" .
1924 "<table cellspacing=\"0\">\n";
1925 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
1927 "<td></td><td> $ad{'rfc2822'}";
1928 if ($ad{'hour_local'} < 6) {
1929 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1931 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1935 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
1936 print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
1937 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
1940 "<td class=\"sha1\">" .
1941 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash"), class => "list"}, $co{'tree'}) .
1943 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
1946 my $parents = $co{'parents'};
1947 foreach my $par (@
$parents) {
1950 "<td class=\"sha1\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$par"), class => "list"}, $par) . "</td>" .
1951 "<td class=\"link\">" .
1952 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$par")}, "commit") .
1953 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash;hp=$par")}, "commitdiff") .
1959 print "<div class=\"page_body\">\n";
1960 my $comment = $co{'comment'};
1963 foreach my $line (@
$comment) {
1964 # print only one empty line
1966 if ($empty || $signed) {
1973 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1975 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1978 print format_log_line_html
($line) . "<br/>\n";
1982 print "<div class=\"list_head\">\n";
1983 if ($#difftree > 10) {
1984 print(($#difftree + 1) . " files changed:\n");
1987 print "<table class=\"diff_tree\">\n";
1989 foreach my $line (@difftree) {
1990 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1991 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1992 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
2000 my $similarity = $6;
2001 my $file = validate_input
(unquote
($7));
2003 print "<tr class=\"dark\">\n";
2005 print "<tr class=\"light\">\n";
2008 if ($status eq "A") {
2010 if (S_ISREG
(oct $to_mode)) {
2011 $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
2014 $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" .
2015 "<td><span class=\"file_status new\">[new " . file_type
($to_mode) . "$mode_chng]</span></td>\n" .
2016 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob") . "</td>\n";
2017 } elsif ($status eq "D") {
2019 $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" .
2020 "<td><span class=\"file_status deleted\">[deleted " . file_type
($from_mode). "]</span></td>\n" .
2021 "<td class=\"link\">" .
2022 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, "blob") .
2023 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;h=$hash;f=$file")}, "history") .
2025 } elsif ($status eq "M" || $status eq "T") {
2026 my $mode_chnge = "";
2027 if ($from_mode != $to_mode) {
2028 $mode_chnge = " <span class=\"file_status mode_chnge\">[changed";
2029 if (((oct $from_mode) & S_IFMT
) != ((oct $to_mode) & S_IFMT
)) {
2030 $mode_chnge .= " from " . file_type
($from_mode) . " to " . file_type
($to_mode);
2032 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
2033 if (S_ISREG
($from_mode) && S_ISREG
($to_mode)) {
2034 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
2035 } elsif (S_ISREG
($to_mode)) {
2036 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
2039 $mode_chnge .= "]</span>\n";
2042 if ($to_id ne $from_id) {
2043 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));
2045 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file"), -class => "list"}, esc_html
($file));
2048 "<td>$mode_chnge</td>\n" .
2049 "<td class=\"link\">";
2050 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob");
2051 if ($to_id ne $from_id) {
2052 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file")}, "diff");
2054 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;h=$hash;f=$file")}, "history") . "\n";
2056 } elsif ($status eq "R") {
2057 my ($from_file, $to_file) = split "\t", $file;
2059 if ($from_mode != $to_mode) {
2060 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
2063 $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" .
2064 "<td><span class=\"file_status moved\">[moved from " .
2065 $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)) .
2066 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
2067 "<td class=\"link\">" .
2068 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file")}, "blob");
2069 if ($to_id ne $from_id) {
2070 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file")}, "diff");
2081 mkdir($git_temp, 0700);
2083 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
2084 print "<div class=\"page_nav\">\n" .
2085 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
2086 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
2087 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
2088 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base")}, "commit") .
2089 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
2090 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") .
2092 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff_plain;h=$hash;hp=$hash_parent")}, "plain") .
2095 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html
($co{'title'})) . "\n" .
2098 print "<div class=\"page_nav\">\n" .
2099 "<br/><br/></div>\n" .
2100 "<div class=\"title\">$hash vs $hash_parent</div>\n";
2102 if (defined $file_name) {
2103 print "<div class=\"page_path\"><b>/" . esc_html
($file_name) . "</b></div>\n";
2105 print "<div class=\"page_body\">\n" .
2106 "<div class=\"diff_info\">blob:" .
2107 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name")}, $hash_parent) .
2109 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, $hash) .
2111 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
2116 sub git_blobdiff_plain
{
2117 mkdir($git_temp, 0700);
2118 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8');
2119 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
2122 sub git_commitdiff
{
2123 mkdir($git_temp, 0700);
2124 my %co = git_read_commit
($hash);
2126 die_error
(undef, "Unknown commit object.");
2128 if (!defined $hash_parent) {
2129 $hash_parent = $co{'parent'};
2131 open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error
(undef, "Open failed.");
2132 my (@difftree) = map { chomp; $_ } <$fd>;
2133 close $fd or die_error
(undef, "Reading diff-tree failed.");
2135 # non-textual hash id's can be cached
2137 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2140 my $refs = read_info_ref
();
2142 if (defined $refs->{$co{'id'}}) {
2143 $ref = " <span class=\"tag\">" . esc_html
($refs->{$co{'id'}}) . "</span>";
2145 git_header_html
(undef, $expires);
2146 print "<div class=\"page_nav\">\n" .
2147 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
2148 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash")}, "shortlog") .
2149 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash")}, "log") .
2150 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash")}, "commit") .
2152 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") . "<br/>\n";
2153 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent")}, "plain") . "\n" .
2156 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html
($co{'title'}) . $ref) . "\n" .
2158 print "<div class=\"page_body\">\n";
2159 my $comment = $co{'comment'};
2162 my @log = @
$comment;
2163 # remove first and empty lines after that
2165 while (defined $log[0] && $log[0] eq "") {
2168 foreach my $line (@log) {
2169 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2180 print format_log_line_html
($line) . "<br/>\n";
2183 foreach my $line (@difftree) {
2184 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2185 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2186 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2192 my $file = validate_input
(unquote
($6));
2193 if ($status eq "A") {
2194 print "<div class=\"diff_info\">" . file_type
($to_mode) . ":" .
2195 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id) . "(new)" .
2197 git_diff_print
(undef, "/dev/null", $to_id, "b/$file");
2198 } elsif ($status eq "D") {
2199 print "<div class=\"diff_info\">" . file_type
($from_mode) . ":" .
2200 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) . "(deleted)" .
2202 git_diff_print
($from_id, "a/$file", undef, "/dev/null");
2203 } elsif ($status eq "M") {
2204 if ($from_id ne $to_id) {
2205 print "<div class=\"diff_info\">" .
2206 file_type
($from_mode) . ":" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) .
2208 file_type
($to_mode) . ":" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id);
2210 git_diff_print
($from_id, "a/$file", $to_id, "b/$file");
2219 sub git_commitdiff_plain
{
2220 mkdir($git_temp, 0700);
2221 open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error
(undef, "Open failed.");
2222 my (@difftree) = map { chomp; $_ } <$fd>;
2223 close $fd or die_error
(undef, "Reading diff-tree failed.");
2225 # try to figure out the next tag after this commit
2227 my $refs = read_info_ref
("tags");
2228 open $fd, "-|", "$gitbin/git-rev-list HEAD";
2229 chomp (my (@commits) = <$fd>);
2231 foreach my $commit (@commits) {
2232 if (defined $refs->{$commit}) {
2233 $tagname = $refs->{$commit}
2235 if ($commit eq $hash) {
2240 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8', '-content-disposition' => "inline; filename=\"git-$hash.patch\"");
2241 my %co = git_read_commit
($hash);
2242 my %ad = date_str
($co{'author_epoch'}, $co{'author_tz'});
2243 my $comment = $co{'comment'};
2244 print "From: $co{'author'}\n" .
2245 "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
2246 "Subject: $co{'title'}\n";
2247 if (defined $tagname) {
2248 print "X-Git-Tag: $tagname\n";
2250 print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
2253 foreach my $line (@
$comment) {;
2258 foreach my $line (@difftree) {
2259 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2264 if ($status eq "A") {
2265 git_diff_print
(undef, "/dev/null", $to_id, "b/$file", "plain");
2266 } elsif ($status eq "D") {
2267 git_diff_print
($from_id, "a/$file", undef, "/dev/null", "plain");
2268 } elsif ($status eq "M") {
2269 git_diff_print
($from_id, "a/$file", $to_id, "b/$file", "plain");
2275 if (!defined $hash) {
2276 $hash = git_read_head
($project);
2278 my %co = git_read_commit
($hash);
2280 die_error
(undef, "Unknown commit object.");
2282 my $refs = read_info_ref
();
2284 print "<div class=\"page_nav\">\n" .
2285 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
2286 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
2287 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
2288 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash")}, "commit") .
2289 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2290 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
2294 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html
($co{'title'})) . "\n" .
2296 print "<div class=\"page_path\"><b>/" . esc_html
($file_name) . "</b><br/></div>\n";
2298 open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin -- \'$file_name\'";
2300 print "<table cellspacing=\"0\">\n";
2302 while (my $line = <$fd>) {
2303 if ($line =~ m/^([0-9a-fA-F]{40})/){
2307 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/ && (defined $commit)) {
2308 my %co = git_read_commit
($commit);
2313 if (defined $refs->{$commit}) {
2314 $ref = " <span class=\"tag\">" . esc_html
($refs->{$commit}) . "</span>";
2317 print "<tr class=\"dark\">\n";
2319 print "<tr class=\"light\">\n";
2322 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2323 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2324 "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list"}, "<b>" .
2325 esc_html
(chop_str
($co{'title'}, 50)) . "$ref</b>") . "</td>\n" .
2326 "<td class=\"link\">" .
2327 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
2328 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2329 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;hb=$commit;f=$file_name")}, "blob");
2330 my $blob = git_get_hash_by_path
($hash, $file_name);
2331 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2332 if (defined $blob && defined $blob_parent && $blob ne $blob_parent) {
2334 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=$file_name")},
2348 if (!defined $searchtext) {
2349 die_error
("", "Text field empty.");
2351 if (!defined $hash) {
2352 $hash = git_read_head
($project);
2354 my %co = git_read_commit
($hash);
2356 die_error
(undef, "Unknown commit object.");
2358 # pickaxe may take all resources of your box and run for several minutes
2359 # with every query - so decide by yourself how public you make this feature :)
2360 my $commit_search = 1;
2361 my $author_search = 0;
2362 my $committer_search = 0;
2363 my $pickaxe_search = 0;
2364 if ($searchtext =~ s/^author\\://i) {
2366 } elsif ($searchtext =~ s/^committer\\://i) {
2367 $committer_search = 1;
2368 } elsif ($searchtext =~ s/^pickaxe\\://i) {
2370 $pickaxe_search = 1;
2373 print "<div class=\"page_nav\">\n" .
2374 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary;h=$hash")}, "summary") .
2375 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
2376 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash")}, "log") .
2377 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash")}, "commit") .
2378 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2379 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
2384 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html
($co{'title'})) . "\n" .
2386 print "<table cellspacing=\"0\">\n";
2388 if ($commit_search) {
2390 open my $fd, "-|", "$gitbin/git-rev-list --header --parents $hash" or next;
2391 while (my $commit_text = <$fd>) {
2392 if (!grep m/$searchtext/i, $commit_text) {
2395 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
2398 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
2401 my @commit_lines = split "\n", $commit_text;
2402 my %co = git_read_commit
(undef, \
@commit_lines);
2407 print "<tr class=\"dark\">\n";
2409 print "<tr class=\"light\">\n";
2412 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2413 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2415 $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/>");
2416 my $comment = $co{'comment'};
2417 foreach my $line (@
$comment) {
2418 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2419 my $lead = esc_html
($1) || "";
2420 $lead = chop_str
($lead, 30, 10);
2421 my $match = esc_html
($2) || "";
2422 my $trail = esc_html
($3) || "";
2423 $trail = chop_str
($trail, 30, 10);
2424 my $text = "$lead<span class=\"match\">$match</span>$trail";
2425 print chop_str
($text, 80, 5) . "<br/>\n";
2429 "<td class=\"link\">" .
2430 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2431 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2438 if ($pickaxe_search) {
2440 open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin -S\'$searchtext\'";
2443 while (my $line = <$fd>) {
2444 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2447 $set{'from_id'} = $3;
2449 $set{'id'} = $set{'to_id'};
2450 if ($set{'id'} =~ m/0{40}/) {
2451 $set{'id'} = $set{'from_id'};
2453 if ($set{'id'} =~ m/0{40}/) {
2457 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
2460 print "<tr class=\"dark\">\n";
2462 print "<tr class=\"light\">\n";
2465 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2466 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2468 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" .
2469 esc_html
(chop_str
($co{'title'}, 50)) . "</b><br/>");
2470 while (my $setref = shift @files) {
2472 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}"), class => "list"},
2473 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
2477 "<td class=\"link\">" .
2478 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2479 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2483 %co = git_read_commit
($1);
2493 my $head = git_read_head
($project);
2494 if (!defined $hash) {
2497 if (!defined $page) {
2500 my $refs = read_info_ref
();
2502 print "<div class=\"page_nav\">\n" .
2503 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
2505 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash")}, "log") .
2506 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash")}, "commit") .
2507 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2508 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$hash;hb=$hash")}, "tree") . "<br/>\n";
2510 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2511 open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error
(undef, "Open failed.");
2512 my (@revlist) = map { chomp; $_ } <$fd>;
2515 if ($hash ne $head || $page) {
2516 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "HEAD");
2522 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash;pg=" . ($page-1)), -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2524 print " ⋅ prev";
2526 if ($#revlist >= (100 * ($page+1)-1)) {
2528 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)), -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2530 print " ⋅ next";
2535 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary"), -class => "title"}, " ") .
2537 print "<table cellspacing=\"0\">\n";
2539 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2540 my $commit = $revlist[$i];
2542 if (defined $refs->{$commit}) {
2543 $ref = " <span class=\"tag\">" . esc_html
($refs->{$commit}) . "</span>";
2545 my %co = git_read_commit
($commit);
2546 my %ad = date_str
($co{'author_epoch'});
2548 print "<tr class=\"dark\">\n";
2550 print "<tr class=\"light\">\n";
2553 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2554 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
2556 if (length($co{'title_short'}) < length($co{'title'})) {
2557 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list", -title
=> "$co{'title'}"},
2558 "<b>" . esc_html
($co{'title_short'}) . "$ref</b>");
2560 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list"},
2561 "<b>" . esc_html
($co{'title_short'}) . "$ref</b>");
2564 "<td class=\"link\">" .
2565 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
2566 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2570 if ($#revlist >= (100 * ($page+1)-1)) {
2573 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)), -title
=> "Alt-n"}, "next") .