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';
21 our $version = "@@GIT_VERSION@@";
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 = "@@GIT_BINDIR@@/git";
30 # absolute fs-path which will be prepended to the project path
31 #our $projectroot = "/pub/scm";
32 our $projectroot = "@@GITWEB_PROJECTROOT@@";
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 = "@@GITWEB_SITENAME@@" || $ENV{'SERVER_NAME'} || "Untitled";
50 # html text to include at home page
51 our $home_text = "@@GITWEB_HOMETEXT@@";
53 # URI of default stylesheet
54 our $stylesheet = "@@GITWEB_CSS@@";
56 our $logo = "@@GITWEB_LOGO@@";
58 # source of projects list
59 our $projects_list = "@@GITWEB_LIST@@" || "$projectroot";
61 # default blob_plain mimetype and default charset for text/plain blob
62 our $default_blob_plain_mimetype = 'text/plain';
63 our $default_text_plain_charset = undef;
65 # file to use for guessing MIME types before trying /etc/mime.types
66 # (relative to the current git repository)
67 our $mimetypes_file = undef;
69 # input validation and dispatch
70 our $action = $cgi->param('a');
71 if (defined $action) {
72 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
74 die_error
(undef, "Invalid action parameter.");
76 if ($action eq "opml") {
82 our $project = ($cgi->param('p') || $ENV{'PATH_INFO'});
83 if (defined $project) {
84 $project =~ s
|^/||; $project =~ s|/$||;
85 $project = validate_input
($project);
86 if (!defined($project)) {
87 die_error
(undef, "Invalid project parameter.");
89 if (!(-d
"$projectroot/$project")) {
91 die_error
(undef, "No such directory.");
93 if (!(-e
"$projectroot/$project/HEAD")) {
95 die_error
(undef, "No such project.");
97 $rss_link = "<link rel=\"alternate\" title=\"" . esc_param
($project) . " log\" href=\"" .
98 "$my_uri?" . esc_param
("p=$project;a=rss") . "\" type=\"application/rss+xml\"/>";
99 $ENV{'GIT_DIR'} = "$projectroot/$project";
105 our $file_name = $cgi->param('f');
106 if (defined $file_name) {
107 $file_name = validate_input
($file_name);
108 if (!defined($file_name)) {
109 die_error
(undef, "Invalid file parameter.");
113 our $hash = $cgi->param('h');
115 $hash = validate_input
($hash);
116 if (!defined($hash)) {
117 die_error
(undef, "Invalid hash parameter.");
121 our $hash_parent = $cgi->param('hp');
122 if (defined $hash_parent) {
123 $hash_parent = validate_input
($hash_parent);
124 if (!defined($hash_parent)) {
125 die_error
(undef, "Invalid hash parent parameter.");
129 our $hash_base = $cgi->param('hb');
130 if (defined $hash_base) {
131 $hash_base = validate_input
($hash_base);
132 if (!defined($hash_base)) {
133 die_error
(undef, "Invalid hash base parameter.");
137 our $page = $cgi->param('pg');
139 if ($page =~ m/[^0-9]$/) {
141 die_error
(undef, "Invalid page parameter.");
145 our $searchtext = $cgi->param('s');
146 if (defined $searchtext) {
147 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
149 die_error
(undef, "Invalid search parameter.");
151 $searchtext = quotemeta $searchtext;
156 "blame" => \
&git_blame2
,
157 "blobdiff" => \
&git_blobdiff
,
158 "blobdiff_plain" => \
&git_blobdiff_plain
,
159 "blob" => \
&git_blob
,
160 "blob_plain" => \
&git_blob_plain
,
161 "commitdiff" => \
&git_commitdiff
,
162 "commitdiff_plain" => \
&git_commitdiff_plain
,
163 "commit" => \
&git_commit
,
164 "heads" => \
&git_heads
,
165 "history" => \
&git_history
,
168 "search" => \
&git_search
,
169 "shortlog" => \
&git_shortlog
,
170 "summary" => \
&git_summary
,
172 "tags" => \
&git_tags
,
173 "tree" => \
&git_tree
,
176 $action = 'summary' if (!defined($action));
177 if (!defined($actions{$action})) {
179 die_error
(undef, "Unknown action.");
181 $actions{$action}->();
184 ## ======================================================================
185 ## validation, quoting/unquoting and escaping
190 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
193 if ($input =~ m/(^|\/)(|\
.|\
.\
.)($|\
/)/) {
196 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\
-\
+\#\
~\
%]/) {
202 # quote unsafe chars, but keep the slash, even when it's not
203 # correct, but quoted slashes look too horrible in bookmarks
206 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
212 # replace invalid utf8 character with SUBSTITUTION sequence
215 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
216 $str = escapeHTML
($str);
217 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
221 # git may return quoted and escaped filenames
224 if ($str =~ m/^"(.*)"$/) {
226 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
231 ## ----------------------------------------------------------------------
232 ## HTML aware string manipulation
237 my $add_len = shift || 10;
239 # allow only $len chars, but don't cut a word if it would fit in $add_len
240 # if it doesn't fit, cut it if it's still longer than the dots we would add
241 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
244 if (length($tail) > 4) {
246 $body =~ s/&[^;]*$//; # remove chopped character entities
251 ## ----------------------------------------------------------------------
252 ## functions returning short strings
254 # CSS class for given age value (in seconds)
258 if ($age < 60*60*2) {
260 } elsif ($age < 60*60*24*2) {
267 # convert age in seconds to "nn units ago" string
272 if ($age > 60*60*24*365*2) {
273 $age_str = (int $age/60/60/24/365);
274 $age_str .= " years ago";
275 } elsif ($age > 60*60*24*(365/12)*2) {
276 $age_str = int $age/60/60/24/(365/12);
277 $age_str .= " months ago";
278 } elsif ($age > 60*60*24*7*2) {
279 $age_str = int $age/60/60/24/7;
280 $age_str .= " weeks ago";
281 } elsif ($age > 60*60*24*2) {
282 $age_str = int $age/60/60/24;
283 $age_str .= " days ago";
284 } elsif ($age > 60*60*2) {
285 $age_str = int $age/60/60;
286 $age_str .= " hours ago";
287 } elsif ($age > 60*2) {
288 $age_str = int $age/60;
289 $age_str .= " min ago";
292 $age_str .= " sec ago";
294 $age_str .= " right now";
299 # convert file mode in octal to symbolic file mode string
301 my $mode = oct shift;
303 if (S_ISDIR
($mode & S_IFMT
)) {
305 } elsif (S_ISLNK
($mode)) {
307 } elsif (S_ISREG
($mode)) {
308 # git cares only about the executable bit
309 if ($mode & S_IXUSR
) {
319 # convert file mode in octal to file type string
321 my $mode = oct shift;
323 if (S_ISDIR
($mode & S_IFMT
)) {
325 } elsif (S_ISLNK
($mode)) {
327 } elsif (S_ISREG
($mode)) {
334 ## ----------------------------------------------------------------------
335 ## functions returning short HTML fragments, or transforming HTML fragments
336 ## which don't beling to other sections
338 # format line of commit message or tag comment
339 sub format_log_line_html
{
342 $line = esc_html
($line);
343 $line =~ s/ / /g;
344 if ($line =~ m/([0-9a-fA-F]{40})/) {
346 if (git_get_type
($hash_text) eq "commit") {
347 my $link = $cgi->a({-class => "text", -href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_text")}, $hash_text);
348 $line =~ s/$hash_text/$link/;
354 # format marker of refs pointing to given object
355 sub git_get_referencing
{
356 my ($refs, $id) = @_;
358 if (defined $refs->{$id}) {
359 return ' <span class="tag">' . esc_html
($refs->{$id}) . '</span>';
365 ## ----------------------------------------------------------------------
366 ## git utility subroutines, invoking git commands
368 # get HEAD ref of given project as hash
371 my $oENV = $ENV{'GIT_DIR'};
373 $ENV{'GIT_DIR'} = "$projectroot/$project";
374 if (open my $fd, "-|", $GIT, "rev-parse", "--verify", "HEAD") {
377 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
382 $ENV{'GIT_DIR'} = $oENV;
387 # get type of given object
391 open my $fd, "-|", $GIT, "cat-file", '-t', $hash or return;
398 sub git_get_project_config
{
401 return unless ($key);
402 $key =~ s/^gitweb\.//;
403 return if ($key =~ m/\W/);
405 my $val = qx($GIT repo
-config
--get gitweb
.$key);
409 sub git_get_project_config_bool
{
410 my $val = git_get_project_config
(@_);
411 if ($val and $val =~ m/true|yes|on/) {
414 return; # implicit false
417 # get hash of given path at given ref
418 sub git_get_hash_by_path
{
420 my $path = shift || return undef;
424 open my $fd, "-|", $GIT, "ls-tree", $base, "--", $path
425 or die_error
(undef, "Open git-ls-tree failed.");
427 close $fd or return undef;
429 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
430 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
434 ## ......................................................................
435 ## git utility functions, directly accessing git repository
437 # assumes that PATH is not symref
441 open my $fd, "$projectroot/$path" or return undef;
445 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
450 sub git_read_description
{
453 open my $fd, "$projectroot/$path/description" or return undef;
460 sub git_read_projects
{
463 if (-d
$projects_list) {
464 # search in directory
465 my $dir = $projects_list;
466 opendir my ($dh), $dir or return undef;
467 while (my $dir = readdir($dh)) {
468 if (-e
"$projectroot/$dir/HEAD") {
476 } elsif (-f
$projects_list) {
477 # read from file(url-encoded):
478 # 'git%2Fgit.git Linus+Torvalds'
479 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
480 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
481 open my ($fd), $projects_list or return undef;
482 while (my $line = <$fd>) {
484 my ($path, $owner) = split ' ', $line;
485 $path = unescape
($path);
486 $owner = unescape
($owner);
487 if (!defined $path) {
490 if (-e
"$projectroot/$path/HEAD") {
493 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
500 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
505 my $type = shift || "";
507 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
508 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
509 open my $fd, "$projectroot/$project/info/refs" or return;
510 while (my $line = <$fd>) {
512 # attention: for $type == "" it saves only last path part of ref name
513 # e.g. from 'refs/heads/jn/gitweb' it would leave only 'gitweb'
514 if ($line =~ m/^([0-9a-fA-F]{40})\t.*$type\/([^\
^]+)/) {
515 if (defined $refs{$1}) {
516 $refs{$1} .= " / $2";
526 ## ----------------------------------------------------------------------
527 ## parse to hash functions
531 my $tz = shift || "-0000";
534 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
535 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
536 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
537 $date{'hour'} = $hour;
538 $date{'minute'} = $min;
539 $date{'mday'} = $mday;
540 $date{'day'} = $days[$wday];
541 $date{'month'} = $months[$mon];
542 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
543 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
545 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
546 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
547 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
548 $date{'hour_local'} = $hour;
549 $date{'minute_local'} = $min;
550 $date{'tz_local'} = $tz;
559 open my $fd, "-|", $GIT, "cat-file", "tag", $tag_id or return;
560 $tag{'id'} = $tag_id;
561 while (my $line = <$fd>) {
563 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
565 } elsif ($line =~ m/^type (.+)$/) {
567 } elsif ($line =~ m/^tag (.+)$/) {
569 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
573 } elsif ($line =~ m/--BEGIN/) {
574 push @comment, $line;
576 } elsif ($line eq "") {
580 push @comment, <$fd>;
581 $tag{'comment'} = \
@comment;
583 if (!defined $tag{'name'}) {
589 sub git_read_commit
{
590 my $commit_id = shift;
591 my $commit_text = shift;
596 if (defined $commit_text) {
597 @commit_lines = @
$commit_text;
600 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", "--max-count=1", $commit_id or return;
601 @commit_lines = split '\n', <$fd>;
606 my $header = shift @commit_lines;
607 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
610 ($co{'id'}, my @parents) = split ' ', $header;
611 $co{'parents'} = \
@parents;
612 $co{'parent'} = $parents[0];
613 while (my $line = shift @commit_lines) {
614 last if $line eq "\n";
615 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
617 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
619 $co{'author_epoch'} = $2;
620 $co{'author_tz'} = $3;
621 if ($co{'author'} =~ m/^([^<]+) </) {
622 $co{'author_name'} = $1;
624 $co{'author_name'} = $co{'author'};
626 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
627 $co{'committer'} = $1;
628 $co{'committer_epoch'} = $2;
629 $co{'committer_tz'} = $3;
630 $co{'committer_name'} = $co{'committer'};
631 $co{'committer_name'} =~ s/ <.*//;
634 if (!defined $co{'tree'}) {
638 foreach my $title (@commit_lines) {
641 $co{'title'} = chop_str
($title, 80, 5);
642 # remove leading stuff of merges to make the interesting part visible
643 if (length($title) > 50) {
644 $title =~ s/^Automatic //;
645 $title =~ s/^merge (of|with) /Merge ... /i;
646 if (length($title) > 50) {
647 $title =~ s/(http|rsync):\/\///;
649 if (length($title) > 50) {
650 $title =~ s/(master|www|rsync)\.//;
652 if (length($title) > 50) {
653 $title =~ s/kernel.org:?//;
655 if (length($title) > 50) {
656 $title =~ s/\/pub\/scm//;
659 $co{'title_short'} = chop_str
($title, 50, 5);
663 # remove added spaces
664 foreach my $line (@commit_lines) {
667 $co{'comment'} = \
@commit_lines;
669 my $age = time - $co{'committer_epoch'};
671 $co{'age_string'} = age_string
($age);
672 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
673 if ($age > 60*60*24*7*2) {
674 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
675 $co{'age_string_age'} = $co{'age_string'};
677 $co{'age_string_date'} = $co{'age_string'};
678 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
683 ## ......................................................................
684 ## parse to array of hashes functions
691 my $pfxlen = length("$projectroot/$project/$ref_dir");
692 File
::Find
::find
(sub {
695 push @refs, substr($File::Find
::name
, $pfxlen + 1);
697 }, "$projectroot/$project/$ref_dir");
699 foreach my $ref_file (@refs) {
700 my $ref_id = git_read_hash
("$project/$ref_dir/$ref_file");
701 my $type = git_get_type
($ref_id) || next;
704 $ref_item{'type'} = $type;
705 $ref_item{'id'} = $ref_id;
706 $ref_item{'epoch'} = 0;
707 $ref_item{'age'} = "unknown";
708 if ($type eq "tag") {
709 my %tag = git_read_tag
($ref_id);
710 $ref_item{'comment'} = $tag{'comment'};
711 if ($tag{'type'} eq "commit") {
712 %co = git_read_commit
($tag{'object'});
713 $ref_item{'epoch'} = $co{'committer_epoch'};
714 $ref_item{'age'} = $co{'age_string'};
715 } elsif (defined($tag{'epoch'})) {
716 my $age = time - $tag{'epoch'};
717 $ref_item{'epoch'} = $tag{'epoch'};
718 $ref_item{'age'} = age_string
($age);
720 $ref_item{'reftype'} = $tag{'type'};
721 $ref_item{'name'} = $tag{'name'};
722 $ref_item{'refid'} = $tag{'object'};
723 } elsif ($type eq "commit"){
724 %co = git_read_commit
($ref_id);
725 $ref_item{'reftype'} = "commit";
726 $ref_item{'name'} = $ref_file;
727 $ref_item{'title'} = $co{'title'};
728 $ref_item{'refid'} = $ref_id;
729 $ref_item{'epoch'} = $co{'committer_epoch'};
730 $ref_item{'age'} = $co{'age_string'};
732 $ref_item{'reftype'} = $type;
733 $ref_item{'name'} = $ref_file;
734 $ref_item{'refid'} = $ref_id;
737 push @reflist, \
%ref_item;
740 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
744 ## ----------------------------------------------------------------------
745 ## filesystem-related functions
750 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
751 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
752 if (!defined $gcos) {
756 $owner =~ s/[,;].*$//;
757 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
760 ## ......................................................................
761 ## mimetype related functions
763 sub mimetype_guess_file
{
764 my $filename = shift;
766 -r
$mimemap or return undef;
769 open(MIME
, $mimemap) or return undef;
771 my ($mime, $exts) = split(/\t+/);
773 my @exts = split(/\s+/, $exts);
774 foreach my $ext (@exts) {
775 $mimemap{$ext} = $mime;
781 $filename =~ /\.(.*?)$/;
786 my $filename = shift;
788 $filename =~ /\./ or return undef;
790 if ($mimetypes_file) {
791 my $file = $mimetypes_file;
792 #$file =~ m#^/# or $file = "$projectroot/$path/$file";
793 $mime = mimetype_guess_file
($filename, $file);
795 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
799 sub git_blob_plain_mimetype
{
801 my $filename = shift;
804 my $mime = mimetype_guess
($filename);
805 $mime and return $mime;
809 return $default_blob_plain_mimetype unless $fd;
812 return 'text/plain' .
813 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
814 } elsif (! $filename) {
815 return 'application/octet-stream';
816 } elsif ($filename =~ m/\.png$/i) {
818 } elsif ($filename =~ m/\.gif$/i) {
820 } elsif ($filename =~ m/\.jpe?g$/i) {
823 return 'application/octet-stream';
827 ## ======================================================================
828 ## functions printing HTML: header, footer, error page
830 sub git_header_html
{
831 my $status = shift || "200 OK";
834 my $title = "$site_name git";
835 if (defined $project) {
836 $title .= " - $project";
837 if (defined $action) {
838 $title .= "/$action";
839 if (defined $file_name) {
840 $title .= " - $file_name";
841 if ($action eq "tree" && $file_name !~ m
|/$|) {
848 # require explicit support from the UA if we are to send the page as
849 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
850 # we have to do this because MSIE sometimes globs '*/*', pretending to
851 # support xhtml+xml but choking when it gets what it asked for.
852 if ($cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ && $cgi->Accept('application/xhtml
+xml
') != 0) {
853 $content_type = 'application
/xhtml
+xml
';
855 $content_type = 'text
/html
';
857 print $cgi->header(-type=>$content_type, -charset => 'utf
-8', -status=> $status, -expires => $expires);
859 <?xml version="1.0" encoding="utf-8"?>
860 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
861 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
862 <!-- git web interface v$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
863 <!-- git core binaries version $git_version -->
865 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
866 <meta name="robots" content="index, nofollow"/>
867 <title>$title</title>
868 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
873 print "<div class=\"page_header\">\n" .
874 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
875 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
877 print $cgi->a({-href
=> esc_param
($home_link)}, "projects") . " / ";
878 if (defined $project) {
879 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, esc_html
($project));
880 if (defined $action) {
884 if (!defined $searchtext) {
888 if (defined $hash_base) {
889 $search_hash = $hash_base;
890 } elsif (defined $hash) {
891 $search_hash = $hash;
893 $search_hash = "HEAD";
895 $cgi->param("a", "search");
896 $cgi->param("h", $search_hash);
897 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
898 "<div class=\"search\">\n" .
899 $cgi->hidden(-name
=> "p") . "\n" .
900 $cgi->hidden(-name
=> "a") . "\n" .
901 $cgi->hidden(-name
=> "h") . "\n" .
902 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
904 $cgi->end_form() . "\n";
909 sub git_footer_html
{
910 print "<div class=\"page_footer\">\n";
911 if (defined $project) {
912 my $descr = git_read_description
($project);
913 if (defined $descr) {
914 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
916 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=rss"), -class => "rss_logo"}, "RSS") . "\n";
918 print $cgi->a({-href
=> "$my_uri?" . esc_param
("a=opml"), -class => "rss_logo"}, "OPML") . "\n";
926 my $status = shift || "403 Forbidden";
927 my $error = shift || "Malformed query, file missing or permission denied";
929 git_header_html
($status);
930 print "<div class=\"page_body\">\n" .
932 "$status - $error\n" .
939 ## ----------------------------------------------------------------------
940 ## functions printing or outputting HTML: navigation
943 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
944 $extra = '' if !defined $extra; # pager or formats
946 my @navs = qw(summary shortlog log commit commitdiff tree);
948 @navs = grep { $_ ne $suppress } @navs;
951 my %arg = map { $_, ''} @navs;
953 for (qw(commit commitdiff)) {
954 $arg{$_} = ";h=$head";
956 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
957 for (qw(shortlog log)) {
958 $arg{$_} = ";h=$head";
962 $arg{tree
} .= ";h=$treehead" if defined $treehead;
963 $arg{tree
} .= ";hb=$treebase" if defined $treebase;
965 print "<div class=\"page_nav\">\n" .
969 : $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$_$arg{$_}")}, "$_")
972 print "<br/>\n$extra<br/>\n" .
976 sub git_get_paging_nav
{
977 my ($action, $hash, $head, $page, $nrevs) = @_;
981 if ($hash ne $head || $page) {
982 $paging_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$action")}, "HEAD");
984 $paging_nav .= "HEAD";
988 $paging_nav .= " ⋅ " .
989 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$action;h=$hash;pg=" . ($page-1)),
990 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
992 $paging_nav .= " ⋅ prev";
995 if ($nrevs >= (100 * ($page+1)-1)) {
996 $paging_nav .= " ⋅ " .
997 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$action;h=$hash;pg=" . ($page+1)),
998 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1000 $paging_nav .= " ⋅ next";
1006 ## ......................................................................
1007 ## functions printing or outputting HTML: div
1009 sub git_header_div
{
1010 my ($action, $title, $hash, $hash_base) = @_;
1013 $rest .= ";h=$hash" if $hash;
1014 $rest .= ";hb=$hash_base" if $hash_base;
1016 print "<div class=\"header\">\n" .
1017 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$action$rest"),
1018 -class => "title"}, $title ?
$title : $action) . "\n" .
1022 sub git_print_page_path
{
1026 if (!defined $name) {
1027 print "<div class=\"page_path\"><b>/</b></div>\n";
1028 } elsif (defined $type && $type eq 'blob') {
1029 print "<div class=\"page_path\"><b>" .
1030 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;f=$file_name")}, esc_html
($name)) . "</b><br/></div>\n";
1032 print "<div class=\"page_path\"><b>" . esc_html
($name) . "</b><br/></div>\n";
1036 ## ......................................................................
1037 ## functions printing large fragments of HTML
1039 sub git_shortlog_body
{
1040 # uses global variable $project
1041 my ($revlist, $from, $to, $refs, $extra) = @_;
1042 $from = 0 unless defined $from;
1043 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1045 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
1047 for (my $i = $from; $i <= $to; $i++) {
1048 my $commit = $revlist->[$i];
1049 #my $ref = defined $refs ? git_get_referencing($refs, $commit) : '';
1050 my $ref = git_get_referencing
($refs, $commit);
1051 my %co = git_read_commit
($commit);
1052 my %ad = date_str
($co{'author_epoch'});
1054 print "<tr class=\"dark\">\n";
1056 print "<tr class=\"light\">\n";
1059 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1060 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1061 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
1063 if (length($co{'title_short'}) < length($co{'title'})) {
1064 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"),
1065 -class => "list", -title
=> "$co{'title'}"},
1066 "<b>" . esc_html
($co{'title_short'}) . "$ref</b>");
1068 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"),
1070 "<b>" . esc_html
($co{'title'}) . "$ref</b>");
1073 "<td class=\"link\">" .
1074 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") . " | " .
1075 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1079 if (defined $extra) {
1081 "<td colspan=\"4\">$extra</td>\n" .
1088 # uses global variable $project
1089 my ($taglist, $from, $to, $extra) = @_;
1090 $from = 0 unless defined $from;
1091 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1093 print "<table class=\"tags\" cellspacing=\"0\">\n";
1095 for (my $i = $from; $i <= $to; $i++) {
1096 my $entry = $taglist->[$i];
1098 my $comment_lines = $tag{'comment'};
1099 my $comment = shift @
$comment_lines;
1101 if (defined $comment) {
1102 $comment_short = chop_str
($comment, 30, 5);
1105 print "<tr class=\"dark\">\n";
1107 print "<tr class=\"light\">\n";
1110 print "<td><i>$tag{'age'}</i></td>\n" .
1112 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"),
1113 -class => "list"}, "<b>" . esc_html
($tag{'name'}) . "</b>") .
1116 if (defined $comment) {
1117 if (length($comment_short) < length($comment)) {
1118 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}"),
1119 -class => "list", -title
=> $comment}, $comment_short);
1121 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}"),
1122 -class => "list"}, $comment);
1126 "<td class=\"selflink\">";
1127 if ($tag{'type'} eq "tag") {
1128 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, "tag");
1133 "<td class=\"link\">" . " | " .
1134 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1135 if ($tag{'reftype'} eq "commit") {
1136 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1137 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'refid'}")}, "log");
1138 } elsif ($tag{'reftype'} eq "blob") {
1139 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$tag{'refid'}")}, "raw");
1144 if (defined $extra) {
1146 "<td colspan=\"5\">$extra</td>\n" .
1152 sub git_heads_body
{
1153 # uses global variable $project
1154 my ($taglist, $head, $from, $to, $extra) = @_;
1155 $from = 0 unless defined $from;
1156 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1158 print "<table class=\"heads\" cellspacing=\"0\">\n";
1160 for (my $i = $from; $i <= $to; $i++) {
1161 my $entry = $taglist->[$i];
1163 my $curr = $tag{'id'} eq $head;
1165 print "<tr class=\"dark\">\n";
1167 print "<tr class=\"light\">\n";
1170 print "<td><i>$tag{'age'}</i></td>\n" .
1171 ($tag{'id'} eq $head ?
"<td class=\"current_head\">" : "<td>") .
1172 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}"),
1173 -class => "list"}, "<b>" . esc_html
($tag{'name'}) . "</b>") .
1175 "<td class=\"link\">" .
1176 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") . " | " .
1177 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'name'}")}, "log") .
1181 if (defined $extra) {
1183 "<td colspan=\"3\">$extra</td>\n" .
1189 ## ----------------------------------------------------------------------
1190 ## functions printing large fragments, format as one of arguments
1192 sub git_diff_print
{
1194 my $from_name = shift;
1196 my $to_name = shift;
1197 my $format = shift || "html";
1199 my $from_tmp = "/dev/null";
1200 my $to_tmp = "/dev/null";
1203 # create tmp from-file
1204 if (defined $from) {
1205 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
1206 open my $fd2, "> $from_tmp";
1207 open my $fd, "-|", $GIT, "cat-file", "blob", $from;
1214 # create tmp to-file
1216 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
1217 open my $fd2, "> $to_tmp";
1218 open my $fd, "-|", $GIT, "cat-file", "blob", $to;
1225 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
1226 if ($format eq "plain") {
1231 while (my $line = <$fd>) {
1233 my $char = substr($line, 0, 1);
1234 my $diff_class = "";
1236 $diff_class = " add";
1237 } elsif ($char eq "-") {
1238 $diff_class = " rem";
1239 } elsif ($char eq "@") {
1240 $diff_class = " chunk_header";
1241 } elsif ($char eq "\\") {
1245 while ((my $pos = index($line, "\t")) != -1) {
1246 if (my $count = (8 - (($pos-1) % 8))) {
1247 my $spaces = ' ' x
$count;
1248 $line =~ s/\t/$spaces/;
1251 print "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
1256 if (defined $from) {
1265 ## ======================================================================
1266 ## ======================================================================
1269 sub git_project_list
{
1270 my $order = $cgi->param('o');
1271 if (defined $order && $order !~ m/project|descr|owner|age/) {
1272 die_error
(undef, "Invalid order parameter '$order'.");
1275 my @list = git_read_projects
();
1278 die_error
(undef, "No projects found.");
1280 foreach my $pr (@list) {
1281 my $head = git_read_head
($pr->{'path'});
1282 if (!defined $head) {
1285 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
1286 my %co = git_read_commit
($head);
1290 $pr->{'commit'} = \
%co;
1291 if (!defined $pr->{'descr'}) {
1292 my $descr = git_read_description
($pr->{'path'}) || "";
1293 $pr->{'descr'} = chop_str
($descr, 25, 5);
1295 if (!defined $pr->{'owner'}) {
1296 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
1298 push @projects, $pr;
1302 if (-f
$home_text) {
1303 print "<div class=\"index_include\">\n";
1304 open (my $fd, $home_text);
1309 print "<table class=\"project_list\">\n" .
1311 $order ||= "project";
1312 if ($order eq "project") {
1313 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
1314 print "<th>Project</th>\n";
1317 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=project"),
1318 -class => "header"}, "Project") .
1321 if ($order eq "descr") {
1322 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
1323 print "<th>Description</th>\n";
1326 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=descr"),
1327 -class => "header"}, "Description") .
1330 if ($order eq "owner") {
1331 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
1332 print "<th>Owner</th>\n";
1335 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=owner"),
1336 -class => "header"}, "Owner") .
1339 if ($order eq "age") {
1340 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
1341 print "<th>Last Change</th>\n";
1344 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=age"),
1345 -class => "header"}, "Last Change") .
1348 print "<th></th>\n" .
1351 foreach my $pr (@projects) {
1353 print "<tr class=\"dark\">\n";
1355 print "<tr class=\"light\">\n";
1358 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=summary"),
1359 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
1360 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
1361 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
1362 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" .
1363 $pr->{'commit'}{'age_string'} . "</td>\n" .
1364 "<td class=\"link\">" .
1365 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=summary")}, "summary") . " | " .
1366 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=shortlog")}, "shortlog") . " | " .
1367 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=log")}, "log") .
1376 my $descr = git_read_description
($project) || "none";
1377 my $head = git_read_head
($project);
1378 my %co = git_read_commit
($head);
1379 my %cd = date_str
($co{'committer_epoch'}, $co{'committer_tz'});
1382 if (-f
$projects_list) {
1383 open (my $fd , $projects_list);
1384 while (my $line = <$fd>) {
1386 my ($pr, $ow) = split ' ', $line;
1387 $pr = unescape
($pr);
1388 $ow = unescape
($ow);
1389 if ($pr eq $project) {
1390 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
1396 if (!defined $owner) {
1397 $owner = get_file_owner
("$projectroot/$project");
1400 my $refs = read_info_ref
();
1402 git_page_nav
('summary','', $head);
1404 print "<div class=\"title\"> </div>\n";
1405 print "<table cellspacing=\"0\">\n" .
1406 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
1407 "<tr><td>owner</td><td>$owner</td></tr>\n" .
1408 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
1411 open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_read_head
($project)
1412 or die_error
(undef, "Open git-rev-list failed.");
1413 my @revlist = map { chomp; $_ } <$fd>;
1415 git_header_div
('shortlog');
1416 git_shortlog_body
(\
@revlist, 0, 15, $refs,
1417 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "..."));
1419 my $taglist = git_read_refs
("refs/tags");
1420 if (defined @
$taglist) {
1421 git_header_div
('tags');
1422 git_tags_body
($taglist, 0, 15,
1423 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tags")}, "..."));
1426 my $headlist = git_read_refs
("refs/heads");
1427 if (defined @
$headlist) {
1428 git_header_div
('heads');
1429 git_heads_body
($headlist, $head, 0, 15,
1430 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=heads")}, "..."));
1437 my $head = git_read_head
($project);
1439 git_page_nav
('','', $head,undef,$head);
1440 my %tag = git_read_tag
($hash);
1441 git_header_div
('commit', esc_html
($tag{'name'}), $hash);
1442 print "<div class=\"title_text\">\n" .
1443 "<table cellspacing=\"0\">\n" .
1445 "<td>object</td>\n" .
1446 "<td>" . $cgi->a({-class => "list", -href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'object'}) . "</td>\n" .
1447 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'type'}) . "</td>\n" .
1449 if (defined($tag{'author'})) {
1450 my %ad = date_str
($tag{'epoch'}, $tag{'tz'});
1451 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
1452 print "<tr><td></td><td>" . $ad{'rfc2822'} . sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) . "</td></tr>\n";
1454 print "</table>\n\n" .
1456 print "<div class=\"page_body\">";
1457 my $comment = $tag{'comment'};
1458 foreach my $line (@
$comment) {
1459 print esc_html
($line) . "<br/>\n";
1468 die_error
(undef, "Permission denied.") if (!git_get_project_config_bool
('blame'));
1469 die_error
('404 Not Found', "File name not defined") if (!$file_name);
1470 $hash_base ||= git_read_head
($project);
1471 die_error
(undef, "Reading commit failed") unless ($hash_base);
1472 my %co = git_read_commit
($hash_base)
1473 or die_error
(undef, "Reading commit failed");
1474 if (!defined $hash) {
1475 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
1476 or die_error
(undef, "Error looking up file");
1478 $ftype = git_get_type
($hash);
1479 if ($ftype !~ "blob") {
1480 die_error
("400 Bad Request", "object is not a blob");
1482 open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base)
1483 or die_error
(undef, "Open git-blame failed.");
1486 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") .
1487 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;f=$file_name")}, "head");
1488 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1489 git_header_div
('commit', esc_html
($co{'title'}), $hash_base);
1490 git_print_page_path
($file_name, $ftype);
1491 my @rev_color = (qw(light dark));
1492 my $num_colors = scalar(@rev_color);
1493 my $current_color = 0;
1495 print "<div class=\"page_body\">\n";
1496 print "<table class=\"blame\">\n";
1497 print "<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n";
1499 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
1501 my $rev = substr($full_rev, 0, 8);
1505 if (!defined $last_rev) {
1506 $last_rev = $full_rev;
1507 } elsif ($last_rev ne $full_rev) {
1508 $last_rev = $full_rev;
1509 $current_color = ++$current_color % $num_colors;
1511 print "<tr class=\"$rev_color[$current_color]\">\n";
1512 print "<td class=\"sha1\">" .
1513 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$full_rev;f=$file_name")}, esc_html
($rev)) . "</td>\n";
1514 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" . esc_html
($lineno) . "</a></td>\n";
1515 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
1520 close $fd or print "Reading blob failed\n";
1526 die_error
('403 Permission denied', "Permission denied.") if (!git_get_project_config_bool
('blame'));
1527 die_error
('404 Not Found', "What file will it be, master?") if (!$file_name);
1528 $hash_base ||= git_read_head
($project);
1529 die_error
(undef, "Reading commit failed.") unless ($hash_base);
1530 my %co = git_read_commit
($hash_base)
1531 or die_error
(undef, "Reading commit failed.");
1532 if (!defined $hash) {
1533 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
1534 or die_error
(undef, "Error lookup file.");
1536 open ($fd, "-|", $GIT, "annotate", '-l', '-t', '-r', $file_name, $hash_base)
1537 or die_error
(undef, "Open git-annotate failed.");
1540 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") .
1541 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;f=$file_name")}, "head");
1542 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1543 git_header_div
('commit', esc_html
($co{'title'}), $hash_base);
1544 git_print_page_path
($file_name, 'blob');
1545 print "<div class=\"page_body\">\n";
1547 <table class="blame">
1556 my @line_class = (qw(light dark));
1557 my $line_class_len = scalar (@line_class);
1558 my $line_class_num = $#line_class;
1559 while (my $line = <$fd>) {
1571 $line_class_num = ($line_class_num + 1) % $line_class_len;
1573 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) \+\d\d\d\d\t(\d+)\)(.*)$/) {
1580 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
1583 $short_rev = substr ($long_rev, 0, 8);
1584 $age = time () - $time;
1585 $age_str = age_string
($age);
1586 $age_str =~ s/ / /g;
1587 $age_class = age_class
($age);
1588 $author = esc_html
($author);
1589 $author =~ s/ / /g;
1591 while ((my $pos = index($data, "\t")) != -1) {
1592 if (my $count = (8 - ($pos % 8))) {
1593 my $spaces = ' ' x
$count;
1594 $data =~ s/\t/$spaces/;
1597 $data = esc_html
($data);
1600 <tr class="$line_class[$line_class_num]">
1601 <td class="sha1"><a href="$my_uri?${\esc_param ("p=$project;a=commit;h=$long_rev")}" class="text">$short_rev..</a></td>
1602 <td class="$age_class">$age_str</td>
1604 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
1605 <td class="pre">$data</td>
1608 } # while (my $line = <$fd>)
1609 print "</table>\n\n";
1610 close $fd or print "Reading blob failed.\n";
1616 my $head = git_read_head
($project);
1618 git_page_nav
('','', $head,undef,$head);
1619 git_header_div
('summary', $project);
1621 my $taglist = git_read_refs
("refs/tags");
1622 if (defined @
$taglist) {
1623 git_tags_body
($taglist);
1629 my $head = git_read_head
($project);
1631 git_page_nav
('','', $head,undef,$head);
1632 git_header_div
('summary', $project);
1634 my $taglist = git_read_refs
("refs/heads");
1636 if (defined @
$taglist) {
1637 git_heads_body
($taglist, $head);
1642 sub git_blob_plain
{
1643 if (!defined $hash) {
1644 if (defined $file_name) {
1645 my $base = $hash_base || git_read_head
($project);
1646 $hash = git_get_hash_by_path
($base, $file_name, "blob")
1647 or die_error
(undef, "Error lookup file.");
1649 die_error
(undef, "No file name defined.");
1653 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
1654 or die_error
("Couldn't cat $file_name, $hash");
1656 $type ||= git_blob_plain_mimetype
($fd, $file_name);
1658 # save as filename, even when no $file_name is given
1659 my $save_as = "$hash";
1660 if (defined $file_name) {
1661 $save_as = $file_name;
1662 } elsif ($type =~ m/^text\//) {
1666 print $cgi->header(-type
=> "$type", '-content-disposition' => "inline; filename=\"$save_as\"");
1668 binmode STDOUT
, ':raw';
1670 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
1676 if (!defined $hash) {
1677 if (defined $file_name) {
1678 my $base = $hash_base || git_read_head
($project);
1679 $hash = git_get_hash_by_path
($base, $file_name, "blob")
1680 or die_error
(undef, "Error lookup file.");
1682 die_error
(undef, "No file name defined.");
1685 my $have_blame = git_get_project_config_bool
('blame');
1686 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
1687 or die_error
(undef, "Couldn't cat $file_name, $hash.");
1688 my $mimetype = git_blob_plain_mimetype
($fd, $file_name);
1689 if ($mimetype !~ m/^text\//) {
1691 return git_blob_plain
($mimetype);
1694 my $formats_nav = '';
1695 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
1696 if (defined $file_name) {
1698 $formats_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;h=$hash;hb=$hash_base;f=$file_name")}, "blame") . " | ";
1701 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$hash;f=$file_name")}, "plain") .
1702 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;hb=HEAD;f=$file_name")}, "head");
1704 $formats_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$hash")}, "plain");
1706 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1707 git_header_div
('commit', esc_html
($co{'title'}), $hash_base);
1709 print "<div class=\"page_nav\">\n" .
1710 "<br/><br/></div>\n" .
1711 "<div class=\"title\">$hash</div>\n";
1713 git_print_page_path
($file_name, "blob");
1714 print "<div class=\"page_body\">\n";
1716 while (my $line = <$fd>) {
1719 while ((my $pos = index($line, "\t")) != -1) {
1720 if (my $count = (8 - ($pos % 8))) {
1721 my $spaces = ' ' x
$count;
1722 $line =~ s/\t/$spaces/;
1725 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", $nr, $nr, $nr, esc_html
($line);
1727 close $fd or print "Reading blob failed.\n";
1733 if (!defined $hash) {
1734 $hash = git_read_head
($project);
1735 if (defined $file_name) {
1736 my $base = $hash_base || $hash;
1737 $hash = git_get_hash_by_path
($base, $file_name, "tree");
1739 if (!defined $hash_base) {
1744 open my $fd, "-|", $GIT, "ls-tree", '-z', $hash
1745 or die_error
(undef, "Open git-ls-tree failed.");
1746 my @entries = map { chomp; $_ } <$fd>;
1747 close $fd or die_error
(undef, "Reading tree failed.");
1750 my $refs = read_info_ref
();
1751 my $ref = git_get_referencing
($refs, $hash_base);
1755 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
1756 $base_key = ";hb=$hash_base";
1757 git_page_nav
('tree','', $hash_base);
1758 git_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
1760 print "<div class=\"page_nav\">\n";
1761 print "<br/><br/></div>\n";
1762 print "<div class=\"title\">$hash</div>\n";
1764 if (defined $file_name) {
1765 $base = esc_html
("$file_name/");
1767 git_print_page_path
($file_name, 'tree');
1768 print "<div class=\"page_body\">\n";
1769 print "<table cellspacing=\"0\">\n";
1771 foreach my $line (@entries) {
1772 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1773 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1777 my $t_name = validate_input
($4);
1779 print "<tr class=\"dark\">\n";
1781 print "<tr class=\"light\">\n";
1784 print "<td class=\"mode\">" . mode_str
($t_mode) . "</td>\n";
1785 if ($t_type eq "blob") {
1786 print "<td class=\"list\">" .
1787 $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)) .
1789 "<td class=\"link\">" .
1790 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name")}, "blob") .
1791 # " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$t_hash$base_key;f=$base$t_name")}, "blame") .
1792 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;h=$t_hash;hb=$hash_base;f=$base$t_name")}, "history") .
1793 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$t_hash;f=$base$t_name")}, "raw") .
1795 } elsif ($t_type eq "tree") {
1796 print "<td class=\"list\">" .
1797 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, esc_html
($t_name)) .
1799 "<td class=\"link\">" .
1800 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, "tree") .
1801 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;hb=$hash_base;f=$base$t_name")}, "history") .
1806 print "</table>\n" .
1812 my $head = git_read_head
($project);
1813 if (!defined $hash) {
1816 if (!defined $page) {
1819 my $refs = read_info_ref
();
1821 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
1822 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
1823 or die_error
(undef, "Open git-rev-list failed.");
1824 my @revlist = map { chomp; $_ } <$fd>;
1827 my $paging_nav = git_get_paging_nav
('log', $hash, $head, $page, $#revlist);
1830 git_page_nav
('log','', $hash,undef,undef, $paging_nav);
1833 my %co = git_read_commit
($hash);
1835 git_header_div
('summary', $project);
1836 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
1838 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
1839 my $commit = $revlist[$i];
1840 my $ref = git_get_referencing
($refs, $commit);
1841 my %co = git_read_commit
($commit);
1843 my %ad = date_str
($co{'author_epoch'});
1844 git_header_div
('commit',
1845 "<span class=\"age\">$co{'age_string'}</span>" .
1846 esc_html
($co{'title'}) . $ref,
1848 print "<div class=\"title_text\">\n" .
1849 "<div class=\"log_link\">\n" .
1850 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
1851 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1854 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
1856 "<div class=\"log_body\">\n";
1857 my $comment = $co{'comment'};
1859 foreach my $line (@
$comment) {
1860 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1871 print format_log_line_html
($line) . "<br/>\n";
1882 my %co = git_read_commit
($hash);
1884 die_error
(undef, "Unknown commit object.");
1886 my %ad = date_str
($co{'author_epoch'}, $co{'author_tz'});
1887 my %cd = date_str
($co{'committer_epoch'}, $co{'committer_tz'});
1889 my $parent = $co{'parent'};
1890 if (!defined $parent) {
1893 open my $fd, "-|", $GIT, "diff-tree", '-r', '-M', $parent, $hash
1894 or die_error
(undef, "Open git-diff-tree failed.");
1895 my @difftree = map { chomp; $_ } <$fd>;
1896 close $fd or die_error
(undef, "Reading git-diff-tree failed.");
1898 # non-textual hash id's can be cached
1900 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
1903 my $refs = read_info_ref
();
1904 my $ref = git_get_referencing
($refs, $co{'id'});
1905 my $formats_nav = '';
1906 if (defined $file_name && defined $co{'parent'}) {
1907 my $parent = $co{'parent'};
1908 $formats_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;hb=$parent;f=$file_name")}, "blame");
1910 git_header_html
(undef, $expires);
1911 git_page_nav
('commit', defined $co{'parent'} ?
'' : 'commitdiff',
1912 $hash, $co{'tree'}, $hash,
1915 if (defined $co{'parent'}) {
1916 git_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
1918 git_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
1920 print "<div class=\"title_text\">\n" .
1921 "<table cellspacing=\"0\">\n";
1922 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
1924 "<td></td><td> $ad{'rfc2822'}";
1925 if ($ad{'hour_local'} < 6) {
1926 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1928 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1932 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
1933 print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
1934 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
1937 "<td class=\"sha1\">" .
1938 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash"), class => "list"}, $co{'tree'}) .
1940 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
1943 my $parents = $co{'parents'};
1944 foreach my $par (@
$parents) {
1947 "<td class=\"sha1\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$par"), class => "list"}, $par) . "</td>" .
1948 "<td class=\"link\">" .
1949 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$par")}, "commit") .
1950 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash;hp=$par")}, "commitdiff") .
1956 print "<div class=\"page_body\">\n";
1957 my $comment = $co{'comment'};
1960 foreach my $line (@
$comment) {
1961 # print only one empty line
1963 if ($empty || $signed) {
1970 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1972 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1975 print format_log_line_html
($line) . "<br/>\n";
1979 print "<div class=\"list_head\">\n";
1980 if ($#difftree > 10) {
1981 print(($#difftree + 1) . " files changed:\n");
1984 print "<table class=\"diff_tree\">\n";
1986 foreach my $line (@difftree) {
1987 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1988 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1989 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
1997 my $similarity = $6;
1998 my $file = validate_input
(unquote
($7));
2000 print "<tr class=\"dark\">\n";
2002 print "<tr class=\"light\">\n";
2005 if ($status eq "A") {
2007 if (S_ISREG
(oct $to_mode)) {
2008 $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
2011 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file"), -class => "list"}, esc_html
($file)) . "</td>\n" .
2012 "<td><span class=\"file_status new\">[new " . file_type
($to_mode) . "$mode_chng]</span></td>\n" .
2013 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob") . "</td>\n";
2014 } elsif ($status eq "D") {
2016 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file"), -class => "list"}, esc_html
($file)) . "</td>\n" .
2017 "<td><span class=\"file_status deleted\">[deleted " . file_type
($from_mode). "]</span></td>\n" .
2018 "<td class=\"link\">" .
2019 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, "blob") .
2020 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;hb=$hash;f=$file")}, "history") .
2022 } elsif ($status eq "M" || $status eq "T") {
2023 my $mode_chnge = "";
2024 if ($from_mode != $to_mode) {
2025 $mode_chnge = " <span class=\"file_status mode_chnge\">[changed";
2026 if (((oct $from_mode) & S_IFMT
) != ((oct $to_mode) & S_IFMT
)) {
2027 $mode_chnge .= " from " . file_type
($from_mode) . " to " . file_type
($to_mode);
2029 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
2030 if (S_ISREG
($from_mode) && S_ISREG
($to_mode)) {
2031 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
2032 } elsif (S_ISREG
($to_mode)) {
2033 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
2036 $mode_chnge .= "]</span>\n";
2039 if ($to_id ne $from_id) {
2040 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file"), -class => "list"}, esc_html
($file));
2042 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file"), -class => "list"}, esc_html
($file));
2045 "<td>$mode_chnge</td>\n" .
2046 "<td class=\"link\">";
2047 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob");
2048 if ($to_id ne $from_id) {
2049 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file")}, "diff");
2051 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;hb=$hash;f=$file")}, "history") . "\n";
2053 } elsif ($status eq "R") {
2054 my ($from_file, $to_file) = split "\t", $file;
2056 if ($from_mode != $to_mode) {
2057 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
2060 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file"), -class => "list"}, esc_html
($to_file)) . "</td>\n" .
2061 "<td><span class=\"file_status moved\">[moved from " .
2062 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$from_file"), -class => "list"}, esc_html
($from_file)) .
2063 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
2064 "<td class=\"link\">" .
2065 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file")}, "blob");
2066 if ($to_id ne $from_id) {
2067 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file")}, "diff");
2078 mkdir($git_temp, 0700);
2080 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
2082 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff_plain;h=$hash;hp=$hash_parent")}, "plain");
2083 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2084 git_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2086 print "<div class=\"page_nav\">\n" .
2087 "<br/><br/></div>\n" .
2088 "<div class=\"title\">$hash vs $hash_parent</div>\n";
2090 git_print_page_path
($file_name, "blob");
2091 print "<div class=\"page_body\">\n" .
2092 "<div class=\"diff_info\">blob:" .
2093 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name")}, $hash_parent) .
2095 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, $hash) .
2097 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
2102 sub git_blobdiff_plain
{
2103 mkdir($git_temp, 0700);
2104 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8');
2105 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
2108 sub git_commitdiff
{
2109 mkdir($git_temp, 0700);
2110 my %co = git_read_commit
($hash);
2112 die_error
(undef, "Unknown commit object.");
2114 if (!defined $hash_parent) {
2115 $hash_parent = $co{'parent'};
2117 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2118 or die_error
(undef, "Open git-diff-tree failed.");
2119 my @difftree = map { chomp; $_ } <$fd>;
2120 close $fd or die_error
(undef, "Reading diff-tree failed.");
2122 # non-textual hash id's can be cached
2124 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2127 my $refs = read_info_ref
();
2128 my $ref = git_get_referencing
($refs, $co{'id'});
2130 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent")}, "plain");
2131 git_header_html
(undef, $expires);
2132 git_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
2133 git_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
2134 print "<div class=\"page_body\">\n";
2135 my $comment = $co{'comment'};
2138 my @log = @
$comment;
2139 # remove first and empty lines after that
2141 while (defined $log[0] && $log[0] eq "") {
2144 foreach my $line (@log) {
2145 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2156 print format_log_line_html
($line) . "<br/>\n";
2159 foreach my $line (@difftree) {
2160 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2161 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2162 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2168 my $file = validate_input
(unquote
($6));
2169 if ($status eq "A") {
2170 print "<div class=\"diff_info\">" . file_type
($to_mode) . ":" .
2171 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id) . "(new)" .
2173 git_diff_print
(undef, "/dev/null", $to_id, "b/$file");
2174 } elsif ($status eq "D") {
2175 print "<div class=\"diff_info\">" . file_type
($from_mode) . ":" .
2176 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) . "(deleted)" .
2178 git_diff_print
($from_id, "a/$file", undef, "/dev/null");
2179 } elsif ($status eq "M") {
2180 if ($from_id ne $to_id) {
2181 print "<div class=\"diff_info\">" .
2182 file_type
($from_mode) . ":" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) .
2184 file_type
($to_mode) . ":" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id);
2186 git_diff_print
($from_id, "a/$file", $to_id, "b/$file");
2195 sub git_commitdiff_plain
{
2196 mkdir($git_temp, 0700);
2197 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2198 or die_error
(undef, "Open git-diff-tree failed.");
2199 my @difftree = map { chomp; $_ } <$fd>;
2200 close $fd or die_error
(undef, "Reading diff-tree failed.");
2202 # try to figure out the next tag after this commit
2204 my $refs = read_info_ref
("tags");
2205 open $fd, "-|", $GIT, "rev-list", "HEAD";
2206 my @commits = map { chomp; $_ } <$fd>;
2208 foreach my $commit (@commits) {
2209 if (defined $refs->{$commit}) {
2210 $tagname = $refs->{$commit}
2212 if ($commit eq $hash) {
2217 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8', '-content-disposition' => "inline; filename=\"git-$hash.patch\"");
2218 my %co = git_read_commit
($hash);
2219 my %ad = date_str
($co{'author_epoch'}, $co{'author_tz'});
2220 my $comment = $co{'comment'};
2221 print "From: $co{'author'}\n" .
2222 "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
2223 "Subject: $co{'title'}\n";
2224 if (defined $tagname) {
2225 print "X-Git-Tag: $tagname\n";
2227 print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
2230 foreach my $line (@
$comment) {;
2235 foreach my $line (@difftree) {
2236 $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/;
2241 if ($status eq "A") {
2242 git_diff_print
(undef, "/dev/null", $to_id, "b/$file", "plain");
2243 } elsif ($status eq "D") {
2244 git_diff_print
($from_id, "a/$file", undef, "/dev/null", "plain");
2245 } elsif ($status eq "M") {
2246 git_diff_print
($from_id, "a/$file", $to_id, "b/$file", "plain");
2252 if (!defined $hash_base) {
2253 $hash_base = git_read_head
($project);
2256 my %co = git_read_commit
($hash_base);
2258 die_error
(undef, "Unknown commit object.");
2260 my $refs = read_info_ref
();
2262 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base);
2263 git_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2264 if (!defined $hash && defined $file_name) {
2265 $hash = git_get_hash_by_path
($hash_base, $file_name);
2267 if (defined $hash) {
2268 $ftype = git_get_type
($hash);
2270 git_print_page_path
($file_name, $ftype);
2273 $GIT, "rev-list", "--full-history", $hash_base, "--", $file_name;
2274 print "<table cellspacing=\"0\">\n";
2276 while (my $line = <$fd>) {
2277 if ($line =~ m/^([0-9a-fA-F]{40})/){
2279 my %co = git_read_commit
($commit);
2283 my $ref = git_get_referencing
($refs, $commit);
2285 print "<tr class=\"dark\">\n";
2287 print "<tr class=\"light\">\n";
2290 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2291 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2292 "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list"}, "<b>" .
2293 esc_html
(chop_str
($co{'title'}, 50)) . "$ref</b>") . "</td>\n" .
2294 "<td class=\"link\">" .
2295 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
2296 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2297 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$ftype;hb=$commit;f=$file_name")}, $ftype);
2298 my $blob = git_get_hash_by_path
($hash_base, $file_name);
2299 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2300 if (defined $blob && defined $blob_parent && $blob ne $blob_parent) {
2302 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=$file_name")},
2315 if (!defined $searchtext) {
2316 die_error
("", "Text field empty.");
2318 if (!defined $hash) {
2319 $hash = git_read_head
($project);
2321 my %co = git_read_commit
($hash);
2323 die_error
(undef, "Unknown commit object.");
2325 # pickaxe may take all resources of your box and run for several minutes
2326 # with every query - so decide by yourself how public you make this feature :)
2327 my $commit_search = 1;
2328 my $author_search = 0;
2329 my $committer_search = 0;
2330 my $pickaxe_search = 0;
2331 if ($searchtext =~ s/^author\\://i) {
2333 } elsif ($searchtext =~ s/^committer\\://i) {
2334 $committer_search = 1;
2335 } elsif ($searchtext =~ s/^pickaxe\\://i) {
2337 $pickaxe_search = 1;
2340 git_page_nav
('','', $hash,$co{'tree'},$hash);
2341 git_header_div
('commit', esc_html
($co{'title'}), $hash);
2343 print "<table cellspacing=\"0\">\n";
2345 if ($commit_search) {
2347 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", $hash or next;
2348 while (my $commit_text = <$fd>) {
2349 if (!grep m/$searchtext/i, $commit_text) {
2352 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
2355 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
2358 my @commit_lines = split "\n", $commit_text;
2359 my %co = git_read_commit
(undef, \
@commit_lines);
2364 print "<tr class=\"dark\">\n";
2366 print "<tr class=\"light\">\n";
2369 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2370 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2372 $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/>");
2373 my $comment = $co{'comment'};
2374 foreach my $line (@
$comment) {
2375 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2376 my $lead = esc_html
($1) || "";
2377 $lead = chop_str
($lead, 30, 10);
2378 my $match = esc_html
($2) || "";
2379 my $trail = esc_html
($3) || "";
2380 $trail = chop_str
($trail, 30, 10);
2381 my $text = "$lead<span class=\"match\">$match</span>$trail";
2382 print chop_str
($text, 80, 5) . "<br/>\n";
2386 "<td class=\"link\">" .
2387 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2388 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2395 if ($pickaxe_search) {
2397 open my $fd, "-|", "$GIT rev-list $hash | $GIT diff-tree -r --stdin -S\'$searchtext\'";
2400 while (my $line = <$fd>) {
2401 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2404 $set{'from_id'} = $3;
2406 $set{'id'} = $set{'to_id'};
2407 if ($set{'id'} =~ m/0{40}/) {
2408 $set{'id'} = $set{'from_id'};
2410 if ($set{'id'} =~ m/0{40}/) {
2414 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
2417 print "<tr class=\"dark\">\n";
2419 print "<tr class=\"light\">\n";
2422 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2423 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2425 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" .
2426 esc_html
(chop_str
($co{'title'}, 50)) . "</b><br/>");
2427 while (my $setref = shift @files) {
2429 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}"), class => "list"},
2430 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
2434 "<td class=\"link\">" .
2435 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2436 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2440 %co = git_read_commit
($1);
2450 my $head = git_read_head
($project);
2451 if (!defined $hash) {
2454 if (!defined $page) {
2457 my $refs = read_info_ref
();
2459 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2460 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2461 or die_error
(undef, "Open git-rev-list failed.");
2462 my @revlist = map { chomp; $_ } <$fd>;
2465 my $paging_nav = git_get_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
2467 if ($#revlist >= (100 * ($page+1)-1)) {
2469 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)),
2470 -title
=> "Alt-n"}, "next");
2475 git_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
2476 git_header_div
('summary', $project);
2478 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
2483 ## ......................................................................
2484 ## feeds (RSS, OPML)
2487 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
2488 open my $fd, "-|", $GIT, "rev-list", "--max-count=150", git_read_head
($project)
2489 or die_error
(undef, "Open git-rev-list failed.");
2490 my @revlist = map { chomp; $_ } <$fd>;
2491 close $fd or die_error
(undef, "Reading rev-list failed.");
2492 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
2493 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
2494 "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
2495 print "<channel>\n";
2496 print "<title>$project</title>\n".
2497 "<link>" . esc_html
("$my_url?p=$project;a=summary") . "</link>\n".
2498 "<description>$project log</description>\n".
2499 "<language>en</language>\n";
2501 for (my $i = 0; $i <= $#revlist; $i++) {
2502 my $commit = $revlist[$i];
2503 my %co = git_read_commit
($commit);
2504 # we read 150, we always show 30 and the ones more recent than 48 hours
2505 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
2508 my %cd = date_str
($co{'committer_epoch'});
2509 open $fd, "-|", $GIT, "diff-tree", '-r', $co{'parent'}, $co{'id'} or next;
2510 my @difftree = map { chomp; $_ } <$fd>;
2514 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
2516 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
2517 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
2518 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
2519 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
2520 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
2521 "<content:encoded>" .
2523 my $comment = $co{'comment'};
2524 foreach my $line (@
$comment) {
2525 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
2526 print "$line<br/>\n";
2529 foreach my $line (@difftree) {
2530 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
2533 my $file = validate_input
(unquote
($7));
2534 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
2535 print "$file<br/>\n";
2538 "</content:encoded>\n" .
2541 print "</channel></rss>";
2545 my @list = git_read_projects
();
2547 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
2548 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
2549 "<opml version=\"1.0\">\n".
2551 " <title>$site_name Git OPML Export</title>\n".
2554 "<outline text=\"git RSS feeds\">\n";
2556 foreach my $pr (@list) {
2558 my $head = git_read_head
($proj{'path'});
2559 if (!defined $head) {
2562 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
2563 my %co = git_read_commit
($head);
2568 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
2569 my $rss = "$my_url?p=$proj{'path'};a=rss";
2570 my $html = "$my_url?p=$proj{'path'};a=summary";
2571 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
2573 print "</outline>\n".