fetch-pack: unify ref in and out param
When a user fetches: - at least one up-to-date ref and at least one non-up-to-date ref, - using HTTP with protocol v0 (or something else that uses the fetch command of a remote helper) some refs might not be updated after the fetch. This bug was introduced in commit989b8c4452("fetch-pack: put shallow info in output parameter", 2018-06-28) which allowed transports to report the refs that they have fetched in a new out-parameter "fetched_refs". If they do so, transport_fetch_refs() makes this information available to its caller. Users of "fetched_refs" rely on the following 3 properties: (1) it is the complete list of refs that was passed to transport_fetch_refs(), (2) it has shallow information (REF_STATUS_REJECT_SHALLOW set if relevant), and (3) it has updated OIDs if ref-in-want was used (introduced after989b8c4452). In an effort to satisfy (1), whenever transport_fetch_refs() filters the refs sent to the transport, it re-adds the filtered refs to whatever the transport supplies before returning it to the user. However, the implementation in989b8c4452unconditionally re-adds the filtered refs without checking if the transport refrained from reporting anything in "fetched_refs" (which it is allowed to do), resulting in an incomplete list, no longer satisfying (1). An earlier effort to resolve this [1] solved the issue by readding the filtered refs only if the transport did not refrain from reporting in "fetched_refs", but after further discussion, it seems that the better solution is to revert the API change that introduced "fetched_refs". This API change was first suggested as part of a ref-in-want implementation that allowed for ref patterns and, thus, there could be drastic differences between the input refs and the refs actually fetched [2]; we eventually decided to only allow exact ref names, but this API change remained even though its necessity was decreased. Therefore, revert this API change by reverting commit989b8c4452, and make receive_wanted_refs() update the OIDs in the sought array (like how update_shallow() updates shallow information in the sought array) instead. A test is also included to show that the user-visible bug discussed at the beginning of this commit message no longer exists. [1] https://public-inbox.org/git/20180801171806.GA122458@google.com/ [2] https://public-inbox.org/git/86a128c5fb710a41791e7183207c4d64889f9307.1485381677.git.jonathantanmy@google.com/ Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
cf1e7c0770
commit
e2842b39f4
@ -948,13 +948,11 @@ static int quickfetch(struct ref *ref_map)
|
||||
return check_connected(iterate_ref_map, &rm, &opt);
|
||||
}
|
||||
|
||||
static int fetch_refs(struct transport *transport, struct ref *ref_map,
|
||||
struct ref **updated_remote_refs)
|
||||
static int fetch_refs(struct transport *transport, struct ref *ref_map)
|
||||
{
|
||||
int ret = quickfetch(ref_map);
|
||||
if (ret)
|
||||
ret = transport_fetch_refs(transport, ref_map,
|
||||
updated_remote_refs);
|
||||
ret = transport_fetch_refs(transport, ref_map);
|
||||
if (!ret)
|
||||
/*
|
||||
* Keep the new pack's ".keep" file around to allow the caller
|
||||
@ -1119,7 +1117,7 @@ static void backfill_tags(struct transport *transport, struct ref *ref_map)
|
||||
transport_set_option(transport, TRANS_OPT_FOLLOWTAGS, NULL);
|
||||
transport_set_option(transport, TRANS_OPT_DEPTH, "0");
|
||||
transport_set_option(transport, TRANS_OPT_DEEPEN_RELATIVE, NULL);
|
||||
if (!fetch_refs(transport, ref_map, NULL))
|
||||
if (!fetch_refs(transport, ref_map))
|
||||
consume_refs(transport, ref_map);
|
||||
|
||||
if (gsecondary) {
|
||||
@ -1135,7 +1133,6 @@ static int do_fetch(struct transport *transport,
|
||||
int autotags = (transport->remote->fetch_tags == 1);
|
||||
int retcode = 0;
|
||||
const struct ref *remote_refs;
|
||||
struct ref *updated_remote_refs = NULL;
|
||||
struct argv_array ref_prefixes = ARGV_ARRAY_INIT;
|
||||
|
||||
if (tags == TAGS_DEFAULT) {
|
||||
@ -1186,24 +1183,7 @@ static int do_fetch(struct transport *transport,
|
||||
transport->url);
|
||||
}
|
||||
}
|
||||
|
||||
if (fetch_refs(transport, ref_map, &updated_remote_refs)) {
|
||||
free_refs(ref_map);
|
||||
retcode = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
if (updated_remote_refs) {
|
||||
/*
|
||||
* Regenerate ref_map using the updated remote refs. This is
|
||||
* to account for additional information which may be provided
|
||||
* by the transport (e.g. shallow info).
|
||||
*/
|
||||
free_refs(ref_map);
|
||||
ref_map = get_ref_map(transport->remote, updated_remote_refs, rs,
|
||||
tags, &autotags);
|
||||
free_refs(updated_remote_refs);
|
||||
}
|
||||
if (consume_refs(transport, ref_map)) {
|
||||
if (fetch_refs(transport, ref_map) || consume_refs(transport, ref_map)) {
|
||||
free_refs(ref_map);
|
||||
retcode = 1;
|
||||
goto cleanup;
|
||||
|
||||
Reference in New Issue
Block a user