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 $file_parent = $cgi->param('fp');
123 if (defined $file_parent) {
124 if (!validate_input
($file_parent)) {
125 die_error
(undef, "Invalid file parent parameter");
129 our $hash = $cgi->param('h');
131 if (!validate_input
($hash)) {
132 die_error
(undef, "Invalid hash parameter");
136 our $hash_parent = $cgi->param('hp');
137 if (defined $hash_parent) {
138 if (!validate_input
($hash_parent)) {
139 die_error
(undef, "Invalid hash parent parameter");
143 our $hash_base = $cgi->param('hb');
144 if (defined $hash_base) {
145 if (!validate_input
($hash_base)) {
146 die_error
(undef, "Invalid hash base parameter");
150 our $page = $cgi->param('pg');
152 if ($page =~ m/[^0-9]$/) {
153 die_error
(undef, "Invalid page parameter");
157 our $searchtext = $cgi->param('s');
158 if (defined $searchtext) {
159 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
160 die_error
(undef, "Invalid search parameter");
162 $searchtext = quotemeta $searchtext;
167 "blame" => \
&git_blame2
,
168 "blobdiff" => \
&git_blobdiff
,
169 "blobdiff_plain" => \
&git_blobdiff_plain
,
170 "blob" => \
&git_blob
,
171 "blob_plain" => \
&git_blob_plain
,
172 "commitdiff" => \
&git_commitdiff
,
173 "commitdiff_plain" => \
&git_commitdiff_plain
,
174 "commit" => \
&git_commit
,
175 "heads" => \
&git_heads
,
176 "history" => \
&git_history
,
179 "search" => \
&git_search
,
180 "shortlog" => \
&git_shortlog
,
181 "summary" => \
&git_summary
,
183 "tags" => \
&git_tags
,
184 "tree" => \
&git_tree
,
187 $action = 'summary' if (!defined($action));
188 if (!defined($actions{$action})) {
189 die_error
(undef, "Unknown action");
191 $actions{$action}->();
194 ## ======================================================================
211 $params{"project"} ||= $project;
213 my $href = "$my_uri?";
214 $href .= esc_param
( join(";",
216 "$mapping{$_}=$params{$_}" if defined $params{$_}
224 ## ======================================================================
225 ## validation, quoting/unquoting and escaping
230 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
233 if ($input =~ m/(^|\/)(|\
.|\
.\
.)($|\
/)/) {
236 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\
-\
+\#\
~\
%]/) {
242 # quote unsafe chars, but keep the slash, even when it's not
243 # correct, but quoted slashes look too horrible in bookmarks
246 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
252 # replace invalid utf8 character with SUBSTITUTION sequence
255 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
256 $str = escapeHTML
($str);
257 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
261 # git may return quoted and escaped filenames
264 if ($str =~ m/^"(.*)"$/) {
266 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
271 # escape tabs (convert tabs to spaces)
275 while ((my $pos = index($line, "\t")) != -1) {
276 if (my $count = (8 - ($pos % 8))) {
277 my $spaces = ' ' x
$count;
278 $line =~ s/\t/$spaces/;
285 ## ----------------------------------------------------------------------
286 ## HTML aware string manipulation
291 my $add_len = shift || 10;
293 # allow only $len chars, but don't cut a word if it would fit in $add_len
294 # if it doesn't fit, cut it if it's still longer than the dots we would add
295 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
298 if (length($tail) > 4) {
300 $body =~ s/&[^;]*$//; # remove chopped character entities
305 ## ----------------------------------------------------------------------
306 ## functions returning short strings
308 # CSS class for given age value (in seconds)
312 if ($age < 60*60*2) {
314 } elsif ($age < 60*60*24*2) {
321 # convert age in seconds to "nn units ago" string
326 if ($age > 60*60*24*365*2) {
327 $age_str = (int $age/60/60/24/365);
328 $age_str .= " years ago";
329 } elsif ($age > 60*60*24*(365/12)*2) {
330 $age_str = int $age/60/60/24/(365/12);
331 $age_str .= " months ago";
332 } elsif ($age > 60*60*24*7*2) {
333 $age_str = int $age/60/60/24/7;
334 $age_str .= " weeks ago";
335 } elsif ($age > 60*60*24*2) {
336 $age_str = int $age/60/60/24;
337 $age_str .= " days ago";
338 } elsif ($age > 60*60*2) {
339 $age_str = int $age/60/60;
340 $age_str .= " hours ago";
341 } elsif ($age > 60*2) {
342 $age_str = int $age/60;
343 $age_str .= " min ago";
346 $age_str .= " sec ago";
348 $age_str .= " right now";
353 # convert file mode in octal to symbolic file mode string
355 my $mode = oct shift;
357 if (S_ISDIR
($mode & S_IFMT
)) {
359 } elsif (S_ISLNK
($mode)) {
361 } elsif (S_ISREG
($mode)) {
362 # git cares only about the executable bit
363 if ($mode & S_IXUSR
) {
373 # convert file mode in octal to file type string
375 my $mode = oct shift;
377 if (S_ISDIR
($mode & S_IFMT
)) {
379 } elsif (S_ISLNK
($mode)) {
381 } elsif (S_ISREG
($mode)) {
388 ## ----------------------------------------------------------------------
389 ## functions returning short HTML fragments, or transforming HTML fragments
390 ## which don't beling to other sections
392 # format line of commit message or tag comment
393 sub format_log_line_html
{
396 $line = esc_html
($line);
397 $line =~ s/ / /g;
398 if ($line =~ m/([0-9a-fA-F]{40})/) {
400 if (git_get_type
($hash_text) eq "commit") {
401 my $link = $cgi->a({-class => "text", -href
=> href
(action
=>"commit", hash
=>$hash_text)}, $hash_text);
402 $line =~ s/$hash_text/$link/;
408 # format marker of refs pointing to given object
409 sub format_ref_marker
{
410 my ($refs, $id) = @_;
413 if (defined $refs->{$id}) {
414 foreach my $ref (@
{$refs->{$id}}) {
415 my ($type, $name) = qw();
416 # e.g. tags/v2.6.11 or heads/next
417 if ($ref =~ m!^(.*?)s?/(.*)$!) {
425 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
430 return ' <span class="refs">'. $markers . '</span>';
436 # format, perhaps shortened and with markers, title line
437 sub format_subject_html
{
438 my ($long, $short, $href, $extra) = @_;
439 $extra = '' unless defined($extra);
441 if (length($short) < length($long)) {
442 return $cgi->a({-href
=> $href, -class => "list",
444 esc_html
($short) . $extra);
446 return $cgi->a({-href
=> $href, -class => "list"},
447 esc_html
($long) . $extra);
451 ## ----------------------------------------------------------------------
452 ## git utility subroutines, invoking git commands
454 # get HEAD ref of given project as hash
455 sub git_get_head_hash
{
457 my $oENV = $ENV{'GIT_DIR'};
459 $ENV{'GIT_DIR'} = "$projectroot/$project";
460 if (open my $fd, "-|", $GIT, "rev-parse", "--verify", "HEAD") {
463 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
468 $ENV{'GIT_DIR'} = $oENV;
473 # get type of given object
477 open my $fd, "-|", $GIT, "cat-file", '-t', $hash or return;
484 sub git_get_project_config
{
487 return unless ($key);
488 $key =~ s/^gitweb\.//;
489 return if ($key =~ m/\W/);
491 my $val = qx($GIT repo
-config
--get gitweb
.$key);
495 sub git_get_project_config_bool
{
496 my $val = git_get_project_config
(@_);
497 if ($val and $val =~ m/true|yes|on/) {
500 return; # implicit false
503 # get hash of given path at given ref
504 sub git_get_hash_by_path
{
506 my $path = shift || return undef;
510 open my $fd, "-|", $GIT, "ls-tree", $base, "--", $path
511 or die_error
(undef, "Open git-ls-tree failed");
513 close $fd or return undef;
515 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
516 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
520 ## ......................................................................
521 ## git utility functions, directly accessing git repository
523 # assumes that PATH is not symref
524 sub git_get_hash_by_ref
{
527 open my $fd, "$projectroot/$path" or return undef;
531 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
536 sub git_get_project_description
{
539 open my $fd, "$projectroot/$path/description" or return undef;
546 sub git_get_project_url_list
{
549 open my $fd, "$projectroot/$path/cloneurl" or return undef;
550 my @git_project_url_list = map { chomp; $_ } <$fd>;
553 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
556 sub git_get_projects_list
{
559 if (-d
$projects_list) {
560 # search in directory
561 my $dir = $projects_list;
562 opendir my ($dh), $dir or return undef;
563 while (my $dir = readdir($dh)) {
564 if (-e
"$projectroot/$dir/HEAD") {
572 } elsif (-f
$projects_list) {
573 # read from file(url-encoded):
574 # 'git%2Fgit.git Linus+Torvalds'
575 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
576 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
577 open my ($fd), $projects_list or return undef;
578 while (my $line = <$fd>) {
580 my ($path, $owner) = split ' ', $line;
581 $path = unescape
($path);
582 $owner = unescape
($owner);
583 if (!defined $path) {
586 if (-e
"$projectroot/$path/HEAD") {
589 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
596 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
600 sub git_get_project_owner
{
604 return undef unless $project;
606 # read from file (url-encoded):
607 # 'git%2Fgit.git Linus+Torvalds'
608 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
609 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
610 if (-f
$projects_list) {
611 open (my $fd , $projects_list);
612 while (my $line = <$fd>) {
614 my ($pr, $ow) = split ' ', $line;
617 if ($pr eq $project) {
618 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
624 if (!defined $owner) {
625 $owner = get_file_owner
("$projectroot/$project");
631 sub git_get_references
{
632 my $type = shift || "";
635 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
636 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
637 if (-f
"$projectroot/$project/info/refs") {
638 open $fd, "$projectroot/$project/info/refs"
641 open $fd, "-|", $GIT, "ls-remote", "."
645 while (my $line = <$fd>) {
647 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?[^\^]+)/) {
648 if (defined $refs{$1}) {
649 push @
{$refs{$1}}, $2;
659 ## ----------------------------------------------------------------------
660 ## parse to hash functions
664 my $tz = shift || "-0000";
667 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
668 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
669 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
670 $date{'hour'} = $hour;
671 $date{'minute'} = $min;
672 $date{'mday'} = $mday;
673 $date{'day'} = $days[$wday];
674 $date{'month'} = $months[$mon];
675 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
676 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
678 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
679 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
680 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
681 $date{'hour_local'} = $hour;
682 $date{'minute_local'} = $min;
683 $date{'tz_local'} = $tz;
692 open my $fd, "-|", $GIT, "cat-file", "tag", $tag_id or return;
693 $tag{'id'} = $tag_id;
694 while (my $line = <$fd>) {
696 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
698 } elsif ($line =~ m/^type (.+)$/) {
700 } elsif ($line =~ m/^tag (.+)$/) {
702 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
706 } elsif ($line =~ m/--BEGIN/) {
707 push @comment, $line;
709 } elsif ($line eq "") {
713 push @comment, <$fd>;
714 $tag{'comment'} = \
@comment;
716 if (!defined $tag{'name'}) {
723 my $commit_id = shift;
724 my $commit_text = shift;
729 if (defined $commit_text) {
730 @commit_lines = @
$commit_text;
733 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", "--max-count=1", $commit_id or return;
734 @commit_lines = split '\n', <$fd>;
739 my $header = shift @commit_lines;
740 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
743 ($co{'id'}, my @parents) = split ' ', $header;
744 $co{'parents'} = \
@parents;
745 $co{'parent'} = $parents[0];
746 while (my $line = shift @commit_lines) {
747 last if $line eq "\n";
748 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
750 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
752 $co{'author_epoch'} = $2;
753 $co{'author_tz'} = $3;
754 if ($co{'author'} =~ m/^([^<]+) </) {
755 $co{'author_name'} = $1;
757 $co{'author_name'} = $co{'author'};
759 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
760 $co{'committer'} = $1;
761 $co{'committer_epoch'} = $2;
762 $co{'committer_tz'} = $3;
763 $co{'committer_name'} = $co{'committer'};
764 $co{'committer_name'} =~ s/ <.*//;
767 if (!defined $co{'tree'}) {
771 foreach my $title (@commit_lines) {
774 $co{'title'} = chop_str
($title, 80, 5);
775 # remove leading stuff of merges to make the interesting part visible
776 if (length($title) > 50) {
777 $title =~ s/^Automatic //;
778 $title =~ s/^merge (of|with) /Merge ... /i;
779 if (length($title) > 50) {
780 $title =~ s/(http|rsync):\/\///;
782 if (length($title) > 50) {
783 $title =~ s/(master|www|rsync)\.//;
785 if (length($title) > 50) {
786 $title =~ s/kernel.org:?//;
788 if (length($title) > 50) {
789 $title =~ s/\/pub\/scm//;
792 $co{'title_short'} = chop_str
($title, 50, 5);
796 # remove added spaces
797 foreach my $line (@commit_lines) {
800 $co{'comment'} = \
@commit_lines;
802 my $age = time - $co{'committer_epoch'};
804 $co{'age_string'} = age_string
($age);
805 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
806 if ($age > 60*60*24*7*2) {
807 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
808 $co{'age_string_age'} = $co{'age_string'};
810 $co{'age_string_date'} = $co{'age_string'};
811 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
816 # parse ref from ref_file, given by ref_id, with given type
818 my $ref_file = shift;
820 my $type = shift || git_get_type
($ref_id);
823 $ref_item{'type'} = $type;
824 $ref_item{'id'} = $ref_id;
825 $ref_item{'epoch'} = 0;
826 $ref_item{'age'} = "unknown";
827 if ($type eq "tag") {
828 my %tag = parse_tag
($ref_id);
829 $ref_item{'comment'} = $tag{'comment'};
830 if ($tag{'type'} eq "commit") {
831 my %co = parse_commit
($tag{'object'});
832 $ref_item{'epoch'} = $co{'committer_epoch'};
833 $ref_item{'age'} = $co{'age_string'};
834 } elsif (defined($tag{'epoch'})) {
835 my $age = time - $tag{'epoch'};
836 $ref_item{'epoch'} = $tag{'epoch'};
837 $ref_item{'age'} = age_string
($age);
839 $ref_item{'reftype'} = $tag{'type'};
840 $ref_item{'name'} = $tag{'name'};
841 $ref_item{'refid'} = $tag{'object'};
842 } elsif ($type eq "commit"){
843 my %co = parse_commit
($ref_id);
844 $ref_item{'reftype'} = "commit";
845 $ref_item{'name'} = $ref_file;
846 $ref_item{'title'} = $co{'title'};
847 $ref_item{'refid'} = $ref_id;
848 $ref_item{'epoch'} = $co{'committer_epoch'};
849 $ref_item{'age'} = $co{'age_string'};
851 $ref_item{'reftype'} = $type;
852 $ref_item{'name'} = $ref_file;
853 $ref_item{'refid'} = $ref_id;
859 ## ......................................................................
860 ## parse to array of hashes functions
862 sub git_get_refs_list
{
867 my $pfxlen = length("$projectroot/$project/$ref_dir");
868 File
::Find
::find
(sub {
871 push @refs, substr($File::Find
::name
, $pfxlen + 1);
873 }, "$projectroot/$project/$ref_dir");
875 foreach my $ref_file (@refs) {
876 my $ref_id = git_get_hash_by_ref
("$project/$ref_dir/$ref_file");
877 my $type = git_get_type
($ref_id) || next;
878 my %ref_item = parse_ref
($ref_file, $ref_id, $type);
880 push @reflist, \
%ref_item;
883 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
887 ## ----------------------------------------------------------------------
888 ## filesystem-related functions
893 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
894 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
895 if (!defined $gcos) {
899 $owner =~ s/[,;].*$//;
900 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
903 ## ......................................................................
904 ## mimetype related functions
906 sub mimetype_guess_file
{
907 my $filename = shift;
909 -r
$mimemap or return undef;
912 open(MIME
, $mimemap) or return undef;
914 next if m/^#/; # skip comments
915 my ($mime, $exts) = split(/\t+/);
917 my @exts = split(/\s+/, $exts);
918 foreach my $ext (@exts) {
919 $mimemap{$ext} = $mime;
925 $filename =~ /\.(.*?)$/;
930 my $filename = shift;
932 $filename =~ /\./ or return undef;
934 if ($mimetypes_file) {
935 my $file = $mimetypes_file;
936 if ($file !~ m!^/!) { # if it is relative path
937 # it is relative to project
938 $file = "$projectroot/$project/$file";
940 $mime = mimetype_guess_file
($filename, $file);
942 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
948 my $filename = shift;
951 my $mime = mimetype_guess
($filename);
952 $mime and return $mime;
956 return $default_blob_plain_mimetype unless $fd;
959 return 'text/plain' .
960 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
961 } elsif (! $filename) {
962 return 'application/octet-stream';
963 } elsif ($filename =~ m/\.png$/i) {
965 } elsif ($filename =~ m/\.gif$/i) {
967 } elsif ($filename =~ m/\.jpe?g$/i) {
970 return 'application/octet-stream';
974 ## ======================================================================
975 ## functions printing HTML: header, footer, error page
977 sub git_header_html
{
978 my $status = shift || "200 OK";
981 my $title = "$site_name git";
982 if (defined $project) {
983 $title .= " - $project";
984 if (defined $action) {
985 $title .= "/$action";
986 if (defined $file_name) {
987 $title .= " - $file_name";
988 if ($action eq "tree" && $file_name !~ m
|/$|) {
995 # require explicit support from the UA if we are to send the page as
996 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
997 # we have to do this because MSIE sometimes globs '*/*', pretending to
998 # support xhtml+xml but choking when it gets what it asked for.
999 if (defined $cgi->http('HTTP_ACCEPT') && $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ && $cgi->Accept('application/xhtml
+xml
') != 0) {
1000 $content_type = 'application
/xhtml
+xml
';
1002 $content_type = 'text
/html
';
1004 print $cgi->header(-type=>$content_type, -charset => 'utf
-8', -status=> $status, -expires => $expires);
1006 <?xml version="1.0" encoding="utf-8"?>
1007 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1008 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1009 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1010 <!-- git core binaries version $git_version -->
1012 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1013 <meta name="generator" content="gitweb/$version git/$git_version"/>
1014 <meta name="robots" content="index, nofollow"/>
1015 <title>$title</title>
1016 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
1018 if (defined $project) {
1019 printf('<link rel="alternate" title="%s log" '.
1020 'href="%s" type="application/rss+xml"/>'."\n",
1021 esc_param
($project), href
(action
=>"rss"));
1026 "<div class=\"page_header\">\n" .
1027 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
1028 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
1030 print $cgi->a({-href
=> esc_param
($home_link)}, $home_link_str) . " / ";
1031 if (defined $project) {
1032 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1033 if (defined $action) {
1037 if (!defined $searchtext) {
1041 if (defined $hash_base) {
1042 $search_hash = $hash_base;
1043 } elsif (defined $hash) {
1044 $search_hash = $hash;
1046 $search_hash = "HEAD";
1048 $cgi->param("a", "search");
1049 $cgi->param("h", $search_hash);
1050 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
1051 "<div class=\"search\">\n" .
1052 $cgi->hidden(-name
=> "p") . "\n" .
1053 $cgi->hidden(-name
=> "a") . "\n" .
1054 $cgi->hidden(-name
=> "h") . "\n" .
1055 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1057 $cgi->end_form() . "\n";
1062 sub git_footer_html
{
1063 print "<div class=\"page_footer\">\n";
1064 if (defined $project) {
1065 my $descr = git_get_project_description
($project);
1066 if (defined $descr) {
1067 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1069 print $cgi->a({-href
=> href
(action
=>"rss"), -class => "rss_logo"}, "RSS") . "\n";
1071 print $cgi->a({-href
=> href
(action
=>"opml"), -class => "rss_logo"}, "OPML") . "\n";
1079 my $status = shift || "403 Forbidden";
1080 my $error = shift || "Malformed query, file missing or permission denied";
1082 git_header_html
($status);
1083 print "<div class=\"page_body\">\n" .
1085 "$status - $error\n" .
1092 ## ----------------------------------------------------------------------
1093 ## functions printing or outputting HTML: navigation
1095 sub git_print_page_nav
{
1096 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1097 $extra = '' if !defined $extra; # pager or formats
1099 my @navs = qw(summary shortlog log commit commitdiff tree);
1101 @navs = grep { $_ ne $suppress } @navs;
1104 my %arg = map { $_ => {action
=>$_} } @navs;
1105 if (defined $head) {
1106 for (qw(commit commitdiff)) {
1107 $arg{$_}{hash
} = $head;
1109 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1110 for (qw(shortlog log)) {
1111 $arg{$_}{hash
} = $head;
1115 $arg{tree
}{hash
} = $treehead if defined $treehead;
1116 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1118 print "<div class=\"page_nav\">\n" .
1120 map { $_ eq $current ?
1121 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1123 print "<br/>\n$extra<br/>\n" .
1127 sub format_paging_nav
{
1128 my ($action, $hash, $head, $page, $nrevs) = @_;
1132 if ($hash ne $head || $page) {
1133 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1135 $paging_nav .= "HEAD";
1139 $paging_nav .= " ⋅ " .
1140 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1141 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1143 $paging_nav .= " ⋅ prev";
1146 if ($nrevs >= (100 * ($page+1)-1)) {
1147 $paging_nav .= " ⋅ " .
1148 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1149 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1151 $paging_nav .= " ⋅ next";
1157 ## ......................................................................
1158 ## functions printing or outputting HTML: div
1160 sub git_print_header_div
{
1161 my ($action, $title, $hash, $hash_base) = @_;
1164 $args{action
} = $action;
1165 $args{hash
} = $hash if $hash;
1166 $args{hash_base
} = $hash_base if $hash_base;
1168 print "<div class=\"header\">\n" .
1169 $cgi->a({-href
=> href
(%args), -class => "title"},
1170 $title ?
$title : $action) .
1174 sub git_print_page_path
{
1178 if (!defined $name) {
1179 print "<div class=\"page_path\"><b>/</b></div>\n";
1180 } elsif (defined $type && $type eq 'blob') {
1181 print "<div class=\"page_path\"><b>" .
1182 $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name)}, esc_html
($name)) . "</b><br/></div>\n";
1184 print "<div class=\"page_path\"><b>" . esc_html
($name) . "</b><br/></div>\n";
1188 ## ......................................................................
1189 ## functions printing large fragments of HTML
1191 sub git_difftree_body
{
1192 my ($difftree, $parent) = @_;
1194 print "<div class=\"list_head\">\n";
1195 if ($#{$difftree} > 10) {
1196 print(($#{$difftree} + 1) . " files changed:\n");
1200 print "<table class=\"diff_tree\">\n";
1202 foreach my $line (@
{$difftree}) {
1203 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1204 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1205 if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1213 my $similarity = $6; # score
1214 my $file = validate_input
(unquote
($7));
1217 print "<tr class=\"dark\">\n";
1219 print "<tr class=\"light\">\n";
1223 if ($status eq "A") { # created
1225 if (S_ISREG
(oct $to_mode)) {
1226 $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
1229 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$file),
1230 -class => "list"}, esc_html
($file)) .
1232 "<td><span class=\"file_status new\">[new " . file_type
($to_mode) . "$mode_chng]</span></td>\n" .
1233 "<td class=\"link\">" .
1234 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$file)}, "blob") .
1237 } elsif ($status eq "D") { # deleted
1239 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$from_id, hash_base
=>$parent, file_name
=>$file),
1240 -class => "list"}, esc_html
($file)) . "</td>\n" .
1241 "<td><span class=\"file_status deleted\">[deleted " . file_type
($from_mode). "]</span></td>\n" .
1242 "<td class=\"link\">" .
1243 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$from_id, hash_base
=>$parent, file_name
=>$file)}, "blob") . " | " .
1244 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent, file_name
=>$file)}, "history") .
1247 } elsif ($status eq "M" || $status eq "T") { # modified, or type changed
1248 my $mode_chnge = "";
1249 if ($from_mode != $to_mode) {
1250 $mode_chnge = " <span class=\"file_status mode_chnge\">[changed";
1251 if (((oct $from_mode) & S_IFMT
) != ((oct $to_mode) & S_IFMT
)) {
1252 $mode_chnge .= " from " . file_type
($from_mode) . " to " . file_type
($to_mode);
1254 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
1255 if (S_ISREG
($from_mode) && S_ISREG
($to_mode)) {
1256 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
1257 } elsif (S_ISREG
($to_mode)) {
1258 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
1261 $mode_chnge .= "]</span>\n";
1264 if ($to_id ne $from_id) { # modified
1265 print $cgi->a({-href
=> href
(action
=>"blobdiff", hash
=>$to_id, hash_parent
=>$from_id, hash_base
=>$hash, file_name
=>$file),
1266 -class => "list"}, esc_html
($file));
1267 } else { # mode changed
1268 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$file),
1269 -class => "list"}, esc_html
($file));
1272 "<td>$mode_chnge</td>\n" .
1273 "<td class=\"link\">" .
1274 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$file)}, "blob");
1275 if ($to_id ne $from_id) { # modified
1276 print " | " . $cgi->a({-href
=> href
(action
=>"blobdiff", hash
=>$to_id, hash_parent
=>$from_id, hash_base
=>$hash, file_name
=>$file)}, "diff");
1278 print " | " . $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash, file_name
=>$file)}, "history") . "\n";
1281 } elsif ($status eq "R") { # renamed
1282 my ($from_file, $to_file) = split "\t", $file;
1284 if ($from_mode != $to_mode) {
1285 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
1288 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$to_file),
1289 -class => "list"}, esc_html
($to_file)) . "</td>\n" .
1290 "<td><span class=\"file_status moved\">[moved from " .
1291 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$from_id, hash_base
=>$parent, file_name
=>$from_file),
1292 -class => "list"}, esc_html
($from_file)) .
1293 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
1294 "<td class=\"link\">" .
1295 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$to_file)}, "blob");
1296 if ($to_id ne $from_id) {
1298 $cgi->a({-href
=> href
(action
=>"blobdiff", hash
=>$to_id, hash_parent
=>$from_id, hash_base
=>$hash, file_name
=>$to_file, file_parent
=>$from_file)}, "diff");
1302 } elsif ($status eq "C") { # copied
1303 my ($from_file, $to_file) = split "\t", $file;
1305 if ($from_mode != $to_mode) {
1306 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
1309 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$to_file),
1310 -class => "list"}, esc_html
($to_file)) . "</td>\n" .
1311 "<td><span class=\"file_status copied\">[copied from " .
1312 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$from_id, hash_base
=>$parent, file_name
=>$from_file),
1313 -class => "list"}, esc_html
($from_file)) .
1314 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
1315 "<td class=\"link\">" .
1316 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$to_file)}, "blob");
1317 if ($to_id ne $from_id) {
1319 $cgi->a({-href
=> href
(action
=>"blobdiff", hash
=>$to_id, hash_parent
=>$from_id, hash_base
=>$hash, file_name
=>$to_file, file_parent
=>$from_file)}, "diff");
1322 } # we should not encounter Unmerged (U) or Unknown (X) status
1328 sub git_shortlog_body
{
1329 # uses global variable $project
1330 my ($revlist, $from, $to, $refs, $extra) = @_;
1331 $from = 0 unless defined $from;
1332 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1334 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
1336 for (my $i = $from; $i <= $to; $i++) {
1337 my $commit = $revlist->[$i];
1338 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
1339 my $ref = format_ref_marker
($refs, $commit);
1340 my %co = parse_commit
($commit);
1342 print "<tr class=\"dark\">\n";
1344 print "<tr class=\"light\">\n";
1347 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1348 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1349 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
1351 print format_subject_html
($co{'title'}, $co{'title_short'}, href
(action
=>"commit", hash
=>$commit), $ref);
1353 "<td class=\"link\">" .
1354 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
1355 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
1359 if (defined $extra) {
1361 "<td colspan=\"4\">$extra</td>\n" .
1367 sub git_history_body
{
1368 # Warning: assumes constant type (blob or tree) during history
1369 my ($fd, $refs, $hash_base, $ftype, $extra) = @_;
1371 print "<table class=\"history\" cellspacing=\"0\">\n";
1373 while (my $line = <$fd>) {
1374 if ($line !~ m/^([0-9a-fA-F]{40})/) {
1379 my %co = parse_commit
($commit);
1384 my $ref = format_ref_marker
($refs, $commit);
1387 print "<tr class=\"dark\">\n";
1389 print "<tr class=\"light\">\n";
1392 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1393 # shortlog uses chop_str($co{'author_name'}, 10)
1394 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
1396 # originally git_history used chop_str($co{'title'}, 50)
1397 print format_subject_html
($co{'title'}, $co{'title_short'}, href
(action
=>"commit", hash
=>$commit), $ref);
1399 "<td class=\"link\">" .
1400 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
1401 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
1402 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype);
1404 if ($ftype eq 'blob') {
1405 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
1406 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
1407 if (defined $blob_current && defined $blob_parent &&
1408 $blob_current ne $blob_parent) {
1410 $cgi->a({-href
=> href
(action
=>"blobdiff", hash
=>$blob_current, hash_parent
=>$blob_parent, hash_base
=>$commit, file_name
=>$file_name)},
1417 if (defined $extra) {
1419 "<td colspan=\"4\">$extra</td>\n" .
1426 # uses global variable $project
1427 my ($taglist, $from, $to, $extra) = @_;
1428 $from = 0 unless defined $from;
1429 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1431 print "<table class=\"tags\" cellspacing=\"0\">\n";
1433 for (my $i = $from; $i <= $to; $i++) {
1434 my $entry = $taglist->[$i];
1436 my $comment_lines = $tag{'comment'};
1437 my $comment = shift @
$comment_lines;
1439 if (defined $comment) {
1440 $comment_short = chop_str
($comment, 30, 5);
1443 print "<tr class=\"dark\">\n";
1445 print "<tr class=\"light\">\n";
1448 print "<td><i>$tag{'age'}</i></td>\n" .
1450 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
1451 -class => "list"}, "<b>" . esc_html
($tag{'name'}) . "</b>") .
1454 if (defined $comment) {
1455 print format_subject_html
($comment, $comment_short, href
(action
=>"tag", hash
=>$tag{'id'}));
1458 "<td class=\"selflink\">";
1459 if ($tag{'type'} eq "tag") {
1460 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
1465 "<td class=\"link\">" . " | " .
1466 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
1467 if ($tag{'reftype'} eq "commit") {
1468 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
1469 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'refid'})}, "log");
1470 } elsif ($tag{'reftype'} eq "blob") {
1471 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
1476 if (defined $extra) {
1478 "<td colspan=\"5\">$extra</td>\n" .
1484 sub git_heads_body
{
1485 # uses global variable $project
1486 my ($taglist, $head, $from, $to, $extra) = @_;
1487 $from = 0 unless defined $from;
1488 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1490 print "<table class=\"heads\" cellspacing=\"0\">\n";
1492 for (my $i = $from; $i <= $to; $i++) {
1493 my $entry = $taglist->[$i];
1495 my $curr = $tag{'id'} eq $head;
1497 print "<tr class=\"dark\">\n";
1499 print "<tr class=\"light\">\n";
1502 print "<td><i>$tag{'age'}</i></td>\n" .
1503 ($tag{'id'} eq $head ?
"<td class=\"current_head\">" : "<td>") .
1504 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'}),
1505 -class => "list"}, "<b>" . esc_html
($tag{'name'}) . "</b>") .
1507 "<td class=\"link\">" .
1508 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") . " | " .
1509 $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log") .
1513 if (defined $extra) {
1515 "<td colspan=\"3\">$extra</td>\n" .
1521 ## ----------------------------------------------------------------------
1522 ## functions printing large fragments, format as one of arguments
1524 sub git_diff_print
{
1526 my $from_name = shift;
1528 my $to_name = shift;
1529 my $format = shift || "html";
1531 my $from_tmp = "/dev/null";
1532 my $to_tmp = "/dev/null";
1535 # create tmp from-file
1536 if (defined $from) {
1537 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
1538 open my $fd2, "> $from_tmp";
1539 open my $fd, "-|", $GIT, "cat-file", "blob", $from;
1546 # create tmp to-file
1548 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
1549 open my $fd2, "> $to_tmp";
1550 open my $fd, "-|", $GIT, "cat-file", "blob", $to;
1557 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
1558 if ($format eq "plain") {
1563 while (my $line = <$fd>) {
1565 my $char = substr($line, 0, 1);
1566 my $diff_class = "";
1568 $diff_class = " add";
1569 } elsif ($char eq "-") {
1570 $diff_class = " rem";
1571 } elsif ($char eq "@") {
1572 $diff_class = " chunk_header";
1573 } elsif ($char eq "\\") {
1577 $line = untabify
($line);
1578 print "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
1583 if (defined $from) {
1592 ## ======================================================================
1593 ## ======================================================================
1596 sub git_project_list
{
1597 my $order = $cgi->param('o');
1598 if (defined $order && $order !~ m/project|descr|owner|age/) {
1599 die_error
(undef, "Unknown order parameter");
1602 my @list = git_get_projects_list
();
1605 die_error
(undef, "No projects found");
1607 foreach my $pr (@list) {
1608 my $head = git_get_head_hash
($pr->{'path'});
1609 if (!defined $head) {
1612 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
1613 my %co = parse_commit
($head);
1617 $pr->{'commit'} = \
%co;
1618 if (!defined $pr->{'descr'}) {
1619 my $descr = git_get_project_description
($pr->{'path'}) || "";
1620 $pr->{'descr'} = chop_str
($descr, 25, 5);
1622 if (!defined $pr->{'owner'}) {
1623 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
1625 push @projects, $pr;
1629 if (-f
$home_text) {
1630 print "<div class=\"index_include\">\n";
1631 open (my $fd, $home_text);
1636 print "<table class=\"project_list\">\n" .
1638 $order ||= "project";
1639 if ($order eq "project") {
1640 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
1641 print "<th>Project</th>\n";
1644 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=project"),
1645 -class => "header"}, "Project") .
1648 if ($order eq "descr") {
1649 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
1650 print "<th>Description</th>\n";
1653 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=descr"),
1654 -class => "header"}, "Description") .
1657 if ($order eq "owner") {
1658 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
1659 print "<th>Owner</th>\n";
1662 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=owner"),
1663 -class => "header"}, "Owner") .
1666 if ($order eq "age") {
1667 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
1668 print "<th>Last Change</th>\n";
1671 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=age"),
1672 -class => "header"}, "Last Change") .
1675 print "<th></th>\n" .
1678 foreach my $pr (@projects) {
1680 print "<tr class=\"dark\">\n";
1682 print "<tr class=\"light\">\n";
1685 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
1686 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
1687 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
1688 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
1689 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" .
1690 $pr->{'commit'}{'age_string'} . "</td>\n" .
1691 "<td class=\"link\">" .
1692 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
1693 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
1694 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") .
1703 my $descr = git_get_project_description
($project) || "none";
1704 my $head = git_get_head_hash
($project);
1705 my %co = parse_commit
($head);
1706 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
1708 my $owner = git_get_project_owner
($project);
1710 my $refs = git_get_references
();
1712 git_print_page_nav
('summary','', $head);
1714 print "<div class=\"title\"> </div>\n";
1715 print "<table cellspacing=\"0\">\n" .
1716 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
1717 "<tr><td>owner</td><td>$owner</td></tr>\n" .
1718 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
1719 # use per project git URL list in $projectroot/$project/cloneurl
1720 # or make project git URL from git base URL and project name
1721 my $url_tag = "URL";
1722 my @url_list = git_get_project_url_list
($project);
1723 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
1724 foreach my $git_url (@url_list) {
1725 next unless $git_url;
1726 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
1731 open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_get_head_hash
($project)
1732 or die_error
(undef, "Open git-rev-list failed");
1733 my @revlist = map { chomp; $_ } <$fd>;
1735 git_print_header_div
('shortlog');
1736 git_shortlog_body
(\
@revlist, 0, 15, $refs,
1737 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
1739 my $taglist = git_get_refs_list
("refs/tags");
1740 if (defined @
$taglist) {
1741 git_print_header_div
('tags');
1742 git_tags_body
($taglist, 0, 15,
1743 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
1746 my $headlist = git_get_refs_list
("refs/heads");
1747 if (defined @
$headlist) {
1748 git_print_header_div
('heads');
1749 git_heads_body
($headlist, $head, 0, 15,
1750 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
1757 my $head = git_get_head_hash
($project);
1759 git_print_page_nav
('','', $head,undef,$head);
1760 my %tag = parse_tag
($hash);
1761 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
1762 print "<div class=\"title_text\">\n" .
1763 "<table cellspacing=\"0\">\n" .
1765 "<td>object</td>\n" .
1766 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})}, $tag{'object'}) . "</td>\n" .
1767 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})}, $tag{'type'}) . "</td>\n" .
1769 if (defined($tag{'author'})) {
1770 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
1771 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
1772 print "<tr><td></td><td>" . $ad{'rfc2822'} . sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) . "</td></tr>\n";
1774 print "</table>\n\n" .
1776 print "<div class=\"page_body\">";
1777 my $comment = $tag{'comment'};
1778 foreach my $line (@
$comment) {
1779 print esc_html
($line) . "<br/>\n";
1788 die_error
(undef, "Permission denied") if (!git_get_project_config_bool
('blame'));
1789 die_error
('404 Not Found', "File name not defined") if (!$file_name);
1790 $hash_base ||= git_get_head_hash
($project);
1791 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
1792 my %co = parse_commit
($hash_base)
1793 or die_error
(undef, "Reading commit failed");
1794 if (!defined $hash) {
1795 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
1796 or die_error
(undef, "Error looking up file");
1798 $ftype = git_get_type
($hash);
1799 if ($ftype !~ "blob") {
1800 die_error
("400 Bad Request", "Object is not a blob");
1802 open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base)
1803 or die_error
(undef, "Open git-blame failed");
1806 $cgi->a({-href
=> href
(action
=>"blobl", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)}, "blob") .
1807 " | " . $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)}, "head");
1808 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1809 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
1810 git_print_page_path
($file_name, $ftype);
1811 my @rev_color = (qw(light2 dark2));
1812 my $num_colors = scalar(@rev_color);
1813 my $current_color = 0;
1815 print "<div class=\"page_body\">\n";
1816 print "<table class=\"blame\">\n";
1817 print "<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n";
1819 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
1821 my $rev = substr($full_rev, 0, 8);
1825 if (!defined $last_rev) {
1826 $last_rev = $full_rev;
1827 } elsif ($last_rev ne $full_rev) {
1828 $last_rev = $full_rev;
1829 $current_color = ++$current_color % $num_colors;
1831 print "<tr class=\"$rev_color[$current_color]\">\n";
1832 print "<td class=\"sha1\">" .
1833 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$full_rev, file_name
=>$file_name)}, esc_html
($rev)) . "</td>\n";
1834 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" . esc_html
($lineno) . "</a></td>\n";
1835 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
1840 close $fd or print "Reading blob failed\n";
1846 die_error
('403 Permission denied', "Permission denied") if (!git_get_project_config_bool
('blame'));
1847 die_error
('404 Not Found', "File name not defined") if (!$file_name);
1848 $hash_base ||= git_get_head_hash
($project);
1849 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
1850 my %co = parse_commit
($hash_base)
1851 or die_error
(undef, "Reading commit failed");
1852 if (!defined $hash) {
1853 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
1854 or die_error
(undef, "Error lookup file");
1856 open ($fd, "-|", $GIT, "annotate", '-l', '-t', '-r', $file_name, $hash_base)
1857 or die_error
(undef, "Open git-annotate failed");
1860 $cgi->a({-href
=> href
(action
=>"blobl", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)}, "blob") .
1861 " | " . $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)}, "head");
1862 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1863 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
1864 git_print_page_path
($file_name, 'blob');
1865 print "<div class=\"page_body\">\n";
1867 <table class="blame">
1876 my @line_class = (qw(light dark));
1877 my $line_class_len = scalar (@line_class);
1878 my $line_class_num = $#line_class;
1879 while (my $line = <$fd>) {
1891 $line_class_num = ($line_class_num + 1) % $line_class_len;
1893 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) \+\d\d\d\d\t(\d+)\)(.*)$/) {
1900 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
1903 $short_rev = substr ($long_rev, 0, 8);
1904 $age = time () - $time;
1905 $age_str = age_string
($age);
1906 $age_str =~ s/ / /g;
1907 $age_class = age_class
($age);
1908 $author = esc_html
($author);
1909 $author =~ s/ / /g;
1911 $data = untabify
($data);
1912 $data = esc_html
($data);
1915 <tr class="$line_class[$line_class_num]">
1916 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
1917 <td class="$age_class">$age_str</td>
1919 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
1920 <td class="pre">$data</td>
1923 } # while (my $line = <$fd>)
1924 print "</table>\n\n";
1925 close $fd or print "Reading blob failed.\n";
1931 my $head = git_get_head_hash
($project);
1933 git_print_page_nav
('','', $head,undef,$head);
1934 git_print_header_div
('summary', $project);
1936 my $taglist = git_get_refs_list
("refs/tags");
1937 if (defined @
$taglist) {
1938 git_tags_body
($taglist);
1944 my $head = git_get_head_hash
($project);
1946 git_print_page_nav
('','', $head,undef,$head);
1947 git_print_header_div
('summary', $project);
1949 my $taglist = git_get_refs_list
("refs/heads");
1950 if (defined @
$taglist) {
1951 git_heads_body
($taglist, $head);
1956 sub git_blob_plain
{
1957 if (!defined $hash) {
1958 if (defined $file_name) {
1959 my $base = $hash_base || git_get_head_hash
($project);
1960 $hash = git_get_hash_by_path
($base, $file_name, "blob")
1961 or die_error
(undef, "Error lookup file");
1963 die_error
(undef, "No file name defined");
1967 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
1968 or die_error
(undef, "Couldn't cat $file_name, $hash");
1970 $type ||= blob_mimetype
($fd, $file_name);
1972 # save as filename, even when no $file_name is given
1973 my $save_as = "$hash";
1974 if (defined $file_name) {
1975 $save_as = $file_name;
1976 } elsif ($type =~ m/^text\//) {
1980 print $cgi->header(-type
=> "$type", '-content-disposition' => "inline; filename=\"$save_as\"");
1982 binmode STDOUT
, ':raw';
1984 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
1990 if (!defined $hash) {
1991 if (defined $file_name) {
1992 my $base = $hash_base || git_get_head_hash
($project);
1993 $hash = git_get_hash_by_path
($base, $file_name, "blob")
1994 or die_error
(undef, "Error lookup file");
1996 die_error
(undef, "No file name defined");
1999 my $have_blame = git_get_project_config_bool
('blame');
2000 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
2001 or die_error
(undef, "Couldn't cat $file_name, $hash");
2002 my $mimetype = blob_mimetype
($fd, $file_name);
2003 if ($mimetype !~ m/^text\//) {
2005 return git_blob_plain
($mimetype);
2008 my $formats_nav = '';
2009 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2010 if (defined $file_name) {
2012 $formats_nav .= $cgi->a({-href
=> href
(action
=>"blame", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)}, "blame") . " | ";
2015 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash, file_name
=>$file_name)}, "plain") .
2016 " | " . $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>"HEAD", file_name
=>$file_name)}, "head");
2018 $formats_nav .= $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "plain");
2020 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2021 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2023 print "<div class=\"page_nav\">\n" .
2024 "<br/><br/></div>\n" .
2025 "<div class=\"title\">$hash</div>\n";
2027 git_print_page_path
($file_name, "blob");
2028 print "<div class=\"page_body\">\n";
2030 while (my $line = <$fd>) {
2033 $line = untabify
($line);
2034 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", $nr, $nr, $nr, esc_html
($line);
2036 close $fd or print "Reading blob failed.\n";
2042 if (!defined $hash) {
2043 $hash = git_get_head_hash
($project);
2044 if (defined $file_name) {
2045 my $base = $hash_base || $hash;
2046 $hash = git_get_hash_by_path
($base, $file_name, "tree");
2048 if (!defined $hash_base) {
2053 open my $fd, "-|", $GIT, "ls-tree", '-z', $hash
2054 or die_error
(undef, "Open git-ls-tree failed");
2055 my @entries = map { chomp; $_ } <$fd>;
2056 close $fd or die_error
(undef, "Reading tree failed");
2059 my $refs = git_get_references
();
2060 my $ref = format_ref_marker
($refs, $hash_base);
2064 my $have_blame = git_get_project_config_bool
('blame');
2065 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2066 $base_key{hash_base
} = $hash_base;
2067 git_print_page_nav
('tree','', $hash_base);
2068 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
2070 print "<div class=\"page_nav\">\n";
2071 print "<br/><br/></div>\n";
2072 print "<div class=\"title\">$hash</div>\n";
2074 if (defined $file_name) {
2075 $base = esc_html
("$file_name/");
2077 git_print_page_path
($file_name, 'tree');
2078 print "<div class=\"page_body\">\n";
2079 print "<table cellspacing=\"0\">\n";
2081 foreach my $line (@entries) {
2082 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2083 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
2087 my $t_name = validate_input
($4);
2089 print "<tr class=\"dark\">\n";
2091 print "<tr class=\"light\">\n";
2094 print "<td class=\"mode\">" . mode_str
($t_mode) . "</td>\n";
2095 if ($t_type eq "blob") {
2096 print "<td class=\"list\">" .
2097 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key), -class => "list"}, esc_html
($t_name)) .
2099 "<td class=\"link\">" .
2100 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)}, "blob");
2102 print " | " . $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)}, "blame");
2104 print " | " . $cgi->a({-href
=> href
(action
=>"history", hash
=>$t_hash, hash_base
=>$hash_base, file_name
=>"$base$t_name")}, "history") .
2105 " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$t_hash, file_name
=>"$base$t_name")}, "raw") .
2107 } elsif ($t_type eq "tree") {
2108 print "<td class=\"list\">" .
2109 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)}, esc_html
($t_name)) .
2111 "<td class=\"link\">" .
2112 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)}, "tree") .
2113 " | " . $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base, file_name
=>"$base$t_name")}, "history") .
2118 print "</table>\n" .
2124 my $head = git_get_head_hash
($project);
2125 if (!defined $hash) {
2128 if (!defined $page) {
2131 my $refs = git_get_references
();
2133 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2134 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2135 or die_error
(undef, "Open git-rev-list failed");
2136 my @revlist = map { chomp; $_ } <$fd>;
2139 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
2142 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
2145 my %co = parse_commit
($hash);
2147 git_print_header_div
('summary', $project);
2148 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
2150 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2151 my $commit = $revlist[$i];
2152 my $ref = format_ref_marker
($refs, $commit);
2153 my %co = parse_commit
($commit);
2155 my %ad = parse_date
($co{'author_epoch'});
2156 git_print_header_div
('commit',
2157 "<span class=\"age\">$co{'age_string'}</span>" .
2158 esc_html
($co{'title'}) . $ref,
2160 print "<div class=\"title_text\">\n" .
2161 "<div class=\"log_link\">\n" .
2162 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
2163 " | " . $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
2166 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
2168 "<div class=\"log_body\">\n";
2169 my $comment = $co{'comment'};
2171 foreach my $line (@
$comment) {
2172 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2183 print format_log_line_html
($line) . "<br/>\n";
2194 my %co = parse_commit
($hash);
2196 die_error
(undef, "Unknown commit object");
2198 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2199 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2201 my $parent = $co{'parent'};
2202 if (!defined $parent) {
2205 open my $fd, "-|", $GIT, "diff-tree", '-r', '-M', $parent, $hash
2206 or die_error
(undef, "Open git-diff-tree failed");
2207 my @difftree = map { chomp; $_ } <$fd>;
2208 close $fd or die_error
(undef, "Reading git-diff-tree failed");
2210 # non-textual hash id's can be cached
2212 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2215 my $refs = git_get_references
();
2216 my $ref = format_ref_marker
($refs, $co{'id'});
2217 my $formats_nav = '';
2218 if (defined $file_name && defined $co{'parent'}) {
2219 my $parent = $co{'parent'};
2220 $formats_nav .= $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)}, "blame");
2222 git_header_html
(undef, $expires);
2223 git_print_page_nav
('commit', defined $co{'parent'} ?
'' : 'commitdiff',
2224 $hash, $co{'tree'}, $hash,
2227 if (defined $co{'parent'}) {
2228 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
2230 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
2232 print "<div class=\"title_text\">\n" .
2233 "<table cellspacing=\"0\">\n";
2234 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
2236 "<td></td><td> $ad{'rfc2822'}";
2237 if ($ad{'hour_local'} < 6) {
2238 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2240 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2244 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
2245 print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
2246 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
2249 "<td class=\"sha1\">" .
2250 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash), class => "list"}, $co{'tree'}) .
2252 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)}, "tree") .
2255 my $parents = $co{'parents'};
2256 foreach my $par (@
$parents) {
2259 "<td class=\"sha1\">" . $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par), class => "list"}, $par) . "</td>" .
2260 "<td class=\"link\">" .
2261 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
2262 " | " . $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "commitdiff") .
2268 print "<div class=\"page_body\">\n";
2269 my $comment = $co{'comment'};
2272 foreach my $line (@
$comment) {
2273 # print only one empty line
2275 if ($empty || $signed) {
2282 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2284 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
2287 print format_log_line_html
($line) . "<br/>\n";
2292 git_difftree_body
(\
@difftree, $parent);
2298 mkdir($git_temp, 0700);
2300 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2302 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", hash
=>$hash, hash_parent
=>$hash_parent)}, "plain");
2303 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2304 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2306 print "<div class=\"page_nav\">\n" .
2307 "<br/><br/></div>\n" .
2308 "<div class=\"title\">$hash vs $hash_parent</div>\n";
2310 git_print_page_path
($file_name, "blob");
2311 print "<div class=\"page_body\">\n" .
2312 "<div class=\"diff_info\">blob:" .
2313 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash_parent, hash_base
=>$hash_base, file_name
=>($file_parent || $file_name))}, $hash_parent) .
2315 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)}, $hash) .
2317 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
2322 sub git_blobdiff_plain
{
2323 mkdir($git_temp, 0700);
2324 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8');
2325 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
2328 sub git_commitdiff
{
2329 mkdir($git_temp, 0700);
2330 my %co = parse_commit
($hash);
2332 die_error
(undef, "Unknown commit object");
2334 if (!defined $hash_parent) {
2335 $hash_parent = $co{'parent'} || '--root';
2337 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2338 or die_error
(undef, "Open git-diff-tree failed");
2339 my @difftree = map { chomp; $_ } <$fd>;
2340 close $fd or die_error
(undef, "Reading git-diff-tree failed");
2342 # non-textual hash id's can be cached
2344 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2347 my $refs = git_get_references
();
2348 my $ref = format_ref_marker
($refs, $co{'id'});
2350 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", hash
=>$hash, hash_parent
=>$hash_parent)}, "plain");
2351 git_header_html
(undef, $expires);
2352 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
2353 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
2354 print "<div class=\"page_body\">\n";
2355 my $comment = $co{'comment'};
2358 my @log = @
$comment;
2359 # remove first and empty lines after that
2361 while (defined $log[0] && $log[0] eq "") {
2364 foreach my $line (@log) {
2365 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
2376 print format_log_line_html
($line) . "<br/>\n";
2379 foreach my $line (@difftree) {
2380 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2381 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2382 if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2390 my $file = validate_input
(unquote
($6));
2391 if ($status eq "A") {
2392 print "<div class=\"diff_info\">" . file_type
($to_mode) . ":" .
2393 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$file)}, $to_id) . "(new)" .
2395 git_diff_print
(undef, "/dev/null", $to_id, "b/$file");
2396 } elsif ($status eq "D") {
2397 print "<div class=\"diff_info\">" . file_type
($from_mode) . ":" .
2398 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$from_id, hash_base
=>$hash_parent, file_name
=>$file)}, $from_id) . "(deleted)" .
2400 git_diff_print
($from_id, "a/$file", undef, "/dev/null");
2401 } elsif ($status eq "M") {
2402 if ($from_id ne $to_id) {
2403 print "<div class=\"diff_info\">" .
2404 file_type
($from_mode) . ":" .
2405 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$from_id, hash_base
=>$hash_parent, file_name
=>$file)}, $from_id) .
2407 file_type
($to_mode) . ":" .
2408 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$file)}, $to_id) .
2410 git_diff_print
($from_id, "a/$file", $to_id, "b/$file");
2419 sub git_commitdiff_plain
{
2420 mkdir($git_temp, 0700);
2421 my %co = parse_commit
($hash);
2423 die_error
(undef, "Unknown commit object");
2425 if (!defined $hash_parent) {
2426 $hash_parent = $co{'parent'} || '--root';
2428 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2429 or die_error
(undef, "Open git-diff-tree failed");
2430 my @difftree = map { chomp; $_ } <$fd>;
2431 close $fd or die_error
(undef, "Reading diff-tree failed");
2433 # try to figure out the next tag after this commit
2435 my $refs = git_get_references
("tags");
2436 open $fd, "-|", $GIT, "rev-list", "HEAD";
2437 my @commits = map { chomp; $_ } <$fd>;
2439 foreach my $commit (@commits) {
2440 if (defined $refs->{$commit}) {
2441 $tagname = $refs->{$commit}
2443 if ($commit eq $hash) {
2448 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8', '-content-disposition' => "inline; filename=\"git-$hash.patch\"");
2449 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2450 my $comment = $co{'comment'};
2451 print "From: $co{'author'}\n" .
2452 "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
2453 "Subject: $co{'title'}\n";
2454 if (defined $tagname) {
2455 print "X-Git-Tag: $tagname\n";
2457 print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
2460 foreach my $line (@
$comment) {;
2465 foreach my $line (@difftree) {
2466 if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2473 if ($status eq "A") {
2474 git_diff_print
(undef, "/dev/null", $to_id, "b/$file", "plain");
2475 } elsif ($status eq "D") {
2476 git_diff_print
($from_id, "a/$file", undef, "/dev/null", "plain");
2477 } elsif ($status eq "M") {
2478 git_diff_print
($from_id, "a/$file", $to_id, "b/$file", "plain");
2484 if (!defined $hash_base) {
2485 $hash_base = git_get_head_hash
($project);
2488 my %co = parse_commit
($hash_base);
2490 die_error
(undef, "Unknown commit object");
2492 my $refs = git_get_references
();
2494 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base);
2495 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2496 if (!defined $hash && defined $file_name) {
2497 $hash = git_get_hash_by_path
($hash_base, $file_name);
2499 if (defined $hash) {
2500 $ftype = git_get_type
($hash);
2502 git_print_page_path
($file_name, $ftype);
2505 $GIT, "rev-list", "--full-history", $hash_base, "--", $file_name;
2506 git_history_body
($fd, $refs, $hash_base, $ftype);
2513 if (!defined $searchtext) {
2514 die_error
(undef, "Text field empty");
2516 if (!defined $hash) {
2517 $hash = git_get_head_hash
($project);
2519 my %co = parse_commit
($hash);
2521 die_error
(undef, "Unknown commit object");
2523 # pickaxe may take all resources of your box and run for several minutes
2524 # with every query - so decide by yourself how public you make this feature :)
2525 my $commit_search = 1;
2526 my $author_search = 0;
2527 my $committer_search = 0;
2528 my $pickaxe_search = 0;
2529 if ($searchtext =~ s/^author\\://i) {
2531 } elsif ($searchtext =~ s/^committer\\://i) {
2532 $committer_search = 1;
2533 } elsif ($searchtext =~ s/^pickaxe\\://i) {
2535 $pickaxe_search = 1;
2538 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
2539 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
2541 print "<table cellspacing=\"0\">\n";
2543 if ($commit_search) {
2545 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", $hash or next;
2546 while (my $commit_text = <$fd>) {
2547 if (!grep m/$searchtext/i, $commit_text) {
2550 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
2553 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
2556 my @commit_lines = split "\n", $commit_text;
2557 my %co = parse_commit
(undef, \
@commit_lines);
2562 print "<tr class=\"dark\">\n";
2564 print "<tr class=\"light\">\n";
2567 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2568 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2570 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}) -class => "list"}, "<b>" . esc_html
(chop_str
($co{'title'}, 50)) . "</b><br/>");
2571 my $comment = $co{'comment'};
2572 foreach my $line (@
$comment) {
2573 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2574 my $lead = esc_html
($1) || "";
2575 $lead = chop_str
($lead, 30, 10);
2576 my $match = esc_html
($2) || "";
2577 my $trail = esc_html
($3) || "";
2578 $trail = chop_str
($trail, 30, 10);
2579 my $text = "$lead<span class=\"match\">$match</span>$trail";
2580 print chop_str
($text, 80, 5) . "<br/>\n";
2584 "<td class=\"link\">" .
2585 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
2586 " | " . $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
2593 if ($pickaxe_search) {
2595 open my $fd, "-|", "$GIT rev-list $hash | $GIT diff-tree -r --stdin -S\'$searchtext\'";
2598 while (my $line = <$fd>) {
2599 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2602 $set{'from_id'} = $3;
2604 $set{'id'} = $set{'to_id'};
2605 if ($set{'id'} =~ m/0{40}/) {
2606 $set{'id'} = $set{'from_id'};
2608 if ($set{'id'} =~ m/0{40}/) {
2612 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
2615 print "<tr class=\"dark\">\n";
2617 print "<tr class=\"light\">\n";
2620 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2621 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2623 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list"}, "<b>" .
2624 esc_html
(chop_str
($co{'title'}, 50)) . "</b><br/>");
2625 while (my $setref = shift @files) {
2627 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$set{'id'}, hash_base
=>$co{'id'}, file_name
=>$set{'file'}), class => "list"},
2628 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
2632 "<td class=\"link\">" .
2633 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
2634 " | " . $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
2638 %co = parse_commit
($1);
2648 my $head = git_get_head_hash
($project);
2649 if (!defined $hash) {
2652 if (!defined $page) {
2655 my $refs = git_get_references
();
2657 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2658 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2659 or die_error
(undef, "Open git-rev-list failed");
2660 my @revlist = map { chomp; $_ } <$fd>;
2663 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
2665 if ($#revlist >= (100 * ($page+1)-1)) {
2667 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
2668 -title
=> "Alt-n"}, "next");
2673 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
2674 git_print_header_div
('summary', $project);
2676 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
2681 ## ......................................................................
2682 ## feeds (RSS, OPML)
2685 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
2686 open my $fd, "-|", $GIT, "rev-list", "--max-count=150", git_get_head_hash
($project)
2687 or die_error
(undef, "Open git-rev-list failed");
2688 my @revlist = map { chomp; $_ } <$fd>;
2689 close $fd or die_error
(undef, "Reading git-rev-list failed");
2690 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
2691 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
2692 "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
2693 print "<channel>\n";
2694 print "<title>$project</title>\n".
2695 "<link>" . esc_html
("$my_url?p=$project;a=summary") . "</link>\n".
2696 "<description>$project log</description>\n".
2697 "<language>en</language>\n";
2699 for (my $i = 0; $i <= $#revlist; $i++) {
2700 my $commit = $revlist[$i];
2701 my %co = parse_commit
($commit);
2702 # we read 150, we always show 30 and the ones more recent than 48 hours
2703 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
2706 my %cd = parse_date
($co{'committer_epoch'});
2707 open $fd, "-|", $GIT, "diff-tree", '-r', $co{'parent'}, $co{'id'} or next;
2708 my @difftree = map { chomp; $_ } <$fd>;
2712 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
2714 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
2715 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
2716 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
2717 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
2718 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
2719 "<content:encoded>" .
2721 my $comment = $co{'comment'};
2722 foreach my $line (@
$comment) {
2723 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
2724 print "$line<br/>\n";
2727 foreach my $line (@difftree) {
2728 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
2731 my $file = validate_input
(unquote
($7));
2732 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
2733 print "$file<br/>\n";
2736 "</content:encoded>\n" .
2739 print "</channel></rss>";
2743 my @list = git_get_projects_list
();
2745 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
2746 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
2747 "<opml version=\"1.0\">\n".
2749 " <title>$site_name Git OPML Export</title>\n".
2752 "<outline text=\"git RSS feeds\">\n";
2754 foreach my $pr (@list) {
2756 my $head = git_get_head_hash
($proj{'path'});
2757 if (!defined $head) {
2760 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
2761 my %co = parse_commit
($head);
2766 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
2767 my $rss = "$my_url?p=$proj{'path'};a=rss";
2768 my $html = "$my_url?p=$proj{'path'};a=summary";
2769 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
2771 print "</outline>\n".