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 sub git_header_html {
256 my $status = shift || "200 OK";
260 if (defined $project) {
261 $title .= " - $project";
262 if (defined $action) {
263 $title .= "/$action";
264 if (defined $file_name) {
265 $title .= " - $file_name";
266 if ($action eq "tree" && $file_name !~ m|/$|) {
272 print $cgi->header(-type=>'text/html', -charset => 'utf-8', -status=> $status, -expires => $expires);
274 <?xml version="1.0" encoding="utf-8"?>
275 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
276 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
277 <!-- git web interface v$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
279 <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
280 <meta name="robots" content="index, nofollow"/>
281 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
282 <title>$title</title>
287 print "<div class=\"page_header\">\n" .
288 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
289 "<img src=\"$my_uri?" . esc_param("a=git-logo.png") . "\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
291 print $cgi->a({-href => esc_param($home_link)}, "projects") . " / ";
292 if (defined $project) {
293 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, esc_html($project));
294 if (defined $action) {
298 if (!defined $searchtext) {
303 $search_hash = $hash;
305 $search_hash = "HEAD";
307 $cgi->param("a", "search");
308 $cgi->param("h", $search_hash);
309 print $cgi->startform(-method => "get", -action => $my_uri) .
310 "<div class=\"search\">\n" .
311 $cgi->hidden(-name => "p") . "\n" .
312 $cgi->hidden(-name => "a") . "\n" .
313 $cgi->hidden(-name => "h") . "\n" .
314 $cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
316 $cgi->end_form() . "\n";
321 sub git_footer_html {
322 print "<div class=\"page_footer\">\n";
323 if (defined $project) {
324 my $descr = git_read_description($project);
325 if (defined $descr) {
326 print "<div class=\"page_footer_text\">" . esc_html($descr) . "</div>\n";
328 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=rss"), -class => "rss_logo"}, "RSS") . "\n";
330 print $cgi->a({-href => "$my_uri?" . esc_param("a=opml"), -class => "rss_logo"}, "OPML") . "\n";
338 my $status = shift || "403 Forbidden";
339 my $error = shift || "Malformed query, file missing or permission denied";
341 git_header_html($status);
342 print "<div class=\"page_body\">\n" .
344 "$status - $error\n" .
354 open my $fd, "-|", "$gitbin/git-cat-file -t $hash" or return;
363 my $oENV = $ENV{'GIT_DIR'};
365 $ENV{'GIT_DIR'} = "$projectroot/$project";
366 if (open my $fd, "-|", "$gitbin/git-rev-parse", "--verify", "HEAD") {
369 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
374 $ENV{'GIT_DIR'} = $oENV;
382 open my $fd, "$projectroot/$path" or return undef;
386 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
391 sub git_read_description {
394 open my $fd, "$projectroot/$path/description" or return undef;
406 open my $fd, "-|", "$gitbin/git-cat-file tag $tag_id" or return;
407 $tag{'id'} = $tag_id;
408 while (my $line = <$fd>) {
410 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
412 } elsif ($line =~ m/^type (.+)$/) {
414 } elsif ($line =~ m/^tag (.+)$/) {
416 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
420 } elsif ($line =~ m/--BEGIN/) {
421 push @comment, $line;
423 } elsif ($line eq "") {
427 push @comment, <$fd>;
428 $tag{'comment'} = \@comment;
430 if (!defined $tag{'name'}) {
440 if ($age > 60*60*24*365*2) {
441 $age_str = (int $age/60/60/24/365);
442 $age_str .= " years ago";
443 } elsif ($age > 60*60*24*(365/12)*2) {
444 $age_str = int $age/60/60/24/(365/12);
445 $age_str .= " months ago";
446 } elsif ($age > 60*60*24*7*2) {
447 $age_str = int $age/60/60/24/7;
448 $age_str .= " weeks ago";
449 } elsif ($age > 60*60*24*2) {
450 $age_str = int $age/60/60/24;
451 $age_str .= " days ago";
452 } elsif ($age > 60*60*2) {
453 $age_str = int $age/60/60;
454 $age_str .= " hours ago";
455 } elsif ($age > 60*2) {
456 $age_str = int $age/60;
457 $age_str .= " min ago";
460 $age_str .= " sec ago";
462 $age_str .= " right now";
467 sub git_read_commit {
468 my $commit_id = shift;
469 my $commit_text = shift;
474 if (defined $commit_text) {
475 @commit_lines = @$commit_text;
478 open my $fd, "-|", "$gitbin/git-rev-list --header --parents --max-count=1 $commit_id" or return;
479 @commit_lines = split '\n', <$fd>;
484 my $header = shift @commit_lines;
485 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
488 ($co{'id'}, my @parents) = split ' ', $header;
489 $co{'parents'} = \@parents;
490 $co{'parent'} = $parents[0];
491 while (my $line = shift @commit_lines) {
492 last if $line eq "\n";
493 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
495 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
497 $co{'author_epoch'} = $2;
498 $co{'author_tz'} = $3;
499 if ($co{'author'} =~ m/^([^<]+) </) {
500 $co{'author_name'} = $1;
502 $co{'author_name'} = $co{'author'};
504 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
505 $co{'committer'} = $1;
506 $co{'committer_epoch'} = $2;
507 $co{'committer_tz'} = $3;
508 $co{'committer_name'} = $co{'committer'};
509 $co{'committer_name'} =~ s/ <.*//;
512 if (!defined $co{'tree'}) {
516 foreach my $title (@commit_lines) {
519 $co{'title'} = chop_str($title, 80, 5);
520 # remove leading stuff of merges to make the interesting part visible
521 if (length($title) > 50) {
522 $title =~ s/^Automatic //;
523 $title =~ s/^merge (of|with) /Merge ... /i;
524 if (length($title) > 50) {
525 $title =~ s/(http|rsync):\/\///;
527 if (length($title) > 50) {
528 $title =~ s/(master|www|rsync)\.//;
530 if (length($title) > 50) {
531 $title =~ s/kernel.org:?//;
533 if (length($title) > 50) {
534 $title =~ s/\/pub\/scm//;
537 $co{'title_short'} = chop_str($title, 50, 5);
541 # remove added spaces
542 foreach my $line (@commit_lines) {
545 $co{'comment'} = \@commit_lines;
547 my $age = time - $co{'committer_epoch'};
549 $co{'age_string'} = age_string($age);
550 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
551 if ($age > 60*60*24*7*2) {
552 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
553 $co{'age_string_age'} = $co{'age_string'};
555 $co{'age_string_date'} = $co{'age_string'};
556 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
563 my $from_name = shift;
566 my $format = shift || "html";
568 my $from_tmp = "/dev/null";
569 my $to_tmp = "/dev/null";
572 # create tmp from-file
574 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
575 open my $fd2, "> $from_tmp";
576 open my $fd, "-|", "$gitbin/git-cat-file blob $from";
585 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
586 open my $fd2, "> $to_tmp";
587 open my $fd, "-|", "$gitbin/git-cat-file blob $to";
594 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
595 if ($format eq "plain") {
600 while (my $line = <$fd>) {
602 my $char = substr($line, 0, 1);
605 $color = " style=\"color:#008800;\"";
606 } elsif ($char eq "-") {
607 $color = " style=\"color:#cc0000;\"";
608 } elsif ($char eq "@") {
609 $color = " style=\"color:#990099;\"";
610 } elsif ($char eq "\\") {
614 while ((my $pos = index($line, "\t")) != -1) {
615 if (my $count = (8 - (($pos-1) % 8))) {
616 my $spaces = ' ' x $count;
617 $line =~ s/\t/$spaces/;
620 print "<div class=\"pre\"$color>" . esc_html($line) . "</div>\n";
634 my $mode = oct shift;
636 if (S_ISDIR($mode & S_IFMT)) {
638 } elsif (S_ISLNK($mode)) {
640 } elsif (S_ISREG($mode)) {
641 # git cares only about the executable bit
642 if ($mode & S_IXUSR) {
655 my $add_len = shift || 10;
657 # allow only $len chars, but don't cut a word if it would fit in $add_len
658 # if it doesn't fit, cut it if it's still longer than the dots we would add
659 $str =~ m/^(.{0,$len}[^ \/\-_:\.@]{0,$add_len})(.*)/;
662 if (length($tail) > 4) {
669 my $mode = oct shift;
671 if (S_ISDIR($mode & S_IFMT)) {
673 } elsif (S_ISLNK($mode)) {
675 } elsif (S_ISREG($mode)) {
682 sub format_log_line_html {
685 $line = esc_html($line);
686 $line =~ s/ / /g;
687 if ($line =~ m/([0-9a-fA-F]{40})/) {
689 if (git_get_type($hash_text) eq "commit") {
690 my $link = $cgi->a({-class => "text", -href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_text")}, $hash_text);
691 $line =~ s/$hash_text/$link/;
699 my $tz = shift || "-0000";
702 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
703 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
704 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
705 $date{'hour'} = $hour;
706 $date{'minute'} = $min;
707 $date{'mday'} = $mday;
708 $date{'day'} = $days[$wday];
709 $date{'month'} = $months[$mon];
710 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
711 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
713 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
714 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
715 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
716 $date{'hour_local'} = $hour;
717 $date{'minute_local'} = $min;
718 $date{'tz_local'} = $tz;
722 # git-logo (cached in browser for one day)
724 binmode STDOUT, ':raw';
725 print $cgi->header(-type => 'image/png', -expires => '+1d');
726 # cat git-logo.png | hexdump -e '16/1 " %02x" "\n"' | sed 's/ /\\x/g'
727 print "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52" .
728 "\x00\x00\x00\x48\x00\x00\x00\x1b\x04\x03\x00\x00\x00\x2d\xd9\xd4" .
729 "\x2d\x00\x00\x00\x18\x50\x4c\x54\x45\xff\xff\xff\x60\x60\x5d\xb0" .
730 "\xaf\xaa\x00\x80\x00\xce\xcd\xc7\xc0\x00\x00\xe8\xe8\xe6\xf7\xf7" .
731 "\xf6\x95\x0c\xa7\x47\x00\x00\x00\x73\x49\x44\x41\x54\x28\xcf\x63" .
732 "\x48\x67\x20\x04\x4a\x5c\x18\x0a\x08\x2a\x62\x53\x61\x20\x02\x08" .
733 "\x0d\x69\x45\xac\xa1\xa1\x01\x30\x0c\x93\x60\x36\x26\x52\x91\xb1" .
734 "\x01\x11\xd6\xe1\x55\x64\x6c\x6c\xcc\x6c\x6c\x0c\xa2\x0c\x70\x2a" .
735 "\x62\x06\x2a\xc1\x62\x1d\xb3\x01\x02\x53\xa4\x08\xe8\x00\x03\x18" .
736 "\x26\x56\x11\xd4\xe1\x20\x97\x1b\xe0\xb4\x0e\x35\x24\x71\x29\x82" .
737 "\x99\x30\xb8\x93\x0a\x11\xb9\x45\x88\xc1\x8d\xa0\xa2\x44\x21\x06" .
738 "\x27\x41\x82\x40\x85\xc1\x45\x89\x20\x70\x01\x00\xa4\x3d\x21\xc5" .
739 "\x12\x1c\x9a\xfe\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\x82";
745 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
746 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
747 if (!defined $gcos) {
751 $owner =~ s/[,;].*$//;
752 return decode("utf8", $owner, Encode::FB_DEFAULT);
755 sub git_read_projects {
758 if (-d $projects_list) {
759 # search in directory
760 my $dir = $projects_list;
761 opendir my $dh, $dir or return undef;
762 while (my $dir = readdir($dh)) {
763 if (-e "$projectroot/$dir/HEAD") {
771 } elsif (-f $projects_list) {
772 # read from file(url-encoded):
773 # 'git%2Fgit.git Linus+Torvalds'
774 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
775 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
776 open my $fd , $projects_list or return undef;
777 while (my $line = <$fd>) {
779 my ($path, $owner) = split ' ', $line;
780 $path = unescape($path);
781 $owner = unescape($owner);
782 if (!defined $path) {
785 if (-e "$projectroot/$path/HEAD") {
788 owner => decode("utf8", $owner, Encode::FB_DEFAULT),
795 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
799 sub git_get_project_config {
802 return unless ($key);
803 $key =~ s/^gitweb\.//;
804 return if ($key =~ m/\W/);
806 my $val = qx(git-repo-config --get gitweb.$key);
810 sub git_get_project_config_bool {
811 my $val = git_get_project_config (@_);
812 if ($val and $val =~ m/true|yes|on/) {
815 return; # implicit false
818 sub git_project_list {
819 my @list = git_read_projects();
822 die_error(undef, "No project found.");
824 foreach my $pr (@list) {
825 my $head = git_read_head($pr->{'path'});
826 if (!defined $head) {
829 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
830 my %co = git_read_commit($head);
834 $pr->{'commit'} = \%co;
835 if (!defined $pr->{'descr'}) {
836 my $descr = git_read_description($pr->{'path'}) || "";
837 $pr->{'descr'} = chop_str($descr, 25, 5);
839 if (!defined $pr->{'owner'}) {
840 $pr->{'owner'} = get_file_owner("$projectroot/$pr->{'path'}") || "";
846 print "<div class=\"index_include\">\n";
847 open (my $fd, $home_text);
852 print "<table cellspacing=\"0\">\n" .
854 if (!defined($order) || (defined($order) && ($order eq "project"))) {
855 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
856 print "<th>Project</th>\n";
858 print "<th>" . $cgi->a({-class => "header", -href => "$my_uri?" . esc_param("o=project")}, "Project") . "</th>\n";
860 if (defined($order) && ($order eq "descr")) {
861 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
862 print "<th>Description</th>\n";
864 print "<th>" . $cgi->a({-class => "header", -href => "$my_uri?" . esc_param("o=descr")}, "Description") . "</th>\n";
866 if (defined($order) && ($order eq "owner")) {
867 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
868 print "<th>Owner</th>\n";
870 print "<th>" . $cgi->a({-class => "header", -href => "$my_uri?" . esc_param("o=owner")}, "Owner") . "</th>\n";
872 if (defined($order) && ($order eq "age")) {
873 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
874 print "<th>Last Change</th>\n";
876 print "<th>" . $cgi->a({-class => "header", -href => "$my_uri?" . esc_param("o=age")}, "Last Change") . "</th>\n";
878 print "<th></th>\n" .
881 foreach my $pr (@projects) {
883 print "<tr class=\"dark\">\n";
885 print "<tr class=\"light\">\n";
888 print "<td>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=summary"), -class => "list"}, esc_html($pr->{'path'})) . "</td>\n" .
889 "<td>$pr->{'descr'}</td>\n" .
890 "<td><i>" . chop_str($pr->{'owner'}, 15) . "</i></td>\n";
892 if ($pr->{'commit'}{'age'} < 60*60*2) {
893 $colored_age = "<span style =\"color: #009900;\"><b><i>$pr->{'commit'}{'age_string'}</i></b></span>";
894 } elsif ($pr->{'commit'}{'age'} < 60*60*24*2) {
895 $colored_age = "<span style =\"color: #009900;\"><i>$pr->{'commit'}{'age_string'}</i></span>";
897 $colored_age = "<i>$pr->{'commit'}{'age_string'}</i>";
899 print "<td>$colored_age</td>\n" .
900 "<td class=\"link\">" .
901 $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=summary")}, "summary") .
902 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=shortlog")}, "shortlog") .
903 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=log")}, "log") .
912 my $type = shift || "";
914 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
915 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
916 open my $fd, "$projectroot/$project/info/refs" or return;
917 while (my $line = <$fd>) {
919 if ($line =~ m/^([0-9a-fA-F]{40})\t.*$type\/([^\^]+)/) {
920 if (defined $refs{$1}) {
921 $refs{$1} .= " / $2";
936 opendir my $dh, "$projectroot/$project/$ref_dir";
937 while (my $dir = readdir($dh)) {
938 if ($dir =~ m/^\./) {
941 if (-d "$projectroot/$project/$ref_dir/$dir") {
942 opendir my $dh2, "$projectroot/$project/$ref_dir/$dir";
943 my @subdirs = grep !m/^\./, readdir $dh2;
945 foreach my $subdir (@subdirs) {
946 push @refs, "$dir/$subdir"
953 foreach my $ref_file (@refs) {
954 my $ref_id = git_read_hash("$project/$ref_dir/$ref_file");
955 my $type = git_get_type($ref_id) || next;
958 $ref_item{'type'} = $type;
959 $ref_item{'id'} = $ref_id;
960 $ref_item{'epoch'} = 0;
961 $ref_item{'age'} = "unknown";
962 if ($type eq "tag") {
963 my %tag = git_read_tag($ref_id);
964 $ref_item{'comment'} = $tag{'comment'};
965 if ($tag{'type'} eq "commit") {
966 %co = git_read_commit($tag{'object'});
967 $ref_item{'epoch'} = $co{'committer_epoch'};
968 $ref_item{'age'} = $co{'age_string'};
969 } elsif (defined($tag{'epoch'})) {
970 my $age = time - $tag{'epoch'};
971 $ref_item{'epoch'} = $tag{'epoch'};
972 $ref_item{'age'} = age_string($age);
974 $ref_item{'reftype'} = $tag{'type'};
975 $ref_item{'name'} = $tag{'name'};
976 $ref_item{'refid'} = $tag{'object'};
977 } elsif ($type eq "commit"){
978 %co = git_read_commit($ref_id);
979 $ref_item{'reftype'} = "commit";
980 $ref_item{'name'} = $ref_file;
981 $ref_item{'title'} = $co{'title'};
982 $ref_item{'refid'} = $ref_id;
983 $ref_item{'epoch'} = $co{'committer_epoch'};
984 $ref_item{'age'} = $co{'age_string'};
987 push @reflist, \%ref_item;
990 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
995 my $descr = git_read_description($project) || "none";
996 my $head = git_read_head($project);
997 my %co = git_read_commit($head);
998 my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'});
1001 if (-f $projects_list) {
1002 open (my $fd , $projects_list);
1003 while (my $line = <$fd>) {
1005 my ($pr, $ow) = split ' ', $line;
1006 $pr = unescape($pr);
1007 $ow = unescape($ow);
1008 if ($pr eq $project) {
1009 $owner = decode("utf8", $ow, Encode::FB_DEFAULT);
1015 if (!defined $owner) {
1016 $owner = get_file_owner("$projectroot/$project");
1019 my $refs = read_info_ref();
1021 print "<div class=\"page_nav\">\n" .
1023 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
1024 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") .
1025 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$head")}, "commit") .
1026 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1027 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree")}, "tree") .
1030 print "<div class=\"title\"> </div>\n";
1031 print "<table cellspacing=\"0\">\n" .
1032 "<tr><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
1033 "<tr><td>owner</td><td>$owner</td></tr>\n" .
1034 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
1036 open my $fd, "-|", "$gitbin/git-rev-list --max-count=17 " . git_read_head($project) or die_error(undef, "Open failed.");
1037 my (@revlist) = map { chomp; $_ } <$fd>;
1040 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog"), -class => "title"}, "shortlog") .
1043 print "<table cellspacing=\"0\">\n";
1045 foreach my $commit (@revlist) {
1046 my %co = git_read_commit($commit);
1047 my %ad = date_str($co{'author_epoch'});
1049 print "<tr class=\"dark\">\n";
1051 print "<tr class=\"light\">\n";
1056 if (defined $refs->{$commit}) {
1057 $ref = " <span class=\"tag\">" . esc_html($refs->{$commit}) . "</span>";
1059 print "<td><i>$co{'age_string'}</i></td>\n" .
1060 "<td><i>" . esc_html(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
1062 if (length($co{'title_short'}) < length($co{'title'})) {
1063 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "list", -title => "$co{'title'}"},
1064 "<b>" . esc_html($co{'title_short'}) . "$ref</b>");
1066 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "list"},
1067 "<b>" . esc_html($co{'title'}) . "$ref</b>");
1070 "<td class=\"link\">" .
1071 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit")}, "commit") .
1072 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1076 print "<td>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "...") . "</td>\n" .
1083 my $taglist = git_read_refs("refs/tags");
1084 if (defined @$taglist) {
1086 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tags"), -class => "title"}, "tags") .
1089 print "<table cellspacing=\"0\">\n";
1091 foreach my $entry (@$taglist) {
1093 my $comment_lines = $tag{'comment'};
1094 my $comment = shift @$comment_lines;
1095 if (defined($comment)) {
1096 $comment = chop_str($comment, 30, 5);
1099 print "<tr class=\"dark\">\n";
1101 print "<tr class=\"light\">\n";
1105 print "<td><i>$tag{'age'}</i></td>\n" .
1107 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), -class => "list"},
1108 "<b>" . esc_html($tag{'name'}) . "</b>") .
1111 if (defined($comment)) {
1112 print $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, $comment);
1115 "<td class=\"link\">";
1116 if ($tag{'type'} eq "tag") {
1117 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
1119 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1120 if ($tag{'reftype'} eq "commit") {
1121 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1122 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'refid'}")}, "log");
1127 print "<td>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tags")}, "...") . "</td>\n" .
1135 my $headlist = git_read_refs("refs/heads");
1136 if (defined @$headlist) {
1138 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=heads"), -class => "title"}, "heads") .
1141 print "<table cellspacing=\"0\">\n";
1143 foreach my $entry (@$headlist) {
1146 print "<tr class=\"dark\">\n";
1148 print "<tr class=\"light\">\n";
1152 print "<td><i>$tag{'age'}</i></td>\n" .
1154 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}"), -class => "list"},
1155 "<b>" . esc_html($tag{'name'}) . "</b>") .
1157 "<td class=\"link\">" .
1158 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1159 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'name'}")}, "log") .
1163 print "<td>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=heads")}, "...") . "</td>\n" .
1174 my $head = git_read_head($project);
1176 print "<div class=\"page_nav\">\n" .
1177 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
1178 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
1179 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") .
1180 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$head")}, "commit") .
1181 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1182 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1185 my %tag = git_read_tag($hash);
1187 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html($tag{'name'})) . "\n" .
1189 print "<div class=\"title_text\">\n" .
1190 "<table cellspacing=\"0\">\n" .
1192 "<td>object</td>\n" .
1193 "<td>" . $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'object'}) . "</td>\n" .
1194 "<td class=\"link\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'type'}) . "</td>\n" .
1196 if (defined($tag{'author'})) {
1197 my %ad = date_str($tag{'epoch'}, $tag{'tz'});
1198 print "<tr><td>author</td><td>" . esc_html($tag{'author'}) . "</td></tr>\n";
1199 print "<tr><td></td><td>" . $ad{'rfc2822'} . sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) . "</td></tr>\n";
1201 print "</table>\n\n" .
1203 print "<div class=\"page_body\">";
1204 my $comment = $tag{'comment'};
1205 foreach my $line (@$comment) {
1206 print esc_html($line) . "<br/>\n";
1214 die_error('403 Permission denied', "Permission denied.") if (!git_get_project_config_bool ('blame'));
1215 die_error('404 Not Found', "What file will it be, master?") if (!$file_name);
1216 $hash_base ||= git_read_head($project);
1217 die_error(undef, "Reading commit failed.") unless ($hash_base);
1218 my %co = git_read_commit($hash_base)
1219 or die_error(undef, "Reading commit failed.");
1220 if (!defined $hash) {
1221 $hash = git_get_hash_by_path($hash_base, $file_name, "blob")
1222 or die_error(undef, "Error lookup file.");
1224 open ($fd, "-|", "$gitbin/git-annotate", '-l', '-t', '-r', $file_name, $hash_base)
1225 or die_error(undef, "Open failed.");
1227 print "<div class=\"page_nav\">\n" .
1228 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
1229 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
1230 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") .
1231 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base")}, "commit") .
1232 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1233 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") . "<br/>\n";
1234 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") .
1235 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;f=$file_name")}, "head") . "<br/>\n";
1238 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) .
1240 print "<div class=\"page_path\"><b>" . esc_html($file_name) . "</b></div>\n";
1241 print "<div class=\"page_body\">\n";
1243 <table style="border-collapse: collapse;">
1252 my @line_class = (qw(light dark));
1253 my $line_class_len = scalar (@line_class);
1254 my $line_class_num = $#line_class;
1255 while (my $line = <$fd>) {
1267 $line_class_num = ($line_class_num + 1) % $line_class_len;
1269 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) \+\d\d\d\d\t(\d+)\)(.*)$/) {
1276 print qq( <tr><td colspan="5" style="color: red; background-color: yellow;">Unable to parse: $line</td></tr>\n);
1279 $short_rev = substr ($long_rev, 0, 8);
1280 $age = time () - $time;
1281 $age_str = age_string ($age);
1282 $age_str =~ s/ / /g;
1283 $age_style = 'font-style: italic;';
1284 $age_style .= ' color: #009900; background: transparent;' if ($age < 60*60*24*2);
1285 $age_style .= ' font-weight: bold;' if ($age < 60*60*2);
1286 $author = esc_html ($author);
1287 $author =~ s/ / /g;
1289 while ((my $pos = index($data, "\t")) != -1) {
1290 if (my $count = (8 - ($pos % 8))) {
1291 my $spaces = ' ' x $count;
1292 $data =~ s/\t/$spaces/;
1295 $data = esc_html ($data);
1296 $data =~ s/ / /g;
1299 <tr class="$line_class[$line_class_num]">
1300 <td style="font-family: monospace;"><a href="$my_uri?${\esc_param ("p=$project;a=commit;h=$long_rev")}" class="text">$short_rev..</a></td>
1301 <td style="$age_style">$age_str</td>
1303 <td style="text-align: right;"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
1304 <td style="font-family: monospace;">$data</td>
1307 } # while (my $line = <$fd>)
1308 print "</table>\n\n";
1309 close $fd or print "Reading blob failed.\n";
1315 my $head = git_read_head($project);
1317 print "<div class=\"page_nav\">\n" .
1318 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
1319 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
1320 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") .
1321 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$head")}, "commit") .
1322 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1323 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1326 my $taglist = git_read_refs("refs/tags");
1328 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary"), -class => "title"}, " ") .
1330 print "<table cellspacing=\"0\">\n";
1332 if (defined @$taglist) {
1333 foreach my $entry (@$taglist) {
1335 my $comment_lines = $tag{'comment'};
1336 my $comment = shift @$comment_lines;
1337 if (defined($comment)) {
1338 $comment = chop_str($comment, 30, 5);
1341 print "<tr class=\"dark\">\n";
1343 print "<tr class=\"light\">\n";
1346 print "<td><i>$tag{'age'}</i></td>\n" .
1348 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), -class => "list"},
1349 "<b>" . esc_html($tag{'name'}) . "</b>") .
1352 if (defined($comment)) {
1353 print $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, $comment);
1356 "<td class=\"link\">";
1357 if ($tag{'type'} eq "tag") {
1358 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
1360 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1361 if ($tag{'reftype'} eq "commit") {
1362 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1363 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'refid'}")}, "log");
1374 my $head = git_read_head($project);
1376 print "<div class=\"page_nav\">\n" .
1377 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
1378 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
1379 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") .
1380 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$head")}, "commit") .
1381 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1382 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1385 my $taglist = git_read_refs("refs/heads");
1387 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary"), -class => "title"}, " ") .
1389 print "<table cellspacing=\"0\">\n";
1391 if (defined @$taglist) {
1392 foreach my $entry (@$taglist) {
1395 print "<tr class=\"dark\">\n";
1397 print "<tr class=\"light\">\n";
1400 print "<td><i>$tag{'age'}</i></td>\n" .
1402 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}"), -class => "list"}, "<b>" . esc_html($tag{'name'}) . "</b>") .
1404 "<td class=\"link\">" .
1405 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1406 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'name'}")}, "log") .
1415 sub git_get_hash_by_path {
1417 my $path = shift || return undef;
1420 my @parts = split '/', $path;
1421 while (my $part = shift @parts) {
1422 open my $fd, "-|", "$gitbin/git-ls-tree $tree" or die_error(undef, "Open git-ls-tree failed.");
1423 my (@entries) = map { chomp; $_ } <$fd>;
1424 close $fd or return undef;
1425 foreach my $line (@entries) {
1426 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1427 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1431 my $t_name = validate_input(unquote($4));
1432 if ($t_name eq $part) {
1436 if ($t_type eq "tree") {
1446 if (!defined $hash && defined $file_name) {
1447 my $base = $hash_base || git_read_head($project);
1448 $hash = git_get_hash_by_path($base, $file_name, "blob") || die_error(undef, "Error lookup file.");
1450 my $have_blame = git_get_project_config_bool ('blame');
1451 open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or die_error(undef, "Open failed.");
1453 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
1454 print "<div class=\"page_nav\">\n" .
1455 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
1456 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
1457 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") .
1458 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base")}, "commit") .
1459 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1460 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") . "<br/>\n";
1461 if (defined $file_name) {
1463 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$hash;hb=$hash_base;f=$file_name")}, "blame") . " | ";
1465 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$hash;f=$file_name")}, "plain") .
1466 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;hb=HEAD;f=$file_name")}, "head") . "<br/>\n";
1468 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$hash")}, "plain") . "<br/>\n";
1472 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) .
1475 print "<div class=\"page_nav\">\n" .
1476 "<br/><br/></div>\n" .
1477 "<div class=\"title\">$hash</div>\n";
1479 if (defined $file_name) {
1480 print "<div class=\"page_path\"><b>" . esc_html($file_name) . "</b></div>\n";
1482 print "<div class=\"page_body\">\n";
1484 while (my $line = <$fd>) {
1487 while ((my $pos = index($line, "\t")) != -1) {
1488 if (my $count = (8 - ($pos % 8))) {
1489 my $spaces = ' ' x $count;
1490 $line =~ s/\t/$spaces/;
1493 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", $nr, $nr, $nr, esc_html($line);
1495 close $fd or print "Reading blob failed.\n";
1500 sub mimetype_guess_file {
1501 my $filename = shift;
1502 my $mimemap = shift;
1503 -r $mimemap or return undef;
1506 open(MIME, $mimemap) or return undef;
1508 my ($mime, $exts) = split(/\t+/);
1509 my @exts = split(/\s+/, $exts);
1510 foreach my $ext (@exts) {
1511 $mimemap{$ext} = $mime;
1516 $filename =~ /\.(.*?)$/;
1517 return $mimemap{$1};
1520 sub mimetype_guess {
1521 my $filename = shift;
1523 $filename =~ /\./ or return undef;
1525 if ($mimetypes_file) {
1526 my $file = $mimetypes_file;
1527 #$file =~ m#^/# or $file = "$projectroot/$path/$file";
1528 $mime = mimetype_guess_file($filename, $file);
1530 $mime ||= mimetype_guess_file($filename, '/etc/mime.types');
1534 sub git_blob_plain_mimetype {
1536 my $filename = shift;
1539 return $default_blob_plain_mimetype unless $fd;
1542 my $mime = mimetype_guess($filename);
1543 $mime and return $mime;
1547 return 'text/plain' .
1548 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1549 } elsif (! $filename) {
1550 return 'application/octet-stream';
1551 } elsif ($filename =~ m/\.png$/i) {
1553 } elsif ($filename =~ m/\.gif$/i) {
1555 } elsif ($filename =~ m/\.jpe?g$/i) {
1556 return 'image/jpeg';
1558 return 'application/octet-stream';
1562 sub git_blob_plain {
1563 open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or return;
1564 my $type = git_blob_plain_mimetype($fd, $file_name);
1566 # save as filename, even when no $file_name is given
1567 my $save_as = "$hash";
1568 if (defined $file_name) {
1569 $save_as = $file_name;
1570 } elsif ($type =~ m/^text\//) {
1574 print $cgi->header(-type => "$type", '-content-disposition' => "inline; filename=\"$save_as\"");
1576 binmode STDOUT, ':raw';
1578 binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
1584 if (!defined $hash) {
1585 $hash = git_read_head($project);
1586 if (defined $file_name) {
1587 my $base = $hash_base || $hash;
1588 $hash = git_get_hash_by_path($base, $file_name, "tree");
1590 if (!defined $hash_base) {
1595 open my $fd, "-|", "$gitbin/git-ls-tree -z $hash" or die_error(undef, "Open git-ls-tree failed.");
1596 chomp (my (@entries) = <$fd>);
1597 close $fd or die_error(undef, "Reading tree failed.");
1600 my $refs = read_info_ref();
1602 if (defined $refs->{$hash_base}) {
1603 $ref = " <span class=\"tag\">" . esc_html($refs->{$hash_base}) . "</span>";
1608 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
1609 $base_key = ";hb=$hash_base";
1610 print "<div class=\"page_nav\">\n" .
1611 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
1612 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash_base")}, "shortlog") .
1613 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash_base")}, "log") .
1614 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base")}, "commit") .
1615 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1620 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'}) . $ref) . "\n" .
1623 print "<div class=\"page_nav\">\n";
1624 print "<br/><br/></div>\n";
1625 print "<div class=\"title\">$hash</div>\n";
1627 if (defined $file_name) {
1628 $base = esc_html("$file_name/");
1629 print "<div class=\"page_path\"><b>/" . esc_html($file_name) . "</b></div>\n";
1631 print "<div class=\"page_path\"><b>/</b></div>\n";
1633 print "<div class=\"page_body\">\n";
1634 print "<table cellspacing=\"0\">\n";
1636 foreach my $line (@entries) {
1637 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1638 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1642 my $t_name = validate_input($4);
1644 print "<tr class=\"dark\">\n";
1646 print "<tr class=\"light\">\n";
1649 print "<td style=\"font-family:monospace\">" . mode_str($t_mode) . "</td>\n";
1650 if ($t_type eq "blob") {
1651 print "<td class=\"list\">" .
1652 $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)) .
1654 "<td class=\"link\">" .
1655 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name")}, "blob") .
1656 # " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$t_hash$base_key;f=$base$t_name")}, "blame") .
1657 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;h=$hash_base;f=$base$t_name")}, "history") .
1659 } elsif ($t_type eq "tree") {
1660 print "<td class=\"list\">" .
1661 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, esc_html($t_name)) .
1663 "<td class=\"link\">" .
1664 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, "tree") .
1669 print "</table>\n" .
1675 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
1676 open my $fd, "-|", "$gitbin/git-rev-list --max-count=150 " . git_read_head($project) or die_error(undef, "Open failed.");
1677 my (@revlist) = map { chomp; $_ } <$fd>;
1678 close $fd or die_error(undef, "Reading rev-list failed.");
1679 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
1680 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1681 "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
1682 print "<channel>\n";
1683 print "<title>$project</title>\n".
1684 "<link>" . esc_html("$my_url?p=$project;a=summary") . "</link>\n".
1685 "<description>$project log</description>\n".
1686 "<language>en</language>\n";
1688 for (my $i = 0; $i <= $#revlist; $i++) {
1689 my $commit = $revlist[$i];
1690 my %co = git_read_commit($commit);
1691 # we read 150, we always show 30 and the ones more recent than 48 hours
1692 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
1695 my %cd = date_str($co{'committer_epoch'});
1696 open $fd, "-|", "$gitbin/git-diff-tree -r $co{'parent'} $co{'id'}" or next;
1697 my @difftree = map { chomp; $_ } <$fd>;
1701 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html($co{'title'}) .
1703 "<author>" . esc_html($co{'author'}) . "</author>\n" .
1704 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
1705 "<guid isPermaLink=\"true\">" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
1706 "<link>" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
1707 "<description>" . esc_html($co{'title'}) . "</description>\n" .
1708 "<content:encoded>" .
1710 my $comment = $co{'comment'};
1711 foreach my $line (@$comment) {
1712 $line = decode("utf8", $line, Encode::FB_DEFAULT);
1713 print "$line<br/>\n";
1716 foreach my $line (@difftree) {
1717 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
1720 my $file = validate_input(unquote($7));
1721 $file = decode("utf8", $file, Encode::FB_DEFAULT);
1722 print "$file<br/>\n";
1725 "</content:encoded>\n" .
1728 print "</channel></rss>";
1732 my @list = git_read_projects();
1734 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
1735 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1736 "<opml version=\"1.0\">\n".
1738 " <title>Git OPML Export</title>\n".
1741 "<outline text=\"git RSS feeds\">\n";
1743 foreach my $pr (@list) {
1745 my $head = git_read_head($proj{'path'});
1746 if (!defined $head) {
1749 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
1750 my %co = git_read_commit($head);
1755 my $path = esc_html(chop_str($proj{'path'}, 25, 5));
1756 my $rss = "$my_url?p=$proj{'path'};a=rss";
1757 my $html = "$my_url?p=$proj{'path'};a=summary";
1758 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
1760 print "</outline>\n".
1766 my $head = git_read_head($project);
1767 if (!defined $hash) {
1770 if (!defined $page) {
1773 my $refs = read_info_ref();
1775 print "<div class=\"page_nav\">\n";
1776 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
1777 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash")}, "shortlog") .
1779 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash")}, "commit") .
1780 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
1781 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$hash;hb=$hash")}, "tree") . "<br/>\n";
1783 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
1784 open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error(undef, "Open failed.");
1785 my (@revlist) = map { chomp; $_ } <$fd>;
1788 if ($hash ne $head || $page) {
1789 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "HEAD");
1795 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash;pg=" . ($page-1)), -accesskey => "p", -title => "Alt-p"}, "prev");
1797 print " ⋅ prev";
1799 if ($#revlist >= (100 * ($page+1)-1)) {
1801 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash;pg=" . ($page+1)), -accesskey => "n", -title => "Alt-n"}, "next");
1803 print " ⋅ next";
1809 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary"), -class => "title"}, " ") .
1811 my %co = git_read_commit($hash);
1812 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
1814 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
1815 my $commit = $revlist[$i];
1817 if (defined $refs->{$commit}) {
1818 $ref = " <span class=\"tag\">" . esc_html($refs->{$commit}) . "</span>";
1820 my %co = git_read_commit($commit);
1822 my %ad = date_str($co{'author_epoch'});
1824 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "title"},
1825 "<span class=\"age\">$co{'age_string'}</span>" . esc_html($co{'title'}) . $ref) . "\n";
1827 print "<div class=\"title_text\">\n" .
1828 "<div class=\"log_link\">\n" .
1829 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit")}, "commit") .
1830 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1833 "<i>" . esc_html($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
1835 "<div class=\"log_body\">\n";
1836 my $comment = $co{'comment'};
1838 foreach my $line (@$comment) {
1839 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1850 print format_log_line_html($line) . "<br/>\n";
1861 my %co = git_read_commit($hash);
1863 die_error(undef, "Unknown commit object.");
1865 my %ad = date_str($co{'author_epoch'}, $co{'author_tz'});
1866 my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'});
1870 my $parent = $co{'parent'};
1871 if (!defined $parent) {
1875 open my $fd, "-|", "$gitbin/git-diff-tree -r -M $root $parent $hash" or die_error(undef, "Open failed.");
1876 @difftree = map { chomp; $_ } <$fd>;
1877 close $fd or die_error(undef, "Reading diff-tree failed.");
1879 # non-textual hash id's can be cached
1881 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
1884 my $refs = read_info_ref();
1886 if (defined $refs->{$co{'id'}}) {
1887 $ref = " <span class=\"tag\">" . esc_html($refs->{$co{'id'}}) . "</span>";
1889 git_header_html(undef, $expires);
1890 print "<div class=\"page_nav\">\n" .
1891 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
1892 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash")}, "shortlog") .
1893 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash")}, "log") .
1895 if (defined $co{'parent'}) {
1896 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash")}, "commitdiff");
1898 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") . "\n" .
1899 "<br/><br/></div>\n";
1900 if (defined $co{'parent'}) {
1902 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash"), -class => "title"}, esc_html($co{'title'}) . $ref) . "\n" .
1906 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash"), -class => "title"}, esc_html($co{'title'})) . "\n" .
1909 print "<div class=\"title_text\">\n" .
1910 "<table cellspacing=\"0\">\n";
1911 print "<tr><td>author</td><td>" . esc_html($co{'author'}) . "</td></tr>\n".
1913 "<td></td><td> $ad{'rfc2822'}";
1914 if ($ad{'hour_local'} < 6) {
1915 printf(" (<span style=\"color: #cc0000;\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1917 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1921 print "<tr><td>committer</td><td>" . esc_html($co{'committer'}) . "</td></tr>\n";
1922 print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
1923 print "<tr><td>commit</td><td style=\"font-family:monospace\">$co{'id'}</td></tr>\n";
1926 "<td style=\"font-family:monospace\">" .
1927 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash"), class => "list"}, $co{'tree'}) .
1929 "<td class=\"link\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
1932 my $parents = $co{'parents'};
1933 foreach my $par (@$parents) {
1936 "<td style=\"font-family:monospace\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$par"), class => "list"}, $par) . "</td>" .
1937 "<td class=\"link\">" .
1938 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$par")}, "commit") .
1939 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash;hp=$par")}, "commitdiff") .
1945 print "<div class=\"page_body\">\n";
1946 my $comment = $co{'comment'};
1949 foreach my $line (@$comment) {
1950 # print only one empty line
1952 if ($empty || $signed) {
1959 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1961 print "<span style=\"color: #888888\">" . esc_html($line) . "</span><br/>\n";
1964 print format_log_line_html($line) . "<br/>\n";
1968 print "<div class=\"list_head\">\n";
1969 if ($#difftree > 10) {
1970 print(($#difftree + 1) . " files changed:\n");
1973 print "<table cellspacing=\"0\">\n";
1975 foreach my $line (@difftree) {
1976 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1977 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1978 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
1986 my $similarity = $6;
1987 my $file = validate_input(unquote($7));
1989 print "<tr class=\"dark\">\n";
1991 print "<tr class=\"light\">\n";
1994 if ($status eq "A") {
1996 if (S_ISREG(oct $to_mode)) {
1997 $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
2000 $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" .
2001 "<td><span style=\"color: #008000;\">[new " . file_type($to_mode) . "$mode_chng]</span></td>\n" .
2002 "<td class=\"link\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob") . "</td>\n";
2003 } elsif ($status eq "D") {
2005 $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" .
2006 "<td><span style=\"color: #c00000;\">[deleted " . file_type($from_mode). "]</span></td>\n" .
2007 "<td class=\"link\">" .
2008 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, "blob") .
2009 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;h=$hash;f=$file")}, "history") .
2011 } elsif ($status eq "M" || $status eq "T") {
2012 my $mode_chnge = "";
2013 if ($from_mode != $to_mode) {
2014 $mode_chnge = " <span style=\"color: #777777;\">[changed";
2015 if (((oct $from_mode) & S_IFMT) != ((oct $to_mode) & S_IFMT)) {
2016 $mode_chnge .= " from " . file_type($from_mode) . " to " . file_type($to_mode);
2018 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
2019 if (S_ISREG($from_mode) && S_ISREG($to_mode)) {
2020 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
2021 } elsif (S_ISREG($to_mode)) {
2022 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
2025 $mode_chnge .= "]</span>\n";
2028 if ($to_id ne $from_id) {
2029 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));
2031 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file"), -class => "list"}, esc_html($file));
2034 "<td>$mode_chnge</td>\n" .
2035 "<td class=\"link\">";
2036 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob");
2037 if ($to_id ne $from_id) {
2038 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file")}, "diff");
2040 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;h=$hash;f=$file")}, "history") . "\n";
2042 } elsif ($status eq "R") {
2043 my ($from_file, $to_file) = split "\t", $file;
2045 if ($from_mode != $to_mode) {
2046 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
2049 $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" .
2050 "<td><span style=\"color: #777777;\">[moved from " .
2051 $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)) .
2052 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
2053 "<td class=\"link\">" .
2054 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file")}, "blob");
2055 if ($to_id ne $from_id) {
2056 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file")}, "diff");
2067 mkdir($git_temp, 0700);
2069 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
2070 print "<div class=\"page_nav\">\n" .
2071 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
2072 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
2073 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") .
2074 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base")}, "commit") .
2075 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
2076 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") .
2078 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff_plain;h=$hash;hp=$hash_parent")}, "plain") .
2081 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) . "\n" .
2084 print "<div class=\"page_nav\">\n" .
2085 "<br/><br/></div>\n" .
2086 "<div class=\"title\">$hash vs $hash_parent</div>\n";
2088 if (defined $file_name) {
2089 print "<div class=\"page_path\"><b>/" . esc_html($file_name) . "</b></div>\n";
2091 print "<div class=\"page_body\">\n" .
2092 "<div class=\"diff_info\">blob:" .
2093 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name")}, $hash_parent) .
2095 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, $hash) .
2097 git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
2102 sub git_blobdiff_plain {
2103 mkdir($git_temp, 0700);
2104 print $cgi->header(-type => "text/plain", -charset => 'utf-8');
2105 git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
2108 sub git_commitdiff {
2109 mkdir($git_temp, 0700);
2110 my %co = git_read_commit($hash);
2112 die_error(undef, "Unknown commit object.");
2114 if (!defined $hash_parent) {
2115 $hash_parent = $co{'parent'};
2117 open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error(undef, "Open failed.");
2118 my (@difftree) = map { chomp; $_ } <$fd>;
2119 close $fd or die_error(undef, "Reading diff-tree failed.");
2121 # non-textual hash id's can be cached
2123 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2126 my $refs = read_info_ref();
2128 if (defined $refs->{$co{'id'}}) {
2129 $ref = " <span class=\"tag\">" . esc_html($refs->{$co{'id'}}) . "</span>";
2131 git_header_html(undef, $expires);
2132 print "<div class=\"page_nav\">\n" .
2133 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
2134 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash")}, "shortlog") .
2135 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash")}, "log") .
2136 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash")}, "commit") .
2138 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") . "<br/>\n";
2139 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent")}, "plain") . "\n" .
2142 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html($co{'title'}) . $ref) . "\n" .
2144 print "<div class=\"page_body\">\n";
2145 my $comment = $co{'comment'};
2148 my @log = @$comment;
2149 # remove first and empty lines after that
2151 while (defined $log[0] && $log[0] eq "") {
2154 foreach my $line (@log) {
2155 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2166 print format_log_line_html($line) . "<br/>\n";
2169 foreach my $line (@difftree) {
2170 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2171 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2172 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2178 my $file = validate_input(unquote($6));
2179 if ($status eq "A") {
2180 print "<div class=\"diff_info\">" . file_type($to_mode) . ":" .
2181 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id) . "(new)" .
2183 git_diff_print(undef, "/dev/null", $to_id, "b/$file");
2184 } elsif ($status eq "D") {
2185 print "<div class=\"diff_info\">" . file_type($from_mode) . ":" .
2186 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) . "(deleted)" .
2188 git_diff_print($from_id, "a/$file", undef, "/dev/null");
2189 } elsif ($status eq "M") {
2190 if ($from_id ne $to_id) {
2191 print "<div class=\"diff_info\">" .
2192 file_type($from_mode) . ":" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) .
2194 file_type($to_mode) . ":" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id);
2196 git_diff_print($from_id, "a/$file", $to_id, "b/$file");
2205 sub git_commitdiff_plain {
2206 mkdir($git_temp, 0700);
2207 open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error(undef, "Open failed.");
2208 my (@difftree) = map { chomp; $_ } <$fd>;
2209 close $fd or die_error(undef, "Reading diff-tree failed.");
2211 # try to figure out the next tag after this commit
2213 my $refs = read_info_ref("tags");
2214 open $fd, "-|", "$gitbin/git-rev-list HEAD";
2215 chomp (my (@commits) = <$fd>);
2217 foreach my $commit (@commits) {
2218 if (defined $refs->{$commit}) {
2219 $tagname = $refs->{$commit}
2221 if ($commit eq $hash) {
2226 print $cgi->header(-type => "text/plain", -charset => 'utf-8', '-content-disposition' => "inline; filename=\"git-$hash.patch\"");
2227 my %co = git_read_commit($hash);
2228 my %ad = date_str($co{'author_epoch'}, $co{'author_tz'});
2229 my $comment = $co{'comment'};
2230 print "From: $co{'author'}\n" .
2231 "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
2232 "Subject: $co{'title'}\n";
2233 if (defined $tagname) {
2234 print "X-Git-Tag: $tagname\n";
2236 print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
2239 foreach my $line (@$comment) {;
2244 foreach my $line (@difftree) {
2245 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2250 if ($status eq "A") {
2251 git_diff_print(undef, "/dev/null", $to_id, "b/$file", "plain");
2252 } elsif ($status eq "D") {
2253 git_diff_print($from_id, "a/$file", undef, "/dev/null", "plain");
2254 } elsif ($status eq "M") {
2255 git_diff_print($from_id, "a/$file", $to_id, "b/$file", "plain");
2261 if (!defined $hash) {
2262 $hash = git_read_head($project);
2264 my %co = git_read_commit($hash);
2266 die_error(undef, "Unknown commit object.");
2268 my $refs = read_info_ref();
2270 print "<div class=\"page_nav\">\n" .
2271 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
2272 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
2273 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") .
2274 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash")}, "commit") .
2275 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2276 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
2280 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html($co{'title'})) . "\n" .
2282 print "<div class=\"page_path\"><b>/" . esc_html($file_name) . "</b><br/></div>\n";
2284 open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin -- \'$file_name\'";
2286 print "<table cellspacing=\"0\">\n";
2288 while (my $line = <$fd>) {
2289 if ($line =~ m/^([0-9a-fA-F]{40})/){
2293 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/ && (defined $commit)) {
2294 my %co = git_read_commit($commit);
2299 if (defined $refs->{$commit}) {
2300 $ref = " <span class=\"tag\">" . esc_html($refs->{$commit}) . "</span>";
2303 print "<tr class=\"dark\">\n";
2305 print "<tr class=\"light\">\n";
2308 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2309 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2310 "<td>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "list"}, "<b>" .
2311 esc_html(chop_str($co{'title'}, 50)) . "$ref</b>") . "</td>\n" .
2312 "<td class=\"link\">" .
2313 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit")}, "commit") .
2314 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2315 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;hb=$commit;f=$file_name")}, "blob");
2316 my $blob = git_get_hash_by_path($hash, $file_name);
2317 my $blob_parent = git_get_hash_by_path($commit, $file_name);
2318 if (defined $blob && defined $blob_parent && $blob ne $blob_parent) {
2320 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=$file_name")},
2334 if (!defined $searchtext) {
2335 die_error("", "Text field empty.");
2337 if (!defined $hash) {
2338 $hash = git_read_head($project);
2340 my %co = git_read_commit($hash);
2342 die_error(undef, "Unknown commit object.");
2344 # pickaxe may take all resources of your box and run for several minutes
2345 # with every query - so decide by yourself how public you make this feature :)
2346 my $commit_search = 1;
2347 my $author_search = 0;
2348 my $committer_search = 0;
2349 my $pickaxe_search = 0;
2350 if ($searchtext =~ s/^author\\://i) {
2352 } elsif ($searchtext =~ s/^committer\\://i) {
2353 $committer_search = 1;
2354 } elsif ($searchtext =~ s/^pickaxe\\://i) {
2356 $pickaxe_search = 1;
2359 print "<div class=\"page_nav\">\n" .
2360 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary;h=$hash")}, "summary") .
2361 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
2362 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash")}, "log") .
2363 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash")}, "commit") .
2364 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2365 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
2370 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html($co{'title'})) . "\n" .
2372 print "<table cellspacing=\"0\">\n";
2374 if ($commit_search) {
2376 open my $fd, "-|", "$gitbin/git-rev-list --header --parents $hash" or next;
2377 while (my $commit_text = <$fd>) {
2378 if (!grep m/$searchtext/i, $commit_text) {
2381 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
2384 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
2387 my @commit_lines = split "\n", $commit_text;
2388 my %co = git_read_commit(undef, \@commit_lines);
2393 print "<tr class=\"dark\">\n";
2395 print "<tr class=\"light\">\n";
2398 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2399 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2401 $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/>");
2402 my $comment = $co{'comment'};
2403 foreach my $line (@$comment) {
2404 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2405 my $lead = esc_html($1) || "";
2406 $lead = chop_str($lead, 30, 10);
2407 my $match = esc_html($2) || "";
2408 my $trail = esc_html($3) || "";
2409 $trail = chop_str($trail, 30, 10);
2410 my $text = "$lead<span style=\"color:#e00000\">$match</span>$trail";
2411 print chop_str($text, 80, 5) . "<br/>\n";
2415 "<td class=\"link\">" .
2416 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2417 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2424 if ($pickaxe_search) {
2426 open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin -S\'$searchtext\'";
2429 while (my $line = <$fd>) {
2430 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2433 $set{'from_id'} = $3;
2435 $set{'id'} = $set{'to_id'};
2436 if ($set{'id'} =~ m/0{40}/) {
2437 $set{'id'} = $set{'from_id'};
2439 if ($set{'id'} =~ m/0{40}/) {
2443 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
2446 print "<tr class=\"dark\">\n";
2448 print "<tr class=\"light\">\n";
2451 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2452 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2454 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" .
2455 esc_html(chop_str($co{'title'}, 50)) . "</b><br/>");
2456 while (my $setref = shift @files) {
2458 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}"), class => "list"},
2459 "<span style=\"color:#e00000\">" . esc_html($set{'file'}) . "</span>") .
2463 "<td class=\"link\">" .
2464 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2465 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2469 %co = git_read_commit($1);
2479 my $head = git_read_head($project);
2480 if (!defined $hash) {
2483 if (!defined $page) {
2486 my $refs = read_info_ref();
2488 print "<div class=\"page_nav\">\n" .
2489 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
2491 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash")}, "log") .
2492 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash")}, "commit") .
2493 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2494 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$hash;hb=$hash")}, "tree") . "<br/>\n";
2496 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2497 open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error(undef, "Open failed.");
2498 my (@revlist) = map { chomp; $_ } <$fd>;
2501 if ($hash ne $head || $page) {
2502 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "HEAD");
2508 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash;pg=" . ($page-1)), -accesskey => "p", -title => "Alt-p"}, "prev");
2510 print " ⋅ prev";
2512 if ($#revlist >= (100 * ($page+1)-1)) {
2514 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)), -accesskey => "n", -title => "Alt-n"}, "next");
2516 print " ⋅ next";
2521 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary"), -class => "title"}, " ") .
2523 print "<table cellspacing=\"0\">\n";
2525 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2526 my $commit = $revlist[$i];
2528 if (defined $refs->{$commit}) {
2529 $ref = " <span class=\"tag\">" . esc_html($refs->{$commit}) . "</span>";
2531 my %co = git_read_commit($commit);
2532 my %ad = date_str($co{'author_epoch'});
2534 print "<tr class=\"dark\">\n";
2536 print "<tr class=\"light\">\n";
2539 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2540 "<td><i>" . esc_html(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
2542 if (length($co{'title_short'}) < length($co{'title'})) {
2543 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "list", -title => "$co{'title'}"},
2544 "<b>" . esc_html($co{'title_short'}) . "$ref</b>");
2546 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "list"},
2547 "<b>" . esc_html($co{'title_short'}) . "$ref</b>");
2550 "<td class=\"link\">" .
2551 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit")}, "commit") .
2552 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2556 if ($#revlist >= (100 * ($page+1)-1)) {
2559 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)), -title => "Alt-n"}, "next") .