git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: git@vger.kernel.org
Cc: karthik nayak <karthik.188@gmail.com>
Subject: [PATCH v2 04/15] reftable/stack: open-code reading refs
Date: Wed, 14 Aug 2024 15:22:54 +0200	[thread overview]
Message-ID: <6ba3fcee4115fbf4e46a6a2a31f0b3c01b0903dd.1723640107.git.ps@pks.im> (raw)
In-Reply-To: <cover.1723640107.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


  parent reply	other threads:[~2024-08-14 13:22 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-14 13:22 [PATCH v2 00/15] reftable: drop generic `reftable_table` interface Patrick Steinhardt
2024-08-14 13:22 ` [PATCH v2 01/15] reftable/merged: expose functions to initialize iterators Patrick Steinhardt
2024-08-14 13:22 ` [PATCH v2 02/15] reftable/merged: rename `reftable_new_merged_table()` Patrick Steinhardt
2024-08-14 13:22 ` [PATCH v2 03/15] reftable/merged: stop using generic tables in the merged table Patrick Steinhardt
2024-08-14 13:22 ` Patrick Steinhardt [this message]
2024-08-14 13:22 ` [PATCH v2 05/15] reftable/iter: drop double-checking logic Patrick Steinhardt
2024-08-14 13:23 ` [PATCH v2 06/15] reftable/generic: move generic iterator code into iterator interface Patrick Steinhardt
2024-08-14 13:23 ` [PATCH v2 07/15] reftable/dump: drop unused `compact_stack()` Patrick Steinhardt
2024-08-14 13:23 ` [PATCH v2 08/15] t/helper: inline `reftable_dump_main()` Patrick Steinhardt
2024-08-14 13:23 ` [PATCH v2 09/15] t/helper: inline `reftable_reader_print_file()` Patrick Steinhardt
2024-08-14 13:23 ` [PATCH v2 10/15] t/helper: inline `reftable_stack_print_directory()` Patrick Steinhardt
2024-08-20  7:34   ` karthik nayak
2024-08-20  8:06     ` Patrick Steinhardt
2024-08-14 13:23 ` [PATCH v2 11/15] t/helper: inline `reftable_table_print()` Patrick Steinhardt
2024-08-14 13:23 ` [PATCH v2 12/15] t/helper: inline printing of reftable records Patrick Steinhardt
2024-08-14 13:23 ` [PATCH v2 13/15] t/helper: use `hash_to_hex_algop()` to print hashes Patrick Steinhardt
2024-08-14 13:23 ` [PATCH v2 14/15] t/helper: refactor to not use `struct reftable_table` Patrick Steinhardt
2024-08-14 13:23 ` [PATCH v2 15/15] reftable/generic: drop interface Patrick Steinhardt
2024-08-14 13:31 ` [PATCH v2 00/15] reftable: drop generic `reftable_table` interface Patrick Steinhardt
2024-08-14 17:21   ` Junio C Hamano
2024-08-15  5:29     ` Patrick Steinhardt
2024-08-20  7:38 ` karthik nayak
2024-08-22  6:34 ` [PATCH v3 " Patrick Steinhardt
2024-08-22  6:34   ` [PATCH v3 01/15] reftable/merged: expose functions to initialize iterators Patrick Steinhardt
2024-08-22  6:34   ` [PATCH v3 02/15] reftable/merged: rename `reftable_new_merged_table()` Patrick Steinhardt
2024-08-22  6:34   ` [PATCH v3 03/15] reftable/merged: stop using generic tables in the merged table Patrick Steinhardt
2024-08-22  6:34   ` [PATCH v3 04/15] reftable/stack: open-code reading refs Patrick Steinhardt
2024-08-22  6:34   ` [PATCH v3 05/15] reftable/iter: drop double-checking logic Patrick Steinhardt
2024-08-22  6:34   ` [PATCH v3 06/15] reftable/generic: move generic iterator code into iterator interface Patrick Steinhardt
2024-08-22  6:35   ` [PATCH v3 07/15] reftable/dump: drop unused `compact_stack()` Patrick Steinhardt
2024-08-22  6:35   ` [PATCH v3 08/15] t/helper: inline `reftable_dump_main()` Patrick Steinhardt
2024-08-22  6:35   ` [PATCH v3 09/15] t/helper: inline `reftable_reader_print_file()` Patrick Steinhardt
2024-08-22  6:35   ` [PATCH v3 10/15] t/helper: inline `reftable_stack_print_directory()` Patrick Steinhardt
2024-08-22  6:35   ` [PATCH v3 11/15] t/helper: inline `reftable_table_print()` Patrick Steinhardt
2024-08-22  6:35   ` [PATCH v3 12/15] t/helper: inline printing of reftable records Patrick Steinhardt
2024-08-22  6:35   ` [PATCH v3 13/15] t/helper: use `hash_to_hex_algop()` to print hashes Patrick Steinhardt
2024-08-22  6:35   ` [PATCH v3 14/15] t/helper: refactor to not use `struct reftable_table` Patrick Steinhardt
2024-08-22  6:35   ` [PATCH v3 15/15] reftable/generic: drop interface Patrick Steinhardt
2024-08-22  8:03   ` [PATCH v3 00/15] reftable: drop generic `reftable_table` interface karthik nayak
2024-08-22 17:11   ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6ba3fcee4115fbf4e46a6a2a31f0b3c01b0903dd.1723640107.git.ps@pks.im \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    --cc=karthik.188@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).