fetch-pack: call prepare_shallow_info only if v0

In fetch_pack(), be clearer that there is no shallow information before the fetch when v2 is used - memset the struct shallow_info to 0 instead of calling prepare_shallow_info(). This patch is in preparation for a future patch in which a v2 fetch might call prepare_shallow_info() after shallow info has been retrieved during the fetch, so I needed to ensure that prepare_shallow_info() is not called before the fetch. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Tan committed Mar 26, 2019 at 12:31 UTC 1e7d440b0a07ec8e71c107d0950ed1dc43b4d20c
2 files changed +11 -3
commit.h
+4
@@ -257,6 +257,10 @@ extern void setup_alternate_shallow(struct lock_file *shallow_lock,
257 extern const char *setup_temporary_shallow(const struct oid_array *extra);
258 extern void advertise_shallow_grafts(int);
259
260 +/*
261 + * Initialize with prepare_shallow_info() or zero-initialize (equivalent to
262 + * prepare_shallow_info with a NULL oid_array).
263 + */
264 struct shallow_info {
265 struct oid_array *shallow;
266 int *ours, nr_ours;
fetch-pack.c
+7 -3
@@ -1648,13 +1648,17 @@ struct ref *fetch_pack(struct fetch_pack_args *args,
1648 packet_flush(fd[1]);
1649 die(_("no matching remote head"));
1650 }
1651 - prepare_shallow_info(&si, shallow);
1652 - if (version == protocol_v2)
1651 + if (version == protocol_v2) {
1652 + if (shallow->nr)
1653 + BUG("Protocol V2 does not provide shallows at this point in the fetch");
1654 + memset(&si, 0, sizeof(si));
1655 ref_cpy = do_fetch_pack_v2(args, fd, ref, sought, nr_sought,
1656 pack_lockfile);
1655 - else
1657 + } else {
1658 + prepare_shallow_info(&si, shallow);
1659 ref_cpy = do_fetch_pack(args, fd, ref, sought, nr_sought,
1660 &si, pack_lockfile);
1661 + }
1662 reprepare_packed_git(the_repository);
1663
1664 if (!args->cloning && args->deepen) {