Calling URL http://<gitweburl>/gitweb.cgi?p=<repo>;a=tree;f=<subdir>;hb=HEAD
will show the tree of <repo>
starting at <subdir>
.
Calling URL http://<gitweburl>/gitweb.cgi?p=<repo>;a=snapshot;f=<subdir>;hb=HEAD
will produce a 404.
Calling URL http://<gitweburl>/gitweb.cgi?p=<repo>.git;a=snapshot;h=HEAD
will provide a snapshot of <repo>
at HEAD revision.
I can't find the right syntax to make Gitweb give a snapshot starting at a sub-directory. I mean something leading to: $ git archive --format=tar --remote=<gituser>@<gitserver>:<repo> HEAD:<subdir>
I naively tried calling URL http://<gitweburl>/gitweb.cgi?p=<repo>;a=snapshot;h=HEAD;f=<subdir>
but that results in an snapshot archive containing the whole repository.
After clicking around in the Gitweb web interface I found out that, changing to "tree" view and moving to <subdir>
and then clicking "snapshot" uses an URL similar to this:
http://<gitweburl>?p=<repo>;a=snapshot;h=42a6503da6aaedc92bb3543e0b0de9b2de0aaae9;sf=tgz
Which delivers exactly what I want but I have no idea what this hash parameter h=...
is. It's no commit id - I've checked. It must somehow identify <subdir>
. But even if it does - this still doesn't help me because somebody just wanting a snapshot starting at/containing only <subdir>
usually doesn't know this hash.
Any idea about how to get a sub-directory snapshot via Gitweb? Thanks in advance!
Addition:
Just found out: h=42a6503da6aaedc92bb3543e0b0de9b2de0aaae9
is the hash value associated to <subdir>
visible by e.g. $ git ls-tree -r -t HEAD
So these 2 commands:
$ git archive --format=tar --remote=<gituser>@<gitserver>:<repo> HEAD:<subdir>
$ git archive --format=tar --remote=<gituser>@<gitserver>:<repo> 42a6503da6aaedc92bb3543e0b0de9b2de0aaae9
do the same which let's me think that HEAD:<subdir>
and 42a6503da6aaedc92bb3543e0b0de9b2de0aaae9
are equivalent. Still I can't just substitute the hash in http://<gitweburl>?p=<repo>;a=snapshot;h=42a6503da6aaedc92bb3543e0b0de9b2de0aaae9;sf=tgz
with HEAD:<subdir>
. Calling this URL results in "400 - Invalid hash parameter"... so no real progress here.
As suggested by poke, a quick'n dirty hack to use URL http://<gitweburl>/gitweb.cgi?p=<repo>;a=snapshot;h=HEAD;f=<subdir>
$ diff -Naur gitweb.cgi.original gitweb.cgi.new
--- gitweb.cgi.original 2012-09-28 00:50:47.000000000 +0200
+++ gitweb.cgi.new 2013-01-22 11:04:29.870532502 +0100
@@ -7029,6 +7029,9 @@
my ($name, $prefix) = snapshot_name($project, $hash);
my $filename = "$name$known_snapshot_formats{$format}{'suffix'}";
+ if ($file_name) {
+ $hash="$hash:$file_name"
+ }
my $cmd = quote_command(
git_cmd(), 'archive',
"--format=$known_snapshot_formats{$format}{'format'}",