On 8/19/06, Junio C Hamano <junkio@xxxxxxx> wrote:
Luben Tuikov <ltuikov@xxxxxxxxx> writes: > --- "Aneesh Kumar K.V" <aneesh.kumar@xxxxxxxxx> wrote: >> This adds snapshort support in gitweb. To enable one need to >> set gitweb.snapshot = true in the config file. > > Could you use bzip2? It generates smaller files (better compression), > which is a good thing when downloading over a network. Because bzip2 is heavier on the server than gzip is (and gzip is heavier than "gzip -1" is), there obviously is a trade-off. We would want it to be configurable just like blame and snapshot itself. Maybe: config.snapshot = no | yes | gzip | bzip2 ... By the way, I think it is a mistake to use only $GIT_DIR/config to control these features.
I have coded this at What should be the content-encoding in this case x-$snapshot ? This is the untested diff that i have. Is this what we are looking for ? -aneesh
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index f8d1036..6ad3141 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -67,6 +67,15 @@ # file to use for guessing MIME types be # (relative to the current git repository) our $mimetypes_file = undef; +# don't enable snapshot support by default +# possible values are no|gzip|bzip2| +our $snapshot = "no"; + +# this indicate whether the snapshot support can be overridden +# by a project specific config. +# possible values are yes|no +our $snapshot_override = "no"; + our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++"; require $GITWEB_CONFIG if -e $GITWEB_CONFIG; @@ -1397,7 +1406,7 @@ 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 ($have_snapshot, $snapshot_comp) = git_get_project_snapshot_config(); $from = 0 unless defined $from; $to = $#{$revlist} if (!defined $to || $#{$revlist} < $to); @@ -2200,13 +2209,14 @@ sub git_snapshot { } my $filename = basename($project) . "-$hash.tar.gz"; + my ($have_snapshot, $snapshot_comp) = git_get_project_snapshot_config(); print $cgi->header(-type => 'application/x-tar', - -content-encoding => 'x-gzip', + -content-encoding => "x-$snapshot_comp", '-content-disposition' => "inline; filename=\"$filename\"", -status => '200 OK'); - open my $fd, "-|", "$GIT tar-tree $hash \'$project\' | gzip" or + open my $fd, "-|", "$GIT tar-tree $hash \'$project\' | $snapshot_comp" or die_error(undef, "Execute git-tar-tree failed."); binmode STDOUT, ':raw'; print <$fd>; @@ -2215,6 +2225,27 @@ sub git_snapshot { } +sub git_get_project_snapshot_config() +{ + my $snap; + + if ($snapshot =~ m/no/) { + return (0, undef); + } + + if ($snapshot_override =~ m/no/) { + return (1, $snapshot); + } + + $snap = git_get_project_config('snapshot'); + + if ($snap and $snap =~ m/no/) { + return (0, undef); + } + return (1, $snap); +} + +} sub git_log { my $head = git_get_head_hash($project); @@ -2293,7 +2324,7 @@ 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 ($have_snapshot, $snapshot_comp) = git_get_project_snapshot_config(); my $formats_nav = ''; if (defined $file_name && defined $co{'parent'}) { my $parent = $co{'parent'};