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

[PATCH 04/10] reftable/stack: open-code reading refs

From
Patrick Steinhardt <ps@pks.im>
Date
Aug 13, 2024, 06:24 UTC
Message-ID
<d5d24e03bd9d901e83ff3cd0f580b66e3601482a.1723528765.git.ps@pks.im>
In-Reply-To
<cover.1723528765.git.ps@pks.im>

To read a reference for the reftable stack, we first create a generic `reftable_table` from the merged table and then read the reference via a convenience function. We are about to remove these generic interfaces, so let's instead open-code the logic to prepare for this removal.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 reftable/stack.c | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)
diff --git a/reftable/stack.c b/reftable/stack.c
index 7f4e267ea9..d08ec00959 100644
--- a/reftable/stack.c
+++ b/reftable/stack.c
@@ -1468,9 +1468,28 @@ reftable_stack_compaction_stats(struct reftable_stack *st)
 int reftable_stack_read_ref(struct reftable_stack *st, const char *refname,
 			    struct reftable_ref_record *ref)
 {
-	struct reftable_table tab = { NULL };
-	reftable_table_from_merged_table(&tab, reftable_stack_merged_table(st));
-	return reftable_table_read_ref(&tab, refname, ref);
+	struct reftable_iterator it = { 0 };
+	int ret;
+
+	reftable_merged_table_init_ref_iterator(st->merged, &it);
+	ret = reftable_iterator_seek_ref(&it, refname);
+	if (ret)
+		goto out;
+
+	ret = reftable_iterator_next_ref(&it, ref);
+	if (ret)
+		goto out;
+
+	if (strcmp(ref->refname, refname) ||
+	    reftable_ref_record_is_deletion(ref)) {
+		reftable_ref_record_release(ref);
+		ret = 1;
+		goto out;
+	}
+
+out:
+	reftable_iterator_destroy(&it);
+	return ret;
 }
 
 int reftable_stack_read_log(struct reftable_stack *st, const char *refname,
-- 
2.46.0.46.g406f326d27.dirty
Previous: Justin ToblerNext: Patrick Steinhardt
Message 11 of 25 in “reftable: drop generic `reftable_table` interface”
  1. 00/10 reftable: drop generic `reftable_table` interfacePatrick Steinhardt, Aug 13, 2024
  2. 01/10 reftable/merged: expose functions to initialize iteratorsPatrick Steinhardt, Aug 13, 2024
  3. karthik nayakAug 13, 2024
  4. Patrick SteinhardtAug 14, 2024
  5. Justin ToblerAug 19, 2024
  6. Patrick SteinhardtAug 20, 2024
  7. 02/10 reftable/merged: rename `reftable_new_merged_table()`Patrick Steinhardt, Aug 13, 2024
  8. 03/10 reftable/merged: stop using generic tables in the merged tablePatrick Steinhardt, Aug 13, 2024
  9. karthik nayakAug 13, 2024
  10. Justin ToblerAug 19, 2024
  11. 04/10 reftable/stack: open-code reading refsPatrick Steinhardt, Aug 13, 2024
  12. 05/10 reftable/iter: drop double-checking logicPatrick Steinhardt, Aug 13, 2024
  13. Eric SunshineAug 13, 2024
  14. 06/10 reftable/generic: move generic iterator code into iterator interfacePatrick Steinhardt, Aug 13, 2024
  15. karthik nayakAug 13, 2024
  16. Patrick SteinhardtAug 14, 2024
  17. Junio C HamanoAug 14, 2024
  18. karthik nayakAug 15, 2024
  19. 07/10 reftable/dump: drop unused `compact_stack()`Patrick Steinhardt, Aug 13, 2024
  20. 08/10 reftable/dump: drop unused printing functionalityPatrick Steinhardt, Aug 13, 2024
  21. karthik nayakAug 13, 2024
  22. Patrick SteinhardtAug 14, 2024
  23. 09/10 reftable/dump: move code into "t/helper/test-reftable.c"Patrick Steinhardt, Aug 13, 2024
  24. 10/10 reftable/generic: drop interfacePatrick Steinhardt, Aug 13, 2024
  25. karthik nayakAug 13, 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.