3 # gitweb - simple web interface to track changes in git repositories
5 # (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
6 # (C) 2005, Christian Gierke
8 # This program is licensed under the GPLv2
12 use CGI
qw(:standard :escapeHTML -nosticky);
13 use CGI
::Util
qw(unescape);
14 use CGI
::Carp
qw(fatalsToBrowser);
18 binmode STDOUT
, ':utf8';
21 our $version = "++GIT_VERSION++";
22 our $my_url = $cgi->url();
23 our $my_uri = $cgi->url(-absolute
=> 1);
25 # core git executable to use
26 # this can just be "git" if your webserver has a sensible PATH
27 our $GIT = "++GIT_BINDIR++/git";
29 # absolute fs-path which will be prepended to the project path
30 #our $projectroot = "/pub/scm";
31 our $projectroot = "++GITWEB_PROJECTROOT++";
33 # location for temporary files needed for diffs
34 our $git_temp = "/tmp/gitweb";
36 # target of the home link on top of all pages
37 our $home_link = $my_uri;
39 # name of your site or organization to appear in page titles
40 # replace this with something more descriptive for clearer bookmarks
41 our $site_name = "++GITWEB_SITENAME++" || $ENV{'SERVER_NAME'} || "Untitled";
43 # html text to include at home page
44 our $home_text = "++GITWEB_HOMETEXT++";
46 # URI of default stylesheet
47 our $stylesheet = "++GITWEB_CSS++";
49 our $logo = "++GITWEB_LOGO++";
51 # source of projects list
52 our $projects_list = "++GITWEB_LIST++";
54 # default blob_plain mimetype and default charset for text/plain blob
55 our $default_blob_plain_mimetype = 'text/plain';
56 our $default_text_plain_charset = undef;
58 # file to use for guessing MIME types before trying /etc/mime.types
59 # (relative to the current git repository)
60 our $mimetypes_file = undef;
62 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
63 require $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
65 # version of the core git binary
66 our $git_version = qx($GIT --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
68 $projects_list ||= $projectroot;
70 mkdir($git_temp, 0700) || die_error
(undef, "Couldn't mkdir $git_temp");
73 # ======================================================================
74 # input validation and dispatch
75 our $action = $cgi->param('a');
76 if (defined $action) {
77 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
78 die_error
(undef, "Invalid action parameter");
80 # action which does not check rest of parameters
81 if ($action eq "opml") {
87 our $project = ($cgi->param('p') || $ENV{'PATH_INFO'});
88 if (defined $project) {
92 if (defined $project && $project) {
93 if (!validate_input
($project)) {
94 die_error
(undef, "Invalid project parameter");
96 if (!(-d
"$projectroot/$project")) {
97 die_error
(undef, "No such directory");
99 if (!(-e
"$projectroot/$project/HEAD")) {
100 die_error
(undef, "No such project");
102 $ENV{'GIT_DIR'} = "$projectroot/$project";
108 our $file_name = $cgi->param('f');
109 if (defined $file_name) {
110 if (!validate_input
($file_name)) {
111 die_error
(undef, "Invalid file parameter");
115 our $hash = $cgi->param('h');
117 if (!validate_input
($hash)) {
118 die_error
(undef, "Invalid hash parameter");
122 our $hash_parent = $cgi->param('hp');
123 if (defined $hash_parent) {
124 if (!validate_input
($hash_parent)) {
125 die_error
(undef, "Invalid hash parent parameter");
129 our $hash_base = $cgi->param('hb');
130 if (defined $hash_base) {
131 if (!validate_input
($hash_base)) {
132 die_error
(undef, "Invalid hash base parameter");
136 our $page = $cgi->param('pg');
138 if ($page =~ m/[^0-9]$/) {
139 die_error
(undef, "Invalid page parameter");
143 our $searchtext = $cgi->param('s');
144 if (defined $searchtext) {
145 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
146 die_error
(undef, "Invalid search parameter");
148 $searchtext = quotemeta $searchtext;
153 "blame" => \
&git_blame2
,
154 "blobdiff" => \
&git_blobdiff
,
155 "blobdiff_plain" => \
&git_blobdiff_plain
,
156 "blob" => \
&git_blob
,
157 "blob_plain" => \
&git_blob_plain
,
158 "commitdiff" => \
&git_commitdiff
,
159 "commitdiff_plain" => \
&git_commitdiff_plain
,
160 "commit" => \
&git_commit
,
161 "heads" => \
&git_heads
,
162 "history" => \
&git_history
,
165 "search" => \
&git_search
,
166 "shortlog" => \
&git_shortlog
,
167 "summary" => \
&git_summary
,
169 "tags" => \
&git_tags
,
170 "tree" => \
&git_tree
,
173 $action = 'summary' if (!defined($action));
174 if (!defined($actions{$action})) {
175 die_error
(undef, "Unknown action");
177 $actions{$action}->();
180 ## ======================================================================
181 ## validation, quoting/unquoting and escaping
186 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
189 if ($input =~ m/(^|\/)(|\
.|\
.\
.)($|\
/)/) {
192 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\
-\
+\#\
~\
%]/) {
198 # quote unsafe chars, but keep the slash, even when it's not
199 # correct, but quoted slashes look too horrible in bookmarks
202 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
208 # replace invalid utf8 character with SUBSTITUTION sequence
211 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
212 $str = escapeHTML
($str);
213 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
217 # git may return quoted and escaped filenames
220 if ($str =~ m/^"(.*)"$/) {
222 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
227 # escape tabs (convert tabs to spaces)
231 while ((my $pos = index($line, "\t")) != -1) {
232 if (my $count = (8 - ($pos % 8))) {
233 my $spaces = ' ' x
$count;
234 $line =~ s/\t/$spaces/;
241 ## ----------------------------------------------------------------------
242 ## HTML aware string manipulation
247 my $add_len = shift || 10;
249 # allow only $len chars, but don't cut a word if it would fit in $add_len
250 # if it doesn't fit, cut it if it's still longer than the dots we would add
251 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
254 if (length($tail) > 4) {
256 $body =~ s/&[^;]*$//; # remove chopped character entities
261 ## ----------------------------------------------------------------------
262 ## functions returning short strings
264 # CSS class for given age value (in seconds)
268 if ($age < 60*60*2) {
270 } elsif ($age < 60*60*24*2) {
277 # convert age in seconds to "nn units ago" string
282 if ($age > 60*60*24*365*2) {
283 $age_str = (int $age/60/60/24/365);
284 $age_str .= " years ago";
285 } elsif ($age > 60*60*24*(365/12)*2) {
286 $age_str = int $age/60/60/24/(365/12);
287 $age_str .= " months ago";
288 } elsif ($age > 60*60*24*7*2) {
289 $age_str = int $age/60/60/24/7;
290 $age_str .= " weeks ago";
291 } elsif ($age > 60*60*24*2) {
292 $age_str = int $age/60/60/24;
293 $age_str .= " days ago";
294 } elsif ($age > 60*60*2) {
295 $age_str = int $age/60/60;
296 $age_str .= " hours ago";
297 } elsif ($age > 60*2) {
298 $age_str = int $age/60;
299 $age_str .= " min ago";
302 $age_str .= " sec ago";
304 $age_str .= " right now";
309 # convert file mode in octal to symbolic file mode string
311 my $mode = oct shift;
313 if (S_ISDIR
($mode & S_IFMT
)) {
315 } elsif (S_ISLNK
($mode)) {
317 } elsif (S_ISREG
($mode)) {
318 # git cares only about the executable bit
319 if ($mode & S_IXUSR
) {
329 # convert file mode in octal to file type string
331 my $mode = oct shift;
333 if (S_ISDIR
($mode & S_IFMT
)) {
335 } elsif (S_ISLNK
($mode)) {
337 } elsif (S_ISREG
($mode)) {
344 ## ----------------------------------------------------------------------
345 ## functions returning short HTML fragments, or transforming HTML fragments
346 ## which don't beling to other sections
348 # format line of commit message or tag comment
349 sub format_log_line_html
{
352 $line = esc_html
($line);
353 $line =~ s/ / /g;
354 if ($line =~ m/([0-9a-fA-F]{40})/) {
356 if (git_get_type
($hash_text) eq "commit") {
357 my $link = $cgi->a({-class => "text", -href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$hash_text")}, $hash_text);
358 $line =~ s/$hash_text/$link/;
364 # format marker of refs pointing to given object
365 sub format_ref_marker
{
366 my ($refs, $id) = @_;
369 if (defined $refs->{$id}) {
370 foreach my $ref (@
{$refs->{$id}}) {
371 my ($type, $name) = qw();
372 # e.g. tags/v2.6.11 or heads/next
373 if ($ref =~ m!^(.*?)s?/(.*)$!) {
381 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
386 return ' <span class="refs">'. $markers . '</span>';
392 # format, perhaps shortened and with markers, title line
393 sub format_subject_html
{
394 my ($long, $short, $query, $extra) = @_;
395 $extra = '' unless defined($extra);
397 if (length($short) < length($long)) {
398 return $cgi->a({-href
=> "$my_uri?" . esc_param
($query),
399 -class => "list", -title
=> $long},
400 esc_html
($short) . $extra);
402 return $cgi->a({-href
=> "$my_uri?" . esc_param
($query),
404 esc_html
($long) . $extra);
408 ## ----------------------------------------------------------------------
409 ## git utility subroutines, invoking git commands
411 # get HEAD ref of given project as hash
412 sub git_get_head_hash
{
414 my $oENV = $ENV{'GIT_DIR'};
416 $ENV{'GIT_DIR'} = "$projectroot/$project";
417 if (open my $fd, "-|", $GIT, "rev-parse", "--verify", "HEAD") {
420 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
425 $ENV{'GIT_DIR'} = $oENV;
430 # get type of given object
434 open my $fd, "-|", $GIT, "cat-file", '-t', $hash or return;
441 sub git_get_project_config
{
444 return unless ($key);
445 $key =~ s/^gitweb\.//;
446 return if ($key =~ m/\W/);
448 my $val = qx($GIT repo
-config
--get gitweb
.$key);
452 sub git_get_project_config_bool
{
453 my $val = git_get_project_config
(@_);
454 if ($val and $val =~ m/true|yes|on/) {
457 return; # implicit false
460 # get hash of given path at given ref
461 sub git_get_hash_by_path
{
463 my $path = shift || return undef;
467 open my $fd, "-|", $GIT, "ls-tree", $base, "--", $path
468 or die_error
(undef, "Open git-ls-tree failed");
470 close $fd or return undef;
472 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
473 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
477 ## ......................................................................
478 ## git utility functions, directly accessing git repository
480 # assumes that PATH is not symref
481 sub git_get_hash_by_ref
{
484 open my $fd, "$projectroot/$path" or return undef;
488 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
493 sub git_get_project_description
{
496 open my $fd, "$projectroot/$path/description" or return undef;
503 sub git_get_projects_list
{
506 if (-d
$projects_list) {
507 # search in directory
508 my $dir = $projects_list;
509 opendir my ($dh), $dir or return undef;
510 while (my $dir = readdir($dh)) {
511 if (-e
"$projectroot/$dir/HEAD") {
519 } elsif (-f
$projects_list) {
520 # read from file(url-encoded):
521 # 'git%2Fgit.git Linus+Torvalds'
522 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
523 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
524 open my ($fd), $projects_list or return undef;
525 while (my $line = <$fd>) {
527 my ($path, $owner) = split ' ', $line;
528 $path = unescape
($path);
529 $owner = unescape
($owner);
530 if (!defined $path) {
533 if (-e
"$projectroot/$path/HEAD") {
536 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
543 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
547 sub git_get_project_owner
{
551 return undef unless $project;
553 # read from file (url-encoded):
554 # 'git%2Fgit.git Linus+Torvalds'
555 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
556 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
557 if (-f
$projects_list) {
558 open (my $fd , $projects_list);
559 while (my $line = <$fd>) {
561 my ($pr, $ow) = split ' ', $line;
564 if ($pr eq $project) {
565 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
571 if (!defined $owner) {
572 $owner = get_file_owner
("$projectroot/$project");
578 sub git_get_references
{
579 my $type = shift || "";
582 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
583 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
584 if (-f
"$projectroot/$project/info/refs") {
585 open $fd, "$projectroot/$project/info/refs"
588 open $fd, "-|", $GIT, "ls-remote", "."
592 while (my $line = <$fd>) {
594 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?[^\^]+)/) {
595 if (defined $refs{$1}) {
596 push @
{$refs{$1}}, $2;
606 ## ----------------------------------------------------------------------
607 ## parse to hash functions
611 my $tz = shift || "-0000";
614 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
615 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
616 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
617 $date{'hour'} = $hour;
618 $date{'minute'} = $min;
619 $date{'mday'} = $mday;
620 $date{'day'} = $days[$wday];
621 $date{'month'} = $months[$mon];
622 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
623 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
625 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
626 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
627 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
628 $date{'hour_local'} = $hour;
629 $date{'minute_local'} = $min;
630 $date{'tz_local'} = $tz;
639 open my $fd, "-|", $GIT, "cat-file", "tag", $tag_id or return;
640 $tag{'id'} = $tag_id;
641 while (my $line = <$fd>) {
643 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
645 } elsif ($line =~ m/^type (.+)$/) {
647 } elsif ($line =~ m/^tag (.+)$/) {
649 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
653 } elsif ($line =~ m/--BEGIN/) {
654 push @comment, $line;
656 } elsif ($line eq "") {
660 push @comment, <$fd>;
661 $tag{'comment'} = \
@comment;
663 if (!defined $tag{'name'}) {
670 my $commit_id = shift;
671 my $commit_text = shift;
676 if (defined $commit_text) {
677 @commit_lines = @
$commit_text;
680 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", "--max-count=1", $commit_id or return;
681 @commit_lines = split '\n', <$fd>;
686 my $header = shift @commit_lines;
687 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
690 ($co{'id'}, my @parents) = split ' ', $header;
691 $co{'parents'} = \
@parents;
692 $co{'parent'} = $parents[0];
693 while (my $line = shift @commit_lines) {
694 last if $line eq "\n";
695 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
697 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
699 $co{'author_epoch'} = $2;
700 $co{'author_tz'} = $3;
701 if ($co{'author'} =~ m/^([^<]+) </) {
702 $co{'author_name'} = $1;
704 $co{'author_name'} = $co{'author'};
706 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
707 $co{'committer'} = $1;
708 $co{'committer_epoch'} = $2;
709 $co{'committer_tz'} = $3;
710 $co{'committer_name'} = $co{'committer'};
711 $co{'committer_name'} =~ s/ <.*//;
714 if (!defined $co{'tree'}) {
718 foreach my $title (@commit_lines) {
721 $co{'title'} = chop_str
($title, 80, 5);
722 # remove leading stuff of merges to make the interesting part visible
723 if (length($title) > 50) {
724 $title =~ s/^Automatic //;
725 $title =~ s/^merge (of|with) /Merge ... /i;
726 if (length($title) > 50) {
727 $title =~ s/(http|rsync):\/\///;
729 if (length($title) > 50) {
730 $title =~ s/(master|www|rsync)\.//;
732 if (length($title) > 50) {
733 $title =~ s/kernel.org:?//;
735 if (length($title) > 50) {
736 $title =~ s/\/pub\/scm//;
739 $co{'title_short'} = chop_str
($title, 50, 5);
743 # remove added spaces
744 foreach my $line (@commit_lines) {
747 $co{'comment'} = \
@commit_lines;
749 my $age = time - $co{'committer_epoch'};
751 $co{'age_string'} = age_string
($age);
752 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
753 if ($age > 60*60*24*7*2) {
754 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
755 $co{'age_string_age'} = $co{'age_string'};
757 $co{'age_string_date'} = $co{'age_string'};
758 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
763 # parse ref from ref_file, given by ref_id, with given type
765 my $ref_file = shift;
767 my $type = shift || git_get_type
($ref_id);
770 $ref_item{'type'} = $type;
771 $ref_item{'id'} = $ref_id;
772 $ref_item{'epoch'} = 0;
773 $ref_item{'age'} = "unknown";
774 if ($type eq "tag") {
775 my %tag = parse_tag
($ref_id);
776 $ref_item{'comment'} = $tag{'comment'};
777 if ($tag{'type'} eq "commit") {
778 my %co = parse_commit
($tag{'object'});
779 $ref_item{'epoch'} = $co{'committer_epoch'};
780 $ref_item{'age'} = $co{'age_string'};
781 } elsif (defined($tag{'epoch'})) {
782 my $age = time - $tag{'epoch'};
783 $ref_item{'epoch'} = $tag{'epoch'};
784 $ref_item{'age'} = age_string
($age);
786 $ref_item{'reftype'} = $tag{'type'};
787 $ref_item{'name'} = $tag{'name'};
788 $ref_item{'refid'} = $tag{'object'};
789 } elsif ($type eq "commit"){
790 my %co = parse_commit
($ref_id);
791 $ref_item{'reftype'} = "commit";
792 $ref_item{'name'} = $ref_file;
793 $ref_item{'title'} = $co{'title'};
794 $ref_item{'refid'} = $ref_id;
795 $ref_item{'epoch'} = $co{'committer_epoch'};
796 $ref_item{'age'} = $co{'age_string'};
798 $ref_item{'reftype'} = $type;
799 $ref_item{'name'} = $ref_file;
800 $ref_item{'refid'} = $ref_id;
806 ## ......................................................................
807 ## parse to array of hashes functions
809 sub git_get_refs_list
{
814 my $pfxlen = length("$projectroot/$project/$ref_dir");
815 File
::Find
::find
(sub {
818 push @refs, substr($File::Find
::name
, $pfxlen + 1);
820 }, "$projectroot/$project/$ref_dir");
822 foreach my $ref_file (@refs) {
823 my $ref_id = git_get_hash_by_ref
("$project/$ref_dir/$ref_file");
824 my $type = git_get_type
($ref_id) || next;
825 my %ref_item = parse_ref
($ref_file, $ref_id, $type);
827 push @reflist, \
%ref_item;
830 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
834 ## ----------------------------------------------------------------------
835 ## filesystem-related functions
840 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
841 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
842 if (!defined $gcos) {
846 $owner =~ s/[,;].*$//;
847 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
850 ## ......................................................................
851 ## mimetype related functions
853 sub mimetype_guess_file
{
854 my $filename = shift;
856 -r
$mimemap or return undef;
859 open(MIME
, $mimemap) or return undef;
861 next if m/^#/; # skip comments
862 my ($mime, $exts) = split(/\t+/);
864 my @exts = split(/\s+/, $exts);
865 foreach my $ext (@exts) {
866 $mimemap{$ext} = $mime;
872 $filename =~ /\.(.*?)$/;
877 my $filename = shift;
879 $filename =~ /\./ or return undef;
881 if ($mimetypes_file) {
882 my $file = $mimetypes_file;
883 if ($file !~ m!^/!) { # if it is relative path
884 # it is relative to project
885 $file = "$projectroot/$project/$file";
887 $mime = mimetype_guess_file
($filename, $file);
889 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
895 my $filename = shift;
898 my $mime = mimetype_guess
($filename);
899 $mime and return $mime;
903 return $default_blob_plain_mimetype unless $fd;
906 return 'text/plain' .
907 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
908 } elsif (! $filename) {
909 return 'application/octet-stream';
910 } elsif ($filename =~ m/\.png$/i) {
912 } elsif ($filename =~ m/\.gif$/i) {
914 } elsif ($filename =~ m/\.jpe?g$/i) {
917 return 'application/octet-stream';
921 ## ======================================================================
922 ## functions printing HTML: header, footer, error page
924 sub git_header_html
{
925 my $status = shift || "200 OK";
928 my $title = "$site_name git";
929 if (defined $project) {
930 $title .= " - $project";
931 if (defined $action) {
932 $title .= "/$action";
933 if (defined $file_name) {
934 $title .= " - $file_name";
935 if ($action eq "tree" && $file_name !~ m
|/$|) {
942 # require explicit support from the UA if we are to send the page as
943 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
944 # we have to do this because MSIE sometimes globs '*/*', pretending to
945 # support xhtml+xml but choking when it gets what it asked for.
946 if (defined $cgi->http('HTTP_ACCEPT') && $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ && $cgi->Accept('application/xhtml
+xml
') != 0) {
947 $content_type = 'application
/xhtml
+xml
';
949 $content_type = 'text
/html
';
951 print $cgi->header(-type=>$content_type, -charset => 'utf
-8', -status=> $status, -expires => $expires);
953 <?xml version="1.0" encoding="utf-8"?>
954 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
955 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
956 <!-- git web interface v$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
957 <!-- git core binaries version $git_version -->
959 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
960 <meta name="robots" content="index, nofollow"/>
961 <title>$title</title>
962 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
964 if (defined $project) {
965 printf('<link rel="alternate" title="%s log" '.
966 'href="%s" type="application/rss+xml"/>'."\n",
968 esc_param
("$my_uri?p=$project;a=rss"));
973 "<div class=\"page_header\">\n" .
974 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
975 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
977 print $cgi->a({-href
=> esc_param
($home_link)}, "projects") . " / ";
978 if (defined $project) {
979 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=summary")}, esc_html
($project));
980 if (defined $action) {
984 if (!defined $searchtext) {
988 if (defined $hash_base) {
989 $search_hash = $hash_base;
990 } elsif (defined $hash) {
991 $search_hash = $hash;
993 $search_hash = "HEAD";
995 $cgi->param("a", "search");
996 $cgi->param("h", $search_hash);
997 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
998 "<div class=\"search\">\n" .
999 $cgi->hidden(-name
=> "p") . "\n" .
1000 $cgi->hidden(-name
=> "a") . "\n" .
1001 $cgi->hidden(-name
=> "h") . "\n" .
1002 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1004 $cgi->end_form() . "\n";
1009 sub git_footer_html
{
1010 print "<div class=\"page_footer\">\n";
1011 if (defined $project) {
1012 my $descr = git_get_project_description
($project);
1013 if (defined $descr) {
1014 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1016 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=rss"), -class => "rss_logo"}, "RSS") . "\n";
1018 print $cgi->a({-href
=> "$my_uri?" . esc_param
("a=opml"), -class => "rss_logo"}, "OPML") . "\n";
1026 my $status = shift || "403 Forbidden";
1027 my $error = shift || "Malformed query, file missing or permission denied";
1029 git_header_html
($status);
1030 print "<div class=\"page_body\">\n" .
1032 "$status - $error\n" .
1039 ## ----------------------------------------------------------------------
1040 ## functions printing or outputting HTML: navigation
1042 sub git_print_page_nav
{
1043 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1044 $extra = '' if !defined $extra; # pager or formats
1046 my @navs = qw(summary shortlog log commit commitdiff tree);
1048 @navs = grep { $_ ne $suppress } @navs;
1051 my %arg = map { $_, ''} @navs;
1052 if (defined $head) {
1053 for (qw(commit commitdiff)) {
1054 $arg{$_} = ";h=$head";
1056 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1057 for (qw(shortlog log)) {
1058 $arg{$_} = ";h=$head";
1062 $arg{tree
} .= ";h=$treehead" if defined $treehead;
1063 $arg{tree
} .= ";hb=$treebase" if defined $treebase;
1065 print "<div class=\"page_nav\">\n" .
1067 map { $_ eq $current
1069 : $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$_$arg{$_}")}, "$_")
1072 print "<br/>\n$extra<br/>\n" .
1076 sub format_paging_nav
{
1077 my ($action, $hash, $head, $page, $nrevs) = @_;
1081 if ($hash ne $head || $page) {
1082 $paging_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$action")}, "HEAD");
1084 $paging_nav .= "HEAD";
1088 $paging_nav .= " ⋅ " .
1089 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$action;h=$hash;pg=" . ($page-1)),
1090 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1092 $paging_nav .= " ⋅ prev";
1095 if ($nrevs >= (100 * ($page+1)-1)) {
1096 $paging_nav .= " ⋅ " .
1097 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$action;h=$hash;pg=" . ($page+1)),
1098 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1100 $paging_nav .= " ⋅ next";
1106 ## ......................................................................
1107 ## functions printing or outputting HTML: div
1109 sub git_print_header_div
{
1110 my ($action, $title, $hash, $hash_base) = @_;
1113 $rest .= ";h=$hash" if $hash;
1114 $rest .= ";hb=$hash_base" if $hash_base;
1116 print "<div class=\"header\">\n" .
1117 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$action$rest"),
1118 -class => "title"}, $title ?
$title : $action) . "\n" .
1122 sub git_print_page_path
{
1126 if (!defined $name) {
1127 print "<div class=\"page_path\"><b>/</b></div>\n";
1128 } elsif (defined $type && $type eq 'blob') {
1129 print "<div class=\"page_path\"><b>" .
1130 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;f=$file_name")}, esc_html
($name)) . "</b><br/></div>\n";
1132 print "<div class=\"page_path\"><b>" . esc_html
($name) . "</b><br/></div>\n";
1136 ## ......................................................................
1137 ## functions printing large fragments of HTML
1139 sub git_difftree_body
{
1140 my ($difftree, $parent) = @_;
1142 print "<div class=\"list_head\">\n";
1143 if ($#{$difftree} > 10) {
1144 print(($#{$difftree} + 1) . " files changed:\n");
1148 print "<table class=\"diff_tree\">\n";
1150 foreach my $line (@
{$difftree}) {
1151 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1152 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1153 if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1161 my $similarity = $6; # score
1162 my $file = validate_input
(unquote
($7));
1165 print "<tr class=\"dark\">\n";
1167 print "<tr class=\"light\">\n";
1171 if ($status eq "A") { # created
1173 if (S_ISREG
(oct $to_mode)) {
1174 $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
1177 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file"),
1178 -class => "list"}, esc_html
($file)) .
1180 "<td><span class=\"file_status new\">[new " . file_type
($to_mode) . "$mode_chng]</span></td>\n" .
1181 "<td class=\"link\">" .
1182 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob") .
1185 } elsif ($status eq "D") { # deleted
1187 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$parent;f=$file"),
1188 -class => "list"}, esc_html
($file)) . "</td>\n" .
1189 "<td><span class=\"file_status deleted\">[deleted " . file_type
($from_mode). "]</span></td>\n" .
1190 "<td class=\"link\">" .
1191 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$parent;f=$file")}, "blob") . " | " .
1192 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;hb=$parent;f=$file")}, "history") .
1195 } elsif ($status eq "M" || $status eq "T") { # modified, or type changed
1196 my $mode_chnge = "";
1197 if ($from_mode != $to_mode) {
1198 $mode_chnge = " <span class=\"file_status mode_chnge\">[changed";
1199 if (((oct $from_mode) & S_IFMT
) != ((oct $to_mode) & S_IFMT
)) {
1200 $mode_chnge .= " from " . file_type
($from_mode) . " to " . file_type
($to_mode);
1202 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
1203 if (S_ISREG
($from_mode) && S_ISREG
($to_mode)) {
1204 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
1205 } elsif (S_ISREG
($to_mode)) {
1206 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
1209 $mode_chnge .= "]</span>\n";
1212 if ($to_id ne $from_id) { # modified
1213 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file"),
1214 -class => "list"}, esc_html
($file));
1215 } else { # mode changed
1216 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file"),
1217 -class => "list"}, esc_html
($file));
1220 "<td>$mode_chnge</td>\n" .
1221 "<td class=\"link\">" .
1222 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, "blob");
1223 if ($to_id ne $from_id) { # modified
1224 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$file")}, "diff");
1226 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;hb=$hash;f=$file")}, "history") . "\n";
1229 } elsif ($status eq "R") { # renamed
1230 my ($from_file, $to_file) = split "\t", $file;
1232 if ($from_mode != $to_mode) {
1233 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
1236 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file"),
1237 -class => "list"}, esc_html
($to_file)) . "</td>\n" .
1238 "<td><span class=\"file_status moved\">[moved from " .
1239 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$parent;f=$from_file"),
1240 -class => "list"}, esc_html
($from_file)) .
1241 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
1242 "<td class=\"link\">" .
1243 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file")}, "blob");
1244 if ($to_id ne $from_id) {
1246 $cgi->a({-href
=> "$my_uri?" .
1247 esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file;fp=$from_file")}, "diff");
1251 } elsif ($status eq "C") { # copied
1252 my ($from_file, $to_file) = split "\t", $file;
1254 if ($from_mode != $to_mode) {
1255 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
1258 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file"),
1259 -class => "list"}, esc_html
($to_file)) . "</td>\n" .
1260 "<td><span class=\"file_status copied\">[copied from " .
1261 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$parent;f=$from_file"),
1262 -class => "list"}, esc_html
($from_file)) .
1263 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
1264 "<td class=\"link\">" .
1265 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$to_file")}, "blob");
1266 if ($to_id ne $from_id) {
1268 $cgi->a({-href
=> "$my_uri?" .
1269 esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file;fp=$from_file")}, "diff");
1272 } # we should not encounter Unmerged (U) or Unknown (X) status
1278 sub git_shortlog_body
{
1279 # uses global variable $project
1280 my ($revlist, $from, $to, $refs, $extra) = @_;
1281 $from = 0 unless defined $from;
1282 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1284 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
1286 for (my $i = $from; $i <= $to; $i++) {
1287 my $commit = $revlist->[$i];
1288 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
1289 my $ref = format_ref_marker
($refs, $commit);
1290 my %co = parse_commit
($commit);
1292 print "<tr class=\"dark\">\n";
1294 print "<tr class=\"light\">\n";
1297 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1298 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1299 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
1301 print format_subject_html
($co{'title'}, $co{'title_short'}, "p=$project;a=commit;h=$commit", $ref);
1303 "<td class=\"link\">" .
1304 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") . " | " .
1305 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
1309 if (defined $extra) {
1311 "<td colspan=\"4\">$extra</td>\n" .
1317 sub git_history_body
{
1318 # Warning: assumes constant type (blob or tree) during history
1319 my ($fd, $refs, $hash_base, $ftype, $extra) = @_;
1321 print "<table class=\"history\" cellspacing=\"0\">\n";
1323 while (my $line = <$fd>) {
1324 if ($line !~ m/^([0-9a-fA-F]{40})/) {
1329 my %co = parse_commit
($commit);
1334 my $ref = format_ref_marker
($refs, $commit);
1337 print "<tr class=\"dark\">\n";
1339 print "<tr class=\"light\">\n";
1342 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1343 # shortlog uses chop_str($co{'author_name'}, 10)
1344 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
1346 # originally git_history used chop_str($co{'title'}, 50)
1347 print format_subject_html
($co{'title'}, $co{'title_short'}, "p=$project;a=commit;h=$commit", $ref);
1349 "<td class=\"link\">" .
1350 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") . " | " .
1351 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") . " | " .
1352 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$ftype;hb=$commit;f=$file_name")}, $ftype);
1354 if ($ftype eq 'blob') {
1355 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
1356 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
1357 if (defined $blob_current && defined $blob_parent &&
1358 $blob_current ne $blob_parent) {
1360 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff;h=$blob_current;hp=$blob_parent;hb=$commit;f=$file_name")},
1367 if (defined $extra) {
1369 "<td colspan=\"4\">$extra</td>\n" .
1376 # uses global variable $project
1377 my ($taglist, $from, $to, $extra) = @_;
1378 $from = 0 unless defined $from;
1379 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1381 print "<table class=\"tags\" cellspacing=\"0\">\n";
1383 for (my $i = $from; $i <= $to; $i++) {
1384 my $entry = $taglist->[$i];
1386 my $comment_lines = $tag{'comment'};
1387 my $comment = shift @
$comment_lines;
1389 if (defined $comment) {
1390 $comment_short = chop_str
($comment, 30, 5);
1393 print "<tr class=\"dark\">\n";
1395 print "<tr class=\"light\">\n";
1398 print "<td><i>$tag{'age'}</i></td>\n" .
1400 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}"),
1401 -class => "list"}, "<b>" . esc_html
($tag{'name'}) . "</b>") .
1404 if (defined $comment) {
1405 print format_subject_html
($comment, $comment_short, "p=$project;a=tag;h=$tag{'id'}");
1408 "<td class=\"selflink\">";
1409 if ($tag{'type'} eq "tag") {
1410 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tag;h=$tag{'id'}")}, "tag");
1415 "<td class=\"link\">" . " | " .
1416 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'reftype'};h=$tag{'refid'}")}, $tag{'reftype'});
1417 if ($tag{'reftype'} eq "commit") {
1418 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") .
1419 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'refid'}")}, "log");
1420 } elsif ($tag{'reftype'} eq "blob") {
1421 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$tag{'refid'}")}, "raw");
1426 if (defined $extra) {
1428 "<td colspan=\"5\">$extra</td>\n" .
1434 sub git_heads_body
{
1435 # uses global variable $project
1436 my ($taglist, $head, $from, $to, $extra) = @_;
1437 $from = 0 unless defined $from;
1438 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1440 print "<table class=\"heads\" cellspacing=\"0\">\n";
1442 for (my $i = $from; $i <= $to; $i++) {
1443 my $entry = $taglist->[$i];
1445 my $curr = $tag{'id'} eq $head;
1447 print "<tr class=\"dark\">\n";
1449 print "<tr class=\"light\">\n";
1452 print "<td><i>$tag{'age'}</i></td>\n" .
1453 ($tag{'id'} eq $head ?
"<td class=\"current_head\">" : "<td>") .
1454 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}"),
1455 -class => "list"}, "<b>" . esc_html
($tag{'name'}) . "</b>") .
1457 "<td class=\"link\">" .
1458 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$tag{'name'}")}, "shortlog") . " | " .
1459 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=log;h=$tag{'name'}")}, "log") .
1463 if (defined $extra) {
1465 "<td colspan=\"3\">$extra</td>\n" .
1471 ## ----------------------------------------------------------------------
1472 ## functions printing large fragments, format as one of arguments
1474 sub git_diff_print
{
1476 my $from_name = shift;
1478 my $to_name = shift;
1479 my $format = shift || "html";
1481 my $from_tmp = "/dev/null";
1482 my $to_tmp = "/dev/null";
1485 # create tmp from-file
1486 if (defined $from) {
1487 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
1488 open my $fd2, "> $from_tmp";
1489 open my $fd, "-|", $GIT, "cat-file", "blob", $from;
1496 # create tmp to-file
1498 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
1499 open my $fd2, "> $to_tmp";
1500 open my $fd, "-|", $GIT, "cat-file", "blob", $to;
1507 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
1508 if ($format eq "plain") {
1513 while (my $line = <$fd>) {
1515 my $char = substr($line, 0, 1);
1516 my $diff_class = "";
1518 $diff_class = " add";
1519 } elsif ($char eq "-") {
1520 $diff_class = " rem";
1521 } elsif ($char eq "@") {
1522 $diff_class = " chunk_header";
1523 } elsif ($char eq "\\") {
1527 $line = untabify
($line);
1528 print "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
1533 if (defined $from) {
1542 ## ======================================================================
1543 ## ======================================================================
1546 sub git_project_list
{
1547 my $order = $cgi->param('o');
1548 if (defined $order && $order !~ m/project|descr|owner|age/) {
1549 die_error
(undef, "Unknown order parameter");
1552 my @list = git_get_projects_list
();
1555 die_error
(undef, "No projects found");
1557 foreach my $pr (@list) {
1558 my $head = git_get_head_hash
($pr->{'path'});
1559 if (!defined $head) {
1562 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
1563 my %co = parse_commit
($head);
1567 $pr->{'commit'} = \
%co;
1568 if (!defined $pr->{'descr'}) {
1569 my $descr = git_get_project_description
($pr->{'path'}) || "";
1570 $pr->{'descr'} = chop_str
($descr, 25, 5);
1572 if (!defined $pr->{'owner'}) {
1573 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
1575 push @projects, $pr;
1579 if (-f
$home_text) {
1580 print "<div class=\"index_include\">\n";
1581 open (my $fd, $home_text);
1586 print "<table class=\"project_list\">\n" .
1588 $order ||= "project";
1589 if ($order eq "project") {
1590 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
1591 print "<th>Project</th>\n";
1594 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=project"),
1595 -class => "header"}, "Project") .
1598 if ($order eq "descr") {
1599 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
1600 print "<th>Description</th>\n";
1603 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=descr"),
1604 -class => "header"}, "Description") .
1607 if ($order eq "owner") {
1608 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
1609 print "<th>Owner</th>\n";
1612 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=owner"),
1613 -class => "header"}, "Owner") .
1616 if ($order eq "age") {
1617 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
1618 print "<th>Last Change</th>\n";
1621 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=age"),
1622 -class => "header"}, "Last Change") .
1625 print "<th></th>\n" .
1628 foreach my $pr (@projects) {
1630 print "<tr class=\"dark\">\n";
1632 print "<tr class=\"light\">\n";
1635 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=summary"),
1636 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
1637 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
1638 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
1639 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" .
1640 $pr->{'commit'}{'age_string'} . "</td>\n" .
1641 "<td class=\"link\">" .
1642 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=summary")}, "summary") . " | " .
1643 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=shortlog")}, "shortlog") . " | " .
1644 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=log")}, "log") .
1653 my $descr = git_get_project_description
($project) || "none";
1654 my $head = git_get_head_hash
($project);
1655 my %co = parse_commit
($head);
1656 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
1658 my $owner = git_get_project_owner
($project);
1660 my $refs = git_get_references
();
1662 git_print_page_nav
('summary','', $head);
1664 print "<div class=\"title\"> </div>\n";
1665 print "<table cellspacing=\"0\">\n" .
1666 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
1667 "<tr><td>owner</td><td>$owner</td></tr>\n" .
1668 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n" .
1671 open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_get_head_hash
($project)
1672 or die_error
(undef, "Open git-rev-list failed");
1673 my @revlist = map { chomp; $_ } <$fd>;
1675 git_print_header_div
('shortlog');
1676 git_shortlog_body
(\
@revlist, 0, 15, $refs,
1677 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog")}, "..."));
1679 my $taglist = git_get_refs_list
("refs/tags");
1680 if (defined @
$taglist) {
1681 git_print_header_div
('tags');
1682 git_tags_body
($taglist, 0, 15,
1683 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tags")}, "..."));
1686 my $headlist = git_get_refs_list
("refs/heads");
1687 if (defined @
$headlist) {
1688 git_print_header_div
('heads');
1689 git_heads_body
($headlist, $head, 0, 15,
1690 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=heads")}, "..."));
1697 my $head = git_get_head_hash
($project);
1699 git_print_page_nav
('','', $head,undef,$head);
1700 my %tag = parse_tag
($hash);
1701 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
1702 print "<div class=\"title_text\">\n" .
1703 "<table cellspacing=\"0\">\n" .
1705 "<td>object</td>\n" .
1706 "<td>" . $cgi->a({-class => "list", -href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'object'}) . "</td>\n" .
1707 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=$tag{'type'};h=$tag{'object'}")}, $tag{'type'}) . "</td>\n" .
1709 if (defined($tag{'author'})) {
1710 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
1711 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
1712 print "<tr><td></td><td>" . $ad{'rfc2822'} . sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) . "</td></tr>\n";
1714 print "</table>\n\n" .
1716 print "<div class=\"page_body\">";
1717 my $comment = $tag{'comment'};
1718 foreach my $line (@
$comment) {
1719 print esc_html
($line) . "<br/>\n";
1728 die_error
(undef, "Permission denied") if (!git_get_project_config_bool
('blame'));
1729 die_error
('404 Not Found', "File name not defined") if (!$file_name);
1730 $hash_base ||= git_get_head_hash
($project);
1731 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
1732 my %co = parse_commit
($hash_base)
1733 or die_error
(undef, "Reading commit failed");
1734 if (!defined $hash) {
1735 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
1736 or die_error
(undef, "Error looking up file");
1738 $ftype = git_get_type
($hash);
1739 if ($ftype !~ "blob") {
1740 die_error
("400 Bad Request", "Object is not a blob");
1742 open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base)
1743 or die_error
(undef, "Open git-blame failed");
1746 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") .
1747 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;f=$file_name")}, "head");
1748 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1749 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
1750 git_print_page_path
($file_name, $ftype);
1751 my @rev_color = (qw(light2 dark2));
1752 my $num_colors = scalar(@rev_color);
1753 my $current_color = 0;
1755 print "<div class=\"page_body\">\n";
1756 print "<table class=\"blame\">\n";
1757 print "<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n";
1759 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
1761 my $rev = substr($full_rev, 0, 8);
1765 if (!defined $last_rev) {
1766 $last_rev = $full_rev;
1767 } elsif ($last_rev ne $full_rev) {
1768 $last_rev = $full_rev;
1769 $current_color = ++$current_color % $num_colors;
1771 print "<tr class=\"$rev_color[$current_color]\">\n";
1772 print "<td class=\"sha1\">" .
1773 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$full_rev;f=$file_name")}, esc_html
($rev)) . "</td>\n";
1774 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" . esc_html
($lineno) . "</a></td>\n";
1775 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
1780 close $fd or print "Reading blob failed\n";
1786 die_error
('403 Permission denied', "Permission denied") if (!git_get_project_config_bool
('blame'));
1787 die_error
('404 Not Found', "File name not defined") if (!$file_name);
1788 $hash_base ||= git_get_head_hash
($project);
1789 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
1790 my %co = parse_commit
($hash_base)
1791 or die_error
(undef, "Reading commit failed");
1792 if (!defined $hash) {
1793 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
1794 or die_error
(undef, "Error lookup file");
1796 open ($fd, "-|", $GIT, "annotate", '-l', '-t', '-r', $file_name, $hash_base)
1797 or die_error
(undef, "Open git-annotate failed");
1800 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, "blob") .
1801 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;f=$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, 'blob');
1805 print "<div class=\"page_body\">\n";
1807 <table class="blame">
1816 my @line_class = (qw(light dark));
1817 my $line_class_len = scalar (@line_class);
1818 my $line_class_num = $#line_class;
1819 while (my $line = <$fd>) {
1831 $line_class_num = ($line_class_num + 1) % $line_class_len;
1833 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) \+\d\d\d\d\t(\d+)\)(.*)$/) {
1840 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
1843 $short_rev = substr ($long_rev, 0, 8);
1844 $age = time () - $time;
1845 $age_str = age_string
($age);
1846 $age_str =~ s/ / /g;
1847 $age_class = age_class
($age);
1848 $author = esc_html
($author);
1849 $author =~ s/ / /g;
1851 $data = untabify
($data);
1852 $data = esc_html
($data);
1855 <tr class="$line_class[$line_class_num]">
1856 <td class="sha1"><a href="$my_uri?${\esc_param ("p=$project;a=commit;h=$long_rev")}" class="text">$short_rev..</a></td>
1857 <td class="$age_class">$age_str</td>
1859 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
1860 <td class="pre">$data</td>
1863 } # while (my $line = <$fd>)
1864 print "</table>\n\n";
1865 close $fd or print "Reading blob failed.\n";
1871 my $head = git_get_head_hash
($project);
1873 git_print_page_nav
('','', $head,undef,$head);
1874 git_print_header_div
('summary', $project);
1876 my $taglist = git_get_refs_list
("refs/tags");
1877 if (defined @
$taglist) {
1878 git_tags_body
($taglist);
1884 my $head = git_get_head_hash
($project);
1886 git_print_page_nav
('','', $head,undef,$head);
1887 git_print_header_div
('summary', $project);
1889 my $taglist = git_get_refs_list
("refs/heads");
1890 if (defined @
$taglist) {
1891 git_heads_body
($taglist, $head);
1896 sub git_blob_plain
{
1897 if (!defined $hash) {
1898 if (defined $file_name) {
1899 my $base = $hash_base || git_get_head_hash
($project);
1900 $hash = git_get_hash_by_path
($base, $file_name, "blob")
1901 or die_error
(undef, "Error lookup file");
1903 die_error
(undef, "No file name defined");
1907 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
1908 or die_error
(undef, "Couldn't cat $file_name, $hash");
1910 $type ||= blob_mimetype
($fd, $file_name);
1912 # save as filename, even when no $file_name is given
1913 my $save_as = "$hash";
1914 if (defined $file_name) {
1915 $save_as = $file_name;
1916 } elsif ($type =~ m/^text\//) {
1920 print $cgi->header(-type
=> "$type", '-content-disposition' => "inline; filename=\"$save_as\"");
1922 binmode STDOUT
, ':raw';
1924 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
1930 if (!defined $hash) {
1931 if (defined $file_name) {
1932 my $base = $hash_base || git_get_head_hash
($project);
1933 $hash = git_get_hash_by_path
($base, $file_name, "blob")
1934 or die_error
(undef, "Error lookup file");
1936 die_error
(undef, "No file name defined");
1939 my $have_blame = git_get_project_config_bool
('blame');
1940 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
1941 or die_error
(undef, "Couldn't cat $file_name, $hash");
1942 my $mimetype = blob_mimetype
($fd, $file_name);
1943 if ($mimetype !~ m/^text\//) {
1945 return git_blob_plain
($mimetype);
1948 my $formats_nav = '';
1949 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
1950 if (defined $file_name) {
1952 $formats_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;h=$hash;hb=$hash_base;f=$file_name")}, "blame") . " | ";
1955 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$hash;f=$file_name")}, "plain") .
1956 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;hb=HEAD;f=$file_name")}, "head");
1958 $formats_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$hash")}, "plain");
1960 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1961 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
1963 print "<div class=\"page_nav\">\n" .
1964 "<br/><br/></div>\n" .
1965 "<div class=\"title\">$hash</div>\n";
1967 git_print_page_path
($file_name, "blob");
1968 print "<div class=\"page_body\">\n";
1970 while (my $line = <$fd>) {
1973 $line = untabify
($line);
1974 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", $nr, $nr, $nr, esc_html
($line);
1976 close $fd or print "Reading blob failed.\n";
1982 if (!defined $hash) {
1983 $hash = git_get_head_hash
($project);
1984 if (defined $file_name) {
1985 my $base = $hash_base || $hash;
1986 $hash = git_get_hash_by_path
($base, $file_name, "tree");
1988 if (!defined $hash_base) {
1993 open my $fd, "-|", $GIT, "ls-tree", '-z', $hash
1994 or die_error
(undef, "Open git-ls-tree failed");
1995 my @entries = map { chomp; $_ } <$fd>;
1996 close $fd or die_error
(undef, "Reading tree failed");
1999 my $refs = git_get_references
();
2000 my $ref = format_ref_marker
($refs, $hash_base);
2004 my $have_blame = git_get_project_config_bool
('blame');
2005 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2006 $base_key = ";hb=$hash_base";
2007 git_print_page_nav
('tree','', $hash_base);
2008 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
2010 print "<div class=\"page_nav\">\n";
2011 print "<br/><br/></div>\n";
2012 print "<div class=\"title\">$hash</div>\n";
2014 if (defined $file_name) {
2015 $base = esc_html
("$file_name/");
2017 git_print_page_path
($file_name, 'tree');
2018 print "<div class=\"page_body\">\n";
2019 print "<table cellspacing=\"0\">\n";
2021 foreach my $line (@entries) {
2022 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2023 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
2027 my $t_name = validate_input
($4);
2029 print "<tr class=\"dark\">\n";
2031 print "<tr class=\"light\">\n";
2034 print "<td class=\"mode\">" . mode_str
($t_mode) . "</td>\n";
2035 if ($t_type eq "blob") {
2036 print "<td class=\"list\">" .
2037 $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)) .
2039 "<td class=\"link\">" .
2040 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name")}, "blob");
2042 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;h=$t_hash$base_key;f=$base$t_name")}, "blame");
2044 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;h=$t_hash;hb=$hash_base;f=$base$t_name")}, "history") .
2045 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$t_hash;f=$base$t_name")}, "raw") .
2047 } elsif ($t_type eq "tree") {
2048 print "<td class=\"list\">" .
2049 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, esc_html
($t_name)) .
2051 "<td class=\"link\">" .
2052 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, "tree") .
2053 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;hb=$hash_base;f=$base$t_name")}, "history") .
2058 print "</table>\n" .
2064 my $head = git_get_head_hash
($project);
2065 if (!defined $hash) {
2068 if (!defined $page) {
2071 my $refs = git_get_references
();
2073 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2074 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2075 or die_error
(undef, "Open git-rev-list failed");
2076 my @revlist = map { chomp; $_ } <$fd>;
2079 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
2082 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
2085 my %co = parse_commit
($hash);
2087 git_print_header_div
('summary', $project);
2088 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
2090 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2091 my $commit = $revlist[$i];
2092 my $ref = format_ref_marker
($refs, $commit);
2093 my %co = parse_commit
($commit);
2095 my %ad = parse_date
($co{'author_epoch'});
2096 git_print_header_div
('commit',
2097 "<span class=\"age\">$co{'age_string'}</span>" .
2098 esc_html
($co{'title'}) . $ref,
2100 print "<div class=\"title_text\">\n" .
2101 "<div class=\"log_link\">\n" .
2102 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$commit")}, "commit") .
2103 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$commit")}, "commitdiff") .
2106 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
2108 "<div class=\"log_body\">\n";
2109 my $comment = $co{'comment'};
2111 foreach my $line (@
$comment) {
2112 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2123 print format_log_line_html
($line) . "<br/>\n";
2134 my %co = parse_commit
($hash);
2136 die_error
(undef, "Unknown commit object");
2138 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2139 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2141 my $parent = $co{'parent'};
2142 if (!defined $parent) {
2145 open my $fd, "-|", $GIT, "diff-tree", '-r', '-M', $parent, $hash
2146 or die_error
(undef, "Open git-diff-tree failed");
2147 my @difftree = map { chomp; $_ } <$fd>;
2148 close $fd or die_error
(undef, "Reading git-diff-tree failed");
2150 # non-textual hash id's can be cached
2152 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2155 my $refs = git_get_references
();
2156 my $ref = format_ref_marker
($refs, $co{'id'});
2157 my $formats_nav = '';
2158 if (defined $file_name && defined $co{'parent'}) {
2159 my $parent = $co{'parent'};
2160 $formats_nav .= $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;hb=$parent;f=$file_name")}, "blame");
2162 git_header_html
(undef, $expires);
2163 git_print_page_nav
('commit', defined $co{'parent'} ?
'' : 'commitdiff',
2164 $hash, $co{'tree'}, $hash,
2167 if (defined $co{'parent'}) {
2168 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
2170 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
2172 print "<div class=\"title_text\">\n" .
2173 "<table cellspacing=\"0\">\n";
2174 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
2176 "<td></td><td> $ad{'rfc2822'}";
2177 if ($ad{'hour_local'} < 6) {
2178 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2180 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2184 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
2185 print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
2186 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
2189 "<td class=\"sha1\">" .
2190 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash"), class => "list"}, $co{'tree'}) .
2192 "<td class=\"link\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree") .
2195 my $parents = $co{'parents'};
2196 foreach my $par (@
$parents) {
2199 "<td class=\"sha1\">" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$par"), class => "list"}, $par) . "</td>" .
2200 "<td class=\"link\">" .
2201 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$par")}, "commit") .
2202 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff;h=$hash;hp=$par")}, "commitdiff") .
2208 print "<div class=\"page_body\">\n";
2209 my $comment = $co{'comment'};
2212 foreach my $line (@
$comment) {
2213 # print only one empty line
2215 if ($empty || $signed) {
2222 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2224 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2227 print format_log_line_html
($line) . "<br/>\n";
2232 git_difftree_body
(\
@difftree, $parent);
2238 mkdir($git_temp, 0700);
2240 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2242 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff_plain;h=$hash;hp=$hash_parent")}, "plain");
2243 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2244 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2246 print "<div class=\"page_nav\">\n" .
2247 "<br/><br/></div>\n" .
2248 "<div class=\"title\">$hash vs $hash_parent</div>\n";
2250 git_print_page_path
($file_name, "blob");
2251 print "<div class=\"page_body\">\n" .
2252 "<div class=\"diff_info\">blob:" .
2253 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name")}, $hash_parent) .
2255 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, $hash) .
2257 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
2262 sub git_blobdiff_plain
{
2263 mkdir($git_temp, 0700);
2264 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8');
2265 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
2268 sub git_commitdiff
{
2269 mkdir($git_temp, 0700);
2270 my %co = parse_commit
($hash);
2272 die_error
(undef, "Unknown commit object");
2274 if (!defined $hash_parent) {
2275 $hash_parent = $co{'parent'} || '--root';
2277 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2278 or die_error
(undef, "Open git-diff-tree failed");
2279 my @difftree = map { chomp; $_ } <$fd>;
2280 close $fd or die_error
(undef, "Reading git-diff-tree failed");
2282 # non-textual hash id's can be cached
2284 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2287 my $refs = git_get_references
();
2288 my $ref = format_ref_marker
($refs, $co{'id'});
2290 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent")}, "plain");
2291 git_header_html
(undef, $expires);
2292 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
2293 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
2294 print "<div class=\"page_body\">\n";
2295 my $comment = $co{'comment'};
2298 my @log = @
$comment;
2299 # remove first and empty lines after that
2301 while (defined $log[0] && $log[0] eq "") {
2304 foreach my $line (@log) {
2305 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2316 print format_log_line_html
($line) . "<br/>\n";
2319 foreach my $line (@difftree) {
2320 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2321 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2322 if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2330 my $file = validate_input
(unquote
($6));
2331 if ($status eq "A") {
2332 print "<div class=\"diff_info\">" . file_type
($to_mode) . ":" .
2333 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id) . "(new)" .
2335 git_diff_print
(undef, "/dev/null", $to_id, "b/$file");
2336 } elsif ($status eq "D") {
2337 print "<div class=\"diff_info\">" . file_type
($from_mode) . ":" .
2338 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash_parent;f=$file")}, $from_id) . "(deleted)" .
2340 git_diff_print
($from_id, "a/$file", undef, "/dev/null");
2341 } elsif ($status eq "M") {
2342 if ($from_id ne $to_id) {
2343 print "<div class=\"diff_info\">" .
2344 file_type
($from_mode) . ":" .
2345 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash_parent;f=$file")}, $from_id) .
2347 file_type
($to_mode) . ":" .
2348 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id);
2350 git_diff_print
($from_id, "a/$file", $to_id, "b/$file");
2359 sub git_commitdiff_plain
{
2360 mkdir($git_temp, 0700);
2361 my %co = parse_commit
($hash);
2363 die_error
(undef, "Unknown commit object");
2365 if (!defined $hash_parent) {
2366 $hash_parent = $co{'parent'} || '--root';
2368 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2369 or die_error
(undef, "Open git-diff-tree failed");
2370 my @difftree = map { chomp; $_ } <$fd>;
2371 close $fd or die_error
(undef, "Reading diff-tree failed");
2373 # try to figure out the next tag after this commit
2375 my $refs = git_get_references
("tags");
2376 open $fd, "-|", $GIT, "rev-list", "HEAD";
2377 my @commits = map { chomp; $_ } <$fd>;
2379 foreach my $commit (@commits) {
2380 if (defined $refs->{$commit}) {
2381 $tagname = $refs->{$commit}
2383 if ($commit eq $hash) {
2388 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8', '-content-disposition' => "inline; filename=\"git-$hash.patch\"");
2389 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2390 my $comment = $co{'comment'};
2391 print "From: $co{'author'}\n" .
2392 "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
2393 "Subject: $co{'title'}\n";
2394 if (defined $tagname) {
2395 print "X-Git-Tag: $tagname\n";
2397 print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
2400 foreach my $line (@
$comment) {;
2405 foreach my $line (@difftree) {
2406 if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2413 if ($status eq "A") {
2414 git_diff_print
(undef, "/dev/null", $to_id, "b/$file", "plain");
2415 } elsif ($status eq "D") {
2416 git_diff_print
($from_id, "a/$file", undef, "/dev/null", "plain");
2417 } elsif ($status eq "M") {
2418 git_diff_print
($from_id, "a/$file", $to_id, "b/$file", "plain");
2424 if (!defined $hash_base) {
2425 $hash_base = git_get_head_hash
($project);
2428 my %co = parse_commit
($hash_base);
2430 die_error
(undef, "Unknown commit object");
2432 my $refs = git_get_references
();
2434 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base);
2435 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2436 if (!defined $hash && defined $file_name) {
2437 $hash = git_get_hash_by_path
($hash_base, $file_name);
2439 if (defined $hash) {
2440 $ftype = git_get_type
($hash);
2442 git_print_page_path
($file_name, $ftype);
2445 $GIT, "rev-list", "--full-history", $hash_base, "--", $file_name;
2446 git_history_body
($fd, $refs, $hash_base, $ftype);
2453 if (!defined $searchtext) {
2454 die_error
(undef, "Text field empty");
2456 if (!defined $hash) {
2457 $hash = git_get_head_hash
($project);
2459 my %co = parse_commit
($hash);
2461 die_error
(undef, "Unknown commit object");
2463 # pickaxe may take all resources of your box and run for several minutes
2464 # with every query - so decide by yourself how public you make this feature :)
2465 my $commit_search = 1;
2466 my $author_search = 0;
2467 my $committer_search = 0;
2468 my $pickaxe_search = 0;
2469 if ($searchtext =~ s/^author\\://i) {
2471 } elsif ($searchtext =~ s/^committer\\://i) {
2472 $committer_search = 1;
2473 } elsif ($searchtext =~ s/^pickaxe\\://i) {
2475 $pickaxe_search = 1;
2478 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
2479 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
2481 print "<table cellspacing=\"0\">\n";
2483 if ($commit_search) {
2485 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", $hash or next;
2486 while (my $commit_text = <$fd>) {
2487 if (!grep m/$searchtext/i, $commit_text) {
2490 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
2493 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
2496 my @commit_lines = split "\n", $commit_text;
2497 my %co = parse_commit
(undef, \
@commit_lines);
2502 print "<tr class=\"dark\">\n";
2504 print "<tr class=\"light\">\n";
2507 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2508 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2510 $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/>");
2511 my $comment = $co{'comment'};
2512 foreach my $line (@
$comment) {
2513 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2514 my $lead = esc_html
($1) || "";
2515 $lead = chop_str
($lead, 30, 10);
2516 my $match = esc_html
($2) || "";
2517 my $trail = esc_html
($3) || "";
2518 $trail = chop_str
($trail, 30, 10);
2519 my $text = "$lead<span class=\"match\">$match</span>$trail";
2520 print chop_str
($text, 80, 5) . "<br/>\n";
2524 "<td class=\"link\">" .
2525 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2526 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2533 if ($pickaxe_search) {
2535 open my $fd, "-|", "$GIT rev-list $hash | $GIT diff-tree -r --stdin -S\'$searchtext\'";
2538 while (my $line = <$fd>) {
2539 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2542 $set{'from_id'} = $3;
2544 $set{'id'} = $set{'to_id'};
2545 if ($set{'id'} =~ m/0{40}/) {
2546 $set{'id'} = $set{'from_id'};
2548 if ($set{'id'} =~ m/0{40}/) {
2552 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
2555 print "<tr class=\"dark\">\n";
2557 print "<tr class=\"light\">\n";
2560 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2561 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2563 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" .
2564 esc_html
(chop_str
($co{'title'}, 50)) . "</b><br/>");
2565 while (my $setref = shift @files) {
2567 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}"), class => "list"},
2568 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
2572 "<td class=\"link\">" .
2573 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2574 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2578 %co = parse_commit
($1);
2588 my $head = git_get_head_hash
($project);
2589 if (!defined $hash) {
2592 if (!defined $page) {
2595 my $refs = git_get_references
();
2597 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2598 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2599 or die_error
(undef, "Open git-rev-list failed");
2600 my @revlist = map { chomp; $_ } <$fd>;
2603 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
2605 if ($#revlist >= (100 * ($page+1)-1)) {
2607 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)),
2608 -title
=> "Alt-n"}, "next");
2613 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
2614 git_print_header_div
('summary', $project);
2616 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
2621 ## ......................................................................
2622 ## feeds (RSS, OPML)
2625 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
2626 open my $fd, "-|", $GIT, "rev-list", "--max-count=150", git_get_head_hash
($project)
2627 or die_error
(undef, "Open git-rev-list failed");
2628 my @revlist = map { chomp; $_ } <$fd>;
2629 close $fd or die_error
(undef, "Reading git-rev-list failed");
2630 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
2631 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
2632 "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
2633 print "<channel>\n";
2634 print "<title>$project</title>\n".
2635 "<link>" . esc_html
("$my_url?p=$project;a=summary") . "</link>\n".
2636 "<description>$project log</description>\n".
2637 "<language>en</language>\n";
2639 for (my $i = 0; $i <= $#revlist; $i++) {
2640 my $commit = $revlist[$i];
2641 my %co = parse_commit
($commit);
2642 # we read 150, we always show 30 and the ones more recent than 48 hours
2643 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
2646 my %cd = parse_date
($co{'committer_epoch'});
2647 open $fd, "-|", $GIT, "diff-tree", '-r', $co{'parent'}, $co{'id'} or next;
2648 my @difftree = map { chomp; $_ } <$fd>;
2652 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
2654 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
2655 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
2656 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
2657 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
2658 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
2659 "<content:encoded>" .
2661 my $comment = $co{'comment'};
2662 foreach my $line (@
$comment) {
2663 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
2664 print "$line<br/>\n";
2667 foreach my $line (@difftree) {
2668 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
2671 my $file = validate_input
(unquote
($7));
2672 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
2673 print "$file<br/>\n";
2676 "</content:encoded>\n" .
2679 print "</channel></rss>";
2683 my @list = git_get_projects_list
();
2685 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
2686 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
2687 "<opml version=\"1.0\">\n".
2689 " <title>$site_name Git OPML Export</title>\n".
2692 "<outline text=\"git RSS feeds\">\n";
2694 foreach my $pr (@list) {
2696 my $head = git_get_head_hash
($proj{'path'});
2697 if (!defined $head) {
2700 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
2701 my %co = parse_commit
($head);
2706 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
2707 my $rss = "$my_url?p=$proj{'path'};a=rss";
2708 my $html = "$my_url?p=$proj{'path'};a=summary";
2709 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
2711 print "</outline>\n".