threads / discuss / 5294

gitweb / cg-export

Subject: gitweb / cg-export

## tl;dr

13 messages between Aug 16, 2006 and Aug 17, 2006.

replies: 12people: 7as markdown or json

Toby White· Aug 16, 2006, 00:16 UTC · lore

I was wondering if a feature like the following would be of use to anyone except me: I'd like to be able to download the full source of a given tree from gitweb.

Use cases:

a) I'm browsing history through gitweb, find the tree I'm interested in & want to download the whole tree without cutting and pasting hashes.

b) I want to be able to quickly let people grab my latest revision who don't have git installed, without faffing about creating tarballs & emailing them; I'd like to be able to paste a URL straight into my IM client.

I've quickly hacked gitweb to do this for me - patch below.

It adds an extra link to the 'commit' page. Next to the link that would lead you to 'tree', there is 'tar.gz' which simply returns the tar.gz of the same tree.

The patch is against the version of gitweb currently in Debian, which is, erm, '264-1', apparently, because that's what I had to hand.

Anyway. I'm no git expert so perhaps this is a really bad idea, but I find it useful.

Toby White

--- gitweb.cgi.orig 2006-08-16 01:00:03.000000000 +0100 +++ gitweb.cgi 2006-08-16 00:58:38.000000000 +0100

@@ -180,6 +180,9 @@
 } elsif ($action eq "tree") {
        git_tree();
+       exit;
 } elsif ($action eq "rss") {
        git_rss();
        exit;
@@ -1523,6 +1526,21 @@
        git_footer_html();
 }

+sub git_export {
+       if (!defined $hash) {
+               $hash = git_read_head($project);
+               if (defined $file_name) {
+                       my $base = $hash_base || $hash;
+                       $hash = git_get_hash_by_path($base, $file_name, "tree");
+               }
+               if (!defined $hash_base) {
+                       $hash_base = $hash;
+               }
+       }
+       print $cgi->header(-type=>'application/x-tar',  -Content-Encoding=>'x-gzip', -status=> '200 OK');
+       exec "$gitbin/git-tar-tree $hash $project | gzip -c9" or die_error(undef, "Execute git-tar-tree failed.");
+}
+
 sub git_rss {
        # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
        open my $fd, "-|", "$gitbin/git-rev-list --max-count=150 " . git_read_head($project) or die_error(undef, "Open failed.");
@@ -1779,6 +1797,7 @@
              $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash"), class => "list"}, $co{'tree'})
.
              "</td>" .
              "<td class=\"link\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree"
) .
+              "|" . $cgi->a({-href => "$my_uri/$project.tar.gz?" . esc_param("p=$project;a=export;h=$co{'tree'};hb=$hash")}, "tar.
gz") .
              "</td>" .
              "</tr>\n";
        my $parents  = $co{'parents'};
Toby White· Aug 16, 2006, 00:23 UTC · re: Toby White · lore

Re: gitweb / cg-export - corrected patch

Argh - sorry, patch got mangled somehow in previous message.
Correct patch below.
Toby

--- gitweb.cgi.orig 2006-08-16 01:00:03.000000000 +0100 +++ gitweb.cgi 2006-08-16 00:58:38.000000000 +0100

@@ -180,6 +180,9 @@
 } elsif ($action eq "tree") {
        git_tree();
        exit;
+} elsif ($action eq "export") {
+       git_export();
+       exit;
 } elsif ($action eq "rss") {
        git_rss();
        exit;
@@ -1523,6 +1526,21 @@
        git_footer_html();
 }

+sub git_export {
+       if (!defined $hash) {
+               $hash = git_read_head($project);
+               if (defined $file_name) {
+                       my $base = $hash_base || $hash;
+                       $hash = git_get_hash_by_path($base, $file_name, "tree");
+               }
+               if (!defined $hash_base) {
+                       $hash_base = $hash;
+               }
+       }
+       print $cgi->header(-type=>'application/x-tar',  -Content-Encoding=>'x-gzip', -status=> '200 OK');
+       exec "$gitbin/git-tar-tree $hash $project | gzip -c9" or die_error(undef, "Execute git-tar-tree failed.");
+}
+
 sub git_rss {
        # http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
        open my $fd, "-|", "$gitbin/git-rev-list --max-count=150 " . git_read_head($project) or die_error(undef, "Open failed.");
@@ -1779,6 +1797,7 @@
              $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash"), class => "list"}, $co{'tree'})
.
              "</td>" .
              "<td class=\"link\">" . $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=tree;h=$co{'tree'};hb=$hash")}, "tree"
) .
+              "|" . $cgi->a({-href => "$my_uri/$project.tar.gz?" . esc_param("p=$project;a=export;h=$co{'tree'};hb=$hash")}, "tar.
gz") .
              "</td>" .
              "</tr>\n";
        my $parents  = $co{'parents'};
Jakub Narebski· Aug 16, 2006, 09:54 UTC · re: Toby White · lore

Re: gitweb / cg-export

Toby White wrote:
> I was wondering if a feature like the following would be of
> use to anyone except me: I'd like to be able to download
> the full source of a given tree from gitweb.

[...] So you want to have snapshot of a tree. Why not snapshot of a commit, or of a tag?

Show 9 quoted lines
> I've quickly hacked gitweb to do this for me - patch below.
> 
> It adds an extra link to the 'commit' page. Next to the link
> that would lead you to 'tree', there is 'tar.gz' which simply
> returns the tar.gz of the same tree.
> 
> The patch is against the version of gitweb currently in
> Debian, which is, erm, '264-1', apparently, because that's
> what I had to hand.
It is really better to hack git with git. And you can use current gitweb
with old git (well, not always, as current gitweb requires --full-history
option to git-rev-list to be available).
 
> Anyway. I'm no git expert so perhaps this is a really bad
> idea, but I find it useful.

It is usefull idea, as it was implemented independently by Sven Verdoolaege in http://marc.theaimsgroup.com/?l=git&m=111909432415478&w=2 directly in gitweb, and by Sham Chukoury in gitweb-xmms2 using snapshot.cgi in Python in "Snapshot links support" commit http://git.xmms.se/?p=gitweb-xmms2.git;a=commit;h=3d0284bb784041907de33df5cff8449f8aeb072e and "Add xmms2 project's snapshot.cgi" commit http://git.xmms.se/?p=gitweb-xmms2.git;a=commit;h=3d0284bb784041907de33df5cff8449f8aeb072e

I have planned to add snapshot support, see "[RFC] gitweb wishlist and TODO
list" thread in mailing list archives, check
   http://git.or.cz/gitwiki/GitCommunity
for list, but I was planning to do some refactoring, including 
<td class="link"> links refactoring (that is where snapshot links would be
added).
-- 
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git
Aneesh Kumar K.V· Aug 16, 2006, 10:53 UTC · re: Jakub Narebski · lore

Re: gitweb / cg-export

Jakub Narebski wrote:
Show 23 quoted lines
> Toby White wrote:
> 
>> I was wondering if a feature like the following would be of
>> use to anyone except me: I'd like to be able to download
>> the full source of a given tree from gitweb.
> [...]
> So you want to have snapshot of a tree. Why not snapshot of a commit, 
> or of a tag?
> 
>> I've quickly hacked gitweb to do this for me - patch below.
>>
>> It adds an extra link to the 'commit' page. Next to the link
>> that would lead you to 'tree', there is 'tar.gz' which simply
>> returns the tar.gz of the same tree.
>>
>> The patch is against the version of gitweb currently in
>> Debian, which is, erm, '264-1', apparently, because that's
>> what I had to hand.
> 
> It is really better to hack git with git. And you can use current gitweb
> with old git (well, not always, as current gitweb requires --full-history
> option to git-rev-list to be available).
> 
How about the below on top of latest git 
-aneesh
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 37a6284..b9b522a 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -175,6 +175,7 @@ my %actions = (
 	"tag" => \&git_tag,
 	"tags" => \&git_tags,
 	"tree" => \&git_tree,
+	"snapshot" => \&git_snapshot,
 );
 
 $action = 'summary' if (!defined($action));
@@ -1334,6 +1335,7 @@ sub git_shortlog_body {
 		      "<td class=\"link\">" .
 		      $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " .
 		      $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") .
+		      " | " .$cgi->a({-href => "$my_uri/$project.tar.gz?" . esc_param("p=$project;a=snapshot;h=$commit")}, "snapshot") .
 		      "</td>\n" .
 		      "</tr>\n";
 	}
@@ -2097,6 +2099,21 @@ sub git_tree {
 	git_footer_html();
 }
 
+sub git_snapshot {
+	if (!defined $hash) {
+		$hash = git_get_head_hash($project);
+	}
+	print $cgi->header(-type=>'application/x-tar',
+			  -Content-Encoding=>'x-gzip', -status=> '200 OK');
+	open my $fd, "-|", "$GIT tar-tree $hash $project | gzip -c9" 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 {
 	my $head = git_get_head_hash($project);
 	if (!defined $hash) {
Aneesh Kumar K.V· Aug 16, 2006, 11:32 UTC · re: Aneesh Kumar K.V · lore

Re: gitweb / cg-export

Aneesh Kumar K.V wrote:
Show 26 quoted lines
> Jakub Narebski wrote:
>> Toby White wrote:
>>
>>> I was wondering if a feature like the following would be of
>>> use to anyone except me: I'd like to be able to download
>>> the full source of a given tree from gitweb.
>> [...]
>> So you want to have snapshot of a tree. Why not snapshot of a commit, 
>> or of a tag?
>>
>>> I've quickly hacked gitweb to do this for me - patch below.
>>>
>>> It adds an extra link to the 'commit' page. Next to the link
>>> that would lead you to 'tree', there is 'tar.gz' which simply
>>> returns the tar.gz of the same tree.
>>>
>>> The patch is against the version of gitweb currently in
>>> Debian, which is, erm, '264-1', apparently, because that's
>>> what I had to hand.
>>
>> It is really better to hack git with git. And you can use current gitweb
>> with old git (well, not always, as current gitweb requires --full-history
>> option to git-rev-list to be available).
>>
> 
> How about the below on top of latest git
Add it to git_commit too. The patch contains the pervious changes also.
-aneesh
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 37a6284..b2e375e 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -175,6 +175,7 @@ my %actions = (
 	"tag" => \&git_tag,
 	"tags" => \&git_tags,
 	"tree" => \&git_tree,
+	"snapshot" => \&git_snapshot,
 );
 
 $action = 'summary' if (!defined($action));
@@ -1334,6 +1335,7 @@ sub git_shortlog_body {
 		      "<td class=\"link\">" .
 		      $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " .
 		      $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") .
+		      " | " .$cgi->a({-href => "$my_uri/$project.tar.gz?" . esc_param("p=$project;a=snapshot;h=$commit")}, "snapshot") .
 		      "</td>\n" .
 		      "</tr>\n";
 	}
@@ -2097,6 +2099,21 @@ sub git_tree {
 	git_footer_html();
 }
 
+sub git_snapshot {
+	if (!defined $hash) {
+		$hash = git_get_head_hash($project);
+	}
+	print $cgi->header(-type=>'application/x-tar',
+			  -Content-Encoding=>'x-gzip', -status=> '200 OK');
+	open my $fd, "-|", "$GIT tar-tree $hash $project | gzip -c9" 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 {
 	my $head = git_get_head_hash($project);
 	if (!defined $hash) {
@@ -2226,7 +2243,8 @@ sub git_commit {
 	      "<td class=\"sha1\">" .
 	      $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash), class => "list"}, $co{'tree'}) .
 	      "</td>" .
-	      "<td class=\"link\">" . $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)}, "tree") .
+	      "<td class=\"link\">" . $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)}, "tree") . " | " .
+	      $cgi->a({-href => "$my_uri/$project.tar.gz?" . esc_param("p=$project;a=snapshot;h=$hash")}, "snapshot") .
 	      "</td>" .
 	      "</tr>\n";
 	my $parents = $co{'parents'};
Fredrik Kuivinen· Aug 16, 2006, 20:05 UTC · re: Aneesh Kumar K.V · lore

Re: gitweb / cg-export

On Wed, Aug 16, 2006 at 05:02:36PM +0530, Aneesh Kumar K.V wrote:
Show 30 quoted lines
> Aneesh Kumar K.V wrote:
> >Jakub Narebski wrote:
> >>Toby White wrote:
> >>
> >>>I was wondering if a feature like the following would be of
> >>>use to anyone except me: I'd like to be able to download
> >>>the full source of a given tree from gitweb.
> >>[...]
> >>So you want to have snapshot of a tree. Why not snapshot of a commit, 
> >>or of a tag?
> >>
> >>>I've quickly hacked gitweb to do this for me - patch below.
> >>>
> >>>It adds an extra link to the 'commit' page. Next to the link
> >>>that would lead you to 'tree', there is 'tar.gz' which simply
> >>>returns the tar.gz of the same tree.
> >>>
> >>>The patch is against the version of gitweb currently in
> >>>Debian, which is, erm, '264-1', apparently, because that's
> >>>what I had to hand.
> >>
> >>It is really better to hack git with git. And you can use current gitweb
> >>with old git (well, not always, as current gitweb requires --full-history
> >>option to git-rev-list to be available).
> >>
> >
> >How about the below on top of latest git
> 
> Add it to git_commit too. The patch contains the pervious changes also.
> 
Nice.
Show 7 quoted lines
> +sub git_snapshot {
> +	if (!defined $hash) {
> +		$hash = git_get_head_hash($project);
> +	}
> +	print $cgi->header(-type=>'application/x-tar',
> +			  -Content-Encoding=>'x-gzip', -status=> '200 OK');
> +	open my $fd, "-|", "$GIT tar-tree $hash $project | gzip -c9" or die_error(undef, "Execute git-tar-tree failed.");

It might be better to use -6 (the default compression/speed trade-off) instead of using -9 (best but slowest compression) here. Or maybe even make it configurable. On some servers it is probably preferable to make the snapshot (slightly) larger and gain some cpu time.

To get some numbers I made a small benchmark with the current git tree. I get the following on my machine:

Compression/speed Size Time -1 1.1M 0.16s -6 923K 0.36s -9 917K 0.50s

- Fredrik
Junio C Hamano· Aug 16, 2006, 18:01 UTC · re: Aneesh Kumar K.V · lore

Re: gitweb / cg-export

"Aneesh Kumar K.V" <aneesh.kumar@gmail.com> writes:
> How about the below on top of latest git
>
> -aneesh

This looks Ok (except "$project" needs to be shell quoted on the pipe-open line and possibly in the URL; there may be some other minor details I missed). It needs to be protected by elective, opt-in configuration variable, similarly to how "blame" is done, since I suspect this would be rather expensive.

Show 42 quoted lines
> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
> index 37a6284..b9b522a 100755
> --- a/gitweb/gitweb.perl
> +++ b/gitweb/gitweb.perl
> @@ -175,6 +175,7 @@ my %actions = (
>  	"tag" => \&git_tag,
>  	"tags" => \&git_tags,
>  	"tree" => \&git_tree,
> +	"snapshot" => \&git_snapshot,
>  );
>  
>  $action = 'summary' if (!defined($action));
> @@ -1334,6 +1335,7 @@ sub git_shortlog_body {
>  		      "<td class=\"link\">" .
>  		      $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " .
>  		      $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") .
> +		      " | " .$cgi->a({-href => "$my_uri/$project.tar.gz?" . esc_param("p=$project;a=snapshot;h=$commit")}, "snapshot") .
>  		      "</td>\n" .
>  		      "</tr>\n";
>  	}
> @@ -2097,6 +2099,21 @@ sub git_tree {
>  	git_footer_html();
>  }
>  
> +sub git_snapshot {
> +	if (!defined $hash) {
> +		$hash = git_get_head_hash($project);
> +	}
> +	print $cgi->header(-type=>'application/x-tar',
> +			  -Content-Encoding=>'x-gzip', -status=> '200 OK');
> +	open my $fd, "-|", "$GIT tar-tree $hash $project | gzip -c9" 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 {
>  	my $head = git_get_head_hash($project);
>  	if (!defined $hash) {
Aneesh Kumar K.V· Aug 17, 2006, 06:29 UTC · re: Junio C Hamano · lore

gitweb: Support for snapshots in gitweb

This add snapshot support to gitweb. This need to be enabled per project using config gitweb.snapshot = true

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@gmail.com>
---
 gitweb/gitweb.perl |   34 ++++++++++++++++++++++++++++++----
 1 files changed, 30 insertions(+), 4 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 37a6284..4c78e80 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -175,6 +175,7 @@ my %actions = (
 	"tag" => \&git_tag,
 	"tags" => \&git_tags,
 	"tree" => \&git_tree,
+	"snapshot" => \&git_snapshot,
 );
 
 $action = 'summary' if (!defined($action));
@@ -1309,6 +1310,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');
 	$from = 0 unless defined $from;
 	$to = $#{$revlist} if (!defined $to || $#{$revlist} < $to);
 
@@ -1333,8 +1335,11 @@ sub git_shortlog_body {
 		print "</td>\n" .
 		      "<td class=\"link\">" .
 		      $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " .
-		      $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") .
-		      "</td>\n" .
+		      $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff");
+		if ($have_snapshot) {
+			print " | " .  $cgi->a({-href => href(action=>"snapshot", hash=>$commit)}, "snapshot");
+		}
+		print "</td>\n" .
 		      "</tr>\n";
 	}
 	if (defined $extra) {
@@ -2097,6 +2102,23 @@ sub git_tree {
 	git_footer_html();
 }
 
+sub git_snapshot {
+	if (!defined $hash) {
+		$hash = git_get_head_hash($project);
+	}
+	print $cgi->header(-type=>'application/x-tar', -Content-Encoding=>'x-gzip',
+		'-content-disposition' => "inline; filename=\"$project.tar.gz\"",
+		-status=> '200 OK');
+
+	open my $fd, "-|", "$GIT tar-tree $hash \'$project\' | gzip -c6" 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 {
 	my $head = git_get_head_hash($project);
 	if (!defined $hash) {
@@ -2191,6 +2213,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 $formats_nav = '';
 	if (defined $file_name && defined $co{'parent'}) {
 		my $parent = $co{'parent'};
@@ -2226,8 +2249,11 @@ sub git_commit {
 	      "<td class=\"sha1\">" .
 	      $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash), class => "list"}, $co{'tree'}) .
 	      "</td>" .
-	      "<td class=\"link\">" . $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)}, "tree") .
-	      "</td>" .
+	      "<td class=\"link\">" . $cgi->a({-href => href(action=>"tree", hash=>$co{'tree'}, hash_base=>$hash)}, "tree");
+	if ($have_snapshot) {
+	      print " | " .  $cgi->a({-href => href(action=>"snapshot", hash=>$hash)}, "snapshot");
+	}
+	print "</td>" .
 	      "</tr>\n";
 	my $parents = $co{'parents'};
 	foreach my $par (@$parents) {
-- 
1.4.2.rc1.g83e1-dirty
Junio C Hamano· Aug 17, 2006, 07:34 UTC · re: Aneesh Kumar K.V · lore

Re: gitweb: Support for snapshots in gitweb

"Aneesh Kumar K.V" <aneesh.kumar@gmail.com> writes:
Show 11 quoted lines
> @@ -2097,6 +2102,23 @@ sub git_tree {
>  	git_footer_html();
>  }
>  
> +sub git_snapshot {
> +	if (!defined $hash) {
> +		$hash = git_get_head_hash($project);
> +	}
> +	print $cgi->header(-type=>'application/x-tar', -Content-Encoding=>'x-gzip',
> +		'-content-disposition' => "inline; filename=\"$project.tar.gz\"",
> +		-status=> '200 OK');

These -Mixed-Case, '-sometimes-quoted', spaces sometimes around double-arrow sometimes missing, parameters bother me. Perhaps:

	print $cgi->header(-type => 'application/x-tar',
                           -content-encoding => 'x-gzip',
                           -content-disposition =>
                               "inline; filename=\"$project.tar.gz\"",
                           -status => '200 OK');

RFC 2616 says that "gzip" content-coding is registered with IANA, so I do not think you need to say "x-gzip".

> +	open my $fd, "-|", "$GIT tar-tree $hash \'$project\' | gzip -c6" or die_error(undef, "Execute git-tar-tree failed.");

I think this "6" is because somebody suggested to use the default "6" instead of "9" in your original and the suggestion was because "9" tends to be too expensive.

But if we do not have a good, specific, reason to use "6" (as opposed to, say, "5" or "7") and have "6" here only because we happen to know "6" is the current gzip default, then probably we are better off just letting gzip decide what compression level to use without specifying it ourselves?

Aneesh Kumar· Aug 17, 2006, 07:48 UTC · re: Junio C Hamano · lore

Re: gitweb: Support for snapshots in gitweb

On 8/17/06, Junio C Hamano <junkio@cox.net> wrote:
Show 26 quoted lines
> "Aneesh Kumar K.V" <aneesh.kumar@gmail.com> writes:
>
> > @@ -2097,6 +2102,23 @@ sub git_tree {
> >       git_footer_html();
> >  }
> >
> > +sub git_snapshot {
> > +     if (!defined $hash) {
> > +             $hash = git_get_head_hash($project);
> > +     }
> > +     print $cgi->header(-type=>'application/x-tar', -Content-Encoding=>'x-gzip',
> > +             '-content-disposition' => "inline; filename=\"$project.tar.gz\"",
> > +             -status=> '200 OK');
>
> These -Mixed-Case, '-sometimes-quoted', spaces sometimes around
> double-arrow sometimes missing, parameters bother me.  Perhaps:
>
>         print $cgi->header(-type => 'application/x-tar',
>                            -content-encoding => 'x-gzip',
>                            -content-disposition =>
>                                "inline; filename=\"$project.tar.gz\"",
>                            -status => '200 OK');
>
> RFC 2616 says that "gzip" content-coding is registered with
> IANA, so I do not think you need to say "x-gzip".
>

Please feel free to change the code. Or if you want me to send another patch with the changes suggested i can do the same. Let me know.

Show 11 quoted lines
> > +     open my $fd, "-|", "$GIT tar-tree $hash \'$project\' | gzip -c6" or die_error(undef, "Execute git-tar-tree failed.");
>
> I think this "6" is because somebody suggested to use the
> default "6" instead of "9" in your original and the suggestion
> was because "9" tends to be too expensive.
>
> But if we do not have a good, specific, reason to use "6" (as
> opposed to, say, "5" or "7") and have "6" here only because we
> happen to know "6" is the current gzip default, then probably we
> are better off just letting gzip decide what compression level
> to use without specifying it ourselves?
yes that is correct. I  changed it because it was suggested.
-aneesh
Jakub Narebski· Aug 17, 2006, 09:49 UTC · re: Aneesh Kumar K.V · lore

Re: gitweb: Support for snapshots in gitweb

Aneesh Kumar K.V wrote:
> +       print $cgi->header(-type=>'application/x-tar', -Content-Encoding=>'x-gzip',
> +               '-content-disposition' => "inline; filename=\"$project.tar.gz\"",
> +               -status=> '200 OK');
Wouldn't it be better to put $hash somewhere in the name?

And please remember that $project can contain slashes, so it should be processed (only basename of $project, perhaps).

-- 
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git
Martin Waitz· Aug 16, 2006, 22:40 UTC · re: Aneesh Kumar K.V · lore

Re: gitweb / cg-export

hoi :)
On Wed, Aug 16, 2006 at 04:23:05PM +0530, Aneesh Kumar K.V wrote:
Show 8 quoted lines
> @@ -1334,6 +1335,7 @@ sub git_shortlog_body {
>  		      "<td class=\"link\">" .
>  		      $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " .
>  		      $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") .
> +		      " | " .$cgi->a({-href => "$my_uri/$project.tar.gz?" . esc_param("p=$project;a=snapshot;h=$commit")}, "snapshot") .
>  		      "</td>\n" .
>  		      "</tr>\n";
>  	}

Isn't there some other way to tell the webbroser how to name the file? I thought there is some HTML header to explicitly give one file name.

-- 
Martin Waitz
Kay Sievers· Aug 16, 2006, 22:50 UTC · re: Martin Waitz · lore

Re: gitweb / cg-export

On Thu, 2006-08-17 at 00:40 +0200, Martin Waitz wrote:
Show 14 quoted lines
> hoi :)
> 
> On Wed, Aug 16, 2006 at 04:23:05PM +0530, Aneesh Kumar K.V wrote:
> > @@ -1334,6 +1335,7 @@ sub git_shortlog_body {
> >  		      "<td class=\"link\">" .
> >  		      $cgi->a({-href => href(action=>"commit", hash=>$commit)}, "commit") . " | " .
> >  		      $cgi->a({-href => href(action=>"commitdiff", hash=>$commit)}, "commitdiff") .
> > +		      " | " .$cgi->a({-href => "$my_uri/$project.tar.gz?" . esc_param("p=$project;a=snapshot;h=$commit")}, "snapshot") .
> >  		      "</td>\n" .
> >  		      "</tr>\n";
> >  	}
> 
> Isn't there some other way to tell the webbroser how to name the file?
> I thought there is some HTML header to explicitly give one file name.
Something like in line 1923?
  $cgi->header(-type => "$type", '-content-disposition' => "inline; filename=\"$save_as\"");
Kay

← back to recent threads