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);
25 # core git executable to use
26 # this can just be "git" if your webserver has a sensible PATH
27 our $GIT = "++GIT_BINDIR++/git";
29 # absolute fs-path which will be prepended to the project path
30 #our $projectroot = "/pub/scm";
31 our $projectroot = "++GITWEB_PROJECTROOT++";
33 # location for temporary files needed for diffs
34 our $git_temp = "/tmp/gitweb";
36 # target of the home link on top of all pages
37 our $home_link = $my_uri;
39 # name of your site or organization to appear in page titles
40 # replace this with something more descriptive for clearer bookmarks
41 our $site_name = "++GITWEB_SITENAME++" || $ENV{'SERVER_NAME'} || "Untitled";
43 # html text to include at home page
44 our $home_text = "++GITWEB_HOMETEXT++";
46 # URI of default stylesheet
47 our $stylesheet = "++GITWEB_CSS++";
49 our $logo = "++GITWEB_LOGO++";
51 # source of projects list
52 our $projects_list = "++GITWEB_LIST++";
54 # default blob_plain mimetype and default charset for text/plain blob
55 our $default_blob_plain_mimetype = 'text/plain';
56 our $default_text_plain_charset = undef;
58 # file to use for guessing MIME types before trying /etc/mime.types
59 # (relative to the current git repository)
60 our $mimetypes_file = undef;
62 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
63 require $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
65 # version of the core git binary
66 our $git_version = qx($GIT --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
68 $projects_list ||= $projectroot;
70 mkdir($git_temp, 0700) || die_error
(undef, "Couldn't mkdir $git_temp");
73 # ======================================================================
74 # input validation and dispatch
75 our $action = $cgi->param('a');
76 if (defined $action) {
77 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
78 die_error
(undef, "Invalid action parameter");
80 # action which does not check rest of parameters
81 if ($action eq "opml") {
87 our $project = ($cgi->param('p') || $ENV{'PATH_INFO'});
88 $project =~ s
|^/||; $project =~ s|/$||;
89 if (defined $project && $project) {
90 if (!validate_input
($project)) {
91 die_error
(undef, "Invalid project parameter");
93 if (!(-d
"$projectroot/$project")) {
94 die_error
(undef, "No such directory");
96 if (!(-e
"$projectroot/$project/HEAD")) {
97 die_error
(undef, "No such project");
99 $ENV{'GIT_DIR'} = "$projectroot/$project";
105 our $file_name = $cgi->param('f');
106 if (defined $file_name) {
107 if (!validate_input
($file_name)) {
108 die_error
(undef, "Invalid file parameter");
112 our $hash = $cgi->param('h');
114 if (!validate_input
($hash)) {
115 die_error
(undef, "Invalid hash parameter");
119 our $hash_parent = $cgi->param('hp');
120 if (defined $hash_parent) {
121 if (!validate_input
($hash_parent)) {
122 die_error
(undef, "Invalid hash parent parameter");
126 our $hash_base = $cgi->param('hb');
127 if (defined $hash_base) {
128 if (!validate_input
($hash_base)) {
129 die_error
(undef, "Invalid hash base parameter");
133 our $page = $cgi->param('pg');
135 if ($page =~ m/[^0-9]$/) {
136 die_error
(undef, "Invalid page parameter");
140 our $searchtext = $cgi->param('s');
141 if (defined $searchtext) {
142 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
143 die_error
(undef, "Invalid search parameter");
145 $searchtext = quotemeta $searchtext;
150 "blame" => \
&git_blame2
,
151 "blobdiff" => \
&git_blobdiff
,
152 "blobdiff_plain" => \
&git_blobdiff_plain
,
153 "blob" => \
&git_blob
,
154 "blob_plain" => \
&git_blob_plain
,
155 "commitdiff" => \
&git_commitdiff
,
156 "commitdiff_plain" => \
&git_commitdiff_plain
,
157 "commit" => \
&git_commit
,
158 "heads" => \
&git_heads
,
159 "history" => \
&git_history
,
162 "search" => \
&git_search
,
163 "shortlog" => \
&git_shortlog
,
164 "summary" => \
&git_summary
,
166 "tags" => \
&git_tags
,
167 "tree" => \
&git_tree
,
170 $action = 'summary' if (!defined($action));
171 if (!defined($actions{$action})) {
172 die_error
(undef, "Unknown action");
174 $actions{$action}->();
177 ## ======================================================================
178 ## validation, quoting/unquoting and escaping
183 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
186 if ($input =~ m/(^|\/)(|\
.|\
.\
.)($|\
/)/) {
189 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\
-\
+\#\
~\
%]/) {
195 # quote unsafe chars, but keep the slash, even when it's not
196 # correct, but quoted slashes look too horrible in bookmarks
199 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
205 # replace invalid utf8 character with SUBSTITUTION sequence
208 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
209 $str = escapeHTML
($str);
210 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
214 # git may return quoted and escaped filenames
217 if ($str =~ m/^"(.*)"$/) {
219 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
224 # escape tabs (convert tabs to spaces)
228 while ((my $pos = index($line, "\t")) != -1) {
229 if (my $count = (8 - ($pos % 8))) {
230 my $spaces = ' ' x
$count;
231 $line =~ s/\t/$spaces/;
238 ## ----------------------------------------------------------------------
239 ## HTML aware string manipulation
244 my $add_len = shift || 10;
246 # allow only $len chars, but don't cut a word if it would fit in $add_len
247 # if it doesn't fit, cut it if it's still longer than the dots we would add
248 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
251 if (length($tail) > 4) {
253 $body =~ s/&[^;]*$//; # remove chopped character entities
258 ## ----------------------------------------------------------------------
259 ## functions returning short strings
261 # CSS class for given age value (in seconds)
265 if ($age < 60*60*2) {
267 } elsif ($age < 60*60*24*2) {
274 # convert age in seconds to "nn units ago" string
279 if ($age > 60*60*24*365*2) {
280 $age_str = (int $age/60/60/24/365);
281 $age_str .= " years ago";
282 } elsif ($age > 60*60*24*(365/12)*2) {
283 $age_str = int $age/60/60/24/(365/12);
284 $age_str .= " months ago";
285 } elsif ($age > 60*60*24*7*2) {
286 $age_str = int $age/60/60/24/7;
287 $age_str .= " weeks ago";
288 } elsif ($age > 60*60*24*2) {
289 $age_str = int $age/60/60/24;
290 $age_str .= " days ago";
291 } elsif ($age > 60*60*2) {
292 $age_str = int $age/60/60;
293 $age_str .= " hours ago";
294 } elsif ($age > 60*2) {
295 $age_str = int $age/60;
296 $age_str .= " min ago";
299 $age_str .= " sec ago";
301 $age_str .= " right now";
306 # convert file mode in octal to symbolic file mode string
308 my $mode = oct shift;
310 if (S_ISDIR
($mode & S_IFMT
)) {
312 } elsif (S_ISLNK
($mode)) {
314 } elsif (S_ISREG
($mode)) {
315 # git cares only about the executable bit
316 if ($mode & S_IXUSR
) {
326 # convert file mode in octal to file type string
328 my $mode = oct shift;
330 if (S_ISDIR
($mode & S_IFMT
)) {
332 } elsif (S_ISLNK
($mode)) {
334 } elsif (S_ISREG
($mode)) {
341 ## ----------------------------------------------------------------------
342 ## functions returning short HTML fragments, or transforming HTML fragments
343 ## which don't beling to other sections
345 # format line of commit message or tag comment
346 sub format_log_line_html
{
349 $line = esc_html
($line);
350 $line =~ s/ / /g;
351 if ($line =~ m/([0-9a-fA-F]{40})/) {
353 if (git_get_type
($hash_text) eq "commit") {
354 my $link = $cgi->a({-class => "text", -href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_text")}, $hash_text);
355 $line =~ s/$hash_text/$link/;
361 # format marker of refs pointing to given object
362 sub git_get_referencing
{
363 my ($refs, $id) = @_;
365 if (defined $refs->{$id}) {
366 return ' <span class="tag">' . esc_html
($refs->{$id}) . '</span>';
372 ## ----------------------------------------------------------------------
373 ## git utility subroutines, invoking git commands
375 # get HEAD ref of given project as hash
378 my $oENV = $ENV{'GIT_DIR'};
380 $ENV{'GIT_DIR'} = "$projectroot/$project";
381 if (open my $fd, "-|", $GIT, "rev-parse", "--verify", "HEAD") {
384 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
389 $ENV{'GIT_DIR'} = $oENV;
394 # get type of given object
398 open my $fd, "-|", $GIT, "cat-file", '-t', $hash or return;
405 sub git_get_project_config
{
408 return unless ($key);
409 $key =~ s/^gitweb\.//;
410 return if ($key =~ m/\W/);
412 my $val = qx($GIT repo
-config
--get gitweb
.$key);
416 sub git_get_project_config_bool
{
417 my $val = git_get_project_config
(@_);
418 if ($val and $val =~ m/true|yes|on/) {
421 return; # implicit false
424 # get hash of given path at given ref
425 sub git_get_hash_by_path
{
427 my $path = shift || return undef;
431 open my $fd, "-|", $GIT, "ls-tree", $base, "--", $path
432 or die_error
(undef, "Open git-ls-tree failed");
434 close $fd or return undef;
436 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
437 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
441 ## ......................................................................
442 ## git utility functions, directly accessing git repository
444 # assumes that PATH is not symref
448 open my $fd, "$projectroot/$path" or return undef;
452 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
457 sub git_read_description
{
460 open my $fd, "$projectroot/$path/description" or return undef;
467 sub git_read_projects
{
470 if (-d
$projects_list) {
471 # search in directory
472 my $dir = $projects_list;
473 opendir my ($dh), $dir or return undef;
474 while (my $dir = readdir($dh)) {
475 if (-e
"$projectroot/$dir/HEAD") {
483 } elsif (-f
$projects_list) {
484 # read from file(url-encoded):
485 # 'git%2Fgit.git Linus+Torvalds'
486 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
487 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
488 open my ($fd), $projects_list or return undef;
489 while (my $line = <$fd>) {
491 my ($path, $owner) = split ' ', $line;
492 $path = unescape
($path);
493 $owner = unescape
($owner);
494 if (!defined $path) {
497 if (-e
"$projectroot/$path/HEAD") {
500 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
507 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
512 my $type = shift || "";
514 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
515 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
516 open my $fd, "$projectroot/$project/info/refs" or return;
517 while (my $line = <$fd>) {
519 # attention: for $type == "" it saves only last path part of ref name
520 # e.g. from 'refs/heads/jn/gitweb' it would leave only 'gitweb'
521 if ($line =~ m/^([0-9a-fA-F]{40})\t.*$type\/([^\
^]+)/) {
522 if (defined $refs{$1}) {
523 $refs{$1} .= " / $2";
533 ## ----------------------------------------------------------------------
534 ## parse to hash functions
538 my $tz = shift || "-0000";
541 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
542 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
543 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
544 $date{'hour'} = $hour;
545 $date{'minute'} = $min;
546 $date{'mday'} = $mday;
547 $date{'day'} = $days[$wday];
548 $date{'month'} = $months[$mon];
549 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
550 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
552 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
553 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
554 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
555 $date{'hour_local'} = $hour;
556 $date{'minute_local'} = $min;
557 $date{'tz_local'} = $tz;
566 open my $fd, "-|", $GIT, "cat-file", "tag", $tag_id or return;
567 $tag{'id'} = $tag_id;
568 while (my $line = <$fd>) {
570 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
572 } elsif ($line =~ m/^type (.+)$/) {
574 } elsif ($line =~ m/^tag (.+)$/) {
576 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
580 } elsif ($line =~ m/--BEGIN/) {
581 push @comment, $line;
583 } elsif ($line eq "") {
587 push @comment, <$fd>;
588 $tag{'comment'} = \
@comment;
590 if (!defined $tag{'name'}) {
596 sub git_read_commit
{
597 my $commit_id = shift;
598 my $commit_text = shift;
603 if (defined $commit_text) {
604 @commit_lines = @
$commit_text;
607 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", "--max-count=1", $commit_id or return;
608 @commit_lines = split '\n', <$fd>;
613 my $header = shift @commit_lines;
614 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
617 ($co{'id'}, my @parents) = split ' ', $header;
618 $co{'parents'} = \
@parents;
619 $co{'parent'} = $parents[0];
620 while (my $line = shift @commit_lines) {
621 last if $line eq "\n";
622 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
624 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
626 $co{'author_epoch'} = $2;
627 $co{'author_tz'} = $3;
628 if ($co{'author'} =~ m/^([^<]+) </) {
629 $co{'author_name'} = $1;
631 $co{'author_name'} = $co{'author'};
633 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
634 $co{'committer'} = $1;
635 $co{'committer_epoch'} = $2;
636 $co{'committer_tz'} = $3;
637 $co{'committer_name'} = $co{'committer'};
638 $co{'committer_name'} =~ s/ <.*//;
641 if (!defined $co{'tree'}) {
645 foreach my $title (@commit_lines) {
648 $co{'title'} = chop_str
($title, 80, 5);
649 # remove leading stuff of merges to make the interesting part visible
650 if (length($title) > 50) {
651 $title =~ s/^Automatic //;
652 $title =~ s/^merge (of|with) /Merge ... /i;
653 if (length($title) > 50) {
654 $title =~ s/(http|rsync):\/\///;
656 if (length($title) > 50) {
657 $title =~ s/(master|www|rsync)\.//;
659 if (length($title) > 50) {
660 $title =~ s/kernel.org:?//;
662 if (length($title) > 50) {
663 $title =~ s/\/pub\/scm//;
666 $co{'title_short'} = chop_str
($title, 50, 5);
670 # remove added spaces
671 foreach my $line (@commit_lines) {
674 $co{'comment'} = \
@commit_lines;
676 my $age = time - $co{'committer_epoch'};
678 $co{'age_string'} = age_string
($age);
679 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
680 if ($age > 60*60*24*7*2) {
681 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
682 $co{'age_string_age'} = $co{'age_string'};
684 $co{'age_string_date'} = $co{'age_string'};
685 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
690 ## ......................................................................
691 ## parse to array of hashes functions
698 my $pfxlen = length("$projectroot/$project/$ref_dir");
699 File
::Find
::find
(sub {
702 push @refs, substr($File::Find
::name
, $pfxlen + 1);
704 }, "$projectroot/$project/$ref_dir");
706 foreach my $ref_file (@refs) {
707 my $ref_id = git_read_hash
("$project/$ref_dir/$ref_file");
708 my $type = git_get_type
($ref_id) || next;
711 $ref_item{'type'} = $type;
712 $ref_item{'id'} = $ref_id;
713 $ref_item{'epoch'} = 0;
714 $ref_item{'age'} = "unknown";
715 if ($type eq "tag") {
716 my %tag = git_read_tag
($ref_id);
717 $ref_item{'comment'} = $tag{'comment'};
718 if ($tag{'type'} eq "commit") {
719 %co = git_read_commit
($tag{'object'});
720 $ref_item{'epoch'} = $co{'committer_epoch'};
721 $ref_item{'age'} = $co{'age_string'};
722 } elsif (defined($tag{'epoch'})) {
723 my $age = time - $tag{'epoch'};
724 $ref_item{'epoch'} = $tag{'epoch'};
725 $ref_item{'age'} = age_string
($age);
727 $ref_item{'reftype'} = $tag{'type'};
728 $ref_item{'name'} = $tag{'name'};
729 $ref_item{'refid'} = $tag{'object'};
730 } elsif ($type eq "commit"){
731 %co = git_read_commit
($ref_id);
732 $ref_item{'reftype'} = "commit";
733 $ref_item{'name'} = $ref_file;
734 $ref_item{'title'} = $co{'title'};
735 $ref_item{'refid'} = $ref_id;
736 $ref_item{'epoch'} = $co{'committer_epoch'};
737 $ref_item{'age'} = $co{'age_string'};
739 $ref_item{'reftype'} = $type;
740 $ref_item{'name'} = $ref_file;
741 $ref_item{'refid'} = $ref_id;
744 push @reflist, \
%ref_item;
747 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
751 ## ----------------------------------------------------------------------
752 ## filesystem-related functions
757 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
758 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
759 if (!defined $gcos) {
763 $owner =~ s/[,;].*$//;
764 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
767 ## ......................................................................
768 ## mimetype related functions
770 sub mimetype_guess_file
{
771 my $filename = shift;
773 -r
$mimemap or return undef;
776 open(MIME
, $mimemap) or return undef;
778 my ($mime, $exts) = split(/\t+/);
780 my @exts = split(/\s+/, $exts);
781 foreach my $ext (@exts) {
782 $mimemap{$ext} = $mime;
788 $filename =~ /\.(.*?)$/;
793 my $filename = shift;
795 $filename =~ /\./ or return undef;
797 if ($mimetypes_file) {
798 my $file = $mimetypes_file;
799 #$file =~ m#^/# or $file = "$projectroot/$path/$file";
800 $mime = mimetype_guess_file
($filename, $file);
802 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
806 sub git_blob_plain_mimetype
{
808 my $filename = shift;
811 my $mime = mimetype_guess
($filename);
812 $mime and return $mime;
816 return $default_blob_plain_mimetype unless $fd;
819 return 'text/plain' .
820 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
821 } elsif (! $filename) {
822 return 'application/octet-stream';
823 } elsif ($filename =~ m/\.png$/i) {
825 } elsif ($filename =~ m/\.gif$/i) {
827 } elsif ($filename =~ m/\.jpe?g$/i) {
830 return 'application/octet-stream';
834 ## ======================================================================
835 ## functions printing HTML: header, footer, error page
837 sub git_header_html
{
838 my $status = shift || "200 OK";
841 my $title = "$site_name git";
842 if (defined $project) {
843 $title .= " - $project";
844 if (defined $action) {
845 $title .= "/$action";
846 if (defined $file_name) {
847 $title .= " - $file_name";
848 if ($action eq "tree" && $file_name !~ m
|/$|) {
855 # require explicit support from the UA if we are to send the page as
856 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
857 # we have to do this because MSIE sometimes globs '*/*', pretending to
858 # support xhtml+xml but choking when it gets what it asked for.
859 if (defined $cgi->http('HTTP_ACCEPT') && $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ && $cgi->Accept('application/xhtml
+xml
') != 0) {
860 $content_type = 'application
/xhtml
+xml
';
862 $content_type = 'text
/html
';
864 print $cgi->header(-type=>$content_type, -charset => 'utf
-8', -status=> $status, -expires => $expires);
866 <?xml version="1.0" encoding="utf-8"?>
867 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
868 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
869 <!-- git web interface v$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
870 <!-- git core binaries version $git_version -->
872 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
873 <meta name="robots" content="index, nofollow"/>
874 <title>$title</title>
875 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
877 print "<link rel=\"alternate\" title=\"" . esc_param
($project) . " log\" href=\"" .
878 "$my_uri?" . esc_param
("p=$project;a=rss") . "\" type=\"application/rss+xml\"/>\n" .
882 "<div class=\"page_header\">\n" .
883 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
884 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
886 print $cgi->a({-href
=> esc_param
($home_link)}, "projects") . " / ";
887 if (defined $project) {
888 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, esc_html
($project));
889 if (defined $action) {
893 if (!defined $searchtext) {
897 if (defined $hash_base) {
898 $search_hash = $hash_base;
899 } elsif (defined $hash) {
900 $search_hash = $hash;
902 $search_hash = "HEAD";
904 $cgi->param("a", "search");
905 $cgi->param("h", $search_hash);
906 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
907 "<div class=\"search\">\n" .
908 $cgi->hidden(-name
=> "p") . "\n" .
909 $cgi->hidden(-name
=> "a") . "\n" .
910 $cgi->hidden(-name
=> "h") . "\n" .
911 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
913 $cgi->end_form() . "\n";
918 sub git_footer_html
{
919 print "<div class=\"page_footer\">\n";
920 if (defined $project) {
921 my $descr = git_read_description
($project);
922 if (defined $descr) {
923 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
925 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=rss"), -class => "rss_logo"}, "RSS") . "\n";
927 print $cgi->a({-href
=> "$my_uri?" . esc_param
("a=opml"), -class => "rss_logo"}, "OPML") . "\n";
935 my $status = shift || "403 Forbidden";
936 my $error = shift || "Malformed query, file missing or permission denied";
938 git_header_html
($status);
939 print "<div class=\"page_body\">\n" .
941 "$status - $error\n" .
948 ## ----------------------------------------------------------------------
949 ## functions printing or outputting HTML: navigation
952 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
953 $extra = '' if !defined $extra; # pager or formats
955 my @navs = qw(summary shortlog log commit commitdiff tree);
957 @navs = grep { $_ ne $suppress } @navs;
960 my %arg = map { $_, ''} @navs;
962 for (qw(commit commitdiff)) {
963 $arg{$_} = ";h=$head";
965 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
966 for (qw(shortlog log)) {
967 $arg{$_} = ";h=$head";
971 $arg{tree
} .= ";h=$treehead" if defined $treehead;
972 $arg{tree
} .= ";hb=$treebase" if defined $treebase;
974 print "<div class=\"page_nav\">\n" .
978 : $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$_$arg{$_}")}, "$_")
981 print "<br/>\n$extra<br/>\n" .
985 sub git_get_paging_nav
{
986 my ($action, $hash, $head, $page, $nrevs) = @_;
990 if ($hash ne $head || $page) {
991 $paging_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$action")}, "HEAD");
993 $paging_nav .= "HEAD";
997 $paging_nav .= " ⋅ " .
998 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$action;h=$hash;pg=" . ($page-1)),
999 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1001 $paging_nav .= " ⋅ prev";
1004 if ($nrevs >= (100 * ($page+1)-1)) {
1005 $paging_nav .= " ⋅ " .
1006 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$action;h=$hash;pg=" . ($page+1)),
1007 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1009 $paging_nav .= " ⋅ next";
1015 ## ......................................................................
1016 ## functions printing or outputting HTML: div
1018 sub git_header_div
{
1019 my ($action, $title, $hash, $hash_base) = @_;
1022 $rest .= ";h=$hash" if $hash;
1023 $rest .= ";hb=$hash_base" if $hash_base;
1025 print "<div class=\"header\">\n" .
1026 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$action$rest"),
1027 -class => "title"}, $title ?
$title : $action) . "\n" .
1031 sub git_print_page_path
{
1035 if (!defined $name) {
1036 print "<div class=\"page_path\"><b>/</b></div>\n";
1037 } elsif (defined $type && $type eq 'blob') {
1038 print "<div class=\"page_path\"><b>" .
1039 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;f=$file_name")}, esc_html
($name)) . "</b><br/></div>\n";
1041 print "<div class=\"page_path\"><b>" . esc_html
($name) . "</b><br/></div>\n";
1045 ## ......................................................................
1046 ## functions printing large fragments of HTML
1048 sub git_shortlog_body
{
1049 # uses global variable $project
1050 my ($revlist, $from, $to, $refs, $extra) = @_;
1051 $from = 0 unless defined $from;
1052 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1054 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
1056 for (my $i = $from; $i <= $to; $i++) {
1057 my $commit = $revlist->[$i];
1058 #my $ref = defined $refs ? git_get_referencing($refs, $commit) : '';
1059 my $ref = git_get_referencing
($refs, $commit);
1060 my %co = git_read_commit
($commit);
1061 my %ad = date_str
($co{'author_epoch'});
1063 print "<tr class=\"dark\">\n";
1065 print "<tr class=\"light\">\n";
1068 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1069 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1070 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
1072 if (length($co{'title_short'}) < length($co{'title'})) {
1073 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"),
1074 -class => "list", -title
=> "$co{'title'}"},
1075 "<b>" . esc_html
($co{'title_short'}) . "$ref</b>");
1077 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"),
1079 "<b>" . esc_html
($co{'title'}) . "$ref</b>");
1082 "<td class=\"link\">" .
1083 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") . " | " .
1084 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1088 if (defined $extra) {
1090 "<td colspan=\"4\">$extra</td>\n" .
1097 # uses global variable $project
1098 my ($taglist, $from, $to, $extra) = @_;
1099 $from = 0 unless defined $from;
1100 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1102 print "<table class=\"tags\" cellspacing=\"0\">\n";
1104 for (my $i = $from; $i <= $to; $i++) {
1105 my $entry = $taglist->[$i];
1107 my $comment_lines = $tag{'comment'};
1108 my $comment = shift @
$comment_lines;
1110 if (defined $comment) {
1111 $comment_short = chop_str
($comment, 30, 5);
1114 print "<tr class=\"dark\">\n";
1116 print "<tr class=\"light\">\n";
1119 print "<td><i>$tag{'age'}</i></td>\n" .
1121 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"),
1122 -class => "list"}, "<b>" . esc_html
($tag{'name'}) . "</b>") .
1125 if (defined $comment) {
1126 if (length($comment_short) < length($comment)) {
1127 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}"),
1128 -class => "list", -title
=> $comment}, $comment_short);
1130 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}"),
1131 -class => "list"}, $comment);
1135 "<td class=\"selflink\">";
1136 if ($tag{'type'} eq "tag") {
1137 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, "tag");
1142 "<td class=\"link\">" . " | " .
1143 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1144 if ($tag{'reftype'} eq "commit") {
1145 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1146 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'refid'}")}, "log");
1147 } elsif ($tag{'reftype'} eq "blob") {
1148 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$tag{'refid'}")}, "raw");
1153 if (defined $extra) {
1155 "<td colspan=\"5\">$extra</td>\n" .
1161 sub git_heads_body
{
1162 # uses global variable $project
1163 my ($taglist, $head, $from, $to, $extra) = @_;
1164 $from = 0 unless defined $from;
1165 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1167 print "<table class=\"heads\" cellspacing=\"0\">\n";
1169 for (my $i = $from; $i <= $to; $i++) {
1170 my $entry = $taglist->[$i];
1172 my $curr = $tag{'id'} eq $head;
1174 print "<tr class=\"dark\">\n";
1176 print "<tr class=\"light\">\n";
1179 print "<td><i>$tag{'age'}</i></td>\n" .
1180 ($tag{'id'} eq $head ?
"<td class=\"current_head\">" : "<td>") .
1181 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}"),
1182 -class => "list"}, "<b>" . esc_html
($tag{'name'}) . "</b>") .
1184 "<td class=\"link\">" .
1185 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") . " | " .
1186 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'name'}")}, "log") .
1190 if (defined $extra) {
1192 "<td colspan=\"3\">$extra</td>\n" .
1198 ## ----------------------------------------------------------------------
1199 ## functions printing large fragments, format as one of arguments
1201 sub git_diff_print
{
1203 my $from_name = shift;
1205 my $to_name = shift;
1206 my $format = shift || "html";
1208 my $from_tmp = "/dev/null";
1209 my $to_tmp = "/dev/null";
1212 # create tmp from-file
1213 if (defined $from) {
1214 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
1215 open my $fd2, "> $from_tmp";
1216 open my $fd, "-|", $GIT, "cat-file", "blob", $from;
1223 # create tmp to-file
1225 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
1226 open my $fd2, "> $to_tmp";
1227 open my $fd, "-|", $GIT, "cat-file", "blob", $to;
1234 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
1235 if ($format eq "plain") {
1240 while (my $line = <$fd>) {
1242 my $char = substr($line, 0, 1);
1243 my $diff_class = "";
1245 $diff_class = " add";
1246 } elsif ($char eq "-") {
1247 $diff_class = " rem";
1248 } elsif ($char eq "@") {
1249 $diff_class = " chunk_header";
1250 } elsif ($char eq "\\") {
1254 $line = untabify
($line);
1255 print "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
1260 if (defined $from) {
1269 ## ======================================================================
1270 ## ======================================================================
1273 sub git_project_list
{
1274 my $order = $cgi->param('o');
1275 if (defined $order && $order !~ m/project|descr|owner|age/) {
1276 die_error
(undef, "Unknown order parameter");
1279 my @list = git_read_projects
();
1282 die_error
(undef, "No projects found");
1284 foreach my $pr (@list) {
1285 my $head = git_read_head
($pr->{'path'});
1286 if (!defined $head) {
1289 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
1290 my %co = git_read_commit
($head);
1294 $pr->{'commit'} = \
%co;
1295 if (!defined $pr->{'descr'}) {
1296 my $descr = git_read_description
($pr->{'path'}) || "";
1297 $pr->{'descr'} = chop_str
($descr, 25, 5);
1299 if (!defined $pr->{'owner'}) {
1300 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
1302 push @projects, $pr;
1306 if (-f
$home_text) {
1307 print "<div class=\"index_include\">\n";
1308 open (my $fd, $home_text);
1313 print "<table class=\"project_list\">\n" .
1315 $order ||= "project";
1316 if ($order eq "project") {
1317 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
1318 print "<th>Project</th>\n";
1321 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=project"),
1322 -class => "header"}, "Project") .
1325 if ($order eq "descr") {
1326 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
1327 print "<th>Description</th>\n";
1330 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=descr"),
1331 -class => "header"}, "Description") .
1334 if ($order eq "owner") {
1335 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
1336 print "<th>Owner</th>\n";
1339 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=owner"),
1340 -class => "header"}, "Owner") .
1343 if ($order eq "age") {
1344 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
1345 print "<th>Last Change</th>\n";
1348 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=age"),
1349 -class => "header"}, "Last Change") .
1352 print "<th></th>\n" .
1355 foreach my $pr (@projects) {
1357 print "<tr class=\"dark\">\n";
1359 print "<tr class=\"light\">\n";
1362 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=summary"),
1363 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
1364 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
1365 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
1366 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" .
1367 $pr->{'commit'}{'age_string'} . "</td>\n" .
1368 "<td class=\"link\">" .
1369 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=summary")}, "summary") . " | " .
1370 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=shortlog")}, "shortlog") . " | " .
1371 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=log")}, "log") .
1380 my $descr = git_read_description
($project) || "none";
1381 my $head = git_read_head
($project);
1382 my %co = git_read_commit
($head);
1383 my %cd = date_str
($co{'committer_epoch'}, $co{'committer_tz'});
1386 if (-f
$projects_list) {
1387 open (my $fd , $projects_list);
1388 while (my $line = <$fd>) {
1390 my ($pr, $ow) = split ' ', $line;
1391 $pr = unescape
($pr);
1392 $ow = unescape
($ow);
1393 if ($pr eq $project) {
1394 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
1400 if (!defined $owner) {
1401 $owner = get_file_owner
("$projectroot/$project");
1404 my $refs = read_info_ref
();
1406 git_page_nav
('summary','', $head);
1408 print "<div class=\"title\"> </div>\n";
1409 print "<table cellspacing=\"0\">\n" .
1410 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
1411 "<tr><td>owner</td><td>$owner</td></tr>\n" .
1412 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
1415 open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_read_head
($project)
1416 or die_error
(undef, "Open git-rev-list failed");
1417 my @revlist = map { chomp; $_ } <$fd>;
1419 git_header_div
('shortlog');
1420 git_shortlog_body
(\
@revlist, 0, 15, $refs,
1421 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "..."));
1423 my $taglist = git_read_refs
("refs/tags");
1424 if (defined @
$taglist) {
1425 git_header_div
('tags');
1426 git_tags_body
($taglist, 0, 15,
1427 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tags")}, "..."));
1430 my $headlist = git_read_refs
("refs/heads");
1431 if (defined @
$headlist) {
1432 git_header_div
('heads');
1433 git_heads_body
($headlist, $head, 0, 15,
1434 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=heads")}, "..."));
1441 my $head = git_read_head
($project);
1443 git_page_nav
('','', $head,undef,$head);
1444 my %tag = git_read_tag
($hash);
1445 git_header_div
('commit', esc_html
($tag{'name'}), $hash);
1446 print "<div class=\"title_text\">\n" .
1447 "<table cellspacing=\"0\">\n" .
1449 "<td>object</td>\n" .
1450 "<td>" . $cgi->a({-class => "list", -href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'object'}) . "</td>\n" .
1451 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'type'}) . "</td>\n" .
1453 if (defined($tag{'author'})) {
1454 my %ad = date_str
($tag{'epoch'}, $tag{'tz'});
1455 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
1456 print "<tr><td></td><td>" . $ad{'rfc2822'} . sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) . "</td></tr>\n";
1458 print "</table>\n\n" .
1460 print "<div class=\"page_body\">";
1461 my $comment = $tag{'comment'};
1462 foreach my $line (@
$comment) {
1463 print esc_html
($line) . "<br/>\n";
1472 die_error
(undef, "Permission denied") if (!git_get_project_config_bool
('blame'));
1473 die_error
('404 Not Found', "File name not defined") if (!$file_name);
1474 $hash_base ||= git_read_head
($project);
1475 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
1476 my %co = git_read_commit
($hash_base)
1477 or die_error
(undef, "Reading commit failed");
1478 if (!defined $hash) {
1479 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
1480 or die_error
(undef, "Error looking up file");
1482 $ftype = git_get_type
($hash);
1483 if ($ftype !~ "blob") {
1484 die_error
("400 Bad Request", "Object is not a blob");
1486 open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base)
1487 or die_error
(undef, "Open git-blame failed");
1490 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") .
1491 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;f=$file_name")}, "head");
1492 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1493 git_header_div
('commit', esc_html
($co{'title'}), $hash_base);
1494 git_print_page_path
($file_name, $ftype);
1495 my @rev_color = (qw(light dark));
1496 my $num_colors = scalar(@rev_color);
1497 my $current_color = 0;
1499 print "<div class=\"page_body\">\n";
1500 print "<table class=\"blame\">\n";
1501 print "<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n";
1503 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
1505 my $rev = substr($full_rev, 0, 8);
1509 if (!defined $last_rev) {
1510 $last_rev = $full_rev;
1511 } elsif ($last_rev ne $full_rev) {
1512 $last_rev = $full_rev;
1513 $current_color = ++$current_color % $num_colors;
1515 print "<tr class=\"$rev_color[$current_color]\">\n";
1516 print "<td class=\"sha1\">" .
1517 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$full_rev;f=$file_name")}, esc_html
($rev)) . "</td>\n";
1518 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" . esc_html
($lineno) . "</a></td>\n";
1519 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
1524 close $fd or print "Reading blob failed\n";
1530 die_error
('403 Permission denied', "Permission denied") if (!git_get_project_config_bool
('blame'));
1531 die_error
('404 Not Found', "File name not defined") if (!$file_name);
1532 $hash_base ||= git_read_head
($project);
1533 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
1534 my %co = git_read_commit
($hash_base)
1535 or die_error
(undef, "Reading commit failed");
1536 if (!defined $hash) {
1537 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
1538 or die_error
(undef, "Error lookup file");
1540 open ($fd, "-|", $GIT, "annotate", '-l', '-t', '-r', $file_name, $hash_base)
1541 or die_error
(undef, "Open git-annotate failed");
1544 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") .
1545 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;f=$file_name")}, "head");
1546 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1547 git_header_div
('commit', esc_html
($co{'title'}), $hash_base);
1548 git_print_page_path
($file_name, 'blob');
1549 print "<div class=\"page_body\">\n";
1551 <table class="blame">
1560 my @line_class = (qw(light dark));
1561 my $line_class_len = scalar (@line_class);
1562 my $line_class_num = $#line_class;
1563 while (my $line = <$fd>) {
1575 $line_class_num = ($line_class_num + 1) % $line_class_len;
1577 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) \+\d\d\d\d\t(\d+)\)(.*)$/) {
1584 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
1587 $short_rev = substr ($long_rev, 0, 8);
1588 $age = time () - $time;
1589 $age_str = age_string
($age);
1590 $age_str =~ s/ / /g;
1591 $age_class = age_class
($age);
1592 $author = esc_html
($author);
1593 $author =~ s/ / /g;
1595 $data = untabify
($data);
1596 $data = esc_html
($data);
1599 <tr class="$line_class[$line_class_num]">
1600 <td class="sha1"><a href="$my_uri?${\esc_param ("p=$project;a=commit;h=$long_rev")}" class="text">$short_rev..</a></td>
1601 <td class="$age_class">$age_str</td>
1603 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
1604 <td class="pre">$data</td>
1607 } # while (my $line = <$fd>)
1608 print "</table>\n\n";
1609 close $fd or print "Reading blob failed.\n";
1615 my $head = git_read_head
($project);
1617 git_page_nav
('','', $head,undef,$head);
1618 git_header_div
('summary', $project);
1620 my $taglist = git_read_refs
("refs/tags");
1621 if (defined @
$taglist) {
1622 git_tags_body
($taglist);
1628 my $head = git_read_head
($project);
1630 git_page_nav
('','', $head,undef,$head);
1631 git_header_div
('summary', $project);
1633 my $taglist = git_read_refs
("refs/heads");
1635 if (defined @
$taglist) {
1636 git_heads_body
($taglist, $head);
1641 sub git_blob_plain
{
1642 if (!defined $hash) {
1643 if (defined $file_name) {
1644 my $base = $hash_base || git_read_head
($project);
1645 $hash = git_get_hash_by_path
($base, $file_name, "blob")
1646 or die_error
(undef, "Error lookup file");
1648 die_error
(undef, "No file name defined");
1652 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
1653 or die_error
(undef, "Couldn't cat $file_name, $hash");
1655 $type ||= git_blob_plain_mimetype
($fd, $file_name);
1657 # save as filename, even when no $file_name is given
1658 my $save_as = "$hash";
1659 if (defined $file_name) {
1660 $save_as = $file_name;
1661 } elsif ($type =~ m/^text\//) {
1665 print $cgi->header(-type
=> "$type", '-content-disposition' => "inline; filename=\"$save_as\"");
1667 binmode STDOUT
, ':raw';
1669 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
1675 if (!defined $hash) {
1676 if (defined $file_name) {
1677 my $base = $hash_base || git_read_head
($project);
1678 $hash = git_get_hash_by_path
($base, $file_name, "blob")
1679 or die_error
(undef, "Error lookup file");
1681 die_error
(undef, "No file name defined");
1684 my $have_blame = git_get_project_config_bool
('blame');
1685 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
1686 or die_error
(undef, "Couldn't cat $file_name, $hash");
1687 my $mimetype = git_blob_plain_mimetype
($fd, $file_name);
1688 if ($mimetype !~ m/^text\//) {
1690 return git_blob_plain
($mimetype);
1693 my $formats_nav = '';
1694 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
1695 if (defined $file_name) {
1697 $formats_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;h=$hash;hb=$hash_base;f=$file_name")}, "blame") . " | ";
1700 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$hash;f=$file_name")}, "plain") .
1701 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;hb=HEAD;f=$file_name")}, "head");
1703 $formats_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$hash")}, "plain");
1705 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1706 git_header_div
('commit', esc_html
($co{'title'}), $hash_base);
1708 print "<div class=\"page_nav\">\n" .
1709 "<br/><br/></div>\n" .
1710 "<div class=\"title\">$hash</div>\n";
1712 git_print_page_path
($file_name, "blob");
1713 print "<div class=\"page_body\">\n";
1715 while (my $line = <$fd>) {
1718 $line = untabify
($line);
1719 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", $nr, $nr, $nr, esc_html
($line);
1721 close $fd or print "Reading blob failed.\n";
1727 if (!defined $hash) {
1728 $hash = git_read_head
($project);
1729 if (defined $file_name) {
1730 my $base = $hash_base || $hash;
1731 $hash = git_get_hash_by_path
($base, $file_name, "tree");
1733 if (!defined $hash_base) {
1738 open my $fd, "-|", $GIT, "ls-tree", '-z', $hash
1739 or die_error
(undef, "Open git-ls-tree failed");
1740 my @entries = map { chomp; $_ } <$fd>;
1741 close $fd or die_error
(undef, "Reading tree failed");
1744 my $refs = read_info_ref
();
1745 my $ref = git_get_referencing
($refs, $hash_base);
1749 my $have_blame = git_get_project_config_bool
('blame');
1750 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
1751 $base_key = ";hb=$hash_base";
1752 git_page_nav
('tree','', $hash_base);
1753 git_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
1755 print "<div class=\"page_nav\">\n";
1756 print "<br/><br/></div>\n";
1757 print "<div class=\"title\">$hash</div>\n";
1759 if (defined $file_name) {
1760 $base = esc_html
("$file_name/");
1762 git_print_page_path
($file_name, 'tree');
1763 print "<div class=\"page_body\">\n";
1764 print "<table cellspacing=\"0\">\n";
1766 foreach my $line (@entries) {
1767 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1768 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1772 my $t_name = validate_input
($4);
1774 print "<tr class=\"dark\">\n";
1776 print "<tr class=\"light\">\n";
1779 print "<td class=\"mode\">" . mode_str
($t_mode) . "</td>\n";
1780 if ($t_type eq "blob") {
1781 print "<td class=\"list\">" .
1782 $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)) .
1784 "<td class=\"link\">" .
1785 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name")}, "blob");
1787 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;h=$t_hash$base_key;f=$base$t_name")}, "blame");
1789 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;h=$t_hash;hb=$hash_base;f=$base$t_name")}, "history") .
1790 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$t_hash;f=$base$t_name")}, "raw") .
1792 } elsif ($t_type eq "tree") {
1793 print "<td class=\"list\">" .
1794 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, esc_html
($t_name)) .
1796 "<td class=\"link\">" .
1797 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, "tree") .
1798 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;hb=$hash_base;f=$base$t_name")}, "history") .
1803 print "</table>\n" .
1809 my $head = git_read_head
($project);
1810 if (!defined $hash) {
1813 if (!defined $page) {
1816 my $refs = read_info_ref
();
1818 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
1819 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
1820 or die_error
(undef, "Open git-rev-list failed");
1821 my @revlist = map { chomp; $_ } <$fd>;
1824 my $paging_nav = git_get_paging_nav
('log', $hash, $head, $page, $#revlist);
1827 git_page_nav
('log','', $hash,undef,undef, $paging_nav);
1830 my %co = git_read_commit
($hash);
1832 git_header_div
('summary', $project);
1833 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
1835 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
1836 my $commit = $revlist[$i];
1837 my $ref = git_get_referencing
($refs, $commit);
1838 my %co = git_read_commit
($commit);
1840 my %ad = date_str
($co{'author_epoch'});
1841 git_header_div
('commit',
1842 "<span class=\"age\">$co{'age_string'}</span>" .
1843 esc_html
($co{'title'}) . $ref,
1845 print "<div class=\"title_text\">\n" .
1846 "<div class=\"log_link\">\n" .
1847 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
1848 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1851 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
1853 "<div class=\"log_body\">\n";
1854 my $comment = $co{'comment'};
1856 foreach my $line (@
$comment) {
1857 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1868 print format_log_line_html
($line) . "<br/>\n";
1879 my %co = git_read_commit
($hash);
1881 die_error
(undef, "Unknown commit object");
1883 my %ad = date_str
($co{'author_epoch'}, $co{'author_tz'});
1884 my %cd = date_str
($co{'committer_epoch'}, $co{'committer_tz'});
1886 my $parent = $co{'parent'};
1887 if (!defined $parent) {
1890 open my $fd, "-|", $GIT, "diff-tree", '-r', '-M', $parent, $hash
1891 or die_error
(undef, "Open git-diff-tree failed");
1892 my @difftree = map { chomp; $_ } <$fd>;
1893 close $fd or die_error
(undef, "Reading git-diff-tree failed");
1895 # non-textual hash id's can be cached
1897 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
1900 my $refs = read_info_ref
();
1901 my $ref = git_get_referencing
($refs, $co{'id'});
1902 my $formats_nav = '';
1903 if (defined $file_name && defined $co{'parent'}) {
1904 my $parent = $co{'parent'};
1905 $formats_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;hb=$parent;f=$file_name")}, "blame");
1907 git_header_html
(undef, $expires);
1908 git_page_nav
('commit', defined $co{'parent'} ?
'' : 'commitdiff',
1909 $hash, $co{'tree'}, $hash,
1912 if (defined $co{'parent'}) {
1913 git_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
1915 git_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
1917 print "<div class=\"title_text\">\n" .
1918 "<table cellspacing=\"0\">\n";
1919 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
1921 "<td></td><td> $ad{'rfc2822'}";
1922 if ($ad{'hour_local'} < 6) {
1923 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1925 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1929 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
1930 print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
1931 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
1934 "<td class=\"sha1\">" .
1935 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash"), class => "list"}, $co{'tree'}) .
1937 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
1940 my $parents = $co{'parents'};
1941 foreach my $par (@
$parents) {
1944 "<td class=\"sha1\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$par"), class => "list"}, $par) . "</td>" .
1945 "<td class=\"link\">" .
1946 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$par")}, "commit") .
1947 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash;hp=$par")}, "commitdiff") .
1953 print "<div class=\"page_body\">\n";
1954 my $comment = $co{'comment'};
1957 foreach my $line (@
$comment) {
1958 # print only one empty line
1960 if ($empty || $signed) {
1967 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1969 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1972 print format_log_line_html
($line) . "<br/>\n";
1976 print "<div class=\"list_head\">\n";
1977 if ($#difftree > 10) {
1978 print(($#difftree + 1) . " files changed:\n");
1981 print "<table class=\"diff_tree\">\n";
1983 foreach my $line (@difftree) {
1984 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1985 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1986 if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1994 my $similarity = $6;
1995 my $file = validate_input
(unquote
($7));
1997 print "<tr class=\"dark\">\n";
1999 print "<tr class=\"light\">\n";
2002 if ($status eq "A") {
2004 if (S_ISREG
(oct $to_mode)) {
2005 $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
2008 $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" .
2009 "<td><span class=\"file_status new\">[new " . file_type
($to_mode) . "$mode_chng]</span></td>\n" .
2010 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob") . "</td>\n";
2011 } elsif ($status eq "D") {
2013 $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" .
2014 "<td><span class=\"file_status deleted\">[deleted " . file_type
($from_mode). "]</span></td>\n" .
2015 "<td class=\"link\">" .
2016 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, "blob") .
2017 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;hb=$hash;f=$file")}, "history") .
2019 } elsif ($status eq "M" || $status eq "T") {
2020 my $mode_chnge = "";
2021 if ($from_mode != $to_mode) {
2022 $mode_chnge = " <span class=\"file_status mode_chnge\">[changed";
2023 if (((oct $from_mode) & S_IFMT
) != ((oct $to_mode) & S_IFMT
)) {
2024 $mode_chnge .= " from " . file_type
($from_mode) . " to " . file_type
($to_mode);
2026 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
2027 if (S_ISREG
($from_mode) && S_ISREG
($to_mode)) {
2028 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
2029 } elsif (S_ISREG
($to_mode)) {
2030 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
2033 $mode_chnge .= "]</span>\n";
2036 if ($to_id ne $from_id) {
2037 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));
2039 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file"), -class => "list"}, esc_html
($file));
2042 "<td>$mode_chnge</td>\n" .
2043 "<td class=\"link\">";
2044 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob");
2045 if ($to_id ne $from_id) {
2046 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file")}, "diff");
2048 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;hb=$hash;f=$file")}, "history") . "\n";
2050 } elsif ($status eq "R") {
2051 my ($from_file, $to_file) = split "\t", $file;
2053 if ($from_mode != $to_mode) {
2054 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
2057 $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" .
2058 "<td><span class=\"file_status moved\">[moved from " .
2059 $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)) .
2060 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
2061 "<td class=\"link\">" .
2062 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file")}, "blob");
2063 if ($to_id ne $from_id) {
2064 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file")}, "diff");
2075 mkdir($git_temp, 0700);
2077 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
2079 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff_plain;h=$hash;hp=$hash_parent")}, "plain");
2080 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2081 git_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2083 print "<div class=\"page_nav\">\n" .
2084 "<br/><br/></div>\n" .
2085 "<div class=\"title\">$hash vs $hash_parent</div>\n";
2087 git_print_page_path
($file_name, "blob");
2088 print "<div class=\"page_body\">\n" .
2089 "<div class=\"diff_info\">blob:" .
2090 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name")}, $hash_parent) .
2092 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, $hash) .
2094 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
2099 sub git_blobdiff_plain
{
2100 mkdir($git_temp, 0700);
2101 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8');
2102 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
2105 sub git_commitdiff
{
2106 mkdir($git_temp, 0700);
2107 my %co = git_read_commit
($hash);
2109 die_error
(undef, "Unknown commit object");
2111 if (!defined $hash_parent) {
2112 $hash_parent = $co{'parent'} || '--root';
2114 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2115 or die_error
(undef, "Open git-diff-tree failed");
2116 my @difftree = map { chomp; $_ } <$fd>;
2117 close $fd or die_error
(undef, "Reading git-diff-tree failed");
2119 # non-textual hash id's can be cached
2121 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2124 my $refs = read_info_ref
();
2125 my $ref = git_get_referencing
($refs, $co{'id'});
2127 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent")}, "plain");
2128 git_header_html
(undef, $expires);
2129 git_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
2130 git_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
2131 print "<div class=\"page_body\">\n";
2132 my $comment = $co{'comment'};
2135 my @log = @
$comment;
2136 # remove first and empty lines after that
2138 while (defined $log[0] && $log[0] eq "") {
2141 foreach my $line (@log) {
2142 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2153 print format_log_line_html
($line) . "<br/>\n";
2156 foreach my $line (@difftree) {
2157 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2158 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2159 if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2167 my $file = validate_input
(unquote
($6));
2168 if ($status eq "A") {
2169 print "<div class=\"diff_info\">" . file_type
($to_mode) . ":" .
2170 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id) . "(new)" .
2172 git_diff_print
(undef, "/dev/null", $to_id, "b/$file");
2173 } elsif ($status eq "D") {
2174 print "<div class=\"diff_info\">" . file_type
($from_mode) . ":" .
2175 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) . "(deleted)" .
2177 git_diff_print
($from_id, "a/$file", undef, "/dev/null");
2178 } elsif ($status eq "M") {
2179 if ($from_id ne $to_id) {
2180 print "<div class=\"diff_info\">" .
2181 file_type
($from_mode) . ":" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) .
2183 file_type
($to_mode) . ":" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id);
2185 git_diff_print
($from_id, "a/$file", $to_id, "b/$file");
2194 sub git_commitdiff_plain
{
2195 mkdir($git_temp, 0700);
2196 my %co = git_read_commit
($hash);
2198 die_error
(undef, "Unknown commit object");
2200 if (!defined $hash_parent) {
2201 $hash_parent = $co{'parent'} || '--root';
2203 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2204 or die_error
(undef, "Open git-diff-tree failed");
2205 my @difftree = map { chomp; $_ } <$fd>;
2206 close $fd or die_error
(undef, "Reading diff-tree failed");
2208 # try to figure out the next tag after this commit
2210 my $refs = read_info_ref
("tags");
2211 open $fd, "-|", $GIT, "rev-list", "HEAD";
2212 my @commits = map { chomp; $_ } <$fd>;
2214 foreach my $commit (@commits) {
2215 if (defined $refs->{$commit}) {
2216 $tagname = $refs->{$commit}
2218 if ($commit eq $hash) {
2223 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8', '-content-disposition' => "inline; filename=\"git-$hash.patch\"");
2224 my %ad = date_str
($co{'author_epoch'}, $co{'author_tz'});
2225 my $comment = $co{'comment'};
2226 print "From: $co{'author'}\n" .
2227 "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
2228 "Subject: $co{'title'}\n";
2229 if (defined $tagname) {
2230 print "X-Git-Tag: $tagname\n";
2232 print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
2235 foreach my $line (@
$comment) {;
2240 foreach my $line (@difftree) {
2241 if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2248 if ($status eq "A") {
2249 git_diff_print
(undef, "/dev/null", $to_id, "b/$file", "plain");
2250 } elsif ($status eq "D") {
2251 git_diff_print
($from_id, "a/$file", undef, "/dev/null", "plain");
2252 } elsif ($status eq "M") {
2253 git_diff_print
($from_id, "a/$file", $to_id, "b/$file", "plain");
2259 if (!defined $hash_base) {
2260 $hash_base = git_read_head
($project);
2263 my %co = git_read_commit
($hash_base);
2265 die_error
(undef, "Unknown commit object");
2267 my $refs = read_info_ref
();
2269 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base);
2270 git_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2271 if (!defined $hash && defined $file_name) {
2272 $hash = git_get_hash_by_path
($hash_base, $file_name);
2274 if (defined $hash) {
2275 $ftype = git_get_type
($hash);
2277 git_print_page_path
($file_name, $ftype);
2280 $GIT, "rev-list", "--full-history", $hash_base, "--", $file_name;
2281 print "<table cellspacing=\"0\">\n";
2283 while (my $line = <$fd>) {
2284 if ($line =~ m/^([0-9a-fA-F]{40})/){
2286 my %co = git_read_commit
($commit);
2290 my $ref = git_get_referencing
($refs, $commit);
2292 print "<tr class=\"dark\">\n";
2294 print "<tr class=\"light\">\n";
2297 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2298 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2299 "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list"}, "<b>" .
2300 esc_html
(chop_str
($co{'title'}, 50)) . "$ref</b>") . "</td>\n" .
2301 "<td class=\"link\">" .
2302 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
2303 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2304 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$ftype;hb=$commit;f=$file_name")}, $ftype);
2305 my $blob = git_get_hash_by_path
($hash_base, $file_name);
2306 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2307 if (defined $blob && defined $blob_parent && $blob ne $blob_parent) {
2309 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=$file_name")},
2322 if (!defined $searchtext) {
2323 die_error
(undef, "Text field empty");
2325 if (!defined $hash) {
2326 $hash = git_read_head
($project);
2328 my %co = git_read_commit
($hash);
2330 die_error
(undef, "Unknown commit object");
2332 # pickaxe may take all resources of your box and run for several minutes
2333 # with every query - so decide by yourself how public you make this feature :)
2334 my $commit_search = 1;
2335 my $author_search = 0;
2336 my $committer_search = 0;
2337 my $pickaxe_search = 0;
2338 if ($searchtext =~ s/^author\\://i) {
2340 } elsif ($searchtext =~ s/^committer\\://i) {
2341 $committer_search = 1;
2342 } elsif ($searchtext =~ s/^pickaxe\\://i) {
2344 $pickaxe_search = 1;
2347 git_page_nav
('','', $hash,$co{'tree'},$hash);
2348 git_header_div
('commit', esc_html
($co{'title'}), $hash);
2350 print "<table cellspacing=\"0\">\n";
2352 if ($commit_search) {
2354 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", $hash or next;
2355 while (my $commit_text = <$fd>) {
2356 if (!grep m/$searchtext/i, $commit_text) {
2359 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
2362 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
2365 my @commit_lines = split "\n", $commit_text;
2366 my %co = git_read_commit
(undef, \
@commit_lines);
2371 print "<tr class=\"dark\">\n";
2373 print "<tr class=\"light\">\n";
2376 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2377 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2379 $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/>");
2380 my $comment = $co{'comment'};
2381 foreach my $line (@
$comment) {
2382 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2383 my $lead = esc_html
($1) || "";
2384 $lead = chop_str
($lead, 30, 10);
2385 my $match = esc_html
($2) || "";
2386 my $trail = esc_html
($3) || "";
2387 $trail = chop_str
($trail, 30, 10);
2388 my $text = "$lead<span class=\"match\">$match</span>$trail";
2389 print chop_str
($text, 80, 5) . "<br/>\n";
2393 "<td class=\"link\">" .
2394 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2395 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2402 if ($pickaxe_search) {
2404 open my $fd, "-|", "$GIT rev-list $hash | $GIT diff-tree -r --stdin -S\'$searchtext\'";
2407 while (my $line = <$fd>) {
2408 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2411 $set{'from_id'} = $3;
2413 $set{'id'} = $set{'to_id'};
2414 if ($set{'id'} =~ m/0{40}/) {
2415 $set{'id'} = $set{'from_id'};
2417 if ($set{'id'} =~ m/0{40}/) {
2421 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
2424 print "<tr class=\"dark\">\n";
2426 print "<tr class=\"light\">\n";
2429 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2430 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2432 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" .
2433 esc_html
(chop_str
($co{'title'}, 50)) . "</b><br/>");
2434 while (my $setref = shift @files) {
2436 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}"), class => "list"},
2437 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
2441 "<td class=\"link\">" .
2442 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2443 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2447 %co = git_read_commit
($1);
2457 my $head = git_read_head
($project);
2458 if (!defined $hash) {
2461 if (!defined $page) {
2464 my $refs = read_info_ref
();
2466 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2467 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2468 or die_error
(undef, "Open git-rev-list failed");
2469 my @revlist = map { chomp; $_ } <$fd>;
2472 my $paging_nav = git_get_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
2474 if ($#revlist >= (100 * ($page+1)-1)) {
2476 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)),
2477 -title
=> "Alt-n"}, "next");
2482 git_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
2483 git_header_div
('summary', $project);
2485 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
2490 ## ......................................................................
2491 ## feeds (RSS, OPML)
2494 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
2495 open my $fd, "-|", $GIT, "rev-list", "--max-count=150", git_read_head
($project)
2496 or die_error
(undef, "Open git-rev-list failed");
2497 my @revlist = map { chomp; $_ } <$fd>;
2498 close $fd or die_error
(undef, "Reading git-rev-list failed");
2499 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
2500 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
2501 "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
2502 print "<channel>\n";
2503 print "<title>$project</title>\n".
2504 "<link>" . esc_html
("$my_url?p=$project;a=summary") . "</link>\n".
2505 "<description>$project log</description>\n".
2506 "<language>en</language>\n";
2508 for (my $i = 0; $i <= $#revlist; $i++) {
2509 my $commit = $revlist[$i];
2510 my %co = git_read_commit
($commit);
2511 # we read 150, we always show 30 and the ones more recent than 48 hours
2512 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
2515 my %cd = date_str
($co{'committer_epoch'});
2516 open $fd, "-|", $GIT, "diff-tree", '-r', $co{'parent'}, $co{'id'} or next;
2517 my @difftree = map { chomp; $_ } <$fd>;
2521 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
2523 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
2524 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
2525 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
2526 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
2527 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
2528 "<content:encoded>" .
2530 my $comment = $co{'comment'};
2531 foreach my $line (@
$comment) {
2532 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
2533 print "$line<br/>\n";
2536 foreach my $line (@difftree) {
2537 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
2540 my $file = validate_input
(unquote
($7));
2541 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
2542 print "$file<br/>\n";
2545 "</content:encoded>\n" .
2548 print "</channel></rss>";
2552 my @list = git_read_projects
();
2554 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
2555 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
2556 "<opml version=\"1.0\">\n".
2558 " <title>$site_name Git OPML Export</title>\n".
2561 "<outline text=\"git RSS feeds\">\n";
2563 foreach my $pr (@list) {
2565 my $head = git_read_head
($proj{'path'});
2566 if (!defined $head) {
2569 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
2570 my %co = git_read_commit
($head);
2575 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
2576 my $rss = "$my_url?p=$proj{'path'};a=rss";
2577 my $html = "$my_url?p=$proj{'path'};a=summary";
2578 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
2580 print "</outline>\n".