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 our $my_url = $cgi->url();
22 our $my_uri = $cgi->url(-absolute
=> 1);
25 # core git executable to use
26 # this can just be "git" if your webserver has a sensible PATH
27 our $GIT = "/usr/bin/git";
29 # absolute fs-path which will be prepended to the project path
30 #our $projectroot = "/pub/scm";
31 our $projectroot = "/home/kay/public_html/pub/scm";
33 # version of the core git binary
34 our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown";
36 # location for temporary files needed for diffs
37 our $git_temp = "/tmp/gitweb";
39 mkdir($git_temp, 0700) || die_error
("Couldn't mkdir $git_temp");
42 # target of the home link on top of all pages
43 our $home_link = $my_uri;
45 # name of your site or organization to appear in page titles
46 # replace this with something more descriptive for clearer bookmarks
47 our $site_name = $ENV{'SERVER_NAME'} || "Untitled";
49 # html text to include at home page
50 our $home_text = "indextext.html";
52 # URI of default stylesheet
53 our $stylesheet = "gitweb.css";
55 # source of projects list
56 #our $projects_list = $projectroot;
57 our $projects_list = "index/index.aux";
59 # default blob_plain mimetype and default charset for text/plain blob
60 our $default_blob_plain_mimetype = 'text/plain';
61 our $default_text_plain_charset = undef;
63 # file to use for guessing MIME types before trying /etc/mime.types
64 # (relative to the current git repository)
65 our $mimetypes_file = undef;
67 # input validation and dispatch
68 our $action = $cgi->param('a');
69 if (defined $action) {
70 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
72 die_error
(undef, "Invalid action parameter.");
74 if ($action eq "git-logo.png") {
77 } elsif ($action eq "opml") {
83 our $order = $cgi->param('o');
85 if ($order =~ m/[^0-9a-zA-Z_]/) {
87 die_error
(undef, "Invalid order parameter.");
91 our $project = ($cgi->param('p') || $ENV{'PATH_INFO'});
92 if (defined $project) {
93 $project =~ s
|^/||; $project =~ s|/$||;
94 $project = validate_input
($project);
95 if (!defined($project)) {
96 die_error
(undef, "Invalid project parameter.");
98 if (!(-d
"$projectroot/$project")) {
100 die_error
(undef, "No such directory.");
102 if (!(-e
"$projectroot/$project/HEAD")) {
104 die_error
(undef, "No such project.");
106 $rss_link = "<link rel=\"alternate\" title=\"" . esc_param
($project) . " log\" href=\"" .
107 "$my_uri?" . esc_param
("p=$project;a=rss") . "\" type=\"application/rss+xml\"/>";
108 $ENV{'GIT_DIR'} = "$projectroot/$project";
114 our $file_name = $cgi->param('f');
115 if (defined $file_name) {
116 $file_name = validate_input
($file_name);
117 if (!defined($file_name)) {
118 die_error
(undef, "Invalid file parameter.");
122 our $hash = $cgi->param('h');
124 $hash = validate_input
($hash);
125 if (!defined($hash)) {
126 die_error
(undef, "Invalid hash parameter.");
130 our $hash_parent = $cgi->param('hp');
131 if (defined $hash_parent) {
132 $hash_parent = validate_input
($hash_parent);
133 if (!defined($hash_parent)) {
134 die_error
(undef, "Invalid hash parent parameter.");
138 our $hash_base = $cgi->param('hb');
139 if (defined $hash_base) {
140 $hash_base = validate_input
($hash_base);
141 if (!defined($hash_base)) {
142 die_error
(undef, "Invalid hash base parameter.");
146 our $page = $cgi->param('pg');
148 if ($page =~ m/[^0-9]$/) {
150 die_error
(undef, "Invalid page parameter.");
154 our $searchtext = $cgi->param('s');
155 if (defined $searchtext) {
156 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\
@ ]/) {
158 die_error
(undef, "Invalid search parameter.");
160 $searchtext = quotemeta $searchtext;
165 "blame" => \
&git_blame2
,
166 "blobdiff" => \
&git_blobdiff
,
167 "blobdiff_plain" => \
&git_blobdiff_plain
,
168 "blob" => \
&git_blob
,
169 "blob_plain" => \
&git_blob_plain
,
170 "commitdiff" => \
&git_commitdiff
,
171 "commitdiff_plain" => \
&git_commitdiff_plain
,
172 "commit" => \
&git_commit
,
173 "heads" => \
&git_heads
,
174 "history" => \
&git_history
,
177 "search" => \
&git_search
,
178 "shortlog" => \
&git_shortlog
,
179 "summary" => \
&git_summary
,
181 "tags" => \
&git_tags
,
182 "tree" => \
&git_tree
,
185 $action = 'summary' if (!defined($action));
186 if (!defined($actions{$action})) {
188 die_error
(undef, "Unknown action.");
190 $actions{$action}->();
193 ## ======================================================================
194 ## validation, quoting/unquoting and escaping
199 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
202 if ($input =~ m/(^|\/)(|\
.|\
.\
.)($|\
/)/) {
205 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\
-\
+\#\
~\
%]/) {
211 # quote unsafe chars, but keep the slash, even when it's not
212 # correct, but quoted slashes look too horrible in bookmarks
215 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
221 # replace invalid utf8 character with SUBSTITUTION sequence
224 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
225 $str = escapeHTML
($str);
226 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
230 # git may return quoted and escaped filenames
233 if ($str =~ m/^"(.*)"$/) {
235 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
240 ## ----------------------------------------------------------------------
241 ## HTML aware string manipulation
246 my $add_len = shift || 10;
248 # allow only $len chars, but don't cut a word if it would fit in $add_len
249 # if it doesn't fit, cut it if it's still longer than the dots we would add
250 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@]{0,$add_len})(.*)/;
253 if (length($tail) > 4) {
255 $body =~ s/&[^;]*$//; # remove chopped character entities
260 ## ----------------------------------------------------------------------
261 ## functions returning short strings
263 # CSS class for given age value (in seconds)
267 if ($age < 60*60*2) {
269 } elsif ($age < 60*60*24*2) {
276 # convert age in seconds to "nn units ago" string
281 if ($age > 60*60*24*365*2) {
282 $age_str = (int $age/60/60/24/365);
283 $age_str .= " years ago";
284 } elsif ($age > 60*60*24*(365/12)*2) {
285 $age_str = int $age/60/60/24/(365/12);
286 $age_str .= " months ago";
287 } elsif ($age > 60*60*24*7*2) {
288 $age_str = int $age/60/60/24/7;
289 $age_str .= " weeks ago";
290 } elsif ($age > 60*60*24*2) {
291 $age_str = int $age/60/60/24;
292 $age_str .= " days ago";
293 } elsif ($age > 60*60*2) {
294 $age_str = int $age/60/60;
295 $age_str .= " hours ago";
296 } elsif ($age > 60*2) {
297 $age_str = int $age/60;
298 $age_str .= " min ago";
301 $age_str .= " sec ago";
303 $age_str .= " right now";
308 # convert file mode in octal to symbolic file mode string
310 my $mode = oct shift;
312 if (S_ISDIR
($mode & S_IFMT
)) {
314 } elsif (S_ISLNK
($mode)) {
316 } elsif (S_ISREG
($mode)) {
317 # git cares only about the executable bit
318 if ($mode & S_IXUSR
) {
328 # convert file mode in octal to file type string
330 my $mode = oct shift;
332 if (S_ISDIR
($mode & S_IFMT
)) {
334 } elsif (S_ISLNK
($mode)) {
336 } elsif (S_ISREG
($mode)) {
343 ## ----------------------------------------------------------------------
344 ## functions returning short HTML fragments, or transforming HTML fragments
345 ## which don't beling to other sections
347 # format line of commit message or tag comment
348 sub format_log_line_html
{
351 $line = esc_html
($line);
352 $line =~ s/ / /g;
353 if ($line =~ m/([0-9a-fA-F]{40})/) {
355 if (git_get_type
($hash_text) eq "commit") {
356 my $link = $cgi->a({-class => "text", -href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_text")}, $hash_text);
357 $line =~ s/$hash_text/$link/;
363 # format marker of refs pointing to given object
364 sub git_get_referencing
{
365 my ($refs, $id) = @_;
367 if (defined $refs->{$id}) {
368 return ' <span class="tag">' . esc_html
($refs->{$id}) . '</span>';
374 ## ----------------------------------------------------------------------
375 ## git utility subroutines, invoking git commands
377 # get HEAD ref of given project as hash
380 my $oENV = $ENV{'GIT_DIR'};
382 $ENV{'GIT_DIR'} = "$projectroot/$project";
383 if (open my $fd, "-|", $GIT, "rev-parse", "--verify", "HEAD") {
386 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
391 $ENV{'GIT_DIR'} = $oENV;
396 # get type of given object
400 open my $fd, "-|", $GIT, "cat-file", '-t', $hash or return;
407 sub git_get_project_config
{
410 return unless ($key);
411 $key =~ s/^gitweb\.//;
412 return if ($key =~ m/\W/);
414 my $val = qx($GIT repo-config --get gitweb.$key);
418 sub git_get_project_config_bool
{
419 my $val = git_get_project_config
(@_);
420 if ($val and $val =~ m/true|yes|on/) {
423 return; # implicit false
426 # get hash of given path at given ref
427 sub git_get_hash_by_path
{
429 my $path = shift || return undef;
433 open my $fd, "-|", $GIT, "ls-tree", $base, "--", $path
434 or die_error
(undef, "Open git-ls-tree failed.");
436 close $fd or return undef;
438 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
439 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
443 ## ......................................................................
444 ## git utility functions, directly accessing git repository
446 # assumes that PATH is not symref
450 open my $fd, "$projectroot/$path" or return undef;
454 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
459 sub git_read_description
{
462 open my $fd, "$projectroot/$path/description" or return undef;
469 sub git_read_projects
{
472 if (-d
$projects_list) {
473 # search in directory
474 my $dir = $projects_list;
475 opendir my ($dh), $dir or return undef;
476 while (my $dir = readdir($dh)) {
477 if (-e
"$projectroot/$dir/HEAD") {
485 } elsif (-f
$projects_list) {
486 # read from file(url-encoded):
487 # 'git%2Fgit.git Linus+Torvalds'
488 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
489 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
490 open my ($fd), $projects_list or return undef;
491 while (my $line = <$fd>) {
493 my ($path, $owner) = split ' ', $line;
494 $path = unescape
($path);
495 $owner = unescape
($owner);
496 if (!defined $path) {
499 if (-e
"$projectroot/$path/HEAD") {
502 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
509 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
514 my $type = shift || "";
516 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
517 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
518 open my $fd, "$projectroot/$project/info/refs" or return;
519 while (my $line = <$fd>) {
521 # attention: for $type == "" it saves only last path part of ref name
522 # e.g. from 'refs/heads/jn/gitweb' it would leave only 'gitweb'
523 if ($line =~ m/^([0-9a-fA-F]{40})\t.*$type\/([^\
^]+)/) {
524 if (defined $refs{$1}) {
525 $refs{$1} .= " / $2";
535 ## ----------------------------------------------------------------------
536 ## parse to hash functions
540 my $tz = shift || "-0000";
543 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
544 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
545 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
546 $date{'hour'} = $hour;
547 $date{'minute'} = $min;
548 $date{'mday'} = $mday;
549 $date{'day'} = $days[$wday];
550 $date{'month'} = $months[$mon];
551 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
552 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
554 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
555 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
556 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
557 $date{'hour_local'} = $hour;
558 $date{'minute_local'} = $min;
559 $date{'tz_local'} = $tz;
568 open my $fd, "-|", $GIT, "cat-file", "tag", $tag_id or return;
569 $tag{'id'} = $tag_id;
570 while (my $line = <$fd>) {
572 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
574 } elsif ($line =~ m/^type (.+)$/) {
576 } elsif ($line =~ m/^tag (.+)$/) {
578 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
582 } elsif ($line =~ m/--BEGIN/) {
583 push @comment, $line;
585 } elsif ($line eq "") {
589 push @comment, <$fd>;
590 $tag{'comment'} = \
@comment;
592 if (!defined $tag{'name'}) {
598 sub git_read_commit
{
599 my $commit_id = shift;
600 my $commit_text = shift;
605 if (defined $commit_text) {
606 @commit_lines = @$commit_text;
609 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", "--max-count=1", $commit_id or return;
610 @commit_lines = split '\n', <$fd>;
615 my $header = shift @commit_lines;
616 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
619 ($co{'id'}, my @parents) = split ' ', $header;
620 $co{'parents'} = \
@parents;
621 $co{'parent'} = $parents[0];
622 while (my $line = shift @commit_lines) {
623 last if $line eq "\n";
624 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
626 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
628 $co{'author_epoch'} = $2;
629 $co{'author_tz'} = $3;
630 if ($co{'author'} =~ m/^([^<]+) </) {
631 $co{'author_name'} = $1;
633 $co{'author_name'} = $co{'author'};
635 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
636 $co{'committer'} = $1;
637 $co{'committer_epoch'} = $2;
638 $co{'committer_tz'} = $3;
639 $co{'committer_name'} = $co{'committer'};
640 $co{'committer_name'} =~ s/ <.*//;
643 if (!defined $co{'tree'}) {
647 foreach my $title (@commit_lines) {
650 $co{'title'} = chop_str
($title, 80, 5);
651 # remove leading stuff of merges to make the interesting part visible
652 if (length($title) > 50) {
653 $title =~ s/^Automatic //;
654 $title =~ s/^merge (of|with) /Merge ... /i;
655 if (length($title) > 50) {
656 $title =~ s/(http|rsync):\/\///;
658 if (length($title) > 50) {
659 $title =~ s/(master|www|rsync)\.//;
661 if (length($title) > 50) {
662 $title =~ s/kernel.org:?//;
664 if (length($title) > 50) {
665 $title =~ s/\/pub\/scm//;
668 $co{'title_short'} = chop_str
($title, 50, 5);
672 # remove added spaces
673 foreach my $line (@commit_lines) {
676 $co{'comment'} = \
@commit_lines;
678 my $age = time - $co{'committer_epoch'};
680 $co{'age_string'} = age_string
($age);
681 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
682 if ($age > 60*60*24*7*2) {
683 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
684 $co{'age_string_age'} = $co{'age_string'};
686 $co{'age_string_date'} = $co{'age_string'};
687 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
692 ## ......................................................................
693 ## parse to array of hashes functions
700 opendir my $dh, "$projectroot/$project/$ref_dir";
701 while (my $dir = readdir($dh)) {
702 if ($dir =~ m/^\./) {
705 if (-d
"$projectroot/$project/$ref_dir/$dir") {
706 opendir my $dh2, "$projectroot/$project/$ref_dir/$dir";
707 my @subdirs = grep !m/^\./, readdir $dh2;
709 foreach my $subdir (@subdirs) {
710 push @refs, "$dir/$subdir"
717 foreach my $ref_file (@refs) {
718 my $ref_id = git_read_hash
("$project/$ref_dir/$ref_file");
719 my $type = git_get_type
($ref_id) || next;
722 $ref_item{'type'} = $type;
723 $ref_item{'id'} = $ref_id;
724 $ref_item{'epoch'} = 0;
725 $ref_item{'age'} = "unknown";
726 if ($type eq "tag") {
727 my %tag = git_read_tag
($ref_id);
728 $ref_item{'comment'} = $tag{'comment'};
729 if ($tag{'type'} eq "commit") {
730 %co = git_read_commit
($tag{'object'});
731 $ref_item{'epoch'} = $co{'committer_epoch'};
732 $ref_item{'age'} = $co{'age_string'};
733 } elsif (defined($tag{'epoch'})) {
734 my $age = time - $tag{'epoch'};
735 $ref_item{'epoch'} = $tag{'epoch'};
736 $ref_item{'age'} = age_string
($age);
738 $ref_item{'reftype'} = $tag{'type'};
739 $ref_item{'name'} = $tag{'name'};
740 $ref_item{'refid'} = $tag{'object'};
741 } elsif ($type eq "commit"){
742 %co = git_read_commit
($ref_id);
743 $ref_item{'reftype'} = "commit";
744 $ref_item{'name'} = $ref_file;
745 $ref_item{'title'} = $co{'title'};
746 $ref_item{'refid'} = $ref_id;
747 $ref_item{'epoch'} = $co{'committer_epoch'};
748 $ref_item{'age'} = $co{'age_string'};
750 $ref_item{'reftype'} = $type;
751 $ref_item{'name'} = $ref_file;
752 $ref_item{'refid'} = $ref_id;
755 push @reflist, \
%ref_item;
758 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
762 ## ----------------------------------------------------------------------
763 ## filesystem-related functions
768 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
769 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
770 if (!defined $gcos) {
774 $owner =~ s/[,;].*$//;
775 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
778 ## ......................................................................
779 ## mimetype related functions
781 sub mimetype_guess_file
{
782 my $filename = shift;
784 -r
$mimemap or return undef;
787 open(MIME
, $mimemap) or return undef;
789 my ($mime, $exts) = split(/\t+/);
790 my @exts = split(/\s+/, $exts);
791 foreach my $ext (@exts) {
792 $mimemap{$ext} = $mime;
797 $filename =~ /\.(.*?)$/;
802 my $filename = shift;
804 $filename =~ /\./ or return undef;
806 if ($mimetypes_file) {
807 my $file = $mimetypes_file;
808 #$file =~ m#^/# or $file = "$projectroot/$path/$file";
809 $mime = mimetype_guess_file
($filename, $file);
811 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
815 sub git_blob_plain_mimetype
{
817 my $filename = shift;
820 my $mime = mimetype_guess
($filename);
821 $mime and return $mime;
825 return $default_blob_plain_mimetype unless $fd;
828 return 'text/plain' .
829 ($default_text_plain_charset ? '; charset='.$default_text_plain_charset : '');
830 } elsif (! $filename) {
831 return 'application/octet-stream';
832 } elsif ($filename =~ m/\.png$/i) {
834 } elsif ($filename =~ m/\.gif$/i) {
836 } elsif ($filename =~ m/\.jpe?g$/i) {
839 return 'application/octet-stream';
843 ## ======================================================================
844 ## functions printing HTML: header, footer, error page
846 sub git_header_html
{
847 my $status = shift || "200 OK";
850 my $title = "$site_name git";
851 if (defined $project) {
852 $title .= " - $project";
853 if (defined $action) {
854 $title .= "/$action";
855 if (defined $file_name) {
856 $title .= " - $file_name";
857 if ($action eq "tree" && $file_name !~ m
|/$|) {
864 # require explicit support from the UA if we are to send the page as
865 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
866 # we have to do this because MSIE sometimes globs '*/*', pretending to
867 # support xhtml+xml but choking when it gets what it asked for.
868 if ($cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ && $cgi->Accept('application/xhtml
+xml
') != 0) {
869 $content_type = 'application
/xhtml
+xml
';
871 $content_type = 'text
/html
';
873 print $cgi->header(-type=>$content_type, -charset => 'utf-8
', -status=> $status, -expires => $expires);
875 <?xml version="1.0" encoding="utf-8"?>
876 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
877 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
878 <!-- git web interface v$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
879 <!-- git core binaries version $git_version -->
881 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
882 <meta name="robots" content="index, nofollow"/>
883 <title>$title</title>
884 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
889 print "<div class=\"page_header\">\n" .
890 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
891 "<img src=\"$my_uri?" . esc_param
("a=git-logo.png") . "\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
893 print $cgi->a({-href
=> esc_param
($home_link)}, "projects") . " / ";
894 if (defined $project) {
895 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, esc_html
($project));
896 if (defined $action) {
900 if (!defined $searchtext) {
904 if (defined $hash_base) {
905 $search_hash = $hash_base;
906 } elsif (defined $hash) {
907 $search_hash = $hash;
909 $search_hash = "HEAD";
911 $cgi->param("a", "search");
912 $cgi->param("h", $search_hash);
913 print $cgi->startform(-method => "get", -action
=> $my_uri) .
914 "<div class=\"search\">\n" .
915 $cgi->hidden(-name
=> "p") . "\n" .
916 $cgi->hidden(-name
=> "a") . "\n" .
917 $cgi->hidden(-name
=> "h") . "\n" .
918 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
920 $cgi->end_form() . "\n";
925 sub git_footer_html
{
926 print "<div class=\"page_footer\">\n";
927 if (defined $project) {
928 my $descr = git_read_description
($project);
929 if (defined $descr) {
930 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
932 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=rss"), -class => "rss_logo"}, "RSS") . "\n";
934 print $cgi->a({-href
=> "$my_uri?" . esc_param
("a=opml"), -class => "rss_logo"}, "OPML") . "\n";
942 my $status = shift || "403 Forbidden";
943 my $error = shift || "Malformed query, file missing or permission denied";
945 git_header_html
($status);
946 print "<div class=\"page_body\">\n" .
948 "$status - $error\n" .
955 ## ----------------------------------------------------------------------
956 ## functions printing or outputting HTML: navigation
959 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
960 $extra = '' if !defined $extra; # pager or formats
962 my @navs = qw(summary shortlog log commit commitdiff tree);
964 @navs = grep { $_ ne $suppress } @navs;
967 my %arg = map { $_, ''} @navs;
969 for (qw(commit commitdiff)) {
970 $arg{$_} = ";h=$head";
972 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
973 for (qw(shortlog log)) {
974 $arg{$_} = ";h=$head";
978 $arg{tree
} .= ";h=$treehead" if defined $treehead;
979 $arg{tree
} .= ";hb=$treebase" if defined $treebase;
981 print "<div class=\"page_nav\">\n" .
985 : $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$_$arg{$_}")}, "$_")
988 print "<br/>\n$extra<br/>\n" .
992 sub git_get_paging_nav
{
993 my ($action, $hash, $head, $page, $nrevs) = @_;
997 if ($hash ne $head || $page) {
998 $paging_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$action")}, "HEAD");
1000 $paging_nav .= "HEAD";
1004 $paging_nav .= " ⋅ " .
1005 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$action;h=$hash;pg=" . ($page-1)),
1006 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1008 $paging_nav .= " ⋅ prev";
1011 if ($nrevs >= (100 * ($page+1)-1)) {
1012 $paging_nav .= " ⋅ " .
1013 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$action;h=$hash;pg=" . ($page+1)),
1014 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1016 $paging_nav .= " ⋅ next";
1022 ## ......................................................................
1023 ## functions printing or outputting HTML: div
1025 sub git_header_div
{
1026 my ($action, $title, $hash, $hash_base) = @_;
1029 $rest .= ";h=$hash" if $hash;
1030 $rest .= ";hb=$hash_base" if $hash_base;
1032 print "<div class=\"header\">\n" .
1033 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$action$rest"),
1034 -class => "title"}, $title ? $title : $action) . "\n" .
1038 sub git_print_page_path
{
1042 if (!defined $name) {
1043 print "<div class=\"page_path\"><b>/</b></div>\n";
1044 } elsif ($type =~ "blob") {
1045 print "<div class=\"page_path\"><b>" .
1046 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;f=$file_name")}, esc_html
($name)) . "</b><br/></div>\n";
1048 print "<div class=\"page_path\"><b>" . esc_html
($name) . "</b><br/></div>\n";
1052 ## ......................................................................
1053 ## functions printing large fragments of HTML
1055 sub git_shortlog_body
{
1056 # uses global variable $project
1057 my ($revlist, $from, $to, $refs, $extra) = @_;
1058 $from = 0 unless defined $from;
1059 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1061 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
1063 for (my $i = $from; $i <= $to; $i++) {
1064 my $commit = $revlist->[$i];
1065 #my $ref = defined $refs ? git_get_referencing($refs, $commit) : '';
1066 my $ref = git_get_referencing
($refs, $commit);
1067 my %co = git_read_commit
($commit);
1068 my %ad = date_str
($co{'author_epoch'});
1070 print "<tr class=\"dark\">\n";
1072 print "<tr class=\"light\">\n";
1075 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1076 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1077 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
1079 if (length($co{'title_short'}) < length($co{'title'})) {
1080 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"),
1081 -class => "list", -title
=> "$co{'title'}"},
1082 "<b>" . esc_html
($co{'title_short'}) . "$ref</b>");
1084 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"),
1086 "<b>" . esc_html
($co{'title'}) . "$ref</b>");
1089 "<td class=\"link\">" .
1090 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") . " | " .
1091 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1095 if (defined $extra) {
1097 "<td colspan=\"4\">$extra</td>\n" .
1104 # uses global variable $project
1105 my ($taglist, $from, $to, $extra) = @_;
1106 $from = 0 unless defined $from;
1107 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1109 print "<table class=\"tags\" cellspacing=\"0\">\n";
1111 for (my $i = $from; $i <= $to; $i++) {
1112 my $entry = $taglist->[$i];
1114 my $comment_lines = $tag{'comment'};
1115 my $comment = shift @$comment_lines;
1117 if (defined $comment) {
1118 $comment_short = chop_str
($comment, 30, 5);
1121 print "<tr class=\"dark\">\n";
1123 print "<tr class=\"light\">\n";
1126 print "<td><i>$tag{'age'}</i></td>\n" .
1128 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"),
1129 -class => "list"}, "<b>" . esc_html
($tag{'name'}) . "</b>") .
1132 if (defined $comment) {
1133 if (length($comment_short) < length($comment)) {
1134 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}"),
1135 -class => "list", -title
=> $comment}, $comment_short);
1137 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}"),
1138 -class => "list"}, $comment);
1142 "<td class=\"selflink\">";
1143 if ($tag{'type'} eq "tag") {
1144 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, "tag");
1149 "<td class=\"link\">" . " | " .
1150 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1151 if ($tag{'reftype'} eq "commit") {
1152 print " | " . $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{'refid'}")}, "log");
1154 } elsif ($tag{'reftype'} eq "blob") {
1155 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$tag{'refid'}")}, "raw");
1160 if (defined $extra) {
1162 "<td colspan=\"5\">$extra</td>\n" .
1168 sub git_heads_body
{
1169 # uses global variable $project
1170 my ($taglist, $head, $from, $to, $extra) = @_;
1171 $from = 0 unless defined $from;
1172 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1174 print "<table class=\"heads\" cellspacing=\"0\">\n";
1176 for (my $i = $from; $i <= $to; $i++) {
1177 my $entry = $taglist->[$i];
1179 my $curr = $tag{'id'} eq $head;
1181 print "<tr class=\"dark\">\n";
1183 print "<tr class=\"light\">\n";
1186 print "<td><i>$tag{'age'}</i></td>\n" .
1187 ($tag{'id'} eq $head ? "<td class=\"current_head\">" : "<td>") .
1188 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}"),
1189 -class => "list"}, "<b>" . esc_html
($tag{'name'}) . "</b>") .
1191 "<td class=\"link\">" .
1192 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") . " | " .
1193 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'name'}")}, "log") .
1197 if (defined $extra) {
1199 "<td colspan=\"3\">$extra</td>\n" .
1205 ## ----------------------------------------------------------------------
1206 ## functions printing large fragments, format as one of arguments
1208 sub git_diff_print
{
1210 my $from_name = shift;
1212 my $to_name = shift;
1213 my $format = shift || "html";
1215 my $from_tmp = "/dev/null";
1216 my $to_tmp = "/dev/null";
1219 # create tmp from-file
1220 if (defined $from) {
1221 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
1222 open my $fd2, "> $from_tmp";
1223 open my $fd, "-|", $GIT, "cat-file", "blob", $from;
1230 # create tmp to-file
1232 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
1233 open my $fd2, "> $to_tmp";
1234 open my $fd, "-|", $GIT, "cat-file", "blob", $to;
1241 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
1242 if ($format eq "plain") {
1247 while (my $line = <$fd>) {
1249 my $char = substr($line, 0, 1);
1250 my $diff_class = "";
1252 $diff_class = " add";
1253 } elsif ($char eq "-") {
1254 $diff_class = " rem";
1255 } elsif ($char eq "@") {
1256 $diff_class = " chunk_header";
1257 } elsif ($char eq "\\") {
1261 while ((my $pos = index($line, "\t")) != -1) {
1262 if (my $count = (8 - (($pos-1) % 8))) {
1263 my $spaces = ' ' x
$count;
1264 $line =~ s/\t/$spaces/;
1267 print "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
1272 if (defined $from) {
1281 ## ======================================================================
1282 ## ======================================================================
1285 # git-logo (cached in browser for one day)
1287 binmode STDOUT
, ':raw';
1288 print $cgi->header(-type
=> 'image/png', -expires
=> '+1d');
1289 # cat git-logo.png | hexdump -e '16/1 " %02x" "\n"' | sed 's/ /\\x/g'
1290 print "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52" .
1291 "\x00\x00\x00\x48\x00\x00\x00\x1b\x04\x03\x00\x00\x00\x2d\xd9\xd4" .
1292 "\x2d\x00\x00\x00\x18\x50\x4c\x54\x45\xff\xff\xff\x60\x60\x5d\xb0" .
1293 "\xaf\xaa\x00\x80\x00\xce\xcd\xc7\xc0\x00\x00\xe8\xe8\xe6\xf7\xf7" .
1294 "\xf6\x95\x0c\xa7\x47\x00\x00\x00\x73\x49\x44\x41\x54\x28\xcf\x63" .
1295 "\x48\x67\x20\x04\x4a\x5c\x18\x0a\x08\x2a\x62\x53\x61\x20\x02\x08" .
1296 "\x0d\x69\x45\xac\xa1\xa1\x01\x30\x0c\x93\x60\x36\x26\x52\x91\xb1" .
1297 "\x01\x11\xd6\xe1\x55\x64\x6c\x6c\xcc\x6c\x6c\x0c\xa2\x0c\x70\x2a" .
1298 "\x62\x06\x2a\xc1\x62\x1d\xb3\x01\x02\x53\xa4\x08\xe8\x00\x03\x18" .
1299 "\x26\x56\x11\xd4\xe1\x20\x97\x1b\xe0\xb4\x0e\x35\x24\x71\x29\x82" .
1300 "\x99\x30\xb8\x93\x0a\x11\xb9\x45\x88\xc1\x8d\xa0\xa2\x44\x21\x06" .
1301 "\x27\x41\x82\x40\x85\xc1\x45\x89\x20\x70\x01\x00\xa4\x3d\x21\xc5" .
1302 "\x12\x1c\x9a\xfe\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\x82";
1305 sub git_project_list
{
1306 my @list = git_read_projects
();
1309 die_error
(undef, "No project found.");
1311 foreach my $pr (@list) {
1312 my $head = git_read_head
($pr->{'path'});
1313 if (!defined $head) {
1316 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
1317 my %co = git_read_commit
($head);
1321 $pr->{'commit'} = \
%co;
1322 if (!defined $pr->{'descr'}) {
1323 my $descr = git_read_description
($pr->{'path'}) || "";
1324 $pr->{'descr'} = chop_str
($descr, 25, 5);
1326 if (!defined $pr->{'owner'}) {
1327 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
1329 push @projects, $pr;
1332 if (-f
$home_text) {
1333 print "<div class=\"index_include\">\n";
1334 open (my $fd, $home_text);
1339 print "<table class=\"project_list\">\n" .
1341 if (!defined($order) || (defined($order) && ($order eq "project"))) {
1342 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
1343 print "<th>Project</th>\n";
1345 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=project")}, "Project") . "</th>\n";
1347 if (defined($order) && ($order eq "descr")) {
1348 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
1349 print "<th>Description</th>\n";
1351 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=descr")}, "Description") . "</th>\n";
1353 if (defined($order) && ($order eq "owner")) {
1354 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
1355 print "<th>Owner</th>\n";
1357 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=owner")}, "Owner") . "</th>\n";
1359 if (defined($order) && ($order eq "age")) {
1360 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
1361 print "<th>Last Change</th>\n";
1363 print "<th>" . $cgi->a({-class => "header", -href
=> "$my_uri?" . esc_param
("o=age")}, "Last Change") . "</th>\n";
1365 print "<th></th>\n" .
1368 foreach my $pr (@projects) {
1370 print "<tr class=\"dark\">\n";
1372 print "<tr class=\"light\">\n";
1375 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=summary"), -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
1376 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
1377 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
1378 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" . $pr->{'commit'}{'age_string'} . "</td>\n" .
1379 "<td class=\"link\">" .
1380 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=summary")}, "summary") .
1381 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=shortlog")}, "shortlog") .
1382 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=log")}, "log") .
1391 my $descr = git_read_description
($project) || "none";
1392 my $head = git_read_head
($project);
1393 my %co = git_read_commit
($head);
1394 my %cd = date_str
($co{'committer_epoch'}, $co{'committer_tz'});
1397 if (-f
$projects_list) {
1398 open (my $fd , $projects_list);
1399 while (my $line = <$fd>) {
1401 my ($pr, $ow) = split ' ', $line;
1402 $pr = unescape
($pr);
1403 $ow = unescape
($ow);
1404 if ($pr eq $project) {
1405 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
1411 if (!defined $owner) {
1412 $owner = get_file_owner
("$projectroot/$project");
1415 my $refs = read_info_ref
();
1417 git_page_nav
('summary','', $head);
1419 print "<div class=\"title\"> </div>\n";
1420 print "<table cellspacing=\"0\">\n" .
1421 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
1422 "<tr><td>owner</td><td>$owner</td></tr>\n" .
1423 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
1426 open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_read_head
($project)
1427 or die_error
(undef, "Open git-rev-list failed.");
1428 my @revlist = map { chomp; $_ } <$fd>;
1430 git_header_div
('shortlog');
1431 git_shortlog_body
(\
@revlist, 0, 15, $refs,
1432 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "..."));
1434 my $taglist = git_read_refs
("refs/tags");
1435 if (defined @$taglist) {
1436 git_header_div
('tags');
1437 git_tags_body
($taglist, 0, 15,
1438 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tags")}, "..."));
1441 my $headlist = git_read_refs
("refs/heads");
1442 if (defined @$headlist) {
1443 git_header_div
('heads');
1444 git_heads_body
($taglist, $head, 0, 15,
1445 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=heads")}, "..."));
1452 my $head = git_read_head
($project);
1454 git_page_nav
('','', $head,undef,$head);
1455 my %tag = git_read_tag
($hash);
1456 git_header_div
('commit', esc_html
($tag{'name'}), $hash);
1457 print "<div class=\"title_text\">\n" .
1458 "<table cellspacing=\"0\">\n" .
1460 "<td>object</td>\n" .
1461 "<td>" . $cgi->a({-class => "list", -href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'object'}) . "</td>\n" .
1462 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'type'}) . "</td>\n" .
1464 if (defined($tag{'author'})) {
1465 my %ad = date_str
($tag{'epoch'}, $tag{'tz'});
1466 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
1467 print "<tr><td></td><td>" . $ad{'rfc2822'} . sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) . "</td></tr>\n";
1469 print "</table>\n\n" .
1471 print "<div class=\"page_body\">";
1472 my $comment = $tag{'comment'};
1473 foreach my $line (@$comment) {
1474 print esc_html
($line) . "<br/>\n";
1483 die_error
(undef, "Permission denied.") if (!git_get_project_config_bool
('blame'));
1484 die_error
('404 Not Found', "File name not defined") if (!$file_name);
1485 $hash_base ||= git_read_head
($project);
1486 die_error
(undef, "Reading commit failed") unless ($hash_base);
1487 my %co = git_read_commit
($hash_base)
1488 or die_error
(undef, "Reading commit failed");
1489 if (!defined $hash) {
1490 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
1491 or die_error
(undef, "Error looking up file");
1493 $ftype = git_get_type
($hash);
1494 if ($ftype !~ "blob") {
1495 die_error
("400 Bad Request", "object is not a blob");
1497 open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base)
1498 or die_error
(undef, "Open git-blame failed.");
1501 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") .
1502 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;f=$file_name")}, "head");
1503 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1504 git_header_div
('commit', esc_html
($co{'title'}), $hash_base);
1505 git_print_page_path
($file_name, $ftype);
1506 my @rev_color = (qw(light dark));
1507 my $num_colors = scalar(@rev_color);
1508 my $current_color = 0;
1510 print "<div class=\"page_body\">\n";
1511 print "<table class=\"blame\">\n";
1512 print "<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n";
1514 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
1516 my $rev = substr($full_rev, 0, 8);
1520 if (!defined $last_rev) {
1521 $last_rev = $full_rev;
1522 } elsif ($last_rev ne $full_rev) {
1523 $last_rev = $full_rev;
1524 $current_color = ++$current_color % $num_colors;
1526 print "<tr class=\"$rev_color[$current_color]\">\n";
1527 print "<td class=\"sha1\">" .
1528 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$full_rev;f=$file_name")}, esc_html
($rev)) . "</td>\n";
1529 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" . esc_html
($lineno) . "</a></td>\n";
1530 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
1535 close $fd or print "Reading blob failed\n";
1541 die_error
('403 Permission denied', "Permission denied.") if (!git_get_project_config_bool
('blame'));
1542 die_error
('404 Not Found', "What file will it be, master?") if (!$file_name);
1543 $hash_base ||= git_read_head
($project);
1544 die_error
(undef, "Reading commit failed.") unless ($hash_base);
1545 my %co = git_read_commit
($hash_base)
1546 or die_error
(undef, "Reading commit failed.");
1547 if (!defined $hash) {
1548 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
1549 or die_error
(undef, "Error lookup file.");
1551 open ($fd, "-|", $GIT, "annotate", '-l', '-t', '-r', $file_name, $hash_base)
1552 or die_error
(undef, "Open git-annotate failed.");
1555 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") .
1556 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;f=$file_name")}, "head");
1557 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1558 git_header_div
('commit', esc_html
($co{'title'}), $hash_base);
1559 git_print_page_path
($file_name);
1560 print "<div class=\"page_body\">\n";
1562 <table class="blame">
1571 my @line_class = (qw(light dark));
1572 my $line_class_len = scalar (@line_class);
1573 my $line_class_num = $#line_class;
1574 while (my $line = <$fd>) {
1586 $line_class_num = ($line_class_num + 1) % $line_class_len;
1588 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) \+\d\d\d\d\t(\d+)\)(.*)$/) {
1595 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
1598 $short_rev = substr ($long_rev, 0, 8);
1599 $age = time () - $time;
1600 $age_str = age_string
($age);
1601 $age_str =~ s/ / /g;
1602 $age_class = age_class
($age);
1603 $author = esc_html
($author);
1604 $author =~ s/ / /g;
1606 while ((my $pos = index($data, "\t")) != -1) {
1607 if (my $count = (8 - ($pos % 8))) {
1608 my $spaces = ' ' x
$count;
1609 $data =~ s/\t/$spaces/;
1612 $data = esc_html
($data);
1615 <tr class="$line_class[$line_class_num]">
1616 <td class="sha1"><a href="$my_uri?${\esc_param ("p=$project;a=commit;h=$long_rev")}" class="text">$short_rev..</a></td>
1617 <td class="$age_class">$age_str</td>
1619 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
1620 <td class="pre">$data</td>
1623 } # while (my $line = <$fd>)
1624 print "</table>\n\n";
1625 close $fd or print "Reading blob failed.\n";
1631 my $head = git_read_head
($project);
1633 git_page_nav
('','', $head,undef,$head);
1634 git_header_div
('summary', $project);
1636 my $taglist = git_read_refs
("refs/tags");
1637 if (defined @$taglist) {
1638 git_tags_body
($taglist);
1644 my $head = git_read_head
($project);
1646 git_page_nav
('','', $head,undef,$head);
1647 git_header_div
('summary', $project);
1649 my $taglist = git_read_refs
("refs/heads");
1651 if (defined @$taglist) {
1652 git_heads_body
($taglist, $head);
1657 sub git_blob_plain
{
1658 if (!defined $hash) {
1659 if (defined $file_name) {
1660 my $base = $hash_base || git_read_head
($project);
1661 $hash = git_get_hash_by_path
($base, $file_name, "blob")
1662 or die_error
(undef, "Error lookup file.");
1664 die_error
(undef, "No file name defined.");
1668 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
1669 or die_error
("Couldn't cat $file_name, $hash");
1671 $type ||= git_blob_plain_mimetype
($fd, $file_name);
1673 # save as filename, even when no $file_name is given
1674 my $save_as = "$hash";
1675 if (defined $file_name) {
1676 $save_as = $file_name;
1677 } elsif ($type =~ m/^text\//) {
1681 print $cgi->header(-type
=> "$type", '-content-disposition' => "inline; filename=\"$save_as\"");
1683 binmode STDOUT
, ':raw';
1685 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
1691 if (!defined $hash) {
1692 if (defined $file_name) {
1693 my $base = $hash_base || git_read_head
($project);
1694 $hash = git_get_hash_by_path
($base, $file_name, "blob")
1695 or die_error
(undef, "Error lookup file.");
1697 die_error
(undef, "No file name defined.");
1700 my $have_blame = git_get_project_config_bool
('blame');
1701 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
1702 or die_error
(undef, "Couldn't cat $file_name, $hash.");
1703 my $mimetype = git_blob_plain_mimetype
($fd, $file_name);
1704 if ($mimetype !~ m/^text\//) {
1706 return git_blob_plain
($mimetype);
1709 my $formats_nav = '';
1710 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
1711 if (defined $file_name) {
1713 $formats_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;h=$hash;hb=$hash_base;f=$file_name")}, "blame") . " | ";
1716 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$hash;f=$file_name")}, "plain") .
1717 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;hb=HEAD;f=$file_name")}, "head");
1719 $formats_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$hash")}, "plain");
1721 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1722 git_header_div
('commit', esc_html
($co{'title'}), $hash_base);
1724 print "<div class=\"page_nav\">\n" .
1725 "<br/><br/></div>\n" .
1726 "<div class=\"title\">$hash</div>\n";
1728 git_print_page_path
($file_name, "blob");
1729 print "<div class=\"page_body\">\n";
1731 while (my $line = <$fd>) {
1734 while ((my $pos = index($line, "\t")) != -1) {
1735 if (my $count = (8 - ($pos % 8))) {
1736 my $spaces = ' ' x
$count;
1737 $line =~ s/\t/$spaces/;
1740 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", $nr, $nr, $nr, esc_html
($line);
1742 close $fd or print "Reading blob failed.\n";
1748 if (!defined $hash) {
1749 $hash = git_read_head
($project);
1750 if (defined $file_name) {
1751 my $base = $hash_base || $hash;
1752 $hash = git_get_hash_by_path
($base, $file_name, "tree");
1754 if (!defined $hash_base) {
1759 open my $fd, "-|", $GIT, "ls-tree", '-z', $hash
1760 or die_error
(undef, "Open git-ls-tree failed.");
1761 my @entries = map { chomp; $_ } <$fd>;
1762 close $fd or die_error
(undef, "Reading tree failed.");
1765 my $refs = read_info_ref
();
1766 my $ref = git_get_referencing
($refs, $hash_base);
1770 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
1771 $base_key = ";hb=$hash_base";
1772 git_page_nav
('tree','', $hash_base);
1773 git_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
1775 print "<div class=\"page_nav\">\n";
1776 print "<br/><br/></div>\n";
1777 print "<div class=\"title\">$hash</div>\n";
1779 if (defined $file_name) {
1780 $base = esc_html
("$file_name/");
1782 git_print_page_path
($file_name);
1783 print "<div class=\"page_body\">\n";
1784 print "<table cellspacing=\"0\">\n";
1786 foreach my $line (@entries) {
1787 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1788 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1792 my $t_name = validate_input
($4);
1794 print "<tr class=\"dark\">\n";
1796 print "<tr class=\"light\">\n";
1799 print "<td class=\"mode\">" . mode_str
($t_mode) . "</td>\n";
1800 if ($t_type eq "blob") {
1801 print "<td class=\"list\">" .
1802 $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)) .
1804 "<td class=\"link\">" .
1805 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name")}, "blob") .
1806 # " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$t_hash$base_key;f=$base$t_name")}, "blame") .
1807 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;h=$t_hash;hb=$hash_base;f=$base$t_name")}, "history") .
1808 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$t_hash;f=$base$t_name")}, "raw") .
1810 } elsif ($t_type eq "tree") {
1811 print "<td class=\"list\">" .
1812 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, esc_html
($t_name)) .
1814 "<td class=\"link\">" .
1815 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, "tree") .
1816 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;hb=$hash_base;f=$base$t_name")}, "history") .
1821 print "</table>\n" .
1827 my $head = git_read_head
($project);
1828 if (!defined $hash) {
1831 if (!defined $page) {
1834 my $refs = read_info_ref
();
1836 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
1837 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
1838 or die_error
(undef, "Open git-rev-list failed.");
1839 my @revlist = map { chomp; $_ } <$fd>;
1842 my $paging_nav = git_get_paging_nav
('log', $hash, $head, $page, $#revlist);
1845 git_page_nav
('log','', $hash,undef,undef, $paging_nav);
1848 my %co = git_read_commit
($hash);
1850 git_header_div
('summary', $project);
1851 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
1853 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
1854 my $commit = $revlist[$i];
1855 my $ref = git_get_referencing
($refs, $commit);
1856 my %co = git_read_commit
($commit);
1858 my %ad = date_str
($co{'author_epoch'});
1859 git_header_div
('commit',
1860 "<span class=\"age\">$co{'age_string'}</span>" .
1861 esc_html
($co{'title'}) . $ref,
1863 print "<div class=\"title_text\">\n" .
1864 "<div class=\"log_link\">\n" .
1865 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
1866 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1869 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
1871 "<div class=\"log_body\">\n";
1872 my $comment = $co{'comment'};
1874 foreach my $line (@$comment) {
1875 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1886 print format_log_line_html
($line) . "<br/>\n";
1897 my %co = git_read_commit
($hash);
1899 die_error
(undef, "Unknown commit object.");
1901 my %ad = date_str
($co{'author_epoch'}, $co{'author_tz'});
1902 my %cd = date_str
($co{'committer_epoch'}, $co{'committer_tz'});
1904 my $parent = $co{'parent'};
1905 if (!defined $parent) {
1908 open my $fd, "-|", $GIT, "diff-tree", '-r', '-M', $parent, $hash
1909 or die_error
(undef, "Open git-diff-tree failed.");
1910 my @difftree = map { chomp; $_ } <$fd>;
1911 close $fd or die_error
(undef, "Reading git-diff-tree failed.");
1913 # non-textual hash id's can be cached
1915 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
1918 my $refs = read_info_ref
();
1919 my $ref = git_get_referencing
($refs, $co{'id'});
1920 my $formats_nav = '';
1921 if (defined $file_name && defined $co{'parent'}) {
1922 my $parent = $co{'parent'};
1923 $formats_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;hb=$parent;f=$file_name")}, "blame");
1925 git_header_html
(undef, $expires);
1926 git_page_nav
('commit', defined $co{'parent'} ? '' : 'commitdiff',
1927 $hash, $co{'tree'}, $hash,
1930 if (defined $co{'parent'}) {
1931 git_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
1933 git_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
1935 print "<div class=\"title_text\">\n" .
1936 "<table cellspacing=\"0\">\n";
1937 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
1939 "<td></td><td> $ad{'rfc2822'}";
1940 if ($ad{'hour_local'} < 6) {
1941 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1943 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1947 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
1948 print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
1949 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
1952 "<td class=\"sha1\">" .
1953 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash"), class => "list"}, $co{'tree'}) .
1955 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
1958 my $parents = $co{'parents'};
1959 foreach my $par (@$parents) {
1962 "<td class=\"sha1\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$par"), class => "list"}, $par) . "</td>" .
1963 "<td class=\"link\">" .
1964 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$par")}, "commit") .
1965 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash;hp=$par")}, "commitdiff") .
1971 print "<div class=\"page_body\">\n";
1972 my $comment = $co{'comment'};
1975 foreach my $line (@$comment) {
1976 # print only one empty line
1978 if ($empty || $signed) {
1985 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1987 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1990 print format_log_line_html
($line) . "<br/>\n";
1994 print "<div class=\"list_head\">\n";
1995 if ($#difftree > 10) {
1996 print(($#difftree + 1) . " files changed:\n");
1999 print "<table class=\"diff_tree\">\n";
2001 foreach my $line (@difftree) {
2002 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2003 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2004 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
2012 my $similarity = $6;
2013 my $file = validate_input
(unquote
($7));
2015 print "<tr class=\"dark\">\n";
2017 print "<tr class=\"light\">\n";
2020 if ($status eq "A") {
2022 if (S_ISREG
(oct $to_mode)) {
2023 $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
2026 $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" .
2027 "<td><span class=\"file_status new\">[new " . file_type
($to_mode) . "$mode_chng]</span></td>\n" .
2028 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob") . "</td>\n";
2029 } elsif ($status eq "D") {
2031 $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" .
2032 "<td><span class=\"file_status deleted\">[deleted " . file_type
($from_mode). "]</span></td>\n" .
2033 "<td class=\"link\">" .
2034 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, "blob") .
2035 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;hb=$hash;f=$file")}, "history") .
2037 } elsif ($status eq "M" || $status eq "T") {
2038 my $mode_chnge = "";
2039 if ($from_mode != $to_mode) {
2040 $mode_chnge = " <span class=\"file_status mode_chnge\">[changed";
2041 if (((oct $from_mode) & S_IFMT
) != ((oct $to_mode) & S_IFMT
)) {
2042 $mode_chnge .= " from " . file_type
($from_mode) . " to " . file_type
($to_mode);
2044 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
2045 if (S_ISREG
($from_mode) && S_ISREG
($to_mode)) {
2046 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
2047 } elsif (S_ISREG
($to_mode)) {
2048 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
2051 $mode_chnge .= "]</span>\n";
2054 if ($to_id ne $from_id) {
2055 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));
2057 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file"), -class => "list"}, esc_html
($file));
2060 "<td>$mode_chnge</td>\n" .
2061 "<td class=\"link\">";
2062 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob");
2063 if ($to_id ne $from_id) {
2064 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file")}, "diff");
2066 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;hb=$hash;f=$file")}, "history") . "\n";
2068 } elsif ($status eq "R") {
2069 my ($from_file, $to_file) = split "\t", $file;
2071 if ($from_mode != $to_mode) {
2072 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
2075 $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" .
2076 "<td><span class=\"file_status moved\">[moved from " .
2077 $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)) .
2078 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
2079 "<td class=\"link\">" .
2080 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file")}, "blob");
2081 if ($to_id ne $from_id) {
2082 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file")}, "diff");
2093 mkdir($git_temp, 0700);
2095 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
2097 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff_plain;h=$hash;hp=$hash_parent")}, "plain");
2098 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2099 git_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2101 print "<div class=\"page_nav\">\n" .
2102 "<br/><br/></div>\n" .
2103 "<div class=\"title\">$hash vs $hash_parent</div>\n";
2105 git_print_page_path
($file_name, "blob");
2106 print "<div class=\"page_body\">\n" .
2107 "<div class=\"diff_info\">blob:" .
2108 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name")}, $hash_parent) .
2110 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, $hash) .
2112 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
2117 sub git_blobdiff_plain
{
2118 mkdir($git_temp, 0700);
2119 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8');
2120 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
2123 sub git_commitdiff
{
2124 mkdir($git_temp, 0700);
2125 my %co = git_read_commit
($hash);
2127 die_error
(undef, "Unknown commit object.");
2129 if (!defined $hash_parent) {
2130 $hash_parent = $co{'parent'};
2132 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2133 or die_error
(undef, "Open git-diff-tree failed.");
2134 my @difftree = map { chomp; $_ } <$fd>;
2135 close $fd or die_error
(undef, "Reading diff-tree failed.");
2137 # non-textual hash id's can be cached
2139 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2142 my $refs = read_info_ref
();
2143 my $ref = git_get_referencing
($refs, $co{'id'});
2145 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent")}, "plain");
2146 git_header_html
(undef, $expires);
2147 git_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
2148 git_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
2149 print "<div class=\"page_body\">\n";
2150 my $comment = $co{'comment'};
2153 my @log = @$comment;
2154 # remove first and empty lines after that
2156 while (defined $log[0] && $log[0] eq "") {
2159 foreach my $line (@log) {
2160 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2171 print format_log_line_html
($line) . "<br/>\n";
2174 foreach my $line (@difftree) {
2175 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2176 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2177 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2183 my $file = validate_input
(unquote
($6));
2184 if ($status eq "A") {
2185 print "<div class=\"diff_info\">" . file_type
($to_mode) . ":" .
2186 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id) . "(new)" .
2188 git_diff_print
(undef, "/dev/null", $to_id, "b/$file");
2189 } elsif ($status eq "D") {
2190 print "<div class=\"diff_info\">" . file_type
($from_mode) . ":" .
2191 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) . "(deleted)" .
2193 git_diff_print
($from_id, "a/$file", undef, "/dev/null");
2194 } elsif ($status eq "M") {
2195 if ($from_id ne $to_id) {
2196 print "<div class=\"diff_info\">" .
2197 file_type
($from_mode) . ":" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) .
2199 file_type
($to_mode) . ":" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id);
2201 git_diff_print
($from_id, "a/$file", $to_id, "b/$file");
2210 sub git_commitdiff_plain
{
2211 mkdir($git_temp, 0700);
2212 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2213 or die_error
(undef, "Open git-diff-tree failed.");
2214 my @difftree = map { chomp; $_ } <$fd>;
2215 close $fd or die_error
(undef, "Reading diff-tree failed.");
2217 # try to figure out the next tag after this commit
2219 my $refs = read_info_ref
("tags");
2220 open $fd, "-|", $GIT, "rev-list", "HEAD";
2221 my @commits = map { chomp; $_ } <$fd>;
2223 foreach my $commit (@commits) {
2224 if (defined $refs->{$commit}) {
2225 $tagname = $refs->{$commit}
2227 if ($commit eq $hash) {
2232 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8', '-content-disposition' => "inline; filename=\"git-$hash.patch\"");
2233 my %co = git_read_commit
($hash);
2234 my %ad = date_str
($co{'author_epoch'}, $co{'author_tz'});
2235 my $comment = $co{'comment'};
2236 print "From: $co{'author'}\n" .
2237 "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
2238 "Subject: $co{'title'}\n";
2239 if (defined $tagname) {
2240 print "X-Git-Tag: $tagname\n";
2242 print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
2245 foreach my $line (@$comment) {;
2250 foreach my $line (@difftree) {
2251 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2256 if ($status eq "A") {
2257 git_diff_print
(undef, "/dev/null", $to_id, "b/$file", "plain");
2258 } elsif ($status eq "D") {
2259 git_diff_print
($from_id, "a/$file", undef, "/dev/null", "plain");
2260 } elsif ($status eq "M") {
2261 git_diff_print
($from_id, "a/$file", $to_id, "b/$file", "plain");
2267 if (!defined $hash_base) {
2268 $hash_base = git_read_head
($project);
2271 my %co = git_read_commit
($hash_base);
2273 die_error
(undef, "Unknown commit object.");
2275 my $refs = read_info_ref
();
2277 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base);
2278 git_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2279 if (!defined $hash && defined $file_name) {
2280 $hash = git_get_hash_by_path
($hash_base, $file_name);
2282 if (defined $hash) {
2283 $ftype = git_get_type
($hash);
2285 git_print_page_path
($file_name, $ftype);
2288 $GIT, "rev-list", "--full-history", $hash_base, "--", $file_name;
2289 print "<table cellspacing=\"0\">\n";
2291 while (my $line = <$fd>) {
2292 if ($line =~ m/^([0-9a-fA-F]{40})/){
2294 my %co = git_read_commit
($commit);
2298 my $ref = git_get_referencing
($refs, $commit);
2300 print "<tr class=\"dark\">\n";
2302 print "<tr class=\"light\">\n";
2305 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2306 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2307 "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list"}, "<b>" .
2308 esc_html
(chop_str
($co{'title'}, 50)) . "$ref</b>") . "</td>\n" .
2309 "<td class=\"link\">" .
2310 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
2311 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2312 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;hb=$commit;f=$file_name")}, "blob");
2313 my $blob = git_get_hash_by_path
($hash_base, $file_name);
2314 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2315 if (defined $blob && defined $blob_parent && $blob ne $blob_parent) {
2317 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=$file_name")},
2330 if (!defined $searchtext) {
2331 die_error
("", "Text field empty.");
2333 if (!defined $hash) {
2334 $hash = git_read_head
($project);
2336 my %co = git_read_commit
($hash);
2338 die_error
(undef, "Unknown commit object.");
2340 # pickaxe may take all resources of your box and run for several minutes
2341 # with every query - so decide by yourself how public you make this feature :)
2342 my $commit_search = 1;
2343 my $author_search = 0;
2344 my $committer_search = 0;
2345 my $pickaxe_search = 0;
2346 if ($searchtext =~ s/^author\\://i) {
2348 } elsif ($searchtext =~ s/^committer\\://i) {
2349 $committer_search = 1;
2350 } elsif ($searchtext =~ s/^pickaxe\\://i) {
2352 $pickaxe_search = 1;
2355 git_page_nav
('','', $hash,$co{'tree'},$hash);
2356 git_header_div
('commit', esc_html
($co{'title'}), $hash);
2358 print "<table cellspacing=\"0\">\n";
2360 if ($commit_search) {
2362 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", $hash or next;
2363 while (my $commit_text = <$fd>) {
2364 if (!grep m/$searchtext/i, $commit_text) {
2367 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
2370 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
2373 my @commit_lines = split "\n", $commit_text;
2374 my %co = git_read_commit
(undef, \
@commit_lines);
2379 print "<tr class=\"dark\">\n";
2381 print "<tr class=\"light\">\n";
2384 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2385 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2387 $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/>");
2388 my $comment = $co{'comment'};
2389 foreach my $line (@$comment) {
2390 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2391 my $lead = esc_html
($1) || "";
2392 $lead = chop_str
($lead, 30, 10);
2393 my $match = esc_html
($2) || "";
2394 my $trail = esc_html
($3) || "";
2395 $trail = chop_str
($trail, 30, 10);
2396 my $text = "$lead<span class=\"match\">$match</span>$trail";
2397 print chop_str
($text, 80, 5) . "<br/>\n";
2401 "<td class=\"link\">" .
2402 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2403 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2410 if ($pickaxe_search) {
2412 open my $fd, "-|", "$GIT rev-list $hash | $GIT diff-tree -r --stdin -S\'$searchtext\'";
2415 while (my $line = <$fd>) {
2416 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2419 $set{'from_id'} = $3;
2421 $set{'id'} = $set{'to_id'};
2422 if ($set{'id'} =~ m/0{40}/) {
2423 $set{'id'} = $set{'from_id'};
2425 if ($set{'id'} =~ m/0{40}/) {
2429 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
2432 print "<tr class=\"dark\">\n";
2434 print "<tr class=\"light\">\n";
2437 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2438 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2440 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" .
2441 esc_html
(chop_str
($co{'title'}, 50)) . "</b><br/>");
2442 while (my $setref = shift @files) {
2444 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}"), class => "list"},
2445 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
2449 "<td class=\"link\">" .
2450 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2451 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2455 %co = git_read_commit
($1);
2465 my $head = git_read_head
($project);
2466 if (!defined $hash) {
2469 if (!defined $page) {
2472 my $refs = read_info_ref
();
2474 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2475 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2476 or die_error
(undef, "Open git-rev-list failed.");
2477 my @revlist = map { chomp; $_ } <$fd>;
2480 my $paging_nav = git_get_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
2482 if ($#revlist >= (100 * ($page+1)-1)) {
2484 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)),
2485 -title
=> "Alt-n"}, "next");
2490 git_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
2491 git_header_div
('summary', $project);
2493 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
2498 ## ......................................................................
2499 ## feeds (RSS, OPML)
2502 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
2503 open my $fd, "-|", $GIT, "rev-list", "--max-count=150", git_read_head
($project)
2504 or die_error
(undef, "Open git-rev-list failed.");
2505 my @revlist = map { chomp; $_ } <$fd>;
2506 close $fd or die_error
(undef, "Reading rev-list failed.");
2507 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
2508 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
2509 "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
2510 print "<channel>\n";
2511 print "<title>$project</title>\n".
2512 "<link>" . esc_html
("$my_url?p=$project;a=summary") . "</link>\n".
2513 "<description>$project log</description>\n".
2514 "<language>en</language>\n";
2516 for (my $i = 0; $i <= $#revlist; $i++) {
2517 my $commit = $revlist[$i];
2518 my %co = git_read_commit
($commit);
2519 # we read 150, we always show 30 and the ones more recent than 48 hours
2520 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
2523 my %cd = date_str
($co{'committer_epoch'});
2524 open $fd, "-|", $GIT, "diff-tree", '-r', $co{'parent'}, $co{'id'} or next;
2525 my @difftree = map { chomp; $_ } <$fd>;
2529 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
2531 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
2532 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
2533 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
2534 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
2535 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
2536 "<content:encoded>" .
2538 my $comment = $co{'comment'};
2539 foreach my $line (@$comment) {
2540 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
2541 print "$line<br/>\n";
2544 foreach my $line (@difftree) {
2545 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
2548 my $file = validate_input
(unquote
($7));
2549 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
2550 print "$file<br/>\n";
2553 "</content:encoded>\n" .
2556 print "</channel></rss>";
2560 my @list = git_read_projects
();
2562 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
2563 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
2564 "<opml version=\"1.0\">\n".
2566 " <title>$site_name Git OPML Export</title>\n".
2569 "<outline text=\"git RSS feeds\">\n";
2571 foreach my $pr (@list) {
2573 my $head = git_read_head
($proj{'path'});
2574 if (!defined $head) {
2577 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
2578 my %co = git_read_commit
($head);
2583 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
2584 my $rss = "$my_url?p=$proj{'path'};a=rss";
2585 my $html = "$my_url?p=$proj{'path'};a=summary";
2586 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
2588 print "</outline>\n".