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

[PATCH v3 2/2] negotiator/skipping.c: parse parents before queueing

From
Taylor Blau <ttaylorr@openai.com>
Date
Oct 26, 2026, 23:49 UTC
Message-ID
<7365a2ab180bc4b534dac3b7515a398a987e8384.1793058562.git.ttaylorr@openai.com>
In-Reply-To
<cover.1793058562.git.ttaylorr@openai.com>

The skipping negotiator sorts its queue by commit date, but callers which push commits onto that queue, such as `push_parent()`, can add a parent before parsing it. When an unparsed commit enters the queue, its date is still zero, so old ref tips may sort ahead of it.

For example, suppose a topic branch is one commit ahead of master. Skipping offers the topic tip and skips master's tip. Master's parent then waits behind old ref tips. With enough old refs, negotiation can end before we offer that recent common ancestor.

Parse commits in rev_list_push() before adding them to the queue, so the queue uses their actual dates. If parsing fails, leave the commit out of the queue. Move the parsing from get_rev() to the insertion point, where the date is needed to order the queue.

Set SEEN only after parsing succeeds, following the default negotiator after the preceding fix. push_parent() assumes that a commit marked SEEN but not POPPED has an entry in the queue. Marking an unparseable parent SEEN would violate that assumption and trigger a BUG() if another child tried to push the same parent.

Unlike the default negotiator, the skipping negotiator's version of rev_list_push() returns a pointer to an entry struct. Check for NULL in push_parent() before using that entry. The other two callers continue to ignore the return value.

Add tests for the ordering of recent ancestors relative to old ref tips and for two tips sharing a missing parent. In the latter case, fetching from a server that has the parent should retrieve it without triggering the missing-entry BUG().

Signed-off-by: Taylor Blau <ttaylorr@openai.com>
---
 negotiator/skipping.c                |  9 +++-
 t/t5552-skipping-fetch-negotiator.sh | 63 ++++++++++++++++++++++++++++
 2 files changed, 70 insertions(+), 2 deletions(-)
diff --git a/negotiator/skipping.c b/negotiator/skipping.c
index db90fa77b53..a7c7b8d9e94 100644
--- a/negotiator/skipping.c
+++ b/negotiator/skipping.c
@@ -64,6 +64,10 @@ static int compare(const void *a_, const void *b_, void *data UNUSED)
 static struct entry *rev_list_push(struct data *data, struct commit *commit, int mark)
 {
 	struct entry *entry;
+
+	if (repo_parse_commit(the_repository, commit))
+		return NULL;
+
 	commit->object.flags |= mark | SEEN;
 
 	CALLOC_ARRAY(entry, 1);
@@ -125,7 +129,7 @@ static void mark_common(struct data *data, struct commit *seen_commit)
  * entry has the correct flags and ttl.
  *
  * This function returns 1 if an entry was found or created, and 0 otherwise
- * (because the entry for this commit had already been popped).
+ * (because the commit could not be parsed or its entry had already been popped).
  */
 static int push_parent(struct data *data, struct entry *entry,
 		       struct commit *to_push)
@@ -152,6 +156,8 @@ static int push_parent(struct data *data, struct entry *entry,
 		;
 	} else {
 		parent_entry = rev_list_push(data, to_push, 0);
+		if (!parent_entry)
+			return 0;
 	}
 
 	if (entry->commit->object.flags & (COMMON | ADVERTISED)) {
@@ -194,7 +200,6 @@ static const struct object_id *get_rev(struct data *data)
 		if (!(commit->object.flags & COMMON) && !entry->ttl)
 			to_send = commit;
 
-		repo_parse_commit(the_repository, commit);
 		for (p = commit->parents; p; p = p->next)
 			parent_pushed |= push_parent(data, entry, p->item);
 
diff --git a/t/t5552-skipping-fetch-negotiator.sh b/t/t5552-skipping-fetch-negotiator.sh
index 96e224168eb..0efd2f2ac49 100755
--- a/t/t5552-skipping-fetch-negotiator.sh
+++ b/t/t5552-skipping-fetch-negotiator.sh
@@ -223,4 +223,67 @@ test_expect_success 'do not send "have" with ancestors of commits that server AC
 	have_sent b2.c1 b2.c0
 '
 
+test_expect_success 'recent ancestors are sent before old ref tips' '
+	rm -rf server client trace &&
+	git init server &&
+	test_tick=2000000000 &&
+	test_commit -C server --no-tag base &&
+	test_commit -C server --no-tag parent &&
+	test_commit -C server --no-tag main &&
+	git clone server client &&
+	test_commit -C server --no-tag to_fetch &&
+
+	git -C client checkout -b topic &&
+	test_commit -C client --no-tag topic &&
+
+	# These old tips have known dates, but the recent parent has no ref.
+	# Without parsing parents before queueing them, its date is zero and
+	# all of these tips are sent first, delaying it past the first batch.
+	for i in $(test_seq 32)
+	do
+		old=$(echo "old $i" |
+			GIT_AUTHOR_DATE="1000000000 +0000" \
+			GIT_COMMITTER_DATE="1000000000 +0000" \
+			git -C client commit-tree HEAD^{tree}) &&
+		git -C client update-ref refs/heads/old-$i "$old" || return 1
+	done &&
+
+	test_config -C client fetch.negotiationalgorithm skipping &&
+	trace_fetch client origin &&
+	git -C client rev-parse HEAD HEAD~2 >expect &&
+	sed -n "s/.*fetch> have //p" trace | head -n 2 >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'missing parent shared by two tips is not treated as queued' '
+	rm -rf server client trace &&
+	git init server &&
+	test_commit -C server base &&
+	parent=$(git -C server rev-parse HEAD) &&
+	test_commit -C server to_fetch &&
+
+	git init client &&
+	tree=$(git -C client mktree </dev/null) &&
+	# Write the tips directly, bypassing the parent lookup in commit-tree.
+	# Both tips name a parent that only the server has.
+	for i in 1 2
+	do
+		cat >commit <<-EOF_COMMIT &&
+		tree $tree
+		parent $parent
+		author A U Thor <author@example.com> 1000000000 +0000
+		committer C O Mitter <committer@example.com> 1000000000 +0000
+
+		tip $i
+		EOF_COMMIT
+		tip=$(git -C client hash-object -w -t commit --stdin <commit) &&
+		git -C client update-ref refs/heads/tip-$i "$tip" || return 1
+	done &&
+
+	test_config -C client fetch.negotiationalgorithm skipping &&
+	trace_fetch client "$(pwd)/server" \
+		--negotiation-tip=tip-1 --negotiation-tip=tip-2 &&
+	git -C client cat-file -e "$parent"
+'
+
 test_done
-- 
2.56.0.187.g9e9ae442333
Previous: Taylor Blau
Message 15 of 15 in “negotiator/skipping.c: parse parents before queueing”
  1. negotiator/skipping.c: parse parents before queueingTaylor Blau, Oct 19, 2026
  2. Patrick SteinhardtOct 21, 2026
  3. Junio C HamanoOct 21, 2026
  4. Taylor BlauOct 22, 2026
  5. Junio C HamanoOct 22, 2026
  6. Taylor BlauOct 22, 2026
  7. negotiator/skipping.c: parse parents before queueingTaylor Blau, Oct 22, 2026
  8. Junio C HamanoOct 22, 2026
  9. Taylor BlauOct 22, 2026
  10. Junio C HamanoOct 23, 2026
  11. Taylor BlauOct 24, 2026
  12. Junio C HamanoOct 24, 2026
  13. 0/2 negotiator: parse commits before queueingTaylor Blau, Oct 26, 2026
  14. 1/2 negotiator/default.c: mark commits seen only after parsingTaylor Blau, Oct 26, 2026
  15. 2/2 negotiator/skipping.c: parse parents before queueingTaylor Blau, Oct 26, 2026

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.