fetch: only populate existing_refs if needed
authorJonathan Tan <jonathantanmy@google.com>
Tue, 18 Aug 2020 04:01:34 +0000 (21:01 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 18 Aug 2020 20:25:05 +0000 (13:25 -0700)
commitabcb7eeb31d0267ada469646be993ad25e127d0d
tree984cd41c305b201a0190545fc6787c74ee77c7ad
parente5b942136ec1af98551b259997872e9849b2766c
fetch: only populate existing_refs if needed

In "fetch", get_ref_map() iterates over all refs to populate
"existing_refs" in order to populate peer_ref->old_oid in the returned
refmap, even if the refmap has no peer_ref set - which is the case when
only literal hashes (i.e. no refs by name) are fetched.

Iterating over refs causes the targets of those refs to be checked for
existence. Avoiding this is especially important when we use "git fetch"
to perform lazy fetches in a partial clone because a target of such a
ref may need to be itself lazy-fetched (and otherwise causing an
infinite loop).

Therefore, avoid populating "existing_refs" until necessary. With this
patch, because Git lazy-fetches objects by literal hashes (to be done in
a subsequent commit), it will then be able to guarantee avoiding reading
targets of refs.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fetch.c