Skip to contentSkip to conversation

gitweb / cg-export

PATCH Toby White 7 participants 13 messages Jun 15, 2016

lore
Share & tools
lore

Toby White

author
#0 lore raw

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 2006-08-16 00:58:38.000000000 +0100 renamed from gitweb.cgi.orig 2006-08-16 01:00:03.000000000 +0100 +16 -0
@@ -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'};
author
#1 lore raw

Re: gitweb / cg-export - corrected patch

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

Correct patch below.

Toby

gitweb.cgi 2006-08-16 00:58:38.000000000 +0100 renamed from gitweb.cgi.orig 2006-08-16 01:00:03.000000000 +0100 +18 -0
@@ -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'};
#2 lore raw
In reply to Toby White
Quoted 3 lines · Toby White

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?

Quoted 9 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).

Quoted 2 lines

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).

Signature · 3 lines
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git
#3 lore raw
Quoted 14 lines · Jakub Narebski
Quoted 3 lines · Toby White

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?

Quoted 6 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.

Quoted 8 lines
Quoted 3 lines

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

gitweb/gitweb.perl +17 -0
index 37a6284..b9b522a 100755
@@ -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) {
#4 lore raw

hoi :)

gitweb/gitweb.perl sub git_shortlog_body { · line 1341

Quoted 8 lines · Aneesh Kumar K.V
gitweb/gitweb.perl +1 -0
@@ -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.

Signature · 1 line
Martin Waitz
#5 lore raw
Quoted 14 lines · Martin Waitz

hoi :)

gitweb/gitweb.perl sub git_shortlog_body { · line 1341

Quoted 8 lines · Aneesh Kumar K.V
gitweb/gitweb.perl +1 -0
@@ -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

#6 lore raw
In reply to Aneesh Kumar K.V
Quoted 3 lines · Aneesh Kumar K.V

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.

Quoted 42 lines
gitweb/gitweb.perl +17 -0
index 37a6284..b9b522a 100755
@@ -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) {
#7 lore raw

gitweb: Support for snapshots in gitweb

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

---
 gitweb/gitweb.perl |   34 ++++++++++++++++++++++++++++++----
 1 files changed, 30 insertions(+), 4 deletions(-)
gitweb/gitweb.perl +30 -4
index 37a6284..4c78e80 100755
@@ -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) {
Signature · 1 line
1.4.2.rc1.g83e1-dirty
#8 lore raw

Re: gitweb: Support for snapshots in gitweb

gitweb/gitweb.perl sub git_tree { · line 2111

Quoted 11 lines · Aneesh Kumar K.V
gitweb/gitweb.perl +7 -0
@@ -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".

gitweb/gitweb.perl sub git_tree { · line 2113

Quoted 1 line
gitweb/gitweb.perl +1 -0
+	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?

#9 lore raw

Re: gitweb: Support for snapshots in gitweb

Quoted 17 lines · Junio C Hamano

gitweb/gitweb.perl sub git_tree { · line 2111

Quoted 11 lines · Aneesh Kumar K.V
gitweb/gitweb.perl +7 -0
@@ -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:

Quoted 9 lines
        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.

Quoted 11 lines

gitweb/gitweb.perl sub git_tree { · line 2113

Quoted 1 line
gitweb/gitweb.perl +1 -0
+     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

#10 lore raw

Re: gitweb: Support for snapshots in gitweb

In reply to Aneesh Kumar K.V
Quoted 3 lines · Aneesh Kumar K.V

+       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).

Signature · 3 lines
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git
#11 lore raw
In reply to Aneesh Kumar K.V
Quoted 19 lines · Aneesh Kumar K.V
Quoted 18 lines · Jakub Narebski
Quoted 3 lines · Toby White

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?

Quoted 9 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.

Quoted 6 lines
Quoted 4 lines

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

gitweb/gitweb.perl +19 -1
index 37a6284..b2e375e 100755
@@ -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'};
#12 lore raw
Quoted 21 lines · Aneesh Kumar K.V
Quoted 20 lines · Aneesh Kumar K.V
Quoted 19 lines · Jakub Narebski
Quoted 3 lines · Toby White

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?

Quoted 9 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.

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

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.

gitweb/gitweb.perl sub git_tree { · line 2108

Quoted 7 lines
gitweb/gitweb.perl +7 -0
+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