clone: check if server supports shallow clones
PATCH 1/1 clone: check if server supports shallow clones
When the user passes --depth to git-clone the server's capabilities are not currently consulted. The client will send shallow requests even if the server does not understand them, and the resulting error may be unhelpful to the user. This change pre-emptively checks so git-clone can exit with a helpful error if necessary.
--- builtin/clone.c | 3 +++ 1 file changed, 3 insertions(+)
builtin/clone.c +3 -0
@@ -944,6 +944,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix) refs =transport_get_remote_refs (transport); +if (option_depth && !is_local && !server_supports ("shallow" )) +die (_ ("Server does not support shallow clients" )); +if (refs) { mapped_refs =wanted_peer_refs (refs, refspec);/*
Signature · 1 line
2.2.0.rc0.207.ga3a616c
Quoted 5 lines · Mike Edgar
When the user passes --depth to git-clone the server's capabilities are not currently consulted. The client will send shallow requests even if the server does not understand them, and the resulting error may be unhelpful to the user. This change pre-emptively checks so git-clone can exit with a helpful error if necessary.
This sounds like a good thing to do, but...
builtin/clone.c int cmd_clone(int argc, const char **argv, const char *prefix) · line 949
Quoted 9 lines
builtin/clone.c +3
-0@@ -944,6 +944,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix) refs =transport_get_remote_refs (transport); +if (option_depth && !is_local && !server_supports ("shallow" )) +die (_ ("Server does not support shallow clients" )); +
It feels a little weird to be checking the option here in cmd_clone. The transport layer knows we have specified a depth, so it seems like a more natural place for it (or possibly even lower, in the actual git-protocol code).
That being said, I think the current capabilities handling is a bit messy and crosses module boundaries freely. So I would not be surprised if this is the most reasonable place to put it. But it does make me wonder whether "git fetch --depth=..." needs the same treatment.
I see that do_fetch_pack checks server_supports("shallow"). Is that enough to cover all fetch cases? And if it is, why does it not cover the matching clone cases?
-Peff
Quoted 5 lines · Jeff King
I see that
do_fetch_packchecksserver_supports("shallow"). Is that enough to cover all fetch cases? And if it is, why does it not cover the matching clone cases?
-Peff
Great question. I determined that the do_fetch_pack logic doesn't work for clones because it also checks is_repository_shallow(), which looks for the .git/shallow file (or the alternate file).
I considered changing clone to create an empty .git/shallow file or alternate, but it turns out that an empty shallow file is treated as no shallow file at all. Since at this stage in cloning we have nothing to put in the shallow file, it seemed like any other fix would require more substantial changes.
Quoted 6 lines · Michael Edgar
Quoted 5 lines · Jeff King
I see that
do_fetch_packchecksserver_supports("shallow"). Is that enough to cover all fetch cases? And if it is, why does it not cover the matching clone cases?
-Peff
Quoted 8 lines
Great question. I determined that the
do_fetch_packlogic doesn't work for clones because it also checksis_repository_shallow(), which looks for the .git/shallow file (or the alternate file).I considered changing clone to create an empty .git/shallow file or alternate, but it turns out that an empty shallow file is treated as no shallow file at all. Since at this stage in cloning we have nothing to put in the shallow file, it seemed like any other fix would require more substantial changes.
Hmm. Can we improve the check in do_fetch_pack? That is, do we have a way of checking whether the _current_ fetch is going to make us shallow? I don't see anything obvious (like a "depth" flag) passed into do_fetch_pack, so I guess it is relying solely on global shallow state that we've already set up? Or is it the case that "git fetch --depth=" in a non-shallow repository does not properly check this flag?
If it turns out that "fetch --depth" is fine, and only "clone --depth" is broken, I can certainly live with the patch you provided. But I think we need to clarify that a bit in the commit message.
-Peff
Quoted 25 lines · Jeff King
Quoted 5 lines · Mike Edgar
When the user passes --depth to git-clone the server's capabilities are not currently consulted. The client will send shallow requests even if the server does not understand them, and the resulting error may be unhelpful to the user. This change pre-emptively checks so git-clone can exit with a helpful error if necessary.
This sounds like a good thing to do, but...
builtin/clone.c int cmd_clone(int argc, const char **argv, const char *prefix) · line 949
Quoted 9 lines
builtin/clone.c +3
-0@@ -944,6 +944,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix) refs =transport_get_remote_refs (transport); +if (option_depth && !is_local && !server_supports ("shallow" )) +die (_ ("Server does not support shallow clients" )); +It feels a little weird to be checking the option here in
cmd_clone. The transport layer knows we have specified a depth, so it seems like a more natural place for it (or possibly even lower, in the actual git-protocol code).
Quoted 8 lines
That being said, I think the current capabilities handling is a bit messy and crosses module boundaries freely. So I would not be surprised if this is the most reasonable place to put it. But it does make me wonder whether "git fetch --depth=..." needs the same treatment.
I see that
do_fetch_packchecksserver_supports("shallow"). Is that enough to cover all fetch cases? And if it is, why does it not cover the matching clone cases?
I think this replacement check would do
if ((args->depth > 0 || is_repository_shallow()) && !server_supports("shallow"))
die("Server does not support shallow clients");Signature · 1 line
Duy
Quoted 8 lines · Duy Nguyen
Quoted 3 lines
I see that
do_fetch_packchecksserver_supports("shallow"). Is that enough to cover all fetch cases? And if it is, why does it not cover the matching clone cases?I think this replacement check would do
if ((
args->depth> 0 ||is_repository_shallow()) && !server_supports("shallow"))die("Server does not support shallow clients");
Oh, indeed, there is the depth flag I was looking for. :)
And from some rudimentary testing, I believe that:
git init
git fetch --depth=1 ...
is currently broken in the same way as clone (we are not shallow yet, so it does not complain when the server does not support it). I think the patch above fixes both that and the clone case.
Of course it's hard to add to the test suite, since we do not have a way of hitting a server that does not understand shallow (I simply fudged server_supports() to return false on the client).
-Peff
Quoted 13 lines · Jeff King
Quoted 8 lines · Duy Nguyen
Quoted 3 lines
I see that
do_fetch_packchecksserver_supports("shallow"). Is that enough to cover all fetch cases? And if it is, why does it not cover the matching clone cases?I think this replacement check would do
if ((
args->depth> 0 ||is_repository_shallow()) && !server_supports("shallow"))die("Server does not support shallow clients");Oh, indeed, there is the depth flag I was looking for. :)
Quoted 8 lines
And from some rudimentary testing, I believe that:
git init
git fetch --depth=1 ...is currently broken in the same way as clone (we are not shallow yet, so it does not complain when the server does not support it). I think the patch above fixes both that and the clone case.
Great point! Duy's proposed fix worked for me testing against the Git server that
led me to the original bug (code.google.com), for both clones and init/fetch.
Shall I send that out as a revised patch for review? (This is my first stab at a Git
patch)
Quoted 3 lines
Of course it's hard to add to the test suite, since we do not have a way of hitting a server that does not understand shallow (I simply fudged
server_supports()to return false on the client).
I noticed this, and figured it would be more dangerous for users to include a testing backdoor (eg a flag overriding the advertised capabilities). Is that an accurate assessment, or is there a safer way to test these sorts of interop cases?
Cheers!
Signature · 1 line
Michael Edgar | Software Engineer | [email protected]
Quoted 19 lines · Michael Edgar
Quoted 18 lines · Jeff King
Quoted 8 lines · Duy Nguyen
Quoted 3 lines
I see that
do_fetch_packchecksserver_supports("shallow"). Is that enough to cover all fetch cases? And if it is, why does it not cover the matching clone cases?I think this replacement check would do
if ((
args->depth> 0 ||is_repository_shallow()) && !server_supports("shallow"))die("Server does not support shallow clients");Oh, indeed, there is the depth flag I was looking for. :)
And from some rudimentary testing, I believe that:
git init
git fetch --depth=1 ...
Quoted 7 lines
Quoted 3 lines
is currently broken in the same way as clone (we are not shallow yet, so it does not complain when the server does not support it). I think the patch above fixes both that and the clone case.
Shall I send that out as a revised patch for review? (This is my first stab at a Git
patch)
Surely, and thanks. Hopefully one or both of them will Ack it and all there is left for me to do will be to pick it up ;-)
PATCH v2 1/1 fetch-pack: check for shallow if depth given
When a repository is first fetched as a shallow clone, either by git-clone or by fetching into an empty repo, the server's capabilities are not currently consulted. The client will send shallow requests even if the server does not understand them, and the resulting error may be unhelpful to the user. This change pre-emptively checks so we can exit with a helpful error if necessary.
--- fetch-pack.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fetch-pack.c +1 -1
@@ -809,7 +809,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,sort_ref_list (&ref, ref_compare_name);qsort (sought, nr_sought,sizeof (*sought), cmp_ref_by_name); -if (is_repository_shallow () && !server_supports ("shallow" )) +if ((args->depth >0 ||is_repository_shallow ()) && !server_supports ("shallow" ))die ("Server does not support shallow clients" );if (server_supports ("multi_ack_detailed" )) {if (args->verbose)
Signature · 1 line
2.2.0.rc0.207.ga3a616c
Re: [PATCH v2] fetch-pack: check for shallow if depth given
Quoted 8 lines · Mike Edgar
When a repository is first fetched as a shallow clone, either by git-clone or by fetching into an empty repo, the server's capabilities are not currently consulted. The client will send shallow requests even if the server does not understand them, and the resulting error may be unhelpful to the user. This change pre-emptively checks so we can exit with a helpful error if necessary.
Signed-off-by Mike Edgar <[email protected]>
Looks good to me.
-Peff
Quoted 18 lines · Jeff King
Quoted 8 lines · Duy Nguyen
Quoted 3 lines
I see that
do_fetch_packchecksserver_supports("shallow"). Is that enough to cover all fetch cases? And if it is, why does it not cover the matching clone cases?I think this replacement check would do
if ((
args->depth> 0 ||is_repository_shallow()) && !server_supports("shallow"))die("Server does not support shallow clients");Oh, indeed, there is the depth flag I was looking for. :)
And from some rudimentary testing, I believe that:
git init
git fetch --depth=1 ...
Quoted 7 lines
is currently broken in the same way as clone (we are not shallow yet, so it does not complain when the server does not support it). I think the patch above fixes both that and the clone case.
Of course it's hard to add to the test suite, since we do not have a way of hitting a server that does not understand shallow (I simply fudged
server_supports()to return false on the client).
We've had the "shallow" capability advertised since ed09aef0 (support fetching into a shallow repository, 2006-10-30), and this patch itself may not be that super-important in practice. Let's not worry too much about a test for situations that may not likely matter to us [*1*].
Thanks, all.
[Footnote]
*1* How behind are re-implementations of upload-pack by other people, I have to wonder, though?
Quoted 9 lines · Junio C Hamano
Quoted 3 lines
Of course it's hard to add to the test suite, since we do not have a way of hitting a server that does not understand shallow (I simply fudged
server_supports()to return false on the client).We've had the "shallow" capability advertised since
ed09aef0(support fetching into a shallow repository, 2006-10-30), and this patch itself may not be that super-important in practice. Let's not worry too much about a test for situations that may not likely matter to us [*1*].
I had actually started looking at doing a generic interop testing suite. It would be nice to be able to do something like:
cd t/interop
./run v1.0.0 v2.0.0 ./t0001-clone.sh
and then the test script looks something like:
test_expect_success 'clone with A from B' '
git.a clone -u "git.b upload-pack"
'
The "run" script is similar to the version in t/perf that builds arbitrary revisions for testing, but with the twist that it points the PATH to "git.a" and "git.b", which symlink into the bin-wrappers/ of the built directories (and probably disallows bare "git" to prevent mistakes).
But I agree that this particular bug is not all that exciting to test.
Quoted 2 lines
*1* How behind are re-implementations of upload-pack by other people, I have to wonder, though?
JGit advertises "shallow". Libgit2 does not, but it also does not implement upload-pack. :)
I do wonder which server Mike was hitting to come across this in the first place. Maybe the Google Code dulwich-based one?
-Peff