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";
266 print $cgi->header(-type=>'text/html', -charset => 'utf-8', -status=> $status, -expires => $expires);
268 <?xml version="1.0" encoding="utf-8"?>
269 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
270 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
271 <!-- git web interface v$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
273 <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
274 <meta name="robots" content="index, nofollow"/>
275 <link rel="stylesheet" href="$stylesheet"/>
276 <title>$title</title>
281 print "<div class=\"page_header\">\n" .
282 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
283 "<img src=\"$my_uri?" . esc_param("a=git-logo.png") . "\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
285 print $cgi->a({-href => esc_param($home_link)}, "projects") . " / ";
286 if (defined $project) {
287 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, esc_html($project));
288 if (defined $action) {
292 if (!defined $searchtext) {
297 $search_hash = $hash;
299 $search_hash = "HEAD";
301 $cgi->param("a", "search");
302 $cgi->param("h", $search_hash);
303 print $cgi->startform(-method => "get", -action => $my_uri) .
304 "<div class=\"search\">\n" .
305 $cgi->hidden(-name => "p") . "\n" .
306 $cgi->hidden(-name => "a") . "\n" .
307 $cgi->hidden(-name => "h") . "\n" .
308 $cgi->textfield(-name => "s", -value => $searchtext) . "\n" .
310 $cgi->end_form() . "\n";
315 sub git_footer_html {
316 print "<div class=\"page_footer\">\n";
317 if (defined $project) {
318 my $descr = git_read_description($project);
319 if (defined $descr) {
320 print "<div class=\"page_footer_text\">" . esc_html($descr) . "</div>\n";
322 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=rss"), -class => "rss_logo"}, "RSS") . "\n";
324 print $cgi->a({-href => "$my_uri?" . esc_param("a=opml"), -class => "rss_logo"}, "OPML") . "\n";
332 my $status = shift || "403 Forbidden";
333 my $error = shift || "Malformed query, file missing or permission denied";
335 git_header_html($status);
336 print "<div class=\"page_body\">\n" .
338 "$status - $error\n" .
348 open my $fd, "-|", "$gitbin/git-cat-file -t $hash" or return;
357 my $oENV = $ENV{'GIT_DIR'};
359 $ENV{'GIT_DIR'} = "$projectroot/$project";
360 if (open my $fd, "-|", "$gitbin/git-rev-parse", "--verify", "HEAD") {
363 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
368 $ENV{'GIT_DIR'} = $oENV;
376 open my $fd, "$projectroot/$path" or return undef;
380 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
385 sub git_read_description {
388 open my $fd, "$projectroot/$path/description" or return undef;
400 open my $fd, "-|", "$gitbin/git-cat-file tag $tag_id" or return;
401 $tag{'id'} = $tag_id;
402 while (my $line = <$fd>) {
404 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
406 } elsif ($line =~ m/^type (.+)$/) {
408 } elsif ($line =~ m/^tag (.+)$/) {
410 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
414 } elsif ($line =~ m/--BEGIN/) {
415 push @comment, $line;
417 } elsif ($line eq "") {
421 push @comment, <$fd>;
422 $tag{'comment'} = \@comment;
424 if (!defined $tag{'name'}) {
434 if ($age > 60*60*24*365*2) {
435 $age_str = (int $age/60/60/24/365);
436 $age_str .= " years ago";
437 } elsif ($age > 60*60*24*(365/12)*2) {
438 $age_str = int $age/60/60/24/(365/12);
439 $age_str .= " months ago";
440 } elsif ($age > 60*60*24*7*2) {
441 $age_str = int $age/60/60/24/7;
442 $age_str .= " weeks ago";
443 } elsif ($age > 60*60*24*2) {
444 $age_str = int $age/60/60/24;
445 $age_str .= " days ago";
446 } elsif ($age > 60*60*2) {
447 $age_str = int $age/60/60;
448 $age_str .= " hours ago";
449 } elsif ($age > 60*2) {
450 $age_str = int $age/60;
451 $age_str .= " min ago";
454 $age_str .= " sec ago";
456 $age_str .= " right now";
461 sub git_read_commit {
462 my $commit_id = shift;
463 my $commit_text = shift;
468 if (defined $commit_text) {
469 @commit_lines = @$commit_text;
472 open my $fd, "-|", "$gitbin/git-rev-list --header --parents --max-count=1 $commit_id" or return;
473 @commit_lines = split '\n', <$fd>;
478 my $header = shift @commit_lines;
479 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
482 ($co{'id'}, my @parents) = split ' ', $header;
483 $co{'parents'} = \@parents;
484 $co{'parent'} = $parents[0];
485 while (my $line = shift @commit_lines) {
486 last if $line eq "\n";
487 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
489 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
491 $co{'author_epoch'} = $2;
492 $co{'author_tz'} = $3;
493 if ($co{'author'} =~ m/^([^<]+) </) {
494 $co{'author_name'} = $1;
496 $co{'author_name'} = $co{'author'};
498 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
499 $co{'committer'} = $1;
500 $co{'committer_epoch'} = $2;
501 $co{'committer_tz'} = $3;
502 $co{'committer_name'} = $co{'committer'};
503 $co{'committer_name'} =~ s/ <.*//;
506 if (!defined $co{'tree'}) {
510 foreach my $title (@commit_lines) {
513 $co{'title'} = chop_str($title, 80, 5);
514 # remove leading stuff of merges to make the interesting part visible
515 if (length($title) > 50) {
516 $title =~ s/^Automatic //;
517 $title =~ s/^merge (of|with) /Merge ... /i;
518 if (length($title) > 50) {
519 $title =~ s/(http|rsync):\/\///;
521 if (length($title) > 50) {
522 $title =~ s/(master|www|rsync)\.//;
524 if (length($title) > 50) {
525 $title =~ s/kernel.org:?//;
527 if (length($title) > 50) {
528 $title =~ s/\/pub\/scm//;
531 $co{'title_short'} = chop_str($title, 50, 5);
535 # remove added spaces
536 foreach my $line (@commit_lines) {
539 $co{'comment'} = \@commit_lines;
541 my $age = time - $co{'committer_epoch'};
543 $co{'age_string'} = age_string($age);
544 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
545 if ($age > 60*60*24*7*2) {
546 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
547 $co{'age_string_age'} = $co{'age_string'};
549 $co{'age_string_date'} = $co{'age_string'};
550 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
557 my $from_name = shift;
560 my $format = shift || "html";
562 my $from_tmp = "/dev/null";
563 my $to_tmp = "/dev/null";
566 # create tmp from-file
568 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
569 open my $fd2, "> $from_tmp";
570 open my $fd, "-|", "$gitbin/git-cat-file blob $from";
579 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
580 open my $fd2, "> $to_tmp";
581 open my $fd, "-|", "$gitbin/git-cat-file blob $to";
588 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
589 if ($format eq "plain") {
594 while (my $line = <$fd>) {
596 my $char = substr($line, 0, 1);
599 $color = " style=\"color:#008800;\"";
600 } elsif ($char eq "-") {
601 $color = " style=\"color:#cc0000;\"";
602 } elsif ($char eq "@") {
603 $color = " style=\"color:#990099;\"";
604 } elsif ($char eq "\\") {
608 while ((my $pos = index($line, "\t")) != -1) {
609 if (my $count = (8 - (($pos-1) % 8))) {
610 my $spaces = ' ' x $count;
611 $line =~ s/\t/$spaces/;
614 print "<div class=\"pre\"$color>" . esc_html($line) . "</div>\n";
628 my $mode = oct shift;
630 if (S_ISDIR($mode & S_IFMT)) {
632 } elsif (S_ISLNK($mode)) {
634 } elsif (S_ISREG($mode)) {
635 # git cares only about the executable bit
636 if ($mode & S_IXUSR) {
649 my $add_len = shift || 10;
651 # allow only $len chars, but don't cut a word if it would fit in $add_len
652 # if it doesn't fit, cut it if it's still longer than the dots we would add
653 $str =~ m/^(.{0,$len}[^ \/\-_:\.@]{0,$add_len})(.*)/;
656 if (length($tail) > 4) {
663 my $mode = oct shift;
665 if (S_ISDIR($mode & S_IFMT)) {
667 } elsif (S_ISLNK($mode)) {
669 } elsif (S_ISREG($mode)) {
676 sub format_log_line_html {
679 $line = esc_html($line);
680 $line =~ s/ / /g;
681 if ($line =~ m/([0-9a-fA-F]{40})/) {
683 if (git_get_type($hash_text) eq "commit") {
684 my $link = $cgi->a({-class => "text", -href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_text")}, $hash_text);
685 $line =~ s/$hash_text/$link/;
693 my $tz = shift || "-0000";
696 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
697 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
698 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
699 $date{'hour'} = $hour;
700 $date{'minute'} = $min;
701 $date{'mday'} = $mday;
702 $date{'day'} = $days[$wday];
703 $date{'month'} = $months[$mon];
704 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
705 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
707 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
708 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
709 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
710 $date{'hour_local'} = $hour;
711 $date{'minute_local'} = $min;
712 $date{'tz_local'} = $tz;
716 # git-logo (cached in browser for one day)
718 binmode STDOUT, ':raw';
719 print $cgi->header(-type => 'image/png', -expires => '+1d');
720 # cat git-logo.png | hexdump -e '16/1 " %02x" "\n"' | sed 's/ /\\x/g'
721 print "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52" .
722 "\x00\x00\x00\x48\x00\x00\x00\x1b\x04\x03\x00\x00\x00\x2d\xd9\xd4" .
723 "\x2d\x00\x00\x00\x18\x50\x4c\x54\x45\xff\xff\xff\x60\x60\x5d\xb0" .
724 "\xaf\xaa\x00\x80\x00\xce\xcd\xc7\xc0\x00\x00\xe8\xe8\xe6\xf7\xf7" .
725 "\xf6\x95\x0c\xa7\x47\x00\x00\x00\x73\x49\x44\x41\x54\x28\xcf\x63" .
726 "\x48\x67\x20\x04\x4a\x5c\x18\x0a\x08\x2a\x62\x53\x61\x20\x02\x08" .
727 "\x0d\x69\x45\xac\xa1\xa1\x01\x30\x0c\x93\x60\x36\x26\x52\x91\xb1" .
728 "\x01\x11\xd6\xe1\x55\x64\x6c\x6c\xcc\x6c\x6c\x0c\xa2\x0c\x70\x2a" .
729 "\x62\x06\x2a\xc1\x62\x1d\xb3\x01\x02\x53\xa4\x08\xe8\x00\x03\x18" .
730 "\x26\x56\x11\xd4\xe1\x20\x97\x1b\xe0\xb4\x0e\x35\x24\x71\x29\x82" .
731 "\x99\x30\xb8\x93\x0a\x11\xb9\x45\x88\xc1\x8d\xa0\xa2\x44\x21\x06" .
732 "\x27\x41\x82\x40\x85\xc1\x45\x89\x20\x70\x01\x00\xa4\x3d\x21\xc5" .
733 "\x12\x1c\x9a\xfe\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\x82";
739 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
740 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
741 if (!defined $gcos) {
745 $owner =~ s/[,;].*$//;
746 return decode("utf8", $owner, Encode::FB_DEFAULT);
749 sub git_read_projects {
752 if (-d $projects_list) {
753 # search in directory
754 my $dir = $projects_list;
755 opendir my $dh, $dir or return undef;
756 while (my $dir = readdir($dh)) {
757 if (-e "$projectroot/$dir/HEAD") {
765 } elsif (-f $projects_list) {
766 # read from file(url-encoded):
767 # 'git%2Fgit.git Linus+Torvalds'
768 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
769 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
770 open my $fd , $projects_list or return undef;
771 while (my $line = <$fd>) {
773 my ($path, $owner) = split ' ', $line;
774 $path = unescape($path);
775 $owner = unescape($owner);
776 if (!defined $path) {
779 if (-e "$projectroot/$path/HEAD") {
782 owner => decode("utf8", $owner, Encode::FB_DEFAULT),
789 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
793 sub git_get_project_config {
796 return unless ($key);
797 $key =~ s/^gitweb\.//;
798 return if ($key =~ m/\W/);
800 my $val = qx(git-repo-config --get gitweb.$key);
804 sub git_get_project_config_bool {
805 my $val = git_get_project_config (@_);
806 if ($val and $val =~ m/true|yes|on/) {
809 return; # implicit false
812 sub git_project_list {
813 my @list = git_read_projects();
816 die_error(undef, "No project found.");
818 foreach my $pr (@list) {
819 my $head = git_read_head($pr->{'path'});
820 if (!defined $head) {
823 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
824 my %co = git_read_commit($head);
828 $pr->{'commit'} = \%co;
829 if (!defined $pr->{'descr'}) {
830 my $descr = git_read_description($pr->{'path'}) || "";
831 $pr->{'descr'} = chop_str($descr, 25, 5);
833 if (!defined $pr->{'owner'}) {
834 $pr->{'owner'} = get_file_owner("$projectroot/$pr->{'path'}") || "";
840 print "<div class=\"index_include\">\n";
841 open (my $fd, $home_text);
846 print "<table cellspacing=\"0\">\n" .
848 if (!defined($order) || (defined($order) && ($order eq "project"))) {
849 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
850 print "<th>Project</th>\n";
852 print "<th>" . $cgi->a({-class => "header", -href => "$my_uri?" . esc_param("o=project")}, "Project") . "</th>\n";
854 if (defined($order) && ($order eq "descr")) {
855 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
856 print "<th>Description</th>\n";
858 print "<th>" . $cgi->a({-class => "header", -href => "$my_uri?" . esc_param("o=descr")}, "Description") . "</th>\n";
860 if (defined($order) && ($order eq "owner")) {
861 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
862 print "<th>Owner</th>\n";
864 print "<th>" . $cgi->a({-class => "header", -href => "$my_uri?" . esc_param("o=owner")}, "Owner") . "</th>\n";
866 if (defined($order) && ($order eq "age")) {
867 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
868 print "<th>Last Change</th>\n";
870 print "<th>" . $cgi->a({-class => "header", -href => "$my_uri?" . esc_param("o=age")}, "Last Change") . "</th>\n";
872 print "<th></th>\n" .
875 foreach my $pr (@projects) {
877 print "<tr class=\"dark\">\n";
879 print "<tr class=\"light\">\n";
882 print "<td>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=summary"), -class => "list"}, esc_html($pr->{'path'})) . "</td>\n" .
883 "<td>$pr->{'descr'}</td>\n" .
884 "<td><i>" . chop_str($pr->{'owner'}, 15) . "</i></td>\n";
886 if ($pr->{'commit'}{'age'} < 60*60*2) {
887 $colored_age = "<span style =\"color: #009900;\"><b><i>$pr->{'commit'}{'age_string'}</i></b></span>";
888 } elsif ($pr->{'commit'}{'age'} < 60*60*24*2) {
889 $colored_age = "<span style =\"color: #009900;\"><i>$pr->{'commit'}{'age_string'}</i></span>";
891 $colored_age = "<i>$pr->{'commit'}{'age_string'}</i>";
893 print "<td>$colored_age</td>\n" .
894 "<td class=\"link\">" .
895 $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=summary")}, "summary") .
896 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=shortlog")}, "shortlog") .
897 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=log")}, "log") .
906 my $type = shift || "";
908 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
909 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
910 open my $fd, "$projectroot/$project/info/refs" or return;
911 while (my $line = <$fd>) {
913 if ($line =~ m/^([0-9a-fA-F]{40})\t.*$type\/([^\^]+)/) {
914 if (defined $refs{$1}) {
915 $refs{$1} .= " / $2";
930 opendir my $dh, "$projectroot/$project/$ref_dir";
931 while (my $dir = readdir($dh)) {
932 if ($dir =~ m/^\./) {
935 if (-d "$projectroot/$project/$ref_dir/$dir") {
936 opendir my $dh2, "$projectroot/$project/$ref_dir/$dir";
937 my @subdirs = grep !m/^\./, readdir $dh2;
939 foreach my $subdir (@subdirs) {
940 push @refs, "$dir/$subdir"
947 foreach my $ref_file (@refs) {
948 my $ref_id = git_read_hash("$project/$ref_dir/$ref_file");
949 my $type = git_get_type($ref_id) || next;
952 $ref_item{'type'} = $type;
953 $ref_item{'id'} = $ref_id;
954 $ref_item{'epoch'} = 0;
955 $ref_item{'age'} = "unknown";
956 if ($type eq "tag") {
957 my %tag = git_read_tag($ref_id);
958 $ref_item{'comment'} = $tag{'comment'};
959 if ($tag{'type'} eq "commit") {
960 %co = git_read_commit($tag{'object'});
961 $ref_item{'epoch'} = $co{'committer_epoch'};
962 $ref_item{'age'} = $co{'age_string'};
963 } elsif (defined($tag{'epoch'})) {
964 my $age = time - $tag{'epoch'};
965 $ref_item{'epoch'} = $tag{'epoch'};
966 $ref_item{'age'} = age_string($age);
968 $ref_item{'reftype'} = $tag{'type'};
969 $ref_item{'name'} = $tag{'name'};
970 $ref_item{'refid'} = $tag{'object'};
971 } elsif ($type eq "commit"){
972 %co = git_read_commit($ref_id);
973 $ref_item{'reftype'} = "commit";
974 $ref_item{'name'} = $ref_file;
975 $ref_item{'title'} = $co{'title'};
976 $ref_item{'refid'} = $ref_id;
977 $ref_item{'epoch'} = $co{'committer_epoch'};
978 $ref_item{'age'} = $co{'age_string'};
981 push @reflist, \%ref_item;
984 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
989 my $descr = git_read_description($project) || "none";
990 my $head = git_read_head($project);
991 my %co = git_read_commit($head);
992 my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'});
995 if (-f $projects_list) {
996 open (my $fd , $projects_list);
997 while (my $line = <$fd>) {
999 my ($pr, $ow) = split ' ', $line;
1000 $pr = unescape($pr);
1001 $ow = unescape($ow);
1002 if ($pr eq $project) {
1003 $owner = decode("utf8", $ow, Encode::FB_DEFAULT);
1009 if (!defined $owner) {
1010 $owner = get_file_owner("$projectroot/$project");
1013 my $refs = read_info_ref();
1015 print "<div class=\"page_nav\">\n" .
1017 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
1018 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") .
1019 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$head")}, "commit") .
1020 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1021 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree")}, "tree") .
1024 print "<div class=\"title\"> </div>\n";
1025 print "<table cellspacing=\"0\">\n" .
1026 "<tr><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
1027 "<tr><td>owner</td><td>$owner</td></tr>\n" .
1028 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
1030 open my $fd, "-|", "$gitbin/git-rev-list --max-count=17 " . git_read_head($project) or die_error(undef, "Open failed.");
1031 my (@revlist) = map { chomp; $_ } <$fd>;
1034 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog"), -class => "title"}, "shortlog") .
1037 print "<table cellspacing=\"0\">\n";
1039 foreach my $commit (@revlist) {
1040 my %co = git_read_commit($commit);
1041 my %ad = date_str($co{'author_epoch'});
1043 print "<tr class=\"dark\">\n";
1045 print "<tr class=\"light\">\n";
1050 if (defined $refs->{$commit}) {
1051 $ref = " <span class=\"tag\">" . esc_html($refs->{$commit}) . "</span>";
1053 print "<td><i>$co{'age_string'}</i></td>\n" .
1054 "<td><i>" . esc_html(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
1056 if (length($co{'title_short'}) < length($co{'title'})) {
1057 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "list", -title => "$co{'title'}"},
1058 "<b>" . esc_html($co{'title_short'}) . "$ref</b>");
1060 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "list"},
1061 "<b>" . esc_html($co{'title'}) . "$ref</b>");
1064 "<td class=\"link\">" .
1065 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit")}, "commit") .
1066 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1070 print "<td>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "...") . "</td>\n" .
1077 my $taglist = git_read_refs("refs/tags");
1078 if (defined @$taglist) {
1080 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tags"), -class => "title"}, "tags") .
1083 print "<table cellspacing=\"0\">\n";
1085 foreach my $entry (@$taglist) {
1087 my $comment_lines = $tag{'comment'};
1088 my $comment = shift @$comment_lines;
1089 if (defined($comment)) {
1090 $comment = chop_str($comment, 30, 5);
1093 print "<tr class=\"dark\">\n";
1095 print "<tr class=\"light\">\n";
1099 print "<td><i>$tag{'age'}</i></td>\n" .
1101 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), -class => "list"},
1102 "<b>" . esc_html($tag{'name'}) . "</b>") .
1105 if (defined($comment)) {
1106 print $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, $comment);
1109 "<td class=\"link\">";
1110 if ($tag{'type'} eq "tag") {
1111 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
1113 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1114 if ($tag{'reftype'} eq "commit") {
1115 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1116 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'refid'}")}, "log");
1121 print "<td>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tags")}, "...") . "</td>\n" .
1129 my $headlist = git_read_refs("refs/heads");
1130 if (defined @$headlist) {
1132 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=heads"), -class => "title"}, "heads") .
1135 print "<table cellspacing=\"0\">\n";
1137 foreach my $entry (@$headlist) {
1140 print "<tr class=\"dark\">\n";
1142 print "<tr class=\"light\">\n";
1146 print "<td><i>$tag{'age'}</i></td>\n" .
1148 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}"), -class => "list"},
1149 "<b>" . esc_html($tag{'name'}) . "</b>") .
1151 "<td class=\"link\">" .
1152 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1153 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'name'}")}, "log") .
1157 print "<td>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=heads")}, "...") . "</td>\n" .
1168 my $head = git_read_head($project);
1170 print "<div class=\"page_nav\">\n" .
1171 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
1172 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
1173 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") .
1174 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$head")}, "commit") .
1175 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1176 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1179 my %tag = git_read_tag($hash);
1181 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html($tag{'name'})) . "\n" .
1183 print "<div class=\"title_text\">\n" .
1184 "<table cellspacing=\"0\">\n" .
1186 "<td>object</td>\n" .
1187 "<td>" . $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'object'}) . "</td>\n" .
1188 "<td class=\"link\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'type'}) . "</td>\n" .
1190 if (defined($tag{'author'})) {
1191 my %ad = date_str($tag{'epoch'}, $tag{'tz'});
1192 print "<tr><td>author</td><td>" . esc_html($tag{'author'}) . "</td></tr>\n";
1193 print "<tr><td></td><td>" . $ad{'rfc2822'} . sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) . "</td></tr>\n";
1195 print "</table>\n\n" .
1197 print "<div class=\"page_body\">";
1198 my $comment = $tag{'comment'};
1199 foreach my $line (@$comment) {
1200 print esc_html($line) . "<br/>\n";
1208 die_error('403 Permission denied', "Permission denied.") if (!git_get_project_config_bool ('blame'));
1209 die_error('404 Not Found', "What file will it be, master?") if (!$file_name);
1210 $hash_base ||= git_read_head($project);
1211 die_error(undef, "Reading commit failed.") unless ($hash_base);
1212 my %co = git_read_commit($hash_base)
1213 or die_error(undef, "Reading commit failed.");
1214 if (!defined $hash) {
1215 $hash = git_get_hash_by_path($hash_base, $file_name, "blob")
1216 or die_error(undef, "Error lookup file.");
1218 open ($fd, "-|", "$gitbin/git-annotate", '-l', '-t', '-r', $file_name, $hash_base)
1219 or die_error(undef, "Open failed.");
1221 print "<div class=\"page_nav\">\n" .
1222 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
1223 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
1224 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") .
1225 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base")}, "commit") .
1226 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1227 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") . "<br/>\n";
1228 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") .
1229 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;f=$file_name")}, "head") . "<br/>\n";
1232 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) .
1234 print "<div class=\"page_path\"><b>" . esc_html($file_name) . "</b></div>\n";
1235 print "<div class=\"page_body\">\n";
1237 <table style="border-collapse: collapse;">
1246 my @line_class = (qw(light dark));
1247 my $line_class_len = scalar (@line_class);
1248 my $line_class_num = $#line_class;
1249 while (my $line = <$fd>) {
1261 $line_class_num = ($line_class_num + 1) % $line_class_len;
1263 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) \+\d\d\d\d\t(\d+)\)(.*)$/) {
1270 print qq( <tr><td colspan="5" style="color: red; background-color: yellow;">Unable to parse: $line</td></tr>\n);
1273 $short_rev = substr ($long_rev, 0, 8);
1274 $age = time () - $time;
1275 $age_str = age_string ($age);
1276 $age_str =~ s/ / /g;
1277 $age_style = 'font-style: italic;';
1278 $age_style .= ' color: #009900; background: transparent;' if ($age < 60*60*24*2);
1279 $age_style .= ' font-weight: bold;' if ($age < 60*60*2);
1280 $author = esc_html ($author);
1281 $author =~ s/ / /g;
1283 while ((my $pos = index($data, "\t")) != -1) {
1284 if (my $count = (8 - ($pos % 8))) {
1285 my $spaces = ' ' x $count;
1286 $data =~ s/\t/$spaces/;
1289 $data = esc_html ($data);
1290 $data =~ s/ / /g;
1293 <tr class="$line_class[$line_class_num]">
1294 <td style="font-family: monospace;"><a href="$my_uri?${\esc_param ("p=$project;a=commit;h=$long_rev")}" class="text">$short_rev..</a></td>
1295 <td style="$age_style">$age_str</td>
1297 <td style="text-align: right;"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
1298 <td style="font-family: monospace;">$data</td>
1301 } # while (my $line = <$fd>)
1302 print "</table>\n\n";
1303 close $fd or print "Reading blob failed.\n";
1309 my $head = git_read_head($project);
1311 print "<div class=\"page_nav\">\n" .
1312 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
1313 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
1314 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") .
1315 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$head")}, "commit") .
1316 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1317 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1320 my $taglist = git_read_refs("refs/tags");
1322 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary"), -class => "title"}, " ") .
1324 print "<table cellspacing=\"0\">\n";
1326 if (defined @$taglist) {
1327 foreach my $entry (@$taglist) {
1329 my $comment_lines = $tag{'comment'};
1330 my $comment = shift @$comment_lines;
1331 if (defined($comment)) {
1332 $comment = chop_str($comment, 30, 5);
1335 print "<tr class=\"dark\">\n";
1337 print "<tr class=\"light\">\n";
1340 print "<td><i>$tag{'age'}</i></td>\n" .
1342 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), -class => "list"},
1343 "<b>" . esc_html($tag{'name'}) . "</b>") .
1346 if (defined($comment)) {
1347 print $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, $comment);
1350 "<td class=\"link\">";
1351 if ($tag{'type'} eq "tag") {
1352 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
1354 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1355 if ($tag{'reftype'} eq "commit") {
1356 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1357 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'refid'}")}, "log");
1368 my $head = git_read_head($project);
1370 print "<div class=\"page_nav\">\n" .
1371 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
1372 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
1373 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") .
1374 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$head")}, "commit") .
1375 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1376 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1379 my $taglist = git_read_refs("refs/heads");
1381 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary"), -class => "title"}, " ") .
1383 print "<table cellspacing=\"0\">\n";
1385 if (defined @$taglist) {
1386 foreach my $entry (@$taglist) {
1389 print "<tr class=\"dark\">\n";
1391 print "<tr class=\"light\">\n";
1394 print "<td><i>$tag{'age'}</i></td>\n" .
1396 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}"), -class => "list"}, "<b>" . esc_html($tag{'name'}) . "</b>") .
1398 "<td class=\"link\">" .
1399 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1400 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'name'}")}, "log") .
1409 sub git_get_hash_by_path {
1411 my $path = shift || return undef;
1414 my @parts = split '/', $path;
1415 while (my $part = shift @parts) {
1416 open my $fd, "-|", "$gitbin/git-ls-tree $tree" or die_error(undef, "Open git-ls-tree failed.");
1417 my (@entries) = map { chomp; $_ } <$fd>;
1418 close $fd or return undef;
1419 foreach my $line (@entries) {
1420 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1421 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1425 my $t_name = validate_input(unquote($4));
1426 if ($t_name eq $part) {
1430 if ($t_type eq "tree") {
1440 if (!defined $hash && defined $file_name) {
1441 my $base = $hash_base || git_read_head($project);
1442 $hash = git_get_hash_by_path($base, $file_name, "blob") || die_error(undef, "Error lookup file.");
1444 my $have_blame = git_get_project_config_bool ('blame');
1445 open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or die_error(undef, "Open failed.");
1447 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
1448 print "<div class=\"page_nav\">\n" .
1449 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
1450 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
1451 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") .
1452 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base")}, "commit") .
1453 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1454 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") . "<br/>\n";
1455 if (defined $file_name) {
1457 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$hash;hb=$hash_base;f=$file_name")}, "blame") . " | ";
1459 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$hash;f=$file_name")}, "plain") .
1460 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;hb=HEAD;f=$file_name")}, "head") . "<br/>\n";
1462 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$hash")}, "plain") . "<br/>\n";
1466 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) .
1469 print "<div class=\"page_nav\">\n" .
1470 "<br/><br/></div>\n" .
1471 "<div class=\"title\">$hash</div>\n";
1473 if (defined $file_name) {
1474 print "<div class=\"page_path\"><b>" . esc_html($file_name) . "</b></div>\n";
1476 print "<div class=\"page_body\">\n";
1478 while (my $line = <$fd>) {
1481 while ((my $pos = index($line, "\t")) != -1) {
1482 if (my $count = (8 - ($pos % 8))) {
1483 my $spaces = ' ' x $count;
1484 $line =~ s/\t/$spaces/;
1487 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", $nr, $nr, $nr, esc_html($line);
1489 close $fd or print "Reading blob failed.\n";
1494 sub mimetype_guess_file {
1495 my $filename = shift;
1496 my $mimemap = shift;
1497 -r $mimemap or return undef;
1500 open(MIME, $mimemap) or return undef;
1502 my ($mime, $exts) = split(/\t+/);
1503 my @exts = split(/\s+/, $exts);
1504 foreach my $ext (@exts) {
1505 $mimemap{$ext} = $mime;
1510 $filename =~ /\.(.*?)$/;
1511 return $mimemap{$1};
1514 sub mimetype_guess {
1515 my $filename = shift;
1517 $filename =~ /\./ or return undef;
1519 if ($mimetypes_file) {
1520 my $file = $mimetypes_file;
1521 $file =~ m#^/# or $file = "$projectroot/$path/$file";
1522 $mime = mimetype_guess_file($filename, $file);
1524 $mime ||= mimetype_guess_file($filename, '/etc/mime.types');
1528 sub git_blob_plain_mimetype {
1530 my $filename = shift;
1533 return $default_blob_plain_mimetype unless $fd;
1536 my $mime = mimetype_guess($filename);
1537 $mime and return $mime;
1541 return 'text/plain' .
1542 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
1543 } elsif (! $filename) {
1544 return 'application/octet-stream';
1545 } elsif ($filename =~ m/\.png$/i) {
1547 } elsif ($filename =~ m/\.gif$/i) {
1549 } elsif ($filename =~ m/\.jpe?g$/i) {
1550 return 'image/jpeg';
1552 return 'application/octet-stream';
1556 sub git_blob_plain {
1557 open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or return;
1558 my $type = git_blob_plain_mimetype($fd, $file_name);
1560 # save as filename, even when no $file_name is given
1561 my $save_as = "$hash";
1562 if (defined $file_name) {
1563 $save_as = $file_name;
1564 } elsif ($type =~ m/^text\//) {
1568 print $cgi->header(-type => "$type", '-content-disposition' => "inline; filename=\"$save_as\"");
1570 binmode STDOUT, ':raw';
1572 binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
1578 if (!defined $hash) {
1579 $hash = git_read_head($project);
1580 if (defined $file_name) {
1581 my $base = $hash_base || $hash;
1582 $hash = git_get_hash_by_path($base, $file_name, "tree");
1584 if (!defined $hash_base) {
1589 open my $fd, "-|", "$gitbin/git-ls-tree -z $hash" or die_error(undef, "Open git-ls-tree failed.");
1590 chomp (my (@entries) = <$fd>);
1591 close $fd or die_error(undef, "Reading tree failed.");
1594 my $refs = read_info_ref();
1596 if (defined $refs->{$hash_base}) {
1597 $ref = " <span class=\"tag\">" . esc_html($refs->{$hash_base}) . "</span>";
1602 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
1603 $base_key = ";hb=$hash_base";
1604 print "<div class=\"page_nav\">\n" .
1605 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
1606 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash_base")}, "shortlog") .
1607 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash_base")}, "log") .
1608 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base")}, "commit") .
1609 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1614 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'}) . $ref) . "\n" .
1617 print "<div class=\"page_nav\">\n";
1618 print "<br/><br/></div>\n";
1619 print "<div class=\"title\">$hash</div>\n";
1621 if (defined $file_name) {
1622 $base = esc_html("$file_name/");
1623 print "<div class=\"page_path\"><b>/" . esc_html($file_name) . "</b></div>\n";
1625 print "<div class=\"page_path\"><b>/</b></div>\n";
1627 print "<div class=\"page_body\">\n";
1628 print "<table cellspacing=\"0\">\n";
1630 foreach my $line (@entries) {
1631 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1632 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1636 my $t_name = validate_input($4);
1638 print "<tr class=\"dark\">\n";
1640 print "<tr class=\"light\">\n";
1643 print "<td style=\"font-family:monospace\">" . mode_str($t_mode) . "</td>\n";
1644 if ($t_type eq "blob") {
1645 print "<td class=\"list\">" .
1646 $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)) .
1648 "<td class=\"link\">" .
1649 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name")}, "blob") .
1650 # " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$t_hash$base_key;f=$base$t_name")}, "blame") .
1651 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;h=$hash_base;f=$base$t_name")}, "history") .
1653 } elsif ($t_type eq "tree") {
1654 print "<td class=\"list\">" .
1655 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, esc_html($t_name)) .
1657 "<td class=\"link\">" .
1658 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, "tree") .
1663 print "</table>\n" .
1669 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
1670 open my $fd, "-|", "$gitbin/git-rev-list --max-count=150 " . git_read_head($project) or die_error(undef, "Open failed.");
1671 my (@revlist) = map { chomp; $_ } <$fd>;
1672 close $fd or die_error(undef, "Reading rev-list failed.");
1673 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
1674 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1675 "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
1676 print "<channel>\n";
1677 print "<title>$project</title>\n".
1678 "<link>" . esc_html("$my_url?p=$project;a=summary") . "</link>\n".
1679 "<description>$project log</description>\n".
1680 "<language>en</language>\n";
1682 for (my $i = 0; $i <= $#revlist; $i++) {
1683 my $commit = $revlist[$i];
1684 my %co = git_read_commit($commit);
1685 # we read 150, we always show 30 and the ones more recent than 48 hours
1686 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
1689 my %cd = date_str($co{'committer_epoch'});
1690 open $fd, "-|", "$gitbin/git-diff-tree -r $co{'parent'} $co{'id'}" or next;
1691 my @difftree = map { chomp; $_ } <$fd>;
1695 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html($co{'title'}) .
1697 "<author>" . esc_html($co{'author'}) . "</author>\n" .
1698 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
1699 "<guid isPermaLink=\"true\">" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
1700 "<link>" . esc_html("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
1701 "<description>" . esc_html($co{'title'}) . "</description>\n" .
1702 "<content:encoded>" .
1704 my $comment = $co{'comment'};
1705 foreach my $line (@$comment) {
1706 $line = decode("utf8", $line, Encode::FB_DEFAULT);
1707 print "$line<br/>\n";
1710 foreach my $line (@difftree) {
1711 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
1714 my $file = validate_input(unquote($7));
1715 $file = decode("utf8", $file, Encode::FB_DEFAULT);
1716 print "$file<br/>\n";
1719 "</content:encoded>\n" .
1722 print "</channel></rss>";
1726 my @list = git_read_projects();
1728 print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
1729 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1730 "<opml version=\"1.0\">\n".
1732 " <title>Git OPML Export</title>\n".
1735 "<outline text=\"git RSS feeds\">\n";
1737 foreach my $pr (@list) {
1739 my $head = git_read_head($proj{'path'});
1740 if (!defined $head) {
1743 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
1744 my %co = git_read_commit($head);
1749 my $path = esc_html(chop_str($proj{'path'}, 25, 5));
1750 my $rss = "$my_url?p=$proj{'path'};a=rss";
1751 my $html = "$my_url?p=$proj{'path'};a=summary";
1752 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
1754 print "</outline>\n".
1760 my $head = git_read_head($project);
1761 if (!defined $hash) {
1764 if (!defined $page) {
1767 my $refs = read_info_ref();
1769 print "<div class=\"page_nav\">\n";
1770 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
1771 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash")}, "shortlog") .
1773 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash")}, "commit") .
1774 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
1775 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$hash;hb=$hash")}, "tree") . "<br/>\n";
1777 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
1778 open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error(undef, "Open failed.");
1779 my (@revlist) = map { chomp; $_ } <$fd>;
1782 if ($hash ne $head || $page) {
1783 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "HEAD");
1789 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash;pg=" . ($page-1)), -accesskey => "p", -title => "Alt-p"}, "prev");
1791 print " ⋅ prev";
1793 if ($#revlist >= (100 * ($page+1)-1)) {
1795 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash;pg=" . ($page+1)), -accesskey => "n", -title => "Alt-n"}, "next");
1797 print " ⋅ next";
1803 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary"), -class => "title"}, " ") .
1805 my %co = git_read_commit($hash);
1806 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
1808 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
1809 my $commit = $revlist[$i];
1811 if (defined $refs->{$commit}) {
1812 $ref = " <span class=\"tag\">" . esc_html($refs->{$commit}) . "</span>";
1814 my %co = git_read_commit($commit);
1816 my %ad = date_str($co{'author_epoch'});
1818 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "title"},
1819 "<span class=\"age\">$co{'age_string'}</span>" . esc_html($co{'title'}) . $ref) . "\n";
1821 print "<div class=\"title_text\">\n" .
1822 "<div class=\"log_link\">\n" .
1823 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit")}, "commit") .
1824 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1827 "<i>" . esc_html($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
1829 "<div class=\"log_body\">\n";
1830 my $comment = $co{'comment'};
1832 foreach my $line (@$comment) {
1833 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1844 print format_log_line_html($line) . "<br/>\n";
1855 my %co = git_read_commit($hash);
1857 die_error(undef, "Unknown commit object.");
1859 my %ad = date_str($co{'author_epoch'}, $co{'author_tz'});
1860 my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'});
1864 my $parent = $co{'parent'};
1865 if (!defined $parent) {
1869 open my $fd, "-|", "$gitbin/git-diff-tree -r -M $root $parent $hash" or die_error(undef, "Open failed.");
1870 @difftree = map { chomp; $_ } <$fd>;
1871 close $fd or die_error(undef, "Reading diff-tree failed.");
1873 # non-textual hash id's can be cached
1875 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
1878 my $refs = read_info_ref();
1880 if (defined $refs->{$co{'id'}}) {
1881 $ref = " <span class=\"tag\">" . esc_html($refs->{$co{'id'}}) . "</span>";
1883 git_header_html(undef, $expires);
1884 print "<div class=\"page_nav\">\n" .
1885 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
1886 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash")}, "shortlog") .
1887 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash")}, "log") .
1889 if (defined $co{'parent'}) {
1890 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash")}, "commitdiff");
1892 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") . "\n" .
1893 "<br/><br/></div>\n";
1894 if (defined $co{'parent'}) {
1896 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash"), -class => "title"}, esc_html($co{'title'}) . $ref) . "\n" .
1900 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash"), -class => "title"}, esc_html($co{'title'})) . "\n" .
1903 print "<div class=\"title_text\">\n" .
1904 "<table cellspacing=\"0\">\n";
1905 print "<tr><td>author</td><td>" . esc_html($co{'author'}) . "</td></tr>\n".
1907 "<td></td><td> $ad{'rfc2822'}";
1908 if ($ad{'hour_local'} < 6) {
1909 printf(" (<span style=\"color: #cc0000;\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1911 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1915 print "<tr><td>committer</td><td>" . esc_html($co{'committer'}) . "</td></tr>\n";
1916 print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
1917 print "<tr><td>commit</td><td style=\"font-family:monospace\">$co{'id'}</td></tr>\n";
1920 "<td style=\"font-family:monospace\">" .
1921 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash"), class => "list"}, $co{'tree'}) .
1923 "<td class=\"link\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
1926 my $parents = $co{'parents'};
1927 foreach my $par (@$parents) {
1930 "<td style=\"font-family:monospace\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$par"), class => "list"}, $par) . "</td>" .
1931 "<td class=\"link\">" .
1932 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$par")}, "commit") .
1933 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash;hp=$par")}, "commitdiff") .
1939 print "<div class=\"page_body\">\n";
1940 my $comment = $co{'comment'};
1943 foreach my $line (@$comment) {
1944 # print only one empty line
1946 if ($empty || $signed) {
1953 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1955 print "<span style=\"color: #888888\">" . esc_html($line) . "</span><br/>\n";
1958 print format_log_line_html($line) . "<br/>\n";
1962 print "<div class=\"list_head\">\n";
1963 if ($#difftree > 10) {
1964 print(($#difftree + 1) . " files changed:\n");
1967 print "<table cellspacing=\"0\">\n";
1969 foreach my $line (@difftree) {
1970 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1971 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1972 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
1980 my $similarity = $6;
1981 my $file = validate_input(unquote($7));
1983 print "<tr class=\"dark\">\n";
1985 print "<tr class=\"light\">\n";
1988 if ($status eq "A") {
1990 if (S_ISREG(oct $to_mode)) {
1991 $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
1994 $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" .
1995 "<td><span style=\"color: #008000;\">[new " . file_type($to_mode) . "$mode_chng]</span></td>\n" .
1996 "<td class=\"link\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob") . "</td>\n";
1997 } elsif ($status eq "D") {
1999 $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" .
2000 "<td><span style=\"color: #c00000;\">[deleted " . file_type($from_mode). "]</span></td>\n" .
2001 "<td class=\"link\">" .
2002 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, "blob") .
2003 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;h=$hash;f=$file")}, "history") .
2005 } elsif ($status eq "M" || $status eq "T") {
2006 my $mode_chnge = "";
2007 if ($from_mode != $to_mode) {
2008 $mode_chnge = " <span style=\"color: #777777;\">[changed";
2009 if (((oct $from_mode) & S_IFMT) != ((oct $to_mode) & S_IFMT)) {
2010 $mode_chnge .= " from " . file_type($from_mode) . " to " . file_type($to_mode);
2012 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
2013 if (S_ISREG($from_mode) && S_ISREG($to_mode)) {
2014 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
2015 } elsif (S_ISREG($to_mode)) {
2016 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
2019 $mode_chnge .= "]</span>\n";
2022 if ($to_id ne $from_id) {
2023 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));
2025 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file"), -class => "list"}, esc_html($file));
2028 "<td>$mode_chnge</td>\n" .
2029 "<td class=\"link\">";
2030 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob");
2031 if ($to_id ne $from_id) {
2032 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file")}, "diff");
2034 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;h=$hash;f=$file")}, "history") . "\n";
2036 } elsif ($status eq "R") {
2037 my ($from_file, $to_file) = split "\t", $file;
2039 if ($from_mode != $to_mode) {
2040 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
2043 $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" .
2044 "<td><span style=\"color: #777777;\">[moved from " .
2045 $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)) .
2046 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
2047 "<td class=\"link\">" .
2048 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_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=$to_file")}, "diff");
2061 mkdir($git_temp, 0700);
2063 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
2064 print "<div class=\"page_nav\">\n" .
2065 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
2066 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
2067 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") .
2068 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base")}, "commit") .
2069 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
2070 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") .
2072 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff_plain;h=$hash;hp=$hash_parent")}, "plain") .
2075 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html($co{'title'})) . "\n" .
2078 print "<div class=\"page_nav\">\n" .
2079 "<br/><br/></div>\n" .
2080 "<div class=\"title\">$hash vs $hash_parent</div>\n";
2082 if (defined $file_name) {
2083 print "<div class=\"page_path\"><b>/" . esc_html($file_name) . "</b></div>\n";
2085 print "<div class=\"page_body\">\n" .
2086 "<div class=\"diff_info\">blob:" .
2087 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name")}, $hash_parent) .
2089 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, $hash) .
2091 git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
2096 sub git_blobdiff_plain {
2097 mkdir($git_temp, 0700);
2098 print $cgi->header(-type => "text/plain", -charset => 'utf-8');
2099 git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
2102 sub git_commitdiff {
2103 mkdir($git_temp, 0700);
2104 my %co = git_read_commit($hash);
2106 die_error(undef, "Unknown commit object.");
2108 if (!defined $hash_parent) {
2109 $hash_parent = $co{'parent'};
2111 open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error(undef, "Open failed.");
2112 my (@difftree) = map { chomp; $_ } <$fd>;
2113 close $fd or die_error(undef, "Reading diff-tree failed.");
2115 # non-textual hash id's can be cached
2117 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2120 my $refs = read_info_ref();
2122 if (defined $refs->{$co{'id'}}) {
2123 $ref = " <span class=\"tag\">" . esc_html($refs->{$co{'id'}}) . "</span>";
2125 git_header_html(undef, $expires);
2126 print "<div class=\"page_nav\">\n" .
2127 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
2128 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash")}, "shortlog") .
2129 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash")}, "log") .
2130 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash")}, "commit") .
2132 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") . "<br/>\n";
2133 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent")}, "plain") . "\n" .
2136 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html($co{'title'}) . $ref) . "\n" .
2138 print "<div class=\"page_body\">\n";
2139 my $comment = $co{'comment'};
2142 my @log = @$comment;
2143 # remove first and empty lines after that
2145 while (defined $log[0] && $log[0] eq "") {
2148 foreach my $line (@log) {
2149 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2160 print format_log_line_html($line) . "<br/>\n";
2163 foreach my $line (@difftree) {
2164 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2165 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2166 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2172 my $file = validate_input(unquote($6));
2173 if ($status eq "A") {
2174 print "<div class=\"diff_info\">" . file_type($to_mode) . ":" .
2175 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id) . "(new)" .
2177 git_diff_print(undef, "/dev/null", $to_id, "b/$file");
2178 } elsif ($status eq "D") {
2179 print "<div class=\"diff_info\">" . file_type($from_mode) . ":" .
2180 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) . "(deleted)" .
2182 git_diff_print($from_id, "a/$file", undef, "/dev/null");
2183 } elsif ($status eq "M") {
2184 if ($from_id ne $to_id) {
2185 print "<div class=\"diff_info\">" .
2186 file_type($from_mode) . ":" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) .
2188 file_type($to_mode) . ":" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id);
2190 git_diff_print($from_id, "a/$file", $to_id, "b/$file");
2199 sub git_commitdiff_plain {
2200 mkdir($git_temp, 0700);
2201 open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error(undef, "Open failed.");
2202 my (@difftree) = map { chomp; $_ } <$fd>;
2203 close $fd or die_error(undef, "Reading diff-tree failed.");
2205 # try to figure out the next tag after this commit
2207 my $refs = read_info_ref("tags");
2208 open $fd, "-|", "$gitbin/git-rev-list HEAD";
2209 chomp (my (@commits) = <$fd>);
2211 foreach my $commit (@commits) {
2212 if (defined $refs->{$commit}) {
2213 $tagname = $refs->{$commit}
2215 if ($commit eq $hash) {
2220 print $cgi->header(-type => "text/plain", -charset => 'utf-8', '-content-disposition' => "inline; filename=\"git-$hash.patch\"");
2221 my %co = git_read_commit($hash);
2222 my %ad = date_str($co{'author_epoch'}, $co{'author_tz'});
2223 my $comment = $co{'comment'};
2224 print "From: $co{'author'}\n" .
2225 "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
2226 "Subject: $co{'title'}\n";
2227 if (defined $tagname) {
2228 print "X-Git-Tag: $tagname\n";
2230 print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
2233 foreach my $line (@$comment) {;
2238 foreach my $line (@difftree) {
2239 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2244 if ($status eq "A") {
2245 git_diff_print(undef, "/dev/null", $to_id, "b/$file", "plain");
2246 } elsif ($status eq "D") {
2247 git_diff_print($from_id, "a/$file", undef, "/dev/null", "plain");
2248 } elsif ($status eq "M") {
2249 git_diff_print($from_id, "a/$file", $to_id, "b/$file", "plain");
2255 if (!defined $hash) {
2256 $hash = git_read_head($project);
2258 my %co = git_read_commit($hash);
2260 die_error(undef, "Unknown commit object.");
2262 my $refs = read_info_ref();
2264 print "<div class=\"page_nav\">\n" .
2265 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
2266 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
2267 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log")}, "log") .
2268 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash")}, "commit") .
2269 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2270 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
2274 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html($co{'title'})) . "\n" .
2276 print "<div class=\"page_path\"><b>/" . esc_html($file_name) . "</b><br/></div>\n";
2278 open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin -- \'$file_name\'";
2280 print "<table cellspacing=\"0\">\n";
2282 while (my $line = <$fd>) {
2283 if ($line =~ m/^([0-9a-fA-F]{40})/){
2287 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/ && (defined $commit)) {
2288 my %co = git_read_commit($commit);
2293 if (defined $refs->{$commit}) {
2294 $ref = " <span class=\"tag\">" . esc_html($refs->{$commit}) . "</span>";
2297 print "<tr class=\"dark\">\n";
2299 print "<tr class=\"light\">\n";
2302 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2303 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2304 "<td>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "list"}, "<b>" .
2305 esc_html(chop_str($co{'title'}, 50)) . "$ref</b>") . "</td>\n" .
2306 "<td class=\"link\">" .
2307 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit")}, "commit") .
2308 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2309 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;hb=$commit;f=$file_name")}, "blob");
2310 my $blob = git_get_hash_by_path($hash, $file_name);
2311 my $blob_parent = git_get_hash_by_path($commit, $file_name);
2312 if (defined $blob && defined $blob_parent && $blob ne $blob_parent) {
2314 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=$file_name")},
2328 if (!defined $searchtext) {
2329 die_error("", "Text field empty.");
2331 if (!defined $hash) {
2332 $hash = git_read_head($project);
2334 my %co = git_read_commit($hash);
2336 die_error(undef, "Unknown commit object.");
2338 # pickaxe may take all resources of your box and run for several minutes
2339 # with every query - so decide by yourself how public you make this feature :)
2340 my $commit_search = 1;
2341 my $author_search = 0;
2342 my $committer_search = 0;
2343 my $pickaxe_search = 0;
2344 if ($searchtext =~ s/^author\\://i) {
2346 } elsif ($searchtext =~ s/^committer\\://i) {
2347 $committer_search = 1;
2348 } elsif ($searchtext =~ s/^pickaxe\\://i) {
2350 $pickaxe_search = 1;
2353 print "<div class=\"page_nav\">\n" .
2354 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary;h=$hash")}, "summary") .
2355 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "shortlog") .
2356 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash")}, "log") .
2357 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash")}, "commit") .
2358 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2359 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
2364 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html($co{'title'})) . "\n" .
2366 print "<table cellspacing=\"0\">\n";
2368 if ($commit_search) {
2370 open my $fd, "-|", "$gitbin/git-rev-list --header --parents $hash" or next;
2371 while (my $commit_text = <$fd>) {
2372 if (!grep m/$searchtext/i, $commit_text) {
2375 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
2378 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
2381 my @commit_lines = split "\n", $commit_text;
2382 my %co = git_read_commit(undef, \@commit_lines);
2387 print "<tr class=\"dark\">\n";
2389 print "<tr class=\"light\">\n";
2392 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2393 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2395 $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/>");
2396 my $comment = $co{'comment'};
2397 foreach my $line (@$comment) {
2398 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2399 my $lead = esc_html($1) || "";
2400 $lead = chop_str($lead, 30, 10);
2401 my $match = esc_html($2) || "";
2402 my $trail = esc_html($3) || "";
2403 $trail = chop_str($trail, 30, 10);
2404 my $text = "$lead<span style=\"color:#e00000\">$match</span>$trail";
2405 print chop_str($text, 80, 5) . "<br/>\n";
2409 "<td class=\"link\">" .
2410 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2411 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2418 if ($pickaxe_search) {
2420 open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin -S\'$searchtext\'";
2423 while (my $line = <$fd>) {
2424 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2427 $set{'from_id'} = $3;
2429 $set{'id'} = $set{'to_id'};
2430 if ($set{'id'} =~ m/0{40}/) {
2431 $set{'id'} = $set{'from_id'};
2433 if ($set{'id'} =~ m/0{40}/) {
2437 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
2440 print "<tr class=\"dark\">\n";
2442 print "<tr class=\"light\">\n";
2445 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2446 "<td><i>" . esc_html(chop_str($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2448 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" .
2449 esc_html(chop_str($co{'title'}, 50)) . "</b><br/>");
2450 while (my $setref = shift @files) {
2452 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}"), class => "list"},
2453 "<span style=\"color:#e00000\">" . esc_html($set{'file'}) . "</span>") .
2457 "<td class=\"link\">" .
2458 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2459 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2463 %co = git_read_commit($1);
2473 my $head = git_read_head($project);
2474 if (!defined $hash) {
2477 if (!defined $page) {
2480 my $refs = read_info_ref();
2482 print "<div class=\"page_nav\">\n" .
2483 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary")}, "summary") .
2485 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$hash")}, "log") .
2486 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$hash")}, "commit") .
2487 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2488 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$hash;hb=$hash")}, "tree") . "<br/>\n";
2490 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2491 open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error(undef, "Open failed.");
2492 my (@revlist) = map { chomp; $_ } <$fd>;
2495 if ($hash ne $head || $page) {
2496 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "HEAD");
2502 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash;pg=" . ($page-1)), -accesskey => "p", -title => "Alt-p"}, "prev");
2504 print " ⋅ prev";
2506 if ($#revlist >= (100 * ($page+1)-1)) {
2508 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)), -accesskey => "n", -title => "Alt-n"}, "next");
2510 print " ⋅ next";
2515 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=summary"), -class => "title"}, " ") .
2517 print "<table cellspacing=\"0\">\n";
2519 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2520 my $commit = $revlist[$i];
2522 if (defined $refs->{$commit}) {
2523 $ref = " <span class=\"tag\">" . esc_html($refs->{$commit}) . "</span>";
2525 my %co = git_read_commit($commit);
2526 my %ad = date_str($co{'author_epoch'});
2528 print "<tr class=\"dark\">\n";
2530 print "<tr class=\"light\">\n";
2533 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2534 "<td><i>" . esc_html(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
2536 if (length($co{'title_short'}) < length($co{'title'})) {
2537 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "list", -title => "$co{'title'}"},
2538 "<b>" . esc_html($co{'title_short'}) . "$ref</b>");
2540 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"), -class => "list"},
2541 "<b>" . esc_html($co{'title_short'}) . "$ref</b>");
2544 "<td class=\"link\">" .
2545 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit")}, "commit") .
2546 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2550 if ($#revlist >= (100 * ($page+1)-1)) {
2553 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)), -title => "Alt-n"}, "next") .