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);
18 binmode STDOUT
, ':utf8';
22 our $my_url = $cgi->url();
23 our $my_uri = $cgi->url(-absolute
=> 1);
26 # core git executable to use
27 # this can just be "git" if your webserver has a sensible PATH
28 our $GIT = "/usr/bin/git";
30 # absolute fs-path which will be prepended to the project path
31 #our $projectroot = "/pub/scm";
32 our $projectroot = "/home/kay/public_html/pub/scm";
34 # version of the core git binary
35 our $git_version = qx($GIT --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
37 # location for temporary files needed for diffs
38 our $git_temp = "/tmp/gitweb";
40 mkdir($git_temp, 0700) || die_error
("Couldn't mkdir $git_temp");
43 # target of the home link on top of all pages
44 our $home_link = $my_uri;
46 # name of your site or organization to appear in page titles
47 # replace this with something more descriptive for clearer bookmarks
48 our $site_name = $ENV{'SERVER_NAME'} || "Untitled";
50 # html text to include at home page
51 our $home_text = "indextext.html";
53 # URI of default stylesheet
54 our $stylesheet = "gitweb.css";
56 # source of projects list
57 #our $projects_list = $projectroot;
58 our $projects_list = "index/index.aux";
60 # default blob_plain mimetype and default charset for text/plain blob
61 our $default_blob_plain_mimetype = 'text/plain';
62 our $default_text_plain_charset = undef;
64 # file to use for guessing MIME types before trying /etc/mime.types
65 # (relative to the current git repository)
66 our $mimetypes_file = undef;
68 # input validation and dispatch
69 our $action = $cgi->param('a');
70 if (defined $action) {
71 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
73 die_error
(undef, "Invalid action parameter.");
75 if ($action eq "git-logo.png") {
78 } elsif ($action eq "opml") {
84 our $project = ($cgi->param('p') || $ENV{'PATH_INFO'});
85 if (defined $project) {
86 $project =~ s
|^/||; $project =~ s|/$||;
87 $project = validate_input
($project);
88 if (!defined($project)) {
89 die_error
(undef, "Invalid project parameter.");
91 if (!(-d
"$projectroot/$project")) {
93 die_error
(undef, "No such directory.");
95 if (!(-e
"$projectroot/$project/HEAD")) {
97 die_error
(undef, "No such project.");
99 $rss_link = "<link rel=\"alternate\" title=\"" . esc_param
($project) . " log\" href=\"" .
100 "$my_uri?" . esc_param
("p=$project;a=rss") . "\" type=\"application/rss+xml\"/>";
101 $ENV{'GIT_DIR'} = "$projectroot/$project";
107 our $file_name = $cgi->param('f');
108 if (defined $file_name) {
109 $file_name = validate_input
($file_name);
110 if (!defined($file_name)) {
111 die_error
(undef, "Invalid file parameter.");
115 our $hash = $cgi->param('h');
117 $hash = validate_input
($hash);
118 if (!defined($hash)) {
119 die_error
(undef, "Invalid hash parameter.");
123 our $hash_parent = $cgi->param('hp');
124 if (defined $hash_parent) {
125 $hash_parent = validate_input
($hash_parent);
126 if (!defined($hash_parent)) {
127 die_error
(undef, "Invalid hash parent parameter.");
131 our $hash_base = $cgi->param('hb');
132 if (defined $hash_base) {
133 $hash_base = validate_input
($hash_base);
134 if (!defined($hash_base)) {
135 die_error
(undef, "Invalid hash base parameter.");
139 our $page = $cgi->param('pg');
141 if ($page =~ m/[^0-9]$/) {
143 die_error
(undef, "Invalid page parameter.");
147 our $searchtext = $cgi->param('s');
148 if (defined $searchtext) {
149 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
151 die_error
(undef, "Invalid search parameter.");
153 $searchtext = quotemeta $searchtext;
158 "blame" => \
&git_blame2
,
159 "blobdiff" => \
&git_blobdiff
,
160 "blobdiff_plain" => \
&git_blobdiff_plain
,
161 "blob" => \
&git_blob
,
162 "blob_plain" => \
&git_blob_plain
,
163 "commitdiff" => \
&git_commitdiff
,
164 "commitdiff_plain" => \
&git_commitdiff_plain
,
165 "commit" => \
&git_commit
,
166 "heads" => \
&git_heads
,
167 "history" => \
&git_history
,
170 "search" => \
&git_search
,
171 "shortlog" => \
&git_shortlog
,
172 "summary" => \
&git_summary
,
174 "tags" => \
&git_tags
,
175 "tree" => \
&git_tree
,
178 $action = 'summary' if (!defined($action));
179 if (!defined($actions{$action})) {
181 die_error
(undef, "Unknown action.");
183 $actions{$action}->();
186 ## ======================================================================
187 ## validation, quoting/unquoting and escaping
192 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
195 if ($input =~ m/(^|\/)(|\
.|\
.\
.)($|\
/)/) {
198 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\
-\
+\#\
~\
%]/) {
204 # quote unsafe chars, but keep the slash, even when it's not
205 # correct, but quoted slashes look too horrible in bookmarks
208 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
214 # replace invalid utf8 character with SUBSTITUTION sequence
217 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
218 $str = escapeHTML
($str);
219 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
223 # git may return quoted and escaped filenames
226 if ($str =~ m/^"(.*)"$/) {
228 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
233 ## ----------------------------------------------------------------------
234 ## HTML aware string manipulation
239 my $add_len = shift || 10;
241 # allow only $len chars, but don't cut a word if it would fit in $add_len
242 # if it doesn't fit, cut it if it's still longer than the dots we would add
243 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
246 if (length($tail) > 4) {
248 $body =~ s/&[^;]*$//; # remove chopped character entities
253 ## ----------------------------------------------------------------------
254 ## functions returning short strings
256 # CSS class for given age value (in seconds)
260 if ($age < 60*60*2) {
262 } elsif ($age < 60*60*24*2) {
269 # convert age in seconds to "nn units ago" string
274 if ($age > 60*60*24*365*2) {
275 $age_str = (int $age/60/60/24/365);
276 $age_str .= " years ago";
277 } elsif ($age > 60*60*24*(365/12)*2) {
278 $age_str = int $age/60/60/24/(365/12);
279 $age_str .= " months ago";
280 } elsif ($age > 60*60*24*7*2) {
281 $age_str = int $age/60/60/24/7;
282 $age_str .= " weeks ago";
283 } elsif ($age > 60*60*24*2) {
284 $age_str = int $age/60/60/24;
285 $age_str .= " days ago";
286 } elsif ($age > 60*60*2) {
287 $age_str = int $age/60/60;
288 $age_str .= " hours ago";
289 } elsif ($age > 60*2) {
290 $age_str = int $age/60;
291 $age_str .= " min ago";
294 $age_str .= " sec ago";
296 $age_str .= " right now";
301 # convert file mode in octal to symbolic file mode string
303 my $mode = oct shift;
305 if (S_ISDIR
($mode & S_IFMT
)) {
307 } elsif (S_ISLNK
($mode)) {
309 } elsif (S_ISREG
($mode)) {
310 # git cares only about the executable bit
311 if ($mode & S_IXUSR
) {
321 # convert file mode in octal to file type string
323 my $mode = oct shift;
325 if (S_ISDIR
($mode & S_IFMT
)) {
327 } elsif (S_ISLNK
($mode)) {
329 } elsif (S_ISREG
($mode)) {
336 ## ----------------------------------------------------------------------
337 ## functions returning short HTML fragments, or transforming HTML fragments
338 ## which don't beling to other sections
340 # format line of commit message or tag comment
341 sub format_log_line_html
{
344 $line = esc_html
($line);
345 $line =~ s/ / /g;
346 if ($line =~ m/([0-9a-fA-F]{40})/) {
348 if (git_get_type
($hash_text) eq "commit") {
349 my $link = $cgi->a({-class => "text", -href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_text")}, $hash_text);
350 $line =~ s/$hash_text/$link/;
356 # format marker of refs pointing to given object
357 sub git_get_referencing
{
358 my ($refs, $id) = @_;
360 if (defined $refs->{$id}) {
361 return ' <span class="tag">' . esc_html
($refs->{$id}) . '</span>';
367 ## ----------------------------------------------------------------------
368 ## git utility subroutines, invoking git commands
370 # get HEAD ref of given project as hash
373 my $oENV = $ENV{'GIT_DIR'};
375 $ENV{'GIT_DIR'} = "$projectroot/$project";
376 if (open my $fd, "-|", $GIT, "rev-parse", "--verify", "HEAD") {
379 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
384 $ENV{'GIT_DIR'} = $oENV;
389 # get type of given object
393 open my $fd, "-|", $GIT, "cat-file", '-t', $hash or return;
400 sub git_get_project_config
{
403 return unless ($key);
404 $key =~ s/^gitweb\.//;
405 return if ($key =~ m/\W/);
407 my $val = qx($GIT repo
-config
--get gitweb
.$key);
411 sub git_get_project_config_bool
{
412 my $val = git_get_project_config
(@_);
413 if ($val and $val =~ m/true|yes|on/) {
416 return; # implicit false
419 # get hash of given path at given ref
420 sub git_get_hash_by_path
{
422 my $path = shift || return undef;
426 open my $fd, "-|", $GIT, "ls-tree", $base, "--", $path
427 or die_error
(undef, "Open git-ls-tree failed.");
429 close $fd or return undef;
431 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
432 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
436 ## ......................................................................
437 ## git utility functions, directly accessing git repository
439 # assumes that PATH is not symref
443 open my $fd, "$projectroot/$path" or return undef;
447 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
452 sub git_read_description
{
455 open my $fd, "$projectroot/$path/description" or return undef;
462 sub git_read_projects
{
465 if (-d
$projects_list) {
466 # search in directory
467 my $dir = $projects_list;
468 opendir my ($dh), $dir or return undef;
469 while (my $dir = readdir($dh)) {
470 if (-e
"$projectroot/$dir/HEAD") {
478 } elsif (-f
$projects_list) {
479 # read from file(url-encoded):
480 # 'git%2Fgit.git Linus+Torvalds'
481 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
482 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
483 open my ($fd), $projects_list or return undef;
484 while (my $line = <$fd>) {
486 my ($path, $owner) = split ' ', $line;
487 $path = unescape
($path);
488 $owner = unescape
($owner);
489 if (!defined $path) {
492 if (-e
"$projectroot/$path/HEAD") {
495 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
502 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
507 my $type = shift || "";
509 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
510 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
511 open my $fd, "$projectroot/$project/info/refs" or return;
512 while (my $line = <$fd>) {
514 # attention: for $type == "" it saves only last path part of ref name
515 # e.g. from 'refs/heads/jn/gitweb' it would leave only 'gitweb'
516 if ($line =~ m/^([0-9a-fA-F]{40})\t.*$type\/([^\
^]+)/) {
517 if (defined $refs{$1}) {
518 $refs{$1} .= " / $2";
528 ## ----------------------------------------------------------------------
529 ## parse to hash functions
533 my $tz = shift || "-0000";
536 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
537 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
538 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
539 $date{'hour'} = $hour;
540 $date{'minute'} = $min;
541 $date{'mday'} = $mday;
542 $date{'day'} = $days[$wday];
543 $date{'month'} = $months[$mon];
544 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
545 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
547 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
548 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
549 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
550 $date{'hour_local'} = $hour;
551 $date{'minute_local'} = $min;
552 $date{'tz_local'} = $tz;
561 open my $fd, "-|", $GIT, "cat-file", "tag", $tag_id or return;
562 $tag{'id'} = $tag_id;
563 while (my $line = <$fd>) {
565 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
567 } elsif ($line =~ m/^type (.+)$/) {
569 } elsif ($line =~ m/^tag (.+)$/) {
571 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
575 } elsif ($line =~ m/--BEGIN/) {
576 push @comment, $line;
578 } elsif ($line eq "") {
582 push @comment, <$fd>;
583 $tag{'comment'} = \
@comment;
585 if (!defined $tag{'name'}) {
591 sub git_read_commit
{
592 my $commit_id = shift;
593 my $commit_text = shift;
598 if (defined $commit_text) {
599 @commit_lines = @
$commit_text;
602 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", "--max-count=1", $commit_id or return;
603 @commit_lines = split '\n', <$fd>;
608 my $header = shift @commit_lines;
609 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
612 ($co{'id'}, my @parents) = split ' ', $header;
613 $co{'parents'} = \
@parents;
614 $co{'parent'} = $parents[0];
615 while (my $line = shift @commit_lines) {
616 last if $line eq "\n";
617 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
619 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
621 $co{'author_epoch'} = $2;
622 $co{'author_tz'} = $3;
623 if ($co{'author'} =~ m/^([^<]+) </) {
624 $co{'author_name'} = $1;
626 $co{'author_name'} = $co{'author'};
628 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
629 $co{'committer'} = $1;
630 $co{'committer_epoch'} = $2;
631 $co{'committer_tz'} = $3;
632 $co{'committer_name'} = $co{'committer'};
633 $co{'committer_name'} =~ s/ <.*//;
636 if (!defined $co{'tree'}) {
640 foreach my $title (@commit_lines) {
643 $co{'title'} = chop_str
($title, 80, 5);
644 # remove leading stuff of merges to make the interesting part visible
645 if (length($title) > 50) {
646 $title =~ s/^Automatic //;
647 $title =~ s/^merge (of|with) /Merge ... /i;
648 if (length($title) > 50) {
649 $title =~ s/(http|rsync):\/\///;
651 if (length($title) > 50) {
652 $title =~ s/(master|www|rsync)\.//;
654 if (length($title) > 50) {
655 $title =~ s/kernel.org:?//;
657 if (length($title) > 50) {
658 $title =~ s/\/pub\/scm//;
661 $co{'title_short'} = chop_str
($title, 50, 5);
665 # remove added spaces
666 foreach my $line (@commit_lines) {
669 $co{'comment'} = \
@commit_lines;
671 my $age = time - $co{'committer_epoch'};
673 $co{'age_string'} = age_string
($age);
674 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
675 if ($age > 60*60*24*7*2) {
676 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
677 $co{'age_string_age'} = $co{'age_string'};
679 $co{'age_string_date'} = $co{'age_string'};
680 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
685 ## ......................................................................
686 ## parse to array of hashes functions
693 my $pfxlen = length("$projectroot/$project/$ref_dir");
694 File
::Find
::find
(sub {
697 push @refs, substr($File::Find
::name
, $pfxlen + 1);
699 }, "$projectroot/$project/$ref_dir");
701 foreach my $ref_file (@refs) {
702 my $ref_id = git_read_hash
("$project/$ref_dir/$ref_file");
703 my $type = git_get_type
($ref_id) || next;
706 $ref_item{'type'} = $type;
707 $ref_item{'id'} = $ref_id;
708 $ref_item{'epoch'} = 0;
709 $ref_item{'age'} = "unknown";
710 if ($type eq "tag") {
711 my %tag = git_read_tag
($ref_id);
712 $ref_item{'comment'} = $tag{'comment'};
713 if ($tag{'type'} eq "commit") {
714 %co = git_read_commit
($tag{'object'});
715 $ref_item{'epoch'} = $co{'committer_epoch'};
716 $ref_item{'age'} = $co{'age_string'};
717 } elsif (defined($tag{'epoch'})) {
718 my $age = time - $tag{'epoch'};
719 $ref_item{'epoch'} = $tag{'epoch'};
720 $ref_item{'age'} = age_string
($age);
722 $ref_item{'reftype'} = $tag{'type'};
723 $ref_item{'name'} = $tag{'name'};
724 $ref_item{'refid'} = $tag{'object'};
725 } elsif ($type eq "commit"){
726 %co = git_read_commit
($ref_id);
727 $ref_item{'reftype'} = "commit";
728 $ref_item{'name'} = $ref_file;
729 $ref_item{'title'} = $co{'title'};
730 $ref_item{'refid'} = $ref_id;
731 $ref_item{'epoch'} = $co{'committer_epoch'};
732 $ref_item{'age'} = $co{'age_string'};
734 $ref_item{'reftype'} = $type;
735 $ref_item{'name'} = $ref_file;
736 $ref_item{'refid'} = $ref_id;
739 push @reflist, \
%ref_item;
742 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
746 ## ----------------------------------------------------------------------
747 ## filesystem-related functions
752 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
753 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
754 if (!defined $gcos) {
758 $owner =~ s/[,;].*$//;
759 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
762 ## ......................................................................
763 ## mimetype related functions
765 sub mimetype_guess_file
{
766 my $filename = shift;
768 -r
$mimemap or return undef;
771 open(MIME
, $mimemap) or return undef;
773 my ($mime, $exts) = split(/\t+/);
775 my @exts = split(/\s+/, $exts);
776 foreach my $ext (@exts) {
777 $mimemap{$ext} = $mime;
783 $filename =~ /\.(.*?)$/;
788 my $filename = shift;
790 $filename =~ /\./ or return undef;
792 if ($mimetypes_file) {
793 my $file = $mimetypes_file;
794 #$file =~ m#^/# or $file = "$projectroot/$path/$file";
795 $mime = mimetype_guess_file
($filename, $file);
797 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
801 sub git_blob_plain_mimetype
{
803 my $filename = shift;
806 my $mime = mimetype_guess
($filename);
807 $mime and return $mime;
811 return $default_blob_plain_mimetype unless $fd;
814 return 'text/plain' .
815 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
816 } elsif (! $filename) {
817 return 'application/octet-stream';
818 } elsif ($filename =~ m/\.png$/i) {
820 } elsif ($filename =~ m/\.gif$/i) {
822 } elsif ($filename =~ m/\.jpe?g$/i) {
825 return 'application/octet-stream';
829 ## ======================================================================
830 ## functions printing HTML: header, footer, error page
832 sub git_header_html
{
833 my $status = shift || "200 OK";
836 my $title = "$site_name git";
837 if (defined $project) {
838 $title .= " - $project";
839 if (defined $action) {
840 $title .= "/$action";
841 if (defined $file_name) {
842 $title .= " - $file_name";
843 if ($action eq "tree" && $file_name !~ m
|/$|) {
850 # require explicit support from the UA if we are to send the page as
851 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
852 # we have to do this because MSIE sometimes globs '*/*', pretending to
853 # support xhtml+xml but choking when it gets what it asked for.
854 if ($cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ && $cgi->Accept('application/xhtml
+xml
') != 0) {
855 $content_type = 'application
/xhtml
+xml
';
857 $content_type = 'text
/html
';
859 print $cgi->header(-type=>$content_type, -charset => 'utf
-8', -status=> $status, -expires => $expires);
861 <?xml version="1.0" encoding="utf-8"?>
862 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
863 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
864 <!-- git web interface v$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
865 <!-- git core binaries version $git_version -->
867 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
868 <meta name="robots" content="index, nofollow"/>
869 <title>$title</title>
870 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
875 print "<div class=\"page_header\">\n" .
876 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
877 "<img src=\"$my_uri?" . esc_param
("a=git-logo.png") . "\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
879 print $cgi->a({-href
=> esc_param
($home_link)}, "projects") . " / ";
880 if (defined $project) {
881 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, esc_html
($project));
882 if (defined $action) {
886 if (!defined $searchtext) {
890 if (defined $hash_base) {
891 $search_hash = $hash_base;
892 } elsif (defined $hash) {
893 $search_hash = $hash;
895 $search_hash = "HEAD";
897 $cgi->param("a", "search");
898 $cgi->param("h", $search_hash);
899 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
900 "<div class=\"search\">\n" .
901 $cgi->hidden(-name
=> "p") . "\n" .
902 $cgi->hidden(-name
=> "a") . "\n" .
903 $cgi->hidden(-name
=> "h") . "\n" .
904 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
906 $cgi->end_form() . "\n";
911 sub git_footer_html
{
912 print "<div class=\"page_footer\">\n";
913 if (defined $project) {
914 my $descr = git_read_description
($project);
915 if (defined $descr) {
916 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
918 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=rss"), -class => "rss_logo"}, "RSS") . "\n";
920 print $cgi->a({-href
=> "$my_uri?" . esc_param
("a=opml"), -class => "rss_logo"}, "OPML") . "\n";
928 my $status = shift || "403 Forbidden";
929 my $error = shift || "Malformed query, file missing or permission denied";
931 git_header_html
($status);
932 print "<div class=\"page_body\">\n" .
934 "$status - $error\n" .
941 ## ----------------------------------------------------------------------
942 ## functions printing or outputting HTML: navigation
945 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
946 $extra = '' if !defined $extra; # pager or formats
948 my @navs = qw(summary shortlog log commit commitdiff tree);
950 @navs = grep { $_ ne $suppress } @navs;
953 my %arg = map { $_, ''} @navs;
955 for (qw(commit commitdiff)) {
956 $arg{$_} = ";h=$head";
958 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
959 for (qw(shortlog log)) {
960 $arg{$_} = ";h=$head";
964 $arg{tree
} .= ";h=$treehead" if defined $treehead;
965 $arg{tree
} .= ";hb=$treebase" if defined $treebase;
967 print "<div class=\"page_nav\">\n" .
971 : $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$_$arg{$_}")}, "$_")
974 print "<br/>\n$extra<br/>\n" .
978 sub git_get_paging_nav
{
979 my ($action, $hash, $head, $page, $nrevs) = @_;
983 if ($hash ne $head || $page) {
984 $paging_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$action")}, "HEAD");
986 $paging_nav .= "HEAD";
990 $paging_nav .= " ⋅ " .
991 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$action;h=$hash;pg=" . ($page-1)),
992 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
994 $paging_nav .= " ⋅ prev";
997 if ($nrevs >= (100 * ($page+1)-1)) {
998 $paging_nav .= " ⋅ " .
999 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$action;h=$hash;pg=" . ($page+1)),
1000 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1002 $paging_nav .= " ⋅ next";
1008 ## ......................................................................
1009 ## functions printing or outputting HTML: div
1011 sub git_header_div
{
1012 my ($action, $title, $hash, $hash_base) = @_;
1015 $rest .= ";h=$hash" if $hash;
1016 $rest .= ";hb=$hash_base" if $hash_base;
1018 print "<div class=\"header\">\n" .
1019 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$action$rest"),
1020 -class => "title"}, $title ?
$title : $action) . "\n" .
1024 sub git_print_page_path
{
1028 if (!defined $name) {
1029 print "<div class=\"page_path\"><b>/</b></div>\n";
1030 } elsif (defined $type && $type eq 'blob') {
1031 print "<div class=\"page_path\"><b>" .
1032 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;f=$file_name")}, esc_html
($name)) . "</b><br/></div>\n";
1034 print "<div class=\"page_path\"><b>" . esc_html
($name) . "</b><br/></div>\n";
1038 ## ......................................................................
1039 ## functions printing large fragments of HTML
1041 sub git_shortlog_body
{
1042 # uses global variable $project
1043 my ($revlist, $from, $to, $refs, $extra) = @_;
1044 $from = 0 unless defined $from;
1045 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1047 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
1049 for (my $i = $from; $i <= $to; $i++) {
1050 my $commit = $revlist->[$i];
1051 #my $ref = defined $refs ? git_get_referencing($refs, $commit) : '';
1052 my $ref = git_get_referencing
($refs, $commit);
1053 my %co = git_read_commit
($commit);
1054 my %ad = date_str
($co{'author_epoch'});
1056 print "<tr class=\"dark\">\n";
1058 print "<tr class=\"light\">\n";
1061 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1062 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1063 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
1065 if (length($co{'title_short'}) < length($co{'title'})) {
1066 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"),
1067 -class => "list", -title
=> "$co{'title'}"},
1068 "<b>" . esc_html
($co{'title_short'}) . "$ref</b>");
1070 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"),
1072 "<b>" . esc_html
($co{'title'}) . "$ref</b>");
1075 "<td class=\"link\">" .
1076 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") . " | " .
1077 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1081 if (defined $extra) {
1083 "<td colspan=\"4\">$extra</td>\n" .
1090 # uses global variable $project
1091 my ($taglist, $from, $to, $extra) = @_;
1092 $from = 0 unless defined $from;
1093 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1095 print "<table class=\"tags\" cellspacing=\"0\">\n";
1097 for (my $i = $from; $i <= $to; $i++) {
1098 my $entry = $taglist->[$i];
1100 my $comment_lines = $tag{'comment'};
1101 my $comment = shift @
$comment_lines;
1103 if (defined $comment) {
1104 $comment_short = chop_str
($comment, 30, 5);
1107 print "<tr class=\"dark\">\n";
1109 print "<tr class=\"light\">\n";
1112 print "<td><i>$tag{'age'}</i></td>\n" .
1114 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"),
1115 -class => "list"}, "<b>" . esc_html
($tag{'name'}) . "</b>") .
1118 if (defined $comment) {
1119 if (length($comment_short) < length($comment)) {
1120 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}"),
1121 -class => "list", -title
=> $comment}, $comment_short);
1123 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}"),
1124 -class => "list"}, $comment);
1128 "<td class=\"selflink\">";
1129 if ($tag{'type'} eq "tag") {
1130 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, "tag");
1135 "<td class=\"link\">" . " | " .
1136 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1137 if ($tag{'reftype'} eq "commit") {
1138 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1139 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'refid'}")}, "log");
1140 } elsif ($tag{'reftype'} eq "blob") {
1141 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$tag{'refid'}")}, "raw");
1146 if (defined $extra) {
1148 "<td colspan=\"5\">$extra</td>\n" .
1154 sub git_heads_body
{
1155 # uses global variable $project
1156 my ($taglist, $head, $from, $to, $extra) = @_;
1157 $from = 0 unless defined $from;
1158 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1160 print "<table class=\"heads\" cellspacing=\"0\">\n";
1162 for (my $i = $from; $i <= $to; $i++) {
1163 my $entry = $taglist->[$i];
1165 my $curr = $tag{'id'} eq $head;
1167 print "<tr class=\"dark\">\n";
1169 print "<tr class=\"light\">\n";
1172 print "<td><i>$tag{'age'}</i></td>\n" .
1173 ($tag{'id'} eq $head ?
"<td class=\"current_head\">" : "<td>") .
1174 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}"),
1175 -class => "list"}, "<b>" . esc_html
($tag{'name'}) . "</b>") .
1177 "<td class=\"link\">" .
1178 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") . " | " .
1179 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'name'}")}, "log") .
1183 if (defined $extra) {
1185 "<td colspan=\"3\">$extra</td>\n" .
1191 ## ----------------------------------------------------------------------
1192 ## functions printing large fragments, format as one of arguments
1194 sub git_diff_print
{
1196 my $from_name = shift;
1198 my $to_name = shift;
1199 my $format = shift || "html";
1201 my $from_tmp = "/dev/null";
1202 my $to_tmp = "/dev/null";
1205 # create tmp from-file
1206 if (defined $from) {
1207 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
1208 open my $fd2, "> $from_tmp";
1209 open my $fd, "-|", $GIT, "cat-file", "blob", $from;
1216 # create tmp to-file
1218 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
1219 open my $fd2, "> $to_tmp";
1220 open my $fd, "-|", $GIT, "cat-file", "blob", $to;
1227 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
1228 if ($format eq "plain") {
1233 while (my $line = <$fd>) {
1235 my $char = substr($line, 0, 1);
1236 my $diff_class = "";
1238 $diff_class = " add";
1239 } elsif ($char eq "-") {
1240 $diff_class = " rem";
1241 } elsif ($char eq "@") {
1242 $diff_class = " chunk_header";
1243 } elsif ($char eq "\\") {
1247 while ((my $pos = index($line, "\t")) != -1) {
1248 if (my $count = (8 - (($pos-1) % 8))) {
1249 my $spaces = ' ' x
$count;
1250 $line =~ s/\t/$spaces/;
1253 print "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
1258 if (defined $from) {
1267 ## ======================================================================
1268 ## ======================================================================
1271 # git-logo (cached in browser for one day)
1273 binmode STDOUT
, ':raw';
1274 print $cgi->header(-type
=> 'image/png', -expires
=> '+1d');
1275 # cat git-logo.png | hexdump -e '16/1 " %02x" "\n"' | sed 's/ /\\x/g'
1276 print "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52" .
1277 "\x00\x00\x00\x48\x00\x00\x00\x1b\x04\x03\x00\x00\x00\x2d\xd9\xd4" .
1278 "\x2d\x00\x00\x00\x18\x50\x4c\x54\x45\xff\xff\xff\x60\x60\x5d\xb0" .
1279 "\xaf\xaa\x00\x80\x00\xce\xcd\xc7\xc0\x00\x00\xe8\xe8\xe6\xf7\xf7" .
1280 "\xf6\x95\x0c\xa7\x47\x00\x00\x00\x73\x49\x44\x41\x54\x28\xcf\x63" .
1281 "\x48\x67\x20\x04\x4a\x5c\x18\x0a\x08\x2a\x62\x53\x61\x20\x02\x08" .
1282 "\x0d\x69\x45\xac\xa1\xa1\x01\x30\x0c\x93\x60\x36\x26\x52\x91\xb1" .
1283 "\x01\x11\xd6\xe1\x55\x64\x6c\x6c\xcc\x6c\x6c\x0c\xa2\x0c\x70\x2a" .
1284 "\x62\x06\x2a\xc1\x62\x1d\xb3\x01\x02\x53\xa4\x08\xe8\x00\x03\x18" .
1285 "\x26\x56\x11\xd4\xe1\x20\x97\x1b\xe0\xb4\x0e\x35\x24\x71\x29\x82" .
1286 "\x99\x30\xb8\x93\x0a\x11\xb9\x45\x88\xc1\x8d\xa0\xa2\x44\x21\x06" .
1287 "\x27\x41\x82\x40\x85\xc1\x45\x89\x20\x70\x01\x00\xa4\x3d\x21\xc5" .
1288 "\x12\x1c\x9a\xfe\x00\x00\x00\x00\x49\x45\x4e\x44\xae\x42\x60\x82";
1291 sub git_project_list
{
1292 my $order = $cgi->param('o');
1293 if (defined $order && $order !~ m/project|descr|owner|age/) {
1294 die_error
(undef, "Invalid order parameter '$order'.");
1297 my @list = git_read_projects
();
1300 die_error
(undef, "No projects found.");
1302 foreach my $pr (@list) {
1303 my $head = git_read_head
($pr->{'path'});
1304 if (!defined $head) {
1307 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
1308 my %co = git_read_commit
($head);
1312 $pr->{'commit'} = \
%co;
1313 if (!defined $pr->{'descr'}) {
1314 my $descr = git_read_description
($pr->{'path'}) || "";
1315 $pr->{'descr'} = chop_str
($descr, 25, 5);
1317 if (!defined $pr->{'owner'}) {
1318 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
1320 push @projects, $pr;
1324 if (-f
$home_text) {
1325 print "<div class=\"index_include\">\n";
1326 open (my $fd, $home_text);
1331 print "<table class=\"project_list\">\n" .
1333 $order ||= "project";
1334 if ($order eq "project") {
1335 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
1336 print "<th>Project</th>\n";
1339 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=project"),
1340 -class => "header"}, "Project") .
1343 if ($order eq "descr") {
1344 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
1345 print "<th>Description</th>\n";
1348 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=descr"),
1349 -class => "header"}, "Description") .
1352 if ($order eq "owner") {
1353 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
1354 print "<th>Owner</th>\n";
1357 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=owner"),
1358 -class => "header"}, "Owner") .
1361 if ($order eq "age") {
1362 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
1363 print "<th>Last Change</th>\n";
1366 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=age"),
1367 -class => "header"}, "Last Change") .
1370 print "<th></th>\n" .
1373 foreach my $pr (@projects) {
1375 print "<tr class=\"dark\">\n";
1377 print "<tr class=\"light\">\n";
1380 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=summary"),
1381 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
1382 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
1383 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
1384 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" .
1385 $pr->{'commit'}{'age_string'} . "</td>\n" .
1386 "<td class=\"link\">" .
1387 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=summary")}, "summary") . " | " .
1388 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=shortlog")}, "shortlog") . " | " .
1389 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=log")}, "log") .
1398 my $descr = git_read_description
($project) || "none";
1399 my $head = git_read_head
($project);
1400 my %co = git_read_commit
($head);
1401 my %cd = date_str
($co{'committer_epoch'}, $co{'committer_tz'});
1404 if (-f
$projects_list) {
1405 open (my $fd , $projects_list);
1406 while (my $line = <$fd>) {
1408 my ($pr, $ow) = split ' ', $line;
1409 $pr = unescape
($pr);
1410 $ow = unescape
($ow);
1411 if ($pr eq $project) {
1412 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
1418 if (!defined $owner) {
1419 $owner = get_file_owner
("$projectroot/$project");
1422 my $refs = read_info_ref
();
1424 git_page_nav
('summary','', $head);
1426 print "<div class=\"title\"> </div>\n";
1427 print "<table cellspacing=\"0\">\n" .
1428 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
1429 "<tr><td>owner</td><td>$owner</td></tr>\n" .
1430 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
1433 open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_read_head
($project)
1434 or die_error
(undef, "Open git-rev-list failed.");
1435 my @revlist = map { chomp; $_ } <$fd>;
1437 git_header_div
('shortlog');
1438 git_shortlog_body
(\
@revlist, 0, 15, $refs,
1439 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "..."));
1441 my $taglist = git_read_refs
("refs/tags");
1442 if (defined @
$taglist) {
1443 git_header_div
('tags');
1444 git_tags_body
($taglist, 0, 15,
1445 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tags")}, "..."));
1448 my $headlist = git_read_refs
("refs/heads");
1449 if (defined @
$headlist) {
1450 git_header_div
('heads');
1451 git_heads_body
($headlist, $head, 0, 15,
1452 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=heads")}, "..."));
1459 my $head = git_read_head
($project);
1461 git_page_nav
('','', $head,undef,$head);
1462 my %tag = git_read_tag
($hash);
1463 git_header_div
('commit', esc_html
($tag{'name'}), $hash);
1464 print "<div class=\"title_text\">\n" .
1465 "<table cellspacing=\"0\">\n" .
1467 "<td>object</td>\n" .
1468 "<td>" . $cgi->a({-class => "list", -href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'object'}) . "</td>\n" .
1469 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'type'}) . "</td>\n" .
1471 if (defined($tag{'author'})) {
1472 my %ad = date_str
($tag{'epoch'}, $tag{'tz'});
1473 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
1474 print "<tr><td></td><td>" . $ad{'rfc2822'} . sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) . "</td></tr>\n";
1476 print "</table>\n\n" .
1478 print "<div class=\"page_body\">";
1479 my $comment = $tag{'comment'};
1480 foreach my $line (@
$comment) {
1481 print esc_html
($line) . "<br/>\n";
1490 die_error
(undef, "Permission denied.") if (!git_get_project_config_bool
('blame'));
1491 die_error
('404 Not Found', "File name not defined") if (!$file_name);
1492 $hash_base ||= git_read_head
($project);
1493 die_error
(undef, "Reading commit failed") unless ($hash_base);
1494 my %co = git_read_commit
($hash_base)
1495 or die_error
(undef, "Reading commit failed");
1496 if (!defined $hash) {
1497 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
1498 or die_error
(undef, "Error looking up file");
1500 $ftype = git_get_type
($hash);
1501 if ($ftype !~ "blob") {
1502 die_error
("400 Bad Request", "object is not a blob");
1504 open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base)
1505 or die_error
(undef, "Open git-blame failed.");
1508 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") .
1509 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;f=$file_name")}, "head");
1510 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1511 git_header_div
('commit', esc_html
($co{'title'}), $hash_base);
1512 git_print_page_path
($file_name, $ftype);
1513 my @rev_color = (qw(light dark));
1514 my $num_colors = scalar(@rev_color);
1515 my $current_color = 0;
1517 print "<div class=\"page_body\">\n";
1518 print "<table class=\"blame\">\n";
1519 print "<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n";
1521 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
1523 my $rev = substr($full_rev, 0, 8);
1527 if (!defined $last_rev) {
1528 $last_rev = $full_rev;
1529 } elsif ($last_rev ne $full_rev) {
1530 $last_rev = $full_rev;
1531 $current_color = ++$current_color % $num_colors;
1533 print "<tr class=\"$rev_color[$current_color]\">\n";
1534 print "<td class=\"sha1\">" .
1535 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$full_rev;f=$file_name")}, esc_html
($rev)) . "</td>\n";
1536 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" . esc_html
($lineno) . "</a></td>\n";
1537 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
1542 close $fd or print "Reading blob failed\n";
1548 die_error
('403 Permission denied', "Permission denied.") if (!git_get_project_config_bool
('blame'));
1549 die_error
('404 Not Found', "What file will it be, master?") if (!$file_name);
1550 $hash_base ||= git_read_head
($project);
1551 die_error
(undef, "Reading commit failed.") unless ($hash_base);
1552 my %co = git_read_commit
($hash_base)
1553 or die_error
(undef, "Reading commit failed.");
1554 if (!defined $hash) {
1555 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
1556 or die_error
(undef, "Error lookup file.");
1558 open ($fd, "-|", $GIT, "annotate", '-l', '-t', '-r', $file_name, $hash_base)
1559 or die_error
(undef, "Open git-annotate failed.");
1562 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") .
1563 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;f=$file_name")}, "head");
1564 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1565 git_header_div
('commit', esc_html
($co{'title'}), $hash_base);
1566 git_print_page_path
($file_name, 'blob');
1567 print "<div class=\"page_body\">\n";
1569 <table class="blame">
1578 my @line_class = (qw(light dark));
1579 my $line_class_len = scalar (@line_class);
1580 my $line_class_num = $#line_class;
1581 while (my $line = <$fd>) {
1593 $line_class_num = ($line_class_num + 1) % $line_class_len;
1595 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) \+\d\d\d\d\t(\d+)\)(.*)$/) {
1602 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
1605 $short_rev = substr ($long_rev, 0, 8);
1606 $age = time () - $time;
1607 $age_str = age_string
($age);
1608 $age_str =~ s/ / /g;
1609 $age_class = age_class
($age);
1610 $author = esc_html
($author);
1611 $author =~ s/ / /g;
1613 while ((my $pos = index($data, "\t")) != -1) {
1614 if (my $count = (8 - ($pos % 8))) {
1615 my $spaces = ' ' x
$count;
1616 $data =~ s/\t/$spaces/;
1619 $data = esc_html
($data);
1622 <tr class="$line_class[$line_class_num]">
1623 <td class="sha1"><a href="$my_uri?${\esc_param ("p=$project;a=commit;h=$long_rev")}" class="text">$short_rev..</a></td>
1624 <td class="$age_class">$age_str</td>
1626 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
1627 <td class="pre">$data</td>
1630 } # while (my $line = <$fd>)
1631 print "</table>\n\n";
1632 close $fd or print "Reading blob failed.\n";
1638 my $head = git_read_head
($project);
1640 git_page_nav
('','', $head,undef,$head);
1641 git_header_div
('summary', $project);
1643 my $taglist = git_read_refs
("refs/tags");
1644 if (defined @
$taglist) {
1645 git_tags_body
($taglist);
1651 my $head = git_read_head
($project);
1653 git_page_nav
('','', $head,undef,$head);
1654 git_header_div
('summary', $project);
1656 my $taglist = git_read_refs
("refs/heads");
1658 if (defined @
$taglist) {
1659 git_heads_body
($taglist, $head);
1664 sub git_blob_plain
{
1665 if (!defined $hash) {
1666 if (defined $file_name) {
1667 my $base = $hash_base || git_read_head
($project);
1668 $hash = git_get_hash_by_path
($base, $file_name, "blob")
1669 or die_error
(undef, "Error lookup file.");
1671 die_error
(undef, "No file name defined.");
1675 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
1676 or die_error
("Couldn't cat $file_name, $hash");
1678 $type ||= git_blob_plain_mimetype
($fd, $file_name);
1680 # save as filename, even when no $file_name is given
1681 my $save_as = "$hash";
1682 if (defined $file_name) {
1683 $save_as = $file_name;
1684 } elsif ($type =~ m/^text\//) {
1688 print $cgi->header(-type
=> "$type", '-content-disposition' => "inline; filename=\"$save_as\"");
1690 binmode STDOUT
, ':raw';
1692 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
1698 if (!defined $hash) {
1699 if (defined $file_name) {
1700 my $base = $hash_base || git_read_head
($project);
1701 $hash = git_get_hash_by_path
($base, $file_name, "blob")
1702 or die_error
(undef, "Error lookup file.");
1704 die_error
(undef, "No file name defined.");
1707 my $have_blame = git_get_project_config_bool
('blame');
1708 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
1709 or die_error
(undef, "Couldn't cat $file_name, $hash.");
1710 my $mimetype = git_blob_plain_mimetype
($fd, $file_name);
1711 if ($mimetype !~ m/^text\//) {
1713 return git_blob_plain
($mimetype);
1716 my $formats_nav = '';
1717 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
1718 if (defined $file_name) {
1720 $formats_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;h=$hash;hb=$hash_base;f=$file_name")}, "blame") . " | ";
1723 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$hash;f=$file_name")}, "plain") .
1724 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;hb=HEAD;f=$file_name")}, "head");
1726 $formats_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$hash")}, "plain");
1728 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1729 git_header_div
('commit', esc_html
($co{'title'}), $hash_base);
1731 print "<div class=\"page_nav\">\n" .
1732 "<br/><br/></div>\n" .
1733 "<div class=\"title\">$hash</div>\n";
1735 git_print_page_path
($file_name, "blob");
1736 print "<div class=\"page_body\">\n";
1738 while (my $line = <$fd>) {
1741 while ((my $pos = index($line, "\t")) != -1) {
1742 if (my $count = (8 - ($pos % 8))) {
1743 my $spaces = ' ' x
$count;
1744 $line =~ s/\t/$spaces/;
1747 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", $nr, $nr, $nr, esc_html
($line);
1749 close $fd or print "Reading blob failed.\n";
1755 if (!defined $hash) {
1756 $hash = git_read_head
($project);
1757 if (defined $file_name) {
1758 my $base = $hash_base || $hash;
1759 $hash = git_get_hash_by_path
($base, $file_name, "tree");
1761 if (!defined $hash_base) {
1766 open my $fd, "-|", $GIT, "ls-tree", '-z', $hash
1767 or die_error
(undef, "Open git-ls-tree failed.");
1768 my @entries = map { chomp; $_ } <$fd>;
1769 close $fd or die_error
(undef, "Reading tree failed.");
1772 my $refs = read_info_ref
();
1773 my $ref = git_get_referencing
($refs, $hash_base);
1777 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
1778 $base_key = ";hb=$hash_base";
1779 git_page_nav
('tree','', $hash_base);
1780 git_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
1782 print "<div class=\"page_nav\">\n";
1783 print "<br/><br/></div>\n";
1784 print "<div class=\"title\">$hash</div>\n";
1786 if (defined $file_name) {
1787 $base = esc_html
("$file_name/");
1789 git_print_page_path
($file_name, 'tree');
1790 print "<div class=\"page_body\">\n";
1791 print "<table cellspacing=\"0\">\n";
1793 foreach my $line (@entries) {
1794 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1795 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1799 my $t_name = validate_input
($4);
1801 print "<tr class=\"dark\">\n";
1803 print "<tr class=\"light\">\n";
1806 print "<td class=\"mode\">" . mode_str
($t_mode) . "</td>\n";
1807 if ($t_type eq "blob") {
1808 print "<td class=\"list\">" .
1809 $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)) .
1811 "<td class=\"link\">" .
1812 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name")}, "blob") .
1813 # " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$t_hash$base_key;f=$base$t_name")}, "blame") .
1814 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;h=$t_hash;hb=$hash_base;f=$base$t_name")}, "history") .
1815 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$t_hash;f=$base$t_name")}, "raw") .
1817 } elsif ($t_type eq "tree") {
1818 print "<td class=\"list\">" .
1819 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, esc_html
($t_name)) .
1821 "<td class=\"link\">" .
1822 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, "tree") .
1823 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;hb=$hash_base;f=$base$t_name")}, "history") .
1828 print "</table>\n" .
1834 my $head = git_read_head
($project);
1835 if (!defined $hash) {
1838 if (!defined $page) {
1841 my $refs = read_info_ref
();
1843 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
1844 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
1845 or die_error
(undef, "Open git-rev-list failed.");
1846 my @revlist = map { chomp; $_ } <$fd>;
1849 my $paging_nav = git_get_paging_nav
('log', $hash, $head, $page, $#revlist);
1852 git_page_nav
('log','', $hash,undef,undef, $paging_nav);
1855 my %co = git_read_commit
($hash);
1857 git_header_div
('summary', $project);
1858 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
1860 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
1861 my $commit = $revlist[$i];
1862 my $ref = git_get_referencing
($refs, $commit);
1863 my %co = git_read_commit
($commit);
1865 my %ad = date_str
($co{'author_epoch'});
1866 git_header_div
('commit',
1867 "<span class=\"age\">$co{'age_string'}</span>" .
1868 esc_html
($co{'title'}) . $ref,
1870 print "<div class=\"title_text\">\n" .
1871 "<div class=\"log_link\">\n" .
1872 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
1873 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1876 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
1878 "<div class=\"log_body\">\n";
1879 my $comment = $co{'comment'};
1881 foreach my $line (@
$comment) {
1882 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1893 print format_log_line_html
($line) . "<br/>\n";
1904 my %co = git_read_commit
($hash);
1906 die_error
(undef, "Unknown commit object.");
1908 my %ad = date_str
($co{'author_epoch'}, $co{'author_tz'});
1909 my %cd = date_str
($co{'committer_epoch'}, $co{'committer_tz'});
1911 my $parent = $co{'parent'};
1912 if (!defined $parent) {
1915 open my $fd, "-|", $GIT, "diff-tree", '-r', '-M', $parent, $hash
1916 or die_error
(undef, "Open git-diff-tree failed.");
1917 my @difftree = map { chomp; $_ } <$fd>;
1918 close $fd or die_error
(undef, "Reading git-diff-tree failed.");
1920 # non-textual hash id's can be cached
1922 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
1925 my $refs = read_info_ref
();
1926 my $ref = git_get_referencing
($refs, $co{'id'});
1927 my $formats_nav = '';
1928 if (defined $file_name && defined $co{'parent'}) {
1929 my $parent = $co{'parent'};
1930 $formats_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;hb=$parent;f=$file_name")}, "blame");
1932 git_header_html
(undef, $expires);
1933 git_page_nav
('commit', defined $co{'parent'} ?
'' : 'commitdiff',
1934 $hash, $co{'tree'}, $hash,
1937 if (defined $co{'parent'}) {
1938 git_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
1940 git_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
1942 print "<div class=\"title_text\">\n" .
1943 "<table cellspacing=\"0\">\n";
1944 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
1946 "<td></td><td> $ad{'rfc2822'}";
1947 if ($ad{'hour_local'} < 6) {
1948 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1950 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1954 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
1955 print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
1956 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
1959 "<td class=\"sha1\">" .
1960 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash"), class => "list"}, $co{'tree'}) .
1962 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
1965 my $parents = $co{'parents'};
1966 foreach my $par (@
$parents) {
1969 "<td class=\"sha1\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$par"), class => "list"}, $par) . "</td>" .
1970 "<td class=\"link\">" .
1971 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$par")}, "commit") .
1972 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash;hp=$par")}, "commitdiff") .
1978 print "<div class=\"page_body\">\n";
1979 my $comment = $co{'comment'};
1982 foreach my $line (@
$comment) {
1983 # print only one empty line
1985 if ($empty || $signed) {
1992 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1994 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1997 print format_log_line_html
($line) . "<br/>\n";
2001 print "<div class=\"list_head\">\n";
2002 if ($#difftree > 10) {
2003 print(($#difftree + 1) . " files changed:\n");
2006 print "<table class=\"diff_tree\">\n";
2008 foreach my $line (@difftree) {
2009 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2010 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2011 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
2019 my $similarity = $6;
2020 my $file = validate_input
(unquote
($7));
2022 print "<tr class=\"dark\">\n";
2024 print "<tr class=\"light\">\n";
2027 if ($status eq "A") {
2029 if (S_ISREG
(oct $to_mode)) {
2030 $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
2033 $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" .
2034 "<td><span class=\"file_status new\">[new " . file_type
($to_mode) . "$mode_chng]</span></td>\n" .
2035 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob") . "</td>\n";
2036 } elsif ($status eq "D") {
2038 $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" .
2039 "<td><span class=\"file_status deleted\">[deleted " . file_type
($from_mode). "]</span></td>\n" .
2040 "<td class=\"link\">" .
2041 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, "blob") .
2042 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;hb=$hash;f=$file")}, "history") .
2044 } elsif ($status eq "M" || $status eq "T") {
2045 my $mode_chnge = "";
2046 if ($from_mode != $to_mode) {
2047 $mode_chnge = " <span class=\"file_status mode_chnge\">[changed";
2048 if (((oct $from_mode) & S_IFMT
) != ((oct $to_mode) & S_IFMT
)) {
2049 $mode_chnge .= " from " . file_type
($from_mode) . " to " . file_type
($to_mode);
2051 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
2052 if (S_ISREG
($from_mode) && S_ISREG
($to_mode)) {
2053 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
2054 } elsif (S_ISREG
($to_mode)) {
2055 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
2058 $mode_chnge .= "]</span>\n";
2061 if ($to_id ne $from_id) {
2062 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));
2064 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file"), -class => "list"}, esc_html
($file));
2067 "<td>$mode_chnge</td>\n" .
2068 "<td class=\"link\">";
2069 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob");
2070 if ($to_id ne $from_id) {
2071 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file")}, "diff");
2073 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;hb=$hash;f=$file")}, "history") . "\n";
2075 } elsif ($status eq "R") {
2076 my ($from_file, $to_file) = split "\t", $file;
2078 if ($from_mode != $to_mode) {
2079 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
2082 $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" .
2083 "<td><span class=\"file_status moved\">[moved from " .
2084 $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)) .
2085 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
2086 "<td class=\"link\">" .
2087 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file")}, "blob");
2088 if ($to_id ne $from_id) {
2089 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file")}, "diff");
2100 mkdir($git_temp, 0700);
2102 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
2104 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff_plain;h=$hash;hp=$hash_parent")}, "plain");
2105 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2106 git_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2108 print "<div class=\"page_nav\">\n" .
2109 "<br/><br/></div>\n" .
2110 "<div class=\"title\">$hash vs $hash_parent</div>\n";
2112 git_print_page_path
($file_name, "blob");
2113 print "<div class=\"page_body\">\n" .
2114 "<div class=\"diff_info\">blob:" .
2115 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name")}, $hash_parent) .
2117 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, $hash) .
2119 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
2124 sub git_blobdiff_plain
{
2125 mkdir($git_temp, 0700);
2126 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8');
2127 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
2130 sub git_commitdiff
{
2131 mkdir($git_temp, 0700);
2132 my %co = git_read_commit
($hash);
2134 die_error
(undef, "Unknown commit object.");
2136 if (!defined $hash_parent) {
2137 $hash_parent = $co{'parent'};
2139 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2140 or die_error
(undef, "Open git-diff-tree failed.");
2141 my @difftree = map { chomp; $_ } <$fd>;
2142 close $fd or die_error
(undef, "Reading diff-tree failed.");
2144 # non-textual hash id's can be cached
2146 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2149 my $refs = read_info_ref
();
2150 my $ref = git_get_referencing
($refs, $co{'id'});
2152 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent")}, "plain");
2153 git_header_html
(undef, $expires);
2154 git_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
2155 git_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
2156 print "<div class=\"page_body\">\n";
2157 my $comment = $co{'comment'};
2160 my @log = @
$comment;
2161 # remove first and empty lines after that
2163 while (defined $log[0] && $log[0] eq "") {
2166 foreach my $line (@log) {
2167 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2178 print format_log_line_html
($line) . "<br/>\n";
2181 foreach my $line (@difftree) {
2182 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2183 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2184 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2190 my $file = validate_input
(unquote
($6));
2191 if ($status eq "A") {
2192 print "<div class=\"diff_info\">" . file_type
($to_mode) . ":" .
2193 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id) . "(new)" .
2195 git_diff_print
(undef, "/dev/null", $to_id, "b/$file");
2196 } elsif ($status eq "D") {
2197 print "<div class=\"diff_info\">" . file_type
($from_mode) . ":" .
2198 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) . "(deleted)" .
2200 git_diff_print
($from_id, "a/$file", undef, "/dev/null");
2201 } elsif ($status eq "M") {
2202 if ($from_id ne $to_id) {
2203 print "<div class=\"diff_info\">" .
2204 file_type
($from_mode) . ":" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) .
2206 file_type
($to_mode) . ":" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id);
2208 git_diff_print
($from_id, "a/$file", $to_id, "b/$file");
2217 sub git_commitdiff_plain
{
2218 mkdir($git_temp, 0700);
2219 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2220 or die_error
(undef, "Open git-diff-tree failed.");
2221 my @difftree = map { chomp; $_ } <$fd>;
2222 close $fd or die_error
(undef, "Reading diff-tree failed.");
2224 # try to figure out the next tag after this commit
2226 my $refs = read_info_ref
("tags");
2227 open $fd, "-|", $GIT, "rev-list", "HEAD";
2228 my @commits = map { chomp; $_ } <$fd>;
2230 foreach my $commit (@commits) {
2231 if (defined $refs->{$commit}) {
2232 $tagname = $refs->{$commit}
2234 if ($commit eq $hash) {
2239 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8', '-content-disposition' => "inline; filename=\"git-$hash.patch\"");
2240 my %co = git_read_commit
($hash);
2241 my %ad = date_str
($co{'author_epoch'}, $co{'author_tz'});
2242 my $comment = $co{'comment'};
2243 print "From: $co{'author'}\n" .
2244 "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
2245 "Subject: $co{'title'}\n";
2246 if (defined $tagname) {
2247 print "X-Git-Tag: $tagname\n";
2249 print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
2252 foreach my $line (@
$comment) {;
2257 foreach my $line (@difftree) {
2258 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2263 if ($status eq "A") {
2264 git_diff_print
(undef, "/dev/null", $to_id, "b/$file", "plain");
2265 } elsif ($status eq "D") {
2266 git_diff_print
($from_id, "a/$file", undef, "/dev/null", "plain");
2267 } elsif ($status eq "M") {
2268 git_diff_print
($from_id, "a/$file", $to_id, "b/$file", "plain");
2274 if (!defined $hash_base) {
2275 $hash_base = git_read_head
($project);
2278 my %co = git_read_commit
($hash_base);
2280 die_error
(undef, "Unknown commit object.");
2282 my $refs = read_info_ref
();
2284 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base);
2285 git_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2286 if (!defined $hash && defined $file_name) {
2287 $hash = git_get_hash_by_path
($hash_base, $file_name);
2289 if (defined $hash) {
2290 $ftype = git_get_type
($hash);
2292 git_print_page_path
($file_name, $ftype);
2295 $GIT, "rev-list", "--full-history", $hash_base, "--", $file_name;
2296 print "<table cellspacing=\"0\">\n";
2298 while (my $line = <$fd>) {
2299 if ($line =~ m/^([0-9a-fA-F]{40})/){
2301 my %co = git_read_commit
($commit);
2305 my $ref = git_get_referencing
($refs, $commit);
2307 print "<tr class=\"dark\">\n";
2309 print "<tr class=\"light\">\n";
2312 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2313 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2314 "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list"}, "<b>" .
2315 esc_html
(chop_str
($co{'title'}, 50)) . "$ref</b>") . "</td>\n" .
2316 "<td class=\"link\">" .
2317 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
2318 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2319 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$ftype;hb=$commit;f=$file_name")}, $ftype);
2320 my $blob = git_get_hash_by_path
($hash_base, $file_name);
2321 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2322 if (defined $blob && defined $blob_parent && $blob ne $blob_parent) {
2324 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=$file_name")},
2337 if (!defined $searchtext) {
2338 die_error
("", "Text field empty.");
2340 if (!defined $hash) {
2341 $hash = git_read_head
($project);
2343 my %co = git_read_commit
($hash);
2345 die_error
(undef, "Unknown commit object.");
2347 # pickaxe may take all resources of your box and run for several minutes
2348 # with every query - so decide by yourself how public you make this feature :)
2349 my $commit_search = 1;
2350 my $author_search = 0;
2351 my $committer_search = 0;
2352 my $pickaxe_search = 0;
2353 if ($searchtext =~ s/^author\\://i) {
2355 } elsif ($searchtext =~ s/^committer\\://i) {
2356 $committer_search = 1;
2357 } elsif ($searchtext =~ s/^pickaxe\\://i) {
2359 $pickaxe_search = 1;
2362 git_page_nav
('','', $hash,$co{'tree'},$hash);
2363 git_header_div
('commit', esc_html
($co{'title'}), $hash);
2365 print "<table cellspacing=\"0\">\n";
2367 if ($commit_search) {
2369 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", $hash or next;
2370 while (my $commit_text = <$fd>) {
2371 if (!grep m/$searchtext/i, $commit_text) {
2374 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
2377 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
2380 my @commit_lines = split "\n", $commit_text;
2381 my %co = git_read_commit
(undef, \
@commit_lines);
2386 print "<tr class=\"dark\">\n";
2388 print "<tr class=\"light\">\n";
2391 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2392 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2394 $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/>");
2395 my $comment = $co{'comment'};
2396 foreach my $line (@
$comment) {
2397 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2398 my $lead = esc_html
($1) || "";
2399 $lead = chop_str
($lead, 30, 10);
2400 my $match = esc_html
($2) || "";
2401 my $trail = esc_html
($3) || "";
2402 $trail = chop_str
($trail, 30, 10);
2403 my $text = "$lead<span class=\"match\">$match</span>$trail";
2404 print chop_str
($text, 80, 5) . "<br/>\n";
2408 "<td class=\"link\">" .
2409 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2410 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2417 if ($pickaxe_search) {
2419 open my $fd, "-|", "$GIT rev-list $hash | $GIT diff-tree -r --stdin -S\'$searchtext\'";
2422 while (my $line = <$fd>) {
2423 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2426 $set{'from_id'} = $3;
2428 $set{'id'} = $set{'to_id'};
2429 if ($set{'id'} =~ m/0{40}/) {
2430 $set{'id'} = $set{'from_id'};
2432 if ($set{'id'} =~ m/0{40}/) {
2436 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
2439 print "<tr class=\"dark\">\n";
2441 print "<tr class=\"light\">\n";
2444 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2445 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2447 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" .
2448 esc_html
(chop_str
($co{'title'}, 50)) . "</b><br/>");
2449 while (my $setref = shift @files) {
2451 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}"), class => "list"},
2452 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
2456 "<td class=\"link\">" .
2457 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2458 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2462 %co = git_read_commit
($1);
2472 my $head = git_read_head
($project);
2473 if (!defined $hash) {
2476 if (!defined $page) {
2479 my $refs = read_info_ref
();
2481 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2482 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2483 or die_error
(undef, "Open git-rev-list failed.");
2484 my @revlist = map { chomp; $_ } <$fd>;
2487 my $paging_nav = git_get_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
2489 if ($#revlist >= (100 * ($page+1)-1)) {
2491 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)),
2492 -title
=> "Alt-n"}, "next");
2497 git_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
2498 git_header_div
('summary', $project);
2500 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
2505 ## ......................................................................
2506 ## feeds (RSS, OPML)
2509 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
2510 open my $fd, "-|", $GIT, "rev-list", "--max-count=150", git_read_head
($project)
2511 or die_error
(undef, "Open git-rev-list failed.");
2512 my @revlist = map { chomp; $_ } <$fd>;
2513 close $fd or die_error
(undef, "Reading rev-list failed.");
2514 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
2515 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
2516 "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
2517 print "<channel>\n";
2518 print "<title>$project</title>\n".
2519 "<link>" . esc_html
("$my_url?p=$project;a=summary") . "</link>\n".
2520 "<description>$project log</description>\n".
2521 "<language>en</language>\n";
2523 for (my $i = 0; $i <= $#revlist; $i++) {
2524 my $commit = $revlist[$i];
2525 my %co = git_read_commit
($commit);
2526 # we read 150, we always show 30 and the ones more recent than 48 hours
2527 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
2530 my %cd = date_str
($co{'committer_epoch'});
2531 open $fd, "-|", $GIT, "diff-tree", '-r', $co{'parent'}, $co{'id'} or next;
2532 my @difftree = map { chomp; $_ } <$fd>;
2536 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
2538 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
2539 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
2540 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
2541 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
2542 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
2543 "<content:encoded>" .
2545 my $comment = $co{'comment'};
2546 foreach my $line (@
$comment) {
2547 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
2548 print "$line<br/>\n";
2551 foreach my $line (@difftree) {
2552 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
2555 my $file = validate_input
(unquote
($7));
2556 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
2557 print "$file<br/>\n";
2560 "</content:encoded>\n" .
2563 print "</channel></rss>";
2567 my @list = git_read_projects
();
2569 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
2570 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
2571 "<opml version=\"1.0\">\n".
2573 " <title>$site_name Git OPML Export</title>\n".
2576 "<outline text=\"git RSS feeds\">\n";
2578 foreach my $pr (@list) {
2580 my $head = git_read_head
($proj{'path'});
2581 if (!defined $head) {
2584 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
2585 my %co = git_read_commit
($head);
2590 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
2591 my $rss = "$my_url?p=$proj{'path'};a=rss";
2592 my $html = "$my_url?p=$proj{'path'};a=summary";
2593 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
2595 print "</outline>\n".