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 # You define site-wide feature defaults here; override them with
71 # $GITWEB_CONFIG as necessary.
73 # feature => {'sub' => feature-sub, 'override' => allow-override, 'default' => [ default options...]
74 # if feature is overridable, feature-sub will be called with default options;
75 # return value indicates if to enable specified feature
78 'sub' => \
&feature_blame
,
83 'sub' => \
&feature_snapshot
,
85 # => [content-encoding, suffix, program]
86 'default' => ['x-gzip', 'gz', 'gzip']},
89 sub gitweb_check_feature
{
91 return undef unless exists $feature{$name};
92 my ($sub, $override, @defaults) = (
93 $feature{$name}{'sub'},
94 $feature{$name}{'override'},
95 @
{$feature{$name}{'default'}});
96 if (!$override) { return @defaults; }
97 return $sub->(@defaults);
100 # To enable system wide have in $GITWEB_CONFIG
101 # $feature{'blame'}{'default'} = [1];
102 # To have project specific config enable override in $GITWEB_CONFIG
103 # $feature{'blame'}{'override'} = 1;
104 # and in project config gitweb.blame = 0|1;
107 my ($val) = git_get_project_config
('blame', '--bool');
109 if ($val eq 'true') {
111 } elsif ($val eq 'false') {
118 # To disable system wide have in $GITWEB_CONFIG
119 # $feature{'snapshot'}{'default'} = [undef];
120 # To have project specific config enable override in $GITWEB_CONFIG
121 # $feature{'blame'}{'override'} = 1;
122 # and in project config gitweb.snapshot = none|gzip|bzip2
124 sub feature_snapshot
{
125 my ($ctype, $suffix, $command) = @_;
127 my ($val) = git_get_project_config
('snapshot');
129 if ($val eq 'gzip') {
130 return ('x-gzip', 'gz', 'gzip');
131 } elsif ($val eq 'bzip2') {
132 return ('x-bzip2', 'bz2', 'bzip2');
133 } elsif ($val eq 'none') {
137 return ($ctype, $suffix, $command);
140 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
141 require $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
143 # version of the core git binary
144 our $git_version = qx($GIT --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
146 $projects_list ||= $projectroot;
147 if (! -d
$git_temp) {
148 mkdir($git_temp, 0700) || die_error
(undef, "Couldn't mkdir $git_temp");
151 # ======================================================================
152 # input validation and dispatch
153 our $action = $cgi->param('a');
154 if (defined $action) {
155 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
156 die_error
(undef, "Invalid action parameter");
160 our $project = ($cgi->param('p') || $ENV{'PATH_INFO'});
161 if (defined $project) {
164 $project = undef unless $project;
166 if (defined $project) {
167 if (!validate_input
($project)) {
168 die_error
(undef, "Invalid project parameter");
170 if (!(-d
"$projectroot/$project")) {
171 die_error
(undef, "No such directory");
173 if (!(-e
"$projectroot/$project/HEAD")) {
174 die_error
(undef, "No such project");
176 $ENV{'GIT_DIR'} = "$projectroot/$project";
179 our $file_name = $cgi->param('f');
180 if (defined $file_name) {
181 if (!validate_input
($file_name)) {
182 die_error
(undef, "Invalid file parameter");
186 our $file_parent = $cgi->param('fp');
187 if (defined $file_parent) {
188 if (!validate_input
($file_parent)) {
189 die_error
(undef, "Invalid file parent parameter");
193 our $hash = $cgi->param('h');
195 if (!validate_input
($hash)) {
196 die_error
(undef, "Invalid hash parameter");
200 our $hash_parent = $cgi->param('hp');
201 if (defined $hash_parent) {
202 if (!validate_input
($hash_parent)) {
203 die_error
(undef, "Invalid hash parent parameter");
207 our $hash_base = $cgi->param('hb');
208 if (defined $hash_base) {
209 if (!validate_input
($hash_base)) {
210 die_error
(undef, "Invalid hash base parameter");
214 our $hash_parent_base = $cgi->param('hpb');
215 if (defined $hash_parent_base) {
216 if (!validate_input
($hash_parent_base)) {
217 die_error
(undef, "Invalid hash parent base parameter");
221 our $page = $cgi->param('pg');
223 if ($page =~ m/[^0-9]$/) {
224 die_error
(undef, "Invalid page parameter");
228 our $searchtext = $cgi->param('s');
229 if (defined $searchtext) {
230 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
231 die_error
(undef, "Invalid search parameter");
233 $searchtext = quotemeta $searchtext;
238 "blame" => \
&git_blame2
,
239 "blobdiff" => \
&git_blobdiff
,
240 "blobdiff_plain" => \
&git_blobdiff_plain
,
241 "blob" => \
&git_blob
,
242 "blob_plain" => \
&git_blob_plain
,
243 "commitdiff" => \
&git_commitdiff
,
244 "commitdiff_plain" => \
&git_commitdiff_plain
,
245 "commit" => \
&git_commit
,
246 "heads" => \
&git_heads
,
247 "history" => \
&git_history
,
250 "search" => \
&git_search
,
251 "shortlog" => \
&git_shortlog
,
252 "summary" => \
&git_summary
,
254 "tags" => \
&git_tags
,
255 "tree" => \
&git_tree
,
256 "snapshot" => \
&git_snapshot
,
257 # those below don't need $project
258 "opml" => \
&git_opml
,
259 "project_list" => \
&git_project_list
,
262 if (defined $project) {
263 $action ||= 'summary';
265 $action ||= 'project_list';
267 if (!defined($actions{$action})) {
268 die_error
(undef, "Unknown action");
270 $actions{$action}->();
273 ## ======================================================================
287 hash_parent_base
=> "hpb",
291 my %mapping = @mapping;
293 $params{"project"} ||= $project;
296 for (my $i = 0; $i < @mapping; $i += 2) {
297 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
298 if (defined $params{$name}) {
299 push @result, $symbol . "=" . esc_param
($params{$name});
302 return "$my_uri?" . join(';', @result);
306 ## ======================================================================
307 ## validation, quoting/unquoting and escaping
312 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
315 if ($input =~ m/(^|\/)(|\
.|\
.\
.)($|\
/)/) {
318 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\
-\
+\#\
~\
%]/) {
324 # quote unsafe chars, but keep the slash, even when it's not
325 # correct, but quoted slashes look too horrible in bookmarks
328 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
334 # replace invalid utf8 character with SUBSTITUTION sequence
337 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
338 $str = escapeHTML
($str);
339 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
343 # git may return quoted and escaped filenames
346 if ($str =~ m/^"(.*)"$/) {
348 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
353 # escape tabs (convert tabs to spaces)
357 while ((my $pos = index($line, "\t")) != -1) {
358 if (my $count = (8 - ($pos % 8))) {
359 my $spaces = ' ' x
$count;
360 $line =~ s/\t/$spaces/;
367 ## ----------------------------------------------------------------------
368 ## HTML aware string manipulation
373 my $add_len = shift || 10;
375 # allow only $len chars, but don't cut a word if it would fit in $add_len
376 # if it doesn't fit, cut it if it's still longer than the dots we would add
377 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
380 if (length($tail) > 4) {
382 $body =~ s/&[^;]*$//; # remove chopped character entities
387 ## ----------------------------------------------------------------------
388 ## functions returning short strings
390 # CSS class for given age value (in seconds)
394 if ($age < 60*60*2) {
396 } elsif ($age < 60*60*24*2) {
403 # convert age in seconds to "nn units ago" string
408 if ($age > 60*60*24*365*2) {
409 $age_str = (int $age/60/60/24/365);
410 $age_str .= " years ago";
411 } elsif ($age > 60*60*24*(365/12)*2) {
412 $age_str = int $age/60/60/24/(365/12);
413 $age_str .= " months ago";
414 } elsif ($age > 60*60*24*7*2) {
415 $age_str = int $age/60/60/24/7;
416 $age_str .= " weeks ago";
417 } elsif ($age > 60*60*24*2) {
418 $age_str = int $age/60/60/24;
419 $age_str .= " days ago";
420 } elsif ($age > 60*60*2) {
421 $age_str = int $age/60/60;
422 $age_str .= " hours ago";
423 } elsif ($age > 60*2) {
424 $age_str = int $age/60;
425 $age_str .= " min ago";
428 $age_str .= " sec ago";
430 $age_str .= " right now";
435 # convert file mode in octal to symbolic file mode string
437 my $mode = oct shift;
439 if (S_ISDIR
($mode & S_IFMT
)) {
441 } elsif (S_ISLNK
($mode)) {
443 } elsif (S_ISREG
($mode)) {
444 # git cares only about the executable bit
445 if ($mode & S_IXUSR
) {
455 # convert file mode in octal to file type string
459 if ($mode !~ m/^[0-7]+$/) {
465 if (S_ISDIR
($mode & S_IFMT
)) {
467 } elsif (S_ISLNK
($mode)) {
469 } elsif (S_ISREG
($mode)) {
476 ## ----------------------------------------------------------------------
477 ## functions returning short HTML fragments, or transforming HTML fragments
478 ## which don't beling to other sections
480 # format line of commit message or tag comment
481 sub format_log_line_html
{
484 $line = esc_html
($line);
485 $line =~ s/ / /g;
486 if ($line =~ m/([0-9a-fA-F]{40})/) {
488 if (git_get_type
($hash_text) eq "commit") {
490 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$hash_text),
491 -class => "text"}, $hash_text);
492 $line =~ s/$hash_text/$link/;
498 # format marker of refs pointing to given object
499 sub format_ref_marker
{
500 my ($refs, $id) = @_;
503 if (defined $refs->{$id}) {
504 foreach my $ref (@
{$refs->{$id}}) {
505 my ($type, $name) = qw();
506 # e.g. tags/v2.6.11 or heads/next
507 if ($ref =~ m!^(.*?)s?/(.*)$!) {
515 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
520 return ' <span class="refs">'. $markers . '</span>';
526 # format, perhaps shortened and with markers, title line
527 sub format_subject_html
{
528 my ($long, $short, $href, $extra) = @_;
529 $extra = '' unless defined($extra);
531 if (length($short) < length($long)) {
532 return $cgi->a({-href
=> $href, -class => "list subject",
534 esc_html
($short) . $extra);
536 return $cgi->a({-href
=> $href, -class => "list subject"},
537 esc_html
($long) . $extra);
541 sub format_diff_line
{
543 my $char = substr($line, 0, 1);
549 $diff_class = " add";
550 } elsif ($char eq "-") {
551 $diff_class = " rem";
552 } elsif ($char eq "@") {
553 $diff_class = " chunk_header";
554 } elsif ($char eq "\\") {
555 $diff_class = " incomplete";
557 $line = untabify
($line);
558 return "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
561 ## ----------------------------------------------------------------------
562 ## git utility subroutines, invoking git commands
564 # get HEAD ref of given project as hash
565 sub git_get_head_hash
{
567 my $oENV = $ENV{'GIT_DIR'};
569 $ENV{'GIT_DIR'} = "$projectroot/$project";
570 if (open my $fd, "-|", $GIT, "rev-parse", "--verify", "HEAD") {
573 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
578 $ENV{'GIT_DIR'} = $oENV;
583 # get type of given object
587 open my $fd, "-|", $GIT, "cat-file", '-t', $hash or return;
594 sub git_get_project_config
{
595 my ($key, $type) = @_;
597 return unless ($key);
598 $key =~ s/^gitweb\.//;
599 return if ($key =~ m/\W/);
601 my @x = ($GIT, 'repo-config');
602 if (defined $type) { push @x, $type; }
604 push @x, "gitweb.$key";
610 # get hash of given path at given ref
611 sub git_get_hash_by_path
{
613 my $path = shift || return undef;
617 open my $fd, "-|", $GIT, "ls-tree", $base, "--", $path
618 or die_error
(undef, "Open git-ls-tree failed");
620 close $fd or return undef;
622 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
623 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
627 # converts symbolic name to hash
630 return undef unless @params;
632 open my $fd, "-|", $GIT, "rev-parse", @params
634 my @hashes = map { chomp; $_ } <$fd>;
639 } elsif (scalar(@hashes) == 1) {
647 ## ......................................................................
648 ## git utility functions, directly accessing git repository
650 # assumes that PATH is not symref
651 sub git_get_hash_by_ref
{
654 open my $fd, "$projectroot/$path" or return undef;
658 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
663 sub git_get_project_description
{
666 open my $fd, "$projectroot/$path/description" or return undef;
673 sub git_get_project_url_list
{
676 open my $fd, "$projectroot/$path/cloneurl" or return undef;
677 my @git_project_url_list = map { chomp; $_ } <$fd>;
680 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
683 sub git_get_projects_list
{
686 if (-d
$projects_list) {
687 # search in directory
688 my $dir = $projects_list;
689 opendir my ($dh), $dir or return undef;
690 while (my $dir = readdir($dh)) {
691 if (-e
"$projectroot/$dir/HEAD") {
699 } elsif (-f
$projects_list) {
700 # read from file(url-encoded):
701 # 'git%2Fgit.git Linus+Torvalds'
702 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
703 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
704 open my ($fd), $projects_list or return undef;
705 while (my $line = <$fd>) {
707 my ($path, $owner) = split ' ', $line;
708 $path = unescape
($path);
709 $owner = unescape
($owner);
710 if (!defined $path) {
713 if (-e
"$projectroot/$path/HEAD") {
716 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
723 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
727 sub git_get_project_owner
{
731 return undef unless $project;
733 # read from file (url-encoded):
734 # 'git%2Fgit.git Linus+Torvalds'
735 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
736 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
737 if (-f
$projects_list) {
738 open (my $fd , $projects_list);
739 while (my $line = <$fd>) {
741 my ($pr, $ow) = split ' ', $line;
744 if ($pr eq $project) {
745 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
751 if (!defined $owner) {
752 $owner = get_file_owner
("$projectroot/$project");
758 sub git_get_references
{
759 my $type = shift || "";
762 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
763 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
764 if (-f
"$projectroot/$project/info/refs") {
765 open $fd, "$projectroot/$project/info/refs"
768 open $fd, "-|", $GIT, "ls-remote", "."
772 while (my $line = <$fd>) {
774 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?[^\^]+)/) {
775 if (defined $refs{$1}) {
776 push @
{$refs{$1}}, $2;
786 sub git_get_following_references
{
787 my $hash = shift || return undef;
789 my $base = shift || $hash_base || "HEAD";
791 my $refs = git_get_references
($type);
792 open my $fd, "-|", $GIT, "rev-list", $base
794 my @commits = map { chomp; $_ } <$fd>;
801 foreach my $commit (@commits) {
802 foreach my $ref (@
{$refs->{$commit}}) {
804 push @reflist, $lastref;
806 if ($commit eq $hash) {
811 return wantarray ?
@reflist : $lastref;
814 sub git_get_preceding_references
{
815 my $hash = shift || return undef;
818 my $refs = git_get_references
($type);
819 open my $fd, "-|", $GIT, "rev-list", $hash
821 my @commits = map { chomp; $_ } <$fd>;
827 foreach my $commit (@commits) {
828 foreach my $ref (@
{$refs->{$commit}}) {
829 return $ref unless wantarray;
837 sub git_get_rev_name_tags
{
838 my $hash = shift || return undef;
840 open my $fd, "-|", $GIT, "name-rev", "--tags", $hash
842 my $name_rev = <$fd>;
845 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
848 # catches also '$hash undefined' output
853 ## ----------------------------------------------------------------------
854 ## parse to hash functions
858 my $tz = shift || "-0000";
861 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
862 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
863 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
864 $date{'hour'} = $hour;
865 $date{'minute'} = $min;
866 $date{'mday'} = $mday;
867 $date{'day'} = $days[$wday];
868 $date{'month'} = $months[$mon];
869 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
870 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
871 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
872 $mday, $months[$mon], $hour ,$min;
874 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
875 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
876 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
877 $date{'hour_local'} = $hour;
878 $date{'minute_local'} = $min;
879 $date{'tz_local'} = $tz;
888 open my $fd, "-|", $GIT, "cat-file", "tag", $tag_id or return;
889 $tag{'id'} = $tag_id;
890 while (my $line = <$fd>) {
892 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
894 } elsif ($line =~ m/^type (.+)$/) {
896 } elsif ($line =~ m/^tag (.+)$/) {
898 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
902 } elsif ($line =~ m/--BEGIN/) {
903 push @comment, $line;
905 } elsif ($line eq "") {
909 push @comment, <$fd>;
910 $tag{'comment'} = \
@comment;
912 if (!defined $tag{'name'}) {
919 my $commit_id = shift;
920 my $commit_text = shift;
925 if (defined $commit_text) {
926 @commit_lines = @
$commit_text;
929 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", "--max-count=1", $commit_id
931 @commit_lines = split '\n', <$fd>;
936 my $header = shift @commit_lines;
937 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
940 ($co{'id'}, my @parents) = split ' ', $header;
941 $co{'parents'} = \
@parents;
942 $co{'parent'} = $parents[0];
943 while (my $line = shift @commit_lines) {
944 last if $line eq "\n";
945 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
947 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
949 $co{'author_epoch'} = $2;
950 $co{'author_tz'} = $3;
951 if ($co{'author'} =~ m/^([^<]+) </) {
952 $co{'author_name'} = $1;
954 $co{'author_name'} = $co{'author'};
956 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
957 $co{'committer'} = $1;
958 $co{'committer_epoch'} = $2;
959 $co{'committer_tz'} = $3;
960 $co{'committer_name'} = $co{'committer'};
961 $co{'committer_name'} =~ s/ <.*//;
964 if (!defined $co{'tree'}) {
968 foreach my $title (@commit_lines) {
971 $co{'title'} = chop_str
($title, 80, 5);
972 # remove leading stuff of merges to make the interesting part visible
973 if (length($title) > 50) {
974 $title =~ s/^Automatic //;
975 $title =~ s/^merge (of|with) /Merge ... /i;
976 if (length($title) > 50) {
977 $title =~ s/(http|rsync):\/\///;
979 if (length($title) > 50) {
980 $title =~ s/(master|www|rsync)\.//;
982 if (length($title) > 50) {
983 $title =~ s/kernel.org:?//;
985 if (length($title) > 50) {
986 $title =~ s/\/pub\/scm//;
989 $co{'title_short'} = chop_str
($title, 50, 5);
993 # remove added spaces
994 foreach my $line (@commit_lines) {
997 $co{'comment'} = \
@commit_lines;
999 my $age = time - $co{'committer_epoch'};
1001 $co{'age_string'} = age_string
($age);
1002 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
1003 if ($age > 60*60*24*7*2) {
1004 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1005 $co{'age_string_age'} = $co{'age_string'};
1007 $co{'age_string_date'} = $co{'age_string'};
1008 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
1013 # parse ref from ref_file, given by ref_id, with given type
1015 my $ref_file = shift;
1017 my $type = shift || git_get_type
($ref_id);
1020 $ref_item{'type'} = $type;
1021 $ref_item{'id'} = $ref_id;
1022 $ref_item{'epoch'} = 0;
1023 $ref_item{'age'} = "unknown";
1024 if ($type eq "tag") {
1025 my %tag = parse_tag
($ref_id);
1026 $ref_item{'comment'} = $tag{'comment'};
1027 if ($tag{'type'} eq "commit") {
1028 my %co = parse_commit
($tag{'object'});
1029 $ref_item{'epoch'} = $co{'committer_epoch'};
1030 $ref_item{'age'} = $co{'age_string'};
1031 } elsif (defined($tag{'epoch'})) {
1032 my $age = time - $tag{'epoch'};
1033 $ref_item{'epoch'} = $tag{'epoch'};
1034 $ref_item{'age'} = age_string
($age);
1036 $ref_item{'reftype'} = $tag{'type'};
1037 $ref_item{'name'} = $tag{'name'};
1038 $ref_item{'refid'} = $tag{'object'};
1039 } elsif ($type eq "commit"){
1040 my %co = parse_commit
($ref_id);
1041 $ref_item{'reftype'} = "commit";
1042 $ref_item{'name'} = $ref_file;
1043 $ref_item{'title'} = $co{'title'};
1044 $ref_item{'refid'} = $ref_id;
1045 $ref_item{'epoch'} = $co{'committer_epoch'};
1046 $ref_item{'age'} = $co{'age_string'};
1048 $ref_item{'reftype'} = $type;
1049 $ref_item{'name'} = $ref_file;
1050 $ref_item{'refid'} = $ref_id;
1056 # parse line of git-diff-tree "raw" output
1057 sub parse_difftree_raw_line
{
1061 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1062 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1063 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1064 $res{'from_mode'} = $1;
1065 $res{'to_mode'} = $2;
1066 $res{'from_id'} = $3;
1068 $res{'status'} = $5;
1069 $res{'similarity'} = $6;
1070 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1071 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1073 $res{'file'} = unquote
($7);
1076 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1077 #elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1078 # $res{'commit'} = $1;
1081 return wantarray ?
%res : \
%res;
1084 ## ......................................................................
1085 ## parse to array of hashes functions
1087 sub git_get_refs_list
{
1088 my $ref_dir = shift;
1092 my $pfxlen = length("$projectroot/$project/$ref_dir");
1093 File
::Find
::find
(sub {
1096 push @refs, substr($File::Find
::name
, $pfxlen + 1);
1098 }, "$projectroot/$project/$ref_dir");
1100 foreach my $ref_file (@refs) {
1101 my $ref_id = git_get_hash_by_ref
("$project/$ref_dir/$ref_file");
1102 my $type = git_get_type
($ref_id) || next;
1103 my %ref_item = parse_ref
($ref_file, $ref_id, $type);
1105 push @reflist, \
%ref_item;
1108 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1112 ## ----------------------------------------------------------------------
1113 ## filesystem-related functions
1115 sub get_file_owner
{
1118 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1119 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1120 if (!defined $gcos) {
1124 $owner =~ s/[,;].*$//;
1125 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
1128 ## ......................................................................
1129 ## mimetype related functions
1131 sub mimetype_guess_file
{
1132 my $filename = shift;
1133 my $mimemap = shift;
1134 -r
$mimemap or return undef;
1137 open(MIME
, $mimemap) or return undef;
1139 next if m/^#/; # skip comments
1140 my ($mime, $exts) = split(/\t+/);
1141 if (defined $exts) {
1142 my @exts = split(/\s+/, $exts);
1143 foreach my $ext (@exts) {
1144 $mimemap{$ext} = $mime;
1150 $filename =~ /\.(.*?)$/;
1151 return $mimemap{$1};
1154 sub mimetype_guess
{
1155 my $filename = shift;
1157 $filename =~ /\./ or return undef;
1159 if ($mimetypes_file) {
1160 my $file = $mimetypes_file;
1161 if ($file !~ m!^/!) { # if it is relative path
1162 # it is relative to project
1163 $file = "$projectroot/$project/$file";
1165 $mime = mimetype_guess_file
($filename, $file);
1167 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1173 my $filename = shift;
1176 my $mime = mimetype_guess
($filename);
1177 $mime and return $mime;
1181 return $default_blob_plain_mimetype unless $fd;
1184 return 'text/plain' .
1185 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
1186 } elsif (! $filename) {
1187 return 'application/octet-stream';
1188 } elsif ($filename =~ m/\.png$/i) {
1190 } elsif ($filename =~ m/\.gif$/i) {
1192 } elsif ($filename =~ m/\.jpe?g$/i) {
1193 return 'image/jpeg';
1195 return 'application/octet-stream';
1199 ## ======================================================================
1200 ## functions printing HTML: header, footer, error page
1202 sub git_header_html
{
1203 my $status = shift || "200 OK";
1204 my $expires = shift;
1206 my $title = "$site_name git";
1207 if (defined $project) {
1208 $title .= " - $project";
1209 if (defined $action) {
1210 $title .= "/$action";
1211 if (defined $file_name) {
1212 $title .= " - $file_name";
1213 if ($action eq "tree" && $file_name !~ m
|/$|) {
1220 # require explicit support from the UA if we are to send the page as
1221 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1222 # we have to do this because MSIE sometimes globs '*/*', pretending to
1223 # support xhtml+xml but choking when it gets what it asked for.
1224 if (defined $cgi->http('HTTP_ACCEPT') &&
1225 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1226 $cgi->Accept('application/xhtml+xml') != 0) {
1227 $content_type = 'application/xhtml+xml';
1229 $content_type = 'text/html';
1231 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1232 -status
=> $status, -expires
=> $expires);
1234 <?xml version="1.0" encoding="utf-8"?>
1235 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1236 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1237 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1238 <!-- git core binaries version $git_version -->
1240 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1241 <meta name="generator" content="gitweb/$version git/$git_version"/>
1242 <meta name="robots" content="index, nofollow"/>
1243 <title>$title</title>
1244 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
1246 if (defined $project) {
1247 printf('<link rel="alternate" title="%s log" '.
1248 'href="%s" type="application/rss+xml"/>'."\n",
1249 esc_param
($project), href
(action
=>"rss"));
1254 "<div class=\"page_header\">\n" .
1255 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
1256 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
1258 print $cgi->a({-href
=> esc_param
($home_link)}, $home_link_str) . " / ";
1259 if (defined $project) {
1260 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1261 if (defined $action) {
1265 if (!defined $searchtext) {
1269 if (defined $hash_base) {
1270 $search_hash = $hash_base;
1271 } elsif (defined $hash) {
1272 $search_hash = $hash;
1274 $search_hash = "HEAD";
1276 $cgi->param("a", "search");
1277 $cgi->param("h", $search_hash);
1278 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
1279 "<div class=\"search\">\n" .
1280 $cgi->hidden(-name
=> "p") . "\n" .
1281 $cgi->hidden(-name
=> "a") . "\n" .
1282 $cgi->hidden(-name
=> "h") . "\n" .
1283 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1285 $cgi->end_form() . "\n";
1290 sub git_footer_html
{
1291 print "<div class=\"page_footer\">\n";
1292 if (defined $project) {
1293 my $descr = git_get_project_description
($project);
1294 if (defined $descr) {
1295 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1297 print $cgi->a({-href
=> href
(action
=>"rss"), -class => "rss_logo"}, "RSS") . "\n";
1299 print $cgi->a({-href
=> href
(action
=>"opml"), -class => "rss_logo"}, "OPML") . "\n";
1307 my $status = shift || "403 Forbidden";
1308 my $error = shift || "Malformed query, file missing or permission denied";
1310 git_header_html
($status);
1312 <div class="page_body">
1322 ## ----------------------------------------------------------------------
1323 ## functions printing or outputting HTML: navigation
1325 sub git_print_page_nav
{
1326 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1327 $extra = '' if !defined $extra; # pager or formats
1329 my @navs = qw(summary shortlog log commit commitdiff tree);
1331 @navs = grep { $_ ne $suppress } @navs;
1334 my %arg = map { $_ => {action
=>$_} } @navs;
1335 if (defined $head) {
1336 for (qw(commit commitdiff)) {
1337 $arg{$_}{hash
} = $head;
1339 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1340 for (qw(shortlog log)) {
1341 $arg{$_}{hash
} = $head;
1345 $arg{tree
}{hash
} = $treehead if defined $treehead;
1346 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1348 print "<div class=\"page_nav\">\n" .
1350 map { $_ eq $current ?
1351 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1353 print "<br/>\n$extra<br/>\n" .
1357 sub format_paging_nav
{
1358 my ($action, $hash, $head, $page, $nrevs) = @_;
1362 if ($hash ne $head || $page) {
1363 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1365 $paging_nav .= "HEAD";
1369 $paging_nav .= " ⋅ " .
1370 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1371 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1373 $paging_nav .= " ⋅ prev";
1376 if ($nrevs >= (100 * ($page+1)-1)) {
1377 $paging_nav .= " ⋅ " .
1378 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1379 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1381 $paging_nav .= " ⋅ next";
1387 ## ......................................................................
1388 ## functions printing or outputting HTML: div
1390 sub git_print_header_div
{
1391 my ($action, $title, $hash, $hash_base) = @_;
1394 $args{action
} = $action;
1395 $args{hash
} = $hash if $hash;
1396 $args{hash_base
} = $hash_base if $hash_base;
1398 print "<div class=\"header\">\n" .
1399 $cgi->a({-href
=> href
(%args), -class => "title"},
1400 $title ?
$title : $action) .
1404 sub git_print_page_path
{
1409 if (!defined $name) {
1410 print "<div class=\"page_path\">/</div>\n";
1411 } elsif (defined $type && $type eq 'blob') {
1412 print "<div class=\"page_path\">";
1414 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1418 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name)},
1421 print "<br/></div>\n";
1423 print "<div class=\"page_path\">" . esc_html
($name) . "<br/></div>\n";
1430 # remove leading empty lines
1431 while (defined $log->[0] && $log->[0] eq "") {
1438 foreach my $line (@
$log) {
1439 # print only one empty line
1440 # do not print empty line after signoff
1442 next if ($empty || $signoff);
1447 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1449 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1452 print format_log_line_html
($line) . "<br/>\n";
1457 sub git_print_simplified_log
{
1459 my $remove_title = shift;
1461 shift @
$log if $remove_title;
1462 # remove leading empty lines
1463 while (defined $log->[0] && $log->[0] eq "") {
1467 # simplify and print log
1469 foreach my $line (@
$log) {
1470 # remove signoff lines
1471 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1474 # print only one empty line
1481 print format_log_line_html
($line) . "<br/>\n";
1483 # end with single empty line
1484 print "<br/>\n" unless $empty;
1487 ## ......................................................................
1488 ## functions printing large fragments of HTML
1490 sub git_difftree_body
{
1491 my ($difftree, $hash, $parent) = @_;
1493 print "<div class=\"list_head\">\n";
1494 if ($#{$difftree} > 10) {
1495 print(($#{$difftree} + 1) . " files changed:\n");
1499 print "<table class=\"diff_tree\">\n";
1501 foreach my $line (@
{$difftree}) {
1502 my %diff = parse_difftree_raw_line
($line);
1505 print "<tr class=\"dark\">\n";
1507 print "<tr class=\"light\">\n";
1511 my ($to_mode_oct, $to_mode_str, $to_file_type);
1512 my ($from_mode_oct, $from_mode_str, $from_file_type);
1513 if ($diff{'to_mode'} ne ('0' x
6)) {
1514 $to_mode_oct = oct $diff{'to_mode'};
1515 if (S_ISREG
($to_mode_oct)) { # only for regular file
1516 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1518 $to_file_type = file_type
($diff{'to_mode'});
1520 if ($diff{'from_mode'} ne ('0' x
6)) {
1521 $from_mode_oct = oct $diff{'from_mode'};
1522 if (S_ISREG
($to_mode_oct)) { # only for regular file
1523 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1525 $from_file_type = file_type
($diff{'from_mode'});
1528 if ($diff{'status'} eq "A") { # created
1529 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1530 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1531 $mode_chng .= "]</span>";
1533 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1534 hash_base
=>$hash, file_name
=>$diff{'file'}),
1535 -class => "list"}, esc_html
($diff{'file'})) .
1537 "<td>$mode_chng</td>\n" .
1538 "<td class=\"link\">" .
1539 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1540 hash_base
=>$hash, file_name
=>$diff{'file'})},
1544 } elsif ($diff{'status'} eq "D") { # deleted
1545 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1547 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1548 hash_base
=>$parent, file_name
=>$diff{'file'}),
1549 -class => "list"}, esc_html
($diff{'file'})) .
1551 "<td>$mode_chng</td>\n" .
1552 "<td class=\"link\">" .
1553 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1554 hash_base
=>$parent, file_name
=>$diff{'file'})},
1557 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1558 file_name
=>$diff{'file'})},\
1562 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1563 my $mode_chnge = "";
1564 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1565 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1566 if ($from_file_type != $to_file_type) {
1567 $mode_chnge .= " from $from_file_type to $to_file_type";
1569 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1570 if ($from_mode_str && $to_mode_str) {
1571 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1572 } elsif ($to_mode_str) {
1573 $mode_chnge .= " mode: $to_mode_str";
1576 $mode_chnge .= "]</span>\n";
1579 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1580 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1581 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1582 hash_base
=>$hash, hash_parent_base
=>$parent,
1583 file_name
=>$diff{'file'}),
1584 -class => "list"}, esc_html
($diff{'file'}));
1585 } else { # only mode changed
1586 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1587 hash_base
=>$hash, file_name
=>$diff{'file'}),
1588 -class => "list"}, esc_html
($diff{'file'}));
1591 "<td>$mode_chnge</td>\n" .
1592 "<td class=\"link\">" .
1593 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1594 hash_base
=>$hash, file_name
=>$diff{'file'})},
1596 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1598 $cgi->a({-href
=> href
(action
=>"blobdiff",
1599 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1600 hash_base
=>$hash, hash_parent_base
=>$parent,
1601 file_name
=>$diff{'file'})},
1605 $cgi->a({-href
=> href
(action
=>"history",
1606 hash_base
=>$hash, file_name
=>$diff{'file'})},
1610 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
1611 my %status_name = ('R' => 'moved', 'C' => 'copied');
1612 my $nstatus = $status_name{$diff{'status'}};
1614 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1615 # mode also for directories, so we cannot use $to_mode_str
1616 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
1619 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1620 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
1621 -class => "list"}, esc_html
($diff{'to_file'})) . "</td>\n" .
1622 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
1623 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
1624 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
1625 -class => "list"}, esc_html
($diff{'from_file'})) .
1626 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
1627 "<td class=\"link\">" .
1628 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1629 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'})},
1631 if ($diff{'to_id'} ne $diff{'from_id'}) {
1633 $cgi->a({-href
=> href
(action
=>"blobdiff",
1634 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1635 hash_base
=>$hash, hash_parent_base
=>$parent,
1636 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
1641 } # we should not encounter Unmerged (U) or Unknown (X) status
1647 sub git_patchset_body
{
1648 my ($fd, $difftree, $hash, $hash_parent) = @_;
1652 my $patch_found = 0;
1655 print "<div class=\"patchset\">\n";
1658 while (my $patch_line @
$fd>) {
1661 if ($patch_line =~ m/^diff /) { # "git diff" header
1662 # beginning of patch (in patchset)
1664 # close previous patch
1665 print "</div>\n"; # class="patch"
1667 # first patch in patchset
1670 print "<div class=\"patch\">\n";
1672 if (ref($difftree->[$patch_idx]) eq "HASH") {
1673 $diffinfo = $difftree->[$patch_idx];
1675 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
1679 # for now, no extended header, hence we skip empty patches
1680 # companion to next LINE if $in_header;
1681 if ($diffinfo->{'from_id'} eq $diffinfo->{'to_id'}) { # no change
1686 if ($diffinfo->{'status'} eq "A") { # added
1687 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'to_mode'}) . ":" .
1688 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1689 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
1690 $diffinfo->{'to_id'}) . "(new)" .
1691 "</div>\n"; # class="diff_info"
1693 } elsif ($diffinfo->{'status'} eq "D") { # deleted
1694 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'from_mode'}) . ":" .
1695 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1696 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
1697 $diffinfo->{'from_id'}) . "(deleted)" .
1698 "</div>\n"; # class="diff_info"
1700 } elsif ($diffinfo->{'status'} eq "R" || # renamed
1701 $diffinfo->{'status'} eq "C" || # copied
1702 $diffinfo->{'status'} eq "2") { # with two filenames (from git_blobdiff)
1703 print "<div class=\"diff_info\">" .
1704 file_type
($diffinfo->{'from_mode'}) . ":" .
1705 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1706 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'from_file'})},
1707 $diffinfo->{'from_id'}) .
1709 file_type
($diffinfo->{'to_mode'}) . ":" .
1710 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1711 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'to_file'})},
1712 $diffinfo->{'to_id'});
1713 print "</div>\n"; # class="diff_info"
1715 } else { # modified, mode changed, ...
1716 print "<div class=\"diff_info\">" .
1717 file_type
($diffinfo->{'from_mode'}) . ":" .
1718 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1719 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
1720 $diffinfo->{'from_id'}) .
1722 file_type
($diffinfo->{'to_mode'}) . ":" .
1723 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1724 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
1725 $diffinfo->{'to_id'});
1726 print "</div>\n"; # class="diff_info"
1729 #print "<div class=\"diff extended_header\">\n";
1732 } # start of patch in patchset
1735 if ($in_header && $patch_line =~ m/^---/) {
1736 #print "</div>\n"; # class="diff extended_header"
1739 my $file = $diffinfo->{'from_file'};
1740 $file ||= $diffinfo->{'file'};
1741 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1742 hash
=>$diffinfo->{'from_id'}, file_name
=>$file),
1743 -class => "list"}, esc_html
($file));
1744 $patch_line =~ s
|a
/.*$|a/$file|g
;
1745 print "<div class=\"diff from_file\">$patch_line</div>\n";
1747 $patch_line = <$fd>;
1750 #$patch_line =~ m/^+++/;
1751 $file = $diffinfo->{'to_file'};
1752 $file ||= $diffinfo->{'file'};
1753 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1754 hash
=>$diffinfo->{'to_id'}, file_name
=>$file),
1755 -class => "list"}, esc_html
($file));
1756 $patch_line =~ s
|b
/.*|b/$file|g
;
1757 print "<div class=\"diff to_file\">$patch_line</div>\n";
1761 next LINE
if $in_header;
1763 print format_diff_line
($patch_line);
1765 print "</div>\n" if $patch_found; # class="patch"
1767 print "</div>\n"; # class="patchset"
1770 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1772 sub git_shortlog_body
{
1773 # uses global variable $project
1774 my ($revlist, $from, $to, $refs, $extra) = @_;
1776 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
1777 my $have_snapshot = (defined $ctype && defined $suffix);
1779 $from = 0 unless defined $from;
1780 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1782 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
1784 for (my $i = $from; $i <= $to; $i++) {
1785 my $commit = $revlist->[$i];
1786 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
1787 my $ref = format_ref_marker
($refs, $commit);
1788 my %co = parse_commit
($commit);
1790 print "<tr class=\"dark\">\n";
1792 print "<tr class=\"light\">\n";
1795 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1796 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1797 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
1799 print format_subject_html
($co{'title'}, $co{'title_short'},
1800 href
(action
=>"commit", hash
=>$commit), $ref);
1802 "<td class=\"link\">" .
1803 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
1804 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
1805 if ($have_snapshot) {
1806 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
1811 if (defined $extra) {
1813 "<td colspan=\"4\">$extra</td>\n" .
1819 sub git_history_body
{
1820 # Warning: assumes constant type (blob or tree) during history
1821 my ($fd, $refs, $hash_base, $ftype, $extra) = @_;
1823 print "<table class=\"history\" cellspacing=\"0\">\n";
1825 while (my $line = <$fd>) {
1826 if ($line !~ m/^([0-9a-fA-F]{40})/) {
1831 my %co = parse_commit
($commit);
1836 my $ref = format_ref_marker
($refs, $commit);
1839 print "<tr class=\"dark\">\n";
1841 print "<tr class=\"light\">\n";
1844 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1845 # shortlog uses chop_str($co{'author_name'}, 10)
1846 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
1848 # originally git_history used chop_str($co{'title'}, 50)
1849 print format_subject_html
($co{'title'}, $co{'title_short'},
1850 href
(action
=>"commit", hash
=>$commit), $ref);
1852 "<td class=\"link\">" .
1853 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
1854 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
1855 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype);
1857 if ($ftype eq 'blob') {
1858 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
1859 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
1860 if (defined $blob_current && defined $blob_parent &&
1861 $blob_current ne $blob_parent) {
1863 $cgi->a({-href
=> href
(action
=>"blobdiff",
1864 hash
=>$blob_current, hash_parent
=>$blob_parent,
1865 hash_base
=>$hash_base, hash_parent_base
=>$commit,
1866 file_name
=>$file_name)},
1873 if (defined $extra) {
1875 "<td colspan=\"4\">$extra</td>\n" .
1882 # uses global variable $project
1883 my ($taglist, $from, $to, $extra) = @_;
1884 $from = 0 unless defined $from;
1885 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1887 print "<table class=\"tags\" cellspacing=\"0\">\n";
1889 for (my $i = $from; $i <= $to; $i++) {
1890 my $entry = $taglist->[$i];
1892 my $comment_lines = $tag{'comment'};
1893 my $comment = shift @
$comment_lines;
1895 if (defined $comment) {
1896 $comment_short = chop_str
($comment, 30, 5);
1899 print "<tr class=\"dark\">\n";
1901 print "<tr class=\"light\">\n";
1904 print "<td><i>$tag{'age'}</i></td>\n" .
1906 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
1907 -class => "list name"}, esc_html
($tag{'name'})) .
1910 if (defined $comment) {
1911 print format_subject_html
($comment, $comment_short,
1912 href
(action
=>"tag", hash
=>$tag{'id'}));
1915 "<td class=\"selflink\">";
1916 if ($tag{'type'} eq "tag") {
1917 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
1922 "<td class=\"link\">" . " | " .
1923 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
1924 if ($tag{'reftype'} eq "commit") {
1925 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
1926 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'refid'})}, "log");
1927 } elsif ($tag{'reftype'} eq "blob") {
1928 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
1933 if (defined $extra) {
1935 "<td colspan=\"5\">$extra</td>\n" .
1941 sub git_heads_body
{
1942 # uses global variable $project
1943 my ($taglist, $head, $from, $to, $extra) = @_;
1944 $from = 0 unless defined $from;
1945 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1947 print "<table class=\"heads\" cellspacing=\"0\">\n";
1949 for (my $i = $from; $i <= $to; $i++) {
1950 my $entry = $taglist->[$i];
1952 my $curr = $tag{'id'} eq $head;
1954 print "<tr class=\"dark\">\n";
1956 print "<tr class=\"light\">\n";
1959 print "<td><i>$tag{'age'}</i></td>\n" .
1960 ($tag{'id'} eq $head ?
"<td class=\"current_head\">" : "<td>") .
1961 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'}),
1962 -class => "list name"},esc_html
($tag{'name'})) .
1964 "<td class=\"link\">" .
1965 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") . " | " .
1966 $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log") .
1970 if (defined $extra) {
1972 "<td colspan=\"3\">$extra</td>\n" .
1978 ## ----------------------------------------------------------------------
1979 ## functions printing large fragments, format as one of arguments
1981 sub git_diff_print
{
1983 my $from_name = shift;
1985 my $to_name = shift;
1986 my $format = shift || "html";
1988 my $from_tmp = "/dev/null";
1989 my $to_tmp = "/dev/null";
1992 # create tmp from-file
1993 if (defined $from) {
1994 $from_tmp = "$git_temp/gitweb_" . $$ . "_from";
1995 open my $fd2, "> $from_tmp";
1996 open my $fd, "-|", $GIT, "cat-file", "blob", $from;
2003 # create tmp to-file
2005 $to_tmp = "$git_temp/gitweb_" . $$ . "_to";
2006 open my $fd2, "> $to_tmp";
2007 open my $fd, "-|", $GIT, "cat-file", "blob", $to;
2014 open my $fd, "-|", "/usr/bin/diff -u -p -L \'$from_name\' -L \'$to_name\' $from_tmp $to_tmp";
2015 if ($format eq "plain") {
2020 while (my $line = <$fd>) {
2022 my $char = substr($line, 0, 1);
2023 my $diff_class = "";
2025 $diff_class = " add";
2026 } elsif ($char eq "-") {
2027 $diff_class = " rem";
2028 } elsif ($char eq "@") {
2029 $diff_class = " chunk_header";
2030 } elsif ($char eq "\\") {
2034 $line = untabify
($line);
2035 print "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
2040 if (defined $from) {
2049 ## ======================================================================
2050 ## ======================================================================
2053 sub git_project_list
{
2054 my $order = $cgi->param('o');
2055 if (defined $order && $order !~ m/project|descr|owner|age/) {
2056 die_error
(undef, "Unknown order parameter");
2059 my @list = git_get_projects_list
();
2062 die_error
(undef, "No projects found");
2064 foreach my $pr (@list) {
2065 my $head = git_get_head_hash
($pr->{'path'});
2066 if (!defined $head) {
2069 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
2070 my %co = parse_commit
($head);
2074 $pr->{'commit'} = \
%co;
2075 if (!defined $pr->{'descr'}) {
2076 my $descr = git_get_project_description
($pr->{'path'}) || "";
2077 $pr->{'descr'} = chop_str
($descr, 25, 5);
2079 if (!defined $pr->{'owner'}) {
2080 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2082 push @projects, $pr;
2086 if (-f
$home_text) {
2087 print "<div class=\"index_include\">\n";
2088 open (my $fd, $home_text);
2093 print "<table class=\"project_list\">\n" .
2095 $order ||= "project";
2096 if ($order eq "project") {
2097 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2098 print "<th>Project</th>\n";
2101 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=project"),
2102 -class => "header"}, "Project") .
2105 if ($order eq "descr") {
2106 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2107 print "<th>Description</th>\n";
2110 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=descr"),
2111 -class => "header"}, "Description") .
2114 if ($order eq "owner") {
2115 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2116 print "<th>Owner</th>\n";
2119 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=owner"),
2120 -class => "header"}, "Owner") .
2123 if ($order eq "age") {
2124 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
2125 print "<th>Last Change</th>\n";
2128 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=age"),
2129 -class => "header"}, "Last Change") .
2132 print "<th></th>\n" .
2135 foreach my $pr (@projects) {
2137 print "<tr class=\"dark\">\n";
2139 print "<tr class=\"light\">\n";
2142 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2143 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2144 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
2145 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2146 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" .
2147 $pr->{'commit'}{'age_string'} . "</td>\n" .
2148 "<td class=\"link\">" .
2149 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2150 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2151 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") .
2160 my $descr = git_get_project_description
($project) || "none";
2161 my $head = git_get_head_hash
($project);
2162 my %co = parse_commit
($head);
2163 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2165 my $owner = git_get_project_owner
($project);
2167 my $refs = git_get_references
();
2169 git_print_page_nav
('summary','', $head);
2171 print "<div class=\"title\"> </div>\n";
2172 print "<table cellspacing=\"0\">\n" .
2173 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
2174 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2175 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2176 # use per project git URL list in $projectroot/$project/cloneurl
2177 # or make project git URL from git base URL and project name
2178 my $url_tag = "URL";
2179 my @url_list = git_get_project_url_list
($project);
2180 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2181 foreach my $git_url (@url_list) {
2182 next unless $git_url;
2183 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2188 open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_get_head_hash
($project)
2189 or die_error
(undef, "Open git-rev-list failed");
2190 my @revlist = map { chomp; $_ } <$fd>;
2192 git_print_header_div
('shortlog');
2193 git_shortlog_body
(\
@revlist, 0, 15, $refs,
2194 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
2196 my $taglist = git_get_refs_list
("refs/tags");
2197 if (defined @
$taglist) {
2198 git_print_header_div
('tags');
2199 git_tags_body
($taglist, 0, 15,
2200 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
2203 my $headlist = git_get_refs_list
("refs/heads");
2204 if (defined @
$headlist) {
2205 git_print_header_div
('heads');
2206 git_heads_body
($headlist, $head, 0, 15,
2207 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
2214 my $head = git_get_head_hash
($project);
2216 git_print_page_nav
('','', $head,undef,$head);
2217 my %tag = parse_tag
($hash);
2218 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
2219 print "<div class=\"title_text\">\n" .
2220 "<table cellspacing=\"0\">\n" .
2222 "<td>object</td>\n" .
2223 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2224 $tag{'object'}) . "</td>\n" .
2225 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2226 $tag{'type'}) . "</td>\n" .
2228 if (defined($tag{'author'})) {
2229 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
2230 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
2231 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2232 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2235 print "</table>\n\n" .
2237 print "<div class=\"page_body\">";
2238 my $comment = $tag{'comment'};
2239 foreach my $line (@
$comment) {
2240 print esc_html
($line) . "<br/>\n";
2250 if (!gitweb_check_feature
('blame')) {
2251 die_error
('403 Permission denied', "Permission denied");
2253 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2254 $hash_base ||= git_get_head_hash
($project);
2255 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2256 my %co = parse_commit
($hash_base)
2257 or die_error
(undef, "Reading commit failed");
2258 if (!defined $hash) {
2259 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2260 or die_error
(undef, "Error looking up file");
2262 $ftype = git_get_type
($hash);
2263 if ($ftype !~ "blob") {
2264 die_error
("400 Bad Request", "Object is not a blob");
2266 open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base)
2267 or die_error
(undef, "Open git-blame failed");
2270 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2273 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2275 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2276 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2277 git_print_page_path
($file_name, $ftype, $hash_base);
2278 my @rev_color = (qw(light2 dark2));
2279 my $num_colors = scalar(@rev_color);
2280 my $current_color = 0;
2283 <div class="page_body">
2284 <table class="blame">
2285 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2288 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
2290 my $rev = substr($full_rev, 0, 8);
2294 if (!defined $last_rev) {
2295 $last_rev = $full_rev;
2296 } elsif ($last_rev ne $full_rev) {
2297 $last_rev = $full_rev;
2298 $current_color = ++$current_color % $num_colors;
2300 print "<tr class=\"$rev_color[$current_color]\">\n";
2301 print "<td class=\"sha1\">" .
2302 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$full_rev, file_name
=>$file_name)},
2303 esc_html
($rev)) . "</td>\n";
2304 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" .
2305 esc_html
($lineno) . "</a></td>\n";
2306 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
2312 or print "Reading blob failed\n";
2319 if (!gitweb_check_feature
('blame')) {
2320 die_error
('403 Permission denied', "Permission denied");
2322 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2323 $hash_base ||= git_get_head_hash
($project);
2324 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2325 my %co = parse_commit
($hash_base)
2326 or die_error
(undef, "Reading commit failed");
2327 if (!defined $hash) {
2328 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2329 or die_error
(undef, "Error lookup file");
2331 open ($fd, "-|", $GIT, "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2332 or die_error
(undef, "Open git-annotate failed");
2335 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2338 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2340 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2341 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2342 git_print_page_path
($file_name, 'blob', $hash_base);
2343 print "<div class=\"page_body\">\n";
2345 <table class="blame">
2354 my @line_class = (qw(light dark));
2355 my $line_class_len = scalar (@line_class);
2356 my $line_class_num = $#line_class;
2357 while (my $line = <$fd>) {
2369 $line_class_num = ($line_class_num + 1) % $line_class_len;
2371 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) \+\d\d\d\d\t(\d+)\)(.*)$/) {
2378 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
2381 $short_rev = substr ($long_rev, 0, 8);
2382 $age = time () - $time;
2383 $age_str = age_string
($age);
2384 $age_str =~ s/ / /g;
2385 $age_class = age_class
($age);
2386 $author = esc_html
($author);
2387 $author =~ s/ / /g;
2389 $data = untabify
($data);
2390 $data = esc_html
($data);
2393 <tr class="$line_class[$line_class_num]">
2394 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2395 <td class="$age_class">$age_str</td>
2397 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2398 <td class="pre">$data</td>
2401 } # while (my $line = <$fd>)
2402 print "</table>\n\n";
2404 or print "Reading blob failed.\n";
2410 my $head = git_get_head_hash
($project);
2412 git_print_page_nav
('','', $head,undef,$head);
2413 git_print_header_div
('summary', $project);
2415 my $taglist = git_get_refs_list
("refs/tags");
2416 if (defined @
$taglist) {
2417 git_tags_body
($taglist);
2423 my $head = git_get_head_hash
($project);
2425 git_print_page_nav
('','', $head,undef,$head);
2426 git_print_header_div
('summary', $project);
2428 my $taglist = git_get_refs_list
("refs/heads");
2429 if (defined @
$taglist) {
2430 git_heads_body
($taglist, $head);
2435 sub git_blob_plain
{
2436 if (!defined $hash) {
2437 if (defined $file_name) {
2438 my $base = $hash_base || git_get_head_hash
($project);
2439 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2440 or die_error
(undef, "Error lookup file");
2442 die_error
(undef, "No file name defined");
2446 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
2447 or die_error
(undef, "Couldn't cat $file_name, $hash");
2449 $type ||= blob_mimetype
($fd, $file_name);
2451 # save as filename, even when no $file_name is given
2452 my $save_as = "$hash";
2453 if (defined $file_name) {
2454 $save_as = $file_name;
2455 } elsif ($type =~ m/^text\//) {
2459 print $cgi->header(-type
=> "$type",
2460 -content_disposition
=> "inline; filename=\"$save_as\"");
2462 binmode STDOUT
, ':raw';
2464 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2470 if (!defined $hash) {
2471 if (defined $file_name) {
2472 my $base = $hash_base || git_get_head_hash
($project);
2473 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2474 or die_error
(undef, "Error lookup file");
2476 die_error
(undef, "No file name defined");
2479 my $have_blame = gitweb_check_feature
('blame');
2480 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
2481 or die_error
(undef, "Couldn't cat $file_name, $hash");
2482 my $mimetype = blob_mimetype
($fd, $file_name);
2483 if ($mimetype !~ m/^text\//) {
2485 return git_blob_plain
($mimetype);
2488 my $formats_nav = '';
2489 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2490 if (defined $file_name) {
2493 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
2494 hash
=>$hash, file_name
=>$file_name)},
2499 $cgi->a({-href
=> href
(action
=>"blob_plain",
2500 hash
=>$hash, file_name
=>$file_name)},
2503 $cgi->a({-href
=> href
(action
=>"blob",
2504 hash_base
=>"HEAD", file_name
=>$file_name)},
2508 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "plain");
2510 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2511 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2513 print "<div class=\"page_nav\">\n" .
2514 "<br/><br/></div>\n" .
2515 "<div class=\"title\">$hash</div>\n";
2517 git_print_page_path
($file_name, "blob", $hash_base);
2518 print "<div class=\"page_body\">\n";
2520 while (my $line = <$fd>) {
2523 $line = untabify
($line);
2524 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
2525 $nr, $nr, $nr, esc_html
($line);
2528 or print "Reading blob failed.\n";
2534 if (!defined $hash) {
2535 $hash = git_get_head_hash
($project);
2536 if (defined $file_name) {
2537 my $base = $hash_base || $hash;
2538 $hash = git_get_hash_by_path
($base, $file_name, "tree");
2540 if (!defined $hash_base) {
2545 open my $fd, "-|", $GIT, "ls-tree", '-z', $hash
2546 or die_error
(undef, "Open git-ls-tree failed");
2547 my @entries = map { chomp; $_ } <$fd>;
2548 close $fd or die_error
(undef, "Reading tree failed");
2551 my $refs = git_get_references
();
2552 my $ref = format_ref_marker
($refs, $hash_base);
2556 my $have_blame = gitweb_check_feature
('blame');
2557 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2558 $base_key{hash_base
} = $hash_base;
2559 git_print_page_nav
('tree','', $hash_base);
2560 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
2562 print "<div class=\"page_nav\">\n";
2563 print "<br/><br/></div>\n";
2564 print "<div class=\"title\">$hash</div>\n";
2566 if (defined $file_name) {
2567 $base = esc_html
("$file_name/");
2569 git_print_page_path
($file_name, 'tree', $hash_base);
2570 print "<div class=\"page_body\">\n";
2571 print "<table cellspacing=\"0\">\n";
2573 foreach my $line (@entries) {
2574 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2575 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
2579 my $t_name = validate_input
($4);
2581 print "<tr class=\"dark\">\n";
2583 print "<tr class=\"light\">\n";
2586 print "<td class=\"mode\">" . mode_str
($t_mode) . "</td>\n";
2587 if ($t_type eq "blob") {
2588 print "<td class=\"list\">" .
2589 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key),
2590 -class => "list"}, esc_html
($t_name)) .
2592 "<td class=\"link\">" .
2593 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)},
2597 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)},
2601 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2602 hash
=>$t_hash, file_name
=>"$base$t_name")},
2605 $cgi->a({-href
=> href
(action
=>"blob_plain",
2606 hash
=>$t_hash, file_name
=>"$base$t_name")},
2609 } elsif ($t_type eq "tree") {
2610 print "<td class=\"list\">" .
2611 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)},
2612 esc_html
($t_name)) .
2614 "<td class=\"link\">" .
2615 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)},
2618 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base, file_name
=>"$base$t_name")},
2624 print "</table>\n" .
2631 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2632 my $have_snapshot = (defined $ctype && defined $suffix);
2633 if (!$have_snapshot) {
2634 die_error
('403 Permission denied', "Permission denied");
2637 if (!defined $hash) {
2638 $hash = git_get_head_hash
($project);
2641 my $filename = basename
($project) . "-$hash.tar.$suffix";
2643 print $cgi->header(-type
=> 'application/x-tar',
2644 -content_encoding
=> $ctype,
2645 -content_disposition
=> "inline; filename=\"$filename\"",
2646 -status
=> '200 OK');
2648 open my $fd, "-|", "$GIT tar-tree $hash \'$project\' | $command" or
2649 die_error
(undef, "Execute git-tar-tree failed.");
2650 binmode STDOUT
, ':raw';
2652 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2658 my $head = git_get_head_hash
($project);
2659 if (!defined $hash) {
2662 if (!defined $page) {
2665 my $refs = git_get_references
();
2667 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2668 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2669 or die_error
(undef, "Open git-rev-list failed");
2670 my @revlist = map { chomp; $_ } <$fd>;
2673 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
2676 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
2679 my %co = parse_commit
($hash);
2681 git_print_header_div
('summary', $project);
2682 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
2684 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2685 my $commit = $revlist[$i];
2686 my $ref = format_ref_marker
($refs, $commit);
2687 my %co = parse_commit
($commit);
2689 my %ad = parse_date
($co{'author_epoch'});
2690 git_print_header_div
('commit',
2691 "<span class=\"age\">$co{'age_string'}</span>" .
2692 esc_html
($co{'title'}) . $ref,
2694 print "<div class=\"title_text\">\n" .
2695 "<div class=\"log_link\">\n" .
2696 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
2698 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
2701 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
2704 print "<div class=\"log_body\">\n";
2705 git_print_simplified_log
($co{'comment'});
2712 my %co = parse_commit
($hash);
2714 die_error
(undef, "Unknown commit object");
2716 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2717 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2719 my $parent = $co{'parent'};
2720 if (!defined $parent) {
2723 open my $fd, "-|", $GIT, "diff-tree", '-r', '-M', $parent, $hash
2724 or die_error
(undef, "Open git-diff-tree failed");
2725 my @difftree = map { chomp; $_ } <$fd>;
2726 close $fd or die_error
(undef, "Reading git-diff-tree failed");
2728 # non-textual hash id's can be cached
2730 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2733 my $refs = git_get_references
();
2734 my $ref = format_ref_marker
($refs, $co{'id'});
2736 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2737 my $have_snapshot = (defined $ctype && defined $suffix);
2739 my $formats_nav = '';
2740 if (defined $file_name && defined $co{'parent'}) {
2741 my $parent = $co{'parent'};
2743 $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)},
2746 git_header_html
(undef, $expires);
2747 git_print_page_nav
('commit', defined $co{'parent'} ?
'' : 'commitdiff',
2748 $hash, $co{'tree'}, $hash,
2751 if (defined $co{'parent'}) {
2752 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
2754 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
2756 print "<div class=\"title_text\">\n" .
2757 "<table cellspacing=\"0\">\n";
2758 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
2760 "<td></td><td> $ad{'rfc2822'}";
2761 if ($ad{'hour_local'} < 6) {
2762 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2763 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2765 printf(" (%02d:%02d %s)",
2766 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2770 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
2771 print "<tr><td></td><td> $cd{'rfc2822'}" .
2772 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
2774 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
2777 "<td class=\"sha1\">" .
2778 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
2779 class => "list"}, $co{'tree'}) .
2781 "<td class=\"link\">" .
2782 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
2784 if ($have_snapshot) {
2786 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
2790 my $parents = $co{'parents'};
2791 foreach my $par (@
$parents) {
2794 "<td class=\"sha1\">" .
2795 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
2796 class => "list"}, $par) .
2798 "<td class=\"link\">" .
2799 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
2801 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "commitdiff") .
2808 print "<div class=\"page_body\">\n";
2809 git_print_log
($co{'comment'});
2812 git_difftree_body
(\
@difftree, $hash, $parent);
2822 # preparing $fd and %diffinfo for git_patchset_body
2824 if (defined $hash_base && defined $hash_parent_base) {
2825 if (defined $file_name) {
2827 open $fd, "-|", $GIT, "diff-tree", '-r', '-M', '-C', $hash_parent_base, $hash_base,
2829 or die_error
(undef, "Open git-diff-tree failed");
2830 @difftree = map { chomp; $_ } <$fd>;
2832 or die_error
(undef, "Reading git-diff-tree failed");
2834 or die_error
('404 Not Found', "Blob diff not found");
2836 } elsif (defined $hash) { # try to find filename from $hash
2837 if ($hash !~ /[0-9a-fA-F]{40}/) {
2838 $hash = git_to_hash
($hash);
2841 # read filtered raw output
2842 open $fd, "-|", $GIT, "diff-tree", '-r', '-M', '-C', $hash_parent_base, $hash_base
2843 or die_error
(undef, "Open git-diff-tree failed");
2845 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
2847 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
2848 map { chomp; $_ } <$fd>;
2850 or die_error
(undef, "Reading git-diff-tree failed");
2852 or die_error
('404 Not Found', "Blob diff not found");
2855 die_error
('404 Not Found', "Missing one of the blob diff parameters");
2858 if (@difftree > 1) {
2859 die_error
('404 Not Found', "Ambiguous blob diff specification");
2862 %diffinfo = parse_difftree_raw_line
($difftree[0]);
2863 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
2864 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
2866 $hash_parent ||= $diffinfo{'from_id'};
2867 $hash ||= $diffinfo{'to_id'};
2870 open $fd, "-|", $GIT, "diff-tree", '-r', '-p', '-M', '-C', $hash_parent_base, $hash_base,
2872 or die_error
(undef, "Open git-diff-tree failed");
2875 # old/legacy style URI
2876 if (!%diffinfo && # if new style URI failed
2877 defined $hash && defined $hash_parent) {
2878 # fake git-diff-tree raw output
2879 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
2880 $diffinfo{'from_id'} = $hash_parent;
2881 $diffinfo{'to_id'} = $hash;
2882 if (defined $file_name) {
2883 if (defined $file_parent) {
2884 $diffinfo{'status'} = '2';
2885 $diffinfo{'from_file'} = $file_parent;
2886 $diffinfo{'to_file'} = $file_name;
2887 } else { # assume not renamed
2888 $diffinfo{'status'} = '1';
2889 $diffinfo{'from_file'} = $file_name;
2890 $diffinfo{'to_file'} = $file_name;
2892 } else { # no filename given
2893 $diffinfo{'status'} = '2';
2894 $diffinfo{'from_file'} = $hash_parent;
2895 $diffinfo{'to_file'} = $hash;
2898 #open $fd, "-|", $GIT, "diff", '-p', $hash_parent, $hash
2899 open $fd, "-|", $GIT, "diff", '-p', $hash, $hash_parent
2900 or die_error
(undef, "Open git-diff failed");
2902 die_error
('404 Not Found', "Missing one of the blob diff parameters")
2908 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
2909 hash
=>$hash, hash_parent
=>$hash_parent,
2910 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
2911 file_name
=>$file_name, file_parent
=>$file_parent)},
2914 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2915 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2916 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2918 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
2919 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
2921 if (defined $file_name) {
2922 git_print_page_path
($file_name, "blob", $hash_base);
2924 print "<div class=\"page_path\"></div>\n";
2928 print "<div class=\"page_body\">\n";
2930 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
2933 print "</div>\n"; # class="page_body"
2937 sub git_blobdiff_plain
{
2938 mkdir($git_temp, 0700);
2939 print $cgi->header(-type
=> "text/plain", -charset
=> 'utf-8');
2940 git_diff_print
($hash_parent, $file_name || $hash_parent, $hash, $file_name || $hash, "plain");
2943 sub git_commitdiff
{
2944 my $format = shift || 'html';
2945 my %co = parse_commit
($hash);
2947 die_error
(undef, "Unknown commit object");
2949 if (!defined $hash_parent) {
2950 $hash_parent = $co{'parent'} || '--root';
2956 if ($format eq 'html') {
2957 open $fd, "-|", $GIT, "diff-tree", '-r', '-M', '-C',
2958 "--patch-with-raw", "--full-index", $hash_parent, $hash
2959 or die_error
(undef, "Open git-diff-tree failed");
2961 while (chomp(my $line = <$fd>)) {
2962 # empty line ends raw part of diff-tree output
2964 push @difftree, $line;
2967 } elsif ($format eq 'plain') {
2968 open $fd, "-|", $GIT, "diff-tree", '-r', '-p', '-B', $hash_parent, $hash
2969 or die_error
(undef, "Open git-diff-tree failed");
2972 die_error
(undef, "Unknown commitdiff format");
2975 # non-textual hash id's can be cached
2977 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2981 # write commit message
2982 if ($format eq 'html') {
2983 my $refs = git_get_references
();
2984 my $ref = format_ref_marker
($refs, $co{'id'});
2986 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
2987 hash
=>$hash, hash_parent
=>$hash_parent)},
2990 git_header_html
(undef, $expires);
2991 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
2992 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
2993 print "<div class=\"page_body\">\n";
2994 print "<div class=\"log\">\n";
2995 git_print_simplified_log
($co{'comment'}, 1); # skip title
2996 print "</div>\n"; # class="log"
2998 } elsif ($format eq 'plain') {
2999 my $refs = git_get_references
("tags");
3000 my $tagname = git_get_rev_name_tags
($hash);
3001 my $filename = basename
($project) . "-$hash.patch";
3004 -type
=> 'text/plain',
3005 -charset
=> 'utf-8',
3006 -expires
=> $expires,
3007 -content_disposition
=> qq(inline
; filename
="$filename"));
3008 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3011 Date: $ad{'rfc2822'} ($ad{'tz_local'})
3012 Subject: $co{'title'}
3014 print "X-Git-Tag: $tagname\n" if $tagname;
3015 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3017 foreach my $line (@
{$co{'comment'}}) {
3024 if ($format eq 'html') {
3025 #git_difftree_body(\@difftree, $hash, $hash_parent);
3028 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
3030 print "</div>\n"; # class="page_body"
3033 } elsif ($format eq 'plain') {
3037 or print "Reading git-diff-tree failed\n";
3041 sub git_commitdiff_plain
{
3042 git_commitdiff
('plain');
3046 if (!defined $hash_base) {
3047 $hash_base = git_get_head_hash
($project);
3050 my %co = parse_commit
($hash_base);
3052 die_error
(undef, "Unknown commit object");
3054 my $refs = git_get_references
();
3056 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base);
3057 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3058 if (!defined $hash && defined $file_name) {
3059 $hash = git_get_hash_by_path
($hash_base, $file_name);
3061 if (defined $hash) {
3062 $ftype = git_get_type
($hash);
3064 git_print_page_path
($file_name, $ftype, $hash_base);
3067 $GIT, "rev-list", "--full-history", $hash_base, "--", $file_name;
3068 git_history_body
($fd, $refs, $hash_base, $ftype);
3075 if (!defined $searchtext) {
3076 die_error
(undef, "Text field empty");
3078 if (!defined $hash) {
3079 $hash = git_get_head_hash
($project);
3081 my %co = parse_commit
($hash);
3083 die_error
(undef, "Unknown commit object");
3085 # pickaxe may take all resources of your box and run for several minutes
3086 # with every query - so decide by yourself how public you make this feature :)
3087 my $commit_search = 1;
3088 my $author_search = 0;
3089 my $committer_search = 0;
3090 my $pickaxe_search = 0;
3091 if ($searchtext =~ s/^author\\://i) {
3093 } elsif ($searchtext =~ s/^committer\\://i) {
3094 $committer_search = 1;
3095 } elsif ($searchtext =~ s/^pickaxe\\://i) {
3097 $pickaxe_search = 1;
3100 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
3101 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
3103 print "<table cellspacing=\"0\">\n";
3105 if ($commit_search) {
3107 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", $hash or next;
3108 while (my $commit_text = <$fd>) {
3109 if (!grep m/$searchtext/i, $commit_text) {
3112 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3115 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3118 my @commit_lines = split "\n", $commit_text;
3119 my %co = parse_commit
(undef, \
@commit_lines);
3124 print "<tr class=\"dark\">\n";
3126 print "<tr class=\"light\">\n";
3129 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3130 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3132 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3133 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3134 my $comment = $co{'comment'};
3135 foreach my $line (@
$comment) {
3136 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3137 my $lead = esc_html
($1) || "";
3138 $lead = chop_str
($lead, 30, 10);
3139 my $match = esc_html
($2) || "";
3140 my $trail = esc_html
($3) || "";
3141 $trail = chop_str
($trail, 30, 10);
3142 my $text = "$lead<span class=\"match\">$match</span>$trail";
3143 print chop_str
($text, 80, 5) . "<br/>\n";
3147 "<td class=\"link\">" .
3148 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3150 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3157 if ($pickaxe_search) {
3159 open my $fd, "-|", "$GIT rev-list $hash | $GIT diff-tree -r --stdin -S\'$searchtext\'";
3162 while (my $line = <$fd>) {
3163 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
3166 $set{'from_id'} = $3;
3168 $set{'id'} = $set{'to_id'};
3169 if ($set{'id'} =~ m/0{40}/) {
3170 $set{'id'} = $set{'from_id'};
3172 if ($set{'id'} =~ m/0{40}/) {
3176 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
3179 print "<tr class=\"dark\">\n";
3181 print "<tr class=\"light\">\n";
3184 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3185 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3187 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3188 -class => "list subject"},
3189 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3190 while (my $setref = shift @files) {
3192 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
3193 hash
=>$set{'id'}, file_name
=>$set{'file'}),
3195 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
3199 "<td class=\"link\">" .
3200 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3202 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3206 %co = parse_commit
($1);
3216 my $head = git_get_head_hash
($project);
3217 if (!defined $hash) {
3220 if (!defined $page) {
3223 my $refs = git_get_references
();
3225 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3226 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
3227 or die_error
(undef, "Open git-rev-list failed");
3228 my @revlist = map { chomp; $_ } <$fd>;
3231 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
3233 if ($#revlist >= (100 * ($page+1)-1)) {
3235 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
3236 -title
=> "Alt-n"}, "next");
3241 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
3242 git_print_header_div
('summary', $project);
3244 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
3249 ## ......................................................................
3250 ## feeds (RSS, OPML)
3253 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
3254 open my $fd, "-|", $GIT, "rev-list", "--max-count=150", git_get_head_hash
($project)
3255 or die_error
(undef, "Open git-rev-list failed");
3256 my @revlist = map { chomp; $_ } <$fd>;
3257 close $fd or die_error
(undef, "Reading git-rev-list failed");
3258 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3260 <?xml version="1.0" encoding="utf-8"?>
3261 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
3263 <title>$project $my_uri $my_url</title>
3264 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
3265 <description>$project log</description>
3266 <language>en</language>
3269 for (my $i = 0; $i <= $#revlist; $i++) {
3270 my $commit = $revlist[$i];
3271 my %co = parse_commit
($commit);
3272 # we read 150, we always show 30 and the ones more recent than 48 hours
3273 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
3276 my %cd = parse_date
($co{'committer_epoch'});
3277 open $fd, "-|", $GIT, "diff-tree", '-r', $co{'parent'}, $co{'id'} or next;
3278 my @difftree = map { chomp; $_ } <$fd>;
3282 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
3284 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
3285 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
3286 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
3287 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
3288 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
3289 "<content:encoded>" .
3291 my $comment = $co{'comment'};
3292 foreach my $line (@
$comment) {
3293 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
3294 print "$line<br/>\n";
3297 foreach my $line (@difftree) {
3298 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3301 my $file = validate_input
(unquote
($7));
3302 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
3303 print "$file<br/>\n";
3306 "</content:encoded>\n" .
3309 print "</channel></rss>";
3313 my @list = git_get_projects_list
();
3315 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3317 <?xml version="1.0" encoding="utf-8"?>
3318 <opml version="1.0">
3320 <title>$site_name Git OPML Export</title>
3323 <outline text="git RSS feeds">
3326 foreach my $pr (@list) {
3328 my $head = git_get_head_hash
($proj{'path'});
3329 if (!defined $head) {
3332 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
3333 my %co = parse_commit
($head);
3338 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
3339 my $rss = "$my_url?p=$proj{'path'};a=rss";
3340 my $html = "$my_url?p=$proj{'path'};a=summary";
3341 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";