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 use File
::Basename
qw(basename);
19 binmode STDOUT
, ':utf8';
22 our $version = "++GIT_VERSION++";
23 our $my_url = $cgi->url();
24 our $my_uri = $cgi->url(-absolute
=> 1);
26 # core git executable to use
27 # this can just be "git" if your webserver has a sensible PATH
28 our $GIT = "++GIT_BINDIR++/git";
30 # absolute fs-path which will be prepended to the project path
31 #our $projectroot = "/pub/scm";
32 our $projectroot = "++GITWEB_PROJECTROOT++";
34 # location for temporary files needed for diffs
35 our $git_temp = "/tmp/gitweb";
37 # target of the home link on top of all pages
38 our $home_link = $my_uri || "/";
40 # string of the home link on top of all pages
41 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
43 # name of your site or organization to appear in page titles
44 # replace this with something more descriptive for clearer bookmarks
45 our $site_name = "++GITWEB_SITENAME++" || $ENV{'SERVER_NAME'} || "Untitled";
47 # html text to include at home page
48 our $home_text = "++GITWEB_HOMETEXT++";
50 # URI of default stylesheet
51 our $stylesheet = "++GITWEB_CSS++";
53 our $logo = "++GITWEB_LOGO++";
55 # source of projects list
56 our $projects_list = "++GITWEB_LIST++";
58 # list of git base URLs used for URL to where fetch project from,
59 # i.e. full URL is "$git_base_url/$project"
60 our @git_base_url_list = ("++GITWEB_BASE_URL++");
62 # default blob_plain mimetype and default charset for text/plain blob
63 our $default_blob_plain_mimetype = 'text/plain';
64 our $default_text_plain_charset = undef;
66 # file to use for guessing MIME types before trying /etc/mime.types
67 # (relative to the current git repository)
68 our $mimetypes_file = undef;
70 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
71 require $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
73 # version of the core git binary
74 our $git_version = qx($GIT --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
76 $projects_list ||= $projectroot;
78 mkdir($git_temp, 0700) || die_error
(undef, "Couldn't mkdir $git_temp");
81 # ======================================================================
82 # input validation and dispatch
83 our $action = $cgi->param('a');
84 if (defined $action) {
85 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
86 die_error
(undef, "Invalid action parameter");
88 # action which does not check rest of parameters
89 if ($action eq "opml") {
95 our $project = ($cgi->param('p') || $ENV{'PATH_INFO'});
96 if (defined $project) {
99 $project = undef unless $project;
101 if (defined $project) {
102 if (!validate_input
($project)) {
103 die_error
(undef, "Invalid project parameter");
105 if (!(-d
"$projectroot/$project")) {
106 die_error
(undef, "No such directory");
108 if (!(-e
"$projectroot/$project/HEAD")) {
109 die_error
(undef, "No such project");
111 $ENV{'GIT_DIR'} = "$projectroot/$project";
117 our $file_name = $cgi->param('f');
118 if (defined $file_name) {
119 if (!validate_input
($file_name)) {
120 die_error
(undef, "Invalid file parameter");
124 our $file_parent = $cgi->param('fp');
125 if (defined $file_parent) {
126 if (!validate_input
($file_parent)) {
127 die_error
(undef, "Invalid file parent parameter");
131 our $hash = $cgi->param('h');
133 if (!validate_input
($hash)) {
134 die_error
(undef, "Invalid hash parameter");
138 our $hash_parent = $cgi->param('hp');
139 if (defined $hash_parent) {
140 if (!validate_input
($hash_parent)) {
141 die_error
(undef, "Invalid hash parent parameter");
145 our $hash_base = $cgi->param('hb');
146 if (defined $hash_base) {
147 if (!validate_input
($hash_base)) {
148 die_error
(undef, "Invalid hash base parameter");
152 our $page = $cgi->param('pg');
154 if ($page =~ m/[^0-9]$/) {
155 die_error
(undef, "Invalid page parameter");
159 our $searchtext = $cgi->param('s');
160 if (defined $searchtext) {
161 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
162 die_error
(undef, "Invalid search parameter");
164 $searchtext = quotemeta $searchtext;
169 "blame" => \
&git_blame2
,
170 "blobdiff" => \
&git_blobdiff
,
171 "blobdiff_plain" => \
&git_blobdiff_plain
,
172 "blob" => \
&git_blob
,
173 "blob_plain" => \
&git_blob_plain
,
174 "commitdiff" => \
&git_commitdiff
,
175 "commitdiff_plain" => \
&git_commitdiff_plain
,
176 "commit" => \
&git_commit
,
177 "heads" => \
&git_heads
,
178 "history" => \
&git_history
,
181 "search" => \
&git_search
,
182 "shortlog" => \
&git_shortlog
,
183 "summary" => \
&git_summary
,
185 "tags" => \
&git_tags
,
186 "tree" => \
&git_tree
,
187 "snapshot" => \
&git_snapshot
,
190 $action = 'summary' if (!defined($action));
191 if (!defined($actions{$action})) {
192 die_error
(undef, "Unknown action");
194 $actions{$action}->();
197 ## ======================================================================
214 $params{"project"} ||= $project;
216 my $href = "$my_uri?";
217 $href .= esc_param
( join(";",
219 "$mapping{$_}=$params{$_}" if defined $params{$_}
227 ## ======================================================================
228 ## validation, quoting/unquoting and escaping
233 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
236 if ($input =~ m/(^|\/)(|\
.|\
.\
.)($|\
/)/) {
239 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\
-\
+\#\
~\
%]/) {
245 # quote unsafe chars, but keep the slash, even when it's not
246 # correct, but quoted slashes look too horrible in bookmarks
249 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
255 # replace invalid utf8 character with SUBSTITUTION sequence
258 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
259 $str = escapeHTML
($str);
260 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
264 # git may return quoted and escaped filenames
267 if ($str =~ m/^"(.*)"$/) {
269 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
274 # escape tabs (convert tabs to spaces)
278 while ((my $pos = index($line, "\t")) != -1) {
279 if (my $count = (8 - ($pos % 8))) {
280 my $spaces = ' ' x
$count;
281 $line =~ s/\t/$spaces/;
288 ## ----------------------------------------------------------------------
289 ## HTML aware string manipulation
294 my $add_len = shift || 10;
296 # allow only $len chars, but don't cut a word if it would fit in $add_len
297 # if it doesn't fit, cut it if it's still longer than the dots we would add
298 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
301 if (length($tail) > 4) {
303 $body =~ s/&[^;]*$//; # remove chopped character entities
308 ## ----------------------------------------------------------------------
309 ## functions returning short strings
311 # CSS class for given age value (in seconds)
315 if ($age < 60*60*2) {
317 } elsif ($age < 60*60*24*2) {
324 # convert age in seconds to "nn units ago" string
329 if ($age > 60*60*24*365*2) {
330 $age_str = (int $age/60/60/24/365);
331 $age_str .= " years ago";
332 } elsif ($age > 60*60*24*(365/12)*2) {
333 $age_str = int $age/60/60/24/(365/12);
334 $age_str .= " months ago";
335 } elsif ($age > 60*60*24*7*2) {
336 $age_str = int $age/60/60/24/7;
337 $age_str .= " weeks ago";
338 } elsif ($age > 60*60*24*2) {
339 $age_str = int $age/60/60/24;
340 $age_str .= " days ago";
341 } elsif ($age > 60*60*2) {
342 $age_str = int $age/60/60;
343 $age_str .= " hours ago";
344 } elsif ($age > 60*2) {
345 $age_str = int $age/60;
346 $age_str .= " min ago";
349 $age_str .= " sec ago";
351 $age_str .= " right now";
356 # convert file mode in octal to symbolic file mode string
358 my $mode = oct shift;
360 if (S_ISDIR
($mode & S_IFMT
)) {
362 } elsif (S_ISLNK
($mode)) {
364 } elsif (S_ISREG
($mode)) {
365 # git cares only about the executable bit
366 if ($mode & S_IXUSR
) {
376 # convert file mode in octal to file type string
378 my $mode = oct shift;
380 if (S_ISDIR
($mode & S_IFMT
)) {
382 } elsif (S_ISLNK
($mode)) {
384 } elsif (S_ISREG
($mode)) {
391 ## ----------------------------------------------------------------------
392 ## functions returning short HTML fragments, or transforming HTML fragments
393 ## which don't beling to other sections
395 # format line of commit message or tag comment
396 sub format_log_line_html
{
399 $line = esc_html
($line);
400 $line =~ s/ / /g;
401 if ($line =~ m/([0-9a-fA-F]{40})/) {
403 if (git_get_type
($hash_text) eq "commit") {
404 my $link = $cgi->a({-class => "text", -href
=> href
(action
=>"commit", hash
=>$hash_text)}, $hash_text);
405 $line =~ s/$hash_text/$link/;
411 # format marker of refs pointing to given object
412 sub format_ref_marker
{
413 my ($refs, $id) = @_;
416 if (defined $refs->{$id}) {
417 foreach my $ref (@
{$refs->{$id}}) {
418 my ($type, $name) = qw();
419 # e.g. tags/v2.6.11 or heads/next
420 if ($ref =~ m!^(.*?)s?/(.*)$!) {
428 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
433 return ' <span class="refs">'. $markers . '</span>';
439 # format, perhaps shortened and with markers, title line
440 sub format_subject_html
{
441 my ($long, $short, $href, $extra) = @_;
442 $extra = '' unless defined($extra);
444 if (length($short) < length($long)) {
445 return $cgi->a({-href
=> $href, -class => "list",
447 esc_html
($short) . $extra);
449 return $cgi->a({-href
=> $href, -class => "list"},
450 esc_html
($long) . $extra);
454 ## ----------------------------------------------------------------------
455 ## git utility subroutines, invoking git commands
457 # get HEAD ref of given project as hash
458 sub git_get_head_hash
{
460 my $oENV = $ENV{'GIT_DIR'};
462 $ENV{'GIT_DIR'} = "$projectroot/$project";
463 if (open my $fd, "-|", $GIT, "rev-parse", "--verify", "HEAD") {
466 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
471 $ENV{'GIT_DIR'} = $oENV;
476 # get type of given object
480 open my $fd, "-|", $GIT, "cat-file", '-t', $hash or return;
487 sub git_get_project_config
{
490 return unless ($key);
491 $key =~ s/^gitweb\.//;
492 return if ($key =~ m/\W/);
494 my $val = qx($GIT repo
-config
--get gitweb
.$key);
498 sub git_get_project_config_bool
{
499 my $val = git_get_project_config
(@_);
500 if ($val and $val =~ m/true|yes|on/) {
503 return; # implicit false
506 # get hash of given path at given ref
507 sub git_get_hash_by_path
{
509 my $path = shift || return undef;
513 open my $fd, "-|", $GIT, "ls-tree", $base, "--", $path
514 or die_error
(undef, "Open git-ls-tree failed");
516 close $fd or return undef;
518 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
519 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
523 ## ......................................................................
524 ## git utility functions, directly accessing git repository
526 # assumes that PATH is not symref
527 sub git_get_hash_by_ref
{
530 open my $fd, "$projectroot/$path" or return undef;
534 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
539 sub git_get_project_description
{
542 open my $fd, "$projectroot/$path/description" or return undef;
549 sub git_get_project_url_list
{
552 open my $fd, "$projectroot/$path/cloneurl" or return undef;
553 my @git_project_url_list = map { chomp; $_ } <$fd>;
556 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
559 sub git_get_projects_list
{
562 if (-d
$projects_list) {
563 # search in directory
564 my $dir = $projects_list;
565 opendir my ($dh), $dir or return undef;
566 while (my $dir = readdir($dh)) {
567 if (-e
"$projectroot/$dir/HEAD") {
575 } elsif (-f
$projects_list) {
576 # read from file(url-encoded):
577 # 'git%2Fgit.git Linus+Torvalds'
578 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
579 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
580 open my ($fd), $projects_list or return undef;
581 while (my $line = <$fd>) {
583 my ($path, $owner) = split ' ', $line;
584 $path = unescape
($path);
585 $owner = unescape
($owner);
586 if (!defined $path) {
589 if (-e
"$projectroot/$path/HEAD") {
592 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
599 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
603 sub git_get_project_owner
{
607 return undef unless $project;
609 # read from file (url-encoded):
610 # 'git%2Fgit.git Linus+Torvalds'
611 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
612 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
613 if (-f
$projects_list) {
614 open (my $fd , $projects_list);
615 while (my $line = <$fd>) {
617 my ($pr, $ow) = split ' ', $line;
620 if ($pr eq $project) {
621 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
627 if (!defined $owner) {
628 $owner = get_file_owner
("$projectroot/$project");
634 sub git_get_references
{
635 my $type = shift || "";
638 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
639 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
640 if (-f
"$projectroot/$project/info/refs") {
641 open $fd, "$projectroot/$project/info/refs"
644 open $fd, "-|", $GIT, "ls-remote", "."
648 while (my $line = <$fd>) {
650 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?[^\^]+)/) {
651 if (defined $refs{$1}) {
652 push @
{$refs{$1}}, $2;
662 ## ----------------------------------------------------------------------
663 ## parse to hash functions
667 my $tz = shift || "-0000";
670 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
671 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
672 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
673 $date{'hour'} = $hour;
674 $date{'minute'} = $min;
675 $date{'mday'} = $mday;
676 $date{'day'} = $days[$wday];
677 $date{'month'} = $months[$mon];
678 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000", $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
679 $date{'mday-time'} = sprintf "%d %s %02d:%02d", $mday, $months[$mon], $hour ,$min;
681 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
682 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
683 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
684 $date{'hour_local'} = $hour;
685 $date{'minute_local'} = $min;
686 $date{'tz_local'} = $tz;
695 open my $fd, "-|", $GIT, "cat-file", "tag", $tag_id or return;
696 $tag{'id'} = $tag_id;
697 while (my $line = <$fd>) {
699 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
701 } elsif ($line =~ m/^type (.+)$/) {
703 } elsif ($line =~ m/^tag (.+)$/) {
705 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
709 } elsif ($line =~ m/--BEGIN/) {
710 push @comment, $line;
712 } elsif ($line eq "") {
716 push @comment, <$fd>;
717 $tag{'comment'} = \
@comment;
719 if (!defined $tag{'name'}) {
726 my $commit_id = shift;
727 my $commit_text = shift;
732 if (defined $commit_text) {
733 @commit_lines = @
$commit_text;
736 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", "--max-count=1", $commit_id or return;
737 @commit_lines = split '\n', <$fd>;
742 my $header = shift @commit_lines;
743 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
746 ($co{'id'}, my @parents) = split ' ', $header;
747 $co{'parents'} = \
@parents;
748 $co{'parent'} = $parents[0];
749 while (my $line = shift @commit_lines) {
750 last if $line eq "\n";
751 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
753 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
755 $co{'author_epoch'} = $2;
756 $co{'author_tz'} = $3;
757 if ($co{'author'} =~ m/^([^<]+) </) {
758 $co{'author_name'} = $1;
760 $co{'author_name'} = $co{'author'};
762 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
763 $co{'committer'} = $1;
764 $co{'committer_epoch'} = $2;
765 $co{'committer_tz'} = $3;
766 $co{'committer_name'} = $co{'committer'};
767 $co{'committer_name'} =~ s/ <.*//;
770 if (!defined $co{'tree'}) {
774 foreach my $title (@commit_lines) {
777 $co{'title'} = chop_str
($title, 80, 5);
778 # remove leading stuff of merges to make the interesting part visible
779 if (length($title) > 50) {
780 $title =~ s/^Automatic //;
781 $title =~ s/^merge (of|with) /Merge ... /i;
782 if (length($title) > 50) {
783 $title =~ s/(http|rsync):\/\///;
785 if (length($title) > 50) {
786 $title =~ s/(master|www|rsync)\.//;
788 if (length($title) > 50) {
789 $title =~ s/kernel.org:?//;
791 if (length($title) > 50) {
792 $title =~ s/\/pub\/scm//;
795 $co{'title_short'} = chop_str
($title, 50, 5);
799 # remove added spaces
800 foreach my $line (@commit_lines) {
803 $co{'comment'} = \
@commit_lines;
805 my $age = time - $co{'committer_epoch'};
807 $co{'age_string'} = age_string
($age);
808 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
809 if ($age > 60*60*24*7*2) {
810 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
811 $co{'age_string_age'} = $co{'age_string'};
813 $co{'age_string_date'} = $co{'age_string'};
814 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
819 # parse ref from ref_file, given by ref_id, with given type
821 my $ref_file = shift;
823 my $type = shift || git_get_type
($ref_id);
826 $ref_item{'type'} = $type;
827 $ref_item{'id'} = $ref_id;
828 $ref_item{'epoch'} = 0;
829 $ref_item{'age'} = "unknown";
830 if ($type eq "tag") {
831 my %tag = parse_tag
($ref_id);
832 $ref_item{'comment'} = $tag{'comment'};
833 if ($tag{'type'} eq "commit") {
834 my %co = parse_commit
($tag{'object'});
835 $ref_item{'epoch'} = $co{'committer_epoch'};
836 $ref_item{'age'} = $co{'age_string'};
837 } elsif (defined($tag{'epoch'})) {
838 my $age = time - $tag{'epoch'};
839 $ref_item{'epoch'} = $tag{'epoch'};
840 $ref_item{'age'} = age_string
($age);
842 $ref_item{'reftype'} = $tag{'type'};
843 $ref_item{'name'} = $tag{'name'};
844 $ref_item{'refid'} = $tag{'object'};
845 } elsif ($type eq "commit"){
846 my %co = parse_commit
($ref_id);
847 $ref_item{'reftype'} = "commit";
848 $ref_item{'name'} = $ref_file;
849 $ref_item{'title'} = $co{'title'};
850 $ref_item{'refid'} = $ref_id;
851 $ref_item{'epoch'} = $co{'committer_epoch'};
852 $ref_item{'age'} = $co{'age_string'};
854 $ref_item{'reftype'} = $type;
855 $ref_item{'name'} = $ref_file;
856 $ref_item{'refid'} = $ref_id;
862 ## ......................................................................
863 ## parse to array of hashes functions
865 sub git_get_refs_list
{
870 my $pfxlen = length("$projectroot/$project/$ref_dir");
871 File
::Find
::find
(sub {
874 push @refs, substr($File::Find
::name
, $pfxlen + 1);
876 }, "$projectroot/$project/$ref_dir");
878 foreach my $ref_file (@refs) {
879 my $ref_id = git_get_hash_by_ref
("$project/$ref_dir/$ref_file");
880 my $type = git_get_type
($ref_id) || next;
881 my %ref_item = parse_ref
($ref_file, $ref_id, $type);
883 push @reflist, \
%ref_item;
886 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
890 ## ----------------------------------------------------------------------
891 ## filesystem-related functions
896 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
897 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
898 if (!defined $gcos) {
902 $owner =~ s/[,;].*$//;
903 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
906 ## ......................................................................
907 ## mimetype related functions
909 sub mimetype_guess_file
{
910 my $filename = shift;
912 -r
$mimemap or return undef;
915 open(MIME
, $mimemap) or return undef;
917 next if m/^#/; # skip comments
918 my ($mime, $exts) = split(/\t+/);
920 my @exts = split(/\s+/, $exts);
921 foreach my $ext (@exts) {
922 $mimemap{$ext} = $mime;
928 $filename =~ /\.(.*?)$/;
933 my $filename = shift;
935 $filename =~ /\./ or return undef;
937 if ($mimetypes_file) {
938 my $file = $mimetypes_file;
939 if ($file !~ m!^/!) { # if it is relative path
940 # it is relative to project
941 $file = "$projectroot/$project/$file";
943 $mime = mimetype_guess_file
($filename, $file);
945 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
951 my $filename = shift;
954 my $mime = mimetype_guess
($filename);
955 $mime and return $mime;
959 return $default_blob_plain_mimetype unless $fd;
962 return 'text/plain' .
963 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
964 } elsif (! $filename) {
965 return 'application/octet-stream';
966 } elsif ($filename =~ m/\.png$/i) {
968 } elsif ($filename =~ m/\.gif$/i) {
970 } elsif ($filename =~ m/\.jpe?g$/i) {
973 return 'application/octet-stream';
977 ## ======================================================================
978 ## functions printing HTML: header, footer, error page
980 sub git_header_html
{
981 my $status = shift || "200 OK";
984 my $title = "$site_name git";
985 if (defined $project) {
986 $title .= " - $project";
987 if (defined $action) {
988 $title .= "/$action";
989 if (defined $file_name) {
990 $title .= " - $file_name";
991 if ($action eq "tree" && $file_name !~ m
|/$|) {
998 # require explicit support from the UA if we are to send the page as
999 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1000 # we have to do this because MSIE sometimes globs '*/*', pretending to
1001 # support xhtml+xml but choking when it gets what it asked for.
1002 if (defined $cgi->http('HTTP_ACCEPT') && $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ && $cgi->Accept('application/xhtml
+xml
') != 0) {
1003 $content_type = 'application
/xhtml
+xml
';
1005 $content_type = 'text
/html
';
1007 print $cgi->header(-type=>$content_type, -charset => 'utf
-8', -status=> $status, -expires => $expires);
1009 <?xml version="1.0" encoding="utf-8"?>
1010 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1011 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1012 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1013 <!-- git core binaries version $git_version -->
1015 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1016 <meta name="generator" content="gitweb/$version git/$git_version"/>
1017 <meta name="robots" content="index, nofollow"/>
1018 <title>$title</title>
1019 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
1021 if (defined $project) {
1022 printf('<link rel="alternate" title="%s log" '.
1023 'href="%s" type="application/rss+xml"/>'."\n",
1024 esc_param
($project), href
(action
=>"rss"));
1029 "<div class=\"page_header\">\n" .
1030 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
1031 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
1033 print $cgi->a({-href
=> esc_param
($home_link)}, $home_link_str) . " / ";
1034 if (defined $project) {
1035 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1036 if (defined $action) {
1040 if (!defined $searchtext) {
1044 if (defined $hash_base) {
1045 $search_hash = $hash_base;
1046 } elsif (defined $hash) {
1047 $search_hash = $hash;
1049 $search_hash = "HEAD";
1051 $cgi->param("a", "search");
1052 $cgi->param("h", $search_hash);
1053 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
1054 "<div class=\"search\">\n" .
1055 $cgi->hidden(-name
=> "p") . "\n" .
1056 $cgi->hidden(-name
=> "a") . "\n" .
1057 $cgi->hidden(-name
=> "h") . "\n" .
1058 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1060 $cgi->end_form() . "\n";
1065 sub git_footer_html
{
1066 print "<div class=\"page_footer\">\n";
1067 if (defined $project) {
1068 my $descr = git_get_project_description
($project);
1069 if (defined $descr) {
1070 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1072 print $cgi->a({-href
=> href
(action
=>"rss"), -class => "rss_logo"}, "RSS") . "\n";
1074 print $cgi->a({-href
=> href
(action
=>"opml"), -class => "rss_logo"}, "OPML") . "\n";
1082 my $status = shift || "403 Forbidden";
1083 my $error = shift || "Malformed query, file missing or permission denied";
1085 git_header_html
($status);
1086 print "<div class=\"page_body\">\n" .
1088 "$status - $error\n" .
1095 ## ----------------------------------------------------------------------
1096 ## functions printing or outputting HTML: navigation
1098 sub git_print_page_nav
{
1099 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1100 $extra = '' if !defined $extra; # pager or formats
1102 my @navs = qw(summary shortlog log commit commitdiff tree);
1104 @navs = grep { $_ ne $suppress } @navs;
1107 my %arg = map { $_ => {action
=>$_} } @navs;
1108 if (defined $head) {
1109 for (qw(commit commitdiff)) {
1110 $arg{$_}{hash
} = $head;
1112 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1113 for (qw(shortlog log)) {
1114 $arg{$_}{hash
} = $head;
1118 $arg{tree
}{hash
} = $treehead if defined $treehead;
1119 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1121 print "<div class=\"page_nav\">\n" .
1123 map { $_ eq $current ?
1124 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1126 print "<br/>\n$extra<br/>\n" .
1130 sub format_paging_nav
{
1131 my ($action, $hash, $head, $page, $nrevs) = @_;
1135 if ($hash ne $head || $page) {
1136 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1138 $paging_nav .= "HEAD";
1142 $paging_nav .= " ⋅ " .
1143 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1144 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1146 $paging_nav .= " ⋅ prev";
1149 if ($nrevs >= (100 * ($page+1)-1)) {
1150 $paging_nav .= " ⋅ " .
1151 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1152 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1154 $paging_nav .= " ⋅ next";
1160 ## ......................................................................
1161 ## functions printing or outputting HTML: div
1163 sub git_print_header_div
{
1164 my ($action, $title, $hash, $hash_base) = @_;
1167 $args{action
} = $action;
1168 $args{hash
} = $hash if $hash;
1169 $args{hash_base
} = $hash_base if $hash_base;
1171 print "<div class=\"header\">\n" .
1172 $cgi->a({-href
=> href
(%args), -class => "title"},
1173 $title ?
$title : $action) .
1177 sub git_print_page_path
{
1182 if (!defined $name) {
1183 print "<div class=\"page_path\"><b>/</b></div>\n";
1184 } elsif (defined $type && $type eq 'blob') {
1185 print "<div class=\"page_path\"><b>";
1187 print $cgi->a({-href
=> href
(action
=>"blob_plain", hash_base
=>$hb, file_name
=>$file_name)}, esc_html
($name));
1189 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name)}, esc_html
($name));
1191 print "</b><br/></div>\n";
1193 print "<div class=\"page_path\"><b>" . esc_html
($name) . "</b><br/></div>\n";
1200 # remove leading empty lines
1201 while (defined $log->[0] && $log->[0] eq "") {
1208 foreach my $line (@
$log) {
1209 # print only one empty line
1210 # do not print empty line after signoff
1212 next if ($empty || $signoff);
1217 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1219 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1222 print format_log_line_html
($line) . "<br/>\n";
1227 sub git_print_simplified_log
{
1229 my $remove_title = shift;
1231 shift @
$log if $remove_title;
1232 # remove leading empty lines
1233 while (defined $log->[0] && $log->[0] eq "") {
1237 # simplify and print log
1239 foreach my $line (@
$log) {
1240 # remove signoff lines
1241 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1244 # print only one empty line
1251 print format_log_line_html
($line) . "<br/>\n";
1253 # end with single empty line
1254 print "<br/>\n" unless $empty;
1257 ## ......................................................................
1258 ## functions printing large fragments of HTML
1260 sub git_difftree_body
{
1261 my ($difftree, $parent) = @_;
1263 print "<div class=\"list_head\">\n";
1264 if ($#{$difftree} > 10) {
1265 print(($#{$difftree} + 1) . " files changed:\n");
1269 print "<table class=\"diff_tree\">\n";
1271 foreach my $line (@
{$difftree}) {
1272 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1273 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1274 if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1282 my $similarity = $6; # score
1283 my $file = validate_input
(unquote
($7));
1286 print "<tr class=\"dark\">\n";
1288 print "<tr class=\"light\">\n";
1292 if ($status eq "A") { # created
1294 if (S_ISREG
(oct $to_mode)) {
1295 $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
1298 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$file),
1299 -class => "list"}, esc_html
($file)) .
1301 "<td><span class=\"file_status new\">[new " . file_type
($to_mode) . "$mode_chng]</span></td>\n" .
1302 "<td class=\"link\">" .
1303 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$file)}, "blob") .
1306 } elsif ($status eq "D") { # deleted
1308 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$from_id, hash_base
=>$parent, file_name
=>$file),
1309 -class => "list"}, esc_html
($file)) . "</td>\n" .
1310 "<td><span class=\"file_status deleted\">[deleted " . file_type
($from_mode). "]</span></td>\n" .
1311 "<td class=\"link\">" .
1312 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$from_id, hash_base
=>$parent, file_name
=>$file)}, "blob") . " | " .
1313 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent, file_name
=>$file)}, "history") .
1316 } elsif ($status eq "M" || $status eq "T") { # modified, or type changed
1317 my $mode_chnge = "";
1318 if ($from_mode != $to_mode) {
1319 $mode_chnge = " <span class=\"file_status mode_chnge\">[changed";
1320 if (((oct $from_mode) & S_IFMT
) != ((oct $to_mode) & S_IFMT
)) {
1321 $mode_chnge .= " from " . file_type
($from_mode) . " to " . file_type
($to_mode);
1323 if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
1324 if (S_ISREG
($from_mode) && S_ISREG
($to_mode)) {
1325 $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
1326 } elsif (S_ISREG
($to_mode)) {
1327 $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
1330 $mode_chnge .= "]</span>\n";
1333 if ($to_id ne $from_id) { # modified
1334 print $cgi->a({-href
=> href
(action
=>"blobdiff", hash
=>$to_id, hash_parent
=>$from_id, hash_base
=>$hash, file_name
=>$file),
1335 -class => "list"}, esc_html
($file));
1336 } else { # mode changed
1337 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$file),
1338 -class => "list"}, esc_html
($file));
1341 "<td>$mode_chnge</td>\n" .
1342 "<td class=\"link\">" .
1343 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$file)}, "blob");
1344 if ($to_id ne $from_id) { # modified
1345 print " | " . $cgi->a({-href
=> href
(action
=>"blobdiff", hash
=>$to_id, hash_parent
=>$from_id, hash_base
=>$hash, file_name
=>$file)}, "diff");
1347 print " | " . $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash, file_name
=>$file)}, "history") . "\n";
1350 } elsif ($status eq "R") { # renamed
1351 my ($from_file, $to_file) = split "\t", $file;
1353 if ($from_mode != $to_mode) {
1354 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
1357 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$to_file),
1358 -class => "list"}, esc_html
($to_file)) . "</td>\n" .
1359 "<td><span class=\"file_status moved\">[moved from " .
1360 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$from_id, hash_base
=>$parent, file_name
=>$from_file),
1361 -class => "list"}, esc_html
($from_file)) .
1362 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
1363 "<td class=\"link\">" .
1364 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$to_file)}, "blob");
1365 if ($to_id ne $from_id) {
1367 $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");
1371 } elsif ($status eq "C") { # copied
1372 my ($from_file, $to_file) = split "\t", $file;
1374 if ($from_mode != $to_mode) {
1375 $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
1378 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$to_file),
1379 -class => "list"}, esc_html
($to_file)) . "</td>\n" .
1380 "<td><span class=\"file_status copied\">[copied from " .
1381 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$from_id, hash_base
=>$parent, file_name
=>$from_file),
1382 -class => "list"}, esc_html
($from_file)) .
1383 " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
1384 "<td class=\"link\">" .
1385 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$to_file)}, "blob");
1386 if ($to_id ne $from_id) {
1388 $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");
1391 } # we should not encounter Unmerged (U) or Unknown (X) status
1397 sub git_shortlog_body
{
1398 # uses global variable $project
1399 my ($revlist, $from, $to, $refs, $extra) = @_;
1400 my $have_snapshot = git_get_project_config_bool
('snapshot');
1401 $from = 0 unless defined $from;
1402 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1404 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
1406 for (my $i = $from; $i <= $to; $i++) {
1407 my $commit = $revlist->[$i];
1408 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
1409 my $ref = format_ref_marker
($refs, $commit);
1410 my %co = parse_commit
($commit);
1412 print "<tr class=\"dark\">\n";
1414 print "<tr class=\"light\">\n";
1417 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1418 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1419 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
1421 print format_subject_html
($co{'title'}, $co{'title_short'}, href
(action
=>"commit", hash
=>$commit), $ref);
1423 "<td class=\"link\">" .
1424 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
1425 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
1426 if ($have_snapshot) {
1427 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
1432 if (defined $extra) {
1434 "<td colspan=\"4\">$extra</td>\n" .
1440 sub git_history_body
{
1441 # Warning: assumes constant type (blob or tree) during history
1442 my ($fd, $refs, $hash_base, $ftype, $extra) = @_;
1444 print "<table class=\"history\" cellspacing=\"0\">\n";
1446 while (my $line = <$fd>) {
1447 if ($line !~ m/^([0-9a-fA-F]{40})/) {
1452 my %co = parse_commit
($commit);
1457 my $ref = format_ref_marker
($refs, $commit);
1460 print "<tr class=\"dark\">\n";
1462 print "<tr class=\"light\">\n";
1465 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1466 # shortlog uses chop_str($co{'author_name'}, 10)
1467 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
1469 # originally git_history used chop_str($co{'title'}, 50)
1470 print format_subject_html
($co{'title'}, $co{'title_short'}, href
(action
=>"commit", hash
=>$commit), $ref);
1472 "<td class=\"link\">" .
1473 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
1474 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
1475 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype);
1477 if ($ftype eq 'blob') {
1478 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
1479 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
1480 if (defined $blob_current && defined $blob_parent &&
1481 $blob_current ne $blob_parent) {
1483 $cgi->a({-href
=> href
(action
=>"blobdiff", hash
=>$blob_current, hash_parent
=>$blob_parent, hash_base
=>$commit, file_name
=>$file_name)},
1490 if (defined $extra) {
1492 "<td colspan=\"4\">$extra</td>\n" .
1499 # uses global variable $project
1500 my ($taglist, $from, $to, $extra) = @_;
1501 $from = 0 unless defined $from;
1502 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1504 print "<table class=\"tags\" cellspacing=\"0\">\n";
1506 for (my $i = $from; $i <= $to; $i++) {
1507 my $entry = $taglist->[$i];
1509 my $comment_lines = $tag{'comment'};
1510 my $comment = shift @
$comment_lines;
1512 if (defined $comment) {
1513 $comment_short = chop_str
($comment, 30, 5);
1516 print "<tr class=\"dark\">\n";
1518 print "<tr class=\"light\">\n";
1521 print "<td><i>$tag{'age'}</i></td>\n" .
1523 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
1524 -class => "list"}, "<b>" . esc_html
($tag{'name'}) . "</b>") .
1527 if (defined $comment) {
1528 print format_subject_html
($comment, $comment_short, href
(action
=>"tag", hash
=>$tag{'id'}));
1531 "<td class=\"selflink\">";
1532 if ($tag{'type'} eq "tag") {
1533 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
1538 "<td class=\"link\">" . " | " .
1539 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
1540 if ($tag{'reftype'} eq "commit") {
1541 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
1542 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'refid'})}, "log");
1543 } elsif ($tag{'reftype'} eq "blob") {
1544 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
1549 if (defined $extra) {
1551 "<td colspan=\"5\">$extra</td>\n" .
1557 sub git_heads_body
{
1558 # uses global variable $project
1559 my ($taglist, $head, $from, $to, $extra) = @_;
1560 $from = 0 unless defined $from;
1561 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1563 print "<table class=\"heads\" cellspacing=\"0\">\n";
1565 for (my $i = $from; $i <= $to; $i++) {
1566 my $entry = $taglist->[$i];
1568 my $curr = $tag{'id'} eq $head;
1570 print "<tr class=\"dark\">\n";
1572 print "<tr class=\"light\">\n";
1575 print "<td><i>$tag{'age'}</i></td>\n" .
1576 ($tag{'id'} eq $head ?
"<td class=\"current_head\">" : "<td>") .
1577 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'}),
1578 -class => "list"}, "<b>" . esc_html
($tag{'name'}) . "</b>") .
1580 "<td class=\"link\">" .
1581 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") . " | " .
1582 $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log") .
1586 if (defined $extra) {
1588 "<td colspan=\"3\">$extra</td>\n" .
1594 ## ----------------------------------------------------------------------
1595 ## functions printing large fragments, format as one of arguments
1597 sub git_diff_print
{
1599 my $from_name = shift;
1601 my $to_name = shift;
1602 my $format = shift || "html";
1604 my $from_tmp = "/dev/null";
1605 my $to_tmp = "/dev/null";
1608 # create tmp from-file
1609 if (defined $from) {
1610 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
1611 open my $fd2, "> $from_tmp";
1612 open my $fd, "-|", $GIT, "cat-file", "blob", $from;
1619 # create tmp to-file
1621 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
1622 open my $fd2, "> $to_tmp";
1623 open my $fd, "-|", $GIT, "cat-file", "blob", $to;
1630 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
1631 if ($format eq "plain") {
1636 while (my $line = <$fd>) {
1638 my $char = substr($line, 0, 1);
1639 my $diff_class = "";
1641 $diff_class = " add";
1642 } elsif ($char eq "-") {
1643 $diff_class = " rem";
1644 } elsif ($char eq "@") {
1645 $diff_class = " chunk_header";
1646 } elsif ($char eq "\\") {
1650 $line = untabify
($line);
1651 print "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
1656 if (defined $from) {
1665 ## ======================================================================
1666 ## ======================================================================
1669 sub git_project_list
{
1670 my $order = $cgi->param('o');
1671 if (defined $order && $order !~ m/project|descr|owner|age/) {
1672 die_error
(undef, "Unknown order parameter");
1675 my @list = git_get_projects_list
();
1678 die_error
(undef, "No projects found");
1680 foreach my $pr (@list) {
1681 my $head = git_get_head_hash
($pr->{'path'});
1682 if (!defined $head) {
1685 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
1686 my %co = parse_commit
($head);
1690 $pr->{'commit'} = \
%co;
1691 if (!defined $pr->{'descr'}) {
1692 my $descr = git_get_project_description
($pr->{'path'}) || "";
1693 $pr->{'descr'} = chop_str
($descr, 25, 5);
1695 if (!defined $pr->{'owner'}) {
1696 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
1698 push @projects, $pr;
1702 if (-f
$home_text) {
1703 print "<div class=\"index_include\">\n";
1704 open (my $fd, $home_text);
1709 print "<table class=\"project_list\">\n" .
1711 $order ||= "project";
1712 if ($order eq "project") {
1713 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
1714 print "<th>Project</th>\n";
1717 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=project"),
1718 -class => "header"}, "Project") .
1721 if ($order eq "descr") {
1722 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
1723 print "<th>Description</th>\n";
1726 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=descr"),
1727 -class => "header"}, "Description") .
1730 if ($order eq "owner") {
1731 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
1732 print "<th>Owner</th>\n";
1735 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=owner"),
1736 -class => "header"}, "Owner") .
1739 if ($order eq "age") {
1740 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
1741 print "<th>Last Change</th>\n";
1744 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=age"),
1745 -class => "header"}, "Last Change") .
1748 print "<th></th>\n" .
1751 foreach my $pr (@projects) {
1753 print "<tr class=\"dark\">\n";
1755 print "<tr class=\"light\">\n";
1758 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
1759 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
1760 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
1761 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
1762 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" .
1763 $pr->{'commit'}{'age_string'} . "</td>\n" .
1764 "<td class=\"link\">" .
1765 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
1766 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
1767 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") .
1776 my $descr = git_get_project_description
($project) || "none";
1777 my $head = git_get_head_hash
($project);
1778 my %co = parse_commit
($head);
1779 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
1781 my $owner = git_get_project_owner
($project);
1783 my $refs = git_get_references
();
1785 git_print_page_nav
('summary','', $head);
1787 print "<div class=\"title\"> </div>\n";
1788 print "<table cellspacing=\"0\">\n" .
1789 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
1790 "<tr><td>owner</td><td>$owner</td></tr>\n" .
1791 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
1792 # use per project git URL list in $projectroot/$project/cloneurl
1793 # or make project git URL from git base URL and project name
1794 my $url_tag = "URL";
1795 my @url_list = git_get_project_url_list
($project);
1796 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
1797 foreach my $git_url (@url_list) {
1798 next unless $git_url;
1799 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
1804 open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_get_head_hash
($project)
1805 or die_error
(undef, "Open git-rev-list failed");
1806 my @revlist = map { chomp; $_ } <$fd>;
1808 git_print_header_div
('shortlog');
1809 git_shortlog_body
(\
@revlist, 0, 15, $refs,
1810 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
1812 my $taglist = git_get_refs_list
("refs/tags");
1813 if (defined @
$taglist) {
1814 git_print_header_div
('tags');
1815 git_tags_body
($taglist, 0, 15,
1816 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
1819 my $headlist = git_get_refs_list
("refs/heads");
1820 if (defined @
$headlist) {
1821 git_print_header_div
('heads');
1822 git_heads_body
($headlist, $head, 0, 15,
1823 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
1830 my $head = git_get_head_hash
($project);
1832 git_print_page_nav
('','', $head,undef,$head);
1833 my %tag = parse_tag
($hash);
1834 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
1835 print "<div class=\"title_text\">\n" .
1836 "<table cellspacing=\"0\">\n" .
1838 "<td>object</td>\n" .
1839 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})}, $tag{'object'}) . "</td>\n" .
1840 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})}, $tag{'type'}) . "</td>\n" .
1842 if (defined($tag{'author'})) {
1843 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
1844 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
1845 print "<tr><td></td><td>" . $ad{'rfc2822'} . sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) . "</td></tr>\n";
1847 print "</table>\n\n" .
1849 print "<div class=\"page_body\">";
1850 my $comment = $tag{'comment'};
1851 foreach my $line (@
$comment) {
1852 print esc_html
($line) . "<br/>\n";
1861 die_error
(undef, "Permission denied") if (!git_get_project_config_bool
('blame'));
1862 die_error
('404 Not Found', "File name not defined") if (!$file_name);
1863 $hash_base ||= git_get_head_hash
($project);
1864 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
1865 my %co = parse_commit
($hash_base)
1866 or die_error
(undef, "Reading commit failed");
1867 if (!defined $hash) {
1868 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
1869 or die_error
(undef, "Error looking up file");
1871 $ftype = git_get_type
($hash);
1872 if ($ftype !~ "blob") {
1873 die_error
("400 Bad Request", "Object is not a blob");
1875 open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base)
1876 or die_error
(undef, "Open git-blame failed");
1879 $cgi->a({-href
=> href
(action
=>"blobl", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)}, "blob") .
1880 " | " . $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)}, "head");
1881 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1882 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
1883 git_print_page_path
($file_name, $ftype, $hash_base);
1884 my @rev_color = (qw(light2 dark2));
1885 my $num_colors = scalar(@rev_color);
1886 my $current_color = 0;
1888 print "<div class=\"page_body\">\n";
1889 print "<table class=\"blame\">\n";
1890 print "<tr><th>Commit</th><th>Line</th><th>Data</th></tr>\n";
1892 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
1894 my $rev = substr($full_rev, 0, 8);
1898 if (!defined $last_rev) {
1899 $last_rev = $full_rev;
1900 } elsif ($last_rev ne $full_rev) {
1901 $last_rev = $full_rev;
1902 $current_color = ++$current_color % $num_colors;
1904 print "<tr class=\"$rev_color[$current_color]\">\n";
1905 print "<td class=\"sha1\">" .
1906 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$full_rev, file_name
=>$file_name)}, esc_html
($rev)) . "</td>\n";
1907 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" . esc_html
($lineno) . "</a></td>\n";
1908 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
1913 close $fd or print "Reading blob failed\n";
1919 die_error
('403 Permission denied', "Permission denied") if (!git_get_project_config_bool
('blame'));
1920 die_error
('404 Not Found', "File name not defined") if (!$file_name);
1921 $hash_base ||= git_get_head_hash
($project);
1922 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
1923 my %co = parse_commit
($hash_base)
1924 or die_error
(undef, "Reading commit failed");
1925 if (!defined $hash) {
1926 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
1927 or die_error
(undef, "Error lookup file");
1929 open ($fd, "-|", $GIT, "annotate", '-l', '-t', '-r', $file_name, $hash_base)
1930 or die_error
(undef, "Open git-annotate failed");
1933 $cgi->a({-href
=> href
(action
=>"blobl", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)}, "blob") .
1934 " | " . $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)}, "head");
1935 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
1936 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
1937 git_print_page_path
($file_name, 'blob', $hash_base);
1938 print "<div class=\"page_body\">\n";
1940 <table class="blame">
1949 my @line_class = (qw(light dark));
1950 my $line_class_len = scalar (@line_class);
1951 my $line_class_num = $#line_class;
1952 while (my $line = <$fd>) {
1964 $line_class_num = ($line_class_num + 1) % $line_class_len;
1966 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) \+\d\d\d\d\t(\d+)\)(.*)$/) {
1973 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
1976 $short_rev = substr ($long_rev, 0, 8);
1977 $age = time () - $time;
1978 $age_str = age_string
($age);
1979 $age_str =~ s/ / /g;
1980 $age_class = age_class
($age);
1981 $author = esc_html
($author);
1982 $author =~ s/ / /g;
1984 $data = untabify
($data);
1985 $data = esc_html
($data);
1988 <tr class="$line_class[$line_class_num]">
1989 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
1990 <td class="$age_class">$age_str</td>
1992 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
1993 <td class="pre">$data</td>
1996 } # while (my $line = <$fd>)
1997 print "</table>\n\n";
1998 close $fd or print "Reading blob failed.\n";
2004 my $head = git_get_head_hash
($project);
2006 git_print_page_nav
('','', $head,undef,$head);
2007 git_print_header_div
('summary', $project);
2009 my $taglist = git_get_refs_list
("refs/tags");
2010 if (defined @
$taglist) {
2011 git_tags_body
($taglist);
2017 my $head = git_get_head_hash
($project);
2019 git_print_page_nav
('','', $head,undef,$head);
2020 git_print_header_div
('summary', $project);
2022 my $taglist = git_get_refs_list
("refs/heads");
2023 if (defined @
$taglist) {
2024 git_heads_body
($taglist, $head);
2029 sub git_blob_plain
{
2030 if (!defined $hash) {
2031 if (defined $file_name) {
2032 my $base = $hash_base || git_get_head_hash
($project);
2033 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2034 or die_error
(undef, "Error lookup file");
2036 die_error
(undef, "No file name defined");
2040 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
2041 or die_error
(undef, "Couldn't cat $file_name, $hash");
2043 $type ||= blob_mimetype
($fd, $file_name);
2045 # save as filename, even when no $file_name is given
2046 my $save_as = "$hash";
2047 if (defined $file_name) {
2048 $save_as = $file_name;
2049 } elsif ($type =~ m/^text\//) {
2053 print $cgi->header(-type
=> "$type", '-content-disposition' => "inline; filename=\"$save_as\"");
2055 binmode STDOUT
, ':raw';
2057 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2063 if (!defined $hash) {
2064 if (defined $file_name) {
2065 my $base = $hash_base || git_get_head_hash
($project);
2066 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2067 or die_error
(undef, "Error lookup file");
2069 die_error
(undef, "No file name defined");
2072 my $have_blame = git_get_project_config_bool
('blame');
2073 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
2074 or die_error
(undef, "Couldn't cat $file_name, $hash");
2075 my $mimetype = blob_mimetype
($fd, $file_name);
2076 if ($mimetype !~ m/^text\//) {
2078 return git_blob_plain
($mimetype);
2081 my $formats_nav = '';
2082 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2083 if (defined $file_name) {
2085 $formats_nav .= $cgi->a({-href
=> href
(action
=>"blame", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)}, "blame") . " | ";
2088 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash, file_name
=>$file_name)}, "plain") .
2089 " | " . $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>"HEAD", file_name
=>$file_name)}, "head");
2091 $formats_nav .= $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "plain");
2093 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2094 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2096 print "<div class=\"page_nav\">\n" .
2097 "<br/><br/></div>\n" .
2098 "<div class=\"title\">$hash</div>\n";
2100 git_print_page_path
($file_name, "blob", $hash_base);
2101 print "<div class=\"page_body\">\n";
2103 while (my $line = <$fd>) {
2106 $line = untabify
($line);
2107 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n", $nr, $nr, $nr, esc_html
($line);
2109 close $fd or print "Reading blob failed.\n";
2115 if (!defined $hash) {
2116 $hash = git_get_head_hash
($project);
2117 if (defined $file_name) {
2118 my $base = $hash_base || $hash;
2119 $hash = git_get_hash_by_path
($base, $file_name, "tree");
2121 if (!defined $hash_base) {
2126 open my $fd, "-|", $GIT, "ls-tree", '-z', $hash
2127 or die_error
(undef, "Open git-ls-tree failed");
2128 my @entries = map { chomp; $_ } <$fd>;
2129 close $fd or die_error
(undef, "Reading tree failed");
2132 my $refs = git_get_references
();
2133 my $ref = format_ref_marker
($refs, $hash_base);
2137 my $have_blame = git_get_project_config_bool
('blame');
2138 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2139 $base_key{hash_base
} = $hash_base;
2140 git_print_page_nav
('tree','', $hash_base);
2141 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
2143 print "<div class=\"page_nav\">\n";
2144 print "<br/><br/></div>\n";
2145 print "<div class=\"title\">$hash</div>\n";
2147 if (defined $file_name) {
2148 $base = esc_html
("$file_name/");
2150 git_print_page_path
($file_name, 'tree', $hash_base);
2151 print "<div class=\"page_body\">\n";
2152 print "<table cellspacing=\"0\">\n";
2154 foreach my $line (@entries) {
2155 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2156 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
2160 my $t_name = validate_input
($4);
2162 print "<tr class=\"dark\">\n";
2164 print "<tr class=\"light\">\n";
2167 print "<td class=\"mode\">" . mode_str
($t_mode) . "</td>\n";
2168 if ($t_type eq "blob") {
2169 print "<td class=\"list\">" .
2170 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key), -class => "list"}, esc_html
($t_name)) .
2172 "<td class=\"link\">" .
2173 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)}, "blob");
2175 print " | " . $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)}, "blame");
2177 print " | " . $cgi->a({-href
=> href
(action
=>"history", hash
=>$t_hash, hash_base
=>$hash_base, file_name
=>"$base$t_name")}, "history") .
2178 " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$t_hash, file_name
=>"$base$t_name")}, "raw") .
2180 } elsif ($t_type eq "tree") {
2181 print "<td class=\"list\">" .
2182 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)}, esc_html
($t_name)) .
2184 "<td class=\"link\">" .
2185 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)}, "tree") .
2186 " | " . $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base, file_name
=>"$base$t_name")}, "history") .
2191 print "</table>\n" .
2198 if (!defined $hash) {
2199 $hash = git_get_head_hash
($project);
2202 my $filename = basename
($project) . "-$hash.tar.gz";
2204 print $cgi->header(-type
=> 'application/x-tar',
2205 -content
-encoding
=> 'x-gzip',
2206 '-content-disposition' => "inline; filename=\"$filename\"",
2207 -status
=> '200 OK');
2209 open my $fd, "-|", "$GIT tar-tree $hash \'$project\' | gzip" or
2210 die_error
(undef, "Execute git-tar-tree failed.");
2211 binmode STDOUT
, ':raw';
2213 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2220 my $head = git_get_head_hash
($project);
2221 if (!defined $hash) {
2224 if (!defined $page) {
2227 my $refs = git_get_references
();
2229 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2230 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2231 or die_error
(undef, "Open git-rev-list failed");
2232 my @revlist = map { chomp; $_ } <$fd>;
2235 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
2238 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
2241 my %co = parse_commit
($hash);
2243 git_print_header_div
('summary', $project);
2244 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
2246 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2247 my $commit = $revlist[$i];
2248 my $ref = format_ref_marker
($refs, $commit);
2249 my %co = parse_commit
($commit);
2251 my %ad = parse_date
($co{'author_epoch'});
2252 git_print_header_div
('commit',
2253 "<span class=\"age\">$co{'age_string'}</span>" .
2254 esc_html
($co{'title'}) . $ref,
2256 print "<div class=\"title_text\">\n" .
2257 "<div class=\"log_link\">\n" .
2258 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
2259 " | " . $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
2262 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
2265 print "<div class=\"log_body\">\n";
2266 git_print_simplified_log
($co{'comment'});
2273 my %co = parse_commit
($hash);
2275 die_error
(undef, "Unknown commit object");
2277 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2278 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2280 my $parent = $co{'parent'};
2281 if (!defined $parent) {
2284 open my $fd, "-|", $GIT, "diff-tree", '-r', '-M', $parent, $hash
2285 or die_error
(undef, "Open git-diff-tree failed");
2286 my @difftree = map { chomp; $_ } <$fd>;
2287 close $fd or die_error
(undef, "Reading git-diff-tree failed");
2289 # non-textual hash id's can be cached
2291 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2294 my $refs = git_get_references
();
2295 my $ref = format_ref_marker
($refs, $co{'id'});
2296 my $have_snapshot = git_get_project_config_bool
('snapshot');
2297 my $formats_nav = '';
2298 if (defined $file_name && defined $co{'parent'}) {
2299 my $parent = $co{'parent'};
2300 $formats_nav .= $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)}, "blame");
2302 git_header_html
(undef, $expires);
2303 git_print_page_nav
('commit', defined $co{'parent'} ?
'' : 'commitdiff',
2304 $hash, $co{'tree'}, $hash,
2307 if (defined $co{'parent'}) {
2308 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
2310 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
2312 print "<div class=\"title_text\">\n" .
2313 "<table cellspacing=\"0\">\n";
2314 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
2316 "<td></td><td> $ad{'rfc2822'}";
2317 if ($ad{'hour_local'} < 6) {
2318 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2320 printf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2324 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
2325 print "<tr><td></td><td> $cd{'rfc2822'}" . sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . "</td></tr>\n";
2326 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
2329 "<td class=\"sha1\">" .
2330 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash), class => "list"}, $co{'tree'}) .
2332 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)}, "tree");
2333 if ($have_snapshot) {
2334 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
2338 my $parents = $co{'parents'};
2339 foreach my $par (@
$parents) {
2342 "<td class=\"sha1\">" . $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par), class => "list"}, $par) . "</td>" .
2343 "<td class=\"link\">" .
2344 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
2345 " | " . $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "commitdiff") .
2352 print "<div class=\"page_body\">\n";
2353 git_print_log
($co{'comment'});
2356 git_difftree_body
(\
@difftree, $parent);
2362 mkdir($git_temp, 0700);
2364 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2366 $cgi->a({-href
=> href
(action
=>"blobdiff_plain", hash
=>$hash, hash_parent
=>$hash_parent)}, "plain");
2367 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2368 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2370 print "<div class=\"page_nav\">\n" .
2371 "<br/><br/></div>\n" .
2372 "<div class=\"title\">$hash vs $hash_parent</div>\n";
2374 git_print_page_path
($file_name, "blob", $hash_base);
2375 print "<div class=\"page_body\">\n" .
2376 "<div class=\"diff_info\">blob:" .
2377 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash_parent, hash_base
=>$hash_base, file_name
=>($file_parent || $file_name))}, $hash_parent) .
2379 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)}, $hash) .
2381 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash);
2386 sub git_blobdiff_plain
{
2387 mkdir($git_temp, 0700);
2388 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8');
2389 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
2392 sub git_commitdiff
{
2393 mkdir($git_temp, 0700);
2394 my %co = parse_commit
($hash);
2396 die_error
(undef, "Unknown commit object");
2398 if (!defined $hash_parent) {
2399 $hash_parent = $co{'parent'} || '--root';
2401 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2402 or die_error
(undef, "Open git-diff-tree failed");
2403 my @difftree = map { chomp; $_ } <$fd>;
2404 close $fd or die_error
(undef, "Reading git-diff-tree failed");
2406 # non-textual hash id's can be cached
2408 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2411 my $refs = git_get_references
();
2412 my $ref = format_ref_marker
($refs, $co{'id'});
2414 $cgi->a({-href
=> href
(action
=>"commitdiff_plain", hash
=>$hash, hash_parent
=>$hash_parent)}, "plain");
2415 git_header_html
(undef, $expires);
2416 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
2417 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
2418 print "<div class=\"page_body\">\n";
2419 git_print_simplified_log
($co{'comment'}, 1); # skip title
2421 foreach my $line (@difftree) {
2422 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
2423 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
2424 if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2432 my $file = validate_input
(unquote
($6));
2433 if ($status eq "A") {
2434 print "<div class=\"diff_info\">" . file_type
($to_mode) . ":" .
2435 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$file)}, $to_id) . "(new)" .
2437 git_diff_print
(undef, "/dev/null", $to_id, "b/$file");
2438 } elsif ($status eq "D") {
2439 print "<div class=\"diff_info\">" . file_type
($from_mode) . ":" .
2440 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$from_id, hash_base
=>$hash_parent, file_name
=>$file)}, $from_id) . "(deleted)" .
2442 git_diff_print
($from_id, "a/$file", undef, "/dev/null");
2443 } elsif ($status eq "M") {
2444 if ($from_id ne $to_id) {
2445 print "<div class=\"diff_info\">" .
2446 file_type
($from_mode) . ":" .
2447 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$from_id, hash_base
=>$hash_parent, file_name
=>$file)}, $from_id) .
2449 file_type
($to_mode) . ":" .
2450 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$to_id, hash_base
=>$hash, file_name
=>$file)}, $to_id);
2452 git_diff_print
($from_id, "a/$file", $to_id, "b/$file");
2461 sub git_commitdiff_plain
{
2462 mkdir($git_temp, 0700);
2463 my %co = parse_commit
($hash);
2465 die_error
(undef, "Unknown commit object");
2467 if (!defined $hash_parent) {
2468 $hash_parent = $co{'parent'} || '--root';
2470 open my $fd, "-|", $GIT, "diff-tree", '-r', $hash_parent, $hash
2471 or die_error
(undef, "Open git-diff-tree failed");
2472 my @difftree = map { chomp; $_ } <$fd>;
2473 close $fd or die_error
(undef, "Reading diff-tree failed");
2475 # try to figure out the next tag after this commit
2477 my $refs = git_get_references
("tags");
2478 open $fd, "-|", $GIT, "rev-list", "HEAD";
2479 my @commits = map { chomp; $_ } <$fd>;
2481 foreach my $commit (@commits) {
2482 if (defined $refs->{$commit}) {
2483 $tagname = $refs->{$commit}
2485 if ($commit eq $hash) {
2490 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8', '-content-disposition' => "inline; filename=\"git-$hash.patch\"");
2491 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2492 my $comment = $co{'comment'};
2493 print "From: $co{'author'}\n" .
2494 "Date: $ad{'rfc2822'} ($ad{'tz_local'})\n".
2495 "Subject: $co{'title'}\n";
2496 if (defined $tagname) {
2497 print "X-Git-Tag: $tagname\n";
2499 print "X-Git-Url: $my_url?p=$project;a=commitdiff;h=$hash\n" .
2502 foreach my $line (@
$comment) {;
2507 foreach my $line (@difftree) {
2508 if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2515 if ($status eq "A") {
2516 git_diff_print
(undef, "/dev/null", $to_id, "b/$file", "plain");
2517 } elsif ($status eq "D") {
2518 git_diff_print
($from_id, "a/$file", undef, "/dev/null", "plain");
2519 } elsif ($status eq "M") {
2520 git_diff_print
($from_id, "a/$file", $to_id, "b/$file", "plain");
2526 if (!defined $hash_base) {
2527 $hash_base = git_get_head_hash
($project);
2530 my %co = parse_commit
($hash_base);
2532 die_error
(undef, "Unknown commit object");
2534 my $refs = git_get_references
();
2536 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base);
2537 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2538 if (!defined $hash && defined $file_name) {
2539 $hash = git_get_hash_by_path
($hash_base, $file_name);
2541 if (defined $hash) {
2542 $ftype = git_get_type
($hash);
2544 git_print_page_path
($file_name, $ftype, $hash_base);
2547 $GIT, "rev-list", "--full-history", $hash_base, "--", $file_name;
2548 git_history_body
($fd, $refs, $hash_base, $ftype);
2555 if (!defined $searchtext) {
2556 die_error
(undef, "Text field empty");
2558 if (!defined $hash) {
2559 $hash = git_get_head_hash
($project);
2561 my %co = parse_commit
($hash);
2563 die_error
(undef, "Unknown commit object");
2565 # pickaxe may take all resources of your box and run for several minutes
2566 # with every query - so decide by yourself how public you make this feature :)
2567 my $commit_search = 1;
2568 my $author_search = 0;
2569 my $committer_search = 0;
2570 my $pickaxe_search = 0;
2571 if ($searchtext =~ s/^author\\://i) {
2573 } elsif ($searchtext =~ s/^committer\\://i) {
2574 $committer_search = 1;
2575 } elsif ($searchtext =~ s/^pickaxe\\://i) {
2577 $pickaxe_search = 1;
2580 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
2581 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
2583 print "<table cellspacing=\"0\">\n";
2585 if ($commit_search) {
2587 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", $hash or next;
2588 while (my $commit_text = <$fd>) {
2589 if (!grep m/$searchtext/i, $commit_text) {
2592 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
2595 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
2598 my @commit_lines = split "\n", $commit_text;
2599 my %co = parse_commit
(undef, \
@commit_lines);
2604 print "<tr class=\"dark\">\n";
2606 print "<tr class=\"light\">\n";
2609 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2610 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2612 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}) -class => "list"}, "<b>" . esc_html
(chop_str
($co{'title'}, 50)) . "</b><br/>");
2613 my $comment = $co{'comment'};
2614 foreach my $line (@
$comment) {
2615 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
2616 my $lead = esc_html
($1) || "";
2617 $lead = chop_str
($lead, 30, 10);
2618 my $match = esc_html
($2) || "";
2619 my $trail = esc_html
($3) || "";
2620 $trail = chop_str
($trail, 30, 10);
2621 my $text = "$lead<span class=\"match\">$match</span>$trail";
2622 print chop_str
($text, 80, 5) . "<br/>\n";
2626 "<td class=\"link\">" .
2627 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
2628 " | " . $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
2635 if ($pickaxe_search) {
2637 open my $fd, "-|", "$GIT rev-list $hash | $GIT diff-tree -r --stdin -S\'$searchtext\'";
2640 while (my $line = <$fd>) {
2641 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
2644 $set{'from_id'} = $3;
2646 $set{'id'} = $set{'to_id'};
2647 if ($set{'id'} =~ m/0{40}/) {
2648 $set{'id'} = $set{'from_id'};
2650 if ($set{'id'} =~ m/0{40}/) {
2654 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
2657 print "<tr class=\"dark\">\n";
2659 print "<tr class=\"light\">\n";
2662 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
2663 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
2665 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list"}, "<b>" .
2666 esc_html
(chop_str
($co{'title'}, 50)) . "</b><br/>");
2667 while (my $setref = shift @files) {
2669 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$set{'id'}, hash_base
=>$co{'id'}, file_name
=>$set{'file'}), class => "list"},
2670 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
2674 "<td class=\"link\">" .
2675 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
2676 " | " . $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
2680 %co = parse_commit
($1);
2690 my $head = git_get_head_hash
($project);
2691 if (!defined $hash) {
2694 if (!defined $page) {
2697 my $refs = git_get_references
();
2699 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2700 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2701 or die_error
(undef, "Open git-rev-list failed");
2702 my @revlist = map { chomp; $_ } <$fd>;
2705 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
2707 if ($#revlist >= (100 * ($page+1)-1)) {
2709 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
2710 -title
=> "Alt-n"}, "next");
2715 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
2716 git_print_header_div
('summary', $project);
2718 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
2723 ## ......................................................................
2724 ## feeds (RSS, OPML)
2727 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
2728 open my $fd, "-|", $GIT, "rev-list", "--max-count=150", git_get_head_hash
($project)
2729 or die_error
(undef, "Open git-rev-list failed");
2730 my @revlist = map { chomp; $_ } <$fd>;
2731 close $fd or die_error
(undef, "Reading git-rev-list failed");
2732 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
2733 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
2734 "<rss version=\"2.0\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\">\n";
2735 print "<channel>\n";
2736 print "<title>$project</title>\n".
2737 "<link>" . esc_html
("$my_url?p=$project;a=summary") . "</link>\n".
2738 "<description>$project log</description>\n".
2739 "<language>en</language>\n";
2741 for (my $i = 0; $i <= $#revlist; $i++) {
2742 my $commit = $revlist[$i];
2743 my %co = parse_commit
($commit);
2744 # we read 150, we always show 30 and the ones more recent than 48 hours
2745 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
2748 my %cd = parse_date
($co{'committer_epoch'});
2749 open $fd, "-|", $GIT, "diff-tree", '-r', $co{'parent'}, $co{'id'} or next;
2750 my @difftree = map { chomp; $_ } <$fd>;
2754 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
2756 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
2757 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
2758 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
2759 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
2760 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
2761 "<content:encoded>" .
2763 my $comment = $co{'comment'};
2764 foreach my $line (@
$comment) {
2765 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
2766 print "$line<br/>\n";
2769 foreach my $line (@difftree) {
2770 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
2773 my $file = validate_input
(unquote
($7));
2774 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
2775 print "$file<br/>\n";
2778 "</content:encoded>\n" .
2781 print "</channel></rss>";
2785 my @list = git_get_projects_list
();
2787 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
2788 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
2789 "<opml version=\"1.0\">\n".
2791 " <title>$site_name Git OPML Export</title>\n".
2794 "<outline text=\"git RSS feeds\">\n";
2796 foreach my $pr (@list) {
2798 my $head = git_get_head_hash
($proj{'path'});
2799 if (!defined $head) {
2802 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
2803 my %co = parse_commit
($head);
2808 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
2809 my $rss = "$my_url?p=$proj{'path'};a=rss";
2810 my $html = "$my_url?p=$proj{'path'};a=summary";
2811 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
2813 print "</outline>\n".