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
81 # use gitweb_check_feature(<feature>) to check if <feature> is enabled
84 'sub' => \
&feature_blame
,
89 'sub' => \
&feature_snapshot
,
91 # => [content-encoding, suffix, program]
92 'default' => ['x-gzip', 'gz', 'gzip']},
95 'sub' => \
&feature_pickaxe
,
100 sub gitweb_check_feature
{
102 return undef unless exists $feature{$name};
103 my ($sub, $override, @defaults) = (
104 $feature{$name}{'sub'},
105 $feature{$name}{'override'},
106 @
{$feature{$name}{'default'}});
107 if (!$override) { return @defaults; }
108 return $sub->(@defaults);
111 # To enable system wide have in $GITWEB_CONFIG
112 # $feature{'blame'}{'default'} = [1];
113 # To have project specific config enable override in $GITWEB_CONFIG
114 # $feature{'blame'}{'override'} = 1;
115 # and in project config gitweb.blame = 0|1;
118 my ($val) = git_get_project_config
('blame', '--bool');
120 if ($val eq 'true') {
122 } elsif ($val eq 'false') {
129 # To disable system wide have in $GITWEB_CONFIG
130 # $feature{'snapshot'}{'default'} = [undef];
131 # To have project specific config enable override in $GITWEB_CONFIG
132 # $feature{'blame'}{'override'} = 1;
133 # and in project config gitweb.snapshot = none|gzip|bzip2
135 sub feature_snapshot
{
136 my ($ctype, $suffix, $command) = @_;
138 my ($val) = git_get_project_config
('snapshot');
140 if ($val eq 'gzip') {
141 return ('x-gzip', 'gz', 'gzip');
142 } elsif ($val eq 'bzip2') {
143 return ('x-bzip2', 'bz2', 'bzip2');
144 } elsif ($val eq 'none') {
148 return ($ctype, $suffix, $command);
151 # To enable system wide have in $GITWEB_CONFIG
152 # $feature{'pickaxe'}{'default'} = [1];
153 # To have project specific config enable override in $GITWEB_CONFIG
154 # $feature{'pickaxe'}{'override'} = 1;
155 # and in project config gitweb.pickaxe = 0|1;
157 sub feature_pickaxe
{
158 my ($val) = git_get_project_config
('pickaxe', '--bool');
160 if ($val eq 'true') {
162 } elsif ($val eq 'false') {
169 # rename detection options for git-diff and git-diff-tree
170 # - default is '-M', with the cost proportional to
171 # (number of removed files) * (number of new files).
172 # - more costly is '-C' (or '-C', '-M'), with the cost proportional to
173 # (number of changed files + number of removed files) * (number of new files)
174 # - even more costly is '-C', '--find-copies-harder' with cost
175 # (number of files in the original tree) * (number of new files)
176 # - one might want to include '-B' option, e.g. '-B', '-M'
177 our @diff_opts = ('-M'); # taken from git_commit
179 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
180 do $GITWEB_CONFIG if -e
$GITWEB_CONFIG;
182 # version of the core git binary
183 our $git_version = qx($GIT --version
) =~ m/git version (.*)$/ ?
$1 : "unknown";
185 # path to the current git repository
188 $projects_list ||= $projectroot;
190 # ======================================================================
191 # input validation and dispatch
192 our $action = $cgi->param('a');
193 if (defined $action) {
194 if ($action =~ m/[^0-9a-zA-Z\.\-_]/) {
195 die_error
(undef, "Invalid action parameter");
199 our $project = ($cgi->param('p') || $ENV{'PATH_INFO'});
200 if (defined $project) {
203 $project = undef unless $project;
205 if (defined $project) {
206 if (!validate_input
($project)) {
207 die_error
(undef, "Invalid project parameter");
209 if (!(-d
"$projectroot/$project")) {
210 die_error
(undef, "No such directory");
212 if (!(-e
"$projectroot/$project/HEAD")) {
213 die_error
(undef, "No such project");
215 $git_dir = "$projectroot/$project";
218 our $file_name = $cgi->param('f');
219 if (defined $file_name) {
220 if (!validate_input
($file_name)) {
221 die_error
(undef, "Invalid file parameter");
225 our $file_parent = $cgi->param('fp');
226 if (defined $file_parent) {
227 if (!validate_input
($file_parent)) {
228 die_error
(undef, "Invalid file parent parameter");
232 our $hash = $cgi->param('h');
234 if (!validate_input
($hash)) {
235 die_error
(undef, "Invalid hash parameter");
239 our $hash_parent = $cgi->param('hp');
240 if (defined $hash_parent) {
241 if (!validate_input
($hash_parent)) {
242 die_error
(undef, "Invalid hash parent parameter");
246 our $hash_base = $cgi->param('hb');
247 if (defined $hash_base) {
248 if (!validate_input
($hash_base)) {
249 die_error
(undef, "Invalid hash base parameter");
253 our $hash_parent_base = $cgi->param('hpb');
254 if (defined $hash_parent_base) {
255 if (!validate_input
($hash_parent_base)) {
256 die_error
(undef, "Invalid hash parent base parameter");
260 our $page = $cgi->param('pg');
262 if ($page =~ m/[^0-9]$/) {
263 die_error
(undef, "Invalid page parameter");
267 our $searchtext = $cgi->param('s');
268 if (defined $searchtext) {
269 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\
-\
+\
:\@
]/) {
270 die_error
(undef, "Invalid search parameter");
272 $searchtext = quotemeta $searchtext;
277 "blame" => \
&git_blame2
,
278 "blobdiff" => \
&git_blobdiff
,
279 "blobdiff_plain" => \
&git_blobdiff_plain
,
280 "blob" => \
&git_blob
,
281 "blob_plain" => \
&git_blob_plain
,
282 "commitdiff" => \
&git_commitdiff
,
283 "commitdiff_plain" => \
&git_commitdiff_plain
,
284 "commit" => \
&git_commit
,
285 "heads" => \
&git_heads
,
286 "history" => \
&git_history
,
289 "search" => \
&git_search
,
290 "shortlog" => \
&git_shortlog
,
291 "summary" => \
&git_summary
,
293 "tags" => \
&git_tags
,
294 "tree" => \
&git_tree
,
295 "snapshot" => \
&git_snapshot
,
296 # those below don't need $project
297 "opml" => \
&git_opml
,
298 "project_list" => \
&git_project_list
,
299 "project_index" => \
&git_project_index
,
302 if (defined $project) {
303 $action ||= 'summary';
305 $action ||= 'project_list';
307 if (!defined($actions{$action})) {
308 die_error
(undef, "Unknown action");
310 $actions{$action}->();
313 ## ======================================================================
327 hash_parent_base
=> "hpb",
332 my %mapping = @mapping;
334 $params{'project'} = $project unless exists $params{'project'};
337 for (my $i = 0; $i < @mapping; $i += 2) {
338 my ($name, $symbol) = ($mapping[$i], $mapping[$i+1]);
339 if (defined $params{$name}) {
340 push @result, $symbol . "=" . esc_param
($params{$name});
343 return "$my_uri?" . join(';', @result);
347 ## ======================================================================
348 ## validation, quoting/unquoting and escaping
353 if ($input =~ m/^[0-9a-fA-F]{40}$/) {
356 if ($input =~ m/(^|\/)(|\
.|\
.\
.)($|\
/)/) {
359 if ($input =~ m/[^a-zA-Z0-9_\x80-\xff\ \t\.\/\
-\
+\#\
~\
%]/) {
365 # quote unsafe chars, but keep the slash, even when it's not
366 # correct, but quoted slashes look too horrible in bookmarks
369 $str =~ s/([^A-Za-z0-9\-_.~();\/;?:@&=])/sprintf
("%%%02X", ord($1))/eg
;
375 # replace invalid utf8 character with SUBSTITUTION sequence
378 $str = decode
("utf8", $str, Encode
::FB_DEFAULT
);
379 $str = escapeHTML
($str);
380 $str =~ s/\014/^L/g; # escape FORM FEED (FF) character (e.g. in COPYING file)
384 # git may return quoted and escaped filenames
387 if ($str =~ m/^"(.*)"$/) {
389 $str =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
394 # escape tabs (convert tabs to spaces)
398 while ((my $pos = index($line, "\t")) != -1) {
399 if (my $count = (8 - ($pos % 8))) {
400 my $spaces = ' ' x
$count;
401 $line =~ s/\t/$spaces/;
408 ## ----------------------------------------------------------------------
409 ## HTML aware string manipulation
414 my $add_len = shift || 10;
416 # allow only $len chars, but don't cut a word if it would fit in $add_len
417 # if it doesn't fit, cut it if it's still longer than the dots we would add
418 $str =~ m/^(.{0,$len}[^ \/\
-_
:\
.@
]{0,$add_len})(.*)/;
421 if (length($tail) > 4) {
423 $body =~ s/&[^;]*$//; # remove chopped character entities
428 ## ----------------------------------------------------------------------
429 ## functions returning short strings
431 # CSS class for given age value (in seconds)
435 if ($age < 60*60*2) {
437 } elsif ($age < 60*60*24*2) {
444 # convert age in seconds to "nn units ago" string
449 if ($age > 60*60*24*365*2) {
450 $age_str = (int $age/60/60/24/365);
451 $age_str .= " years ago";
452 } elsif ($age > 60*60*24*(365/12)*2) {
453 $age_str = int $age/60/60/24/(365/12);
454 $age_str .= " months ago";
455 } elsif ($age > 60*60*24*7*2) {
456 $age_str = int $age/60/60/24/7;
457 $age_str .= " weeks ago";
458 } elsif ($age > 60*60*24*2) {
459 $age_str = int $age/60/60/24;
460 $age_str .= " days ago";
461 } elsif ($age > 60*60*2) {
462 $age_str = int $age/60/60;
463 $age_str .= " hours ago";
464 } elsif ($age > 60*2) {
465 $age_str = int $age/60;
466 $age_str .= " min ago";
469 $age_str .= " sec ago";
471 $age_str .= " right now";
476 # convert file mode in octal to symbolic file mode string
478 my $mode = oct shift;
480 if (S_ISDIR
($mode & S_IFMT
)) {
482 } elsif (S_ISLNK
($mode)) {
484 } elsif (S_ISREG
($mode)) {
485 # git cares only about the executable bit
486 if ($mode & S_IXUSR
) {
496 # convert file mode in octal to file type string
500 if ($mode !~ m/^[0-7]+$/) {
506 if (S_ISDIR
($mode & S_IFMT
)) {
508 } elsif (S_ISLNK
($mode)) {
510 } elsif (S_ISREG
($mode)) {
517 ## ----------------------------------------------------------------------
518 ## functions returning short HTML fragments, or transforming HTML fragments
519 ## which don't beling to other sections
521 # format line of commit message or tag comment
522 sub format_log_line_html
{
525 $line = esc_html
($line);
526 $line =~ s/ / /g;
527 if ($line =~ m/([0-9a-fA-F]{40})/) {
529 if (git_get_type
($hash_text) eq "commit") {
531 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$hash_text),
532 -class => "text"}, $hash_text);
533 $line =~ s/$hash_text/$link/;
539 # format marker of refs pointing to given object
540 sub format_ref_marker
{
541 my ($refs, $id) = @_;
544 if (defined $refs->{$id}) {
545 foreach my $ref (@
{$refs->{$id}}) {
546 my ($type, $name) = qw();
547 # e.g. tags/v2.6.11 or heads/next
548 if ($ref =~ m!^(.*?)s?/(.*)$!) {
556 $markers .= " <span class=\"$type\">" . esc_html
($name) . "</span>";
561 return ' <span class="refs">'. $markers . '</span>';
567 # format, perhaps shortened and with markers, title line
568 sub format_subject_html
{
569 my ($long, $short, $href, $extra) = @_;
570 $extra = '' unless defined($extra);
572 if (length($short) < length($long)) {
573 return $cgi->a({-href
=> $href, -class => "list subject",
575 esc_html
($short) . $extra);
577 return $cgi->a({-href
=> $href, -class => "list subject"},
578 esc_html
($long) . $extra);
582 sub format_diff_line
{
584 my $char = substr($line, 0, 1);
590 $diff_class = " add";
591 } elsif ($char eq "-") {
592 $diff_class = " rem";
593 } elsif ($char eq "@") {
594 $diff_class = " chunk_header";
595 } elsif ($char eq "\\") {
596 $diff_class = " incomplete";
598 $line = untabify
($line);
599 return "<div class=\"diff$diff_class\">" . esc_html
($line) . "</div>\n";
602 ## ----------------------------------------------------------------------
603 ## git utility subroutines, invoking git commands
605 # returns path to the core git executable and the --git-dir parameter as list
607 return $GIT, '--git-dir='.$git_dir;
610 # returns path to the core git executable and the --git-dir parameter as string
612 return join(' ', git_cmd
());
615 # get HEAD ref of given project as hash
616 sub git_get_head_hash
{
618 my $o_git_dir = $git_dir;
620 $git_dir = "$projectroot/$project";
621 if (open my $fd, "-|", git_cmd
(), "rev-parse", "--verify", "HEAD") {
624 if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
628 if (defined $o_git_dir) {
629 $git_dir = $o_git_dir;
634 # get type of given object
638 open my $fd, "-|", git_cmd
(), "cat-file", '-t', $hash or return;
645 sub git_get_project_config
{
646 my ($key, $type) = @_;
648 return unless ($key);
649 $key =~ s/^gitweb\.//;
650 return if ($key =~ m/\W/);
652 my @x = (git_cmd
(), 'repo-config');
653 if (defined $type) { push @x, $type; }
655 push @x, "gitweb.$key";
661 # get hash of given path at given ref
662 sub git_get_hash_by_path
{
664 my $path = shift || return undef;
668 open my $fd, "-|", git_cmd
(), "ls-tree", $base, "--", $path
669 or die_error
(undef, "Open git-ls-tree failed");
671 close $fd or return undef;
673 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
674 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
678 ## ......................................................................
679 ## git utility functions, directly accessing git repository
681 sub git_get_project_description
{
684 open my $fd, "$projectroot/$path/description" or return undef;
691 sub git_get_project_url_list
{
694 open my $fd, "$projectroot/$path/cloneurl" or return undef;
695 my @git_project_url_list = map { chomp; $_ } <$fd>;
698 return wantarray ?
@git_project_url_list : \
@git_project_url_list;
701 sub git_get_projects_list
{
704 if (-d
$projects_list) {
705 # search in directory
706 my $dir = $projects_list;
707 my $pfxlen = length("$dir");
710 follow_fast
=> 1, # follow symbolic links
711 dangling_symlinks
=> 0, # ignore dangling symlinks, silently
713 # skip project-list toplevel, if we get it.
714 return if (m!^[/.]$!);
715 # only directories can be git repositories
716 return unless (-d
$_);
718 my $subdir = substr($File::Find
::name
, $pfxlen + 1);
719 # we check related file in $projectroot
720 if (-e
"$projectroot/$subdir/HEAD") {
721 push @list, { path
=> $subdir };
722 $File::Find
::prune
= 1;
727 } elsif (-f
$projects_list) {
728 # read from file(url-encoded):
729 # 'git%2Fgit.git Linus+Torvalds'
730 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
731 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
732 open my ($fd), $projects_list or return undef;
733 while (my $line = <$fd>) {
735 my ($path, $owner) = split ' ', $line;
736 $path = unescape
($path);
737 $owner = unescape
($owner);
738 if (!defined $path) {
741 if (-e
"$projectroot/$path/HEAD") {
744 owner
=> decode
("utf8", $owner, Encode
::FB_DEFAULT
),
751 @list = sort {$a->{'path'} cmp $b->{'path'}} @list;
755 sub git_get_project_owner
{
759 return undef unless $project;
761 # read from file (url-encoded):
762 # 'git%2Fgit.git Linus+Torvalds'
763 # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
764 # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
765 if (-f
$projects_list) {
766 open (my $fd , $projects_list);
767 while (my $line = <$fd>) {
769 my ($pr, $ow) = split ' ', $line;
772 if ($pr eq $project) {
773 $owner = decode
("utf8", $ow, Encode
::FB_DEFAULT
);
779 if (!defined $owner) {
780 $owner = get_file_owner
("$projectroot/$project");
786 sub git_get_references
{
787 my $type = shift || "";
790 # 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
791 # c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
792 if (-f
"$projectroot/$project/info/refs") {
793 open $fd, "$projectroot/$project/info/refs"
796 open $fd, "-|", git_cmd
(), "ls-remote", "."
800 while (my $line = <$fd>) {
802 if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\
/?[^\^]+)/) {
803 if (defined $refs{$1}) {
804 push @
{$refs{$1}}, $2;
814 sub git_get_rev_name_tags
{
815 my $hash = shift || return undef;
817 open my $fd, "-|", git_cmd
(), "name-rev", "--tags", $hash
819 my $name_rev = <$fd>;
822 if ($name_rev =~ m
|^$hash tags
/(.*)$|) {
825 # catches also '$hash undefined' output
830 ## ----------------------------------------------------------------------
831 ## parse to hash functions
835 my $tz = shift || "-0000";
838 my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
839 my @days = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
840 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($epoch);
841 $date{'hour'} = $hour;
842 $date{'minute'} = $min;
843 $date{'mday'} = $mday;
844 $date{'day'} = $days[$wday];
845 $date{'month'} = $months[$mon];
846 $date{'rfc2822'} = sprintf "%s, %d %s %4d %02d:%02d:%02d +0000",
847 $days[$wday], $mday, $months[$mon], 1900+$year, $hour ,$min, $sec;
848 $date{'mday-time'} = sprintf "%d %s %02d:%02d",
849 $mday, $months[$mon], $hour ,$min;
851 $tz =~ m/^([+\-][0-9][0-9])([0-9][0-9])$/;
852 my $local = $epoch + ((int $1 + ($2/60)) * 3600);
853 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($local);
854 $date{'hour_local'} = $hour;
855 $date{'minute_local'} = $min;
856 $date{'tz_local'} = $tz;
865 open my $fd, "-|", git_cmd
(), "cat-file", "tag", $tag_id or return;
866 $tag{'id'} = $tag_id;
867 while (my $line = <$fd>) {
869 if ($line =~ m/^object ([0-9a-fA-F]{40})$/) {
871 } elsif ($line =~ m/^type (.+)$/) {
873 } elsif ($line =~ m/^tag (.+)$/) {
875 } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) {
879 } elsif ($line =~ m/--BEGIN/) {
880 push @comment, $line;
882 } elsif ($line eq "") {
886 push @comment, <$fd>;
887 $tag{'comment'} = \
@comment;
889 if (!defined $tag{'name'}) {
896 my $commit_id = shift;
897 my $commit_text = shift;
902 if (defined $commit_text) {
903 @commit_lines = @
$commit_text;
906 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", "--max-count=1", $commit_id
908 @commit_lines = split '\n', <$fd>;
913 my $header = shift @commit_lines;
914 if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
917 ($co{'id'}, my @parents) = split ' ', $header;
918 $co{'parents'} = \
@parents;
919 $co{'parent'} = $parents[0];
920 while (my $line = shift @commit_lines) {
921 last if $line eq "\n";
922 if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
924 } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) {
926 $co{'author_epoch'} = $2;
927 $co{'author_tz'} = $3;
928 if ($co{'author'} =~ m/^([^<]+) </) {
929 $co{'author_name'} = $1;
931 $co{'author_name'} = $co{'author'};
933 } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) {
934 $co{'committer'} = $1;
935 $co{'committer_epoch'} = $2;
936 $co{'committer_tz'} = $3;
937 $co{'committer_name'} = $co{'committer'};
938 $co{'committer_name'} =~ s/ <.*//;
941 if (!defined $co{'tree'}) {
945 foreach my $title (@commit_lines) {
948 $co{'title'} = chop_str
($title, 80, 5);
949 # remove leading stuff of merges to make the interesting part visible
950 if (length($title) > 50) {
951 $title =~ s/^Automatic //;
952 $title =~ s/^merge (of|with) /Merge ... /i;
953 if (length($title) > 50) {
954 $title =~ s/(http|rsync):\/\///;
956 if (length($title) > 50) {
957 $title =~ s/(master|www|rsync)\.//;
959 if (length($title) > 50) {
960 $title =~ s/kernel.org:?//;
962 if (length($title) > 50) {
963 $title =~ s/\/pub\/scm//;
966 $co{'title_short'} = chop_str
($title, 50, 5);
970 # remove added spaces
971 foreach my $line (@commit_lines) {
974 $co{'comment'} = \
@commit_lines;
976 my $age = time - $co{'committer_epoch'};
978 $co{'age_string'} = age_string
($age);
979 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($co{'committer_epoch'});
980 if ($age > 60*60*24*7*2) {
981 $co{'age_string_date'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
982 $co{'age_string_age'} = $co{'age_string'};
984 $co{'age_string_date'} = $co{'age_string'};
985 $co{'age_string_age'} = sprintf "%4i-%02u-%02i", 1900 + $year, $mon+1, $mday;
990 # parse ref from ref_file, given by ref_id, with given type
992 my $ref_file = shift;
994 my $type = shift || git_get_type
($ref_id);
997 $ref_item{'type'} = $type;
998 $ref_item{'id'} = $ref_id;
999 $ref_item{'epoch'} = 0;
1000 $ref_item{'age'} = "unknown";
1001 if ($type eq "tag") {
1002 my %tag = parse_tag
($ref_id);
1003 $ref_item{'comment'} = $tag{'comment'};
1004 if ($tag{'type'} eq "commit") {
1005 my %co = parse_commit
($tag{'object'});
1006 $ref_item{'epoch'} = $co{'committer_epoch'};
1007 $ref_item{'age'} = $co{'age_string'};
1008 } elsif (defined($tag{'epoch'})) {
1009 my $age = time - $tag{'epoch'};
1010 $ref_item{'epoch'} = $tag{'epoch'};
1011 $ref_item{'age'} = age_string
($age);
1013 $ref_item{'reftype'} = $tag{'type'};
1014 $ref_item{'name'} = $tag{'name'};
1015 $ref_item{'refid'} = $tag{'object'};
1016 } elsif ($type eq "commit"){
1017 my %co = parse_commit
($ref_id);
1018 $ref_item{'reftype'} = "commit";
1019 $ref_item{'name'} = $ref_file;
1020 $ref_item{'title'} = $co{'title'};
1021 $ref_item{'refid'} = $ref_id;
1022 $ref_item{'epoch'} = $co{'committer_epoch'};
1023 $ref_item{'age'} = $co{'age_string'};
1025 $ref_item{'reftype'} = $type;
1026 $ref_item{'name'} = $ref_file;
1027 $ref_item{'refid'} = $ref_id;
1033 # parse line of git-diff-tree "raw" output
1034 sub parse_difftree_raw_line
{
1038 # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M ls-files.c'
1039 # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M rev-tree.c'
1040 if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
1041 $res{'from_mode'} = $1;
1042 $res{'to_mode'} = $2;
1043 $res{'from_id'} = $3;
1045 $res{'status'} = $5;
1046 $res{'similarity'} = $6;
1047 if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
1048 ($res{'from_file'}, $res{'to_file'}) = map { unquote
($_) } split("\t", $7);
1050 $res{'file'} = unquote
($7);
1053 # 'c512b523472485aef4fff9e57b229d9d243c967f'
1054 elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
1055 $res{'commit'} = $1;
1058 return wantarray ?
%res : \
%res;
1061 # parse line of git-ls-tree output
1062 sub parse_ls_tree_line
($;%) {
1067 #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
1068 $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/;
1076 $res{'name'} = unquote
($4);
1079 return wantarray ?
%res : \
%res;
1082 ## ......................................................................
1083 ## parse to array of hashes functions
1085 sub git_get_refs_list
{
1086 my $ref_dir = shift;
1090 open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
1092 while (my $line = <$fd>) {
1094 if ($line =~ m/^([0-9a-fA-F]{40})\t$ref_dir\/?
([^\
^]+)$/) {
1095 push @refs, { hash
=> $1, name
=> $2 };
1096 } elsif ($line =~ m/^[0-9a-fA-F]{40}\t$ref_dir\/?
(.*)\
^\
{\
}$/ &&
1097 $1 eq $refs[-1]{'name'}) {
1098 # most likely a tag is followed by its peeled
1099 # (deref) one, and when that happens we know the
1100 # previous one was of type 'tag'.
1101 $refs[-1]{'type'} = "tag";
1106 foreach my $ref (@refs) {
1107 my $ref_file = $ref->{'name'};
1108 my $ref_id = $ref->{'hash'};
1110 my $type = $ref->{'type'} || git_get_type
($ref_id) || next;
1111 my %ref_item = parse_ref
($ref_file, $ref_id, $type);
1113 push @reflist, \
%ref_item;
1116 @reflist = sort {$b->{'epoch'} <=> $a->{'epoch'}} @reflist;
1120 ## ----------------------------------------------------------------------
1121 ## filesystem-related functions
1123 sub get_file_owner
{
1126 my ($dev, $ino, $mode, $nlink, $st_uid, $st_gid, $rdev, $size) = stat($path);
1127 my ($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid($st_uid);
1128 if (!defined $gcos) {
1132 $owner =~ s/[,;].*$//;
1133 return decode
("utf8", $owner, Encode
::FB_DEFAULT
);
1136 ## ......................................................................
1137 ## mimetype related functions
1139 sub mimetype_guess_file
{
1140 my $filename = shift;
1141 my $mimemap = shift;
1142 -r
$mimemap or return undef;
1145 open(MIME
, $mimemap) or return undef;
1147 next if m/^#/; # skip comments
1148 my ($mime, $exts) = split(/\t+/);
1149 if (defined $exts) {
1150 my @exts = split(/\s+/, $exts);
1151 foreach my $ext (@exts) {
1152 $mimemap{$ext} = $mime;
1158 $filename =~ /\.(.*?)$/;
1159 return $mimemap{$1};
1162 sub mimetype_guess
{
1163 my $filename = shift;
1165 $filename =~ /\./ or return undef;
1167 if ($mimetypes_file) {
1168 my $file = $mimetypes_file;
1169 if ($file !~ m!^/!) { # if it is relative path
1170 # it is relative to project
1171 $file = "$projectroot/$project/$file";
1173 $mime = mimetype_guess_file
($filename, $file);
1175 $mime ||= mimetype_guess_file
($filename, '/etc/mime.types');
1181 my $filename = shift;
1184 my $mime = mimetype_guess
($filename);
1185 $mime and return $mime;
1189 return $default_blob_plain_mimetype unless $fd;
1192 return 'text/plain' .
1193 ($default_text_plain_charset ?
'; charset='.$default_text_plain_charset : '');
1194 } elsif (! $filename) {
1195 return 'application/octet-stream';
1196 } elsif ($filename =~ m/\.png$/i) {
1198 } elsif ($filename =~ m/\.gif$/i) {
1200 } elsif ($filename =~ m/\.jpe?g$/i) {
1201 return 'image/jpeg';
1203 return 'application/octet-stream';
1207 ## ======================================================================
1208 ## functions printing HTML: header, footer, error page
1210 sub git_header_html
{
1211 my $status = shift || "200 OK";
1212 my $expires = shift;
1214 my $title = "$site_name git";
1215 if (defined $project) {
1216 $title .= " - $project";
1217 if (defined $action) {
1218 $title .= "/$action";
1219 if (defined $file_name) {
1220 $title .= " - $file_name";
1221 if ($action eq "tree" && $file_name !~ m
|/$|) {
1228 # require explicit support from the UA if we are to send the page as
1229 # 'application/xhtml+xml', otherwise send it as plain old 'text/html'.
1230 # we have to do this because MSIE sometimes globs '*/*', pretending to
1231 # support xhtml+xml but choking when it gets what it asked for.
1232 if (defined $cgi->http('HTTP_ACCEPT') &&
1233 $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\
+xml
(,|;|\s
|$)/ &&
1234 $cgi->Accept('application/xhtml+xml') != 0) {
1235 $content_type = 'application/xhtml+xml';
1237 $content_type = 'text/html';
1239 print $cgi->header(-type
=>$content_type, -charset
=> 'utf-8',
1240 -status
=> $status, -expires
=> $expires);
1242 <?xml version="1.0" encoding="utf-8"?>
1243 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
1244 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
1245 <!-- git web interface version $version, (C) 2005-2006, Kay Sievers <kay.sievers\@vrfy.org>, Christian Gierke -->
1246 <!-- git core binaries version $git_version -->
1248 <meta http-equiv="content-type" content="$content_type; charset=utf-8"/>
1249 <meta name="generator" content="gitweb/$version git/$git_version"/>
1250 <meta name="robots" content="index, nofollow"/>
1251 <title>$title</title>
1252 <link rel="stylesheet" type="text/css" href="$stylesheet"/>
1254 if (defined $project) {
1255 printf('<link rel="alternate" title="%s log" '.
1256 'href="%s" type="application/rss+xml"/>'."\n",
1257 esc_param
($project), href
(action
=>"rss"));
1259 printf('<link rel="alternate" title="%s projects list" '.
1260 'href="%s" type="text/plain; charset=utf-8"/>'."\n",
1261 $site_name, href
(project
=>undef, action
=>"project_index"));
1262 printf('<link rel="alternate" title="%s projects logs" '.
1263 'href="%s" type="text/x-opml"/>'."\n",
1264 $site_name, href
(project
=>undef, action
=>"opml"));
1266 if (defined $favicon) {
1267 print qq(<link rel
="shortcut icon" href
="$favicon" type
="image/png"/>\n);
1272 "<div class=\"page_header\">\n" .
1273 "<a href=\"http://www.kernel.org/pub/software/scm/git/docs/\" title=\"git documentation\">" .
1274 "<img src=\"$logo\" width=\"72\" height=\"27\" alt=\"git\" style=\"float:right; border-width:0px;\"/>" .
1276 print $cgi->a({-href
=> esc_param
($home_link)}, $home_link_str) . " / ";
1277 if (defined $project) {
1278 print $cgi->a({-href
=> href
(action
=>"summary")}, esc_html
($project));
1279 if (defined $action) {
1283 if (!defined $searchtext) {
1287 if (defined $hash_base) {
1288 $search_hash = $hash_base;
1289 } elsif (defined $hash) {
1290 $search_hash = $hash;
1292 $search_hash = "HEAD";
1294 $cgi->param("a", "search");
1295 $cgi->param("h", $search_hash);
1296 print $cgi->startform(-method
=> "get", -action
=> $my_uri) .
1297 "<div class=\"search\">\n" .
1298 $cgi->hidden(-name
=> "p") . "\n" .
1299 $cgi->hidden(-name
=> "a") . "\n" .
1300 $cgi->hidden(-name
=> "h") . "\n" .
1301 $cgi->textfield(-name
=> "s", -value
=> $searchtext) . "\n" .
1303 $cgi->end_form() . "\n";
1308 sub git_footer_html
{
1309 print "<div class=\"page_footer\">\n";
1310 if (defined $project) {
1311 my $descr = git_get_project_description
($project);
1312 if (defined $descr) {
1313 print "<div class=\"page_footer_text\">" . esc_html
($descr) . "</div>\n";
1315 print $cgi->a({-href
=> href
(action
=>"rss"),
1316 -class => "rss_logo"}, "RSS") . "\n";
1318 print $cgi->a({-href
=> href
(project
=>undef, action
=>"opml"),
1319 -class => "rss_logo"}, "OPML") . " ";
1320 print $cgi->a({-href
=> href
(project
=>undef, action
=>"project_index"),
1321 -class => "rss_logo"}, "TXT") . "\n";
1329 my $status = shift || "403 Forbidden";
1330 my $error = shift || "Malformed query, file missing or permission denied";
1332 git_header_html
($status);
1334 <div class="page_body">
1344 ## ----------------------------------------------------------------------
1345 ## functions printing or outputting HTML: navigation
1347 sub git_print_page_nav
{
1348 my ($current, $suppress, $head, $treehead, $treebase, $extra) = @_;
1349 $extra = '' if !defined $extra; # pager or formats
1351 my @navs = qw(summary shortlog log commit commitdiff tree);
1353 @navs = grep { $_ ne $suppress } @navs;
1356 my %arg = map { $_ => {action
=>$_} } @navs;
1357 if (defined $head) {
1358 for (qw(commit commitdiff)) {
1359 $arg{$_}{hash
} = $head;
1361 if ($current =~ m/^(tree | log | shortlog | commit | commitdiff | search)$/x) {
1362 for (qw(shortlog log)) {
1363 $arg{$_}{hash
} = $head;
1367 $arg{tree
}{hash
} = $treehead if defined $treehead;
1368 $arg{tree
}{hash_base
} = $treebase if defined $treebase;
1370 print "<div class=\"page_nav\">\n" .
1372 map { $_ eq $current ?
1373 $_ : $cgi->a({-href
=> href
(%{$arg{$_}})}, "$_")
1375 print "<br/>\n$extra<br/>\n" .
1379 sub format_paging_nav
{
1380 my ($action, $hash, $head, $page, $nrevs) = @_;
1384 if ($hash ne $head || $page) {
1385 $paging_nav .= $cgi->a({-href
=> href
(action
=>$action)}, "HEAD");
1387 $paging_nav .= "HEAD";
1391 $paging_nav .= " ⋅ " .
1392 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page-1),
1393 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
1395 $paging_nav .= " ⋅ prev";
1398 if ($nrevs >= (100 * ($page+1)-1)) {
1399 $paging_nav .= " ⋅ " .
1400 $cgi->a({-href
=> href
(action
=>$action, hash
=>$hash, page
=>$page+1),
1401 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
1403 $paging_nav .= " ⋅ next";
1409 ## ......................................................................
1410 ## functions printing or outputting HTML: div
1412 sub git_print_header_div
{
1413 my ($action, $title, $hash, $hash_base) = @_;
1416 $args{action
} = $action;
1417 $args{hash
} = $hash if $hash;
1418 $args{hash_base
} = $hash_base if $hash_base;
1420 print "<div class=\"header\">\n" .
1421 $cgi->a({-href
=> href
(%args), -class => "title"},
1422 $title ?
$title : $action) .
1426 #sub git_print_authorship (\%) {
1427 sub git_print_authorship
{
1430 my %ad = parse_date
($co->{'author_epoch'}, $co->{'author_tz'});
1431 print "<div class=\"author_date\">" .
1432 esc_html
($co->{'author_name'}) .
1434 if ($ad{'hour_local'} < 6) {
1435 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
1436 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1438 printf(" (%02d:%02d %s)",
1439 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
1444 sub git_print_page_path
{
1449 if (!defined $name) {
1450 print "<div class=\"page_path\">/</div>\n";
1452 my @dirname = split '/', $name;
1453 my $basename = pop @dirname;
1456 print "<div class=\"page_path\">";
1457 foreach my $dir (@dirname) {
1458 $fullname .= $dir . '/';
1459 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$fullname,
1461 -title
=> $fullname}, esc_html
($dir));
1464 if (defined $type && $type eq 'blob') {
1465 print $cgi->a({-href
=> href
(action
=>"blob_plain", file_name
=>$file_name,
1467 -title
=> $name}, esc_html
($basename));
1468 } elsif (defined $type && $type eq 'tree') {
1469 print $cgi->a({-href
=> href
(action
=>"tree", file_name
=>$file_name,
1471 -title
=> $name}, esc_html
($basename));
1474 print esc_html
($basename);
1476 print "<br/></div>\n";
1480 # sub git_print_log (\@;%) {
1481 sub git_print_log
($;%) {
1485 if ($opts{'-remove_title'}) {
1486 # remove title, i.e. first line of log
1489 # remove leading empty lines
1490 while (defined $log->[0] && $log->[0] eq "") {
1497 foreach my $line (@
$log) {
1498 if ($line =~ m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i) {
1501 if (! $opts{'-remove_signoff'}) {
1502 print "<span class=\"signoff\">" . esc_html
($line) . "</span><br/>\n";
1505 # remove signoff lines
1512 # print only one empty line
1513 # do not print empty line after signoff
1515 next if ($empty || $signoff);
1521 print format_log_line_html
($line) . "<br/>\n";
1524 if ($opts{'-final_empty_line'}) {
1525 # end with single empty line
1526 print "<br/>\n" unless $empty;
1530 sub git_print_simplified_log
{
1532 my $remove_title = shift;
1535 -final_empty_line
=> 1,
1536 -remove_title
=> $remove_title);
1539 # print tree entry (row of git_tree), but without encompassing <tr> element
1540 sub git_print_tree_entry
{
1541 my ($t, $basedir, $hash_base, $have_blame) = @_;
1544 $base_key{hash_base
} = $hash_base if defined $hash_base;
1546 print "<td class=\"mode\">" . mode_str
($t->{'mode'}) . "</td>\n";
1547 if ($t->{'type'} eq "blob") {
1548 print "<td class=\"list\">" .
1549 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
1550 file_name
=>"$basedir$t->{'name'}", %base_key),
1551 -class => "list"}, esc_html
($t->{'name'})) .
1553 "<td class=\"link\">" .
1554 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$t->{'hash'},
1555 file_name
=>"$basedir$t->{'name'}", %base_key)},
1559 $cgi->a({-href
=> href
(action
=>"blame", hash
=>$t->{'hash'},
1560 file_name
=>"$basedir$t->{'name'}", %base_key)},
1563 if (defined $hash_base) {
1565 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1566 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
1570 $cgi->a({-href
=> href
(action
=>"blob_plain",
1571 hash
=>$t->{'hash'}, file_name
=>"$basedir$t->{'name'}")},
1575 } elsif ($t->{'type'} eq "tree") {
1576 print "<td class=\"list\">" .
1577 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
1578 file_name
=>"$basedir$t->{'name'}", %base_key)},
1579 esc_html
($t->{'name'})) .
1581 "<td class=\"link\">" .
1582 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$t->{'hash'},
1583 file_name
=>"$basedir$t->{'name'}", %base_key)},
1585 if (defined $hash_base) {
1587 $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$hash_base,
1588 file_name
=>"$basedir$t->{'name'}")},
1595 ## ......................................................................
1596 ## functions printing large fragments of HTML
1598 sub git_difftree_body
{
1599 my ($difftree, $hash, $parent) = @_;
1601 print "<div class=\"list_head\">\n";
1602 if ($#{$difftree} > 10) {
1603 print(($#{$difftree} + 1) . " files changed:\n");
1607 print "<table class=\"diff_tree\">\n";
1610 foreach my $line (@
{$difftree}) {
1611 my %diff = parse_difftree_raw_line
($line);
1614 print "<tr class=\"dark\">\n";
1616 print "<tr class=\"light\">\n";
1620 my ($to_mode_oct, $to_mode_str, $to_file_type);
1621 my ($from_mode_oct, $from_mode_str, $from_file_type);
1622 if ($diff{'to_mode'} ne ('0' x
6)) {
1623 $to_mode_oct = oct $diff{'to_mode'};
1624 if (S_ISREG
($to_mode_oct)) { # only for regular file
1625 $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
1627 $to_file_type = file_type
($diff{'to_mode'});
1629 if ($diff{'from_mode'} ne ('0' x
6)) {
1630 $from_mode_oct = oct $diff{'from_mode'};
1631 if (S_ISREG
($to_mode_oct)) { # only for regular file
1632 $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
1634 $from_file_type = file_type
($diff{'from_mode'});
1637 if ($diff{'status'} eq "A") { # created
1638 my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
1639 $mode_chng .= " with mode: $to_mode_str" if $to_mode_str;
1640 $mode_chng .= "]</span>";
1642 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1643 hash_base
=>$hash, file_name
=>$diff{'file'}),
1644 -class => "list"}, esc_html
($diff{'file'})) .
1646 "<td>$mode_chng</td>\n" .
1647 "<td class=\"link\">" .
1648 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1649 hash_base
=>$hash, file_name
=>$diff{'file'})},
1651 if ($action eq 'commitdiff') {
1655 $cgi->a({-href
=> "#patch$patchno"}, "patch");
1659 } elsif ($diff{'status'} eq "D") { # deleted
1660 my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
1662 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1663 hash_base
=>$parent, file_name
=>$diff{'file'}),
1664 -class => "list"}, esc_html
($diff{'file'})) .
1666 "<td>$mode_chng</td>\n" .
1667 "<td class=\"link\">" .
1668 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'from_id'},
1669 hash_base
=>$parent, file_name
=>$diff{'file'})},
1672 if ($action eq 'commitdiff') {
1676 $cgi->a({-href
=> "#patch$patchno"}, "patch");
1678 print $cgi->a({-href
=> href
(action
=>"history", hash_base
=>$parent,
1679 file_name
=>$diff{'file'})},
1683 } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
1684 my $mode_chnge = "";
1685 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1686 $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
1687 if ($from_file_type != $to_file_type) {
1688 $mode_chnge .= " from $from_file_type to $to_file_type";
1690 if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
1691 if ($from_mode_str && $to_mode_str) {
1692 $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
1693 } elsif ($to_mode_str) {
1694 $mode_chnge .= " mode: $to_mode_str";
1697 $mode_chnge .= "]</span>\n";
1700 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1701 print $cgi->a({-href
=> href
(action
=>"blobdiff",
1702 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1703 hash_base
=>$hash, hash_parent_base
=>$parent,
1704 file_name
=>$diff{'file'}),
1705 -class => "list"}, esc_html
($diff{'file'}));
1706 } else { # only mode changed
1707 print $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1708 hash_base
=>$hash, file_name
=>$diff{'file'}),
1709 -class => "list"}, esc_html
($diff{'file'}));
1712 "<td>$mode_chnge</td>\n" .
1713 "<td class=\"link\">" .
1714 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$diff{'to_id'},
1715 hash_base
=>$hash, file_name
=>$diff{'file'})},
1717 if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
1718 if ($action eq 'commitdiff') {
1722 $cgi->a({-href
=> "#patch$patchno"}, "patch");
1725 $cgi->a({-href
=> href
(action
=>"blobdiff",
1726 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1727 hash_base
=>$hash, hash_parent_base
=>$parent,
1728 file_name
=>$diff{'file'})},
1733 $cgi->a({-href
=> href
(action
=>"history",
1734 hash_base
=>$hash, file_name
=>$diff{'file'})},
1738 } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
1739 my %status_name = ('R' => 'moved', 'C' => 'copied');
1740 my $nstatus = $status_name{$diff{'status'}};
1742 if ($diff{'from_mode'} != $diff{'to_mode'}) {
1743 # mode also for directories, so we cannot use $to_mode_str
1744 $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
1747 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1748 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'}),
1749 -class => "list"}, esc_html
($diff{'to_file'})) . "</td>\n" .
1750 "<td><span class=\"file_status $nstatus\">[$nstatus from " .
1751 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$parent,
1752 hash
=>$diff{'from_id'}, file_name
=>$diff{'from_file'}),
1753 -class => "list"}, esc_html
($diff{'from_file'})) .
1754 " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
1755 "<td class=\"link\">" .
1756 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1757 hash
=>$diff{'to_id'}, file_name
=>$diff{'to_file'})},
1759 if ($diff{'to_id'} ne $diff{'from_id'}) {
1760 if ($action eq 'commitdiff') {
1764 $cgi->a({-href
=> "#patch$patchno"}, "patch");
1767 $cgi->a({-href
=> href
(action
=>"blobdiff",
1768 hash
=>$diff{'to_id'}, hash_parent
=>$diff{'from_id'},
1769 hash_base
=>$hash, hash_parent_base
=>$parent,
1770 file_name
=>$diff{'to_file'}, file_parent
=>$diff{'from_file'})},
1776 } # we should not encounter Unmerged (U) or Unknown (X) status
1782 sub git_patchset_body
{
1783 my ($fd, $difftree, $hash, $hash_parent) = @_;
1787 my $patch_found = 0;
1790 print "<div class=\"patchset\">\n";
1793 while (my $patch_line = <$fd>) {
1796 if ($patch_line =~ m/^diff /) { # "git diff" header
1797 # beginning of patch (in patchset)
1799 # close previous patch
1800 print "</div>\n"; # class="patch"
1802 # first patch in patchset
1805 print "<div class=\"patch\" id=\"patch". ($patch_idx+1) ."\">\n";
1807 if (ref($difftree->[$patch_idx]) eq "HASH") {
1808 $diffinfo = $difftree->[$patch_idx];
1810 $diffinfo = parse_difftree_raw_line
($difftree->[$patch_idx]);
1814 # for now, no extended header, hence we skip empty patches
1815 # companion to next LINE if $in_header;
1816 if ($diffinfo->{'from_id'} eq $diffinfo->{'to_id'}) { # no change
1821 if ($diffinfo->{'status'} eq "A") { # added
1822 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'to_mode'}) . ":" .
1823 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1824 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
1825 $diffinfo->{'to_id'}) . "(new)" .
1826 "</div>\n"; # class="diff_info"
1828 } elsif ($diffinfo->{'status'} eq "D") { # deleted
1829 print "<div class=\"diff_info\">" . file_type
($diffinfo->{'from_mode'}) . ":" .
1830 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1831 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
1832 $diffinfo->{'from_id'}) . "(deleted)" .
1833 "</div>\n"; # class="diff_info"
1835 } elsif ($diffinfo->{'status'} eq "R" || # renamed
1836 $diffinfo->{'status'} eq "C" || # copied
1837 $diffinfo->{'status'} eq "2") { # with two filenames (from git_blobdiff)
1838 print "<div class=\"diff_info\">" .
1839 file_type
($diffinfo->{'from_mode'}) . ":" .
1840 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1841 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'from_file'})},
1842 $diffinfo->{'from_id'}) .
1844 file_type
($diffinfo->{'to_mode'}) . ":" .
1845 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1846 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'to_file'})},
1847 $diffinfo->{'to_id'});
1848 print "</div>\n"; # class="diff_info"
1850 } else { # modified, mode changed, ...
1851 print "<div class=\"diff_info\">" .
1852 file_type
($diffinfo->{'from_mode'}) . ":" .
1853 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1854 hash
=>$diffinfo->{'from_id'}, file_name
=>$diffinfo->{'file'})},
1855 $diffinfo->{'from_id'}) .
1857 file_type
($diffinfo->{'to_mode'}) . ":" .
1858 $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1859 hash
=>$diffinfo->{'to_id'}, file_name
=>$diffinfo->{'file'})},
1860 $diffinfo->{'to_id'});
1861 print "</div>\n"; # class="diff_info"
1864 #print "<div class=\"diff extended_header\">\n";
1867 } # start of patch in patchset
1870 if ($in_header && $patch_line =~ m/^---/) {
1871 #print "</div>\n"; # class="diff extended_header"
1874 my $file = $diffinfo->{'from_file'};
1875 $file ||= $diffinfo->{'file'};
1876 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash_parent,
1877 hash
=>$diffinfo->{'from_id'}, file_name
=>$file),
1878 -class => "list"}, esc_html
($file));
1879 $patch_line =~ s
|a
/.*$|a/$file|g
;
1880 print "<div class=\"diff from_file\">$patch_line</div>\n";
1882 $patch_line = <$fd>;
1885 #$patch_line =~ m/^+++/;
1886 $file = $diffinfo->{'to_file'};
1887 $file ||= $diffinfo->{'file'};
1888 $file = $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$hash,
1889 hash
=>$diffinfo->{'to_id'}, file_name
=>$file),
1890 -class => "list"}, esc_html
($file));
1891 $patch_line =~ s
|b
/.*|b/$file|g
;
1892 print "<div class=\"diff to_file\">$patch_line</div>\n";
1896 next LINE
if $in_header;
1898 print format_diff_line
($patch_line);
1900 print "</div>\n" if $patch_found; # class="patch"
1902 print "</div>\n"; # class="patchset"
1905 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1907 sub git_shortlog_body
{
1908 # uses global variable $project
1909 my ($revlist, $from, $to, $refs, $extra) = @_;
1911 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
1912 my $have_snapshot = (defined $ctype && defined $suffix);
1914 $from = 0 unless defined $from;
1915 $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
1917 print "<table class=\"shortlog\" cellspacing=\"0\">\n";
1919 for (my $i = $from; $i <= $to; $i++) {
1920 my $commit = $revlist->[$i];
1921 #my $ref = defined $refs ? format_ref_marker($refs, $commit) : '';
1922 my $ref = format_ref_marker
($refs, $commit);
1923 my %co = parse_commit
($commit);
1925 print "<tr class=\"dark\">\n";
1927 print "<tr class=\"light\">\n";
1930 # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" .
1931 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1932 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 10)) . "</i></td>\n" .
1934 print format_subject_html
($co{'title'}, $co{'title_short'},
1935 href
(action
=>"commit", hash
=>$commit), $ref);
1937 "<td class=\"link\">" .
1938 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
1939 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff");
1940 if ($have_snapshot) {
1941 print " | " . $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$commit)}, "snapshot");
1946 if (defined $extra) {
1948 "<td colspan=\"4\">$extra</td>\n" .
1954 sub git_history_body
{
1955 # Warning: assumes constant type (blob or tree) during history
1956 my ($revlist, $from, $to, $refs, $hash_base, $ftype, $extra) = @_;
1958 $from = 0 unless defined $from;
1959 $to = $#{$revlist} unless (defined $to && $to <= $#{$revlist});
1961 print "<table class=\"history\" cellspacing=\"0\">\n";
1963 for (my $i = $from; $i <= $to; $i++) {
1964 if ($revlist->[$i] !~ m/^([0-9a-fA-F]{40})/) {
1969 my %co = parse_commit
($commit);
1974 my $ref = format_ref_marker
($refs, $commit);
1977 print "<tr class=\"dark\">\n";
1979 print "<tr class=\"light\">\n";
1982 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
1983 # shortlog uses chop_str($co{'author_name'}, 10)
1984 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 3)) . "</i></td>\n" .
1986 # originally git_history used chop_str($co{'title'}, 50)
1987 print format_subject_html
($co{'title'}, $co{'title_short'},
1988 href
(action
=>"commit", hash
=>$commit), $ref);
1990 "<td class=\"link\">" .
1991 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") . " | " .
1992 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") . " | " .
1993 $cgi->a({-href
=> href
(action
=>$ftype, hash_base
=>$commit, file_name
=>$file_name)}, $ftype);
1995 if ($ftype eq 'blob') {
1996 my $blob_current = git_get_hash_by_path
($hash_base, $file_name);
1997 my $blob_parent = git_get_hash_by_path
($commit, $file_name);
1998 if (defined $blob_current && defined $blob_parent &&
1999 $blob_current ne $blob_parent) {
2001 $cgi->a({-href
=> href
(action
=>"blobdiff",
2002 hash
=>$blob_current, hash_parent
=>$blob_parent,
2003 hash_base
=>$hash_base, hash_parent_base
=>$commit,
2004 file_name
=>$file_name)},
2011 if (defined $extra) {
2013 "<td colspan=\"4\">$extra</td>\n" .
2020 # uses global variable $project
2021 my ($taglist, $from, $to, $extra) = @_;
2022 $from = 0 unless defined $from;
2023 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2025 print "<table class=\"tags\" cellspacing=\"0\">\n";
2027 for (my $i = $from; $i <= $to; $i++) {
2028 my $entry = $taglist->[$i];
2030 my $comment_lines = $tag{'comment'};
2031 my $comment = shift @
$comment_lines;
2033 if (defined $comment) {
2034 $comment_short = chop_str
($comment, 30, 5);
2037 print "<tr class=\"dark\">\n";
2039 print "<tr class=\"light\">\n";
2042 print "<td><i>$tag{'age'}</i></td>\n" .
2044 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'}),
2045 -class => "list name"}, esc_html
($tag{'name'})) .
2048 if (defined $comment) {
2049 print format_subject_html
($comment, $comment_short,
2050 href
(action
=>"tag", hash
=>$tag{'id'}));
2053 "<td class=\"selflink\">";
2054 if ($tag{'type'} eq "tag") {
2055 print $cgi->a({-href
=> href
(action
=>"tag", hash
=>$tag{'id'})}, "tag");
2060 "<td class=\"link\">" . " | " .
2061 $cgi->a({-href
=> href
(action
=>$tag{'reftype'}, hash
=>$tag{'refid'})}, $tag{'reftype'});
2062 if ($tag{'reftype'} eq "commit") {
2063 print " | " . $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") .
2064 " | " . $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'refid'})}, "log");
2065 } elsif ($tag{'reftype'} eq "blob") {
2066 print " | " . $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$tag{'refid'})}, "raw");
2071 if (defined $extra) {
2073 "<td colspan=\"5\">$extra</td>\n" .
2079 sub git_heads_body
{
2080 # uses global variable $project
2081 my ($taglist, $head, $from, $to, $extra) = @_;
2082 $from = 0 unless defined $from;
2083 $to = $#{$taglist} if (!defined $to || $#{$taglist} < $to);
2085 print "<table class=\"heads\" cellspacing=\"0\">\n";
2087 for (my $i = $from; $i <= $to; $i++) {
2088 my $entry = $taglist->[$i];
2090 my $curr = $tag{'id'} eq $head;
2092 print "<tr class=\"dark\">\n";
2094 print "<tr class=\"light\">\n";
2097 print "<td><i>$tag{'age'}</i></td>\n" .
2098 ($tag{'id'} eq $head ?
"<td class=\"current_head\">" : "<td>") .
2099 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'}),
2100 -class => "list name"},esc_html
($tag{'name'})) .
2102 "<td class=\"link\">" .
2103 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$tag{'name'})}, "shortlog") . " | " .
2104 $cgi->a({-href
=> href
(action
=>"log", hash
=>$tag{'name'})}, "log") .
2108 if (defined $extra) {
2110 "<td colspan=\"3\">$extra</td>\n" .
2116 ## ======================================================================
2117 ## ======================================================================
2120 sub git_project_list
{
2121 my $order = $cgi->param('o');
2122 if (defined $order && $order !~ m/project|descr|owner|age/) {
2123 die_error
(undef, "Unknown order parameter");
2126 my @list = git_get_projects_list
();
2129 die_error
(undef, "No projects found");
2131 foreach my $pr (@list) {
2132 my $head = git_get_head_hash
($pr->{'path'});
2133 if (!defined $head) {
2136 $git_dir = "$projectroot/$pr->{'path'}";
2137 my %co = parse_commit
($head);
2141 $pr->{'commit'} = \
%co;
2142 if (!defined $pr->{'descr'}) {
2143 my $descr = git_get_project_description
($pr->{'path'}) || "";
2144 $pr->{'descr'} = chop_str
($descr, 25, 5);
2146 if (!defined $pr->{'owner'}) {
2147 $pr->{'owner'} = get_file_owner
("$projectroot/$pr->{'path'}") || "";
2149 push @projects, $pr;
2153 if (-f
$home_text) {
2154 print "<div class=\"index_include\">\n";
2155 open (my $fd, $home_text);
2160 print "<table class=\"project_list\">\n" .
2162 $order ||= "project";
2163 if ($order eq "project") {
2164 @projects = sort {$a->{'path'} cmp $b->{'path'}} @projects;
2165 print "<th>Project</th>\n";
2168 $cgi->a({-href
=> href
(project
=>undef, order
=>'project'),
2169 -class => "header"}, "Project") .
2172 if ($order eq "descr") {
2173 @projects = sort {$a->{'descr'} cmp $b->{'descr'}} @projects;
2174 print "<th>Description</th>\n";
2177 $cgi->a({-href
=> href
(project
=>undef, order
=>'descr'),
2178 -class => "header"}, "Description") .
2181 if ($order eq "owner") {
2182 @projects = sort {$a->{'owner'} cmp $b->{'owner'}} @projects;
2183 print "<th>Owner</th>\n";
2186 $cgi->a({-href
=> href
(project
=>undef, order
=>'owner'),
2187 -class => "header"}, "Owner") .
2190 if ($order eq "age") {
2191 @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
2192 print "<th>Last Change</th>\n";
2195 $cgi->a({-href
=> href
(project
=>undef, order
=>'age'),
2196 -class => "header"}, "Last Change") .
2199 print "<th></th>\n" .
2202 foreach my $pr (@projects) {
2204 print "<tr class=\"dark\">\n";
2206 print "<tr class=\"light\">\n";
2209 print "<td>" . $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary"),
2210 -class => "list"}, esc_html
($pr->{'path'})) . "</td>\n" .
2211 "<td>" . esc_html
($pr->{'descr'}) . "</td>\n" .
2212 "<td><i>" . chop_str
($pr->{'owner'}, 15) . "</i></td>\n";
2213 print "<td class=\"". age_class
($pr->{'commit'}{'age'}) . "\">" .
2214 $pr->{'commit'}{'age_string'} . "</td>\n" .
2215 "<td class=\"link\">" .
2216 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"summary")}, "summary") . " | " .
2217 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"shortlog")}, "shortlog") . " | " .
2218 $cgi->a({-href
=> href
(project
=>$pr->{'path'}, action
=>"log")}, "log") .
2226 sub git_project_index
{
2227 my @projects = git_get_projects_list
();
2230 -type
=> 'text/plain',
2231 -charset
=> 'utf-8',
2232 -content_disposition
=> qq(inline
; filename
="index.aux"));
2234 foreach my $pr (@projects) {
2235 if (!exists $pr->{'owner'}) {
2236 $pr->{'owner'} = get_file_owner
("$projectroot/$project");
2239 my ($path, $owner) = ($pr->{'path'}, $pr->{'owner'});
2240 # quote as in CGI::Util::encode, but keep the slash, and use '+' for ' '
2241 $path =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2242 $owner =~ s/([^a-zA-Z0-9_.\-\/ ])/sprintf
("%%%02X", ord($1))/eg
;
2246 print "$path $owner\n";
2251 my $descr = git_get_project_description
($project) || "none";
2252 my $head = git_get_head_hash
($project);
2253 my %co = parse_commit
($head);
2254 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2256 my $owner = git_get_project_owner
($project);
2258 my $refs = git_get_references
();
2260 git_print_page_nav
('summary','', $head);
2262 print "<div class=\"title\"> </div>\n";
2263 print "<table cellspacing=\"0\">\n" .
2264 "<tr><td>description</td><td>" . esc_html
($descr) . "</td></tr>\n" .
2265 "<tr><td>owner</td><td>$owner</td></tr>\n" .
2266 "<tr><td>last change</td><td>$cd{'rfc2822'}</td></tr>\n";
2267 # use per project git URL list in $projectroot/$project/cloneurl
2268 # or make project git URL from git base URL and project name
2269 my $url_tag = "URL";
2270 my @url_list = git_get_project_url_list
($project);
2271 @url_list = map { "$_/$project" } @git_base_url_list unless @url_list;
2272 foreach my $git_url (@url_list) {
2273 next unless $git_url;
2274 print "<tr><td>$url_tag</td><td>$git_url</td></tr>\n";
2279 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=17",
2280 git_get_head_hash
($project)
2281 or die_error
(undef, "Open git-rev-list failed");
2282 my @revlist = map { chomp; $_ } <$fd>;
2284 git_print_header_div
('shortlog');
2285 git_shortlog_body
(\
@revlist, 0, 15, $refs,
2286 $cgi->a({-href
=> href
(action
=>"shortlog")}, "..."));
2288 my $taglist = git_get_refs_list
("refs/tags");
2289 if (defined @
$taglist) {
2290 git_print_header_div
('tags');
2291 git_tags_body
($taglist, 0, 15,
2292 $cgi->a({-href
=> href
(action
=>"tags")}, "..."));
2295 my $headlist = git_get_refs_list
("refs/heads");
2296 if (defined @
$headlist) {
2297 git_print_header_div
('heads');
2298 git_heads_body
($headlist, $head, 0, 15,
2299 $cgi->a({-href
=> href
(action
=>"heads")}, "..."));
2306 my $head = git_get_head_hash
($project);
2308 git_print_page_nav
('','', $head,undef,$head);
2309 my %tag = parse_tag
($hash);
2310 git_print_header_div
('commit', esc_html
($tag{'name'}), $hash);
2311 print "<div class=\"title_text\">\n" .
2312 "<table cellspacing=\"0\">\n" .
2314 "<td>object</td>\n" .
2315 "<td>" . $cgi->a({-class => "list", -href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2316 $tag{'object'}) . "</td>\n" .
2317 "<td class=\"link\">" . $cgi->a({-href
=> href
(action
=>$tag{'type'}, hash
=>$tag{'object'})},
2318 $tag{'type'}) . "</td>\n" .
2320 if (defined($tag{'author'})) {
2321 my %ad = parse_date
($tag{'epoch'}, $tag{'tz'});
2322 print "<tr><td>author</td><td>" . esc_html
($tag{'author'}) . "</td></tr>\n";
2323 print "<tr><td></td><td>" . $ad{'rfc2822'} .
2324 sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) .
2327 print "</table>\n\n" .
2329 print "<div class=\"page_body\">";
2330 my $comment = $tag{'comment'};
2331 foreach my $line (@
$comment) {
2332 print esc_html
($line) . "<br/>\n";
2342 my ($have_blame) = gitweb_check_feature
('blame');
2344 die_error
('403 Permission denied', "Permission denied");
2346 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2347 $hash_base ||= git_get_head_hash
($project);
2348 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2349 my %co = parse_commit
($hash_base)
2350 or die_error
(undef, "Reading commit failed");
2351 if (!defined $hash) {
2352 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2353 or die_error
(undef, "Error looking up file");
2355 $ftype = git_get_type
($hash);
2356 if ($ftype !~ "blob") {
2357 die_error
("400 Bad Request", "Object is not a blob");
2359 open ($fd, "-|", git_cmd
(), "blame", '-l', $file_name, $hash_base)
2360 or die_error
(undef, "Open git-blame failed");
2363 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2366 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2368 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2369 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2370 git_print_page_path
($file_name, $ftype, $hash_base);
2371 my @rev_color = (qw(light2 dark2));
2372 my $num_colors = scalar(@rev_color);
2373 my $current_color = 0;
2376 <div class="page_body">
2377 <table class="blame">
2378 <tr><th>Commit</th><th>Line</th><th>Data</th></tr>
2381 /^([0-9a-fA-F]{40}).*?(\d+)\)\s{1}(\s*.*)/;
2383 my $rev = substr($full_rev, 0, 8);
2387 if (!defined $last_rev) {
2388 $last_rev = $full_rev;
2389 } elsif ($last_rev ne $full_rev) {
2390 $last_rev = $full_rev;
2391 $current_color = ++$current_color % $num_colors;
2393 print "<tr class=\"$rev_color[$current_color]\">\n";
2394 print "<td class=\"sha1\">" .
2395 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$full_rev, file_name
=>$file_name)},
2396 esc_html
($rev)) . "</td>\n";
2397 print "<td class=\"linenr\"><a id=\"l$lineno\" href=\"#l$lineno\" class=\"linenr\">" .
2398 esc_html
($lineno) . "</a></td>\n";
2399 print "<td class=\"pre\">" . esc_html
($data) . "</td>\n";
2405 or print "Reading blob failed\n";
2412 my ($have_blame) = gitweb_check_feature
('blame');
2414 die_error
('403 Permission denied', "Permission denied");
2416 die_error
('404 Not Found', "File name not defined") if (!$file_name);
2417 $hash_base ||= git_get_head_hash
($project);
2418 die_error
(undef, "Couldn't find base commit") unless ($hash_base);
2419 my %co = parse_commit
($hash_base)
2420 or die_error
(undef, "Reading commit failed");
2421 if (!defined $hash) {
2422 $hash = git_get_hash_by_path
($hash_base, $file_name, "blob")
2423 or die_error
(undef, "Error lookup file");
2425 open ($fd, "-|", git_cmd
(), "annotate", '-l', '-t', '-r', $file_name, $hash_base)
2426 or die_error
(undef, "Open git-annotate failed");
2429 $cgi->a({-href
=> href
(action
=>"blob", hash
=>$hash, hash_base
=>$hash_base, file_name
=>$file_name)},
2432 $cgi->a({-href
=> href
(action
=>"blame", file_name
=>$file_name)},
2434 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2435 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2436 git_print_page_path
($file_name, 'blob', $hash_base);
2437 print "<div class=\"page_body\">\n";
2439 <table class="blame">
2448 my @line_class = (qw(light dark));
2449 my $line_class_len = scalar (@line_class);
2450 my $line_class_num = $#line_class;
2451 while (my $line = <$fd>) {
2463 $line_class_num = ($line_class_num + 1) % $line_class_len;
2465 if ($line =~ m/^([0-9a-fA-F]{40})\t\(\s*([^\t]+)\t(\d+) [+-]\d\d\d\d\t(\d+)\)(.*)$/) {
2472 print qq( <tr
><td colspan
="5" class="error">Unable to parse
: $line</td></tr
>\n);
2475 $short_rev = substr ($long_rev, 0, 8);
2476 $age = time () - $time;
2477 $age_str = age_string
($age);
2478 $age_str =~ s/ / /g;
2479 $age_class = age_class
($age);
2480 $author = esc_html
($author);
2481 $author =~ s/ / /g;
2483 $data = untabify
($data);
2484 $data = esc_html
($data);
2487 <tr class="$line_class[$line_class_num]">
2488 <td class="sha1"><a href="${\href (action=>"commit", hash=>$long_rev)}" class="text">$short_rev..</a></td>
2489 <td class="$age_class">$age_str</td>
2491 <td class="linenr"><a id="$lineno" href="#$lineno" class="linenr">$lineno</a></td>
2492 <td class="pre">$data</td>
2495 } # while (my $line = <$fd>)
2496 print "</table>\n\n";
2498 or print "Reading blob failed.\n";
2504 my $head = git_get_head_hash
($project);
2506 git_print_page_nav
('','', $head,undef,$head);
2507 git_print_header_div
('summary', $project);
2509 my $taglist = git_get_refs_list
("refs/tags");
2510 if (defined @
$taglist) {
2511 git_tags_body
($taglist);
2517 my $head = git_get_head_hash
($project);
2519 git_print_page_nav
('','', $head,undef,$head);
2520 git_print_header_div
('summary', $project);
2522 my $taglist = git_get_refs_list
("refs/heads");
2523 if (defined @
$taglist) {
2524 git_heads_body
($taglist, $head);
2529 sub git_blob_plain
{
2530 # blobs defined by non-textual hash id's can be cached
2532 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2536 if (!defined $hash) {
2537 if (defined $file_name) {
2538 my $base = $hash_base || git_get_head_hash
($project);
2539 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2540 or die_error
(undef, "Error lookup file");
2542 die_error
(undef, "No file name defined");
2546 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2547 or die_error
(undef, "Couldn't cat $file_name, $hash");
2549 $type ||= blob_mimetype
($fd, $file_name);
2551 # save as filename, even when no $file_name is given
2552 my $save_as = "$hash";
2553 if (defined $file_name) {
2554 $save_as = $file_name;
2555 } elsif ($type =~ m/^text\//) {
2562 -content_disposition
=> "inline; filename=\"$save_as\"");
2564 binmode STDOUT
, ':raw';
2566 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2572 # blobs defined by non-textual hash id's can be cached
2574 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2578 if (!defined $hash) {
2579 if (defined $file_name) {
2580 my $base = $hash_base || git_get_head_hash
($project);
2581 $hash = git_get_hash_by_path
($base, $file_name, "blob")
2582 or die_error
(undef, "Error lookup file");
2584 die_error
(undef, "No file name defined");
2587 my ($have_blame) = gitweb_check_feature
('blame');
2588 open my $fd, "-|", git_cmd
(), "cat-file", "blob", $hash
2589 or die_error
(undef, "Couldn't cat $file_name, $hash");
2590 my $mimetype = blob_mimetype
($fd, $file_name);
2591 if ($mimetype !~ m/^text\//) {
2593 return git_blob_plain
($mimetype);
2595 git_header_html
(undef, $expires);
2596 my $formats_nav = '';
2597 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2598 if (defined $file_name) {
2601 $cgi->a({-href
=> href
(action
=>"blame", hash_base
=>$hash_base,
2602 hash
=>$hash, file_name
=>$file_name)},
2607 $cgi->a({-href
=> href
(action
=>"blob_plain",
2608 hash
=>$hash, file_name
=>$file_name)},
2611 $cgi->a({-href
=> href
(action
=>"blob",
2612 hash_base
=>"HEAD", file_name
=>$file_name)},
2616 $cgi->a({-href
=> href
(action
=>"blob_plain", hash
=>$hash)}, "plain");
2618 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
2619 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
2621 print "<div class=\"page_nav\">\n" .
2622 "<br/><br/></div>\n" .
2623 "<div class=\"title\">$hash</div>\n";
2625 git_print_page_path
($file_name, "blob", $hash_base);
2626 print "<div class=\"page_body\">\n";
2628 while (my $line = <$fd>) {
2631 $line = untabify
($line);
2632 printf "<div class=\"pre\"><a id=\"l%i\" href=\"#l%i\" class=\"linenr\">%4i</a> %s</div>\n",
2633 $nr, $nr, $nr, esc_html
($line);
2636 or print "Reading blob failed.\n";
2642 if (!defined $hash) {
2643 $hash = git_get_head_hash
($project);
2644 if (defined $file_name) {
2645 my $base = $hash_base || $hash;
2646 $hash = git_get_hash_by_path
($base, $file_name, "tree");
2648 if (!defined $hash_base) {
2653 open my $fd, "-|", git_cmd
(), "ls-tree", '-z', $hash
2654 or die_error
(undef, "Open git-ls-tree failed");
2655 my @entries = map { chomp; $_ } <$fd>;
2656 close $fd or die_error
(undef, "Reading tree failed");
2659 my $refs = git_get_references
();
2660 my $ref = format_ref_marker
($refs, $hash_base);
2663 my ($have_blame) = gitweb_check_feature
('blame');
2664 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
2665 git_print_page_nav
('tree','', $hash_base);
2666 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash_base);
2669 print "<div class=\"page_nav\">\n";
2670 print "<br/><br/></div>\n";
2671 print "<div class=\"title\">$hash</div>\n";
2673 if (defined $file_name) {
2674 $base = esc_html
("$file_name/");
2676 git_print_page_path
($file_name, 'tree', $hash_base);
2677 print "<div class=\"page_body\">\n";
2678 print "<table cellspacing=\"0\">\n";
2680 foreach my $line (@entries) {
2681 my %t = parse_ls_tree_line
($line, -z
=> 1);
2684 print "<tr class=\"dark\">\n";
2686 print "<tr class=\"light\">\n";
2690 git_print_tree_entry
(\
%t, $base, $hash_base, $have_blame);
2694 print "</table>\n" .
2701 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2702 my $have_snapshot = (defined $ctype && defined $suffix);
2703 if (!$have_snapshot) {
2704 die_error
('403 Permission denied', "Permission denied");
2707 if (!defined $hash) {
2708 $hash = git_get_head_hash
($project);
2711 my $filename = basename
($project) . "-$hash.tar.$suffix";
2713 print $cgi->header(-type
=> 'application/x-tar',
2714 -content_encoding
=> $ctype,
2715 -content_disposition
=> "inline; filename=\"$filename\"",
2716 -status
=> '200 OK');
2718 my $git_command = git_cmd_str
();
2719 open my $fd, "-|", "$git_command tar-tree $hash \'$project\' | $command" or
2720 die_error
(undef, "Execute git-tar-tree failed.");
2721 binmode STDOUT
, ':raw';
2723 binmode STDOUT
, ':utf8'; # as set at the beginning of gitweb.cgi
2729 my $head = git_get_head_hash
($project);
2730 if (!defined $hash) {
2733 if (!defined $page) {
2736 my $refs = git_get_references
();
2738 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
2739 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
2740 or die_error
(undef, "Open git-rev-list failed");
2741 my @revlist = map { chomp; $_ } <$fd>;
2744 my $paging_nav = format_paging_nav
('log', $hash, $head, $page, $#revlist);
2747 git_print_page_nav
('log','', $hash,undef,undef, $paging_nav);
2750 my %co = parse_commit
($hash);
2752 git_print_header_div
('summary', $project);
2753 print "<div class=\"page_body\"> Last change $co{'age_string'}.<br/><br/></div>\n";
2755 for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2756 my $commit = $revlist[$i];
2757 my $ref = format_ref_marker
($refs, $commit);
2758 my %co = parse_commit
($commit);
2760 my %ad = parse_date
($co{'author_epoch'});
2761 git_print_header_div
('commit',
2762 "<span class=\"age\">$co{'age_string'}</span>" .
2763 esc_html
($co{'title'}) . $ref,
2765 print "<div class=\"title_text\">\n" .
2766 "<div class=\"log_link\">\n" .
2767 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$commit)}, "commit") .
2769 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$commit)}, "commitdiff") .
2772 "<i>" . esc_html
($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" .
2775 print "<div class=\"log_body\">\n";
2776 git_print_simplified_log
($co{'comment'});
2783 my %co = parse_commit
($hash);
2785 die_error
(undef, "Unknown commit object");
2787 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
2788 my %cd = parse_date
($co{'committer_epoch'}, $co{'committer_tz'});
2790 my $parent = $co{'parent'};
2791 if (!defined $parent) {
2794 open my $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $parent, $hash
2795 or die_error
(undef, "Open git-diff-tree failed");
2796 my @difftree = map { chomp; $_ } <$fd>;
2797 close $fd or die_error
(undef, "Reading git-diff-tree failed");
2799 # non-textual hash id's can be cached
2801 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
2804 my $refs = git_get_references
();
2805 my $ref = format_ref_marker
($refs, $co{'id'});
2807 my ($ctype, $suffix, $command) = gitweb_check_feature
('snapshot');
2808 my $have_snapshot = (defined $ctype && defined $suffix);
2810 my $formats_nav = '';
2811 if (defined $file_name && defined $co{'parent'}) {
2812 my $parent = $co{'parent'};
2814 $cgi->a({-href
=> href
(action
=>"blame", hash_parent
=>$parent, file_name
=>$file_name)},
2817 git_header_html
(undef, $expires);
2818 git_print_page_nav
('commit', defined $co{'parent'} ?
'' : 'commitdiff',
2819 $hash, $co{'tree'}, $hash,
2822 if (defined $co{'parent'}) {
2823 git_print_header_div
('commitdiff', esc_html
($co{'title'}) . $ref, $hash);
2825 git_print_header_div
('tree', esc_html
($co{'title'}) . $ref, $co{'tree'}, $hash);
2827 print "<div class=\"title_text\">\n" .
2828 "<table cellspacing=\"0\">\n";
2829 print "<tr><td>author</td><td>" . esc_html
($co{'author'}) . "</td></tr>\n".
2831 "<td></td><td> $ad{'rfc2822'}";
2832 if ($ad{'hour_local'} < 6) {
2833 printf(" (<span class=\"atnight\">%02d:%02d</span> %s)",
2834 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2836 printf(" (%02d:%02d %s)",
2837 $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'});
2841 print "<tr><td>committer</td><td>" . esc_html
($co{'committer'}) . "</td></tr>\n";
2842 print "<tr><td></td><td> $cd{'rfc2822'}" .
2843 sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) .
2845 print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n";
2848 "<td class=\"sha1\">" .
2849 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash),
2850 class => "list"}, $co{'tree'}) .
2852 "<td class=\"link\">" .
2853 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$hash)},
2855 if ($have_snapshot) {
2857 $cgi->a({-href
=> href
(action
=>"snapshot", hash
=>$hash)}, "snapshot");
2861 my $parents = $co{'parents'};
2862 foreach my $par (@
$parents) {
2865 "<td class=\"sha1\">" .
2866 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par),
2867 class => "list"}, $par) .
2869 "<td class=\"link\">" .
2870 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$par)}, "commit") .
2872 $cgi->a({-href
=> href
(action
=>"commitdiff", hash
=>$hash, hash_parent
=>$par)}, "diff") .
2879 print "<div class=\"page_body\">\n";
2880 git_print_log
($co{'comment'});
2883 git_difftree_body
(\
@difftree, $hash, $parent);
2889 my $format = shift || 'html';
2896 # preparing $fd and %diffinfo for git_patchset_body
2898 if (defined $hash_base && defined $hash_parent_base) {
2899 if (defined $file_name) {
2901 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base,
2903 or die_error
(undef, "Open git-diff-tree failed");
2904 @difftree = map { chomp; $_ } <$fd>;
2906 or die_error
(undef, "Reading git-diff-tree failed");
2908 or die_error
('404 Not Found', "Blob diff not found");
2910 } elsif (defined $hash &&
2911 $hash =~ /[0-9a-fA-F]{40}/) {
2912 # try to find filename from $hash
2914 # read filtered raw output
2915 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts, $hash_parent_base, $hash_base
2916 or die_error
(undef, "Open git-diff-tree failed");
2918 # ':100644 100644 03b21826... 3b93d5e7... M ls-files.c'
2920 grep { /^:[0-7]{6} [0-7]{6} [0-9a-fA-F]{40} $hash/ }
2921 map { chomp; $_ } <$fd>;
2923 or die_error
(undef, "Reading git-diff-tree failed");
2925 or die_error
('404 Not Found', "Blob diff not found");
2928 die_error
('404 Not Found', "Missing one of the blob diff parameters");
2931 if (@difftree > 1) {
2932 die_error
('404 Not Found', "Ambiguous blob diff specification");
2935 %diffinfo = parse_difftree_raw_line
($difftree[0]);
2936 $file_parent ||= $diffinfo{'from_file'} || $file_name || $diffinfo{'file'};
2937 $file_name ||= $diffinfo{'to_file'} || $diffinfo{'file'};
2939 $hash_parent ||= $diffinfo{'from_id'};
2940 $hash ||= $diffinfo{'to_id'};
2942 # non-textual hash id's can be cached
2943 if ($hash_base =~ m/^[0-9a-fA-F]{40}$/ &&
2944 $hash_parent_base =~ m/^[0-9a-fA-F]{40}$/) {
2949 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
2950 '-p', $hash_parent_base, $hash_base,
2952 or die_error
(undef, "Open git-diff-tree failed");
2955 # old/legacy style URI
2956 if (!%diffinfo && # if new style URI failed
2957 defined $hash && defined $hash_parent) {
2958 # fake git-diff-tree raw output
2959 $diffinfo{'from_mode'} = $diffinfo{'to_mode'} = "blob";
2960 $diffinfo{'from_id'} = $hash_parent;
2961 $diffinfo{'to_id'} = $hash;
2962 if (defined $file_name) {
2963 if (defined $file_parent) {
2964 $diffinfo{'status'} = '2';
2965 $diffinfo{'from_file'} = $file_parent;
2966 $diffinfo{'to_file'} = $file_name;
2967 } else { # assume not renamed
2968 $diffinfo{'status'} = '1';
2969 $diffinfo{'from_file'} = $file_name;
2970 $diffinfo{'to_file'} = $file_name;
2972 } else { # no filename given
2973 $diffinfo{'status'} = '2';
2974 $diffinfo{'from_file'} = $hash_parent;
2975 $diffinfo{'to_file'} = $hash;
2978 # non-textual hash id's can be cached
2979 if ($hash =~ m/^[0-9a-fA-F]{40}$/ &&
2980 $hash_parent =~ m/^[0-9a-fA-F]{40}$/) {
2985 open $fd, "-|", git_cmd
(), "diff", '-p', @diff_opts, $hash_parent, $hash
2986 or die_error
(undef, "Open git-diff failed");
2988 die_error
('404 Not Found', "Missing one of the blob diff parameters")
2993 if ($format eq 'html') {
2995 $cgi->a({-href
=> href
(action
=>"blobdiff_plain",
2996 hash
=>$hash, hash_parent
=>$hash_parent,
2997 hash_base
=>$hash_base, hash_parent_base
=>$hash_parent_base,
2998 file_name
=>$file_name, file_parent
=>$file_parent)},
3000 git_header_html
(undef, $expires);
3001 if (defined $hash_base && (my %co = parse_commit
($hash_base))) {
3002 git_print_page_nav
('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
3003 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3005 print "<div class=\"page_nav\"><br/>$formats_nav<br/></div>\n";
3006 print "<div class=\"title\">$hash vs $hash_parent</div>\n";
3008 if (defined $file_name) {
3009 git_print_page_path
($file_name, "blob", $hash_base);
3011 print "<div class=\"page_path\"></div>\n";
3014 } elsif ($format eq 'plain') {
3016 -type
=> 'text/plain',
3017 -charset
=> 'utf-8',
3018 -expires
=> $expires,
3019 -content_disposition
=> qq(inline
; filename
="${file_name}.patch"));
3021 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3024 die_error
(undef, "Unknown blobdiff format");
3028 if ($format eq 'html') {
3029 print "<div class=\"page_body\">\n";
3031 git_patchset_body
($fd, [ \
%diffinfo ], $hash_base, $hash_parent_base);
3034 print "</div>\n"; # class="page_body"
3038 while (my $line = <$fd>) {
3039 $line =~ s!a/($hash|$hash_parent)!a/$diffinfo{'from_file'}!g;
3040 $line =~ s!b/($hash|$hash_parent)!b/$diffinfo{'to_file'}!g;
3044 last if $line =~ m!^\+\+\+!;
3052 sub git_blobdiff_plain
{
3053 git_blobdiff
('plain');
3056 sub git_commitdiff
{
3057 my $format = shift || 'html';
3058 my %co = parse_commit
($hash);
3060 die_error
(undef, "Unknown commit object");
3062 if (!defined $hash_parent) {
3063 $hash_parent = $co{'parent'} || '--root';
3069 if ($format eq 'html') {
3070 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3071 "--patch-with-raw", "--full-index", $hash_parent, $hash
3072 or die_error
(undef, "Open git-diff-tree failed");
3074 while (chomp(my $line = <$fd>)) {
3075 # empty line ends raw part of diff-tree output
3077 push @difftree, $line;
3080 } elsif ($format eq 'plain') {
3081 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3082 '-p', $hash_parent, $hash
3083 or die_error
(undef, "Open git-diff-tree failed");
3086 die_error
(undef, "Unknown commitdiff format");
3089 # non-textual hash id's can be cached
3091 if ($hash =~ m/^[0-9a-fA-F]{40}$/) {
3095 # write commit message
3096 if ($format eq 'html') {
3097 my $refs = git_get_references
();
3098 my $ref = format_ref_marker
($refs, $co{'id'});
3100 $cgi->a({-href
=> href
(action
=>"commitdiff_plain",
3101 hash
=>$hash, hash_parent
=>$hash_parent)},
3104 git_header_html
(undef, $expires);
3105 git_print_page_nav
('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
3106 git_print_header_div
('commit', esc_html
($co{'title'}) . $ref, $hash);
3107 git_print_authorship
(\
%co);
3108 print "<div class=\"page_body\">\n";
3109 print "<div class=\"log\">\n";
3110 git_print_simplified_log
($co{'comment'}, 1); # skip title
3111 print "</div>\n"; # class="log"
3113 } elsif ($format eq 'plain') {
3114 my $refs = git_get_references
("tags");
3115 my $tagname = git_get_rev_name_tags
($hash);
3116 my $filename = basename
($project) . "-$hash.patch";
3119 -type
=> 'text/plain',
3120 -charset
=> 'utf-8',
3121 -expires
=> $expires,
3122 -content_disposition
=> qq(inline
; filename
="$filename"));
3123 my %ad = parse_date
($co{'author_epoch'}, $co{'author_tz'});
3126 Date: $ad{'rfc2822'} ($ad{'tz_local'})
3127 Subject: $co{'title'}
3129 print "X-Git-Tag: $tagname\n" if $tagname;
3130 print "X-Git-Url: " . $cgi->self_url() . "\n\n";
3132 foreach my $line (@
{$co{'comment'}}) {
3139 if ($format eq 'html') {
3140 git_difftree_body
(\
@difftree, $hash, $hash_parent);
3143 git_patchset_body
($fd, \
@difftree, $hash, $hash_parent);
3145 print "</div>\n"; # class="page_body"
3148 } elsif ($format eq 'plain') {
3152 or print "Reading git-diff-tree failed\n";
3156 sub git_commitdiff_plain
{
3157 git_commitdiff
('plain');
3161 if (!defined $hash_base) {
3162 $hash_base = git_get_head_hash
($project);
3164 if (!defined $page) {
3168 my %co = parse_commit
($hash_base);
3170 die_error
(undef, "Unknown commit object");
3173 my $refs = git_get_references
();
3174 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3176 if (!defined $hash && defined $file_name) {
3177 $hash = git_get_hash_by_path
($hash_base, $file_name);
3179 if (defined $hash) {
3180 $ftype = git_get_type
($hash);
3184 git_cmd
(), "rev-list", $limit, "--full-history", $hash_base, "--", $file_name
3185 or die_error
(undef, "Open git-rev-list-failed");
3186 my @revlist = map { chomp; $_ } <$fd>;
3188 or die_error
(undef, "Reading git-rev-list failed");
3190 my $paging_nav = '';
3193 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3194 file_name
=>$file_name)},
3196 $paging_nav .= " ⋅ " .
3197 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3198 file_name
=>$file_name, page
=>$page-1),
3199 -accesskey
=> "p", -title
=> "Alt-p"}, "prev");
3201 $paging_nav .= "first";
3202 $paging_nav .= " ⋅ prev";
3204 if ($#revlist >= (100 * ($page+1)-1)) {
3205 $paging_nav .= " ⋅ " .
3206 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3207 file_name
=>$file_name, page
=>$page+1),
3208 -accesskey
=> "n", -title
=> "Alt-n"}, "next");
3210 $paging_nav .= " ⋅ next";
3213 if ($#revlist >= (100 * ($page+1)-1)) {
3215 $cgi->a({-href
=> href
(action
=>"history", hash
=>$hash, hash_base
=>$hash_base,
3216 file_name
=>$file_name, page
=>$page+1),
3217 -title
=> "Alt-n"}, "next");
3221 git_print_page_nav
('history','', $hash_base,$co{'tree'},$hash_base, $paging_nav);
3222 git_print_header_div
('commit', esc_html
($co{'title'}), $hash_base);
3223 git_print_page_path
($file_name, $ftype, $hash_base);
3225 git_history_body
(\
@revlist, ($page * 100), $#revlist,
3226 $refs, $hash_base, $ftype, $next_link);
3232 if (!defined $searchtext) {
3233 die_error
(undef, "Text field empty");
3235 if (!defined $hash) {
3236 $hash = git_get_head_hash
($project);
3238 my %co = parse_commit
($hash);
3240 die_error
(undef, "Unknown commit object");
3243 my $commit_search = 1;
3244 my $author_search = 0;
3245 my $committer_search = 0;
3246 my $pickaxe_search = 0;
3247 if ($searchtext =~ s/^author\\://i) {
3249 } elsif ($searchtext =~ s/^committer\\://i) {
3250 $committer_search = 1;
3251 } elsif ($searchtext =~ s/^pickaxe\\://i) {
3253 $pickaxe_search = 1;
3255 # pickaxe may take all resources of your box and run for several minutes
3256 # with every query - so decide by yourself how public you make this feature
3257 my ($have_pickaxe) = gitweb_check_feature
('pickaxe');
3258 if (!$have_pickaxe) {
3259 die_error
('403 Permission denied', "Permission denied");
3263 git_print_page_nav
('','', $hash,$co{'tree'},$hash);
3264 git_print_header_div
('commit', esc_html
($co{'title'}), $hash);
3266 print "<table cellspacing=\"0\">\n";
3268 if ($commit_search) {
3270 open my $fd, "-|", git_cmd
(), "rev-list", "--header", "--parents", $hash or next;
3271 while (my $commit_text = <$fd>) {
3272 if (!grep m/$searchtext/i, $commit_text) {
3275 if ($author_search && !grep m/\nauthor .*$searchtext/i, $commit_text) {
3278 if ($committer_search && !grep m/\ncommitter .*$searchtext/i, $commit_text) {
3281 my @commit_lines = split "\n", $commit_text;
3282 my %co = parse_commit
(undef, \
@commit_lines);
3287 print "<tr class=\"dark\">\n";
3289 print "<tr class=\"light\">\n";
3292 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3293 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3295 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}), -class => "list subject"},
3296 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3297 my $comment = $co{'comment'};
3298 foreach my $line (@
$comment) {
3299 if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3300 my $lead = esc_html
($1) || "";
3301 $lead = chop_str
($lead, 30, 10);
3302 my $match = esc_html
($2) || "";
3303 my $trail = esc_html
($3) || "";
3304 $trail = chop_str
($trail, 30, 10);
3305 my $text = "$lead<span class=\"match\">$match</span>$trail";
3306 print chop_str
($text, 80, 5) . "<br/>\n";
3310 "<td class=\"link\">" .
3311 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3313 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3320 if ($pickaxe_search) {
3322 my $git_command = git_cmd_str
();
3323 open my $fd, "-|", "$git_command rev-list $hash | " .
3324 "$git_command diff-tree -r --stdin -S\'$searchtext\'";
3327 while (my $line = <$fd>) {
3328 if (%co && $line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)\t(.*)$/) {
3331 $set{'from_id'} = $3;
3333 $set{'id'} = $set{'to_id'};
3334 if ($set{'id'} =~ m/0{40}/) {
3335 $set{'id'} = $set{'from_id'};
3337 if ($set{'id'} =~ m/0{40}/) {
3341 } elsif ($line =~ m/^([0-9a-fA-F]{40})$/){
3344 print "<tr class=\"dark\">\n";
3346 print "<tr class=\"light\">\n";
3349 print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
3350 "<td><i>" . esc_html
(chop_str
($co{'author_name'}, 15, 5)) . "</i></td>\n" .
3352 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'}),
3353 -class => "list subject"},
3354 esc_html
(chop_str
($co{'title'}, 50)) . "<br/>");
3355 while (my $setref = shift @files) {
3357 print $cgi->a({-href
=> href
(action
=>"blob", hash_base
=>$co{'id'},
3358 hash
=>$set{'id'}, file_name
=>$set{'file'}),
3360 "<span class=\"match\">" . esc_html
($set{'file'}) . "</span>") .
3364 "<td class=\"link\">" .
3365 $cgi->a({-href
=> href
(action
=>"commit", hash
=>$co{'id'})}, "commit") .
3367 $cgi->a({-href
=> href
(action
=>"tree", hash
=>$co{'tree'}, hash_base
=>$co{'id'})}, "tree");
3371 %co = parse_commit
($1);
3381 my $head = git_get_head_hash
($project);
3382 if (!defined $hash) {
3385 if (!defined $page) {
3388 my $refs = git_get_references
();
3390 my $limit = sprintf("--max-count=%i", (100 * ($page+1)));
3391 open my $fd, "-|", git_cmd
(), "rev-list", $limit, $hash
3392 or die_error
(undef, "Open git-rev-list failed");
3393 my @revlist = map { chomp; $_ } <$fd>;
3396 my $paging_nav = format_paging_nav
('shortlog', $hash, $head, $page, $#revlist);
3398 if ($#revlist >= (100 * ($page+1)-1)) {
3400 $cgi->a({-href
=> href
(action
=>"shortlog", hash
=>$hash, page
=>$page+1),
3401 -title
=> "Alt-n"}, "next");
3406 git_print_page_nav
('shortlog','', $hash,$hash,$hash, $paging_nav);
3407 git_print_header_div
('summary', $project);
3409 git_shortlog_body
(\
@revlist, ($page * 100), $#revlist, $refs, $next_link);
3414 ## ......................................................................
3415 ## feeds (RSS, OPML)
3418 # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
3419 open my $fd, "-|", git_cmd
(), "rev-list", "--max-count=150", git_get_head_hash
($project)
3420 or die_error
(undef, "Open git-rev-list failed");
3421 my @revlist = map { chomp; $_ } <$fd>;
3422 close $fd or die_error
(undef, "Reading git-rev-list failed");
3423 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3425 <?xml version="1.0" encoding="utf-8"?>
3426 <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
3428 <title>$project $my_uri $my_url</title>
3429 <link>${\esc_html("$my_url?p=$project;a=summary")}</link>
3430 <description>$project log</description>
3431 <language>en</language>
3434 for (my $i = 0; $i <= $#revlist; $i++) {
3435 my $commit = $revlist[$i];
3436 my %co = parse_commit
($commit);
3437 # we read 150, we always show 30 and the ones more recent than 48 hours
3438 if (($i >= 20) && ((time - $co{'committer_epoch'}) > 48*60*60)) {
3441 my %cd = parse_date
($co{'committer_epoch'});
3442 open $fd, "-|", git_cmd
(), "diff-tree", '-r', @diff_opts,
3443 $co{'parent'}, $co{'id'}
3445 my @difftree = map { chomp; $_ } <$fd>;
3450 sprintf("%d %s %02d:%02d", $cd{'mday'}, $cd{'month'}, $cd{'hour'}, $cd{'minute'}) . " - " . esc_html
($co{'title'}) .
3452 "<author>" . esc_html
($co{'author'}) . "</author>\n" .
3453 "<pubDate>$cd{'rfc2822'}</pubDate>\n" .
3454 "<guid isPermaLink=\"true\">" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</guid>\n" .
3455 "<link>" . esc_html
("$my_url?p=$project;a=commit;h=$commit") . "</link>\n" .
3456 "<description>" . esc_html
($co{'title'}) . "</description>\n" .
3457 "<content:encoded>" .
3459 my $comment = $co{'comment'};
3460 foreach my $line (@
$comment) {
3461 $line = decode
("utf8", $line, Encode
::FB_DEFAULT
);
3462 print "$line<br/>\n";
3465 foreach my $line (@difftree) {
3466 if (!($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/)) {
3469 my $file = validate_input
(unquote
($7));
3470 $file = decode
("utf8", $file, Encode
::FB_DEFAULT
);
3471 print "$file<br/>\n";
3474 "</content:encoded>\n" .
3477 print "</channel></rss>";
3481 my @list = git_get_projects_list
();
3483 print $cgi->header(-type
=> 'text/xml', -charset
=> 'utf-8');
3485 <?xml version="1.0" encoding="utf-8"?>
3486 <opml version="1.0">
3488 <title>$site_name Git OPML Export</title>
3491 <outline text="git RSS feeds">
3494 foreach my $pr (@list) {
3496 my $head = git_get_head_hash
($proj{'path'});
3497 if (!defined $head) {
3500 $git_dir = "$projectroot/$proj{'path'}";
3501 my %co = parse_commit
($head);
3506 my $path = esc_html
(chop_str
($proj{'path'}, 25, 5));
3507 my $rss = "$my_url?p=$proj{'path'};a=rss";
3508 my $html = "$my_url?p=$proj{'path'};a=summary";
3509 print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";