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

Re: [PATCH v3 2/5] fetch-pack: load tip_oids eagerly iff needed

From
René Scharfe <l.s.r@web.de>
Date
Oct 5, 2018, 20:13 UTC
Message-ID
<413be4ec-2473-c971-8545-3b7effbc157e@web.de>
In-Reply-To
<a82bf622-8ef8-5525-c3a8-b983d0cfe662@web.de>
Am 05.10.2018 um 00:11 schrieb René Scharfe:
Show 11 quoted lines
> Am 04.10.2018 um 23:38 schrieb Jonathan Tan:
>> I don't think the concerns are truly separated - the first loop quoted
>> needs to know that in the second loop, tip_oids is accessed only if
>> there is at least one unmatched ref.
> 
> Right, the two loops are still closely related, but only the first one
> is concerned with loading refs.
> 
> For a true separation we could first build a list of unmatched refs and
> then loop through that instead of `sought`.  Not sure if that's better,
> but maybe the overhead I imagine it would introduce isn't all that big.
Here's what I mean, on top of the other two patches:
---
 fetch-pack.c | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)
diff --git a/fetch-pack.c b/fetch-pack.c
index 53914563b5..7f28584bce 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -543,6 +543,8 @@ static void filter_refs(struct fetch_pack_args *args,
 	struct ref *newlist = NULL;
 	struct ref **newtail = &newlist;
 	struct ref *unmatched = NULL;
+	struct ref **unfound;
+	int nr_unfound = 0;
 	struct ref *ref, *next;
 	struct oidset tip_oids = OIDSET_INIT;
 	int i;
@@ -584,23 +586,19 @@ static void filter_refs(struct fetch_pack_args *args,
 		}
 	}
 
-	if (strict) {
-		for (i = 0; i < nr_sought; i++) {
-			ref = sought[i];
-			if (!is_unmatched_ref(ref))
-				continue;
-
-			add_refs_to_oidset(&tip_oids, unmatched);
-			add_refs_to_oidset(&tip_oids, newlist);
-			break;
-		}
+	ALLOC_ARRAY(unfound, nr_sought);
+	for (i = 0; i < nr_sought; i++) {
+		if (is_unmatched_ref(sought[i]))
+			unfound[nr_unfound++] = sought[i];
+	}
+	if (strict && nr_unfound) {
+		add_refs_to_oidset(&tip_oids, unmatched);
+		add_refs_to_oidset(&tip_oids, newlist);
 	}
 
 	/* Append unmatched requests to the list */
-	for (i = 0; i < nr_sought; i++) {
-		ref = sought[i];
-		if (!is_unmatched_ref(ref))
-			continue;
+	for (i = 0; i < nr_unfound; i++) {
+		ref = unfound[i];
 
 		if (!strict || oidset_contains(&tip_oids, &ref->old_oid)) {
 			ref->match_status = REF_MATCHED;
@@ -611,6 +609,7 @@ static void filter_refs(struct fetch_pack_args *args,
 		}
 	}
 
+	free(unfound);
 	oidset_clear(&tip_oids);
 	for (ref = unmatched; ref; ref = next) {
 		next = ref->next;
-- 
2.19.0
Previous: René ScharfeNext: Jeff King
Message 14 of 26 in “oidset: use khash”
  1. 0/2 oidset: use khashRené Scharfe, Oct 3, 2018
  2. 1/2 khash: factor out kh_release_*René Scharfe, Oct 3, 2018
  3. 2/2 oidset: use khashRené Scharfe, Oct 3, 2018
  4. Jeff KingOct 3, 2018
  5. René ScharfeOct 4, 2018
  6. Jeff KingOct 4, 2018
  7. Jeff KingOct 4, 2018
  8. René ScharfeOct 4, 2018
  9. 0/5 oidset: use khashRené Scharfe, Oct 4, 2018
  10. 1/5 fetch-pack: factor out is_unmatched_ref()René Scharfe, Oct 4, 2018
  11. 2/5 fetch-pack: load tip_oids eagerly iff neededRené Scharfe, Oct 4, 2018
  12. Jonathan TanOct 4, 2018
  13. René ScharfeOct 4, 2018
  14. René ScharfeOct 5, 2018
  15. Jeff KingOct 4, 2018
  16. Jonathan TanOct 4, 2018
  17. Jeff KingOct 4, 2018
  18. Jeff KingOct 4, 2018
  19. René ScharfeOct 5, 2018
  20. Jeff KingOct 5, 2018
  21. René ScharfeOct 5, 2018
  22. Jeff KingOct 5, 2018
  23. 3/5 khash: factor out kh_release_*René Scharfe, Oct 4, 2018
  24. 4/5 oidset: use khashRené Scharfe, Oct 4, 2018
  25. 5/5 oidset: uninline oidset_init()René Scharfe, Oct 4, 2018
  26. Jeff KingOct 4, 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.