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 our $my_url = $cgi->url();
22 our $my_uri = $cgi->url(-absolute
=> 1);
25 # location of the git-core binaries
26 our $gitbin = "/usr/bin";
28 # absolute fs-path which will be prepended to the project path
29 #our $projectroot = "/pub/scm";
30 our $projectroot = "/home/kay/public_html/pub/scm";
32 # version of the git-core binaries
33 our $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 our $git_temp = "/tmp/gitweb";
43 # target of the home link on top of all pages
44 our $home_link = $my_uri;
46 # html text to include at home page
47 our $home_text = "indextext.html";
49 # URI of default stylesheet
50 our $stylesheet = "gitweb.css";
52 # source of projects list
53 #our $projects_list = $projectroot;
54 our $projects_list = "index/index.aux";
56 # default blob_plain mimetype and default charset for text/plain blob
57 our $default_blob_plain_mimetype = 'text/plain';
58 our $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 our $mimetypes_file = undef;
64 # input validation and dispatch
65 our $action = $cgi->param('a');
66 if (defined $action) {
67 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
69 die_error
(undef, "Invalid action parameter.");
71 if ($action eq "git-logo.png") {
74 } elsif ($action eq "opml") {
80 our $order = $cgi->param('o');
82 if ($order =~ m/[^0-9a-zA-Z_]/) {
84 die_error
(undef, "Invalid order parameter.");
88 our $project = ($cgi->param('p') || $ENV{'PATH_INFO'});
89 if (defined $project) {
90 $project =~ s
|^/||; $project =~ s|/$||;
91 $project = validate_input
($project);
92 if (!defined($project)) {
93 die_error
(undef, "Invalid project parameter.");
95 if (!(-d
"$projectroot/$project")) {
97 die_error
(undef, "No such directory.");
99 if (!(-e
"$projectroot/$project/HEAD")) {
101 die_error
(undef, "No such project.");
103 $rss_link = "<link rel=\"alternate\" title=\"" . esc_param
($project) . " log\" href=\"" .
104 "$my_uri?" . esc_param
("p=$project;a=rss") . "\" type=\"application/rss+xml\"/>";
105 $ENV{'GIT_DIR'} = "$projectroot/$project";
111 our $file_name = $cgi->param('f');
112 if (defined $file_name) {
113 $file_name = validate_input
($file_name);
114 if (!defined($file_name)) {
115 die_error
(undef, "Invalid file parameter.");
119 our $hash = $cgi->param('h');
121 $hash = validate_input
($hash);
122 if (!defined($hash)) {
123 die_error
(undef, "Invalid hash parameter.");
127 our $hash_parent = $cgi->param('hp');
128 if (defined $hash_parent) {
129 $hash_parent = validate_input
($hash_parent);
130 if (!defined($hash_parent)) {
131 die_error
(undef, "Invalid hash parent parameter.");
135 our $hash_base = $cgi->param('hb');
136 if (defined $hash_base) {
137 $hash_base = validate_input
($hash_base);
138 if (!defined($hash_base)) {
139 die_error
(undef, "Invalid hash base parameter.");
143 our $page = $cgi->param('pg');
145 if ($page =~ m/[^0-9]$/) {
147 die_error
(undef, "Invalid page parameter.");
151 our $searchtext = $cgi->param('s');
152 if (defined $searchtext) {
153 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
155 die_error
(undef, "Invalid search parameter.");
157 $searchtext = quotemeta $searchtext;
163 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
166 if ($input =~ m/(^|\/)(|\
.|\
.\
.)($|\
/)/) {
169 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\
-\
+\#\
~\
%]/) {
175 if (!defined $action || $action eq "summary") {
178 } elsif ($action eq "heads") {
181 } elsif ($action eq "tags") {
184 } elsif ($action eq "blob") {
187 } elsif ($action eq "blob_plain") {
190 } elsif ($action eq "tree") {
193 } elsif ($action eq "rss") {
196 } elsif ($action eq "commit") {
199 } elsif ($action eq "log") {
202 } elsif ($action eq "blobdiff") {
205 } elsif ($action eq "blobdiff_plain") {
206 git_blobdiff_plain
();
208 } elsif ($action eq "commitdiff") {
211 } elsif ($action eq "commitdiff_plain") {
212 git_commitdiff_plain
();
214 } elsif ($action eq "history") {
217 } elsif ($action eq "search") {
220 } elsif ($action eq "shortlog") {
223 } elsif ($action eq "tag") {
226 } elsif ($action eq "blame") {
231 die_error
(undef, "Unknown action.");
235 # quote unsafe chars, but keep the slash, even when it's not
236 # correct, but quoted slashes look too horrible in bookmarks
239 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
245 # replace invalid utf8 character with SUBSTITUTION sequence
248 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
249 $str = escapeHTML
($str);
253 # git may return quoted and escaped filenames
256 if ($str =~ m/^"(.*)"$/) {
258 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
263 # CSS class for given age value (in seconds)
267 if ($age < 60*60*2) {
269 } elsif ($age < 60*60*24*2) {
276 sub git_header_html
{
277 my $status = shift || "200 OK";
281 if (defined $project) {
282 $title .= " - $project";
283 if (defined $action) {
284 $title .= "/$action";
285 if (defined $file_name) {
286 $title .= " - $file_name";
287 if ($action eq "tree" && $file_name !~ m
|/$|) {
293 print $cgi->header(-type
=>'text/html', -charset
=> 'utf-8', -status
=> $status, -expires
=> $expires);
295 <?xml version="1.0" encoding="utf-8"?>
296 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
297 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
298 <!-- git web interface v$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
299 <!-- git core binaries version $git_version -->
301 <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
302 <meta name="robots" content="index, nofollow"/>
303 <title>$title</title>
304 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
309 print "<div class=\"page_header\">\n" .
310 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
311 "<img src=\"$my_uri?" . esc_param
("a=git-logo.png") . "\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
313 print $cgi->a({-href
=> esc_param
($home_link)}, "projects") . " / ";
314 if (defined $project) {
315 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, esc_html
($project));
316 if (defined $action) {
320 if (!defined $searchtext) {
324 if (defined $hash_base) {
325 $search_hash = $hash_base;
326 } elsif (defined $hash) {
327 $search_hash = $hash;
329 $search_hash = "HEAD";
331 $cgi->param("a", "search");
332 $cgi->param("h", $search_hash);
333 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
334 "<div class=\"search\">\n" .
335 $cgi->hidden(-name
=> "p") . "\n" .
336 $cgi->hidden(-name
=> "a") . "\n" .
337 $cgi->hidden(-name
=> "h") . "\n" .
338 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
340 $cgi->end_form() . "\n";
345 sub git_footer_html
{
346 print "<div class=\"page_footer\">\n";
347 if (defined $project) {
348 my $descr = git_read_description
($project);
349 if (defined $descr) {
350 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
352 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=rss"), -class => "rss_logo"}, "RSS") . "\n";
354 print $cgi->a({-href
=> "$my_uri?" . esc_param
("a=opml"), -class => "rss_logo"}, "OPML") . "\n";
362 my $status = shift || "403 Forbidden";
363 my $error = shift || "Malformed query, file missing or permission denied";
365 git_header_html
($status);
366 print "<div class=\"page_body\">\n" .
368 "$status - $error\n" .
378 open my $fd, "-|", "$gitbin/git-cat-file -t $hash" or return;
387 my $oENV = $ENV{'GIT_DIR'};
389 $ENV{'GIT_DIR'} = "$projectroot/$project";
390 if (open my $fd, "-|", "$gitbin/git-rev-parse", "--verify", "HEAD") {
393 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
398 $ENV{'GIT_DIR'} = $oENV;
406 open my $fd, "$projectroot/$path" or return undef;
410 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
415 sub git_read_description
{
418 open my $fd, "$projectroot/$path/description" or return undef;
430 open my $fd, "-|", "$gitbin/git-cat-file tag $tag_id" or return;
431 $tag{'id'} = $tag_id;
432 while (my $line = <$fd>) {
434 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
436 } elsif ($line =~ m/^type (.+)$/) {
438 } elsif ($line =~ m/^tag (.+)$/) {
440 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
444 } elsif ($line =~ m/--BEGIN/) {
445 push @comment, $line;
447 } elsif ($line eq "") {
451 push @comment, <$fd>;
452 $tag{'comment'} = \
@comment;
454 if (!defined $tag{'name'}) {
464 if ($age > 60*60*24*365*2) {
465 $age_str = (int $age/60/60/24/365);
466 $age_str .= " years ago";
467 } elsif ($age > 60*60*24*(365/12)*2) {
468 $age_str = int $age/60/60/24/(365/12);
469 $age_str .= " months ago";
470 } elsif ($age > 60*60*24*7*2) {
471 $age_str = int $age/60/60/24/7;
472 $age_str .= " weeks ago";
473 } elsif ($age > 60*60*24*2) {
474 $age_str = int $age/60/60/24;
475 $age_str .= " days ago";
476 } elsif ($age > 60*60*2) {
477 $age_str = int $age/60/60;
478 $age_str .= " hours ago";
479 } elsif ($age > 60*2) {
480 $age_str = int $age/60;
481 $age_str .= " min ago";
484 $age_str .= " sec ago";
486 $age_str .= " right now";
491 sub git_read_commit
{
492 my $commit_id = shift;
493 my $commit_text = shift;
498 if (defined $commit_text) {
499 @commit_lines = @
$commit_text;
502 open my $fd, "-|", "$gitbin/git-rev-list --header --parents --max-count=1 $commit_id" or return;
503 @commit_lines = split '\n', <$fd>;
508 my $header = shift @commit_lines;
509 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
512 ($co{'id'}, my @parents) = split ' ', $header;
513 $co{'parents'} = \
@parents;
514 $co{'parent'} = $parents[0];
515 while (my $line = shift @commit_lines) {
516 last if $line eq "\n";
517 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
519 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
521 $co{'author_epoch'} = $2;
522 $co{'author_tz'} = $3;
523 if ($co{'author'} =~ m/^([^<]+) </) {
524 $co{'author_name'} = $1;
526 $co{'author_name'} = $co{'author'};
528 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
529 $co{'committer'} = $1;
530 $co{'committer_epoch'} = $2;
531 $co{'committer_tz'} = $3;
532 $co{'committer_name'} = $co{'committer'};
533 $co{'committer_name'} =~ s/ <.*//;
536 if (!defined $co{'tree'}) {
540 foreach my $title (@commit_lines) {
543 $co{'title'} = chop_str
($title, 80, 5);
544 # remove leading stuff of merges to make the interesting part visible
545 if (length($title) > 50) {
546 $title =~ s/^Automatic //;
547 $title =~ s/^merge (of|with) /Merge ... /i;
548 if (length($title) > 50) {
549 $title =~ s/(http|rsync):\/\///;
551 if (length($title) > 50) {
552 $title =~ s/(master|www|rsync)\.//;
554 if (length($title) > 50) {
555 $title =~ s/kernel.org:?//;
557 if (length($title) > 50) {
558 $title =~ s/\/pub\/scm//;
561 $co{'title_short'} = chop_str
($title, 50, 5);
565 # remove added spaces
566 foreach my $line (@commit_lines) {
569 $co{'comment'} = \
@commit_lines;
571 my $age = time - $co{'committer_epoch'};
573 $co{'age_string'} = age_string
($age);
574 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
575 if ($age > 60*60*24*7*2) {
576 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
577 $co{'age_string_age'} = $co{'age_string'};
579 $co{'age_string_date'} = $co{'age_string'};
580 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
587 my $from_name = shift;
590 my $format = shift || "html";
592 my $from_tmp = "/dev/null";
593 my $to_tmp = "/dev/null";
596 # create tmp from-file
598 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
599 open my $fd2, "> $from_tmp";
600 open my $fd, "-|", "$gitbin/git-cat-file blob $from";
609 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
610 open my $fd2, "> $to_tmp";
611 open my $fd, "-|", "$gitbin/git-cat-file blob $to";
618 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
619 if ($format eq "plain") {
624 while (my $line = <$fd>) {
626 my $char = substr($line, 0, 1);
629 $diff_class = " add";
630 } elsif ($char eq "-") {
631 $diff_class = " rem";
632 } elsif ($char eq "@") {
633 $diff_class = " chunk_header";
634 } elsif ($char eq "\\") {
638 while ((my $pos = index($line, "\t")) != -1) {
639 if (my $count = (8 - (($pos-1) % 8))) {
640 my $spaces = ' ' x
$count;
641 $line =~ s/\t/$spaces/;
644 print "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
658 my $mode = oct shift;
660 if (S_ISDIR
($mode & S_IFMT
)) {
662 } elsif (S_ISLNK
($mode)) {
664 } elsif (S_ISREG
($mode)) {
665 # git cares only about the executable bit
666 if ($mode & S_IXUSR
) {
679 my $add_len = shift || 10;
681 # allow only $len chars, but don't cut a word if it would fit in $add_len
682 # if it doesn't fit, cut it if it's still longer than the dots we would add
683 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
686 if (length($tail) > 4) {
693 my $mode = oct shift;
695 if (S_ISDIR
($mode & S_IFMT
)) {
697 } elsif (S_ISLNK
($mode)) {
699 } elsif (S_ISREG
($mode)) {
706 sub format_log_line_html
{
709 $line = esc_html
($line);
710 $line =~ s/ / /g;
711 if ($line =~ m/([0-9a-fA-F]{40})/) {
713 if (git_get_type
($hash_text) eq "commit") {
714 my $link = $cgi->a({-class => "text", -href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_text")}, $hash_text);
715 $line =~ s/$hash_text/$link/;
723 my $tz = shift || "-0000";
726 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
727 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
728 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
729 $date{'hour'} = $hour;
730 $date{'minute'} = $min;
731 $date{'mday'} = $mday;
732 $date{'day'} = $days[$wday];
733 $date{'month'} = $months[$mon];
734 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
735 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
737 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
738 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
739 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
740 $date{'hour_local'} = $hour;
741 $date{'minute_local'} = $min;
742 $date{'tz_local'} = $tz;
746 # git-logo (cached in browser for one day)
748 binmode STDOUT
, ':raw';
749 print $cgi->header(-type
=> 'image/png', -expires
=> '+1d');
750 # cat git-logo.png | hexdump -e '16/1 " %02x" "\n"' | sed 's/ /\\x/g'
751 print "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52" .
752 "\x00\x00\x00\x48\x00\x00\x00\x1b\x04\x03\x00\x00\x00\x2d\xd9\xd4" .
753 "\x2d\x00\x00\x00\x18\x50\x4c\x54\x45\xff\xff\xff\x60\x60\x5d\xb0" .
754 "\xaf\xaa\x00\x80\x00\xce\xcd\xc7\xc0\x00\x00\xe8\xe8\xe6\xf7\xf7" .
755 "\xf6\x95\x0c\xa7\x47\x00\x00\x00\x73\x49\x44\x41\x54\x28\xcf\x63" .
756 "\x48\x67\x20\x04\x4a\x5c\x18\x0a\x08\x2a\x62\x53\x61\x20\x02\x08" .
757 "\x0d\x69\x45\xac\xa1\xa1\x01\x30\x0c\x93\x60\x36\x26\x52\x91\xb1" .
758 "\x01\x11\xd6\xe1\x55\x64\x6c\x6c\xcc\x6c\x6c\x0c\xa2\x0c\x70\x2a" .
759 "\x62\x06\x2a\xc1\x62\x1d\xb3\x01\x02\x53\xa4\x08\xe8\x00\x03\x18" .
760 "\x26\x56\x11\xd4\xe1\x20\x97\x1b\xe0\xb4\x0e\x35\x24\x71\x29\x82" .
761 "\x99\x30\xb8\x93\x0a\x11\xb9\x45\x88\xc1\x8d\xa0\xa2\x44\x21\x06" .
762 "\x27\x41\x82\x40\x85\xc1\x45\x89\x20\x70\x01\x00\xa4\x3d\x21\xc5" .
763 "\x12\x1c\x9a\xfe\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\x82";
769 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
770 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
771 if (!defined $gcos) {
775 $owner =~ s/[,;].*$//;
776 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
779 sub git_read_projects
{
782 if (-d
$projects_list) {
783 # search in directory
784 my $dir = $projects_list;
785 opendir my $dh, $dir or return undef;
786 while (my $dir = readdir($dh)) {
787 if (-e
"$projectroot/$dir/HEAD") {
795 } elsif (-f
$projects_list) {
796 # read from file(url-encoded):
797 # 'git%2Fgit.git Linus+Torvalds'
798 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
799 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
800 open my $fd , $projects_list or return undef;
801 while (my $line = <$fd>) {
803 my ($path, $owner) = split ' ', $line;
804 $path = unescape
($path);
805 $owner = unescape
($owner);
806 if (!defined $path) {
809 if (-e
"$projectroot/$path/HEAD") {
812 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
819 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
823 sub git_get_project_config
{
826 return unless ($key);
827 $key =~ s/^gitweb\.//;
828 return if ($key =~ m/\W/);
830 my $val = qx($gitbin/git
-repo
-config
--get gitweb
.$key);
834 sub git_get_project_config_bool
{
835 my $val = git_get_project_config
(@_);
836 if ($val and $val =~ m/true|yes|on/) {
839 return; # implicit false
842 sub git_project_list
{
843 my @list = git_read_projects
();
846 die_error
(undef, "No project found.");
848 foreach my $pr (@list) {
849 my $head = git_read_head
($pr->{'path'});
850 if (!defined $head) {
853 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
854 my %co = git_read_commit
($head);
858 $pr->{'commit'} = \
%co;
859 if (!defined $pr->{'descr'}) {
860 my $descr = git_read_description
($pr->{'path'}) || "";
861 $pr->{'descr'} = chop_str
($descr, 25, 5);
863 if (!defined $pr->{'owner'}) {
864 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
870 print "<div class=\"index_include\">\n";
871 open (my $fd, $home_text);
876 print "<table class=\"project_list\">\n" .
878 if (!defined($order) || (defined($order) && ($order eq "project"))) {
879 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
880 print "<th>Project</th>\n";
882 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=project")}, "Project") . "</th>\n";
884 if (defined($order) && ($order eq "descr")) {
885 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
886 print "<th>Description</th>\n";
888 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=descr")}, "Description") . "</th>\n";
890 if (defined($order) && ($order eq "owner")) {
891 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
892 print "<th>Owner</th>\n";
894 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=owner")}, "Owner") . "</th>\n";
896 if (defined($order) && ($order eq "age")) {
897 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
898 print "<th>Last Change</th>\n";
900 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=age")}, "Last Change") . "</th>\n";
902 print "<th></th>\n" .
905 foreach my $pr (@projects) {
907 print "<tr class=\"dark\">\n";
909 print "<tr class=\"light\">\n";
912 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=summary"), -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
913 "<td>$pr->{'descr'}</td>\n" .
914 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
915 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" . $pr->{'commit'}{'age_string'} . "</td>\n" .
916 "<td class=\"link\">" .
917 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=summary")}, "summary") .
918 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=shortlog")}, "shortlog") .
919 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=log")}, "log") .
928 my $type = shift || "";
930 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
931 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
932 open my $fd, "$projectroot/$project/info/refs" or return;
933 while (my $line = <$fd>) {
935 if ($line =~ m/^([0-9a-fA-F]{40})\t.*$type\/([^\
^]+)/) {
936 if (defined $refs{$1}) {
937 $refs{$1} .= " / $2";
952 opendir my $dh, "$projectroot/$project/$ref_dir";
953 while (my $dir = readdir($dh)) {
954 if ($dir =~ m/^\./) {
957 if (-d
"$projectroot/$project/$ref_dir/$dir") {
958 opendir my $dh2, "$projectroot/$project/$ref_dir/$dir";
959 my @subdirs = grep !m/^\./, readdir $dh2;
961 foreach my $subdir (@subdirs) {
962 push @refs, "$dir/$subdir"
969 foreach my $ref_file (@refs) {
970 my $ref_id = git_read_hash
("$project/$ref_dir/$ref_file");
971 my $type = git_get_type
($ref_id) || next;
974 $ref_item{'type'} = $type;
975 $ref_item{'id'} = $ref_id;
976 $ref_item{'epoch'} = 0;
977 $ref_item{'age'} = "unknown";
978 if ($type eq "tag") {
979 my %tag = git_read_tag
($ref_id);
980 $ref_item{'comment'} = $tag{'comment'};
981 if ($tag{'type'} eq "commit") {
982 %co = git_read_commit
($tag{'object'});
983 $ref_item{'epoch'} = $co{'committer_epoch'};
984 $ref_item{'age'} = $co{'age_string'};
985 } elsif (defined($tag{'epoch'})) {
986 my $age = time - $tag{'epoch'};
987 $ref_item{'epoch'} = $tag{'epoch'};
988 $ref_item{'age'} = age_string
($age);
990 $ref_item{'reftype'} = $tag{'type'};
991 $ref_item{'name'} = $tag{'name'};
992 $ref_item{'refid'} = $tag{'object'};
993 } elsif ($type eq "commit"){
994 %co = git_read_commit
($ref_id);
995 $ref_item{'reftype'} = "commit";
996 $ref_item{'name'} = $ref_file;
997 $ref_item{'title'} = $co{'title'};
998 $ref_item{'refid'} = $ref_id;
999 $ref_item{'epoch'} = $co{'committer_epoch'};
1000 $ref_item{'age'} = $co{'age_string'};
1003 push @reflist, \
%ref_item;
1006 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1011 my $descr = git_read_description
($project) || "none";
1012 my $head = git_read_head
($project);
1013 my %co = git_read_commit
($head);
1014 my %cd = date_str
($co{'committer_epoch'}, $co{'committer_tz'});
1017 if (-f
$projects_list) {
1018 open (my $fd , $projects_list);
1019 while (my $line = <$fd>) {
1021 my ($pr, $ow) = split ' ', $line;
1022 $pr = unescape
($pr);
1023 $ow = unescape
($ow);
1024 if ($pr eq $project) {
1025 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
1031 if (!defined $owner) {
1032 $owner = get_file_owner
("$projectroot/$project");
1035 my $refs = read_info_ref
();
1037 print "<div class=\"page_nav\">\n" .
1039 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1040 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1041 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$head")}, "commit") .
1042 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1043 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree")}, "tree") .
1046 print "<div class=\"title\"> </div>\n";
1047 print "<table cellspacing=\"0\">\n" .
1048 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
1049 "<tr><td>owner</td><td>$owner</td></tr>\n" .
1050 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
1052 open my $fd, "-|", "$gitbin/git-rev-list --max-count=17 " . git_read_head
($project) or die_error
(undef, "Open failed.");
1053 my (@revlist) = map { chomp; $_ } <$fd>;
1056 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog"), -class => "title"}, "shortlog") .
1059 print "<table cellspacing=\"0\">\n";
1061 foreach my $commit (@revlist) {
1062 my %co = git_read_commit
($commit);
1063 my %ad = date_str
($co{'author_epoch'});
1065 print "<tr class=\"dark\">\n";
1067 print "<tr class=\"light\">\n";
1072 if (defined $refs->{$commit}) {
1073 $ref = " <span class=\"tag\">" . esc_html
($refs->{$commit}) . "</span>";
1075 print "<td><i>$co{'age_string'}</i></td>\n" .
1076 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
1078 if (length($co{'title_short'}) < length($co{'title'})) {
1079 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list", -title
=> "$co{'title'}"},
1080 "<b>" . esc_html
($co{'title_short'}) . "$ref</b>");
1082 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list"},
1083 "<b>" . esc_html
($co{'title'}) . "$ref</b>");
1086 "<td class=\"link\">" .
1087 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
1088 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1092 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "...") . "</td>\n" .
1099 my $taglist = git_read_refs
("refs/tags");
1100 if (defined @
$taglist) {
1102 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tags"), -class => "title"}, "tags") .
1105 print "<table cellspacing=\"0\">\n";
1107 foreach my $entry (@
$taglist) {
1109 my $comment_lines = $tag{'comment'};
1110 my $comment = shift @
$comment_lines;
1111 if (defined($comment)) {
1112 $comment = chop_str
($comment, 30, 5);
1115 print "<tr class=\"dark\">\n";
1117 print "<tr class=\"light\">\n";
1121 print "<td><i>$tag{'age'}</i></td>\n" .
1123 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), -class => "list"},
1124 "<b>" . esc_html
($tag{'name'}) . "</b>") .
1127 if (defined($comment)) {
1128 print $cgi->a({-class => "list", -href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, $comment);
1131 "<td class=\"link\">";
1132 if ($tag{'type'} eq "tag") {
1133 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
1135 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1136 if ($tag{'reftype'} eq "commit") {
1137 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1138 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'refid'}")}, "log");
1143 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tags")}, "...") . "</td>\n" .
1151 my $headlist = git_read_refs
("refs/heads");
1152 if (defined @
$headlist) {
1154 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=heads"), -class => "title"}, "heads") .
1157 print "<table cellspacing=\"0\">\n";
1159 foreach my $entry (@
$headlist) {
1162 print "<tr class=\"dark\">\n";
1164 print "<tr class=\"light\">\n";
1168 print "<td><i>$tag{'age'}</i></td>\n" .
1170 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}"), -class => "list"},
1171 "<b>" . esc_html
($tag{'name'}) . "</b>") .
1173 "<td class=\"link\">" .
1174 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1175 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'name'}")}, "log") .
1179 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=heads")}, "...") . "</td>\n" .
1190 my $head = git_read_head
($project);
1192 print "<div class=\"page_nav\">\n" .
1193 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1194 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1195 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1196 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$head")}, "commit") .
1197 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1198 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1201 my %tag = git_read_tag
($hash);
1203 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html
($tag{'name'})) . "\n" .
1205 print "<div class=\"title_text\">\n" .
1206 "<table cellspacing=\"0\">\n" .
1208 "<td>object</td>\n" .
1209 "<td>" . $cgi->a({-class => "list", -href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'object'}) . "</td>\n" .
1210 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'type'}) . "</td>\n" .
1212 if (defined($tag{'author'})) {
1213 my %ad = date_str
($tag{'epoch'}, $tag{'tz'});
1214 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
1215 print "<tr><td></td><td>" . $ad{'rfc2822'} . sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) . "</td></tr>\n";
1217 print "</table>\n\n" .
1219 print "<div class=\"page_body\">";
1220 my $comment = $tag{'comment'};
1221 foreach my $line (@
$comment) {
1222 print esc_html
($line) . "<br/>\n";
1230 die_error
('403 Permission denied', "Permission denied.") if (!git_get_project_config_bool
('blame'));
1231 die_error
('404 Not Found', "What file will it be, master?") if (!$file_name);
1232 $hash_base ||= git_read_head
($project);
1233 die_error
(undef, "Reading commit failed.") unless ($hash_base);
1234 my %co = git_read_commit
($hash_base)
1235 or die_error
(undef, "Reading commit failed.");
1236 if (!defined $hash) {
1237 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
1238 or die_error
(undef, "Error lookup file.");
1240 open ($fd, "-|", "$gitbin/git-annotate", '-l', '-t', '-r', $file_name, $hash_base)
1241 or die_error
(undef, "Open failed.");
1243 print "<div class=\"page_nav\">\n" .
1244 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1245 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1246 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1247 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base")}, "commit") .
1248 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1249 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") . "<br/>\n";
1250 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") .
1251 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;f=$file_name")}, "head") . "<br/>\n";
1254 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html
($co{'title'})) .
1256 print "<div class=\"page_path\"><b>" . esc_html
($file_name) . "</b></div>\n";
1257 print "<div class=\"page_body\">\n";
1259 <table class="blame">
1268 my @line_class = (qw(light dark));
1269 my $line_class_len = scalar (@line_class);
1270 my $line_class_num = $#line_class;
1271 while (my $line = <$fd>) {
1283 $line_class_num = ($line_class_num + 1) % $line_class_len;
1285 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) \+\d\d\d\d\t(\d+)\)(.*)$/) {
1292 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
1295 $short_rev = substr ($long_rev, 0, 8);
1296 $age = time () - $time;
1297 $age_str = age_string
($age);
1298 $age_str =~ s/ / /g;
1299 $age_class = age_class
($age);
1300 $author = esc_html
($author);
1301 $author =~ s/ / /g;
1303 while ((my $pos = index($data, "\t")) != -1) {
1304 if (my $count = (8 - ($pos % 8))) {
1305 my $spaces = ' ' x
$count;
1306 $data =~ s/\t/$spaces/;
1309 $data = esc_html
($data);
1312 <tr class="$line_class[$line_class_num]">
1313 <td class="sha1"><a href="$my_uri?${\esc_param ("p=$project;a=commit;h=$long_rev")}" class="text">$short_rev..</a></td>
1314 <td class="$age_class">$age_str</td>
1316 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
1317 <td class="pre">$data</td>
1320 } # while (my $line = <$fd>)
1321 print "</table>\n\n";
1322 close $fd or print "Reading blob failed.\n";
1328 my $head = git_read_head
($project);
1330 print "<div class=\"page_nav\">\n" .
1331 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1332 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1333 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1334 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$head")}, "commit") .
1335 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1336 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1339 my $taglist = git_read_refs
("refs/tags");
1341 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary"), -class => "title"}, " ") .
1343 print "<table cellspacing=\"0\">\n";
1345 if (defined @
$taglist) {
1346 foreach my $entry (@
$taglist) {
1348 my $comment_lines = $tag{'comment'};
1349 my $comment = shift @
$comment_lines;
1350 if (defined($comment)) {
1351 $comment = chop_str
($comment, 30, 5);
1354 print "<tr class=\"dark\">\n";
1356 print "<tr class=\"light\">\n";
1359 print "<td><i>$tag{'age'}</i></td>\n" .
1361 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), -class => "list"},
1362 "<b>" . esc_html
($tag{'name'}) . "</b>") .
1365 if (defined($comment)) {
1366 print $cgi->a({-class => "list", -href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, $comment);
1369 "<td class=\"link\">";
1370 if ($tag{'type'} eq "tag") {
1371 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
1373 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1374 if ($tag{'reftype'} eq "commit") {
1375 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1376 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'refid'}")}, "log");
1387 my $head = git_read_head
($project);
1389 print "<div class=\"page_nav\">\n" .
1390 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1391 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1392 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1393 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$head")}, "commit") .
1394 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1395 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1398 my $taglist = git_read_refs
("refs/heads");
1400 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary"), -class => "title"}, " ") .
1402 print "<table cellspacing=\"0\">\n";
1404 if (defined @
$taglist) {
1405 foreach my $entry (@
$taglist) {
1408 print "<tr class=\"dark\">\n";
1410 print "<tr class=\"light\">\n";
1413 print "<td><i>$tag{'age'}</i></td>\n" .
1415 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}"), -class => "list"}, "<b>" . esc_html
($tag{'name'}) . "</b>") .
1417 "<td class=\"link\">" .
1418 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1419 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'name'}")}, "log") .
1428 sub git_get_hash_by_path
{
1430 my $path = shift || return undef;
1433 my @parts = split '/', $path;
1434 while (my $part = shift @parts) {
1435 open my $fd, "-|", "$gitbin/git-ls-tree $tree" or die_error
(undef, "Open git-ls-tree failed.");
1436 my (@entries) = map { chomp; $_ } <$fd>;
1437 close $fd or return undef;
1438 foreach my $line (@entries) {
1439 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1440 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1444 my $t_name = validate_input
(unquote
($4));
1445 if ($t_name eq $part) {
1449 if ($t_type eq "tree") {
1459 if (!defined $hash && defined $file_name) {
1460 my $base = $hash_base || git_read_head
($project);
1461 $hash = git_get_hash_by_path
($base, $file_name, "blob") || die_error
(undef, "Error lookup file.");
1463 my $have_blame = git_get_project_config_bool
('blame');
1464 open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or die_error
(undef, "Open failed.");
1466 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
1467 print "<div class=\"page_nav\">\n" .
1468 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1469 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1470 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1471 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base")}, "commit") .
1472 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1473 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") . "<br/>\n";
1474 if (defined $file_name) {
1476 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;h=$hash;hb=$hash_base;f=$file_name")}, "blame") . " | ";
1478 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$hash;f=$file_name")}, "plain") .
1479 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;hb=HEAD;f=$file_name")}, "head") . "<br/>\n";
1481 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$hash")}, "plain") . "<br/>\n";
1485 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html
($co{'title'})) .
1488 print "<div class=\"page_nav\">\n" .
1489 "<br/><br/></div>\n" .
1490 "<div class=\"title\">$hash</div>\n";
1492 if (defined $file_name) {
1493 print "<div class=\"page_path\"><b>" . esc_html
($file_name) . "</b></div>\n";
1495 print "<div class=\"page_body\">\n";
1497 while (my $line = <$fd>) {
1500 while ((my $pos = index($line, "\t")) != -1) {
1501 if (my $count = (8 - ($pos % 8))) {
1502 my $spaces = ' ' x
$count;
1503 $line =~ s/\t/$spaces/;
1506 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", $nr, $nr, $nr, esc_html
($line);
1508 close $fd or print "Reading blob failed.\n";
1513 sub mimetype_guess_file
{
1514 my $filename = shift;
1515 my $mimemap = shift;
1516 -r
$mimemap or return undef;
1519 open(MIME
, $mimemap) or return undef;
1521 my ($mime, $exts) = split(/\t+/);
1522 my @exts = split(/\s+/, $exts);
1523 foreach my $ext (@exts) {
1524 $mimemap{$ext} = $mime;
1529 $filename =~ /\.(.*?)$/;
1530 return $mimemap{$1};
1533 sub mimetype_guess
{
1534 my $filename = shift;
1536 $filename =~ /\./ or return undef;
1538 if ($mimetypes_file) {
1539 my $file = $mimetypes_file;
1540 #$file =~ m#^/# or $file = "$projectroot/$path/$file";
1541 $mime = mimetype_guess_file
($filename, $file);
1543 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1547 sub git_blob_plain_mimetype
{
1549 my $filename = shift;
1552 return $default_blob_plain_mimetype unless $fd;
1555 my $mime = mimetype_guess
($filename);
1556 $mime and return $mime;
1560 return 'text/plain' .
1561 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
1562 } elsif (! $filename) {
1563 return 'application/octet-stream';
1564 } elsif ($filename =~ m/\.png$/i) {
1566 } elsif ($filename =~ m/\.gif$/i) {
1568 } elsif ($filename =~ m/\.jpe?g$/i) {
1569 return 'image/jpeg';
1571 return 'application/octet-stream';
1575 sub git_blob_plain
{
1576 open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or return;
1577 my $type = git_blob_plain_mimetype
($fd, $file_name);
1579 # save as filename, even when no $file_name is given
1580 my $save_as = "$hash";
1581 if (defined $file_name) {
1582 $save_as = $file_name;
1583 } elsif ($type =~ m/^text\//) {
1587 print $cgi->header(-type
=> "$type", '-content-disposition' => "inline; filename=\"$save_as\"");
1589 binmode STDOUT
, ':raw';
1591 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
1597 if (!defined $hash) {
1598 $hash = git_read_head
($project);
1599 if (defined $file_name) {
1600 my $base = $hash_base || $hash;
1601 $hash = git_get_hash_by_path
($base, $file_name, "tree");
1603 if (!defined $hash_base) {
1608 open my $fd, "-|", "$gitbin/git-ls-tree -z $hash" or die_error
(undef, "Open git-ls-tree failed.");
1609 chomp (my (@entries) = <$fd>);
1610 close $fd or die_error
(undef, "Reading tree failed.");
1613 my $refs = read_info_ref
();
1615 if (defined $refs->{$hash_base}) {
1616 $ref = " <span class=\"tag\">" . esc_html
($refs->{$hash_base}) . "</span>";
1621 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
1622 $base_key = ";hb=$hash_base";
1623 print "<div class=\"page_nav\">\n" .
1624 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1625 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash_base")}, "shortlog") .
1626 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash_base")}, "log") .
1627 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base")}, "commit") .
1628 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1633 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html
($co{'title'}) . $ref) . "\n" .
1636 print "<div class=\"page_nav\">\n";
1637 print "<br/><br/></div>\n";
1638 print "<div class=\"title\">$hash</div>\n";
1640 if (defined $file_name) {
1641 $base = esc_html
("$file_name/");
1642 print "<div class=\"page_path\"><b>/" . esc_html
($file_name) . "</b></div>\n";
1644 print "<div class=\"page_path\"><b>/</b></div>\n";
1646 print "<div class=\"page_body\">\n";
1647 print "<table cellspacing=\"0\">\n";
1649 foreach my $line (@entries) {
1650 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1651 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1655 my $t_name = validate_input
($4);
1657 print "<tr class=\"dark\">\n";
1659 print "<tr class=\"light\">\n";
1662 print "<td class=\"mode\">" . mode_str
($t_mode) . "</td>\n";
1663 if ($t_type eq "blob") {
1664 print "<td class=\"list\">" .
1665 $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)) .
1667 "<td class=\"link\">" .
1668 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name")}, "blob") .
1669 # " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$t_hash$base_key;f=$base$t_name")}, "blame") .
1670 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;h=$hash_base;f=$base$t_name")}, "history") .
1672 } elsif ($t_type eq "tree") {
1673 print "<td class=\"list\">" .
1674 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, esc_html
($t_name)) .
1676 "<td class=\"link\">" .
1677 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, "tree") .
1678 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;h=$hash_base;f=$base$t_name")}, "history") .
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";
2299 "$gitbin/git-rev-list --full-history $hash -- \'$file_name\'";
2300 print "<table cellspacing=\"0\">\n";
2302 while (my $line = <$fd>) {
2303 if ($line =~ m/^([0-9a-fA-F]{40})/){
2305 my %co = git_read_commit
($commit);
2310 if (defined $refs->{$commit}) {
2311 $ref = " <span class=\"tag\">" . esc_html
($refs->{$commit}) . "</span>";
2314 print "<tr class=\"dark\">\n";
2316 print "<tr class=\"light\">\n";
2319 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2320 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2321 "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list"}, "<b>" .
2322 esc_html
(chop_str
($co{'title'}, 50)) . "$ref</b>") . "</td>\n" .
2323 "<td class=\"link\">" .
2324 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
2325 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2326 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;hb=$commit;f=$file_name")}, "blob");
2327 my $blob = git_get_hash_by_path
($hash, $file_name);
2328 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2329 if (defined $blob && defined $blob_parent && $blob ne $blob_parent) {
2331 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=$file_name")},
2344 if (!defined $searchtext) {
2345 die_error
("", "Text field empty.");
2347 if (!defined $hash) {
2348 $hash = git_read_head
($project);
2350 my %co = git_read_commit
($hash);
2352 die_error
(undef, "Unknown commit object.");
2354 # pickaxe may take all resources of your box and run for several minutes
2355 # with every query - so decide by yourself how public you make this feature :)
2356 my $commit_search = 1;
2357 my $author_search = 0;
2358 my $committer_search = 0;
2359 my $pickaxe_search = 0;
2360 if ($searchtext =~ s/^author\\://i) {
2362 } elsif ($searchtext =~ s/^committer\\://i) {
2363 $committer_search = 1;
2364 } elsif ($searchtext =~ s/^pickaxe\\://i) {
2366 $pickaxe_search = 1;
2369 print "<div class=\"page_nav\">\n" .
2370 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary;h=$hash")}, "summary") .
2371 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
2372 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash")}, "log") .
2373 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash")}, "commit") .
2374 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2375 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
2380 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html
($co{'title'})) . "\n" .
2382 print "<table cellspacing=\"0\">\n";
2384 if ($commit_search) {
2386 open my $fd, "-|", "$gitbin/git-rev-list --header --parents $hash" or next;
2387 while (my $commit_text = <$fd>) {
2388 if (!grep m/$searchtext/i, $commit_text) {
2391 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
2394 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
2397 my @commit_lines = split "\n", $commit_text;
2398 my %co = git_read_commit
(undef, \
@commit_lines);
2403 print "<tr class=\"dark\">\n";
2405 print "<tr class=\"light\">\n";
2408 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2409 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2411 $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/>");
2412 my $comment = $co{'comment'};
2413 foreach my $line (@
$comment) {
2414 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2415 my $lead = esc_html
($1) || "";
2416 $lead = chop_str
($lead, 30, 10);
2417 my $match = esc_html
($2) || "";
2418 my $trail = esc_html
($3) || "";
2419 $trail = chop_str
($trail, 30, 10);
2420 my $text = "$lead<span class=\"match\">$match</span>$trail";
2421 print chop_str
($text, 80, 5) . "<br/>\n";
2425 "<td class=\"link\">" .
2426 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2427 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2434 if ($pickaxe_search) {
2436 open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin -S\'$searchtext\'";
2439 while (my $line = <$fd>) {
2440 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2443 $set{'from_id'} = $3;
2445 $set{'id'} = $set{'to_id'};
2446 if ($set{'id'} =~ m/0{40}/) {
2447 $set{'id'} = $set{'from_id'};
2449 if ($set{'id'} =~ m/0{40}/) {
2453 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
2456 print "<tr class=\"dark\">\n";
2458 print "<tr class=\"light\">\n";
2461 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2462 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2464 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" .
2465 esc_html
(chop_str
($co{'title'}, 50)) . "</b><br/>");
2466 while (my $setref = shift @files) {
2468 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}"), class => "list"},
2469 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
2473 "<td class=\"link\">" .
2474 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2475 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2479 %co = git_read_commit
($1);
2489 my $head = git_read_head
($project);
2490 if (!defined $hash) {
2493 if (!defined $page) {
2496 my $refs = read_info_ref
();
2498 print "<div class=\"page_nav\">\n" .
2499 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
2501 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash")}, "log") .
2502 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash")}, "commit") .
2503 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2504 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$hash;hb=$hash")}, "tree") . "<br/>\n";
2506 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2507 open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error
(undef, "Open failed.");
2508 my (@revlist) = map { chomp; $_ } <$fd>;
2511 if ($hash ne $head || $page) {
2512 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "HEAD");
2518 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash;pg=" . ($page-1)), -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2520 print " ⋅ prev";
2522 if ($#revlist >= (100 * ($page+1)-1)) {
2524 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)), -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2526 print " ⋅ next";
2531 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary"), -class => "title"}, " ") .
2533 print "<table cellspacing=\"0\">\n";
2535 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2536 my $commit = $revlist[$i];
2538 if (defined $refs->{$commit}) {
2539 $ref = " <span class=\"tag\">" . esc_html
($refs->{$commit}) . "</span>";
2541 my %co = git_read_commit
($commit);
2542 my %ad = date_str
($co{'author_epoch'});
2544 print "<tr class=\"dark\">\n";
2546 print "<tr class=\"light\">\n";
2549 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2550 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
2552 if (length($co{'title_short'}) < length($co{'title'})) {
2553 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list", -title
=> "$co{'title'}"},
2554 "<b>" . esc_html
($co{'title_short'}) . "$ref</b>");
2556 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list"},
2557 "<b>" . esc_html
($co{'title_short'}) . "$ref</b>");
2560 "<td class=\"link\">" .
2561 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
2562 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2566 if ($#revlist >= (100 * ($page+1)-1)) {
2569 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)), -title
=> "Alt-n"}, "next") .