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

[PATCH 1/2] refs: introduce the `refs_single_ref` function

From
Karthik Nayak <karthik.188@gmail.com>
Date
Dec 21, 2023, 17:07 UTC
Message-ID
<20231221170715.110565-2-karthik.188@gmail.com>
In-Reply-To
<20231221170715.110565-1-karthik.188@gmail.com>

We currently provide the functionality to iterate over refs and call a specific callback. This functionality currently supports iterating over the entire "refs/*" space or directly the "HEAD" ref. This leaves operational refs "ORIG_HEAD", "REBASE_HEAD" and so forth behind.

In the following commit, we introduce a mechanism to process all the operational refs outside the "refs/*" space. To do this, we require a function similar `refs_head_ref`, which can process a single specified reference. This commit introduces `refs_single_ref` to fill in that gap.

Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
---
 refs.c | 12 +++++++++---
 refs.h |  2 ++
 2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/refs.c b/refs.c
index 59fea0d44b..cebc5458d3 100644
--- a/refs.c
+++ b/refs.c
@@ -1549,18 +1549,24 @@ const char *find_descendant_ref(const char *dirname,
 	return NULL;
 }
 
-int refs_head_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data)
+int refs_single_ref(struct ref_store *refs, const char *refname,
+					each_ref_fn fn, void *cb_data)
 {
 	struct object_id oid;
 	int flag;
 
-	if (refs_resolve_ref_unsafe(refs, "HEAD", RESOLVE_REF_READING,
+	if (refs_resolve_ref_unsafe(refs, refname, RESOLVE_REF_READING,
 				    &oid, &flag))
-		return fn("HEAD", &oid, flag, cb_data);
+		return fn(refname, &oid, flag, cb_data);
 
 	return 0;
 }
 
+int refs_head_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data)
+{
+	return refs_single_ref(refs, "HEAD", fn, cb_data);
+}
+
 int head_ref(each_ref_fn fn, void *cb_data)
 {
 	return refs_head_ref(get_main_ref_store(the_repository), fn, cb_data);
diff --git a/refs.h b/refs.h
index 4816e46846..e147f13a85 100644
--- a/refs.h
+++ b/refs.h
@@ -324,6 +324,8 @@ typedef int each_repo_ref_fn(struct repository *r,
  * modifies the reference also returns a nonzero value to immediately
  * stop the iteration. Returned references are sorted.
  */
+int refs_single_ref(struct ref_store *refs, const char *refname,
+					each_ref_fn fn, void *cb_data);
 int refs_head_ref(struct ref_store *refs,
 		  each_ref_fn fn, void *cb_data);
 int refs_for_each_ref(struct ref_store *refs,
-- 
2.43.GIT
Previous: Karthik NayakNext: Karthik Nayak
Message 2 of 27 in “[RFC 0/2] Initial changes to support printing all refs”
  1. Karthik NayakDec 21, 2023
  2. 1/2 refs: introduce the `refs_single_ref` functionKarthik Nayak, Dec 21, 2023
  3. 2/2 ref-filter: support filtering of operational refsKarthik Nayak, Dec 21, 2023
  4. Junio C HamanoDec 21, 2023
  5. Karthik NayakDec 22, 2023
  6. Junio C HamanoDec 26, 2023
  7. Karthik NayakJan 2, 2024
  8. Junio C HamanoJan 2, 2024
  9. Taylor BlauJan 2, 2024
  10. Patrick SteinhardtJan 3, 2024
  11. Karthik NayakJan 3, 2024
  12. Junio C HamanoJan 3, 2024
  13. Patrick SteinhardtJan 3, 2024
  14. Junio C HamanoJan 3, 2024
  15. Patrick SteinhardtJan 3, 2024
  16. Junio C HamanoJan 3, 2024
  17. Patrick SteinhardtJan 3, 2024
  18. Junio C HamanoJan 3, 2024
  19. Patrick SteinhardtJan 3, 2024
  20. Karthik NayakJan 4, 2024
  21. Junio C HamanoJan 4, 2024
  22. Taylor BlauJan 3, 2024
  23. Patrick SteinhardtJan 3, 2024
  24. Taylor BlauJan 3, 2024
  25. Patrick SteinhardtDec 28, 2023
  26. Karthik NayakJan 2, 2024
  27. Taylor BlauJan 2, 2024

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.