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

[PATCH v3 09/14] filter_refs(): build refs list as we go

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Sep 9, 2012, 06:19 UTC
Message-ID
<1347171589-13327-10-git-send-email-mhagger@alum.mit.edu>
In-Reply-To
<1347171589-13327-1-git-send-email-mhagger@alum.mit.edu>

Instead of temporarily storing matched refs to temporary array "return_refs", simply append them to newlist as we go. This changes the order of references in newlist to strictly sorted if "--all" and "--depth" and named references are all specified, but that usage is broken anyway (see the last two tests in t5500).

This changes the last test in t5500 from segfaulting into just emitting a spurious error (this will be fixed in a moment).

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
 builtin/fetch-pack.c | 31 ++++---------------------------
 1 file changed, 4 insertions(+), 27 deletions(-)
diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c
index 12ba009..4e94aa4 100644
--- a/builtin/fetch-pack.c
+++ b/builtin/fetch-pack.c
@@ -537,24 +537,11 @@ static int non_matching_ref(struct string_list_item *item, void *unused)
 
 static void filter_refs(struct ref **refs, struct string_list *sought)
 {
-	struct ref **return_refs;
 	struct ref *newlist = NULL;
 	struct ref **newtail = &newlist;
 	struct ref *ref, *next;
-	struct ref *fastarray[32];
 	int sought_pos;
 
-	if (sought->nr && !args.fetch_all) {
-		if (ARRAY_SIZE(fastarray) < sought->nr)
-			return_refs = xcalloc(sought->nr, sizeof(struct ref *));
-		else {
-			return_refs = fastarray;
-			memset(return_refs, 0, sizeof(struct ref *) * sought->nr);
-		}
-	}
-	else
-		return_refs = NULL;
-
 	sought_pos = 0;
 	for (ref = *refs; ref; ref = next) {
 		next = ref->next;
@@ -575,8 +562,10 @@ static void filter_refs(struct ref **refs, struct string_list *sought)
 				if (cmp < 0) /* definitely do not have it */
 					break;
 				else if (cmp == 0) { /* definitely have it */
-					return_refs[sought_pos] = ref;
 					sought->items[sought_pos++].util = "matched";
+					*newtail = ref;
+					ref->next = NULL;
+					newtail = &ref->next;
 					break;
 				}
 				else /* might have it; keep looking */
@@ -588,20 +577,8 @@ static void filter_refs(struct ref **refs, struct string_list *sought)
 		free(ref);
 	}
 
-	if (!args.fetch_all) {
-		int i;
-		for (i = 0; i < sought->nr; i++) {
-			ref = return_refs[i];
-			if (ref) {
-				*newtail = ref;
-				ref->next = NULL;
-				newtail = &ref->next;
-			}
-		}
-		if (return_refs != fastarray)
-			free(return_refs);
+	if (!args.fetch_all)
 		filter_string_list(sought, 0, non_matching_ref, NULL);
-	}
 	*refs = newlist;
 }
 
-- 
1.7.11.3
Previous: Michael HaggertyNext: Junio C Hamano
Message 18 of 32 in “Clean up how fetch_pack() handles the heads list”
  1. 00/14 Clean up how fetch_pack() handles the heads listMichael Haggerty, Sep 9, 2012
  2. 01/14 t5500: add tests of error output for missing refsMichael Haggerty, Sep 9, 2012
  3. 02/14 t5500: add tests of fetch-pack --all --depth=N $URL $REFMichael Haggerty, Sep 9, 2012
  4. Junio C HamanoSep 10, 2012
  5. Michael HaggertySep 10, 2012
  6. Philip OakleySep 18, 2012
  7. 03/14 Rename static function fetch_pack() to http_fetch_pack()Michael Haggerty, Sep 9, 2012
  8. 04/14 fetch_pack(): reindent function decl and defnMichael Haggerty, Sep 9, 2012
  9. 05/14 Change fetch_pack() and friends to take string_list argumentsMichael Haggerty, Sep 9, 2012
  10. Junio C HamanoSep 10, 2012
  11. Michael HaggertySep 17, 2012
  12. Junio C HamanoSep 17, 2012
  13. Jeff KingSep 17, 2012
  14. Junio C HamanoSep 18, 2012
  15. 06/14 filter_refs(): do not check the same sought_pos twiceMichael Haggerty, Sep 9, 2012
  16. 07/14 fetch_pack(): update sought->nr to reflect number of unique entriesMichael Haggerty, Sep 9, 2012
  17. 08/14 filter_refs(): delete matched refs from sought listMichael Haggerty, Sep 9, 2012
  18. 09/14 filter_refs(): build refs list as we goMichael Haggerty, Sep 9, 2012
  19. Junio C HamanoSep 10, 2012
  20. 10/14 filter_refs(): simplify logicMichael Haggerty, Sep 9, 2012
  21. 11/14 cmd_fetch_pack(): return early if finish_connect() failsMichael Haggerty, Sep 9, 2012
  22. 12/14 fetch-pack: report missing refs even if no existing refs were receivedMichael Haggerty, Sep 9, 2012
  23. 13/14 cmd_fetch_pack(): simplify computation of return valueMichael Haggerty, Sep 9, 2012
  24. 14/14 fetch-pack: eliminate spurious error messagesMichael Haggerty, Sep 9, 2012
  25. Junio C HamanoSep 9, 2012
  26. Jeff KingSep 9, 2012
  27. Junio C HamanoSep 9, 2012
  28. Michael HaggertySep 10, 2012
  29. Junio C HamanoSep 10, 2012
  30. Michael HaggertySep 17, 2012
  31. Junio C HamanoSep 17, 2012
  32. Junio C HamanoSep 10, 2012

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.