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);
1068 my %ad = date_str($co{'author_epoch'});
1070 print "<tr class=\"dark\">\n";
1072 print "<tr class=\"light\">\n";
1075 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1076 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1077 "<td><i>" . esc_html(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
1079 if (length($co{'title_short'}) < length($co{'title'})) {
1080 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"),
1081 -class => "list", -title => "$co{'title'}"},
1082 "<b>" . esc_html($co{'title_short'}) . "$ref</b>");
1084 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit"),
1086 "<b>" . esc_html($co{'title'}) . "$ref</b>");
1089 "<td class=\"link\">" .
1090 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit")}, "commit") . " | " .
1091 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1095 if (defined $extra) {
1097 "<td colspan=\"4\">$extra</td>\n" .
1104 # uses global variable $project
1105 my ($taglist, $from, $to, $extra) = @_;
1106 $from = 0 unless defined $from;
1107 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1109 print "<table class=\"tags\" cellspacing=\"0\">\n";
1111 for (my $i = $from; $i <= $to; $i++) {
1112 my $entry = $taglist->[$i];
1114 my $comment_lines = $tag{'comment'};
1115 my $comment = shift @$comment_lines;
1117 if (defined $comment) {
1118 $comment_short = chop_str($comment, 30, 5);
1121 print "<tr class=\"dark\">\n";
1123 print "<tr class=\"light\">\n";
1126 print "<td><i>$tag{'age'}</i></td>\n" .
1128 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"),
1129 -class => "list"}, "<b>" . esc_html($tag{'name'}) . "</b>") .
1132 if (defined $comment) {
1133 if (length($comment_short) < length($comment)) {
1134 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}"),
1135 -class => "list", -title => $comment}, $comment_short);
1137 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}"),
1138 -class => "list"}, $comment);
1142 "<td class=\"selflink\">";
1143 if ($tag{'type'} eq "tag") {
1144 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tag;h=$tag{'id'}")}, "tag");
1149 "<td class=\"link\">" . " | " .
1150 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1151 if ($tag{'reftype'} eq "commit") {
1152 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1153 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'refid'}")}, "log");
1154 } elsif ($tag{'reftype'} eq "blob") {
1155 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$tag{'refid'}")}, "raw");
1160 if (defined $extra) {
1162 "<td colspan=\"5\">$extra</td>\n" .
1168 sub git_heads_body {
1169 # uses global variable $project
1170 my ($taglist, $head, $from, $to, $extra) = @_;
1171 $from = 0 unless defined $from;
1172 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1174 print "<table class=\"heads\" cellspacing=\"0\">\n";
1176 for (my $i = $from; $i <= $to; $i++) {
1177 my $entry = $taglist->[$i];
1179 my $curr = $tag{'id'} eq $head;
1181 print "<tr class=\"dark\">\n";
1183 print "<tr class=\"light\">\n";
1186 print "<td><i>$tag{'age'}</i></td>\n" .
1187 ($tag{'id'} eq $head ? "<td class=\"current_head\">" : "<td>") .
1188 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}"),
1189 -class => "list"}, "<b>" . esc_html($tag{'name'}) . "</b>") .
1191 "<td class=\"link\">" .
1192 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") . " | " .
1193 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=log;h=$tag{'name'}")}, "log") .
1197 if (defined $extra) {
1199 "<td colspan=\"3\">$extra</td>\n" .
1205 ## ----------------------------------------------------------------------
1206 ## functions printing large fragments, format as one of arguments
1208 sub git_diff_print {
1210 my $from_name = shift;
1212 my $to_name = shift;
1213 my $format = shift || "html";
1215 my $from_tmp = "/dev/null";
1216 my $to_tmp = "/dev/null";
1219 # create tmp from-file
1220 if (defined $from) {
1221 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
1222 open my $fd2, "> $from_tmp";
1223 open my $fd, "-|", $GIT, "cat-file", "blob", $from;
1230 # create tmp to-file
1232 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
1233 open my $fd2, "> $to_tmp";
1234 open my $fd, "-|", $GIT, "cat-file", "blob", $to;
1241 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
1242 if ($format eq "plain") {
1247 while (my $line = <$fd>) {
1249 my $char = substr($line, 0, 1);
1250 my $diff_class = "";
1252 $diff_class = " add";
1253 } elsif ($char eq "-") {
1254 $diff_class = " rem";
1255 } elsif ($char eq "@") {
1256 $diff_class = " chunk_header";
1257 } elsif ($char eq "\\") {
1261 $line = untabify($line);
1262 print "<div class=\"diff$diff_class\">" . esc_html($line) . "</div>\n";
1267 if (defined $from) {
1276 ## ======================================================================
1277 ## ======================================================================
1280 sub git_project_list {
1281 my $order = $cgi->param('o');
1282 if (defined $order && $order !~ m/project|descr|owner|age/) {
1283 die_error(undef, "Unknown order parameter");
1286 my @list = git_read_projects();
1289 die_error(undef, "No projects found");
1291 foreach my $pr (@list) {
1292 my $head = git_read_head($pr->{'path'});
1293 if (!defined $head) {
1296 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
1297 my %co = git_read_commit($head);
1301 $pr->{'commit'} = \%co;
1302 if (!defined $pr->{'descr'}) {
1303 my $descr = git_read_description($pr->{'path'}) || "";
1304 $pr->{'descr'} = chop_str($descr, 25, 5);
1306 if (!defined $pr->{'owner'}) {
1307 $pr->{'owner'} = get_file_owner("$projectroot/$pr->{'path'}") || "";
1309 push @projects, $pr;
1313 if (-f $home_text) {
1314 print "<div class=\"index_include\">\n";
1315 open (my $fd, $home_text);
1320 print "<table class=\"project_list\">\n" .
1322 $order ||= "project";
1323 if ($order eq "project") {
1324 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
1325 print "<th>Project</th>\n";
1328 $cgi->a({-href => "$my_uri?" . esc_param("o=project"),
1329 -class => "header"}, "Project") .
1332 if ($order eq "descr") {
1333 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
1334 print "<th>Description</th>\n";
1337 $cgi->a({-href => "$my_uri?" . esc_param("o=descr"),
1338 -class => "header"}, "Description") .
1341 if ($order eq "owner") {
1342 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
1343 print "<th>Owner</th>\n";
1346 $cgi->a({-href => "$my_uri?" . esc_param("o=owner"),
1347 -class => "header"}, "Owner") .
1350 if ($order eq "age") {
1351 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
1352 print "<th>Last Change</th>\n";
1355 $cgi->a({-href => "$my_uri?" . esc_param("o=age"),
1356 -class => "header"}, "Last Change") .
1359 print "<th></th>\n" .
1362 foreach my $pr (@projects) {
1364 print "<tr class=\"dark\">\n";
1366 print "<tr class=\"light\">\n";
1369 print "<td>" . $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=summary"),
1370 -class => "list"}, esc_html($pr->{'path'})) . "</td>\n" .
1371 "<td>" . esc_html($pr->{'descr'}) . "</td>\n" .
1372 "<td><i>" . chop_str($pr->{'owner'}, 15) . "</i></td>\n";
1373 print "<td class=\"". age_class($pr->{'commit'}{'age'}) . "\">" .
1374 $pr->{'commit'}{'age_string'} . "</td>\n" .
1375 "<td class=\"link\">" .
1376 $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=summary")}, "summary") . " | " .
1377 $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=shortlog")}, "shortlog") . " | " .
1378 $cgi->a({-href => "$my_uri?" . esc_param("p=$pr->{'path'};a=log")}, "log") .
1387 my $descr = git_read_description($project) || "none";
1388 my $head = git_read_head($project);
1389 my %co = git_read_commit($head);
1390 my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'});
1393 if (-f $projects_list) {
1394 open (my $fd , $projects_list);
1395 while (my $line = <$fd>) {
1397 my ($pr, $ow) = split ' ', $line;
1398 $pr = unescape($pr);
1399 $ow = unescape($ow);
1400 if ($pr eq $project) {
1401 $owner = decode("utf8", $ow, Encode::FB_DEFAULT);
1407 if (!defined $owner) {
1408 $owner = get_file_owner("$projectroot/$project");
1411 my $refs = read_info_ref();
1413 git_page_nav('summary','', $head);
1415 print "<div class=\"title\"> </div>\n";
1416 print "<table cellspacing=\"0\">\n" .
1417 "<tr><td>description</td><td>" . esc_html($descr) . "</td></tr>\n" .
1418 "<tr><td>owner</td><td>$owner</td></tr>\n" .
1419 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
1422 open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_read_head($project)
1423 or die_error(undef, "Open git-rev-list failed");
1424 my @revlist = map { chomp; $_ } <$fd>;
1426 git_header_div('shortlog');
1427 git_shortlog_body(\@revlist, 0, 15, $refs,
1428 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=shortlog")}, "..."));
1430 my $taglist = git_read_refs("refs/tags");
1431 if (defined @$taglist) {
1432 git_header_div('tags');
1433 git_tags_body($taglist, 0, 15,
1434 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tags")}, "..."));
1437 my $headlist = git_read_refs("refs/heads");
1438 if (defined @$headlist) {
1439 git_header_div('heads');
1440 git_heads_body($headlist, $head, 0, 15,
1441 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=heads")}, "..."));
1448 my $head = git_read_head($project);
1450 git_page_nav('','', $head,undef,$head);
1451 my %tag = git_read_tag($hash);
1452 git_header_div('commit', esc_html($tag{'name'}), $hash);
1453 print "<div class=\"title_text\">\n" .
1454 "<table cellspacing=\"0\">\n" .
1456 "<td>object</td>\n" .
1457 "<td>" . $cgi->a({-class => "list", -href => "$my_uri?" . esc_param("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'object'}) . "</td>\n" .
1458 "<td class=\"link\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'type'}) . "</td>\n" .
1460 if (defined($tag{'author'})) {
1461 my %ad = date_str($tag{'epoch'}, $tag{'tz'});
1462 print "<tr><td>author</td><td>" . esc_html($tag{'author'}) . "</td></tr>\n";
1463 print "<tr><td></td><td>" . $ad{'rfc2822'} . sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) . "</td></tr>\n";
1465 print "</table>\n\n" .
1467 print "<div class=\"page_body\">";
1468 my $comment = $tag{'comment'};
1469 foreach my $line (@$comment) {
1470 print esc_html($line) . "<br/>\n";
1479 die_error(undef, "Permission denied") if (!git_get_project_config_bool ('blame'));
1480 die_error('404 Not Found', "File name not defined") if (!$file_name);
1481 $hash_base ||= git_read_head($project);
1482 die_error(undef, "Couldn't find base commit") unless ($hash_base);
1483 my %co = git_read_commit($hash_base)
1484 or die_error(undef, "Reading commit failed");
1485 if (!defined $hash) {
1486 $hash = git_get_hash_by_path($hash_base, $file_name, "blob")
1487 or die_error(undef, "Error looking up file");
1489 $ftype = git_get_type($hash);
1490 if ($ftype !~ "blob") {
1491 die_error("400 Bad Request", "Object is not a blob");
1493 open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base)
1494 or die_error(undef, "Open git-blame failed");
1497 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") .
1498 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;f=$file_name")}, "head");
1499 git_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1500 git_header_div('commit', esc_html($co{'title'}), $hash_base);
1501 git_print_page_path($file_name, $ftype);
1502 my @rev_color = (qw(light dark));
1503 my $num_colors = scalar(@rev_color);
1504 my $current_color = 0;
1506 print "<div class=\"page_body\">\n";
1507 print "<table class=\"blame\">\n";
1508 print "<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n";
1510 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
1512 my $rev = substr($full_rev, 0, 8);
1516 if (!defined $last_rev) {
1517 $last_rev = $full_rev;
1518 } elsif ($last_rev ne $full_rev) {
1519 $last_rev = $full_rev;
1520 $current_color = ++$current_color % $num_colors;
1522 print "<tr class=\"$rev_color[$current_color]\">\n";
1523 print "<td class=\"sha1\">" .
1524 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$full_rev;f=$file_name")}, esc_html($rev)) . "</td>\n";
1525 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" . esc_html($lineno) . "</a></td>\n";
1526 print "<td class=\"pre\">" . esc_html($data) . "</td>\n";
1531 close $fd or print "Reading blob failed\n";
1537 die_error('403 Permission denied', "Permission denied") if (!git_get_project_config_bool ('blame'));
1538 die_error('404 Not Found', "File name not defined") if (!$file_name);
1539 $hash_base ||= git_read_head($project);
1540 die_error(undef, "Couldn't find base commit") unless ($hash_base);
1541 my %co = git_read_commit($hash_base)
1542 or die_error(undef, "Reading commit failed");
1543 if (!defined $hash) {
1544 $hash = git_get_hash_by_path($hash_base, $file_name, "blob")
1545 or die_error(undef, "Error lookup file");
1547 open ($fd, "-|", $GIT, "annotate", '-l', '-t', '-r', $file_name, $hash_base)
1548 or die_error(undef, "Open git-annotate failed");
1551 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") .
1552 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;f=$file_name")}, "head");
1553 git_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1554 git_header_div('commit', esc_html($co{'title'}), $hash_base);
1555 git_print_page_path($file_name, 'blob');
1556 print "<div class=\"page_body\">\n";
1558 <table class="blame">
1567 my @line_class = (qw(light dark));
1568 my $line_class_len = scalar (@line_class);
1569 my $line_class_num = $#line_class;
1570 while (my $line = <$fd>) {
1582 $line_class_num = ($line_class_num + 1) % $line_class_len;
1584 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) \+\d\d\d\d\t(\d+)\)(.*)$/) {
1591 print qq( <tr><td colspan="5" class="error">Unable to parse: $line</td></tr>\n);
1594 $short_rev = substr ($long_rev, 0, 8);
1595 $age = time () - $time;
1596 $age_str = age_string ($age);
1597 $age_str =~ s/ / /g;
1598 $age_class = age_class($age);
1599 $author = esc_html ($author);
1600 $author =~ s/ / /g;
1602 $data = untabify($data);
1603 $data = esc_html ($data);
1606 <tr class="$line_class[$line_class_num]">
1607 <td class="sha1"><a href="$my_uri?${\esc_param ("p=$project;a=commit;h=$long_rev")}" class="text">$short_rev..</a></td>
1608 <td class="$age_class">$age_str</td>
1610 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
1611 <td class="pre">$data</td>
1614 } # while (my $line = <$fd>)
1615 print "</table>\n\n";
1616 close $fd or print "Reading blob failed.\n";
1622 my $head = git_read_head($project);
1624 git_page_nav('','', $head,undef,$head);
1625 git_header_div('summary', $project);
1627 my $taglist = git_read_refs("refs/tags");
1628 if (defined @$taglist) {
1629 git_tags_body($taglist);
1635 my $head = git_read_head($project);
1637 git_page_nav('','', $head,undef,$head);
1638 git_header_div('summary', $project);
1640 my $taglist = git_read_refs("refs/heads");
1642 if (defined @$taglist) {
1643 git_heads_body($taglist, $head);
1648 sub git_blob_plain {
1649 if (!defined $hash) {
1650 if (defined $file_name) {
1651 my $base = $hash_base || git_read_head($project);
1652 $hash = git_get_hash_by_path($base, $file_name, "blob")
1653 or die_error(undef, "Error lookup file");
1655 die_error(undef, "No file name defined");
1659 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
1660 or die_error(undef, "Couldn't cat $file_name, $hash");
1662 $type ||= git_blob_plain_mimetype($fd, $file_name);
1664 # save as filename, even when no $file_name is given
1665 my $save_as = "$hash";
1666 if (defined $file_name) {
1667 $save_as = $file_name;
1668 } elsif ($type =~ m/^text\//) {
1672 print $cgi->header(-type => "$type", '-content-disposition' => "inline; filename=\"$save_as\"");
1674 binmode STDOUT, ':raw';
1676 binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
1682 if (!defined $hash) {
1683 if (defined $file_name) {
1684 my $base = $hash_base || git_read_head($project);
1685 $hash = git_get_hash_by_path($base, $file_name, "blob")
1686 or die_error(undef, "Error lookup file");
1688 die_error(undef, "No file name defined");
1691 my $have_blame = git_get_project_config_bool ('blame');
1692 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
1693 or die_error(undef, "Couldn't cat $file_name, $hash");
1694 my $mimetype = git_blob_plain_mimetype($fd, $file_name);
1695 if ($mimetype !~ m/^text\//) {
1697 return git_blob_plain($mimetype);
1700 my $formats_nav = '';
1701 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
1702 if (defined $file_name) {
1704 $formats_nav .= $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$hash;hb=$hash_base;f=$file_name")}, "blame") . " | ";
1707 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$hash;f=$file_name")}, "plain") .
1708 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;hb=HEAD;f=$file_name")}, "head");
1710 $formats_nav .= $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$hash")}, "plain");
1712 git_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1713 git_header_div('commit', esc_html($co{'title'}), $hash_base);
1715 print "<div class=\"page_nav\">\n" .
1716 "<br/><br/></div>\n" .
1717 "<div class=\"title\">$hash</div>\n";
1719 git_print_page_path($file_name, "blob");
1720 print "<div class=\"page_body\">\n";
1722 while (my $line = <$fd>) {
1725 $line = untabify($line);
1726 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", $nr, $nr, $nr, esc_html($line);
1728 close $fd or print "Reading blob failed.\n";
1734 if (!defined $hash) {
1735 $hash = git_read_head($project);
1736 if (defined $file_name) {
1737 my $base = $hash_base || $hash;
1738 $hash = git_get_hash_by_path($base, $file_name, "tree");
1740 if (!defined $hash_base) {
1745 open my $fd, "-|", $GIT, "ls-tree", '-z', $hash
1746 or die_error(undef, "Open git-ls-tree failed");
1747 my @entries = map { chomp; $_ } <$fd>;
1748 close $fd or die_error(undef, "Reading tree failed");
1751 my $refs = read_info_ref();
1752 my $ref = git_get_referencing($refs, $hash_base);
1756 my $have_blame = git_get_project_config_bool ('blame');
1757 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
1758 $base_key = ";hb=$hash_base";
1759 git_page_nav('tree','', $hash_base);
1760 git_header_div('commit', esc_html($co{'title'}) . $ref, $hash_base);
1762 print "<div class=\"page_nav\">\n";
1763 print "<br/><br/></div>\n";
1764 print "<div class=\"title\">$hash</div>\n";
1766 if (defined $file_name) {
1767 $base = esc_html("$file_name/");
1769 git_print_page_path($file_name, 'tree');
1770 print "<div class=\"page_body\">\n";
1771 print "<table cellspacing=\"0\">\n";
1773 foreach my $line (@entries) {
1774 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1775 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1779 my $t_name = validate_input($4);
1781 print "<tr class=\"dark\">\n";
1783 print "<tr class=\"light\">\n";
1786 print "<td class=\"mode\">" . mode_str($t_mode) . "</td>\n";
1787 if ($t_type eq "blob") {
1788 print "<td class=\"list\">" .
1789 $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)) .
1791 "<td class=\"link\">" .
1792 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name")}, "blob");
1794 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;h=$t_hash$base_key;f=$base$t_name")}, "blame");
1796 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;h=$t_hash;hb=$hash_base;f=$base$t_name")}, "history") .
1797 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob_plain;h=$t_hash;f=$base$t_name")}, "raw") .
1799 } elsif ($t_type eq "tree") {
1800 print "<td class=\"list\">" .
1801 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, esc_html($t_name)) .
1803 "<td class=\"link\">" .
1804 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, "tree") .
1805 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;hb=$hash_base;f=$base$t_name")}, "history") .
1810 print "</table>\n" .
1816 my $head = git_read_head($project);
1817 if (!defined $hash) {
1820 if (!defined $page) {
1823 my $refs = read_info_ref();
1825 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
1826 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
1827 or die_error(undef, "Open git-rev-list failed");
1828 my @revlist = map { chomp; $_ } <$fd>;
1831 my $paging_nav = git_get_paging_nav('log', $hash, $head, $page, $#revlist);
1834 git_page_nav('log','', $hash,undef,undef, $paging_nav);
1837 my %co = git_read_commit($hash);
1839 git_header_div('summary', $project);
1840 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
1842 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
1843 my $commit = $revlist[$i];
1844 my $ref = git_get_referencing($refs, $commit);
1845 my %co = git_read_commit($commit);
1847 my %ad = date_str($co{'author_epoch'});
1848 git_header_div('commit',
1849 "<span class=\"age\">$co{'age_string'}</span>" .
1850 esc_html($co{'title'}) . $ref,
1852 print "<div class=\"title_text\">\n" .
1853 "<div class=\"log_link\">\n" .
1854 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$commit")}, "commit") .
1855 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1858 "<i>" . esc_html($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
1860 "<div class=\"log_body\">\n";
1861 my $comment = $co{'comment'};
1863 foreach my $line (@$comment) {
1864 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1875 print format_log_line_html($line) . "<br/>\n";
1886 my %co = git_read_commit($hash);
1888 die_error(undef, "Unknown commit object");
1890 my %ad = date_str($co{'author_epoch'}, $co{'author_tz'});
1891 my %cd = date_str($co{'committer_epoch'}, $co{'committer_tz'});
1893 my $parent = $co{'parent'};
1894 if (!defined $parent) {
1897 open my $fd, "-|", $GIT, "diff-tree", '-r', '-M', $parent, $hash
1898 or die_error(undef, "Open git-diff-tree failed");
1899 my @difftree = map { chomp; $_ } <$fd>;
1900 close $fd or die_error(undef, "Reading git-diff-tree failed");
1902 # non-textual hash id's can be cached
1904 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
1907 my $refs = read_info_ref();
1908 my $ref = git_get_referencing($refs, $co{'id'});
1909 my $formats_nav = '';
1910 if (defined $file_name && defined $co{'parent'}) {
1911 my $parent = $co{'parent'};
1912 $formats_nav .= $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;hb=$parent;f=$file_name")}, "blame");
1914 git_header_html(undef, $expires);
1915 git_page_nav('commit', defined $co{'parent'} ? '' : 'commitdiff',
1916 $hash, $co{'tree'}, $hash,
1919 if (defined $co{'parent'}) {
1920 git_header_div('commitdiff', esc_html($co{'title'}) . $ref, $hash);
1922 git_header_div('tree', esc_html($co{'title'}) . $ref, $co{'tree'}, $hash);
1924 print "<div class=\"title_text\">\n" .
1925 "<table cellspacing=\"0\">\n";
1926 print "<tr><td>author</td><td>" . esc_html($co{'author'}) . "</td></tr>\n".
1928 "<td></td><td> $ad{'rfc2822'}";
1929 if ($ad{'hour_local'} < 6) {
1930 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1932 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1936 print "<tr><td>committer</td><td>" . esc_html($co{'committer'}) . "</td></tr>\n";
1937 print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
1938 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
1941 "<td class=\"sha1\">" .
1942 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash"), class => "list"}, $co{'tree'}) .
1944 "<td class=\"link\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
1947 my $parents = $co{'parents'};
1948 foreach my $par (@$parents) {
1951 "<td class=\"sha1\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$par"), class => "list"}, $par) . "</td>" .
1952 "<td class=\"link\">" .
1953 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commit;h=$par")}, "commit") .
1954 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff;h=$hash;hp=$par")}, "commitdiff") .
1960 print "<div class=\"page_body\">\n";
1961 my $comment = $co{'comment'};
1964 foreach my $line (@$comment) {
1965 # print only one empty line
1967 if ($empty || $signed) {
1974 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1976 print "<span class=\"signoff\">" . esc_html($line) . "</span><br/>\n";
1979 print format_log_line_html($line) . "<br/>\n";
1983 print "<div class=\"list_head\">\n";
1984 if ($#difftree > 10) {
1985 print(($#difftree + 1) . " files changed:\n");
1988 print "<table class=\"diff_tree\">\n";
1990 foreach my $line (@difftree) {
1991 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1992 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1993 if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
2001 my $similarity = $6;
2002 my $file = validate_input(unquote($7));
2004 print "<tr class=\"dark\">\n";
2006 print "<tr class=\"light\">\n";
2009 if ($status eq "A") {
2011 if (S_ISREG(oct $to_mode)) {
2012 $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
2015 $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" .
2016 "<td><span class=\"file_status new\">[new " . file_type($to_mode) . "$mode_chng]</span></td>\n" .
2017 "<td class=\"link\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob") . "</td>\n";
2018 } elsif ($status eq "D") {
2020 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$hash;f=$file"), -class => "list"}, esc_html($file)) . "</td>\n" .
2021 "<td><span class=\"file_status deleted\">[deleted " . file_type($from_mode). "]</span></td>\n" .
2022 "<td class=\"link\">" .
2023 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, "blob") .
2024 " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;hb=$hash;f=$file")}, "history") .
2026 } elsif ($status eq "M" || $status eq "T") {
2027 my $mode_chnge = "";
2028 if ($from_mode != $to_mode) {
2029 $mode_chnge = " <span class=\"file_status mode_chnge\">[changed";
2030 if (((oct $from_mode) & S_IFMT) != ((oct $to_mode) & S_IFMT)) {
2031 $mode_chnge .= " from " . file_type($from_mode) . " to " . file_type($to_mode);
2033 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
2034 if (S_ISREG($from_mode) && S_ISREG($to_mode)) {
2035 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
2036 } elsif (S_ISREG($to_mode)) {
2037 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
2040 $mode_chnge .= "]</span>\n";
2043 if ($to_id ne $from_id) {
2044 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));
2046 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file"), -class => "list"}, esc_html($file));
2049 "<td>$mode_chnge</td>\n" .
2050 "<td class=\"link\">";
2051 print $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob");
2052 if ($to_id ne $from_id) {
2053 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file")}, "diff");
2055 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=history;hb=$hash;f=$file")}, "history") . "\n";
2057 } elsif ($status eq "R") {
2058 my ($from_file, $to_file) = split "\t", $file;
2060 if ($from_mode != $to_mode) {
2061 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
2064 $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" .
2065 "<td><span class=\"file_status moved\">[moved from " .
2066 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$hash;f=$from_file"), -class => "list"}, esc_html($from_file)) .
2067 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
2068 "<td class=\"link\">" .
2069 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file")}, "blob");
2070 if ($to_id ne $from_id) {
2071 print " | " . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file")}, "diff");
2082 mkdir($git_temp, 0700);
2084 if (defined $hash_base && (my %co = git_read_commit($hash_base))) {
2086 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blobdiff_plain;h=$hash;hp=$hash_parent")}, "plain");
2087 git_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2088 git_header_div('commit', esc_html($co{'title'}), $hash_base);
2090 print "<div class=\"page_nav\">\n" .
2091 "<br/><br/></div>\n" .
2092 "<div class=\"title\">$hash vs $hash_parent</div>\n";
2094 git_print_page_path($file_name, "blob");
2095 print "<div class=\"page_body\">\n" .
2096 "<div class=\"diff_info\">blob:" .
2097 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name")}, $hash_parent) .
2099 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, $hash) .
2101 git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
2106 sub git_blobdiff_plain {
2107 mkdir($git_temp, 0700);
2108 print $cgi->header(-type => "text/plain", -charset => 'utf-8');
2109 git_diff_print($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
2112 sub git_commitdiff {
2113 mkdir($git_temp, 0700);
2114 my %co = git_read_commit($hash);
2116 die_error(undef, "Unknown commit object");
2118 if (!defined $hash_parent) {
2119 $hash_parent = $co{'parent'} || '--root';
2121 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2122 or die_error(undef, "Open git-diff-tree failed");
2123 my @difftree = map { chomp; $_ } <$fd>;
2124 close $fd or die_error(undef, "Reading git-diff-tree failed");
2126 # non-textual hash id's can be cached
2128 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2131 my $refs = read_info_ref();
2132 my $ref = git_get_referencing($refs, $co{'id'});
2134 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent")}, "plain");
2135 git_header_html(undef, $expires);
2136 git_page_nav('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
2137 git_header_div('commit', esc_html($co{'title'}) . $ref, $hash);
2138 print "<div class=\"page_body\">\n";
2139 my $comment = $co{'comment'};
2142 my @log = @$comment;
2143 # remove first and empty lines after that
2145 while (defined $log[0] && $log[0] eq "") {
2148 foreach my $line (@log) {
2149 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2160 print format_log_line_html($line) . "<br/>\n";
2163 foreach my $line (@difftree) {
2164 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2165 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2166 if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2174 my $file = validate_input(unquote($6));
2175 if ($status eq "A") {
2176 print "<div class=\"diff_info\">" . file_type($to_mode) . ":" .
2177 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id) . "(new)" .
2179 git_diff_print(undef, "/dev/null", $to_id, "b/$file");
2180 } elsif ($status eq "D") {
2181 print "<div class=\"diff_info\">" . file_type($from_mode) . ":" .
2182 $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) . "(deleted)" .
2184 git_diff_print($from_id, "a/$file", undef, "/dev/null");
2185 } elsif ($status eq "M") {
2186 if ($from_id ne $to_id) {
2187 print "<div class=\"diff_info\">" .
2188 file_type($from_mode) . ":" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blob;h=$from_id;hb=$hash;f=$file")}, $from_id) .
2190 file_type($to_mode) . ":" . $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".