Skip to content

Commit 1e7d440

Browse files
jonathantanmygitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a51423b commit 1e7d440

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

commit.h

+4
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,10 @@ extern void setup_alternate_shallow(struct lock_file *shallow_lock,
257257
extern const char *setup_temporary_shallow(const struct oid_array *extra);
258258
extern void advertise_shallow_grafts(int);
259259

260+
/*
261+
* Initialize with prepare_shallow_info() or zero-initialize (equivalent to
262+
* prepare_shallow_info with a NULL oid_array).
263+
*/
260264
struct shallow_info {
261265
struct oid_array *shallow;
262266
int *ours, nr_ours;

fetch-pack.c

+7-3
Original file line numberDiff line numberDiff line change
@@ -1648,13 +1648,17 @@ struct ref *fetch_pack(struct fetch_pack_args *args,
16481648
packet_flush(fd[1]);
16491649
die(_("no matching remote head"));
16501650
}
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));
16531655
ref_cpy = do_fetch_pack_v2(args, fd, ref, sought, nr_sought,
16541656
pack_lockfile);
1655-
else
1657+
} else {
1658+
prepare_shallow_info(&si, shallow);
16561659
ref_cpy = do_fetch_pack(args, fd, ref, sought, nr_sought,
16571660
&si, pack_lockfile);
1661+
}
16581662
reprepare_packed_git(the_repository);
16591663

16601664
if (!args->cloning && args->deepen) {

0 commit comments

Comments
 (0)