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

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

From
Taylor Blau <ttaylorr@openai.com>
Date
Oct 22, 2026, 21:21 UTC
Message-ID
<9e9ae442333b5e2ccc0905c44c2c3e16c49481a7.1792704069.git.me@ttaylorr.com>
In-Reply-To
<dc3dfa3647c42da9170bf3289f4e8a4a8a55c8e2.1792441003.git.me@ttaylorr.com>
From: Taylor Blau <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 each unseen parent before adding it to the queue, so the queue uses its actual date. If parsing fails, leave the parent out of the queue.

Since the sole caller of `prio_queue_put()` ensures that commits are fully parsed before pushing them onto the queue, we can avoid a noop call to `repo_parse_commit()` within `get_rev()`.

Note that unlike the default negotiator, the skipping negotiator's version of `rev_list_push()` returns a pointer to an 'entry' struct. As a consequence, callers must be prepared to handle a NULL return value. The caller in `push_parent()` gains a NULL-ness check, and the remaining two callers continue to ignore the return value from `rev_list_push()`.

Signed-off-by: Taylor Blau <ttaylorr@openai.com>
---
 negotiator/skipping.c                |  8 +++++--
 t/t5552-skipping-fetch-negotiator.sh | 32 ++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 2 deletions(-)
diff --git a/negotiator/skipping.c b/negotiator/skipping.c
index db90fa77b53..0ae5f28d353 100644
--- a/negotiator/skipping.c
+++ b/negotiator/skipping.c
@@ -66,6 +66,9 @@ static struct entry *rev_list_push(struct data *data, struct commit *commit, int
 	struct entry *entry;
 	commit->object.flags |= mark | SEEN;
 
+	if (repo_parse_commit(the_repository, commit))
+		return NULL;
+
 	CALLOC_ARRAY(entry, 1);
 	entry->commit = commit;
 	prio_queue_put(&data->rev_list, entry);
@@ -125,7 +128,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 +155,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 +199,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..7479424ca94 100755
--- a/t/t5552-skipping-fetch-negotiator.sh
+++ b/t/t5552-skipping-fetch-negotiator.sh
@@ -223,4 +223,36 @@ 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_done

Range-diff against v1:
1:  cfb16d16d8c ! 1:  9e9ae442333 negotiator/skipping.c: parse parents before queueing
    @@ Metadata
      ## Commit message ##
         negotiator/skipping.c: parse parents before queueing
     
    -    The skipping negotiator sorts its queue by commit date, but
    -    `push_parent()` can add a parent before parsing it. Its date is still
    -    zero, so old ref tips go ahead of it.
    +    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
    @@ Commit message
         uses its actual date. If parsing fails, leave the parent out of the
         queue.
     
    +    Since the sole caller of `prio_queue_put()` ensures that commits are
    +    fully parsed before pushing them onto the queue, we can avoid a noop
    +    call to `repo_parse_commit()` within `get_rev()`.
    +
    +    Note that unlike the default negotiator, the skipping negotiator's
    +    version of `rev_list_push()` returns a pointer to an 'entry' struct. As
    +    a consequence, callers must be prepared to handle a NULL return value.
    +    The caller in `push_parent()` gains a NULL-ness check, and the remaining
    +    two callers continue to ignore the return value from `rev_list_push()`.
    +
         Signed-off-by: Taylor Blau <ttaylorr@openai.com>
    -    Signed-off-by: Taylor Blau <me@ttaylorr.com>
     
      ## negotiator/skipping.c ##
    +@@ negotiator/skipping.c: static struct entry *rev_list_push(struct data *data, struct commit *commit, int
    + 	struct entry *entry;
    + 	commit->object.flags |= mark | SEEN;
    + 
    ++	if (repo_parse_commit(the_repository, commit))
    ++		return NULL;
    ++
    + 	CALLOC_ARRAY(entry, 1);
    + 	entry->commit = commit;
    + 	prio_queue_put(&data->rev_list, entry);
     @@ negotiator/skipping.c: static void mark_common(struct data *data, struct commit *seen_commit)
       * entry has the correct flags and ttl.
       *
    @@ negotiator/skipping.c: static void mark_common(struct data *data, struct commit
      static int push_parent(struct data *data, struct entry *entry,
      		       struct commit *to_push)
     @@ negotiator/skipping.c: static int push_parent(struct data *data, struct entry *entry,
    - parent_found:
      		;
      	} else {
    -+		/* Parse the parent before using its date to order the queue. */
    -+		if (repo_parse_commit(the_repository, to_push))
    -+			return 0;
      		parent_entry = rev_list_push(data, to_push, 0);
    ++		if (!parent_entry)
    ++			return 0;
      	}
      
    + 	if (entry->commit->object.flags & (COMMON | ADVERTISED)) {
    +@@ negotiator/skipping.c: 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);
    + 
     
      ## t/t5552-skipping-fetch-negotiator.sh ##
     @@ t/t5552-skipping-fetch-negotiator.sh: test_expect_success 'do not send "have" with ancestors of commits that server AC
    @@ t/t5552-skipping-fetch-negotiator.sh: test_expect_success 'do not send "have" wi
     +	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 >haves &&
    -+	sed -n "1,2p" haves >actual &&
    ++	sed -n "s/.*fetch> have //p" trace | head -n 2 >actual &&
     +	test_cmp expect actual
     +'
     +

base-commit: c51408889c3b372814bc20b9431c3b74d0d268eb
-- 
2.56.0.187.g9e9ae442333
Previous: Taylor BlauNext: Junio C Hamano
Message 7 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.