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>
Mark Levedahl committed
May 20, 2007 at 11:46 UTC
072570ee2689c5f19513157d654f04f5a7113a24
1 file changed
+17
-8
gitweb/gitweb.perl
+17
-8
@@ -132,7 +132,7 @@ our %feature = (
132
# $feature{'snapshot'}{'default'} = [undef];
133
# To have project specific config enable override in $GITWEB_CONFIG
134
# $feature{'snapshot'}{'override'} = 1;
135
- # and in project config gitweb.snapshot = none|gzip|bzip2;
135
+ # and in project config gitweb.snapshot = none|gzip|bzip2|zip;
136
'snapshot' => {
137
'sub' => \&feature_snapshot,
138
'override' => 0,
@@ -244,6 +244,8 @@ sub feature_snapshot {
244
return ('x-gzip', 'gz', 'gzip');
245
} elsif ($val eq 'bzip2') {
246
return ('x-bzip2', 'bz2', 'bzip2');
247
+ } elsif ($val eq 'zip') {
248
+ return ('x-zip', 'zip', '');
249
} elsif ($val eq 'none') {
250
return ();
251
}
@@ -3976,19 +3978,26 @@ sub git_snapshot {
3978
$hash = git_get_head_hash($project);
3979
}
3980
3979
- my $filename = decode_utf8(basename($project)) . "-$hash.tar.$suffix";
3981
+ my $git = git_cmd_str();
3982
+ my $name = $project;
3983
+ $name =~ s/\047/\047\\\047\047/g;
3984
+ my $filename = decode_utf8(basename($project));
3985
+ my $cmd;
3986
+ if ($suffix eq 'zip') {
3987
+ $filename .= "-$hash.$suffix";
3988
+ $cmd = "$git archive --format=zip --prefix=\'$name\'/ $hash";
3989
+ } else {
3990
+ $filename .= "-$hash.tar.$suffix";
3991
+ $cmd = "$git archive --format=tar --prefix=\'$name\'/ $hash | $command";
3992
+ }
3993
3994
print $cgi->header(
3995
-type => "application/$ctype",
3996
-content_disposition => 'inline; filename="' . "$filename" . '"',
3997
-status => '200 OK');
3998
3986
- my $git = git_cmd_str();
3987
- my $name = $project;
3988
- $name =~ s/\047/\047\\\047\047/g;
3989
- open my $fd, "-|",
3990
- "$git archive --format=tar --prefix=\'$name\'/ $hash | $command"
3991
- or die_error(undef, "Execute git-tar-tree failed");
3999
+ open my $fd, "-|", $cmd
4000
+ or die_error(undef, "Execute git-archive failed");
4001
binmode STDOUT, ':raw';
4002
print <$fd>;
4003
binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi