git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* gitweb / cg-export
@ 2006-08-16  0:16 Toby White
  2006-08-16  0:23 ` gitweb / cg-export - corrected patch Toby White
  2006-08-16  9:54 ` gitweb / cg-export Jakub Narebski
  0 siblings, 2 replies; 13+ messages in thread
From: Toby White @ 2006-08-16  0:16 UTC (permalink / raw)
  To: git

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'};

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: gitweb / cg-export - corrected patch
  2006-08-16  0:16 gitweb / cg-export Toby White
@ 2006-08-16  0:23 ` Toby White
  2006-08-16  9:54 ` gitweb / cg-export Jakub Narebski
  1 sibling, 0 replies; 13+ messages in thread
From: Toby White @ 2006-08-16  0:23 UTC (permalink / raw)
  To: Toby White; +Cc: git

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'};

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: gitweb / cg-export
  2006-08-16  0:16 gitweb / cg-export Toby White
  2006-08-16  0:23 ` gitweb / cg-export - corrected patch Toby White
@ 2006-08-16  9:54 ` Jakub Narebski
  2006-08-16 10:53   ` Aneesh Kumar K.V
  1 sibling, 1 reply; 13+ messages in thread
From: Jakub Narebski @ 2006-08-16  9:54 UTC (permalink / raw)
  To: git

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: gitweb / cg-export
  2006-08-16  9:54 ` gitweb / cg-export Jakub Narebski
@ 2006-08-16 10:53   ` Aneesh Kumar K.V
  2006-08-16 11:32     ` Aneesh Kumar K.V
                       ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Aneesh Kumar K.V @ 2006-08-16 10:53 UTC (permalink / raw)
  To: git

[-- Attachment #1: Type: text/plain, Size: 950 bytes --]

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 

-aneesh


[-- Attachment #2: gitweb.snapshot.diff --]
[-- Type: text/x-patch, Size: 1328 bytes --]

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

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: gitweb / cg-export
  2006-08-16 10:53   ` Aneesh Kumar K.V
@ 2006-08-16 11:32     ` Aneesh Kumar K.V
  2006-08-16 20:05       ` Fredrik Kuivinen
  2006-08-16 18:01     ` Junio C Hamano
  2006-08-16 22:40     ` gitweb / cg-export Martin Waitz
  2 siblings, 1 reply; 13+ messages in thread
From: Aneesh Kumar K.V @ 2006-08-16 11:32 UTC (permalink / raw)
  To: git

[-- Attachment #1: Type: text/plain, Size: 1071 bytes --]

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.

-aneesh


[-- Attachment #2: gitweb.snapshot.diff --]
[-- Type: text/x-patch, Size: 1966 bytes --]

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'};

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: gitweb / cg-export
  2006-08-16 10:53   ` Aneesh Kumar K.V
  2006-08-16 11:32     ` Aneesh Kumar K.V
@ 2006-08-16 18:01     ` Junio C Hamano
  2006-08-17  6:29       ` gitweb: Support for snapshots in gitweb Aneesh Kumar K.V
  2006-08-16 22:40     ` gitweb / cg-export Martin Waitz
  2 siblings, 1 reply; 13+ messages in thread
From: Junio C Hamano @ 2006-08-16 18:01 UTC (permalink / raw)
  To: Aneesh Kumar K.V; +Cc: git

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

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: gitweb / cg-export
  2006-08-16 11:32     ` Aneesh Kumar K.V
@ 2006-08-16 20:05       ` Fredrik Kuivinen
  0 siblings, 0 replies; 13+ messages in thread
From: Fredrik Kuivinen @ 2006-08-16 20:05 UTC (permalink / raw)
  To: Aneesh Kumar K.V; +Cc: git

On Wed, Aug 16, 2006 at 05:02:36PM +0530, Aneesh Kumar K.V wrote:
> 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.

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: gitweb / cg-export
  2006-08-16 10:53   ` Aneesh Kumar K.V
  2006-08-16 11:32     ` Aneesh Kumar K.V
  2006-08-16 18:01     ` Junio C Hamano
@ 2006-08-16 22:40     ` Martin Waitz
  2006-08-16 22:50       ` Kay Sievers
  2 siblings, 1 reply; 13+ messages in thread
From: Martin Waitz @ 2006-08-16 22:40 UTC (permalink / raw)
  To: Aneesh Kumar K.V; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 689 bytes --]

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.

-- 
Martin Waitz

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: gitweb / cg-export
  2006-08-16 22:40     ` gitweb / cg-export Martin Waitz
@ 2006-08-16 22:50       ` Kay Sievers
  0 siblings, 0 replies; 13+ messages in thread
From: Kay Sievers @ 2006-08-16 22:50 UTC (permalink / raw)
  To: Martin Waitz; +Cc: Aneesh Kumar K.V, git

On Thu, 2006-08-17 at 00:40 +0200, Martin Waitz wrote:
> 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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* gitweb: Support for snapshots in gitweb
  2006-08-16 18:01     ` Junio C Hamano
@ 2006-08-17  6:29       ` Aneesh Kumar K.V
  2006-08-17  7:34         ` Junio C Hamano
  2006-08-17  9:49         ` Jakub Narebski
  0 siblings, 2 replies; 13+ messages in thread
From: Aneesh Kumar K.V @ 2006-08-17  6:29 UTC (permalink / raw)
  To: git; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 0 bytes --]



[-- Attachment #2: 0001-gitweb-Support-for-snapshots-in-gitweb.txt --]
[-- Type: text/plain, Size: 3167 bytes --]


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


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: gitweb: Support for snapshots in gitweb
  2006-08-17  6:29       ` gitweb: Support for snapshots in gitweb Aneesh Kumar K.V
@ 2006-08-17  7:34         ` Junio C Hamano
  2006-08-17  7:48           ` Aneesh Kumar
  2006-08-17  9:49         ` Jakub Narebski
  1 sibling, 1 reply; 13+ messages in thread
From: Junio C Hamano @ 2006-08-17  7:34 UTC (permalink / raw)
  To: Aneesh Kumar K.V; +Cc: git

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

> +	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?

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: gitweb: Support for snapshots in gitweb
  2006-08-17  7:34         ` Junio C Hamano
@ 2006-08-17  7:48           ` Aneesh Kumar
  0 siblings, 0 replies; 13+ messages in thread
From: Aneesh Kumar @ 2006-08-17  7:48 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

On 8/17/06, Junio C Hamano <junkio@cox.net> wrote:
> "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.



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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: gitweb: Support for snapshots in gitweb
  2006-08-17  6:29       ` gitweb: Support for snapshots in gitweb Aneesh Kumar K.V
  2006-08-17  7:34         ` Junio C Hamano
@ 2006-08-17  9:49         ` Jakub Narebski
  1 sibling, 0 replies; 13+ messages in thread
From: Jakub Narebski @ 2006-08-17  9:49 UTC (permalink / raw)
  To: git

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2006-08-17  9:48 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-16  0:16 gitweb / cg-export Toby White
2006-08-16  0:23 ` gitweb / cg-export - corrected patch Toby White
2006-08-16  9:54 ` gitweb / cg-export Jakub Narebski
2006-08-16 10:53   ` Aneesh Kumar K.V
2006-08-16 11:32     ` Aneesh Kumar K.V
2006-08-16 20:05       ` Fredrik Kuivinen
2006-08-16 18:01     ` Junio C Hamano
2006-08-17  6:29       ` gitweb: Support for snapshots in gitweb Aneesh Kumar K.V
2006-08-17  7:34         ` Junio C Hamano
2006-08-17  7:48           ` Aneesh Kumar
2006-08-17  9:49         ` Jakub Narebski
2006-08-16 22:40     ` gitweb / cg-export Martin Waitz
2006-08-16 22:50       ` Kay Sievers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).