git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] gitweb: Support for snapshot

From
Aneesh Kumar <aneesh.kumar@gmail.com>
Date
Aug 19, 2006, 08:10 UTC
Message-ID
<cc723f590608190110t68e6de8etbf6b5b002fd83ca1@mail.gmail.com>
In-Reply-To
<7v64gp7prk.fsf@assigned-by-dhcp.cox.net>
On 8/19/06, Junio C Hamano <junkio@cox.net> wrote:
Show 21 quoted lines
> Luben Tuikov <ltuikov@yahoo.com> writes:
>
> > --- "Aneesh Kumar K.V" <aneesh.kumar@gmail.com> 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'};
Previous: Timo HirvonenNext: Junio C Hamano
Message 5 of 14 in “gitweb: Support for snapshot”
  1. Aneesh Kumar K.VAug 17, 2006
  2. gitweb: Support for snapshotAneesh Kumar K.V, Aug 18, 2006
  3. Luben TuikovAug 18, 2006
  4. Timo HirvonenAug 18, 2006
  5. Aneesh KumarAug 19, 2006
  6. Junio C HamanoAug 19, 2006
  7. Jakub NarebskiAug 19, 2006
  8. Jakub NarebskiAug 19, 2006
  9. Aneesh Kumar K.VAug 19, 2006
  10. Aneesh Kumar K.VAug 19, 2006
  11. Jakub NarebskiAug 19, 2006
  12. Aneesh Kumar K.VAug 19, 2006
  13. Aneesh Kumar K.VAug 19, 2006
  14. Junio C HamanoAug 19, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.