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 # core git executable to use
26 # this can just be "git" if your webserver has a sensible PATH
27 our $GIT = "/usr/bin/git";
29 # absolute fs-path which will be prepended to the project path
30 #our $projectroot = "/pub/scm";
31 our $projectroot = "/home/kay/public_html/pub/scm";
33 # version of the core git binary
34 our $git_version = qx($GIT --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
36 # location for temporary files needed for diffs
37 our $git_temp = "/tmp/gitweb";
39 mkdir($git_temp, 0700) || die_error
("Couldn't mkdir $git_temp");
42 # target of the home link on top of all pages
43 our $home_link = $my_uri;
45 # name of your site or organization to appear in page titles
46 # replace this with something more descriptive for clearer bookmarks
47 our $site_name = $ENV{'SERVER_NAME'} || "Untitled";
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);
253 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
257 # git may return quoted and escaped filenames
260 if ($str =~ m/^"(.*)"$/) {
262 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
267 # CSS class for given age value (in seconds)
271 if ($age < 60*60*2) {
273 } elsif ($age < 60*60*24*2) {
280 sub git_header_html
{
281 my $status = shift || "200 OK";
284 my $title = "$site_name git";
285 if (defined $project) {
286 $title .= " - $project";
287 if (defined $action) {
288 $title .= "/$action";
289 if (defined $file_name) {
290 $title .= " - $file_name";
291 if ($action eq "tree" && $file_name !~ m
|/$|) {
298 # require explicit support from the UA if we are to send the page as
299 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
300 # we have to do this because MSIE sometimes globs '*/*', pretending to
301 # support xhtml+xml but choking when it gets what it asked for.
302 if ($cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ && $cgi->Accept('application/xhtml
+xml
') != 0) {
303 $content_type = 'application
/xhtml
+xml
';
305 $content_type = 'text
/html
';
307 print $cgi->header(-type=>$content_type, -charset => 'utf
-8', -status=> $status, -expires => $expires);
309 <?xml version="1.0" encoding="utf-8"?>
310 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
311 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
312 <!-- git web interface v$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
313 <!-- git core binaries version $git_version -->
315 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
316 <meta name="robots" content="index, nofollow"/>
317 <title>$title</title>
318 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
323 print "<div class=\"page_header\">\n" .
324 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
325 "<img src=\"$my_uri?" . esc_param
("a=git-logo.png") . "\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
327 print $cgi->a({-href
=> esc_param
($home_link)}, "projects") . " / ";
328 if (defined $project) {
329 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, esc_html
($project));
330 if (defined $action) {
334 if (!defined $searchtext) {
338 if (defined $hash_base) {
339 $search_hash = $hash_base;
340 } elsif (defined $hash) {
341 $search_hash = $hash;
343 $search_hash = "HEAD";
345 $cgi->param("a", "search");
346 $cgi->param("h", $search_hash);
347 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
348 "<div class=\"search\">\n" .
349 $cgi->hidden(-name
=> "p") . "\n" .
350 $cgi->hidden(-name
=> "a") . "\n" .
351 $cgi->hidden(-name
=> "h") . "\n" .
352 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
354 $cgi->end_form() . "\n";
359 sub git_footer_html
{
360 print "<div class=\"page_footer\">\n";
361 if (defined $project) {
362 my $descr = git_read_description
($project);
363 if (defined $descr) {
364 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
366 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=rss"), -class => "rss_logo"}, "RSS") . "\n";
368 print $cgi->a({-href
=> "$my_uri?" . esc_param
("a=opml"), -class => "rss_logo"}, "OPML") . "\n";
376 my $status = shift || "403 Forbidden";
377 my $error = shift || "Malformed query, file missing or permission denied";
379 git_header_html
($status);
380 print "<div class=\"page_body\">\n" .
382 "$status - $error\n" .
390 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
391 $extra = '' if !defined $extra; # pager or formats
393 my @navs = qw(summary shortlog log commit commitdiff tree);
395 @navs = grep { $_ ne $suppress } @navs;
398 my %arg = map { $_, ''} @navs;
400 for (qw(commit commitdiff)) {
401 $arg{$_} = ";h=$head";
403 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
404 for (qw(shortlog log)) {
405 $arg{$_} = ";h=$head";
409 $arg{tree
} .= ";h=$treehead" if defined $treehead;
410 $arg{tree
} .= ";hb=$treebase" if defined $treebase;
412 print "<div class=\"page_nav\">\n" .
416 : $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$_$arg{$_}")}, "$_")
419 print "<br/>$extra<br/>\n" .
426 open my $fd, "-|", $GIT, "cat-file", '-t', $hash or return;
435 my $oENV = $ENV{'GIT_DIR'};
437 $ENV{'GIT_DIR'} = "$projectroot/$project";
438 if (open my $fd, "-|", $GIT, "rev-parse", "--verify", "HEAD") {
441 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
446 $ENV{'GIT_DIR'} = $oENV;
454 open my $fd, "$projectroot/$path" or return undef;
458 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
463 sub git_read_description
{
466 open my $fd, "$projectroot/$path/description" or return undef;
478 open my $fd, "-|", $GIT, "cat-file", "tag", $tag_id or return;
479 $tag{'id'} = $tag_id;
480 while (my $line = <$fd>) {
482 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
484 } elsif ($line =~ m/^type (.+)$/) {
486 } elsif ($line =~ m/^tag (.+)$/) {
488 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
492 } elsif ($line =~ m/--BEGIN/) {
493 push @comment, $line;
495 } elsif ($line eq "") {
499 push @comment, <$fd>;
500 $tag{'comment'} = \
@comment;
502 if (!defined $tag{'name'}) {
512 if ($age > 60*60*24*365*2) {
513 $age_str = (int $age/60/60/24/365);
514 $age_str .= " years ago";
515 } elsif ($age > 60*60*24*(365/12)*2) {
516 $age_str = int $age/60/60/24/(365/12);
517 $age_str .= " months ago";
518 } elsif ($age > 60*60*24*7*2) {
519 $age_str = int $age/60/60/24/7;
520 $age_str .= " weeks ago";
521 } elsif ($age > 60*60*24*2) {
522 $age_str = int $age/60/60/24;
523 $age_str .= " days ago";
524 } elsif ($age > 60*60*2) {
525 $age_str = int $age/60/60;
526 $age_str .= " hours ago";
527 } elsif ($age > 60*2) {
528 $age_str = int $age/60;
529 $age_str .= " min ago";
532 $age_str .= " sec ago";
534 $age_str .= " right now";
539 sub git_read_commit
{
540 my $commit_id = shift;
541 my $commit_text = shift;
546 if (defined $commit_text) {
547 @commit_lines = @
$commit_text;
550 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", "--max-count=1", $commit_id or return;
551 @commit_lines = split '\n', <$fd>;
556 my $header = shift @commit_lines;
557 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
560 ($co{'id'}, my @parents) = split ' ', $header;
561 $co{'parents'} = \
@parents;
562 $co{'parent'} = $parents[0];
563 while (my $line = shift @commit_lines) {
564 last if $line eq "\n";
565 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
567 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
569 $co{'author_epoch'} = $2;
570 $co{'author_tz'} = $3;
571 if ($co{'author'} =~ m/^([^<]+) </) {
572 $co{'author_name'} = $1;
574 $co{'author_name'} = $co{'author'};
576 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
577 $co{'committer'} = $1;
578 $co{'committer_epoch'} = $2;
579 $co{'committer_tz'} = $3;
580 $co{'committer_name'} = $co{'committer'};
581 $co{'committer_name'} =~ s/ <.*//;
584 if (!defined $co{'tree'}) {
588 foreach my $title (@commit_lines) {
591 $co{'title'} = chop_str
($title, 80, 5);
592 # remove leading stuff of merges to make the interesting part visible
593 if (length($title) > 50) {
594 $title =~ s/^Automatic //;
595 $title =~ s/^merge (of|with) /Merge ... /i;
596 if (length($title) > 50) {
597 $title =~ s/(http|rsync):\/\///;
599 if (length($title) > 50) {
600 $title =~ s/(master|www|rsync)\.//;
602 if (length($title) > 50) {
603 $title =~ s/kernel.org:?//;
605 if (length($title) > 50) {
606 $title =~ s/\/pub\/scm//;
609 $co{'title_short'} = chop_str
($title, 50, 5);
613 # remove added spaces
614 foreach my $line (@commit_lines) {
617 $co{'comment'} = \
@commit_lines;
619 my $age = time - $co{'committer_epoch'};
621 $co{'age_string'} = age_string
($age);
622 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
623 if ($age > 60*60*24*7*2) {
624 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
625 $co{'age_string_age'} = $co{'age_string'};
627 $co{'age_string_date'} = $co{'age_string'};
628 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
635 my $from_name = shift;
638 my $format = shift || "html";
640 my $from_tmp = "/dev/null";
641 my $to_tmp = "/dev/null";
644 # create tmp from-file
646 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
647 open my $fd2, "> $from_tmp";
648 open my $fd, "-|", $GIT, "cat-file", "blob", $from;
657 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
658 open my $fd2, "> $to_tmp";
659 open my $fd, "-|", $GIT, "cat-file", "blob", $to;
666 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
667 if ($format eq "plain") {
672 while (my $line = <$fd>) {
674 my $char = substr($line, 0, 1);
677 $diff_class = " add";
678 } elsif ($char eq "-") {
679 $diff_class = " rem";
680 } elsif ($char eq "@") {
681 $diff_class = " chunk_header";
682 } elsif ($char eq "\\") {
686 while ((my $pos = index($line, "\t")) != -1) {
687 if (my $count = (8 - (($pos-1) % 8))) {
688 my $spaces = ' ' x
$count;
689 $line =~ s/\t/$spaces/;
692 print "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
706 my $mode = oct shift;
708 if (S_ISDIR
($mode & S_IFMT
)) {
710 } elsif (S_ISLNK
($mode)) {
712 } elsif (S_ISREG
($mode)) {
713 # git cares only about the executable bit
714 if ($mode & S_IXUSR
) {
727 my $add_len = shift || 10;
729 # allow only $len chars, but don't cut a word if it would fit in $add_len
730 # if it doesn't fit, cut it if it's still longer than the dots we would add
731 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
734 if (length($tail) > 4) {
741 my $mode = oct shift;
743 if (S_ISDIR
($mode & S_IFMT
)) {
745 } elsif (S_ISLNK
($mode)) {
747 } elsif (S_ISREG
($mode)) {
754 sub format_log_line_html
{
757 $line = esc_html
($line);
758 $line =~ s/ / /g;
759 if ($line =~ m/([0-9a-fA-F]{40})/) {
761 if (git_get_type
($hash_text) eq "commit") {
762 my $link = $cgi->a({-class => "text", -href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_text")}, $hash_text);
763 $line =~ s/$hash_text/$link/;
771 my $tz = shift || "-0000";
774 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
775 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
776 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
777 $date{'hour'} = $hour;
778 $date{'minute'} = $min;
779 $date{'mday'} = $mday;
780 $date{'day'} = $days[$wday];
781 $date{'month'} = $months[$mon];
782 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
783 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
785 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
786 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
787 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
788 $date{'hour_local'} = $hour;
789 $date{'minute_local'} = $min;
790 $date{'tz_local'} = $tz;
794 # git-logo (cached in browser for one day)
796 binmode STDOUT
, ':raw';
797 print $cgi->header(-type
=> 'image/png', -expires
=> '+1d');
798 # cat git-logo.png | hexdump -e '16/1 " %02x" "\n"' | sed 's/ /\\x/g'
799 print "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52" .
800 "\x00\x00\x00\x48\x00\x00\x00\x1b\x04\x03\x00\x00\x00\x2d\xd9\xd4" .
801 "\x2d\x00\x00\x00\x18\x50\x4c\x54\x45\xff\xff\xff\x60\x60\x5d\xb0" .
802 "\xaf\xaa\x00\x80\x00\xce\xcd\xc7\xc0\x00\x00\xe8\xe8\xe6\xf7\xf7" .
803 "\xf6\x95\x0c\xa7\x47\x00\x00\x00\x73\x49\x44\x41\x54\x28\xcf\x63" .
804 "\x48\x67\x20\x04\x4a\x5c\x18\x0a\x08\x2a\x62\x53\x61\x20\x02\x08" .
805 "\x0d\x69\x45\xac\xa1\xa1\x01\x30\x0c\x93\x60\x36\x26\x52\x91\xb1" .
806 "\x01\x11\xd6\xe1\x55\x64\x6c\x6c\xcc\x6c\x6c\x0c\xa2\x0c\x70\x2a" .
807 "\x62\x06\x2a\xc1\x62\x1d\xb3\x01\x02\x53\xa4\x08\xe8\x00\x03\x18" .
808 "\x26\x56\x11\xd4\xe1\x20\x97\x1b\xe0\xb4\x0e\x35\x24\x71\x29\x82" .
809 "\x99\x30\xb8\x93\x0a\x11\xb9\x45\x88\xc1\x8d\xa0\xa2\x44\x21\x06" .
810 "\x27\x41\x82\x40\x85\xc1\x45\x89\x20\x70\x01\x00\xa4\x3d\x21\xc5" .
811 "\x12\x1c\x9a\xfe\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\x82";
817 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
818 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
819 if (!defined $gcos) {
823 $owner =~ s/[,;].*$//;
824 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
827 sub git_read_projects
{
830 if (-d
$projects_list) {
831 # search in directory
832 my $dir = $projects_list;
833 opendir my ($dh), $dir or return undef;
834 while (my $dir = readdir($dh)) {
835 if (-e
"$projectroot/$dir/HEAD") {
843 } elsif (-f
$projects_list) {
844 # read from file(url-encoded):
845 # 'git%2Fgit.git Linus+Torvalds'
846 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
847 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
848 open my ($fd), $projects_list or return undef;
849 while (my $line = <$fd>) {
851 my ($path, $owner) = split ' ', $line;
852 $path = unescape
($path);
853 $owner = unescape
($owner);
854 if (!defined $path) {
857 if (-e
"$projectroot/$path/HEAD") {
860 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
867 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
871 sub git_get_project_config
{
874 return unless ($key);
875 $key =~ s/^gitweb\.//;
876 return if ($key =~ m/\W/);
878 my $val = qx($GIT repo
-config
--get gitweb
.$key);
882 sub git_get_project_config_bool
{
883 my $val = git_get_project_config
(@_);
884 if ($val and $val =~ m/true|yes|on/) {
887 return; # implicit false
890 sub git_project_list
{
891 my @list = git_read_projects
();
894 die_error
(undef, "No project found.");
896 foreach my $pr (@list) {
897 my $head = git_read_head
($pr->{'path'});
898 if (!defined $head) {
901 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
902 my %co = git_read_commit
($head);
906 $pr->{'commit'} = \
%co;
907 if (!defined $pr->{'descr'}) {
908 my $descr = git_read_description
($pr->{'path'}) || "";
909 $pr->{'descr'} = chop_str
($descr, 25, 5);
911 if (!defined $pr->{'owner'}) {
912 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
918 print "<div class=\"index_include\">\n";
919 open (my $fd, $home_text);
924 print "<table class=\"project_list\">\n" .
926 if (!defined($order) || (defined($order) && ($order eq "project"))) {
927 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
928 print "<th>Project</th>\n";
930 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=project")}, "Project") . "</th>\n";
932 if (defined($order) && ($order eq "descr")) {
933 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
934 print "<th>Description</th>\n";
936 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=descr")}, "Description") . "</th>\n";
938 if (defined($order) && ($order eq "owner")) {
939 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
940 print "<th>Owner</th>\n";
942 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=owner")}, "Owner") . "</th>\n";
944 if (defined($order) && ($order eq "age")) {
945 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
946 print "<th>Last Change</th>\n";
948 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=age")}, "Last Change") . "</th>\n";
950 print "<th></th>\n" .
953 foreach my $pr (@projects) {
955 print "<tr class=\"dark\">\n";
957 print "<tr class=\"light\">\n";
960 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=summary"), -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
961 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
962 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
963 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" . $pr->{'commit'}{'age_string'} . "</td>\n" .
964 "<td class=\"link\">" .
965 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=summary")}, "summary") .
966 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=shortlog")}, "shortlog") .
967 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=log")}, "log") .
976 my $type = shift || "";
978 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
979 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
980 open my $fd, "$projectroot/$project/info/refs" or return;
981 while (my $line = <$fd>) {
983 if ($line =~ m/^([0-9a-fA-F]{40})\t.*$type\/([^\
^]+)/) {
984 if (defined $refs{$1}) {
985 $refs{$1} .= " / $2";
1000 opendir my $dh, "$projectroot/$project/$ref_dir";
1001 while (my $dir = readdir($dh)) {
1002 if ($dir =~ m/^\./) {
1005 if (-d
"$projectroot/$project/$ref_dir/$dir") {
1006 opendir my $dh2, "$projectroot/$project/$ref_dir/$dir";
1007 my @subdirs = grep !m/^\./, readdir $dh2;
1009 foreach my $subdir (@subdirs) {
1010 push @refs, "$dir/$subdir"
1017 foreach my $ref_file (@refs) {
1018 my $ref_id = git_read_hash
("$project/$ref_dir/$ref_file");
1019 my $type = git_get_type
($ref_id) || next;
1022 $ref_item{'type'} = $type;
1023 $ref_item{'id'} = $ref_id;
1024 $ref_item{'epoch'} = 0;
1025 $ref_item{'age'} = "unknown";
1026 if ($type eq "tag") {
1027 my %tag = git_read_tag
($ref_id);
1028 $ref_item{'comment'} = $tag{'comment'};
1029 if ($tag{'type'} eq "commit") {
1030 %co = git_read_commit
($tag{'object'});
1031 $ref_item{'epoch'} = $co{'committer_epoch'};
1032 $ref_item{'age'} = $co{'age_string'};
1033 } elsif (defined($tag{'epoch'})) {
1034 my $age = time - $tag{'epoch'};
1035 $ref_item{'epoch'} = $tag{'epoch'};
1036 $ref_item{'age'} = age_string
($age);
1038 $ref_item{'reftype'} = $tag{'type'};
1039 $ref_item{'name'} = $tag{'name'};
1040 $ref_item{'refid'} = $tag{'object'};
1041 } elsif ($type eq "commit"){
1042 %co = git_read_commit
($ref_id);
1043 $ref_item{'reftype'} = "commit";
1044 $ref_item{'name'} = $ref_file;
1045 $ref_item{'title'} = $co{'title'};
1046 $ref_item{'refid'} = $ref_id;
1047 $ref_item{'epoch'} = $co{'committer_epoch'};
1048 $ref_item{'age'} = $co{'age_string'};
1051 push @reflist, \
%ref_item;
1054 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1059 my $descr = git_read_description
($project) || "none";
1060 my $head = git_read_head
($project);
1061 my %co = git_read_commit
($head);
1062 my %cd = date_str
($co{'committer_epoch'}, $co{'committer_tz'});
1065 if (-f
$projects_list) {
1066 open (my $fd , $projects_list);
1067 while (my $line = <$fd>) {
1069 my ($pr, $ow) = split ' ', $line;
1070 $pr = unescape
($pr);
1071 $ow = unescape
($ow);
1072 if ($pr eq $project) {
1073 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
1079 if (!defined $owner) {
1080 $owner = get_file_owner
("$projectroot/$project");
1083 my $refs = read_info_ref
();
1085 git_page_nav
('summary','', $head);
1086 print "<div class=\"title\"> </div>\n";
1087 print "<table cellspacing=\"0\">\n" .
1088 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
1089 "<tr><td>owner</td><td>$owner</td></tr>\n" .
1090 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
1092 open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_read_head
($project)
1093 or die_error
(undef, "Open git-rev-list failed.");
1094 my @revlist = map { chomp; $_ } <$fd>;
1097 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog"), -class => "title"}, "shortlog") .
1100 print "<table cellspacing=\"0\">\n";
1102 foreach my $commit (@revlist) {
1103 my %co = git_read_commit
($commit);
1104 my %ad = date_str
($co{'author_epoch'});
1106 print "<tr class=\"dark\">\n";
1108 print "<tr class=\"light\">\n";
1113 if (defined $refs->{$commit}) {
1114 $ref = " <span class=\"tag\">" . esc_html
($refs->{$commit}) . "</span>";
1116 print "<td><i>$co{'age_string'}</i></td>\n" .
1117 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
1119 if (length($co{'title_short'}) < length($co{'title'})) {
1120 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list", -title
=> "$co{'title'}"},
1121 "<b>" . esc_html
($co{'title_short'}) . "$ref</b>");
1123 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list"},
1124 "<b>" . esc_html
($co{'title'}) . "$ref</b>");
1127 "<td class=\"link\">" .
1128 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
1129 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1133 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "...") . "</td>\n" .
1140 my $taglist = git_read_refs
("refs/tags");
1141 if (defined @
$taglist) {
1143 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tags"), -class => "title"}, "tags") .
1146 print "<table cellspacing=\"0\">\n";
1148 foreach my $entry (@
$taglist) {
1150 my $comment_lines = $tag{'comment'};
1151 my $comment = shift @
$comment_lines;
1152 if (defined($comment)) {
1153 $comment = chop_str
($comment, 30, 5);
1156 print "<tr class=\"dark\">\n";
1158 print "<tr class=\"light\">\n";
1162 print "<td><i>$tag{'age'}</i></td>\n" .
1164 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), -class => "list"},
1165 "<b>" . esc_html
($tag{'name'}) . "</b>") .
1168 if (defined($comment)) {
1169 print $cgi->a({-class => "list", -href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, esc_html
($comment));
1172 "<td class=\"link\">";
1173 if ($tag{'type'} eq "tag") {
1174 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
1176 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1177 if ($tag{'reftype'} eq "commit") {
1178 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1179 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'refid'}")}, "log");
1184 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tags")}, "...") . "</td>\n" .
1192 my $headlist = git_read_refs
("refs/heads");
1193 if (defined @
$headlist) {
1195 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=heads"), -class => "title"}, "heads") .
1198 print "<table cellspacing=\"0\">\n";
1200 foreach my $entry (@
$headlist) {
1203 print "<tr class=\"dark\">\n";
1205 print "<tr class=\"light\">\n";
1209 print "<td><i>$tag{'age'}</i></td>\n" .
1211 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}"), -class => "list"},
1212 "<b>" . esc_html
($tag{'name'}) . "</b>") .
1214 "<td class=\"link\">" .
1215 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1216 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'name'}")}, "log") .
1220 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=heads")}, "...") . "</td>\n" .
1230 sub git_print_page_path
{
1234 if (!defined $name) {
1235 print "<div class=\"page_path\"><b>/</b></div>\n";
1236 } elsif ($type =~ "blob") {
1237 print "<div class=\"page_path\"><b>" .
1238 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;f=$file_name")}, esc_html
($name)) . "</b><br/></div>\n";
1240 print "<div class=\"page_path\"><b>" . esc_html
($name) . "</b><br/></div>\n";
1245 my $head = git_read_head
($project);
1247 git_page_nav
('','', $head,undef,$head);
1248 my %tag = git_read_tag
($hash);
1250 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html
($tag{'name'})) . "\n" .
1252 print "<div class=\"title_text\">\n" .
1253 "<table cellspacing=\"0\">\n" .
1255 "<td>object</td>\n" .
1256 "<td>" . $cgi->a({-class => "list", -href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'object'}) . "</td>\n" .
1257 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'type'}) . "</td>\n" .
1259 if (defined($tag{'author'})) {
1260 my %ad = date_str
($tag{'epoch'}, $tag{'tz'});
1261 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
1262 print "<tr><td></td><td>" . $ad{'rfc2822'} . sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) . "</td></tr>\n";
1264 print "</table>\n\n" .
1266 print "<div class=\"page_body\">";
1267 my $comment = $tag{'comment'};
1268 foreach my $line (@
$comment) {
1269 print esc_html
($line) . "<br/>\n";
1278 die_error
(undef, "Permission denied.") if (!git_get_project_config_bool
('blame'));
1279 die_error
('404 Not Found', "File name not defined") if (!$file_name);
1280 $hash_base ||= git_read_head
($project);
1281 die_error
(undef, "Reading commit failed") unless ($hash_base);
1282 my %co = git_read_commit
($hash_base)
1283 or die_error
(undef, "Reading commit failed");
1284 if (!defined $hash) {
1285 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
1286 or die_error
(undef, "Error looking up file");
1288 $ftype = git_get_type
($hash);
1289 if ($ftype !~ "blob") {
1290 die_error
("400 Bad Request", "object is not a blob");
1292 open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base)
1293 or die_error
(undef, "Open git-blame failed.");
1296 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") .
1297 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;f=$file_name")}, "head");
1298 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1300 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html
($co{'title'})) .
1302 git_print_page_path
($file_name, $ftype);
1303 my @rev_color = (qw(light dark));
1304 my $num_colors = scalar(@rev_color);
1305 my $current_color = 0;
1307 print "<div class=\"page_body\">\n";
1308 print "<table class=\"blame\">\n";
1309 print "<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n";
1311 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
1313 my $rev = substr($full_rev, 0, 8);
1317 if (!defined $last_rev) {
1318 $last_rev = $full_rev;
1319 } elsif ($last_rev ne $full_rev) {
1320 $last_rev = $full_rev;
1321 $current_color = ++$current_color % $num_colors;
1323 print "<tr class=\"$rev_color[$current_color]\">\n";
1324 print "<td class=\"sha1\">" .
1325 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$full_rev;f=$file_name")}, esc_html
($rev)) . "</td>\n";
1326 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" . esc_html
($lineno) . "</a></td>\n";
1327 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
1332 close $fd or print "Reading blob failed\n";
1338 die_error
('403 Permission denied', "Permission denied.") if (!git_get_project_config_bool
('blame'));
1339 die_error
('404 Not Found', "What file will it be, master?") if (!$file_name);
1340 $hash_base ||= git_read_head
($project);
1341 die_error
(undef, "Reading commit failed.") unless ($hash_base);
1342 my %co = git_read_commit
($hash_base)
1343 or die_error
(undef, "Reading commit failed.");
1344 if (!defined $hash) {
1345 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
1346 or die_error
(undef, "Error lookup file.");
1348 open ($fd, "-|", $GIT, "annotate", '-l', '-t', '-r', $file_name, $hash_base)
1349 or die_error
(undef, "Open git-annotate failed.");
1352 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") .
1353 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;f=$file_name")}, "head");
1354 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1356 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html
($co{'title'})) .
1358 git_print_page_path
($file_name);
1359 print "<div class=\"page_body\">\n";
1361 <table class="blame">
1370 my @line_class = (qw(light dark));
1371 my $line_class_len = scalar (@line_class);
1372 my $line_class_num = $#line_class;
1373 while (my $line = <$fd>) {
1385 $line_class_num = ($line_class_num + 1) % $line_class_len;
1387 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) \+\d\d\d\d\t(\d+)\)(.*)$/) {
1394 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
1397 $short_rev = substr ($long_rev, 0, 8);
1398 $age = time () - $time;
1399 $age_str = age_string
($age);
1400 $age_str =~ s/ / /g;
1401 $age_class = age_class
($age);
1402 $author = esc_html
($author);
1403 $author =~ s/ / /g;
1405 while ((my $pos = index($data, "\t")) != -1) {
1406 if (my $count = (8 - ($pos % 8))) {
1407 my $spaces = ' ' x
$count;
1408 $data =~ s/\t/$spaces/;
1411 $data = esc_html
($data);
1414 <tr class="$line_class[$line_class_num]">
1415 <td class="sha1"><a href="$my_uri?${\esc_param ("p=$project;a=commit;h=$long_rev")}" class="text">$short_rev..</a></td>
1416 <td class="$age_class">$age_str</td>
1418 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
1419 <td class="pre">$data</td>
1422 } # while (my $line = <$fd>)
1423 print "</table>\n\n";
1424 close $fd or print "Reading blob failed.\n";
1430 my $head = git_read_head
($project);
1432 git_page_nav
('','', $head,undef,$head);
1433 my $taglist = git_read_refs
("refs/tags");
1435 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary"), -class => "title"}, " ") .
1437 print "<table cellspacing=\"0\">\n";
1439 if (defined @
$taglist) {
1440 foreach my $entry (@
$taglist) {
1442 my $comment_lines = $tag{'comment'};
1443 my $comment = shift @
$comment_lines;
1444 if (defined($comment)) {
1445 $comment = chop_str
($comment, 30, 5);
1448 print "<tr class=\"dark\">\n";
1450 print "<tr class=\"light\">\n";
1453 print "<td><i>$tag{'age'}</i></td>\n" .
1455 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), -class => "list"},
1456 "<b>" . esc_html
($tag{'name'}) . "</b>") .
1459 if (defined($comment)) {
1460 print $cgi->a({-class => "list", -href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, $comment);
1463 "<td class=\"link\">";
1464 if ($tag{'type'} eq "tag") {
1465 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
1467 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1468 if ($tag{'reftype'} eq "commit") {
1469 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1470 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'refid'}")}, "log");
1481 my $head = git_read_head
($project);
1483 git_page_nav
('','', $head,undef,$head);
1484 my $taglist = git_read_refs
("refs/heads");
1486 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary"), -class => "title"}, " ") .
1488 print "<table cellspacing=\"0\">\n";
1490 if (defined @
$taglist) {
1491 foreach my $entry (@
$taglist) {
1494 print "<tr class=\"dark\">\n";
1496 print "<tr class=\"light\">\n";
1499 print "<td><i>$tag{'age'}</i></td>\n" .
1501 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}"), -class => "list"}, "<b>" . esc_html
($tag{'name'}) . "</b>") .
1503 "<td class=\"link\">" .
1504 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1505 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'name'}")}, "log") .
1514 sub git_get_hash_by_path
{
1516 my $path = shift || return undef;
1520 open my $fd, "-|", $GIT, "ls-tree", $base, "--", $path
1521 or die_error
(undef, "Open git-ls-tree failed.");
1523 close $fd or return undef;
1525 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1526 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1530 sub mimetype_guess_file
{
1531 my $filename = shift;
1532 my $mimemap = shift;
1533 -r
$mimemap or return undef;
1536 open(MIME
, $mimemap) or return undef;
1538 my ($mime, $exts) = split(/\t+/);
1539 my @exts = split(/\s+/, $exts);
1540 foreach my $ext (@exts) {
1541 $mimemap{$ext} = $mime;
1546 $filename =~ /\.(.*?)$/;
1547 return $mimemap{$1};
1550 sub mimetype_guess
{
1551 my $filename = shift;
1553 $filename =~ /\./ or return undef;
1555 if ($mimetypes_file) {
1556 my $file = $mimetypes_file;
1557 #$file =~ m#^/# or $file = "$projectroot/$path/$file";
1558 $mime = mimetype_guess_file
($filename, $file);
1560 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1564 sub git_blob_plain_mimetype
{
1566 my $filename = shift;
1569 my $mime = mimetype_guess
($filename);
1570 $mime and return $mime;
1574 return $default_blob_plain_mimetype unless $fd;
1577 return 'text/plain' .
1578 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
1579 } elsif (! $filename) {
1580 return 'application/octet-stream';
1581 } elsif ($filename =~ m/\.png$/i) {
1583 } elsif ($filename =~ m/\.gif$/i) {
1585 } elsif ($filename =~ m/\.jpe?g$/i) {
1586 return 'image/jpeg';
1588 return 'application/octet-stream';
1592 sub git_blob_plain
{
1593 if (!defined $hash) {
1594 if (defined $file_name) {
1595 my $base = $hash_base || git_read_head
($project);
1596 $hash = git_get_hash_by_path
($base, $file_name, "blob")
1597 or die_error
(undef, "Error lookup file.");
1599 die_error
(undef, "No file name defined.");
1603 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
1604 or die_error
("Couldn't cat $file_name, $hash");
1606 $type ||= git_blob_plain_mimetype
($fd, $file_name);
1608 # save as filename, even when no $file_name is given
1609 my $save_as = "$hash";
1610 if (defined $file_name) {
1611 $save_as = $file_name;
1612 } elsif ($type =~ m/^text\//) {
1616 print $cgi->header(-type
=> "$type", '-content-disposition' => "inline; filename=\"$save_as\"");
1618 binmode STDOUT
, ':raw';
1620 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
1626 if (!defined $hash) {
1627 if (defined $file_name) {
1628 my $base = $hash_base || git_read_head
($project);
1629 $hash = git_get_hash_by_path
($base, $file_name, "blob")
1630 or die_error
(undef, "Error lookup file.");
1632 die_error
(undef, "No file name defined.");
1635 my $have_blame = git_get_project_config_bool
('blame');
1636 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
1637 or die_error
(undef, "Couldn't cat $file_name, $hash.");
1638 my $mimetype = git_blob_plain_mimetype
($fd, $file_name);
1639 if ($mimetype !~ m/^text\//) {
1641 return git_blob_plain
($mimetype);
1644 my $formats_nav = '';
1645 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
1646 if (defined $file_name) {
1648 $formats_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;h=$hash;hb=$hash_base;f=$file_name")}, "blame") . " | ";
1651 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$hash;f=$file_name")}, "plain") .
1652 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;hb=HEAD;f=$file_name")}, "head");
1654 $formats_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$hash")}, "plain");
1656 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1658 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html
($co{'title'})) .
1661 print "<div class=\"page_nav\">\n" .
1662 "<br/><br/></div>\n" .
1663 "<div class=\"title\">$hash</div>\n";
1665 git_print_page_path
($file_name, "blob");
1666 print "<div class=\"page_body\">\n";
1668 while (my $line = <$fd>) {
1671 while ((my $pos = index($line, "\t")) != -1) {
1672 if (my $count = (8 - ($pos % 8))) {
1673 my $spaces = ' ' x
$count;
1674 $line =~ s/\t/$spaces/;
1677 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", $nr, $nr, $nr, esc_html
($line);
1679 close $fd or print "Reading blob failed.\n";
1685 if (!defined $hash) {
1686 $hash = git_read_head
($project);
1687 if (defined $file_name) {
1688 my $base = $hash_base || $hash;
1689 $hash = git_get_hash_by_path
($base, $file_name, "tree");
1691 if (!defined $hash_base) {
1696 open my $fd, "-|", $GIT, "ls-tree", '-z', $hash
1697 or die_error
(undef, "Open git-ls-tree failed.");
1698 my @entries = map { chomp; $_ } <$fd>;
1699 close $fd or die_error
(undef, "Reading tree failed.");
1702 my $refs = read_info_ref
();
1704 if (defined $refs->{$hash_base}) {
1705 $ref = " <span class=\"tag\">" . esc_html
($refs->{$hash_base}) . "</span>";
1710 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
1711 $base_key = ";hb=$hash_base";
1712 git_page_nav
('tree','', $hash_base);
1714 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html
($co{'title'}) . $ref) . "\n" .
1717 print "<div class=\"page_nav\">\n";
1718 print "<br/><br/></div>\n";
1719 print "<div class=\"title\">$hash</div>\n";
1721 if (defined $file_name) {
1722 $base = esc_html
("$file_name/");
1724 git_print_page_path
($file_name);
1725 print "<div class=\"page_body\">\n";
1726 print "<table cellspacing=\"0\">\n";
1728 foreach my $line (@entries) {
1729 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1730 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1734 my $t_name = validate_input
($4);
1736 print "<tr class=\"dark\">\n";
1738 print "<tr class=\"light\">\n";
1741 print "<td class=\"mode\">" . mode_str
($t_mode) . "</td>\n";
1742 if ($t_type eq "blob") {
1743 print "<td class=\"list\">" .
1744 $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)) .
1746 "<td class=\"link\">" .
1747 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name")}, "blob") .
1748 # " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$t_hash$base_key;f=$base$t_name")}, "blame") .
1749 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;h=$t_hash;hb=$hash_base;f=$base$t_name")}, "history") .
1750 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$t_hash;f=$base$t_name")}, "raw") .
1752 } elsif ($t_type eq "tree") {
1753 print "<td class=\"list\">" .
1754 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, esc_html
($t_name)) .
1756 "<td class=\"link\">" .
1757 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, "tree") .
1758 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;hb=$hash_base;f=$base$t_name")}, "history") .
1763 print "</table>\n" .
1769 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
1770 open my $fd, "-|", $GIT, "rev-list", "--max-count=150", git_read_head
($project)
1771 or die_error
(undef, "Open git-rev-list failed.");
1772 my @revlist = map { chomp; $_ } <$fd>;
1773 close $fd or die_error
(undef, "Reading rev-list failed.");
1774 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
1775 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1776 "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
1777 print "<channel>\n";
1778 print "<title>$project</title>\n".
1779 "<link>" . esc_html
("$my_url?p=$project;a=summary") . "</link>\n".
1780 "<description>$project log</description>\n".
1781 "<language>en</language>\n";
1783 for (my $i = 0; $i <= $#revlist; $i++) {
1784 my $commit = $revlist[$i];
1785 my %co = git_read_commit
($commit);
1786 # we read 150, we always show 30 and the ones more recent than 48 hours
1787 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
1790 my %cd = date_str
($co{'committer_epoch'});
1791 open $fd, "-|", $GIT, "diff-tree", '-r', $co{'parent'}, $co{'id'} or next;
1792 my @difftree = map { chomp; $_ } <$fd>;
1796 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
1798 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
1799 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
1800 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
1801 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
1802 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
1803 "<content:encoded>" .
1805 my $comment = $co{'comment'};
1806 foreach my $line (@
$comment) {
1807 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
1808 print "$line<br/>\n";
1811 foreach my $line (@difftree) {
1812 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
1815 my $file = validate_input
(unquote
($7));
1816 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
1817 print "$file<br/>\n";
1820 "</content:encoded>\n" .
1823 print "</channel></rss>";
1827 my @list = git_read_projects
();
1829 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
1830 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1831 "<opml version=\"1.0\">\n".
1833 " <title>$site_name Git OPML Export</title>\n".
1836 "<outline text=\"git RSS feeds\">\n";
1838 foreach my $pr (@list) {
1840 my $head = git_read_head
($proj{'path'});
1841 if (!defined $head) {
1844 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
1845 my %co = git_read_commit
($head);
1850 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
1851 my $rss = "$my_url?p=$proj{'path'};a=rss";
1852 my $html = "$my_url?p=$proj{'path'};a=summary";
1853 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
1855 print "</outline>\n".
1861 my $head = git_read_head
($project);
1862 if (!defined $hash) {
1865 if (!defined $page) {
1868 my $refs = read_info_ref
();
1870 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
1871 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
1872 or die_error
(undef, "Open git-rev-list failed.");
1873 my @revlist = map { chomp; $_ } <$fd>;
1876 my $paging_nav = '';
1877 if ($hash ne $head || $page) {
1878 $paging_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "HEAD");
1880 $paging_nav .= "HEAD";
1883 $paging_nav .= " ⋅ " .
1884 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash;pg=" . ($page-1)), -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1886 $paging_nav .= " ⋅ prev";
1888 if ($#revlist >= (100 * ($page+1)-1)) {
1889 $paging_nav .= " ⋅ " .
1890 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash;pg=" . ($page+1)), -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1892 $paging_nav .= " ⋅ next";
1896 git_page_nav
('log','', $hash,undef,undef, $paging_nav);
1900 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary"), -class => "title"}, " ") .
1902 my %co = git_read_commit
($hash);
1903 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
1905 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
1906 my $commit = $revlist[$i];
1908 if (defined $refs->{$commit}) {
1909 $ref = " <span class=\"tag\">" . esc_html
($refs->{$commit}) . "</span>";
1911 my %co = git_read_commit
($commit);
1913 my %ad = date_str
($co{'author_epoch'});
1915 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "title"},
1916 "<span class=\"age\">$co{'age_string'}</span>" . esc_html
($co{'title'}) . $ref) . "\n";
1918 print "<div class=\"title_text\">\n" .
1919 "<div class=\"log_link\">\n" .
1920 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
1921 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1924 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
1926 "<div class=\"log_body\">\n";
1927 my $comment = $co{'comment'};
1929 foreach my $line (@
$comment) {
1930 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1941 print format_log_line_html
($line) . "<br/>\n";
1952 my %co = git_read_commit
($hash);
1954 die_error
(undef, "Unknown commit object.");
1956 my %ad = date_str
($co{'author_epoch'}, $co{'author_tz'});
1957 my %cd = date_str
($co{'committer_epoch'}, $co{'committer_tz'});
1959 my $parent = $co{'parent'};
1960 if (!defined $parent) {
1963 open my $fd, "-|", $GIT, "diff-tree", '-r', '-M', $parent, $hash
1964 or die_error
(undef, "Open git-diff-tree failed.");
1965 my @difftree = map { chomp; $_ } <$fd>;
1966 close $fd or die_error
(undef, "Reading git-diff-tree failed.");
1968 # non-textual hash id's can be cached
1970 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
1973 my $refs = read_info_ref
();
1975 if (defined $refs->{$co{'id'}}) {
1976 $ref = " <span class=\"tag\">" . esc_html
($refs->{$co{'id'}}) . "</span>";
1978 git_header_html
(undef, $expires);
1979 my $formats_nav = '';
1980 if (defined $file_name && defined $co{'parent'}) {
1981 my $parent = $co{'parent'};
1982 $formats_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;hb=$parent;f=$file_name")}, "blame");
1984 git_page_nav
('commit', defined $co{'parent'} ?
'' : 'commitdiff',
1985 $hash, $co{'tree'}, $hash,
1988 if (defined $co{'parent'}) {
1990 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash"), -class => "title"}, esc_html
($co{'title'}) . $ref) . "\n" .
1994 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash"), -class => "title"}, esc_html
($co{'title'})) . "\n" .
1997 print "<div class=\"title_text\">\n" .
1998 "<table cellspacing=\"0\">\n";
1999 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
2001 "<td></td><td> $ad{'rfc2822'}";
2002 if ($ad{'hour_local'} < 6) {
2003 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2005 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2009 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
2010 print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
2011 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
2014 "<td class=\"sha1\">" .
2015 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash"), class => "list"}, $co{'tree'}) .
2017 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
2020 my $parents = $co{'parents'};
2021 foreach my $par (@
$parents) {
2024 "<td class=\"sha1\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$par"), class => "list"}, $par) . "</td>" .
2025 "<td class=\"link\">" .
2026 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$par")}, "commit") .
2027 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash;hp=$par")}, "commitdiff") .
2033 print "<div class=\"page_body\">\n";
2034 my $comment = $co{'comment'};
2037 foreach my $line (@
$comment) {
2038 # print only one empty line
2040 if ($empty || $signed) {
2047 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2049 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2052 print format_log_line_html
($line) . "<br/>\n";
2056 print "<div class=\"list_head\">\n";
2057 if ($#difftree > 10) {
2058 print(($#difftree + 1) . " files changed:\n");
2061 print "<table class=\"diff_tree\">\n";
2063 foreach my $line (@difftree) {
2064 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2065 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2066 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
2074 my $similarity = $6;
2075 my $file = validate_input
(unquote
($7));
2077 print "<tr class=\"dark\">\n";
2079 print "<tr class=\"light\">\n";
2082 if ($status eq "A") {
2084 if (S_ISREG
(oct $to_mode)) {
2085 $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
2088 $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" .
2089 "<td><span class=\"file_status new\">[new " . file_type
($to_mode) . "$mode_chng]</span></td>\n" .
2090 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob") . "</td>\n";
2091 } elsif ($status eq "D") {
2093 $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" .
2094 "<td><span class=\"file_status deleted\">[deleted " . file_type
($from_mode). "]</span></td>\n" .
2095 "<td class=\"link\">" .
2096 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, "blob") .
2097 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;hb=$hash;f=$file")}, "history") .
2099 } elsif ($status eq "M" || $status eq "T") {
2100 my $mode_chnge = "";
2101 if ($from_mode != $to_mode) {
2102 $mode_chnge = " <span class=\"file_status mode_chnge\">[changed";
2103 if (((oct $from_mode) & S_IFMT
) != ((oct $to_mode) & S_IFMT
)) {
2104 $mode_chnge .= " from " . file_type
($from_mode) . " to " . file_type
($to_mode);
2106 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
2107 if (S_ISREG
($from_mode) && S_ISREG
($to_mode)) {
2108 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
2109 } elsif (S_ISREG
($to_mode)) {
2110 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
2113 $mode_chnge .= "]</span>\n";
2116 if ($to_id ne $from_id) {
2117 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));
2119 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file"), -class => "list"}, esc_html
($file));
2122 "<td>$mode_chnge</td>\n" .
2123 "<td class=\"link\">";
2124 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob");
2125 if ($to_id ne $from_id) {
2126 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file")}, "diff");
2128 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;hb=$hash;f=$file")}, "history") . "\n";
2130 } elsif ($status eq "R") {
2131 my ($from_file, $to_file) = split "\t", $file;
2133 if ($from_mode != $to_mode) {
2134 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
2137 $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" .
2138 "<td><span class=\"file_status moved\">[moved from " .
2139 $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)) .
2140 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
2141 "<td class=\"link\">" .
2142 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file")}, "blob");
2143 if ($to_id ne $from_id) {
2144 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file")}, "diff");
2155 mkdir($git_temp, 0700);
2157 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
2159 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff_plain;h=$hash;hp=$hash_parent")}, "plain");
2160 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2162 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html
($co{'title'})) . "\n" .
2165 print "<div class=\"page_nav\">\n" .
2166 "<br/><br/></div>\n" .
2167 "<div class=\"title\">$hash vs $hash_parent</div>\n";
2169 git_print_page_path
($file_name, "blob");
2170 print "<div class=\"page_body\">\n" .
2171 "<div class=\"diff_info\">blob:" .
2172 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name")}, $hash_parent) .
2174 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, $hash) .
2176 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
2181 sub git_blobdiff_plain
{
2182 mkdir($git_temp, 0700);
2183 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8');
2184 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
2187 sub git_commitdiff
{
2188 mkdir($git_temp, 0700);
2189 my %co = git_read_commit
($hash);
2191 die_error
(undef, "Unknown commit object.");
2193 if (!defined $hash_parent) {
2194 $hash_parent = $co{'parent'};
2196 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2197 or die_error
(undef, "Open git-diff-tree failed.");
2198 my @difftree = map { chomp; $_ } <$fd>;
2199 close $fd or die_error
(undef, "Reading diff-tree failed.");
2201 # non-textual hash id's can be cached
2203 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2206 my $refs = read_info_ref
();
2208 if (defined $refs->{$co{'id'}}) {
2209 $ref = " <span class=\"tag\">" . esc_html
($refs->{$co{'id'}}) . "</span>";
2211 git_header_html
(undef, $expires);
2213 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent")}, "plain");
2214 git_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
2216 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html
($co{'title'}) . $ref) . "\n" .
2218 print "<div class=\"page_body\">\n";
2219 my $comment = $co{'comment'};
2222 my @log = @
$comment;
2223 # remove first and empty lines after that
2225 while (defined $log[0] && $log[0] eq "") {
2228 foreach my $line (@log) {
2229 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2240 print format_log_line_html
($line) . "<br/>\n";
2243 foreach my $line (@difftree) {
2244 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2245 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2246 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2252 my $file = validate_input
(unquote
($6));
2253 if ($status eq "A") {
2254 print "<div class=\"diff_info\">" . file_type
($to_mode) . ":" .
2255 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id) . "(new)" .
2257 git_diff_print
(undef, "/dev/null", $to_id, "b/$file");
2258 } elsif ($status eq "D") {
2259 print "<div class=\"diff_info\">" . file_type
($from_mode) . ":" .
2260 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) . "(deleted)" .
2262 git_diff_print
($from_id, "a/$file", undef, "/dev/null");
2263 } elsif ($status eq "M") {
2264 if ($from_id ne $to_id) {
2265 print "<div class=\"diff_info\">" .
2266 file_type
($from_mode) . ":" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) .
2268 file_type
($to_mode) . ":" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id);
2270 git_diff_print
($from_id, "a/$file", $to_id, "b/$file");
2279 sub git_commitdiff_plain
{
2280 mkdir($git_temp, 0700);
2281 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2282 or die_error
(undef, "Open git-diff-tree failed.");
2283 my @difftree = map { chomp; $_ } <$fd>;
2284 close $fd or die_error
(undef, "Reading diff-tree failed.");
2286 # try to figure out the next tag after this commit
2288 my $refs = read_info_ref
("tags");
2289 open $fd, "-|", $GIT, "rev-list", "HEAD";
2290 my @commits = map { chomp; $_ } <$fd>;
2292 foreach my $commit (@commits) {
2293 if (defined $refs->{$commit}) {
2294 $tagname = $refs->{$commit}
2296 if ($commit eq $hash) {
2301 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8', '-content-disposition' => "inline; filename=\"git-$hash.patch\"");
2302 my %co = git_read_commit
($hash);
2303 my %ad = date_str
($co{'author_epoch'}, $co{'author_tz'});
2304 my $comment = $co{'comment'};
2305 print "From: $co{'author'}\n" .
2306 "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
2307 "Subject: $co{'title'}\n";
2308 if (defined $tagname) {
2309 print "X-Git-Tag: $tagname\n";
2311 print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
2314 foreach my $line (@
$comment) {;
2319 foreach my $line (@difftree) {
2320 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2325 if ($status eq "A") {
2326 git_diff_print
(undef, "/dev/null", $to_id, "b/$file", "plain");
2327 } elsif ($status eq "D") {
2328 git_diff_print
($from_id, "a/$file", undef, "/dev/null", "plain");
2329 } elsif ($status eq "M") {
2330 git_diff_print
($from_id, "a/$file", $to_id, "b/$file", "plain");
2336 if (!defined $hash_base) {
2337 $hash_base = git_read_head
($project);
2340 my %co = git_read_commit
($hash_base);
2342 die_error
(undef, "Unknown commit object.");
2344 my $refs = read_info_ref
();
2346 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base);
2348 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html
($co{'title'})) . "\n" .
2350 if (!defined $hash && defined $file_name) {
2351 $hash = git_get_hash_by_path
($hash_base, $file_name);
2353 if (defined $hash) {
2354 $ftype = git_get_type
($hash);
2356 git_print_page_path
($file_name, $ftype);
2359 $GIT, "rev-list", "--full-history", $hash_base, "--", "\'$file_name\'";
2360 print "<table cellspacing=\"0\">\n";
2362 while (my $line = <$fd>) {
2363 if ($line =~ m/^([0-9a-fA-F]{40})/){
2365 my %co = git_read_commit
($commit);
2370 if (defined $refs->{$commit}) {
2371 $ref = " <span class=\"tag\">" . esc_html
($refs->{$commit}) . "</span>";
2374 print "<tr class=\"dark\">\n";
2376 print "<tr class=\"light\">\n";
2379 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2380 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2381 "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list"}, "<b>" .
2382 esc_html
(chop_str
($co{'title'}, 50)) . "$ref</b>") . "</td>\n" .
2383 "<td class=\"link\">" .
2384 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
2385 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2386 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;hb=$commit;f=$file_name")}, "blob");
2387 my $blob = git_get_hash_by_path
($hash_base, $file_name);
2388 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2389 if (defined $blob && defined $blob_parent && $blob ne $blob_parent) {
2391 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=$file_name")},
2404 if (!defined $searchtext) {
2405 die_error
("", "Text field empty.");
2407 if (!defined $hash) {
2408 $hash = git_read_head
($project);
2410 my %co = git_read_commit
($hash);
2412 die_error
(undef, "Unknown commit object.");
2414 # pickaxe may take all resources of your box and run for several minutes
2415 # with every query - so decide by yourself how public you make this feature :)
2416 my $commit_search = 1;
2417 my $author_search = 0;
2418 my $committer_search = 0;
2419 my $pickaxe_search = 0;
2420 if ($searchtext =~ s/^author\\://i) {
2422 } elsif ($searchtext =~ s/^committer\\://i) {
2423 $committer_search = 1;
2424 } elsif ($searchtext =~ s/^pickaxe\\://i) {
2426 $pickaxe_search = 1;
2429 git_page_nav
('','', $hash,$co{'tree'},$hash);
2432 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html
($co{'title'})) . "\n" .
2434 print "<table cellspacing=\"0\">\n";
2436 if ($commit_search) {
2438 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", $hash or next;
2439 while (my $commit_text = <$fd>) {
2440 if (!grep m/$searchtext/i, $commit_text) {
2443 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
2446 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
2449 my @commit_lines = split "\n", $commit_text;
2450 my %co = git_read_commit
(undef, \
@commit_lines);
2455 print "<tr class=\"dark\">\n";
2457 print "<tr class=\"light\">\n";
2460 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2461 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2463 $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/>");
2464 my $comment = $co{'comment'};
2465 foreach my $line (@
$comment) {
2466 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2467 my $lead = esc_html
($1) || "";
2468 $lead = chop_str
($lead, 30, 10);
2469 my $match = esc_html
($2) || "";
2470 my $trail = esc_html
($3) || "";
2471 $trail = chop_str
($trail, 30, 10);
2472 my $text = "$lead<span class=\"match\">$match</span>$trail";
2473 print chop_str
($text, 80, 5) . "<br/>\n";
2477 "<td class=\"link\">" .
2478 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2479 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2486 if ($pickaxe_search) {
2488 open my $fd, "-|", "$GIT rev-list $hash | $GIT diff-tree -r --stdin -S\'$searchtext\'";
2491 while (my $line = <$fd>) {
2492 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2495 $set{'from_id'} = $3;
2497 $set{'id'} = $set{'to_id'};
2498 if ($set{'id'} =~ m/0{40}/) {
2499 $set{'id'} = $set{'from_id'};
2501 if ($set{'id'} =~ m/0{40}/) {
2505 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
2508 print "<tr class=\"dark\">\n";
2510 print "<tr class=\"light\">\n";
2513 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2514 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2516 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" .
2517 esc_html
(chop_str
($co{'title'}, 50)) . "</b><br/>");
2518 while (my $setref = shift @files) {
2520 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}"), class => "list"},
2521 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
2525 "<td class=\"link\">" .
2526 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2527 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2531 %co = git_read_commit
($1);
2541 my $head = git_read_head
($project);
2542 if (!defined $hash) {
2545 if (!defined $page) {
2548 my $refs = read_info_ref
();
2550 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2551 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2552 or die_error
(undef, "Open git-rev-list failed.");
2553 my @revlist = map { chomp; $_ } <$fd>;
2556 my $paging_nav = '';
2557 if ($hash ne $head || $page) {
2558 $paging_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "HEAD");
2560 $paging_nav .= "HEAD";
2563 $paging_nav .= " ⋅ " .
2564 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash;pg=" . ($page-1)), -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2566 $paging_nav .= " ⋅ prev";
2568 if ($#revlist >= (100 * ($page+1)-1)) {
2569 $paging_nav .= " ⋅ " .
2570 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)), -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2572 $paging_nav .= " ⋅ next";
2576 git_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
2579 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary"), -class => "title"}, " ") .
2581 print "<table cellspacing=\"0\">\n";
2583 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2584 my $commit = $revlist[$i];
2586 if (defined $refs->{$commit}) {
2587 $ref = " <span class=\"tag\">" . esc_html
($refs->{$commit}) . "</span>";
2589 my %co = git_read_commit
($commit);
2590 my %ad = date_str
($co{'author_epoch'});
2592 print "<tr class=\"dark\">\n";
2594 print "<tr class=\"light\">\n";
2597 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2598 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
2600 if (length($co{'title_short'}) < length($co{'title'})) {
2601 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list", -title
=> "$co{'title'}"},
2602 "<b>" . esc_html
($co{'title_short'}) . "$ref</b>");
2604 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list"},
2605 "<b>" . esc_html
($co{'title_short'}) . "$ref</b>");
2608 "<td class=\"link\">" .
2609 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
2610 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2614 if ($#revlist >= (100 * ($page+1)-1)) {
2617 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)), -title
=> "Alt-n"}, "next") .