3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI
qw(:standard :escapeHTML -nosticky);
13 use CGI
::Util
qw(unescape);
14 use CGI
::Carp
qw(fatalsToBrowser);
17 binmode STDOUT
, ':utf8';
21 my $my_url = $cgi->url();
22 my $my_uri = $cgi->url(-absolute
=> 1);
25 # location of the git-core binaries
26 my $gitbin = "/usr/bin";
28 # absolute fs-path which will be prepended to the project path
29 #my $projectroot = "/pub/scm";
30 my $projectroot = "/home/kay/public_html/pub/scm";
32 # version of the git-core binaries
33 my $git_version = qx($gitbin/git
--version
);
34 if ($git_version =~ m/git version (.*)$/) {
37 $git_version = "unknown";
40 # location for temporary files needed for diffs
41 my $git_temp = "/tmp/gitweb";
43 # target of the home link on top of all pages
44 my $home_link = $my_uri;
46 # html text to include at home page
47 my $home_text = "indextext.html";
49 # URI of default stylesheet
50 my $stylesheet = "gitweb.css";
52 # source of projects list
53 #my $projects_list = $projectroot;
54 my $projects_list = "index/index.aux";
56 # default blob_plain mimetype and default charset for text/plain blob
57 my $default_blob_plain_mimetype = 'text/plain';
58 my $default_text_plain_charset = undef;
60 # file to use for guessing MIME types before trying /etc/mime.types
61 # (relative to the current git repository)
62 my $mimetypes_file = undef;
65 # input validation and dispatch
66 my $action = $cgi->param('a');
67 if (defined $action) {
68 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
70 die_error
(undef, "Invalid action parameter.");
72 if ($action eq "git-logo.png") {
75 } elsif ($action eq "opml") {
81 my $order = $cgi->param('o');
83 if ($order =~ m/[^0-9a-zA-Z_]/) {
85 die_error
(undef, "Invalid order parameter.");
89 my $project = $cgi->param('p');
90 if (defined $project) {
91 $project = validate_input
($project);
92 if (!defined($project)) {
93 die_error
(undef, "Invalid project parameter.");
95 if (!(-d
"$projectroot/$project")) {
97 die_error
(undef, "No such directory.");
99 if (!(-e
"$projectroot/$project/HEAD")) {
101 die_error
(undef, "No such project.");
103 $rss_link = "<link rel=\"alternate\" title=\"" . esc_param
($project) . " log\" href=\"" .
104 "$my_uri?" . esc_param
("p=$project;a=rss") . "\" type=\"application/rss+xml\"/>";
105 $ENV{'GIT_DIR'} = "$projectroot/$project";
111 my $file_name = $cgi->param('f');
112 if (defined $file_name) {
113 $file_name = validate_input
($file_name);
114 if (!defined($file_name)) {
115 die_error
(undef, "Invalid file parameter.");
119 my $hash = $cgi->param('h');
121 $hash = validate_input
($hash);
122 if (!defined($hash)) {
123 die_error
(undef, "Invalid hash parameter.");
127 my $hash_parent = $cgi->param('hp');
128 if (defined $hash_parent) {
129 $hash_parent = validate_input
($hash_parent);
130 if (!defined($hash_parent)) {
131 die_error
(undef, "Invalid hash parent parameter.");
135 my $hash_base = $cgi->param('hb');
136 if (defined $hash_base) {
137 $hash_base = validate_input
($hash_base);
138 if (!defined($hash_base)) {
139 die_error
(undef, "Invalid hash base parameter.");
143 my $page = $cgi->param('pg');
145 if ($page =~ m/[^0-9]$/) {
147 die_error
(undef, "Invalid page parameter.");
151 my $searchtext = $cgi->param('s');
152 if (defined $searchtext) {
153 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
155 die_error
(undef, "Invalid search parameter.");
157 $searchtext = quotemeta $searchtext;
163 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
166 if ($input =~ m/(^|\/)(|\
.|\
.\
.)($|\
/)/) {
169 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\
-\
+\#\
~\
%]/) {
175 if (!defined $action || $action eq "summary") {
178 } elsif ($action eq "heads") {
181 } elsif ($action eq "tags") {
184 } elsif ($action eq "blob") {
187 } elsif ($action eq "blob_plain") {
190 } elsif ($action eq "tree") {
193 } elsif ($action eq "rss") {
196 } elsif ($action eq "commit") {
199 } elsif ($action eq "log") {
202 } elsif ($action eq "blobdiff") {
205 } elsif ($action eq "blobdiff_plain") {
206 git_blobdiff_plain
();
208 } elsif ($action eq "commitdiff") {
211 } elsif ($action eq "commitdiff_plain") {
212 git_commitdiff_plain
();
214 } elsif ($action eq "history") {
217 } elsif ($action eq "search") {
220 } elsif ($action eq "shortlog") {
223 } elsif ($action eq "tag") {
226 } elsif ($action eq "blame") {
231 die_error
(undef, "Unknown action.");
235 # quote unsafe chars, but keep the slash, even when it's not
236 # correct, but quoted slashes look too horrible in bookmarks
239 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
245 # replace invalid utf8 character with SUBSTITUTION sequence
248 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
249 $str = escapeHTML
($str);
253 # git may return quoted and escaped filenames
256 if ($str =~ m/^"(.*)"$/) {
258 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
263 # CSS class for given age value (in seconds)
267 if ($age < 60*60*2) {
269 } elsif ($age < 60*60*24*2) {
276 sub git_header_html
{
277 my $status = shift || "200 OK";
281 if (defined $project) {
282 $title .= " - $project";
283 if (defined $action) {
284 $title .= "/$action";
285 if (defined $file_name) {
286 $title .= " - $file_name";
287 if ($action eq "tree" && $file_name !~ m
|/$|) {
293 print $cgi->header(-type
=>'text/html', -charset
=> 'utf-8', -status
=> $status, -expires
=> $expires);
295 <?xml version="1.0" encoding="utf-8"?>
296 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
297 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
298 <!-- git web interface v$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
299 <!-- git core binaries version $git_version -->
301 <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
302 <meta name="robots" content="index, nofollow"/>
303 <title>$title</title>
304 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
309 print "<div class=\"page_header\">\n" .
310 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
311 "<img src=\"$my_uri?" . esc_param
("a=git-logo.png") . "\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
313 print $cgi->a({-href
=> esc_param
($home_link)}, "projects") . " / ";
314 if (defined $project) {
315 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, esc_html
($project));
316 if (defined $action) {
320 if (!defined $searchtext) {
325 $search_hash = $hash;
327 $search_hash = "HEAD";
329 $cgi->param("a", "search");
330 $cgi->param("h", $search_hash);
331 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
332 "<div class=\"search\">\n" .
333 $cgi->hidden(-name
=> "p") . "\n" .
334 $cgi->hidden(-name
=> "a") . "\n" .
335 $cgi->hidden(-name
=> "h") . "\n" .
336 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
338 $cgi->end_form() . "\n";
343 sub git_footer_html
{
344 print "<div class=\"page_footer\">\n";
345 if (defined $project) {
346 my $descr = git_read_description
($project);
347 if (defined $descr) {
348 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
350 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=rss"), -class => "rss_logo"}, "RSS") . "\n";
352 print $cgi->a({-href
=> "$my_uri?" . esc_param
("a=opml"), -class => "rss_logo"}, "OPML") . "\n";
360 my $status = shift || "403 Forbidden";
361 my $error = shift || "Malformed query, file missing or permission denied";
363 git_header_html
($status);
364 print "<div class=\"page_body\">\n" .
366 "$status - $error\n" .
376 open my $fd, "-|", "$gitbin/git-cat-file -t $hash" or return;
385 my $oENV = $ENV{'GIT_DIR'};
387 $ENV{'GIT_DIR'} = "$projectroot/$project";
388 if (open my $fd, "-|", "$gitbin/git-rev-parse", "--verify", "HEAD") {
391 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
396 $ENV{'GIT_DIR'} = $oENV;
404 open my $fd, "$projectroot/$path" or return undef;
408 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
413 sub git_read_description
{
416 open my $fd, "$projectroot/$path/description" or return undef;
428 open my $fd, "-|", "$gitbin/git-cat-file tag $tag_id" or return;
429 $tag{'id'} = $tag_id;
430 while (my $line = <$fd>) {
432 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
434 } elsif ($line =~ m/^type (.+)$/) {
436 } elsif ($line =~ m/^tag (.+)$/) {
438 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
442 } elsif ($line =~ m/--BEGIN/) {
443 push @comment, $line;
445 } elsif ($line eq "") {
449 push @comment, <$fd>;
450 $tag{'comment'} = \
@comment;
452 if (!defined $tag{'name'}) {
462 if ($age > 60*60*24*365*2) {
463 $age_str = (int $age/60/60/24/365);
464 $age_str .= " years ago";
465 } elsif ($age > 60*60*24*(365/12)*2) {
466 $age_str = int $age/60/60/24/(365/12);
467 $age_str .= " months ago";
468 } elsif ($age > 60*60*24*7*2) {
469 $age_str = int $age/60/60/24/7;
470 $age_str .= " weeks ago";
471 } elsif ($age > 60*60*24*2) {
472 $age_str = int $age/60/60/24;
473 $age_str .= " days ago";
474 } elsif ($age > 60*60*2) {
475 $age_str = int $age/60/60;
476 $age_str .= " hours ago";
477 } elsif ($age > 60*2) {
478 $age_str = int $age/60;
479 $age_str .= " min ago";
482 $age_str .= " sec ago";
484 $age_str .= " right now";
489 sub git_read_commit
{
490 my $commit_id = shift;
491 my $commit_text = shift;
496 if (defined $commit_text) {
497 @commit_lines = @
$commit_text;
500 open my $fd, "-|", "$gitbin/git-rev-list --header --parents --max-count=1 $commit_id" or return;
501 @commit_lines = split '\n', <$fd>;
506 my $header = shift @commit_lines;
507 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
510 ($co{'id'}, my @parents) = split ' ', $header;
511 $co{'parents'} = \
@parents;
512 $co{'parent'} = $parents[0];
513 while (my $line = shift @commit_lines) {
514 last if $line eq "\n";
515 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
517 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
519 $co{'author_epoch'} = $2;
520 $co{'author_tz'} = $3;
521 if ($co{'author'} =~ m/^([^<]+) </) {
522 $co{'author_name'} = $1;
524 $co{'author_name'} = $co{'author'};
526 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
527 $co{'committer'} = $1;
528 $co{'committer_epoch'} = $2;
529 $co{'committer_tz'} = $3;
530 $co{'committer_name'} = $co{'committer'};
531 $co{'committer_name'} =~ s/ <.*//;
534 if (!defined $co{'tree'}) {
538 foreach my $title (@commit_lines) {
541 $co{'title'} = chop_str
($title, 80, 5);
542 # remove leading stuff of merges to make the interesting part visible
543 if (length($title) > 50) {
544 $title =~ s/^Automatic //;
545 $title =~ s/^merge (of|with) /Merge ... /i;
546 if (length($title) > 50) {
547 $title =~ s/(http|rsync):\/\///;
549 if (length($title) > 50) {
550 $title =~ s/(master|www|rsync)\.//;
552 if (length($title) > 50) {
553 $title =~ s/kernel.org:?//;
555 if (length($title) > 50) {
556 $title =~ s/\/pub\/scm//;
559 $co{'title_short'} = chop_str
($title, 50, 5);
563 # remove added spaces
564 foreach my $line (@commit_lines) {
567 $co{'comment'} = \
@commit_lines;
569 my $age = time - $co{'committer_epoch'};
571 $co{'age_string'} = age_string
($age);
572 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
573 if ($age > 60*60*24*7*2) {
574 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
575 $co{'age_string_age'} = $co{'age_string'};
577 $co{'age_string_date'} = $co{'age_string'};
578 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
585 my $from_name = shift;
588 my $format = shift || "html";
590 my $from_tmp = "/dev/null";
591 my $to_tmp = "/dev/null";
594 # create tmp from-file
596 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
597 open my $fd2, "> $from_tmp";
598 open my $fd, "-|", "$gitbin/git-cat-file blob $from";
607 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
608 open my $fd2, "> $to_tmp";
609 open my $fd, "-|", "$gitbin/git-cat-file blob $to";
616 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
617 if ($format eq "plain") {
622 while (my $line = <$fd>) {
624 my $char = substr($line, 0, 1);
627 $diff_class = " add";
628 } elsif ($char eq "-") {
629 $diff_class = " rem";
630 } elsif ($char eq "@") {
631 $diff_class = " chunk_header";
632 } elsif ($char eq "\\") {
636 while ((my $pos = index($line, "\t")) != -1) {
637 if (my $count = (8 - (($pos-1) % 8))) {
638 my $spaces = ' ' x
$count;
639 $line =~ s/\t/$spaces/;
642 print "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
656 my $mode = oct shift;
658 if (S_ISDIR
($mode & S_IFMT
)) {
660 } elsif (S_ISLNK
($mode)) {
662 } elsif (S_ISREG
($mode)) {
663 # git cares only about the executable bit
664 if ($mode & S_IXUSR
) {
677 my $add_len = shift || 10;
679 # allow only $len chars, but don't cut a word if it would fit in $add_len
680 # if it doesn't fit, cut it if it's still longer than the dots we would add
681 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
684 if (length($tail) > 4) {
691 my $mode = oct shift;
693 if (S_ISDIR
($mode & S_IFMT
)) {
695 } elsif (S_ISLNK
($mode)) {
697 } elsif (S_ISREG
($mode)) {
704 sub format_log_line_html
{
707 $line = esc_html
($line);
708 $line =~ s/ / /g;
709 if ($line =~ m/([0-9a-fA-F]{40})/) {
711 if (git_get_type
($hash_text) eq "commit") {
712 my $link = $cgi->a({-class => "text", -href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_text")}, $hash_text);
713 $line =~ s/$hash_text/$link/;
721 my $tz = shift || "-0000";
724 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
725 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
726 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
727 $date{'hour'} = $hour;
728 $date{'minute'} = $min;
729 $date{'mday'} = $mday;
730 $date{'day'} = $days[$wday];
731 $date{'month'} = $months[$mon];
732 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
733 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
735 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
736 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
737 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
738 $date{'hour_local'} = $hour;
739 $date{'minute_local'} = $min;
740 $date{'tz_local'} = $tz;
744 # git-logo (cached in browser for one day)
746 binmode STDOUT
, ':raw';
747 print $cgi->header(-type
=> 'image/png', -expires
=> '+1d');
748 # cat git-logo.png | hexdump -e '16/1 " %02x" "\n"' | sed 's/ /\\x/g'
749 print "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52" .
750 "\x00\x00\x00\x48\x00\x00\x00\x1b\x04\x03\x00\x00\x00\x2d\xd9\xd4" .
751 "\x2d\x00\x00\x00\x18\x50\x4c\x54\x45\xff\xff\xff\x60\x60\x5d\xb0" .
752 "\xaf\xaa\x00\x80\x00\xce\xcd\xc7\xc0\x00\x00\xe8\xe8\xe6\xf7\xf7" .
753 "\xf6\x95\x0c\xa7\x47\x00\x00\x00\x73\x49\x44\x41\x54\x28\xcf\x63" .
754 "\x48\x67\x20\x04\x4a\x5c\x18\x0a\x08\x2a\x62\x53\x61\x20\x02\x08" .
755 "\x0d\x69\x45\xac\xa1\xa1\x01\x30\x0c\x93\x60\x36\x26\x52\x91\xb1" .
756 "\x01\x11\xd6\xe1\x55\x64\x6c\x6c\xcc\x6c\x6c\x0c\xa2\x0c\x70\x2a" .
757 "\x62\x06\x2a\xc1\x62\x1d\xb3\x01\x02\x53\xa4\x08\xe8\x00\x03\x18" .
758 "\x26\x56\x11\xd4\xe1\x20\x97\x1b\xe0\xb4\x0e\x35\x24\x71\x29\x82" .
759 "\x99\x30\xb8\x93\x0a\x11\xb9\x45\x88\xc1\x8d\xa0\xa2\x44\x21\x06" .
760 "\x27\x41\x82\x40\x85\xc1\x45\x89\x20\x70\x01\x00\xa4\x3d\x21\xc5" .
761 "\x12\x1c\x9a\xfe\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\x82";
767 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
768 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
769 if (!defined $gcos) {
773 $owner =~ s/[,;].*$//;
774 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
777 sub git_read_projects
{
780 if (-d
$projects_list) {
781 # search in directory
782 my $dir = $projects_list;
783 opendir my $dh, $dir or return undef;
784 while (my $dir = readdir($dh)) {
785 if (-e
"$projectroot/$dir/HEAD") {
793 } elsif (-f
$projects_list) {
794 # read from file(url-encoded):
795 # 'git%2Fgit.git Linus+Torvalds'
796 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
797 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
798 open my $fd , $projects_list or return undef;
799 while (my $line = <$fd>) {
801 my ($path, $owner) = split ' ', $line;
802 $path = unescape
($path);
803 $owner = unescape
($owner);
804 if (!defined $path) {
807 if (-e
"$projectroot/$path/HEAD") {
810 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
817 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
821 sub git_get_project_config
{
824 return unless ($key);
825 $key =~ s/^gitweb\.//;
826 return if ($key =~ m/\W/);
828 my $val = qx($gitbin/git
-repo
-config
--get gitweb
.$key);
832 sub git_get_project_config_bool
{
833 my $val = git_get_project_config
(@_);
834 if ($val and $val =~ m/true|yes|on/) {
837 return; # implicit false
840 sub git_project_list
{
841 my @list = git_read_projects
();
844 die_error
(undef, "No project found.");
846 foreach my $pr (@list) {
847 my $head = git_read_head
($pr->{'path'});
848 if (!defined $head) {
851 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
852 my %co = git_read_commit
($head);
856 $pr->{'commit'} = \
%co;
857 if (!defined $pr->{'descr'}) {
858 my $descr = git_read_description
($pr->{'path'}) || "";
859 $pr->{'descr'} = chop_str
($descr, 25, 5);
861 if (!defined $pr->{'owner'}) {
862 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
868 print "<div class=\"index_include\">\n";
869 open (my $fd, $home_text);
874 print "<table class=\"project_list\">\n" .
876 if (!defined($order) || (defined($order) && ($order eq "project"))) {
877 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
878 print "<th>Project</th>\n";
880 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=project")}, "Project") . "</th>\n";
882 if (defined($order) && ($order eq "descr")) {
883 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
884 print "<th>Description</th>\n";
886 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=descr")}, "Description") . "</th>\n";
888 if (defined($order) && ($order eq "owner")) {
889 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
890 print "<th>Owner</th>\n";
892 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=owner")}, "Owner") . "</th>\n";
894 if (defined($order) && ($order eq "age")) {
895 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
896 print "<th>Last Change</th>\n";
898 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=age")}, "Last Change") . "</th>\n";
900 print "<th></th>\n" .
903 foreach my $pr (@projects) {
905 print "<tr class=\"dark\">\n";
907 print "<tr class=\"light\">\n";
910 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=summary"), -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
911 "<td>$pr->{'descr'}</td>\n" .
912 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
913 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" . $pr->{'commit'}{'age_string'} . "</td>\n" .
914 "<td class=\"link\">" .
915 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=summary")}, "summary") .
916 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=shortlog")}, "shortlog") .
917 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=log")}, "log") .
926 my $type = shift || "";
928 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
929 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
930 open my $fd, "$projectroot/$project/info/refs" or return;
931 while (my $line = <$fd>) {
933 if ($line =~ m/^([0-9a-fA-F]{40})\t.*$type\/([^\
^]+)/) {
934 if (defined $refs{$1}) {
935 $refs{$1} .= " / $2";
950 opendir my $dh, "$projectroot/$project/$ref_dir";
951 while (my $dir = readdir($dh)) {
952 if ($dir =~ m/^\./) {
955 if (-d
"$projectroot/$project/$ref_dir/$dir") {
956 opendir my $dh2, "$projectroot/$project/$ref_dir/$dir";
957 my @subdirs = grep !m/^\./, readdir $dh2;
959 foreach my $subdir (@subdirs) {
960 push @refs, "$dir/$subdir"
967 foreach my $ref_file (@refs) {
968 my $ref_id = git_read_hash
("$project/$ref_dir/$ref_file");
969 my $type = git_get_type
($ref_id) || next;
972 $ref_item{'type'} = $type;
973 $ref_item{'id'} = $ref_id;
974 $ref_item{'epoch'} = 0;
975 $ref_item{'age'} = "unknown";
976 if ($type eq "tag") {
977 my %tag = git_read_tag
($ref_id);
978 $ref_item{'comment'} = $tag{'comment'};
979 if ($tag{'type'} eq "commit") {
980 %co = git_read_commit
($tag{'object'});
981 $ref_item{'epoch'} = $co{'committer_epoch'};
982 $ref_item{'age'} = $co{'age_string'};
983 } elsif (defined($tag{'epoch'})) {
984 my $age = time - $tag{'epoch'};
985 $ref_item{'epoch'} = $tag{'epoch'};
986 $ref_item{'age'} = age_string
($age);
988 $ref_item{'reftype'} = $tag{'type'};
989 $ref_item{'name'} = $tag{'name'};
990 $ref_item{'refid'} = $tag{'object'};
991 } elsif ($type eq "commit"){
992 %co = git_read_commit
($ref_id);
993 $ref_item{'reftype'} = "commit";
994 $ref_item{'name'} = $ref_file;
995 $ref_item{'title'} = $co{'title'};
996 $ref_item{'refid'} = $ref_id;
997 $ref_item{'epoch'} = $co{'committer_epoch'};
998 $ref_item{'age'} = $co{'age_string'};
1001 push @reflist, \
%ref_item;
1004 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1009 my $descr = git_read_description
($project) || "none";
1010 my $head = git_read_head
($project);
1011 my %co = git_read_commit
($head);
1012 my %cd = date_str
($co{'committer_epoch'}, $co{'committer_tz'});
1015 if (-f
$projects_list) {
1016 open (my $fd , $projects_list);
1017 while (my $line = <$fd>) {
1019 my ($pr, $ow) = split ' ', $line;
1020 $pr = unescape
($pr);
1021 $ow = unescape
($ow);
1022 if ($pr eq $project) {
1023 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
1029 if (!defined $owner) {
1030 $owner = get_file_owner
("$projectroot/$project");
1033 my $refs = read_info_ref
();
1035 print "<div class=\"page_nav\">\n" .
1037 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1038 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1039 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$head")}, "commit") .
1040 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1041 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree")}, "tree") .
1044 print "<div class=\"title\"> </div>\n";
1045 print "<table cellspacing=\"0\">\n" .
1046 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
1047 "<tr><td>owner</td><td>$owner</td></tr>\n" .
1048 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
1050 open my $fd, "-|", "$gitbin/git-rev-list --max-count=17 " . git_read_head
($project) or die_error
(undef, "Open failed.");
1051 my (@revlist) = map { chomp; $_ } <$fd>;
1054 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog"), -class => "title"}, "shortlog") .
1057 print "<table cellspacing=\"0\">\n";
1059 foreach my $commit (@revlist) {
1060 my %co = git_read_commit
($commit);
1061 my %ad = date_str
($co{'author_epoch'});
1063 print "<tr class=\"dark\">\n";
1065 print "<tr class=\"light\">\n";
1070 if (defined $refs->{$commit}) {
1071 $ref = " <span class=\"tag\">" . esc_html
($refs->{$commit}) . "</span>";
1073 print "<td><i>$co{'age_string'}</i></td>\n" .
1074 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
1076 if (length($co{'title_short'}) < length($co{'title'})) {
1077 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list", -title
=> "$co{'title'}"},
1078 "<b>" . esc_html
($co{'title_short'}) . "$ref</b>");
1080 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list"},
1081 "<b>" . esc_html
($co{'title'}) . "$ref</b>");
1084 "<td class=\"link\">" .
1085 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
1086 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1090 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "...") . "</td>\n" .
1097 my $taglist = git_read_refs
("refs/tags");
1098 if (defined @
$taglist) {
1100 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tags"), -class => "title"}, "tags") .
1103 print "<table cellspacing=\"0\">\n";
1105 foreach my $entry (@
$taglist) {
1107 my $comment_lines = $tag{'comment'};
1108 my $comment = shift @
$comment_lines;
1109 if (defined($comment)) {
1110 $comment = chop_str
($comment, 30, 5);
1113 print "<tr class=\"dark\">\n";
1115 print "<tr class=\"light\">\n";
1119 print "<td><i>$tag{'age'}</i></td>\n" .
1121 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), -class => "list"},
1122 "<b>" . esc_html
($tag{'name'}) . "</b>") .
1125 if (defined($comment)) {
1126 print $cgi->a({-class => "list", -href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, $comment);
1129 "<td class=\"link\">";
1130 if ($tag{'type'} eq "tag") {
1131 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
1133 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1134 if ($tag{'reftype'} eq "commit") {
1135 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1136 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'refid'}")}, "log");
1141 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tags")}, "...") . "</td>\n" .
1149 my $headlist = git_read_refs
("refs/heads");
1150 if (defined @
$headlist) {
1152 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=heads"), -class => "title"}, "heads") .
1155 print "<table cellspacing=\"0\">\n";
1157 foreach my $entry (@
$headlist) {
1160 print "<tr class=\"dark\">\n";
1162 print "<tr class=\"light\">\n";
1166 print "<td><i>$tag{'age'}</i></td>\n" .
1168 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}"), -class => "list"},
1169 "<b>" . esc_html
($tag{'name'}) . "</b>") .
1171 "<td class=\"link\">" .
1172 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1173 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'name'}")}, "log") .
1177 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=heads")}, "...") . "</td>\n" .
1188 my $head = git_read_head
($project);
1190 print "<div class=\"page_nav\">\n" .
1191 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1192 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1193 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1194 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$head")}, "commit") .
1195 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1196 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1199 my %tag = git_read_tag
($hash);
1201 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html
($tag{'name'})) . "\n" .
1203 print "<div class=\"title_text\">\n" .
1204 "<table cellspacing=\"0\">\n" .
1206 "<td>object</td>\n" .
1207 "<td>" . $cgi->a({-class => "list", -href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'object'}) . "</td>\n" .
1208 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'type'}) . "</td>\n" .
1210 if (defined($tag{'author'})) {
1211 my %ad = date_str
($tag{'epoch'}, $tag{'tz'});
1212 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
1213 print "<tr><td></td><td>" . $ad{'rfc2822'} . sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) . "</td></tr>\n";
1215 print "</table>\n\n" .
1217 print "<div class=\"page_body\">";
1218 my $comment = $tag{'comment'};
1219 foreach my $line (@
$comment) {
1220 print esc_html
($line) . "<br/>\n";
1228 die_error
('403 Permission denied', "Permission denied.") if (!git_get_project_config_bool
('blame'));
1229 die_error
('404 Not Found', "What file will it be, master?") if (!$file_name);
1230 $hash_base ||= git_read_head
($project);
1231 die_error
(undef, "Reading commit failed.") unless ($hash_base);
1232 my %co = git_read_commit
($hash_base)
1233 or die_error
(undef, "Reading commit failed.");
1234 if (!defined $hash) {
1235 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
1236 or die_error
(undef, "Error lookup file.");
1238 open ($fd, "-|", "$gitbin/git-annotate", '-l', '-t', '-r', $file_name, $hash_base)
1239 or die_error
(undef, "Open failed.");
1241 print "<div class=\"page_nav\">\n" .
1242 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1243 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1244 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1245 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base")}, "commit") .
1246 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1247 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") . "<br/>\n";
1248 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") .
1249 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;f=$file_name")}, "head") . "<br/>\n";
1252 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html
($co{'title'})) .
1254 print "<div class=\"page_path\"><b>" . esc_html
($file_name) . "</b></div>\n";
1255 print "<div class=\"page_body\">\n";
1257 <table class="blame">
1266 my @line_class = (qw(light dark));
1267 my $line_class_len = scalar (@line_class);
1268 my $line_class_num = $#line_class;
1269 while (my $line = <$fd>) {
1281 $line_class_num = ($line_class_num + 1) % $line_class_len;
1283 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) \+\d\d\d\d\t(\d+)\)(.*)$/) {
1290 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
1293 $short_rev = substr ($long_rev, 0, 8);
1294 $age = time () - $time;
1295 $age_str = age_string
($age);
1296 $age_str =~ s/ / /g;
1297 $age_class = age_class
($age);
1298 $author = esc_html
($author);
1299 $author =~ s/ / /g;
1301 while ((my $pos = index($data, "\t")) != -1) {
1302 if (my $count = (8 - ($pos % 8))) {
1303 my $spaces = ' ' x
$count;
1304 $data =~ s/\t/$spaces/;
1307 $data = esc_html
($data);
1310 <tr class="$line_class[$line_class_num]">
1311 <td class="sha1"><a href="$my_uri?${\esc_param ("p=$project;a=commit;h=$long_rev")}" class="text">$short_rev..</a></td>
1312 <td class="$age_class">$age_str</td>
1314 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
1315 <td class="pre">$data</td>
1318 } # while (my $line = <$fd>)
1319 print "</table>\n\n";
1320 close $fd or print "Reading blob failed.\n";
1326 my $head = git_read_head
($project);
1328 print "<div class=\"page_nav\">\n" .
1329 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1330 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1331 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1332 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$head")}, "commit") .
1333 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1334 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1337 my $taglist = git_read_refs
("refs/tags");
1339 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary"), -class => "title"}, " ") .
1341 print "<table cellspacing=\"0\">\n";
1343 if (defined @
$taglist) {
1344 foreach my $entry (@
$taglist) {
1346 my $comment_lines = $tag{'comment'};
1347 my $comment = shift @
$comment_lines;
1348 if (defined($comment)) {
1349 $comment = chop_str
($comment, 30, 5);
1352 print "<tr class=\"dark\">\n";
1354 print "<tr class=\"light\">\n";
1357 print "<td><i>$tag{'age'}</i></td>\n" .
1359 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"), -class => "list"},
1360 "<b>" . esc_html
($tag{'name'}) . "</b>") .
1363 if (defined($comment)) {
1364 print $cgi->a({-class => "list", -href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, $comment);
1367 "<td class=\"link\">";
1368 if ($tag{'type'} eq "tag") {
1369 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, "tag") . " | ";
1371 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1372 if ($tag{'reftype'} eq "commit") {
1373 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1374 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'refid'}")}, "log");
1385 my $head = git_read_head
($project);
1387 print "<div class=\"page_nav\">\n" .
1388 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1389 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1390 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1391 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$head")}, "commit") .
1392 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$head")}, "commitdiff") .
1393 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;hb=$head")}, "tree") . "<br/>\n" .
1396 my $taglist = git_read_refs
("refs/heads");
1398 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary"), -class => "title"}, " ") .
1400 print "<table cellspacing=\"0\">\n";
1402 if (defined @
$taglist) {
1403 foreach my $entry (@
$taglist) {
1406 print "<tr class=\"dark\">\n";
1408 print "<tr class=\"light\">\n";
1411 print "<td><i>$tag{'age'}</i></td>\n" .
1413 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}"), -class => "list"}, "<b>" . esc_html
($tag{'name'}) . "</b>") .
1415 "<td class=\"link\">" .
1416 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1417 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'name'}")}, "log") .
1426 sub git_get_hash_by_path
{
1428 my $path = shift || return undef;
1431 my @parts = split '/', $path;
1432 while (my $part = shift @parts) {
1433 open my $fd, "-|", "$gitbin/git-ls-tree $tree" or die_error
(undef, "Open git-ls-tree failed.");
1434 my (@entries) = map { chomp; $_ } <$fd>;
1435 close $fd or return undef;
1436 foreach my $line (@entries) {
1437 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1438 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1442 my $t_name = validate_input
(unquote
($4));
1443 if ($t_name eq $part) {
1447 if ($t_type eq "tree") {
1457 if (!defined $hash && defined $file_name) {
1458 my $base = $hash_base || git_read_head
($project);
1459 $hash = git_get_hash_by_path
($base, $file_name, "blob") || die_error
(undef, "Error lookup file.");
1461 my $have_blame = git_get_project_config_bool
('blame');
1462 open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or die_error
(undef, "Open failed.");
1464 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
1465 print "<div class=\"page_nav\">\n" .
1466 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1467 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
1468 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
1469 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base")}, "commit") .
1470 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1471 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") . "<br/>\n";
1472 if (defined $file_name) {
1474 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;h=$hash;hb=$hash_base;f=$file_name")}, "blame") . " | ";
1476 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$hash;f=$file_name")}, "plain") .
1477 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;hb=HEAD;f=$file_name")}, "head") . "<br/>\n";
1479 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$hash")}, "plain") . "<br/>\n";
1483 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html
($co{'title'})) .
1486 print "<div class=\"page_nav\">\n" .
1487 "<br/><br/></div>\n" .
1488 "<div class=\"title\">$hash</div>\n";
1490 if (defined $file_name) {
1491 print "<div class=\"page_path\"><b>" . esc_html
($file_name) . "</b></div>\n";
1493 print "<div class=\"page_body\">\n";
1495 while (my $line = <$fd>) {
1498 while ((my $pos = index($line, "\t")) != -1) {
1499 if (my $count = (8 - ($pos % 8))) {
1500 my $spaces = ' ' x
$count;
1501 $line =~ s/\t/$spaces/;
1504 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", $nr, $nr, $nr, esc_html
($line);
1506 close $fd or print "Reading blob failed.\n";
1511 sub mimetype_guess_file
{
1512 my $filename = shift;
1513 my $mimemap = shift;
1514 -r
$mimemap or return undef;
1517 open(MIME
, $mimemap) or return undef;
1519 my ($mime, $exts) = split(/\t+/);
1520 my @exts = split(/\s+/, $exts);
1521 foreach my $ext (@exts) {
1522 $mimemap{$ext} = $mime;
1527 $filename =~ /\.(.*?)$/;
1528 return $mimemap{$1};
1531 sub mimetype_guess
{
1532 my $filename = shift;
1534 $filename =~ /\./ or return undef;
1536 if ($mimetypes_file) {
1537 my $file = $mimetypes_file;
1538 #$file =~ m#^/# or $file = "$projectroot/$path/$file";
1539 $mime = mimetype_guess_file
($filename, $file);
1541 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1545 sub git_blob_plain_mimetype
{
1547 my $filename = shift;
1550 return $default_blob_plain_mimetype unless $fd;
1553 my $mime = mimetype_guess
($filename);
1554 $mime and return $mime;
1558 return 'text/plain' .
1559 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
1560 } elsif (! $filename) {
1561 return 'application/octet-stream';
1562 } elsif ($filename =~ m/\.png$/i) {
1564 } elsif ($filename =~ m/\.gif$/i) {
1566 } elsif ($filename =~ m/\.jpe?g$/i) {
1567 return 'image/jpeg';
1569 return 'application/octet-stream';
1573 sub git_blob_plain
{
1574 open my $fd, "-|", "$gitbin/git-cat-file blob $hash" or return;
1575 my $type = git_blob_plain_mimetype
($fd, $file_name);
1577 # save as filename, even when no $file_name is given
1578 my $save_as = "$hash";
1579 if (defined $file_name) {
1580 $save_as = $file_name;
1581 } elsif ($type =~ m/^text\//) {
1585 print $cgi->header(-type
=> "$type", '-content-disposition' => "inline; filename=\"$save_as\"");
1587 binmode STDOUT
, ':raw';
1589 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
1595 if (!defined $hash) {
1596 $hash = git_read_head
($project);
1597 if (defined $file_name) {
1598 my $base = $hash_base || $hash;
1599 $hash = git_get_hash_by_path
($base, $file_name, "tree");
1601 if (!defined $hash_base) {
1606 open my $fd, "-|", "$gitbin/git-ls-tree -z $hash" or die_error
(undef, "Open git-ls-tree failed.");
1607 chomp (my (@entries) = <$fd>);
1608 close $fd or die_error
(undef, "Reading tree failed.");
1611 my $refs = read_info_ref
();
1613 if (defined $refs->{$hash_base}) {
1614 $ref = " <span class=\"tag\">" . esc_html
($refs->{$hash_base}) . "</span>";
1619 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
1620 $base_key = ";hb=$hash_base";
1621 print "<div class=\"page_nav\">\n" .
1622 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1623 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash_base")}, "shortlog") .
1624 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash_base")}, "log") .
1625 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base")}, "commit") .
1626 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
1631 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html
($co{'title'}) . $ref) . "\n" .
1634 print "<div class=\"page_nav\">\n";
1635 print "<br/><br/></div>\n";
1636 print "<div class=\"title\">$hash</div>\n";
1638 if (defined $file_name) {
1639 $base = esc_html
("$file_name/");
1640 print "<div class=\"page_path\"><b>/" . esc_html
($file_name) . "</b></div>\n";
1642 print "<div class=\"page_path\"><b>/</b></div>\n";
1644 print "<div class=\"page_body\">\n";
1645 print "<table cellspacing=\"0\">\n";
1647 foreach my $line (@entries) {
1648 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1649 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1653 my $t_name = validate_input
($4);
1655 print "<tr class=\"dark\">\n";
1657 print "<tr class=\"light\">\n";
1660 print "<td class=\"mode\">" . mode_str
($t_mode) . "</td>\n";
1661 if ($t_type eq "blob") {
1662 print "<td class=\"list\">" .
1663 $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)) .
1665 "<td class=\"link\">" .
1666 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name")}, "blob") .
1667 # " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$t_hash$base_key;f=$base$t_name")}, "blame") .
1668 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;h=$hash_base;f=$base$t_name")}, "history") .
1670 } elsif ($t_type eq "tree") {
1671 print "<td class=\"list\">" .
1672 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, esc_html
($t_name)) .
1674 "<td class=\"link\">" .
1675 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, "tree") .
1680 print "</table>\n" .
1686 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
1687 open my $fd, "-|", "$gitbin/git-rev-list --max-count=150 " . git_read_head
($project) or die_error
(undef, "Open failed.");
1688 my (@revlist) = map { chomp; $_ } <$fd>;
1689 close $fd or die_error
(undef, "Reading rev-list failed.");
1690 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
1691 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1692 "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
1693 print "<channel>\n";
1694 print "<title>$project</title>\n".
1695 "<link>" . esc_html
("$my_url?p=$project;a=summary") . "</link>\n".
1696 "<description>$project log</description>\n".
1697 "<language>en</language>\n";
1699 for (my $i = 0; $i <= $#revlist; $i++) {
1700 my $commit = $revlist[$i];
1701 my %co = git_read_commit
($commit);
1702 # we read 150, we always show 30 and the ones more recent than 48 hours
1703 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
1706 my %cd = date_str
($co{'committer_epoch'});
1707 open $fd, "-|", "$gitbin/git-diff-tree -r $co{'parent'} $co{'id'}" or next;
1708 my @difftree = map { chomp; $_ } <$fd>;
1712 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
1714 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
1715 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
1716 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
1717 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
1718 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
1719 "<content:encoded>" .
1721 my $comment = $co{'comment'};
1722 foreach my $line (@
$comment) {
1723 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
1724 print "$line<br/>\n";
1727 foreach my $line (@difftree) {
1728 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
1731 my $file = validate_input
(unquote
($7));
1732 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
1733 print "$file<br/>\n";
1736 "</content:encoded>\n" .
1739 print "</channel></rss>";
1743 my @list = git_read_projects
();
1745 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
1746 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
1747 "<opml version=\"1.0\">\n".
1749 " <title>Git OPML Export</title>\n".
1752 "<outline text=\"git RSS feeds\">\n";
1754 foreach my $pr (@list) {
1756 my $head = git_read_head
($proj{'path'});
1757 if (!defined $head) {
1760 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
1761 my %co = git_read_commit
($head);
1766 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
1767 my $rss = "$my_url?p=$proj{'path'};a=rss";
1768 my $html = "$my_url?p=$proj{'path'};a=summary";
1769 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
1771 print "</outline>\n".
1777 my $head = git_read_head
($project);
1778 if (!defined $hash) {
1781 if (!defined $page) {
1784 my $refs = read_info_ref
();
1786 print "<div class=\"page_nav\">\n";
1787 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1788 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash")}, "shortlog") .
1790 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash")}, "commit") .
1791 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
1792 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$hash;hb=$hash")}, "tree") . "<br/>\n";
1794 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
1795 open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error
(undef, "Open failed.");
1796 my (@revlist) = map { chomp; $_ } <$fd>;
1799 if ($hash ne $head || $page) {
1800 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "HEAD");
1806 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash;pg=" . ($page-1)), -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1808 print " ⋅ prev";
1810 if ($#revlist >= (100 * ($page+1)-1)) {
1812 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash;pg=" . ($page+1)), -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1814 print " ⋅ next";
1820 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary"), -class => "title"}, " ") .
1822 my %co = git_read_commit
($hash);
1823 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
1825 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
1826 my $commit = $revlist[$i];
1828 if (defined $refs->{$commit}) {
1829 $ref = " <span class=\"tag\">" . esc_html
($refs->{$commit}) . "</span>";
1831 my %co = git_read_commit
($commit);
1833 my %ad = date_str
($co{'author_epoch'});
1835 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "title"},
1836 "<span class=\"age\">$co{'age_string'}</span>" . esc_html
($co{'title'}) . $ref) . "\n";
1838 print "<div class=\"title_text\">\n" .
1839 "<div class=\"log_link\">\n" .
1840 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
1841 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1844 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
1846 "<div class=\"log_body\">\n";
1847 my $comment = $co{'comment'};
1849 foreach my $line (@
$comment) {
1850 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1861 print format_log_line_html
($line) . "<br/>\n";
1872 my %co = git_read_commit
($hash);
1874 die_error
(undef, "Unknown commit object.");
1876 my %ad = date_str
($co{'author_epoch'}, $co{'author_tz'});
1877 my %cd = date_str
($co{'committer_epoch'}, $co{'committer_tz'});
1881 my $parent = $co{'parent'};
1882 if (!defined $parent) {
1886 open my $fd, "-|", "$gitbin/git-diff-tree -r -M $root $parent $hash" or die_error
(undef, "Open failed.");
1887 @difftree = map { chomp; $_ } <$fd>;
1888 close $fd or die_error
(undef, "Reading diff-tree failed.");
1890 # non-textual hash id's can be cached
1892 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
1895 my $refs = read_info_ref
();
1897 if (defined $refs->{$co{'id'}}) {
1898 $ref = " <span class=\"tag\">" . esc_html
($refs->{$co{'id'}}) . "</span>";
1900 git_header_html
(undef, $expires);
1901 print "<div class=\"page_nav\">\n" .
1902 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
1903 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash")}, "shortlog") .
1904 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash")}, "log") .
1906 if (defined $co{'parent'}) {
1907 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash")}, "commitdiff");
1909 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") . "\n" .
1910 "<br/><br/></div>\n";
1911 if (defined $co{'parent'}) {
1913 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash"), -class => "title"}, esc_html
($co{'title'}) . $ref) . "\n" .
1917 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash"), -class => "title"}, esc_html
($co{'title'})) . "\n" .
1920 print "<div class=\"title_text\">\n" .
1921 "<table cellspacing=\"0\">\n";
1922 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
1924 "<td></td><td> $ad{'rfc2822'}";
1925 if ($ad{'hour_local'} < 6) {
1926 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1928 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1932 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
1933 print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
1934 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
1937 "<td class=\"sha1\">" .
1938 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash"), class => "list"}, $co{'tree'}) .
1940 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
1943 my $parents = $co{'parents'};
1944 foreach my $par (@
$parents) {
1947 "<td class=\"sha1\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$par"), class => "list"}, $par) . "</td>" .
1948 "<td class=\"link\">" .
1949 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$par")}, "commit") .
1950 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash;hp=$par")}, "commitdiff") .
1956 print "<div class=\"page_body\">\n";
1957 my $comment = $co{'comment'};
1960 foreach my $line (@
$comment) {
1961 # print only one empty line
1963 if ($empty || $signed) {
1970 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1972 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1975 print format_log_line_html
($line) . "<br/>\n";
1979 print "<div class=\"list_head\">\n";
1980 if ($#difftree > 10) {
1981 print(($#difftree + 1) . " files changed:\n");
1984 print "<table class=\"diff_tree\">\n";
1986 foreach my $line (@difftree) {
1987 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1988 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1989 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
1997 my $similarity = $6;
1998 my $file = validate_input
(unquote
($7));
2000 print "<tr class=\"dark\">\n";
2002 print "<tr class=\"light\">\n";
2005 if ($status eq "A") {
2007 if (S_ISREG
(oct $to_mode)) {
2008 $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
2011 $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" .
2012 "<td><span class=\"file_status new\">[new " . file_type
($to_mode) . "$mode_chng]</span></td>\n" .
2013 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob") . "</td>\n";
2014 } elsif ($status eq "D") {
2016 $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" .
2017 "<td><span class=\"file_status deleted\">[deleted " . file_type
($from_mode). "]</span></td>\n" .
2018 "<td class=\"link\">" .
2019 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, "blob") .
2020 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;h=$hash;f=$file")}, "history") .
2022 } elsif ($status eq "M" || $status eq "T") {
2023 my $mode_chnge = "";
2024 if ($from_mode != $to_mode) {
2025 $mode_chnge = " <span class=\"file_status mode_chnge\">[changed";
2026 if (((oct $from_mode) & S_IFMT
) != ((oct $to_mode) & S_IFMT
)) {
2027 $mode_chnge .= " from " . file_type
($from_mode) . " to " . file_type
($to_mode);
2029 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
2030 if (S_ISREG
($from_mode) && S_ISREG
($to_mode)) {
2031 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
2032 } elsif (S_ISREG
($to_mode)) {
2033 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
2036 $mode_chnge .= "]</span>\n";
2039 if ($to_id ne $from_id) {
2040 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file"), -class => "list"}, esc_html
($file));
2042 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file"), -class => "list"}, esc_html
($file));
2045 "<td>$mode_chnge</td>\n" .
2046 "<td class=\"link\">";
2047 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob");
2048 if ($to_id ne $from_id) {
2049 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file")}, "diff");
2051 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;h=$hash;f=$file")}, "history") . "\n";
2053 } elsif ($status eq "R") {
2054 my ($from_file, $to_file) = split "\t", $file;
2056 if ($from_mode != $to_mode) {
2057 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
2060 $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" .
2061 "<td><span class=\"file_status moved\">[moved from " .
2062 $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)) .
2063 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
2064 "<td class=\"link\">" .
2065 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file")}, "blob");
2066 if ($to_id ne $from_id) {
2067 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file")}, "diff");
2078 mkdir($git_temp, 0700);
2080 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
2081 print "<div class=\"page_nav\">\n" .
2082 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
2083 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
2084 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
2085 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base")}, "commit") .
2086 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash_base")}, "commitdiff") .
2087 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash_base")}, "tree") .
2089 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff_plain;h=$hash;hp=$hash_parent")}, "plain") .
2092 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_base"), -class => "title"}, esc_html
($co{'title'})) . "\n" .
2095 print "<div class=\"page_nav\">\n" .
2096 "<br/><br/></div>\n" .
2097 "<div class=\"title\">$hash vs $hash_parent</div>\n";
2099 if (defined $file_name) {
2100 print "<div class=\"page_path\"><b>/" . esc_html
($file_name) . "</b></div>\n";
2102 print "<div class=\"page_body\">\n" .
2103 "<div class=\"diff_info\">blob:" .
2104 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name")}, $hash_parent) .
2106 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, $hash) .
2108 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
2113 sub git_blobdiff_plain
{
2114 mkdir($git_temp, 0700);
2115 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8');
2116 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
2119 sub git_commitdiff
{
2120 mkdir($git_temp, 0700);
2121 my %co = git_read_commit
($hash);
2123 die_error
(undef, "Unknown commit object.");
2125 if (!defined $hash_parent) {
2126 $hash_parent = $co{'parent'};
2128 open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error
(undef, "Open failed.");
2129 my (@difftree) = map { chomp; $_ } <$fd>;
2130 close $fd or die_error
(undef, "Reading diff-tree failed.");
2132 # non-textual hash id's can be cached
2134 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2137 my $refs = read_info_ref
();
2139 if (defined $refs->{$co{'id'}}) {
2140 $ref = " <span class=\"tag\">" . esc_html
($refs->{$co{'id'}}) . "</span>";
2142 git_header_html
(undef, $expires);
2143 print "<div class=\"page_nav\">\n" .
2144 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
2145 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash")}, "shortlog") .
2146 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash")}, "log") .
2147 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash")}, "commit") .
2149 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") . "<br/>\n";
2150 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent")}, "plain") . "\n" .
2153 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html
($co{'title'}) . $ref) . "\n" .
2155 print "<div class=\"page_body\">\n";
2156 my $comment = $co{'comment'};
2159 my @log = @
$comment;
2160 # remove first and empty lines after that
2162 while (defined $log[0] && $log[0] eq "") {
2165 foreach my $line (@log) {
2166 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2177 print format_log_line_html
($line) . "<br/>\n";
2180 foreach my $line (@difftree) {
2181 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2182 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2183 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2189 my $file = validate_input
(unquote
($6));
2190 if ($status eq "A") {
2191 print "<div class=\"diff_info\">" . file_type
($to_mode) . ":" .
2192 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id) . "(new)" .
2194 git_diff_print
(undef, "/dev/null", $to_id, "b/$file");
2195 } elsif ($status eq "D") {
2196 print "<div class=\"diff_info\">" . file_type
($from_mode) . ":" .
2197 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) . "(deleted)" .
2199 git_diff_print
($from_id, "a/$file", undef, "/dev/null");
2200 } elsif ($status eq "M") {
2201 if ($from_id ne $to_id) {
2202 print "<div class=\"diff_info\">" .
2203 file_type
($from_mode) . ":" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) .
2205 file_type
($to_mode) . ":" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id);
2207 git_diff_print
($from_id, "a/$file", $to_id, "b/$file");
2216 sub git_commitdiff_plain
{
2217 mkdir($git_temp, 0700);
2218 open my $fd, "-|", "$gitbin/git-diff-tree -r $hash_parent $hash" or die_error
(undef, "Open failed.");
2219 my (@difftree) = map { chomp; $_ } <$fd>;
2220 close $fd or die_error
(undef, "Reading diff-tree failed.");
2222 # try to figure out the next tag after this commit
2224 my $refs = read_info_ref
("tags");
2225 open $fd, "-|", "$gitbin/git-rev-list HEAD";
2226 chomp (my (@commits) = <$fd>);
2228 foreach my $commit (@commits) {
2229 if (defined $refs->{$commit}) {
2230 $tagname = $refs->{$commit}
2232 if ($commit eq $hash) {
2237 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8', '-content-disposition' => "inline; filename=\"git-$hash.patch\"");
2238 my %co = git_read_commit
($hash);
2239 my %ad = date_str
($co{'author_epoch'}, $co{'author_tz'});
2240 my $comment = $co{'comment'};
2241 print "From: $co{'author'}\n" .
2242 "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
2243 "Subject: $co{'title'}\n";
2244 if (defined $tagname) {
2245 print "X-Git-Tag: $tagname\n";
2247 print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
2250 foreach my $line (@
$comment) {;
2255 foreach my $line (@difftree) {
2256 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2261 if ($status eq "A") {
2262 git_diff_print
(undef, "/dev/null", $to_id, "b/$file", "plain");
2263 } elsif ($status eq "D") {
2264 git_diff_print
($from_id, "a/$file", undef, "/dev/null", "plain");
2265 } elsif ($status eq "M") {
2266 git_diff_print
($from_id, "a/$file", $to_id, "b/$file", "plain");
2272 if (!defined $hash) {
2273 $hash = git_read_head
($project);
2275 my %co = git_read_commit
($hash);
2277 die_error
(undef, "Unknown commit object.");
2279 my $refs = read_info_ref
();
2281 print "<div class=\"page_nav\">\n" .
2282 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
2283 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
2284 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log")}, "log") .
2285 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash")}, "commit") .
2286 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2287 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
2291 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html
($co{'title'})) . "\n" .
2293 print "<div class=\"page_path\"><b>/" . esc_html
($file_name) . "</b><br/></div>\n";
2295 open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin -- \'$file_name\'";
2297 print "<table cellspacing=\"0\">\n";
2299 while (my $line = <$fd>) {
2300 if ($line =~ m/^([0-9a-fA-F]{40})/){
2304 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/ && (defined $commit)) {
2305 my %co = git_read_commit
($commit);
2310 if (defined $refs->{$commit}) {
2311 $ref = " <span class=\"tag\">" . esc_html
($refs->{$commit}) . "</span>";
2314 print "<tr class=\"dark\">\n";
2316 print "<tr class=\"light\">\n";
2319 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2320 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2321 "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list"}, "<b>" .
2322 esc_html
(chop_str
($co{'title'}, 50)) . "$ref</b>") . "</td>\n" .
2323 "<td class=\"link\">" .
2324 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
2325 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2326 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;hb=$commit;f=$file_name")}, "blob");
2327 my $blob = git_get_hash_by_path
($hash, $file_name);
2328 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2329 if (defined $blob && defined $blob_parent && $blob ne $blob_parent) {
2331 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=$file_name")},
2345 if (!defined $searchtext) {
2346 die_error
("", "Text field empty.");
2348 if (!defined $hash) {
2349 $hash = git_read_head
($project);
2351 my %co = git_read_commit
($hash);
2353 die_error
(undef, "Unknown commit object.");
2355 # pickaxe may take all resources of your box and run for several minutes
2356 # with every query - so decide by yourself how public you make this feature :)
2357 my $commit_search = 1;
2358 my $author_search = 0;
2359 my $committer_search = 0;
2360 my $pickaxe_search = 0;
2361 if ($searchtext =~ s/^author\\://i) {
2363 } elsif ($searchtext =~ s/^committer\\://i) {
2364 $committer_search = 1;
2365 } elsif ($searchtext =~ s/^pickaxe\\://i) {
2367 $pickaxe_search = 1;
2370 print "<div class=\"page_nav\">\n" .
2371 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary;h=$hash")}, "summary") .
2372 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "shortlog") .
2373 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash")}, "log") .
2374 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash")}, "commit") .
2375 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2376 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
2381 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash"), -class => "title"}, esc_html
($co{'title'})) . "\n" .
2383 print "<table cellspacing=\"0\">\n";
2385 if ($commit_search) {
2387 open my $fd, "-|", "$gitbin/git-rev-list --header --parents $hash" or next;
2388 while (my $commit_text = <$fd>) {
2389 if (!grep m/$searchtext/i, $commit_text) {
2392 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
2395 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
2398 my @commit_lines = split "\n", $commit_text;
2399 my %co = git_read_commit
(undef, \
@commit_lines);
2404 print "<tr class=\"dark\">\n";
2406 print "<tr class=\"light\">\n";
2409 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2410 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2412 $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/>");
2413 my $comment = $co{'comment'};
2414 foreach my $line (@
$comment) {
2415 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2416 my $lead = esc_html
($1) || "";
2417 $lead = chop_str
($lead, 30, 10);
2418 my $match = esc_html
($2) || "";
2419 my $trail = esc_html
($3) || "";
2420 $trail = chop_str
($trail, 30, 10);
2421 my $text = "$lead<span class=\"match\">$match</span>$trail";
2422 print chop_str
($text, 80, 5) . "<br/>\n";
2426 "<td class=\"link\">" .
2427 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2428 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2435 if ($pickaxe_search) {
2437 open my $fd, "-|", "$gitbin/git-rev-list $hash | $gitbin/git-diff-tree -r --stdin -S\'$searchtext\'";
2440 while (my $line = <$fd>) {
2441 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2444 $set{'from_id'} = $3;
2446 $set{'id'} = $set{'to_id'};
2447 if ($set{'id'} =~ m/0{40}/) {
2448 $set{'id'} = $set{'from_id'};
2450 if ($set{'id'} =~ m/0{40}/) {
2454 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
2457 print "<tr class=\"dark\">\n";
2459 print "<tr class=\"light\">\n";
2462 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2463 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2465 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" .
2466 esc_html
(chop_str
($co{'title'}, 50)) . "</b><br/>");
2467 while (my $setref = shift @files) {
2469 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}"), class => "list"},
2470 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
2474 "<td class=\"link\">" .
2475 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2476 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2480 %co = git_read_commit
($1);
2490 my $head = git_read_head
($project);
2491 if (!defined $hash) {
2494 if (!defined $page) {
2497 my $refs = read_info_ref
();
2499 print "<div class=\"page_nav\">\n" .
2500 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, "summary") .
2502 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$hash")}, "log") .
2503 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash")}, "commit") .
2504 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash")}, "commitdiff") .
2505 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$hash;hb=$hash")}, "tree") . "<br/>\n";
2507 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2508 open my $fd, "-|", "$gitbin/git-rev-list $limit $hash" or die_error
(undef, "Open failed.");
2509 my (@revlist) = map { chomp; $_ } <$fd>;
2512 if ($hash ne $head || $page) {
2513 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "HEAD");
2519 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash;pg=" . ($page-1)), -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
2521 print " ⋅ prev";
2523 if ($#revlist >= (100 * ($page+1)-1)) {
2525 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)), -accesskey
=> "n", -title
=> "Alt-n"}, "next");
2527 print " ⋅ next";
2532 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary"), -class => "title"}, " ") .
2534 print "<table cellspacing=\"0\">\n";
2536 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2537 my $commit = $revlist[$i];
2539 if (defined $refs->{$commit}) {
2540 $ref = " <span class=\"tag\">" . esc_html
($refs->{$commit}) . "</span>";
2542 my %co = git_read_commit
($commit);
2543 my %ad = date_str
($co{'author_epoch'});
2545 print "<tr class=\"dark\">\n";
2547 print "<tr class=\"light\">\n";
2550 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2551 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
2553 if (length($co{'title_short'}) < length($co{'title'})) {
2554 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list", -title
=> "$co{'title'}"},
2555 "<b>" . esc_html
($co{'title_short'}) . "$ref</b>");
2557 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list"},
2558 "<b>" . esc_html
($co{'title_short'}) . "$ref</b>");
2561 "<td class=\"link\">" .
2562 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
2563 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2567 if ($#revlist >= (100 * ($page+1)-1)) {
2570 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)), -title
=> "Alt-n"}, "next") .