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 format_ref_marker
{
366 my ($refs, $id) = @_;
368 if (defined $refs->{$id}) {
369 return ' <span class="tag">' . esc_html
($refs->{$id}) . '</span>';
375 # format, perhaps shortened and with markers, title line
376 sub format_subject_html
{
377 my ($long, $short, $query, $extra) = @_;
378 $extra = '' unless defined($extra);
380 if (length($short) < length($long)) {
381 return $cgi->a({-href
=> "$my_uri?" . esc_param
($query),
382 -class => "list", -title
=> $long},
383 esc_html
($short) . $extra);
385 return $cgi->a({-href
=> "$my_uri?" . esc_param
($query),
387 esc_html
($long) . $extra);
391 ## ----------------------------------------------------------------------
392 ## git utility subroutines, invoking git commands
394 # get HEAD ref of given project as hash
395 sub git_get_head_hash
{
397 my $oENV = $ENV{'GIT_DIR'};
399 $ENV{'GIT_DIR'} = "$projectroot/$project";
400 if (open my $fd, "-|", $GIT, "rev-parse", "--verify", "HEAD") {
403 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
408 $ENV{'GIT_DIR'} = $oENV;
413 # get type of given object
417 open my $fd, "-|", $GIT, "cat-file", '-t', $hash or return;
424 sub git_get_project_config
{
427 return unless ($key);
428 $key =~ s/^gitweb\.//;
429 return if ($key =~ m/\W/);
431 my $val = qx($GIT repo
-config
--get gitweb
.$key);
435 sub git_get_project_config_bool
{
436 my $val = git_get_project_config
(@_);
437 if ($val and $val =~ m/true|yes|on/) {
440 return; # implicit false
443 # get hash of given path at given ref
444 sub git_get_hash_by_path
{
446 my $path = shift || return undef;
450 open my $fd, "-|", $GIT, "ls-tree", $base, "--", $path
451 or die_error
(undef, "Open git-ls-tree failed");
453 close $fd or return undef;
455 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
456 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
460 ## ......................................................................
461 ## git utility functions, directly accessing git repository
463 # assumes that PATH is not symref
464 sub git_get_hash_by_ref
{
467 open my $fd, "$projectroot/$path" or return undef;
471 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
476 sub git_get_project_description
{
479 open my $fd, "$projectroot/$path/description" or return undef;
486 sub git_get_projects_list
{
489 if (-d
$projects_list) {
490 # search in directory
491 my $dir = $projects_list;
492 opendir my ($dh), $dir or return undef;
493 while (my $dir = readdir($dh)) {
494 if (-e
"$projectroot/$dir/HEAD") {
502 } elsif (-f
$projects_list) {
503 # read from file(url-encoded):
504 # 'git%2Fgit.git Linus+Torvalds'
505 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
506 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
507 open my ($fd), $projects_list or return undef;
508 while (my $line = <$fd>) {
510 my ($path, $owner) = split ' ', $line;
511 $path = unescape
($path);
512 $owner = unescape
($owner);
513 if (!defined $path) {
516 if (-e
"$projectroot/$path/HEAD") {
519 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
526 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
530 sub git_get_references
{
531 my $type = shift || "";
533 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
534 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
535 open my $fd, "$projectroot/$project/info/refs" or return;
536 while (my $line = <$fd>) {
538 # attention: for $type == "" it saves only last path part of ref name
539 # e.g. from 'refs/heads/jn/gitweb' it would leave only 'gitweb'
540 if ($line =~ m/^([0-9a-fA-F]{40})\t.*$type\/([^\
^]+)/) {
541 if (defined $refs{$1}) {
542 $refs{$1} .= " / $2";
552 ## ----------------------------------------------------------------------
553 ## parse to hash functions
557 my $tz = shift || "-0000";
560 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
561 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
562 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
563 $date{'hour'} = $hour;
564 $date{'minute'} = $min;
565 $date{'mday'} = $mday;
566 $date{'day'} = $days[$wday];
567 $date{'month'} = $months[$mon];
568 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
569 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
571 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
572 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
573 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
574 $date{'hour_local'} = $hour;
575 $date{'minute_local'} = $min;
576 $date{'tz_local'} = $tz;
585 open my $fd, "-|", $GIT, "cat-file", "tag", $tag_id or return;
586 $tag{'id'} = $tag_id;
587 while (my $line = <$fd>) {
589 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
591 } elsif ($line =~ m/^type (.+)$/) {
593 } elsif ($line =~ m/^tag (.+)$/) {
595 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
599 } elsif ($line =~ m/--BEGIN/) {
600 push @comment, $line;
602 } elsif ($line eq "") {
606 push @comment, <$fd>;
607 $tag{'comment'} = \
@comment;
609 if (!defined $tag{'name'}) {
616 my $commit_id = shift;
617 my $commit_text = shift;
622 if (defined $commit_text) {
623 @commit_lines = @
$commit_text;
626 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", "--max-count=1", $commit_id or return;
627 @commit_lines = split '\n', <$fd>;
632 my $header = shift @commit_lines;
633 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
636 ($co{'id'}, my @parents) = split ' ', $header;
637 $co{'parents'} = \
@parents;
638 $co{'parent'} = $parents[0];
639 while (my $line = shift @commit_lines) {
640 last if $line eq "\n";
641 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
643 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
645 $co{'author_epoch'} = $2;
646 $co{'author_tz'} = $3;
647 if ($co{'author'} =~ m/^([^<]+) </) {
648 $co{'author_name'} = $1;
650 $co{'author_name'} = $co{'author'};
652 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
653 $co{'committer'} = $1;
654 $co{'committer_epoch'} = $2;
655 $co{'committer_tz'} = $3;
656 $co{'committer_name'} = $co{'committer'};
657 $co{'committer_name'} =~ s/ <.*//;
660 if (!defined $co{'tree'}) {
664 foreach my $title (@commit_lines) {
667 $co{'title'} = chop_str
($title, 80, 5);
668 # remove leading stuff of merges to make the interesting part visible
669 if (length($title) > 50) {
670 $title =~ s/^Automatic //;
671 $title =~ s/^merge (of|with) /Merge ... /i;
672 if (length($title) > 50) {
673 $title =~ s/(http|rsync):\/\///;
675 if (length($title) > 50) {
676 $title =~ s/(master|www|rsync)\.//;
678 if (length($title) > 50) {
679 $title =~ s/kernel.org:?//;
681 if (length($title) > 50) {
682 $title =~ s/\/pub\/scm//;
685 $co{'title_short'} = chop_str
($title, 50, 5);
689 # remove added spaces
690 foreach my $line (@commit_lines) {
693 $co{'comment'} = \
@commit_lines;
695 my $age = time - $co{'committer_epoch'};
697 $co{'age_string'} = age_string
($age);
698 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
699 if ($age > 60*60*24*7*2) {
700 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
701 $co{'age_string_age'} = $co{'age_string'};
703 $co{'age_string_date'} = $co{'age_string'};
704 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
709 # parse ref from ref_file, given by ref_id, with given type
711 my $ref_file = shift;
713 my $type = shift || git_get_type
($ref_id);
716 $ref_item{'type'} = $type;
717 $ref_item{'id'} = $ref_id;
718 $ref_item{'epoch'} = 0;
719 $ref_item{'age'} = "unknown";
720 if ($type eq "tag") {
721 my %tag = parse_tag
($ref_id);
722 $ref_item{'comment'} = $tag{'comment'};
723 if ($tag{'type'} eq "commit") {
724 my %co = parse_commit
($tag{'object'});
725 $ref_item{'epoch'} = $co{'committer_epoch'};
726 $ref_item{'age'} = $co{'age_string'};
727 } elsif (defined($tag{'epoch'})) {
728 my $age = time - $tag{'epoch'};
729 $ref_item{'epoch'} = $tag{'epoch'};
730 $ref_item{'age'} = age_string
($age);
732 $ref_item{'reftype'} = $tag{'type'};
733 $ref_item{'name'} = $tag{'name'};
734 $ref_item{'refid'} = $tag{'object'};
735 } elsif ($type eq "commit"){
736 my %co = parse_commit
($ref_id);
737 $ref_item{'reftype'} = "commit";
738 $ref_item{'name'} = $ref_file;
739 $ref_item{'title'} = $co{'title'};
740 $ref_item{'refid'} = $ref_id;
741 $ref_item{'epoch'} = $co{'committer_epoch'};
742 $ref_item{'age'} = $co{'age_string'};
744 $ref_item{'reftype'} = $type;
745 $ref_item{'name'} = $ref_file;
746 $ref_item{'refid'} = $ref_id;
752 ## ......................................................................
753 ## parse to array of hashes functions
755 sub git_get_refs_list
{
760 my $pfxlen = length("$projectroot/$project/$ref_dir");
761 File
::Find
::find
(sub {
764 push @refs, substr($File::Find
::name
, $pfxlen + 1);
766 }, "$projectroot/$project/$ref_dir");
768 foreach my $ref_file (@refs) {
769 my $ref_id = git_get_hash_by_ref
("$project/$ref_dir/$ref_file");
770 my $type = git_get_type
($ref_id) || next;
771 my %ref_item = parse_ref
($ref_file, $ref_id, $type);
773 push @reflist, \
%ref_item;
776 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
780 ## ----------------------------------------------------------------------
781 ## filesystem-related functions
786 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
787 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
788 if (!defined $gcos) {
792 $owner =~ s/[,;].*$//;
793 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
796 ## ......................................................................
797 ## mimetype related functions
799 sub mimetype_guess_file
{
800 my $filename = shift;
802 -r
$mimemap or return undef;
805 open(MIME
, $mimemap) or return undef;
807 my ($mime, $exts) = split(/\t+/);
809 my @exts = split(/\s+/, $exts);
810 foreach my $ext (@exts) {
811 $mimemap{$ext} = $mime;
817 $filename =~ /\.(.*?)$/;
822 my $filename = shift;
824 $filename =~ /\./ or return undef;
826 if ($mimetypes_file) {
827 my $file = $mimetypes_file;
828 #$file =~ m#^/# or $file = "$projectroot/$path/$file";
829 $mime = mimetype_guess_file
($filename, $file);
831 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
837 my $filename = shift;
840 my $mime = mimetype_guess
($filename);
841 $mime and return $mime;
845 return $default_blob_plain_mimetype unless $fd;
848 return 'text/plain' .
849 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
850 } elsif (! $filename) {
851 return 'application/octet-stream';
852 } elsif ($filename =~ m/\.png$/i) {
854 } elsif ($filename =~ m/\.gif$/i) {
856 } elsif ($filename =~ m/\.jpe?g$/i) {
859 return 'application/octet-stream';
863 ## ======================================================================
864 ## functions printing HTML: header, footer, error page
866 sub git_header_html
{
867 my $status = shift || "200 OK";
870 my $title = "$site_name git";
871 if (defined $project) {
872 $title .= " - $project";
873 if (defined $action) {
874 $title .= "/$action";
875 if (defined $file_name) {
876 $title .= " - $file_name";
877 if ($action eq "tree" && $file_name !~ m
|/$|) {
884 # require explicit support from the UA if we are to send the page as
885 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
886 # we have to do this because MSIE sometimes globs '*/*', pretending to
887 # support xhtml+xml but choking when it gets what it asked for.
888 if (defined $cgi->http('HTTP_ACCEPT') && $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ && $cgi->Accept('application/xhtml
+xml
') != 0) {
889 $content_type = 'application
/xhtml
+xml
';
891 $content_type = 'text
/html
';
893 print $cgi->header(-type=>$content_type, -charset => 'utf
-8', -status=> $status, -expires => $expires);
895 <?xml version="1.0" encoding="utf-8"?>
896 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
897 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
898 <!-- git web interface v$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
899 <!-- git core binaries version $git_version -->
901 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
902 <meta name="robots" content="index, nofollow"/>
903 <title>$title</title>
904 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
906 if (defined $project) {
907 printf('<link rel="alternate" title="%s log" '.
908 'href="%s" type="application/rss+xml"/>'."\n",
910 esc_param
("$my_uri?p=$project;a=rss"));
915 "<div class=\"page_header\">\n" .
916 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
917 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
919 print $cgi->a({-href
=> esc_param
($home_link)}, "projects") . " / ";
920 if (defined $project) {
921 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, esc_html
($project));
922 if (defined $action) {
926 if (!defined $searchtext) {
930 if (defined $hash_base) {
931 $search_hash = $hash_base;
932 } elsif (defined $hash) {
933 $search_hash = $hash;
935 $search_hash = "HEAD";
937 $cgi->param("a", "search");
938 $cgi->param("h", $search_hash);
939 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
940 "<div class=\"search\">\n" .
941 $cgi->hidden(-name
=> "p") . "\n" .
942 $cgi->hidden(-name
=> "a") . "\n" .
943 $cgi->hidden(-name
=> "h") . "\n" .
944 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
946 $cgi->end_form() . "\n";
951 sub git_footer_html
{
952 print "<div class=\"page_footer\">\n";
953 if (defined $project) {
954 my $descr = git_get_project_description
($project);
955 if (defined $descr) {
956 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
958 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=rss"), -class => "rss_logo"}, "RSS") . "\n";
960 print $cgi->a({-href
=> "$my_uri?" . esc_param
("a=opml"), -class => "rss_logo"}, "OPML") . "\n";
968 my $status = shift || "403 Forbidden";
969 my $error = shift || "Malformed query, file missing or permission denied";
971 git_header_html
($status);
972 print "<div class=\"page_body\">\n" .
974 "$status - $error\n" .
981 ## ----------------------------------------------------------------------
982 ## functions printing or outputting HTML: navigation
984 sub git_print_page_nav
{
985 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
986 $extra = '' if !defined $extra; # pager or formats
988 my @navs = qw(summary shortlog log commit commitdiff tree);
990 @navs = grep { $_ ne $suppress } @navs;
993 my %arg = map { $_, ''} @navs;
995 for (qw(commit commitdiff)) {
996 $arg{$_} = ";h=$head";
998 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
999 for (qw(shortlog log)) {
1000 $arg{$_} = ";h=$head";
1004 $arg{tree
} .= ";h=$treehead" if defined $treehead;
1005 $arg{tree
} .= ";hb=$treebase" if defined $treebase;
1007 print "<div class=\"page_nav\">\n" .
1009 map { $_ eq $current
1011 : $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$_$arg{$_}")}, "$_")
1014 print "<br/>\n$extra<br/>\n" .
1018 sub format_paging_nav
{
1019 my ($action, $hash, $head, $page, $nrevs) = @_;
1023 if ($hash ne $head || $page) {
1024 $paging_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$action")}, "HEAD");
1026 $paging_nav .= "HEAD";
1030 $paging_nav .= " ⋅ " .
1031 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$action;h=$hash;pg=" . ($page-1)),
1032 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1034 $paging_nav .= " ⋅ prev";
1037 if ($nrevs >= (100 * ($page+1)-1)) {
1038 $paging_nav .= " ⋅ " .
1039 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$action;h=$hash;pg=" . ($page+1)),
1040 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1042 $paging_nav .= " ⋅ next";
1048 ## ......................................................................
1049 ## functions printing or outputting HTML: div
1051 sub git_print_header_div
{
1052 my ($action, $title, $hash, $hash_base) = @_;
1055 $rest .= ";h=$hash" if $hash;
1056 $rest .= ";hb=$hash_base" if $hash_base;
1058 print "<div class=\"header\">\n" .
1059 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$action$rest"),
1060 -class => "title"}, $title ?
$title : $action) . "\n" .
1064 sub git_print_page_path
{
1068 if (!defined $name) {
1069 print "<div class=\"page_path\"><b>/</b></div>\n";
1070 } elsif (defined $type && $type eq 'blob') {
1071 print "<div class=\"page_path\"><b>" .
1072 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;f=$file_name")}, esc_html
($name)) . "</b><br/></div>\n";
1074 print "<div class=\"page_path\"><b>" . esc_html
($name) . "</b><br/></div>\n";
1078 ## ......................................................................
1079 ## functions printing large fragments of HTML
1081 sub git_shortlog_body
{
1082 # uses global variable $project
1083 my ($revlist, $from, $to, $refs, $extra) = @_;
1084 $from = 0 unless defined $from;
1085 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1087 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
1089 for (my $i = $from; $i <= $to; $i++) {
1090 my $commit = $revlist->[$i];
1091 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
1092 my $ref = format_ref_marker
($refs, $commit);
1093 my %co = parse_commit
($commit);
1095 print "<tr class=\"dark\">\n";
1097 print "<tr class=\"light\">\n";
1100 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1101 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1102 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
1104 print format_subject_html
($co{'title'}, $co{'title_short'}, "p=$project;a=commit;h=$commit", $ref);
1106 "<td class=\"link\">" .
1107 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") . " | " .
1108 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1112 if (defined $extra) {
1114 "<td colspan=\"4\">$extra</td>\n" .
1121 # uses global variable $project
1122 my ($taglist, $from, $to, $extra) = @_;
1123 $from = 0 unless defined $from;
1124 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1126 print "<table class=\"tags\" cellspacing=\"0\">\n";
1128 for (my $i = $from; $i <= $to; $i++) {
1129 my $entry = $taglist->[$i];
1131 my $comment_lines = $tag{'comment'};
1132 my $comment = shift @
$comment_lines;
1134 if (defined $comment) {
1135 $comment_short = chop_str
($comment, 30, 5);
1138 print "<tr class=\"dark\">\n";
1140 print "<tr class=\"light\">\n";
1143 print "<td><i>$tag{'age'}</i></td>\n" .
1145 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"),
1146 -class => "list"}, "<b>" . esc_html
($tag{'name'}) . "</b>") .
1149 if (defined $comment) {
1150 print format_subject_html
($comment, $comment_short, "p=$project;a=tag;h=$tag{'id'}");
1153 "<td class=\"selflink\">";
1154 if ($tag{'type'} eq "tag") {
1155 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, "tag");
1160 "<td class=\"link\">" . " | " .
1161 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1162 if ($tag{'reftype'} eq "commit") {
1163 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1164 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'refid'}")}, "log");
1165 } elsif ($tag{'reftype'} eq "blob") {
1166 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$tag{'refid'}")}, "raw");
1171 if (defined $extra) {
1173 "<td colspan=\"5\">$extra</td>\n" .
1179 sub git_heads_body
{
1180 # uses global variable $project
1181 my ($taglist, $head, $from, $to, $extra) = @_;
1182 $from = 0 unless defined $from;
1183 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1185 print "<table class=\"heads\" cellspacing=\"0\">\n";
1187 for (my $i = $from; $i <= $to; $i++) {
1188 my $entry = $taglist->[$i];
1190 my $curr = $tag{'id'} eq $head;
1192 print "<tr class=\"dark\">\n";
1194 print "<tr class=\"light\">\n";
1197 print "<td><i>$tag{'age'}</i></td>\n" .
1198 ($tag{'id'} eq $head ?
"<td class=\"current_head\">" : "<td>") .
1199 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}"),
1200 -class => "list"}, "<b>" . esc_html
($tag{'name'}) . "</b>") .
1202 "<td class=\"link\">" .
1203 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") . " | " .
1204 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'name'}")}, "log") .
1208 if (defined $extra) {
1210 "<td colspan=\"3\">$extra</td>\n" .
1216 ## ----------------------------------------------------------------------
1217 ## functions printing large fragments, format as one of arguments
1219 sub git_diff_print
{
1221 my $from_name = shift;
1223 my $to_name = shift;
1224 my $format = shift || "html";
1226 my $from_tmp = "/dev/null";
1227 my $to_tmp = "/dev/null";
1230 # create tmp from-file
1231 if (defined $from) {
1232 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
1233 open my $fd2, "> $from_tmp";
1234 open my $fd, "-|", $GIT, "cat-file", "blob", $from;
1241 # create tmp to-file
1243 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
1244 open my $fd2, "> $to_tmp";
1245 open my $fd, "-|", $GIT, "cat-file", "blob", $to;
1252 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
1253 if ($format eq "plain") {
1258 while (my $line = <$fd>) {
1260 my $char = substr($line, 0, 1);
1261 my $diff_class = "";
1263 $diff_class = " add";
1264 } elsif ($char eq "-") {
1265 $diff_class = " rem";
1266 } elsif ($char eq "@") {
1267 $diff_class = " chunk_header";
1268 } elsif ($char eq "\\") {
1272 $line = untabify
($line);
1273 print "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
1278 if (defined $from) {
1287 ## ======================================================================
1288 ## ======================================================================
1291 sub git_project_list
{
1292 my $order = $cgi->param('o');
1293 if (defined $order && $order !~ m/project|descr|owner|age/) {
1294 die_error
(undef, "Unknown order parameter");
1297 my @list = git_get_projects_list
();
1300 die_error
(undef, "No projects found");
1302 foreach my $pr (@list) {
1303 my $head = git_get_head_hash
($pr->{'path'});
1304 if (!defined $head) {
1307 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
1308 my %co = parse_commit
($head);
1312 $pr->{'commit'} = \
%co;
1313 if (!defined $pr->{'descr'}) {
1314 my $descr = git_get_project_description
($pr->{'path'}) || "";
1315 $pr->{'descr'} = chop_str
($descr, 25, 5);
1317 if (!defined $pr->{'owner'}) {
1318 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
1320 push @projects, $pr;
1324 if (-f
$home_text) {
1325 print "<div class=\"index_include\">\n";
1326 open (my $fd, $home_text);
1331 print "<table class=\"project_list\">\n" .
1333 $order ||= "project";
1334 if ($order eq "project") {
1335 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
1336 print "<th>Project</th>\n";
1339 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=project"),
1340 -class => "header"}, "Project") .
1343 if ($order eq "descr") {
1344 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
1345 print "<th>Description</th>\n";
1348 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=descr"),
1349 -class => "header"}, "Description") .
1352 if ($order eq "owner") {
1353 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
1354 print "<th>Owner</th>\n";
1357 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=owner"),
1358 -class => "header"}, "Owner") .
1361 if ($order eq "age") {
1362 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
1363 print "<th>Last Change</th>\n";
1366 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=age"),
1367 -class => "header"}, "Last Change") .
1370 print "<th></th>\n" .
1373 foreach my $pr (@projects) {
1375 print "<tr class=\"dark\">\n";
1377 print "<tr class=\"light\">\n";
1380 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=summary"),
1381 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
1382 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
1383 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
1384 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" .
1385 $pr->{'commit'}{'age_string'} . "</td>\n" .
1386 "<td class=\"link\">" .
1387 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=summary")}, "summary") . " | " .
1388 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=shortlog")}, "shortlog") . " | " .
1389 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=log")}, "log") .
1398 my $descr = git_get_project_description
($project) || "none";
1399 my $head = git_get_head_hash
($project);
1400 my %co = parse_commit
($head);
1401 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
1404 if (-f
$projects_list) {
1405 open (my $fd , $projects_list);
1406 while (my $line = <$fd>) {
1408 my ($pr, $ow) = split ' ', $line;
1409 $pr = unescape
($pr);
1410 $ow = unescape
($ow);
1411 if ($pr eq $project) {
1412 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
1418 if (!defined $owner) {
1419 $owner = get_file_owner
("$projectroot/$project");
1422 my $refs = git_get_references
();
1424 git_print_page_nav
('summary','', $head);
1426 print "<div class=\"title\"> </div>\n";
1427 print "<table cellspacing=\"0\">\n" .
1428 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
1429 "<tr><td>owner</td><td>$owner</td></tr>\n" .
1430 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
1433 open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_get_head_hash
($project)
1434 or die_error
(undef, "Open git-rev-list failed");
1435 my @revlist = map { chomp; $_ } <$fd>;
1437 git_print_header_div
('shortlog');
1438 git_shortlog_body
(\
@revlist, 0, 15, $refs,
1439 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "..."));
1441 my $taglist = git_get_refs_list
("refs/tags");
1442 if (defined @
$taglist) {
1443 git_print_header_div
('tags');
1444 git_tags_body
($taglist, 0, 15,
1445 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tags")}, "..."));
1448 my $headlist = git_get_refs_list
("refs/heads");
1449 if (defined @
$headlist) {
1450 git_print_header_div
('heads');
1451 git_heads_body
($headlist, $head, 0, 15,
1452 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=heads")}, "..."));
1459 my $head = git_get_head_hash
($project);
1461 git_print_page_nav
('','', $head,undef,$head);
1462 my %tag = parse_tag
($hash);
1463 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
1464 print "<div class=\"title_text\">\n" .
1465 "<table cellspacing=\"0\">\n" .
1467 "<td>object</td>\n" .
1468 "<td>" . $cgi->a({-class => "list", -href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'object'}) . "</td>\n" .
1469 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'type'}) . "</td>\n" .
1471 if (defined($tag{'author'})) {
1472 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
1473 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
1474 print "<tr><td></td><td>" . $ad{'rfc2822'} . sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) . "</td></tr>\n";
1476 print "</table>\n\n" .
1478 print "<div class=\"page_body\">";
1479 my $comment = $tag{'comment'};
1480 foreach my $line (@
$comment) {
1481 print esc_html
($line) . "<br/>\n";
1490 die_error
(undef, "Permission denied") if (!git_get_project_config_bool
('blame'));
1491 die_error
('404 Not Found', "File name not defined") if (!$file_name);
1492 $hash_base ||= git_get_head_hash
($project);
1493 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
1494 my %co = parse_commit
($hash_base)
1495 or die_error
(undef, "Reading commit failed");
1496 if (!defined $hash) {
1497 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
1498 or die_error
(undef, "Error looking up file");
1500 $ftype = git_get_type
($hash);
1501 if ($ftype !~ "blob") {
1502 die_error
("400 Bad Request", "Object is not a blob");
1504 open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base)
1505 or die_error
(undef, "Open git-blame failed");
1508 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") .
1509 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;f=$file_name")}, "head");
1510 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1511 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
1512 git_print_page_path
($file_name, $ftype);
1513 my @rev_color = (qw(light2 dark2));
1514 my $num_colors = scalar(@rev_color);
1515 my $current_color = 0;
1517 print "<div class=\"page_body\">\n";
1518 print "<table class=\"blame\">\n";
1519 print "<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n";
1521 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
1523 my $rev = substr($full_rev, 0, 8);
1527 if (!defined $last_rev) {
1528 $last_rev = $full_rev;
1529 } elsif ($last_rev ne $full_rev) {
1530 $last_rev = $full_rev;
1531 $current_color = ++$current_color % $num_colors;
1533 print "<tr class=\"$rev_color[$current_color]\">\n";
1534 print "<td class=\"sha1\">" .
1535 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$full_rev;f=$file_name")}, esc_html
($rev)) . "</td>\n";
1536 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" . esc_html
($lineno) . "</a></td>\n";
1537 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
1542 close $fd or print "Reading blob failed\n";
1548 die_error
('403 Permission denied', "Permission denied") if (!git_get_project_config_bool
('blame'));
1549 die_error
('404 Not Found', "File name not defined") if (!$file_name);
1550 $hash_base ||= git_get_head_hash
($project);
1551 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
1552 my %co = parse_commit
($hash_base)
1553 or die_error
(undef, "Reading commit failed");
1554 if (!defined $hash) {
1555 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
1556 or die_error
(undef, "Error lookup file");
1558 open ($fd, "-|", $GIT, "annotate", '-l', '-t', '-r', $file_name, $hash_base)
1559 or die_error
(undef, "Open git-annotate failed");
1562 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") .
1563 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;f=$file_name")}, "head");
1564 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1565 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
1566 git_print_page_path
($file_name, 'blob');
1567 print "<div class=\"page_body\">\n";
1569 <table class="blame">
1578 my @line_class = (qw(light dark));
1579 my $line_class_len = scalar (@line_class);
1580 my $line_class_num = $#line_class;
1581 while (my $line = <$fd>) {
1593 $line_class_num = ($line_class_num + 1) % $line_class_len;
1595 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) \+\d\d\d\d\t(\d+)\)(.*)$/) {
1602 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
1605 $short_rev = substr ($long_rev, 0, 8);
1606 $age = time () - $time;
1607 $age_str = age_string
($age);
1608 $age_str =~ s/ / /g;
1609 $age_class = age_class
($age);
1610 $author = esc_html
($author);
1611 $author =~ s/ / /g;
1613 $data = untabify
($data);
1614 $data = esc_html
($data);
1617 <tr class="$line_class[$line_class_num]">
1618 <td class="sha1"><a href="$my_uri?${\esc_param ("p=$project;a=commit;h=$long_rev")}" class="text">$short_rev..</a></td>
1619 <td class="$age_class">$age_str</td>
1621 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
1622 <td class="pre">$data</td>
1625 } # while (my $line = <$fd>)
1626 print "</table>\n\n";
1627 close $fd or print "Reading blob failed.\n";
1633 my $head = git_get_head_hash
($project);
1635 git_print_page_nav
('','', $head,undef,$head);
1636 git_print_header_div
('summary', $project);
1638 my $taglist = git_get_refs_list
("refs/tags");
1639 if (defined @
$taglist) {
1640 git_tags_body
($taglist);
1646 my $head = git_get_head_hash
($project);
1648 git_print_page_nav
('','', $head,undef,$head);
1649 git_print_header_div
('summary', $project);
1651 my $taglist = git_get_refs_list
("refs/heads");
1652 if (defined @
$taglist) {
1653 git_heads_body
($taglist, $head);
1658 sub git_blob_plain
{
1659 if (!defined $hash) {
1660 if (defined $file_name) {
1661 my $base = $hash_base || git_get_head_hash
($project);
1662 $hash = git_get_hash_by_path
($base, $file_name, "blob")
1663 or die_error
(undef, "Error lookup file");
1665 die_error
(undef, "No file name defined");
1669 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
1670 or die_error
(undef, "Couldn't cat $file_name, $hash");
1672 $type ||= blob_mimetype
($fd, $file_name);
1674 # save as filename, even when no $file_name is given
1675 my $save_as = "$hash";
1676 if (defined $file_name) {
1677 $save_as = $file_name;
1678 } elsif ($type =~ m/^text\//) {
1682 print $cgi->header(-type
=> "$type", '-content-disposition' => "inline; filename=\"$save_as\"");
1684 binmode STDOUT
, ':raw';
1686 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
1692 if (!defined $hash) {
1693 if (defined $file_name) {
1694 my $base = $hash_base || git_get_head_hash
($project);
1695 $hash = git_get_hash_by_path
($base, $file_name, "blob")
1696 or die_error
(undef, "Error lookup file");
1698 die_error
(undef, "No file name defined");
1701 my $have_blame = git_get_project_config_bool
('blame');
1702 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
1703 or die_error
(undef, "Couldn't cat $file_name, $hash");
1704 my $mimetype = blob_mimetype
($fd, $file_name);
1705 if ($mimetype !~ m/^text\//) {
1707 return git_blob_plain
($mimetype);
1710 my $formats_nav = '';
1711 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
1712 if (defined $file_name) {
1714 $formats_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;h=$hash;hb=$hash_base;f=$file_name")}, "blame") . " | ";
1717 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$hash;f=$file_name")}, "plain") .
1718 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;hb=HEAD;f=$file_name")}, "head");
1720 $formats_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$hash")}, "plain");
1722 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1723 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
1725 print "<div class=\"page_nav\">\n" .
1726 "<br/><br/></div>\n" .
1727 "<div class=\"title\">$hash</div>\n";
1729 git_print_page_path
($file_name, "blob");
1730 print "<div class=\"page_body\">\n";
1732 while (my $line = <$fd>) {
1735 $line = untabify
($line);
1736 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", $nr, $nr, $nr, esc_html
($line);
1738 close $fd or print "Reading blob failed.\n";
1744 if (!defined $hash) {
1745 $hash = git_get_head_hash
($project);
1746 if (defined $file_name) {
1747 my $base = $hash_base || $hash;
1748 $hash = git_get_hash_by_path
($base, $file_name, "tree");
1750 if (!defined $hash_base) {
1755 open my $fd, "-|", $GIT, "ls-tree", '-z', $hash
1756 or die_error
(undef, "Open git-ls-tree failed");
1757 my @entries = map { chomp; $_ } <$fd>;
1758 close $fd or die_error
(undef, "Reading tree failed");
1761 my $refs = git_get_references
();
1762 my $ref = format_ref_marker
($refs, $hash_base);
1766 my $have_blame = git_get_project_config_bool
('blame');
1767 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
1768 $base_key = ";hb=$hash_base";
1769 git_print_page_nav
('tree','', $hash_base);
1770 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
1772 print "<div class=\"page_nav\">\n";
1773 print "<br/><br/></div>\n";
1774 print "<div class=\"title\">$hash</div>\n";
1776 if (defined $file_name) {
1777 $base = esc_html
("$file_name/");
1779 git_print_page_path
($file_name, 'tree');
1780 print "<div class=\"page_body\">\n";
1781 print "<table cellspacing=\"0\">\n";
1783 foreach my $line (@entries) {
1784 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1785 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1789 my $t_name = validate_input
($4);
1791 print "<tr class=\"dark\">\n";
1793 print "<tr class=\"light\">\n";
1796 print "<td class=\"mode\">" . mode_str
($t_mode) . "</td>\n";
1797 if ($t_type eq "blob") {
1798 print "<td class=\"list\">" .
1799 $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)) .
1801 "<td class=\"link\">" .
1802 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name")}, "blob");
1804 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;h=$t_hash$base_key;f=$base$t_name")}, "blame");
1806 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;h=$t_hash;hb=$hash_base;f=$base$t_name")}, "history") .
1807 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$t_hash;f=$base$t_name")}, "raw") .
1809 } elsif ($t_type eq "tree") {
1810 print "<td class=\"list\">" .
1811 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, esc_html
($t_name)) .
1813 "<td class=\"link\">" .
1814 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, "tree") .
1815 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;hb=$hash_base;f=$base$t_name")}, "history") .
1820 print "</table>\n" .
1826 my $head = git_get_head_hash
($project);
1827 if (!defined $hash) {
1830 if (!defined $page) {
1833 my $refs = git_get_references
();
1835 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
1836 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
1837 or die_error
(undef, "Open git-rev-list failed");
1838 my @revlist = map { chomp; $_ } <$fd>;
1841 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
1844 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
1847 my %co = parse_commit
($hash);
1849 git_print_header_div
('summary', $project);
1850 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
1852 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
1853 my $commit = $revlist[$i];
1854 my $ref = format_ref_marker
($refs, $commit);
1855 my %co = parse_commit
($commit);
1857 my %ad = parse_date
($co{'author_epoch'});
1858 git_print_header_div
('commit',
1859 "<span class=\"age\">$co{'age_string'}</span>" .
1860 esc_html
($co{'title'}) . $ref,
1862 print "<div class=\"title_text\">\n" .
1863 "<div class=\"log_link\">\n" .
1864 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
1865 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1868 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
1870 "<div class=\"log_body\">\n";
1871 my $comment = $co{'comment'};
1873 foreach my $line (@
$comment) {
1874 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1885 print format_log_line_html
($line) . "<br/>\n";
1896 my %co = parse_commit
($hash);
1898 die_error
(undef, "Unknown commit object");
1900 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
1901 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
1903 my $parent = $co{'parent'};
1904 if (!defined $parent) {
1907 open my $fd, "-|", $GIT, "diff-tree", '-r', '-M', $parent, $hash
1908 or die_error
(undef, "Open git-diff-tree failed");
1909 my @difftree = map { chomp; $_ } <$fd>;
1910 close $fd or die_error
(undef, "Reading git-diff-tree failed");
1912 # non-textual hash id's can be cached
1914 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
1917 my $refs = git_get_references
();
1918 my $ref = format_ref_marker
($refs, $co{'id'});
1919 my $formats_nav = '';
1920 if (defined $file_name && defined $co{'parent'}) {
1921 my $parent = $co{'parent'};
1922 $formats_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;hb=$parent;f=$file_name")}, "blame");
1924 git_header_html
(undef, $expires);
1925 git_print_page_nav
('commit', defined $co{'parent'} ?
'' : 'commitdiff',
1926 $hash, $co{'tree'}, $hash,
1929 if (defined $co{'parent'}) {
1930 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
1932 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
1934 print "<div class=\"title_text\">\n" .
1935 "<table cellspacing=\"0\">\n";
1936 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
1938 "<td></td><td> $ad{'rfc2822'}";
1939 if ($ad{'hour_local'} < 6) {
1940 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1942 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1946 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
1947 print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
1948 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
1951 "<td class=\"sha1\">" .
1952 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash"), class => "list"}, $co{'tree'}) .
1954 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
1957 my $parents = $co{'parents'};
1958 foreach my $par (@
$parents) {
1961 "<td class=\"sha1\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$par"), class => "list"}, $par) . "</td>" .
1962 "<td class=\"link\">" .
1963 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$par")}, "commit") .
1964 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash;hp=$par")}, "commitdiff") .
1970 print "<div class=\"page_body\">\n";
1971 my $comment = $co{'comment'};
1974 foreach my $line (@
$comment) {
1975 # print only one empty line
1977 if ($empty || $signed) {
1984 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1986 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1989 print format_log_line_html
($line) . "<br/>\n";
1993 print "<div class=\"list_head\">\n";
1994 if ($#difftree > 10) {
1995 print(($#difftree + 1) . " files changed:\n");
1998 print "<table class=\"diff_tree\">\n";
2000 foreach my $line (@difftree) {
2001 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2002 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2003 if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2011 my $similarity = $6;
2012 my $file = validate_input
(unquote
($7));
2014 print "<tr class=\"dark\">\n";
2016 print "<tr class=\"light\">\n";
2019 if ($status eq "A") {
2021 if (S_ISREG
(oct $to_mode)) {
2022 $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
2025 $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" .
2026 "<td><span class=\"file_status new\">[new " . file_type
($to_mode) . "$mode_chng]</span></td>\n" .
2027 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob") . "</td>\n";
2028 } elsif ($status eq "D") {
2030 $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" .
2031 "<td><span class=\"file_status deleted\">[deleted " . file_type
($from_mode). "]</span></td>\n" .
2032 "<td class=\"link\">" .
2033 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$parent;f=$file")}, "blob") .
2034 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;hb=$parent;f=$file")}, "history") .
2036 } elsif ($status eq "M" || $status eq "T") {
2037 my $mode_chnge = "";
2038 if ($from_mode != $to_mode) {
2039 $mode_chnge = " <span class=\"file_status mode_chnge\">[changed";
2040 if (((oct $from_mode) & S_IFMT
) != ((oct $to_mode) & S_IFMT
)) {
2041 $mode_chnge .= " from " . file_type
($from_mode) . " to " . file_type
($to_mode);
2043 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
2044 if (S_ISREG
($from_mode) && S_ISREG
($to_mode)) {
2045 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
2046 } elsif (S_ISREG
($to_mode)) {
2047 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
2050 $mode_chnge .= "]</span>\n";
2053 if ($to_id ne $from_id) {
2054 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));
2056 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file"), -class => "list"}, esc_html
($file));
2059 "<td>$mode_chnge</td>\n" .
2060 "<td class=\"link\">";
2061 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob");
2062 if ($to_id ne $from_id) {
2063 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file")}, "diff");
2065 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;hb=$hash;f=$file")}, "history") . "\n";
2067 } elsif ($status eq "R") {
2068 my ($from_file, $to_file) = split "\t", $file;
2070 if ($from_mode != $to_mode) {
2071 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
2074 $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" .
2075 "<td><span class=\"file_status moved\">[moved from " .
2076 $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)) .
2077 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
2078 "<td class=\"link\">" .
2079 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file")}, "blob");
2080 if ($to_id ne $from_id) {
2081 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file")}, "diff");
2092 mkdir($git_temp, 0700);
2094 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2096 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff_plain;h=$hash;hp=$hash_parent")}, "plain");
2097 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2098 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2100 print "<div class=\"page_nav\">\n" .
2101 "<br/><br/></div>\n" .
2102 "<div class=\"title\">$hash vs $hash_parent</div>\n";
2104 git_print_page_path
($file_name, "blob");
2105 print "<div class=\"page_body\">\n" .
2106 "<div class=\"diff_info\">blob:" .
2107 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name")}, $hash_parent) .
2109 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, $hash) .
2111 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
2116 sub git_blobdiff_plain
{
2117 mkdir($git_temp, 0700);
2118 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8');
2119 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
2122 sub git_commitdiff
{
2123 mkdir($git_temp, 0700);
2124 my %co = parse_commit
($hash);
2126 die_error
(undef, "Unknown commit object");
2128 if (!defined $hash_parent) {
2129 $hash_parent = $co{'parent'} || '--root';
2131 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2132 or die_error
(undef, "Open git-diff-tree failed");
2133 my @difftree = map { chomp; $_ } <$fd>;
2134 close $fd or die_error
(undef, "Reading git-diff-tree failed");
2136 # non-textual hash id's can be cached
2138 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2141 my $refs = git_get_references
();
2142 my $ref = format_ref_marker
($refs, $co{'id'});
2144 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent")}, "plain");
2145 git_header_html
(undef, $expires);
2146 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
2147 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
2148 print "<div class=\"page_body\">\n";
2149 my $comment = $co{'comment'};
2152 my @log = @
$comment;
2153 # remove first and empty lines after that
2155 while (defined $log[0] && $log[0] eq "") {
2158 foreach my $line (@log) {
2159 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2170 print format_log_line_html
($line) . "<br/>\n";
2173 foreach my $line (@difftree) {
2174 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2175 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2176 if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2184 my $file = validate_input
(unquote
($6));
2185 if ($status eq "A") {
2186 print "<div class=\"diff_info\">" . file_type
($to_mode) . ":" .
2187 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id) . "(new)" .
2189 git_diff_print
(undef, "/dev/null", $to_id, "b/$file");
2190 } elsif ($status eq "D") {
2191 print "<div class=\"diff_info\">" . file_type
($from_mode) . ":" .
2192 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash_parent;f=$file")}, $from_id) . "(deleted)" .
2194 git_diff_print
($from_id, "a/$file", undef, "/dev/null");
2195 } elsif ($status eq "M") {
2196 if ($from_id ne $to_id) {
2197 print "<div class=\"diff_info\">" .
2198 file_type
($from_mode) . ":" .
2199 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash_parent;f=$file")}, $from_id) .
2201 file_type
($to_mode) . ":" .
2202 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id);
2204 git_diff_print
($from_id, "a/$file", $to_id, "b/$file");
2213 sub git_commitdiff_plain
{
2214 mkdir($git_temp, 0700);
2215 my %co = parse_commit
($hash);
2217 die_error
(undef, "Unknown commit object");
2219 if (!defined $hash_parent) {
2220 $hash_parent = $co{'parent'} || '--root';
2222 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2223 or die_error
(undef, "Open git-diff-tree failed");
2224 my @difftree = map { chomp; $_ } <$fd>;
2225 close $fd or die_error
(undef, "Reading diff-tree failed");
2227 # try to figure out the next tag after this commit
2229 my $refs = git_get_references
("tags");
2230 open $fd, "-|", $GIT, "rev-list", "HEAD";
2231 my @commits = map { chomp; $_ } <$fd>;
2233 foreach my $commit (@commits) {
2234 if (defined $refs->{$commit}) {
2235 $tagname = $refs->{$commit}
2237 if ($commit eq $hash) {
2242 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8', '-content-disposition' => "inline; filename=\"git-$hash.patch\"");
2243 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2244 my $comment = $co{'comment'};
2245 print "From: $co{'author'}\n" .
2246 "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
2247 "Subject: $co{'title'}\n";
2248 if (defined $tagname) {
2249 print "X-Git-Tag: $tagname\n";
2251 print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
2254 foreach my $line (@
$comment) {;
2259 foreach my $line (@difftree) {
2260 if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2267 if ($status eq "A") {
2268 git_diff_print
(undef, "/dev/null", $to_id, "b/$file", "plain");
2269 } elsif ($status eq "D") {
2270 git_diff_print
($from_id, "a/$file", undef, "/dev/null", "plain");
2271 } elsif ($status eq "M") {
2272 git_diff_print
($from_id, "a/$file", $to_id, "b/$file", "plain");
2278 if (!defined $hash_base) {
2279 $hash_base = git_get_head_hash
($project);
2282 my %co = parse_commit
($hash_base);
2284 die_error
(undef, "Unknown commit object");
2286 my $refs = git_get_references
();
2288 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base);
2289 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2290 if (!defined $hash && defined $file_name) {
2291 $hash = git_get_hash_by_path
($hash_base, $file_name);
2293 if (defined $hash) {
2294 $ftype = git_get_type
($hash);
2296 git_print_page_path
($file_name, $ftype);
2299 $GIT, "rev-list", "--full-history", $hash_base, "--", $file_name;
2300 print "<table cellspacing=\"0\">\n";
2302 while (my $line = <$fd>) {
2303 if ($line =~ m/^([0-9a-fA-F]{40})/){
2305 my %co = parse_commit
($commit);
2309 my $ref = format_ref_marker
($refs, $commit);
2311 print "<tr class=\"dark\">\n";
2313 print "<tr class=\"light\">\n";
2316 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2317 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
2318 "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit"), -class => "list"}, "<b>" .
2319 esc_html
(chop_str
($co{'title'}, 50)) . "$ref</b>") . "</td>\n" .
2320 "<td class=\"link\">" .
2321 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
2322 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2323 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$ftype;hb=$commit;f=$file_name")}, $ftype);
2324 my $blob = git_get_hash_by_path
($hash_base, $file_name);
2325 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
2326 if (defined $blob && defined $blob_parent && $blob ne $blob_parent) {
2328 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$blob;hp=$blob_parent;hb=$commit;f=$file_name")},
2341 if (!defined $searchtext) {
2342 die_error
(undef, "Text field empty");
2344 if (!defined $hash) {
2345 $hash = git_get_head_hash
($project);
2347 my %co = parse_commit
($hash);
2349 die_error
(undef, "Unknown commit object");
2351 # pickaxe may take all resources of your box and run for several minutes
2352 # with every query - so decide by yourself how public you make this feature :)
2353 my $commit_search = 1;
2354 my $author_search = 0;
2355 my $committer_search = 0;
2356 my $pickaxe_search = 0;
2357 if ($searchtext =~ s/^author\\://i) {
2359 } elsif ($searchtext =~ s/^committer\\://i) {
2360 $committer_search = 1;
2361 } elsif ($searchtext =~ s/^pickaxe\\://i) {
2363 $pickaxe_search = 1;
2366 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
2367 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
2369 print "<table cellspacing=\"0\">\n";
2371 if ($commit_search) {
2373 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", $hash or next;
2374 while (my $commit_text = <$fd>) {
2375 if (!grep m/$searchtext/i, $commit_text) {
2378 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
2381 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
2384 my @commit_lines = split "\n", $commit_text;
2385 my %co = parse_commit
(undef, \
@commit_lines);
2390 print "<tr class=\"dark\">\n";
2392 print "<tr class=\"light\">\n";
2395 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2396 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2398 $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/>");
2399 my $comment = $co{'comment'};
2400 foreach my $line (@
$comment) {
2401 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2402 my $lead = esc_html
($1) || "";
2403 $lead = chop_str
($lead, 30, 10);
2404 my $match = esc_html
($2) || "";
2405 my $trail = esc_html
($3) || "";
2406 $trail = chop_str
($trail, 30, 10);
2407 my $text = "$lead<span class=\"match\">$match</span>$trail";
2408 print chop_str
($text, 80, 5) . "<br/>\n";
2412 "<td class=\"link\">" .
2413 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2414 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2421 if ($pickaxe_search) {
2423 open my $fd, "-|", "$GIT rev-list $hash | $GIT diff-tree -r --stdin -S\'$searchtext\'";
2426 while (my $line = <$fd>) {
2427 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2430 $set{'from_id'} = $3;
2432 $set{'id'} = $set{'to_id'};
2433 if ($set{'id'} =~ m/0{40}/) {
2434 $set{'id'} = $set{'from_id'};
2436 if ($set{'id'} =~ m/0{40}/) {
2440 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
2443 print "<tr class=\"dark\">\n";
2445 print "<tr class=\"light\">\n";
2448 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2449 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2451 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" .
2452 esc_html
(chop_str
($co{'title'}, 50)) . "</b><br/>");
2453 while (my $setref = shift @files) {
2455 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}"), class => "list"},
2456 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
2460 "<td class=\"link\">" .
2461 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2462 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2466 %co = parse_commit
($1);
2476 my $head = git_get_head_hash
($project);
2477 if (!defined $hash) {
2480 if (!defined $page) {
2483 my $refs = git_get_references
();
2485 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2486 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2487 or die_error
(undef, "Open git-rev-list failed");
2488 my @revlist = map { chomp; $_ } <$fd>;
2491 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
2493 if ($#revlist >= (100 * ($page+1)-1)) {
2495 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)),
2496 -title
=> "Alt-n"}, "next");
2501 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
2502 git_print_header_div
('summary', $project);
2504 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
2509 ## ......................................................................
2510 ## feeds (RSS, OPML)
2513 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
2514 open my $fd, "-|", $GIT, "rev-list", "--max-count=150", git_get_head_hash
($project)
2515 or die_error
(undef, "Open git-rev-list failed");
2516 my @revlist = map { chomp; $_ } <$fd>;
2517 close $fd or die_error
(undef, "Reading git-rev-list failed");
2518 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
2519 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
2520 "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
2521 print "<channel>\n";
2522 print "<title>$project</title>\n".
2523 "<link>" . esc_html
("$my_url?p=$project;a=summary") . "</link>\n".
2524 "<description>$project log</description>\n".
2525 "<language>en</language>\n";
2527 for (my $i = 0; $i <= $#revlist; $i++) {
2528 my $commit = $revlist[$i];
2529 my %co = parse_commit
($commit);
2530 # we read 150, we always show 30 and the ones more recent than 48 hours
2531 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
2534 my %cd = parse_date
($co{'committer_epoch'});
2535 open $fd, "-|", $GIT, "diff-tree", '-r', $co{'parent'}, $co{'id'} or next;
2536 my @difftree = map { chomp; $_ } <$fd>;
2540 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
2542 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
2543 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
2544 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
2545 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
2546 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
2547 "<content:encoded>" .
2549 my $comment = $co{'comment'};
2550 foreach my $line (@
$comment) {
2551 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
2552 print "$line<br/>\n";
2555 foreach my $line (@difftree) {
2556 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
2559 my $file = validate_input
(unquote
($7));
2560 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
2561 print "$file<br/>\n";
2564 "</content:encoded>\n" .
2567 print "</channel></rss>";
2571 my @list = git_get_projects_list
();
2573 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
2574 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
2575 "<opml version=\"1.0\">\n".
2577 " <title>$site_name Git OPML Export</title>\n".
2580 "<outline text=\"git RSS feeds\">\n";
2582 foreach my $pr (@list) {
2584 my $head = git_get_head_hash
($proj{'path'});
2585 if (!defined $head) {
2588 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
2589 my %co = parse_commit
($head);
2594 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
2595 my $rss = "$my_url?p=$proj{'path'};a=rss";
2596 my $html = "$my_url?p=$proj{'path'};a=summary";
2597 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
2599 print "</outline>\n".