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(";",
207 map { "$mapping{$_}=$params{$_}" } keys %params
214 ## ======================================================================
215 ## validation, quoting/unquoting and escaping
220 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
223 if ($input =~ m/(^|\/)(|\
.|\
.\
.)($|\
/)/) {
226 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\
-\
+\#\
~\
%]/) {
232 # quote unsafe chars, but keep the slash, even when it's not
233 # correct, but quoted slashes look too horrible in bookmarks
236 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
242 # replace invalid utf8 character with SUBSTITUTION sequence
245 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
246 $str = escapeHTML
($str);
247 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
251 # git may return quoted and escaped filenames
254 if ($str =~ m/^"(.*)"$/) {
256 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
261 # escape tabs (convert tabs to spaces)
265 while ((my $pos = index($line, "\t")) != -1) {
266 if (my $count = (8 - ($pos % 8))) {
267 my $spaces = ' ' x
$count;
268 $line =~ s/\t/$spaces/;
275 ## ----------------------------------------------------------------------
276 ## HTML aware string manipulation
281 my $add_len = shift || 10;
283 # allow only $len chars, but don't cut a word if it would fit in $add_len
284 # if it doesn't fit, cut it if it's still longer than the dots we would add
285 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
288 if (length($tail) > 4) {
290 $body =~ s/&[^;]*$//; # remove chopped character entities
295 ## ----------------------------------------------------------------------
296 ## functions returning short strings
298 # CSS class for given age value (in seconds)
302 if ($age < 60*60*2) {
304 } elsif ($age < 60*60*24*2) {
311 # convert age in seconds to "nn units ago" string
316 if ($age > 60*60*24*365*2) {
317 $age_str = (int $age/60/60/24/365);
318 $age_str .= " years ago";
319 } elsif ($age > 60*60*24*(365/12)*2) {
320 $age_str = int $age/60/60/24/(365/12);
321 $age_str .= " months ago";
322 } elsif ($age > 60*60*24*7*2) {
323 $age_str = int $age/60/60/24/7;
324 $age_str .= " weeks ago";
325 } elsif ($age > 60*60*24*2) {
326 $age_str = int $age/60/60/24;
327 $age_str .= " days ago";
328 } elsif ($age > 60*60*2) {
329 $age_str = int $age/60/60;
330 $age_str .= " hours ago";
331 } elsif ($age > 60*2) {
332 $age_str = int $age/60;
333 $age_str .= " min ago";
336 $age_str .= " sec ago";
338 $age_str .= " right now";
343 # convert file mode in octal to symbolic file mode string
345 my $mode = oct shift;
347 if (S_ISDIR
($mode & S_IFMT
)) {
349 } elsif (S_ISLNK
($mode)) {
351 } elsif (S_ISREG
($mode)) {
352 # git cares only about the executable bit
353 if ($mode & S_IXUSR
) {
363 # convert file mode in octal to file type string
365 my $mode = oct shift;
367 if (S_ISDIR
($mode & S_IFMT
)) {
369 } elsif (S_ISLNK
($mode)) {
371 } elsif (S_ISREG
($mode)) {
378 ## ----------------------------------------------------------------------
379 ## functions returning short HTML fragments, or transforming HTML fragments
380 ## which don't beling to other sections
382 # format line of commit message or tag comment
383 sub format_log_line_html
{
386 $line = esc_html
($line);
387 $line =~ s/ / /g;
388 if ($line =~ m/([0-9a-fA-F]{40})/) {
390 if (git_get_type
($hash_text) eq "commit") {
391 my $link = $cgi->a({-class => "text", -href
=> href
(action
=>"commit", hash
=>$hash_text)}, $hash_text);
392 $line =~ s/$hash_text/$link/;
398 # format marker of refs pointing to given object
399 sub format_ref_marker
{
400 my ($refs, $id) = @_;
403 if (defined $refs->{$id}) {
404 foreach my $ref (@
{$refs->{$id}}) {
405 my ($type, $name) = qw();
406 # e.g. tags/v2.6.11 or heads/next
407 if ($ref =~ m!^(.*?)s?/(.*)$!) {
415 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
420 return ' <span class="refs">'. $markers . '</span>';
426 # format, perhaps shortened and with markers, title line
427 sub format_subject_html
{
428 my ($long, $short, $href, $extra) = @_;
429 $extra = '' unless defined($extra);
431 if (length($short) < length($long)) {
432 return $cgi->a({-href
=> $href, -class => "list",
434 esc_html
($short) . $extra);
436 return $cgi->a({-href
=> $href, -class => "list"},
437 esc_html
($long) . $extra);
441 ## ----------------------------------------------------------------------
442 ## git utility subroutines, invoking git commands
444 # get HEAD ref of given project as hash
445 sub git_get_head_hash
{
447 my $oENV = $ENV{'GIT_DIR'};
449 $ENV{'GIT_DIR'} = "$projectroot/$project";
450 if (open my $fd, "-|", $GIT, "rev-parse", "--verify", "HEAD") {
453 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
458 $ENV{'GIT_DIR'} = $oENV;
463 # get type of given object
467 open my $fd, "-|", $GIT, "cat-file", '-t', $hash or return;
474 sub git_get_project_config
{
477 return unless ($key);
478 $key =~ s/^gitweb\.//;
479 return if ($key =~ m/\W/);
481 my $val = qx($GIT repo
-config
--get gitweb
.$key);
485 sub git_get_project_config_bool
{
486 my $val = git_get_project_config
(@_);
487 if ($val and $val =~ m/true|yes|on/) {
490 return; # implicit false
493 # get hash of given path at given ref
494 sub git_get_hash_by_path
{
496 my $path = shift || return undef;
500 open my $fd, "-|", $GIT, "ls-tree", $base, "--", $path
501 or die_error
(undef, "Open git-ls-tree failed");
503 close $fd or return undef;
505 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
506 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
510 ## ......................................................................
511 ## git utility functions, directly accessing git repository
513 # assumes that PATH is not symref
514 sub git_get_hash_by_ref
{
517 open my $fd, "$projectroot/$path" or return undef;
521 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
526 sub git_get_project_description
{
529 open my $fd, "$projectroot/$path/description" or return undef;
536 sub git_get_projects_list
{
539 if (-d
$projects_list) {
540 # search in directory
541 my $dir = $projects_list;
542 opendir my ($dh), $dir or return undef;
543 while (my $dir = readdir($dh)) {
544 if (-e
"$projectroot/$dir/HEAD") {
552 } elsif (-f
$projects_list) {
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 open my ($fd), $projects_list or return undef;
558 while (my $line = <$fd>) {
560 my ($path, $owner) = split ' ', $line;
561 $path = unescape
($path);
562 $owner = unescape
($owner);
563 if (!defined $path) {
566 if (-e
"$projectroot/$path/HEAD") {
569 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
576 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
580 sub git_get_project_owner
{
584 return undef unless $project;
586 # read from file (url-encoded):
587 # 'git%2Fgit.git Linus+Torvalds'
588 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
589 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
590 if (-f
$projects_list) {
591 open (my $fd , $projects_list);
592 while (my $line = <$fd>) {
594 my ($pr, $ow) = split ' ', $line;
597 if ($pr eq $project) {
598 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
604 if (!defined $owner) {
605 $owner = get_file_owner
("$projectroot/$project");
611 sub git_get_references
{
612 my $type = shift || "";
615 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
616 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
617 if (-f
"$projectroot/$project/info/refs") {
618 open $fd, "$projectroot/$project/info/refs"
621 open $fd, "-|", $GIT, "ls-remote", "."
625 while (my $line = <$fd>) {
627 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?[^\^]+)/) {
628 if (defined $refs{$1}) {
629 push @
{$refs{$1}}, $2;
639 ## ----------------------------------------------------------------------
640 ## parse to hash functions
644 my $tz = shift || "-0000";
647 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
648 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
649 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
650 $date{'hour'} = $hour;
651 $date{'minute'} = $min;
652 $date{'mday'} = $mday;
653 $date{'day'} = $days[$wday];
654 $date{'month'} = $months[$mon];
655 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
656 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
658 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
659 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
660 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
661 $date{'hour_local'} = $hour;
662 $date{'minute_local'} = $min;
663 $date{'tz_local'} = $tz;
672 open my $fd, "-|", $GIT, "cat-file", "tag", $tag_id or return;
673 $tag{'id'} = $tag_id;
674 while (my $line = <$fd>) {
676 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
678 } elsif ($line =~ m/^type (.+)$/) {
680 } elsif ($line =~ m/^tag (.+)$/) {
682 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
686 } elsif ($line =~ m/--BEGIN/) {
687 push @comment, $line;
689 } elsif ($line eq "") {
693 push @comment, <$fd>;
694 $tag{'comment'} = \
@comment;
696 if (!defined $tag{'name'}) {
703 my $commit_id = shift;
704 my $commit_text = shift;
709 if (defined $commit_text) {
710 @commit_lines = @
$commit_text;
713 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", "--max-count=1", $commit_id or return;
714 @commit_lines = split '\n', <$fd>;
719 my $header = shift @commit_lines;
720 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
723 ($co{'id'}, my @parents) = split ' ', $header;
724 $co{'parents'} = \
@parents;
725 $co{'parent'} = $parents[0];
726 while (my $line = shift @commit_lines) {
727 last if $line eq "\n";
728 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
730 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
732 $co{'author_epoch'} = $2;
733 $co{'author_tz'} = $3;
734 if ($co{'author'} =~ m/^([^<]+) </) {
735 $co{'author_name'} = $1;
737 $co{'author_name'} = $co{'author'};
739 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
740 $co{'committer'} = $1;
741 $co{'committer_epoch'} = $2;
742 $co{'committer_tz'} = $3;
743 $co{'committer_name'} = $co{'committer'};
744 $co{'committer_name'} =~ s/ <.*//;
747 if (!defined $co{'tree'}) {
751 foreach my $title (@commit_lines) {
754 $co{'title'} = chop_str
($title, 80, 5);
755 # remove leading stuff of merges to make the interesting part visible
756 if (length($title) > 50) {
757 $title =~ s/^Automatic //;
758 $title =~ s/^merge (of|with) /Merge ... /i;
759 if (length($title) > 50) {
760 $title =~ s/(http|rsync):\/\///;
762 if (length($title) > 50) {
763 $title =~ s/(master|www|rsync)\.//;
765 if (length($title) > 50) {
766 $title =~ s/kernel.org:?//;
768 if (length($title) > 50) {
769 $title =~ s/\/pub\/scm//;
772 $co{'title_short'} = chop_str
($title, 50, 5);
776 # remove added spaces
777 foreach my $line (@commit_lines) {
780 $co{'comment'} = \
@commit_lines;
782 my $age = time - $co{'committer_epoch'};
784 $co{'age_string'} = age_string
($age);
785 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
786 if ($age > 60*60*24*7*2) {
787 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
788 $co{'age_string_age'} = $co{'age_string'};
790 $co{'age_string_date'} = $co{'age_string'};
791 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
796 # parse ref from ref_file, given by ref_id, with given type
798 my $ref_file = shift;
800 my $type = shift || git_get_type
($ref_id);
803 $ref_item{'type'} = $type;
804 $ref_item{'id'} = $ref_id;
805 $ref_item{'epoch'} = 0;
806 $ref_item{'age'} = "unknown";
807 if ($type eq "tag") {
808 my %tag = parse_tag
($ref_id);
809 $ref_item{'comment'} = $tag{'comment'};
810 if ($tag{'type'} eq "commit") {
811 my %co = parse_commit
($tag{'object'});
812 $ref_item{'epoch'} = $co{'committer_epoch'};
813 $ref_item{'age'} = $co{'age_string'};
814 } elsif (defined($tag{'epoch'})) {
815 my $age = time - $tag{'epoch'};
816 $ref_item{'epoch'} = $tag{'epoch'};
817 $ref_item{'age'} = age_string
($age);
819 $ref_item{'reftype'} = $tag{'type'};
820 $ref_item{'name'} = $tag{'name'};
821 $ref_item{'refid'} = $tag{'object'};
822 } elsif ($type eq "commit"){
823 my %co = parse_commit
($ref_id);
824 $ref_item{'reftype'} = "commit";
825 $ref_item{'name'} = $ref_file;
826 $ref_item{'title'} = $co{'title'};
827 $ref_item{'refid'} = $ref_id;
828 $ref_item{'epoch'} = $co{'committer_epoch'};
829 $ref_item{'age'} = $co{'age_string'};
831 $ref_item{'reftype'} = $type;
832 $ref_item{'name'} = $ref_file;
833 $ref_item{'refid'} = $ref_id;
839 ## ......................................................................
840 ## parse to array of hashes functions
842 sub git_get_refs_list
{
847 my $pfxlen = length("$projectroot/$project/$ref_dir");
848 File
::Find
::find
(sub {
851 push @refs, substr($File::Find
::name
, $pfxlen + 1);
853 }, "$projectroot/$project/$ref_dir");
855 foreach my $ref_file (@refs) {
856 my $ref_id = git_get_hash_by_ref
("$project/$ref_dir/$ref_file");
857 my $type = git_get_type
($ref_id) || next;
858 my %ref_item = parse_ref
($ref_file, $ref_id, $type);
860 push @reflist, \
%ref_item;
863 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
867 ## ----------------------------------------------------------------------
868 ## filesystem-related functions
873 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
874 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
875 if (!defined $gcos) {
879 $owner =~ s/[,;].*$//;
880 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
883 ## ......................................................................
884 ## mimetype related functions
886 sub mimetype_guess_file
{
887 my $filename = shift;
889 -r
$mimemap or return undef;
892 open(MIME
, $mimemap) or return undef;
894 next if m/^#/; # skip comments
895 my ($mime, $exts) = split(/\t+/);
897 my @exts = split(/\s+/, $exts);
898 foreach my $ext (@exts) {
899 $mimemap{$ext} = $mime;
905 $filename =~ /\.(.*?)$/;
910 my $filename = shift;
912 $filename =~ /\./ or return undef;
914 if ($mimetypes_file) {
915 my $file = $mimetypes_file;
916 if ($file !~ m!^/!) { # if it is relative path
917 # it is relative to project
918 $file = "$projectroot/$project/$file";
920 $mime = mimetype_guess_file
($filename, $file);
922 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
928 my $filename = shift;
931 my $mime = mimetype_guess
($filename);
932 $mime and return $mime;
936 return $default_blob_plain_mimetype unless $fd;
939 return 'text/plain' .
940 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
941 } elsif (! $filename) {
942 return 'application/octet-stream';
943 } elsif ($filename =~ m/\.png$/i) {
945 } elsif ($filename =~ m/\.gif$/i) {
947 } elsif ($filename =~ m/\.jpe?g$/i) {
950 return 'application/octet-stream';
954 ## ======================================================================
955 ## functions printing HTML: header, footer, error page
957 sub git_header_html
{
958 my $status = shift || "200 OK";
961 my $title = "$site_name git";
962 if (defined $project) {
963 $title .= " - $project";
964 if (defined $action) {
965 $title .= "/$action";
966 if (defined $file_name) {
967 $title .= " - $file_name";
968 if ($action eq "tree" && $file_name !~ m
|/$|) {
975 # require explicit support from the UA if we are to send the page as
976 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
977 # we have to do this because MSIE sometimes globs '*/*', pretending to
978 # support xhtml+xml but choking when it gets what it asked for.
979 if (defined $cgi->http('HTTP_ACCEPT') && $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ && $cgi->Accept('application/xhtml
+xml
') != 0) {
980 $content_type = 'application
/xhtml
+xml
';
982 $content_type = 'text
/html
';
984 print $cgi->header(-type=>$content_type, -charset => 'utf
-8', -status=> $status, -expires => $expires);
986 <?xml version="1.0" encoding="utf-8"?>
987 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
988 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
989 <!-- git web interface v$version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
990 <!-- git core binaries version $git_version -->
992 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
993 <meta name="robots" content="index, nofollow"/>
994 <title>$title</title>
995 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
997 if (defined $project) {
998 printf('<link rel="alternate" title="%s log" '.
999 'href="%s" type="application/rss+xml"/>'."\n",
1000 esc_param
($project), href
(action
=>"rss"));
1005 "<div class=\"page_header\">\n" .
1006 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
1007 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
1009 print $cgi->a({-href
=> esc_param
($home_link)}, $home_link_str) . " / ";
1010 if (defined $project) {
1011 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1012 if (defined $action) {
1016 if (!defined $searchtext) {
1020 if (defined $hash_base) {
1021 $search_hash = $hash_base;
1022 } elsif (defined $hash) {
1023 $search_hash = $hash;
1025 $search_hash = "HEAD";
1027 $cgi->param("a", "search");
1028 $cgi->param("h", $search_hash);
1029 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
1030 "<div class=\"search\">\n" .
1031 $cgi->hidden(-name
=> "p") . "\n" .
1032 $cgi->hidden(-name
=> "a") . "\n" .
1033 $cgi->hidden(-name
=> "h") . "\n" .
1034 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1036 $cgi->end_form() . "\n";
1041 sub git_footer_html
{
1042 print "<div class=\"page_footer\">\n";
1043 if (defined $project) {
1044 my $descr = git_get_project_description
($project);
1045 if (defined $descr) {
1046 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1048 print $cgi->a({-href
=> href
(action
=>"rss"), -class => "rss_logo"}, "RSS") . "\n";
1050 print $cgi->a({-href
=> "$my_uri?" . esc_param
("a=opml"), -class => "rss_logo"}, "OPML") . "\n";
1058 my $status = shift || "403 Forbidden";
1059 my $error = shift || "Malformed query, file missing or permission denied";
1061 git_header_html
($status);
1062 print "<div class=\"page_body\">\n" .
1064 "$status - $error\n" .
1071 ## ----------------------------------------------------------------------
1072 ## functions printing or outputting HTML: navigation
1074 sub git_print_page_nav
{
1075 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1076 $extra = '' if !defined $extra; # pager or formats
1078 my @navs = qw(summary shortlog log commit commitdiff tree);
1080 @navs = grep { $_ ne $suppress } @navs;
1083 my %arg = map { $_ => {action
=>$_} } @navs;
1084 if (defined $head) {
1085 for (qw(commit commitdiff)) {
1086 $arg{$_}{hash
} = $head;
1088 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1089 for (qw(shortlog log)) {
1090 $arg{$_}{hash
} = $head;
1094 $arg{tree
}{hash
} = $treehead if defined $treehead;
1095 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1097 print "<div class=\"page_nav\">\n" .
1099 map { $_ eq $current ?
1100 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1102 print "<br/>\n$extra<br/>\n" .
1106 sub format_paging_nav
{
1107 my ($action, $hash, $head, $page, $nrevs) = @_;
1111 if ($hash ne $head || $page) {
1112 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1114 $paging_nav .= "HEAD";
1118 $paging_nav .= " ⋅ " .
1119 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1120 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1122 $paging_nav .= " ⋅ prev";
1125 if ($nrevs >= (100 * ($page+1)-1)) {
1126 $paging_nav .= " ⋅ " .
1127 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1128 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1130 $paging_nav .= " ⋅ next";
1136 ## ......................................................................
1137 ## functions printing or outputting HTML: div
1139 sub git_print_header_div
{
1140 my ($action, $title, $hash, $hash_base) = @_;
1143 $args{action
} = $action;
1144 $args{hash
} = $hash if $hash;
1145 $args{hash_base
} = $hash_base if $hash_base;
1147 print "<div class=\"header\">\n" .
1148 $cgi->a({-href
=> href
(%args), -class => "title"},
1149 $title ?
$title : $action) .
1153 sub git_print_page_path
{
1157 if (!defined $name) {
1158 print "<div class=\"page_path\"><b>/</b></div>\n";
1159 } elsif (defined $type && $type eq 'blob') {
1160 print "<div class=\"page_path\"><b>" .
1161 $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name)}, esc_html
($name)) . "</b><br/></div>\n";
1163 print "<div class=\"page_path\"><b>" . esc_html
($name) . "</b><br/></div>\n";
1167 ## ......................................................................
1168 ## functions printing large fragments of HTML
1170 sub git_difftree_body
{
1171 my ($difftree, $parent) = @_;
1173 print "<div class=\"list_head\">\n";
1174 if ($#{$difftree} > 10) {
1175 print(($#{$difftree} + 1) . " files changed:\n");
1179 print "<table class=\"diff_tree\">\n";
1181 foreach my $line (@
{$difftree}) {
1182 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1183 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1184 if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1192 my $similarity = $6; # score
1193 my $file = validate_input
(unquote
($7));
1196 print "<tr class=\"dark\">\n";
1198 print "<tr class=\"light\">\n";
1202 if ($status eq "A") { # created
1204 if (S_ISREG
(oct $to_mode)) {
1205 $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
1208 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$file),
1209 -class => "list"}, esc_html
($file)) .
1211 "<td><span class=\"file_status new\">[new " . file_type
($to_mode) . "$mode_chng]</span></td>\n" .
1212 "<td class=\"link\">" .
1213 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$file)}, "blob") .
1216 } elsif ($status eq "D") { # deleted
1218 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$from_id, hash_base
=>$parent, file_name
=>$file),
1219 -class => "list"}, esc_html
($file)) . "</td>\n" .
1220 "<td><span class=\"file_status deleted\">[deleted " . file_type
($from_mode). "]</span></td>\n" .
1221 "<td class=\"link\">" .
1222 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$from_id, hash_base
=>$parent, file_name
=>$file)}, "blob") . " | " .
1223 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent, file_name
=>$file)}, "history") .
1226 } elsif ($status eq "M" || $status eq "T") { # modified, or type changed
1227 my $mode_chnge = "";
1228 if ($from_mode != $to_mode) {
1229 $mode_chnge = " <span class=\"file_status mode_chnge\">[changed";
1230 if (((oct $from_mode) & S_IFMT
) != ((oct $to_mode) & S_IFMT
)) {
1231 $mode_chnge .= " from " . file_type
($from_mode) . " to " . file_type
($to_mode);
1233 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
1234 if (S_ISREG
($from_mode) && S_ISREG
($to_mode)) {
1235 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
1236 } elsif (S_ISREG
($to_mode)) {
1237 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
1240 $mode_chnge .= "]</span>\n";
1243 if ($to_id ne $from_id) { # modified
1244 print $cgi->a({-href
=> href
(action
=>"blobdiff", hash
=>$to_id, hash_parent
=>$from_id, hash_base
=>$hash, file_name
=>$file),
1245 -class => "list"}, esc_html
($file));
1246 } else { # mode changed
1247 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$file),
1248 -class => "list"}, esc_html
($file));
1251 "<td>$mode_chnge</td>\n" .
1252 "<td class=\"link\">" .
1253 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$file)}, "blob");
1254 if ($to_id ne $from_id) { # modified
1255 print $cgi->a({-href
=> href
(action
=>"blobdiff", hash
=>$to_id, hash_parent
=>$from_id, hash_base
=>$hash, file_name
=>$file)}, "diff");
1257 print " | " . $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash, file_name
=>$file)}, "history") . "\n";
1260 } elsif ($status eq "R") { # renamed
1261 my ($from_file, $to_file) = split "\t", $file;
1263 if ($from_mode != $to_mode) {
1264 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
1267 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$to_file),
1268 -class => "list"}, esc_html
($to_file)) . "</td>\n" .
1269 "<td><span class=\"file_status moved\">[moved from " .
1270 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$from_id, hash_base
=>$parent, file_name
=>$from_file),
1271 -class => "list"}, esc_html
($from_file)) .
1272 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
1273 "<td class=\"link\">" .
1274 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$to_file)}, "blob");
1275 if ($to_id ne $from_id) {
1277 $cgi->a({-href
=> "$my_uri?" .
1278 esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file;fp=$from_file")}, "diff");
1282 } elsif ($status eq "C") { # copied
1283 my ($from_file, $to_file) = split "\t", $file;
1285 if ($from_mode != $to_mode) {
1286 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
1289 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$to_file),
1290 -class => "list"}, esc_html
($to_file)) . "</td>\n" .
1291 "<td><span class=\"file_status copied\">[copied from " .
1292 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$from_id, hash_base
=>$parent, file_name
=>$from_file),
1293 -class => "list"}, esc_html
($from_file)) .
1294 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
1295 "<td class=\"link\">" .
1296 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$to_file)}, "blob");
1297 if ($to_id ne $from_id) {
1299 $cgi->a({-href
=> "$my_uri?" .
1300 esc_param
("p=$project;a=blobdiff;h=$to_id;hp=$from_id;hb=$hash;f=$to_file;fp=$from_file")}, "diff");
1303 } # we should not encounter Unmerged (U) or Unknown (X) status
1309 sub git_shortlog_body
{
1310 # uses global variable $project
1311 my ($revlist, $from, $to, $refs, $extra) = @_;
1312 $from = 0 unless defined $from;
1313 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1315 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
1317 for (my $i = $from; $i <= $to; $i++) {
1318 my $commit = $revlist->[$i];
1319 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
1320 my $ref = format_ref_marker
($refs, $commit);
1321 my %co = parse_commit
($commit);
1323 print "<tr class=\"dark\">\n";
1325 print "<tr class=\"light\">\n";
1328 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1329 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1330 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
1332 print format_subject_html
($co{'title'}, $co{'title_short'}, href
(action
=>"commit", hash
=>$commit), $ref);
1334 "<td class=\"link\">" .
1335 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
1336 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
1340 if (defined $extra) {
1342 "<td colspan=\"4\">$extra</td>\n" .
1348 sub git_history_body
{
1349 # Warning: assumes constant type (blob or tree) during history
1350 my ($fd, $refs, $hash_base, $ftype, $extra) = @_;
1352 print "<table class=\"history\" cellspacing=\"0\">\n";
1354 while (my $line = <$fd>) {
1355 if ($line !~ m/^([0-9a-fA-F]{40})/) {
1360 my %co = parse_commit
($commit);
1365 my $ref = format_ref_marker
($refs, $commit);
1368 print "<tr class=\"dark\">\n";
1370 print "<tr class=\"light\">\n";
1373 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1374 # shortlog uses chop_str($co{'author_name'}, 10)
1375 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
1377 # originally git_history used chop_str($co{'title'}, 50)
1378 print format_subject_html
($co{'title'}, $co{'title_short'}, href
(action
=>"commit", hash
=>$commit), $ref);
1380 "<td class=\"link\">" .
1381 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
1382 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
1383 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype);
1385 if ($ftype eq 'blob') {
1386 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
1387 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
1388 if (defined $blob_current && defined $blob_parent &&
1389 $blob_current ne $blob_parent) {
1391 $cgi->a({-href
=> href
(action
=>"blobdiff", hash
=>$blob_current, hash_parent
=>$blob_parent, hash_base
=>$commit, file_name
=>$file_name)},
1398 if (defined $extra) {
1400 "<td colspan=\"4\">$extra</td>\n" .
1407 # uses global variable $project
1408 my ($taglist, $from, $to, $extra) = @_;
1409 $from = 0 unless defined $from;
1410 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1412 print "<table class=\"tags\" cellspacing=\"0\">\n";
1414 for (my $i = $from; $i <= $to; $i++) {
1415 my $entry = $taglist->[$i];
1417 my $comment_lines = $tag{'comment'};
1418 my $comment = shift @
$comment_lines;
1420 if (defined $comment) {
1421 $comment_short = chop_str
($comment, 30, 5);
1424 print "<tr class=\"dark\">\n";
1426 print "<tr class=\"light\">\n";
1429 print "<td><i>$tag{'age'}</i></td>\n" .
1431 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
1432 -class => "list"}, "<b>" . esc_html
($tag{'name'}) . "</b>") .
1435 if (defined $comment) {
1436 print format_subject_html
($comment, $comment_short, href
(action
=>"tag", hash
=>$tag{'id'}));
1439 "<td class=\"selflink\">";
1440 if ($tag{'type'} eq "tag") {
1441 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
1446 "<td class=\"link\">" . " | " .
1447 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
1448 if ($tag{'reftype'} eq "commit") {
1449 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
1450 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'refid'})}, "log");
1451 } elsif ($tag{'reftype'} eq "blob") {
1452 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
1457 if (defined $extra) {
1459 "<td colspan=\"5\">$extra</td>\n" .
1465 sub git_heads_body
{
1466 # uses global variable $project
1467 my ($taglist, $head, $from, $to, $extra) = @_;
1468 $from = 0 unless defined $from;
1469 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1471 print "<table class=\"heads\" cellspacing=\"0\">\n";
1473 for (my $i = $from; $i <= $to; $i++) {
1474 my $entry = $taglist->[$i];
1476 my $curr = $tag{'id'} eq $head;
1478 print "<tr class=\"dark\">\n";
1480 print "<tr class=\"light\">\n";
1483 print "<td><i>$tag{'age'}</i></td>\n" .
1484 ($tag{'id'} eq $head ?
"<td class=\"current_head\">" : "<td>") .
1485 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'}),
1486 -class => "list"}, "<b>" . esc_html
($tag{'name'}) . "</b>") .
1488 "<td class=\"link\">" .
1489 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") . " | " .
1490 $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log") .
1494 if (defined $extra) {
1496 "<td colspan=\"3\">$extra</td>\n" .
1502 ## ----------------------------------------------------------------------
1503 ## functions printing large fragments, format as one of arguments
1505 sub git_diff_print
{
1507 my $from_name = shift;
1509 my $to_name = shift;
1510 my $format = shift || "html";
1512 my $from_tmp = "/dev/null";
1513 my $to_tmp = "/dev/null";
1516 # create tmp from-file
1517 if (defined $from) {
1518 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
1519 open my $fd2, "> $from_tmp";
1520 open my $fd, "-|", $GIT, "cat-file", "blob", $from;
1527 # create tmp to-file
1529 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
1530 open my $fd2, "> $to_tmp";
1531 open my $fd, "-|", $GIT, "cat-file", "blob", $to;
1538 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
1539 if ($format eq "plain") {
1544 while (my $line = <$fd>) {
1546 my $char = substr($line, 0, 1);
1547 my $diff_class = "";
1549 $diff_class = " add";
1550 } elsif ($char eq "-") {
1551 $diff_class = " rem";
1552 } elsif ($char eq "@") {
1553 $diff_class = " chunk_header";
1554 } elsif ($char eq "\\") {
1558 $line = untabify
($line);
1559 print "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
1564 if (defined $from) {
1573 ## ======================================================================
1574 ## ======================================================================
1577 sub git_project_list
{
1578 my $order = $cgi->param('o');
1579 if (defined $order && $order !~ m/project|descr|owner|age/) {
1580 die_error
(undef, "Unknown order parameter");
1583 my @list = git_get_projects_list
();
1586 die_error
(undef, "No projects found");
1588 foreach my $pr (@list) {
1589 my $head = git_get_head_hash
($pr->{'path'});
1590 if (!defined $head) {
1593 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
1594 my %co = parse_commit
($head);
1598 $pr->{'commit'} = \
%co;
1599 if (!defined $pr->{'descr'}) {
1600 my $descr = git_get_project_description
($pr->{'path'}) || "";
1601 $pr->{'descr'} = chop_str
($descr, 25, 5);
1603 if (!defined $pr->{'owner'}) {
1604 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
1606 push @projects, $pr;
1610 if (-f
$home_text) {
1611 print "<div class=\"index_include\">\n";
1612 open (my $fd, $home_text);
1617 print "<table class=\"project_list\">\n" .
1619 $order ||= "project";
1620 if ($order eq "project") {
1621 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
1622 print "<th>Project</th>\n";
1625 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=project"),
1626 -class => "header"}, "Project") .
1629 if ($order eq "descr") {
1630 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
1631 print "<th>Description</th>\n";
1634 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=descr"),
1635 -class => "header"}, "Description") .
1638 if ($order eq "owner") {
1639 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
1640 print "<th>Owner</th>\n";
1643 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=owner"),
1644 -class => "header"}, "Owner") .
1647 if ($order eq "age") {
1648 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
1649 print "<th>Last Change</th>\n";
1652 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=age"),
1653 -class => "header"}, "Last Change") .
1656 print "<th></th>\n" .
1659 foreach my $pr (@projects) {
1661 print "<tr class=\"dark\">\n";
1663 print "<tr class=\"light\">\n";
1666 print "<td>" . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=summary"),
1667 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
1668 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
1669 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
1670 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" .
1671 $pr->{'commit'}{'age_string'} . "</td>\n" .
1672 "<td class=\"link\">" .
1673 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=summary")}, "summary") . " | " .
1674 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=shortlog")}, "shortlog") . " | " .
1675 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$pr->{'path'};a=log")}, "log") .
1684 my $descr = git_get_project_description
($project) || "none";
1685 my $head = git_get_head_hash
($project);
1686 my %co = parse_commit
($head);
1687 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
1689 my $owner = git_get_project_owner
($project);
1691 my $refs = git_get_references
();
1693 git_print_page_nav
('summary','', $head);
1695 print "<div class=\"title\"> </div>\n";
1696 print "<table cellspacing=\"0\">\n" .
1697 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
1698 "<tr><td>owner</td><td>$owner</td></tr>\n" .
1699 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
1700 my $url_tag = "URL";
1701 foreach my $git_base_url (@git_base_url_list) {
1702 next unless $git_base_url;
1703 print "<tr><td>$url_tag</td><td>$git_base_url/$project</td></tr>\n";
1708 open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_get_head_hash
($project)
1709 or die_error
(undef, "Open git-rev-list failed");
1710 my @revlist = map { chomp; $_ } <$fd>;
1712 git_print_header_div
('shortlog');
1713 git_shortlog_body
(\
@revlist, 0, 15, $refs,
1714 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
1716 my $taglist = git_get_refs_list
("refs/tags");
1717 if (defined @
$taglist) {
1718 git_print_header_div
('tags');
1719 git_tags_body
($taglist, 0, 15,
1720 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
1723 my $headlist = git_get_refs_list
("refs/heads");
1724 if (defined @
$headlist) {
1725 git_print_header_div
('heads');
1726 git_heads_body
($headlist, $head, 0, 15,
1727 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
1734 my $head = git_get_head_hash
($project);
1736 git_print_page_nav
('','', $head,undef,$head);
1737 my %tag = parse_tag
($hash);
1738 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
1739 print "<div class=\"title_text\">\n" .
1740 "<table cellspacing=\"0\">\n" .
1742 "<td>object</td>\n" .
1743 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})}, $tag{'object'}) . "</td>\n" .
1744 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})}, $tag{'type'}) . "</td>\n" .
1746 if (defined($tag{'author'})) {
1747 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
1748 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
1749 print "<tr><td></td><td>" . $ad{'rfc2822'} . sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) . "</td></tr>\n";
1751 print "</table>\n\n" .
1753 print "<div class=\"page_body\">";
1754 my $comment = $tag{'comment'};
1755 foreach my $line (@
$comment) {
1756 print esc_html
($line) . "<br/>\n";
1765 die_error
(undef, "Permission denied") if (!git_get_project_config_bool
('blame'));
1766 die_error
('404 Not Found', "File name not defined") if (!$file_name);
1767 $hash_base ||= git_get_head_hash
($project);
1768 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
1769 my %co = parse_commit
($hash_base)
1770 or die_error
(undef, "Reading commit failed");
1771 if (!defined $hash) {
1772 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
1773 or die_error
(undef, "Error looking up file");
1775 $ftype = git_get_type
($hash);
1776 if ($ftype !~ "blob") {
1777 die_error
("400 Bad Request", "Object is not a blob");
1779 open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base)
1780 or die_error
(undef, "Open git-blame failed");
1783 $cgi->a({-href
=> href
(action
=>"blobl", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)}, "blob") .
1784 " | " . $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)}, "head");
1785 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1786 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
1787 git_print_page_path
($file_name, $ftype);
1788 my @rev_color = (qw(light2 dark2));
1789 my $num_colors = scalar(@rev_color);
1790 my $current_color = 0;
1792 print "<div class=\"page_body\">\n";
1793 print "<table class=\"blame\">\n";
1794 print "<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n";
1796 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
1798 my $rev = substr($full_rev, 0, 8);
1802 if (!defined $last_rev) {
1803 $last_rev = $full_rev;
1804 } elsif ($last_rev ne $full_rev) {
1805 $last_rev = $full_rev;
1806 $current_color = ++$current_color % $num_colors;
1808 print "<tr class=\"$rev_color[$current_color]\">\n";
1809 print "<td class=\"sha1\">" .
1810 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$full_rev, file_name
=>$file_name)}, esc_html
($rev)) . "</td>\n";
1811 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" . esc_html
($lineno) . "</a></td>\n";
1812 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
1817 close $fd or print "Reading blob failed\n";
1823 die_error
('403 Permission denied', "Permission denied") if (!git_get_project_config_bool
('blame'));
1824 die_error
('404 Not Found', "File name not defined") if (!$file_name);
1825 $hash_base ||= git_get_head_hash
($project);
1826 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
1827 my %co = parse_commit
($hash_base)
1828 or die_error
(undef, "Reading commit failed");
1829 if (!defined $hash) {
1830 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
1831 or die_error
(undef, "Error lookup file");
1833 open ($fd, "-|", $GIT, "annotate", '-l', '-t', '-r', $file_name, $hash_base)
1834 or die_error
(undef, "Open git-annotate failed");
1837 $cgi->a({-href
=> href
(action
=>"blobl", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)}, "blob") .
1838 " | " . $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)}, "head");
1839 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1840 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
1841 git_print_page_path
($file_name, 'blob');
1842 print "<div class=\"page_body\">\n";
1844 <table class="blame">
1853 my @line_class = (qw(light dark));
1854 my $line_class_len = scalar (@line_class);
1855 my $line_class_num = $#line_class;
1856 while (my $line = <$fd>) {
1868 $line_class_num = ($line_class_num + 1) % $line_class_len;
1870 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) \+\d\d\d\d\t(\d+)\)(.*)$/) {
1877 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
1880 $short_rev = substr ($long_rev, 0, 8);
1881 $age = time () - $time;
1882 $age_str = age_string
($age);
1883 $age_str =~ s/ / /g;
1884 $age_class = age_class
($age);
1885 $author = esc_html
($author);
1886 $author =~ s/ / /g;
1888 $data = untabify
($data);
1889 $data = esc_html
($data);
1892 <tr class="$line_class[$line_class_num]">
1893 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
1894 <td class="$age_class">$age_str</td>
1896 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
1897 <td class="pre">$data</td>
1900 } # while (my $line = <$fd>)
1901 print "</table>\n\n";
1902 close $fd or print "Reading blob failed.\n";
1908 my $head = git_get_head_hash
($project);
1910 git_print_page_nav
('','', $head,undef,$head);
1911 git_print_header_div
('summary', $project);
1913 my $taglist = git_get_refs_list
("refs/tags");
1914 if (defined @
$taglist) {
1915 git_tags_body
($taglist);
1921 my $head = git_get_head_hash
($project);
1923 git_print_page_nav
('','', $head,undef,$head);
1924 git_print_header_div
('summary', $project);
1926 my $taglist = git_get_refs_list
("refs/heads");
1927 if (defined @
$taglist) {
1928 git_heads_body
($taglist, $head);
1933 sub git_blob_plain
{
1934 if (!defined $hash) {
1935 if (defined $file_name) {
1936 my $base = $hash_base || git_get_head_hash
($project);
1937 $hash = git_get_hash_by_path
($base, $file_name, "blob")
1938 or die_error
(undef, "Error lookup file");
1940 die_error
(undef, "No file name defined");
1944 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
1945 or die_error
(undef, "Couldn't cat $file_name, $hash");
1947 $type ||= blob_mimetype
($fd, $file_name);
1949 # save as filename, even when no $file_name is given
1950 my $save_as = "$hash";
1951 if (defined $file_name) {
1952 $save_as = $file_name;
1953 } elsif ($type =~ m/^text\//) {
1957 print $cgi->header(-type
=> "$type", '-content-disposition' => "inline; filename=\"$save_as\"");
1959 binmode STDOUT
, ':raw';
1961 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
1967 if (!defined $hash) {
1968 if (defined $file_name) {
1969 my $base = $hash_base || git_get_head_hash
($project);
1970 $hash = git_get_hash_by_path
($base, $file_name, "blob")
1971 or die_error
(undef, "Error lookup file");
1973 die_error
(undef, "No file name defined");
1976 my $have_blame = git_get_project_config_bool
('blame');
1977 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
1978 or die_error
(undef, "Couldn't cat $file_name, $hash");
1979 my $mimetype = blob_mimetype
($fd, $file_name);
1980 if ($mimetype !~ m/^text\//) {
1982 return git_blob_plain
($mimetype);
1985 my $formats_nav = '';
1986 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
1987 if (defined $file_name) {
1989 $formats_nav .= $cgi->a({-href
=> href
(action
=>"blame", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)}, "blame") . " | ";
1992 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash, file_name
=>$file_name)}, "plain") .
1993 " | " . $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>"HEAD", file_name
=>$file_name)}, "head");
1995 $formats_nav .= $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "plain");
1997 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1998 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2000 print "<div class=\"page_nav\">\n" .
2001 "<br/><br/></div>\n" .
2002 "<div class=\"title\">$hash</div>\n";
2004 git_print_page_path
($file_name, "blob");
2005 print "<div class=\"page_body\">\n";
2007 while (my $line = <$fd>) {
2010 $line = untabify
($line);
2011 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", $nr, $nr, $nr, esc_html
($line);
2013 close $fd or print "Reading blob failed.\n";
2019 if (!defined $hash) {
2020 $hash = git_get_head_hash
($project);
2021 if (defined $file_name) {
2022 my $base = $hash_base || $hash;
2023 $hash = git_get_hash_by_path
($base, $file_name, "tree");
2025 if (!defined $hash_base) {
2030 open my $fd, "-|", $GIT, "ls-tree", '-z', $hash
2031 or die_error
(undef, "Open git-ls-tree failed");
2032 my @entries = map { chomp; $_ } <$fd>;
2033 close $fd or die_error
(undef, "Reading tree failed");
2036 my $refs = git_get_references
();
2037 my $ref = format_ref_marker
($refs, $hash_base);
2041 my $have_blame = git_get_project_config_bool
('blame');
2042 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2043 $base_key = ";hb=$hash_base";
2044 git_print_page_nav
('tree','', $hash_base);
2045 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
2047 print "<div class=\"page_nav\">\n";
2048 print "<br/><br/></div>\n";
2049 print "<div class=\"title\">$hash</div>\n";
2051 if (defined $file_name) {
2052 $base = esc_html
("$file_name/");
2054 git_print_page_path
($file_name, 'tree');
2055 print "<div class=\"page_body\">\n";
2056 print "<table cellspacing=\"0\">\n";
2058 foreach my $line (@entries) {
2059 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2060 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
2064 my $t_name = validate_input
($4);
2066 print "<tr class=\"dark\">\n";
2068 print "<tr class=\"light\">\n";
2071 print "<td class=\"mode\">" . mode_str
($t_mode) . "</td>\n";
2072 if ($t_type eq "blob") {
2073 print "<td class=\"list\">" .
2074 $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)) .
2076 "<td class=\"link\">" .
2077 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$t_hash$base_key;f=$base$t_name")}, "blob");
2079 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blame;h=$t_hash$base_key;f=$base$t_name")}, "blame");
2081 print " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;h=$t_hash;hb=$hash_base;f=$base$t_name")}, "history") .
2082 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob_plain;h=$t_hash;f=$base$t_name")}, "raw") .
2084 } elsif ($t_type eq "tree") {
2085 print "<td class=\"list\">" .
2086 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, esc_html
($t_name)) .
2088 "<td class=\"link\">" .
2089 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$t_hash$base_key;f=$base$t_name")}, "tree") .
2090 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=history;hb=$hash_base;f=$base$t_name")}, "history") .
2095 print "</table>\n" .
2101 my $head = git_get_head_hash
($project);
2102 if (!defined $hash) {
2105 if (!defined $page) {
2108 my $refs = git_get_references
();
2110 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2111 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2112 or die_error
(undef, "Open git-rev-list failed");
2113 my @revlist = map { chomp; $_ } <$fd>;
2116 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
2119 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
2122 my %co = parse_commit
($hash);
2124 git_print_header_div
('summary', $project);
2125 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
2127 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2128 my $commit = $revlist[$i];
2129 my $ref = format_ref_marker
($refs, $commit);
2130 my %co = parse_commit
($commit);
2132 my %ad = parse_date
($co{'author_epoch'});
2133 git_print_header_div
('commit',
2134 "<span class=\"age\">$co{'age_string'}</span>" .
2135 esc_html
($co{'title'}) . $ref,
2137 print "<div class=\"title_text\">\n" .
2138 "<div class=\"log_link\">\n" .
2139 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
2140 " | " . $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
2143 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
2145 "<div class=\"log_body\">\n";
2146 my $comment = $co{'comment'};
2148 foreach my $line (@
$comment) {
2149 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2160 print format_log_line_html
($line) . "<br/>\n";
2171 my %co = parse_commit
($hash);
2173 die_error
(undef, "Unknown commit object");
2175 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2176 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2178 my $parent = $co{'parent'};
2179 if (!defined $parent) {
2182 open my $fd, "-|", $GIT, "diff-tree", '-r', '-M', $parent, $hash
2183 or die_error
(undef, "Open git-diff-tree failed");
2184 my @difftree = map { chomp; $_ } <$fd>;
2185 close $fd or die_error
(undef, "Reading git-diff-tree failed");
2187 # non-textual hash id's can be cached
2189 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2192 my $refs = git_get_references
();
2193 my $ref = format_ref_marker
($refs, $co{'id'});
2194 my $formats_nav = '';
2195 if (defined $file_name && defined $co{'parent'}) {
2196 my $parent = $co{'parent'};
2197 $formats_nav .= $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)}, "blame");
2199 git_header_html
(undef, $expires);
2200 git_print_page_nav
('commit', defined $co{'parent'} ?
'' : 'commitdiff',
2201 $hash, $co{'tree'}, $hash,
2204 if (defined $co{'parent'}) {
2205 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
2207 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
2209 print "<div class=\"title_text\">\n" .
2210 "<table cellspacing=\"0\">\n";
2211 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
2213 "<td></td><td> $ad{'rfc2822'}";
2214 if ($ad{'hour_local'} < 6) {
2215 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2217 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2221 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
2222 print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
2223 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
2226 "<td class=\"sha1\">" .
2227 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash), class => "list"}, $co{'tree'}) .
2229 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)}, "tree") .
2232 my $parents = $co{'parents'};
2233 foreach my $par (@
$parents) {
2236 "<td class=\"sha1\">" . $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par), class => "list"}, $par) . "</td>" .
2237 "<td class=\"link\">" .
2238 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
2239 " | " . $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "commitdiff") .
2245 print "<div class=\"page_body\">\n";
2246 my $comment = $co{'comment'};
2249 foreach my $line (@
$comment) {
2250 # print only one empty line
2252 if ($empty || $signed) {
2259 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2261 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2264 print format_log_line_html
($line) . "<br/>\n";
2269 git_difftree_body
(\
@difftree, $parent);
2275 mkdir($git_temp, 0700);
2277 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2279 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blobdiff_plain;h=$hash;hp=$hash_parent")}, "plain");
2280 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2281 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2283 print "<div class=\"page_nav\">\n" .
2284 "<br/><br/></div>\n" .
2285 "<div class=\"title\">$hash vs $hash_parent</div>\n";
2287 git_print_page_path
($file_name, "blob");
2288 print "<div class=\"page_body\">\n" .
2289 "<div class=\"diff_info\">blob:" .
2290 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash_parent;hb=$hash_base;f=$file_name")}, $hash_parent) .
2292 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$hash;hb=$hash_base;f=$file_name")}, $hash) .
2294 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
2299 sub git_blobdiff_plain
{
2300 mkdir($git_temp, 0700);
2301 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8');
2302 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
2305 sub git_commitdiff
{
2306 mkdir($git_temp, 0700);
2307 my %co = parse_commit
($hash);
2309 die_error
(undef, "Unknown commit object");
2311 if (!defined $hash_parent) {
2312 $hash_parent = $co{'parent'} || '--root';
2314 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2315 or die_error
(undef, "Open git-diff-tree failed");
2316 my @difftree = map { chomp; $_ } <$fd>;
2317 close $fd or die_error
(undef, "Reading git-diff-tree failed");
2319 # non-textual hash id's can be cached
2321 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2324 my $refs = git_get_references
();
2325 my $ref = format_ref_marker
($refs, $co{'id'});
2327 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent")}, "plain");
2328 git_header_html
(undef, $expires);
2329 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
2330 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
2331 print "<div class=\"page_body\">\n";
2332 my $comment = $co{'comment'};
2335 my @log = @
$comment;
2336 # remove first and empty lines after that
2338 while (defined $log[0] && $log[0] eq "") {
2341 foreach my $line (@log) {
2342 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2353 print format_log_line_html
($line) . "<br/>\n";
2356 foreach my $line (@difftree) {
2357 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2358 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2359 if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2367 my $file = validate_input
(unquote
($6));
2368 if ($status eq "A") {
2369 print "<div class=\"diff_info\">" . file_type
($to_mode) . ":" .
2370 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id) . "(new)" .
2372 git_diff_print
(undef, "/dev/null", $to_id, "b/$file");
2373 } elsif ($status eq "D") {
2374 print "<div class=\"diff_info\">" . file_type
($from_mode) . ":" .
2375 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash_parent;f=$file")}, $from_id) . "(deleted)" .
2377 git_diff_print
($from_id, "a/$file", undef, "/dev/null");
2378 } elsif ($status eq "M") {
2379 if ($from_id ne $to_id) {
2380 print "<div class=\"diff_info\">" .
2381 file_type
($from_mode) . ":" .
2382 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$from_id;hb=$hash_parent;f=$file")}, $from_id) .
2384 file_type
($to_mode) . ":" .
2385 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$to_id;hb=$hash;f=$file")}, $to_id);
2387 git_diff_print
($from_id, "a/$file", $to_id, "b/$file");
2396 sub git_commitdiff_plain
{
2397 mkdir($git_temp, 0700);
2398 my %co = parse_commit
($hash);
2400 die_error
(undef, "Unknown commit object");
2402 if (!defined $hash_parent) {
2403 $hash_parent = $co{'parent'} || '--root';
2405 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2406 or die_error
(undef, "Open git-diff-tree failed");
2407 my @difftree = map { chomp; $_ } <$fd>;
2408 close $fd or die_error
(undef, "Reading diff-tree failed");
2410 # try to figure out the next tag after this commit
2412 my $refs = git_get_references
("tags");
2413 open $fd, "-|", $GIT, "rev-list", "HEAD";
2414 my @commits = map { chomp; $_ } <$fd>;
2416 foreach my $commit (@commits) {
2417 if (defined $refs->{$commit}) {
2418 $tagname = $refs->{$commit}
2420 if ($commit eq $hash) {
2425 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8', '-content-disposition' => "inline; filename=\"git-$hash.patch\"");
2426 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2427 my $comment = $co{'comment'};
2428 print "From: $co{'author'}\n" .
2429 "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
2430 "Subject: $co{'title'}\n";
2431 if (defined $tagname) {
2432 print "X-Git-Tag: $tagname\n";
2434 print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
2437 foreach my $line (@
$comment) {;
2442 foreach my $line (@difftree) {
2443 if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2450 if ($status eq "A") {
2451 git_diff_print
(undef, "/dev/null", $to_id, "b/$file", "plain");
2452 } elsif ($status eq "D") {
2453 git_diff_print
($from_id, "a/$file", undef, "/dev/null", "plain");
2454 } elsif ($status eq "M") {
2455 git_diff_print
($from_id, "a/$file", $to_id, "b/$file", "plain");
2461 if (!defined $hash_base) {
2462 $hash_base = git_get_head_hash
($project);
2465 my %co = parse_commit
($hash_base);
2467 die_error
(undef, "Unknown commit object");
2469 my $refs = git_get_references
();
2471 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base);
2472 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2473 if (!defined $hash && defined $file_name) {
2474 $hash = git_get_hash_by_path
($hash_base, $file_name);
2476 if (defined $hash) {
2477 $ftype = git_get_type
($hash);
2479 git_print_page_path
($file_name, $ftype);
2482 $GIT, "rev-list", "--full-history", $hash_base, "--", $file_name;
2483 git_history_body
($fd, $refs, $hash_base, $ftype);
2490 if (!defined $searchtext) {
2491 die_error
(undef, "Text field empty");
2493 if (!defined $hash) {
2494 $hash = git_get_head_hash
($project);
2496 my %co = parse_commit
($hash);
2498 die_error
(undef, "Unknown commit object");
2500 # pickaxe may take all resources of your box and run for several minutes
2501 # with every query - so decide by yourself how public you make this feature :)
2502 my $commit_search = 1;
2503 my $author_search = 0;
2504 my $committer_search = 0;
2505 my $pickaxe_search = 0;
2506 if ($searchtext =~ s/^author\\://i) {
2508 } elsif ($searchtext =~ s/^committer\\://i) {
2509 $committer_search = 1;
2510 } elsif ($searchtext =~ s/^pickaxe\\://i) {
2512 $pickaxe_search = 1;
2515 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
2516 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
2518 print "<table cellspacing=\"0\">\n";
2520 if ($commit_search) {
2522 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", $hash or next;
2523 while (my $commit_text = <$fd>) {
2524 if (!grep m/$searchtext/i, $commit_text) {
2527 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
2530 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
2533 my @commit_lines = split "\n", $commit_text;
2534 my %co = parse_commit
(undef, \
@commit_lines);
2539 print "<tr class=\"dark\">\n";
2541 print "<tr class=\"light\">\n";
2544 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2545 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2547 $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/>");
2548 my $comment = $co{'comment'};
2549 foreach my $line (@
$comment) {
2550 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2551 my $lead = esc_html
($1) || "";
2552 $lead = chop_str
($lead, 30, 10);
2553 my $match = esc_html
($2) || "";
2554 my $trail = esc_html
($3) || "";
2555 $trail = chop_str
($trail, 30, 10);
2556 my $text = "$lead<span class=\"match\">$match</span>$trail";
2557 print chop_str
($text, 80, 5) . "<br/>\n";
2561 "<td class=\"link\">" .
2562 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2563 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2570 if ($pickaxe_search) {
2572 open my $fd, "-|", "$GIT rev-list $hash | $GIT diff-tree -r --stdin -S\'$searchtext\'";
2575 while (my $line = <$fd>) {
2576 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2579 $set{'from_id'} = $3;
2581 $set{'id'} = $set{'to_id'};
2582 if ($set{'id'} =~ m/0{40}/) {
2583 $set{'id'} = $set{'from_id'};
2585 if ($set{'id'} =~ m/0{40}/) {
2589 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
2592 print "<tr class=\"dark\">\n";
2594 print "<tr class=\"light\">\n";
2597 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2598 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2600 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}"), -class => "list"}, "<b>" .
2601 esc_html
(chop_str
($co{'title'}, 50)) . "</b><br/>");
2602 while (my $setref = shift @files) {
2604 print $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=blob;h=$set{'id'};hb=$co{'id'};f=$set{'file'}"), class => "list"},
2605 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
2609 "<td class=\"link\">" .
2610 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=commit;h=$co{'id'}")}, "commit") .
2611 " | " . $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=tree;h=$co{'tree'};hb=$co{'id'}")}, "tree");
2615 %co = parse_commit
($1);
2625 my $head = git_get_head_hash
($project);
2626 if (!defined $hash) {
2629 if (!defined $page) {
2632 my $refs = git_get_references
();
2634 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2635 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2636 or die_error
(undef, "Open git-rev-list failed");
2637 my @revlist = map { chomp; $_ } <$fd>;
2640 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
2642 if ($#revlist >= (100 * ($page+1)-1)) {
2644 $cgi->a({-href
=> "$my_uri?" . esc_param
("p=$project;a=shortlog;h=$hash;pg=" . ($page+1)),
2645 -title
=> "Alt-n"}, "next");
2650 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
2651 git_print_header_div
('summary', $project);
2653 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
2658 ## ......................................................................
2659 ## feeds (RSS, OPML)
2662 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
2663 open my $fd, "-|", $GIT, "rev-list", "--max-count=150", git_get_head_hash
($project)
2664 or die_error
(undef, "Open git-rev-list failed");
2665 my @revlist = map { chomp; $_ } <$fd>;
2666 close $fd or die_error
(undef, "Reading git-rev-list failed");
2667 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
2668 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
2669 "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
2670 print "<channel>\n";
2671 print "<title>$project</title>\n".
2672 "<link>" . esc_html
("$my_url?p=$project;a=summary") . "</link>\n".
2673 "<description>$project log</description>\n".
2674 "<language>en</language>\n";
2676 for (my $i = 0; $i <= $#revlist; $i++) {
2677 my $commit = $revlist[$i];
2678 my %co = parse_commit
($commit);
2679 # we read 150, we always show 30 and the ones more recent than 48 hours
2680 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
2683 my %cd = parse_date
($co{'committer_epoch'});
2684 open $fd, "-|", $GIT, "diff-tree", '-r', $co{'parent'}, $co{'id'} or next;
2685 my @difftree = map { chomp; $_ } <$fd>;
2689 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
2691 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
2692 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
2693 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
2694 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
2695 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
2696 "<content:encoded>" .
2698 my $comment = $co{'comment'};
2699 foreach my $line (@
$comment) {
2700 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
2701 print "$line<br/>\n";
2704 foreach my $line (@difftree) {
2705 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
2708 my $file = validate_input
(unquote
($7));
2709 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
2710 print "$file<br/>\n";
2713 "</content:encoded>\n" .
2716 print "</channel></rss>";
2720 my @list = git_get_projects_list
();
2722 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
2723 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
2724 "<opml version=\"1.0\">\n".
2726 " <title>$site_name Git OPML Export</title>\n".
2729 "<outline text=\"git RSS feeds\">\n";
2731 foreach my $pr (@list) {
2733 my $head = git_get_head_hash
($proj{'path'});
2734 if (!defined $head) {
2737 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
2738 my %co = parse_commit
($head);
2743 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
2744 my $rss = "$my_url?p=$proj{'path'};a=rss";
2745 my $html = "$my_url?p=$proj{'path'};a=summary";
2746 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
2748 print "</outline>\n".