Browse Source

gitweb.perl - Optionally send archives as .zip files

git-archive already knows how to generate an archive as a tar or a zip
file, but gitweb did not. zip archvies are much more usable in a Windows
environment due to native support and this patch allows a site admin the
option to deliver zip rather than tar files. The selection is done by
inserting

    $feature{'snapshot'}{'default'} = ['x-zip', 'zip', ''];

in gitweb_config.perl.

Tar files remain the default option.

Signed-off-by: Mark Levedahl <mdl123@verizon.net>
Acked-by: Petr Baudis <pasky@suse.cz>
Signed-off-by: Junio C Hamano <junkio@cox.net>
maint
Mark Levedahl 18 years ago committed by Junio C Hamano
parent
commit
072570ee26
  1. 25
      gitweb/gitweb.perl

25
gitweb/gitweb.perl

@ -132,7 +132,7 @@ our %feature = (
# $feature{'snapshot'}{'default'} = [undef]; # $feature{'snapshot'}{'default'} = [undef];
# To have project specific config enable override in $GITWEB_CONFIG # To have project specific config enable override in $GITWEB_CONFIG
# $feature{'snapshot'}{'override'} = 1; # $feature{'snapshot'}{'override'} = 1;
# and in project config gitweb.snapshot = none|gzip|bzip2; # and in project config gitweb.snapshot = none|gzip|bzip2|zip;
'snapshot' => { 'snapshot' => {
'sub' => \&feature_snapshot, 'sub' => \&feature_snapshot,
'override' => 0, 'override' => 0,
@ -244,6 +244,8 @@ sub feature_snapshot {
return ('x-gzip', 'gz', 'gzip'); return ('x-gzip', 'gz', 'gzip');
} elsif ($val eq 'bzip2') { } elsif ($val eq 'bzip2') {
return ('x-bzip2', 'bz2', 'bzip2'); return ('x-bzip2', 'bz2', 'bzip2');
} elsif ($val eq 'zip') {
return ('x-zip', 'zip', '');
} elsif ($val eq 'none') { } elsif ($val eq 'none') {
return (); return ();
} }
@ -3976,19 +3978,26 @@ sub git_snapshot {
$hash = git_get_head_hash($project); $hash = git_get_head_hash($project);
} }


my $filename = decode_utf8(basename($project)) . "-$hash.tar.$suffix"; my $git = git_cmd_str();
my $name = $project;
$name =~ s/\047/\047\\\047\047/g;
my $filename = decode_utf8(basename($project));
my $cmd;
if ($suffix eq 'zip') {
$filename .= "-$hash.$suffix";
$cmd = "$git archive --format=zip --prefix=\'$name\'/ $hash";
} else {
$filename .= "-$hash.tar.$suffix";
$cmd = "$git archive --format=tar --prefix=\'$name\'/ $hash | $command";
}


print $cgi->header( print $cgi->header(
-type => "application/$ctype", -type => "application/$ctype",
-content_disposition => 'inline; filename="' . "$filename" . '"', -content_disposition => 'inline; filename="' . "$filename" . '"',
-status => '200 OK'); -status => '200 OK');


my $git = git_cmd_str(); open my $fd, "-|", $cmd
my $name = $project; or die_error(undef, "Execute git-archive failed");
$name =~ s/\047/\047\\\047\047/g;
open my $fd, "-|",
"$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
or die_error(undef, "Execute git-tar-tree failed");
binmode STDOUT, ':raw'; binmode STDOUT, ':raw';
print <$fd>; print <$fd>;
binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi

Loading…
Cancel
Save