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

Re: gitweb / cg-export

From
Aneesh Kumar K.V <aneesh.kumar@gmail.com>
Date
Aug 16, 2006, 11:32 UTC
Message-ID
<ebuvok$vnv$1@sea.gmane.org>
In-Reply-To
<44E2F911.6060002@gmail.com>
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'};
Previous: Aneesh Kumar K.VNext: Fredrik Kuivinen
Message 5 of 13 in “gitweb / cg-export”
  1. Toby WhiteAug 16, 2006
  2. Toby WhiteAug 16, 2006
  3. Jakub NarebskiAug 16, 2006
  4. Aneesh Kumar K.VAug 16, 2006
  5. Aneesh Kumar K.VAug 16, 2006
  6. Fredrik KuivinenAug 16, 2006
  7. Junio C HamanoAug 16, 2006
  8. gitweb: Support for snapshots in gitwebAneesh Kumar K.V, Aug 17, 2006
  9. Junio C HamanoAug 17, 2006
  10. Aneesh KumarAug 17, 2006
  11. Jakub NarebskiAug 17, 2006
  12. Martin WaitzAug 16, 2006
  13. Kay SieversAug 16, 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.