3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI
qw(:standard :escapeHTML -nosticky);
13 use CGI
::Util
qw(unescape);
14 use CGI
::Carp
qw(fatalsToBrowser);
17 binmode STDOUT
, ':utf8';
21 my $my_url = $cgi->url();
22 my $my_uri = $cgi->url(-absolute
=> 1);
25 # absolute fs-path which will be prepended to the project path
26 #my $projectroot = "/pub/scm";
27 my $projectroot = "/home/kay/public_html/pub/scm";
29 # location of the git-core binaries
30 my $gitbin = "/usr/bin";
32 # location for temporary files needed for diffs
33 my $git_temp = "/tmp/gitweb";
35 # target of the home link on top of all pages
36 my $home_link = $my_uri;
38 # html text to include at home page
39 my $home_text = "indextext.html";
41 # URI of default stylesheet
42 my $stylesheet = "gitweb.css";
44 # source of projects list
45 #my $projects_list = $projectroot;
46 my $projects_list = "index/index.aux";
48 # default blob_plain mimetype and default charset for text/plain blob
49 my $default_blob_plain_mimetype = 'text/plain';
50 my $default_text_plain_charset = undef;
52 # file to use for guessing MIME types before trying /etc/mime.types
53 # (relative to the current git repository)
54 my $mimetypes_file = undef;
57 # input validation and dispatch
58 my $action = $cgi->param('a');
59 if (defined $action) {
60 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
62 die_error
(undef, "Invalid action parameter.");
64 if ($action eq "git-logo.png") {
67 } elsif ($action eq "opml") {
73 my $order = $cgi->param('o');
75 if ($order =~ m/[^0-9a-zA-Z_]/) {
77 die_error
(undef, "Invalid order parameter.");
81 my $project = $cgi->param('p');
82 if (defined $project) {
83 $project = validate_input
($project);
84 if (!defined($project)) {
85 die_error
(undef, "Invalid project parameter.");
87 if (!(-d
"$projectroot/$project")) {
89 die_error
(undef, "No such directory.");
91 if (!(-e
"$projectroot/$project/HEAD")) {
93 die_error
(undef, "No such project.");
95 $rss_link = "<link rel=\"alternate\" title=\"" . esc_param
($project) . " log\" href=\"" .
96 "$my_uri?" . esc_param
("p=$project;a=rss") . "\" type=\"application/rss+xml\"/>";
97 $ENV{'GIT_DIR'} = "$projectroot/$project";
103 my $file_name = $cgi->param('f');
104 if (defined $file_name) {
105 $file_name = validate_input
($file_name);
106 if (!defined($file_name)) {
107 die_error
(undef, "Invalid file parameter.");
111 my $hash = $cgi->param('h');
113 $hash = validate_input
($hash);
114 if (!defined($hash)) {
115 die_error
(undef, "Invalid hash parameter.");
119 my $hash_parent = $cgi->param('hp');
120 if (defined $hash_parent) {
121 $hash_parent = validate_input
($hash_parent);
122 if (!defined($hash_parent)) {
123 die_error
(undef, "Invalid hash parent parameter.");
127 my $hash_base = $cgi->param('hb');
128 if (defined $hash_base) {
129 $hash_base = validate_input
($hash_base);
130 if (!defined($hash_base)) {
131 die_error
(undef, "Invalid hash base parameter.");
135 my $page = $cgi->param('pg');
137 if ($page =~ m/[^0-9]$/) {
139 die_error
(undef, "Invalid page parameter.");
143 my $searchtext = $cgi->param('s');
144 if (defined $searchtext) {
145 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
147 die_error
(undef, "Invalid search parameter.");
149 $searchtext = quotemeta $searchtext;
155 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
158 if ($input =~ m/(^|\/)(|\
.|\
.\
.)($|\
/)/) {
161 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\
-\
+\#\
~\
%]/) {
167 if (!defined $action || $action eq "summary") {
170 } elsif ($action eq "heads") {
173 } elsif ($action eq "tags") {
176 } elsif ($action eq "blob") {
179 } elsif ($action eq "blob_plain") {
182 } elsif ($action eq "tree") {
185 } elsif ($action eq "rss") {
188 } elsif ($action eq "commit") {
191 } elsif ($action eq "log") {
194 } elsif ($action eq "blobdiff") {
197 } elsif ($action eq "blobdiff_plain") {
198 git_blobdiff_plain
();
200 } elsif ($action eq "commitdiff") {
203 } elsif ($action eq "commitdiff_plain") {
204 git_commitdiff_plain
();
206 } elsif ($action eq "history") {
209 } elsif ($action eq "search") {
212 } elsif ($action eq "shortlog") {
215 } elsif ($action eq "tag") {
218 } elsif ($action eq "blame") {
223 die_error
(undef, "Unknown action.");
227 # quote unsafe chars, but keep the slash, even when it's not
228 # correct, but quoted slashes look too horrible in bookmarks
231 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
237 # replace invalid utf8 character with SUBSTITUTION sequence
240 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
241 $str = escapeHTML
($str);
245 # git may return quoted and escaped filenames
248 if ($str =~ m/^"(.*)"$/) {
250 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
255 # CSS class for given age value (in seconds)
259 if ($age < 60*60*2) {
261 } elsif ($age < 60*60*24*2) {
268 sub git_header_html
{
269 my $status = shift || "200 OK";
273 if (defined $project) {
274 $title .= " - $project";
275 if (defined $action) {
276 $title .= "/$action";
277 if (defined $file_name) {
278 $title .= " - $file_name";
279 if ($action eq "tree" && $file_name !~ m
|/$|) {
285 print $cgi->header(-type
=>'text/html', -charset
=> 'utf-8', -status
=> $status, -expires
=> $expires);
287 <?xml version="1.0" encoding="utf-8"?>
288 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
289 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
290 <!-- git web interface v$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
292 <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
293 <meta name="robots" content="index, nofollow"/>
294 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
295 <title>$title</title>
300 print "<div class=\"page_header\">\n" .
301 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
302 "<img src=\"$my_uri?" . esc_param
("a=git-logo.png") . "\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
304 print $cgi->a({-href
=> esc_param
($home_link)}, "projects") . " / ";
305 if (defined $project) {
306 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, esc_html
($project));
307 if (defined $action) {
311 if (!defined $searchtext) {
316 $search_hash = $hash;
318 $search_hash = "HEAD";
320 $cgi->param("a", "search");
321 $cgi->param("h", $search_hash);
322 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
323 "<div class=\"search\">\n" .
324 $cgi->hidden(-name
=> "p") . "\n" .
325 $cgi->hidden(-name
=> "a") . "\n" .
326 $cgi->hidden(-name
=> "h") . "\n" .
327 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
329 $cgi->end_form() . "\n";
334 sub git_footer_html
{
335 print "<div class=\"page_footer\">\n";
336 if (defined $project) {
337 my $descr = git_read_description
($project);
338 if (defined $descr) {
339 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
341 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=rss"), -class => "rss_logo"}, "RSS") . "\n";
343 print $cgi->a({-href
=> "$my_uri?" . esc_param
("a=opml"), -class => "rss_logo"}, "OPML") . "\n";
351 my $status = shift || "403 Forbidden";
352 my $error = shift || "Malformed query, file missing or permission denied";
354 git_header_html
($status);
355 print "<div class=\"page_body\">\n" .
357 "$status - $error\n" .
367 open my $fd, "-|", "$gitbin/git-cat-file -t $hash" or return;
376 my $oENV = $ENV{'GIT_DIR'};
378 $ENV{'GIT_DIR'} = "$projectroot/$project";
379 if (open my $fd, "-|", "$gitbin/git-rev-parse", "--verify", "HEAD") {
382 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
387 $ENV{'GIT_DIR'} = $oENV;
395 open my $fd, "$projectroot/$path" or return undef;
399 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
404 sub git_read_description
{
407 open my $fd, "$projectroot/$path/description" or return undef;
419 open my $fd, "-|", "$gitbin/git-cat-file tag $tag_id" or return;
420 $tag{'id'} = $tag_id;
421 while (my $line = <$fd>) {
423 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
425 } elsif ($line =~ m/^type (.+)$/) {
427 } elsif ($line =~ m/^tag (.+)$/) {
429 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
433 } elsif ($line =~ m/--BEGIN/) {
434 push @comment, $line;
436 } elsif ($line eq "") {
440 push @comment, <$fd>;
441 $tag{'comment'} = \
@comment;
443 if (!defined $tag{'name'}) {
453 if ($age > 60*60*24*365*2) {
454 $age_str = (int $age/60/60/24/365);
455 $age_str .= " years ago";
456 } elsif ($age > 60*60*24*(365/12)*2) {
457 $age_str = int $age/60/60/24/(365/12);
458 $age_str .= " months ago";
459 } elsif ($age > 60*60*24*7*2) {
460 $age_str = int $age/60/60/24/7;
461 $age_str .= " weeks ago";
462 } elsif ($age > 60*60*24*2) {
463 $age_str = int $age/60/60/24;
464 $age_str .= " days ago";
465 } elsif ($age > 60*60*2) {
466 $age_str = int $age/60/60;
467 $age_str .= " hours ago";
468 } elsif ($age > 60*2) {
469 $age_str = int $age/60;
470 $age_str .= " min ago";
473 $age_str .= " sec ago";
475 $age_str .= " right now";
480 sub git_read_commit
{
481 my $commit_id = shift;
482 my $commit_text = shift;
487 if (defined $commit_text) {
488 @commit_lines = @
$commit_text;
491 open my $fd, "-|", "$gitbin/git-rev-list --header --parents --max-count=1 $commit_id" or return;
492 @commit_lines = split '\n', <$fd>;
497 my $header = shift @commit_lines;
498 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
501 ($co{'id'}, my @parents) = split ' ', $header;
502 $co{'parents'} = \
@parents;
503 $co{'parent'} = $parents[0];
504 while (my $line = shift @commit_lines) {
505 last if $line eq "\n";
506 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
508 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
510 $co{'author_epoch'} = $2;
511 $co{'author_tz'} = $3;
512 if ($co{'author'} =~ m/^([^<]+) </) {
513 $co{'author_name'} = $1;
515 $co{'author_name'} = $co{'author'};
517 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
518 $co{'committer'} = $1;
519 $co{'committer_epoch'} = $2;
520 $co{'committer_tz'} = $3;
521 $co{'committer_name'} = $co{'committer'};
522 $co{'committer_name'} =~ s/ <.*//;
525 if (!defined $co{'tree'}) {
529 foreach my $title (@commit_lines) {
532 $co{'title'} = chop_str
($title, 80, 5);
533 # remove leading stuff of merges to make the interesting part visible
534 if (length($title) > 50) {
535 $title =~ s/^Automatic //;
536 $title =~ s/^merge (of|with) /Merge ... /i;
537 if (length($title) > 50) {
538 $title =~ s/(http|rsync):\/\///;
540 if (length($title) > 50) {
541 $title =~ s/(master|www|rsync)\.//;
543 if (length($title) > 50) {
544 $title =~ s/kernel.org:?//;
546 if (length($title) > 50) {
547 $title =~ s/\/pub\/scm//;
550 $co{'title_short'} = chop_str
($title, 50, 5);
554 # remove added spaces
555 foreach my $line (@commit_lines) {
558 $co{'comment'} = \
@commit_lines;
560 my $age = time - $co{'committer_epoch'};
562 $co{'age_string'} = age_string
($age);
563 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
564 if ($age > 60*60*24*7*2) {
565 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
566 $co{'age_string_age'} = $co{'age_string'};
568 $co{'age_string_date'} = $co{'age_string'};
569 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
576 my $from_name = shift;
579 my $format = shift || "html";
581 my $from_tmp = "/dev/null";
582 my $to_tmp = "/dev/null";
585 # create tmp from-file
587 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
588 open my $fd2, "> $from_tmp";
589 open my $fd, "-|", "$gitbin/git-cat-file blob $from";
598 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
599 open my $fd2, "> $to_tmp";
600 open my $fd, "-|", "$gitbin/git-cat-file blob $to";
607 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
608 if ($format eq "plain") {
613 while (my $line = <$fd>) {
615 my $char = substr($line, 0, 1);
618 $diff_class = " add";
619 } elsif ($char eq "-") {
620 $diff_class = " rem";
621 } elsif ($char eq "@") {
622 $diff_class = " chunk_header";
623 } elsif ($char eq "\\") {
627 while ((my $pos = index($line, "\t")) != -1) {
628 if (my $count = (8 - (($pos-1) % 8))) {
629 my $spaces = ' ' x
$count;
630 $line =~ s/\t/$spaces/;
633 print "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
647 my $mode = oct shift;
649 if (S_ISDIR
($mode & S_IFMT
)) {
651 } elsif (S_ISLNK
($mode)) {
653 } elsif (S_ISREG
($mode)) {
654 # git cares only about the executable bit
655 if ($mode & S_IXUSR
) {
668 my $add_len = shift || 10;
670 # allow only $len chars, but don't cut a word if it would fit in $add_len
671 # if it doesn't fit, cut it if it's still longer than the dots we would add
672 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
675 if (length($tail) > 4) {
682 my $mode = oct shift;
684 if (S_ISDIR
($mode & S_IFMT
)) {
686 } elsif (S_ISLNK
($mode)) {
688 } elsif (S_ISREG
($mode)) {
695 sub format_log_line_html
{
698 $line = esc_html
($line);
699 $line =~ s/ / /g;
700 if ($line =~ m/([0-9a-fA-F]{40})/) {
702 if (git_get_type
($hash_text) eq "commit") {
703 my $link = $cgi->a({-class => "text", -href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_text")}, $hash_text);
704 $line =~ s/$hash_text/$link/;
712 my $tz = shift || "-0000";
715 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
716 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
717 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
718 $date{'hour'} = $hour;
719 $date{'minute'} = $min;
720 $date{'mday'} = $mday;
721 $date{'day'} = $days[$wday];
722 $date{'month'} = $months[$mon];
723 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
724 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
726 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
727 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
728 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
729 $date{'hour_local'} = $hour;
730 $date{'minute_local'} = $min;
731 $date{'tz_local'} = $tz;
735 # git-logo (cached in browser for one day)
737 binmode STDOUT
, ':raw';
738 print $cgi->header(-type
=> 'image/png', -expires
=> '+1d');
739 # cat git-logo.png | hexdump -e '16/1 " %02x" "\n"' | sed 's/ /\\x/g'
740 print "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52" .
741 "\x00\x00\x00\x48\x00\x00\x00\x1b\x04\x03\x00\x00\x00\x2d\xd9\xd4" .
742 "\x2d\x00\x00\x00\x18\x50\x4c\x54\x45\xff\xff\xff\x60\x60\x5d\xb0" .
743 "\xaf\xaa\x00\x80\x00\xce\xcd\xc7\xc0\x00\x00\xe8\xe8\xe6\xf7\xf7" .
744 "\xf6\x95\x0c\xa7\x47\x00\x00\x00\x73\x49\x44\x41\x54\x28\xcf\x63" .
745 "\x48\x67\x20\x04\x4a\x5c\x18\x0a\x08\x2a\x62\x53\x61\x20\x02\x08" .
746 "\x0d\x69\x45\xac\xa1\xa1\x01\x30\x0c\x93\x60\x36\x26\x52\x91\xb1" .
747 "\x01\x11\xd6\xe1\x55\x64\x6c\x6c\xcc\x6c\x6c\x0c\xa2\x0c\x70\x2a" .
748 "\x62\x06\x2a\xc1\x62\x1d\xb3\x01\x02\x53\xa4\x08\xe8\x00\x03\x18" .
749 "\x26\x56\x11\xd4\xe1\x20\x97\x1b\xe0\xb4\x0e\x35\x24\x71\x29\x82" .
750 "\x99\x30\xb8\x93\x0a\x11\xb9\x45\x88\xc1\x8d\xa0\xa2\x44\x21\x06" .
751 "\x27\x41\x82\x40\x85\xc1\x45\x89\x20\x70\x01\x00\xa4\x3d\x21\xc5" .
752 "\x12\x1c\x9a\xfe\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\x82";
758 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
759 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
760 if (!defined $gcos) {
764 $owner =~ s/[,;].*$//;
765 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
768 sub git_read_projects
{
771 if (-d
$projects_list) {
772 # search in directory
773 my $dir = $projects_list;
774 opendir my $dh, $dir or return undef;
775 while (my $dir = readdir($dh)) {
776 if (-e
"$projectroot/$dir/HEAD") {
784 } elsif (-f
$projects_list) {
785 # read from file(url-encoded):
786 # 'git%2Fgit.git Linus+Torvalds'
787 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
788 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
789 open my $fd , $projects_list or return undef;
790 while (my $line = <$fd>) {
792 my ($path, $owner) = split ' ', $line;
793 $path = unescape
($path);
794 $owner = unescape
($owner);
795 if (!defined $path) {
798 if (-e
"$projectroot/$path/HEAD") {
801 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
808 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
812 sub git_get_project_config
{
815 return unless ($key);
816 $key =~ s/^gitweb\.//;
817 return if ($key =~ m/\W/);
819 my $val = qx(git
-repo
-config
--get gitweb
.$key);
823 sub git_get_project_config_bool
{
824 my $val = git_get_project_config
(@_);
825 if ($val and $val =~ m/true|yes|on/) {
828 return; # implicit false
831 sub git_project_list
{
832 my @list = git_read_projects
();
835 die_error
(undef, "No project found.");
837 foreach my $pr (@list) {
838 my $head = git_read_head
($pr->{'path'});
839 if (!defined $head) {
842 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
843 my %co = git_read_commit
($head);
847 $pr->{'commit'} = \
%co;
848 if (!defined $pr->{'descr'}) {
849 my $descr = git_read_description
($pr->{'path'}) || "";
850 $pr->{'descr'} = chop_str
($descr, 25, 5);
852 if (!defined $pr->{'owner'}) {
853 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
859 print "<div class=\"index_include\">\n";
860 open (my $fd, $home_text);
865 print "<table class=\"project_list\">\n" .
867 if (!defined($order) || (defined($order) && ($order eq "project"))) {
868 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
869 print "<th>Project</th>\n";
871 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=project")}, "Project") . "</th>\n";
873 if (defined($order) && ($order eq "descr")) {
874 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
875 print "<th>Description</th>\n";
877 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=descr")}, "Description") . "</th>\n";
879 if (defined($order) && ($order eq "owner")) {
880 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
881 print "<th>Owner</th>\n";
883 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=owner")}, "Owner") . "</th>\n";
885 if (defined($order) && ($order eq "age")) {
886 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
887 print "<th>Last Change</th>\n";
889 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=age")}, "Last Change") . "</th>\n";
891 print "<th></th>\n" .
894 foreach my $pr (@projects) {
896 print "<tr class=\"dark\">\n";
898 print "<tr class=\"light\">\n";
901 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=summary"), -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
902 "<td>$pr->{'descr'}</td>\n" .
903 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
904 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" . $pr->{'commit'}{'age_string'} . "</td>\n" .
905 "<td class=\"link\">" .
906 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=summary")}, "summary") .
907 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=shortlog")}, "shortlog") .
908 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=log")}, "log") .
917 my $type = shift || "";
919 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
920 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
921 open my $fd, "$projectroot/$project/info/refs" or return;
922 while (my $line = <$fd>) {
924 if ($line =~ m/^([0-9a-fA-F]{40})\t.*$type\/([^\
^]+)/) {
925 if (defined $refs{$1}) {
926 $refs{$1} .= " / $2";
941 opendir my $dh, "$projectroot/$project/$ref_dir";
942 while (my $dir = readdir($dh)) {
943 if ($dir =~ m/^\./) {
946 if (-d
"$projectroot/$project/$ref_dir/$dir") {
947 opendir my $dh2, "$projectroot/$project/$ref_dir/$dir";
948 my @subdirs = grep !m/^\./, readdir $dh2;
950 foreach my $subdir (@subdirs) {
951 push @refs, "$dir/$subdir"
958 foreach my $ref_file (@refs) {
959 my $ref_id = git_read_hash
("$project/$ref_dir/$ref_file");
960 my $type = git_get_type
($ref_id) || next;
963 $ref_item{'type'} = $type;
964 $ref_item{'id'} = $ref_id;
965 $ref_item{'epoch'} = 0;
966 $ref_item{'age'} = "unknown";
967 if ($type eq "tag") {
968 my %tag = git_read_tag
($ref_id);
969 $ref_item{'comment'} = $tag{'comment'};
970 if ($tag{'type'} eq "commit") {
971 %co = git_read_commit
($tag{'object'});
972 $ref_item{'epoch'} = $co{'committer_epoch'};
973 $ref_item{'age'} = $co{'age_string'};
974 } elsif (defined($tag{'epoch'})) {
975 my $age = time - $tag{'epoch'};
976 $ref_item{'epoch'} = $tag{'epoch'};
977 $ref_item{'age'} = age_string
($age);
979 $ref_item{'reftype'} = $tag{'type'};
980 $ref_item{'name'} = $tag{'name'};
981 $ref_item{'refid'} = $tag{'object'};
982 } elsif ($type eq "commit"){
983 %co = git_read_commit
($ref_id);
984 $ref_item{'reftype'} = "commit";
985 $ref_item{'name'} = $ref_file;
986 $ref_item{'title'} = $co{'title'};
987 $ref_item{'refid'} = $ref_id;
988 $ref_item{'epoch'} = $co{'committer_epoch'};
989 $ref_item{'age'} = $co{'age_string'};
992 push @reflist, \
%ref_item;
995 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1000 my $descr = git_read_description
($project) || "none";
1001 my $head = git_read_head
($project);
1002 my %co = git_read_commit
($head);
1003 my %cd = date_str
($co{'committer_epoch'}, $co{'committer_tz'});
1006 if (-f
$projects_list) {
1007 open (my $fd , $projects_list);
1008 while (my $line = <$fd>) {
1010 my ($pr, $ow) = split ' ', $line;
1011 $pr = unescape
($pr);
1012 $ow = unescape
($ow);
1013 if ($pr eq $project) {
1014 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
1020 if (!defined $owner) {
1021 $owner = get_file_owner
("$projectroot/$project");
1024 my $refs = read_info_ref
();
1026 print "<div class=\"page_nav\">\n" .
1028 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1029 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1030 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$head")}, "commit") .
1031 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1032 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree")}, "tree") .
1035 print "<div class=\"title\"> </div>\n";
1036 print "<table cellspacing=\"0\">\n" .
1037 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
1038 "<tr><td>owner</td><td>$owner</td></tr>\n" .
1039 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
1041 open my $fd, "-|", "$gitbin/git-rev-list --max-count=17 " . git_read_head
($project) or die_error
(undef, "Open failed.");
1042 my (@revlist) = map { chomp; $_ } <$fd>;
1045 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog"), -class => "title"}, "shortlog") .
1048 print "<table cellspacing=\"0\">\n";
1050 foreach my $commit (@revlist) {
1051 my %co = git_read_commit
($commit);
1052 my %ad = date_str
($co{'author_epoch'});
1054 print "<tr class=\"dark\">\n";
1056 print "<tr class=\"light\">\n";
1061 if (defined $refs->{$commit}) {
1062 $ref = " <span class=\"tag\">" . esc_html
($refs->{$commit}) . "</span>";
1064 print "<td><i>$co{'age_string'}</i></td>\n" .
1065 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
1067 if (length($co{'title_short'}) < length($co{'title'})) {
1068 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list", -title
=> "$co{'title'}"},
1069 "<b>" . esc_html
($co{'title_short'}) . "$ref</b>");
1071 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list"},
1072 "<b>" . esc_html
($co{'title'}) . "$ref</b>");
1075 "<td class=\"link\">" .
1076 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
1077 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1081 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "...") . "</td>\n" .
1088 my $taglist = git_read_refs
("refs/tags");
1089 if (defined @
$taglist) {
1091 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tags"), -class => "title"}, "tags") .
1094 print "<table cellspacing=\"0\">\n";
1096 foreach my $entry (@
$taglist) {
1098 my $comment_lines = $tag{'comment'};
1099 my $comment = shift @
$comment_lines;
1100 if (defined($comment)) {
1101 $comment = chop_str
($comment, 30, 5);
1104 print "<tr class=\"dark\">\n";
1106 print "<tr class=\"light\">\n";
1110 print "<td><i>$tag{'age'}</i></td>\n" .
1112 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), -class => "list"},
1113 "<b>" . esc_html
($tag{'name'}) . "</b>") .
1116 if (defined($comment)) {
1117 print $cgi->a({-class => "list", -href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, $comment);
1120 "<td class=\"link\">";
1121 if ($tag{'type'} eq "tag") {
1122 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
1124 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1125 if ($tag{'reftype'} eq "commit") {
1126 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1127 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'refid'}")}, "log");
1132 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tags")}, "...") . "</td>\n" .
1140 my $headlist = git_read_refs
("refs/heads");
1141 if (defined @
$headlist) {
1143 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=heads"), -class => "title"}, "heads") .
1146 print "<table cellspacing=\"0\">\n";
1148 foreach my $entry (@
$headlist) {
1151 print "<tr class=\"dark\">\n";
1153 print "<tr class=\"light\">\n";
1157 print "<td><i>$tag{'age'}</i></td>\n" .
1159 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}"), -class => "list"},
1160 "<b>" . esc_html
($tag{'name'}) . "</b>") .
1162 "<td class=\"link\">" .
1163 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1164 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'name'}")}, "log") .
1168 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=heads")}, "...") . "</td>\n" .
1179 my $head = git_read_head
($project);
1181 print "<div class=\"page_nav\">\n" .
1182 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1183 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1184 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1185 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$head")}, "commit") .
1186 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1187 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1190 my %tag = git_read_tag
($hash);
1192 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html
($tag{'name'})) . "\n" .
1194 print "<div class=\"title_text\">\n" .
1195 "<table cellspacing=\"0\">\n" .
1197 "<td>object</td>\n" .
1198 "<td>" . $cgi->a({-class => "list", -href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'object'}) . "</td>\n" .
1199 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'type'}) . "</td>\n" .
1201 if (defined($tag{'author'})) {
1202 my %ad = date_str
($tag{'epoch'}, $tag{'tz'});
1203 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
1204 print "<tr><td></td><td>" . $ad{'rfc2822'} . sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) . "</td></tr>\n";
1206 print "</table>\n\n" .
1208 print "<div class=\"page_body\">";
1209 my $comment = $tag{'comment'};
1210 foreach my $line (@
$comment) {
1211 print esc_html
($line) . "<br/>\n";
1219 die_error
('403 Permission denied', "Permission denied.") if (!git_get_project_config_bool
('blame'));
1220 die_error
('404 Not Found', "What file will it be, master?") if (!$file_name);
1221 $hash_base ||= git_read_head
($project);
1222 die_error
(undef, "Reading commit failed.") unless ($hash_base);
1223 my %co = git_read_commit
($hash_base)
1224 or die_error
(undef, "Reading commit failed.");
1225 if (!defined $hash) {
1226 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
1227 or die_error
(undef, "Error lookup file.");
1229 open ($fd, "-|", "$gitbin/git-annotate", '-l', '-t', '-r', $file_name, $hash_base)
1230 or die_error
(undef, "Open failed.");
1232 print "<div class=\"page_nav\">\n" .
1233 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1234 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1235 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1236 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base")}, "commit") .
1237 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1238 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") . "<br/>\n";
1239 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") .
1240 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;f=$file_name")}, "head") . "<br/>\n";
1243 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html
($co{'title'})) .
1245 print "<div class=\"page_path\"><b>" . esc_html
($file_name) . "</b></div>\n";
1246 print "<div class=\"page_body\">\n";
1248 <table class="blame">
1257 my @line_class = (qw(light dark));
1258 my $line_class_len = scalar (@line_class);
1259 my $line_class_num = $#line_class;
1260 while (my $line = <$fd>) {
1272 $line_class_num = ($line_class_num + 1) % $line_class_len;
1274 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) \+\d\d\d\d\t(\d+)\)(.*)$/) {
1281 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
1284 $short_rev = substr ($long_rev, 0, 8);
1285 $age = time () - $time;
1286 $age_str = age_string
($age);
1287 $age_str =~ s/ / /g;
1288 $age_class = age_class
($age);
1289 $author = esc_html
($author);
1290 $author =~ s/ / /g;
1292 while ((my $pos = index($data, "\t")) != -1) {
1293 if (my $count = (8 - ($pos % 8))) {
1294 my $spaces = ' ' x
$count;
1295 $data =~ s/\t/$spaces/;
1298 $data = esc_html
($data);
1301 <tr class="$line_class[$line_class_num]">
1302 <td class="sha1"><a href="$my_uri?${\esc_param ("p=$project;a=commit;h=$long_rev")}" class="text">$short_rev..</a></td>
1303 <td class="$age_class">$age_str</td>
1305 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
1306 <td class="pre">$data</td>
1309 } # while (my $line = <$fd>)
1310 print "</table>\n\n";
1311 close $fd or print "Reading blob failed.\n";
1317 my $head = git_read_head
($project);
1319 print "<div class=\"page_nav\">\n" .
1320 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1321 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1322 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1323 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$head")}, "commit") .
1324 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1325 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1328 my $taglist = git_read_refs
("refs/tags");
1330 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary"), -class => "title"}, " ") .
1332 print "<table cellspacing=\"0\">\n";
1334 if (defined @
$taglist) {
1335 foreach my $entry (@
$taglist) {
1337 my $comment_lines = $tag{'comment'};
1338 my $comment = shift @
$comment_lines;
1339 if (defined($comment)) {
1340 $comment = chop_str
($comment, 30, 5);
1343 print "<tr class=\"dark\">\n";
1345 print "<tr class=\"light\">\n";
1348 print "<td><i>$tag{'age'}</i></td>\n" .
1350 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), -class => "list"},
1351 "<b>" . esc_html
($tag{'name'}) . "</b>") .
1354 if (defined($comment)) {
1355 print $cgi->a({-class => "list", -href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, $comment);
1358 "<td class=\"link\">";
1359 if ($tag{'type'} eq "tag") {
1360 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
1362 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1363 if ($tag{'reftype'} eq "commit") {
1364 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1365 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'refid'}")}, "log");
1376 my $head = git_read_head
($project);
1378 print "<div class=\"page_nav\">\n" .
1379 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1380 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1381 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1382 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$head")}, "commit") .
1383 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1384 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1387 my $taglist = git_read_refs
("refs/heads");
1389 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary"), -class => "title"}, " ") .
1391 print "<table cellspacing=\"0\">\n";
1393 if (defined @
$taglist) {
1394 foreach my $entry (@
$taglist) {
1397 print "<tr class=\"dark\">\n";
1399 print "<tr class=\"light\">\n";
1402 print "<td><i>$tag{'age'}</i></td>\n" .
1404 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}"), -class => "list"}, "<b>" . esc_html
($tag{'name'}) . "</b>") .
1406 "<td class=\"link\">" .
1407 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1408 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'name'}")}, "log") .
1417 sub git_get_hash_by_path
{
1419 my $path = shift || return undef;
1422 my @parts = split '/', $path;
1423 while (my $part = shift @parts) {
1424 open my $fd, "-|", "$gitbin/git-ls-tree $tree" or die_error
(undef, "Open git-ls-tree failed.");
1425 my (@entries) = map { chomp; $_ } <$fd>;
1426 close $fd or return undef;
1427 foreach my $line (@entries) {
1428 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1429 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1433 my $t_name = validate_input
(unquote
($4));
1434 if ($t_name eq $part) {
1438 if ($t_type eq "tree") {
1448 if (!defined $hash && defined $file_name) {
1449 my $base = $hash_base || git_read_head
($project);
1450 $hash = git_get_hash_by_path
($base, $file_name, "blob") || die_error
(undef, "Error lookup file.");
1452 my $have_blame = git_get_project_config_bool
('blame');
1453 open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or die_error
(undef, "Open failed.");
1455 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
1456 print "<div class=\"page_nav\">\n" .
1457 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1458 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1459 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1460 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base")}, "commit") .
1461 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1462 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") . "<br/>\n";
1463 if (defined $file_name) {
1465 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;h=$hash;hb=$hash_base;f=$file_name")}, "blame") . " | ";
1467 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$hash;f=$file_name")}, "plain") .
1468 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;hb=HEAD;f=$file_name")}, "head") . "<br/>\n";
1470 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$hash")}, "plain") . "<br/>\n";
1474 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html
($co{'title'})) .
1477 print "<div class=\"page_nav\">\n" .
1478 "<br/><br/></div>\n" .
1479 "<div class=\"title\">$hash</div>\n";
1481 if (defined $file_name) {
1482 print "<div class=\"page_path\"><b>" . esc_html
($file_name) . "</b></div>\n";
1484 print "<div class=\"page_body\">\n";
1486 while (my $line = <$fd>) {
1489 while ((my $pos = index($line, "\t")) != -1) {
1490 if (my $count = (8 - ($pos % 8))) {
1491 my $spaces = ' ' x
$count;
1492 $line =~ s/\t/$spaces/;
1495 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", $nr, $nr, $nr, esc_html
($line);
1497 close $fd or print "Reading blob failed.\n";
1502 sub mimetype_guess_file
{
1503 my $filename = shift;
1504 my $mimemap = shift;
1505 -r
$mimemap or return undef;
1508 open(MIME
, $mimemap) or return undef;
1510 my ($mime, $exts) = split(/\t+/);
1511 my @exts = split(/\s+/, $exts);
1512 foreach my $ext (@exts) {
1513 $mimemap{$ext} = $mime;
1518 $filename =~ /\.(.*?)$/;
1519 return $mimemap{$1};
1522 sub mimetype_guess
{
1523 my $filename = shift;
1525 $filename =~ /\./ or return undef;
1527 if ($mimetypes_file) {
1528 my $file = $mimetypes_file;
1529 #$file =~ m#^/# or $file = "$projectroot/$path/$file";
1530 $mime = mimetype_guess_file
($filename, $file);
1532 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1536 sub git_blob_plain_mimetype
{
1538 my $filename = shift;
1541 return $default_blob_plain_mimetype unless $fd;
1544 my $mime = mimetype_guess
($filename);
1545 $mime and return $mime;
1549 return 'text/plain' .
1550 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
1551 } elsif (! $filename) {
1552 return 'application/octet-stream';
1553 } elsif ($filename =~ m/\.png$/i) {
1555 } elsif ($filename =~ m/\.gif$/i) {
1557 } elsif ($filename =~ m/\.jpe?g$/i) {
1558 return 'image/jpeg';
1560 return 'application/octet-stream';
1564 sub git_blob_plain
{
1565 open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or return;
1566 my $type = git_blob_plain_mimetype
($fd, $file_name);
1568 # save as filename, even when no $file_name is given
1569 my $save_as = "$hash";
1570 if (defined $file_name) {
1571 $save_as = $file_name;
1572 } elsif ($type =~ m/^text\//) {
1576 print $cgi->header(-type
=> "$type", '-content-disposition' => "inline; filename=\"$save_as\"");
1578 binmode STDOUT
, ':raw';
1580 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
1586 if (!defined $hash) {
1587 $hash = git_read_head
($project);
1588 if (defined $file_name) {
1589 my $base = $hash_base || $hash;
1590 $hash = git_get_hash_by_path
($base, $file_name, "tree");
1592 if (!defined $hash_base) {
1597 open my $fd, "-|", "$gitbin/git-ls-tree -z $hash" or die_error
(undef, "Open git-ls-tree failed.");
1598 chomp (my (@entries) = <$fd>);
1599 close $fd or die_error
(undef, "Reading tree failed.");
1602 my $refs = read_info_ref
();
1604 if (defined $refs->{$hash_base}) {
1605 $ref = " <span class=\"tag\">" . esc_html
($refs->{$hash_base}) . "</span>";
1610 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
1611 $base_key = ";hb=$hash_base";
1612 print "<div class=\"page_nav\">\n" .
1613 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1614 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash_base")}, "shortlog") .
1615 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash_base")}, "log") .
1616 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base")}, "commit") .
1617 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1622 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html
($co{'title'}) . $ref) . "\n" .
1625 print "<div class=\"page_nav\">\n";
1626 print "<br/><br/></div>\n";
1627 print "<div class=\"title\">$hash</div>\n";
1629 if (defined $file_name) {
1630 $base = esc_html
("$file_name/");
1631 print "<div class=\"page_path\"><b>/" . esc_html
($file_name) . "</b></div>\n";
1633 print "<div class=\"page_path\"><b>/</b></div>\n";
1635 print "<div class=\"page_body\">\n";
1636 print "<table cellspacing=\"0\">\n";
1638 foreach my $line (@entries) {
1639 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1640 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1644 my $t_name = validate_input
($4);
1646 print "<tr class=\"dark\">\n";
1648 print "<tr class=\"light\">\n";
1651 print "<td class=\"mode\">" . mode_str
($t_mode) . "</td>\n";
1652 if ($t_type eq "blob") {
1653 print "<td class=\"list\">" .
1654 $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)) .
1656 "<td class=\"link\">" .
1657 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name")}, "blob") .
1658 # " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$t_hash$base_key;f=$base$t_name")}, "blame") .
1659 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;h=$hash_base;f=$base$t_name")}, "history") .
1661 } elsif ($t_type eq "tree") {
1662 print "<td class=\"list\">" .
1663 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, esc_html
($t_name)) .
1665 "<td class=\"link\">" .
1666 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, "tree") .
1671 print "</table>\n" .
1677 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
1678 open my $fd, "-|", "$gitbin/git-rev-list --max-count=150 " . git_read_head
($project) or die_error
(undef, "Open failed.");
1679 my (@revlist) = map { chomp; $_ } <$fd>;
1680 close $fd or die_error
(undef, "Reading rev-list failed.");
1681 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
1682 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1683 "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
1684 print "<channel>\n";
1685 print "<title>$project</title>\n".
1686 "<link>" . esc_html
("$my_url?p=$project;a=summary") . "</link>\n".
1687 "<description>$project log</description>\n".
1688 "<language>en</language>\n";
1690 for (my $i = 0; $i <= $#revlist; $i++) {
1691 my $commit = $revlist[$i];
1692 my %co = git_read_commit
($commit);
1693 # we read 150, we always show 30 and the ones more recent than 48 hours
1694 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
1697 my %cd = date_str
($co{'committer_epoch'});
1698 open $fd, "-|", "$gitbin/git-diff-tree -r $co{'parent'} $co{'id'}" or next;
1699 my @difftree = map { chomp; $_ } <$fd>;
1703 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
1705 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
1706 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
1707 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
1708 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
1709 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
1710 "<content:encoded>" .
1712 my $comment = $co{'comment'};
1713 foreach my $line (@
$comment) {
1714 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
1715 print "$line<br/>\n";
1718 foreach my $line (@difftree) {
1719 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
1722 my $file = validate_input
(unquote
($7));
1723 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
1724 print "$file<br/>\n";
1727 "</content:encoded>\n" .
1730 print "</channel></rss>";
1734 my @list = git_read_projects
();
1736 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
1737 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1738 "<opml version=\"1.0\">\n".
1740 " <title>Git OPML Export</title>\n".
1743 "<outline text=\"git RSS feeds\">\n";
1745 foreach my $pr (@list) {
1747 my $head = git_read_head
($proj{'path'});
1748 if (!defined $head) {
1751 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
1752 my %co = git_read_commit
($head);
1757 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
1758 my $rss = "$my_url?p=$proj{'path'};a=rss";
1759 my $html = "$my_url?p=$proj{'path'};a=summary";
1760 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
1762 print "</outline>\n".
1768 my $head = git_read_head
($project);
1769 if (!defined $hash) {
1772 if (!defined $page) {
1775 my $refs = read_info_ref
();
1777 print "<div class=\"page_nav\">\n";
1778 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1779 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash")}, "shortlog") .
1781 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash")}, "commit") .
1782 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
1783 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$hash;hb=$hash")}, "tree") . "<br/>\n";
1785 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
1786 open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error
(undef, "Open failed.");
1787 my (@revlist) = map { chomp; $_ } <$fd>;
1790 if ($hash ne $head || $page) {
1791 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "HEAD");
1797 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash;pg=" . ($page-1)), -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1799 print " ⋅ prev";
1801 if ($#revlist >= (100 * ($page+1)-1)) {
1803 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash;pg=" . ($page+1)), -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1805 print " ⋅ next";
1811 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary"), -class => "title"}, " ") .
1813 my %co = git_read_commit
($hash);
1814 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
1816 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
1817 my $commit = $revlist[$i];
1819 if (defined $refs->{$commit}) {
1820 $ref = " <span class=\"tag\">" . esc_html
($refs->{$commit}) . "</span>";
1822 my %co = git_read_commit
($commit);
1824 my %ad = date_str
($co{'author_epoch'});
1826 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "title"},
1827 "<span class=\"age\">$co{'age_string'}</span>" . esc_html
($co{'title'}) . $ref) . "\n";
1829 print "<div class=\"title_text\">\n" .
1830 "<div class=\"log_link\">\n" .
1831 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
1832 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1835 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
1837 "<div class=\"log_body\">\n";
1838 my $comment = $co{'comment'};
1840 foreach my $line (@
$comment) {
1841 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1852 print format_log_line_html
($line) . "<br/>\n";
1863 my %co = git_read_commit
($hash);
1865 die_error
(undef, "Unknown commit object.");
1867 my %ad = date_str
($co{'author_epoch'}, $co{'author_tz'});
1868 my %cd = date_str
($co{'committer_epoch'}, $co{'committer_tz'});
1872 my $parent = $co{'parent'};
1873 if (!defined $parent) {
1877 open my $fd, "-|", "$gitbin/git-diff-tree -r -M $root $parent $hash" or die_error
(undef, "Open failed.");
1878 @difftree = map { chomp; $_ } <$fd>;
1879 close $fd or die_error
(undef, "Reading diff-tree failed.");
1881 # non-textual hash id's can be cached
1883 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
1886 my $refs = read_info_ref
();
1888 if (defined $refs->{$co{'id'}}) {
1889 $ref = " <span class=\"tag\">" . esc_html
($refs->{$co{'id'}}) . "</span>";
1891 git_header_html
(undef, $expires);
1892 print "<div class=\"page_nav\">\n" .
1893 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1894 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash")}, "shortlog") .
1895 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash")}, "log") .
1897 if (defined $co{'parent'}) {
1898 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash")}, "commitdiff");
1900 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") . "\n" .
1901 "<br/><br/></div>\n";
1902 if (defined $co{'parent'}) {
1904 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash"), -class => "title"}, esc_html
($co{'title'}) . $ref) . "\n" .
1908 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash"), -class => "title"}, esc_html
($co{'title'})) . "\n" .
1911 print "<div class=\"title_text\">\n" .
1912 "<table cellspacing=\"0\">\n";
1913 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
1915 "<td></td><td> $ad{'rfc2822'}";
1916 if ($ad{'hour_local'} < 6) {
1917 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1919 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1923 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
1924 print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
1925 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
1928 "<td class=\"sha1\">" .
1929 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash"), class => "list"}, $co{'tree'}) .
1931 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
1934 my $parents = $co{'parents'};
1935 foreach my $par (@
$parents) {
1938 "<td class=\"sha1\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$par"), class => "list"}, $par) . "</td>" .
1939 "<td class=\"link\">" .
1940 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$par")}, "commit") .
1941 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash;hp=$par")}, "commitdiff") .
1947 print "<div class=\"page_body\">\n";
1948 my $comment = $co{'comment'};
1951 foreach my $line (@
$comment) {
1952 # print only one empty line
1954 if ($empty || $signed) {
1961 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1963 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1966 print format_log_line_html
($line) . "<br/>\n";
1970 print "<div class=\"list_head\">\n";
1971 if ($#difftree > 10) {
1972 print(($#difftree + 1) . " files changed:\n");
1975 print "<table class=\"diff_tree\">\n";
1977 foreach my $line (@difftree) {
1978 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1979 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1980 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
1988 my $similarity = $6;
1989 my $file = validate_input
(unquote
($7));
1991 print "<tr class=\"dark\">\n";
1993 print "<tr class=\"light\">\n";
1996 if ($status eq "A") {
1998 if (S_ISREG
(oct $to_mode)) {
1999 $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
2002 $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" .
2003 "<td><span class=\"file_status new\">[new " . file_type
($to_mode) . "$mode_chng]</span></td>\n" .
2004 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob") . "</td>\n";
2005 } elsif ($status eq "D") {
2007 $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" .
2008 "<td><span class=\"file_status deleted\">[deleted " . file_type
($from_mode). "]</span></td>\n" .
2009 "<td class=\"link\">" .
2010 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, "blob") .
2011 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;h=$hash;f=$file")}, "history") .
2013 } elsif ($status eq "M" || $status eq "T") {
2014 my $mode_chnge = "";
2015 if ($from_mode != $to_mode) {
2016 $mode_chnge = " <span class=\"file_status mode_chnge\">[changed";
2017 if (((oct $from_mode) & S_IFMT
) != ((oct $to_mode) & S_IFMT
)) {
2018 $mode_chnge .= " from " . file_type
($from_mode) . " to " . file_type
($to_mode);
2020 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
2021 if (S_ISREG
($from_mode) && S_ISREG
($to_mode)) {
2022 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
2023 } elsif (S_ISREG
($to_mode)) {
2024 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
2027 $mode_chnge .= "]</span>\n";
2030 if ($to_id ne $from_id) {
2031 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));
2033 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file"), -class => "list"}, esc_html
($file));
2036 "<td>$mode_chnge</td>\n" .
2037 "<td class=\"link\">";
2038 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob");
2039 if ($to_id ne $from_id) {
2040 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file")}, "diff");
2042 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;h=$hash;f=$file")}, "history") . "\n";
2044 } elsif ($status eq "R") {
2045 my ($from_file, $to_file) = split "\t", $file;
2047 if ($from_mode != $to_mode) {
2048 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
2051 $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" .
2052 "<td><span class=\"file_status moved\">[moved from " .
2053 $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)) .
2054 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
2055 "<td class=\"link\">" .
2056 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file")}, "blob");
2057 if ($to_id ne $from_id) {
2058 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file")}, "diff");
2069 mkdir($git_temp, 0700);
2071 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
2072 print "<div class=\"page_nav\">\n" .
2073 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
2074 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
2075 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
2076 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base")}, "commit") .
2077 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
2078 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") .
2080 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff_plain;h=$hash;hp=$hash_parent")}, "plain") .
2083 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html
($co{'title'})) . "\n" .
2086 print "<div class=\"page_nav\">\n" .
2087 "<br/><br/></div>\n" .
2088 "<div class=\"title\">$hash vs $hash_parent</div>\n";
2090 if (defined $file_name) {
2091 print "<div class=\"page_path\"><b>/" . esc_html
($file_name) . "</b></div>\n";
2093 print "<div class=\"page_body\">\n" .
2094 "<div class=\"diff_info\">blob:" .
2095 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name")}, $hash_parent) .
2097 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, $hash) .
2099 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
2104 sub git_blobdiff_plain
{
2105 mkdir($git_temp, 0700);
2106 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8');
2107 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
2110 sub git_commitdiff
{
2111 mkdir($git_temp, 0700);
2112 my %co = git_read_commit
($hash);
2114 die_error
(undef, "Unknown commit object.");
2116 if (!defined $hash_parent) {
2117 $hash_parent = $co{'parent'};
2119 open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error
(undef, "Open failed.");
2120 my (@difftree) = map { chomp; $_ } <$fd>;
2121 close $fd or die_error
(undef, "Reading diff-tree failed.");
2123 # non-textual hash id's can be cached
2125 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2128 my $refs = read_info_ref
();
2130 if (defined $refs->{$co{'id'}}) {
2131 $ref = " <span class=\"tag\">" . esc_html
($refs->{$co{'id'}}) . "</span>";
2133 git_header_html
(undef, $expires);
2134 print "<div class=\"page_nav\">\n" .
2135 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
2136 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash")}, "shortlog") .
2137 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash")}, "log") .
2138 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash")}, "commit") .
2140 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") . "<br/>\n";
2141 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent")}, "plain") . "\n" .
2144 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html
($co{'title'}) . $ref) . "\n" .
2146 print "<div class=\"page_body\">\n";
2147 my $comment = $co{'comment'};
2150 my @log = @
$comment;
2151 # remove first and empty lines after that
2153 while (defined $log[0] && $log[0] eq "") {
2156 foreach my $line (@log) {
2157 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2168 print format_log_line_html
($line) . "<br/>\n";
2171 foreach my $line (@difftree) {
2172 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2173 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2174 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2180 my $file = validate_input
(unquote
($6));
2181 if ($status eq "A") {
2182 print "<div class=\"diff_info\">" . file_type
($to_mode) . ":" .
2183 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id) . "(new)" .
2185 git_diff_print
(undef, "/dev/null", $to_id, "b/$file");
2186 } elsif ($status eq "D") {
2187 print "<div class=\"diff_info\">" . file_type
($from_mode) . ":" .
2188 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) . "(deleted)" .
2190 git_diff_print
($from_id, "a/$file", undef, "/dev/null");
2191 } elsif ($status eq "M") {
2192 if ($from_id ne $to_id) {
2193 print "<div class=\"diff_info\">" .
2194 file_type
($from_mode) . ":" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) .
2196 file_type
($to_mode) . ":" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id);
2198 git_diff_print
($from_id, "a/$file", $to_id, "b/$file");
2207 sub git_commitdiff_plain
{
2208 mkdir($git_temp, 0700);
2209 open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error
(undef, "Open failed.");
2210 my (@difftree) = map { chomp; $_ } <$fd>;
2211 close $fd or die_error
(undef, "Reading diff-tree failed.");
2213 # try to figure out the next tag after this commit
2215 my $refs = read_info_ref
("tags");
2216 open $fd, "-|", "$gitbin/git-rev-list HEAD";
2217 chomp (my (@commits) = <$fd>);
2219 foreach my $commit (@commits) {
2220 if (defined $refs->{$commit}) {
2221 $tagname = $refs->{$commit}
2223 if ($commit eq $hash) {
2228 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8', '-content-disposition' => "inline; filename=\"git-$hash.patch\"");
2229 my %co = git_read_commit
($hash);
2230 my %ad = date_str
($co{'author_epoch'}, $co{'author_tz'});
2231 my $comment = $co{'comment'};
2232 print "From: $co{'author'}\n" .
2233 "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
2234 "Subject: $co{'title'}\n";
2235 if (defined $tagname) {
2236 print "X-Git-Tag: $tagname\n";
2238 print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
2241 foreach my $line (@
$comment) {;
2246 foreach my $line (@difftree) {
2247 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2252 if ($status eq "A") {
2253 git_diff_print
(undef, "/dev/null", $to_id, "b/$file", "plain");
2254 } elsif ($status eq "D") {
2255 git_diff_print
($from_id, "a/$file", undef, "/dev/null", "plain");
2256 } elsif ($status eq "M") {
2257 git_diff_print
($from_id, "a/$file", $to_id, "b/$file", "plain");
2263 if (!defined $hash) {
2264 $hash = git_read_head
($project);
2266 my %co = git_read_commit
($hash);
2268 die_error
(undef, "Unknown commit object.");
2270 my $refs = read_info_ref
();
2272 print "<div class=\"page_nav\">\n" .
2273 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
2274 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
2275 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
2276 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash")}, "commit") .
2277 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2278 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
2282 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html
($co{'title'})) . "\n" .
2284 print "<div class=\"page_path\"><b>/" . esc_html
($file_name) . "</b><br/></div>\n";
2286 open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin -- \'$file_name\'";
2288 print "<table cellspacing=\"0\">\n";
2290 while (my $line = <$fd>) {
2291 if ($line =~ m/^([0-9a-fA-F]{40})/){
2295 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/ && (defined $commit)) {
2296 my %co = git_read_commit
($commit);
2301 if (defined $refs->{$commit}) {
2302 $ref = " <span class=\"tag\">" . esc_html
($refs->{$commit}) . "</span>";
2305 print "<tr class=\"dark\">\n";
2307 print "<tr class=\"light\">\n";
2310 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2311 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2312 "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list"}, "<b>" .
2313 esc_html
(chop_str
($co{'title'}, 50)) . "$ref</b>") . "</td>\n" .
2314 "<td class=\"link\">" .
2315 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
2316 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2317 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;hb=$commit;f=$file_name")}, "blob");
2318 my $blob = git_get_hash_by_path
($hash, $file_name);
2319 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2320 if (defined $blob && defined $blob_parent && $blob ne $blob_parent) {
2322 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=$file_name")},
2336 if (!defined $searchtext) {
2337 die_error
("", "Text field empty.");
2339 if (!defined $hash) {
2340 $hash = git_read_head
($project);
2342 my %co = git_read_commit
($hash);
2344 die_error
(undef, "Unknown commit object.");
2346 # pickaxe may take all resources of your box and run for several minutes
2347 # with every query - so decide by yourself how public you make this feature :)
2348 my $commit_search = 1;
2349 my $author_search = 0;
2350 my $committer_search = 0;
2351 my $pickaxe_search = 0;
2352 if ($searchtext =~ s/^author\\://i) {
2354 } elsif ($searchtext =~ s/^committer\\://i) {
2355 $committer_search = 1;
2356 } elsif ($searchtext =~ s/^pickaxe\\://i) {
2358 $pickaxe_search = 1;
2361 print "<div class=\"page_nav\">\n" .
2362 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary;h=$hash")}, "summary") .
2363 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
2364 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash")}, "log") .
2365 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash")}, "commit") .
2366 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2367 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
2372 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html
($co{'title'})) . "\n" .
2374 print "<table cellspacing=\"0\">\n";
2376 if ($commit_search) {
2378 open my $fd, "-|", "$gitbin/git-rev-list --header --parents $hash" or next;
2379 while (my $commit_text = <$fd>) {
2380 if (!grep m/$searchtext/i, $commit_text) {
2383 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
2386 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
2389 my @commit_lines = split "\n", $commit_text;
2390 my %co = git_read_commit
(undef, \
@commit_lines);
2395 print "<tr class=\"dark\">\n";
2397 print "<tr class=\"light\">\n";
2400 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2401 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2403 $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/>");
2404 my $comment = $co{'comment'};
2405 foreach my $line (@
$comment) {
2406 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2407 my $lead = esc_html
($1) || "";
2408 $lead = chop_str
($lead, 30, 10);
2409 my $match = esc_html
($2) || "";
2410 my $trail = esc_html
($3) || "";
2411 $trail = chop_str
($trail, 30, 10);
2412 my $text = "$lead<span class=\"match\">$match</span>$trail";
2413 print chop_str
($text, 80, 5) . "<br/>\n";
2417 "<td class=\"link\">" .
2418 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2419 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2426 if ($pickaxe_search) {
2428 open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin -S\'$searchtext\'";
2431 while (my $line = <$fd>) {
2432 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2435 $set{'from_id'} = $3;
2437 $set{'id'} = $set{'to_id'};
2438 if ($set{'id'} =~ m/0{40}/) {
2439 $set{'id'} = $set{'from_id'};
2441 if ($set{'id'} =~ m/0{40}/) {
2445 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
2448 print "<tr class=\"dark\">\n";
2450 print "<tr class=\"light\">\n";
2453 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2454 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2456 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" .
2457 esc_html
(chop_str
($co{'title'}, 50)) . "</b><br/>");
2458 while (my $setref = shift @files) {
2460 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}"), class => "list"},
2461 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
2465 "<td class=\"link\">" .
2466 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2467 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2471 %co = git_read_commit
($1);
2481 my $head = git_read_head
($project);
2482 if (!defined $hash) {
2485 if (!defined $page) {
2488 my $refs = read_info_ref
();
2490 print "<div class=\"page_nav\">\n" .
2491 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
2493 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash")}, "log") .
2494 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash")}, "commit") .
2495 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2496 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$hash;hb=$hash")}, "tree") . "<br/>\n";
2498 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2499 open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error
(undef, "Open failed.");
2500 my (@revlist) = map { chomp; $_ } <$fd>;
2503 if ($hash ne $head || $page) {
2504 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "HEAD");
2510 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash;pg=" . ($page-1)), -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2512 print " ⋅ prev";
2514 if ($#revlist >= (100 * ($page+1)-1)) {
2516 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)), -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2518 print " ⋅ next";
2523 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary"), -class => "title"}, " ") .
2525 print "<table cellspacing=\"0\">\n";
2527 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2528 my $commit = $revlist[$i];
2530 if (defined $refs->{$commit}) {
2531 $ref = " <span class=\"tag\">" . esc_html
($refs->{$commit}) . "</span>";
2533 my %co = git_read_commit
($commit);
2534 my %ad = date_str
($co{'author_epoch'});
2536 print "<tr class=\"dark\">\n";
2538 print "<tr class=\"light\">\n";
2541 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2542 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
2544 if (length($co{'title_short'}) < length($co{'title'})) {
2545 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list", -title
=> "$co{'title'}"},
2546 "<b>" . esc_html
($co{'title_short'}) . "$ref</b>");
2548 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list"},
2549 "<b>" . esc_html
($co{'title_short'}) . "$ref</b>");
2552 "<td class=\"link\">" .
2553 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
2554 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2558 if ($#revlist >= (100 * ($page+1)-1)) {
2561 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)), -title
=> "Alt-n"}, "next") .