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 mkdir($git_temp, 0700) || die_error
("Couldn't mkdir $git_temp");
46 # target of the home link on top of all pages
47 our $home_link = $my_uri;
49 # html text to include at home page
50 our $home_text = "indextext.html";
52 # URI of default stylesheet
53 our $stylesheet = "gitweb.css";
55 # source of projects list
56 #our $projects_list = $projectroot;
57 our $projects_list = "index/index.aux";
59 # default blob_plain mimetype and default charset for text/plain blob
60 our $default_blob_plain_mimetype = 'text/plain';
61 our $default_text_plain_charset = undef;
63 # file to use for guessing MIME types before trying /etc/mime.types
64 # (relative to the current git repository)
65 our $mimetypes_file = undef;
67 # input validation and dispatch
68 our $action = $cgi->param('a');
69 if (defined $action) {
70 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
72 die_error
(undef, "Invalid action parameter.");
74 if ($action eq "git-logo.png") {
77 } elsif ($action eq "opml") {
83 our $order = $cgi->param('o');
85 if ($order =~ m/[^0-9a-zA-Z_]/) {
87 die_error
(undef, "Invalid order parameter.");
91 our $project = ($cgi->param('p') || $ENV{'PATH_INFO'});
92 if (defined $project) {
93 $project =~ s
|^/||; $project =~ s|/$||;
94 $project = validate_input
($project);
95 if (!defined($project)) {
96 die_error
(undef, "Invalid project parameter.");
98 if (!(-d
"$projectroot/$project")) {
100 die_error
(undef, "No such directory.");
102 if (!(-e
"$projectroot/$project/HEAD")) {
104 die_error
(undef, "No such project.");
106 $rss_link = "<link rel=\"alternate\" title=\"" . esc_param
($project) . " log\" href=\"" .
107 "$my_uri?" . esc_param
("p=$project;a=rss") . "\" type=\"application/rss+xml\"/>";
108 $ENV{'GIT_DIR'} = "$projectroot/$project";
114 our $file_name = $cgi->param('f');
115 if (defined $file_name) {
116 $file_name = validate_input
($file_name);
117 if (!defined($file_name)) {
118 die_error
(undef, "Invalid file parameter.");
122 our $hash = $cgi->param('h');
124 $hash = validate_input
($hash);
125 if (!defined($hash)) {
126 die_error
(undef, "Invalid hash parameter.");
130 our $hash_parent = $cgi->param('hp');
131 if (defined $hash_parent) {
132 $hash_parent = validate_input
($hash_parent);
133 if (!defined($hash_parent)) {
134 die_error
(undef, "Invalid hash parent parameter.");
138 our $hash_base = $cgi->param('hb');
139 if (defined $hash_base) {
140 $hash_base = validate_input
($hash_base);
141 if (!defined($hash_base)) {
142 die_error
(undef, "Invalid hash base parameter.");
146 our $page = $cgi->param('pg');
148 if ($page =~ m/[^0-9]$/) {
150 die_error
(undef, "Invalid page parameter.");
154 our $searchtext = $cgi->param('s');
155 if (defined $searchtext) {
156 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
158 die_error
(undef, "Invalid search parameter.");
160 $searchtext = quotemeta $searchtext;
166 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
169 if ($input =~ m/(^|\/)(|\
.|\
.\
.)($|\
/)/) {
172 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\
-\
+\#\
~\
%]/) {
178 if (!defined $action || $action eq "summary") {
181 } elsif ($action eq "heads") {
184 } elsif ($action eq "tags") {
187 } elsif ($action eq "blob") {
190 } elsif ($action eq "blob_plain") {
193 } elsif ($action eq "tree") {
196 } elsif ($action eq "rss") {
199 } elsif ($action eq "commit") {
202 } elsif ($action eq "log") {
205 } elsif ($action eq "blobdiff") {
208 } elsif ($action eq "blobdiff_plain") {
209 git_blobdiff_plain
();
211 } elsif ($action eq "commitdiff") {
214 } elsif ($action eq "commitdiff_plain") {
215 git_commitdiff_plain
();
217 } elsif ($action eq "history") {
220 } elsif ($action eq "search") {
223 } elsif ($action eq "shortlog") {
226 } elsif ($action eq "tag") {
229 } elsif ($action eq "blame") {
234 die_error
(undef, "Unknown action.");
238 # quote unsafe chars, but keep the slash, even when it's not
239 # correct, but quoted slashes look too horrible in bookmarks
242 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
248 # replace invalid utf8 character with SUBSTITUTION sequence
251 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
252 $str = escapeHTML
($str);
256 # git may return quoted and escaped filenames
259 if ($str =~ m/^"(.*)"$/) {
261 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
266 # CSS class for given age value (in seconds)
270 if ($age < 60*60*2) {
272 } elsif ($age < 60*60*24*2) {
279 sub git_header_html
{
280 my $status = shift || "200 OK";
284 if (defined $project) {
285 $title .= " - $project";
286 if (defined $action) {
287 $title .= "/$action";
288 if (defined $file_name) {
289 $title .= " - $file_name";
290 if ($action eq "tree" && $file_name !~ m
|/$|) {
296 print $cgi->header(-type
=>'text/html', -charset
=> 'utf-8', -status
=> $status, -expires
=> $expires);
298 <?xml version="1.0" encoding="utf-8"?>
299 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
300 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
301 <!-- git web interface v$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
302 <!-- git core binaries version $git_version -->
304 <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
305 <meta name="robots" content="index, nofollow"/>
306 <title>$title</title>
307 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
312 print "<div class=\"page_header\">\n" .
313 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
314 "<img src=\"$my_uri?" . esc_param
("a=git-logo.png") . "\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
316 print $cgi->a({-href
=> esc_param
($home_link)}, "projects") . " / ";
317 if (defined $project) {
318 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, esc_html
($project));
319 if (defined $action) {
323 if (!defined $searchtext) {
327 if (defined $hash_base) {
328 $search_hash = $hash_base;
329 } elsif (defined $hash) {
330 $search_hash = $hash;
332 $search_hash = "HEAD";
334 $cgi->param("a", "search");
335 $cgi->param("h", $search_hash);
336 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
337 "<div class=\"search\">\n" .
338 $cgi->hidden(-name
=> "p") . "\n" .
339 $cgi->hidden(-name
=> "a") . "\n" .
340 $cgi->hidden(-name
=> "h") . "\n" .
341 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
343 $cgi->end_form() . "\n";
348 sub git_footer_html
{
349 print "<div class=\"page_footer\">\n";
350 if (defined $project) {
351 my $descr = git_read_description
($project);
352 if (defined $descr) {
353 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
355 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=rss"), -class => "rss_logo"}, "RSS") . "\n";
357 print $cgi->a({-href
=> "$my_uri?" . esc_param
("a=opml"), -class => "rss_logo"}, "OPML") . "\n";
365 my $status = shift || "403 Forbidden";
366 my $error = shift || "Malformed query, file missing or permission denied";
368 git_header_html
($status);
369 print "<div class=\"page_body\">\n" .
371 "$status - $error\n" .
381 open my $fd, "-|", "$gitbin/git-cat-file -t $hash" or return;
390 my $oENV = $ENV{'GIT_DIR'};
392 $ENV{'GIT_DIR'} = "$projectroot/$project";
393 if (open my $fd, "-|", "$gitbin/git-rev-parse", "--verify", "HEAD") {
396 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
401 $ENV{'GIT_DIR'} = $oENV;
409 open my $fd, "$projectroot/$path" or return undef;
413 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
418 sub git_read_description
{
421 open my $fd, "$projectroot/$path/description" or return undef;
433 open my $fd, "-|", "$gitbin/git-cat-file tag $tag_id" or return;
434 $tag{'id'} = $tag_id;
435 while (my $line = <$fd>) {
437 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
439 } elsif ($line =~ m/^type (.+)$/) {
441 } elsif ($line =~ m/^tag (.+)$/) {
443 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
447 } elsif ($line =~ m/--BEGIN/) {
448 push @comment, $line;
450 } elsif ($line eq "") {
454 push @comment, <$fd>;
455 $tag{'comment'} = \
@comment;
457 if (!defined $tag{'name'}) {
467 if ($age > 60*60*24*365*2) {
468 $age_str = (int $age/60/60/24/365);
469 $age_str .= " years ago";
470 } elsif ($age > 60*60*24*(365/12)*2) {
471 $age_str = int $age/60/60/24/(365/12);
472 $age_str .= " months ago";
473 } elsif ($age > 60*60*24*7*2) {
474 $age_str = int $age/60/60/24/7;
475 $age_str .= " weeks ago";
476 } elsif ($age > 60*60*24*2) {
477 $age_str = int $age/60/60/24;
478 $age_str .= " days ago";
479 } elsif ($age > 60*60*2) {
480 $age_str = int $age/60/60;
481 $age_str .= " hours ago";
482 } elsif ($age > 60*2) {
483 $age_str = int $age/60;
484 $age_str .= " min ago";
487 $age_str .= " sec ago";
489 $age_str .= " right now";
494 sub git_read_commit
{
495 my $commit_id = shift;
496 my $commit_text = shift;
501 if (defined $commit_text) {
502 @commit_lines = @
$commit_text;
505 open my $fd, "-|", "$gitbin/git-rev-list --header --parents --max-count=1 $commit_id" or return;
506 @commit_lines = split '\n', <$fd>;
511 my $header = shift @commit_lines;
512 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
515 ($co{'id'}, my @parents) = split ' ', $header;
516 $co{'parents'} = \
@parents;
517 $co{'parent'} = $parents[0];
518 while (my $line = shift @commit_lines) {
519 last if $line eq "\n";
520 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
522 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
524 $co{'author_epoch'} = $2;
525 $co{'author_tz'} = $3;
526 if ($co{'author'} =~ m/^([^<]+) </) {
527 $co{'author_name'} = $1;
529 $co{'author_name'} = $co{'author'};
531 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
532 $co{'committer'} = $1;
533 $co{'committer_epoch'} = $2;
534 $co{'committer_tz'} = $3;
535 $co{'committer_name'} = $co{'committer'};
536 $co{'committer_name'} =~ s/ <.*//;
539 if (!defined $co{'tree'}) {
543 foreach my $title (@commit_lines) {
546 $co{'title'} = chop_str
($title, 80, 5);
547 # remove leading stuff of merges to make the interesting part visible
548 if (length($title) > 50) {
549 $title =~ s/^Automatic //;
550 $title =~ s/^merge (of|with) /Merge ... /i;
551 if (length($title) > 50) {
552 $title =~ s/(http|rsync):\/\///;
554 if (length($title) > 50) {
555 $title =~ s/(master|www|rsync)\.//;
557 if (length($title) > 50) {
558 $title =~ s/kernel.org:?//;
560 if (length($title) > 50) {
561 $title =~ s/\/pub\/scm//;
564 $co{'title_short'} = chop_str
($title, 50, 5);
568 # remove added spaces
569 foreach my $line (@commit_lines) {
572 $co{'comment'} = \
@commit_lines;
574 my $age = time - $co{'committer_epoch'};
576 $co{'age_string'} = age_string
($age);
577 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
578 if ($age > 60*60*24*7*2) {
579 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
580 $co{'age_string_age'} = $co{'age_string'};
582 $co{'age_string_date'} = $co{'age_string'};
583 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
590 my $from_name = shift;
593 my $format = shift || "html";
595 my $from_tmp = "/dev/null";
596 my $to_tmp = "/dev/null";
599 # create tmp from-file
601 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
602 open my $fd2, "> $from_tmp";
603 open my $fd, "-|", "$gitbin/git-cat-file blob $from";
612 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
613 open my $fd2, "> $to_tmp";
614 open my $fd, "-|", "$gitbin/git-cat-file blob $to";
621 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
622 if ($format eq "plain") {
627 while (my $line = <$fd>) {
629 my $char = substr($line, 0, 1);
632 $diff_class = " add";
633 } elsif ($char eq "-") {
634 $diff_class = " rem";
635 } elsif ($char eq "@") {
636 $diff_class = " chunk_header";
637 } elsif ($char eq "\\") {
641 while ((my $pos = index($line, "\t")) != -1) {
642 if (my $count = (8 - (($pos-1) % 8))) {
643 my $spaces = ' ' x
$count;
644 $line =~ s/\t/$spaces/;
647 print "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
661 my $mode = oct shift;
663 if (S_ISDIR
($mode & S_IFMT
)) {
665 } elsif (S_ISLNK
($mode)) {
667 } elsif (S_ISREG
($mode)) {
668 # git cares only about the executable bit
669 if ($mode & S_IXUSR
) {
682 my $add_len = shift || 10;
684 # allow only $len chars, but don't cut a word if it would fit in $add_len
685 # if it doesn't fit, cut it if it's still longer than the dots we would add
686 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
689 if (length($tail) > 4) {
696 my $mode = oct shift;
698 if (S_ISDIR
($mode & S_IFMT
)) {
700 } elsif (S_ISLNK
($mode)) {
702 } elsif (S_ISREG
($mode)) {
709 sub format_log_line_html
{
712 $line = esc_html
($line);
713 $line =~ s/ / /g;
714 if ($line =~ m/([0-9a-fA-F]{40})/) {
716 if (git_get_type
($hash_text) eq "commit") {
717 my $link = $cgi->a({-class => "text", -href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_text")}, $hash_text);
718 $line =~ s/$hash_text/$link/;
726 my $tz = shift || "-0000";
729 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
730 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
731 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
732 $date{'hour'} = $hour;
733 $date{'minute'} = $min;
734 $date{'mday'} = $mday;
735 $date{'day'} = $days[$wday];
736 $date{'month'} = $months[$mon];
737 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
738 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
740 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
741 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
742 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
743 $date{'hour_local'} = $hour;
744 $date{'minute_local'} = $min;
745 $date{'tz_local'} = $tz;
749 # git-logo (cached in browser for one day)
751 binmode STDOUT
, ':raw';
752 print $cgi->header(-type
=> 'image/png', -expires
=> '+1d');
753 # cat git-logo.png | hexdump -e '16/1 " %02x" "\n"' | sed 's/ /\\x/g'
754 print "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52" .
755 "\x00\x00\x00\x48\x00\x00\x00\x1b\x04\x03\x00\x00\x00\x2d\xd9\xd4" .
756 "\x2d\x00\x00\x00\x18\x50\x4c\x54\x45\xff\xff\xff\x60\x60\x5d\xb0" .
757 "\xaf\xaa\x00\x80\x00\xce\xcd\xc7\xc0\x00\x00\xe8\xe8\xe6\xf7\xf7" .
758 "\xf6\x95\x0c\xa7\x47\x00\x00\x00\x73\x49\x44\x41\x54\x28\xcf\x63" .
759 "\x48\x67\x20\x04\x4a\x5c\x18\x0a\x08\x2a\x62\x53\x61\x20\x02\x08" .
760 "\x0d\x69\x45\xac\xa1\xa1\x01\x30\x0c\x93\x60\x36\x26\x52\x91\xb1" .
761 "\x01\x11\xd6\xe1\x55\x64\x6c\x6c\xcc\x6c\x6c\x0c\xa2\x0c\x70\x2a" .
762 "\x62\x06\x2a\xc1\x62\x1d\xb3\x01\x02\x53\xa4\x08\xe8\x00\x03\x18" .
763 "\x26\x56\x11\xd4\xe1\x20\x97\x1b\xe0\xb4\x0e\x35\x24\x71\x29\x82" .
764 "\x99\x30\xb8\x93\x0a\x11\xb9\x45\x88\xc1\x8d\xa0\xa2\x44\x21\x06" .
765 "\x27\x41\x82\x40\x85\xc1\x45\x89\x20\x70\x01\x00\xa4\x3d\x21\xc5" .
766 "\x12\x1c\x9a\xfe\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\x82";
772 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
773 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
774 if (!defined $gcos) {
778 $owner =~ s/[,;].*$//;
779 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
782 sub git_read_projects
{
785 if (-d
$projects_list) {
786 # search in directory
787 my $dir = $projects_list;
788 opendir my $dh, $dir or return undef;
789 while (my $dir = readdir($dh)) {
790 if (-e
"$projectroot/$dir/HEAD") {
798 } elsif (-f
$projects_list) {
799 # read from file(url-encoded):
800 # 'git%2Fgit.git Linus+Torvalds'
801 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
802 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
803 open my $fd , $projects_list or return undef;
804 while (my $line = <$fd>) {
806 my ($path, $owner) = split ' ', $line;
807 $path = unescape
($path);
808 $owner = unescape
($owner);
809 if (!defined $path) {
812 if (-e
"$projectroot/$path/HEAD") {
815 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
822 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
826 sub git_get_project_config
{
829 return unless ($key);
830 $key =~ s/^gitweb\.//;
831 return if ($key =~ m/\W/);
833 my $val = qx($gitbin/git
-repo
-config
--get gitweb
.$key);
837 sub git_get_project_config_bool
{
838 my $val = git_get_project_config
(@_);
839 if ($val and $val =~ m/true|yes|on/) {
842 return; # implicit false
845 sub git_project_list
{
846 my @list = git_read_projects
();
849 die_error
(undef, "No project found.");
851 foreach my $pr (@list) {
852 my $head = git_read_head
($pr->{'path'});
853 if (!defined $head) {
856 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
857 my %co = git_read_commit
($head);
861 $pr->{'commit'} = \
%co;
862 if (!defined $pr->{'descr'}) {
863 my $descr = git_read_description
($pr->{'path'}) || "";
864 $pr->{'descr'} = chop_str
($descr, 25, 5);
866 if (!defined $pr->{'owner'}) {
867 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
873 print "<div class=\"index_include\">\n";
874 open (my $fd, $home_text);
879 print "<table class=\"project_list\">\n" .
881 if (!defined($order) || (defined($order) && ($order eq "project"))) {
882 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
883 print "<th>Project</th>\n";
885 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=project")}, "Project") . "</th>\n";
887 if (defined($order) && ($order eq "descr")) {
888 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
889 print "<th>Description</th>\n";
891 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=descr")}, "Description") . "</th>\n";
893 if (defined($order) && ($order eq "owner")) {
894 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
895 print "<th>Owner</th>\n";
897 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=owner")}, "Owner") . "</th>\n";
899 if (defined($order) && ($order eq "age")) {
900 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
901 print "<th>Last Change</th>\n";
903 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=age")}, "Last Change") . "</th>\n";
905 print "<th></th>\n" .
908 foreach my $pr (@projects) {
910 print "<tr class=\"dark\">\n";
912 print "<tr class=\"light\">\n";
915 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=summary"), -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
916 "<td>$pr->{'descr'}</td>\n" .
917 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
918 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" . $pr->{'commit'}{'age_string'} . "</td>\n" .
919 "<td class=\"link\">" .
920 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=summary")}, "summary") .
921 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=shortlog")}, "shortlog") .
922 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=log")}, "log") .
931 my $type = shift || "";
933 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
934 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
935 open my $fd, "$projectroot/$project/info/refs" or return;
936 while (my $line = <$fd>) {
938 if ($line =~ m/^([0-9a-fA-F]{40})\t.*$type\/([^\
^]+)/) {
939 if (defined $refs{$1}) {
940 $refs{$1} .= " / $2";
955 opendir my $dh, "$projectroot/$project/$ref_dir";
956 while (my $dir = readdir($dh)) {
957 if ($dir =~ m/^\./) {
960 if (-d
"$projectroot/$project/$ref_dir/$dir") {
961 opendir my $dh2, "$projectroot/$project/$ref_dir/$dir";
962 my @subdirs = grep !m/^\./, readdir $dh2;
964 foreach my $subdir (@subdirs) {
965 push @refs, "$dir/$subdir"
972 foreach my $ref_file (@refs) {
973 my $ref_id = git_read_hash
("$project/$ref_dir/$ref_file");
974 my $type = git_get_type
($ref_id) || next;
977 $ref_item{'type'} = $type;
978 $ref_item{'id'} = $ref_id;
979 $ref_item{'epoch'} = 0;
980 $ref_item{'age'} = "unknown";
981 if ($type eq "tag") {
982 my %tag = git_read_tag
($ref_id);
983 $ref_item{'comment'} = $tag{'comment'};
984 if ($tag{'type'} eq "commit") {
985 %co = git_read_commit
($tag{'object'});
986 $ref_item{'epoch'} = $co{'committer_epoch'};
987 $ref_item{'age'} = $co{'age_string'};
988 } elsif (defined($tag{'epoch'})) {
989 my $age = time - $tag{'epoch'};
990 $ref_item{'epoch'} = $tag{'epoch'};
991 $ref_item{'age'} = age_string
($age);
993 $ref_item{'reftype'} = $tag{'type'};
994 $ref_item{'name'} = $tag{'name'};
995 $ref_item{'refid'} = $tag{'object'};
996 } elsif ($type eq "commit"){
997 %co = git_read_commit
($ref_id);
998 $ref_item{'reftype'} = "commit";
999 $ref_item{'name'} = $ref_file;
1000 $ref_item{'title'} = $co{'title'};
1001 $ref_item{'refid'} = $ref_id;
1002 $ref_item{'epoch'} = $co{'committer_epoch'};
1003 $ref_item{'age'} = $co{'age_string'};
1006 push @reflist, \
%ref_item;
1009 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1014 my $descr = git_read_description
($project) || "none";
1015 my $head = git_read_head
($project);
1016 my %co = git_read_commit
($head);
1017 my %cd = date_str
($co{'committer_epoch'}, $co{'committer_tz'});
1020 if (-f
$projects_list) {
1021 open (my $fd , $projects_list);
1022 while (my $line = <$fd>) {
1024 my ($pr, $ow) = split ' ', $line;
1025 $pr = unescape
($pr);
1026 $ow = unescape
($ow);
1027 if ($pr eq $project) {
1028 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
1034 if (!defined $owner) {
1035 $owner = get_file_owner
("$projectroot/$project");
1038 my $refs = read_info_ref
();
1040 print "<div class=\"page_nav\">\n" .
1042 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1043 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1044 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$head")}, "commit") .
1045 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1046 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree")}, "tree") .
1049 print "<div class=\"title\"> </div>\n";
1050 print "<table cellspacing=\"0\">\n" .
1051 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
1052 "<tr><td>owner</td><td>$owner</td></tr>\n" .
1053 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
1055 open my $fd, "-|", "$gitbin/git-rev-list --max-count=17 " . git_read_head
($project) or die_error
(undef, "Open failed.");
1056 my (@revlist) = map { chomp; $_ } <$fd>;
1059 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog"), -class => "title"}, "shortlog") .
1062 print "<table cellspacing=\"0\">\n";
1064 foreach my $commit (@revlist) {
1065 my %co = git_read_commit
($commit);
1066 my %ad = date_str
($co{'author_epoch'});
1068 print "<tr class=\"dark\">\n";
1070 print "<tr class=\"light\">\n";
1075 if (defined $refs->{$commit}) {
1076 $ref = " <span class=\"tag\">" . esc_html
($refs->{$commit}) . "</span>";
1078 print "<td><i>$co{'age_string'}</i></td>\n" .
1079 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
1081 if (length($co{'title_short'}) < length($co{'title'})) {
1082 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list", -title
=> "$co{'title'}"},
1083 "<b>" . esc_html
($co{'title_short'}) . "$ref</b>");
1085 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list"},
1086 "<b>" . esc_html
($co{'title'}) . "$ref</b>");
1089 "<td class=\"link\">" .
1090 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
1091 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1095 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "...") . "</td>\n" .
1102 my $taglist = git_read_refs
("refs/tags");
1103 if (defined @
$taglist) {
1105 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tags"), -class => "title"}, "tags") .
1108 print "<table cellspacing=\"0\">\n";
1110 foreach my $entry (@
$taglist) {
1112 my $comment_lines = $tag{'comment'};
1113 my $comment = shift @
$comment_lines;
1114 if (defined($comment)) {
1115 $comment = chop_str
($comment, 30, 5);
1118 print "<tr class=\"dark\">\n";
1120 print "<tr class=\"light\">\n";
1124 print "<td><i>$tag{'age'}</i></td>\n" .
1126 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), -class => "list"},
1127 "<b>" . esc_html
($tag{'name'}) . "</b>") .
1130 if (defined($comment)) {
1131 print $cgi->a({-class => "list", -href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, $comment);
1134 "<td class=\"link\">";
1135 if ($tag{'type'} eq "tag") {
1136 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
1138 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1139 if ($tag{'reftype'} eq "commit") {
1140 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1141 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'refid'}")}, "log");
1146 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tags")}, "...") . "</td>\n" .
1154 my $headlist = git_read_refs
("refs/heads");
1155 if (defined @
$headlist) {
1157 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=heads"), -class => "title"}, "heads") .
1160 print "<table cellspacing=\"0\">\n";
1162 foreach my $entry (@
$headlist) {
1165 print "<tr class=\"dark\">\n";
1167 print "<tr class=\"light\">\n";
1171 print "<td><i>$tag{'age'}</i></td>\n" .
1173 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}"), -class => "list"},
1174 "<b>" . esc_html
($tag{'name'}) . "</b>") .
1176 "<td class=\"link\">" .
1177 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1178 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'name'}")}, "log") .
1182 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=heads")}, "...") . "</td>\n" .
1193 my $head = git_read_head
($project);
1195 print "<div class=\"page_nav\">\n" .
1196 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1197 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1198 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1199 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$head")}, "commit") .
1200 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1201 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1204 my %tag = git_read_tag
($hash);
1206 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html
($tag{'name'})) . "\n" .
1208 print "<div class=\"title_text\">\n" .
1209 "<table cellspacing=\"0\">\n" .
1211 "<td>object</td>\n" .
1212 "<td>" . $cgi->a({-class => "list", -href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'object'}) . "</td>\n" .
1213 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'type'}) . "</td>\n" .
1215 if (defined($tag{'author'})) {
1216 my %ad = date_str
($tag{'epoch'}, $tag{'tz'});
1217 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
1218 print "<tr><td></td><td>" . $ad{'rfc2822'} . sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) . "</td></tr>\n";
1220 print "</table>\n\n" .
1222 print "<div class=\"page_body\">";
1223 my $comment = $tag{'comment'};
1224 foreach my $line (@
$comment) {
1225 print esc_html
($line) . "<br/>\n";
1233 die_error
('403 Permission denied', "Permission denied.") if (!git_get_project_config_bool
('blame'));
1234 die_error
('404 Not Found', "What file will it be, master?") if (!$file_name);
1235 $hash_base ||= git_read_head
($project);
1236 die_error
(undef, "Reading commit failed.") unless ($hash_base);
1237 my %co = git_read_commit
($hash_base)
1238 or die_error
(undef, "Reading commit failed.");
1239 if (!defined $hash) {
1240 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
1241 or die_error
(undef, "Error lookup file.");
1243 open ($fd, "-|", "$gitbin/git-annotate", '-l', '-t', '-r', $file_name, $hash_base)
1244 or die_error
(undef, "Open failed.");
1246 print "<div class=\"page_nav\">\n" .
1247 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1248 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1249 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1250 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base")}, "commit") .
1251 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1252 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") . "<br/>\n";
1253 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") .
1254 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;f=$file_name")}, "head") . "<br/>\n";
1257 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html
($co{'title'})) .
1259 print "<div class=\"page_path\"><b>" . esc_html
($file_name) . "</b></div>\n";
1260 print "<div class=\"page_body\">\n";
1262 <table class="blame">
1271 my @line_class = (qw(light dark));
1272 my $line_class_len = scalar (@line_class);
1273 my $line_class_num = $#line_class;
1274 while (my $line = <$fd>) {
1286 $line_class_num = ($line_class_num + 1) % $line_class_len;
1288 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) \+\d\d\d\d\t(\d+)\)(.*)$/) {
1295 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
1298 $short_rev = substr ($long_rev, 0, 8);
1299 $age = time () - $time;
1300 $age_str = age_string
($age);
1301 $age_str =~ s/ / /g;
1302 $age_class = age_class
($age);
1303 $author = esc_html
($author);
1304 $author =~ s/ / /g;
1306 while ((my $pos = index($data, "\t")) != -1) {
1307 if (my $count = (8 - ($pos % 8))) {
1308 my $spaces = ' ' x
$count;
1309 $data =~ s/\t/$spaces/;
1312 $data = esc_html
($data);
1315 <tr class="$line_class[$line_class_num]">
1316 <td class="sha1"><a href="$my_uri?${\esc_param ("p=$project;a=commit;h=$long_rev")}" class="text">$short_rev..</a></td>
1317 <td class="$age_class">$age_str</td>
1319 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
1320 <td class="pre">$data</td>
1323 } # while (my $line = <$fd>)
1324 print "</table>\n\n";
1325 close $fd or print "Reading blob failed.\n";
1331 my $head = git_read_head
($project);
1333 print "<div class=\"page_nav\">\n" .
1334 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1335 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1336 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1337 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$head")}, "commit") .
1338 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1339 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1342 my $taglist = git_read_refs
("refs/tags");
1344 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary"), -class => "title"}, " ") .
1346 print "<table cellspacing=\"0\">\n";
1348 if (defined @
$taglist) {
1349 foreach my $entry (@
$taglist) {
1351 my $comment_lines = $tag{'comment'};
1352 my $comment = shift @
$comment_lines;
1353 if (defined($comment)) {
1354 $comment = chop_str
($comment, 30, 5);
1357 print "<tr class=\"dark\">\n";
1359 print "<tr class=\"light\">\n";
1362 print "<td><i>$tag{'age'}</i></td>\n" .
1364 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), -class => "list"},
1365 "<b>" . esc_html
($tag{'name'}) . "</b>") .
1368 if (defined($comment)) {
1369 print $cgi->a({-class => "list", -href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, $comment);
1372 "<td class=\"link\">";
1373 if ($tag{'type'} eq "tag") {
1374 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
1376 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1377 if ($tag{'reftype'} eq "commit") {
1378 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1379 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'refid'}")}, "log");
1390 my $head = git_read_head
($project);
1392 print "<div class=\"page_nav\">\n" .
1393 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1394 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1395 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1396 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$head")}, "commit") .
1397 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1398 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1401 my $taglist = git_read_refs
("refs/heads");
1403 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary"), -class => "title"}, " ") .
1405 print "<table cellspacing=\"0\">\n";
1407 if (defined @
$taglist) {
1408 foreach my $entry (@
$taglist) {
1411 print "<tr class=\"dark\">\n";
1413 print "<tr class=\"light\">\n";
1416 print "<td><i>$tag{'age'}</i></td>\n" .
1418 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}"), -class => "list"}, "<b>" . esc_html
($tag{'name'}) . "</b>") .
1420 "<td class=\"link\">" .
1421 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1422 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'name'}")}, "log") .
1431 sub git_get_hash_by_path
{
1433 my $path = shift || return undef;
1436 my @parts = split '/', $path;
1437 while (my $part = shift @parts) {
1438 open my $fd, "-|", "$gitbin/git-ls-tree $tree" or die_error
(undef, "Open git-ls-tree failed.");
1439 my (@entries) = map { chomp; $_ } <$fd>;
1440 close $fd or return undef;
1441 foreach my $line (@entries) {
1442 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1443 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1447 my $t_name = validate_input
(unquote
($4));
1448 if ($t_name eq $part) {
1452 if ($t_type eq "tree") {
1461 sub mimetype_guess_file
{
1462 my $filename = shift;
1463 my $mimemap = shift;
1464 -r
$mimemap or return undef;
1467 open(MIME
, $mimemap) or return undef;
1469 my ($mime, $exts) = split(/\t+/);
1470 my @exts = split(/\s+/, $exts);
1471 foreach my $ext (@exts) {
1472 $mimemap{$ext} = $mime;
1477 $filename =~ /\.(.*?)$/;
1478 return $mimemap{$1};
1481 sub mimetype_guess
{
1482 my $filename = shift;
1484 $filename =~ /\./ or return undef;
1486 if ($mimetypes_file) {
1487 my $file = $mimetypes_file;
1488 #$file =~ m#^/# or $file = "$projectroot/$path/$file";
1489 $mime = mimetype_guess_file
($filename, $file);
1491 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1495 sub git_blob_plain_mimetype
{
1497 my $filename = shift;
1500 my $mime = mimetype_guess
($filename);
1501 $mime and return $mime;
1505 return $default_blob_plain_mimetype unless $fd;
1508 return 'text/plain' .
1509 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
1510 } elsif (! $filename) {
1511 return 'application/octet-stream';
1512 } elsif ($filename =~ m/\.png$/i) {
1514 } elsif ($filename =~ m/\.gif$/i) {
1516 } elsif ($filename =~ m/\.jpe?g$/i) {
1517 return 'image/jpeg';
1519 return 'application/octet-stream';
1523 sub git_blob_plain
{
1525 open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or die_error
("Couldn't cat $file_name, $hash");
1527 $type ||= git_blob_plain_mimetype
($fd, $file_name);
1529 # save as filename, even when no $file_name is given
1530 my $save_as = "$hash";
1531 if (defined $file_name) {
1532 $save_as = $file_name;
1533 } elsif ($type =~ m/^text\//) {
1537 print $cgi->header(-type
=> "$type", '-content-disposition' => "inline; filename=\"$save_as\"");
1539 binmode STDOUT
, ':raw';
1541 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
1547 if (!defined $hash && defined $file_name) {
1548 my $base = $hash_base || git_read_head
($project);
1549 $hash = git_get_hash_by_path
($base, $file_name, "blob") || die_error
(undef, "Error lookup file.");
1551 my $have_blame = git_get_project_config_bool
('blame');
1552 open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or die_error
(undef, "Open failed.");
1553 my $mimetype = git_blob_plain_mimetype
($fd, $file_name);
1554 if ($mimetype !~ m/^text\//) {
1556 return git_blob_plain
($mimetype);
1559 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
1560 print "<div class=\"page_nav\">\n" .
1561 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1562 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1563 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1564 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base")}, "commit") .
1565 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1566 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") . "<br/>\n";
1567 if (defined $file_name) {
1569 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;h=$hash;hb=$hash_base;f=$file_name")}, "blame") . " | ";
1571 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$hash;f=$file_name")}, "plain") .
1572 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;hb=HEAD;f=$file_name")}, "head") . "<br/>\n";
1574 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$hash")}, "plain") . "<br/>\n";
1578 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html
($co{'title'})) .
1581 print "<div class=\"page_nav\">\n" .
1582 "<br/><br/></div>\n" .
1583 "<div class=\"title\">$hash</div>\n";
1585 if (defined $file_name) {
1586 print "<div class=\"page_path\"><b>" . esc_html
($file_name) . "</b></div>\n";
1588 print "<div class=\"page_body\">\n";
1590 while (my $line = <$fd>) {
1593 while ((my $pos = index($line, "\t")) != -1) {
1594 if (my $count = (8 - ($pos % 8))) {
1595 my $spaces = ' ' x
$count;
1596 $line =~ s/\t/$spaces/;
1599 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", $nr, $nr, $nr, esc_html
($line);
1601 close $fd or print "Reading blob failed.\n";
1607 if (!defined $hash) {
1608 $hash = git_read_head
($project);
1609 if (defined $file_name) {
1610 my $base = $hash_base || $hash;
1611 $hash = git_get_hash_by_path
($base, $file_name, "tree");
1613 if (!defined $hash_base) {
1618 open my $fd, "-|", "$gitbin/git-ls-tree -z $hash" or die_error
(undef, "Open git-ls-tree failed.");
1619 chomp (my (@entries) = <$fd>);
1620 close $fd or die_error
(undef, "Reading tree failed.");
1623 my $refs = read_info_ref
();
1625 if (defined $refs->{$hash_base}) {
1626 $ref = " <span class=\"tag\">" . esc_html
($refs->{$hash_base}) . "</span>";
1631 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
1632 $base_key = ";hb=$hash_base";
1633 print "<div class=\"page_nav\">\n" .
1634 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1635 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash_base")}, "shortlog") .
1636 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash_base")}, "log") .
1637 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base")}, "commit") .
1638 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1643 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html
($co{'title'}) . $ref) . "\n" .
1646 print "<div class=\"page_nav\">\n";
1647 print "<br/><br/></div>\n";
1648 print "<div class=\"title\">$hash</div>\n";
1650 if (defined $file_name) {
1651 $base = esc_html
("$file_name/");
1652 print "<div class=\"page_path\"><b>/" . esc_html
($file_name) . "</b></div>\n";
1654 print "<div class=\"page_path\"><b>/</b></div>\n";
1656 print "<div class=\"page_body\">\n";
1657 print "<table cellspacing=\"0\">\n";
1659 foreach my $line (@entries) {
1660 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1661 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1665 my $t_name = validate_input
($4);
1667 print "<tr class=\"dark\">\n";
1669 print "<tr class=\"light\">\n";
1672 print "<td class=\"mode\">" . mode_str
($t_mode) . "</td>\n";
1673 if ($t_type eq "blob") {
1674 print "<td class=\"list\">" .
1675 $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)) .
1677 "<td class=\"link\">" .
1678 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name")}, "blob") .
1679 # " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$t_hash$base_key;f=$base$t_name")}, "blame") .
1680 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;h=$hash_base;f=$base$t_name")}, "history") .
1681 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$t_hash;f=$base$t_name")}, "raw") .
1683 } elsif ($t_type eq "tree") {
1684 print "<td class=\"list\">" .
1685 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, esc_html
($t_name)) .
1687 "<td class=\"link\">" .
1688 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, "tree") .
1689 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;h=$hash_base;f=$base$t_name")}, "history") .
1694 print "</table>\n" .
1700 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
1701 open my $fd, "-|", "$gitbin/git-rev-list --max-count=150 " . git_read_head
($project) or die_error
(undef, "Open failed.");
1702 my (@revlist) = map { chomp; $_ } <$fd>;
1703 close $fd or die_error
(undef, "Reading rev-list failed.");
1704 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
1705 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1706 "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
1707 print "<channel>\n";
1708 print "<title>$project</title>\n".
1709 "<link>" . esc_html
("$my_url?p=$project;a=summary") . "</link>\n".
1710 "<description>$project log</description>\n".
1711 "<language>en</language>\n";
1713 for (my $i = 0; $i <= $#revlist; $i++) {
1714 my $commit = $revlist[$i];
1715 my %co = git_read_commit
($commit);
1716 # we read 150, we always show 30 and the ones more recent than 48 hours
1717 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
1720 my %cd = date_str
($co{'committer_epoch'});
1721 open $fd, "-|", "$gitbin/git-diff-tree -r $co{'parent'} $co{'id'}" or next;
1722 my @difftree = map { chomp; $_ } <$fd>;
1726 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
1728 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
1729 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
1730 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
1731 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
1732 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
1733 "<content:encoded>" .
1735 my $comment = $co{'comment'};
1736 foreach my $line (@
$comment) {
1737 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
1738 print "$line<br/>\n";
1741 foreach my $line (@difftree) {
1742 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
1745 my $file = validate_input
(unquote
($7));
1746 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
1747 print "$file<br/>\n";
1750 "</content:encoded>\n" .
1753 print "</channel></rss>";
1757 my @list = git_read_projects
();
1759 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
1760 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1761 "<opml version=\"1.0\">\n".
1763 " <title>Git OPML Export</title>\n".
1766 "<outline text=\"git RSS feeds\">\n";
1768 foreach my $pr (@list) {
1770 my $head = git_read_head
($proj{'path'});
1771 if (!defined $head) {
1774 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
1775 my %co = git_read_commit
($head);
1780 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
1781 my $rss = "$my_url?p=$proj{'path'};a=rss";
1782 my $html = "$my_url?p=$proj{'path'};a=summary";
1783 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
1785 print "</outline>\n".
1791 my $head = git_read_head
($project);
1792 if (!defined $hash) {
1795 if (!defined $page) {
1798 my $refs = read_info_ref
();
1800 print "<div class=\"page_nav\">\n";
1801 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1802 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash")}, "shortlog") .
1804 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash")}, "commit") .
1805 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
1806 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$hash;hb=$hash")}, "tree") . "<br/>\n";
1808 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
1809 open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error
(undef, "Open failed.");
1810 my (@revlist) = map { chomp; $_ } <$fd>;
1813 if ($hash ne $head || $page) {
1814 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "HEAD");
1820 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash;pg=" . ($page-1)), -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1822 print " ⋅ prev";
1824 if ($#revlist >= (100 * ($page+1)-1)) {
1826 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash;pg=" . ($page+1)), -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1828 print " ⋅ next";
1834 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary"), -class => "title"}, " ") .
1836 my %co = git_read_commit
($hash);
1837 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
1839 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
1840 my $commit = $revlist[$i];
1842 if (defined $refs->{$commit}) {
1843 $ref = " <span class=\"tag\">" . esc_html
($refs->{$commit}) . "</span>";
1845 my %co = git_read_commit
($commit);
1847 my %ad = date_str
($co{'author_epoch'});
1849 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "title"},
1850 "<span class=\"age\">$co{'age_string'}</span>" . esc_html
($co{'title'}) . $ref) . "\n";
1852 print "<div class=\"title_text\">\n" .
1853 "<div class=\"log_link\">\n" .
1854 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
1855 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1858 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
1860 "<div class=\"log_body\">\n";
1861 my $comment = $co{'comment'};
1863 foreach my $line (@
$comment) {
1864 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1875 print format_log_line_html
($line) . "<br/>\n";
1886 my %co = git_read_commit
($hash);
1888 die_error
(undef, "Unknown commit object.");
1890 my %ad = date_str
($co{'author_epoch'}, $co{'author_tz'});
1891 my %cd = date_str
($co{'committer_epoch'}, $co{'committer_tz'});
1895 my $parent = $co{'parent'};
1896 if (!defined $parent) {
1900 open my $fd, "-|", "$gitbin/git-diff-tree -r -M $root $parent $hash" or die_error
(undef, "Open failed.");
1901 @difftree = map { chomp; $_ } <$fd>;
1902 close $fd or die_error
(undef, "Reading diff-tree failed.");
1904 # non-textual hash id's can be cached
1906 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
1909 my $refs = read_info_ref
();
1911 if (defined $refs->{$co{'id'}}) {
1912 $ref = " <span class=\"tag\">" . esc_html
($refs->{$co{'id'}}) . "</span>";
1914 git_header_html
(undef, $expires);
1915 print "<div class=\"page_nav\">\n" .
1916 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1917 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash")}, "shortlog") .
1918 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash")}, "log") .
1920 if (defined $co{'parent'}) {
1921 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash")}, "commitdiff");
1923 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") . "\n" .
1924 "<br/><br/></div>\n";
1925 if (defined $co{'parent'}) {
1927 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash"), -class => "title"}, esc_html
($co{'title'}) . $ref) . "\n" .
1931 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash"), -class => "title"}, esc_html
($co{'title'})) . "\n" .
1934 print "<div class=\"title_text\">\n" .
1935 "<table cellspacing=\"0\">\n";
1936 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
1938 "<td></td><td> $ad{'rfc2822'}";
1939 if ($ad{'hour_local'} < 6) {
1940 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1942 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1946 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
1947 print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
1948 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
1951 "<td class=\"sha1\">" .
1952 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash"), class => "list"}, $co{'tree'}) .
1954 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
1957 my $parents = $co{'parents'};
1958 foreach my $par (@
$parents) {
1961 "<td class=\"sha1\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$par"), class => "list"}, $par) . "</td>" .
1962 "<td class=\"link\">" .
1963 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$par")}, "commit") .
1964 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash;hp=$par")}, "commitdiff") .
1970 print "<div class=\"page_body\">\n";
1971 my $comment = $co{'comment'};
1974 foreach my $line (@
$comment) {
1975 # print only one empty line
1977 if ($empty || $signed) {
1984 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1986 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1989 print format_log_line_html
($line) . "<br/>\n";
1993 print "<div class=\"list_head\">\n";
1994 if ($#difftree > 10) {
1995 print(($#difftree + 1) . " files changed:\n");
1998 print "<table class=\"diff_tree\">\n";
2000 foreach my $line (@difftree) {
2001 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2002 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2003 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
2011 my $similarity = $6;
2012 my $file = validate_input
(unquote
($7));
2014 print "<tr class=\"dark\">\n";
2016 print "<tr class=\"light\">\n";
2019 if ($status eq "A") {
2021 if (S_ISREG
(oct $to_mode)) {
2022 $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
2025 $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" .
2026 "<td><span class=\"file_status new\">[new " . file_type
($to_mode) . "$mode_chng]</span></td>\n" .
2027 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob") . "</td>\n";
2028 } elsif ($status eq "D") {
2030 $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" .
2031 "<td><span class=\"file_status deleted\">[deleted " . file_type
($from_mode). "]</span></td>\n" .
2032 "<td class=\"link\">" .
2033 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, "blob") .
2034 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;h=$hash;f=$file")}, "history") .
2036 } elsif ($status eq "M" || $status eq "T") {
2037 my $mode_chnge = "";
2038 if ($from_mode != $to_mode) {
2039 $mode_chnge = " <span class=\"file_status mode_chnge\">[changed";
2040 if (((oct $from_mode) & S_IFMT
) != ((oct $to_mode) & S_IFMT
)) {
2041 $mode_chnge .= " from " . file_type
($from_mode) . " to " . file_type
($to_mode);
2043 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
2044 if (S_ISREG
($from_mode) && S_ISREG
($to_mode)) {
2045 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
2046 } elsif (S_ISREG
($to_mode)) {
2047 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
2050 $mode_chnge .= "]</span>\n";
2053 if ($to_id ne $from_id) {
2054 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));
2056 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file"), -class => "list"}, esc_html
($file));
2059 "<td>$mode_chnge</td>\n" .
2060 "<td class=\"link\">";
2061 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob");
2062 if ($to_id ne $from_id) {
2063 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file")}, "diff");
2065 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;h=$hash;f=$file")}, "history") . "\n";
2067 } elsif ($status eq "R") {
2068 my ($from_file, $to_file) = split "\t", $file;
2070 if ($from_mode != $to_mode) {
2071 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
2074 $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" .
2075 "<td><span class=\"file_status moved\">[moved from " .
2076 $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)) .
2077 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
2078 "<td class=\"link\">" .
2079 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file")}, "blob");
2080 if ($to_id ne $from_id) {
2081 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file")}, "diff");
2092 mkdir($git_temp, 0700);
2094 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
2095 print "<div class=\"page_nav\">\n" .
2096 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
2097 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
2098 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
2099 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base")}, "commit") .
2100 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
2101 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") .
2103 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff_plain;h=$hash;hp=$hash_parent")}, "plain") .
2106 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html
($co{'title'})) . "\n" .
2109 print "<div class=\"page_nav\">\n" .
2110 "<br/><br/></div>\n" .
2111 "<div class=\"title\">$hash vs $hash_parent</div>\n";
2113 if (defined $file_name) {
2114 print "<div class=\"page_path\"><b>/" . esc_html
($file_name) . "</b></div>\n";
2116 print "<div class=\"page_body\">\n" .
2117 "<div class=\"diff_info\">blob:" .
2118 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name")}, $hash_parent) .
2120 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, $hash) .
2122 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
2127 sub git_blobdiff_plain
{
2128 mkdir($git_temp, 0700);
2129 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8');
2130 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
2133 sub git_commitdiff
{
2134 mkdir($git_temp, 0700);
2135 my %co = git_read_commit
($hash);
2137 die_error
(undef, "Unknown commit object.");
2139 if (!defined $hash_parent) {
2140 $hash_parent = $co{'parent'};
2142 open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error
(undef, "Open failed.");
2143 my (@difftree) = map { chomp; $_ } <$fd>;
2144 close $fd or die_error
(undef, "Reading diff-tree failed.");
2146 # non-textual hash id's can be cached
2148 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2151 my $refs = read_info_ref
();
2153 if (defined $refs->{$co{'id'}}) {
2154 $ref = " <span class=\"tag\">" . esc_html
($refs->{$co{'id'}}) . "</span>";
2156 git_header_html
(undef, $expires);
2157 print "<div class=\"page_nav\">\n" .
2158 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
2159 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash")}, "shortlog") .
2160 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash")}, "log") .
2161 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash")}, "commit") .
2163 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") . "<br/>\n";
2164 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent")}, "plain") . "\n" .
2167 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html
($co{'title'}) . $ref) . "\n" .
2169 print "<div class=\"page_body\">\n";
2170 my $comment = $co{'comment'};
2173 my @log = @
$comment;
2174 # remove first and empty lines after that
2176 while (defined $log[0] && $log[0] eq "") {
2179 foreach my $line (@log) {
2180 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2191 print format_log_line_html
($line) . "<br/>\n";
2194 foreach my $line (@difftree) {
2195 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2196 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2197 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2203 my $file = validate_input
(unquote
($6));
2204 if ($status eq "A") {
2205 print "<div class=\"diff_info\">" . file_type
($to_mode) . ":" .
2206 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id) . "(new)" .
2208 git_diff_print
(undef, "/dev/null", $to_id, "b/$file");
2209 } elsif ($status eq "D") {
2210 print "<div class=\"diff_info\">" . file_type
($from_mode) . ":" .
2211 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) . "(deleted)" .
2213 git_diff_print
($from_id, "a/$file", undef, "/dev/null");
2214 } elsif ($status eq "M") {
2215 if ($from_id ne $to_id) {
2216 print "<div class=\"diff_info\">" .
2217 file_type
($from_mode) . ":" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) .
2219 file_type
($to_mode) . ":" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id);
2221 git_diff_print
($from_id, "a/$file", $to_id, "b/$file");
2230 sub git_commitdiff_plain
{
2231 mkdir($git_temp, 0700);
2232 open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error
(undef, "Open failed.");
2233 my (@difftree) = map { chomp; $_ } <$fd>;
2234 close $fd or die_error
(undef, "Reading diff-tree failed.");
2236 # try to figure out the next tag after this commit
2238 my $refs = read_info_ref
("tags");
2239 open $fd, "-|", "$gitbin/git-rev-list HEAD";
2240 chomp (my (@commits) = <$fd>);
2242 foreach my $commit (@commits) {
2243 if (defined $refs->{$commit}) {
2244 $tagname = $refs->{$commit}
2246 if ($commit eq $hash) {
2251 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8', '-content-disposition' => "inline; filename=\"git-$hash.patch\"");
2252 my %co = git_read_commit
($hash);
2253 my %ad = date_str
($co{'author_epoch'}, $co{'author_tz'});
2254 my $comment = $co{'comment'};
2255 print "From: $co{'author'}\n" .
2256 "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
2257 "Subject: $co{'title'}\n";
2258 if (defined $tagname) {
2259 print "X-Git-Tag: $tagname\n";
2261 print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
2264 foreach my $line (@
$comment) {;
2269 foreach my $line (@difftree) {
2270 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2275 if ($status eq "A") {
2276 git_diff_print
(undef, "/dev/null", $to_id, "b/$file", "plain");
2277 } elsif ($status eq "D") {
2278 git_diff_print
($from_id, "a/$file", undef, "/dev/null", "plain");
2279 } elsif ($status eq "M") {
2280 git_diff_print
($from_id, "a/$file", $to_id, "b/$file", "plain");
2286 if (!defined $hash) {
2287 $hash = git_read_head
($project);
2289 my %co = git_read_commit
($hash);
2291 die_error
(undef, "Unknown commit object.");
2293 my $refs = read_info_ref
();
2295 print "<div class=\"page_nav\">\n" .
2296 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
2297 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
2298 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
2299 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash")}, "commit") .
2300 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2301 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
2305 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html
($co{'title'})) . "\n" .
2307 print "<div class=\"page_path\"><b>/" . esc_html
($file_name) . "</b><br/></div>\n";
2310 "$gitbin/git-rev-list --full-history $hash -- \'$file_name\'";
2311 print "<table cellspacing=\"0\">\n";
2313 while (my $line = <$fd>) {
2314 if ($line =~ m/^([0-9a-fA-F]{40})/){
2316 my %co = git_read_commit
($commit);
2321 if (defined $refs->{$commit}) {
2322 $ref = " <span class=\"tag\">" . esc_html
($refs->{$commit}) . "</span>";
2325 print "<tr class=\"dark\">\n";
2327 print "<tr class=\"light\">\n";
2330 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2331 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2332 "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list"}, "<b>" .
2333 esc_html
(chop_str
($co{'title'}, 50)) . "$ref</b>") . "</td>\n" .
2334 "<td class=\"link\">" .
2335 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
2336 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2337 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;hb=$commit;f=$file_name")}, "blob");
2338 my $blob = git_get_hash_by_path
($hash, $file_name);
2339 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2340 if (defined $blob && defined $blob_parent && $blob ne $blob_parent) {
2342 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=$file_name")},
2355 if (!defined $searchtext) {
2356 die_error
("", "Text field empty.");
2358 if (!defined $hash) {
2359 $hash = git_read_head
($project);
2361 my %co = git_read_commit
($hash);
2363 die_error
(undef, "Unknown commit object.");
2365 # pickaxe may take all resources of your box and run for several minutes
2366 # with every query - so decide by yourself how public you make this feature :)
2367 my $commit_search = 1;
2368 my $author_search = 0;
2369 my $committer_search = 0;
2370 my $pickaxe_search = 0;
2371 if ($searchtext =~ s/^author\\://i) {
2373 } elsif ($searchtext =~ s/^committer\\://i) {
2374 $committer_search = 1;
2375 } elsif ($searchtext =~ s/^pickaxe\\://i) {
2377 $pickaxe_search = 1;
2380 print "<div class=\"page_nav\">\n" .
2381 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary;h=$hash")}, "summary") .
2382 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
2383 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash")}, "log") .
2384 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash")}, "commit") .
2385 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2386 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
2391 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html
($co{'title'})) . "\n" .
2393 print "<table cellspacing=\"0\">\n";
2395 if ($commit_search) {
2397 open my $fd, "-|", "$gitbin/git-rev-list --header --parents $hash" or next;
2398 while (my $commit_text = <$fd>) {
2399 if (!grep m/$searchtext/i, $commit_text) {
2402 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
2405 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
2408 my @commit_lines = split "\n", $commit_text;
2409 my %co = git_read_commit
(undef, \
@commit_lines);
2414 print "<tr class=\"dark\">\n";
2416 print "<tr class=\"light\">\n";
2419 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2420 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2422 $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/>");
2423 my $comment = $co{'comment'};
2424 foreach my $line (@
$comment) {
2425 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2426 my $lead = esc_html
($1) || "";
2427 $lead = chop_str
($lead, 30, 10);
2428 my $match = esc_html
($2) || "";
2429 my $trail = esc_html
($3) || "";
2430 $trail = chop_str
($trail, 30, 10);
2431 my $text = "$lead<span class=\"match\">$match</span>$trail";
2432 print chop_str
($text, 80, 5) . "<br/>\n";
2436 "<td class=\"link\">" .
2437 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2438 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2445 if ($pickaxe_search) {
2447 open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin -S\'$searchtext\'";
2450 while (my $line = <$fd>) {
2451 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2454 $set{'from_id'} = $3;
2456 $set{'id'} = $set{'to_id'};
2457 if ($set{'id'} =~ m/0{40}/) {
2458 $set{'id'} = $set{'from_id'};
2460 if ($set{'id'} =~ m/0{40}/) {
2464 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
2467 print "<tr class=\"dark\">\n";
2469 print "<tr class=\"light\">\n";
2472 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2473 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2475 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" .
2476 esc_html
(chop_str
($co{'title'}, 50)) . "</b><br/>");
2477 while (my $setref = shift @files) {
2479 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}"), class => "list"},
2480 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
2484 "<td class=\"link\">" .
2485 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2486 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2490 %co = git_read_commit
($1);
2500 my $head = git_read_head
($project);
2501 if (!defined $hash) {
2504 if (!defined $page) {
2507 my $refs = read_info_ref
();
2509 print "<div class=\"page_nav\">\n" .
2510 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
2512 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash")}, "log") .
2513 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash")}, "commit") .
2514 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2515 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$hash;hb=$hash")}, "tree") . "<br/>\n";
2517 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2518 open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error
(undef, "Open failed.");
2519 my (@revlist) = map { chomp; $_ } <$fd>;
2522 if ($hash ne $head || $page) {
2523 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "HEAD");
2529 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash;pg=" . ($page-1)), -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2531 print " ⋅ prev";
2533 if ($#revlist >= (100 * ($page+1)-1)) {
2535 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)), -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2537 print " ⋅ next";
2542 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary"), -class => "title"}, " ") .
2544 print "<table cellspacing=\"0\">\n";
2546 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2547 my $commit = $revlist[$i];
2549 if (defined $refs->{$commit}) {
2550 $ref = " <span class=\"tag\">" . esc_html
($refs->{$commit}) . "</span>";
2552 my %co = git_read_commit
($commit);
2553 my %ad = date_str
($co{'author_epoch'});
2555 print "<tr class=\"dark\">\n";
2557 print "<tr class=\"light\">\n";
2560 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2561 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
2563 if (length($co{'title_short'}) < length($co{'title'})) {
2564 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list", -title
=> "$co{'title'}"},
2565 "<b>" . esc_html
($co{'title_short'}) . "$ref</b>");
2567 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list"},
2568 "<b>" . esc_html
($co{'title_short'}) . "$ref</b>");
2571 "<td class=\"link\">" .
2572 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
2573 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2577 if ($#revlist >= (100 * ($page+1)-1)) {
2580 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)), -title
=> "Alt-n"}, "next") .