Skip to contentSkip to conversation

negotiator/skipping: parse commit before queueing

PATCH In review Jonathan Tan 2 participants 2 messages Sep 27, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 negotiator/skipping: parse commit before queueing

The skipping negotiator pushes entries onto the priority queue without ensuring that the commit is parsed, resulting in the entry ending up in the wrong position due to a lack of commit time. Fix this by parsing the commit whenever we push an entry onto the priority queue.

---
This was noticed by Aevar in [1]. With this fix, 163 "have" lines are produced instead of the 14002 reported in [1].

I have included a test to demonstrate the issue, but I'm not sure if it's worth including it in the source tree.

[1] https://public-inbox.org/git/[email protected]/

---
 negotiator/skipping.c                |  2 +-
 t/t5552-skipping-fetch-negotiator.sh | 22 ++++++++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)
negotiator/skipping.c +1 -1
index dffbc76c49..9ce0555840 100644
@@ -64,6 +64,7 @@ static struct entry *rev_list_push(struct data *data, struct commit *commit, int
 
 	entry = xcalloc(1, sizeof(*entry));
 	entry->commit = commit;
+	parse_commit(commit);
 	prio_queue_put(&data->rev_list, entry);
 
 	if (!(mark & COMMON))
@@ -177,7 +178,6 @@ static const struct object_id *get_rev(struct data *data)
 		if (!(commit->object.flags & COMMON) && !entry->ttl)
 			to_send = commit;
 
-		parse_commit(commit);
 		for (p = commit->parents; p; p = p->next)
 			parent_pushed |= push_parent(data, entry, p->item);
 
t/t5552-skipping-fetch-negotiator.sh +22 -0
index 30857b84a8..f2f938e54e 100755
@@ -83,6 +83,28 @@ test_expect_success 'unknown fetch.negotiationAlgorithm values error out' '
 	test_i18ngrep ! "unknown fetch negotiation algorithm" err
 '
 
+test_expect_success 'works in absence of tags' '
+	rm -rf server client trace &&
+	git init server &&
+	test_commit -C server to_fetch &&
+
+	git init client &&
+	for i in $(test_seq 11)
+	do
+		test_commit -C client c$i
+	done &&
+	git -C client tag middle c6 &&
+	for i in $(test_seq 11)
+	do
+		git -C client tag -d c$i
+	done &&
+
+	test_config -C client fetch.negotiationalgorithm skipping &&
+	trace_fetch client "$(pwd)/server" &&
+	have_sent HEAD HEAD~2 HEAD~5 HEAD~10 &&
+	have_not_sent HEAD~1 HEAD~3 HEAD~4 HEAD~6 HEAD~7 HEAD~8 HEAD~9
+'
+
 test_expect_success 'when two skips collide, favor the larger one' '
 	rm -rf server client trace &&
 	git init server &&
Signature · 1 line
2.19.0.605.g01d371f741-goog
#1 lore raw
Quoted 7 lines · Jonathan Tan

The skipping negotiator pushes entries onto the priority queue without ensuring that the commit is parsed, resulting in the entry ending up in the wrong position due to a lack of commit time. Fix this by parsing the commit whenever we push an entry onto the priority queue.

---

Thanks for the prompt fix!

Quoted 5 lines

This was noticed by Aevar in [1]. With this fix, 163 "have" lines are produced instead of the 14002 reported in [1].

I have included a test to demonstrate the issue, but I'm not sure if it's worth including it in the source tree.

The test fails before the patch, and passes after, and tests that we do the right thing here. Seems best to include such tests whenever we can.