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);
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";
283 my $title = "$site_name git";
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
|/$|) {
297 # require explicit support from the UA if we are to send the page as
298 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
299 # we have to do this because MSIE sometimes globs '*/*', pretending to
300 # support xhtml+xml but choking when it gets what it asked for.
301 if ($cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ && $cgi->Accept('application/xhtml
+xml
') != 0) {
302 $content_type = 'application
/xhtml
+xml
';
304 $content_type = 'text
/html
';
306 print $cgi->header(-type=>$content_type, -charset => 'utf
-8', -status=> $status, -expires => $expires);
308 <?xml version="1.0" encoding="utf-8"?>
309 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
310 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
311 <!-- git web interface v$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
312 <!-- git core binaries version $git_version -->
314 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
315 <meta name="robots" content="index, nofollow"/>
316 <title>$title</title>
317 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
322 print "<div class=\"page_header\">\n" .
323 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
324 "<img src=\"$my_uri?" . esc_param
("a=git-logo.png") . "\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
326 print $cgi->a({-href
=> esc_param
($home_link)}, "projects") . " / ";
327 if (defined $project) {
328 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, esc_html
($project));
329 if (defined $action) {
333 if (!defined $searchtext) {
337 if (defined $hash_base) {
338 $search_hash = $hash_base;
339 } elsif (defined $hash) {
340 $search_hash = $hash;
342 $search_hash = "HEAD";
344 $cgi->param("a", "search");
345 $cgi->param("h", $search_hash);
346 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
347 "<div class=\"search\">\n" .
348 $cgi->hidden(-name
=> "p") . "\n" .
349 $cgi->hidden(-name
=> "a") . "\n" .
350 $cgi->hidden(-name
=> "h") . "\n" .
351 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
353 $cgi->end_form() . "\n";
358 sub git_footer_html
{
359 print "<div class=\"page_footer\">\n";
360 if (defined $project) {
361 my $descr = git_read_description
($project);
362 if (defined $descr) {
363 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
365 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=rss"), -class => "rss_logo"}, "RSS") . "\n";
367 print $cgi->a({-href
=> "$my_uri?" . esc_param
("a=opml"), -class => "rss_logo"}, "OPML") . "\n";
375 my $status = shift || "403 Forbidden";
376 my $error = shift || "Malformed query, file missing or permission denied";
378 git_header_html
($status);
379 print "<div class=\"page_body\">\n" .
381 "$status - $error\n" .
389 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
390 $extra = '' if !defined $extra; # pager or formats
392 my @navs = qw(summary shortlog log commit commitdiff tree);
394 @navs = grep { $_ ne $suppress } @navs;
397 my %arg = map { $_, ''} @navs;
399 for (qw(commit commitdiff)) {
400 $arg{$_} = ";h=$head";
402 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
403 for (qw(shortlog log)) {
404 $arg{$_} = ";h=$head";
408 $arg{tree
} .= ";h=$treehead" if defined $treehead;
409 $arg{tree
} .= ";hb=$treebase" if defined $treebase;
411 print "<div class=\"page_nav\">\n" .
415 : $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$_$arg{$_}")}, "$_")
418 print "<br/>$extra<br/>\n" .
425 open my $fd, "-|", $GIT, "cat-file", '-t', $hash or return;
434 my $oENV = $ENV{'GIT_DIR'};
436 $ENV{'GIT_DIR'} = "$projectroot/$project";
437 if (open my $fd, "-|", $GIT, "rev-parse", "--verify", "HEAD") {
440 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
445 $ENV{'GIT_DIR'} = $oENV;
453 open my $fd, "$projectroot/$path" or return undef;
457 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
462 sub git_read_description
{
465 open my $fd, "$projectroot/$path/description" or return undef;
477 open my $fd, "-|", $GIT, "cat-file", "tag", $tag_id or return;
478 $tag{'id'} = $tag_id;
479 while (my $line = <$fd>) {
481 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
483 } elsif ($line =~ m/^type (.+)$/) {
485 } elsif ($line =~ m/^tag (.+)$/) {
487 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
491 } elsif ($line =~ m/--BEGIN/) {
492 push @comment, $line;
494 } elsif ($line eq "") {
498 push @comment, <$fd>;
499 $tag{'comment'} = \
@comment;
501 if (!defined $tag{'name'}) {
511 if ($age > 60*60*24*365*2) {
512 $age_str = (int $age/60/60/24/365);
513 $age_str .= " years ago";
514 } elsif ($age > 60*60*24*(365/12)*2) {
515 $age_str = int $age/60/60/24/(365/12);
516 $age_str .= " months ago";
517 } elsif ($age > 60*60*24*7*2) {
518 $age_str = int $age/60/60/24/7;
519 $age_str .= " weeks ago";
520 } elsif ($age > 60*60*24*2) {
521 $age_str = int $age/60/60/24;
522 $age_str .= " days ago";
523 } elsif ($age > 60*60*2) {
524 $age_str = int $age/60/60;
525 $age_str .= " hours ago";
526 } elsif ($age > 60*2) {
527 $age_str = int $age/60;
528 $age_str .= " min ago";
531 $age_str .= " sec ago";
533 $age_str .= " right now";
538 sub git_read_commit
{
539 my $commit_id = shift;
540 my $commit_text = shift;
545 if (defined $commit_text) {
546 @commit_lines = @
$commit_text;
549 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", "--max-count=1", $commit_id or return;
550 @commit_lines = split '\n', <$fd>;
555 my $header = shift @commit_lines;
556 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
559 ($co{'id'}, my @parents) = split ' ', $header;
560 $co{'parents'} = \
@parents;
561 $co{'parent'} = $parents[0];
562 while (my $line = shift @commit_lines) {
563 last if $line eq "\n";
564 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
566 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
568 $co{'author_epoch'} = $2;
569 $co{'author_tz'} = $3;
570 if ($co{'author'} =~ m/^([^<]+) </) {
571 $co{'author_name'} = $1;
573 $co{'author_name'} = $co{'author'};
575 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
576 $co{'committer'} = $1;
577 $co{'committer_epoch'} = $2;
578 $co{'committer_tz'} = $3;
579 $co{'committer_name'} = $co{'committer'};
580 $co{'committer_name'} =~ s/ <.*//;
583 if (!defined $co{'tree'}) {
587 foreach my $title (@commit_lines) {
590 $co{'title'} = chop_str
($title, 80, 5);
591 # remove leading stuff of merges to make the interesting part visible
592 if (length($title) > 50) {
593 $title =~ s/^Automatic //;
594 $title =~ s/^merge (of|with) /Merge ... /i;
595 if (length($title) > 50) {
596 $title =~ s/(http|rsync):\/\///;
598 if (length($title) > 50) {
599 $title =~ s/(master|www|rsync)\.//;
601 if (length($title) > 50) {
602 $title =~ s/kernel.org:?//;
604 if (length($title) > 50) {
605 $title =~ s/\/pub\/scm//;
608 $co{'title_short'} = chop_str
($title, 50, 5);
612 # remove added spaces
613 foreach my $line (@commit_lines) {
616 $co{'comment'} = \
@commit_lines;
618 my $age = time - $co{'committer_epoch'};
620 $co{'age_string'} = age_string
($age);
621 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
622 if ($age > 60*60*24*7*2) {
623 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
624 $co{'age_string_age'} = $co{'age_string'};
626 $co{'age_string_date'} = $co{'age_string'};
627 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
634 my $from_name = shift;
637 my $format = shift || "html";
639 my $from_tmp = "/dev/null";
640 my $to_tmp = "/dev/null";
643 # create tmp from-file
645 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
646 open my $fd2, "> $from_tmp";
647 open my $fd, "-|", $GIT, "cat-file", "blob", $from;
656 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
657 open my $fd2, "> $to_tmp";
658 open my $fd, "-|", $GIT, "cat-file", "blob", $to;
665 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
666 if ($format eq "plain") {
671 while (my $line = <$fd>) {
673 my $char = substr($line, 0, 1);
676 $diff_class = " add";
677 } elsif ($char eq "-") {
678 $diff_class = " rem";
679 } elsif ($char eq "@") {
680 $diff_class = " chunk_header";
681 } elsif ($char eq "\\") {
685 while ((my $pos = index($line, "\t")) != -1) {
686 if (my $count = (8 - (($pos-1) % 8))) {
687 my $spaces = ' ' x
$count;
688 $line =~ s/\t/$spaces/;
691 print "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
705 my $mode = oct shift;
707 if (S_ISDIR
($mode & S_IFMT
)) {
709 } elsif (S_ISLNK
($mode)) {
711 } elsif (S_ISREG
($mode)) {
712 # git cares only about the executable bit
713 if ($mode & S_IXUSR
) {
726 my $add_len = shift || 10;
728 # allow only $len chars, but don't cut a word if it would fit in $add_len
729 # if it doesn't fit, cut it if it's still longer than the dots we would add
730 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
733 if (length($tail) > 4) {
740 my $mode = oct shift;
742 if (S_ISDIR
($mode & S_IFMT
)) {
744 } elsif (S_ISLNK
($mode)) {
746 } elsif (S_ISREG
($mode)) {
753 sub format_log_line_html
{
756 $line = esc_html
($line);
757 $line =~ s/ / /g;
758 if ($line =~ m/([0-9a-fA-F]{40})/) {
760 if (git_get_type
($hash_text) eq "commit") {
761 my $link = $cgi->a({-class => "text", -href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_text")}, $hash_text);
762 $line =~ s/$hash_text/$link/;
770 my $tz = shift || "-0000";
773 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
774 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
775 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
776 $date{'hour'} = $hour;
777 $date{'minute'} = $min;
778 $date{'mday'} = $mday;
779 $date{'day'} = $days[$wday];
780 $date{'month'} = $months[$mon];
781 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
782 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
784 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
785 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
786 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
787 $date{'hour_local'} = $hour;
788 $date{'minute_local'} = $min;
789 $date{'tz_local'} = $tz;
793 # git-logo (cached in browser for one day)
795 binmode STDOUT
, ':raw';
796 print $cgi->header(-type
=> 'image/png', -expires
=> '+1d');
797 # cat git-logo.png | hexdump -e '16/1 " %02x" "\n"' | sed 's/ /\\x/g'
798 print "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52" .
799 "\x00\x00\x00\x48\x00\x00\x00\x1b\x04\x03\x00\x00\x00\x2d\xd9\xd4" .
800 "\x2d\x00\x00\x00\x18\x50\x4c\x54\x45\xff\xff\xff\x60\x60\x5d\xb0" .
801 "\xaf\xaa\x00\x80\x00\xce\xcd\xc7\xc0\x00\x00\xe8\xe8\xe6\xf7\xf7" .
802 "\xf6\x95\x0c\xa7\x47\x00\x00\x00\x73\x49\x44\x41\x54\x28\xcf\x63" .
803 "\x48\x67\x20\x04\x4a\x5c\x18\x0a\x08\x2a\x62\x53\x61\x20\x02\x08" .
804 "\x0d\x69\x45\xac\xa1\xa1\x01\x30\x0c\x93\x60\x36\x26\x52\x91\xb1" .
805 "\x01\x11\xd6\xe1\x55\x64\x6c\x6c\xcc\x6c\x6c\x0c\xa2\x0c\x70\x2a" .
806 "\x62\x06\x2a\xc1\x62\x1d\xb3\x01\x02\x53\xa4\x08\xe8\x00\x03\x18" .
807 "\x26\x56\x11\xd4\xe1\x20\x97\x1b\xe0\xb4\x0e\x35\x24\x71\x29\x82" .
808 "\x99\x30\xb8\x93\x0a\x11\xb9\x45\x88\xc1\x8d\xa0\xa2\x44\x21\x06" .
809 "\x27\x41\x82\x40\x85\xc1\x45\x89\x20\x70\x01\x00\xa4\x3d\x21\xc5" .
810 "\x12\x1c\x9a\xfe\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\x82";
816 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
817 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
818 if (!defined $gcos) {
822 $owner =~ s/[,;].*$//;
823 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
826 sub git_read_projects
{
829 if (-d
$projects_list) {
830 # search in directory
831 my $dir = $projects_list;
832 opendir my ($dh), $dir or return undef;
833 while (my $dir = readdir($dh)) {
834 if (-e
"$projectroot/$dir/HEAD") {
842 } elsif (-f
$projects_list) {
843 # read from file(url-encoded):
844 # 'git%2Fgit.git Linus+Torvalds'
845 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
846 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
847 open my ($fd), $projects_list or return undef;
848 while (my $line = <$fd>) {
850 my ($path, $owner) = split ' ', $line;
851 $path = unescape
($path);
852 $owner = unescape
($owner);
853 if (!defined $path) {
856 if (-e
"$projectroot/$path/HEAD") {
859 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
866 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
870 sub git_get_project_config
{
873 return unless ($key);
874 $key =~ s/^gitweb\.//;
875 return if ($key =~ m/\W/);
877 my $val = qx($GIT repo
-config
--get gitweb
.$key);
881 sub git_get_project_config_bool
{
882 my $val = git_get_project_config
(@_);
883 if ($val and $val =~ m/true|yes|on/) {
886 return; # implicit false
889 sub git_project_list
{
890 my @list = git_read_projects
();
893 die_error
(undef, "No project found.");
895 foreach my $pr (@list) {
896 my $head = git_read_head
($pr->{'path'});
897 if (!defined $head) {
900 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
901 my %co = git_read_commit
($head);
905 $pr->{'commit'} = \
%co;
906 if (!defined $pr->{'descr'}) {
907 my $descr = git_read_description
($pr->{'path'}) || "";
908 $pr->{'descr'} = chop_str
($descr, 25, 5);
910 if (!defined $pr->{'owner'}) {
911 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
917 print "<div class=\"index_include\">\n";
918 open (my $fd, $home_text);
923 print "<table class=\"project_list\">\n" .
925 if (!defined($order) || (defined($order) && ($order eq "project"))) {
926 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
927 print "<th>Project</th>\n";
929 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=project")}, "Project") . "</th>\n";
931 if (defined($order) && ($order eq "descr")) {
932 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
933 print "<th>Description</th>\n";
935 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=descr")}, "Description") . "</th>\n";
937 if (defined($order) && ($order eq "owner")) {
938 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
939 print "<th>Owner</th>\n";
941 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=owner")}, "Owner") . "</th>\n";
943 if (defined($order) && ($order eq "age")) {
944 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
945 print "<th>Last Change</th>\n";
947 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=age")}, "Last Change") . "</th>\n";
949 print "<th></th>\n" .
952 foreach my $pr (@projects) {
954 print "<tr class=\"dark\">\n";
956 print "<tr class=\"light\">\n";
959 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=summary"), -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
960 "<td>$pr->{'descr'}</td>\n" .
961 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
962 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" . $pr->{'commit'}{'age_string'} . "</td>\n" .
963 "<td class=\"link\">" .
964 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=summary")}, "summary") .
965 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=shortlog")}, "shortlog") .
966 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=log")}, "log") .
975 my $type = shift || "";
977 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
978 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
979 open my $fd, "$projectroot/$project/info/refs" or return;
980 while (my $line = <$fd>) {
982 if ($line =~ m/^([0-9a-fA-F]{40})\t.*$type\/([^\
^]+)/) {
983 if (defined $refs{$1}) {
984 $refs{$1} .= " / $2";
999 opendir my $dh, "$projectroot/$project/$ref_dir";
1000 while (my $dir = readdir($dh)) {
1001 if ($dir =~ m/^\./) {
1004 if (-d
"$projectroot/$project/$ref_dir/$dir") {
1005 opendir my $dh2, "$projectroot/$project/$ref_dir/$dir";
1006 my @subdirs = grep !m/^\./, readdir $dh2;
1008 foreach my $subdir (@subdirs) {
1009 push @refs, "$dir/$subdir"
1016 foreach my $ref_file (@refs) {
1017 my $ref_id = git_read_hash
("$project/$ref_dir/$ref_file");
1018 my $type = git_get_type
($ref_id) || next;
1021 $ref_item{'type'} = $type;
1022 $ref_item{'id'} = $ref_id;
1023 $ref_item{'epoch'} = 0;
1024 $ref_item{'age'} = "unknown";
1025 if ($type eq "tag") {
1026 my %tag = git_read_tag
($ref_id);
1027 $ref_item{'comment'} = $tag{'comment'};
1028 if ($tag{'type'} eq "commit") {
1029 %co = git_read_commit
($tag{'object'});
1030 $ref_item{'epoch'} = $co{'committer_epoch'};
1031 $ref_item{'age'} = $co{'age_string'};
1032 } elsif (defined($tag{'epoch'})) {
1033 my $age = time - $tag{'epoch'};
1034 $ref_item{'epoch'} = $tag{'epoch'};
1035 $ref_item{'age'} = age_string
($age);
1037 $ref_item{'reftype'} = $tag{'type'};
1038 $ref_item{'name'} = $tag{'name'};
1039 $ref_item{'refid'} = $tag{'object'};
1040 } elsif ($type eq "commit"){
1041 %co = git_read_commit
($ref_id);
1042 $ref_item{'reftype'} = "commit";
1043 $ref_item{'name'} = $ref_file;
1044 $ref_item{'title'} = $co{'title'};
1045 $ref_item{'refid'} = $ref_id;
1046 $ref_item{'epoch'} = $co{'committer_epoch'};
1047 $ref_item{'age'} = $co{'age_string'};
1050 push @reflist, \
%ref_item;
1053 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1058 my $descr = git_read_description
($project) || "none";
1059 my $head = git_read_head
($project);
1060 my %co = git_read_commit
($head);
1061 my %cd = date_str
($co{'committer_epoch'}, $co{'committer_tz'});
1064 if (-f
$projects_list) {
1065 open (my $fd , $projects_list);
1066 while (my $line = <$fd>) {
1068 my ($pr, $ow) = split ' ', $line;
1069 $pr = unescape
($pr);
1070 $ow = unescape
($ow);
1071 if ($pr eq $project) {
1072 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
1078 if (!defined $owner) {
1079 $owner = get_file_owner
("$projectroot/$project");
1082 my $refs = read_info_ref
();
1084 git_page_nav
('summary','', $head);
1085 print "<div class=\"title\"> </div>\n";
1086 print "<table cellspacing=\"0\">\n" .
1087 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
1088 "<tr><td>owner</td><td>$owner</td></tr>\n" .
1089 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
1091 open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_read_head
($project)
1092 or die_error
(undef, "Open git-rev-list failed.");
1093 my @revlist = map { chomp; $_ } <$fd>;
1096 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog"), -class => "title"}, "shortlog") .
1099 print "<table cellspacing=\"0\">\n";
1101 foreach my $commit (@revlist) {
1102 my %co = git_read_commit
($commit);
1103 my %ad = date_str
($co{'author_epoch'});
1105 print "<tr class=\"dark\">\n";
1107 print "<tr class=\"light\">\n";
1112 if (defined $refs->{$commit}) {
1113 $ref = " <span class=\"tag\">" . esc_html
($refs->{$commit}) . "</span>";
1115 print "<td><i>$co{'age_string'}</i></td>\n" .
1116 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
1118 if (length($co{'title_short'}) < length($co{'title'})) {
1119 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list", -title
=> "$co{'title'}"},
1120 "<b>" . esc_html
($co{'title_short'}) . "$ref</b>");
1122 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list"},
1123 "<b>" . esc_html
($co{'title'}) . "$ref</b>");
1126 "<td class=\"link\">" .
1127 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
1128 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1132 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "...") . "</td>\n" .
1139 my $taglist = git_read_refs
("refs/tags");
1140 if (defined @
$taglist) {
1142 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tags"), -class => "title"}, "tags") .
1145 print "<table cellspacing=\"0\">\n";
1147 foreach my $entry (@
$taglist) {
1149 my $comment_lines = $tag{'comment'};
1150 my $comment = shift @
$comment_lines;
1151 if (defined($comment)) {
1152 $comment = chop_str
($comment, 30, 5);
1155 print "<tr class=\"dark\">\n";
1157 print "<tr class=\"light\">\n";
1161 print "<td><i>$tag{'age'}</i></td>\n" .
1163 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), -class => "list"},
1164 "<b>" . esc_html
($tag{'name'}) . "</b>") .
1167 if (defined($comment)) {
1168 print $cgi->a({-class => "list", -href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, esc_html
($comment));
1171 "<td class=\"link\">";
1172 if ($tag{'type'} eq "tag") {
1173 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
1175 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1176 if ($tag{'reftype'} eq "commit") {
1177 print " | " . $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{'refid'}")}, "log");
1183 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tags")}, "...") . "</td>\n" .
1191 my $headlist = git_read_refs
("refs/heads");
1192 if (defined @
$headlist) {
1194 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=heads"), -class => "title"}, "heads") .
1197 print "<table cellspacing=\"0\">\n";
1199 foreach my $entry (@
$headlist) {
1202 print "<tr class=\"dark\">\n";
1204 print "<tr class=\"light\">\n";
1208 print "<td><i>$tag{'age'}</i></td>\n" .
1210 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}"), -class => "list"},
1211 "<b>" . esc_html
($tag{'name'}) . "</b>") .
1213 "<td class=\"link\">" .
1214 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1215 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'name'}")}, "log") .
1219 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=heads")}, "...") . "</td>\n" .
1229 sub git_print_page_path
{
1233 if (!defined $name) {
1234 print "<div class=\"page_path\"><b>/</b></div>\n";
1235 } elsif ($type =~ "blob") {
1236 print "<div class=\"page_path\"><b>" .
1237 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;f=$file_name")}, esc_html
($name)) . "</b><br/></div>\n";
1239 print "<div class=\"page_path\"><b>" . esc_html
($name) . "</b><br/></div>\n";
1244 my $head = git_read_head
($project);
1246 git_page_nav
('','', $head,undef,$head);
1247 my %tag = git_read_tag
($hash);
1249 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html
($tag{'name'})) . "\n" .
1251 print "<div class=\"title_text\">\n" .
1252 "<table cellspacing=\"0\">\n" .
1254 "<td>object</td>\n" .
1255 "<td>" . $cgi->a({-class => "list", -href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'object'}) . "</td>\n" .
1256 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'type'}) . "</td>\n" .
1258 if (defined($tag{'author'})) {
1259 my %ad = date_str
($tag{'epoch'}, $tag{'tz'});
1260 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
1261 print "<tr><td></td><td>" . $ad{'rfc2822'} . sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) . "</td></tr>\n";
1263 print "</table>\n\n" .
1265 print "<div class=\"page_body\">";
1266 my $comment = $tag{'comment'};
1267 foreach my $line (@
$comment) {
1268 print esc_html
($line) . "<br/>\n";
1277 die_error
(undef, "Permission denied.") if (!git_get_project_config_bool
('blame'));
1278 die_error
('404 Not Found', "File name not defined") if (!$file_name);
1279 $hash_base ||= git_read_head
($project);
1280 die_error
(undef, "Reading commit failed") unless ($hash_base);
1281 my %co = git_read_commit
($hash_base)
1282 or die_error
(undef, "Reading commit failed");
1283 if (!defined $hash) {
1284 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
1285 or die_error
(undef, "Error looking up file");
1287 $ftype = git_get_type
($hash);
1288 if ($ftype !~ "blob") {
1289 die_error
("400 Bad Request", "object is not a blob");
1291 open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base)
1292 or die_error
(undef, "Open git-blame failed.");
1295 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") .
1296 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;f=$file_name")}, "head");
1297 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1299 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html
($co{'title'})) .
1301 git_print_page_path
($file_name, $ftype);
1302 my @rev_color = (qw(light dark));
1303 my $num_colors = scalar(@rev_color);
1304 my $current_color = 0;
1306 print "<div class=\"page_body\">\n";
1307 print "<table class=\"blame\">\n";
1308 print "<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n";
1310 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
1312 my $rev = substr($full_rev, 0, 8);
1316 if (!defined $last_rev) {
1317 $last_rev = $full_rev;
1318 } elsif ($last_rev ne $full_rev) {
1319 $last_rev = $full_rev;
1320 $current_color = ++$current_color % $num_colors;
1322 print "<tr class=\"$rev_color[$current_color]\">\n";
1323 print "<td class=\"sha1\">" .
1324 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$full_rev;f=$file_name")}, esc_html
($rev)) . "</td>\n";
1325 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" . esc_html
($lineno) . "</a></td>\n";
1326 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
1331 close $fd or print "Reading blob failed\n";
1337 die_error
('403 Permission denied', "Permission denied.") if (!git_get_project_config_bool
('blame'));
1338 die_error
('404 Not Found', "What file will it be, master?") if (!$file_name);
1339 $hash_base ||= git_read_head
($project);
1340 die_error
(undef, "Reading commit failed.") unless ($hash_base);
1341 my %co = git_read_commit
($hash_base)
1342 or die_error
(undef, "Reading commit failed.");
1343 if (!defined $hash) {
1344 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
1345 or die_error
(undef, "Error lookup file.");
1347 open ($fd, "-|", $GIT, "annotate", '-l', '-t', '-r', $file_name, $hash_base)
1348 or die_error
(undef, "Open git-annotate failed.");
1351 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") .
1352 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;f=$file_name")}, "head");
1353 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1355 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html
($co{'title'})) .
1357 git_print_page_path
($file_name);
1358 print "<div class=\"page_body\">\n";
1360 <table class="blame">
1369 my @line_class = (qw(light dark));
1370 my $line_class_len = scalar (@line_class);
1371 my $line_class_num = $#line_class;
1372 while (my $line = <$fd>) {
1384 $line_class_num = ($line_class_num + 1) % $line_class_len;
1386 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) \+\d\d\d\d\t(\d+)\)(.*)$/) {
1393 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
1396 $short_rev = substr ($long_rev, 0, 8);
1397 $age = time () - $time;
1398 $age_str = age_string
($age);
1399 $age_str =~ s/ / /g;
1400 $age_class = age_class
($age);
1401 $author = esc_html
($author);
1402 $author =~ s/ / /g;
1404 while ((my $pos = index($data, "\t")) != -1) {
1405 if (my $count = (8 - ($pos % 8))) {
1406 my $spaces = ' ' x
$count;
1407 $data =~ s/\t/$spaces/;
1410 $data = esc_html
($data);
1413 <tr class="$line_class[$line_class_num]">
1414 <td class="sha1"><a href="$my_uri?${\esc_param ("p=$project;a=commit;h=$long_rev")}" class="text">$short_rev..</a></td>
1415 <td class="$age_class">$age_str</td>
1417 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
1418 <td class="pre">$data</td>
1421 } # while (my $line = <$fd>)
1422 print "</table>\n\n";
1423 close $fd or print "Reading blob failed.\n";
1429 my $head = git_read_head
($project);
1431 git_page_nav
('','', $head,undef,$head);
1432 my $taglist = git_read_refs
("refs/tags");
1434 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary"), -class => "title"}, " ") .
1436 print "<table cellspacing=\"0\">\n";
1438 if (defined @
$taglist) {
1439 foreach my $entry (@
$taglist) {
1441 my $comment_lines = $tag{'comment'};
1442 my $comment = shift @
$comment_lines;
1443 if (defined($comment)) {
1444 $comment = chop_str
($comment, 30, 5);
1447 print "<tr class=\"dark\">\n";
1449 print "<tr class=\"light\">\n";
1452 print "<td><i>$tag{'age'}</i></td>\n" .
1454 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), -class => "list"},
1455 "<b>" . esc_html
($tag{'name'}) . "</b>") .
1458 if (defined($comment)) {
1459 print $cgi->a({-class => "list", -href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, $comment);
1462 "<td class=\"link\">";
1463 if ($tag{'type'} eq "tag") {
1464 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
1466 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1467 if ($tag{'reftype'} eq "commit") {
1468 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1469 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'refid'}")}, "log");
1480 my $head = git_read_head
($project);
1482 git_page_nav
('','', $head,undef,$head);
1483 my $taglist = git_read_refs
("refs/heads");
1485 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary"), -class => "title"}, " ") .
1487 print "<table cellspacing=\"0\">\n";
1489 if (defined @
$taglist) {
1490 foreach my $entry (@
$taglist) {
1493 print "<tr class=\"dark\">\n";
1495 print "<tr class=\"light\">\n";
1498 print "<td><i>$tag{'age'}</i></td>\n" .
1500 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}"), -class => "list"}, "<b>" . esc_html
($tag{'name'}) . "</b>") .
1502 "<td class=\"link\">" .
1503 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1504 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'name'}")}, "log") .
1513 sub git_get_hash_by_path
{
1515 my $path = shift || return undef;
1519 open my $fd, "-|", $GIT, "ls-tree", $base, "--", $path
1520 or die_error
(undef, "Open git-ls-tree failed.");
1522 close $fd or return undef;
1524 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1525 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1529 sub mimetype_guess_file
{
1530 my $filename = shift;
1531 my $mimemap = shift;
1532 -r
$mimemap or return undef;
1535 open(MIME
, $mimemap) or return undef;
1537 my ($mime, $exts) = split(/\t+/);
1538 my @exts = split(/\s+/, $exts);
1539 foreach my $ext (@exts) {
1540 $mimemap{$ext} = $mime;
1545 $filename =~ /\.(.*?)$/;
1546 return $mimemap{$1};
1549 sub mimetype_guess
{
1550 my $filename = shift;
1552 $filename =~ /\./ or return undef;
1554 if ($mimetypes_file) {
1555 my $file = $mimetypes_file;
1556 #$file =~ m#^/# or $file = "$projectroot/$path/$file";
1557 $mime = mimetype_guess_file
($filename, $file);
1559 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1563 sub git_blob_plain_mimetype
{
1565 my $filename = shift;
1568 my $mime = mimetype_guess
($filename);
1569 $mime and return $mime;
1573 return $default_blob_plain_mimetype unless $fd;
1576 return 'text/plain' .
1577 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
1578 } elsif (! $filename) {
1579 return 'application/octet-stream';
1580 } elsif ($filename =~ m/\.png$/i) {
1582 } elsif ($filename =~ m/\.gif$/i) {
1584 } elsif ($filename =~ m/\.jpe?g$/i) {
1585 return 'image/jpeg';
1587 return 'application/octet-stream';
1591 sub git_blob_plain
{
1592 if (!defined $hash) {
1593 if (defined $file_name) {
1594 my $base = $hash_base || git_read_head
($project);
1595 $hash = git_get_hash_by_path
($base, $file_name, "blob")
1596 or die_error
(undef, "Error lookup file.");
1598 die_error
(undef, "No file name defined.");
1602 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
1603 or die_error
("Couldn't cat $file_name, $hash");
1605 $type ||= git_blob_plain_mimetype
($fd, $file_name);
1607 # save as filename, even when no $file_name is given
1608 my $save_as = "$hash";
1609 if (defined $file_name) {
1610 $save_as = $file_name;
1611 } elsif ($type =~ m/^text\//) {
1615 print $cgi->header(-type
=> "$type", '-content-disposition' => "inline; filename=\"$save_as\"");
1617 binmode STDOUT
, ':raw';
1619 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
1625 if (!defined $hash) {
1626 if (defined $file_name) {
1627 my $base = $hash_base || git_read_head
($project);
1628 $hash = git_get_hash_by_path
($base, $file_name, "blob")
1629 or die_error
(undef, "Error lookup file.");
1631 die_error
(undef, "No file name defined.");
1634 my $have_blame = git_get_project_config_bool
('blame');
1635 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
1636 or die_error
(undef, "Couldn't cat $file_name, $hash.");
1637 my $mimetype = git_blob_plain_mimetype
($fd, $file_name);
1638 if ($mimetype !~ m/^text\//) {
1640 return git_blob_plain
($mimetype);
1643 my $formats_nav = '';
1644 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
1645 if (defined $file_name) {
1647 $formats_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;h=$hash;hb=$hash_base;f=$file_name")}, "blame") . " | ";
1650 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$hash;f=$file_name")}, "plain") .
1651 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;hb=HEAD;f=$file_name")}, "head");
1653 $formats_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$hash")}, "plain");
1655 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1657 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html
($co{'title'})) .
1660 print "<div class=\"page_nav\">\n" .
1661 "<br/><br/></div>\n" .
1662 "<div class=\"title\">$hash</div>\n";
1664 git_print_page_path
($file_name, "blob");
1665 print "<div class=\"page_body\">\n";
1667 while (my $line = <$fd>) {
1670 while ((my $pos = index($line, "\t")) != -1) {
1671 if (my $count = (8 - ($pos % 8))) {
1672 my $spaces = ' ' x
$count;
1673 $line =~ s/\t/$spaces/;
1676 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", $nr, $nr, $nr, esc_html
($line);
1678 close $fd or print "Reading blob failed.\n";
1684 if (!defined $hash) {
1685 $hash = git_read_head
($project);
1686 if (defined $file_name) {
1687 my $base = $hash_base || $hash;
1688 $hash = git_get_hash_by_path
($base, $file_name, "tree");
1690 if (!defined $hash_base) {
1695 open my $fd, "-|", $GIT, "ls-tree", '-z', $hash
1696 or die_error
(undef, "Open git-ls-tree failed.");
1697 my @entries = map { chomp; $_ } <$fd>;
1698 close $fd or die_error
(undef, "Reading tree failed.");
1701 my $refs = read_info_ref
();
1703 if (defined $refs->{$hash_base}) {
1704 $ref = " <span class=\"tag\">" . esc_html
($refs->{$hash_base}) . "</span>";
1709 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
1710 $base_key = ";hb=$hash_base";
1711 git_page_nav
('tree','', $hash_base);
1713 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html
($co{'title'}) . $ref) . "\n" .
1716 print "<div class=\"page_nav\">\n";
1717 print "<br/><br/></div>\n";
1718 print "<div class=\"title\">$hash</div>\n";
1720 if (defined $file_name) {
1721 $base = esc_html
("$file_name/");
1723 git_print_page_path
($file_name);
1724 print "<div class=\"page_body\">\n";
1725 print "<table cellspacing=\"0\">\n";
1727 foreach my $line (@entries) {
1728 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1729 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1733 my $t_name = validate_input
($4);
1735 print "<tr class=\"dark\">\n";
1737 print "<tr class=\"light\">\n";
1740 print "<td class=\"mode\">" . mode_str
($t_mode) . "</td>\n";
1741 if ($t_type eq "blob") {
1742 print "<td class=\"list\">" .
1743 $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)) .
1745 "<td class=\"link\">" .
1746 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name")}, "blob") .
1747 # " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$t_hash$base_key;f=$base$t_name")}, "blame") .
1748 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;h=$t_hash;hb=$hash_base;f=$base$t_name")}, "history") .
1749 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$t_hash;f=$base$t_name")}, "raw") .
1751 } elsif ($t_type eq "tree") {
1752 print "<td class=\"list\">" .
1753 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, esc_html
($t_name)) .
1755 "<td class=\"link\">" .
1756 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, "tree") .
1757 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;hb=$hash_base;f=$base$t_name")}, "history") .
1762 print "</table>\n" .
1768 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
1769 open my $fd, "-|", $GIT, "rev-list", "--max-count=150", git_read_head
($project)
1770 or die_error
(undef, "Open git-rev-list failed.");
1771 my @revlist = map { chomp; $_ } <$fd>;
1772 close $fd or die_error
(undef, "Reading rev-list failed.");
1773 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
1774 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1775 "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
1776 print "<channel>\n";
1777 print "<title>$project</title>\n".
1778 "<link>" . esc_html
("$my_url?p=$project;a=summary") . "</link>\n".
1779 "<description>$project log</description>\n".
1780 "<language>en</language>\n";
1782 for (my $i = 0; $i <= $#revlist; $i++) {
1783 my $commit = $revlist[$i];
1784 my %co = git_read_commit
($commit);
1785 # we read 150, we always show 30 and the ones more recent than 48 hours
1786 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
1789 my %cd = date_str
($co{'committer_epoch'});
1790 open $fd, "-|", $GIT, "diff-tree", '-r', $co{'parent'}, $co{'id'} or next;
1791 my @difftree = map { chomp; $_ } <$fd>;
1795 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
1797 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
1798 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
1799 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
1800 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
1801 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
1802 "<content:encoded>" .
1804 my $comment = $co{'comment'};
1805 foreach my $line (@
$comment) {
1806 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
1807 print "$line<br/>\n";
1810 foreach my $line (@difftree) {
1811 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
1814 my $file = validate_input
(unquote
($7));
1815 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
1816 print "$file<br/>\n";
1819 "</content:encoded>\n" .
1822 print "</channel></rss>";
1826 my @list = git_read_projects
();
1828 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
1829 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1830 "<opml version=\"1.0\">\n".
1832 " <title>$site_name Git OPML Export</title>\n".
1835 "<outline text=\"git RSS feeds\">\n";
1837 foreach my $pr (@list) {
1839 my $head = git_read_head
($proj{'path'});
1840 if (!defined $head) {
1843 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
1844 my %co = git_read_commit
($head);
1849 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
1850 my $rss = "$my_url?p=$proj{'path'};a=rss";
1851 my $html = "$my_url?p=$proj{'path'};a=summary";
1852 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
1854 print "</outline>\n".
1860 my $head = git_read_head
($project);
1861 if (!defined $hash) {
1864 if (!defined $page) {
1867 my $refs = read_info_ref
();
1869 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
1870 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
1871 or die_error
(undef, "Open git-rev-list failed.");
1872 my @revlist = map { chomp; $_ } <$fd>;
1875 my $paging_nav = '';
1876 if ($hash ne $head || $page) {
1877 $paging_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "HEAD");
1879 $paging_nav .= "HEAD";
1882 $paging_nav .= " ⋅ " .
1883 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash;pg=" . ($page-1)), -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1885 $paging_nav .= " ⋅ prev";
1887 if ($#revlist >= (100 * ($page+1)-1)) {
1888 $paging_nav .= " ⋅ " .
1889 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash;pg=" . ($page+1)), -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1891 $paging_nav .= " ⋅ next";
1895 git_page_nav
('log','', $hash,undef,undef, $paging_nav);
1899 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary"), -class => "title"}, " ") .
1901 my %co = git_read_commit
($hash);
1902 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
1904 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
1905 my $commit = $revlist[$i];
1907 if (defined $refs->{$commit}) {
1908 $ref = " <span class=\"tag\">" . esc_html
($refs->{$commit}) . "</span>";
1910 my %co = git_read_commit
($commit);
1912 my %ad = date_str
($co{'author_epoch'});
1914 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "title"},
1915 "<span class=\"age\">$co{'age_string'}</span>" . esc_html
($co{'title'}) . $ref) . "\n";
1917 print "<div class=\"title_text\">\n" .
1918 "<div class=\"log_link\">\n" .
1919 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
1920 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1923 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
1925 "<div class=\"log_body\">\n";
1926 my $comment = $co{'comment'};
1928 foreach my $line (@
$comment) {
1929 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1940 print format_log_line_html
($line) . "<br/>\n";
1951 my %co = git_read_commit
($hash);
1953 die_error
(undef, "Unknown commit object.");
1955 my %ad = date_str
($co{'author_epoch'}, $co{'author_tz'});
1956 my %cd = date_str
($co{'committer_epoch'}, $co{'committer_tz'});
1958 my $parent = $co{'parent'};
1959 if (!defined $parent) {
1962 open my $fd, "-|", $GIT, "diff-tree", '-r', '-M', $parent, $hash
1963 or die_error
(undef, "Open git-diff-tree failed.");
1964 my @difftree = map { chomp; $_ } <$fd>;
1965 close $fd or die_error
(undef, "Reading git-diff-tree failed.");
1967 # non-textual hash id's can be cached
1969 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
1972 my $refs = read_info_ref
();
1974 if (defined $refs->{$co{'id'}}) {
1975 $ref = " <span class=\"tag\">" . esc_html
($refs->{$co{'id'}}) . "</span>";
1977 git_header_html
(undef, $expires);
1978 my $formats_nav = '';
1979 if (defined $file_name && defined $co{'parent'}) {
1980 my $parent = $co{'parent'};
1981 $formats_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;hb=$parent;f=$file_name")}, "blame");
1983 git_page_nav
('commit', defined $co{'parent'} ?
'' : 'commitdiff',
1984 $hash, $co{'tree'}, $hash,
1987 if (defined $co{'parent'}) {
1989 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash"), -class => "title"}, esc_html
($co{'title'}) . $ref) . "\n" .
1993 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash"), -class => "title"}, esc_html
($co{'title'})) . "\n" .
1996 print "<div class=\"title_text\">\n" .
1997 "<table cellspacing=\"0\">\n";
1998 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
2000 "<td></td><td> $ad{'rfc2822'}";
2001 if ($ad{'hour_local'} < 6) {
2002 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2004 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2008 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
2009 print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
2010 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
2013 "<td class=\"sha1\">" .
2014 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash"), class => "list"}, $co{'tree'}) .
2016 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
2019 my $parents = $co{'parents'};
2020 foreach my $par (@
$parents) {
2023 "<td class=\"sha1\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$par"), class => "list"}, $par) . "</td>" .
2024 "<td class=\"link\">" .
2025 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$par")}, "commit") .
2026 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash;hp=$par")}, "commitdiff") .
2032 print "<div class=\"page_body\">\n";
2033 my $comment = $co{'comment'};
2036 foreach my $line (@
$comment) {
2037 # print only one empty line
2039 if ($empty || $signed) {
2046 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2048 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2051 print format_log_line_html
($line) . "<br/>\n";
2055 print "<div class=\"list_head\">\n";
2056 if ($#difftree > 10) {
2057 print(($#difftree + 1) . " files changed:\n");
2060 print "<table class=\"diff_tree\">\n";
2062 foreach my $line (@difftree) {
2063 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2064 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2065 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
2073 my $similarity = $6;
2074 my $file = validate_input
(unquote
($7));
2076 print "<tr class=\"dark\">\n";
2078 print "<tr class=\"light\">\n";
2081 if ($status eq "A") {
2083 if (S_ISREG
(oct $to_mode)) {
2084 $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
2087 $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" .
2088 "<td><span class=\"file_status new\">[new " . file_type
($to_mode) . "$mode_chng]</span></td>\n" .
2089 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob") . "</td>\n";
2090 } elsif ($status eq "D") {
2092 $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" .
2093 "<td><span class=\"file_status deleted\">[deleted " . file_type
($from_mode). "]</span></td>\n" .
2094 "<td class=\"link\">" .
2095 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, "blob") .
2096 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;hb=$hash;f=$file")}, "history") .
2098 } elsif ($status eq "M" || $status eq "T") {
2099 my $mode_chnge = "";
2100 if ($from_mode != $to_mode) {
2101 $mode_chnge = " <span class=\"file_status mode_chnge\">[changed";
2102 if (((oct $from_mode) & S_IFMT
) != ((oct $to_mode) & S_IFMT
)) {
2103 $mode_chnge .= " from " . file_type
($from_mode) . " to " . file_type
($to_mode);
2105 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
2106 if (S_ISREG
($from_mode) && S_ISREG
($to_mode)) {
2107 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
2108 } elsif (S_ISREG
($to_mode)) {
2109 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
2112 $mode_chnge .= "]</span>\n";
2115 if ($to_id ne $from_id) {
2116 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));
2118 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file"), -class => "list"}, esc_html
($file));
2121 "<td>$mode_chnge</td>\n" .
2122 "<td class=\"link\">";
2123 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob");
2124 if ($to_id ne $from_id) {
2125 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file")}, "diff");
2127 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;hb=$hash;f=$file")}, "history") . "\n";
2129 } elsif ($status eq "R") {
2130 my ($from_file, $to_file) = split "\t", $file;
2132 if ($from_mode != $to_mode) {
2133 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
2136 $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" .
2137 "<td><span class=\"file_status moved\">[moved from " .
2138 $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)) .
2139 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
2140 "<td class=\"link\">" .
2141 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file")}, "blob");
2142 if ($to_id ne $from_id) {
2143 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file")}, "diff");
2154 mkdir($git_temp, 0700);
2156 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
2158 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff_plain;h=$hash;hp=$hash_parent")}, "plain");
2159 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2161 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html
($co{'title'})) . "\n" .
2164 print "<div class=\"page_nav\">\n" .
2165 "<br/><br/></div>\n" .
2166 "<div class=\"title\">$hash vs $hash_parent</div>\n";
2168 git_print_page_path
($file_name, "blob");
2169 print "<div class=\"page_body\">\n" .
2170 "<div class=\"diff_info\">blob:" .
2171 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name")}, $hash_parent) .
2173 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, $hash) .
2175 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
2180 sub git_blobdiff_plain
{
2181 mkdir($git_temp, 0700);
2182 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8');
2183 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
2186 sub git_commitdiff
{
2187 mkdir($git_temp, 0700);
2188 my %co = git_read_commit
($hash);
2190 die_error
(undef, "Unknown commit object.");
2192 if (!defined $hash_parent) {
2193 $hash_parent = $co{'parent'};
2195 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2196 or die_error
(undef, "Open git-diff-tree failed.");
2197 my @difftree = map { chomp; $_ } <$fd>;
2198 close $fd or die_error
(undef, "Reading diff-tree failed.");
2200 # non-textual hash id's can be cached
2202 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2205 my $refs = read_info_ref
();
2207 if (defined $refs->{$co{'id'}}) {
2208 $ref = " <span class=\"tag\">" . esc_html
($refs->{$co{'id'}}) . "</span>";
2210 git_header_html
(undef, $expires);
2212 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent")}, "plain");
2213 git_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
2215 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html
($co{'title'}) . $ref) . "\n" .
2217 print "<div class=\"page_body\">\n";
2218 my $comment = $co{'comment'};
2221 my @log = @
$comment;
2222 # remove first and empty lines after that
2224 while (defined $log[0] && $log[0] eq "") {
2227 foreach my $line (@log) {
2228 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2239 print format_log_line_html
($line) . "<br/>\n";
2242 foreach my $line (@difftree) {
2243 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2244 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2245 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2251 my $file = validate_input
(unquote
($6));
2252 if ($status eq "A") {
2253 print "<div class=\"diff_info\">" . file_type
($to_mode) . ":" .
2254 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id) . "(new)" .
2256 git_diff_print
(undef, "/dev/null", $to_id, "b/$file");
2257 } elsif ($status eq "D") {
2258 print "<div class=\"diff_info\">" . file_type
($from_mode) . ":" .
2259 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) . "(deleted)" .
2261 git_diff_print
($from_id, "a/$file", undef, "/dev/null");
2262 } elsif ($status eq "M") {
2263 if ($from_id ne $to_id) {
2264 print "<div class=\"diff_info\">" .
2265 file_type
($from_mode) . ":" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) .
2267 file_type
($to_mode) . ":" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id);
2269 git_diff_print
($from_id, "a/$file", $to_id, "b/$file");
2278 sub git_commitdiff_plain
{
2279 mkdir($git_temp, 0700);
2280 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2281 or die_error
(undef, "Open git-diff-tree failed.");
2282 my @difftree = map { chomp; $_ } <$fd>;
2283 close $fd or die_error
(undef, "Reading diff-tree failed.");
2285 # try to figure out the next tag after this commit
2287 my $refs = read_info_ref
("tags");
2288 open $fd, "-|", $GIT, "rev-list", "HEAD";
2289 my @commits = map { chomp; $_ } <$fd>;
2291 foreach my $commit (@commits) {
2292 if (defined $refs->{$commit}) {
2293 $tagname = $refs->{$commit}
2295 if ($commit eq $hash) {
2300 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8', '-content-disposition' => "inline; filename=\"git-$hash.patch\"");
2301 my %co = git_read_commit
($hash);
2302 my %ad = date_str
($co{'author_epoch'}, $co{'author_tz'});
2303 my $comment = $co{'comment'};
2304 print "From: $co{'author'}\n" .
2305 "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
2306 "Subject: $co{'title'}\n";
2307 if (defined $tagname) {
2308 print "X-Git-Tag: $tagname\n";
2310 print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
2313 foreach my $line (@
$comment) {;
2318 foreach my $line (@difftree) {
2319 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2324 if ($status eq "A") {
2325 git_diff_print
(undef, "/dev/null", $to_id, "b/$file", "plain");
2326 } elsif ($status eq "D") {
2327 git_diff_print
($from_id, "a/$file", undef, "/dev/null", "plain");
2328 } elsif ($status eq "M") {
2329 git_diff_print
($from_id, "a/$file", $to_id, "b/$file", "plain");
2335 if (!defined $hash_base) {
2336 $hash_base = git_read_head
($project);
2339 my %co = git_read_commit
($hash_base);
2341 die_error
(undef, "Unknown commit object.");
2343 my $refs = read_info_ref
();
2345 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base);
2347 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html
($co{'title'})) . "\n" .
2349 if (!defined $hash && defined $file_name) {
2350 $hash = git_get_hash_by_path
($hash_base, $file_name);
2352 if (defined $hash) {
2353 $ftype = git_get_type
($hash);
2355 git_print_page_path
($file_name, $ftype);
2358 $GIT, "rev-list", "--full-history", $hash_base, "--", "\'$file_name\'";
2359 print "<table cellspacing=\"0\">\n";
2361 while (my $line = <$fd>) {
2362 if ($line =~ m/^([0-9a-fA-F]{40})/){
2364 my %co = git_read_commit
($commit);
2369 if (defined $refs->{$commit}) {
2370 $ref = " <span class=\"tag\">" . esc_html
($refs->{$commit}) . "</span>";
2373 print "<tr class=\"dark\">\n";
2375 print "<tr class=\"light\">\n";
2378 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2379 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2380 "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list"}, "<b>" .
2381 esc_html
(chop_str
($co{'title'}, 50)) . "$ref</b>") . "</td>\n" .
2382 "<td class=\"link\">" .
2383 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
2384 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2385 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;hb=$commit;f=$file_name")}, "blob");
2386 my $blob = git_get_hash_by_path
($hash_base, $file_name);
2387 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2388 if (defined $blob && defined $blob_parent && $blob ne $blob_parent) {
2390 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=$file_name")},
2403 if (!defined $searchtext) {
2404 die_error
("", "Text field empty.");
2406 if (!defined $hash) {
2407 $hash = git_read_head
($project);
2409 my %co = git_read_commit
($hash);
2411 die_error
(undef, "Unknown commit object.");
2413 # pickaxe may take all resources of your box and run for several minutes
2414 # with every query - so decide by yourself how public you make this feature :)
2415 my $commit_search = 1;
2416 my $author_search = 0;
2417 my $committer_search = 0;
2418 my $pickaxe_search = 0;
2419 if ($searchtext =~ s/^author\\://i) {
2421 } elsif ($searchtext =~ s/^committer\\://i) {
2422 $committer_search = 1;
2423 } elsif ($searchtext =~ s/^pickaxe\\://i) {
2425 $pickaxe_search = 1;
2428 git_page_nav
('','', $hash,$co{'tree'},$hash);
2431 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html
($co{'title'})) . "\n" .
2433 print "<table cellspacing=\"0\">\n";
2435 if ($commit_search) {
2437 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", $hash or next;
2438 while (my $commit_text = <$fd>) {
2439 if (!grep m/$searchtext/i, $commit_text) {
2442 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
2445 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
2448 my @commit_lines = split "\n", $commit_text;
2449 my %co = git_read_commit
(undef, \
@commit_lines);
2454 print "<tr class=\"dark\">\n";
2456 print "<tr class=\"light\">\n";
2459 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2460 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2462 $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/>");
2463 my $comment = $co{'comment'};
2464 foreach my $line (@
$comment) {
2465 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2466 my $lead = esc_html
($1) || "";
2467 $lead = chop_str
($lead, 30, 10);
2468 my $match = esc_html
($2) || "";
2469 my $trail = esc_html
($3) || "";
2470 $trail = chop_str
($trail, 30, 10);
2471 my $text = "$lead<span class=\"match\">$match</span>$trail";
2472 print chop_str
($text, 80, 5) . "<br/>\n";
2476 "<td class=\"link\">" .
2477 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2478 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2485 if ($pickaxe_search) {
2487 open my $fd, "-|", "$GIT rev-list $hash | $GIT diff-tree -r --stdin -S\'$searchtext\'";
2490 while (my $line = <$fd>) {
2491 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2494 $set{'from_id'} = $3;
2496 $set{'id'} = $set{'to_id'};
2497 if ($set{'id'} =~ m/0{40}/) {
2498 $set{'id'} = $set{'from_id'};
2500 if ($set{'id'} =~ m/0{40}/) {
2504 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
2507 print "<tr class=\"dark\">\n";
2509 print "<tr class=\"light\">\n";
2512 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2513 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2515 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" .
2516 esc_html
(chop_str
($co{'title'}, 50)) . "</b><br/>");
2517 while (my $setref = shift @files) {
2519 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}"), class => "list"},
2520 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
2524 "<td class=\"link\">" .
2525 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2526 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2530 %co = git_read_commit
($1);
2540 my $head = git_read_head
($project);
2541 if (!defined $hash) {
2544 if (!defined $page) {
2547 my $refs = read_info_ref
();
2549 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2550 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2551 or die_error
(undef, "Open git-rev-list failed.");
2552 my @revlist = map { chomp; $_ } <$fd>;
2555 my $paging_nav = '';
2556 if ($hash ne $head || $page) {
2557 $paging_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "HEAD");
2559 $paging_nav .= "HEAD";
2562 $paging_nav .= " ⋅ " .
2563 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash;pg=" . ($page-1)), -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2565 $paging_nav .= " ⋅ prev";
2567 if ($#revlist >= (100 * ($page+1)-1)) {
2568 $paging_nav .= " ⋅ " .
2569 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)), -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2571 $paging_nav .= " ⋅ next";
2575 git_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
2578 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary"), -class => "title"}, " ") .
2580 print "<table cellspacing=\"0\">\n";
2582 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2583 my $commit = $revlist[$i];
2585 if (defined $refs->{$commit}) {
2586 $ref = " <span class=\"tag\">" . esc_html
($refs->{$commit}) . "</span>";
2588 my %co = git_read_commit
($commit);
2589 my %ad = date_str
($co{'author_epoch'});
2591 print "<tr class=\"dark\">\n";
2593 print "<tr class=\"light\">\n";
2596 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2597 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
2599 if (length($co{'title_short'}) < length($co{'title'})) {
2600 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list", -title
=> "$co{'title'}"},
2601 "<b>" . esc_html
($co{'title_short'}) . "$ref</b>");
2603 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list"},
2604 "<b>" . esc_html
($co{'title_short'}) . "$ref</b>");
2607 "<td class=\"link\">" .
2608 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
2609 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2613 if ($#revlist >= (100 * ($page+1)-1)) {
2616 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)), -title
=> "Alt-n"}, "next") .