gitweb: Use parse_difftree_raw_line in git_difftree_body
[gitweb.git] / gitweb / gitweb.perl
index 18ba4b0d86e8e78fef5a2c8bfa645063e90acad3..31a1824d7a5d04b2cf7fc4d0b99a4dc98a73dc65 100755 (executable)
 # (relative to the current git repository)
 our $mimetypes_file = undef;
 
+# You define site-wide feature defaults here; override them with
+# $GITWEB_CONFIG as necessary.
+our %feature =
+(
+
+# feature  => {'sub' => feature-sub, 'override' => allow-override, 'default' => [ default options...]
+
+'blame'         => {'sub' => \&feature_blame, 'override' => 0, 'default' => [0]},
+'snapshot'      => {'sub' => \&feature_snapshot, 'override' => 0, 'default' => ['x-gzip', 'gz', 'gzip']},
+
+);
+
+sub gitweb_check_feature {
+       my ($name) = @_;
+       return undef unless exists $feature{$name};
+       my ($sub, $override, @defaults) = ($feature{$name}{'sub'},
+                                               $feature{$name}{'override'},
+                                               @{$feature{$name}{'default'}});
+       if (!$override) { return @defaults; }
+       return $sub->(@defaults);
+}
+
+# To enable system wide have in $GITWEB_CONFIG
+# $feature{'blame'}{'default'} =  [1];
+# To have project specific config enable override in  $GITWEB_CONFIG
+# $feature{'blame'}{'override'} =  1;
+# and in project config gitweb.blame = 0|1;
+
+sub feature_blame {
+       my ($val) = git_get_project_config('blame', '--bool');
+
+       if ($val eq 'true') {
+               return 1;
+       } elsif ($val eq 'false') {
+               return 0;
+       }
+
+       return $_[0];
+}
+
+# To disable system wide have in $GITWEB_CONFIG
+# $feature{'snapshot'}{'default'} =  [undef];
+# To have project specific config enable override in  $GITWEB_CONFIG
+# $feature{'blame'}{'override'} =  1;
+# and in project config  gitweb.snapshot = none|gzip|bzip2
+
+sub feature_snapshot {
+       my ($ctype, $suffix, $command) = @_;
+
+       my ($val) = git_get_project_config('snapshot');
+
+       if ($val eq 'gzip') {
+               return ('x-gzip', 'gz', 'gzip');
+       } elsif ($val eq 'bzip2') {
+               return ('x-bzip2', 'bz2', 'bzip2');
+       } elsif ($val eq 'none') {
+               return ();
+       }
+
+       return ($ctype, $suffix, $command);
+}
+
 our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++";
 require $GITWEB_CONFIG if -e $GITWEB_CONFIG;
 
@@ -485,24 +547,21 @@ sub git_get_type {
 }
 
 sub git_get_project_config {
-       my $key = shift;
+       my ($key, $type) = @_;
 
        return unless ($key);
        $key =~ s/^gitweb\.//;
        return if ($key =~ m/\W/);
 
-       my $val = qx($GIT repo-config --get gitweb.$key);
+       my @x = ($GIT, 'repo-config');
+       if (defined $type) { push @x, $type; }
+       push @x, "--get";
+       push @x, "gitweb.$key";
+       my $val = qx(@x);
+       chomp $val;
        return ($val);
 }
 
-sub git_get_project_config_bool {
-       my $val = git_get_project_config (@_);
-       if ($val and $val =~ m/true|yes|on/) {
-               return (1);
-       }
-       return; # implicit false
-}
-
 # get hash of given path at given ref
 sub git_get_hash_by_path {
        my $base = shift;
@@ -859,6 +918,34 @@ sub parse_ref {
        return %ref_item;
 }
 
+# parse line of git-diff-tree "raw" output
+sub parse_difftree_raw_line {
+       my $line = shift;
+       my %res;
+
+       # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M   ls-files.c'
+       # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M   rev-tree.c'
+       if ($line =~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
+               $res{'from_mode'} = $1;
+               $res{'to_mode'} = $2;
+               $res{'from_id'} = $3;
+               $res{'to_id'} = $4;
+               $res{'status'} = $5;
+               $res{'similarity'} = $6;
+               if ($res{'status'} eq 'R' || $res{'status'} eq 'C') { # renamed or copied
+                       ($res{'from_file'}, $res{'to_file'}) = map { unquote($_) } split("\t", $7);
+               } else {
+                       $res{'file'} = unquote($7);
+               }
+       }
+       # 'c512b523472485aef4fff9e57b229d9d243c967f'
+       #elsif ($line =~ m/^([0-9a-fA-F]{40})$/) {
+       #       $res{'commit'} = $1;
+       #}
+
+       return wantarray ? %res : \%res;
+}
+
 ## ......................................................................
 ## parse to array of hashes functions
 
@@ -1177,12 +1264,18 @@ sub git_print_header_div {
 sub git_print_page_path {
        my $name = shift;
        my $type = shift;
+       my $hb = shift;
 
        if (!defined $name) {
                print "<div class=\"page_path\"><b>/</b></div>\n";
        } elsif (defined $type && $type eq 'blob') {
-               print "<div class=\"page_path\"><b>" .
-                       $cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name)}, esc_html($name)) . "</b><br/></div>\n";
+               print "<div class=\"page_path\"><b>";
+               if (defined $hb) {
+                       print $cgi->a({-href => href(action=>"blob_plain", hash_base=>$hb, file_name=>$file_name)}, esc_html($name));
+               } else {
+                       print $cgi->a({-href => href(action=>"blob_plain", file_name=>$file_name)}, esc_html($name));
+               }
+               print "</b><br/></div>\n";
        } else {
                print "<div class=\"page_path\"><b>" . esc_html($name) . "</b><br/></div>\n";
        }
@@ -1263,18 +1356,7 @@ sub git_difftree_body {
        print "<table class=\"diff_tree\">\n";
        my $alternate = 0;
        foreach my $line (@{$difftree}) {
-               # ':100644 100644 03b218260e99b78c6df0ed378e59ed9205ccc96d 3b93d5e7cc7f7dd4ebed13a5cc1a4ad976fc94d8 M   ls-files.c'
-               # ':100644 100644 7f9281985086971d3877aca27704f2aaf9c448ce bc190ebc71bbd923f2b728e505408f5e54bd073a M   rev-tree.c'
-               if ($line !~ m/^:([0-7]{6}) ([0-7]{6}) ([0-9a-fA-F]{40}) ([0-9a-fA-F]{40}) (.)([0-9]{0,3})\t(.*)$/) {
-                       next;
-               }
-               my $from_mode = $1;
-               my $to_mode = $2;
-               my $from_id = $3;
-               my $to_id = $4;
-               my $status = $5;
-               my $similarity = $6; # score
-               my $file = validate_input(unquote($7));
+               my %diff = parse_difftree_raw_line($line);
 
                if ($alternate) {
                        print "<tr class=\"dark\">\n";
@@ -1283,105 +1365,131 @@ sub git_difftree_body {
                }
                $alternate ^= 1;
 
-               if ($status eq "A") { # created
-                       my $mode_chng = "";
-                       if (S_ISREG(oct $to_mode)) {
-                               $mode_chng = sprintf(" with mode: %04o", (oct $to_mode) & 0777);
+               my ($to_mode_oct, $to_mode_str, $to_file_type);
+               my ($from_mode_oct, $from_mode_str, $from_file_type);
+               if ($diff{'to_mode'} ne ('0' x 6)) {
+                       $to_mode_oct = oct $diff{'to_mode'};
+                       if (S_ISREG($to_mode_oct)) { # only for regular file
+                               $to_mode_str = sprintf("%04o", $to_mode_oct & 0777); # permission bits
+                       }
+                       $to_file_type = file_type($diff{'to_mode'});
+               }
+               if ($diff{'from_mode'} ne ('0' x 6)) {
+                       $from_mode_oct = oct $diff{'from_mode'};
+                       if (S_ISREG($to_mode_oct)) { # only for regular file
+                               $from_mode_str = sprintf("%04o", $from_mode_oct & 0777); # permission bits
                        }
+                       $from_file_type = file_type($diff{'from_mode'});
+               }
+
+               if ($diff{'status'} eq "A") { # created
+                       my $mode_chng = "<span class=\"file_status new\">[new $to_file_type";
+                       $mode_chng   .= " with mode: $to_mode_str" if $to_mode_str;
+                       $mode_chng   .= "]</span>";
                        print "<td>" .
-                             $cgi->a({-href => href(action=>"blob", hash=>$to_id, hash_base=>$hash, file_name=>$file),
-                                     -class => "list"}, esc_html($file)) .
+                             $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
+                                                    hash_base=>$hash, file_name=>$diff{'file'}),
+                                     -class => "list"}, esc_html($diff{'file'})) .
                              "</td>\n" .
-                             "<td><span class=\"file_status new\">[new " . file_type($to_mode) . "$mode_chng]</span></td>\n" .
+                             "<td>$mode_chng</td>\n" .
                              "<td class=\"link\">" .
-                             $cgi->a({-href => href(action=>"blob", hash=>$to_id, hash_base=>$hash, file_name=>$file)}, "blob") .
+                             $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
+                                                    hash_base=>$hash, file_name=>$diff{'file'})},
+                                     "blob") .
                              "</td>\n";
 
-               } elsif ($status eq "D") { # deleted
+               } elsif ($diff{'status'} eq "D") { # deleted
+                       my $mode_chng = "<span class=\"file_status deleted\">[deleted $from_file_type]</span>";
                        print "<td>" .
-                             $cgi->a({-href => href(action=>"blob", hash=>$from_id, hash_base=>$parent, file_name=>$file),
-                                      -class => "list"}, esc_html($file)) . "</td>\n" .
-                             "<td><span class=\"file_status deleted\">[deleted " . file_type($from_mode). "]</span></td>\n" .
+                             $cgi->a({-href => href(action=>"blob", hash=>$diff{'from_id'},
+                                                    hash_base=>$parent, file_name=>$diff{'file'}),
+                                      -class => "list"}, esc_html($diff{'file'})) .
+                             "</td>\n" .
+                             "<td>$mode_chng</td>\n" .
                              "<td class=\"link\">" .
-                             $cgi->a({-href => href(action=>"blob", hash=>$from_id, hash_base=>$parent, file_name=>$file)}, "blob") . " | " .
-                             $cgi->a({-href => href(action=>"history", hash_base=>$parent, file_name=>$file)}, "history") .
-                             "</td>\n"
+                             $cgi->a({-href => href(action=>"blob", hash=>$diff{'from_id'},
+                                                    hash_base=>$parent, file_name=>$diff{'file'})},
+                                     "blob") .
+                             " | " .
+                             $cgi->a({-href => href(action=>"history", hash_base=>$parent,
+                                                    file_name=>$diff{'file'})},\
+                                     "history") .
+                             "</td>\n";
 
-               } elsif ($status eq "M" || $status eq "T") { # modified, or type changed
+               } elsif ($diff{'status'} eq "M" || $diff{'status'} eq "T") { # modified, or type changed
                        my $mode_chnge = "";
-                       if ($from_mode != $to_mode) {
-                               $mode_chnge = " <span class=\"file_status mode_chnge\">[changed";
-                               if (((oct $from_mode) & S_IFMT) != ((oct $to_mode) & S_IFMT)) {
-                                       $mode_chnge .= " from " . file_type($from_mode) . " to " . file_type($to_mode);
+                       if ($diff{'from_mode'} != $diff{'to_mode'}) {
+                               $mode_chnge = "<span class=\"file_status mode_chnge\">[changed";
+                               if ($from_file_type != $to_file_type) {
+                                       $mode_chnge .= " from $from_file_type to $to_file_type";
                                }
-                               if (((oct $from_mode) & 0777) != ((oct $to_mode) & 0777)) {
-                                       if (S_ISREG($from_mode) && S_ISREG($to_mode)) {
-                                               $mode_chnge .= sprintf(" mode: %04o->%04o", (oct $from_mode) & 0777, (oct $to_mode) & 0777);
-                                       } elsif (S_ISREG($to_mode)) {
-                                               $mode_chnge .= sprintf(" mode: %04o", (oct $to_mode) & 0777);
+                               if (($from_mode_oct & 0777) != ($to_mode_oct & 0777)) {
+                                       if ($from_mode_str && $to_mode_str) {
+                                               $mode_chnge .= " mode: $from_mode_str->$to_mode_str";
+                                       } elsif ($to_mode_str) {
+                                               $mode_chnge .= " mode: $to_mode_str";
                                        }
                                }
                                $mode_chnge .= "]</span>\n";
                        }
                        print "<td>";
-                       if ($to_id ne $from_id) { # modified
-                               print $cgi->a({-href => href(action=>"blobdiff", hash=>$to_id, hash_parent=>$from_id, hash_base=>$hash, file_name=>$file),
-                                             -class => "list"}, esc_html($file));
-                       } else { # mode changed
-                               print $cgi->a({-href => href(action=>"blob", hash=>$to_id, hash_base=>$hash, file_name=>$file),
-                                             -class => "list"}, esc_html($file));
+                       if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
+                               print $cgi->a({-href => href(action=>"blobdiff", hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
+                                                            hash_base=>$hash, file_name=>$diff{'file'}),
+                                             -class => "list"}, esc_html($diff{'file'}));
+                       } else { # only mode changed
+                               print $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
+                                                            hash_base=>$hash, file_name=>$diff{'file'}),
+                                             -class => "list"}, esc_html($diff{'file'}));
                        }
                        print "</td>\n" .
                              "<td>$mode_chnge</td>\n" .
                              "<td class=\"link\">" .
-                               $cgi->a({-href => href(action=>"blob", hash=>$to_id, hash_base=>$hash, file_name=>$file)}, "blob");
-                       if ($to_id ne $from_id) { # modified
-                               print " | " . $cgi->a({-href => href(action=>"blobdiff", hash=>$to_id, hash_parent=>$from_id, hash_base=>$hash, file_name=>$file)}, "diff");
-                       }
-                       print " | " . $cgi->a({-href => href(action=>"history", hash_base=>$hash, file_name=>$file)}, "history") . "\n";
-                       print "</td>\n";
-
-               } elsif ($status eq "R") { # renamed
-                       my ($from_file, $to_file) = split "\t", $file;
-                       my $mode_chng = "";
-                       if ($from_mode != $to_mode) {
-                               $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
-                       }
-                       print "<td>" .
-                             $cgi->a({-href => href(action=>"blob", hash=>$to_id, hash_base=>$hash, file_name=>$to_file),
-                                     -class => "list"}, esc_html($to_file)) . "</td>\n" .
-                             "<td><span class=\"file_status moved\">[moved from " .
-                             $cgi->a({-href => href(action=>"blob", hash=>$from_id, hash_base=>$parent, file_name=>$from_file),
-                                     -class => "list"}, esc_html($from_file)) .
-                             " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
-                             "<td class=\"link\">" .
-                             $cgi->a({-href => href(action=>"blob", hash=>$to_id, hash_base=>$hash, file_name=>$to_file)}, "blob");
-                       if ($to_id ne $from_id) {
+                               $cgi->a({-href => href(action=>"blob", hash=>$diff{'to_id'},
+                                                      hash_base=>$hash, file_name=>$diff{'file'})},
+                                       "blob");
+                       if ($diff{'to_id'} ne $diff{'from_id'}) { # modified
                                print " | " .
-                                     $cgi->a({-href => href(action=>"blobdiff", hash=>$to_id, hash_parent=>$from_id, hash_base=>$hash, file_name=>$to_file, file_parent=>$from_file)}, "diff");
+                                       $cgi->a({-href => href(action=>"blobdiff", hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
+                                                              hash_base=>$hash, file_name=>$diff{'file'})},
+                                               "diff");
                        }
+                       print " | " .
+                               $cgi->a({-href => href(action=>"history",
+                                                      hash_base=>$hash, file_name=>$diff{'file'})},
+                                       "history");
                        print "</td>\n";
 
-               } elsif ($status eq "C") { # copied
-                       my ($from_file, $to_file) = split "\t", $file;
+               } elsif ($diff{'status'} eq "R" || $diff{'status'} eq "C") { # renamed or copied
+                       my %status_name = ('R' => 'moved', 'C' => 'copied');
+                       my $nstatus = $status_name{$diff{'status'}};
                        my $mode_chng = "";
-                       if ($from_mode != $to_mode) {
-                               $mode_chng = sprintf(", mode: %04o", (oct $to_mode) & 0777);
+                       if ($diff{'from_mode'} != $diff{'to_mode'}) {
+                               # mode also for directories, so we cannot use $to_mode_str
+                               $mode_chng = sprintf(", mode: %04o", $to_mode_oct & 0777);
                        }
                        print "<td>" .
-                             $cgi->a({-href => href(action=>"blob", hash=>$to_id, hash_base=>$hash, file_name=>$to_file),
-                                     -class => "list"}, esc_html($to_file)) . "</td>\n" .
-                             "<td><span class=\"file_status copied\">[copied from " .
-                             $cgi->a({-href => href(action=>"blob", hash=>$from_id, hash_base=>$parent, file_name=>$from_file),
-                                     -class => "list"}, esc_html($from_file)) .
-                             " with " . (int $similarity) . "% similarity$mode_chng]</span></td>\n" .
+                             $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
+                                                    hash=>$diff{'to_id'}, file_name=>$diff{'to_file'}),
+                                     -class => "list"}, esc_html($diff{'to_file'})) . "</td>\n" .
+                             "<td><span class=\"file_status $nstatus\">[$nstatus from " .
+                             $cgi->a({-href => href(action=>"blob", hash_base=>$parent,
+                                                    hash=>$diff{'from_id'}, file_name=>$diff{'from_file'}),
+                                     -class => "list"}, esc_html($diff{'from_file'})) .
+                             " with " . (int $diff{'similarity'}) . "% similarity$mode_chng]</span></td>\n" .
                              "<td class=\"link\">" .
-                             $cgi->a({-href => href(action=>"blob", hash=>$to_id, hash_base=>$hash, file_name=>$to_file)}, "blob");
-                       if ($to_id ne $from_id) {
+                             $cgi->a({-href => href(action=>"blob", hash_base=>$hash,
+                                                    hash=>$diff{'to_id'}, file_name=>$diff{'to_file'})},
+                                     "blob");
+                       if ($diff{'to_id'} ne $diff{'from_id'}) {
                                print " | " .
-                                     $cgi->a({-href => href(action=>"blobdiff", hash=>$to_id, hash_parent=>$from_id, hash_base=>$hash, file_name=>$to_file, file_parent=>$from_file)}, "diff");
+                                       $cgi->a({-href => href(action=>"blobdiff", hash_base=>$hash,
+                                                              hash=>$diff{'to_id'}, hash_parent=>$diff{'from_id'},
+                                                              file_name=>$diff{'to_file'}, file_parent=>$diff{'from_file'})},
+                                               "diff");
                        }
                        print "</td>\n";
+
                } # we should not encounter Unmerged (U) or Unknown (X) status
                print "</tr>\n";
        }
@@ -1391,7 +1499,10 @@ sub git_difftree_body {
 sub git_shortlog_body {
        # uses global variable $project
        my ($revlist, $from, $to, $refs, $extra) = @_;
-       my $have_snapshot = git_get_project_config_bool('snapshot');
+
+       my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
+       my $have_snapshot = (defined $ctype && defined $suffix);
+
        $from = 0 unless defined $from;
        $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
 
@@ -1852,7 +1963,10 @@ sub git_tag {
 sub git_blame2 {
        my $fd;
        my $ftype;
-       die_error(undef, "Permission denied") if (!git_get_project_config_bool ('blame'));
+
+       if (!gitweb_check_feature('blame')) {
+               die_error('403 Permission denied', "Permission denied");
+       }
        die_error('404 Not Found', "File name not defined") if (!$file_name);
        $hash_base ||= git_get_head_hash($project);
        die_error(undef, "Couldn't find base commit") unless ($hash_base);
@@ -1874,7 +1988,7 @@ sub git_blame2 {
                " | " . $cgi->a({-href => href(action=>"blame", file_name=>$file_name)}, "head");
        git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
        git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
-       git_print_page_path($file_name, $ftype);
+       git_print_page_path($file_name, $ftype, $hash_base);
        my @rev_color = (qw(light2 dark2));
        my $num_colors = scalar(@rev_color);
        my $current_color = 0;
@@ -1910,7 +2024,10 @@ sub git_blame2 {
 
 sub git_blame {
        my $fd;
-       die_error('403 Permission denied', "Permission denied") if (!git_get_project_config_bool ('blame'));
+
+       if (!gitweb_check_feature('blame')) {
+               die_error('403 Permission denied', "Permission denied");
+       }
        die_error('404 Not Found', "File name not defined") if (!$file_name);
        $hash_base ||= git_get_head_hash($project);
        die_error(undef, "Couldn't find base commit") unless ($hash_base);
@@ -1928,7 +2045,7 @@ sub git_blame {
                " | " . $cgi->a({-href => href(action=>"blame", file_name=>$file_name)}, "head");
        git_print_page_nav('','', $hash_base,$co{'tree'},$hash_base, $formats_nav);
        git_print_header_div('commit', esc_html($co{'title'}), $hash_base);
-       git_print_page_path($file_name, 'blob');
+       git_print_page_path($file_name, 'blob', $hash_base);
        print "<div class=\"page_body\">\n";
        print <<HTML;
 <table class="blame">
@@ -2063,7 +2180,7 @@ sub git_blob {
                        die_error(undef, "No file name defined");
                }
        }
-       my $have_blame = git_get_project_config_bool ('blame');
+       my $have_blame = gitweb_check_feature('blame');
        open my $fd, "-|", $GIT, "cat-file", "blob", $hash
                or die_error(undef, "Couldn't cat $file_name, $hash");
        my $mimetype = blob_mimetype($fd, $file_name);
@@ -2091,7 +2208,7 @@ sub git_blob {
                      "<br/><br/></div>\n" .
                      "<div class=\"title\">$hash</div>\n";
        }
-       git_print_page_path($file_name, "blob");
+       git_print_page_path($file_name, "blob", $hash_base);
        print "<div class=\"page_body\">\n";
        my $nr;
        while (my $line = <$fd>) {
@@ -2128,7 +2245,7 @@ sub git_tree {
        git_header_html();
        my %base_key = ();
        my $base = "";
-       my $have_blame = git_get_project_config_bool ('blame');
+       my $have_blame = gitweb_check_feature('blame');
        if (defined $hash_base && (my %co = parse_commit($hash_base))) {
                $base_key{hash_base} = $hash_base;
                git_print_page_nav('tree','', $hash_base);
@@ -2141,7 +2258,7 @@ sub git_tree {
        if (defined $file_name) {
                $base = esc_html("$file_name/");
        }
-       git_print_page_path($file_name, 'tree');
+       git_print_page_path($file_name, 'tree', $hash_base);
        print "<div class=\"page_body\">\n";
        print "<table cellspacing=\"0\">\n";
        my $alternate = 0;
@@ -2189,25 +2306,31 @@ sub git_tree {
 
 sub git_snapshot {
 
+       my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
+       my $have_snapshot = (defined $ctype && defined $suffix);
+       if (!$have_snapshot) {
+               die_error('403 Permission denied', "Permission denied");
+       }
+
        if (!defined $hash) {
                $hash = git_get_head_hash($project);
        }
 
-       my $filename = basename($project) . "-$hash.tar.gz";
+       my $filename = basename($project) . "-$hash.tar.$suffix";
 
        print $cgi->header(-type => 'application/x-tar',
-                       -content-encoding => 'gzip',
-                       '-content-disposition' => "inline; filename=\"$filename\"",
-                       -status => '200 OK');
+                          -content-encoding => $ctype,
+                          '-content-disposition' =>
+                          "inline; filename=\"$filename\"",
+                          -status => '200 OK');
 
-       open my $fd, "-|", "$GIT tar-tree $hash \'$project\' | gzip" or
-                               die_error(undef, "Execute git-tar-tree failed.");
+       open my $fd, "-|", "$GIT tar-tree $hash \'$project\' | $command" or
+               die_error(undef, "Execute git-tar-tree failed.");
        binmode STDOUT, ':raw';
        print <$fd>;
        binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi
        close $fd;
 
-
 }
 
 sub git_log {
@@ -2287,7 +2410,10 @@ sub git_commit {
        }
        my $refs = git_get_references();
        my $ref = format_ref_marker($refs, $co{'id'});
-       my $have_snapshot = git_get_project_config_bool('snapshot');
+
+       my ($ctype, $suffix, $command) = gitweb_check_feature('snapshot');
+       my $have_snapshot = (defined $ctype && defined $suffix);
+
        my $formats_nav = '';
        if (defined $file_name && defined $co{'parent'}) {
                my $parent = $co{'parent'};
@@ -2365,7 +2491,7 @@ sub git_blobdiff {
                      "<br/><br/></div>\n" .
                      "<div class=\"title\">$hash vs $hash_parent</div>\n";
        }
-       git_print_page_path($file_name, "blob");
+       git_print_page_path($file_name, "blob", $hash_base);
        print "<div class=\"page_body\">\n" .
              "<div class=\"diff_info\">blob:" .
              $cgi->a({-href => href(action=>"blob", hash=>$hash_parent, hash_base=>$hash_base, file_name=>($file_parent || $file_name))}, $hash_parent) .
@@ -2535,7 +2661,7 @@ sub git_history {
        if (defined $hash) {
                $ftype = git_get_type($hash);
        }
-       git_print_page_path($file_name, $ftype);
+       git_print_page_path($file_name, $ftype, $hash_base);
 
        open my $fd, "-|",
                $GIT, "rev-list", "--full-history", $hash_base, "--", $file_name;