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 # string of the home link on top of all pages
40 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
42 # name of your site or organization to appear in page titles
43 # replace this with something more descriptive for clearer bookmarks
44 our $site_name = "++GITWEB_SITENAME++" || $ENV{'SERVER_NAME'} || "Untitled";
46 # html text to include at home page
47 our $home_text = "++GITWEB_HOMETEXT++";
49 # URI of default stylesheet
50 our $stylesheet = "++GITWEB_CSS++";
52 our $logo = "++GITWEB_LOGO++";
54 # source of projects list
55 our $projects_list = "++GITWEB_LIST++";
57 # list of git base URLs used for URL to where fetch project from,
58 # i.e. full URL is "$git_base_url/$project"
59 our @git_base_url_list = ("++GITWEB_BASE_URL++");
61 # default blob_plain mimetype and default charset for text/plain blob
62 our $default_blob_plain_mimetype = 'text/plain';
63 our $default_text_plain_charset = undef;
65 # file to use for guessing MIME types before trying /etc/mime.types
66 # (relative to the current git repository)
67 our $mimetypes_file = undef;
69 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
70 require $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
72 # version of the core git binary
73 our $git_version = qx($GIT --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
75 $projects_list ||= $projectroot;
77 mkdir($git_temp, 0700) || die_error
(undef, "Couldn't mkdir $git_temp");
80 # ======================================================================
81 # input validation and dispatch
82 our $action = $cgi->param('a');
83 if (defined $action) {
84 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
85 die_error
(undef, "Invalid action parameter");
87 # action which does not check rest of parameters
88 if ($action eq "opml") {
94 our $project = ($cgi->param('p') || $ENV{'PATH_INFO'});
95 if (defined $project) {
99 if (defined $project && $project) {
100 if (!validate_input
($project)) {
101 die_error
(undef, "Invalid project parameter");
103 if (!(-d
"$projectroot/$project")) {
104 die_error
(undef, "No such directory");
106 if (!(-e
"$projectroot/$project/HEAD")) {
107 die_error
(undef, "No such project");
109 $ENV{'GIT_DIR'} = "$projectroot/$project";
115 our $file_name = $cgi->param('f');
116 if (defined $file_name) {
117 if (!validate_input
($file_name)) {
118 die_error
(undef, "Invalid file parameter");
122 our $hash = $cgi->param('h');
124 if (!validate_input
($hash)) {
125 die_error
(undef, "Invalid hash parameter");
129 our $hash_parent = $cgi->param('hp');
130 if (defined $hash_parent) {
131 if (!validate_input
($hash_parent)) {
132 die_error
(undef, "Invalid hash parent parameter");
136 our $hash_base = $cgi->param('hb');
137 if (defined $hash_base) {
138 if (!validate_input
($hash_base)) {
139 die_error
(undef, "Invalid hash base parameter");
143 our $page = $cgi->param('pg');
145 if ($page =~ m/[^0-9]$/) {
146 die_error
(undef, "Invalid page parameter");
150 our $searchtext = $cgi->param('s');
151 if (defined $searchtext) {
152 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
153 die_error
(undef, "Invalid search parameter");
155 $searchtext = quotemeta $searchtext;
160 "blame" => \
&git_blame2
,
161 "blobdiff" => \
&git_blobdiff
,
162 "blobdiff_plain" => \
&git_blobdiff_plain
,
163 "blob" => \
&git_blob
,
164 "blob_plain" => \
&git_blob_plain
,
165 "commitdiff" => \
&git_commitdiff
,
166 "commitdiff_plain" => \
&git_commitdiff_plain
,
167 "commit" => \
&git_commit
,
168 "heads" => \
&git_heads
,
169 "history" => \
&git_history
,
172 "search" => \
&git_search
,
173 "shortlog" => \
&git_shortlog
,
174 "summary" => \
&git_summary
,
176 "tags" => \
&git_tags
,
177 "tree" => \
&git_tree
,
180 $action = 'summary' if (!defined($action));
181 if (!defined($actions{$action})) {
182 die_error
(undef, "Unknown action");
184 $actions{$action}->();
187 ## ======================================================================
203 $params{"project"} ||= $project;
205 my $href = "$my_uri?";
206 $href .= esc_param
( join(";",
208 "$mapping{$_}=$params{$_}" if defined $params{$_}
216 ## ======================================================================
217 ## validation, quoting/unquoting and escaping
222 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
225 if ($input =~ m/(^|\/)(|\
.|\
.\
.)($|\
/)/) {
228 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\
-\
+\#\
~\
%]/) {
234 # quote unsafe chars, but keep the slash, even when it's not
235 # correct, but quoted slashes look too horrible in bookmarks
238 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
244 # replace invalid utf8 character with SUBSTITUTION sequence
247 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
248 $str = escapeHTML
($str);
249 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
253 # git may return quoted and escaped filenames
256 if ($str =~ m/^"(.*)"$/) {
258 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
263 # escape tabs (convert tabs to spaces)
267 while ((my $pos = index($line, "\t")) != -1) {
268 if (my $count = (8 - ($pos % 8))) {
269 my $spaces = ' ' x
$count;
270 $line =~ s/\t/$spaces/;
277 ## ----------------------------------------------------------------------
278 ## HTML aware string manipulation
283 my $add_len = shift || 10;
285 # allow only $len chars, but don't cut a word if it would fit in $add_len
286 # if it doesn't fit, cut it if it's still longer than the dots we would add
287 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
290 if (length($tail) > 4) {
292 $body =~ s/&[^;]*$//; # remove chopped character entities
297 ## ----------------------------------------------------------------------
298 ## functions returning short strings
300 # CSS class for given age value (in seconds)
304 if ($age < 60*60*2) {
306 } elsif ($age < 60*60*24*2) {
313 # convert age in seconds to "nn units ago" string
318 if ($age > 60*60*24*365*2) {
319 $age_str = (int $age/60/60/24/365);
320 $age_str .= " years ago";
321 } elsif ($age > 60*60*24*(365/12)*2) {
322 $age_str = int $age/60/60/24/(365/12);
323 $age_str .= " months ago";
324 } elsif ($age > 60*60*24*7*2) {
325 $age_str = int $age/60/60/24/7;
326 $age_str .= " weeks ago";
327 } elsif ($age > 60*60*24*2) {
328 $age_str = int $age/60/60/24;
329 $age_str .= " days ago";
330 } elsif ($age > 60*60*2) {
331 $age_str = int $age/60/60;
332 $age_str .= " hours ago";
333 } elsif ($age > 60*2) {
334 $age_str = int $age/60;
335 $age_str .= " min ago";
338 $age_str .= " sec ago";
340 $age_str .= " right now";
345 # convert file mode in octal to symbolic file mode string
347 my $mode = oct shift;
349 if (S_ISDIR
($mode & S_IFMT
)) {
351 } elsif (S_ISLNK
($mode)) {
353 } elsif (S_ISREG
($mode)) {
354 # git cares only about the executable bit
355 if ($mode & S_IXUSR
) {
365 # convert file mode in octal to file type string
367 my $mode = oct shift;
369 if (S_ISDIR
($mode & S_IFMT
)) {
371 } elsif (S_ISLNK
($mode)) {
373 } elsif (S_ISREG
($mode)) {
380 ## ----------------------------------------------------------------------
381 ## functions returning short HTML fragments, or transforming HTML fragments
382 ## which don't beling to other sections
384 # format line of commit message or tag comment
385 sub format_log_line_html
{
388 $line = esc_html
($line);
389 $line =~ s/ / /g;
390 if ($line =~ m/([0-9a-fA-F]{40})/) {
392 if (git_get_type
($hash_text) eq "commit") {
393 my $link = $cgi->a({-class => "text", -href
=> href
(action
=>"commit", hash
=>$hash_text)}, $hash_text);
394 $line =~ s/$hash_text/$link/;
400 # format marker of refs pointing to given object
401 sub format_ref_marker
{
402 my ($refs, $id) = @_;
405 if (defined $refs->{$id}) {
406 foreach my $ref (@
{$refs->{$id}}) {
407 my ($type, $name) = qw();
408 # e.g. tags/v2.6.11 or heads/next
409 if ($ref =~ m!^(.*?)s?/(.*)$!) {
417 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
422 return ' <span class="refs">'. $markers . '</span>';
428 # format, perhaps shortened and with markers, title line
429 sub format_subject_html
{
430 my ($long, $short, $href, $extra) = @_;
431 $extra = '' unless defined($extra);
433 if (length($short) < length($long)) {
434 return $cgi->a({-href
=> $href, -class => "list",
436 esc_html
($short) . $extra);
438 return $cgi->a({-href
=> $href, -class => "list"},
439 esc_html
($long) . $extra);
443 ## ----------------------------------------------------------------------
444 ## git utility subroutines, invoking git commands
446 # get HEAD ref of given project as hash
447 sub git_get_head_hash
{
449 my $oENV = $ENV{'GIT_DIR'};
451 $ENV{'GIT_DIR'} = "$projectroot/$project";
452 if (open my $fd, "-|", $GIT, "rev-parse", "--verify", "HEAD") {
455 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
460 $ENV{'GIT_DIR'} = $oENV;
465 # get type of given object
469 open my $fd, "-|", $GIT, "cat-file", '-t', $hash or return;
476 sub git_get_project_config
{
479 return unless ($key);
480 $key =~ s/^gitweb\.//;
481 return if ($key =~ m/\W/);
483 my $val = qx($GIT repo
-config
--get gitweb
.$key);
487 sub git_get_project_config_bool
{
488 my $val = git_get_project_config
(@_);
489 if ($val and $val =~ m/true|yes|on/) {
492 return; # implicit false
495 # get hash of given path at given ref
496 sub git_get_hash_by_path
{
498 my $path = shift || return undef;
502 open my $fd, "-|", $GIT, "ls-tree", $base, "--", $path
503 or die_error
(undef, "Open git-ls-tree failed");
505 close $fd or return undef;
507 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
508 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
512 ## ......................................................................
513 ## git utility functions, directly accessing git repository
515 # assumes that PATH is not symref
516 sub git_get_hash_by_ref
{
519 open my $fd, "$projectroot/$path" or return undef;
523 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
528 sub git_get_project_description
{
531 open my $fd, "$projectroot/$path/description" or return undef;
538 sub git_get_project_url_list
{
541 open my $fd, "$projectroot/$path/cloneurl" or return undef;
542 my @git_project_url_list = map { chomp; $_ } <$fd>;
545 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
548 sub git_get_projects_list
{
551 if (-d
$projects_list) {
552 # search in directory
553 my $dir = $projects_list;
554 opendir my ($dh), $dir or return undef;
555 while (my $dir = readdir($dh)) {
556 if (-e
"$projectroot/$dir/HEAD") {
564 } elsif (-f
$projects_list) {
565 # read from file(url-encoded):
566 # 'git%2Fgit.git Linus+Torvalds'
567 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
568 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
569 open my ($fd), $projects_list or return undef;
570 while (my $line = <$fd>) {
572 my ($path, $owner) = split ' ', $line;
573 $path = unescape
($path);
574 $owner = unescape
($owner);
575 if (!defined $path) {
578 if (-e
"$projectroot/$path/HEAD") {
581 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
588 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
592 sub git_get_project_owner
{
596 return undef unless $project;
598 # read from file (url-encoded):
599 # 'git%2Fgit.git Linus+Torvalds'
600 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
601 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
602 if (-f
$projects_list) {
603 open (my $fd , $projects_list);
604 while (my $line = <$fd>) {
606 my ($pr, $ow) = split ' ', $line;
609 if ($pr eq $project) {
610 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
616 if (!defined $owner) {
617 $owner = get_file_owner
("$projectroot/$project");
623 sub git_get_references
{
624 my $type = shift || "";
627 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
628 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
629 if (-f
"$projectroot/$project/info/refs") {
630 open $fd, "$projectroot/$project/info/refs"
633 open $fd, "-|", $GIT, "ls-remote", "."
637 while (my $line = <$fd>) {
639 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?[^\^]+)/) {
640 if (defined $refs{$1}) {
641 push @
{$refs{$1}}, $2;
651 ## ----------------------------------------------------------------------
652 ## parse to hash functions
656 my $tz = shift || "-0000";
659 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
660 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
661 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
662 $date{'hour'} = $hour;
663 $date{'minute'} = $min;
664 $date{'mday'} = $mday;
665 $date{'day'} = $days[$wday];
666 $date{'month'} = $months[$mon];
667 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
668 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
670 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
671 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
672 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
673 $date{'hour_local'} = $hour;
674 $date{'minute_local'} = $min;
675 $date{'tz_local'} = $tz;
684 open my $fd, "-|", $GIT, "cat-file", "tag", $tag_id or return;
685 $tag{'id'} = $tag_id;
686 while (my $line = <$fd>) {
688 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
690 } elsif ($line =~ m/^type (.+)$/) {
692 } elsif ($line =~ m/^tag (.+)$/) {
694 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
698 } elsif ($line =~ m/--BEGIN/) {
699 push @comment, $line;
701 } elsif ($line eq "") {
705 push @comment, <$fd>;
706 $tag{'comment'} = \
@comment;
708 if (!defined $tag{'name'}) {
715 my $commit_id = shift;
716 my $commit_text = shift;
721 if (defined $commit_text) {
722 @commit_lines = @
$commit_text;
725 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", "--max-count=1", $commit_id or return;
726 @commit_lines = split '\n', <$fd>;
731 my $header = shift @commit_lines;
732 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
735 ($co{'id'}, my @parents) = split ' ', $header;
736 $co{'parents'} = \
@parents;
737 $co{'parent'} = $parents[0];
738 while (my $line = shift @commit_lines) {
739 last if $line eq "\n";
740 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
742 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
744 $co{'author_epoch'} = $2;
745 $co{'author_tz'} = $3;
746 if ($co{'author'} =~ m/^([^<]+) </) {
747 $co{'author_name'} = $1;
749 $co{'author_name'} = $co{'author'};
751 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
752 $co{'committer'} = $1;
753 $co{'committer_epoch'} = $2;
754 $co{'committer_tz'} = $3;
755 $co{'committer_name'} = $co{'committer'};
756 $co{'committer_name'} =~ s/ <.*//;
759 if (!defined $co{'tree'}) {
763 foreach my $title (@commit_lines) {
766 $co{'title'} = chop_str
($title, 80, 5);
767 # remove leading stuff of merges to make the interesting part visible
768 if (length($title) > 50) {
769 $title =~ s/^Automatic //;
770 $title =~ s/^merge (of|with) /Merge ... /i;
771 if (length($title) > 50) {
772 $title =~ s/(http|rsync):\/\///;
774 if (length($title) > 50) {
775 $title =~ s/(master|www|rsync)\.//;
777 if (length($title) > 50) {
778 $title =~ s/kernel.org:?//;
780 if (length($title) > 50) {
781 $title =~ s/\/pub\/scm//;
784 $co{'title_short'} = chop_str
($title, 50, 5);
788 # remove added spaces
789 foreach my $line (@commit_lines) {
792 $co{'comment'} = \
@commit_lines;
794 my $age = time - $co{'committer_epoch'};
796 $co{'age_string'} = age_string
($age);
797 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
798 if ($age > 60*60*24*7*2) {
799 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
800 $co{'age_string_age'} = $co{'age_string'};
802 $co{'age_string_date'} = $co{'age_string'};
803 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
808 # parse ref from ref_file, given by ref_id, with given type
810 my $ref_file = shift;
812 my $type = shift || git_get_type
($ref_id);
815 $ref_item{'type'} = $type;
816 $ref_item{'id'} = $ref_id;
817 $ref_item{'epoch'} = 0;
818 $ref_item{'age'} = "unknown";
819 if ($type eq "tag") {
820 my %tag = parse_tag
($ref_id);
821 $ref_item{'comment'} = $tag{'comment'};
822 if ($tag{'type'} eq "commit") {
823 my %co = parse_commit
($tag{'object'});
824 $ref_item{'epoch'} = $co{'committer_epoch'};
825 $ref_item{'age'} = $co{'age_string'};
826 } elsif (defined($tag{'epoch'})) {
827 my $age = time - $tag{'epoch'};
828 $ref_item{'epoch'} = $tag{'epoch'};
829 $ref_item{'age'} = age_string
($age);
831 $ref_item{'reftype'} = $tag{'type'};
832 $ref_item{'name'} = $tag{'name'};
833 $ref_item{'refid'} = $tag{'object'};
834 } elsif ($type eq "commit"){
835 my %co = parse_commit
($ref_id);
836 $ref_item{'reftype'} = "commit";
837 $ref_item{'name'} = $ref_file;
838 $ref_item{'title'} = $co{'title'};
839 $ref_item{'refid'} = $ref_id;
840 $ref_item{'epoch'} = $co{'committer_epoch'};
841 $ref_item{'age'} = $co{'age_string'};
843 $ref_item{'reftype'} = $type;
844 $ref_item{'name'} = $ref_file;
845 $ref_item{'refid'} = $ref_id;
851 ## ......................................................................
852 ## parse to array of hashes functions
854 sub git_get_refs_list
{
859 my $pfxlen = length("$projectroot/$project/$ref_dir");
860 File
::Find
::find
(sub {
863 push @refs, substr($File::Find
::name
, $pfxlen + 1);
865 }, "$projectroot/$project/$ref_dir");
867 foreach my $ref_file (@refs) {
868 my $ref_id = git_get_hash_by_ref
("$project/$ref_dir/$ref_file");
869 my $type = git_get_type
($ref_id) || next;
870 my %ref_item = parse_ref
($ref_file, $ref_id, $type);
872 push @reflist, \
%ref_item;
875 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
879 ## ----------------------------------------------------------------------
880 ## filesystem-related functions
885 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
886 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
887 if (!defined $gcos) {
891 $owner =~ s/[,;].*$//;
892 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
895 ## ......................................................................
896 ## mimetype related functions
898 sub mimetype_guess_file
{
899 my $filename = shift;
901 -r
$mimemap or return undef;
904 open(MIME
, $mimemap) or return undef;
906 next if m/^#/; # skip comments
907 my ($mime, $exts) = split(/\t+/);
909 my @exts = split(/\s+/, $exts);
910 foreach my $ext (@exts) {
911 $mimemap{$ext} = $mime;
917 $filename =~ /\.(.*?)$/;
922 my $filename = shift;
924 $filename =~ /\./ or return undef;
926 if ($mimetypes_file) {
927 my $file = $mimetypes_file;
928 if ($file !~ m!^/!) { # if it is relative path
929 # it is relative to project
930 $file = "$projectroot/$project/$file";
932 $mime = mimetype_guess_file
($filename, $file);
934 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
940 my $filename = shift;
943 my $mime = mimetype_guess
($filename);
944 $mime and return $mime;
948 return $default_blob_plain_mimetype unless $fd;
951 return 'text/plain' .
952 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
953 } elsif (! $filename) {
954 return 'application/octet-stream';
955 } elsif ($filename =~ m/\.png$/i) {
957 } elsif ($filename =~ m/\.gif$/i) {
959 } elsif ($filename =~ m/\.jpe?g$/i) {
962 return 'application/octet-stream';
966 ## ======================================================================
967 ## functions printing HTML: header, footer, error page
969 sub git_header_html
{
970 my $status = shift || "200 OK";
973 my $title = "$site_name git";
974 if (defined $project) {
975 $title .= " - $project";
976 if (defined $action) {
977 $title .= "/$action";
978 if (defined $file_name) {
979 $title .= " - $file_name";
980 if ($action eq "tree" && $file_name !~ m
|/$|) {
987 # require explicit support from the UA if we are to send the page as
988 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
989 # we have to do this because MSIE sometimes globs '*/*', pretending to
990 # support xhtml+xml but choking when it gets what it asked for.
991 if (defined $cgi->http('HTTP_ACCEPT') && $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ && $cgi->Accept('application/xhtml
+xml
') != 0) {
992 $content_type = 'application
/xhtml
+xml
';
994 $content_type = 'text
/html
';
996 print $cgi->header(-type=>$content_type, -charset => 'utf
-8', -status=> $status, -expires => $expires);
998 <?xml version="1.0" encoding="utf-8"?>
999 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1000 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1001 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1002 <!-- git core binaries version $git_version -->
1004 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1005 <meta name="generator" content="gitweb/$version git/$git_version"/>
1006 <meta name="robots" content="index, nofollow"/>
1007 <title>$title</title>
1008 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
1010 if (defined $project) {
1011 printf('<link rel="alternate" title="%s log" '.
1012 'href="%s" type="application/rss+xml"/>'."\n",
1013 esc_param
($project), href
(action
=>"rss"));
1018 "<div class=\"page_header\">\n" .
1019 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
1020 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
1022 print $cgi->a({-href
=> esc_param
($home_link)}, $home_link_str) . " / ";
1023 if (defined $project) {
1024 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1025 if (defined $action) {
1029 if (!defined $searchtext) {
1033 if (defined $hash_base) {
1034 $search_hash = $hash_base;
1035 } elsif (defined $hash) {
1036 $search_hash = $hash;
1038 $search_hash = "HEAD";
1040 $cgi->param("a", "search");
1041 $cgi->param("h", $search_hash);
1042 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
1043 "<div class=\"search\">\n" .
1044 $cgi->hidden(-name
=> "p") . "\n" .
1045 $cgi->hidden(-name
=> "a") . "\n" .
1046 $cgi->hidden(-name
=> "h") . "\n" .
1047 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1049 $cgi->end_form() . "\n";
1054 sub git_footer_html
{
1055 print "<div class=\"page_footer\">\n";
1056 if (defined $project) {
1057 my $descr = git_get_project_description
($project);
1058 if (defined $descr) {
1059 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1061 print $cgi->a({-href
=> href
(action
=>"rss"), -class => "rss_logo"}, "RSS") . "\n";
1063 print $cgi->a({-href
=> href
(action
=>"opml"), -class => "rss_logo"}, "OPML") . "\n";
1071 my $status = shift || "403 Forbidden";
1072 my $error = shift || "Malformed query, file missing or permission denied";
1074 git_header_html
($status);
1075 print "<div class=\"page_body\">\n" .
1077 "$status - $error\n" .
1084 ## ----------------------------------------------------------------------
1085 ## functions printing or outputting HTML: navigation
1087 sub git_print_page_nav
{
1088 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1089 $extra = '' if !defined $extra; # pager or formats
1091 my @navs = qw(summary shortlog log commit commitdiff tree);
1093 @navs = grep { $_ ne $suppress } @navs;
1096 my %arg = map { $_ => {action
=>$_} } @navs;
1097 if (defined $head) {
1098 for (qw(commit commitdiff)) {
1099 $arg{$_}{hash
} = $head;
1101 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1102 for (qw(shortlog log)) {
1103 $arg{$_}{hash
} = $head;
1107 $arg{tree
}{hash
} = $treehead if defined $treehead;
1108 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1110 print "<div class=\"page_nav\">\n" .
1112 map { $_ eq $current ?
1113 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1115 print "<br/>\n$extra<br/>\n" .
1119 sub format_paging_nav
{
1120 my ($action, $hash, $head, $page, $nrevs) = @_;
1124 if ($hash ne $head || $page) {
1125 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1127 $paging_nav .= "HEAD";
1131 $paging_nav .= " ⋅ " .
1132 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1133 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1135 $paging_nav .= " ⋅ prev";
1138 if ($nrevs >= (100 * ($page+1)-1)) {
1139 $paging_nav .= " ⋅ " .
1140 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1141 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1143 $paging_nav .= " ⋅ next";
1149 ## ......................................................................
1150 ## functions printing or outputting HTML: div
1152 sub git_print_header_div
{
1153 my ($action, $title, $hash, $hash_base) = @_;
1156 $args{action
} = $action;
1157 $args{hash
} = $hash if $hash;
1158 $args{hash_base
} = $hash_base if $hash_base;
1160 print "<div class=\"header\">\n" .
1161 $cgi->a({-href
=> href
(%args), -class => "title"},
1162 $title ?
$title : $action) .
1166 sub git_print_page_path
{
1170 if (!defined $name) {
1171 print "<div class=\"page_path\"><b>/</b></div>\n";
1172 } elsif (defined $type && $type eq 'blob') {
1173 print "<div class=\"page_path\"><b>" .
1174 $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name)}, esc_html
($name)) . "</b><br/></div>\n";
1176 print "<div class=\"page_path\"><b>" . esc_html
($name) . "</b><br/></div>\n";
1180 ## ......................................................................
1181 ## functions printing large fragments of HTML
1183 sub git_difftree_body
{
1184 my ($difftree, $parent) = @_;
1186 print "<div class=\"list_head\">\n";
1187 if ($#{$difftree} > 10) {
1188 print(($#{$difftree} + 1) . " files changed:\n");
1192 print "<table class=\"diff_tree\">\n";
1194 foreach my $line (@
{$difftree}) {
1195 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1196 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1197 if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1205 my $similarity = $6; # score
1206 my $file = validate_input
(unquote
($7));
1209 print "<tr class=\"dark\">\n";
1211 print "<tr class=\"light\">\n";
1215 if ($status eq "A") { # created
1217 if (S_ISREG
(oct $to_mode)) {
1218 $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
1221 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$file),
1222 -class => "list"}, esc_html
($file)) .
1224 "<td><span class=\"file_status new\">[new " . file_type
($to_mode) . "$mode_chng]</span></td>\n" .
1225 "<td class=\"link\">" .
1226 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$file)}, "blob") .
1229 } elsif ($status eq "D") { # deleted
1231 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$from_id, hash_base
=>$parent, file_name
=>$file),
1232 -class => "list"}, esc_html
($file)) . "</td>\n" .
1233 "<td><span class=\"file_status deleted\">[deleted " . file_type
($from_mode). "]</span></td>\n" .
1234 "<td class=\"link\">" .
1235 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$from_id, hash_base
=>$parent, file_name
=>$file)}, "blob") . " | " .
1236 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent, file_name
=>$file)}, "history") .
1239 } elsif ($status eq "M" || $status eq "T") { # modified, or type changed
1240 my $mode_chnge = "";
1241 if ($from_mode != $to_mode) {
1242 $mode_chnge = " <span class=\"file_status mode_chnge\">[changed";
1243 if (((oct $from_mode) & S_IFMT
) != ((oct $to_mode) & S_IFMT
)) {
1244 $mode_chnge .= " from " . file_type
($from_mode) . " to " . file_type
($to_mode);
1246 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
1247 if (S_ISREG
($from_mode) && S_ISREG
($to_mode)) {
1248 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
1249 } elsif (S_ISREG
($to_mode)) {
1250 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
1253 $mode_chnge .= "]</span>\n";
1256 if ($to_id ne $from_id) { # modified
1257 print $cgi->a({-href
=> href
(action
=>"blobdiff", hash
=>$to_id, hash_parent
=>$from_id, hash_base
=>$hash, file_name
=>$file),
1258 -class => "list"}, esc_html
($file));
1259 } else { # mode changed
1260 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$file),
1261 -class => "list"}, esc_html
($file));
1264 "<td>$mode_chnge</td>\n" .
1265 "<td class=\"link\">" .
1266 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$file)}, "blob");
1267 if ($to_id ne $from_id) { # modified
1268 print " | " . $cgi->a({-href
=> href
(action
=>"blobdiff", hash
=>$to_id, hash_parent
=>$from_id, hash_base
=>$hash, file_name
=>$file)}, "diff");
1270 print " | " . $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash, file_name
=>$file)}, "history") . "\n";
1273 } elsif ($status eq "R") { # renamed
1274 my ($from_file, $to_file) = split "\t", $file;
1276 if ($from_mode != $to_mode) {
1277 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
1280 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$to_file),
1281 -class => "list"}, esc_html
($to_file)) . "</td>\n" .
1282 "<td><span class=\"file_status moved\">[moved from " .
1283 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$from_id, hash_base
=>$parent, file_name
=>$from_file),
1284 -class => "list"}, esc_html
($from_file)) .
1285 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
1286 "<td class=\"link\">" .
1287 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$to_file)}, "blob");
1288 if ($to_id ne $from_id) {
1290 $cgi->a({-href
=> "$my_uri?" .
1291 esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file;fp=$from_file")}, "diff");
1295 } elsif ($status eq "C") { # copied
1296 my ($from_file, $to_file) = split "\t", $file;
1298 if ($from_mode != $to_mode) {
1299 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
1302 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$to_file),
1303 -class => "list"}, esc_html
($to_file)) . "</td>\n" .
1304 "<td><span class=\"file_status copied\">[copied from " .
1305 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$from_id, hash_base
=>$parent, file_name
=>$from_file),
1306 -class => "list"}, esc_html
($from_file)) .
1307 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
1308 "<td class=\"link\">" .
1309 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$to_file)}, "blob");
1310 if ($to_id ne $from_id) {
1312 $cgi->a({-href
=> "$my_uri?" .
1313 esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file;fp=$from_file")}, "diff");
1316 } # we should not encounter Unmerged (U) or Unknown (X) status
1322 sub git_shortlog_body
{
1323 # uses global variable $project
1324 my ($revlist, $from, $to, $refs, $extra) = @_;
1325 $from = 0 unless defined $from;
1326 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1328 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
1330 for (my $i = $from; $i <= $to; $i++) {
1331 my $commit = $revlist->[$i];
1332 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
1333 my $ref = format_ref_marker
($refs, $commit);
1334 my %co = parse_commit
($commit);
1336 print "<tr class=\"dark\">\n";
1338 print "<tr class=\"light\">\n";
1341 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1342 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1343 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
1345 print format_subject_html
($co{'title'}, $co{'title_short'}, href
(action
=>"commit", hash
=>$commit), $ref);
1347 "<td class=\"link\">" .
1348 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
1349 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
1353 if (defined $extra) {
1355 "<td colspan=\"4\">$extra</td>\n" .
1361 sub git_history_body
{
1362 # Warning: assumes constant type (blob or tree) during history
1363 my ($fd, $refs, $hash_base, $ftype, $extra) = @_;
1365 print "<table class=\"history\" cellspacing=\"0\">\n";
1367 while (my $line = <$fd>) {
1368 if ($line !~ m/^([0-9a-fA-F]{40})/) {
1373 my %co = parse_commit
($commit);
1378 my $ref = format_ref_marker
($refs, $commit);
1381 print "<tr class=\"dark\">\n";
1383 print "<tr class=\"light\">\n";
1386 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1387 # shortlog uses chop_str($co{'author_name'}, 10)
1388 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
1390 # originally git_history used chop_str($co{'title'}, 50)
1391 print format_subject_html
($co{'title'}, $co{'title_short'}, href
(action
=>"commit", hash
=>$commit), $ref);
1393 "<td class=\"link\">" .
1394 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
1395 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
1396 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype);
1398 if ($ftype eq 'blob') {
1399 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
1400 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
1401 if (defined $blob_current && defined $blob_parent &&
1402 $blob_current ne $blob_parent) {
1404 $cgi->a({-href
=> href
(action
=>"blobdiff", hash
=>$blob_current, hash_parent
=>$blob_parent, hash_base
=>$commit, file_name
=>$file_name)},
1411 if (defined $extra) {
1413 "<td colspan=\"4\">$extra</td>\n" .
1420 # uses global variable $project
1421 my ($taglist, $from, $to, $extra) = @_;
1422 $from = 0 unless defined $from;
1423 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1425 print "<table class=\"tags\" cellspacing=\"0\">\n";
1427 for (my $i = $from; $i <= $to; $i++) {
1428 my $entry = $taglist->[$i];
1430 my $comment_lines = $tag{'comment'};
1431 my $comment = shift @
$comment_lines;
1433 if (defined $comment) {
1434 $comment_short = chop_str
($comment, 30, 5);
1437 print "<tr class=\"dark\">\n";
1439 print "<tr class=\"light\">\n";
1442 print "<td><i>$tag{'age'}</i></td>\n" .
1444 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
1445 -class => "list"}, "<b>" . esc_html
($tag{'name'}) . "</b>") .
1448 if (defined $comment) {
1449 print format_subject_html
($comment, $comment_short, href
(action
=>"tag", hash
=>$tag{'id'}));
1452 "<td class=\"selflink\">";
1453 if ($tag{'type'} eq "tag") {
1454 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
1459 "<td class=\"link\">" . " | " .
1460 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
1461 if ($tag{'reftype'} eq "commit") {
1462 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
1463 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'refid'})}, "log");
1464 } elsif ($tag{'reftype'} eq "blob") {
1465 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
1470 if (defined $extra) {
1472 "<td colspan=\"5\">$extra</td>\n" .
1478 sub git_heads_body
{
1479 # uses global variable $project
1480 my ($taglist, $head, $from, $to, $extra) = @_;
1481 $from = 0 unless defined $from;
1482 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1484 print "<table class=\"heads\" cellspacing=\"0\">\n";
1486 for (my $i = $from; $i <= $to; $i++) {
1487 my $entry = $taglist->[$i];
1489 my $curr = $tag{'id'} eq $head;
1491 print "<tr class=\"dark\">\n";
1493 print "<tr class=\"light\">\n";
1496 print "<td><i>$tag{'age'}</i></td>\n" .
1497 ($tag{'id'} eq $head ?
"<td class=\"current_head\">" : "<td>") .
1498 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'}),
1499 -class => "list"}, "<b>" . esc_html
($tag{'name'}) . "</b>") .
1501 "<td class=\"link\">" .
1502 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") . " | " .
1503 $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log") .
1507 if (defined $extra) {
1509 "<td colspan=\"3\">$extra</td>\n" .
1515 ## ----------------------------------------------------------------------
1516 ## functions printing large fragments, format as one of arguments
1518 sub git_diff_print
{
1520 my $from_name = shift;
1522 my $to_name = shift;
1523 my $format = shift || "html";
1525 my $from_tmp = "/dev/null";
1526 my $to_tmp = "/dev/null";
1529 # create tmp from-file
1530 if (defined $from) {
1531 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
1532 open my $fd2, "> $from_tmp";
1533 open my $fd, "-|", $GIT, "cat-file", "blob", $from;
1540 # create tmp to-file
1542 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
1543 open my $fd2, "> $to_tmp";
1544 open my $fd, "-|", $GIT, "cat-file", "blob", $to;
1551 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
1552 if ($format eq "plain") {
1557 while (my $line = <$fd>) {
1559 my $char = substr($line, 0, 1);
1560 my $diff_class = "";
1562 $diff_class = " add";
1563 } elsif ($char eq "-") {
1564 $diff_class = " rem";
1565 } elsif ($char eq "@") {
1566 $diff_class = " chunk_header";
1567 } elsif ($char eq "\\") {
1571 $line = untabify
($line);
1572 print "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
1577 if (defined $from) {
1586 ## ======================================================================
1587 ## ======================================================================
1590 sub git_project_list
{
1591 my $order = $cgi->param('o');
1592 if (defined $order && $order !~ m/project|descr|owner|age/) {
1593 die_error
(undef, "Unknown order parameter");
1596 my @list = git_get_projects_list
();
1599 die_error
(undef, "No projects found");
1601 foreach my $pr (@list) {
1602 my $head = git_get_head_hash
($pr->{'path'});
1603 if (!defined $head) {
1606 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
1607 my %co = parse_commit
($head);
1611 $pr->{'commit'} = \
%co;
1612 if (!defined $pr->{'descr'}) {
1613 my $descr = git_get_project_description
($pr->{'path'}) || "";
1614 $pr->{'descr'} = chop_str
($descr, 25, 5);
1616 if (!defined $pr->{'owner'}) {
1617 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
1619 push @projects, $pr;
1623 if (-f
$home_text) {
1624 print "<div class=\"index_include\">\n";
1625 open (my $fd, $home_text);
1630 print "<table class=\"project_list\">\n" .
1632 $order ||= "project";
1633 if ($order eq "project") {
1634 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
1635 print "<th>Project</th>\n";
1638 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=project"),
1639 -class => "header"}, "Project") .
1642 if ($order eq "descr") {
1643 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
1644 print "<th>Description</th>\n";
1647 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=descr"),
1648 -class => "header"}, "Description") .
1651 if ($order eq "owner") {
1652 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
1653 print "<th>Owner</th>\n";
1656 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=owner"),
1657 -class => "header"}, "Owner") .
1660 if ($order eq "age") {
1661 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
1662 print "<th>Last Change</th>\n";
1665 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=age"),
1666 -class => "header"}, "Last Change") .
1669 print "<th></th>\n" .
1672 foreach my $pr (@projects) {
1674 print "<tr class=\"dark\">\n";
1676 print "<tr class=\"light\">\n";
1679 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
1680 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
1681 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
1682 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
1683 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" .
1684 $pr->{'commit'}{'age_string'} . "</td>\n" .
1685 "<td class=\"link\">" .
1686 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
1687 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
1688 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") .
1697 my $descr = git_get_project_description
($project) || "none";
1698 my $head = git_get_head_hash
($project);
1699 my %co = parse_commit
($head);
1700 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
1702 my $owner = git_get_project_owner
($project);
1704 my $refs = git_get_references
();
1706 git_print_page_nav
('summary','', $head);
1708 print "<div class=\"title\"> </div>\n";
1709 print "<table cellspacing=\"0\">\n" .
1710 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
1711 "<tr><td>owner</td><td>$owner</td></tr>\n" .
1712 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
1713 # use per project git URL list in $projectroot/$project/cloneurl
1714 # or make project git URL from git base URL and project name
1715 my $url_tag = "URL";
1716 my @url_list = git_get_project_url_list
($project);
1717 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
1718 foreach my $git_url (@url_list) {
1719 next unless $git_url;
1720 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
1725 open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_get_head_hash
($project)
1726 or die_error
(undef, "Open git-rev-list failed");
1727 my @revlist = map { chomp; $_ } <$fd>;
1729 git_print_header_div
('shortlog');
1730 git_shortlog_body
(\
@revlist, 0, 15, $refs,
1731 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
1733 my $taglist = git_get_refs_list
("refs/tags");
1734 if (defined @
$taglist) {
1735 git_print_header_div
('tags');
1736 git_tags_body
($taglist, 0, 15,
1737 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
1740 my $headlist = git_get_refs_list
("refs/heads");
1741 if (defined @
$headlist) {
1742 git_print_header_div
('heads');
1743 git_heads_body
($headlist, $head, 0, 15,
1744 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
1751 my $head = git_get_head_hash
($project);
1753 git_print_page_nav
('','', $head,undef,$head);
1754 my %tag = parse_tag
($hash);
1755 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
1756 print "<div class=\"title_text\">\n" .
1757 "<table cellspacing=\"0\">\n" .
1759 "<td>object</td>\n" .
1760 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})}, $tag{'object'}) . "</td>\n" .
1761 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})}, $tag{'type'}) . "</td>\n" .
1763 if (defined($tag{'author'})) {
1764 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
1765 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
1766 print "<tr><td></td><td>" . $ad{'rfc2822'} . sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) . "</td></tr>\n";
1768 print "</table>\n\n" .
1770 print "<div class=\"page_body\">";
1771 my $comment = $tag{'comment'};
1772 foreach my $line (@
$comment) {
1773 print esc_html
($line) . "<br/>\n";
1782 die_error
(undef, "Permission denied") if (!git_get_project_config_bool
('blame'));
1783 die_error
('404 Not Found', "File name not defined") if (!$file_name);
1784 $hash_base ||= git_get_head_hash
($project);
1785 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
1786 my %co = parse_commit
($hash_base)
1787 or die_error
(undef, "Reading commit failed");
1788 if (!defined $hash) {
1789 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
1790 or die_error
(undef, "Error looking up file");
1792 $ftype = git_get_type
($hash);
1793 if ($ftype !~ "blob") {
1794 die_error
("400 Bad Request", "Object is not a blob");
1796 open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base)
1797 or die_error
(undef, "Open git-blame failed");
1800 $cgi->a({-href
=> href
(action
=>"blobl", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)}, "blob") .
1801 " | " . $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)}, "head");
1802 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1803 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
1804 git_print_page_path
($file_name, $ftype);
1805 my @rev_color = (qw(light2 dark2));
1806 my $num_colors = scalar(@rev_color);
1807 my $current_color = 0;
1809 print "<div class=\"page_body\">\n";
1810 print "<table class=\"blame\">\n";
1811 print "<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n";
1813 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
1815 my $rev = substr($full_rev, 0, 8);
1819 if (!defined $last_rev) {
1820 $last_rev = $full_rev;
1821 } elsif ($last_rev ne $full_rev) {
1822 $last_rev = $full_rev;
1823 $current_color = ++$current_color % $num_colors;
1825 print "<tr class=\"$rev_color[$current_color]\">\n";
1826 print "<td class=\"sha1\">" .
1827 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$full_rev, file_name
=>$file_name)}, esc_html
($rev)) . "</td>\n";
1828 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" . esc_html
($lineno) . "</a></td>\n";
1829 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
1834 close $fd or print "Reading blob failed\n";
1840 die_error
('403 Permission denied', "Permission denied") if (!git_get_project_config_bool
('blame'));
1841 die_error
('404 Not Found', "File name not defined") if (!$file_name);
1842 $hash_base ||= git_get_head_hash
($project);
1843 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
1844 my %co = parse_commit
($hash_base)
1845 or die_error
(undef, "Reading commit failed");
1846 if (!defined $hash) {
1847 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
1848 or die_error
(undef, "Error lookup file");
1850 open ($fd, "-|", $GIT, "annotate", '-l', '-t', '-r', $file_name, $hash_base)
1851 or die_error
(undef, "Open git-annotate failed");
1854 $cgi->a({-href
=> href
(action
=>"blobl", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)}, "blob") .
1855 " | " . $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)}, "head");
1856 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1857 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
1858 git_print_page_path
($file_name, 'blob');
1859 print "<div class=\"page_body\">\n";
1861 <table class="blame">
1870 my @line_class = (qw(light dark));
1871 my $line_class_len = scalar (@line_class);
1872 my $line_class_num = $#line_class;
1873 while (my $line = <$fd>) {
1885 $line_class_num = ($line_class_num + 1) % $line_class_len;
1887 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) \+\d\d\d\d\t(\d+)\)(.*)$/) {
1894 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
1897 $short_rev = substr ($long_rev, 0, 8);
1898 $age = time () - $time;
1899 $age_str = age_string
($age);
1900 $age_str =~ s/ / /g;
1901 $age_class = age_class
($age);
1902 $author = esc_html
($author);
1903 $author =~ s/ / /g;
1905 $data = untabify
($data);
1906 $data = esc_html
($data);
1909 <tr class="$line_class[$line_class_num]">
1910 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
1911 <td class="$age_class">$age_str</td>
1913 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
1914 <td class="pre">$data</td>
1917 } # while (my $line = <$fd>)
1918 print "</table>\n\n";
1919 close $fd or print "Reading blob failed.\n";
1925 my $head = git_get_head_hash
($project);
1927 git_print_page_nav
('','', $head,undef,$head);
1928 git_print_header_div
('summary', $project);
1930 my $taglist = git_get_refs_list
("refs/tags");
1931 if (defined @
$taglist) {
1932 git_tags_body
($taglist);
1938 my $head = git_get_head_hash
($project);
1940 git_print_page_nav
('','', $head,undef,$head);
1941 git_print_header_div
('summary', $project);
1943 my $taglist = git_get_refs_list
("refs/heads");
1944 if (defined @
$taglist) {
1945 git_heads_body
($taglist, $head);
1950 sub git_blob_plain
{
1951 if (!defined $hash) {
1952 if (defined $file_name) {
1953 my $base = $hash_base || git_get_head_hash
($project);
1954 $hash = git_get_hash_by_path
($base, $file_name, "blob")
1955 or die_error
(undef, "Error lookup file");
1957 die_error
(undef, "No file name defined");
1961 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
1962 or die_error
(undef, "Couldn't cat $file_name, $hash");
1964 $type ||= blob_mimetype
($fd, $file_name);
1966 # save as filename, even when no $file_name is given
1967 my $save_as = "$hash";
1968 if (defined $file_name) {
1969 $save_as = $file_name;
1970 } elsif ($type =~ m/^text\//) {
1974 print $cgi->header(-type
=> "$type", '-content-disposition' => "inline; filename=\"$save_as\"");
1976 binmode STDOUT
, ':raw';
1978 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
1984 if (!defined $hash) {
1985 if (defined $file_name) {
1986 my $base = $hash_base || git_get_head_hash
($project);
1987 $hash = git_get_hash_by_path
($base, $file_name, "blob")
1988 or die_error
(undef, "Error lookup file");
1990 die_error
(undef, "No file name defined");
1993 my $have_blame = git_get_project_config_bool
('blame');
1994 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
1995 or die_error
(undef, "Couldn't cat $file_name, $hash");
1996 my $mimetype = blob_mimetype
($fd, $file_name);
1997 if ($mimetype !~ m/^text\//) {
1999 return git_blob_plain
($mimetype);
2002 my $formats_nav = '';
2003 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2004 if (defined $file_name) {
2006 $formats_nav .= $cgi->a({-href
=> href
(action
=>"blame", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)}, "blame") . " | ";
2009 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash, file_name
=>$file_name)}, "plain") .
2010 " | " . $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>"HEAD", file_name
=>$file_name)}, "head");
2012 $formats_nav .= $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "plain");
2014 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2015 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2017 print "<div class=\"page_nav\">\n" .
2018 "<br/><br/></div>\n" .
2019 "<div class=\"title\">$hash</div>\n";
2021 git_print_page_path
($file_name, "blob");
2022 print "<div class=\"page_body\">\n";
2024 while (my $line = <$fd>) {
2027 $line = untabify
($line);
2028 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", $nr, $nr, $nr, esc_html
($line);
2030 close $fd or print "Reading blob failed.\n";
2036 if (!defined $hash) {
2037 $hash = git_get_head_hash
($project);
2038 if (defined $file_name) {
2039 my $base = $hash_base || $hash;
2040 $hash = git_get_hash_by_path
($base, $file_name, "tree");
2042 if (!defined $hash_base) {
2047 open my $fd, "-|", $GIT, "ls-tree", '-z', $hash
2048 or die_error
(undef, "Open git-ls-tree failed");
2049 my @entries = map { chomp; $_ } <$fd>;
2050 close $fd or die_error
(undef, "Reading tree failed");
2053 my $refs = git_get_references
();
2054 my $ref = format_ref_marker
($refs, $hash_base);
2058 my $have_blame = git_get_project_config_bool
('blame');
2059 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2060 $base_key{hash_base
} = $hash_base;
2061 git_print_page_nav
('tree','', $hash_base);
2062 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
2064 print "<div class=\"page_nav\">\n";
2065 print "<br/><br/></div>\n";
2066 print "<div class=\"title\">$hash</div>\n";
2068 if (defined $file_name) {
2069 $base = esc_html
("$file_name/");
2071 git_print_page_path
($file_name, 'tree');
2072 print "<div class=\"page_body\">\n";
2073 print "<table cellspacing=\"0\">\n";
2075 foreach my $line (@entries) {
2076 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2077 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
2081 my $t_name = validate_input
($4);
2083 print "<tr class=\"dark\">\n";
2085 print "<tr class=\"light\">\n";
2088 print "<td class=\"mode\">" . mode_str
($t_mode) . "</td>\n";
2089 if ($t_type eq "blob") {
2090 print "<td class=\"list\">" .
2091 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key), -class => "list"}, esc_html
($t_name)) .
2093 "<td class=\"link\">" .
2094 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)}, "blob");
2096 print " | " . $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)}, "blame");
2098 print " | " . $cgi->a({-href
=> href
(action
=>"history", hash
=>$t_hash, hash_base
=>$hash_base, file_name
=>"$base$t_name")}, "history") .
2099 " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$t_hash, file_name
=>"$base$t_name")}, "raw") .
2101 } elsif ($t_type eq "tree") {
2102 print "<td class=\"list\">" .
2103 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)}, esc_html
($t_name)) .
2105 "<td class=\"link\">" .
2106 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)}, "tree") .
2107 " | " . $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base, file_name
=>"$base$t_name")}, "history") .
2112 print "</table>\n" .
2118 my $head = git_get_head_hash
($project);
2119 if (!defined $hash) {
2122 if (!defined $page) {
2125 my $refs = git_get_references
();
2127 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2128 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2129 or die_error
(undef, "Open git-rev-list failed");
2130 my @revlist = map { chomp; $_ } <$fd>;
2133 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
2136 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
2139 my %co = parse_commit
($hash);
2141 git_print_header_div
('summary', $project);
2142 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
2144 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2145 my $commit = $revlist[$i];
2146 my $ref = format_ref_marker
($refs, $commit);
2147 my %co = parse_commit
($commit);
2149 my %ad = parse_date
($co{'author_epoch'});
2150 git_print_header_div
('commit',
2151 "<span class=\"age\">$co{'age_string'}</span>" .
2152 esc_html
($co{'title'}) . $ref,
2154 print "<div class=\"title_text\">\n" .
2155 "<div class=\"log_link\">\n" .
2156 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
2157 " | " . $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
2160 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
2162 "<div class=\"log_body\">\n";
2163 my $comment = $co{'comment'};
2165 foreach my $line (@
$comment) {
2166 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2177 print format_log_line_html
($line) . "<br/>\n";
2188 my %co = parse_commit
($hash);
2190 die_error
(undef, "Unknown commit object");
2192 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2193 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2195 my $parent = $co{'parent'};
2196 if (!defined $parent) {
2199 open my $fd, "-|", $GIT, "diff-tree", '-r', '-M', $parent, $hash
2200 or die_error
(undef, "Open git-diff-tree failed");
2201 my @difftree = map { chomp; $_ } <$fd>;
2202 close $fd or die_error
(undef, "Reading git-diff-tree failed");
2204 # non-textual hash id's can be cached
2206 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2209 my $refs = git_get_references
();
2210 my $ref = format_ref_marker
($refs, $co{'id'});
2211 my $formats_nav = '';
2212 if (defined $file_name && defined $co{'parent'}) {
2213 my $parent = $co{'parent'};
2214 $formats_nav .= $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)}, "blame");
2216 git_header_html
(undef, $expires);
2217 git_print_page_nav
('commit', defined $co{'parent'} ?
'' : 'commitdiff',
2218 $hash, $co{'tree'}, $hash,
2221 if (defined $co{'parent'}) {
2222 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
2224 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
2226 print "<div class=\"title_text\">\n" .
2227 "<table cellspacing=\"0\">\n";
2228 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
2230 "<td></td><td> $ad{'rfc2822'}";
2231 if ($ad{'hour_local'} < 6) {
2232 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2234 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2238 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
2239 print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
2240 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
2243 "<td class=\"sha1\">" .
2244 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash), class => "list"}, $co{'tree'}) .
2246 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)}, "tree") .
2249 my $parents = $co{'parents'};
2250 foreach my $par (@
$parents) {
2253 "<td class=\"sha1\">" . $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par), class => "list"}, $par) . "</td>" .
2254 "<td class=\"link\">" .
2255 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
2256 " | " . $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "commitdiff") .
2262 print "<div class=\"page_body\">\n";
2263 my $comment = $co{'comment'};
2266 foreach my $line (@
$comment) {
2267 # print only one empty line
2269 if ($empty || $signed) {
2276 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2278 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2281 print format_log_line_html
($line) . "<br/>\n";
2286 git_difftree_body
(\
@difftree, $parent);
2292 mkdir($git_temp, 0700);
2294 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2296 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", hash
=>$hash, hash_parent
=>$hash_parent)}, "plain");
2297 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2298 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2300 print "<div class=\"page_nav\">\n" .
2301 "<br/><br/></div>\n" .
2302 "<div class=\"title\">$hash vs $hash_parent</div>\n";
2304 git_print_page_path
($file_name, "blob");
2305 print "<div class=\"page_body\">\n" .
2306 "<div class=\"diff_info\">blob:" .
2307 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash_parent, hash_base
=>$hash_base, file_name
=>$file_name)}, $hash_parent) .
2309 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)}, $hash) .
2311 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
2316 sub git_blobdiff_plain
{
2317 mkdir($git_temp, 0700);
2318 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8');
2319 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
2322 sub git_commitdiff
{
2323 mkdir($git_temp, 0700);
2324 my %co = parse_commit
($hash);
2326 die_error
(undef, "Unknown commit object");
2328 if (!defined $hash_parent) {
2329 $hash_parent = $co{'parent'} || '--root';
2331 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2332 or die_error
(undef, "Open git-diff-tree failed");
2333 my @difftree = map { chomp; $_ } <$fd>;
2334 close $fd or die_error
(undef, "Reading git-diff-tree failed");
2336 # non-textual hash id's can be cached
2338 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2341 my $refs = git_get_references
();
2342 my $ref = format_ref_marker
($refs, $co{'id'});
2344 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", hash
=>$hash, hash_parent
=>$hash_parent)}, "plain");
2345 git_header_html
(undef, $expires);
2346 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
2347 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
2348 print "<div class=\"page_body\">\n";
2349 my $comment = $co{'comment'};
2352 my @log = @
$comment;
2353 # remove first and empty lines after that
2355 while (defined $log[0] && $log[0] eq "") {
2358 foreach my $line (@log) {
2359 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2370 print format_log_line_html
($line) . "<br/>\n";
2373 foreach my $line (@difftree) {
2374 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2375 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2376 if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2384 my $file = validate_input
(unquote
($6));
2385 if ($status eq "A") {
2386 print "<div class=\"diff_info\">" . file_type
($to_mode) . ":" .
2387 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$file)}, $to_id) . "(new)" .
2389 git_diff_print
(undef, "/dev/null", $to_id, "b/$file");
2390 } elsif ($status eq "D") {
2391 print "<div class=\"diff_info\">" . file_type
($from_mode) . ":" .
2392 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$from_id, hash_base
=>$hash_parent, file_name
=>$file)}, $from_id) . "(deleted)" .
2394 git_diff_print
($from_id, "a/$file", undef, "/dev/null");
2395 } elsif ($status eq "M") {
2396 if ($from_id ne $to_id) {
2397 print "<div class=\"diff_info\">" .
2398 file_type
($from_mode) . ":" .
2399 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$from_id, hash_base
=>$hash_parent, file_name
=>$file)}, $from_id) .
2401 file_type
($to_mode) . ":" .
2402 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$file)}, $to_id) .
2404 git_diff_print
($from_id, "a/$file", $to_id, "b/$file");
2413 sub git_commitdiff_plain
{
2414 mkdir($git_temp, 0700);
2415 my %co = parse_commit
($hash);
2417 die_error
(undef, "Unknown commit object");
2419 if (!defined $hash_parent) {
2420 $hash_parent = $co{'parent'} || '--root';
2422 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2423 or die_error
(undef, "Open git-diff-tree failed");
2424 my @difftree = map { chomp; $_ } <$fd>;
2425 close $fd or die_error
(undef, "Reading diff-tree failed");
2427 # try to figure out the next tag after this commit
2429 my $refs = git_get_references
("tags");
2430 open $fd, "-|", $GIT, "rev-list", "HEAD";
2431 my @commits = map { chomp; $_ } <$fd>;
2433 foreach my $commit (@commits) {
2434 if (defined $refs->{$commit}) {
2435 $tagname = $refs->{$commit}
2437 if ($commit eq $hash) {
2442 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8', '-content-disposition' => "inline; filename=\"git-$hash.patch\"");
2443 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2444 my $comment = $co{'comment'};
2445 print "From: $co{'author'}\n" .
2446 "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
2447 "Subject: $co{'title'}\n";
2448 if (defined $tagname) {
2449 print "X-Git-Tag: $tagname\n";
2451 print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
2454 foreach my $line (@
$comment) {;
2459 foreach my $line (@difftree) {
2460 if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2467 if ($status eq "A") {
2468 git_diff_print
(undef, "/dev/null", $to_id, "b/$file", "plain");
2469 } elsif ($status eq "D") {
2470 git_diff_print
($from_id, "a/$file", undef, "/dev/null", "plain");
2471 } elsif ($status eq "M") {
2472 git_diff_print
($from_id, "a/$file", $to_id, "b/$file", "plain");
2478 if (!defined $hash_base) {
2479 $hash_base = git_get_head_hash
($project);
2482 my %co = parse_commit
($hash_base);
2484 die_error
(undef, "Unknown commit object");
2486 my $refs = git_get_references
();
2488 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base);
2489 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2490 if (!defined $hash && defined $file_name) {
2491 $hash = git_get_hash_by_path
($hash_base, $file_name);
2493 if (defined $hash) {
2494 $ftype = git_get_type
($hash);
2496 git_print_page_path
($file_name, $ftype);
2499 $GIT, "rev-list", "--full-history", $hash_base, "--", $file_name;
2500 git_history_body
($fd, $refs, $hash_base, $ftype);
2507 if (!defined $searchtext) {
2508 die_error
(undef, "Text field empty");
2510 if (!defined $hash) {
2511 $hash = git_get_head_hash
($project);
2513 my %co = parse_commit
($hash);
2515 die_error
(undef, "Unknown commit object");
2517 # pickaxe may take all resources of your box and run for several minutes
2518 # with every query - so decide by yourself how public you make this feature :)
2519 my $commit_search = 1;
2520 my $author_search = 0;
2521 my $committer_search = 0;
2522 my $pickaxe_search = 0;
2523 if ($searchtext =~ s/^author\\://i) {
2525 } elsif ($searchtext =~ s/^committer\\://i) {
2526 $committer_search = 1;
2527 } elsif ($searchtext =~ s/^pickaxe\\://i) {
2529 $pickaxe_search = 1;
2532 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
2533 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
2535 print "<table cellspacing=\"0\">\n";
2537 if ($commit_search) {
2539 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", $hash or next;
2540 while (my $commit_text = <$fd>) {
2541 if (!grep m/$searchtext/i, $commit_text) {
2544 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
2547 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
2550 my @commit_lines = split "\n", $commit_text;
2551 my %co = parse_commit
(undef, \
@commit_lines);
2556 print "<tr class=\"dark\">\n";
2558 print "<tr class=\"light\">\n";
2561 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2562 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2564 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}) -class => "list"}, "<b>" . esc_html
(chop_str
($co{'title'}, 50)) . "</b><br/>");
2565 my $comment = $co{'comment'};
2566 foreach my $line (@
$comment) {
2567 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2568 my $lead = esc_html
($1) || "";
2569 $lead = chop_str
($lead, 30, 10);
2570 my $match = esc_html
($2) || "";
2571 my $trail = esc_html
($3) || "";
2572 $trail = chop_str
($trail, 30, 10);
2573 my $text = "$lead<span class=\"match\">$match</span>$trail";
2574 print chop_str
($text, 80, 5) . "<br/>\n";
2578 "<td class=\"link\">" .
2579 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
2580 " | " . $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
2587 if ($pickaxe_search) {
2589 open my $fd, "-|", "$GIT rev-list $hash | $GIT diff-tree -r --stdin -S\'$searchtext\'";
2592 while (my $line = <$fd>) {
2593 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2596 $set{'from_id'} = $3;
2598 $set{'id'} = $set{'to_id'};
2599 if ($set{'id'} =~ m/0{40}/) {
2600 $set{'id'} = $set{'from_id'};
2602 if ($set{'id'} =~ m/0{40}/) {
2606 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
2609 print "<tr class=\"dark\">\n";
2611 print "<tr class=\"light\">\n";
2614 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2615 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2617 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list"}, "<b>" .
2618 esc_html
(chop_str
($co{'title'}, 50)) . "</b><br/>");
2619 while (my $setref = shift @files) {
2621 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$set{'id'}, hash_base
=>$co{'id'}, file_name
=>$set{'file'}), class => "list"},
2622 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
2626 "<td class=\"link\">" .
2627 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
2628 " | " . $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
2632 %co = parse_commit
($1);
2642 my $head = git_get_head_hash
($project);
2643 if (!defined $hash) {
2646 if (!defined $page) {
2649 my $refs = git_get_references
();
2651 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2652 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2653 or die_error
(undef, "Open git-rev-list failed");
2654 my @revlist = map { chomp; $_ } <$fd>;
2657 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
2659 if ($#revlist >= (100 * ($page+1)-1)) {
2661 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
2662 -title
=> "Alt-n"}, "next");
2667 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
2668 git_print_header_div
('summary', $project);
2670 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
2675 ## ......................................................................
2676 ## feeds (RSS, OPML)
2679 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
2680 open my $fd, "-|", $GIT, "rev-list", "--max-count=150", git_get_head_hash
($project)
2681 or die_error
(undef, "Open git-rev-list failed");
2682 my @revlist = map { chomp; $_ } <$fd>;
2683 close $fd or die_error
(undef, "Reading git-rev-list failed");
2684 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
2685 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
2686 "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
2687 print "<channel>\n";
2688 print "<title>$project</title>\n".
2689 "<link>" . esc_html
("$my_url?p=$project;a=summary") . "</link>\n".
2690 "<description>$project log</description>\n".
2691 "<language>en</language>\n";
2693 for (my $i = 0; $i <= $#revlist; $i++) {
2694 my $commit = $revlist[$i];
2695 my %co = parse_commit
($commit);
2696 # we read 150, we always show 30 and the ones more recent than 48 hours
2697 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
2700 my %cd = parse_date
($co{'committer_epoch'});
2701 open $fd, "-|", $GIT, "diff-tree", '-r', $co{'parent'}, $co{'id'} or next;
2702 my @difftree = map { chomp; $_ } <$fd>;
2706 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
2708 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
2709 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
2710 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
2711 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
2712 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
2713 "<content:encoded>" .
2715 my $comment = $co{'comment'};
2716 foreach my $line (@
$comment) {
2717 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
2718 print "$line<br/>\n";
2721 foreach my $line (@difftree) {
2722 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
2725 my $file = validate_input
(unquote
($7));
2726 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
2727 print "$file<br/>\n";
2730 "</content:encoded>\n" .
2733 print "</channel></rss>";
2737 my @list = git_get_projects_list
();
2739 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
2740 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
2741 "<opml version=\"1.0\">\n".
2743 " <title>$site_name Git OPML Export</title>\n".
2746 "<outline text=\"git RSS feeds\">\n";
2748 foreach my $pr (@list) {
2750 my $head = git_get_head_hash
($proj{'path'});
2751 if (!defined $head) {
2754 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
2755 my %co = parse_commit
($head);
2760 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
2761 my $rss = "$my_url?p=$proj{'path'};a=rss";
2762 my $html = "$my_url?p=$proj{'path'};a=summary";
2763 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
2765 print "</outline>\n".