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++";
52 # source of projects list
53 our $projects_list = "++GITWEB_LIST++";
55 # list of git base URLs used for URL to where fetch project from,
56 # i.e. full URL is "$git_base_url/$project"
57 our @git_base_url_list = ("++GITWEB_BASE_URL++");
59 # default blob_plain mimetype and default charset for text/plain blob
60 our $default_blob_plain_mimetype = 'text/plain';
61 our $default_text_plain_charset = undef;
63 # file to use for guessing MIME types before trying /etc/mime.types
64 # (relative to the current git repository)
65 our $mimetypes_file = undef;
67 # You define site-wide feature defaults here; override them with
68 # $GITWEB_CONFIG as necessary.
71 # 'sub' => feature-sub (subroutine),
72 # 'override' => allow-override (boolean),
73 # 'default' => [ default options...] (array reference)}
75 # if feature is overridable (it means that allow-override has true value,
76 # then feature-sub will be called with default options as parameters;
77 # return value of feature-sub indicates if to enable specified feature
79 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
82 'sub' => \
&feature_blame
,
87 'sub' => \
&feature_snapshot
,
89 # => [content-encoding, suffix, program]
90 'default' => ['x-gzip', 'gz', 'gzip']},
93 sub gitweb_check_feature
{
95 return undef unless exists $feature{$name};
96 my ($sub, $override, @defaults) = (
97 $feature{$name}{'sub'},
98 $feature{$name}{'override'},
99 @
{$feature{$name}{'default'}});
100 if (!$override) { return @defaults; }
101 return $sub->(@defaults);
104 # To enable system wide have in $GITWEB_CONFIG
105 # $feature{'blame'}{'default'} = [1];
106 # To have project specific config enable override in $GITWEB_CONFIG
107 # $feature{'blame'}{'override'} = 1;
108 # and in project config gitweb.blame = 0|1;
111 my ($val) = git_get_project_config
('blame', '--bool');
113 if ($val eq 'true') {
115 } elsif ($val eq 'false') {
122 # To disable system wide have in $GITWEB_CONFIG
123 # $feature{'snapshot'}{'default'} = [undef];
124 # To have project specific config enable override in $GITWEB_CONFIG
125 # $feature{'blame'}{'override'} = 1;
126 # and in project config gitweb.snapshot = none|gzip|bzip2
128 sub feature_snapshot
{
129 my ($ctype, $suffix, $command) = @_;
131 my ($val) = git_get_project_config
('snapshot');
133 if ($val eq 'gzip') {
134 return ('x-gzip', 'gz', 'gzip');
135 } elsif ($val eq 'bzip2') {
136 return ('x-bzip2', 'bz2', 'bzip2');
137 } elsif ($val eq 'none') {
141 return ($ctype, $suffix, $command);
144 # rename detection options for git-diff and git-diff-tree
145 # - default is '-M', with the cost proportional to
146 # (number of removed files) * (number of new files).
147 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
148 # (number of changed files + number of removed files) * (number of new files)
149 # - even more costly is '-C', '--find-copies-harder' with cost
150 # (number of files in the original tree) * (number of new files)
151 # - one might want to include '-B' option, e.g. '-B', '-M'
152 our @diff_opts = ('-M'); # taken from git_commit
154 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
155 require $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
157 # version of the core git binary
158 our $git_version = qx($GIT --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
160 $projects_list ||= $projectroot;
162 # ======================================================================
163 # input validation and dispatch
164 our $action = $cgi->param('a');
165 if (defined $action) {
166 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
167 die_error
(undef, "Invalid action parameter");
171 our $project = ($cgi->param('p') || $ENV{'PATH_INFO'});
172 if (defined $project) {
175 $project = undef unless $project;
177 if (defined $project) {
178 if (!validate_input
($project)) {
179 die_error
(undef, "Invalid project parameter");
181 if (!(-d
"$projectroot/$project")) {
182 die_error
(undef, "No such directory");
184 if (!(-e
"$projectroot/$project/HEAD")) {
185 die_error
(undef, "No such project");
187 $ENV{'GIT_DIR'} = "$projectroot/$project";
190 our $file_name = $cgi->param('f');
191 if (defined $file_name) {
192 if (!validate_input
($file_name)) {
193 die_error
(undef, "Invalid file parameter");
197 our $file_parent = $cgi->param('fp');
198 if (defined $file_parent) {
199 if (!validate_input
($file_parent)) {
200 die_error
(undef, "Invalid file parent parameter");
204 our $hash = $cgi->param('h');
206 if (!validate_input
($hash)) {
207 die_error
(undef, "Invalid hash parameter");
211 our $hash_parent = $cgi->param('hp');
212 if (defined $hash_parent) {
213 if (!validate_input
($hash_parent)) {
214 die_error
(undef, "Invalid hash parent parameter");
218 our $hash_base = $cgi->param('hb');
219 if (defined $hash_base) {
220 if (!validate_input
($hash_base)) {
221 die_error
(undef, "Invalid hash base parameter");
225 our $hash_parent_base = $cgi->param('hpb');
226 if (defined $hash_parent_base) {
227 if (!validate_input
($hash_parent_base)) {
228 die_error
(undef, "Invalid hash parent base parameter");
232 our $page = $cgi->param('pg');
234 if ($page =~ m/[^0-9]$/) {
235 die_error
(undef, "Invalid page parameter");
239 our $searchtext = $cgi->param('s');
240 if (defined $searchtext) {
241 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
242 die_error
(undef, "Invalid search parameter");
244 $searchtext = quotemeta $searchtext;
249 "blame" => \
&git_blame2
,
250 "blobdiff" => \
&git_blobdiff
,
251 "blobdiff_plain" => \
&git_blobdiff_plain
,
252 "blob" => \
&git_blob
,
253 "blob_plain" => \
&git_blob_plain
,
254 "commitdiff" => \
&git_commitdiff
,
255 "commitdiff_plain" => \
&git_commitdiff_plain
,
256 "commit" => \
&git_commit
,
257 "heads" => \
&git_heads
,
258 "history" => \
&git_history
,
261 "search" => \
&git_search
,
262 "shortlog" => \
&git_shortlog
,
263 "summary" => \
&git_summary
,
265 "tags" => \
&git_tags
,
266 "tree" => \
&git_tree
,
267 "snapshot" => \
&git_snapshot
,
268 # those below don't need $project
269 "opml" => \
&git_opml
,
270 "project_list" => \
&git_project_list
,
271 "project_index" => \
&git_project_index
,
274 if (defined $project) {
275 $action ||= 'summary';
277 $action ||= 'project_list';
279 if (!defined($actions{$action})) {
280 die_error
(undef, "Unknown action");
282 $actions{$action}->();
285 ## ======================================================================
299 hash_parent_base
=> "hpb",
303 my %mapping = @mapping;
305 $params{"project"} ||= $project;
308 for (my $i = 0; $i < @mapping; $i += 2) {
309 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
310 if (defined $params{$name}) {
311 push @result, $symbol . "=" . esc_param
($params{$name});
314 return "$my_uri?" . join(';', @result);
318 ## ======================================================================
319 ## validation, quoting/unquoting and escaping
324 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
327 if ($input =~ m/(^|\/)(|\
.|\
.\
.)($|\
/)/) {
330 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\
-\
+\#\
~\
%]/) {
336 # quote unsafe chars, but keep the slash, even when it's not
337 # correct, but quoted slashes look too horrible in bookmarks
340 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
346 # replace invalid utf8 character with SUBSTITUTION sequence
349 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
350 $str = escapeHTML
($str);
351 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
355 # git may return quoted and escaped filenames
358 if ($str =~ m/^"(.*)"$/) {
360 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
365 # escape tabs (convert tabs to spaces)
369 while ((my $pos = index($line, "\t")) != -1) {
370 if (my $count = (8 - ($pos % 8))) {
371 my $spaces = ' ' x
$count;
372 $line =~ s/\t/$spaces/;
379 ## ----------------------------------------------------------------------
380 ## HTML aware string manipulation
385 my $add_len = shift || 10;
387 # allow only $len chars, but don't cut a word if it would fit in $add_len
388 # if it doesn't fit, cut it if it's still longer than the dots we would add
389 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
392 if (length($tail) > 4) {
394 $body =~ s/&[^;]*$//; # remove chopped character entities
399 ## ----------------------------------------------------------------------
400 ## functions returning short strings
402 # CSS class for given age value (in seconds)
406 if ($age < 60*60*2) {
408 } elsif ($age < 60*60*24*2) {
415 # convert age in seconds to "nn units ago" string
420 if ($age > 60*60*24*365*2) {
421 $age_str = (int $age/60/60/24/365);
422 $age_str .= " years ago";
423 } elsif ($age > 60*60*24*(365/12)*2) {
424 $age_str = int $age/60/60/24/(365/12);
425 $age_str .= " months ago";
426 } elsif ($age > 60*60*24*7*2) {
427 $age_str = int $age/60/60/24/7;
428 $age_str .= " weeks ago";
429 } elsif ($age > 60*60*24*2) {
430 $age_str = int $age/60/60/24;
431 $age_str .= " days ago";
432 } elsif ($age > 60*60*2) {
433 $age_str = int $age/60/60;
434 $age_str .= " hours ago";
435 } elsif ($age > 60*2) {
436 $age_str = int $age/60;
437 $age_str .= " min ago";
440 $age_str .= " sec ago";
442 $age_str .= " right now";
447 # convert file mode in octal to symbolic file mode string
449 my $mode = oct shift;
451 if (S_ISDIR
($mode & S_IFMT
)) {
453 } elsif (S_ISLNK
($mode)) {
455 } elsif (S_ISREG
($mode)) {
456 # git cares only about the executable bit
457 if ($mode & S_IXUSR
) {
467 # convert file mode in octal to file type string
471 if ($mode !~ m/^[0-7]+$/) {
477 if (S_ISDIR
($mode & S_IFMT
)) {
479 } elsif (S_ISLNK
($mode)) {
481 } elsif (S_ISREG
($mode)) {
488 ## ----------------------------------------------------------------------
489 ## functions returning short HTML fragments, or transforming HTML fragments
490 ## which don't beling to other sections
492 # format line of commit message or tag comment
493 sub format_log_line_html
{
496 $line = esc_html
($line);
497 $line =~ s/ / /g;
498 if ($line =~ m/([0-9a-fA-F]{40})/) {
500 if (git_get_type
($hash_text) eq "commit") {
502 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$hash_text),
503 -class => "text"}, $hash_text);
504 $line =~ s/$hash_text/$link/;
510 # format marker of refs pointing to given object
511 sub format_ref_marker
{
512 my ($refs, $id) = @_;
515 if (defined $refs->{$id}) {
516 foreach my $ref (@
{$refs->{$id}}) {
517 my ($type, $name) = qw();
518 # e.g. tags/v2.6.11 or heads/next
519 if ($ref =~ m!^(.*?)s?/(.*)$!) {
527 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
532 return ' <span class="refs">'. $markers . '</span>';
538 # format, perhaps shortened and with markers, title line
539 sub format_subject_html
{
540 my ($long, $short, $href, $extra) = @_;
541 $extra = '' unless defined($extra);
543 if (length($short) < length($long)) {
544 return $cgi->a({-href
=> $href, -class => "list subject",
546 esc_html
($short) . $extra);
548 return $cgi->a({-href
=> $href, -class => "list subject"},
549 esc_html
($long) . $extra);
553 sub format_diff_line
{
555 my $char = substr($line, 0, 1);
561 $diff_class = " add";
562 } elsif ($char eq "-") {
563 $diff_class = " rem";
564 } elsif ($char eq "@") {
565 $diff_class = " chunk_header";
566 } elsif ($char eq "\\") {
567 $diff_class = " incomplete";
569 $line = untabify
($line);
570 return "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
573 ## ----------------------------------------------------------------------
574 ## git utility subroutines, invoking git commands
576 # get HEAD ref of given project as hash
577 sub git_get_head_hash
{
579 my $oENV = $ENV{'GIT_DIR'};
581 $ENV{'GIT_DIR'} = "$projectroot/$project";
582 if (open my $fd, "-|", $GIT, "rev-parse", "--verify", "HEAD") {
585 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
590 $ENV{'GIT_DIR'} = $oENV;
595 # get type of given object
599 open my $fd, "-|", $GIT, "cat-file", '-t', $hash or return;
606 sub git_get_project_config
{
607 my ($key, $type) = @_;
609 return unless ($key);
610 $key =~ s/^gitweb\.//;
611 return if ($key =~ m/\W/);
613 my @x = ($GIT, 'repo-config');
614 if (defined $type) { push @x, $type; }
616 push @x, "gitweb.$key";
622 # get hash of given path at given ref
623 sub git_get_hash_by_path
{
625 my $path = shift || return undef;
629 open my $fd, "-|", $GIT, "ls-tree", $base, "--", $path
630 or die_error
(undef, "Open git-ls-tree failed");
632 close $fd or return undef;
634 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
635 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
639 ## ......................................................................
640 ## git utility functions, directly accessing git repository
642 # assumes that PATH is not symref
643 sub git_get_hash_by_ref
{
646 open my $fd, "$projectroot/$path" or return undef;
650 if ($head =~ m/^[0-9a-fA-F]{40}$/) {
655 sub git_get_project_description
{
658 open my $fd, "$projectroot/$path/description" or return undef;
665 sub git_get_project_url_list
{
668 open my $fd, "$projectroot/$path/cloneurl" or return undef;
669 my @git_project_url_list = map { chomp; $_ } <$fd>;
672 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
675 sub git_get_projects_list
{
678 if (-d
$projects_list) {
679 # search in directory
680 my $dir = $projects_list;
681 opendir my ($dh), $dir or return undef;
682 while (my $dir = readdir($dh)) {
683 if (-e
"$projectroot/$dir/HEAD") {
691 } elsif (-f
$projects_list) {
692 # read from file(url-encoded):
693 # 'git%2Fgit.git Linus+Torvalds'
694 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
695 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
696 open my ($fd), $projects_list or return undef;
697 while (my $line = <$fd>) {
699 my ($path, $owner) = split ' ', $line;
700 $path = unescape
($path);
701 $owner = unescape
($owner);
702 if (!defined $path) {
705 if (-e
"$projectroot/$path/HEAD") {
708 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
715 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
719 sub git_get_project_owner
{
723 return undef unless $project;
725 # read from file (url-encoded):
726 # 'git%2Fgit.git Linus+Torvalds'
727 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
728 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
729 if (-f
$projects_list) {
730 open (my $fd , $projects_list);
731 while (my $line = <$fd>) {
733 my ($pr, $ow) = split ' ', $line;
736 if ($pr eq $project) {
737 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
743 if (!defined $owner) {
744 $owner = get_file_owner
("$projectroot/$project");
750 sub git_get_references
{
751 my $type = shift || "";
754 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
755 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
756 if (-f
"$projectroot/$project/info/refs") {
757 open $fd, "$projectroot/$project/info/refs"
760 open $fd, "-|", $GIT, "ls-remote", "."
764 while (my $line = <$fd>) {
766 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?[^\^]+)/) {
767 if (defined $refs{$1}) {
768 push @
{$refs{$1}}, $2;
778 sub git_get_rev_name_tags
{
779 my $hash = shift || return undef;
781 open my $fd, "-|", $GIT, "name-rev", "--tags", $hash
783 my $name_rev = <$fd>;
786 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
789 # catches also '$hash undefined' output
794 ## ----------------------------------------------------------------------
795 ## parse to hash functions
799 my $tz = shift || "-0000";
802 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
803 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
804 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
805 $date{'hour'} = $hour;
806 $date{'minute'} = $min;
807 $date{'mday'} = $mday;
808 $date{'day'} = $days[$wday];
809 $date{'month'} = $months[$mon];
810 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
811 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
812 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
813 $mday, $months[$mon], $hour ,$min;
815 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
816 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
817 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
818 $date{'hour_local'} = $hour;
819 $date{'minute_local'} = $min;
820 $date{'tz_local'} = $tz;
829 open my $fd, "-|", $GIT, "cat-file", "tag", $tag_id or return;
830 $tag{'id'} = $tag_id;
831 while (my $line = <$fd>) {
833 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
835 } elsif ($line =~ m/^type (.+)$/) {
837 } elsif ($line =~ m/^tag (.+)$/) {
839 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
843 } elsif ($line =~ m/--BEGIN/) {
844 push @comment, $line;
846 } elsif ($line eq "") {
850 push @comment, <$fd>;
851 $tag{'comment'} = \
@comment;
853 if (!defined $tag{'name'}) {
860 my $commit_id = shift;
861 my $commit_text = shift;
866 if (defined $commit_text) {
867 @commit_lines = @
$commit_text;
870 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", "--max-count=1", $commit_id
872 @commit_lines = split '\n', <$fd>;
877 my $header = shift @commit_lines;
878 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
881 ($co{'id'}, my @parents) = split ' ', $header;
882 $co{'parents'} = \
@parents;
883 $co{'parent'} = $parents[0];
884 while (my $line = shift @commit_lines) {
885 last if $line eq "\n";
886 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
888 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
890 $co{'author_epoch'} = $2;
891 $co{'author_tz'} = $3;
892 if ($co{'author'} =~ m/^([^<]+) </) {
893 $co{'author_name'} = $1;
895 $co{'author_name'} = $co{'author'};
897 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
898 $co{'committer'} = $1;
899 $co{'committer_epoch'} = $2;
900 $co{'committer_tz'} = $3;
901 $co{'committer_name'} = $co{'committer'};
902 $co{'committer_name'} =~ s/ <.*//;
905 if (!defined $co{'tree'}) {
909 foreach my $title (@commit_lines) {
912 $co{'title'} = chop_str
($title, 80, 5);
913 # remove leading stuff of merges to make the interesting part visible
914 if (length($title) > 50) {
915 $title =~ s/^Automatic //;
916 $title =~ s/^merge (of|with) /Merge ... /i;
917 if (length($title) > 50) {
918 $title =~ s/(http|rsync):\/\///;
920 if (length($title) > 50) {
921 $title =~ s/(master|www|rsync)\.//;
923 if (length($title) > 50) {
924 $title =~ s/kernel.org:?//;
926 if (length($title) > 50) {
927 $title =~ s/\/pub\/scm//;
930 $co{'title_short'} = chop_str
($title, 50, 5);
934 # remove added spaces
935 foreach my $line (@commit_lines) {
938 $co{'comment'} = \
@commit_lines;
940 my $age = time - $co{'committer_epoch'};
942 $co{'age_string'} = age_string
($age);
943 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
944 if ($age > 60*60*24*7*2) {
945 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
946 $co{'age_string_age'} = $co{'age_string'};
948 $co{'age_string_date'} = $co{'age_string'};
949 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
954 # parse ref from ref_file, given by ref_id, with given type
956 my $ref_file = shift;
958 my $type = shift || git_get_type
($ref_id);
961 $ref_item{'type'} = $type;
962 $ref_item{'id'} = $ref_id;
963 $ref_item{'epoch'} = 0;
964 $ref_item{'age'} = "unknown";
965 if ($type eq "tag") {
966 my %tag = parse_tag
($ref_id);
967 $ref_item{'comment'} = $tag{'comment'};
968 if ($tag{'type'} eq "commit") {
969 my %co = parse_commit
($tag{'object'});
970 $ref_item{'epoch'} = $co{'committer_epoch'};
971 $ref_item{'age'} = $co{'age_string'};
972 } elsif (defined($tag{'epoch'})) {
973 my $age = time - $tag{'epoch'};
974 $ref_item{'epoch'} = $tag{'epoch'};
975 $ref_item{'age'} = age_string
($age);
977 $ref_item{'reftype'} = $tag{'type'};
978 $ref_item{'name'} = $tag{'name'};
979 $ref_item{'refid'} = $tag{'object'};
980 } elsif ($type eq "commit"){
981 my %co = parse_commit
($ref_id);
982 $ref_item{'reftype'} = "commit";
983 $ref_item{'name'} = $ref_file;
984 $ref_item{'title'} = $co{'title'};
985 $ref_item{'refid'} = $ref_id;
986 $ref_item{'epoch'} = $co{'committer_epoch'};
987 $ref_item{'age'} = $co{'age_string'};
989 $ref_item{'reftype'} = $type;
990 $ref_item{'name'} = $ref_file;
991 $ref_item{'refid'} = $ref_id;
997 # parse line of git-diff-tree "raw" output
998 sub parse_difftree_raw_line
{
1002 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1003 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1004 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1005 $res{'from_mode'} = $1;
1006 $res{'to_mode'} = $2;
1007 $res{'from_id'} = $3;
1009 $res{'status'} = $5;
1010 $res{'similarity'} = $6;
1011 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1012 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1014 $res{'file'} = unquote
($7);
1017 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1018 #elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1019 # $res{'commit'} = $1;
1022 return wantarray ?
%res : \
%res;
1025 ## ......................................................................
1026 ## parse to array of hashes functions
1028 sub git_get_refs_list
{
1029 my $ref_dir = shift;
1033 my $pfxlen = length("$projectroot/$project/$ref_dir");
1034 File
::Find
::find
(sub {
1037 push @refs, substr($File::Find
::name
, $pfxlen + 1);
1039 }, "$projectroot/$project/$ref_dir");
1041 foreach my $ref_file (@refs) {
1042 my $ref_id = git_get_hash_by_ref
("$project/$ref_dir/$ref_file");
1043 my $type = git_get_type
($ref_id) || next;
1044 my %ref_item = parse_ref
($ref_file, $ref_id, $type);
1046 push @reflist, \
%ref_item;
1049 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1053 ## ----------------------------------------------------------------------
1054 ## filesystem-related functions
1056 sub get_file_owner
{
1059 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1060 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1061 if (!defined $gcos) {
1065 $owner =~ s/[,;].*$//;
1066 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
1069 ## ......................................................................
1070 ## mimetype related functions
1072 sub mimetype_guess_file
{
1073 my $filename = shift;
1074 my $mimemap = shift;
1075 -r
$mimemap or return undef;
1078 open(MIME
, $mimemap) or return undef;
1080 next if m/^#/; # skip comments
1081 my ($mime, $exts) = split(/\t+/);
1082 if (defined $exts) {
1083 my @exts = split(/\s+/, $exts);
1084 foreach my $ext (@exts) {
1085 $mimemap{$ext} = $mime;
1091 $filename =~ /\.(.*?)$/;
1092 return $mimemap{$1};
1095 sub mimetype_guess
{
1096 my $filename = shift;
1098 $filename =~ /\./ or return undef;
1100 if ($mimetypes_file) {
1101 my $file = $mimetypes_file;
1102 if ($file !~ m!^/!) { # if it is relative path
1103 # it is relative to project
1104 $file = "$projectroot/$project/$file";
1106 $mime = mimetype_guess_file
($filename, $file);
1108 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1114 my $filename = shift;
1117 my $mime = mimetype_guess
($filename);
1118 $mime and return $mime;
1122 return $default_blob_plain_mimetype unless $fd;
1125 return 'text/plain' .
1126 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
1127 } elsif (! $filename) {
1128 return 'application/octet-stream';
1129 } elsif ($filename =~ m/\.png$/i) {
1131 } elsif ($filename =~ m/\.gif$/i) {
1133 } elsif ($filename =~ m/\.jpe?g$/i) {
1134 return 'image/jpeg';
1136 return 'application/octet-stream';
1140 ## ======================================================================
1141 ## functions printing HTML: header, footer, error page
1143 sub git_header_html
{
1144 my $status = shift || "200 OK";
1145 my $expires = shift;
1147 my $title = "$site_name git";
1148 if (defined $project) {
1149 $title .= " - $project";
1150 if (defined $action) {
1151 $title .= "/$action";
1152 if (defined $file_name) {
1153 $title .= " - $file_name";
1154 if ($action eq "tree" && $file_name !~ m
|/$|) {
1161 # require explicit support from the UA if we are to send the page as
1162 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1163 # we have to do this because MSIE sometimes globs '*/*', pretending to
1164 # support xhtml+xml but choking when it gets what it asked for.
1165 if (defined $cgi->http('HTTP_ACCEPT') &&
1166 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1167 $cgi->Accept('application/xhtml+xml') != 0) {
1168 $content_type = 'application/xhtml+xml';
1170 $content_type = 'text/html';
1172 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1173 -status
=> $status, -expires
=> $expires);
1175 <?xml version="1.0" encoding="utf-8"?>
1176 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1177 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1178 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1179 <!-- git core binaries version $git_version -->
1181 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1182 <meta name="generator" content="gitweb/$version git/$git_version"/>
1183 <meta name="robots" content="index, nofollow"/>
1184 <title>$title</title>
1185 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
1187 if (defined $project) {
1188 printf('<link rel="alternate" title="%s log" '.
1189 'href="%s" type="application/rss+xml"/>'."\n",
1190 esc_param
($project), href
(action
=>"rss"));
1195 "<div class=\"page_header\">\n" .
1196 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
1197 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
1199 print $cgi->a({-href
=> esc_param
($home_link)}, $home_link_str) . " / ";
1200 if (defined $project) {
1201 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1202 if (defined $action) {
1206 if (!defined $searchtext) {
1210 if (defined $hash_base) {
1211 $search_hash = $hash_base;
1212 } elsif (defined $hash) {
1213 $search_hash = $hash;
1215 $search_hash = "HEAD";
1217 $cgi->param("a", "search");
1218 $cgi->param("h", $search_hash);
1219 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
1220 "<div class=\"search\">\n" .
1221 $cgi->hidden(-name
=> "p") . "\n" .
1222 $cgi->hidden(-name
=> "a") . "\n" .
1223 $cgi->hidden(-name
=> "h") . "\n" .
1224 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1226 $cgi->end_form() . "\n";
1231 sub git_footer_html
{
1232 print "<div class=\"page_footer\">\n";
1233 if (defined $project) {
1234 my $descr = git_get_project_description
($project);
1235 if (defined $descr) {
1236 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1238 print $cgi->a({-href
=> href
(action
=>"rss"), -class => "rss_logo"}, "RSS") . "\n";
1240 print $cgi->a({-href
=> href
(action
=>"opml"), -class => "rss_logo"}, "OPML") . "\n";
1248 my $status = shift || "403 Forbidden";
1249 my $error = shift || "Malformed query, file missing or permission denied";
1251 git_header_html
($status);
1253 <div class="page_body">
1263 ## ----------------------------------------------------------------------
1264 ## functions printing or outputting HTML: navigation
1266 sub git_print_page_nav
{
1267 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1268 $extra = '' if !defined $extra; # pager or formats
1270 my @navs = qw(summary shortlog log commit commitdiff tree);
1272 @navs = grep { $_ ne $suppress } @navs;
1275 my %arg = map { $_ => {action
=>$_} } @navs;
1276 if (defined $head) {
1277 for (qw(commit commitdiff)) {
1278 $arg{$_}{hash
} = $head;
1280 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1281 for (qw(shortlog log)) {
1282 $arg{$_}{hash
} = $head;
1286 $arg{tree
}{hash
} = $treehead if defined $treehead;
1287 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1289 print "<div class=\"page_nav\">\n" .
1291 map { $_ eq $current ?
1292 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1294 print "<br/>\n$extra<br/>\n" .
1298 sub format_paging_nav
{
1299 my ($action, $hash, $head, $page, $nrevs) = @_;
1303 if ($hash ne $head || $page) {
1304 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1306 $paging_nav .= "HEAD";
1310 $paging_nav .= " ⋅ " .
1311 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1312 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1314 $paging_nav .= " ⋅ prev";
1317 if ($nrevs >= (100 * ($page+1)-1)) {
1318 $paging_nav .= " ⋅ " .
1319 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1320 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1322 $paging_nav .= " ⋅ next";
1328 ## ......................................................................
1329 ## functions printing or outputting HTML: div
1331 sub git_print_header_div
{
1332 my ($action, $title, $hash, $hash_base) = @_;
1335 $args{action
} = $action;
1336 $args{hash
} = $hash if $hash;
1337 $args{hash_base
} = $hash_base if $hash_base;
1339 print "<div class=\"header\">\n" .
1340 $cgi->a({-href
=> href
(%args), -class => "title"},
1341 $title ?
$title : $action) .
1345 #sub git_print_authorship (\%) {
1346 sub git_print_authorship
{
1349 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
1350 print "<div class=\"author_date\">" .
1351 esc_html
($co->{'author_name'}) .
1353 if ($ad{'hour_local'} < 6) {
1354 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1355 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1357 printf(" (%02d:%02d %s)",
1358 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1363 sub git_print_page_path
{
1368 if (!defined $name) {
1369 print "<div class=\"page_path\">/</div>\n";
1370 } elsif (defined $type && $type eq 'blob') {
1371 print "<div class=\"page_path\">";
1373 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1377 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name)},
1380 print "<br/></div>\n";
1382 print "<div class=\"page_path\">" . esc_html
($name) . "<br/></div>\n";
1386 # sub git_print_log (\@;%) {
1387 sub git_print_log
($;%) {
1391 if ($opts{'-remove_title'}) {
1392 # remove title, i.e. first line of log
1395 # remove leading empty lines
1396 while (defined $log->[0] && $log->[0] eq "") {
1403 foreach my $line (@
$log) {
1404 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1407 if (! $opts{'-remove_signoff'}) {
1408 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1411 # remove signoff lines
1418 # print only one empty line
1419 # do not print empty line after signoff
1421 next if ($empty || $signoff);
1427 print format_log_line_html
($line) . "<br/>\n";
1430 if ($opts{'-final_empty_line'}) {
1431 # end with single empty line
1432 print "<br/>\n" unless $empty;
1436 sub git_print_simplified_log
{
1438 my $remove_title = shift;
1441 -final_empty_line
=> 1,
1442 -remove_title
=> $remove_title);
1445 ## ......................................................................
1446 ## functions printing large fragments of HTML
1448 sub git_difftree_body
{
1449 my ($difftree, $hash, $parent) = @_;
1451 print "<div class=\"list_head\">\n";
1452 if ($#{$difftree} > 10) {
1453 print(($#{$difftree} + 1) . " files changed:\n");
1457 print "<table class=\"diff_tree\">\n";
1460 foreach my $line (@
{$difftree}) {
1461 my %diff = parse_difftree_raw_line
($line);
1464 print "<tr class=\"dark\">\n";
1466 print "<tr class=\"light\">\n";
1470 my ($to_mode_oct, $to_mode_str, $to_file_type);
1471 my ($from_mode_oct, $from_mode_str, $from_file_type);
1472 if ($diff{'to_mode'} ne ('0' x
6)) {
1473 $to_mode_oct = oct $diff{'to_mode'};
1474 if (S_ISREG
($to_mode_oct)) { # only for regular file
1475 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1477 $to_file_type = file_type
($diff{'to_mode'});
1479 if ($diff{'from_mode'} ne ('0' x
6)) {
1480 $from_mode_oct = oct $diff{'from_mode'};
1481 if (S_ISREG
($to_mode_oct)) { # only for regular file
1482 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1484 $from_file_type = file_type
($diff{'from_mode'});
1487 if ($diff{'status'} eq "A") { # created
1488 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1489 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1490 $mode_chng .= "]</span>";
1492 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1493 hash_base
=>$hash, file_name
=>$diff{'file'}),
1494 -class => "list"}, esc_html
($diff{'file'})) .
1496 "<td>$mode_chng</td>\n" .
1497 "<td class=\"link\">" .
1498 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1499 hash_base
=>$hash, file_name
=>$diff{'file'})},
1501 if ($action == "commitdiff") {
1505 $cgi->a({-href
=> "#patch$patchno"}, "patch");
1509 } elsif ($diff{'status'} eq "D") { # deleted
1510 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1512 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1513 hash_base
=>$parent, file_name
=>$diff{'file'}),
1514 -class => "list"}, esc_html
($diff{'file'})) .
1516 "<td>$mode_chng</td>\n" .
1517 "<td class=\"link\">" .
1518 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1519 hash_base
=>$parent, file_name
=>$diff{'file'})},
1522 if ($action == "commitdiff") {
1526 $cgi->a({-href
=> "#patch$patchno"}, "patch");
1528 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1529 file_name
=>$diff{'file'})},
1533 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1534 my $mode_chnge = "";
1535 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1536 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1537 if ($from_file_type != $to_file_type) {
1538 $mode_chnge .= " from $from_file_type to $to_file_type";
1540 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1541 if ($from_mode_str && $to_mode_str) {
1542 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1543 } elsif ($to_mode_str) {
1544 $mode_chnge .= " mode: $to_mode_str";
1547 $mode_chnge .= "]</span>\n";
1550 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1551 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1552 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1553 hash_base
=>$hash, hash_parent_base
=>$parent,
1554 file_name
=>$diff{'file'}),
1555 -class => "list"}, esc_html
($diff{'file'}));
1556 } else { # only mode changed
1557 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1558 hash_base
=>$hash, file_name
=>$diff{'file'}),
1559 -class => "list"}, esc_html
($diff{'file'}));
1562 "<td>$mode_chnge</td>\n" .
1563 "<td class=\"link\">" .
1564 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1565 hash_base
=>$hash, file_name
=>$diff{'file'})},
1567 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1568 if ($action == "commitdiff") {
1572 $cgi->a({-href
=> "#patch$patchno"}, "patch");
1575 $cgi->a({-href
=> href
(action
=>"blobdiff",
1576 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1577 hash_base
=>$hash, hash_parent_base
=>$parent,
1578 file_name
=>$diff{'file'})},
1583 $cgi->a({-href
=> href
(action
=>"history",
1584 hash_base
=>$hash, file_name
=>$diff{'file'})},
1588 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
1589 my %status_name = ('R' => 'moved', 'C' => 'copied');
1590 my $nstatus = $status_name{$diff{'status'}};
1592 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1593 # mode also for directories, so we cannot use $to_mode_str
1594 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
1597 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1598 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
1599 -class => "list"}, esc_html
($diff{'to_file'})) . "</td>\n" .
1600 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
1601 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
1602 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
1603 -class => "list"}, esc_html
($diff{'from_file'})) .
1604 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
1605 "<td class=\"link\">" .
1606 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1607 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'})},
1609 if ($diff{'to_id'} ne $diff{'from_id'}) {
1610 if ($action == "commitdiff") {
1614 $cgi->a({-href
=> "#patch$patchno"}, "patch");
1617 $cgi->a({-href
=> href
(action
=>"blobdiff",
1618 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1619 hash_base
=>$hash, hash_parent_base
=>$parent,
1620 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
1626 } # we should not encounter Unmerged (U) or Unknown (X) status
1632 sub git_patchset_body
{
1633 my ($fd, $difftree, $hash, $hash_parent) = @_;
1637 my $patch_found = 0;
1640 print "<div class=\"patchset\">\n";
1643 while (my $patch_line = <$fd>) {
1646 if ($patch_line =~ m/^diff /) { # "git diff" header
1647 # beginning of patch (in patchset)
1649 # close previous patch
1650 print "</div>\n"; # class="patch"
1652 # first patch in patchset
1655 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
1657 if (ref($difftree->[$patch_idx]) eq "HASH") {
1658 $diffinfo = $difftree->[$patch_idx];
1660 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
1664 # for now, no extended header, hence we skip empty patches
1665 # companion to next LINE if $in_header;
1666 if ($diffinfo->{'from_id'} eq $diffinfo->{'to_id'}) { # no change
1671 if ($diffinfo->{'status'} eq "A") { # added
1672 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'to_mode'}) . ":" .
1673 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1674 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
1675 $diffinfo->{'to_id'}) . "(new)" .
1676 "</div>\n"; # class="diff_info"
1678 } elsif ($diffinfo->{'status'} eq "D") { # deleted
1679 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'from_mode'}) . ":" .
1680 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1681 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
1682 $diffinfo->{'from_id'}) . "(deleted)" .
1683 "</div>\n"; # class="diff_info"
1685 } elsif ($diffinfo->{'status'} eq "R" || # renamed
1686 $diffinfo->{'status'} eq "C" || # copied
1687 $diffinfo->{'status'} eq "2") { # with two filenames (from git_blobdiff)
1688 print "<div class=\"diff_info\">" .
1689 file_type
($diffinfo->{'from_mode'}) . ":" .
1690 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1691 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'from_file'})},
1692 $diffinfo->{'from_id'}) .
1694 file_type
($diffinfo->{'to_mode'}) . ":" .
1695 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1696 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'to_file'})},
1697 $diffinfo->{'to_id'});
1698 print "</div>\n"; # class="diff_info"
1700 } else { # modified, mode changed, ...
1701 print "<div class=\"diff_info\">" .
1702 file_type
($diffinfo->{'from_mode'}) . ":" .
1703 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1704 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
1705 $diffinfo->{'from_id'}) .
1707 file_type
($diffinfo->{'to_mode'}) . ":" .
1708 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1709 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
1710 $diffinfo->{'to_id'});
1711 print "</div>\n"; # class="diff_info"
1714 #print "<div class=\"diff extended_header\">\n";
1717 } # start of patch in patchset
1720 if ($in_header && $patch_line =~ m/^---/) {
1721 #print "</div>\n"; # class="diff extended_header"
1724 my $file = $diffinfo->{'from_file'};
1725 $file ||= $diffinfo->{'file'};
1726 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1727 hash
=>$diffinfo->{'from_id'}, file_name
=>$file),
1728 -class => "list"}, esc_html
($file));
1729 $patch_line =~ s
|a
/.*$|a/$file|g
;
1730 print "<div class=\"diff from_file\">$patch_line</div>\n";
1732 $patch_line = <$fd>;
1735 #$patch_line =~ m/^+++/;
1736 $file = $diffinfo->{'to_file'};
1737 $file ||= $diffinfo->{'file'};
1738 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1739 hash
=>$diffinfo->{'to_id'}, file_name
=>$file),
1740 -class => "list"}, esc_html
($file));
1741 $patch_line =~ s
|b
/.*|b/$file|g
;
1742 print "<div class=\"diff to_file\">$patch_line</div>\n";
1746 next LINE
if $in_header;
1748 print format_diff_line
($patch_line);
1750 print "</div>\n" if $patch_found; # class="patch"
1752 print "</div>\n"; # class="patchset"
1755 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1757 sub git_shortlog_body
{
1758 # uses global variable $project
1759 my ($revlist, $from, $to, $refs, $extra) = @_;
1761 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
1762 my $have_snapshot = (defined $ctype && defined $suffix);
1764 $from = 0 unless defined $from;
1765 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1767 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
1769 for (my $i = $from; $i <= $to; $i++) {
1770 my $commit = $revlist->[$i];
1771 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
1772 my $ref = format_ref_marker
($refs, $commit);
1773 my %co = parse_commit
($commit);
1775 print "<tr class=\"dark\">\n";
1777 print "<tr class=\"light\">\n";
1780 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1781 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1782 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
1784 print format_subject_html
($co{'title'}, $co{'title_short'},
1785 href
(action
=>"commit", hash
=>$commit), $ref);
1787 "<td class=\"link\">" .
1788 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
1789 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
1790 if ($have_snapshot) {
1791 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
1796 if (defined $extra) {
1798 "<td colspan=\"4\">$extra</td>\n" .
1804 sub git_history_body
{
1805 # Warning: assumes constant type (blob or tree) during history
1806 my ($fd, $refs, $hash_base, $ftype, $extra) = @_;
1808 print "<table class=\"history\" cellspacing=\"0\">\n";
1810 while (my $line = <$fd>) {
1811 if ($line !~ m/^([0-9a-fA-F]{40})/) {
1816 my %co = parse_commit
($commit);
1821 my $ref = format_ref_marker
($refs, $commit);
1824 print "<tr class=\"dark\">\n";
1826 print "<tr class=\"light\">\n";
1829 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1830 # shortlog uses chop_str($co{'author_name'}, 10)
1831 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
1833 # originally git_history used chop_str($co{'title'}, 50)
1834 print format_subject_html
($co{'title'}, $co{'title_short'},
1835 href
(action
=>"commit", hash
=>$commit), $ref);
1837 "<td class=\"link\">" .
1838 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
1839 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
1840 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype);
1842 if ($ftype eq 'blob') {
1843 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
1844 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
1845 if (defined $blob_current && defined $blob_parent &&
1846 $blob_current ne $blob_parent) {
1848 $cgi->a({-href
=> href
(action
=>"blobdiff",
1849 hash
=>$blob_current, hash_parent
=>$blob_parent,
1850 hash_base
=>$hash_base, hash_parent_base
=>$commit,
1851 file_name
=>$file_name)},
1858 if (defined $extra) {
1860 "<td colspan=\"4\">$extra</td>\n" .
1867 # uses global variable $project
1868 my ($taglist, $from, $to, $extra) = @_;
1869 $from = 0 unless defined $from;
1870 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1872 print "<table class=\"tags\" cellspacing=\"0\">\n";
1874 for (my $i = $from; $i <= $to; $i++) {
1875 my $entry = $taglist->[$i];
1877 my $comment_lines = $tag{'comment'};
1878 my $comment = shift @
$comment_lines;
1880 if (defined $comment) {
1881 $comment_short = chop_str
($comment, 30, 5);
1884 print "<tr class=\"dark\">\n";
1886 print "<tr class=\"light\">\n";
1889 print "<td><i>$tag{'age'}</i></td>\n" .
1891 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
1892 -class => "list name"}, esc_html
($tag{'name'})) .
1895 if (defined $comment) {
1896 print format_subject_html
($comment, $comment_short,
1897 href
(action
=>"tag", hash
=>$tag{'id'}));
1900 "<td class=\"selflink\">";
1901 if ($tag{'type'} eq "tag") {
1902 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
1907 "<td class=\"link\">" . " | " .
1908 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
1909 if ($tag{'reftype'} eq "commit") {
1910 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
1911 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'refid'})}, "log");
1912 } elsif ($tag{'reftype'} eq "blob") {
1913 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
1918 if (defined $extra) {
1920 "<td colspan=\"5\">$extra</td>\n" .
1926 sub git_heads_body
{
1927 # uses global variable $project
1928 my ($taglist, $head, $from, $to, $extra) = @_;
1929 $from = 0 unless defined $from;
1930 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
1932 print "<table class=\"heads\" cellspacing=\"0\">\n";
1934 for (my $i = $from; $i <= $to; $i++) {
1935 my $entry = $taglist->[$i];
1937 my $curr = $tag{'id'} eq $head;
1939 print "<tr class=\"dark\">\n";
1941 print "<tr class=\"light\">\n";
1944 print "<td><i>$tag{'age'}</i></td>\n" .
1945 ($tag{'id'} eq $head ?
"<td class=\"current_head\">" : "<td>") .
1946 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'}),
1947 -class => "list name"},esc_html
($tag{'name'})) .
1949 "<td class=\"link\">" .
1950 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") . " | " .
1951 $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log") .
1955 if (defined $extra) {
1957 "<td colspan=\"3\">$extra</td>\n" .
1963 ## ======================================================================
1964 ## ======================================================================
1967 sub git_project_list
{
1968 my $order = $cgi->param('o');
1969 if (defined $order && $order !~ m/project|descr|owner|age/) {
1970 die_error
(undef, "Unknown order parameter");
1973 my @list = git_get_projects_list
();
1976 die_error
(undef, "No projects found");
1978 foreach my $pr (@list) {
1979 my $head = git_get_head_hash
($pr->{'path'});
1980 if (!defined $head) {
1983 $ENV{'GIT_DIR'} = "$projectroot/$pr->{'path'}";
1984 my %co = parse_commit
($head);
1988 $pr->{'commit'} = \
%co;
1989 if (!defined $pr->{'descr'}) {
1990 my $descr = git_get_project_description
($pr->{'path'}) || "";
1991 $pr->{'descr'} = chop_str
($descr, 25, 5);
1993 if (!defined $pr->{'owner'}) {
1994 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
1996 push @projects, $pr;
2000 if (-f
$home_text) {
2001 print "<div class=\"index_include\">\n";
2002 open (my $fd, $home_text);
2007 print "<table class=\"project_list\">\n" .
2009 $order ||= "project";
2010 if ($order eq "project") {
2011 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2012 print "<th>Project</th>\n";
2015 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=project"),
2016 -class => "header"}, "Project") .
2019 if ($order eq "descr") {
2020 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2021 print "<th>Description</th>\n";
2024 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=descr"),
2025 -class => "header"}, "Description") .
2028 if ($order eq "owner") {
2029 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2030 print "<th>Owner</th>\n";
2033 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=owner"),
2034 -class => "header"}, "Owner") .
2037 if ($order eq "age") {
2038 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
2039 print "<th>Last Change</th>\n";
2042 $cgi->a({-href
=> "$my_uri?" . esc_param
("o=age"),
2043 -class => "header"}, "Last Change") .
2046 print "<th></th>\n" .
2049 foreach my $pr (@projects) {
2051 print "<tr class=\"dark\">\n";
2053 print "<tr class=\"light\">\n";
2056 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2057 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2058 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
2059 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2060 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" .
2061 $pr->{'commit'}{'age_string'} . "</td>\n" .
2062 "<td class=\"link\">" .
2063 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2064 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2065 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") .
2073 sub git_project_index
{
2074 my @projects = git_get_projects_list
();
2077 -type
=> 'text/plain',
2078 -charset
=> 'utf-8',
2079 -content_disposition
=> qq(inline
; filename
="index.aux"));
2081 foreach my $pr (@projects) {
2082 if (!exists $pr->{'owner'}) {
2083 $pr->{'owner'} = get_file_owner
("$projectroot/$project");
2086 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
2087 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
2088 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2089 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2093 print "$path $owner\n";
2098 my $descr = git_get_project_description
($project) || "none";
2099 my $head = git_get_head_hash
($project);
2100 my %co = parse_commit
($head);
2101 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2103 my $owner = git_get_project_owner
($project);
2105 my $refs = git_get_references
();
2107 git_print_page_nav
('summary','', $head);
2109 print "<div class=\"title\"> </div>\n";
2110 print "<table cellspacing=\"0\">\n" .
2111 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
2112 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2113 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2114 # use per project git URL list in $projectroot/$project/cloneurl
2115 # or make project git URL from git base URL and project name
2116 my $url_tag = "URL";
2117 my @url_list = git_get_project_url_list
($project);
2118 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2119 foreach my $git_url (@url_list) {
2120 next unless $git_url;
2121 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2126 open my $fd, "-|", $GIT, "rev-list", "--max-count=17", git_get_head_hash
($project)
2127 or die_error
(undef, "Open git-rev-list failed");
2128 my @revlist = map { chomp; $_ } <$fd>;
2130 git_print_header_div
('shortlog');
2131 git_shortlog_body
(\
@revlist, 0, 15, $refs,
2132 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
2134 my $taglist = git_get_refs_list
("refs/tags");
2135 if (defined @
$taglist) {
2136 git_print_header_div
('tags');
2137 git_tags_body
($taglist, 0, 15,
2138 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
2141 my $headlist = git_get_refs_list
("refs/heads");
2142 if (defined @
$headlist) {
2143 git_print_header_div
('heads');
2144 git_heads_body
($headlist, $head, 0, 15,
2145 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
2152 my $head = git_get_head_hash
($project);
2154 git_print_page_nav
('','', $head,undef,$head);
2155 my %tag = parse_tag
($hash);
2156 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
2157 print "<div class=\"title_text\">\n" .
2158 "<table cellspacing=\"0\">\n" .
2160 "<td>object</td>\n" .
2161 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2162 $tag{'object'}) . "</td>\n" .
2163 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2164 $tag{'type'}) . "</td>\n" .
2166 if (defined($tag{'author'})) {
2167 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
2168 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
2169 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2170 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2173 print "</table>\n\n" .
2175 print "<div class=\"page_body\">";
2176 my $comment = $tag{'comment'};
2177 foreach my $line (@
$comment) {
2178 print esc_html
($line) . "<br/>\n";
2188 if (!gitweb_check_feature
('blame')) {
2189 die_error
('403 Permission denied', "Permission denied");
2191 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2192 $hash_base ||= git_get_head_hash
($project);
2193 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2194 my %co = parse_commit
($hash_base)
2195 or die_error
(undef, "Reading commit failed");
2196 if (!defined $hash) {
2197 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2198 or die_error
(undef, "Error looking up file");
2200 $ftype = git_get_type
($hash);
2201 if ($ftype !~ "blob") {
2202 die_error
("400 Bad Request", "Object is not a blob");
2204 open ($fd, "-|", $GIT, "blame", '-l', $file_name, $hash_base)
2205 or die_error
(undef, "Open git-blame failed");
2208 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2211 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2213 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2214 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2215 git_print_page_path
($file_name, $ftype, $hash_base);
2216 my @rev_color = (qw(light2 dark2));
2217 my $num_colors = scalar(@rev_color);
2218 my $current_color = 0;
2221 <div class="page_body">
2222 <table class="blame">
2223 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2226 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
2228 my $rev = substr($full_rev, 0, 8);
2232 if (!defined $last_rev) {
2233 $last_rev = $full_rev;
2234 } elsif ($last_rev ne $full_rev) {
2235 $last_rev = $full_rev;
2236 $current_color = ++$current_color % $num_colors;
2238 print "<tr class=\"$rev_color[$current_color]\">\n";
2239 print "<td class=\"sha1\">" .
2240 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$full_rev, file_name
=>$file_name)},
2241 esc_html
($rev)) . "</td>\n";
2242 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" .
2243 esc_html
($lineno) . "</a></td>\n";
2244 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
2250 or print "Reading blob failed\n";
2257 if (!gitweb_check_feature
('blame')) {
2258 die_error
('403 Permission denied', "Permission denied");
2260 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2261 $hash_base ||= git_get_head_hash
($project);
2262 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2263 my %co = parse_commit
($hash_base)
2264 or die_error
(undef, "Reading commit failed");
2265 if (!defined $hash) {
2266 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2267 or die_error
(undef, "Error lookup file");
2269 open ($fd, "-|", $GIT, "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2270 or die_error
(undef, "Open git-annotate failed");
2273 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2276 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2278 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2279 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2280 git_print_page_path
($file_name, 'blob', $hash_base);
2281 print "<div class=\"page_body\">\n";
2283 <table class="blame">
2292 my @line_class = (qw(light dark));
2293 my $line_class_len = scalar (@line_class);
2294 my $line_class_num = $#line_class;
2295 while (my $line = <$fd>) {
2307 $line_class_num = ($line_class_num + 1) % $line_class_len;
2309 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
2316 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
2319 $short_rev = substr ($long_rev, 0, 8);
2320 $age = time () - $time;
2321 $age_str = age_string
($age);
2322 $age_str =~ s/ / /g;
2323 $age_class = age_class
($age);
2324 $author = esc_html
($author);
2325 $author =~ s/ / /g;
2327 $data = untabify
($data);
2328 $data = esc_html
($data);
2331 <tr class="$line_class[$line_class_num]">
2332 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2333 <td class="$age_class">$age_str</td>
2335 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2336 <td class="pre">$data</td>
2339 } # while (my $line = <$fd>)
2340 print "</table>\n\n";
2342 or print "Reading blob failed.\n";
2348 my $head = git_get_head_hash
($project);
2350 git_print_page_nav
('','', $head,undef,$head);
2351 git_print_header_div
('summary', $project);
2353 my $taglist = git_get_refs_list
("refs/tags");
2354 if (defined @
$taglist) {
2355 git_tags_body
($taglist);
2361 my $head = git_get_head_hash
($project);
2363 git_print_page_nav
('','', $head,undef,$head);
2364 git_print_header_div
('summary', $project);
2366 my $taglist = git_get_refs_list
("refs/heads");
2367 if (defined @
$taglist) {
2368 git_heads_body
($taglist, $head);
2373 sub git_blob_plain
{
2374 # blobs defined by non-textual hash id's can be cached
2376 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2380 if (!defined $hash) {
2381 if (defined $file_name) {
2382 my $base = $hash_base || git_get_head_hash
($project);
2383 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2384 or die_error
(undef, "Error lookup file");
2386 die_error
(undef, "No file name defined");
2390 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
2391 or die_error
(undef, "Couldn't cat $file_name, $hash");
2393 $type ||= blob_mimetype
($fd, $file_name);
2395 # save as filename, even when no $file_name is given
2396 my $save_as = "$hash";
2397 if (defined $file_name) {
2398 $save_as = $file_name;
2399 } elsif ($type =~ m/^text\//) {
2406 -content_disposition
=> "inline; filename=\"$save_as\"");
2408 binmode STDOUT
, ':raw';
2410 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2416 # blobs defined by non-textual hash id's can be cached
2418 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2422 if (!defined $hash) {
2423 if (defined $file_name) {
2424 my $base = $hash_base || git_get_head_hash
($project);
2425 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2426 or die_error
(undef, "Error lookup file");
2428 die_error
(undef, "No file name defined");
2431 my $have_blame = gitweb_check_feature
('blame');
2432 open my $fd, "-|", $GIT, "cat-file", "blob", $hash
2433 or die_error
(undef, "Couldn't cat $file_name, $hash");
2434 my $mimetype = blob_mimetype
($fd, $file_name);
2435 if ($mimetype !~ m/^text\//) {
2437 return git_blob_plain
($mimetype);
2439 git_header_html
(undef, $expires);
2440 my $formats_nav = '';
2441 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2442 if (defined $file_name) {
2445 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
2446 hash
=>$hash, file_name
=>$file_name)},
2451 $cgi->a({-href
=> href
(action
=>"blob_plain",
2452 hash
=>$hash, file_name
=>$file_name)},
2455 $cgi->a({-href
=> href
(action
=>"blob",
2456 hash_base
=>"HEAD", file_name
=>$file_name)},
2460 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "plain");
2462 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2463 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2465 print "<div class=\"page_nav\">\n" .
2466 "<br/><br/></div>\n" .
2467 "<div class=\"title\">$hash</div>\n";
2469 git_print_page_path
($file_name, "blob", $hash_base);
2470 print "<div class=\"page_body\">\n";
2472 while (my $line = <$fd>) {
2475 $line = untabify
($line);
2476 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
2477 $nr, $nr, $nr, esc_html
($line);
2480 or print "Reading blob failed.\n";
2486 if (!defined $hash) {
2487 $hash = git_get_head_hash
($project);
2488 if (defined $file_name) {
2489 my $base = $hash_base || $hash;
2490 $hash = git_get_hash_by_path
($base, $file_name, "tree");
2492 if (!defined $hash_base) {
2497 open my $fd, "-|", $GIT, "ls-tree", '-z', $hash
2498 or die_error
(undef, "Open git-ls-tree failed");
2499 my @entries = map { chomp; $_ } <$fd>;
2500 close $fd or die_error
(undef, "Reading tree failed");
2503 my $refs = git_get_references
();
2504 my $ref = format_ref_marker
($refs, $hash_base);
2508 my $have_blame = gitweb_check_feature
('blame');
2509 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2510 $base_key{hash_base
} = $hash_base;
2511 git_print_page_nav
('tree','', $hash_base);
2512 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
2514 print "<div class=\"page_nav\">\n";
2515 print "<br/><br/></div>\n";
2516 print "<div class=\"title\">$hash</div>\n";
2518 if (defined $file_name) {
2519 $base = esc_html
("$file_name/");
2521 git_print_page_path
($file_name, 'tree', $hash_base);
2522 print "<div class=\"page_body\">\n";
2523 print "<table cellspacing=\"0\">\n";
2525 foreach my $line (@entries) {
2526 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2527 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
2531 my $t_name = validate_input
($4);
2533 print "<tr class=\"dark\">\n";
2535 print "<tr class=\"light\">\n";
2538 print "<td class=\"mode\">" . mode_str
($t_mode) . "</td>\n";
2539 if ($t_type eq "blob") {
2540 print "<td class=\"list\">" .
2541 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key),
2542 -class => "list"}, esc_html
($t_name)) .
2544 "<td class=\"link\">" .
2545 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)},
2549 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)},
2553 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
2554 hash
=>$t_hash, file_name
=>"$base$t_name")},
2557 $cgi->a({-href
=> href
(action
=>"blob_plain",
2558 hash
=>$t_hash, file_name
=>"$base$t_name")},
2561 } elsif ($t_type eq "tree") {
2562 print "<td class=\"list\">" .
2563 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)},
2564 esc_html
($t_name)) .
2566 "<td class=\"link\">" .
2567 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t_hash, file_name
=>"$base$t_name", %base_key)},
2570 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base, file_name
=>"$base$t_name")},
2576 print "</table>\n" .
2583 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2584 my $have_snapshot = (defined $ctype && defined $suffix);
2585 if (!$have_snapshot) {
2586 die_error
('403 Permission denied', "Permission denied");
2589 if (!defined $hash) {
2590 $hash = git_get_head_hash
($project);
2593 my $filename = basename
($project) . "-$hash.tar.$suffix";
2595 print $cgi->header(-type
=> 'application/x-tar',
2596 -content_encoding
=> $ctype,
2597 -content_disposition
=> "inline; filename=\"$filename\"",
2598 -status
=> '200 OK');
2600 open my $fd, "-|", "$GIT tar-tree $hash \'$project\' | $command" or
2601 die_error
(undef, "Execute git-tar-tree failed.");
2602 binmode STDOUT
, ':raw';
2604 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2610 my $head = git_get_head_hash
($project);
2611 if (!defined $hash) {
2614 if (!defined $page) {
2617 my $refs = git_get_references
();
2619 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2620 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
2621 or die_error
(undef, "Open git-rev-list failed");
2622 my @revlist = map { chomp; $_ } <$fd>;
2625 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
2628 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
2631 my %co = parse_commit
($hash);
2633 git_print_header_div
('summary', $project);
2634 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
2636 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2637 my $commit = $revlist[$i];
2638 my $ref = format_ref_marker
($refs, $commit);
2639 my %co = parse_commit
($commit);
2641 my %ad = parse_date
($co{'author_epoch'});
2642 git_print_header_div
('commit',
2643 "<span class=\"age\">$co{'age_string'}</span>" .
2644 esc_html
($co{'title'}) . $ref,
2646 print "<div class=\"title_text\">\n" .
2647 "<div class=\"log_link\">\n" .
2648 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
2650 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
2653 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
2656 print "<div class=\"log_body\">\n";
2657 git_print_simplified_log
($co{'comment'});
2664 my %co = parse_commit
($hash);
2666 die_error
(undef, "Unknown commit object");
2668 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2669 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2671 my $parent = $co{'parent'};
2672 if (!defined $parent) {
2675 open my $fd, "-|", $GIT, "diff-tree", '-r', @diff_opts, $parent, $hash
2676 or die_error
(undef, "Open git-diff-tree failed");
2677 my @difftree = map { chomp; $_ } <$fd>;
2678 close $fd or die_error
(undef, "Reading git-diff-tree failed");
2680 # non-textual hash id's can be cached
2682 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2685 my $refs = git_get_references
();
2686 my $ref = format_ref_marker
($refs, $co{'id'});
2688 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2689 my $have_snapshot = (defined $ctype && defined $suffix);
2691 my $formats_nav = '';
2692 if (defined $file_name && defined $co{'parent'}) {
2693 my $parent = $co{'parent'};
2695 $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)},
2698 git_header_html
(undef, $expires);
2699 git_print_page_nav
('commit', defined $co{'parent'} ?
'' : 'commitdiff',
2700 $hash, $co{'tree'}, $hash,
2703 if (defined $co{'parent'}) {
2704 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
2706 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
2708 print "<div class=\"title_text\">\n" .
2709 "<table cellspacing=\"0\">\n";
2710 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
2712 "<td></td><td> $ad{'rfc2822'}";
2713 if ($ad{'hour_local'} < 6) {
2714 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2715 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2717 printf(" (%02d:%02d %s)",
2718 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2722 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
2723 print "<tr><td></td><td> $cd{'rfc2822'}" .
2724 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
2726 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
2729 "<td class=\"sha1\">" .
2730 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
2731 class => "list"}, $co{'tree'}) .
2733 "<td class=\"link\">" .
2734 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
2736 if ($have_snapshot) {
2738 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
2742 my $parents = $co{'parents'};
2743 foreach my $par (@
$parents) {
2746 "<td class=\"sha1\">" .
2747 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
2748 class => "list"}, $par) .
2750 "<td class=\"link\">" .
2751 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
2753 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "commitdiff") .
2760 print "<div class=\"page_body\">\n";
2761 git_print_log
($co{'comment'});
2764 git_difftree_body
(\
@difftree, $hash, $parent);
2770 my $format = shift || 'html';
2777 # preparing $fd and %diffinfo for git_patchset_body
2779 if (defined $hash_base && defined $hash_parent_base) {
2780 if (defined $file_name) {
2782 open $fd, "-|", $GIT, "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base,
2784 or die_error
(undef, "Open git-diff-tree failed");
2785 @difftree = map { chomp; $_ } <$fd>;
2787 or die_error
(undef, "Reading git-diff-tree failed");
2789 or die_error
('404 Not Found', "Blob diff not found");
2791 } elsif (defined $hash &&
2792 $hash =~ /[0-9a-fA-F]{40}/) {
2793 # try to find filename from $hash
2795 # read filtered raw output
2796 open $fd, "-|", $GIT, "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base
2797 or die_error
(undef, "Open git-diff-tree failed");
2799 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
2801 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
2802 map { chomp; $_ } <$fd>;
2804 or die_error
(undef, "Reading git-diff-tree failed");
2806 or die_error
('404 Not Found', "Blob diff not found");
2809 die_error
('404 Not Found', "Missing one of the blob diff parameters");
2812 if (@difftree > 1) {
2813 die_error
('404 Not Found', "Ambiguous blob diff specification");
2816 %diffinfo = parse_difftree_raw_line
($difftree[0]);
2817 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
2818 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
2820 $hash_parent ||= $diffinfo{'from_id'};
2821 $hash ||= $diffinfo{'to_id'};
2823 # non-textual hash id's can be cached
2824 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
2825 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
2830 open $fd, "-|", $GIT, "diff-tree", '-r', @diff_opts,
2831 '-p', $hash_parent_base, $hash_base,
2833 or die_error
(undef, "Open git-diff-tree failed");
2836 # old/legacy style URI
2837 if (!%diffinfo && # if new style URI failed
2838 defined $hash && defined $hash_parent) {
2839 # fake git-diff-tree raw output
2840 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
2841 $diffinfo{'from_id'} = $hash_parent;
2842 $diffinfo{'to_id'} = $hash;
2843 if (defined $file_name) {
2844 if (defined $file_parent) {
2845 $diffinfo{'status'} = '2';
2846 $diffinfo{'from_file'} = $file_parent;
2847 $diffinfo{'to_file'} = $file_name;
2848 } else { # assume not renamed
2849 $diffinfo{'status'} = '1';
2850 $diffinfo{'from_file'} = $file_name;
2851 $diffinfo{'to_file'} = $file_name;
2853 } else { # no filename given
2854 $diffinfo{'status'} = '2';
2855 $diffinfo{'from_file'} = $hash_parent;
2856 $diffinfo{'to_file'} = $hash;
2859 # non-textual hash id's can be cached
2860 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
2861 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
2866 open $fd, "-|", $GIT, "diff", '-p', @diff_opts, $hash_parent, $hash
2867 or die_error
(undef, "Open git-diff failed");
2869 die_error
('404 Not Found', "Missing one of the blob diff parameters")
2874 if ($format eq 'html') {
2876 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
2877 hash
=>$hash, hash_parent
=>$hash_parent,
2878 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
2879 file_name
=>$file_name, file_parent
=>$file_parent)},
2881 git_header_html
(undef, $expires);
2882 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2883 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2884 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2886 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
2887 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
2889 if (defined $file_name) {
2890 git_print_page_path
($file_name, "blob", $hash_base);
2892 print "<div class=\"page_path\"></div>\n";
2895 } elsif ($format eq 'plain') {
2897 -type
=> 'text/plain',
2898 -charset
=> 'utf-8',
2899 -expires
=> $expires,
2900 -content_disposition
=> qq(inline
; filename
="${file_name}.patch"));
2902 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
2905 die_error
(undef, "Unknown blobdiff format");
2909 if ($format eq 'html') {
2910 print "<div class=\"page_body\">\n";
2912 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
2915 print "</div>\n"; # class="page_body"
2919 while (my $line = <$fd>) {
2920 $line =~ s!a/($hash|$hash_parent)!a/$diffinfo{'from_file'}!g;
2921 $line =~ s!b/($hash|$hash_parent)!b/$diffinfo{'to_file'}!g;
2925 last if $line =~ m!^\+\+\+!;
2933 sub git_blobdiff_plain
{
2934 git_blobdiff
('plain');
2937 sub git_commitdiff
{
2938 my $format = shift || 'html';
2939 my %co = parse_commit
($hash);
2941 die_error
(undef, "Unknown commit object");
2943 if (!defined $hash_parent) {
2944 $hash_parent = $co{'parent'} || '--root';
2950 if ($format eq 'html') {
2951 open $fd, "-|", $GIT, "diff-tree", '-r', @diff_opts,
2952 "--patch-with-raw", "--full-index", $hash_parent, $hash
2953 or die_error
(undef, "Open git-diff-tree failed");
2955 while (chomp(my $line = <$fd>)) {
2956 # empty line ends raw part of diff-tree output
2958 push @difftree, $line;
2961 } elsif ($format eq 'plain') {
2962 open $fd, "-|", $GIT, "diff-tree", '-r', @diff_opts,
2963 '-p', $hash_parent, $hash
2964 or die_error
(undef, "Open git-diff-tree failed");
2967 die_error
(undef, "Unknown commitdiff format");
2970 # non-textual hash id's can be cached
2972 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2976 # write commit message
2977 if ($format eq 'html') {
2978 my $refs = git_get_references
();
2979 my $ref = format_ref_marker
($refs, $co{'id'});
2981 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
2982 hash
=>$hash, hash_parent
=>$hash_parent)},
2985 git_header_html
(undef, $expires);
2986 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
2987 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
2988 git_print_authorship
(\
%co);
2989 print "<div class=\"page_body\">\n";
2990 print "<div class=\"log\">\n";
2991 git_print_simplified_log
($co{'comment'}, 1); # skip title
2992 print "</div>\n"; # class="log"
2994 } elsif ($format eq 'plain') {
2995 my $refs = git_get_references
("tags");
2996 my $tagname = git_get_rev_name_tags
($hash);
2997 my $filename = basename
($project) . "-$hash.patch";
3000 -type
=> 'text/plain',
3001 -charset
=> 'utf-8',
3002 -expires
=> $expires,
3003 -content_disposition
=> qq(inline
; filename
="$filename"));
3004 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3007 Date: $ad{'rfc2822'} ($ad{'tz_local'})
3008 Subject: $co{'title'}
3010 print "X-Git-Tag: $tagname\n" if $tagname;
3011 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3013 foreach my $line (@
{$co{'comment'}}) {
3020 if ($format eq 'html') {
3021 git_difftree_body
(\
@difftree, $hash, $hash_parent);
3024 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
3026 print "</div>\n"; # class="page_body"
3029 } elsif ($format eq 'plain') {
3033 or print "Reading git-diff-tree failed\n";
3037 sub git_commitdiff_plain
{
3038 git_commitdiff
('plain');
3042 if (!defined $hash_base) {
3043 $hash_base = git_get_head_hash
($project);
3046 my %co = parse_commit
($hash_base);
3048 die_error
(undef, "Unknown commit object");
3050 my $refs = git_get_references
();
3052 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base);
3053 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3054 if (!defined $hash && defined $file_name) {
3055 $hash = git_get_hash_by_path
($hash_base, $file_name);
3057 if (defined $hash) {
3058 $ftype = git_get_type
($hash);
3060 git_print_page_path
($file_name, $ftype, $hash_base);
3063 $GIT, "rev-list", "--full-history", $hash_base, "--", $file_name;
3064 git_history_body
($fd, $refs, $hash_base, $ftype);
3071 if (!defined $searchtext) {
3072 die_error
(undef, "Text field empty");
3074 if (!defined $hash) {
3075 $hash = git_get_head_hash
($project);
3077 my %co = parse_commit
($hash);
3079 die_error
(undef, "Unknown commit object");
3081 # pickaxe may take all resources of your box and run for several minutes
3082 # with every query - so decide by yourself how public you make this feature :)
3083 my $commit_search = 1;
3084 my $author_search = 0;
3085 my $committer_search = 0;
3086 my $pickaxe_search = 0;
3087 if ($searchtext =~ s/^author\\://i) {
3089 } elsif ($searchtext =~ s/^committer\\://i) {
3090 $committer_search = 1;
3091 } elsif ($searchtext =~ s/^pickaxe\\://i) {
3093 $pickaxe_search = 1;
3096 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
3097 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
3099 print "<table cellspacing=\"0\">\n";
3101 if ($commit_search) {
3103 open my $fd, "-|", $GIT, "rev-list", "--header", "--parents", $hash or next;
3104 while (my $commit_text = <$fd>) {
3105 if (!grep m/$searchtext/i, $commit_text) {
3108 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3111 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3114 my @commit_lines = split "\n", $commit_text;
3115 my %co = parse_commit
(undef, \
@commit_lines);
3120 print "<tr class=\"dark\">\n";
3122 print "<tr class=\"light\">\n";
3125 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3126 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3128 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3129 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3130 my $comment = $co{'comment'};
3131 foreach my $line (@
$comment) {
3132 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3133 my $lead = esc_html
($1) || "";
3134 $lead = chop_str
($lead, 30, 10);
3135 my $match = esc_html
($2) || "";
3136 my $trail = esc_html
($3) || "";
3137 $trail = chop_str
($trail, 30, 10);
3138 my $text = "$lead<span class=\"match\">$match</span>$trail";
3139 print chop_str
($text, 80, 5) . "<br/>\n";
3143 "<td class=\"link\">" .
3144 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3146 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3153 if ($pickaxe_search) {
3155 open my $fd, "-|", "$GIT rev-list $hash | $GIT diff-tree -r --stdin -S\'$searchtext\'";
3158 while (my $line = <$fd>) {
3159 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
3162 $set{'from_id'} = $3;
3164 $set{'id'} = $set{'to_id'};
3165 if ($set{'id'} =~ m/0{40}/) {
3166 $set{'id'} = $set{'from_id'};
3168 if ($set{'id'} =~ m/0{40}/) {
3172 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
3175 print "<tr class=\"dark\">\n";
3177 print "<tr class=\"light\">\n";
3180 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3181 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3183 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3184 -class => "list subject"},
3185 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3186 while (my $setref = shift @files) {
3188 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
3189 hash
=>$set{'id'}, file_name
=>$set{'file'}),
3191 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
3195 "<td class=\"link\">" .
3196 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3198 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3202 %co = parse_commit
($1);
3212 my $head = git_get_head_hash
($project);
3213 if (!defined $hash) {
3216 if (!defined $page) {
3219 my $refs = git_get_references
();
3221 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3222 open my $fd, "-|", $GIT, "rev-list", $limit, $hash
3223 or die_error
(undef, "Open git-rev-list failed");
3224 my @revlist = map { chomp; $_ } <$fd>;
3227 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
3229 if ($#revlist >= (100 * ($page+1)-1)) {
3231 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
3232 -title
=> "Alt-n"}, "next");
3237 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
3238 git_print_header_div
('summary', $project);
3240 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
3245 ## ......................................................................
3246 ## feeds (RSS, OPML)
3249 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
3250 open my $fd, "-|", $GIT, "rev-list", "--max-count=150", git_get_head_hash
($project)
3251 or die_error
(undef, "Open git-rev-list failed");
3252 my @revlist = map { chomp; $_ } <$fd>;
3253 close $fd or die_error
(undef, "Reading git-rev-list failed");
3254 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3256 <?xml version="1.0" encoding="utf-8"?>
3257 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
3259 <title>$project $my_uri $my_url</title>
3260 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
3261 <description>$project log</description>
3262 <language>en</language>
3265 for (my $i = 0; $i <= $#revlist; $i++) {
3266 my $commit = $revlist[$i];
3267 my %co = parse_commit
($commit);
3268 # we read 150, we always show 30 and the ones more recent than 48 hours
3269 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
3272 my %cd = parse_date
($co{'committer_epoch'});
3273 open $fd, "-|", $GIT, "diff-tree", '-r', @diff_opts,
3274 $co{'parent'}, $co{'id'}
3276 my @difftree = map { chomp; $_ } <$fd>;
3281 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
3283 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
3284 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
3285 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
3286 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
3287 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
3288 "<content:encoded>" .
3290 my $comment = $co{'comment'};
3291 foreach my $line (@
$comment) {
3292 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
3293 print "$line<br/>\n";
3296 foreach my $line (@difftree) {
3297 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3300 my $file = validate_input
(unquote
($7));
3301 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
3302 print "$file<br/>\n";
3305 "</content:encoded>\n" .
3308 print "</channel></rss>";
3312 my @list = git_get_projects_list
();
3314 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3316 <?xml version="1.0" encoding="utf-8"?>
3317 <opml version="1.0">
3319 <title>$site_name Git OPML Export</title>
3322 <outline text="git RSS feeds">
3325 foreach my $pr (@list) {
3327 my $head = git_get_head_hash
($proj{'path'});
3328 if (!defined $head) {
3331 $ENV{'GIT_DIR'} = "$projectroot/$proj{'path'}";
3332 my %co = parse_commit
($head);
3337 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
3338 my $rss = "$my_url?p=$proj{'path'};a=rss";
3339 my $html = "$my_url?p=$proj{'path'};a=summary";
3340 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";