git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/2] fetch-object: set exact_oid when fetching

From
JTJonathan Tan <jonathantanmy@google.com>
Date
Sep 12, 2018, 15:47 UTC
Message-ID
<ac5abaa46d41afe46a944264277e75ce4365d6fd.1536767071.git.jonathantanmy@google.com>
In-Reply-To
<cover.1536767071.git.jonathantanmy@google.com>

fetch_objects() currently does not set exact_oid in struct ref when invoking transport_fetch_refs(). If the server supports ref-in-want, fetch_pack() uses this field to determine whether a wanted ref should be requested as a "want-ref" line or a "want" line; without the setting of exact_oid, the wrong line will be sent.

Set exact_oid, so that the correct line is sent.
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
---
 fetch-object.c           |  1 +
 t/t0410-partial-clone.sh | 12 ++++++++++++
 2 files changed, 13 insertions(+)
diff --git a/fetch-object.c b/fetch-object.c
index 1af1bf857..426654880 100644
--- a/fetch-object.c
+++ b/fetch-object.c
@@ -32,6 +32,7 @@ void fetch_objects(const char *remote_name, const struct object_id *oids,
 	for (i = 0; i < oid_nr; i++) {
 		struct ref *new_ref = alloc_ref(oid_to_hex(&oids[i]));
 		oidcpy(&new_ref->old_oid, &oids[i]);
+		new_ref->exact_oid = 1;
 		new_ref->next = ref;
 		ref = new_ref;
 	}
diff --git a/t/t0410-partial-clone.sh b/t/t0410-partial-clone.sh
index 128130066..0ab02c337 100755
--- a/t/t0410-partial-clone.sh
+++ b/t/t0410-partial-clone.sh
@@ -170,6 +170,18 @@ test_expect_success 'fetching of missing objects' '
 	git verify-pack --verbose "$IDX" | grep "$HASH"
 '
 
+test_expect_success 'fetching of missing objects works with ref-in-want enabled' '
+	# ref-in-want requires protocol version 2
+	git -C server config protocol.version 2 &&
+	git -C server config uploadpack.allowrefinwant 1 &&
+	git -C repo config protocol.version 2 &&
+
+	rm -rf repo/.git/objects/* &&
+	rm -f trace &&
+	GIT_TRACE_PACKET="$(pwd)/trace" git -C repo cat-file -p "$HASH" &&
+	grep "git< fetch=.*ref-in-want" trace
+'
+
 test_expect_success 'rev-list stops traversal at missing and promised commit' '
 	rm -rf repo &&
 	test_create_repo repo &&
-- 
2.19.0.397.gdd90340f6a-goog
Previous: Junio C Hamano
Message 6 of 6 in “Bugfix for partial clones and ref-in-want servers”
  1. 0/2 Bugfix for partial clones and ref-in-want serversJonathan Tan, Sep 12, 2018
  2. 1/2 fetch-object: provide only one fetching functionJonathan Tan, Sep 12, 2018
  3. Junio C HamanoSep 12, 2018
  4. Jonathan TanSep 13, 2018
  5. Junio C HamanoSep 13, 2018
  6. 2/2 fetch-object: set exact_oid when fetchingJonathan Tan, Sep 12, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.