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 if (defined $project) {
92 if (defined $project && $project) {
93 if (!validate_input
($project)) {
94 die_error
(undef, "Invalid project parameter");
96 if (!(-d
"$projectroot/$project")) {
97 die_error
(undef, "No such directory");
99 if (!(-e
"$projectroot/$project/HEAD")) {
100 die_error
(undef, "No such project");
102 $ENV{'GIT_DIR'} = "$projectroot/$project";
108 our $file_name = $cgi->param('f');
109 if (defined $file_name) {
110 if (!validate_input
($file_name)) {
111 die_error
(undef, "Invalid file parameter");
115 our $hash = $cgi->param('h');
117 if (!validate_input
($hash)) {
118 die_error
(undef, "Invalid hash parameter");
122 our $hash_parent = $cgi->param('hp');
123 if (defined $hash_parent) {
124 if (!validate_input
($hash_parent)) {
125 die_error
(undef, "Invalid hash parent parameter");
129 our $hash_base = $cgi->param('hb');
130 if (defined $hash_base) {
131 if (!validate_input
($hash_base)) {
132 die_error
(undef, "Invalid hash base parameter");
136 our $page = $cgi->param('pg');
138 if ($page =~ m/[^0-9]$/) {
139 die_error
(undef, "Invalid page parameter");
143 our $searchtext = $cgi->param('s');
144 if (defined $searchtext) {
145 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
146 die_error
(undef, "Invalid search parameter");
148 $searchtext = quotemeta $searchtext;
153 "blame" => \
&git_blame2
,
154 "blobdiff" => \
&git_blobdiff
,
155 "blobdiff_plain" => \
&git_blobdiff_plain
,
156 "blob" => \
&git_blob
,
157 "blob_plain" => \
&git_blob_plain
,
158 "commitdiff" => \
&git_commitdiff
,
159 "commitdiff_plain" => \
&git_commitdiff_plain
,
160 "commit" => \
&git_commit
,
161 "heads" => \
&git_heads
,
162 "history" => \
&git_history
,
165 "search" => \
&git_search
,
166 "shortlog" => \
&git_shortlog
,
167 "summary" => \
&git_summary
,
169 "tags" => \
&git_tags
,
170 "tree" => \
&git_tree
,
173 $action = 'summary' if (!defined($action));
174 if (!defined($actions{$action})) {
175 die_error
(undef, "Unknown action");
177 $actions{$action}->();
180 ## ======================================================================
181 ## validation, quoting/unquoting and escaping
186 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
189 if ($input =~ m/(^|\/)(|\
.|\
.\
.)($|\
/)/) {
192 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\
-\
+\#\
~\
%]/) {
198 # quote unsafe chars, but keep the slash, even when it's not
199 # correct, but quoted slashes look too horrible in bookmarks
202 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
208 # replace invalid utf8 character with SUBSTITUTION sequence
211 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
212 $str = escapeHTML
($str);
213 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
217 # git may return quoted and escaped filenames
220 if ($str =~ m/^"(.*)"$/) {
222 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
227 # escape tabs (convert tabs to spaces)
231 while ((my $pos = index($line, "\t")) != -1) {
232 if (my $count = (8 - ($pos % 8))) {
233 my $spaces = ' ' x
$count;
234 $line =~ s/\t/$spaces/;
241 ## ----------------------------------------------------------------------
242 ## HTML aware string manipulation
247 my $add_len = shift || 10;
249 # allow only $len chars, but don't cut a word if it would fit in $add_len
250 # if it doesn't fit, cut it if it's still longer than the dots we would add
251 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
254 if (length($tail) > 4) {
256 $body =~ s/&[^;]*$//; # remove chopped character entities
261 ## ----------------------------------------------------------------------
262 ## functions returning short strings
264 # CSS class for given age value (in seconds)
268 if ($age < 60*60*2) {
270 } elsif ($age < 60*60*24*2) {
277 # convert age in seconds to "nn units ago" string
282 if ($age > 60*60*24*365*2) {
283 $age_str = (int $age/60/60/24/365);
284 $age_str .= " years ago";
285 } elsif ($age > 60*60*24*(365/12)*2) {
286 $age_str = int $age/60/60/24/(365/12);
287 $age_str .= " months ago";
288 } elsif ($age > 60*60*24*7*2) {
289 $age_str = int $age/60/60/24/7;
290 $age_str .= " weeks ago";
291 } elsif ($age > 60*60*24*2) {
292 $age_str = int $age/60/60/24;
293 $age_str .= " days ago";
294 } elsif ($age > 60*60*2) {
295 $age_str = int $age/60/60;
296 $age_str .= " hours ago";
297 } elsif ($age > 60*2) {
298 $age_str = int $age/60;
299 $age_str .= " min ago";
302 $age_str .= " sec ago";
304 $age_str .= " right now";
309 # convert file mode in octal to symbolic file mode string
311 my $mode = oct shift;
313 if (S_ISDIR
($mode & S_IFMT
)) {
315 } elsif (S_ISLNK
($mode)) {
317 } elsif (S_ISREG
($mode)) {
318 # git cares only about the executable bit
319 if ($mode & S_IXUSR
) {
329 # convert file mode in octal to file type string
331 my $mode = oct shift;
333 if (S_ISDIR
($mode & S_IFMT
)) {
335 } elsif (S_ISLNK
($mode)) {
337 } elsif (S_ISREG
($mode)) {
344 ## ----------------------------------------------------------------------
345 ## functions returning short HTML fragments, or transforming HTML fragments
346 ## which don't beling to other sections
348 # format line of commit message or tag comment
349 sub format_log_line_html
{
352 $line = esc_html
($line);
353 $line =~ s/ / /g;
354 if ($line =~ m/([0-9a-fA-F]{40})/) {
356 if (git_get_type
($hash_text) eq "commit") {
357 my $link = $cgi->a({-class => "text", -href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_text")}, $hash_text);
358 $line =~ s/$hash_text/$link/;
364 # format marker of refs pointing to given object
365 sub git_get_referencing
{
366 my ($refs, $id) = @_;
368 if (defined $refs->{$id}) {
369 return ' <span class="tag">' . esc_html
($refs->{$id}) . '</span>';
375 ## ----------------------------------------------------------------------
376 ## git utility subroutines, invoking git commands
378 # get HEAD ref of given project as hash
381 my $oENV = $ENV{'GIT_DIR'};
383 $ENV{'GIT_DIR'} = "$projectroot/$project";
384 if (open my $fd, "-|", $GIT, "rev-parse", "--verify", "HEAD") {
387 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
392 $ENV{'GIT_DIR'} = $oENV;
397 # get type of given object
401 open my $fd, "-|", $GIT, "cat-file", '-t', $hash or return;
408 sub git_get_project_config
{
411 return unless ($key);
412 $key =~ s/^gitweb\.//;
413 return if ($key =~ m/\W/);
415 my $val = qx($GIT repo
-config
--get gitweb
.$key);
419 sub git_get_project_config_bool
{
420 my $val = git_get_project_config
(@_);
421 if ($val and $val =~ m/true|yes|on/) {
424 return; # implicit false
427 # get hash of given path at given ref
428 sub git_get_hash_by_path
{
430 my $path = shift || return undef;
434 open my $fd, "-|", $GIT, "ls-tree", $base, "--", $path
435 or die_error
(undef, "Open git-ls-tree failed");
437 close $fd or return undef;
439 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
440 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
444 ## ......................................................................
445 ## git utility functions, directly accessing git repository
447 # assumes that PATH is not symref
451 open my $fd, "$projectroot/$path" or return undef;
455 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
460 sub git_read_description
{
463 open my $fd, "$projectroot/$path/description" or return undef;
470 sub git_read_projects
{
473 if (-d
$projects_list) {
474 # search in directory
475 my $dir = $projects_list;
476 opendir my ($dh), $dir or return undef;
477 while (my $dir = readdir($dh)) {
478 if (-e
"$projectroot/$dir/HEAD") {
486 } elsif (-f
$projects_list) {
487 # read from file(url-encoded):
488 # 'git%2Fgit.git Linus+Torvalds'
489 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
490 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
491 open my ($fd), $projects_list or return undef;
492 while (my $line = <$fd>) {
494 my ($path, $owner) = split ' ', $line;
495 $path = unescape
($path);
496 $owner = unescape
($owner);
497 if (!defined $path) {
500 if (-e
"$projectroot/$path/HEAD") {
503 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
510 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
515 my $type = shift || "";
517 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
518 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
519 open my $fd, "$projectroot/$project/info/refs" or return;
520 while (my $line = <$fd>) {
522 # attention: for $type == "" it saves only last path part of ref name
523 # e.g. from 'refs/heads/jn/gitweb' it would leave only 'gitweb'
524 if ($line =~ m/^([0-9a-fA-F]{40})\t.*$type\/([^\
^]+)/) {
525 if (defined $refs{$1}) {
526 $refs{$1} .= " / $2";
536 ## ----------------------------------------------------------------------
537 ## parse to hash functions
541 my $tz = shift || "-0000";
544 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
545 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
546 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
547 $date{'hour'} = $hour;
548 $date{'minute'} = $min;
549 $date{'mday'} = $mday;
550 $date{'day'} = $days[$wday];
551 $date{'month'} = $months[$mon];
552 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
553 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
555 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
556 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
557 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
558 $date{'hour_local'} = $hour;
559 $date{'minute_local'} = $min;
560 $date{'tz_local'} = $tz;
569 open my $fd, "-|", $GIT, "cat-file", "tag", $tag_id or return;
570 $tag{'id'} = $tag_id;
571 while (my $line = <$fd>) {
573 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
575 } elsif ($line =~ m/^type (.+)$/) {
577 } elsif ($line =~ m/^tag (.+)$/) {
579 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
583 } elsif ($line =~ m/--BEGIN/) {
584 push @comment, $line;
586 } elsif ($line eq "") {
590 push @comment, <$fd>;
591 $tag{'comment'} = \
@comment;
593 if (!defined $tag{'name'}) {
599 sub git_read_commit
{
600 my $commit_id = shift;
601 my $commit_text = shift;
606 if (defined $commit_text) {
607 @commit_lines = @
$commit_text;
610 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", "--max-count=1", $commit_id or return;
611 @commit_lines = split '\n', <$fd>;
616 my $header = shift @commit_lines;
617 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
620 ($co{'id'}, my @parents) = split ' ', $header;
621 $co{'parents'} = \
@parents;
622 $co{'parent'} = $parents[0];
623 while (my $line = shift @commit_lines) {
624 last if $line eq "\n";
625 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
627 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
629 $co{'author_epoch'} = $2;
630 $co{'author_tz'} = $3;
631 if ($co{'author'} =~ m/^([^<]+) </) {
632 $co{'author_name'} = $1;
634 $co{'author_name'} = $co{'author'};
636 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
637 $co{'committer'} = $1;
638 $co{'committer_epoch'} = $2;
639 $co{'committer_tz'} = $3;
640 $co{'committer_name'} = $co{'committer'};
641 $co{'committer_name'} =~ s/ <.*//;
644 if (!defined $co{'tree'}) {
648 foreach my $title (@commit_lines) {
651 $co{'title'} = chop_str
($title, 80, 5);
652 # remove leading stuff of merges to make the interesting part visible
653 if (length($title) > 50) {
654 $title =~ s/^Automatic //;
655 $title =~ s/^merge (of|with) /Merge ... /i;
656 if (length($title) > 50) {
657 $title =~ s/(http|rsync):\/\///;
659 if (length($title) > 50) {
660 $title =~ s/(master|www|rsync)\.//;
662 if (length($title) > 50) {
663 $title =~ s/kernel.org:?//;
665 if (length($title) > 50) {
666 $title =~ s/\/pub\/scm//;
669 $co{'title_short'} = chop_str
($title, 50, 5);
673 # remove added spaces
674 foreach my $line (@commit_lines) {
677 $co{'comment'} = \
@commit_lines;
679 my $age = time - $co{'committer_epoch'};
681 $co{'age_string'} = age_string
($age);
682 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
683 if ($age > 60*60*24*7*2) {
684 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
685 $co{'age_string_age'} = $co{'age_string'};
687 $co{'age_string_date'} = $co{'age_string'};
688 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
693 ## ......................................................................
694 ## parse to array of hashes functions
701 my $pfxlen = length("$projectroot/$project/$ref_dir");
702 File
::Find
::find
(sub {
705 push @refs, substr($File::Find
::name
, $pfxlen + 1);
707 }, "$projectroot/$project/$ref_dir");
709 foreach my $ref_file (@refs) {
710 my $ref_id = git_read_hash
("$project/$ref_dir/$ref_file");
711 my $type = git_get_type
($ref_id) || next;
714 $ref_item{'type'} = $type;
715 $ref_item{'id'} = $ref_id;
716 $ref_item{'epoch'} = 0;
717 $ref_item{'age'} = "unknown";
718 if ($type eq "tag") {
719 my %tag = git_read_tag
($ref_id);
720 $ref_item{'comment'} = $tag{'comment'};
721 if ($tag{'type'} eq "commit") {
722 %co = git_read_commit
($tag{'object'});
723 $ref_item{'epoch'} = $co{'committer_epoch'};
724 $ref_item{'age'} = $co{'age_string'};
725 } elsif (defined($tag{'epoch'})) {
726 my $age = time - $tag{'epoch'};
727 $ref_item{'epoch'} = $tag{'epoch'};
728 $ref_item{'age'} = age_string
($age);
730 $ref_item{'reftype'} = $tag{'type'};
731 $ref_item{'name'} = $tag{'name'};
732 $ref_item{'refid'} = $tag{'object'};
733 } elsif ($type eq "commit"){
734 %co = git_read_commit
($ref_id);
735 $ref_item{'reftype'} = "commit";
736 $ref_item{'name'} = $ref_file;
737 $ref_item{'title'} = $co{'title'};
738 $ref_item{'refid'} = $ref_id;
739 $ref_item{'epoch'} = $co{'committer_epoch'};
740 $ref_item{'age'} = $co{'age_string'};
742 $ref_item{'reftype'} = $type;
743 $ref_item{'name'} = $ref_file;
744 $ref_item{'refid'} = $ref_id;
747 push @reflist, \
%ref_item;
750 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
754 ## ----------------------------------------------------------------------
755 ## filesystem-related functions
760 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
761 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
762 if (!defined $gcos) {
766 $owner =~ s/[,;].*$//;
767 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
770 ## ......................................................................
771 ## mimetype related functions
773 sub mimetype_guess_file
{
774 my $filename = shift;
776 -r
$mimemap or return undef;
779 open(MIME
, $mimemap) or return undef;
781 my ($mime, $exts) = split(/\t+/);
783 my @exts = split(/\s+/, $exts);
784 foreach my $ext (@exts) {
785 $mimemap{$ext} = $mime;
791 $filename =~ /\.(.*?)$/;
796 my $filename = shift;
798 $filename =~ /\./ or return undef;
800 if ($mimetypes_file) {
801 my $file = $mimetypes_file;
802 #$file =~ m#^/# or $file = "$projectroot/$path/$file";
803 $mime = mimetype_guess_file
($filename, $file);
805 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
809 sub git_blob_plain_mimetype
{
811 my $filename = shift;
814 my $mime = mimetype_guess
($filename);
815 $mime and return $mime;
819 return $default_blob_plain_mimetype unless $fd;
822 return 'text/plain' .
823 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
824 } elsif (! $filename) {
825 return 'application/octet-stream';
826 } elsif ($filename =~ m/\.png$/i) {
828 } elsif ($filename =~ m/\.gif$/i) {
830 } elsif ($filename =~ m/\.jpe?g$/i) {
833 return 'application/octet-stream';
837 ## ======================================================================
838 ## functions printing HTML: header, footer, error page
840 sub git_header_html
{
841 my $status = shift || "200 OK";
844 my $title = "$site_name git";
845 if (defined $project) {
846 $title .= " - $project";
847 if (defined $action) {
848 $title .= "/$action";
849 if (defined $file_name) {
850 $title .= " - $file_name";
851 if ($action eq "tree" && $file_name !~ m
|/$|) {
858 # require explicit support from the UA if we are to send the page as
859 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
860 # we have to do this because MSIE sometimes globs '*/*', pretending to
861 # support xhtml+xml but choking when it gets what it asked for.
862 if (defined $cgi->http('HTTP_ACCEPT') && $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ && $cgi->Accept('application/xhtml
+xml
') != 0) {
863 $content_type = 'application
/xhtml
+xml
';
865 $content_type = 'text
/html
';
867 print $cgi->header(-type=>$content_type, -charset => 'utf
-8', -status=> $status, -expires => $expires);
869 <?xml version="1.0" encoding="utf-8"?>
870 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
871 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
872 <!-- git web interface v$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
873 <!-- git core binaries version $git_version -->
875 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
876 <meta name="robots" content="index, nofollow"/>
877 <title>$title</title>
878 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
880 if (defined $project) {
881 printf('<link rel="alternate" title="%s log" '.
882 'href="%s" type="application/rss+xml"/>'."\n",
884 esc_param
("$my_uri?p=$project;a=rss"));
889 "<div class=\"page_header\">\n" .
890 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
891 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
893 print $cgi->a({-href
=> esc_param
($home_link)}, "projects") . " / ";
894 if (defined $project) {
895 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, esc_html
($project));
896 if (defined $action) {
900 if (!defined $searchtext) {
904 if (defined $hash_base) {
905 $search_hash = $hash_base;
906 } elsif (defined $hash) {
907 $search_hash = $hash;
909 $search_hash = "HEAD";
911 $cgi->param("a", "search");
912 $cgi->param("h", $search_hash);
913 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
914 "<div class=\"search\">\n" .
915 $cgi->hidden(-name
=> "p") . "\n" .
916 $cgi->hidden(-name
=> "a") . "\n" .
917 $cgi->hidden(-name
=> "h") . "\n" .
918 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
920 $cgi->end_form() . "\n";
925 sub git_footer_html
{
926 print "<div class=\"page_footer\">\n";
927 if (defined $project) {
928 my $descr = git_read_description
($project);
929 if (defined $descr) {
930 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
932 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=rss"), -class => "rss_logo"}, "RSS") . "\n";
934 print $cgi->a({-href
=> "$my_uri?" . esc_param
("a=opml"), -class => "rss_logo"}, "OPML") . "\n";
942 my $status = shift || "403 Forbidden";
943 my $error = shift || "Malformed query, file missing or permission denied";
945 git_header_html
($status);
946 print "<div class=\"page_body\">\n" .
948 "$status - $error\n" .
955 ## ----------------------------------------------------------------------
956 ## functions printing or outputting HTML: navigation
959 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
960 $extra = '' if !defined $extra; # pager or formats
962 my @navs = qw(summary shortlog log commit commitdiff tree);
964 @navs = grep { $_ ne $suppress } @navs;
967 my %arg = map { $_, ''} @navs;
969 for (qw(commit commitdiff)) {
970 $arg{$_} = ";h=$head";
972 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
973 for (qw(shortlog log)) {
974 $arg{$_} = ";h=$head";
978 $arg{tree
} .= ";h=$treehead" if defined $treehead;
979 $arg{tree
} .= ";hb=$treebase" if defined $treebase;
981 print "<div class=\"page_nav\">\n" .
985 : $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$_$arg{$_}")}, "$_")
988 print "<br/>\n$extra<br/>\n" .
992 sub git_get_paging_nav
{
993 my ($action, $hash, $head, $page, $nrevs) = @_;
997 if ($hash ne $head || $page) {
998 $paging_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$action")}, "HEAD");
1000 $paging_nav .= "HEAD";
1004 $paging_nav .= " ⋅ " .
1005 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$action;h=$hash;pg=" . ($page-1)),
1006 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1008 $paging_nav .= " ⋅ prev";
1011 if ($nrevs >= (100 * ($page+1)-1)) {
1012 $paging_nav .= " ⋅ " .
1013 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$action;h=$hash;pg=" . ($page+1)),
1014 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1016 $paging_nav .= " ⋅ next";
1022 ## ......................................................................
1023 ## functions printing or outputting HTML: div
1025 sub git_header_div
{
1026 my ($action, $title, $hash, $hash_base) = @_;
1029 $rest .= ";h=$hash" if $hash;
1030 $rest .= ";hb=$hash_base" if $hash_base;
1032 print "<div class=\"header\">\n" .
1033 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$action$rest"),
1034 -class => "title"}, $title ?
$title : $action) . "\n" .
1038 sub git_print_page_path
{
1042 if (!defined $name) {
1043 print "<div class=\"page_path\"><b>/</b></div>\n";
1044 } elsif (defined $type && $type eq 'blob') {
1045 print "<div class=\"page_path\"><b>" .
1046 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;f=$file_name")}, esc_html
($name)) . "</b><br/></div>\n";
1048 print "<div class=\"page_path\"><b>" . esc_html
($name) . "</b><br/></div>\n";
1052 ## ......................................................................
1053 ## functions printing large fragments of HTML
1055 sub git_shortlog_body
{
1056 # uses global variable $project
1057 my ($revlist, $from, $to, $refs, $extra) = @_;
1058 $from = 0 unless defined $from;
1059 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1061 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
1063 for (my $i = $from; $i <= $to; $i++) {
1064 my $commit = $revlist->[$i];
1065 #my $ref = defined $refs ? git_get_referencing($refs, $commit) : '';
1066 my $ref = git_get_referencing
($refs, $commit);
1067 my %co = git_read_commit
($commit);
1069 print "<tr class=\"dark\">\n";
1071 print "<tr class=\"light\">\n";
1074 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1075 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1076 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
1078 if (length($co{'title_short'}) < length($co{'title'})) {
1079 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"),
1080 -class => "list", -title
=> "$co{'title'}"},
1081 "<b>" . esc_html
($co{'title_short'}) . "$ref</b>");
1083 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"),
1085 "<b>" . esc_html
($co{'title'}) . "$ref</b>");
1088 "<td class=\"link\">" .
1089 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") . " | " .
1090 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1094 if (defined $extra) {
1096 "<td colspan=\"4\">$extra</td>\n" .
1103 # uses global variable $project
1104 my ($taglist, $from, $to, $extra) = @_;
1105 $from = 0 unless defined $from;
1106 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1108 print "<table class=\"tags\" cellspacing=\"0\">\n";
1110 for (my $i = $from; $i <= $to; $i++) {
1111 my $entry = $taglist->[$i];
1113 my $comment_lines = $tag{'comment'};
1114 my $comment = shift @
$comment_lines;
1116 if (defined $comment) {
1117 $comment_short = chop_str
($comment, 30, 5);
1120 print "<tr class=\"dark\">\n";
1122 print "<tr class=\"light\">\n";
1125 print "<td><i>$tag{'age'}</i></td>\n" .
1127 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"),
1128 -class => "list"}, "<b>" . esc_html
($tag{'name'}) . "</b>") .
1131 if (defined $comment) {
1132 if (length($comment_short) < length($comment)) {
1133 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}"),
1134 -class => "list", -title
=> $comment}, $comment_short);
1136 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}"),
1137 -class => "list"}, $comment);
1141 "<td class=\"selflink\">";
1142 if ($tag{'type'} eq "tag") {
1143 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, "tag");
1148 "<td class=\"link\">" . " | " .
1149 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1150 if ($tag{'reftype'} eq "commit") {
1151 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1152 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'refid'}")}, "log");
1153 } elsif ($tag{'reftype'} eq "blob") {
1154 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$tag{'refid'}")}, "raw");
1159 if (defined $extra) {
1161 "<td colspan=\"5\">$extra</td>\n" .
1167 sub git_heads_body
{
1168 # uses global variable $project
1169 my ($taglist, $head, $from, $to, $extra) = @_;
1170 $from = 0 unless defined $from;
1171 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1173 print "<table class=\"heads\" cellspacing=\"0\">\n";
1175 for (my $i = $from; $i <= $to; $i++) {
1176 my $entry = $taglist->[$i];
1178 my $curr = $tag{'id'} eq $head;
1180 print "<tr class=\"dark\">\n";
1182 print "<tr class=\"light\">\n";
1185 print "<td><i>$tag{'age'}</i></td>\n" .
1186 ($tag{'id'} eq $head ?
"<td class=\"current_head\">" : "<td>") .
1187 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}"),
1188 -class => "list"}, "<b>" . esc_html
($tag{'name'}) . "</b>") .
1190 "<td class=\"link\">" .
1191 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") . " | " .
1192 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'name'}")}, "log") .
1196 if (defined $extra) {
1198 "<td colspan=\"3\">$extra</td>\n" .
1204 ## ----------------------------------------------------------------------
1205 ## functions printing large fragments, format as one of arguments
1207 sub git_diff_print
{
1209 my $from_name = shift;
1211 my $to_name = shift;
1212 my $format = shift || "html";
1214 my $from_tmp = "/dev/null";
1215 my $to_tmp = "/dev/null";
1218 # create tmp from-file
1219 if (defined $from) {
1220 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
1221 open my $fd2, "> $from_tmp";
1222 open my $fd, "-|", $GIT, "cat-file", "blob", $from;
1229 # create tmp to-file
1231 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
1232 open my $fd2, "> $to_tmp";
1233 open my $fd, "-|", $GIT, "cat-file", "blob", $to;
1240 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
1241 if ($format eq "plain") {
1246 while (my $line = <$fd>) {
1248 my $char = substr($line, 0, 1);
1249 my $diff_class = "";
1251 $diff_class = " add";
1252 } elsif ($char eq "-") {
1253 $diff_class = " rem";
1254 } elsif ($char eq "@") {
1255 $diff_class = " chunk_header";
1256 } elsif ($char eq "\\") {
1260 $line = untabify
($line);
1261 print "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
1266 if (defined $from) {
1275 ## ======================================================================
1276 ## ======================================================================
1279 sub git_project_list
{
1280 my $order = $cgi->param('o');
1281 if (defined $order && $order !~ m/project|descr|owner|age/) {
1282 die_error
(undef, "Unknown order parameter");
1285 my @list = git_read_projects
();
1288 die_error
(undef, "No projects found");
1290 foreach my $pr (@list) {
1291 my $head = git_read_head
($pr->{'path'});
1292 if (!defined $head) {
1295 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
1296 my %co = git_read_commit
($head);
1300 $pr->{'commit'} = \
%co;
1301 if (!defined $pr->{'descr'}) {
1302 my $descr = git_read_description
($pr->{'path'}) || "";
1303 $pr->{'descr'} = chop_str
($descr, 25, 5);
1305 if (!defined $pr->{'owner'}) {
1306 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
1308 push @projects, $pr;
1312 if (-f
$home_text) {
1313 print "<div class=\"index_include\">\n";
1314 open (my $fd, $home_text);
1319 print "<table class=\"project_list\">\n" .
1321 $order ||= "project";
1322 if ($order eq "project") {
1323 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
1324 print "<th>Project</th>\n";
1327 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=project"),
1328 -class => "header"}, "Project") .
1331 if ($order eq "descr") {
1332 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
1333 print "<th>Description</th>\n";
1336 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=descr"),
1337 -class => "header"}, "Description") .
1340 if ($order eq "owner") {
1341 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
1342 print "<th>Owner</th>\n";
1345 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=owner"),
1346 -class => "header"}, "Owner") .
1349 if ($order eq "age") {
1350 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
1351 print "<th>Last Change</th>\n";
1354 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=age"),
1355 -class => "header"}, "Last Change") .
1358 print "<th></th>\n" .
1361 foreach my $pr (@projects) {
1363 print "<tr class=\"dark\">\n";
1365 print "<tr class=\"light\">\n";
1368 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=summary"),
1369 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
1370 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
1371 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
1372 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" .
1373 $pr->{'commit'}{'age_string'} . "</td>\n" .
1374 "<td class=\"link\">" .
1375 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=summary")}, "summary") . " | " .
1376 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=shortlog")}, "shortlog") . " | " .
1377 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=log")}, "log") .
1386 my $descr = git_read_description
($project) || "none";
1387 my $head = git_read_head
($project);
1388 my %co = git_read_commit
($head);
1389 my %cd = date_str
($co{'committer_epoch'}, $co{'committer_tz'});
1392 if (-f
$projects_list) {
1393 open (my $fd , $projects_list);
1394 while (my $line = <$fd>) {
1396 my ($pr, $ow) = split ' ', $line;
1397 $pr = unescape
($pr);
1398 $ow = unescape
($ow);
1399 if ($pr eq $project) {
1400 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
1406 if (!defined $owner) {
1407 $owner = get_file_owner
("$projectroot/$project");
1410 my $refs = read_info_ref
();
1412 git_page_nav
('summary','', $head);
1414 print "<div class=\"title\"> </div>\n";
1415 print "<table cellspacing=\"0\">\n" .
1416 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
1417 "<tr><td>owner</td><td>$owner</td></tr>\n" .
1418 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
1421 open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_read_head
($project)
1422 or die_error
(undef, "Open git-rev-list failed");
1423 my @revlist = map { chomp; $_ } <$fd>;
1425 git_header_div
('shortlog');
1426 git_shortlog_body
(\
@revlist, 0, 15, $refs,
1427 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "..."));
1429 my $taglist = git_read_refs
("refs/tags");
1430 if (defined @
$taglist) {
1431 git_header_div
('tags');
1432 git_tags_body
($taglist, 0, 15,
1433 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tags")}, "..."));
1436 my $headlist = git_read_refs
("refs/heads");
1437 if (defined @
$headlist) {
1438 git_header_div
('heads');
1439 git_heads_body
($headlist, $head, 0, 15,
1440 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=heads")}, "..."));
1447 my $head = git_read_head
($project);
1449 git_page_nav
('','', $head,undef,$head);
1450 my %tag = git_read_tag
($hash);
1451 git_header_div
('commit', esc_html
($tag{'name'}), $hash);
1452 print "<div class=\"title_text\">\n" .
1453 "<table cellspacing=\"0\">\n" .
1455 "<td>object</td>\n" .
1456 "<td>" . $cgi->a({-class => "list", -href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'object'}) . "</td>\n" .
1457 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'type'}) . "</td>\n" .
1459 if (defined($tag{'author'})) {
1460 my %ad = date_str
($tag{'epoch'}, $tag{'tz'});
1461 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
1462 print "<tr><td></td><td>" . $ad{'rfc2822'} . sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) . "</td></tr>\n";
1464 print "</table>\n\n" .
1466 print "<div class=\"page_body\">";
1467 my $comment = $tag{'comment'};
1468 foreach my $line (@
$comment) {
1469 print esc_html
($line) . "<br/>\n";
1478 die_error
(undef, "Permission denied") if (!git_get_project_config_bool
('blame'));
1479 die_error
('404 Not Found', "File name not defined") if (!$file_name);
1480 $hash_base ||= git_read_head
($project);
1481 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
1482 my %co = git_read_commit
($hash_base)
1483 or die_error
(undef, "Reading commit failed");
1484 if (!defined $hash) {
1485 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
1486 or die_error
(undef, "Error looking up file");
1488 $ftype = git_get_type
($hash);
1489 if ($ftype !~ "blob") {
1490 die_error
("400 Bad Request", "Object is not a blob");
1492 open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base)
1493 or die_error
(undef, "Open git-blame failed");
1496 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") .
1497 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;f=$file_name")}, "head");
1498 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1499 git_header_div
('commit', esc_html
($co{'title'}), $hash_base);
1500 git_print_page_path
($file_name, $ftype);
1501 my @rev_color = (qw(light2 dark2));
1502 my $num_colors = scalar(@rev_color);
1503 my $current_color = 0;
1505 print "<div class=\"page_body\">\n";
1506 print "<table class=\"blame\">\n";
1507 print "<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n";
1509 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
1511 my $rev = substr($full_rev, 0, 8);
1515 if (!defined $last_rev) {
1516 $last_rev = $full_rev;
1517 } elsif ($last_rev ne $full_rev) {
1518 $last_rev = $full_rev;
1519 $current_color = ++$current_color % $num_colors;
1521 print "<tr class=\"$rev_color[$current_color]\">\n";
1522 print "<td class=\"sha1\">" .
1523 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$full_rev;f=$file_name")}, esc_html
($rev)) . "</td>\n";
1524 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" . esc_html
($lineno) . "</a></td>\n";
1525 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
1530 close $fd or print "Reading blob failed\n";
1536 die_error
('403 Permission denied', "Permission denied") if (!git_get_project_config_bool
('blame'));
1537 die_error
('404 Not Found', "File name not defined") if (!$file_name);
1538 $hash_base ||= git_read_head
($project);
1539 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
1540 my %co = git_read_commit
($hash_base)
1541 or die_error
(undef, "Reading commit failed");
1542 if (!defined $hash) {
1543 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
1544 or die_error
(undef, "Error lookup file");
1546 open ($fd, "-|", $GIT, "annotate", '-l', '-t', '-r', $file_name, $hash_base)
1547 or die_error
(undef, "Open git-annotate failed");
1550 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") .
1551 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;f=$file_name")}, "head");
1552 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1553 git_header_div
('commit', esc_html
($co{'title'}), $hash_base);
1554 git_print_page_path
($file_name, 'blob');
1555 print "<div class=\"page_body\">\n";
1557 <table class="blame">
1566 my @line_class = (qw(light dark));
1567 my $line_class_len = scalar (@line_class);
1568 my $line_class_num = $#line_class;
1569 while (my $line = <$fd>) {
1581 $line_class_num = ($line_class_num + 1) % $line_class_len;
1583 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) \+\d\d\d\d\t(\d+)\)(.*)$/) {
1590 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
1593 $short_rev = substr ($long_rev, 0, 8);
1594 $age = time () - $time;
1595 $age_str = age_string
($age);
1596 $age_str =~ s/ / /g;
1597 $age_class = age_class
($age);
1598 $author = esc_html
($author);
1599 $author =~ s/ / /g;
1601 $data = untabify
($data);
1602 $data = esc_html
($data);
1605 <tr class="$line_class[$line_class_num]">
1606 <td class="sha1"><a href="$my_uri?${\esc_param ("p=$project;a=commit;h=$long_rev")}" class="text">$short_rev..</a></td>
1607 <td class="$age_class">$age_str</td>
1609 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
1610 <td class="pre">$data</td>
1613 } # while (my $line = <$fd>)
1614 print "</table>\n\n";
1615 close $fd or print "Reading blob failed.\n";
1621 my $head = git_read_head
($project);
1623 git_page_nav
('','', $head,undef,$head);
1624 git_header_div
('summary', $project);
1626 my $taglist = git_read_refs
("refs/tags");
1627 if (defined @
$taglist) {
1628 git_tags_body
($taglist);
1634 my $head = git_read_head
($project);
1636 git_page_nav
('','', $head,undef,$head);
1637 git_header_div
('summary', $project);
1639 my $taglist = git_read_refs
("refs/heads");
1640 if (defined @
$taglist) {
1641 git_heads_body
($taglist, $head);
1646 sub git_blob_plain
{
1647 if (!defined $hash) {
1648 if (defined $file_name) {
1649 my $base = $hash_base || git_read_head
($project);
1650 $hash = git_get_hash_by_path
($base, $file_name, "blob")
1651 or die_error
(undef, "Error lookup file");
1653 die_error
(undef, "No file name defined");
1657 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
1658 or die_error
(undef, "Couldn't cat $file_name, $hash");
1660 $type ||= git_blob_plain_mimetype
($fd, $file_name);
1662 # save as filename, even when no $file_name is given
1663 my $save_as = "$hash";
1664 if (defined $file_name) {
1665 $save_as = $file_name;
1666 } elsif ($type =~ m/^text\//) {
1670 print $cgi->header(-type
=> "$type", '-content-disposition' => "inline; filename=\"$save_as\"");
1672 binmode STDOUT
, ':raw';
1674 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
1680 if (!defined $hash) {
1681 if (defined $file_name) {
1682 my $base = $hash_base || git_read_head
($project);
1683 $hash = git_get_hash_by_path
($base, $file_name, "blob")
1684 or die_error
(undef, "Error lookup file");
1686 die_error
(undef, "No file name defined");
1689 my $have_blame = git_get_project_config_bool
('blame');
1690 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
1691 or die_error
(undef, "Couldn't cat $file_name, $hash");
1692 my $mimetype = git_blob_plain_mimetype
($fd, $file_name);
1693 if ($mimetype !~ m/^text\//) {
1695 return git_blob_plain
($mimetype);
1698 my $formats_nav = '';
1699 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
1700 if (defined $file_name) {
1702 $formats_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;h=$hash;hb=$hash_base;f=$file_name")}, "blame") . " | ";
1705 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$hash;f=$file_name")}, "plain") .
1706 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;hb=HEAD;f=$file_name")}, "head");
1708 $formats_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$hash")}, "plain");
1710 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1711 git_header_div
('commit', esc_html
($co{'title'}), $hash_base);
1713 print "<div class=\"page_nav\">\n" .
1714 "<br/><br/></div>\n" .
1715 "<div class=\"title\">$hash</div>\n";
1717 git_print_page_path
($file_name, "blob");
1718 print "<div class=\"page_body\">\n";
1720 while (my $line = <$fd>) {
1723 $line = untabify
($line);
1724 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", $nr, $nr, $nr, esc_html
($line);
1726 close $fd or print "Reading blob failed.\n";
1732 if (!defined $hash) {
1733 $hash = git_read_head
($project);
1734 if (defined $file_name) {
1735 my $base = $hash_base || $hash;
1736 $hash = git_get_hash_by_path
($base, $file_name, "tree");
1738 if (!defined $hash_base) {
1743 open my $fd, "-|", $GIT, "ls-tree", '-z', $hash
1744 or die_error
(undef, "Open git-ls-tree failed");
1745 my @entries = map { chomp; $_ } <$fd>;
1746 close $fd or die_error
(undef, "Reading tree failed");
1749 my $refs = read_info_ref
();
1750 my $ref = git_get_referencing
($refs, $hash_base);
1754 my $have_blame = git_get_project_config_bool
('blame');
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");
1792 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;h=$t_hash$base_key;f=$base$t_name")}, "blame");
1794 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;h=$t_hash;hb=$hash_base;f=$base$t_name")}, "history") .
1795 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$t_hash;f=$base$t_name")}, "raw") .
1797 } elsif ($t_type eq "tree") {
1798 print "<td class=\"list\">" .
1799 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, esc_html
($t_name)) .
1801 "<td class=\"link\">" .
1802 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, "tree") .
1803 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;hb=$hash_base;f=$base$t_name")}, "history") .
1808 print "</table>\n" .
1814 my $head = git_read_head
($project);
1815 if (!defined $hash) {
1818 if (!defined $page) {
1821 my $refs = read_info_ref
();
1823 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
1824 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
1825 or die_error
(undef, "Open git-rev-list failed");
1826 my @revlist = map { chomp; $_ } <$fd>;
1829 my $paging_nav = git_get_paging_nav
('log', $hash, $head, $page, $#revlist);
1832 git_page_nav
('log','', $hash,undef,undef, $paging_nav);
1835 my %co = git_read_commit
($hash);
1837 git_header_div
('summary', $project);
1838 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
1840 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
1841 my $commit = $revlist[$i];
1842 my $ref = git_get_referencing
($refs, $commit);
1843 my %co = git_read_commit
($commit);
1845 my %ad = date_str
($co{'author_epoch'});
1846 git_header_div
('commit',
1847 "<span class=\"age\">$co{'age_string'}</span>" .
1848 esc_html
($co{'title'}) . $ref,
1850 print "<div class=\"title_text\">\n" .
1851 "<div class=\"log_link\">\n" .
1852 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
1853 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1856 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
1858 "<div class=\"log_body\">\n";
1859 my $comment = $co{'comment'};
1861 foreach my $line (@
$comment) {
1862 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1873 print format_log_line_html
($line) . "<br/>\n";
1884 my %co = git_read_commit
($hash);
1886 die_error
(undef, "Unknown commit object");
1888 my %ad = date_str
($co{'author_epoch'}, $co{'author_tz'});
1889 my %cd = date_str
($co{'committer_epoch'}, $co{'committer_tz'});
1891 my $parent = $co{'parent'};
1892 if (!defined $parent) {
1895 open my $fd, "-|", $GIT, "diff-tree", '-r', '-M', $parent, $hash
1896 or die_error
(undef, "Open git-diff-tree failed");
1897 my @difftree = map { chomp; $_ } <$fd>;
1898 close $fd or die_error
(undef, "Reading git-diff-tree failed");
1900 # non-textual hash id's can be cached
1902 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
1905 my $refs = read_info_ref
();
1906 my $ref = git_get_referencing
($refs, $co{'id'});
1907 my $formats_nav = '';
1908 if (defined $file_name && defined $co{'parent'}) {
1909 my $parent = $co{'parent'};
1910 $formats_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;hb=$parent;f=$file_name")}, "blame");
1912 git_header_html
(undef, $expires);
1913 git_page_nav
('commit', defined $co{'parent'} ?
'' : 'commitdiff',
1914 $hash, $co{'tree'}, $hash,
1917 if (defined $co{'parent'}) {
1918 git_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
1920 git_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
1922 print "<div class=\"title_text\">\n" .
1923 "<table cellspacing=\"0\">\n";
1924 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
1926 "<td></td><td> $ad{'rfc2822'}";
1927 if ($ad{'hour_local'} < 6) {
1928 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1930 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1934 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
1935 print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
1936 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
1939 "<td class=\"sha1\">" .
1940 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash"), class => "list"}, $co{'tree'}) .
1942 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
1945 my $parents = $co{'parents'};
1946 foreach my $par (@
$parents) {
1949 "<td class=\"sha1\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$par"), class => "list"}, $par) . "</td>" .
1950 "<td class=\"link\">" .
1951 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$par")}, "commit") .
1952 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash;hp=$par")}, "commitdiff") .
1958 print "<div class=\"page_body\">\n";
1959 my $comment = $co{'comment'};
1962 foreach my $line (@
$comment) {
1963 # print only one empty line
1965 if ($empty || $signed) {
1972 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1974 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1977 print format_log_line_html
($line) . "<br/>\n";
1981 print "<div class=\"list_head\">\n";
1982 if ($#difftree > 10) {
1983 print(($#difftree + 1) . " files changed:\n");
1986 print "<table class=\"diff_tree\">\n";
1988 foreach my $line (@difftree) {
1989 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1990 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1991 if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1999 my $similarity = $6;
2000 my $file = validate_input
(unquote
($7));
2002 print "<tr class=\"dark\">\n";
2004 print "<tr class=\"light\">\n";
2007 if ($status eq "A") {
2009 if (S_ISREG
(oct $to_mode)) {
2010 $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
2013 $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" .
2014 "<td><span class=\"file_status new\">[new " . file_type
($to_mode) . "$mode_chng]</span></td>\n" .
2015 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob") . "</td>\n";
2016 } elsif ($status eq "D") {
2018 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$parent;f=$file"), -class => "list"}, esc_html
($file)) . "</td>\n" .
2019 "<td><span class=\"file_status deleted\">[deleted " . file_type
($from_mode). "]</span></td>\n" .
2020 "<td class=\"link\">" .
2021 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$parent;f=$file")}, "blob") .
2022 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;hb=$parent;f=$file")}, "history") .
2024 } elsif ($status eq "M" || $status eq "T") {
2025 my $mode_chnge = "";
2026 if ($from_mode != $to_mode) {
2027 $mode_chnge = " <span class=\"file_status mode_chnge\">[changed";
2028 if (((oct $from_mode) & S_IFMT
) != ((oct $to_mode) & S_IFMT
)) {
2029 $mode_chnge .= " from " . file_type
($from_mode) . " to " . file_type
($to_mode);
2031 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
2032 if (S_ISREG
($from_mode) && S_ISREG
($to_mode)) {
2033 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
2034 } elsif (S_ISREG
($to_mode)) {
2035 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
2038 $mode_chnge .= "]</span>\n";
2041 if ($to_id ne $from_id) {
2042 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));
2044 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file"), -class => "list"}, esc_html
($file));
2047 "<td>$mode_chnge</td>\n" .
2048 "<td class=\"link\">";
2049 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob");
2050 if ($to_id ne $from_id) {
2051 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file")}, "diff");
2053 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;hb=$hash;f=$file")}, "history") . "\n";
2055 } elsif ($status eq "R") {
2056 my ($from_file, $to_file) = split "\t", $file;
2058 if ($from_mode != $to_mode) {
2059 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
2062 $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" .
2063 "<td><span class=\"file_status moved\">[moved from " .
2064 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$parent;f=$from_file"), -class => "list"}, esc_html
($from_file)) .
2065 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
2066 "<td class=\"link\">" .
2067 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file")}, "blob");
2068 if ($to_id ne $from_id) {
2069 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file")}, "diff");
2080 mkdir($git_temp, 0700);
2082 if (defined $hash_base && (my %co = git_read_commit
($hash_base))) {
2084 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff_plain;h=$hash;hp=$hash_parent")}, "plain");
2085 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2086 git_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2088 print "<div class=\"page_nav\">\n" .
2089 "<br/><br/></div>\n" .
2090 "<div class=\"title\">$hash vs $hash_parent</div>\n";
2092 git_print_page_path
($file_name, "blob");
2093 print "<div class=\"page_body\">\n" .
2094 "<div class=\"diff_info\">blob:" .
2095 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name")}, $hash_parent) .
2097 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, $hash) .
2099 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
2104 sub git_blobdiff_plain
{
2105 mkdir($git_temp, 0700);
2106 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8');
2107 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
2110 sub git_commitdiff
{
2111 mkdir($git_temp, 0700);
2112 my %co = git_read_commit
($hash);
2114 die_error
(undef, "Unknown commit object");
2116 if (!defined $hash_parent) {
2117 $hash_parent = $co{'parent'} || '--root';
2119 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2120 or die_error
(undef, "Open git-diff-tree failed");
2121 my @difftree = map { chomp; $_ } <$fd>;
2122 close $fd or die_error
(undef, "Reading git-diff-tree failed");
2124 # non-textual hash id's can be cached
2126 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2129 my $refs = read_info_ref
();
2130 my $ref = git_get_referencing
($refs, $co{'id'});
2132 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent")}, "plain");
2133 git_header_html
(undef, $expires);
2134 git_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
2135 git_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
2136 print "<div class=\"page_body\">\n";
2137 my $comment = $co{'comment'};
2140 my @log = @
$comment;
2141 # remove first and empty lines after that
2143 while (defined $log[0] && $log[0] eq "") {
2146 foreach my $line (@log) {
2147 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2158 print format_log_line_html
($line) . "<br/>\n";
2161 foreach my $line (@difftree) {
2162 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2163 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2164 if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2172 my $file = validate_input
(unquote
($6));
2173 if ($status eq "A") {
2174 print "<div class=\"diff_info\">" . file_type
($to_mode) . ":" .
2175 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id) . "(new)" .
2177 git_diff_print
(undef, "/dev/null", $to_id, "b/$file");
2178 } elsif ($status eq "D") {
2179 print "<div class=\"diff_info\">" . file_type
($from_mode) . ":" .
2180 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash_parent;f=$file")}, $from_id) . "(deleted)" .
2182 git_diff_print
($from_id, "a/$file", undef, "/dev/null");
2183 } elsif ($status eq "M") {
2184 if ($from_id ne $to_id) {
2185 print "<div class=\"diff_info\">" .
2186 file_type
($from_mode) . ":" .
2187 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash_parent;f=$file")}, $from_id) .
2189 file_type
($to_mode) . ":" .
2190 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id);
2192 git_diff_print
($from_id, "a/$file", $to_id, "b/$file");
2201 sub git_commitdiff_plain
{
2202 mkdir($git_temp, 0700);
2203 my %co = git_read_commit
($hash);
2205 die_error
(undef, "Unknown commit object");
2207 if (!defined $hash_parent) {
2208 $hash_parent = $co{'parent'} || '--root';
2210 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2211 or die_error
(undef, "Open git-diff-tree failed");
2212 my @difftree = map { chomp; $_ } <$fd>;
2213 close $fd or die_error
(undef, "Reading diff-tree failed");
2215 # try to figure out the next tag after this commit
2217 my $refs = read_info_ref
("tags");
2218 open $fd, "-|", $GIT, "rev-list", "HEAD";
2219 my @commits = map { chomp; $_ } <$fd>;
2221 foreach my $commit (@commits) {
2222 if (defined $refs->{$commit}) {
2223 $tagname = $refs->{$commit}
2225 if ($commit eq $hash) {
2230 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8', '-content-disposition' => "inline; filename=\"git-$hash.patch\"");
2231 my %ad = date_str
($co{'author_epoch'}, $co{'author_tz'});
2232 my $comment = $co{'comment'};
2233 print "From: $co{'author'}\n" .
2234 "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
2235 "Subject: $co{'title'}\n";
2236 if (defined $tagname) {
2237 print "X-Git-Tag: $tagname\n";
2239 print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
2242 foreach my $line (@
$comment) {;
2247 foreach my $line (@difftree) {
2248 if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2255 if ($status eq "A") {
2256 git_diff_print
(undef, "/dev/null", $to_id, "b/$file", "plain");
2257 } elsif ($status eq "D") {
2258 git_diff_print
($from_id, "a/$file", undef, "/dev/null", "plain");
2259 } elsif ($status eq "M") {
2260 git_diff_print
($from_id, "a/$file", $to_id, "b/$file", "plain");
2266 if (!defined $hash_base) {
2267 $hash_base = git_read_head
($project);
2270 my %co = git_read_commit
($hash_base);
2272 die_error
(undef, "Unknown commit object");
2274 my $refs = read_info_ref
();
2276 git_page_nav
('','', $hash_base,$co{'tree'},$hash_base);
2277 git_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2278 if (!defined $hash && defined $file_name) {
2279 $hash = git_get_hash_by_path
($hash_base, $file_name);
2281 if (defined $hash) {
2282 $ftype = git_get_type
($hash);
2284 git_print_page_path
($file_name, $ftype);
2287 $GIT, "rev-list", "--full-history", $hash_base, "--", $file_name;
2288 print "<table cellspacing=\"0\">\n";
2290 while (my $line = <$fd>) {
2291 if ($line =~ m/^([0-9a-fA-F]{40})/){
2293 my %co = git_read_commit
($commit);
2297 my $ref = git_get_referencing
($refs, $commit);
2299 print "<tr class=\"dark\">\n";
2301 print "<tr class=\"light\">\n";
2304 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2305 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2306 "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list"}, "<b>" .
2307 esc_html
(chop_str
($co{'title'}, 50)) . "$ref</b>") . "</td>\n" .
2308 "<td class=\"link\">" .
2309 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
2310 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2311 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$ftype;hb=$commit;f=$file_name")}, $ftype);
2312 my $blob = git_get_hash_by_path
($hash_base, $file_name);
2313 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2314 if (defined $blob && defined $blob_parent && $blob ne $blob_parent) {
2316 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=$file_name")},
2329 if (!defined $searchtext) {
2330 die_error
(undef, "Text field empty");
2332 if (!defined $hash) {
2333 $hash = git_read_head
($project);
2335 my %co = git_read_commit
($hash);
2337 die_error
(undef, "Unknown commit object");
2339 # pickaxe may take all resources of your box and run for several minutes
2340 # with every query - so decide by yourself how public you make this feature :)
2341 my $commit_search = 1;
2342 my $author_search = 0;
2343 my $committer_search = 0;
2344 my $pickaxe_search = 0;
2345 if ($searchtext =~ s/^author\\://i) {
2347 } elsif ($searchtext =~ s/^committer\\://i) {
2348 $committer_search = 1;
2349 } elsif ($searchtext =~ s/^pickaxe\\://i) {
2351 $pickaxe_search = 1;
2354 git_page_nav
('','', $hash,$co{'tree'},$hash);
2355 git_header_div
('commit', esc_html
($co{'title'}), $hash);
2357 print "<table cellspacing=\"0\">\n";
2359 if ($commit_search) {
2361 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", $hash or next;
2362 while (my $commit_text = <$fd>) {
2363 if (!grep m/$searchtext/i, $commit_text) {
2366 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
2369 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
2372 my @commit_lines = split "\n", $commit_text;
2373 my %co = git_read_commit
(undef, \
@commit_lines);
2378 print "<tr class=\"dark\">\n";
2380 print "<tr class=\"light\">\n";
2383 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2384 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2386 $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/>");
2387 my $comment = $co{'comment'};
2388 foreach my $line (@
$comment) {
2389 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2390 my $lead = esc_html
($1) || "";
2391 $lead = chop_str
($lead, 30, 10);
2392 my $match = esc_html
($2) || "";
2393 my $trail = esc_html
($3) || "";
2394 $trail = chop_str
($trail, 30, 10);
2395 my $text = "$lead<span class=\"match\">$match</span>$trail";
2396 print chop_str
($text, 80, 5) . "<br/>\n";
2400 "<td class=\"link\">" .
2401 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2402 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2409 if ($pickaxe_search) {
2411 open my $fd, "-|", "$GIT rev-list $hash | $GIT diff-tree -r --stdin -S\'$searchtext\'";
2414 while (my $line = <$fd>) {
2415 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2418 $set{'from_id'} = $3;
2420 $set{'id'} = $set{'to_id'};
2421 if ($set{'id'} =~ m/0{40}/) {
2422 $set{'id'} = $set{'from_id'};
2424 if ($set{'id'} =~ m/0{40}/) {
2428 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
2431 print "<tr class=\"dark\">\n";
2433 print "<tr class=\"light\">\n";
2436 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2437 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2439 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" .
2440 esc_html
(chop_str
($co{'title'}, 50)) . "</b><br/>");
2441 while (my $setref = shift @files) {
2443 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}"), class => "list"},
2444 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
2448 "<td class=\"link\">" .
2449 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2450 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2454 %co = git_read_commit
($1);
2464 my $head = git_read_head
($project);
2465 if (!defined $hash) {
2468 if (!defined $page) {
2471 my $refs = read_info_ref
();
2473 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2474 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2475 or die_error
(undef, "Open git-rev-list failed");
2476 my @revlist = map { chomp; $_ } <$fd>;
2479 my $paging_nav = git_get_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
2481 if ($#revlist >= (100 * ($page+1)-1)) {
2483 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)),
2484 -title
=> "Alt-n"}, "next");
2489 git_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
2490 git_header_div
('summary', $project);
2492 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
2497 ## ......................................................................
2498 ## feeds (RSS, OPML)
2501 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
2502 open my $fd, "-|", $GIT, "rev-list", "--max-count=150", git_read_head
($project)
2503 or die_error
(undef, "Open git-rev-list failed");
2504 my @revlist = map { chomp; $_ } <$fd>;
2505 close $fd or die_error
(undef, "Reading git-rev-list failed");
2506 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
2507 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
2508 "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
2509 print "<channel>\n";
2510 print "<title>$project</title>\n".
2511 "<link>" . esc_html
("$my_url?p=$project;a=summary") . "</link>\n".
2512 "<description>$project log</description>\n".
2513 "<language>en</language>\n";
2515 for (my $i = 0; $i <= $#revlist; $i++) {
2516 my $commit = $revlist[$i];
2517 my %co = git_read_commit
($commit);
2518 # we read 150, we always show 30 and the ones more recent than 48 hours
2519 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
2522 my %cd = date_str
($co{'committer_epoch'});
2523 open $fd, "-|", $GIT, "diff-tree", '-r', $co{'parent'}, $co{'id'} or next;
2524 my @difftree = map { chomp; $_ } <$fd>;
2528 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
2530 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
2531 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
2532 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
2533 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
2534 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
2535 "<content:encoded>" .
2537 my $comment = $co{'comment'};
2538 foreach my $line (@
$comment) {
2539 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
2540 print "$line<br/>\n";
2543 foreach my $line (@difftree) {
2544 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
2547 my $file = validate_input
(unquote
($7));
2548 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
2549 print "$file<br/>\n";
2552 "</content:encoded>\n" .
2555 print "</channel></rss>";
2559 my @list = git_read_projects
();
2561 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
2562 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
2563 "<opml version=\"1.0\">\n".
2565 " <title>$site_name Git OPML Export</title>\n".
2568 "<outline text=\"git RSS feeds\">\n";
2570 foreach my $pr (@list) {
2572 my $head = git_read_head
($proj{'path'});
2573 if (!defined $head) {
2576 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
2577 my %co = git_read_commit
($head);
2582 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
2583 my $rss = "$my_url?p=$proj{'path'};a=rss";
2584 my $html = "$my_url?p=$proj{'path'};a=summary";
2585 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
2587 print "</outline>\n".