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 # target of the home link on top of all pages
35 our $home_link = $my_uri || "/";
37 # string of the home link on top of all pages
38 our $home_link_str = "++GITWEB_HOME_LINK_STR++";
40 # name of your site or organization to appear in page titles
41 # replace this with something more descriptive for clearer bookmarks
42 our $site_name = "++GITWEB_SITENAME++" || $ENV{'SERVER_NAME'} || "Untitled";
44 # html text to include at home page
45 our $home_text = "++GITWEB_HOMETEXT++";
47 # URI of default stylesheet
48 our $stylesheet = "++GITWEB_CSS++";
50 our $logo = "++GITWEB_LOGO++";
51 # URI of GIT favicon, assumed to be image/png type
52 our $favicon = "++GITWEB_FAVICON++";
54 # source of projects list
55 our $projects_list = "++GITWEB_LIST++";
57 # list of git base URLs used for URL to where fetch project from,
58 # i.e. full URL is "$git_base_url/$project"
59 our @git_base_url_list = ("++GITWEB_BASE_URL++");
61 # default blob_plain mimetype and default charset for text/plain blob
62 our $default_blob_plain_mimetype = 'text/plain';
63 our $default_text_plain_charset = undef;
65 # file to use for guessing MIME types before trying /etc/mime.types
66 # (relative to the current git repository)
67 our $mimetypes_file = undef;
69 # You define site-wide feature defaults here; override them with
70 # $GITWEB_CONFIG as necessary.
73 # 'sub' => feature-sub (subroutine),
74 # 'override' => allow-override (boolean),
75 # 'default' => [ default options...] (array reference)}
77 # if feature is overridable (it means that allow-override has true value,
78 # then feature-sub will be called with default options as parameters;
79 # return value of feature-sub indicates if to enable specified feature,
80 # and is taken to be current parameters of the feature
82 # use gitweb_check_feature(<feature>) to check if <feature> is enabled;
83 # to be more exact to get current parameters of <feature>;
84 # gitweb_check_feature(<feature>) returns array (list) of current options
87 'sub' => \
&feature_blame
,
92 'sub' => \
&feature_snapshot
,
94 # => [content-encoding, suffix, program]
95 'default' => ['x-gzip', 'gz', 'gzip']},
98 sub gitweb_check_feature
{
100 return undef unless exists $feature{$name};
101 my ($sub, $override, @defaults) = (
102 $feature{$name}{'sub'},
103 $feature{$name}{'override'},
104 @
{$feature{$name}{'default'}});
105 if (!$override) { return @defaults; }
106 return $sub->(@defaults);
109 # To enable system wide have in $GITWEB_CONFIG
110 # $feature{'blame'}{'default'} = [1];
111 # To have project specific config enable override in $GITWEB_CONFIG
112 # $feature{'blame'}{'override'} = 1;
113 # and in project config gitweb.blame = 0|1;
116 my ($val) = git_get_project_config
('blame', '--bool');
118 if ($val eq 'true') {
120 } elsif ($val eq 'false') {
127 # To disable system wide have in $GITWEB_CONFIG
128 # $feature{'snapshot'}{'default'} = [undef];
129 # To have project specific config enable override in $GITWEB_CONFIG
130 # $feature{'blame'}{'override'} = 1;
131 # and in project config gitweb.snapshot = none|gzip|bzip2
133 sub feature_snapshot
{
134 my ($ctype, $suffix, $command) = @_;
136 my ($val) = git_get_project_config
('snapshot');
138 if ($val eq 'gzip') {
139 return ('x-gzip', 'gz', 'gzip');
140 } elsif ($val eq 'bzip2') {
141 return ('x-bzip2', 'bz2', 'bzip2');
142 } elsif ($val eq 'none') {
146 return ($ctype, $suffix, $command);
149 # rename detection options for git-diff and git-diff-tree
150 # - default is '-M', with the cost proportional to
151 # (number of removed files) * (number of new files).
152 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
153 # (number of changed files + number of removed files) * (number of new files)
154 # - even more costly is '-C', '--find-copies-harder' with cost
155 # (number of files in the original tree) * (number of new files)
156 # - one might want to include '-B' option, e.g. '-B', '-M'
157 our @diff_opts = ('-M'); # taken from git_commit
159 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
160 require $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
162 # version of the core git binary
163 our $git_version = qx($GIT --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
165 $projects_list ||= $projectroot;
167 # ======================================================================
168 # input validation and dispatch
169 our $action = $cgi->param('a');
170 if (defined $action) {
171 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
172 die_error
(undef, "Invalid action parameter");
176 our $project = ($cgi->param('p') || $ENV{'PATH_INFO'});
177 if (defined $project) {
180 $project = undef unless $project;
182 if (defined $project) {
183 if (!validate_input
($project)) {
184 die_error
(undef, "Invalid project parameter");
186 if (!(-d
"$projectroot/$project")) {
187 die_error
(undef, "No such directory");
189 if (!(-e
"$projectroot/$project/HEAD")) {
190 die_error
(undef, "No such project");
192 $ENV{'GIT_DIR'} = "$projectroot/$project";
195 our $file_name = $cgi->param('f');
196 if (defined $file_name) {
197 if (!validate_input
($file_name)) {
198 die_error
(undef, "Invalid file parameter");
202 our $file_parent = $cgi->param('fp');
203 if (defined $file_parent) {
204 if (!validate_input
($file_parent)) {
205 die_error
(undef, "Invalid file parent parameter");
209 our $hash = $cgi->param('h');
211 if (!validate_input
($hash)) {
212 die_error
(undef, "Invalid hash parameter");
216 our $hash_parent = $cgi->param('hp');
217 if (defined $hash_parent) {
218 if (!validate_input
($hash_parent)) {
219 die_error
(undef, "Invalid hash parent parameter");
223 our $hash_base = $cgi->param('hb');
224 if (defined $hash_base) {
225 if (!validate_input
($hash_base)) {
226 die_error
(undef, "Invalid hash base parameter");
230 our $hash_parent_base = $cgi->param('hpb');
231 if (defined $hash_parent_base) {
232 if (!validate_input
($hash_parent_base)) {
233 die_error
(undef, "Invalid hash parent base parameter");
237 our $page = $cgi->param('pg');
239 if ($page =~ m/[^0-9]$/) {
240 die_error
(undef, "Invalid page parameter");
244 our $searchtext = $cgi->param('s');
245 if (defined $searchtext) {
246 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
247 die_error
(undef, "Invalid search parameter");
249 $searchtext = quotemeta $searchtext;
254 "blame" => \
&git_blame2
,
255 "blobdiff" => \
&git_blobdiff
,
256 "blobdiff_plain" => \
&git_blobdiff_plain
,
257 "blob" => \
&git_blob
,
258 "blob_plain" => \
&git_blob_plain
,
259 "commitdiff" => \
&git_commitdiff
,
260 "commitdiff_plain" => \
&git_commitdiff_plain
,
261 "commit" => \
&git_commit
,
262 "heads" => \
&git_heads
,
263 "history" => \
&git_history
,
266 "search" => \
&git_search
,
267 "shortlog" => \
&git_shortlog
,
268 "summary" => \
&git_summary
,
270 "tags" => \
&git_tags
,
271 "tree" => \
&git_tree
,
272 "snapshot" => \
&git_snapshot
,
273 # those below don't need $project
274 "opml" => \
&git_opml
,
275 "project_list" => \
&git_project_list
,
276 "project_index" => \
&git_project_index
,
279 if (defined $project) {
280 $action ||= 'summary';
282 $action ||= 'project_list';
284 if (!defined($actions{$action})) {
285 die_error
(undef, "Unknown action");
287 $actions{$action}->();
290 ## ======================================================================
304 hash_parent_base
=> "hpb",
308 my %mapping = @mapping;
310 $params{"project"} ||= $project;
313 for (my $i = 0; $i < @mapping; $i += 2) {
314 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
315 if (defined $params{$name}) {
316 push @result, $symbol . "=" . esc_param
($params{$name});
319 return "$my_uri?" . join(';', @result);
323 ## ======================================================================
324 ## validation, quoting/unquoting and escaping
329 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
332 if ($input =~ m/(^|\/)(|\
.|\
.\
.)($|\
/)/) {
335 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\
-\
+\#\
~\
%]/) {
341 # quote unsafe chars, but keep the slash, even when it's not
342 # correct, but quoted slashes look too horrible in bookmarks
345 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
351 # replace invalid utf8 character with SUBSTITUTION sequence
354 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
355 $str = escapeHTML
($str);
356 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
360 # git may return quoted and escaped filenames
363 if ($str =~ m/^"(.*)"$/) {
365 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
370 # escape tabs (convert tabs to spaces)
374 while ((my $pos = index($line, "\t")) != -1) {
375 if (my $count = (8 - ($pos % 8))) {
376 my $spaces = ' ' x
$count;
377 $line =~ s/\t/$spaces/;
384 ## ----------------------------------------------------------------------
385 ## HTML aware string manipulation
390 my $add_len = shift || 10;
392 # allow only $len chars, but don't cut a word if it would fit in $add_len
393 # if it doesn't fit, cut it if it's still longer than the dots we would add
394 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
397 if (length($tail) > 4) {
399 $body =~ s/&[^;]*$//; # remove chopped character entities
404 ## ----------------------------------------------------------------------
405 ## functions returning short strings
407 # CSS class for given age value (in seconds)
411 if ($age < 60*60*2) {
413 } elsif ($age < 60*60*24*2) {
420 # convert age in seconds to "nn units ago" string
425 if ($age > 60*60*24*365*2) {
426 $age_str = (int $age/60/60/24/365);
427 $age_str .= " years ago";
428 } elsif ($age > 60*60*24*(365/12)*2) {
429 $age_str = int $age/60/60/24/(365/12);
430 $age_str .= " months ago";
431 } elsif ($age > 60*60*24*7*2) {
432 $age_str = int $age/60/60/24/7;
433 $age_str .= " weeks ago";
434 } elsif ($age > 60*60*24*2) {
435 $age_str = int $age/60/60/24;
436 $age_str .= " days ago";
437 } elsif ($age > 60*60*2) {
438 $age_str = int $age/60/60;
439 $age_str .= " hours ago";
440 } elsif ($age > 60*2) {
441 $age_str = int $age/60;
442 $age_str .= " min ago";
445 $age_str .= " sec ago";
447 $age_str .= " right now";
452 # convert file mode in octal to symbolic file mode string
454 my $mode = oct shift;
456 if (S_ISDIR
($mode & S_IFMT
)) {
458 } elsif (S_ISLNK
($mode)) {
460 } elsif (S_ISREG
($mode)) {
461 # git cares only about the executable bit
462 if ($mode & S_IXUSR
) {
472 # convert file mode in octal to file type string
476 if ($mode !~ m/^[0-7]+$/) {
482 if (S_ISDIR
($mode & S_IFMT
)) {
484 } elsif (S_ISLNK
($mode)) {
486 } elsif (S_ISREG
($mode)) {
493 ## ----------------------------------------------------------------------
494 ## functions returning short HTML fragments, or transforming HTML fragments
495 ## which don't beling to other sections
497 # format line of commit message or tag comment
498 sub format_log_line_html
{
501 $line = esc_html
($line);
502 $line =~ s/ / /g;
503 if ($line =~ m/([0-9a-fA-F]{40})/) {
505 if (git_get_type
($hash_text) eq "commit") {
507 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$hash_text),
508 -class => "text"}, $hash_text);
509 $line =~ s/$hash_text/$link/;
515 # format marker of refs pointing to given object
516 sub format_ref_marker
{
517 my ($refs, $id) = @_;
520 if (defined $refs->{$id}) {
521 foreach my $ref (@
{$refs->{$id}}) {
522 my ($type, $name) = qw();
523 # e.g. tags/v2.6.11 or heads/next
524 if ($ref =~ m!^(.*?)s?/(.*)$!) {
532 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
537 return ' <span class="refs">'. $markers . '</span>';
543 # format, perhaps shortened and with markers, title line
544 sub format_subject_html
{
545 my ($long, $short, $href, $extra) = @_;
546 $extra = '' unless defined($extra);
548 if (length($short) < length($long)) {
549 return $cgi->a({-href
=> $href, -class => "list subject",
551 esc_html
($short) . $extra);
553 return $cgi->a({-href
=> $href, -class => "list subject"},
554 esc_html
($long) . $extra);
558 sub format_diff_line
{
560 my $char = substr($line, 0, 1);
566 $diff_class = " add";
567 } elsif ($char eq "-") {
568 $diff_class = " rem";
569 } elsif ($char eq "@") {
570 $diff_class = " chunk_header";
571 } elsif ($char eq "\\") {
572 $diff_class = " incomplete";
574 $line = untabify
($line);
575 return "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
578 ## ----------------------------------------------------------------------
579 ## git utility subroutines, invoking git commands
581 # get HEAD ref of given project as hash
582 sub git_get_head_hash
{
584 my $oENV = $ENV{'GIT_DIR'};
586 $ENV{'GIT_DIR'} = "$projectroot/$project";
587 if (open my $fd, "-|", $GIT, "rev-parse", "--verify", "HEAD") {
590 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
595 $ENV{'GIT_DIR'} = $oENV;
600 # get type of given object
604 open my $fd, "-|", $GIT, "cat-file", '-t', $hash or return;
611 sub git_get_project_config
{
612 my ($key, $type) = @_;
614 return unless ($key);
615 $key =~ s/^gitweb\.//;
616 return if ($key =~ m/\W/);
618 my @x = ($GIT, 'repo-config');
619 if (defined $type) { push @x, $type; }
621 push @x, "gitweb.$key";
627 # get hash of given path at given ref
628 sub git_get_hash_by_path
{
630 my $path = shift || return undef;
634 open my $fd, "-|", $GIT, "ls-tree", $base, "--", $path
635 or die_error
(undef, "Open git-ls-tree failed");
637 close $fd or return undef;
639 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
640 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
644 ## ......................................................................
645 ## git utility functions, directly accessing git repository
647 # assumes that PATH is not symref
648 sub git_get_hash_by_ref
{
651 open my $fd, "$projectroot/$path" or return undef;
655 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
660 sub git_get_project_description
{
663 open my $fd, "$projectroot/$path/description" or return undef;
670 sub git_get_project_url_list
{
673 open my $fd, "$projectroot/$path/cloneurl" or return undef;
674 my @git_project_url_list = map { chomp; $_ } <$fd>;
677 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
680 sub git_get_projects_list
{
683 if (-d
$projects_list) {
684 # search in directory
685 my $dir = $projects_list;
686 opendir my ($dh), $dir or return undef;
687 while (my $dir = readdir($dh)) {
688 if (-e
"$projectroot/$dir/HEAD") {
696 } elsif (-f
$projects_list) {
697 # read from file(url-encoded):
698 # 'git%2Fgit.git Linus+Torvalds'
699 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
700 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
701 open my ($fd), $projects_list or return undef;
702 while (my $line = <$fd>) {
704 my ($path, $owner) = split ' ', $line;
705 $path = unescape
($path);
706 $owner = unescape
($owner);
707 if (!defined $path) {
710 if (-e
"$projectroot/$path/HEAD") {
713 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
720 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
724 sub git_get_project_owner
{
728 return undef unless $project;
730 # read from file (url-encoded):
731 # 'git%2Fgit.git Linus+Torvalds'
732 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
733 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
734 if (-f
$projects_list) {
735 open (my $fd , $projects_list);
736 while (my $line = <$fd>) {
738 my ($pr, $ow) = split ' ', $line;
741 if ($pr eq $project) {
742 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
748 if (!defined $owner) {
749 $owner = get_file_owner
("$projectroot/$project");
755 sub git_get_references
{
756 my $type = shift || "";
759 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
760 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
761 if (-f
"$projectroot/$project/info/refs") {
762 open $fd, "$projectroot/$project/info/refs"
765 open $fd, "-|", $GIT, "ls-remote", "."
769 while (my $line = <$fd>) {
771 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?[^\^]+)/) {
772 if (defined $refs{$1}) {
773 push @
{$refs{$1}}, $2;
783 sub git_get_rev_name_tags
{
784 my $hash = shift || return undef;
786 open my $fd, "-|", $GIT, "name-rev", "--tags", $hash
788 my $name_rev = <$fd>;
791 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
794 # catches also '$hash undefined' output
799 ## ----------------------------------------------------------------------
800 ## parse to hash functions
804 my $tz = shift || "-0000";
807 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
808 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
809 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
810 $date{'hour'} = $hour;
811 $date{'minute'} = $min;
812 $date{'mday'} = $mday;
813 $date{'day'} = $days[$wday];
814 $date{'month'} = $months[$mon];
815 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
816 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
817 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
818 $mday, $months[$mon], $hour ,$min;
820 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
821 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
822 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
823 $date{'hour_local'} = $hour;
824 $date{'minute_local'} = $min;
825 $date{'tz_local'} = $tz;
834 open my $fd, "-|", $GIT, "cat-file", "tag", $tag_id or return;
835 $tag{'id'} = $tag_id;
836 while (my $line = <$fd>) {
838 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
840 } elsif ($line =~ m/^type (.+)$/) {
842 } elsif ($line =~ m/^tag (.+)$/) {
844 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
848 } elsif ($line =~ m/--BEGIN/) {
849 push @comment, $line;
851 } elsif ($line eq "") {
855 push @comment, <$fd>;
856 $tag{'comment'} = \
@comment;
858 if (!defined $tag{'name'}) {
865 my $commit_id = shift;
866 my $commit_text = shift;
871 if (defined $commit_text) {
872 @commit_lines = @
$commit_text;
875 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", "--max-count=1", $commit_id
877 @commit_lines = split '\n', <$fd>;
882 my $header = shift @commit_lines;
883 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
886 ($co{'id'}, my @parents) = split ' ', $header;
887 $co{'parents'} = \
@parents;
888 $co{'parent'} = $parents[0];
889 while (my $line = shift @commit_lines) {
890 last if $line eq "\n";
891 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
893 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
895 $co{'author_epoch'} = $2;
896 $co{'author_tz'} = $3;
897 if ($co{'author'} =~ m/^([^<]+) </) {
898 $co{'author_name'} = $1;
900 $co{'author_name'} = $co{'author'};
902 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
903 $co{'committer'} = $1;
904 $co{'committer_epoch'} = $2;
905 $co{'committer_tz'} = $3;
906 $co{'committer_name'} = $co{'committer'};
907 $co{'committer_name'} =~ s/ <.*//;
910 if (!defined $co{'tree'}) {
914 foreach my $title (@commit_lines) {
917 $co{'title'} = chop_str
($title, 80, 5);
918 # remove leading stuff of merges to make the interesting part visible
919 if (length($title) > 50) {
920 $title =~ s/^Automatic //;
921 $title =~ s/^merge (of|with) /Merge ... /i;
922 if (length($title) > 50) {
923 $title =~ s/(http|rsync):\/\///;
925 if (length($title) > 50) {
926 $title =~ s/(master|www|rsync)\.//;
928 if (length($title) > 50) {
929 $title =~ s/kernel.org:?//;
931 if (length($title) > 50) {
932 $title =~ s/\/pub\/scm//;
935 $co{'title_short'} = chop_str
($title, 50, 5);
939 # remove added spaces
940 foreach my $line (@commit_lines) {
943 $co{'comment'} = \
@commit_lines;
945 my $age = time - $co{'committer_epoch'};
947 $co{'age_string'} = age_string
($age);
948 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
949 if ($age > 60*60*24*7*2) {
950 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
951 $co{'age_string_age'} = $co{'age_string'};
953 $co{'age_string_date'} = $co{'age_string'};
954 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
959 # parse ref from ref_file, given by ref_id, with given type
961 my $ref_file = shift;
963 my $type = shift || git_get_type
($ref_id);
966 $ref_item{'type'} = $type;
967 $ref_item{'id'} = $ref_id;
968 $ref_item{'epoch'} = 0;
969 $ref_item{'age'} = "unknown";
970 if ($type eq "tag") {
971 my %tag = parse_tag
($ref_id);
972 $ref_item{'comment'} = $tag{'comment'};
973 if ($tag{'type'} eq "commit") {
974 my %co = parse_commit
($tag{'object'});
975 $ref_item{'epoch'} = $co{'committer_epoch'};
976 $ref_item{'age'} = $co{'age_string'};
977 } elsif (defined($tag{'epoch'})) {
978 my $age = time - $tag{'epoch'};
979 $ref_item{'epoch'} = $tag{'epoch'};
980 $ref_item{'age'} = age_string
($age);
982 $ref_item{'reftype'} = $tag{'type'};
983 $ref_item{'name'} = $tag{'name'};
984 $ref_item{'refid'} = $tag{'object'};
985 } elsif ($type eq "commit"){
986 my %co = parse_commit
($ref_id);
987 $ref_item{'reftype'} = "commit";
988 $ref_item{'name'} = $ref_file;
989 $ref_item{'title'} = $co{'title'};
990 $ref_item{'refid'} = $ref_id;
991 $ref_item{'epoch'} = $co{'committer_epoch'};
992 $ref_item{'age'} = $co{'age_string'};
994 $ref_item{'reftype'} = $type;
995 $ref_item{'name'} = $ref_file;
996 $ref_item{'refid'} = $ref_id;
1002 # parse line of git-diff-tree "raw" output
1003 sub parse_difftree_raw_line
{
1007 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1008 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1009 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1010 $res{'from_mode'} = $1;
1011 $res{'to_mode'} = $2;
1012 $res{'from_id'} = $3;
1014 $res{'status'} = $5;
1015 $res{'similarity'} = $6;
1016 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1017 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1019 $res{'file'} = unquote
($7);
1022 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1023 #elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1024 # $res{'commit'} = $1;
1027 return wantarray ?
%res : \
%res;
1030 ## ......................................................................
1031 ## parse to array of hashes functions
1033 sub git_get_refs_list
{
1034 my $ref_dir = shift;
1038 my $pfxlen = length("$projectroot/$project/$ref_dir");
1039 File
::Find
::find
(sub {
1042 push @refs, substr($File::Find
::name
, $pfxlen + 1);
1044 }, "$projectroot/$project/$ref_dir");
1046 foreach my $ref_file (@refs) {
1047 my $ref_id = git_get_hash_by_ref
("$project/$ref_dir/$ref_file");
1048 my $type = git_get_type
($ref_id) || next;
1049 my %ref_item = parse_ref
($ref_file, $ref_id, $type);
1051 push @reflist, \
%ref_item;
1054 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1058 ## ----------------------------------------------------------------------
1059 ## filesystem-related functions
1061 sub get_file_owner
{
1064 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1065 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1066 if (!defined $gcos) {
1070 $owner =~ s/[,;].*$//;
1071 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
1074 ## ......................................................................
1075 ## mimetype related functions
1077 sub mimetype_guess_file
{
1078 my $filename = shift;
1079 my $mimemap = shift;
1080 -r
$mimemap or return undef;
1083 open(MIME
, $mimemap) or return undef;
1085 next if m/^#/; # skip comments
1086 my ($mime, $exts) = split(/\t+/);
1087 if (defined $exts) {
1088 my @exts = split(/\s+/, $exts);
1089 foreach my $ext (@exts) {
1090 $mimemap{$ext} = $mime;
1096 $filename =~ /\.(.*?)$/;
1097 return $mimemap{$1};
1100 sub mimetype_guess
{
1101 my $filename = shift;
1103 $filename =~ /\./ or return undef;
1105 if ($mimetypes_file) {
1106 my $file = $mimetypes_file;
1107 if ($file !~ m!^/!) { # if it is relative path
1108 # it is relative to project
1109 $file = "$projectroot/$project/$file";
1111 $mime = mimetype_guess_file
($filename, $file);
1113 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1119 my $filename = shift;
1122 my $mime = mimetype_guess
($filename);
1123 $mime and return $mime;
1127 return $default_blob_plain_mimetype unless $fd;
1130 return 'text/plain' .
1131 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
1132 } elsif (! $filename) {
1133 return 'application/octet-stream';
1134 } elsif ($filename =~ m/\.png$/i) {
1136 } elsif ($filename =~ m/\.gif$/i) {
1138 } elsif ($filename =~ m/\.jpe?g$/i) {
1139 return 'image/jpeg';
1141 return 'application/octet-stream';
1145 ## ======================================================================
1146 ## functions printing HTML: header, footer, error page
1148 sub git_header_html
{
1149 my $status = shift || "200 OK";
1150 my $expires = shift;
1152 my $title = "$site_name git";
1153 if (defined $project) {
1154 $title .= " - $project";
1155 if (defined $action) {
1156 $title .= "/$action";
1157 if (defined $file_name) {
1158 $title .= " - $file_name";
1159 if ($action eq "tree" && $file_name !~ m
|/$|) {
1166 # require explicit support from the UA if we are to send the page as
1167 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1168 # we have to do this because MSIE sometimes globs '*/*', pretending to
1169 # support xhtml+xml but choking when it gets what it asked for.
1170 if (defined $cgi->http('HTTP_ACCEPT') &&
1171 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1172 $cgi->Accept('application/xhtml+xml') != 0) {
1173 $content_type = 'application/xhtml+xml';
1175 $content_type = 'text/html';
1177 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1178 -status
=> $status, -expires
=> $expires);
1180 <?xml version="1.0" encoding="utf-8"?>
1181 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1182 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1183 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1184 <!-- git core binaries version $git_version -->
1186 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1187 <meta name="generator" content="gitweb/$version git/$git_version"/>
1188 <meta name="robots" content="index, nofollow"/>
1189 <title>$title</title>
1190 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
1192 if (defined $project) {
1193 printf('<link rel="alternate" title="%s log" '.
1194 'href="%s" type="application/rss+xml"/>'."\n",
1195 esc_param
($project), href
(action
=>"rss"));
1197 if (defined $favicon) {
1198 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png"/>\n);
1203 "<div class=\"page_header\">\n" .
1204 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
1205 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
1207 print $cgi->a({-href
=> esc_param
($home_link)}, $home_link_str) . " / ";
1208 if (defined $project) {
1209 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1210 if (defined $action) {
1214 if (!defined $searchtext) {
1218 if (defined $hash_base) {
1219 $search_hash = $hash_base;
1220 } elsif (defined $hash) {
1221 $search_hash = $hash;
1223 $search_hash = "HEAD";
1225 $cgi->param("a", "search");
1226 $cgi->param("h", $search_hash);
1227 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
1228 "<div class=\"search\">\n" .
1229 $cgi->hidden(-name
=> "p") . "\n" .
1230 $cgi->hidden(-name
=> "a") . "\n" .
1231 $cgi->hidden(-name
=> "h") . "\n" .
1232 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1234 $cgi->end_form() . "\n";
1239 sub git_footer_html
{
1240 print "<div class=\"page_footer\">\n";
1241 if (defined $project) {
1242 my $descr = git_get_project_description
($project);
1243 if (defined $descr) {
1244 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1246 print $cgi->a({-href
=> href
(action
=>"rss"), -class => "rss_logo"}, "RSS") . "\n";
1248 print $cgi->a({-href
=> href
(action
=>"opml"), -class => "rss_logo"}, "OPML") . "\n";
1256 my $status = shift || "403 Forbidden";
1257 my $error = shift || "Malformed query, file missing or permission denied";
1259 git_header_html
($status);
1261 <div class="page_body">
1271 ## ----------------------------------------------------------------------
1272 ## functions printing or outputting HTML: navigation
1274 sub git_print_page_nav
{
1275 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1276 $extra = '' if !defined $extra; # pager or formats
1278 my @navs = qw(summary shortlog log commit commitdiff tree);
1280 @navs = grep { $_ ne $suppress } @navs;
1283 my %arg = map { $_ => {action
=>$_} } @navs;
1284 if (defined $head) {
1285 for (qw(commit commitdiff)) {
1286 $arg{$_}{hash
} = $head;
1288 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1289 for (qw(shortlog log)) {
1290 $arg{$_}{hash
} = $head;
1294 $arg{tree
}{hash
} = $treehead if defined $treehead;
1295 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1297 print "<div class=\"page_nav\">\n" .
1299 map { $_ eq $current ?
1300 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1302 print "<br/>\n$extra<br/>\n" .
1306 sub format_paging_nav
{
1307 my ($action, $hash, $head, $page, $nrevs) = @_;
1311 if ($hash ne $head || $page) {
1312 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1314 $paging_nav .= "HEAD";
1318 $paging_nav .= " ⋅ " .
1319 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1320 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1322 $paging_nav .= " ⋅ prev";
1325 if ($nrevs >= (100 * ($page+1)-1)) {
1326 $paging_nav .= " ⋅ " .
1327 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1328 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1330 $paging_nav .= " ⋅ next";
1336 ## ......................................................................
1337 ## functions printing or outputting HTML: div
1339 sub git_print_header_div
{
1340 my ($action, $title, $hash, $hash_base) = @_;
1343 $args{action
} = $action;
1344 $args{hash
} = $hash if $hash;
1345 $args{hash_base
} = $hash_base if $hash_base;
1347 print "<div class=\"header\">\n" .
1348 $cgi->a({-href
=> href
(%args), -class => "title"},
1349 $title ?
$title : $action) .
1353 #sub git_print_authorship (\%) {
1354 sub git_print_authorship
{
1357 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
1358 print "<div class=\"author_date\">" .
1359 esc_html
($co->{'author_name'}) .
1361 if ($ad{'hour_local'} < 6) {
1362 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1363 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1365 printf(" (%02d:%02d %s)",
1366 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1371 sub git_print_page_path
{
1376 if (!defined $name) {
1377 print "<div class=\"page_path\">/</div>\n";
1379 my @dirname = split '/', $name;
1380 my $basename = pop @dirname;
1383 print "<div class=\"page_path\">";
1384 foreach my $dir (@dirname) {
1385 $fullname .= $dir . '/';
1386 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
1388 -title
=> $fullname}, esc_html
($dir));
1391 if (defined $type && $type eq 'blob') {
1392 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1394 -title
=> $name}, esc_html
($basename));
1395 } elsif (defined $type && $type eq 'tree') {
1396 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
1398 -title
=> $name}, esc_html
($basename));
1401 print esc_html
($basename);
1403 print "<br/></div>\n";
1407 # sub git_print_log (\@;%) {
1408 sub git_print_log
($;%) {
1412 if ($opts{'-remove_title'}) {
1413 # remove title, i.e. first line of log
1416 # remove leading empty lines
1417 while (defined $log->[0] && $log->[0] eq "") {
1424 foreach my $line (@
$log) {
1425 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1428 if (! $opts{'-remove_signoff'}) {
1429 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1432 # remove signoff lines
1439 # print only one empty line
1440 # do not print empty line after signoff
1442 next if ($empty || $signoff);
1448 print format_log_line_html
($line) . "<br/>\n";
1451 if ($opts{'-final_empty_line'}) {
1452 # end with single empty line
1453 print "<br/>\n" unless $empty;
1457 sub git_print_simplified_log
{
1459 my $remove_title = shift;
1462 -final_empty_line
=> 1,
1463 -remove_title
=> $remove_title);
1466 ## ......................................................................
1467 ## functions printing large fragments of HTML
1469 sub git_difftree_body
{
1470 my ($difftree, $hash, $parent) = @_;
1472 print "<div class=\"list_head\">\n";
1473 if ($#{$difftree} > 10) {
1474 print(($#{$difftree} + 1) . " files changed:\n");
1478 print "<table class=\"diff_tree\">\n";
1481 foreach my $line (@
{$difftree}) {
1482 my %diff = parse_difftree_raw_line
($line);
1485 print "<tr class=\"dark\">\n";
1487 print "<tr class=\"light\">\n";
1491 my ($to_mode_oct, $to_mode_str, $to_file_type);
1492 my ($from_mode_oct, $from_mode_str, $from_file_type);
1493 if ($diff{'to_mode'} ne ('0' x
6)) {
1494 $to_mode_oct = oct $diff{'to_mode'};
1495 if (S_ISREG
($to_mode_oct)) { # only for regular file
1496 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1498 $to_file_type = file_type
($diff{'to_mode'});
1500 if ($diff{'from_mode'} ne ('0' x
6)) {
1501 $from_mode_oct = oct $diff{'from_mode'};
1502 if (S_ISREG
($to_mode_oct)) { # only for regular file
1503 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1505 $from_file_type = file_type
($diff{'from_mode'});
1508 if ($diff{'status'} eq "A") { # created
1509 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1510 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1511 $mode_chng .= "]</span>";
1513 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1514 hash_base
=>$hash, file_name
=>$diff{'file'}),
1515 -class => "list"}, esc_html
($diff{'file'})) .
1517 "<td>$mode_chng</td>\n" .
1518 "<td class=\"link\">" .
1519 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1520 hash_base
=>$hash, file_name
=>$diff{'file'})},
1522 if ($action eq 'commitdiff') {
1526 $cgi->a({-href
=> "#patch$patchno"}, "patch");
1530 } elsif ($diff{'status'} eq "D") { # deleted
1531 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1533 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1534 hash_base
=>$parent, 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{'from_id'},
1540 hash_base
=>$parent, file_name
=>$diff{'file'})},
1543 if ($action eq 'commitdiff') {
1547 $cgi->a({-href
=> "#patch$patchno"}, "patch");
1549 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1550 file_name
=>$diff{'file'})},
1554 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1555 my $mode_chnge = "";
1556 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1557 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1558 if ($from_file_type != $to_file_type) {
1559 $mode_chnge .= " from $from_file_type to $to_file_type";
1561 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1562 if ($from_mode_str && $to_mode_str) {
1563 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1564 } elsif ($to_mode_str) {
1565 $mode_chnge .= " mode: $to_mode_str";
1568 $mode_chnge .= "]</span>\n";
1571 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1572 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1573 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1574 hash_base
=>$hash, hash_parent_base
=>$parent,
1575 file_name
=>$diff{'file'}),
1576 -class => "list"}, esc_html
($diff{'file'}));
1577 } else { # only mode changed
1578 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1579 hash_base
=>$hash, file_name
=>$diff{'file'}),
1580 -class => "list"}, esc_html
($diff{'file'}));
1583 "<td>$mode_chnge</td>\n" .
1584 "<td class=\"link\">" .
1585 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1586 hash_base
=>$hash, file_name
=>$diff{'file'})},
1588 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1589 if ($action eq 'commitdiff') {
1593 $cgi->a({-href
=> "#patch$patchno"}, "patch");
1596 $cgi->a({-href
=> href
(action
=>"blobdiff",
1597 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1598 hash_base
=>$hash, hash_parent_base
=>$parent,
1599 file_name
=>$diff{'file'})},
1604 $cgi->a({-href
=> href
(action
=>"history",
1605 hash_base
=>$hash, file_name
=>$diff{'file'})},
1609 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
1610 my %status_name = ('R' => 'moved', 'C' => 'copied');
1611 my $nstatus = $status_name{$diff{'status'}};
1613 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1614 # mode also for directories, so we cannot use $to_mode_str
1615 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
1618 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1619 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
1620 -class => "list"}, esc_html
($diff{'to_file'})) . "</td>\n" .
1621 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
1622 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
1623 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
1624 -class => "list"}, esc_html
($diff{'from_file'})) .
1625 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
1626 "<td class=\"link\">" .
1627 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1628 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'})},
1630 if ($diff{'to_id'} ne $diff{'from_id'}) {
1631 if ($action eq 'commitdiff') {
1635 $cgi->a({-href
=> "#patch$patchno"}, "patch");
1638 $cgi->a({-href
=> href
(action
=>"blobdiff",
1639 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1640 hash_base
=>$hash, hash_parent_base
=>$parent,
1641 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
1647 } # we should not encounter Unmerged (U) or Unknown (X) status
1653 sub git_patchset_body
{
1654 my ($fd, $difftree, $hash, $hash_parent) = @_;
1658 my $patch_found = 0;
1661 print "<div class=\"patchset\">\n";
1664 while (my $patch_line = <$fd>) {
1667 if ($patch_line =~ m/^diff /) { # "git diff" header
1668 # beginning of patch (in patchset)
1670 # close previous patch
1671 print "</div>\n"; # class="patch"
1673 # first patch in patchset
1676 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
1678 if (ref($difftree->[$patch_idx]) eq "HASH") {
1679 $diffinfo = $difftree->[$patch_idx];
1681 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
1685 # for now, no extended header, hence we skip empty patches
1686 # companion to next LINE if $in_header;
1687 if ($diffinfo->{'from_id'} eq $diffinfo->{'to_id'}) { # no change
1692 if ($diffinfo->{'status'} eq "A") { # added
1693 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'to_mode'}) . ":" .
1694 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1695 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
1696 $diffinfo->{'to_id'}) . "(new)" .
1697 "</div>\n"; # class="diff_info"
1699 } elsif ($diffinfo->{'status'} eq "D") { # deleted
1700 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'from_mode'}) . ":" .
1701 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1702 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
1703 $diffinfo->{'from_id'}) . "(deleted)" .
1704 "</div>\n"; # class="diff_info"
1706 } elsif ($diffinfo->{'status'} eq "R" || # renamed
1707 $diffinfo->{'status'} eq "C" || # copied
1708 $diffinfo->{'status'} eq "2") { # with two filenames (from git_blobdiff)
1709 print "<div class=\"diff_info\">" .
1710 file_type
($diffinfo->{'from_mode'}) . ":" .
1711 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1712 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'from_file'})},
1713 $diffinfo->{'from_id'}) .
1715 file_type
($diffinfo->{'to_mode'}) . ":" .
1716 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1717 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'to_file'})},
1718 $diffinfo->{'to_id'});
1719 print "</div>\n"; # class="diff_info"
1721 } else { # modified, mode changed, ...
1722 print "<div class=\"diff_info\">" .
1723 file_type
($diffinfo->{'from_mode'}) . ":" .
1724 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1725 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
1726 $diffinfo->{'from_id'}) .
1728 file_type
($diffinfo->{'to_mode'}) . ":" .
1729 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1730 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
1731 $diffinfo->{'to_id'});
1732 print "</div>\n"; # class="diff_info"
1735 #print "<div class=\"diff extended_header\">\n";
1738 } # start of patch in patchset
1741 if ($in_header && $patch_line =~ m/^---/) {
1742 #print "</div>\n"; # class="diff extended_header"
1745 my $file = $diffinfo->{'from_file'};
1746 $file ||= $diffinfo->{'file'};
1747 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1748 hash
=>$diffinfo->{'from_id'}, file_name
=>$file),
1749 -class => "list"}, esc_html
($file));
1750 $patch_line =~ s
|a
/.*$|a/$file|g
;
1751 print "<div class=\"diff from_file\">$patch_line</div>\n";
1753 $patch_line = <$fd>;
1756 #$patch_line =~ m/^+++/;
1757 $file = $diffinfo->{'to_file'};
1758 $file ||= $diffinfo->{'file'};
1759 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1760 hash
=>$diffinfo->{'to_id'}, file_name
=>$file),
1761 -class => "list"}, esc_html
($file));
1762 $patch_line =~ s
|b
/.*|b/$file|g
;
1763 print "<div class=\"diff to_file\">$patch_line</div>\n";
1767 next LINE
if $in_header;
1769 print format_diff_line
($patch_line);
1771 print "</div>\n" if $patch_found; # class="patch"
1773 print "</div>\n"; # class="patchset"
1776 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1778 sub git_shortlog_body
{
1779 # uses global variable $project
1780 my ($revlist, $from, $to, $refs, $extra) = @_;
1782 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
1783 my $have_snapshot = (defined $ctype && defined $suffix);
1785 $from = 0 unless defined $from;
1786 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1788 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
1790 for (my $i = $from; $i <= $to; $i++) {
1791 my $commit = $revlist->[$i];
1792 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
1793 my $ref = format_ref_marker
($refs, $commit);
1794 my %co = parse_commit
($commit);
1796 print "<tr class=\"dark\">\n";
1798 print "<tr class=\"light\">\n";
1801 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1802 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1803 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
1805 print format_subject_html
($co{'title'}, $co{'title_short'},
1806 href
(action
=>"commit", hash
=>$commit), $ref);
1808 "<td class=\"link\">" .
1809 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
1810 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
1811 if ($have_snapshot) {
1812 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
1817 if (defined $extra) {
1819 "<td colspan=\"4\">$extra</td>\n" .
1825 sub git_history_body
{
1826 # Warning: assumes constant type (blob or tree) during history
1827 my ($fd, $refs, $hash_base, $ftype, $extra) = @_;
1829 print "<table class=\"history\" cellspacing=\"0\">\n";
1831 while (my $line = <$fd>) {
1832 if ($line !~ m/^([0-9a-fA-F]{40})/) {
1837 my %co = parse_commit
($commit);
1842 my $ref = format_ref_marker
($refs, $commit);
1845 print "<tr class=\"dark\">\n";
1847 print "<tr class=\"light\">\n";
1850 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1851 # shortlog uses chop_str($co{'author_name'}, 10)
1852 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
1854 # originally git_history used chop_str($co{'title'}, 50)
1855 print format_subject_html
($co{'title'}, $co{'title_short'},
1856 href
(action
=>"commit", hash
=>$commit), $ref);
1858 "<td class=\"link\">" .
1859 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
1860 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
1861 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype);
1863 if ($ftype eq 'blob') {
1864 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
1865 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
1866 if (defined $blob_current && defined $blob_parent &&
1867 $blob_current ne $blob_parent) {
1869 $cgi->a({-href
=> href
(action
=>"blobdiff",
1870 hash
=>$blob_current, hash_parent
=>$blob_parent,
1871 hash_base
=>$hash_base, hash_parent_base
=>$commit,
1872 file_name
=>$file_name)},
1879 if (defined $extra) {
1881 "<td colspan=\"4\">$extra</td>\n" .
1888 # uses global variable $project
1889 my ($taglist, $from, $to, $extra) = @_;
1890 $from = 0 unless defined $from;
1891 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1893 print "<table class=\"tags\" cellspacing=\"0\">\n";
1895 for (my $i = $from; $i <= $to; $i++) {
1896 my $entry = $taglist->[$i];
1898 my $comment_lines = $tag{'comment'};
1899 my $comment = shift @
$comment_lines;
1901 if (defined $comment) {
1902 $comment_short = chop_str
($comment, 30, 5);
1905 print "<tr class=\"dark\">\n";
1907 print "<tr class=\"light\">\n";
1910 print "<td><i>$tag{'age'}</i></td>\n" .
1912 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
1913 -class => "list name"}, esc_html
($tag{'name'})) .
1916 if (defined $comment) {
1917 print format_subject_html
($comment, $comment_short,
1918 href
(action
=>"tag", hash
=>$tag{'id'}));
1921 "<td class=\"selflink\">";
1922 if ($tag{'type'} eq "tag") {
1923 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
1928 "<td class=\"link\">" . " | " .
1929 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
1930 if ($tag{'reftype'} eq "commit") {
1931 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
1932 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'refid'})}, "log");
1933 } elsif ($tag{'reftype'} eq "blob") {
1934 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
1939 if (defined $extra) {
1941 "<td colspan=\"5\">$extra</td>\n" .
1947 sub git_heads_body
{
1948 # uses global variable $project
1949 my ($taglist, $head, $from, $to, $extra) = @_;
1950 $from = 0 unless defined $from;
1951 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1953 print "<table class=\"heads\" cellspacing=\"0\">\n";
1955 for (my $i = $from; $i <= $to; $i++) {
1956 my $entry = $taglist->[$i];
1958 my $curr = $tag{'id'} eq $head;
1960 print "<tr class=\"dark\">\n";
1962 print "<tr class=\"light\">\n";
1965 print "<td><i>$tag{'age'}</i></td>\n" .
1966 ($tag{'id'} eq $head ?
"<td class=\"current_head\">" : "<td>") .
1967 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'}),
1968 -class => "list name"},esc_html
($tag{'name'})) .
1970 "<td class=\"link\">" .
1971 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") . " | " .
1972 $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log") .
1976 if (defined $extra) {
1978 "<td colspan=\"3\">$extra</td>\n" .
1984 ## ======================================================================
1985 ## ======================================================================
1988 sub git_project_list
{
1989 my $order = $cgi->param('o');
1990 if (defined $order && $order !~ m/project|descr|owner|age/) {
1991 die_error
(undef, "Unknown order parameter");
1994 my @list = git_get_projects_list
();
1997 die_error
(undef, "No projects found");
1999 foreach my $pr (@list) {
2000 my $head = git_get_head_hash
($pr->{'path'});
2001 if (!defined $head) {
2004 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
2005 my %co = parse_commit
($head);
2009 $pr->{'commit'} = \
%co;
2010 if (!defined $pr->{'descr'}) {
2011 my $descr = git_get_project_description
($pr->{'path'}) || "";
2012 $pr->{'descr'} = chop_str
($descr, 25, 5);
2014 if (!defined $pr->{'owner'}) {
2015 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2017 push @projects, $pr;
2021 if (-f
$home_text) {
2022 print "<div class=\"index_include\">\n";
2023 open (my $fd, $home_text);
2028 print "<table class=\"project_list\">\n" .
2030 $order ||= "project";
2031 if ($order eq "project") {
2032 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2033 print "<th>Project</th>\n";
2036 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=project"),
2037 -class => "header"}, "Project") .
2040 if ($order eq "descr") {
2041 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2042 print "<th>Description</th>\n";
2045 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=descr"),
2046 -class => "header"}, "Description") .
2049 if ($order eq "owner") {
2050 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2051 print "<th>Owner</th>\n";
2054 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=owner"),
2055 -class => "header"}, "Owner") .
2058 if ($order eq "age") {
2059 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
2060 print "<th>Last Change</th>\n";
2063 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=age"),
2064 -class => "header"}, "Last Change") .
2067 print "<th></th>\n" .
2070 foreach my $pr (@projects) {
2072 print "<tr class=\"dark\">\n";
2074 print "<tr class=\"light\">\n";
2077 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2078 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2079 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
2080 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2081 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" .
2082 $pr->{'commit'}{'age_string'} . "</td>\n" .
2083 "<td class=\"link\">" .
2084 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2085 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2086 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") .
2094 sub git_project_index
{
2095 my @projects = git_get_projects_list
();
2098 -type
=> 'text/plain',
2099 -charset
=> 'utf-8',
2100 -content_disposition
=> qq(inline
; filename
="index.aux"));
2102 foreach my $pr (@projects) {
2103 if (!exists $pr->{'owner'}) {
2104 $pr->{'owner'} = get_file_owner
("$projectroot/$project");
2107 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
2108 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
2109 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2110 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2114 print "$path $owner\n";
2119 my $descr = git_get_project_description
($project) || "none";
2120 my $head = git_get_head_hash
($project);
2121 my %co = parse_commit
($head);
2122 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2124 my $owner = git_get_project_owner
($project);
2126 my $refs = git_get_references
();
2128 git_print_page_nav
('summary','', $head);
2130 print "<div class=\"title\"> </div>\n";
2131 print "<table cellspacing=\"0\">\n" .
2132 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
2133 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2134 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2135 # use per project git URL list in $projectroot/$project/cloneurl
2136 # or make project git URL from git base URL and project name
2137 my $url_tag = "URL";
2138 my @url_list = git_get_project_url_list
($project);
2139 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2140 foreach my $git_url (@url_list) {
2141 next unless $git_url;
2142 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2147 open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_get_head_hash
($project)
2148 or die_error
(undef, "Open git-rev-list failed");
2149 my @revlist = map { chomp; $_ } <$fd>;
2151 git_print_header_div
('shortlog');
2152 git_shortlog_body
(\
@revlist, 0, 15, $refs,
2153 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
2155 my $taglist = git_get_refs_list
("refs/tags");
2156 if (defined @
$taglist) {
2157 git_print_header_div
('tags');
2158 git_tags_body
($taglist, 0, 15,
2159 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
2162 my $headlist = git_get_refs_list
("refs/heads");
2163 if (defined @
$headlist) {
2164 git_print_header_div
('heads');
2165 git_heads_body
($headlist, $head, 0, 15,
2166 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
2173 my $head = git_get_head_hash
($project);
2175 git_print_page_nav
('','', $head,undef,$head);
2176 my %tag = parse_tag
($hash);
2177 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
2178 print "<div class=\"title_text\">\n" .
2179 "<table cellspacing=\"0\">\n" .
2181 "<td>object</td>\n" .
2182 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2183 $tag{'object'}) . "</td>\n" .
2184 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2185 $tag{'type'}) . "</td>\n" .
2187 if (defined($tag{'author'})) {
2188 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
2189 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
2190 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2191 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2194 print "</table>\n\n" .
2196 print "<div class=\"page_body\">";
2197 my $comment = $tag{'comment'};
2198 foreach my $line (@
$comment) {
2199 print esc_html
($line) . "<br/>\n";
2209 if (!gitweb_check_feature
('blame')) {
2210 die_error
('403 Permission denied', "Permission denied");
2212 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2213 $hash_base ||= git_get_head_hash
($project);
2214 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2215 my %co = parse_commit
($hash_base)
2216 or die_error
(undef, "Reading commit failed");
2217 if (!defined $hash) {
2218 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2219 or die_error
(undef, "Error looking up file");
2221 $ftype = git_get_type
($hash);
2222 if ($ftype !~ "blob") {
2223 die_error
("400 Bad Request", "Object is not a blob");
2225 open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base)
2226 or die_error
(undef, "Open git-blame failed");
2229 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2232 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2234 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2235 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2236 git_print_page_path
($file_name, $ftype, $hash_base);
2237 my @rev_color = (qw(light2 dark2));
2238 my $num_colors = scalar(@rev_color);
2239 my $current_color = 0;
2242 <div class="page_body">
2243 <table class="blame">
2244 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2247 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
2249 my $rev = substr($full_rev, 0, 8);
2253 if (!defined $last_rev) {
2254 $last_rev = $full_rev;
2255 } elsif ($last_rev ne $full_rev) {
2256 $last_rev = $full_rev;
2257 $current_color = ++$current_color % $num_colors;
2259 print "<tr class=\"$rev_color[$current_color]\">\n";
2260 print "<td class=\"sha1\">" .
2261 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$full_rev, file_name
=>$file_name)},
2262 esc_html
($rev)) . "</td>\n";
2263 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" .
2264 esc_html
($lineno) . "</a></td>\n";
2265 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
2271 or print "Reading blob failed\n";
2278 if (!gitweb_check_feature
('blame')) {
2279 die_error
('403 Permission denied', "Permission denied");
2281 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2282 $hash_base ||= git_get_head_hash
($project);
2283 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2284 my %co = parse_commit
($hash_base)
2285 or die_error
(undef, "Reading commit failed");
2286 if (!defined $hash) {
2287 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2288 or die_error
(undef, "Error lookup file");
2290 open ($fd, "-|", $GIT, "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2291 or die_error
(undef, "Open git-annotate failed");
2294 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2297 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2299 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2300 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2301 git_print_page_path
($file_name, 'blob', $hash_base);
2302 print "<div class=\"page_body\">\n";
2304 <table class="blame">
2313 my @line_class = (qw(light dark));
2314 my $line_class_len = scalar (@line_class);
2315 my $line_class_num = $#line_class;
2316 while (my $line = <$fd>) {
2328 $line_class_num = ($line_class_num + 1) % $line_class_len;
2330 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
2337 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
2340 $short_rev = substr ($long_rev, 0, 8);
2341 $age = time () - $time;
2342 $age_str = age_string
($age);
2343 $age_str =~ s/ / /g;
2344 $age_class = age_class
($age);
2345 $author = esc_html
($author);
2346 $author =~ s/ / /g;
2348 $data = untabify
($data);
2349 $data = esc_html
($data);
2352 <tr class="$line_class[$line_class_num]">
2353 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2354 <td class="$age_class">$age_str</td>
2356 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2357 <td class="pre">$data</td>
2360 } # while (my $line = <$fd>)
2361 print "</table>\n\n";
2363 or print "Reading blob failed.\n";
2369 my $head = git_get_head_hash
($project);
2371 git_print_page_nav
('','', $head,undef,$head);
2372 git_print_header_div
('summary', $project);
2374 my $taglist = git_get_refs_list
("refs/tags");
2375 if (defined @
$taglist) {
2376 git_tags_body
($taglist);
2382 my $head = git_get_head_hash
($project);
2384 git_print_page_nav
('','', $head,undef,$head);
2385 git_print_header_div
('summary', $project);
2387 my $taglist = git_get_refs_list
("refs/heads");
2388 if (defined @
$taglist) {
2389 git_heads_body
($taglist, $head);
2394 sub git_blob_plain
{
2395 # blobs defined by non-textual hash id's can be cached
2397 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2401 if (!defined $hash) {
2402 if (defined $file_name) {
2403 my $base = $hash_base || git_get_head_hash
($project);
2404 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2405 or die_error
(undef, "Error lookup file");
2407 die_error
(undef, "No file name defined");
2411 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
2412 or die_error
(undef, "Couldn't cat $file_name, $hash");
2414 $type ||= blob_mimetype
($fd, $file_name);
2416 # save as filename, even when no $file_name is given
2417 my $save_as = "$hash";
2418 if (defined $file_name) {
2419 $save_as = $file_name;
2420 } elsif ($type =~ m/^text\//) {
2427 -content_disposition
=> "inline; filename=\"$save_as\"");
2429 binmode STDOUT
, ':raw';
2431 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2437 # blobs defined by non-textual hash id's can be cached
2439 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2443 if (!defined $hash) {
2444 if (defined $file_name) {
2445 my $base = $hash_base || git_get_head_hash
($project);
2446 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2447 or die_error
(undef, "Error lookup file");
2449 die_error
(undef, "No file name defined");
2452 my $have_blame = gitweb_check_feature
('blame');
2453 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
2454 or die_error
(undef, "Couldn't cat $file_name, $hash");
2455 my $mimetype = blob_mimetype
($fd, $file_name);
2456 if ($mimetype !~ m/^text\//) {
2458 return git_blob_plain
($mimetype);
2460 git_header_html
(undef, $expires);
2461 my $formats_nav = '';
2462 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2463 if (defined $file_name) {
2466 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
2467 hash
=>$hash, file_name
=>$file_name)},
2472 $cgi->a({-href
=> href
(action
=>"blob_plain",
2473 hash
=>$hash, file_name
=>$file_name)},
2476 $cgi->a({-href
=> href
(action
=>"blob",
2477 hash_base
=>"HEAD", file_name
=>$file_name)},
2481 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "plain");
2483 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2484 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2486 print "<div class=\"page_nav\">\n" .
2487 "<br/><br/></div>\n" .
2488 "<div class=\"title\">$hash</div>\n";
2490 git_print_page_path
($file_name, "blob", $hash_base);
2491 print "<div class=\"page_body\">\n";
2493 while (my $line = <$fd>) {
2496 $line = untabify
($line);
2497 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
2498 $nr, $nr, $nr, esc_html
($line);
2501 or print "Reading blob failed.\n";
2507 if (!defined $hash) {
2508 $hash = git_get_head_hash
($project);
2509 if (defined $file_name) {
2510 my $base = $hash_base || $hash;
2511 $hash = git_get_hash_by_path
($base, $file_name, "tree");
2513 if (!defined $hash_base) {
2518 open my $fd, "-|", $GIT, "ls-tree", '-z', $hash
2519 or die_error
(undef, "Open git-ls-tree failed");
2520 my @entries = map { chomp; $_ } <$fd>;
2521 close $fd or die_error
(undef, "Reading tree failed");
2524 my $refs = git_get_references
();
2525 my $ref = format_ref_marker
($refs, $hash_base);
2529 my $have_blame = gitweb_check_feature
('blame');
2530 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2531 $base_key{hash_base
} = $hash_base;
2532 git_print_page_nav
('tree','', $hash_base);
2533 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
2535 print "<div class=\"page_nav\">\n";
2536 print "<br/><br/></div>\n";
2537 print "<div class=\"title\">$hash</div>\n";
2539 if (defined $file_name) {
2540 $base = esc_html
("$file_name/");
2542 git_print_page_path
($file_name, 'tree', $hash_base);
2543 print "<div class=\"page_body\">\n";
2544 print "<table cellspacing=\"0\">\n";
2546 foreach my $line (@entries) {
2547 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2548 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
2552 my $t_name = validate_input
($4);
2554 print "<tr class=\"dark\">\n";
2556 print "<tr class=\"light\">\n";
2559 print "<td class=\"mode\">" . mode_str
($t_mode) . "</td>\n";
2560 if ($t_type eq "blob") {
2561 print "<td class=\"list\">" .
2562 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key),
2563 -class => "list"}, esc_html
($t_name)) .
2565 "<td class=\"link\">" .
2566 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)},
2570 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)},
2574 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2575 hash
=>$t_hash, file_name
=>"$base$t_name")},
2578 $cgi->a({-href
=> href
(action
=>"blob_plain",
2579 hash
=>$t_hash, file_name
=>"$base$t_name")},
2582 } elsif ($t_type eq "tree") {
2583 print "<td class=\"list\">" .
2584 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)},
2585 esc_html
($t_name)) .
2587 "<td class=\"link\">" .
2588 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)},
2591 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base, file_name
=>"$base$t_name")},
2597 print "</table>\n" .
2604 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2605 my $have_snapshot = (defined $ctype && defined $suffix);
2606 if (!$have_snapshot) {
2607 die_error
('403 Permission denied', "Permission denied");
2610 if (!defined $hash) {
2611 $hash = git_get_head_hash
($project);
2614 my $filename = basename
($project) . "-$hash.tar.$suffix";
2616 print $cgi->header(-type
=> 'application/x-tar',
2617 -content_encoding
=> $ctype,
2618 -content_disposition
=> "inline; filename=\"$filename\"",
2619 -status
=> '200 OK');
2621 open my $fd, "-|", "$GIT tar-tree $hash \'$project\' | $command" or
2622 die_error
(undef, "Execute git-tar-tree failed.");
2623 binmode STDOUT
, ':raw';
2625 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2631 my $head = git_get_head_hash
($project);
2632 if (!defined $hash) {
2635 if (!defined $page) {
2638 my $refs = git_get_references
();
2640 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2641 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2642 or die_error
(undef, "Open git-rev-list failed");
2643 my @revlist = map { chomp; $_ } <$fd>;
2646 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
2649 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
2652 my %co = parse_commit
($hash);
2654 git_print_header_div
('summary', $project);
2655 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
2657 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2658 my $commit = $revlist[$i];
2659 my $ref = format_ref_marker
($refs, $commit);
2660 my %co = parse_commit
($commit);
2662 my %ad = parse_date
($co{'author_epoch'});
2663 git_print_header_div
('commit',
2664 "<span class=\"age\">$co{'age_string'}</span>" .
2665 esc_html
($co{'title'}) . $ref,
2667 print "<div class=\"title_text\">\n" .
2668 "<div class=\"log_link\">\n" .
2669 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
2671 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
2674 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
2677 print "<div class=\"log_body\">\n";
2678 git_print_simplified_log
($co{'comment'});
2685 my %co = parse_commit
($hash);
2687 die_error
(undef, "Unknown commit object");
2689 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2690 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2692 my $parent = $co{'parent'};
2693 if (!defined $parent) {
2696 open my $fd, "-|", $GIT, "diff-tree", '-r', @diff_opts, $parent, $hash
2697 or die_error
(undef, "Open git-diff-tree failed");
2698 my @difftree = map { chomp; $_ } <$fd>;
2699 close $fd or die_error
(undef, "Reading git-diff-tree failed");
2701 # non-textual hash id's can be cached
2703 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2706 my $refs = git_get_references
();
2707 my $ref = format_ref_marker
($refs, $co{'id'});
2709 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2710 my $have_snapshot = (defined $ctype && defined $suffix);
2712 my $formats_nav = '';
2713 if (defined $file_name && defined $co{'parent'}) {
2714 my $parent = $co{'parent'};
2716 $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)},
2719 git_header_html
(undef, $expires);
2720 git_print_page_nav
('commit', defined $co{'parent'} ?
'' : 'commitdiff',
2721 $hash, $co{'tree'}, $hash,
2724 if (defined $co{'parent'}) {
2725 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
2727 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
2729 print "<div class=\"title_text\">\n" .
2730 "<table cellspacing=\"0\">\n";
2731 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
2733 "<td></td><td> $ad{'rfc2822'}";
2734 if ($ad{'hour_local'} < 6) {
2735 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2736 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2738 printf(" (%02d:%02d %s)",
2739 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2743 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
2744 print "<tr><td></td><td> $cd{'rfc2822'}" .
2745 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
2747 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
2750 "<td class=\"sha1\">" .
2751 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
2752 class => "list"}, $co{'tree'}) .
2754 "<td class=\"link\">" .
2755 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
2757 if ($have_snapshot) {
2759 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
2763 my $parents = $co{'parents'};
2764 foreach my $par (@
$parents) {
2767 "<td class=\"sha1\">" .
2768 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
2769 class => "list"}, $par) .
2771 "<td class=\"link\">" .
2772 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
2774 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
2781 print "<div class=\"page_body\">\n";
2782 git_print_log
($co{'comment'});
2785 git_difftree_body
(\
@difftree, $hash, $parent);
2791 my $format = shift || 'html';
2798 # preparing $fd and %diffinfo for git_patchset_body
2800 if (defined $hash_base && defined $hash_parent_base) {
2801 if (defined $file_name) {
2803 open $fd, "-|", $GIT, "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base,
2805 or die_error
(undef, "Open git-diff-tree failed");
2806 @difftree = map { chomp; $_ } <$fd>;
2808 or die_error
(undef, "Reading git-diff-tree failed");
2810 or die_error
('404 Not Found', "Blob diff not found");
2812 } elsif (defined $hash &&
2813 $hash =~ /[0-9a-fA-F]{40}/) {
2814 # try to find filename from $hash
2816 # read filtered raw output
2817 open $fd, "-|", $GIT, "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base
2818 or die_error
(undef, "Open git-diff-tree failed");
2820 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
2822 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
2823 map { chomp; $_ } <$fd>;
2825 or die_error
(undef, "Reading git-diff-tree failed");
2827 or die_error
('404 Not Found', "Blob diff not found");
2830 die_error
('404 Not Found', "Missing one of the blob diff parameters");
2833 if (@difftree > 1) {
2834 die_error
('404 Not Found', "Ambiguous blob diff specification");
2837 %diffinfo = parse_difftree_raw_line
($difftree[0]);
2838 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
2839 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
2841 $hash_parent ||= $diffinfo{'from_id'};
2842 $hash ||= $diffinfo{'to_id'};
2844 # non-textual hash id's can be cached
2845 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
2846 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
2851 open $fd, "-|", $GIT, "diff-tree", '-r', @diff_opts,
2852 '-p', $hash_parent_base, $hash_base,
2854 or die_error
(undef, "Open git-diff-tree failed");
2857 # old/legacy style URI
2858 if (!%diffinfo && # if new style URI failed
2859 defined $hash && defined $hash_parent) {
2860 # fake git-diff-tree raw output
2861 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
2862 $diffinfo{'from_id'} = $hash_parent;
2863 $diffinfo{'to_id'} = $hash;
2864 if (defined $file_name) {
2865 if (defined $file_parent) {
2866 $diffinfo{'status'} = '2';
2867 $diffinfo{'from_file'} = $file_parent;
2868 $diffinfo{'to_file'} = $file_name;
2869 } else { # assume not renamed
2870 $diffinfo{'status'} = '1';
2871 $diffinfo{'from_file'} = $file_name;
2872 $diffinfo{'to_file'} = $file_name;
2874 } else { # no filename given
2875 $diffinfo{'status'} = '2';
2876 $diffinfo{'from_file'} = $hash_parent;
2877 $diffinfo{'to_file'} = $hash;
2880 # non-textual hash id's can be cached
2881 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
2882 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
2887 open $fd, "-|", $GIT, "diff", '-p', @diff_opts, $hash_parent, $hash
2888 or die_error
(undef, "Open git-diff failed");
2890 die_error
('404 Not Found', "Missing one of the blob diff parameters")
2895 if ($format eq 'html') {
2897 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
2898 hash
=>$hash, hash_parent
=>$hash_parent,
2899 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
2900 file_name
=>$file_name, file_parent
=>$file_parent)},
2902 git_header_html
(undef, $expires);
2903 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2904 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2905 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2907 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
2908 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
2910 if (defined $file_name) {
2911 git_print_page_path
($file_name, "blob", $hash_base);
2913 print "<div class=\"page_path\"></div>\n";
2916 } elsif ($format eq 'plain') {
2918 -type
=> 'text/plain',
2919 -charset
=> 'utf-8',
2920 -expires
=> $expires,
2921 -content_disposition
=> qq(inline
; filename
="${file_name}.patch"));
2923 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
2926 die_error
(undef, "Unknown blobdiff format");
2930 if ($format eq 'html') {
2931 print "<div class=\"page_body\">\n";
2933 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
2936 print "</div>\n"; # class="page_body"
2940 while (my $line = <$fd>) {
2941 $line =~ s!a/($hash|$hash_parent)!a/$diffinfo{'from_file'}!g;
2942 $line =~ s!b/($hash|$hash_parent)!b/$diffinfo{'to_file'}!g;
2946 last if $line =~ m!^\+\+\+!;
2954 sub git_blobdiff_plain
{
2955 git_blobdiff
('plain');
2958 sub git_commitdiff
{
2959 my $format = shift || 'html';
2960 my %co = parse_commit
($hash);
2962 die_error
(undef, "Unknown commit object");
2964 if (!defined $hash_parent) {
2965 $hash_parent = $co{'parent'} || '--root';
2971 if ($format eq 'html') {
2972 open $fd, "-|", $GIT, "diff-tree", '-r', @diff_opts,
2973 "--patch-with-raw", "--full-index", $hash_parent, $hash
2974 or die_error
(undef, "Open git-diff-tree failed");
2976 while (chomp(my $line = <$fd>)) {
2977 # empty line ends raw part of diff-tree output
2979 push @difftree, $line;
2982 } elsif ($format eq 'plain') {
2983 open $fd, "-|", $GIT, "diff-tree", '-r', @diff_opts,
2984 '-p', $hash_parent, $hash
2985 or die_error
(undef, "Open git-diff-tree failed");
2988 die_error
(undef, "Unknown commitdiff format");
2991 # non-textual hash id's can be cached
2993 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2997 # write commit message
2998 if ($format eq 'html') {
2999 my $refs = git_get_references
();
3000 my $ref = format_ref_marker
($refs, $co{'id'});
3002 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
3003 hash
=>$hash, hash_parent
=>$hash_parent)},
3006 git_header_html
(undef, $expires);
3007 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
3008 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
3009 git_print_authorship
(\
%co);
3010 print "<div class=\"page_body\">\n";
3011 print "<div class=\"log\">\n";
3012 git_print_simplified_log
($co{'comment'}, 1); # skip title
3013 print "</div>\n"; # class="log"
3015 } elsif ($format eq 'plain') {
3016 my $refs = git_get_references
("tags");
3017 my $tagname = git_get_rev_name_tags
($hash);
3018 my $filename = basename
($project) . "-$hash.patch";
3021 -type
=> 'text/plain',
3022 -charset
=> 'utf-8',
3023 -expires
=> $expires,
3024 -content_disposition
=> qq(inline
; filename
="$filename"));
3025 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3028 Date: $ad{'rfc2822'} ($ad{'tz_local'})
3029 Subject: $co{'title'}
3031 print "X-Git-Tag: $tagname\n" if $tagname;
3032 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3034 foreach my $line (@
{$co{'comment'}}) {
3041 if ($format eq 'html') {
3042 git_difftree_body
(\
@difftree, $hash, $hash_parent);
3045 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
3047 print "</div>\n"; # class="page_body"
3050 } elsif ($format eq 'plain') {
3054 or print "Reading git-diff-tree failed\n";
3058 sub git_commitdiff_plain
{
3059 git_commitdiff
('plain');
3063 if (!defined $hash_base) {
3064 $hash_base = git_get_head_hash
($project);
3067 my %co = parse_commit
($hash_base);
3069 die_error
(undef, "Unknown commit object");
3071 my $refs = git_get_references
();
3073 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base);
3074 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3075 if (!defined $hash && defined $file_name) {
3076 $hash = git_get_hash_by_path
($hash_base, $file_name);
3078 if (defined $hash) {
3079 $ftype = git_get_type
($hash);
3081 git_print_page_path
($file_name, $ftype, $hash_base);
3084 $GIT, "rev-list", "--full-history", $hash_base, "--", $file_name;
3085 git_history_body
($fd, $refs, $hash_base, $ftype);
3092 if (!defined $searchtext) {
3093 die_error
(undef, "Text field empty");
3095 if (!defined $hash) {
3096 $hash = git_get_head_hash
($project);
3098 my %co = parse_commit
($hash);
3100 die_error
(undef, "Unknown commit object");
3102 # pickaxe may take all resources of your box and run for several minutes
3103 # with every query - so decide by yourself how public you make this feature :)
3104 my $commit_search = 1;
3105 my $author_search = 0;
3106 my $committer_search = 0;
3107 my $pickaxe_search = 0;
3108 if ($searchtext =~ s/^author\\://i) {
3110 } elsif ($searchtext =~ s/^committer\\://i) {
3111 $committer_search = 1;
3112 } elsif ($searchtext =~ s/^pickaxe\\://i) {
3114 $pickaxe_search = 1;
3117 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
3118 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
3120 print "<table cellspacing=\"0\">\n";
3122 if ($commit_search) {
3124 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", $hash or next;
3125 while (my $commit_text = <$fd>) {
3126 if (!grep m/$searchtext/i, $commit_text) {
3129 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3132 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3135 my @commit_lines = split "\n", $commit_text;
3136 my %co = parse_commit
(undef, \
@commit_lines);
3141 print "<tr class=\"dark\">\n";
3143 print "<tr class=\"light\">\n";
3146 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3147 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3149 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3150 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3151 my $comment = $co{'comment'};
3152 foreach my $line (@
$comment) {
3153 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3154 my $lead = esc_html
($1) || "";
3155 $lead = chop_str
($lead, 30, 10);
3156 my $match = esc_html
($2) || "";
3157 my $trail = esc_html
($3) || "";
3158 $trail = chop_str
($trail, 30, 10);
3159 my $text = "$lead<span class=\"match\">$match</span>$trail";
3160 print chop_str
($text, 80, 5) . "<br/>\n";
3164 "<td class=\"link\">" .
3165 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3167 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3174 if ($pickaxe_search) {
3176 open my $fd, "-|", "$GIT rev-list $hash | $GIT diff-tree -r --stdin -S\'$searchtext\'";
3179 while (my $line = <$fd>) {
3180 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
3183 $set{'from_id'} = $3;
3185 $set{'id'} = $set{'to_id'};
3186 if ($set{'id'} =~ m/0{40}/) {
3187 $set{'id'} = $set{'from_id'};
3189 if ($set{'id'} =~ m/0{40}/) {
3193 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
3196 print "<tr class=\"dark\">\n";
3198 print "<tr class=\"light\">\n";
3201 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3202 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3204 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3205 -class => "list subject"},
3206 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3207 while (my $setref = shift @files) {
3209 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
3210 hash
=>$set{'id'}, file_name
=>$set{'file'}),
3212 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
3216 "<td class=\"link\">" .
3217 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3219 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3223 %co = parse_commit
($1);
3233 my $head = git_get_head_hash
($project);
3234 if (!defined $hash) {
3237 if (!defined $page) {
3240 my $refs = git_get_references
();
3242 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3243 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
3244 or die_error
(undef, "Open git-rev-list failed");
3245 my @revlist = map { chomp; $_ } <$fd>;
3248 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
3250 if ($#revlist >= (100 * ($page+1)-1)) {
3252 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
3253 -title
=> "Alt-n"}, "next");
3258 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
3259 git_print_header_div
('summary', $project);
3261 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
3266 ## ......................................................................
3267 ## feeds (RSS, OPML)
3270 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
3271 open my $fd, "-|", $GIT, "rev-list", "--max-count=150", git_get_head_hash
($project)
3272 or die_error
(undef, "Open git-rev-list failed");
3273 my @revlist = map { chomp; $_ } <$fd>;
3274 close $fd or die_error
(undef, "Reading git-rev-list failed");
3275 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3277 <?xml version="1.0" encoding="utf-8"?>
3278 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
3280 <title>$project $my_uri $my_url</title>
3281 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
3282 <description>$project log</description>
3283 <language>en</language>
3286 for (my $i = 0; $i <= $#revlist; $i++) {
3287 my $commit = $revlist[$i];
3288 my %co = parse_commit
($commit);
3289 # we read 150, we always show 30 and the ones more recent than 48 hours
3290 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
3293 my %cd = parse_date
($co{'committer_epoch'});
3294 open $fd, "-|", $GIT, "diff-tree", '-r', @diff_opts,
3295 $co{'parent'}, $co{'id'}
3297 my @difftree = map { chomp; $_ } <$fd>;
3302 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
3304 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
3305 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
3306 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
3307 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
3308 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
3309 "<content:encoded>" .
3311 my $comment = $co{'comment'};
3312 foreach my $line (@
$comment) {
3313 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
3314 print "$line<br/>\n";
3317 foreach my $line (@difftree) {
3318 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3321 my $file = validate_input
(unquote
($7));
3322 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
3323 print "$file<br/>\n";
3326 "</content:encoded>\n" .
3329 print "</channel></rss>";
3333 my @list = git_get_projects_list
();
3335 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3337 <?xml version="1.0" encoding="utf-8"?>
3338 <opml version="1.0">
3340 <title>$site_name Git OPML Export</title>
3343 <outline text="git RSS feeds">
3346 foreach my $pr (@list) {
3348 my $head = git_get_head_hash
($proj{'path'});
3349 if (!defined $head) {
3352 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
3353 my %co = parse_commit
($head);
3358 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
3359 my $rss = "$my_url?p=$proj{'path'};a=rss";
3360 my $html = "$my_url?p=$proj{'path'};a=summary";
3361 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";