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 # location of the git-core binaries
26 my $gitbin = "/usr/bin";
28 # absolute fs-path which will be prepended to the project path
29 #my $projectroot = "/pub/scm";
30 my $projectroot = "/home/kay/public_html/pub/scm";
32 # version of the git-core binaries
33 my $git_version = qx($gitbin/git --version);
34 if ($git_version =~ m/git version (.*)$/) {
37 $git_version = "unknown";
40 # location for temporary files needed for diffs
41 my $git_temp = "/tmp/gitweb";
43 # target of the home link on top of all pages
44 my $home_link = $my_uri;
46 # html text to include at home page
47 my $home_text = "indextext.html";
49 # URI of default stylesheet
50 my $stylesheet = "gitweb.css";
52 # source of projects list
53 #my $projects_list = $projectroot;
54 my $projects_list = "index/index.aux";
56 # default blob_plain mimetype and default charset for text/plain blob
57 my $default_blob_plain_mimetype = 'text/plain';
58 my $default_text_plain_charset = undef;
60 # file to use for guessing MIME types before trying /etc/mime.types
61 # (relative to the current git repository)
62 my $mimetypes_file = undef;
65 # input validation and dispatch
66 my $action = $cgi->param('a');
67 if (defined $action) {
68 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
70 die_error(undef, "Invalid action parameter.");
72 if ($action eq "git-logo.png") {
75 } elsif ($action eq "opml") {
81 my $order = $cgi->param('o');
83 if ($order =~ m/[^0-9a-zA-Z_]/) {
85 die_error(undef, "Invalid order parameter.");
89 my $project = ($cgi->param('p') || $ENV{'PATH_INFO'});
90 if (defined $project) {
91 $project =~ s|^/||; $project =~ s|/$||;
92 $project = validate_input($project);
93 if (!defined($project)) {
94 die_error(undef, "Invalid project parameter.");
96 if (!(-d "$projectroot/$project")) {
98 die_error(undef, "No such directory.");
100 if (!(-e "$projectroot/$project/HEAD")) {
102 die_error(undef, "No such project.");
104 $rss_link = "<link rel=\"alternate\" title=\"" . esc_param($project) . " log\" href=\"" .
105 "$my_uri?" . esc_param("p=$project;a=rss") . "\" type=\"application/rss+xml\"/>";
106 $ENV{'GIT_DIR'} = "$projectroot/$project";
112 my $file_name = $cgi->param('f');
113 if (defined $file_name) {
114 $file_name = validate_input($file_name);
115 if (!defined($file_name)) {
116 die_error(undef, "Invalid file parameter.");
120 my $hash = $cgi->param('h');
122 $hash = validate_input($hash);
123 if (!defined($hash)) {
124 die_error(undef, "Invalid hash parameter.");
128 my $hash_parent = $cgi->param('hp');
129 if (defined $hash_parent) {
130 $hash_parent = validate_input($hash_parent);
131 if (!defined($hash_parent)) {
132 die_error(undef, "Invalid hash parent parameter.");
136 my $hash_base = $cgi->param('hb');
137 if (defined $hash_base) {
138 $hash_base = validate_input($hash_base);
139 if (!defined($hash_base)) {
140 die_error(undef, "Invalid hash base parameter.");
144 my $page = $cgi->param('pg');
146 if ($page =~ m/[^0-9]$/) {
148 die_error(undef, "Invalid page parameter.");
152 my $searchtext = $cgi->param('s');
153 if (defined $searchtext) {
154 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\-\+\:\@ ]/) {
156 die_error(undef, "Invalid search parameter.");
158 $searchtext = quotemeta $searchtext;
164 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
167 if ($input =~ m/(^|\/)(|\.|\.\.)($|\/)/) {
170 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\-\+\#\~\%]/) {
176 if (!defined $action || $action eq "summary") {
179 } elsif ($action eq "heads") {
182 } elsif ($action eq "tags") {
185 } elsif ($action eq "blob") {
188 } elsif ($action eq "blob_plain") {
191 } elsif ($action eq "tree") {
194 } elsif ($action eq "rss") {
197 } elsif ($action eq "commit") {
200 } elsif ($action eq "log") {
203 } elsif ($action eq "blobdiff") {
206 } elsif ($action eq "blobdiff_plain") {
207 git_blobdiff_plain();
209 } elsif ($action eq "commitdiff") {
212 } elsif ($action eq "commitdiff_plain") {
213 git_commitdiff_plain();
215 } elsif ($action eq "history") {
218 } elsif ($action eq "search") {
221 } elsif ($action eq "shortlog") {
224 } elsif ($action eq "tag") {
227 } elsif ($action eq "blame") {
232 die_error(undef, "Unknown action.");
236 # quote unsafe chars, but keep the slash, even when it's not
237 # correct, but quoted slashes look too horrible in bookmarks
240 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf("%%%02X", ord($1))/eg;
246 # replace invalid utf8 character with SUBSTITUTION sequence
249 $str = decode("utf8", $str, Encode::FB_DEFAULT);
250 $str = escapeHTML($str);
254 # git may return quoted and escaped filenames
257 if ($str =~ m/^"(.*)"$/) {
259 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
264 # CSS class for given age value (in seconds)
268 if ($age < 60*60*2) {
270 } elsif ($age < 60*60*24*2) {
277 sub git_header_html {
278 my $status = shift || "200 OK";
282 if (defined $project) {
283 $title .= " - $project";
284 if (defined $action) {
285 $title .= "/$action";
286 if (defined $file_name) {
287 $title .= " - $file_name";
288 if ($action eq "tree" && $file_name !~ m|/$|) {
294 print $cgi->header(-type=>'text/html', -charset => 'utf-8', -status=> $status, -expires => $expires);
296 <?xml version="1.0" encoding="utf-8"?>
297 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
298 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
299 <!-- git web interface v$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
300 <!-- git core binaries version $git_version -->
302 <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
303 <meta name="robots" content="index, nofollow"/>
304 <title>$title</title>
305 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
310 print "<div class=\"page_header\">\n" .
311 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
312 "<img src=\"$my_uri?" . esc_param("a=git-logo.png") . "\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
314 print $cgi->a({-href => esc_param($home_link)}, "projects") . " / ";
315 if (defined $project) {
316 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, esc_html($project));
317 if (defined $action) {
321 if (!defined $searchtext) {
326 $search_hash = $hash;
328 $search_hash = "HEAD";
330 $cgi->param("a", "search");
331 $cgi->param("h", $search_hash);
332 print $cgi->startform(-method => "get", -action => $my_uri) .
333 "<div class=\"search\">\n" .
334 $cgi->hidden(-name => "p") . "\n" .
335 $cgi->hidden(-name => "a") . "\n" .
336 $cgi->hidden(-name => "h") . "\n" .
337 $cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
339 $cgi->end_form() . "\n";
344 sub git_footer_html {
345 print "<div class=\"page_footer\">\n";
346 if (defined $project) {
347 my $descr = git_read_description($project);
348 if (defined $descr) {
349 print "<div class=\"page_footer_text\">" . esc_html($descr) . "</div>\n";
351 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=rss"), -class => "rss_logo"}, "RSS") . "\n";
353 print $cgi->a({-href => "$my_uri?" . esc_param("a=opml"), -class => "rss_logo"}, "OPML") . "\n";
361 my $status = shift || "403 Forbidden";
362 my $error = shift || "Malformed query, file missing or permission denied";
364 git_header_html($status);
365 print "<div class=\"page_body\">\n" .
367 "$status - $error\n" .
377 open my $fd, "-|", "$gitbin/git-cat-file -t $hash" or return;
386 my $oENV = $ENV{'GIT_DIR'};
388 $ENV{'GIT_DIR'} = "$projectroot/$project";
389 if (open my $fd, "-|", "$gitbin/git-rev-parse", "--verify", "HEAD") {
392 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
397 $ENV{'GIT_DIR'} = $oENV;
405 open my $fd, "$projectroot/$path" or return undef;
409 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
414 sub git_read_description {
417 open my $fd, "$projectroot/$path/description" or return undef;
429 open my $fd, "-|", "$gitbin/git-cat-file tag $tag_id" or return;
430 $tag{'id'} = $tag_id;
431 while (my $line = <$fd>) {
433 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
435 } elsif ($line =~ m/^type (.+)$/) {
437 } elsif ($line =~ m/^tag (.+)$/) {
439 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
443 } elsif ($line =~ m/--BEGIN/) {
444 push @comment, $line;
446 } elsif ($line eq "") {
450 push @comment, <$fd>;
451 $tag{'comment'} = \@comment;
453 if (!defined $tag{'name'}) {
463 if ($age > 60*60*24*365*2) {
464 $age_str = (int $age/60/60/24/365);
465 $age_str .= " years ago";
466 } elsif ($age > 60*60*24*(365/12)*2) {
467 $age_str = int $age/60/60/24/(365/12);
468 $age_str .= " months ago";
469 } elsif ($age > 60*60*24*7*2) {
470 $age_str = int $age/60/60/24/7;
471 $age_str .= " weeks ago";
472 } elsif ($age > 60*60*24*2) {
473 $age_str = int $age/60/60/24;
474 $age_str .= " days ago";
475 } elsif ($age > 60*60*2) {
476 $age_str = int $age/60/60;
477 $age_str .= " hours ago";
478 } elsif ($age > 60*2) {
479 $age_str = int $age/60;
480 $age_str .= " min ago";
483 $age_str .= " sec ago";
485 $age_str .= " right now";
490 sub git_read_commit {
491 my $commit_id = shift;
492 my $commit_text = shift;
497 if (defined $commit_text) {
498 @commit_lines = @$commit_text;
501 open my $fd, "-|", "$gitbin/git-rev-list --header --parents --max-count=1 $commit_id" or return;
502 @commit_lines = split '\n', <$fd>;
507 my $header = shift @commit_lines;
508 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
511 ($co{'id'}, my @parents) = split ' ', $header;
512 $co{'parents'} = \@parents;
513 $co{'parent'} = $parents[0];
514 while (my $line = shift @commit_lines) {
515 last if $line eq "\n";
516 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
518 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
520 $co{'author_epoch'} = $2;
521 $co{'author_tz'} = $3;
522 if ($co{'author'} =~ m/^([^<]+) </) {
523 $co{'author_name'} = $1;
525 $co{'author_name'} = $co{'author'};
527 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
528 $co{'committer'} = $1;
529 $co{'committer_epoch'} = $2;
530 $co{'committer_tz'} = $3;
531 $co{'committer_name'} = $co{'committer'};
532 $co{'committer_name'} =~ s/ <.*//;
535 if (!defined $co{'tree'}) {
539 foreach my $title (@commit_lines) {
542 $co{'title'} = chop_str($title, 80, 5);
543 # remove leading stuff of merges to make the interesting part visible
544 if (length($title) > 50) {
545 $title =~ s/^Automatic //;
546 $title =~ s/^merge (of|with) /Merge ... /i;
547 if (length($title) > 50) {
548 $title =~ s/(http|rsync):\/\///;
550 if (length($title) > 50) {
551 $title =~ s/(master|www|rsync)\.//;
553 if (length($title) > 50) {
554 $title =~ s/kernel.org:?//;
556 if (length($title) > 50) {
557 $title =~ s/\/pub\/scm//;
560 $co{'title_short'} = chop_str($title, 50, 5);
564 # remove added spaces
565 foreach my $line (@commit_lines) {
568 $co{'comment'} = \@commit_lines;
570 my $age = time - $co{'committer_epoch'};
572 $co{'age_string'} = age_string($age);
573 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
574 if ($age > 60*60*24*7*2) {
575 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
576 $co{'age_string_age'} = $co{'age_string'};
578 $co{'age_string_date'} = $co{'age_string'};
579 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
586 my $from_name = shift;
589 my $format = shift || "html";
591 my $from_tmp = "/dev/null";
592 my $to_tmp = "/dev/null";
595 # create tmp from-file
597 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
598 open my $fd2, "> $from_tmp";
599 open my $fd, "-|", "$gitbin/git-cat-file blob $from";
608 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
609 open my $fd2, "> $to_tmp";
610 open my $fd, "-|", "$gitbin/git-cat-file blob $to";
617 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
618 if ($format eq "plain") {
623 while (my $line = <$fd>) {
625 my $char = substr($line, 0, 1);
628 $diff_class = " add";
629 } elsif ($char eq "-") {
630 $diff_class = " rem";
631 } elsif ($char eq "@") {
632 $diff_class = " chunk_header";
633 } elsif ($char eq "\\") {
637 while ((my $pos = index($line, "\t")) != -1) {
638 if (my $count = (8 - (($pos-1) % 8))) {
639 my $spaces = ' ' x $count;
640 $line =~ s/\t/$spaces/;
643 print "<div class=\"diff$diff_class\">" . esc_html($line) . "</div>\n";
657 my $mode = oct shift;
659 if (S_ISDIR($mode & S_IFMT)) {
661 } elsif (S_ISLNK($mode)) {
663 } elsif (S_ISREG($mode)) {
664 # git cares only about the executable bit
665 if ($mode & S_IXUSR) {
678 my $add_len = shift || 10;
680 # allow only $len chars, but don't cut a word if it would fit in $add_len
681 # if it doesn't fit, cut it if it's still longer than the dots we would add
682 $str =~ m/^(.{0,$len}[^ \/\-_:\.@]{0,$add_len})(.*)/;
685 if (length($tail) > 4) {
692 my $mode = oct shift;
694 if (S_ISDIR($mode & S_IFMT)) {
696 } elsif (S_ISLNK($mode)) {
698 } elsif (S_ISREG($mode)) {
705 sub format_log_line_html {
708 $line = esc_html($line);
709 $line =~ s/ / /g;
710 if ($line =~ m/([0-9a-fA-F]{40})/) {
712 if (git_get_type($hash_text) eq "commit") {
713 my $link = $cgi->a({-class => "text", -href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_text")}, $hash_text);
714 $line =~ s/$hash_text/$link/;
722 my $tz = shift || "-0000";
725 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
726 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
727 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
728 $date{'hour'} = $hour;
729 $date{'minute'} = $min;
730 $date{'mday'} = $mday;
731 $date{'day'} = $days[$wday];
732 $date{'month'} = $months[$mon];
733 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
734 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
736 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
737 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
738 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
739 $date{'hour_local'} = $hour;
740 $date{'minute_local'} = $min;
741 $date{'tz_local'} = $tz;
745 # git-logo (cached in browser for one day)
747 binmode STDOUT, ':raw';
748 print $cgi->header(-type => 'image/png', -expires => '+1d');
749 # cat git-logo.png | hexdump -e '16/1 " %02x" "\n"' | sed 's/ /\\x/g'
750 print "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52" .
751 "\x00\x00\x00\x48\x00\x00\x00\x1b\x04\x03\x00\x00\x00\x2d\xd9\xd4" .
752 "\x2d\x00\x00\x00\x18\x50\x4c\x54\x45\xff\xff\xff\x60\x60\x5d\xb0" .
753 "\xaf\xaa\x00\x80\x00\xce\xcd\xc7\xc0\x00\x00\xe8\xe8\xe6\xf7\xf7" .
754 "\xf6\x95\x0c\xa7\x47\x00\x00\x00\x73\x49\x44\x41\x54\x28\xcf\x63" .
755 "\x48\x67\x20\x04\x4a\x5c\x18\x0a\x08\x2a\x62\x53\x61\x20\x02\x08" .
756 "\x0d\x69\x45\xac\xa1\xa1\x01\x30\x0c\x93\x60\x36\x26\x52\x91\xb1" .
757 "\x01\x11\xd6\xe1\x55\x64\x6c\x6c\xcc\x6c\x6c\x0c\xa2\x0c\x70\x2a" .
758 "\x62\x06\x2a\xc1\x62\x1d\xb3\x01\x02\x53\xa4\x08\xe8\x00\x03\x18" .
759 "\x26\x56\x11\xd4\xe1\x20\x97\x1b\xe0\xb4\x0e\x35\x24\x71\x29\x82" .
760 "\x99\x30\xb8\x93\x0a\x11\xb9\x45\x88\xc1\x8d\xa0\xa2\x44\x21\x06" .
761 "\x27\x41\x82\x40\x85\xc1\x45\x89\x20\x70\x01\x00\xa4\x3d\x21\xc5" .
762 "\x12\x1c\x9a\xfe\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\x82";
768 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
769 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
770 if (!defined $gcos) {
774 $owner =~ s/[,;].*$//;
775 return decode("utf8", $owner, Encode::FB_DEFAULT);
778 sub git_read_projects {
781 if (-d $projects_list) {
782 # search in directory
783 my $dir = $projects_list;
784 opendir my $dh, $dir or return undef;
785 while (my $dir = readdir($dh)) {
786 if (-e "$projectroot/$dir/HEAD") {
794 } elsif (-f $projects_list) {
795 # read from file(url-encoded):
796 # 'git%2Fgit.git Linus+Torvalds'
797 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
798 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
799 open my $fd , $projects_list or return undef;
800 while (my $line = <$fd>) {
802 my ($path, $owner) = split ' ', $line;
803 $path = unescape($path);
804 $owner = unescape($owner);
805 if (!defined $path) {
808 if (-e "$projectroot/$path/HEAD") {
811 owner => decode("utf8", $owner, Encode::FB_DEFAULT),
818 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
822 sub git_get_project_config {
825 return unless ($key);
826 $key =~ s/^gitweb\.//;
827 return if ($key =~ m/\W/);
829 my $val = qx($gitbin/git-repo-config --get gitweb.$key);
833 sub git_get_project_config_bool {
834 my $val = git_get_project_config (@_);
835 if ($val and $val =~ m/true|yes|on/) {
838 return; # implicit false
841 sub git_project_list {
842 my @list = git_read_projects();
845 die_error(undef, "No project found.");
847 foreach my $pr (@list) {
848 my $head = git_read_head($pr->{'path'});
849 if (!defined $head) {
852 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
853 my %co = git_read_commit($head);
857 $pr->{'commit'} = \%co;
858 if (!defined $pr->{'descr'}) {
859 my $descr = git_read_description($pr->{'path'}) || "";
860 $pr->{'descr'} = chop_str($descr, 25, 5);
862 if (!defined $pr->{'owner'}) {
863 $pr->{'owner'} = get_file_owner("$projectroot/$pr->{'path'}") || "";
869 print "<div class=\"index_include\">\n";
870 open (my $fd, $home_text);
875 print "<table class=\"project_list\">\n" .
877 if (!defined($order) || (defined($order) && ($order eq "project"))) {
878 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
879 print "<th>Project</th>\n";
881 print "<th>" . $cgi->a({-class => "header", -href => "$my_uri?" . esc_param("o=project")}, "Project") . "</th>\n";
883 if (defined($order) && ($order eq "descr")) {
884 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
885 print "<th>Description</th>\n";
887 print "<th>" . $cgi->a({-class => "header", -href => "$my_uri?" . esc_param("o=descr")}, "Description") . "</th>\n";
889 if (defined($order) && ($order eq "owner")) {
890 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
891 print "<th>Owner</th>\n";
893 print "<th>" . $cgi->a({-class => "header", -href => "$my_uri?" . esc_param("o=owner")}, "Owner") . "</th>\n";
895 if (defined($order) && ($order eq "age")) {
896 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
897 print "<th>Last Change</th>\n";
899 print "<th>" . $cgi->a({-class => "header", -href => "$my_uri?" . esc_param("o=age")}, "Last Change") . "</th>\n";
901 print "<th></th>\n" .
904 foreach my $pr (@projects) {
906 print "<tr class=\"dark\">\n";
908 print "<tr class=\"light\">\n";
911 print "<td>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=summary"), -class => "list"}, esc_html($pr->{'path'})) . "</td>\n" .
912 "<td>$pr->{'descr'}</td>\n" .
913 "<td><i>" . chop_str($pr->{'owner'}, 15) . "</i></td>\n";
914 print "<td class=\"". age_class($pr->{'commit'}{'age'}) . "\">" . $pr->{'commit'}{'age_string'} . "</td>\n" .
915 "<td class=\"link\">" .
916 $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=summary")}, "summary") .
917 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=shortlog")}, "shortlog") .
918 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=log")}, "log") .
927 my $type = shift || "";
929 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
930 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
931 open my $fd, "$projectroot/$project/info/refs" or return;
932 while (my $line = <$fd>) {
934 if ($line =~ m/^([0-9a-fA-F]{40})\t.*$type\/([^\^]+)/) {
935 if (defined $refs{$1}) {
936 $refs{$1} .= " / $2";
951 opendir my $dh, "$projectroot/$project/$ref_dir";
952 while (my $dir = readdir($dh)) {
953 if ($dir =~ m/^\./) {
956 if (-d "$projectroot/$project/$ref_dir/$dir") {
957 opendir my $dh2, "$projectroot/$project/$ref_dir/$dir";
958 my @subdirs = grep !m/^\./, readdir $dh2;
960 foreach my $subdir (@subdirs) {
961 push @refs, "$dir/$subdir"
968 foreach my $ref_file (@refs) {
969 my $ref_id = git_read_hash("$project/$ref_dir/$ref_file");
970 my $type = git_get_type($ref_id) || next;
973 $ref_item{'type'} = $type;
974 $ref_item{'id'} = $ref_id;
975 $ref_item{'epoch'} = 0;
976 $ref_item{'age'} = "unknown";
977 if ($type eq "tag") {
978 my %tag = git_read_tag($ref_id);
979 $ref_item{'comment'} = $tag{'comment'};
980 if ($tag{'type'} eq "commit") {
981 %co = git_read_commit($tag{'object'});
982 $ref_item{'epoch'} = $co{'committer_epoch'};
983 $ref_item{'age'} = $co{'age_string'};
984 } elsif (defined($tag{'epoch'})) {
985 my $age = time - $tag{'epoch'};
986 $ref_item{'epoch'} = $tag{'epoch'};
987 $ref_item{'age'} = age_string($age);
989 $ref_item{'reftype'} = $tag{'type'};
990 $ref_item{'name'} = $tag{'name'};
991 $ref_item{'refid'} = $tag{'object'};
992 } elsif ($type eq "commit"){
993 %co = git_read_commit($ref_id);
994 $ref_item{'reftype'} = "commit";
995 $ref_item{'name'} = $ref_file;
996 $ref_item{'title'} = $co{'title'};
997 $ref_item{'refid'} = $ref_id;
998 $ref_item{'epoch'} = $co{'committer_epoch'};
999 $ref_item{'age'} = $co{'age_string'};
1002 push @reflist, \%ref_item;
1005 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1010 my $descr = git_read_description($project) || "none";
1011 my $head = git_read_head($project);
1012 my %co = git_read_commit($head);
1013 my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'});
1016 if (-f $projects_list) {
1017 open (my $fd , $projects_list);
1018 while (my $line = <$fd>) {
1020 my ($pr, $ow) = split ' ', $line;
1021 $pr = unescape($pr);
1022 $ow = unescape($ow);
1023 if ($pr eq $project) {
1024 $owner = decode("utf8", $ow, Encode::FB_DEFAULT);
1030 if (!defined $owner) {
1031 $owner = get_file_owner("$projectroot/$project");
1034 my $refs = read_info_ref();
1036 print "<div class=\"page_nav\">\n" .
1038 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
1039 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") .
1040 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$head")}, "commit") .
1041 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1042 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree")}, "tree") .
1045 print "<div class=\"title\"> </div>\n";
1046 print "<table cellspacing=\"0\">\n" .
1047 "<tr><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
1048 "<tr><td>owner</td><td>$owner</td></tr>\n" .
1049 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
1051 open my $fd, "-|", "$gitbin/git-rev-list --max-count=17 " . git_read_head($project) or die_error(undef, "Open failed.");
1052 my (@revlist) = map { chomp; $_ } <$fd>;
1055 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog"), -class => "title"}, "shortlog") .
1058 print "<table cellspacing=\"0\">\n";
1060 foreach my $commit (@revlist) {
1061 my %co = git_read_commit($commit);
1062 my %ad = date_str($co{'author_epoch'});
1064 print "<tr class=\"dark\">\n";
1066 print "<tr class=\"light\">\n";
1071 if (defined $refs->{$commit}) {
1072 $ref = " <span class=\"tag\">" . esc_html($refs->{$commit}) . "</span>";
1074 print "<td><i>$co{'age_string'}</i></td>\n" .
1075 "<td><i>" . esc_html(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
1077 if (length($co{'title_short'}) < length($co{'title'})) {
1078 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "list", -title => "$co{'title'}"},
1079 "<b>" . esc_html($co{'title_short'}) . "$ref</b>");
1081 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "list"},
1082 "<b>" . esc_html($co{'title'}) . "$ref</b>");
1085 "<td class=\"link\">" .
1086 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit")}, "commit") .
1087 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1091 print "<td>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "...") . "</td>\n" .
1098 my $taglist = git_read_refs("refs/tags");
1099 if (defined @$taglist) {
1101 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tags"), -class => "title"}, "tags") .
1104 print "<table cellspacing=\"0\">\n";
1106 foreach my $entry (@$taglist) {
1108 my $comment_lines = $tag{'comment'};
1109 my $comment = shift @$comment_lines;
1110 if (defined($comment)) {
1111 $comment = chop_str($comment, 30, 5);
1114 print "<tr class=\"dark\">\n";
1116 print "<tr class=\"light\">\n";
1120 print "<td><i>$tag{'age'}</i></td>\n" .
1122 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), -class => "list"},
1123 "<b>" . esc_html($tag{'name'}) . "</b>") .
1126 if (defined($comment)) {
1127 print $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, $comment);
1130 "<td class=\"link\">";
1131 if ($tag{'type'} eq "tag") {
1132 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
1134 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1135 if ($tag{'reftype'} eq "commit") {
1136 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1137 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'refid'}")}, "log");
1142 print "<td>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tags")}, "...") . "</td>\n" .
1150 my $headlist = git_read_refs("refs/heads");
1151 if (defined @$headlist) {
1153 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=heads"), -class => "title"}, "heads") .
1156 print "<table cellspacing=\"0\">\n";
1158 foreach my $entry (@$headlist) {
1161 print "<tr class=\"dark\">\n";
1163 print "<tr class=\"light\">\n";
1167 print "<td><i>$tag{'age'}</i></td>\n" .
1169 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}"), -class => "list"},
1170 "<b>" . esc_html($tag{'name'}) . "</b>") .
1172 "<td class=\"link\">" .
1173 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1174 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'name'}")}, "log") .
1178 print "<td>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=heads")}, "...") . "</td>\n" .
1189 my $head = git_read_head($project);
1191 print "<div class=\"page_nav\">\n" .
1192 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
1193 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
1194 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") .
1195 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$head")}, "commit") .
1196 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1197 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1200 my %tag = git_read_tag($hash);
1202 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html($tag{'name'})) . "\n" .
1204 print "<div class=\"title_text\">\n" .
1205 "<table cellspacing=\"0\">\n" .
1207 "<td>object</td>\n" .
1208 "<td>" . $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'object'}) . "</td>\n" .
1209 "<td class=\"link\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'type'}) . "</td>\n" .
1211 if (defined($tag{'author'})) {
1212 my %ad = date_str($tag{'epoch'}, $tag{'tz'});
1213 print "<tr><td>author</td><td>" . esc_html($tag{'author'}) . "</td></tr>\n";
1214 print "<tr><td></td><td>" . $ad{'rfc2822'} . sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) . "</td></tr>\n";
1216 print "</table>\n\n" .
1218 print "<div class=\"page_body\">";
1219 my $comment = $tag{'comment'};
1220 foreach my $line (@$comment) {
1221 print esc_html($line) . "<br/>\n";
1229 die_error('403 Permission denied', "Permission denied.") if (!git_get_project_config_bool ('blame'));
1230 die_error('404 Not Found', "What file will it be, master?") if (!$file_name);
1231 $hash_base ||= git_read_head($project);
1232 die_error(undef, "Reading commit failed.") unless ($hash_base);
1233 my %co = git_read_commit($hash_base)
1234 or die_error(undef, "Reading commit failed.");
1235 if (!defined $hash) {
1236 $hash = git_get_hash_by_path($hash_base, $file_name, "blob")
1237 or die_error(undef, "Error lookup file.");
1239 open ($fd, "-|", "$gitbin/git-annotate", '-l', '-t', '-r', $file_name, $hash_base)
1240 or die_error(undef, "Open failed.");
1242 print "<div class=\"page_nav\">\n" .
1243 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
1244 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
1245 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") .
1246 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base")}, "commit") .
1247 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1248 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") . "<br/>\n";
1249 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") .
1250 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;f=$file_name")}, "head") . "<br/>\n";
1253 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) .
1255 print "<div class=\"page_path\"><b>" . esc_html($file_name) . "</b></div>\n";
1256 print "<div class=\"page_body\">\n";
1258 <table class="blame">
1267 my @line_class = (qw(light dark));
1268 my $line_class_len = scalar (@line_class);
1269 my $line_class_num = $#line_class;
1270 while (my $line = <$fd>) {
1282 $line_class_num = ($line_class_num + 1) % $line_class_len;
1284 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) \+\d\d\d\d\t(\d+)\)(.*)$/) {
1291 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
1294 $short_rev = substr ($long_rev, 0, 8);
1295 $age = time () - $time;
1296 $age_str = age_string ($age);
1297 $age_str =~ s/ / /g;
1298 $age_class = age_class($age);
1299 $author = esc_html ($author);
1300 $author =~ s/ / /g;
1302 while ((my $pos = index($data, "\t")) != -1) {
1303 if (my $count = (8 - ($pos % 8))) {
1304 my $spaces = ' ' x $count;
1305 $data =~ s/\t/$spaces/;
1308 $data = esc_html ($data);
1311 <tr class="$line_class[$line_class_num]">
1312 <td class="sha1"><a href="$my_uri?${\esc_param ("p=$project;a=commit;h=$long_rev")}" class="text">$short_rev..</a></td>
1313 <td class="$age_class">$age_str</td>
1315 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
1316 <td class="pre">$data</td>
1319 } # while (my $line = <$fd>)
1320 print "</table>\n\n";
1321 close $fd or print "Reading blob failed.\n";
1327 my $head = git_read_head($project);
1329 print "<div class=\"page_nav\">\n" .
1330 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
1331 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
1332 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") .
1333 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$head")}, "commit") .
1334 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1335 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1338 my $taglist = git_read_refs("refs/tags");
1340 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary"), -class => "title"}, " ") .
1342 print "<table cellspacing=\"0\">\n";
1344 if (defined @$taglist) {
1345 foreach my $entry (@$taglist) {
1347 my $comment_lines = $tag{'comment'};
1348 my $comment = shift @$comment_lines;
1349 if (defined($comment)) {
1350 $comment = chop_str($comment, 30, 5);
1353 print "<tr class=\"dark\">\n";
1355 print "<tr class=\"light\">\n";
1358 print "<td><i>$tag{'age'}</i></td>\n" .
1360 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), -class => "list"},
1361 "<b>" . esc_html($tag{'name'}) . "</b>") .
1364 if (defined($comment)) {
1365 print $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, $comment);
1368 "<td class=\"link\">";
1369 if ($tag{'type'} eq "tag") {
1370 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
1372 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1373 if ($tag{'reftype'} eq "commit") {
1374 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1375 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'refid'}")}, "log");
1386 my $head = git_read_head($project);
1388 print "<div class=\"page_nav\">\n" .
1389 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
1390 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
1391 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") .
1392 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$head")}, "commit") .
1393 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1394 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1397 my $taglist = git_read_refs("refs/heads");
1399 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary"), -class => "title"}, " ") .
1401 print "<table cellspacing=\"0\">\n";
1403 if (defined @$taglist) {
1404 foreach my $entry (@$taglist) {
1407 print "<tr class=\"dark\">\n";
1409 print "<tr class=\"light\">\n";
1412 print "<td><i>$tag{'age'}</i></td>\n" .
1414 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}"), -class => "list"}, "<b>" . esc_html($tag{'name'}) . "</b>") .
1416 "<td class=\"link\">" .
1417 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1418 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'name'}")}, "log") .
1427 sub git_get_hash_by_path {
1429 my $path = shift || return undef;
1432 my @parts = split '/', $path;
1433 while (my $part = shift @parts) {
1434 open my $fd, "-|", "$gitbin/git-ls-tree $tree" or die_error(undef, "Open git-ls-tree failed.");
1435 my (@entries) = map { chomp; $_ } <$fd>;
1436 close $fd or return undef;
1437 foreach my $line (@entries) {
1438 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1439 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1443 my $t_name = validate_input(unquote($4));
1444 if ($t_name eq $part) {
1448 if ($t_type eq "tree") {
1458 if (!defined $hash && defined $file_name) {
1459 my $base = $hash_base || git_read_head($project);
1460 $hash = git_get_hash_by_path($base, $file_name, "blob") || die_error(undef, "Error lookup file.");
1462 my $have_blame = git_get_project_config_bool ('blame');
1463 open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or die_error(undef, "Open failed.");
1465 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
1466 print "<div class=\"page_nav\">\n" .
1467 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
1468 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
1469 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") .
1470 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base")}, "commit") .
1471 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1472 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") . "<br/>\n";
1473 if (defined $file_name) {
1475 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$hash;hb=$hash_base;f=$file_name")}, "blame") . " | ";
1477 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$hash;f=$file_name")}, "plain") .
1478 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;hb=HEAD;f=$file_name")}, "head") . "<br/>\n";
1480 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$hash")}, "plain") . "<br/>\n";
1484 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) .
1487 print "<div class=\"page_nav\">\n" .
1488 "<br/><br/></div>\n" .
1489 "<div class=\"title\">$hash</div>\n";
1491 if (defined $file_name) {
1492 print "<div class=\"page_path\"><b>" . esc_html($file_name) . "</b></div>\n";
1494 print "<div class=\"page_body\">\n";
1496 while (my $line = <$fd>) {
1499 while ((my $pos = index($line, "\t")) != -1) {
1500 if (my $count = (8 - ($pos % 8))) {
1501 my $spaces = ' ' x $count;
1502 $line =~ s/\t/$spaces/;
1505 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", $nr, $nr, $nr, esc_html($line);
1507 close $fd or print "Reading blob failed.\n";
1512 sub mimetype_guess_file {
1513 my $filename = shift;
1514 my $mimemap = shift;
1515 -r $mimemap or return undef;
1518 open(MIME, $mimemap) or return undef;
1520 my ($mime, $exts) = split(/\t+/);
1521 my @exts = split(/\s+/, $exts);
1522 foreach my $ext (@exts) {
1523 $mimemap{$ext} = $mime;
1528 $filename =~ /\.(.*?)$/;
1529 return $mimemap{$1};
1532 sub mimetype_guess {
1533 my $filename = shift;
1535 $filename =~ /\./ or return undef;
1537 if ($mimetypes_file) {
1538 my $file = $mimetypes_file;
1539 #$file =~ m#^/# or $file = "$projectroot/$path/$file";
1540 $mime = mimetype_guess_file($filename, $file);
1542 $mime ||= mimetype_guess_file($filename, '/etc/mime.types');
1546 sub git_blob_plain_mimetype {
1548 my $filename = shift;
1551 return $default_blob_plain_mimetype unless $fd;
1554 my $mime = mimetype_guess($filename);
1555 $mime and return $mime;
1559 return 'text/plain' .
1560 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1561 } elsif (! $filename) {
1562 return 'application/octet-stream';
1563 } elsif ($filename =~ m/\.png$/i) {
1565 } elsif ($filename =~ m/\.gif$/i) {
1567 } elsif ($filename =~ m/\.jpe?g$/i) {
1568 return 'image/jpeg';
1570 return 'application/octet-stream';
1574 sub git_blob_plain {
1575 open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or return;
1576 my $type = git_blob_plain_mimetype($fd, $file_name);
1578 # save as filename, even when no $file_name is given
1579 my $save_as = "$hash";
1580 if (defined $file_name) {
1581 $save_as = $file_name;
1582 } elsif ($type =~ m/^text\//) {
1586 print $cgi->header(-type => "$type", '-content-disposition' => "inline; filename=\"$save_as\"");
1588 binmode STDOUT, ':raw';
1590 binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
1596 if (!defined $hash) {
1597 $hash = git_read_head($project);
1598 if (defined $file_name) {
1599 my $base = $hash_base || $hash;
1600 $hash = git_get_hash_by_path($base, $file_name, "tree");
1602 if (!defined $hash_base) {
1607 open my $fd, "-|", "$gitbin/git-ls-tree -z $hash" or die_error(undef, "Open git-ls-tree failed.");
1608 chomp (my (@entries) = <$fd>);
1609 close $fd or die_error(undef, "Reading tree failed.");
1612 my $refs = read_info_ref();
1614 if (defined $refs->{$hash_base}) {
1615 $ref = " <span class=\"tag\">" . esc_html($refs->{$hash_base}) . "</span>";
1620 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
1621 $base_key = ";hb=$hash_base";
1622 print "<div class=\"page_nav\">\n" .
1623 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
1624 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash_base")}, "shortlog") .
1625 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash_base")}, "log") .
1626 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base")}, "commit") .
1627 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1632 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'}) . $ref) . "\n" .
1635 print "<div class=\"page_nav\">\n";
1636 print "<br/><br/></div>\n";
1637 print "<div class=\"title\">$hash</div>\n";
1639 if (defined $file_name) {
1640 $base = esc_html("$file_name/");
1641 print "<div class=\"page_path\"><b>/" . esc_html($file_name) . "</b></div>\n";
1643 print "<div class=\"page_path\"><b>/</b></div>\n";
1645 print "<div class=\"page_body\">\n";
1646 print "<table cellspacing=\"0\">\n";
1648 foreach my $line (@entries) {
1649 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1650 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1654 my $t_name = validate_input($4);
1656 print "<tr class=\"dark\">\n";
1658 print "<tr class=\"light\">\n";
1661 print "<td class=\"mode\">" . mode_str($t_mode) . "</td>\n";
1662 if ($t_type eq "blob") {
1663 print "<td class=\"list\">" .
1664 $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)) .
1666 "<td class=\"link\">" .
1667 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name")}, "blob") .
1668 # " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$t_hash$base_key;f=$base$t_name")}, "blame") .
1669 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;h=$hash_base;f=$base$t_name")}, "history") .
1671 } elsif ($t_type eq "tree") {
1672 print "<td class=\"list\">" .
1673 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, esc_html($t_name)) .
1675 "<td class=\"link\">" .
1676 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, "tree") .
1681 print "</table>\n" .
1687 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
1688 open my $fd, "-|", "$gitbin/git-rev-list --max-count=150 " . git_read_head($project) or die_error(undef, "Open failed.");
1689 my (@revlist) = map { chomp; $_ } <$fd>;
1690 close $fd or die_error(undef, "Reading rev-list failed.");
1691 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
1692 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1693 "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
1694 print "<channel>\n";
1695 print "<title>$project</title>\n".
1696 "<link>" . esc_html("$my_url?p=$project;a=summary") . "</link>\n".
1697 "<description>$project log</description>\n".
1698 "<language>en</language>\n";
1700 for (my $i = 0; $i <= $#revlist; $i++) {
1701 my $commit = $revlist[$i];
1702 my %co = git_read_commit($commit);
1703 # we read 150, we always show 30 and the ones more recent than 48 hours
1704 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
1707 my %cd = date_str($co{'committer_epoch'});
1708 open $fd, "-|", "$gitbin/git-diff-tree -r $co{'parent'} $co{'id'}" or next;
1709 my @difftree = map { chomp; $_ } <$fd>;
1713 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html($co{'title'}) .
1715 "<author>" . esc_html($co{'author'}) . "</author>\n" .
1716 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
1717 "<guid isPermaLink=\"true\">" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
1718 "<link>" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
1719 "<description>" . esc_html($co{'title'}) . "</description>\n" .
1720 "<content:encoded>" .
1722 my $comment = $co{'comment'};
1723 foreach my $line (@$comment) {
1724 $line = decode("utf8", $line, Encode::FB_DEFAULT);
1725 print "$line<br/>\n";
1728 foreach my $line (@difftree) {
1729 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
1732 my $file = validate_input(unquote($7));
1733 $file = decode("utf8", $file, Encode::FB_DEFAULT);
1734 print "$file<br/>\n";
1737 "</content:encoded>\n" .
1740 print "</channel></rss>";
1744 my @list = git_read_projects();
1746 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
1747 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1748 "<opml version=\"1.0\">\n".
1750 " <title>Git OPML Export</title>\n".
1753 "<outline text=\"git RSS feeds\">\n";
1755 foreach my $pr (@list) {
1757 my $head = git_read_head($proj{'path'});
1758 if (!defined $head) {
1761 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
1762 my %co = git_read_commit($head);
1767 my $path = esc_html(chop_str($proj{'path'}, 25, 5));
1768 my $rss = "$my_url?p=$proj{'path'};a=rss";
1769 my $html = "$my_url?p=$proj{'path'};a=summary";
1770 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
1772 print "</outline>\n".
1778 my $head = git_read_head($project);
1779 if (!defined $hash) {
1782 if (!defined $page) {
1785 my $refs = read_info_ref();
1787 print "<div class=\"page_nav\">\n";
1788 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
1789 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash")}, "shortlog") .
1791 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash")}, "commit") .
1792 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
1793 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$hash;hb=$hash")}, "tree") . "<br/>\n";
1795 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
1796 open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error(undef, "Open failed.");
1797 my (@revlist) = map { chomp; $_ } <$fd>;
1800 if ($hash ne $head || $page) {
1801 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "HEAD");
1807 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash;pg=" . ($page-1)), -accesskey => "p", -title => "Alt-p"}, "prev");
1809 print " ⋅ prev";
1811 if ($#revlist >= (100 * ($page+1)-1)) {
1813 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash;pg=" . ($page+1)), -accesskey => "n", -title => "Alt-n"}, "next");
1815 print " ⋅ next";
1821 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary"), -class => "title"}, " ") .
1823 my %co = git_read_commit($hash);
1824 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
1826 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
1827 my $commit = $revlist[$i];
1829 if (defined $refs->{$commit}) {
1830 $ref = " <span class=\"tag\">" . esc_html($refs->{$commit}) . "</span>";
1832 my %co = git_read_commit($commit);
1834 my %ad = date_str($co{'author_epoch'});
1836 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "title"},
1837 "<span class=\"age\">$co{'age_string'}</span>" . esc_html($co{'title'}) . $ref) . "\n";
1839 print "<div class=\"title_text\">\n" .
1840 "<div class=\"log_link\">\n" .
1841 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit")}, "commit") .
1842 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1845 "<i>" . esc_html($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
1847 "<div class=\"log_body\">\n";
1848 my $comment = $co{'comment'};
1850 foreach my $line (@$comment) {
1851 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1862 print format_log_line_html($line) . "<br/>\n";
1873 my %co = git_read_commit($hash);
1875 die_error(undef, "Unknown commit object.");
1877 my %ad = date_str($co{'author_epoch'}, $co{'author_tz'});
1878 my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'});
1882 my $parent = $co{'parent'};
1883 if (!defined $parent) {
1887 open my $fd, "-|", "$gitbin/git-diff-tree -r -M $root $parent $hash" or die_error(undef, "Open failed.");
1888 @difftree = map { chomp; $_ } <$fd>;
1889 close $fd or die_error(undef, "Reading diff-tree failed.");
1891 # non-textual hash id's can be cached
1893 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
1896 my $refs = read_info_ref();
1898 if (defined $refs->{$co{'id'}}) {
1899 $ref = " <span class=\"tag\">" . esc_html($refs->{$co{'id'}}) . "</span>";
1901 git_header_html(undef, $expires);
1902 print "<div class=\"page_nav\">\n" .
1903 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
1904 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash")}, "shortlog") .
1905 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash")}, "log") .
1907 if (defined $co{'parent'}) {
1908 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash")}, "commitdiff");
1910 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") . "\n" .
1911 "<br/><br/></div>\n";
1912 if (defined $co{'parent'}) {
1914 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash"), -class => "title"}, esc_html($co{'title'}) . $ref) . "\n" .
1918 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash"), -class => "title"}, esc_html($co{'title'})) . "\n" .
1921 print "<div class=\"title_text\">\n" .
1922 "<table cellspacing=\"0\">\n";
1923 print "<tr><td>author</td><td>" . esc_html($co{'author'}) . "</td></tr>\n".
1925 "<td></td><td> $ad{'rfc2822'}";
1926 if ($ad{'hour_local'} < 6) {
1927 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1929 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1933 print "<tr><td>committer</td><td>" . esc_html($co{'committer'}) . "</td></tr>\n";
1934 print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
1935 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
1938 "<td class=\"sha1\">" .
1939 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash"), class => "list"}, $co{'tree'}) .
1941 "<td class=\"link\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
1944 my $parents = $co{'parents'};
1945 foreach my $par (@$parents) {
1948 "<td class=\"sha1\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$par"), class => "list"}, $par) . "</td>" .
1949 "<td class=\"link\">" .
1950 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$par")}, "commit") .
1951 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash;hp=$par")}, "commitdiff") .
1957 print "<div class=\"page_body\">\n";
1958 my $comment = $co{'comment'};
1961 foreach my $line (@$comment) {
1962 # print only one empty line
1964 if ($empty || $signed) {
1971 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1973 print "<span class=\"signoff\">" . esc_html($line) . "</span><br/>\n";
1976 print format_log_line_html($line) . "<br/>\n";
1980 print "<div class=\"list_head\">\n";
1981 if ($#difftree > 10) {
1982 print(($#difftree + 1) . " files changed:\n");
1985 print "<table class=\"diff_tree\">\n";
1987 foreach my $line (@difftree) {
1988 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1989 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1990 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
1998 my $similarity = $6;
1999 my $file = validate_input(unquote($7));
2001 print "<tr class=\"dark\">\n";
2003 print "<tr class=\"light\">\n";
2006 if ($status eq "A") {
2008 if (S_ISREG(oct $to_mode)) {
2009 $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
2012 $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" .
2013 "<td><span class=\"file_status new\">[new " . file_type($to_mode) . "$mode_chng]</span></td>\n" .
2014 "<td class=\"link\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob") . "</td>\n";
2015 } elsif ($status eq "D") {
2017 $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" .
2018 "<td><span class=\"file_status deleted\">[deleted " . file_type($from_mode). "]</span></td>\n" .
2019 "<td class=\"link\">" .
2020 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, "blob") .
2021 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;h=$hash;f=$file")}, "history") .
2023 } elsif ($status eq "M" || $status eq "T") {
2024 my $mode_chnge = "";
2025 if ($from_mode != $to_mode) {
2026 $mode_chnge = " <span class=\"file_status mode_chnge\">[changed";
2027 if (((oct $from_mode) & S_IFMT) != ((oct $to_mode) & S_IFMT)) {
2028 $mode_chnge .= " from " . file_type($from_mode) . " to " . file_type($to_mode);
2030 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
2031 if (S_ISREG($from_mode) && S_ISREG($to_mode)) {
2032 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
2033 } elsif (S_ISREG($to_mode)) {
2034 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
2037 $mode_chnge .= "]</span>\n";
2040 if ($to_id ne $from_id) {
2041 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));
2043 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file"), -class => "list"}, esc_html($file));
2046 "<td>$mode_chnge</td>\n" .
2047 "<td class=\"link\">";
2048 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob");
2049 if ($to_id ne $from_id) {
2050 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file")}, "diff");
2052 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;h=$hash;f=$file")}, "history") . "\n";
2054 } elsif ($status eq "R") {
2055 my ($from_file, $to_file) = split "\t", $file;
2057 if ($from_mode != $to_mode) {
2058 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
2061 $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" .
2062 "<td><span class=\"file_status moved\">[moved from " .
2063 $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)) .
2064 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
2065 "<td class=\"link\">" .
2066 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file")}, "blob");
2067 if ($to_id ne $from_id) {
2068 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file")}, "diff");
2079 mkdir($git_temp, 0700);
2081 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
2082 print "<div class=\"page_nav\">\n" .
2083 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
2084 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
2085 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") .
2086 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base")}, "commit") .
2087 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
2088 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") .
2090 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff_plain;h=$hash;hp=$hash_parent")}, "plain") .
2093 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) . "\n" .
2096 print "<div class=\"page_nav\">\n" .
2097 "<br/><br/></div>\n" .
2098 "<div class=\"title\">$hash vs $hash_parent</div>\n";
2100 if (defined $file_name) {
2101 print "<div class=\"page_path\"><b>/" . esc_html($file_name) . "</b></div>\n";
2103 print "<div class=\"page_body\">\n" .
2104 "<div class=\"diff_info\">blob:" .
2105 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name")}, $hash_parent) .
2107 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, $hash) .
2109 git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
2114 sub git_blobdiff_plain {
2115 mkdir($git_temp, 0700);
2116 print $cgi->header(-type => "text/plain", -charset => 'utf-8');
2117 git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
2120 sub git_commitdiff {
2121 mkdir($git_temp, 0700);
2122 my %co = git_read_commit($hash);
2124 die_error(undef, "Unknown commit object.");
2126 if (!defined $hash_parent) {
2127 $hash_parent = $co{'parent'};
2129 open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error(undef, "Open failed.");
2130 my (@difftree) = map { chomp; $_ } <$fd>;
2131 close $fd or die_error(undef, "Reading diff-tree failed.");
2133 # non-textual hash id's can be cached
2135 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2138 my $refs = read_info_ref();
2140 if (defined $refs->{$co{'id'}}) {
2141 $ref = " <span class=\"tag\">" . esc_html($refs->{$co{'id'}}) . "</span>";
2143 git_header_html(undef, $expires);
2144 print "<div class=\"page_nav\">\n" .
2145 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
2146 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash")}, "shortlog") .
2147 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash")}, "log") .
2148 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash")}, "commit") .
2150 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") . "<br/>\n";
2151 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent")}, "plain") . "\n" .
2154 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html($co{'title'}) . $ref) . "\n" .
2156 print "<div class=\"page_body\">\n";
2157 my $comment = $co{'comment'};
2160 my @log = @$comment;
2161 # remove first and empty lines after that
2163 while (defined $log[0] && $log[0] eq "") {
2166 foreach my $line (@log) {
2167 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2178 print format_log_line_html($line) . "<br/>\n";
2181 foreach my $line (@difftree) {
2182 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2183 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2184 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2190 my $file = validate_input(unquote($6));
2191 if ($status eq "A") {
2192 print "<div class=\"diff_info\">" . file_type($to_mode) . ":" .
2193 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id) . "(new)" .
2195 git_diff_print(undef, "/dev/null", $to_id, "b/$file");
2196 } elsif ($status eq "D") {
2197 print "<div class=\"diff_info\">" . file_type($from_mode) . ":" .
2198 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) . "(deleted)" .
2200 git_diff_print($from_id, "a/$file", undef, "/dev/null");
2201 } elsif ($status eq "M") {
2202 if ($from_id ne $to_id) {
2203 print "<div class=\"diff_info\">" .
2204 file_type($from_mode) . ":" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) .
2206 file_type($to_mode) . ":" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id);
2208 git_diff_print($from_id, "a/$file", $to_id, "b/$file");
2217 sub git_commitdiff_plain {
2218 mkdir($git_temp, 0700);
2219 open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error(undef, "Open failed.");
2220 my (@difftree) = map { chomp; $_ } <$fd>;
2221 close $fd or die_error(undef, "Reading diff-tree failed.");
2223 # try to figure out the next tag after this commit
2225 my $refs = read_info_ref("tags");
2226 open $fd, "-|", "$gitbin/git-rev-list HEAD";
2227 chomp (my (@commits) = <$fd>);
2229 foreach my $commit (@commits) {
2230 if (defined $refs->{$commit}) {
2231 $tagname = $refs->{$commit}
2233 if ($commit eq $hash) {
2238 print $cgi->header(-type => "text/plain", -charset => 'utf-8', '-content-disposition' => "inline; filename=\"git-$hash.patch\"");
2239 my %co = git_read_commit($hash);
2240 my %ad = date_str($co{'author_epoch'}, $co{'author_tz'});
2241 my $comment = $co{'comment'};
2242 print "From: $co{'author'}\n" .
2243 "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
2244 "Subject: $co{'title'}\n";
2245 if (defined $tagname) {
2246 print "X-Git-Tag: $tagname\n";
2248 print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
2251 foreach my $line (@$comment) {;
2256 foreach my $line (@difftree) {
2257 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2262 if ($status eq "A") {
2263 git_diff_print(undef, "/dev/null", $to_id, "b/$file", "plain");
2264 } elsif ($status eq "D") {
2265 git_diff_print($from_id, "a/$file", undef, "/dev/null", "plain");
2266 } elsif ($status eq "M") {
2267 git_diff_print($from_id, "a/$file", $to_id, "b/$file", "plain");
2273 if (!defined $hash) {
2274 $hash = git_read_head($project);
2276 my %co = git_read_commit($hash);
2278 die_error(undef, "Unknown commit object.");
2280 my $refs = read_info_ref();
2282 print "<div class=\"page_nav\">\n" .
2283 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
2284 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
2285 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") .
2286 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash")}, "commit") .
2287 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2288 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
2292 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html($co{'title'})) . "\n" .
2294 print "<div class=\"page_path\"><b>/" . esc_html($file_name) . "</b><br/></div>\n";
2296 open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin -- \'$file_name\'";
2298 print "<table cellspacing=\"0\">\n";
2300 while (my $line = <$fd>) {
2301 if ($line =~ m/^([0-9a-fA-F]{40})/){
2305 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/ && (defined $commit)) {
2306 my %co = git_read_commit($commit);
2311 if (defined $refs->{$commit}) {
2312 $ref = " <span class=\"tag\">" . esc_html($refs->{$commit}) . "</span>";
2315 print "<tr class=\"dark\">\n";
2317 print "<tr class=\"light\">\n";
2320 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2321 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2322 "<td>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "list"}, "<b>" .
2323 esc_html(chop_str($co{'title'}, 50)) . "$ref</b>") . "</td>\n" .
2324 "<td class=\"link\">" .
2325 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit")}, "commit") .
2326 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2327 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;hb=$commit;f=$file_name")}, "blob");
2328 my $blob = git_get_hash_by_path($hash, $file_name);
2329 my $blob_parent = git_get_hash_by_path($commit, $file_name);
2330 if (defined $blob && defined $blob_parent && $blob ne $blob_parent) {
2332 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=$file_name")},
2346 if (!defined $searchtext) {
2347 die_error("", "Text field empty.");
2349 if (!defined $hash) {
2350 $hash = git_read_head($project);
2352 my %co = git_read_commit($hash);
2354 die_error(undef, "Unknown commit object.");
2356 # pickaxe may take all resources of your box and run for several minutes
2357 # with every query - so decide by yourself how public you make this feature :)
2358 my $commit_search = 1;
2359 my $author_search = 0;
2360 my $committer_search = 0;
2361 my $pickaxe_search = 0;
2362 if ($searchtext =~ s/^author\\://i) {
2364 } elsif ($searchtext =~ s/^committer\\://i) {
2365 $committer_search = 1;
2366 } elsif ($searchtext =~ s/^pickaxe\\://i) {
2368 $pickaxe_search = 1;
2371 print "<div class=\"page_nav\">\n" .
2372 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary;h=$hash")}, "summary") .
2373 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
2374 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash")}, "log") .
2375 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash")}, "commit") .
2376 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2377 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
2382 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html($co{'title'})) . "\n" .
2384 print "<table cellspacing=\"0\">\n";
2386 if ($commit_search) {
2388 open my $fd, "-|", "$gitbin/git-rev-list --header --parents $hash" or next;
2389 while (my $commit_text = <$fd>) {
2390 if (!grep m/$searchtext/i, $commit_text) {
2393 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
2396 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
2399 my @commit_lines = split "\n", $commit_text;
2400 my %co = git_read_commit(undef, \@commit_lines);
2405 print "<tr class=\"dark\">\n";
2407 print "<tr class=\"light\">\n";
2410 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2411 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2413 $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/>");
2414 my $comment = $co{'comment'};
2415 foreach my $line (@$comment) {
2416 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2417 my $lead = esc_html($1) || "";
2418 $lead = chop_str($lead, 30, 10);
2419 my $match = esc_html($2) || "";
2420 my $trail = esc_html($3) || "";
2421 $trail = chop_str($trail, 30, 10);
2422 my $text = "$lead<span class=\"match\">$match</span>$trail";
2423 print chop_str($text, 80, 5) . "<br/>\n";
2427 "<td class=\"link\">" .
2428 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2429 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2436 if ($pickaxe_search) {
2438 open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin -S\'$searchtext\'";
2441 while (my $line = <$fd>) {
2442 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2445 $set{'from_id'} = $3;
2447 $set{'id'} = $set{'to_id'};
2448 if ($set{'id'} =~ m/0{40}/) {
2449 $set{'id'} = $set{'from_id'};
2451 if ($set{'id'} =~ m/0{40}/) {
2455 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
2458 print "<tr class=\"dark\">\n";
2460 print "<tr class=\"light\">\n";
2463 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2464 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2466 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" .
2467 esc_html(chop_str($co{'title'}, 50)) . "</b><br/>");
2468 while (my $setref = shift @files) {
2470 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}"), class => "list"},
2471 "<span class=\"match\">" . esc_html($set{'file'}) . "</span>") .
2475 "<td class=\"link\">" .
2476 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2477 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2481 %co = git_read_commit($1);
2491 my $head = git_read_head($project);
2492 if (!defined $hash) {
2495 if (!defined $page) {
2498 my $refs = read_info_ref();
2500 print "<div class=\"page_nav\">\n" .
2501 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
2503 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash")}, "log") .
2504 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash")}, "commit") .
2505 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2506 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$hash;hb=$hash")}, "tree") . "<br/>\n";
2508 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2509 open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error(undef, "Open failed.");
2510 my (@revlist) = map { chomp; $_ } <$fd>;
2513 if ($hash ne $head || $page) {
2514 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "HEAD");
2520 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash;pg=" . ($page-1)), -accesskey => "p", -title => "Alt-p"}, "prev");
2522 print " ⋅ prev";
2524 if ($#revlist >= (100 * ($page+1)-1)) {
2526 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)), -accesskey => "n", -title => "Alt-n"}, "next");
2528 print " ⋅ next";
2533 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary"), -class => "title"}, " ") .
2535 print "<table cellspacing=\"0\">\n";
2537 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2538 my $commit = $revlist[$i];
2540 if (defined $refs->{$commit}) {
2541 $ref = " <span class=\"tag\">" . esc_html($refs->{$commit}) . "</span>";
2543 my %co = git_read_commit($commit);
2544 my %ad = date_str($co{'author_epoch'});
2546 print "<tr class=\"dark\">\n";
2548 print "<tr class=\"light\">\n";
2551 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2552 "<td><i>" . esc_html(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
2554 if (length($co{'title_short'}) < length($co{'title'})) {
2555 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "list", -title => "$co{'title'}"},
2556 "<b>" . esc_html($co{'title_short'}) . "$ref</b>");
2558 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "list"},
2559 "<b>" . esc_html($co{'title_short'}) . "$ref</b>");
2562 "<td class=\"link\">" .
2563 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit")}, "commit") .
2564 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2568 if ($#revlist >= (100 * ($page+1)-1)) {
2571 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)), -title => "Alt-n"}, "next") .