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

[PATCH 6/7] remote.c: make singular free_ref() public

From
Jeff King <peff@peff.net>
Date
Apr 13, 2019, 05:54 UTC
Message-ID
<20190413055430.GF19495@sigill.intra.peff.net>
In-Reply-To
<20190413055127.GA32340@sigill.intra.peff.net>

We provide a free_refs() function to free a list, but there's no easy way for a caller to free a single ref. Let's make our singular free_ref() function public. Since its name is so similar to the list-freeing free_refs(), and because both of those functions have the same signature, it might be easy to accidentally use the wrong one. Let's call the singular version the more verbose "free_one_ref()" to distinguish it.

Signed-off-by: Jeff King <peff@peff.net>
---
 remote.c | 6 +++---
 remote.h | 4 +++-
 2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/remote.c b/remote.c
index 9cc3b07d21..3fe34eae85 100644
--- a/remote.c
+++ b/remote.c
@@ -820,11 +820,11 @@ struct ref *copy_ref_list(const struct ref *ref)
 	return ret;
 }
 
-static void free_ref(struct ref *ref)
+void free_one_ref(struct ref *ref)
 {
 	if (!ref)
 		return;
-	free_ref(ref->peer_ref);
+	free_one_ref(ref->peer_ref);
 	free(ref->remote_status);
 	free(ref->symref);
 	free(ref);
@@ -835,7 +835,7 @@ void free_refs(struct ref *ref)
 	struct ref *next;
 	while (ref) {
 		next = ref->next;
-		free_ref(ref);
+		free_one_ref(ref);
 		ref = next;
 	}
 }
diff --git a/remote.h b/remote.h
index da53ad570b..f58332a27e 100644
--- a/remote.h
+++ b/remote.h
@@ -131,8 +131,10 @@ int ref_compare_name(const void *, const void *);
 int check_ref_type(const struct ref *ref, int flags);
 
 /*
- * Frees the entire list and peers of elements.
+ * Free a single ref and its peer, or an entire list of refs and their peers,
+ * respectively.
  */
+void free_one_ref(struct ref *ref);
 void free_refs(struct ref *ref);
 
 struct oid_array;
-- 
2.21.0.931.gd0bc72a411
Previous: Jeff KingNext: Jeff King
Message 7 of 9 in “some fetch reachability-error fixes”
  1. 0/7 some fetch reachability-error fixesJeff King, Apr 13, 2019
  2. 1/7 t5516: drop ok=sigpipe from unreachable-want testsJeff King, Apr 13, 2019
  3. 2/7 t5530: check protocol response for "not our ref"Jeff King, Apr 13, 2019
  4. 3/7 upload-pack: send ERR packet for non-tip objectsJeff King, Apr 13, 2019
  5. 4/7 pkt-line: prepare buffer before handling ERR packetsJeff King, Apr 13, 2019
  6. 5/7 fetch: use free_refs()Jeff King, Apr 13, 2019
  7. 6/7 remote.c: make singular free_ref() publicJeff King, Apr 13, 2019
  8. 7/7 fetch: do not consider peeled tags as advertised tipsJeff King, Apr 13, 2019
  9. Jonathan TanApr 15, 2019

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.