diff options
author | Jonathan Tan <jonathantanmy@google.com> | 2018-07-02 15:08:43 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2018-07-03 14:57:44 -0700 |
commit | cf1e7c07705eb21c30d0ee414810e7bc8fdf7d82 (patch) | |
tree | db2515073445cc5b9fdb89f6472f91ed8505a59c /builtin/fetch.c | |
parent | fetch-pack: implement ref-in-want (diff) | |
download | tgif-cf1e7c07705eb21c30d0ee414810e7bc8fdf7d82.tar.xz |
fetch-pack: write shallow, then check connectivity
When fetching, connectivity is checked after the shallow file is
updated. There are 2 issues with this: (1) the connectivity check is
only performed up to ancestors of existing refs (which is not thorough
enough if we were deepening an existing ref in the first place), and (2)
there is no rollback of the shallow file if the connectivity check
fails.
To solve (1), update the connectivity check to check the ancestry chain
completely in the case of a deepening fetch by refraining from passing
"--not --all" when invoking rev-list in connected.c.
To solve (2), have fetch_pack() perform its own connectivity check
before updating the shallow file. To support existing use cases in which
"git fetch-pack" is used to download objects without much regard as to
the connectivity of the resulting objects with respect to the existing
repository, the connectivity check is only done if necessary (that is,
the fetch is not a clone, and the fetch involves shallow/deepen
functionality). "git fetch" still performs its own connectivity check,
preserving correctness but sometimes performing redundant work. This
redundancy is mitigated by the fact that fetch_pack() reports if it has
performed a connectivity check itself, and if the transport supports
connect or stateless-connect, it will bubble up that report so that "git
fetch" knows not to perform the connectivity check in such a case.
This was noticed when a user tried to deepen an existing repository by
fetching with --no-shallow from a server that did not send all necessary
objects - the connectivity check as run by "git fetch" succeeded, but a
subsequent "git fsck" failed.
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/fetch.c')
-rw-r--r-- | builtin/fetch.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/builtin/fetch.c b/builtin/fetch.c index 0347cf0167..d4b2767d48 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -769,7 +769,7 @@ static int iterate_ref_map(void *cb_data, struct object_id *oid) } static int store_updated_refs(const char *raw_url, const char *remote_name, - struct ref *ref_map) + int connectivity_checked, struct ref *ref_map) { FILE *fp; struct commit *commit; @@ -791,10 +791,12 @@ static int store_updated_refs(const char *raw_url, const char *remote_name, else url = xstrdup("foreign"); - rm = ref_map; - if (check_connected(iterate_ref_map, &rm, NULL)) { - rc = error(_("%s did not send all necessary objects\n"), url); - goto abort; + if (!connectivity_checked) { + rm = ref_map; + if (check_connected(iterate_ref_map, &rm, NULL)) { + rc = error(_("%s did not send all necessary objects\n"), url); + goto abort; + } } prepare_format_display(ref_map); @@ -966,8 +968,11 @@ static int fetch_refs(struct transport *transport, struct ref *ref_map, /* Update local refs based on the ref values fetched from a remote */ static int consume_refs(struct transport *transport, struct ref *ref_map) { + int connectivity_checked = transport->smart_options + ? transport->smart_options->connectivity_checked : 0; int ret = store_updated_refs(transport->url, transport->remote->name, + connectivity_checked, ref_map); transport_unlock_pack(transport); return ret; |