From patchwork Tue Aug 13 06:24:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761362 Received: from fout1-smtp.messagingengine.com (fout1-smtp.messagingengine.com [103.168.172.144]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 10CB01C68C for ; Tue, 13 Aug 2024 06:24:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723530249; cv=none; b=h19+VFqx9QD1z2LzkByGi46f1sElZtnKXUH7txwV07ppIDFBTT34PfZpd99vLeUMgA2kBxpgsSfrur10NVirjX2oCFMpy6Ge2fzKgFE/iTklgWVXU+/rN7aZr0/d0UEmUVLwNnfFtsVzGL5lKPtlO+6EfXomaQFuuUOfgcZASxs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723530249; c=relaxed/simple; bh=ZiCLUi/BUqvxOdjN//zYawYCHFEi7nYpsw6HleDgafs=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=mQLOcpM59VbIwHazPnpfKnaw4+PHZrpDMsQubtqes3wD487sMyldfDDCc9zQrB/59erVrK9o5qSYuj9v1W5Eq0ED4UWFDy50dzcgG7hOTQbetNEf+pFEi5cvA0T68pLKh4hOSHih626noFFijr3PATyLPslHOLzVWp9WEdnJV6I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=laFpgeCi; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=PvQsoGv3; arc=none smtp.client-ip=103.168.172.144 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="laFpgeCi"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="PvQsoGv3" Received: from phl-compute-06.internal (phl-compute-06.nyi.internal [10.202.2.46]) by mailfout.nyi.internal (Postfix) with ESMTP id 15FEC138FD41 for ; Tue, 13 Aug 2024 02:24:06 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Tue, 13 Aug 2024 02:24:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1723530246; x=1723616646; bh=M5mbTth+1a 44lg4toqj2ICmCYVSy1NhOJWo3fQUJ4NU=; b=laFpgeCikOuhXayGO6r6h2RbLA IT9tzmKFx8xj015PjYvdpdR0dGJzV5P5271JZ95qRuWh7kzO9a11bHaQtIs93jaI GIfy6dPXQJYn3x/er9ijJbjMPYrUCOErfWOq+KDDckSGMrPBl9tj1ANcoX7kuCAM BGSE32Ys4EdssCGvkc7Ad0UcWig3HamDYoM7S9/1h3IC9O7JDapj1jCMCw/JinXe /G+/ao27GrwRTWwXhF+3Jj+Xe2RKPOV0bPOvpNVNlrTtWKOjwtubaDNcygGaMS2w DATPDFWYd6ApZ3haW0q9aLEzW9jwqO1w0fQoaoF7b0lqQrusfPFwrrfaXpIA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1723530246; x=1723616646; bh=M5mbTth+1a44lg4toqj2ICmCYVSy 1NhOJWo3fQUJ4NU=; b=PvQsoGv3BZ8jiPu6+qVKyvfYfD0RJeNdUeYmYa13U2P5 sOtAfRRnW4Cy+Oj2TuhJD4ZsI6aQWwz0FOYQRzmWPLKUYz9VWhnTc3QNaDv0TZVq +0uPJGWbGppltNtqCtZgfHZDehw2FdUW9rvPtvF/52PWHpyIp0owcT6hdZ/mQUH4 d11XOc5gzezXlAkVrk1k2D/OYdhIQ/r6STjSSnTiUPG5LjHAZuUdRPGjgtjn2RIa TE8UCUwFoALwM0gPYOl0ObrkGbmrEY7AndHE2y0lk37ZAa948P2Z/JOKuVLq2VWv V7B4x44ICBaz22No2TGoSv6Cuhb/FwW4dmvvsFyfvA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtuddguddtkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhepfffhvf fukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhn hhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrhhnpeehkeeffeegge dvgedvfeefheettddtffejuefflefggfehfeelffeljedvfeehieenucevlhhushhtvghr ufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsg gprhgtphhtthhopedupdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehgihhtsehv ghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 13 Aug 2024 02:24:05 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 7ac530c9 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 13 Aug 2024 06:23:49 +0000 (UTC) Date: Tue, 13 Aug 2024 08:24:04 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 01/10] reftable/merged: expose functions to initialize iterators Message-ID: <404d64effde3bee424e338d858ed507ff83dff20.1723528765.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: We do not expose any functions via our public headers that would allow a caller to initialize a reftable iterator from a merged table. Instead, they are expected to go via the generic `reftable_table` interface, which is somewhat roundabout. Implement two new functions to initialize iterators for ref and log records to plug this gap. Signed-off-by: Patrick Steinhardt --- reftable/merged.c | 12 ++++++++++++ reftable/reftable-merged.h | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/reftable/merged.c b/reftable/merged.c index 6adce44f4b..8d78b3da71 100644 --- a/reftable/merged.c +++ b/reftable/merged.c @@ -254,6 +254,18 @@ void merged_table_init_iter(struct reftable_merged_table *mt, iterator_from_merged_iter(it, mi); } +void reftable_merged_table_init_ref_iterator(struct reftable_merged_table *mt, + struct reftable_iterator *it) +{ + merged_table_init_iter(mt, it, BLOCK_TYPE_REF); +} + +void reftable_merged_table_init_log_iterator(struct reftable_merged_table *mt, + struct reftable_iterator *it) +{ + merged_table_init_iter(mt, it, BLOCK_TYPE_LOG); +} + uint32_t reftable_merged_table_hash_id(struct reftable_merged_table *mt) { return mt->hash_id; diff --git a/reftable/reftable-merged.h b/reftable/reftable-merged.h index 14d5fc9f05..4deb0ad22e 100644 --- a/reftable/reftable-merged.h +++ b/reftable/reftable-merged.h @@ -36,6 +36,14 @@ int reftable_new_merged_table(struct reftable_merged_table **dest, struct reftable_table *stack, size_t n, uint32_t hash_id); +/* Initialize a merged table iterator for reading refs. */ +void reftable_merged_table_init_ref_iterator(struct reftable_merged_table *mt, + struct reftable_iterator *it); + +/* Initialize a merged table iterator for reading logs. */ +void reftable_merged_table_init_log_iterator(struct reftable_merged_table *mt, + struct reftable_iterator *it); + /* returns the max update_index covered by this merged table. */ uint64_t reftable_merged_table_max_update_index(struct reftable_merged_table *mt); From patchwork Tue Aug 13 06:24:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761364 Received: from fout1-smtp.messagingengine.com (fout1-smtp.messagingengine.com [103.168.172.144]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C7B45364A4 for ; Tue, 13 Aug 2024 06:24:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723530251; cv=none; b=o2rd0fRBPBqeJiJ0/Af5Mz0vYhMLaT84iT9EfGDeVbtdlIegtrarjz41GSF73N20HePOuln2YThtWhrSQAHmE3WvQHPMGYu2EoWI/t0xCxvz4Larb1o34lxdmYJoFk4HndPhHxkey91ycM+m0SFDF9tJkxrVU87npVDPnYIAoEs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723530251; c=relaxed/simple; bh=UpAlBSqIAJIpMu8J2u5EahvDWzpl9hnzUvCAQFFGDKo=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nz71tCR4mhJ2bHzPHno9PAvTOtWRZjR+3ysfIcsm4nr0KO9SvaDeXjRb3AjpemADl0cOERFcbHNoWqagaP2406pmSiVp8AL3D9T9F4VYJ6FhAWXCS1df8kfGcwgbF0K5ORVaVL8zhKObvGTMA2u72TczEsxlzzCdL8mOEkez15U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=nH39ujT/; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=FqZSkaVW; arc=none smtp.client-ip=103.168.172.144 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="nH39ujT/"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="FqZSkaVW" Received: from phl-compute-01.internal (phl-compute-01.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id E4883138FD46 for ; Tue, 13 Aug 2024 02:24:08 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Tue, 13 Aug 2024 02:24:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1723530248; x=1723616648; bh=ISM+OyIsFj cXsFWN8SP+YOmX15fIP+fBmMlyP2t1JY4=; b=nH39ujT/ojxgSL5lSjiHYJ1SUk BMKRbbkKqmn/vquGXiJRXxzqrrETrefm7SBOvIxvS6mpbl0+jRK5Qs41OjfazRXR 4yzXo8fAHiCg7SeviVfuhEQ4KANxS1Cf7kzHsWNfdPRWulnaoQAezlUZMwoVHx1D E2jOcnoaU1HXgLdhWCjRmRqC/6EP9vS24oYCXU6LI36cwczo1Rt7IskPctmg+gEi t5LSsjhYsZmb9DVPSTyj0AMPvsvxA6ZWmDZz7BKcyteJ+FR2IbG2cyJfUv+NQzzd o6pb/9j/xnv82BKqZSaol/Jgd4o8Xj2QOFM7eO24c3zQiuHMUubee78pN0Aw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1723530248; x=1723616648; bh=ISM+OyIsFjcXsFWN8SP+YOmX15fI P+fBmMlyP2t1JY4=; b=FqZSkaVWq3tLHX/v/g+zpF2bk5ch5naTDmTeFFX1remh knzqoeUGvhnR0VMgKhEOfhKCla46o15uBCtP/SSj5JyxVWIkgZLfJq4uHuWDYkKC wSIBXu7fLiBITWYhcPBKuo6ZDr2L227MCMXUMquITwZof2vwi+qzpY3pXHu5R/kx igLZIqC15pjk/72+OZtwAdcXAEXOE8KTc6Eu9CdJmQjVH/NzvIHzB+G7RyoySq8v UkD362/Tgqnt3ZcPXA55DPgELEf2ZUc6sGgplNFYPjBX5u9s/3pPm4pASvXB51ol V+OwjbjqyIFojmYOz+pp5n4D52Ir7IvKCc8ndY2qVw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtuddguddtkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhepfffhvf fukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhn hhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrhhnpeehkeeffeegge dvgedvfeefheettddtffejuefflefggfehfeelffeljedvfeehieenucevlhhushhtvghr ufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsg gprhgtphhtthhopedupdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehgihhtsehv ghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 13 Aug 2024 02:24:08 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 16d378b8 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 13 Aug 2024 06:23:52 +0000 (UTC) Date: Tue, 13 Aug 2024 08:24:07 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 02/10] reftable/merged: rename `reftable_new_merged_table()` Message-ID: <511416fb73f2ab42dac08966ca6e82ced0f91e50.1723528765.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Rename `reftable_new_merged_table()` to `reftable_merged_table_new()` such that the name matches our coding style. Signed-off-by: Patrick Steinhardt --- reftable/merged.c | 2 +- reftable/reftable-merged.h | 9 +++++---- reftable/stack.c | 4 ++-- t/unit-tests/t-reftable-merged.c | 8 ++++---- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/reftable/merged.c b/reftable/merged.c index 8d78b3da71..25d414ec41 100644 --- a/reftable/merged.c +++ b/reftable/merged.c @@ -192,7 +192,7 @@ static void iterator_from_merged_iter(struct reftable_iterator *it, it->ops = &merged_iter_vtable; } -int reftable_new_merged_table(struct reftable_merged_table **dest, +int reftable_merged_table_new(struct reftable_merged_table **dest, struct reftable_table *stack, size_t n, uint32_t hash_id) { diff --git a/reftable/reftable-merged.h b/reftable/reftable-merged.h index 4deb0ad22e..72762483b9 100644 --- a/reftable/reftable-merged.h +++ b/reftable/reftable-merged.h @@ -29,10 +29,11 @@ struct reftable_merged_table; /* A generic reftable; see below. */ struct reftable_table; -/* reftable_new_merged_table creates a new merged table. It takes ownership of - the stack array. -*/ -int reftable_new_merged_table(struct reftable_merged_table **dest, +/* + * reftable_merged_table_new creates a new merged table. It takes ownership of + * the stack array. + */ +int reftable_merged_table_new(struct reftable_merged_table **dest, struct reftable_table *stack, size_t n, uint32_t hash_id); diff --git a/reftable/stack.c b/reftable/stack.c index 2071e428a8..64c7fdf8c4 100644 --- a/reftable/stack.c +++ b/reftable/stack.c @@ -272,7 +272,7 @@ static int reftable_stack_reload_once(struct reftable_stack *st, } /* success! */ - err = reftable_new_merged_table(&new_merged, new_tables, + err = reftable_merged_table_new(&new_merged, new_tables, new_readers_len, st->opts.hash_id); if (err < 0) goto done; @@ -924,7 +924,7 @@ static int stack_write_compact(struct reftable_stack *st, reftable_writer_set_limits(wr, st->readers[first]->min_update_index, st->readers[last]->max_update_index); - err = reftable_new_merged_table(&mt, subtabs, subtabs_len, + err = reftable_merged_table_new(&mt, subtabs, subtabs_len, st->opts.hash_id); if (err < 0) { reftable_free(subtabs); diff --git a/t/unit-tests/t-reftable-merged.c b/t/unit-tests/t-reftable-merged.c index b6263ee8b5..210603e8c7 100644 --- a/t/unit-tests/t-reftable-merged.c +++ b/t/unit-tests/t-reftable-merged.c @@ -111,7 +111,7 @@ merged_table_from_records(struct reftable_ref_record **refs, reftable_table_from_reader(&tabs[i], (*readers)[i]); } - err = reftable_new_merged_table(&mt, tabs, n, GIT_SHA1_FORMAT_ID); + err = reftable_merged_table_new(&mt, tabs, n, GIT_SHA1_FORMAT_ID); check(!err); return mt; } @@ -289,7 +289,7 @@ merged_table_from_log_records(struct reftable_log_record **logs, reftable_table_from_reader(&tabs[i], (*readers)[i]); } - err = reftable_new_merged_table(&mt, tabs, n, GIT_SHA1_FORMAT_ID); + err = reftable_merged_table_new(&mt, tabs, n, GIT_SHA1_FORMAT_ID); check(!err); return mt; } @@ -441,9 +441,9 @@ static void t_default_write_opts(void) check_int(hash_id, ==, GIT_SHA1_FORMAT_ID); reftable_table_from_reader(&tab[0], rd); - err = reftable_new_merged_table(&merged, tab, 1, GIT_SHA256_FORMAT_ID); + err = reftable_merged_table_new(&merged, tab, 1, GIT_SHA256_FORMAT_ID); check_int(err, ==, REFTABLE_FORMAT_ERROR); - err = reftable_new_merged_table(&merged, tab, 1, GIT_SHA1_FORMAT_ID); + err = reftable_merged_table_new(&merged, tab, 1, GIT_SHA1_FORMAT_ID); check(!err); reftable_reader_free(rd); From patchwork Tue Aug 13 06:24:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761365 Received: from fout1-smtp.messagingengine.com (fout1-smtp.messagingengine.com [103.168.172.144]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B03B84206D for ; Tue, 13 Aug 2024 06:24:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723530255; cv=none; b=UTm5M4Ib7OhnF788lCAdXp0xXsaIAjRVfIYMqfofsZTi+w26yfGt4cirsajIEBlE7iFWs5e7xv/Hz8So02HrD6lHKreG3l6R+g+GrWs/ObIYJjYuHjj1eHliVMB/Dn2mv5rlrGqJUbXQIB+r2iQEHKCCCjaO4jxfcdpOOmIna3E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723530255; c=relaxed/simple; bh=Mhwge3xFJBXNESpNv8E1WB4VbEiluGJkK9PCYRj6xEw=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=c6oIqPkH2lEIMhJEgKaKbNxNGwAjPWl5bfcDGor5ES8UDXCA29+BzILailfsv3eVmVuU6ezxl8QvQDqfatuGhe3waybEKT6mX5N1swVIilFIe3trWT3JHlEvY6GC469bvIKhjnMMH0Z+CkAnZquduj+dP5USYAps4Igv1dHMXQM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=G/x/84xb; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=l2lvA41w; arc=none smtp.client-ip=103.168.172.144 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="G/x/84xb"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="l2lvA41w" Received: from phl-compute-01.internal (phl-compute-01.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id B8072138FD3E for ; Tue, 13 Aug 2024 02:24:11 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Tue, 13 Aug 2024 02:24:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1723530251; x=1723616651; bh=p75PYTHWih BwWHhm6Bla7LK/qR6/OmQezxH65fLHq+I=; b=G/x/84xbJvrMPu+ce5Lm4107xY jXadTYXV/fgwCz6gAeyurjOTvWgyKNqTfl4i9A16mS7BlWnOocgnveQYjR9wo8i4 88dv51eSyICqWhJ9KfoehgXu9xaWZV89S3BHUZl8xiJ6VFRRbd1afHDYD3KxD/hW XnqUe+ls85wDO9sjk+y4IDBUvsH7jQLycLAanIdgL+sWKhopxAUZj3Q7BWl5Q4Oi MSqKOm/beDCPHEk2o3hOuwrMHMSuAU44tK4vZHN5R6TMjY75Q9fBnMUjeEZvgWMQ bTfArTnldZ3QhJXEe53aSP/h/eyc42YgRk4EJSBoFarQ40ll4l7lj2fJxvhg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1723530251; x=1723616651; bh=p75PYTHWihBwWHhm6Bla7LK/qR6/ OmQezxH65fLHq+I=; b=l2lvA41wvSFfPiAY5DsPPBJ1YspSINDxRjlS/l4/8+NO hQK4F2FLaPq7vvFDM5E4ffJvykvSiXMV7o9BQo9+ViKL/T9BKESjv6DvgmPrIi4A c5+GPDFC21ypf2++r5EpJUAUSa7h3qBtHxyU2eu/TAnivqTaXGTkjFO6KcJu+NxD 0hlYXM/XJ730/7KB7VkF1ca2i5g9iEGmNn9/9dNiJx9jZ74wS0xzmStY1gcdJKyM a376pK63lr6K5dg7VM2Vs/szndWiVvcumjO60IUCPgkR5tofviih63wIzEQAkE7g J6UA0OMAa+0pvGQFAiSVpTZhCOgr5P5MwQAmy5qjJw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtuddguddtkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhepfffhvf fukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhn hhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrhhnpeehkeeffeegge dvgedvfeefheettddtffejuefflefggfehfeelffeljedvfeehieenucevlhhushhtvghr ufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsg gprhgtphhtthhopedupdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehgihhtsehv ghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 13 Aug 2024 02:24:11 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id b59f0fd9 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 13 Aug 2024 06:23:55 +0000 (UTC) Date: Tue, 13 Aug 2024 08:24:09 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 03/10] reftable/merged: stop using generic tables in the merged table Message-ID: <86e2f9f5dc64eee97510e597820791287032ba29.1723528765.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The merged table provides access to a reftable stack by merging the contents of those tables into a virtual table. These subtables are being tracked via `struct reftable_table`, which is a generic interface for accessing either a single reftable or a merged reftable. So in theory, it would be possible for the merged table to merge together other merged tables. This is somewhat nonsensical though: we only ever set up a merged table over normal reftables, and there is no reason to do otherwise. This generic interface thus makes the code way harder to follow and reason about than really necessary. The abstraction layer may also have an impact on performance, even though the extra set of vtable function calls probably doesn't really matter. Refactor the merged tables to use a `struct reftable_reader` for each of the subtables instead, which gives us direct access to the underlying tables. Adjust names accordingly. Signed-off-by: Patrick Steinhardt --- reftable/merged.c | 28 +++++++++---------- reftable/merged.h | 4 +-- reftable/reader.c | 6 ++-- reftable/reader.h | 4 +++ reftable/reftable-merged.h | 7 +++-- reftable/stack.c | 48 ++++++++++++-------------------- reftable/stack_test.c | 22 +++++++-------- t/unit-tests/t-reftable-merged.c | 16 +++-------- 8 files changed, 60 insertions(+), 75 deletions(-) diff --git a/reftable/merged.c b/reftable/merged.c index 25d414ec41..2e72eab306 100644 --- a/reftable/merged.c +++ b/reftable/merged.c @@ -11,6 +11,7 @@ license that can be found in the LICENSE file or at #include "constants.h" #include "iter.h" #include "pq.h" +#include "reader.h" #include "record.h" #include "generic.h" #include "reftable-merged.h" @@ -25,7 +26,7 @@ struct merged_subiter { struct merged_iter { struct merged_subiter *subiters; struct merged_iter_pqueue pq; - size_t stack_len; + size_t subiters_len; int suppress_deletions; ssize_t advance_index; }; @@ -38,12 +39,12 @@ static void merged_iter_init(struct merged_iter *mi, mi->advance_index = -1; mi->suppress_deletions = mt->suppress_deletions; - REFTABLE_CALLOC_ARRAY(mi->subiters, mt->stack_len); - for (size_t i = 0; i < mt->stack_len; i++) { + REFTABLE_CALLOC_ARRAY(mi->subiters, mt->readers_len); + for (size_t i = 0; i < mt->readers_len; i++) { reftable_record_init(&mi->subiters[i].rec, typ); - table_init_iter(&mt->stack[i], &mi->subiters[i].iter, typ); + reader_init_iter(mt->readers[i], &mi->subiters[i].iter, typ); } - mi->stack_len = mt->stack_len; + mi->subiters_len = mt->readers_len; } static void merged_iter_close(void *p) @@ -51,7 +52,7 @@ static void merged_iter_close(void *p) struct merged_iter *mi = p; merged_iter_pqueue_release(&mi->pq); - for (size_t i = 0; i < mi->stack_len; i++) { + for (size_t i = 0; i < mi->subiters_len; i++) { reftable_iterator_destroy(&mi->subiters[i].iter); reftable_record_release(&mi->subiters[i].rec); } @@ -80,7 +81,7 @@ static int merged_iter_seek(struct merged_iter *mi, struct reftable_record *want mi->advance_index = -1; - for (size_t i = 0; i < mi->stack_len; i++) { + for (size_t i = 0; i < mi->subiters_len; i++) { err = iterator_seek(&mi->subiters[i].iter, want); if (err < 0) return err; @@ -193,7 +194,7 @@ static void iterator_from_merged_iter(struct reftable_iterator *it, } int reftable_merged_table_new(struct reftable_merged_table **dest, - struct reftable_table *stack, size_t n, + struct reftable_reader **readers, size_t n, uint32_t hash_id) { struct reftable_merged_table *m = NULL; @@ -201,10 +202,10 @@ int reftable_merged_table_new(struct reftable_merged_table **dest, uint64_t first_min = 0; for (size_t i = 0; i < n; i++) { - uint64_t min = reftable_table_min_update_index(&stack[i]); - uint64_t max = reftable_table_max_update_index(&stack[i]); + uint64_t min = reftable_reader_min_update_index(readers[i]); + uint64_t max = reftable_reader_max_update_index(readers[i]); - if (reftable_table_hash_id(&stack[i]) != hash_id) { + if (reftable_reader_hash_id(readers[i]) != hash_id) { return REFTABLE_FORMAT_ERROR; } if (i == 0 || min < first_min) { @@ -216,8 +217,8 @@ int reftable_merged_table_new(struct reftable_merged_table **dest, } REFTABLE_CALLOC_ARRAY(m, 1); - m->stack = stack; - m->stack_len = n; + m->readers = readers; + m->readers_len = n; m->min = first_min; m->max = last_max; m->hash_id = hash_id; @@ -229,7 +230,6 @@ void reftable_merged_table_free(struct reftable_merged_table *mt) { if (!mt) return; - FREE_AND_NULL(mt->stack); reftable_free(mt); } diff --git a/reftable/merged.h b/reftable/merged.h index 2efe571da6..de5fd33f01 100644 --- a/reftable/merged.h +++ b/reftable/merged.h @@ -12,8 +12,8 @@ license that can be found in the LICENSE file or at #include "system.h" struct reftable_merged_table { - struct reftable_table *stack; - size_t stack_len; + struct reftable_reader **readers; + size_t readers_len; uint32_t hash_id; /* If unset, produce deletions. This is useful for compaction. For the diff --git a/reftable/reader.c b/reftable/reader.c index 29c99e2269..f7ae35da72 100644 --- a/reftable/reader.c +++ b/reftable/reader.c @@ -605,9 +605,9 @@ static void iterator_from_table_iter(struct reftable_iterator *it, it->ops = &table_iter_vtable; } -static void reader_init_iter(struct reftable_reader *r, - struct reftable_iterator *it, - uint8_t typ) +void reader_init_iter(struct reftable_reader *r, + struct reftable_iterator *it, + uint8_t typ) { struct reftable_reader_offsets *offs = reader_offsets_for(r, typ); diff --git a/reftable/reader.h b/reftable/reader.h index e869165f23..a2c204d523 100644 --- a/reftable/reader.h +++ b/reftable/reader.h @@ -57,6 +57,10 @@ int init_reader(struct reftable_reader *r, struct reftable_block_source *source, void reader_close(struct reftable_reader *r); const char *reader_name(struct reftable_reader *r); +void reader_init_iter(struct reftable_reader *r, + struct reftable_iterator *it, + uint8_t typ); + /* initialize a block reader to read from `r` */ int reader_init_block_reader(struct reftable_reader *r, struct block_reader *br, uint64_t next_off, uint8_t want_typ); diff --git a/reftable/reftable-merged.h b/reftable/reftable-merged.h index 72762483b9..03c2619c0f 100644 --- a/reftable/reftable-merged.h +++ b/reftable/reftable-merged.h @@ -28,13 +28,14 @@ struct reftable_merged_table; /* A generic reftable; see below. */ struct reftable_table; +struct reftable_reader; /* - * reftable_merged_table_new creates a new merged table. It takes ownership of - * the stack array. + * reftable_merged_table_new creates a new merged table. The readers must be + * kept alive as long as the merged table is still in use. */ int reftable_merged_table_new(struct reftable_merged_table **dest, - struct reftable_table *stack, size_t n, + struct reftable_reader **readers, size_t n, uint32_t hash_id); /* Initialize a merged table iterator for reading refs. */ diff --git a/reftable/stack.c b/reftable/stack.c index 64c7fdf8c4..7f4e267ea9 100644 --- a/reftable/stack.c +++ b/reftable/stack.c @@ -225,13 +225,11 @@ static int reftable_stack_reload_once(struct reftable_stack *st, const char **names, int reuse_open) { - size_t cur_len = !st->merged ? 0 : st->merged->stack_len; + size_t cur_len = !st->merged ? 0 : st->merged->readers_len; struct reftable_reader **cur = stack_copy_readers(st, cur_len); size_t names_len = names_length(names); struct reftable_reader **new_readers = reftable_calloc(names_len, sizeof(*new_readers)); - struct reftable_table *new_tables = - reftable_calloc(names_len, sizeof(*new_tables)); size_t new_readers_len = 0; struct reftable_merged_table *new_merged = NULL; struct strbuf table_path = STRBUF_INIT; @@ -267,17 +265,15 @@ static int reftable_stack_reload_once(struct reftable_stack *st, } new_readers[new_readers_len] = rd; - reftable_table_from_reader(&new_tables[new_readers_len], rd); new_readers_len++; } /* success! */ - err = reftable_merged_table_new(&new_merged, new_tables, + err = reftable_merged_table_new(&new_merged, new_readers, new_readers_len, st->opts.hash_id); if (err < 0) goto done; - new_tables = NULL; st->readers_len = new_readers_len; if (st->merged) reftable_merged_table_free(st->merged); @@ -309,7 +305,6 @@ static int reftable_stack_reload_once(struct reftable_stack *st, reftable_reader_free(new_readers[i]); } reftable_free(new_readers); - reftable_free(new_tables); reftable_free(cur); strbuf_release(&table_path); return err; @@ -520,7 +515,7 @@ static int stack_uptodate(struct reftable_stack *st) } } - if (names[st->merged->stack_len]) { + if (names[st->merged->readers_len]) { err = 1; goto done; } @@ -659,7 +654,7 @@ int reftable_addition_commit(struct reftable_addition *add) if (add->new_tables_len == 0) goto done; - for (i = 0; i < add->stack->merged->stack_len; i++) { + for (i = 0; i < add->stack->merged->readers_len; i++) { strbuf_addstr(&table_list, add->stack->readers[i]->name); strbuf_addstr(&table_list, "\n"); } @@ -839,7 +834,7 @@ int reftable_addition_add(struct reftable_addition *add, uint64_t reftable_stack_next_update_index(struct reftable_stack *st) { - int sz = st->merged->stack_len; + int sz = st->merged->readers_len; if (sz > 0) return reftable_reader_max_update_index(st->readers[sz - 1]) + 1; @@ -906,30 +901,23 @@ static int stack_write_compact(struct reftable_stack *st, size_t first, size_t last, struct reftable_log_expiry_config *config) { - size_t subtabs_len = last - first + 1; - struct reftable_table *subtabs = reftable_calloc( - last - first + 1, sizeof(*subtabs)); struct reftable_merged_table *mt = NULL; struct reftable_iterator it = { NULL }; struct reftable_ref_record ref = { NULL }; struct reftable_log_record log = { NULL }; + size_t subtabs_len = last - first + 1; uint64_t entries = 0; int err = 0; - for (size_t i = first, j = 0; i <= last; i++) { - struct reftable_reader *t = st->readers[i]; - reftable_table_from_reader(&subtabs[j++], t); - st->stats.bytes += t->size; - } + for (size_t i = first; i <= last; i++) + st->stats.bytes += st->readers[i]->size; reftable_writer_set_limits(wr, st->readers[first]->min_update_index, st->readers[last]->max_update_index); - err = reftable_merged_table_new(&mt, subtabs, subtabs_len, + err = reftable_merged_table_new(&mt, st->readers + first, subtabs_len, st->opts.hash_id); - if (err < 0) { - reftable_free(subtabs); + if (err < 0) goto done; - } merged_table_init_iter(mt, &it, BLOCK_TYPE_REF); err = reftable_iterator_seek_ref(&it, ""); @@ -1207,7 +1195,7 @@ static int stack_compact_range(struct reftable_stack *st, * have compacted them. */ for (size_t j = 1; j < last - first + 1; j++) { - const char *old = first + j < st->merged->stack_len ? + const char *old = first + j < st->merged->readers_len ? st->readers[first + j]->name : NULL; const char *new = names[i + j]; @@ -1248,10 +1236,10 @@ static int stack_compact_range(struct reftable_stack *st, * `fd_read_lines()` uses a `NULL` sentinel to indicate that * the array is at its end. As we use `free_names()` to free * the array, we need to include this sentinel value here and - * thus have to allocate `stack_len + 1` many entries. + * thus have to allocate `readers_len + 1` many entries. */ - REFTABLE_CALLOC_ARRAY(names, st->merged->stack_len + 1); - for (size_t i = 0; i < st->merged->stack_len; i++) + REFTABLE_CALLOC_ARRAY(names, st->merged->readers_len + 1); + for (size_t i = 0; i < st->merged->readers_len; i++) names[i] = xstrdup(st->readers[i]->name); first_to_replace = first; last_to_replace = last; @@ -1358,7 +1346,7 @@ static int stack_compact_range_stats(struct reftable_stack *st, int reftable_stack_compact_all(struct reftable_stack *st, struct reftable_log_expiry_config *config) { - size_t last = st->merged->stack_len ? st->merged->stack_len - 1 : 0; + size_t last = st->merged->readers_len ? st->merged->readers_len - 1 : 0; return stack_compact_range_stats(st, 0, last, config, 0); } @@ -1449,9 +1437,9 @@ static uint64_t *stack_table_sizes_for_compaction(struct reftable_stack *st) int overhead = header_size(version) - 1; uint64_t *sizes; - REFTABLE_CALLOC_ARRAY(sizes, st->merged->stack_len); + REFTABLE_CALLOC_ARRAY(sizes, st->merged->readers_len); - for (size_t i = 0; i < st->merged->stack_len; i++) + for (size_t i = 0; i < st->merged->readers_len; i++) sizes[i] = st->readers[i]->size - overhead; return sizes; @@ -1461,7 +1449,7 @@ int reftable_stack_auto_compact(struct reftable_stack *st) { uint64_t *sizes = stack_table_sizes_for_compaction(st); struct segment seg = - suggest_compaction_segment(sizes, st->merged->stack_len, + suggest_compaction_segment(sizes, st->merged->readers_len, st->opts.auto_compaction_factor); reftable_free(sizes); if (segment_size(&seg) > 0) diff --git a/reftable/stack_test.c b/reftable/stack_test.c index 8c36590ff0..dbca9eaf4a 100644 --- a/reftable/stack_test.c +++ b/reftable/stack_test.c @@ -347,9 +347,9 @@ static void test_reftable_stack_transaction_api_performs_auto_compaction(void) * all tables in the stack. */ if (i != n) - EXPECT(st->merged->stack_len == i + 1); + EXPECT(st->merged->readers_len == i + 1); else - EXPECT(st->merged->stack_len == 1); + EXPECT(st->merged->readers_len == 1); } reftable_stack_destroy(st); @@ -375,7 +375,7 @@ static void test_reftable_stack_auto_compaction_fails_gracefully(void) err = reftable_stack_add(st, write_test_ref, &ref); EXPECT_ERR(err); - EXPECT(st->merged->stack_len == 1); + EXPECT(st->merged->readers_len == 1); EXPECT(st->stats.attempts == 0); EXPECT(st->stats.failures == 0); @@ -390,7 +390,7 @@ static void test_reftable_stack_auto_compaction_fails_gracefully(void) ref.update_index = 2; err = reftable_stack_add(st, write_test_ref, &ref); EXPECT_ERR(err); - EXPECT(st->merged->stack_len == 2); + EXPECT(st->merged->readers_len == 2); EXPECT(st->stats.attempts == 1); EXPECT(st->stats.failures == 1); @@ -881,7 +881,7 @@ static void test_reftable_stack_auto_compaction(void) err = reftable_stack_auto_compact(st); EXPECT_ERR(err); - EXPECT(i < 3 || st->merged->stack_len < 2 * fastlog2(i)); + EXPECT(i < 3 || st->merged->readers_len < 2 * fastlog2(i)); } EXPECT(reftable_stack_compaction_stats(st)->entries_written < @@ -905,7 +905,7 @@ static void test_reftable_stack_auto_compaction_with_locked_tables(void) EXPECT_ERR(err); write_n_ref_tables(st, 5); - EXPECT(st->merged->stack_len == 5); + EXPECT(st->merged->readers_len == 5); /* * Given that all tables we have written should be roughly the same @@ -925,7 +925,7 @@ static void test_reftable_stack_auto_compaction_with_locked_tables(void) err = reftable_stack_auto_compact(st); EXPECT_ERR(err); EXPECT(st->stats.failures == 0); - EXPECT(st->merged->stack_len == 4); + EXPECT(st->merged->readers_len == 4); reftable_stack_destroy(st); strbuf_release(&buf); @@ -970,9 +970,9 @@ static void test_reftable_stack_add_performs_auto_compaction(void) * all tables in the stack. */ if (i != n) - EXPECT(st->merged->stack_len == i + 1); + EXPECT(st->merged->readers_len == i + 1); else - EXPECT(st->merged->stack_len == 1); + EXPECT(st->merged->readers_len == 1); } reftable_stack_destroy(st); @@ -994,7 +994,7 @@ static void test_reftable_stack_compaction_with_locked_tables(void) EXPECT_ERR(err); write_n_ref_tables(st, 3); - EXPECT(st->merged->stack_len == 3); + EXPECT(st->merged->readers_len == 3); /* Lock one of the tables that we're about to compact. */ strbuf_reset(&buf); @@ -1008,7 +1008,7 @@ static void test_reftable_stack_compaction_with_locked_tables(void) err = reftable_stack_compact_all(st, NULL); EXPECT(err == REFTABLE_LOCK_ERROR); EXPECT(st->stats.failures == 1); - EXPECT(st->merged->stack_len == 3); + EXPECT(st->merged->readers_len == 3); reftable_stack_destroy(st); strbuf_release(&buf); diff --git a/t/unit-tests/t-reftable-merged.c b/t/unit-tests/t-reftable-merged.c index 210603e8c7..577b1a5be8 100644 --- a/t/unit-tests/t-reftable-merged.c +++ b/t/unit-tests/t-reftable-merged.c @@ -94,10 +94,8 @@ merged_table_from_records(struct reftable_ref_record **refs, struct strbuf *buf, const size_t n) { struct reftable_merged_table *mt = NULL; - struct reftable_table *tabs; int err; - REFTABLE_CALLOC_ARRAY(tabs, n); REFTABLE_CALLOC_ARRAY(*readers, n); REFTABLE_CALLOC_ARRAY(*source, n); @@ -108,10 +106,9 @@ merged_table_from_records(struct reftable_ref_record **refs, err = reftable_new_reader(&(*readers)[i], &(*source)[i], "name"); check(!err); - reftable_table_from_reader(&tabs[i], (*readers)[i]); } - err = reftable_merged_table_new(&mt, tabs, n, GIT_SHA1_FORMAT_ID); + err = reftable_merged_table_new(&mt, *readers, n, GIT_SHA1_FORMAT_ID); check(!err); return mt; } @@ -272,10 +269,8 @@ merged_table_from_log_records(struct reftable_log_record **logs, struct strbuf *buf, const size_t n) { struct reftable_merged_table *mt = NULL; - struct reftable_table *tabs; int err; - REFTABLE_CALLOC_ARRAY(tabs, n); REFTABLE_CALLOC_ARRAY(*readers, n); REFTABLE_CALLOC_ARRAY(*source, n); @@ -286,10 +281,9 @@ merged_table_from_log_records(struct reftable_log_record **logs, err = reftable_new_reader(&(*readers)[i], &(*source)[i], "name"); check(!err); - reftable_table_from_reader(&tabs[i], (*readers)[i]); } - err = reftable_merged_table_new(&mt, tabs, n, GIT_SHA1_FORMAT_ID); + err = reftable_merged_table_new(&mt, *readers, n, GIT_SHA1_FORMAT_ID); check(!err); return mt; } @@ -418,7 +412,6 @@ static void t_default_write_opts(void) }; int err; struct reftable_block_source source = { 0 }; - struct reftable_table *tab = reftable_calloc(1, sizeof(*tab)); uint32_t hash_id; struct reftable_reader *rd = NULL; struct reftable_merged_table *merged = NULL; @@ -440,10 +433,9 @@ static void t_default_write_opts(void) hash_id = reftable_reader_hash_id(rd); check_int(hash_id, ==, GIT_SHA1_FORMAT_ID); - reftable_table_from_reader(&tab[0], rd); - err = reftable_merged_table_new(&merged, tab, 1, GIT_SHA256_FORMAT_ID); + err = reftable_merged_table_new(&merged, &rd, 1, GIT_SHA256_FORMAT_ID); check_int(err, ==, REFTABLE_FORMAT_ERROR); - err = reftable_merged_table_new(&merged, tab, 1, GIT_SHA1_FORMAT_ID); + err = reftable_merged_table_new(&merged, &rd, 1, GIT_SHA1_FORMAT_ID); check(!err); reftable_reader_free(rd); From patchwork Tue Aug 13 06:24:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761366 Received: from fout1-smtp.messagingengine.com (fout1-smtp.messagingengine.com [103.168.172.144]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1FC993A8CE for ; Tue, 13 Aug 2024 06:24:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723530268; cv=none; b=Me3xGKpXYzEhaeUYa2X0TxO53F02M/JtijoSaHcmvMUR2+IpZlLMiCS3R6GdtlF867/D0uEcAMrvS1W56yM9UcZed2IpatQsJ97hBCA0G3+lKthPdMPk3+p4EKtRk0v1CQL3FaCpEDkJv7hc1V4Dl7g+6u2Rq/84QhnO0xMvggw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723530268; c=relaxed/simple; bh=/n1ONX+6Rl8Wxi2ERbWSYHCjKw1b17YJJeMkYdzohw8=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=gC9bnwXZAVH6AIBAYUQIdRyqIDzaFeUZ/zqfAJkNSphtODnlseoisF8wV8EuQeqI1Wsy4iXmvbxF6MupkBpmKQR/PQEzG2pZ66fzE7gOdMuebisJpUFoMSgdc0ZQ9v1d5LgUh9gLAbZysvlKdy5rz5D83SK7E5Ufo9xZWmH2uM8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=jFxwLgmT; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=HoPSKusg; arc=none smtp.client-ip=103.168.172.144 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="jFxwLgmT"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="HoPSKusg" Received: from phl-compute-02.internal (phl-compute-02.nyi.internal [10.202.2.42]) by mailfout.nyi.internal (Postfix) with ESMTP id 61029138FD36 for ; Tue, 13 Aug 2024 02:24:26 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Tue, 13 Aug 2024 02:24:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1723530266; x=1723616666; bh=lSyf3bDsCR KY5WWxvlKmO3/3JrFUopcOcNf1JFBjfxs=; b=jFxwLgmTlVNEgkBNzAwCasr3Qm NuxqEKjWLRAXJSUqFMXiNUEkLASd9+1N3IWTBgJsXakfgiSZlLeQolIgj6Yn1Bfi ykSTJ9hICrddLLAWa8lCw6KzHLV9q4Gu8DWHJcAr8w/Moxx6MXJVR6eaPIcWMzDN REVjMeowH5fJ+6A42EDkGi7AdyksDyw5vzgR8DEL6OLRKCkaeGgAif35q5+vboi6 /MMCggZjSlLOxtSbTHpL72EFaatkwWjaR+m0hknbjJBw6QhUzPmEbunZ4PuEWK3p F85nLTm4sFIi2ywuj5sp9Hj23IWZTegC/1kyzk3LPKDlvjIKKeGFa6gbDPAw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1723530266; x=1723616666; bh=lSyf3bDsCRKY5WWxvlKmO3/3JrFU opcOcNf1JFBjfxs=; b=HoPSKusgBvx5cW72PVH3X96Qc/Gmpj3R4bkWJKJuvpQ6 l1zXE9/OzXHz1ZKk9LOr73fXAbqoVr5qEoJSKVPCdum6Na7psvin9wR1dccD2SWC z3T1CbUJ6SOy8xueXNzBQExgmi+oXv0Kj65ZLp+3M6kGvQJ9oVd1ktEKp+F3usxf 89aELosXulbWxpQOm8x6jFkAW48LD80J1UvPtSCFPlM1UkxQLoB2XrGM8/5eYHJC AgMouHhPUdAza/7+jSPwo8/NxYthJ0XCAJTTbN/r5NRhRE1XVJQLflxkJPQfO6KW t2/zLMbhrBlHoOp7YUJDYlHAheg8dIUIUwJdWDR56w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtuddguddtkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhepfffhvf fukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhn hhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrhhnpeehkeeffeegge dvgedvfeefheettddtffejuefflefggfehfeelffeljedvfeehieenucevlhhushhtvghr ufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsg gprhgtphhtthhopedupdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehgihhtsehv ghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 13 Aug 2024 02:24:25 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 0f0c8b85 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 13 Aug 2024 06:24:09 +0000 (UTC) Date: Tue, 13 Aug 2024 08:24:12 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 04/10] reftable/stack: open-code reading refs Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: 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 --- 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, From patchwork Tue Aug 13 06:24:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761367 Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC92D21364 for ; Tue, 13 Aug 2024 06:24:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723530273; cv=none; b=n3NQoVv1l6+wyQhuftb2V0cGtokODkSKrdTZLUXIk4MSOyoBqikAvpMxVjHRj5+WnkVkO4u9Az1MBxnhs8muiVUz3QHZOffCHpZLKPofxaPvQEPZoIGnv2/1LQd+vrDdqKnLqONp2hq3l1abekB7Q/B2YMuLkUyUosIDDCrJvIM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723530273; c=relaxed/simple; bh=r5VuZnNzzCesQA11EYvHShl4fGeZTGgYnXDVZZEcqDg=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=YPc1rKbqSWDKzXB7OUL8M8o7b6q0jH+9O/KNZXOK083AEC91AHMn84nss+5pGMqtd3lRu53XdLblO6ImeyCGM6HiZDheAPejxSDBDZX8aJuWJk83LcFGRExwzm0ZhpOUGB5guO8pRrUdwzyFTiUrOOm12g6PlQPSpUKvU6+5y3s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=AR2R5JY5; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=dkZGGw3R; arc=none smtp.client-ip=103.168.172.155 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="AR2R5JY5"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="dkZGGw3R" Received: from phl-compute-03.internal (phl-compute-03.nyi.internal [10.202.2.43]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 450991151B14 for ; Tue, 13 Aug 2024 02:24:29 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Tue, 13 Aug 2024 02:24:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1723530269; x=1723616669; bh=2gBsMCtfwi nPFzx0Qt+z7LVbBUwnUEyg8ZD/2vGjjMQ=; b=AR2R5JY52ZKOPtE/+0s7jbuk/9 JJERkaPg+SQcM/2XHYfP3q6nfqqs6Uu/DxWl5i0HdhwY4hesJA9tuD0+xO78ksP4 RKQI1H4Q/pn4YSJ+KJzCiSLacF3ZPi8s+JmL5QvL4Rxh/ToAEfpQh9w+i2GcHEgm 6sjMiO7khG5lXrmwSSvkVttAA5ePGZt2MPhNUpoFiCOA6eEPdDXqprge4SRraraE 0czkMNK1WB6yVFxrKYfodZzUZHTurMiTiBZbJciUVpGwjqjnJXxa/7m3wCOoSPsR Lk8jfpXOi9atj/0AXCetygPk2CmpuwA/KqcVpUwTNKfoRp+5P61XhoXXUTaQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1723530269; x=1723616669; bh=2gBsMCtfwinPFzx0Qt+z7LVbBUwn UEyg8ZD/2vGjjMQ=; b=dkZGGw3Rnp0Z8+bEyDJvWSIbViS8JfW1gafJK/VunO8W dhRF/BTOxtbWjUQ9mGlePQvt1jSy8XqBp8RPnRnTP8RVSStUgYG+zCtLfMVSHybd SVif3MXq/F/L3alMT4aojEAJWFBLCmEOKiFb9eX0nVMQGQY892Q2Bzsv5DX+6DnH Zynqdt/RDgyg0F5Jprkpb0BcuI28FVU7QiP2YHm8MMw7ZE2axaWhzX1KmVpdLLVK /QVP4N+WyObfo/OugVwwhiMOplzQ28THUG0gW45rKD05VxXoD7xPCMBa/7X+m37Q aosSU+wPrE6qAfupPe02NOqGbTVpB69L2Z2zzf7ijQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtuddguddtlecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhepfffhvf fukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhn hhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrhhnpeevveeukeeuje ehtdelveeuffffhfduteektdehtdfhtdetgfejtefhveegheekjeenucffohhmrghinhep vhgrlhdvrdhtrghrghgvthenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopedupdhmohguvgep shhmthhpohhuthdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 13 Aug 2024 02:24:28 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 47e029ab (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 13 Aug 2024 06:24:11 +0000 (UTC) Date: Tue, 13 Aug 2024 08:24:26 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 05/10] reftable/iter: drop double-checking logic Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The filtering ref iterator can be used to only yield refs which are not in a specific skip list. This iterator has an option to double-check the results it returns, which causes us to seek tho reference we are about to yield via a separate table such that we detect whether the reference that the first iterator has yielded actually exists. The value of this is somewhat dubious, and I cannot think of any usecase where this functionality should be required. Furthermore, this option is never set in our codebase, which means that it is essentially untested. And last but not least, the `struct reftable_table` that is used to implement it is about to go away. So while we could refactor the code to not use a `reftable_table`, it very much feels like a wasted effort. Let's just drop this code. Signed-off-by: Patrick Steinhardt --- reftable/iter.c | 20 -------------------- reftable/iter.h | 2 -- reftable/reader.c | 2 -- 3 files changed, 24 deletions(-) diff --git a/reftable/iter.c b/reftable/iter.c index fddea31e51..a7484aba60 100644 --- a/reftable/iter.c +++ b/reftable/iter.c @@ -42,26 +42,6 @@ static int filtering_ref_iterator_next(void *iter_arg, break; } - if (fri->double_check) { - struct reftable_iterator it = { NULL }; - - reftable_table_init_ref_iter(&fri->tab, &it); - - err = reftable_iterator_seek_ref(&it, ref->refname); - if (err == 0) - err = reftable_iterator_next_ref(&it, ref); - - reftable_iterator_destroy(&it); - - if (err < 0) { - break; - } - - if (err > 0) { - continue; - } - } - if (ref->value_type == REFTABLE_REF_VAL2 && (!memcmp(fri->oid.buf, ref->value.val2.target_value, fri->oid.len) || diff --git a/reftable/iter.h b/reftable/iter.h index 537431baba..b75d7ac2ac 100644 --- a/reftable/iter.h +++ b/reftable/iter.h @@ -18,8 +18,6 @@ license that can be found in the LICENSE file or at /* iterator that produces only ref records that point to `oid` */ struct filtering_ref_iterator { - int double_check; - struct reftable_table tab; struct strbuf oid; struct reftable_iterator it; }; diff --git a/reftable/reader.c b/reftable/reader.c index f7ae35da72..e3f5854229 100644 --- a/reftable/reader.c +++ b/reftable/reader.c @@ -735,8 +735,6 @@ static int reftable_reader_refs_for_unindexed(struct reftable_reader *r, *filter = empty; strbuf_add(&filter->oid, oid, oid_len); - reftable_table_from_reader(&filter->tab, r); - filter->double_check = 0; iterator_from_table_iter(&filter->it, ti); iterator_from_filtering_ref_iterator(it, filter); From patchwork Tue Aug 13 06:24:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761368 Received: from fout1-smtp.messagingengine.com (fout1-smtp.messagingengine.com [103.168.172.144]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CBB873218B for ; Tue, 13 Aug 2024 06:24:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723530274; cv=none; b=JVJtq225CyiZvP5q2Vqw5p9zSMmVy6xGvFOI1cIKKldjQ92F42MqCEVAdqXOoYWuXwp9Q8xQ4t84V9LTL+XmKwvJNBFHW7z2PLFZQjJ5iJJYC6F/+JLMp+giILTLHnHUCIuina+kMvIzbfXr5/F3xrUXh+lBDWATY/YDqUOfoe4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723530274; c=relaxed/simple; bh=HvovhnfCGEPAzIP0MQ2SlJlew1hTgOdeWRdDGXSyTf4=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=FT+2RkhbuLm1xi23a3LBufY6eGr35Wkbz+g0rPSt2uKiDhdN+21shG32/VJ/LYSfSWiuq5vi2c+AHIZAO5Ve3s/Vla25TAeWR/PteP/c/TtrvoH/gdwE3vKtdgtlTzbBdYhTGjOIEdzr4AW0c5fbmKpMEIOxxpNK150kO4+YA4M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=IxsnoxHT; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=KrgT2rtT; arc=none smtp.client-ip=103.168.172.144 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="IxsnoxHT"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="KrgT2rtT" Received: from phl-compute-05.internal (phl-compute-05.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id 228D9138FCDB for ; Tue, 13 Aug 2024 02:24:32 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Tue, 13 Aug 2024 02:24:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1723530272; x=1723616672; bh=Hd56cJ62eU pl63+Zj/TkVKm/ROVOcmzFH0sX+iuJ5dU=; b=IxsnoxHTTWFCcJDpNf6OPlT640 BoyLpT2GfyhZBkmio1nbpjlhQ1esVGstPudigpIHYNNqINmuyNeXMANo7VVa+euE yWyX0MhER7xPjUXc3spdV0W78Na5KTsCvQMDwRJgG64ZdSEPMzhuDlYz0K/jr7Sz Cakdim/8SqzX7Io7rekaFfMHqUaRBX4aF49kM6h1gNPd1uG+3Ol1d8mTKdT9FhMv u/cWVmLUxXvFj4ylUCV20DZZLvZCp+8ufe9OG4HnMWhMJPWC5LWKVMga3cUKOMH8 mnob1oeKPmwvN7o1tCpbpJGnWNvPZ+NG1OKUyrI2JbIpBBO0XpFWfQa7JtiA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1723530272; x=1723616672; bh=Hd56cJ62eUpl63+Zj/TkVKm/ROVO cmzFH0sX+iuJ5dU=; b=KrgT2rtT0RxqpXTR1uf5ReOlHZaioSzcJCIM/pCHwSPY C8HKEzwI8R7oe6F5Jxl/57f5h0XKmO1rFSnpX00oLxsY/S9sS4HL5frkr3cYEp10 E32Mn91zSl/OdxJ8r+s0vXfcKvmluwHmD7V3QiJxs9FZS7dnZRr9nzFr/I5OJYh+ WNQ13N7ZmEwGNf3mTGWNUqFXucnLFucry2oBcBGIFth440FZkiPGWGQ67+MS+HNz 4R9qQOiDiH2IO3ZU0JbUYGz1G7CW8BmOBEudYTosKZMCv4rAYYMG7YJlc7TrzqsB LGhcg1NNsJDtLEQ6U2cYhnZDx3I/56lD+zS6oCrWRw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtuddguddtlecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhepfffhvf fukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhn hhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrhhnpeehkeeffeegge dvgedvfeefheettddtffejuefflefggfehfeelffeljedvfeehieenucevlhhushhtvghr ufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsg gprhgtphhtthhopedupdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehgihhtsehv ghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 13 Aug 2024 02:24:31 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id e27cc024 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 13 Aug 2024 06:24:14 +0000 (UTC) Date: Tue, 13 Aug 2024 08:24:29 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 06/10] reftable/generic: move generic iterator code into iterator interface Message-ID: <14924604cebe20ac30d291399b0200016fa8b4e3.1723528765.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Move functions relating to the reftable iterator from "generic.c" into "iter.c". This prepares for the removal of the former subsystem. Signed-off-by: Patrick Steinhardt --- reftable/generic.c | 107 +-------------------------------------------- reftable/generic.h | 10 ----- reftable/iter.c | 106 ++++++++++++++++++++++++++++++++++++++++++++ reftable/iter.h | 27 ++++++++++++ 4 files changed, 134 insertions(+), 116 deletions(-) diff --git a/reftable/generic.c b/reftable/generic.c index 28ae26145e..6ecf9b880f 100644 --- a/reftable/generic.c +++ b/reftable/generic.c @@ -9,6 +9,7 @@ license that can be found in the LICENSE file or at #include "constants.h" #include "record.h" #include "generic.h" +#include "iter.h" #include "reftable-iterator.h" #include "reftable-generic.h" @@ -32,37 +33,6 @@ void reftable_table_init_log_iter(struct reftable_table *tab, table_init_iter(tab, it, BLOCK_TYPE_LOG); } -int reftable_iterator_seek_ref(struct reftable_iterator *it, - const char *name) -{ - struct reftable_record want = { - .type = BLOCK_TYPE_REF, - .u.ref = { - .refname = (char *)name, - }, - }; - return it->ops->seek(it->iter_arg, &want); -} - -int reftable_iterator_seek_log_at(struct reftable_iterator *it, - const char *name, uint64_t update_index) -{ - struct reftable_record want = { - .type = BLOCK_TYPE_LOG, - .u.log = { - .refname = (char *)name, - .update_index = update_index, - }, - }; - return it->ops->seek(it->iter_arg, &want); -} - -int reftable_iterator_seek_log(struct reftable_iterator *it, - const char *name) -{ - return reftable_iterator_seek_log_at(it, name, ~((uint64_t) 0)); -} - int reftable_table_read_ref(struct reftable_table *tab, const char *name, struct reftable_ref_record *ref) { @@ -152,78 +122,3 @@ uint32_t reftable_table_hash_id(struct reftable_table *tab) { return tab->ops->hash_id(tab->table_arg); } - -void reftable_iterator_destroy(struct reftable_iterator *it) -{ - if (!it->ops) { - return; - } - it->ops->close(it->iter_arg); - it->ops = NULL; - FREE_AND_NULL(it->iter_arg); -} - -int reftable_iterator_next_ref(struct reftable_iterator *it, - struct reftable_ref_record *ref) -{ - struct reftable_record rec = { - .type = BLOCK_TYPE_REF, - .u = { - .ref = *ref - }, - }; - int err = iterator_next(it, &rec); - *ref = rec.u.ref; - return err; -} - -int reftable_iterator_next_log(struct reftable_iterator *it, - struct reftable_log_record *log) -{ - struct reftable_record rec = { - .type = BLOCK_TYPE_LOG, - .u = { - .log = *log, - }, - }; - int err = iterator_next(it, &rec); - *log = rec.u.log; - return err; -} - -int iterator_seek(struct reftable_iterator *it, struct reftable_record *want) -{ - return it->ops->seek(it->iter_arg, want); -} - -int iterator_next(struct reftable_iterator *it, struct reftable_record *rec) -{ - return it->ops->next(it->iter_arg, rec); -} - -static int empty_iterator_seek(void *arg, struct reftable_record *want) -{ - return 0; -} - -static int empty_iterator_next(void *arg, struct reftable_record *rec) -{ - return 1; -} - -static void empty_iterator_close(void *arg) -{ -} - -static struct reftable_iterator_vtable empty_vtable = { - .seek = &empty_iterator_seek, - .next = &empty_iterator_next, - .close = &empty_iterator_close, -}; - -void iterator_set_empty(struct reftable_iterator *it) -{ - assert(!it->ops); - it->iter_arg = NULL; - it->ops = &empty_vtable; -} diff --git a/reftable/generic.h b/reftable/generic.h index 8341fa570e..837fbb8df2 100644 --- a/reftable/generic.h +++ b/reftable/generic.h @@ -24,14 +24,4 @@ void table_init_iter(struct reftable_table *tab, struct reftable_iterator *it, uint8_t typ); -struct reftable_iterator_vtable { - int (*seek)(void *iter_arg, struct reftable_record *want); - int (*next)(void *iter_arg, struct reftable_record *rec); - void (*close)(void *iter_arg); -}; - -void iterator_set_empty(struct reftable_iterator *it); -int iterator_seek(struct reftable_iterator *it, struct reftable_record *want); -int iterator_next(struct reftable_iterator *it, struct reftable_record *rec); - #endif diff --git a/reftable/iter.c b/reftable/iter.c index a7484aba60..844853fad2 100644 --- a/reftable/iter.c +++ b/reftable/iter.c @@ -16,6 +16,43 @@ license that can be found in the LICENSE file or at #include "reader.h" #include "reftable-error.h" +int iterator_seek(struct reftable_iterator *it, struct reftable_record *want) +{ + return it->ops->seek(it->iter_arg, want); +} + +int iterator_next(struct reftable_iterator *it, struct reftable_record *rec) +{ + return it->ops->next(it->iter_arg, rec); +} + +static int empty_iterator_seek(void *arg, struct reftable_record *want) +{ + return 0; +} + +static int empty_iterator_next(void *arg, struct reftable_record *rec) +{ + return 1; +} + +static void empty_iterator_close(void *arg) +{ +} + +static struct reftable_iterator_vtable empty_vtable = { + .seek = &empty_iterator_seek, + .next = &empty_iterator_next, + .close = &empty_iterator_close, +}; + +void iterator_set_empty(struct reftable_iterator *it) +{ + assert(!it->ops); + it->iter_arg = NULL; + it->ops = &empty_vtable; +} + static void filtering_ref_iterator_close(void *iter_arg) { struct filtering_ref_iterator *fri = iter_arg; @@ -181,3 +218,72 @@ void iterator_from_indexed_table_ref_iter(struct reftable_iterator *it, it->iter_arg = itr; it->ops = &indexed_table_ref_iter_vtable; } + +void reftable_iterator_destroy(struct reftable_iterator *it) +{ + if (!it->ops) { + return; + } + it->ops->close(it->iter_arg); + it->ops = NULL; + FREE_AND_NULL(it->iter_arg); +} + +int reftable_iterator_seek_ref(struct reftable_iterator *it, + const char *name) +{ + struct reftable_record want = { + .type = BLOCK_TYPE_REF, + .u.ref = { + .refname = (char *)name, + }, + }; + return it->ops->seek(it->iter_arg, &want); +} + +int reftable_iterator_next_ref(struct reftable_iterator *it, + struct reftable_ref_record *ref) +{ + struct reftable_record rec = { + .type = BLOCK_TYPE_REF, + .u = { + .ref = *ref + }, + }; + int err = iterator_next(it, &rec); + *ref = rec.u.ref; + return err; +} + +int reftable_iterator_seek_log_at(struct reftable_iterator *it, + const char *name, uint64_t update_index) +{ + struct reftable_record want = { + .type = BLOCK_TYPE_LOG, + .u.log = { + .refname = (char *)name, + .update_index = update_index, + }, + }; + return it->ops->seek(it->iter_arg, &want); +} + +int reftable_iterator_seek_log(struct reftable_iterator *it, + const char *name) +{ + return reftable_iterator_seek_log_at(it, name, ~((uint64_t) 0)); +} + +int reftable_iterator_next_log(struct reftable_iterator *it, + struct reftable_log_record *log) +{ + struct reftable_record rec = { + .type = BLOCK_TYPE_LOG, + .u = { + .log = *log, + }, + }; + int err = iterator_next(it, &rec); + *log = rec.u.log; + return err; +} diff --git a/reftable/iter.h b/reftable/iter.h index b75d7ac2ac..3b401f1259 100644 --- a/reftable/iter.h +++ b/reftable/iter.h @@ -16,6 +16,33 @@ license that can be found in the LICENSE file or at #include "reftable-iterator.h" #include "reftable-generic.h" +/* + * The virtual function table for implementing generic reftable iterators. + */ +struct reftable_iterator_vtable { + int (*seek)(void *iter_arg, struct reftable_record *want); + int (*next)(void *iter_arg, struct reftable_record *rec); + void (*close)(void *iter_arg); +}; + +/* + * Position the iterator at the wanted record such that a call to + * `iterator_next()` would return that record, if it exists. + */ +int iterator_seek(struct reftable_iterator *it, struct reftable_record *want); + +/* + * Yield the next record and advance the iterator. Returns <0 on error, 0 when + * a record was yielded, and >0 when the iterator hit an error. + */ +int iterator_next(struct reftable_iterator *it, struct reftable_record *rec); + +/* + * Set up the iterator such that it behaves the same as an iterator with no + * entries. + */ +void iterator_set_empty(struct reftable_iterator *it); + /* iterator that produces only ref records that point to `oid` */ struct filtering_ref_iterator { struct strbuf oid; From patchwork Tue Aug 13 06:24:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761369 Received: from fout1-smtp.messagingengine.com (fout1-smtp.messagingengine.com [103.168.172.144]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB71340BE3 for ; Tue, 13 Aug 2024 06:24:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723530276; cv=none; b=J8PNqqKEdEztj6RmF/ZVFMRCh7Zs2fFpzvf+6Z1bH1KppenbOyf1tbePN1odP8OVR2ppTD74opsJYNmSOt0vEPrw8maREAdxAacfpVv57JNMIpoUaAT2Uuo5PkOZ+pdt5u4w9GW3J75So2v6ZIJRKRxest5T2NqQEdjmL87utsc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723530276; c=relaxed/simple; bh=td4J694ju0kTvXrZn0I3A9RvLF8kk3emzosqjtZBLTg=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=MSJzYUkKLMLMQv2SJ8RlMg7/CL6HO1RAhMb0j7cKw1DX2Y8WRRHhPU026avw4fwbocaz5Cq6Pqin1gKLcZoD1iOPyq317wv+pk+UCs106zPkTG1HSKk+aPyeF+WlF4lC4jc/RbtT0pMWUYiBkDdtKLZR9VhYda00cHYyHe8w8o8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=JffIIqbW; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=abxSzj5g; arc=none smtp.client-ip=103.168.172.144 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="JffIIqbW"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="abxSzj5g" Received: from phl-compute-02.internal (phl-compute-02.nyi.internal [10.202.2.42]) by mailfout.nyi.internal (Postfix) with ESMTP id 02CFF138FD3F for ; Tue, 13 Aug 2024 02:24:34 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Tue, 13 Aug 2024 02:24:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1723530273; x=1723616673; bh=DLBLTkkIDo UvYnZkEjeswestdvRZvzArAMMR5CVZd2c=; b=JffIIqbWpmh/W3IXQz6NaTkmWe E3e9SZKAACeNDV0AcB/GCdEn9VxAC1LW4yIazjIjGm6VXf5P5C1n0F60pq6AMaRy vp+NYK8L4zp2cTVQiRUja4jtCq8GDhiGoCfasQWNQoXO2FwI1il6gZPt/b+RYMXU RQidF7TPSb4vPJvhFQAi9ToiQIOB9NpPMIfYvqJ1EfYlWOKQLdQ/c3d628Ed58p0 yc+bzKMDw9W6E+vy3Zsb5OGv7A+Zm0Sy/GZEy+vhGaoDxO/LzJD52k1YkLa2HEu8 /eTI5nYfKTdNu99wFBpYpRSRApzaoUf/KVbVW4DB6FaBX84fP0W4da/Bd94g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1723530273; x=1723616673; bh=DLBLTkkIDoUvYnZkEjeswestdvRZ vzArAMMR5CVZd2c=; b=abxSzj5g6bTHBA+Ke1106X7+9itgG2rcvR/xsHa9SG9o uw1ZPioTHP/CxJ9zOaaAq5KiHSwpF0Fisp509zaI2GIbL0sB7SsDVdknRNhTs7Kv FN8/mpI57rBHPXugjysARmaPjAhnPg056FTD3j+nGdR86uO9r88LVSjLaOXiKzGa EvgIujwieVOOs7mBxr07McD3b2VR22CnRI5/VzmpDn7OTEQdxFxkYTM5+/gTb7ws osdcmy9R87OLXg9K7Bi3b85MLAZF+X0wYnxRY9O3ZF2QXdyPRaARUz2qz7nnuaPd +OdwGM9qEzEyPGdtst3daDJK1h1gu0GJXHqMcGpTEg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtuddguddtkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhepfffhvf fukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhn hhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrhhnpeehkeeffeegge dvgedvfeefheettddtffejuefflefggfehfeelffeljedvfeehieenucevlhhushhtvghr ufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsg gprhgtphhtthhopedupdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehgihhtsehv ghgvrhdrkhgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 13 Aug 2024 02:24:33 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id d5c84d47 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 13 Aug 2024 06:24:17 +0000 (UTC) Date: Tue, 13 Aug 2024 08:24:32 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 07/10] reftable/dump: drop unused `compact_stack()` Message-ID: <0aa718606767dc4890fee5af16bb9a0f01a688c1.1723528765.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The `compact_stack()` function is exposed via `reftable_dump_main()`, which ultimately ends up being wired into "test-tool reftable". It is never used by our tests though, and nowadays we have wired up support for stack compaction into git-pack-refs(1). Remove the code. Signed-off-by: Patrick Steinhardt --- reftable/dump.c | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/reftable/dump.c b/reftable/dump.c index dd65d9e8bb..2953e0a83a 100644 --- a/reftable/dump.c +++ b/reftable/dump.c @@ -24,25 +24,6 @@ license that can be found in the LICENSE file or at #include #include -static int compact_stack(const char *stackdir) -{ - struct reftable_stack *stack = NULL; - struct reftable_write_options opts = { 0 }; - - int err = reftable_new_stack(&stack, stackdir, &opts); - if (err < 0) - goto done; - - err = reftable_stack_compact_all(stack, NULL); - if (err < 0) - goto done; -done: - if (stack) { - reftable_stack_destroy(stack); - } - return err; -} - static void print_help(void) { printf("usage: dump [-cst] arg\n\n" @@ -62,7 +43,6 @@ int reftable_dump_main(int argc, char *const *argv) int opt_dump_blocks = 0; int opt_dump_table = 0; int opt_dump_stack = 0; - int opt_compact = 0; uint32_t opt_hash_id = GIT_SHA1_FORMAT_ID; const char *arg = NULL, *argv0 = argv[0]; @@ -77,8 +57,6 @@ int reftable_dump_main(int argc, char *const *argv) opt_hash_id = GIT_SHA256_FORMAT_ID; else if (!strcmp("-s", argv[1])) opt_dump_stack = 1; - else if (!strcmp("-c", argv[1])) - opt_compact = 1; else if (!strcmp("-?", argv[1]) || !strcmp("-h", argv[1])) { print_help(); return 2; @@ -98,8 +76,6 @@ int reftable_dump_main(int argc, char *const *argv) err = reftable_reader_print_file(arg); } else if (opt_dump_stack) { err = reftable_stack_print_directory(arg, opt_hash_id); - } else if (opt_compact) { - err = compact_stack(arg); } if (err < 0) { From patchwork Tue Aug 13 06:24:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761370 Received: from fout1-smtp.messagingengine.com (fout1-smtp.messagingengine.com [103.168.172.144]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B7C403B791 for ; Tue, 13 Aug 2024 06:24:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723530280; cv=none; b=q+608KB3jwHdrX84/MegV7cohrVggebE83MSFBbqT/w1w40l7epnsEflgJzzvoKkYfTxblgYMpUejWxAwlTowXo+cwjM0cxkSC335wQRlfI+PuGYP77h0MxOZN/A3+xLC5oU4EpcUXLwapRX0tftuTf8mwLrq+ZOHQK65S6Cw3Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723530280; c=relaxed/simple; bh=sbm2LABtedkEkw6qh62E/XYlwAsIg3FOTYGO0VDt//E=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=DuiYPHVXWCox8Q/muYvxrM19g37viHnz2frIXLPHurMf8wbR91Sx2b2nBaJRHMMofy+VT4ITmsfAerIT3Ba7Dxnzm2eHespiCg3SQ7+f4vLq13w0jzWgM0J3kd6EtK3Togu7/luko25vZUHZq8bWTmvQq99u7TbZB21fwwvd2eY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=BVMdOHNO; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=B/UA7Unp; arc=none smtp.client-ip=103.168.172.144 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="BVMdOHNO"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="B/UA7Unp" Received: from phl-compute-08.internal (phl-compute-08.nyi.internal [10.202.2.48]) by mailfout.nyi.internal (Postfix) with ESMTP id DAFD7138FD36 for ; Tue, 13 Aug 2024 02:24:37 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-08.internal (MEProxy); Tue, 13 Aug 2024 02:24:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1723530277; x=1723616677; bh=LV16Lv5WoF 3bfbCT8dIHSa4VkKsYmQyknu+3joM6svI=; b=BVMdOHNOYJtvxMnOA0DZs6jRis BSRDeluG7Nxu0Se9c+7TdiQtiUNKZqO4IzmGUSp8LBMFSeBLIQCWGQWHaBZhdu3C U/eUeZJxz+9iTowuvdHRTb5SVZeyx8qGK7NT85aDOUajyd9zv6ufejH2qWC7ma6r YUBl7eEja8SmoHdAVSjEBGvLaDHCP74sxfbCp7VfLjufOs01m6o1hxmLw4zLWOtL EJXe9IgNtwv4TplgaaBGbUTVYl/6nPhGSC1DWkzRF9hZItWbdHjUUmFWocunrJZt grZsRhutPJ18Du9AgzItEwF9bu+qwB3rsQeJsreiWrm/jXikUTM+zGtRe1pQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1723530277; x=1723616677; bh=LV16Lv5WoF3bfbCT8dIHSa4VkKsY mQyknu+3joM6svI=; b=B/UA7UnpFkuS3O5TkBug5m2uYsjhk8KqalXqqzl6Pp9N mUoTwfdJuObl78UiPrALmm2fGu69mJAr7AElvnFuOdly8z2QNG6PIUZcu+kYRXzh RuE0L2MgAJjCkTd6UiBKk5uwrQW29hm1PvnL9hWA5yrJRrxNO6kM1R37vmcVzwvB OXwyBCGV2htp4RxbiYMzbXMDEUkAmUe9WJElt668RjwGjXf9TJUezJ7CaCf2QpUG vnV7TLJydsxlw3R2vDh8tN20WrDBDzIq4oDnMjoKjQjUpuuIULFxH5Wm3uEnPjh6 bH4dxd9PdWnJ/udt2hrPYQITNb4sDRmcylRpClQ1Nw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtuddguddtkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhepfffhvf fukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhn hhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrhhnpeetleegteevte euhfeigfefjeejffdttefhvdevtefghfeuhefgtdfhffefffeugeenucffohhmrghinhep vhgrlhdvrdhtrghrghgvthdpuhhpuggrthgvrdhnrghmvgdpuhhpuggrthgvrdgvmhgrih hlpdhuphgurghtvgdrthiipdhuphgurghtvgdrnhgvfienucevlhhushhtvghrufhiiigv pedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtph htthhopedupdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehgihhtsehvghgvrhdr khgvrhhnvghlrdhorhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 13 Aug 2024 02:24:37 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 4ad9bb61 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 13 Aug 2024 06:24:20 +0000 (UTC) Date: Tue, 13 Aug 2024 08:24:35 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 08/10] reftable/dump: drop unused printing functionality Message-ID: <1f211e514d049379ada609e6a4e8cf985e721271.1723528765.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: We have a bunch of infrastructure wired up that allows us to print reftable records, tables and stacks. While this functionality is wired up via various "test-tool reftable" options, it is never used. It also feels kind of dubious whether any other eventual user of the reftable library should use it as it very much feels like a debugging aid rather than something sensible. The format itself is somewhat inscrutable and the infrastructure is non-extensible. Drop this code. The only remaining function in this context is `reftable_reader_print_blocks()`, which we do use in our tests. Signed-off-by: Patrick Steinhardt --- reftable/dump.c | 16 +---- reftable/generic.c | 47 ------------- reftable/reader.c | 21 ------ reftable/record.c | 127 ------------------------------------ reftable/record.h | 4 -- reftable/reftable-generic.h | 3 - reftable/reftable-reader.h | 2 - reftable/reftable-record.h | 8 --- reftable/reftable-stack.h | 3 - reftable/stack.c | 20 ------ reftable/stack_test.c | 7 -- 11 files changed, 1 insertion(+), 257 deletions(-) diff --git a/reftable/dump.c b/reftable/dump.c index 2953e0a83a..35a1731da9 100644 --- a/reftable/dump.c +++ b/reftable/dump.c @@ -41,9 +41,6 @@ int reftable_dump_main(int argc, char *const *argv) { int err = 0; int opt_dump_blocks = 0; - int opt_dump_table = 0; - int opt_dump_stack = 0; - uint32_t opt_hash_id = GIT_SHA1_FORMAT_ID; const char *arg = NULL, *argv0 = argv[0]; for (; argc > 1; argv++, argc--) @@ -51,12 +48,6 @@ int reftable_dump_main(int argc, char *const *argv) break; else if (!strcmp("-b", argv[1])) opt_dump_blocks = 1; - else if (!strcmp("-t", argv[1])) - opt_dump_table = 1; - else if (!strcmp("-6", argv[1])) - opt_hash_id = GIT_SHA256_FORMAT_ID; - else if (!strcmp("-s", argv[1])) - opt_dump_stack = 1; else if (!strcmp("-?", argv[1]) || !strcmp("-h", argv[1])) { print_help(); return 2; @@ -70,13 +61,8 @@ int reftable_dump_main(int argc, char *const *argv) arg = argv[1]; - if (opt_dump_blocks) { + if (opt_dump_blocks) err = reftable_reader_print_blocks(arg); - } else if (opt_dump_table) { - err = reftable_reader_print_file(arg); - } else if (opt_dump_stack) { - err = reftable_stack_print_directory(arg, opt_hash_id); - } if (err < 0) { fprintf(stderr, "%s: %s: %s\n", argv0, arg, diff --git a/reftable/generic.c b/reftable/generic.c index 6ecf9b880f..495ee9af6b 100644 --- a/reftable/generic.c +++ b/reftable/generic.c @@ -61,53 +61,6 @@ int reftable_table_read_ref(struct reftable_table *tab, const char *name, return err; } -int reftable_table_print(struct reftable_table *tab) { - struct reftable_iterator it = { NULL }; - struct reftable_ref_record ref = { NULL }; - struct reftable_log_record log = { NULL }; - uint32_t hash_id = reftable_table_hash_id(tab); - int err; - - reftable_table_init_ref_iter(tab, &it); - - err = reftable_iterator_seek_ref(&it, ""); - if (err < 0) - return err; - - while (1) { - err = reftable_iterator_next_ref(&it, &ref); - if (err > 0) { - break; - } - if (err < 0) { - return err; - } - reftable_ref_record_print(&ref, hash_id); - } - reftable_iterator_destroy(&it); - reftable_ref_record_release(&ref); - - reftable_table_init_log_iter(tab, &it); - - err = reftable_iterator_seek_log(&it, ""); - if (err < 0) - return err; - - while (1) { - err = reftable_iterator_next_log(&it, &log); - if (err > 0) { - break; - } - if (err < 0) { - return err; - } - reftable_log_record_print(&log, hash_id); - } - reftable_iterator_destroy(&it); - reftable_log_record_release(&log); - return 0; -} - uint64_t reftable_table_max_update_index(struct reftable_table *tab) { return tab->ops->max_update_index(tab->table_arg); diff --git a/reftable/reader.c b/reftable/reader.c index e3f5854229..fbd93b88df 100644 --- a/reftable/reader.c +++ b/reftable/reader.c @@ -798,27 +798,6 @@ void reftable_table_from_reader(struct reftable_table *tab, tab->table_arg = reader; } - -int reftable_reader_print_file(const char *tablename) -{ - struct reftable_block_source src = { NULL }; - int err = reftable_block_source_from_file(&src, tablename); - struct reftable_reader *r = NULL; - struct reftable_table tab = { NULL }; - if (err < 0) - goto done; - - err = reftable_new_reader(&r, &src, tablename); - if (err < 0) - goto done; - - reftable_table_from_reader(&tab, r); - err = reftable_table_print(&tab); -done: - reftable_reader_free(r); - return err; -} - int reftable_reader_print_blocks(const char *tablename) { struct { diff --git a/reftable/record.c b/reftable/record.c index a2cba5ef74..e26bd4bc8d 100644 --- a/reftable/record.c +++ b/reftable/record.c @@ -259,58 +259,6 @@ static void reftable_ref_record_copy_from(void *rec, const void *src_rec, } } -static char hexdigit(int c) -{ - if (c <= 9) - return '0' + c; - return 'a' + (c - 10); -} - -static void hex_format(char *dest, const unsigned char *src, int hash_size) -{ - assert(hash_size > 0); - if (src) { - int i = 0; - for (i = 0; i < hash_size; i++) { - dest[2 * i] = hexdigit(src[i] >> 4); - dest[2 * i + 1] = hexdigit(src[i] & 0xf); - } - dest[2 * hash_size] = 0; - } -} - -static void reftable_ref_record_print_sz(const struct reftable_ref_record *ref, - int hash_size) -{ - char hex[GIT_MAX_HEXSZ + 1] = { 0 }; /* BUG */ - printf("ref{%s(%" PRIu64 ") ", ref->refname, ref->update_index); - switch (ref->value_type) { - case REFTABLE_REF_SYMREF: - printf("=> %s", ref->value.symref); - break; - case REFTABLE_REF_VAL2: - hex_format(hex, ref->value.val2.value, hash_size); - printf("val 2 %s", hex); - hex_format(hex, ref->value.val2.target_value, - hash_size); - printf("(T %s)", hex); - break; - case REFTABLE_REF_VAL1: - hex_format(hex, ref->value.val1, hash_size); - printf("val 1 %s", hex); - break; - case REFTABLE_REF_DELETION: - printf("delete"); - break; - } - printf("}\n"); -} - -void reftable_ref_record_print(const struct reftable_ref_record *ref, - uint32_t hash_id) { - reftable_ref_record_print_sz(ref, hash_size(hash_id)); -} - static void reftable_ref_record_release_void(void *rec) { reftable_ref_record_release(rec); @@ -480,12 +428,6 @@ static int reftable_ref_record_cmp_void(const void *_a, const void *_b) return strcmp(a->refname, b->refname); } -static void reftable_ref_record_print_void(const void *rec, - int hash_size) -{ - reftable_ref_record_print_sz((struct reftable_ref_record *) rec, hash_size); -} - static struct reftable_record_vtable reftable_ref_record_vtable = { .key = &reftable_ref_record_key, .type = BLOCK_TYPE_REF, @@ -497,7 +439,6 @@ static struct reftable_record_vtable reftable_ref_record_vtable = { .is_deletion = &reftable_ref_record_is_deletion_void, .equal = &reftable_ref_record_equal_void, .cmp = &reftable_ref_record_cmp_void, - .print = &reftable_ref_record_print_void, }; static void reftable_obj_record_key(const void *r, struct strbuf *dest) @@ -516,21 +457,6 @@ static void reftable_obj_record_release(void *rec) memset(obj, 0, sizeof(struct reftable_obj_record)); } -static void reftable_obj_record_print(const void *rec, int hash_size) -{ - const struct reftable_obj_record *obj = rec; - char hex[GIT_MAX_HEXSZ + 1] = { 0 }; - struct strbuf offset_str = STRBUF_INIT; - int i; - - for (i = 0; i < obj->offset_len; i++) - strbuf_addf(&offset_str, "%" PRIu64 " ", obj->offsets[i]); - hex_format(hex, obj->hash_prefix, obj->hash_prefix_len); - printf("prefix %s (len %d), offsets [%s]\n", - hex, obj->hash_prefix_len, offset_str.buf); - strbuf_release(&offset_str); -} - static void reftable_obj_record_copy_from(void *rec, const void *src_rec, int hash_size) { @@ -701,41 +627,8 @@ static struct reftable_record_vtable reftable_obj_record_vtable = { .is_deletion = ¬_a_deletion, .equal = &reftable_obj_record_equal_void, .cmp = &reftable_obj_record_cmp_void, - .print = &reftable_obj_record_print, }; -static void reftable_log_record_print_sz(struct reftable_log_record *log, - int hash_size) -{ - char hex[GIT_MAX_HEXSZ + 1] = { 0 }; - - switch (log->value_type) { - case REFTABLE_LOG_DELETION: - printf("log{%s(%" PRIu64 ") delete\n", log->refname, - log->update_index); - break; - case REFTABLE_LOG_UPDATE: - printf("log{%s(%" PRIu64 ") %s <%s> %" PRIu64 " %04d\n", - log->refname, log->update_index, - log->value.update.name ? log->value.update.name : "", - log->value.update.email ? log->value.update.email : "", - log->value.update.time, - log->value.update.tz_offset); - hex_format(hex, log->value.update.old_hash, hash_size); - printf("%s => ", hex); - hex_format(hex, log->value.update.new_hash, hash_size); - printf("%s\n\n%s\n}\n", hex, - log->value.update.message ? log->value.update.message : ""); - break; - } -} - -void reftable_log_record_print(struct reftable_log_record *log, - uint32_t hash_id) -{ - reftable_log_record_print_sz(log, hash_size(hash_id)); -} - static void reftable_log_record_key(const void *r, struct strbuf *dest) { const struct reftable_log_record *rec = @@ -1039,11 +932,6 @@ static int reftable_log_record_is_deletion_void(const void *p) (const struct reftable_log_record *)p); } -static void reftable_log_record_print_void(const void *rec, int hash_size) -{ - reftable_log_record_print_sz((struct reftable_log_record*)rec, hash_size); -} - static struct reftable_record_vtable reftable_log_record_vtable = { .key = &reftable_log_record_key, .type = BLOCK_TYPE_LOG, @@ -1055,7 +943,6 @@ static struct reftable_record_vtable reftable_log_record_vtable = { .is_deletion = &reftable_log_record_is_deletion_void, .equal = &reftable_log_record_equal_void, .cmp = &reftable_log_record_cmp_void, - .print = &reftable_log_record_print_void, }; static void reftable_index_record_key(const void *r, struct strbuf *dest) @@ -1137,13 +1024,6 @@ static int reftable_index_record_cmp(const void *_a, const void *_b) return strbuf_cmp(&a->last_key, &b->last_key); } -static void reftable_index_record_print(const void *rec, int hash_size) -{ - const struct reftable_index_record *idx = rec; - /* TODO: escape null chars? */ - printf("\"%s\" %" PRIu64 "\n", idx->last_key.buf, idx->offset); -} - static struct reftable_record_vtable reftable_index_record_vtable = { .key = &reftable_index_record_key, .type = BLOCK_TYPE_INDEX, @@ -1155,7 +1035,6 @@ static struct reftable_record_vtable reftable_index_record_vtable = { .is_deletion = ¬_a_deletion, .equal = &reftable_index_record_equal, .cmp = &reftable_index_record_cmp, - .print = &reftable_index_record_print, }; void reftable_record_key(struct reftable_record *rec, struct strbuf *dest) @@ -1334,9 +1213,3 @@ void reftable_record_init(struct reftable_record *rec, uint8_t typ) BUG("unhandled record type"); } } - -void reftable_record_print(struct reftable_record *rec, int hash_size) -{ - printf("'%c': ", rec->type); - reftable_record_vtable(rec)->print(reftable_record_data(rec), hash_size); -} diff --git a/reftable/record.h b/reftable/record.h index d778133e6e..5edd46ec75 100644 --- a/reftable/record.h +++ b/reftable/record.h @@ -72,9 +72,6 @@ struct reftable_record_vtable { * the same type. */ int (*cmp)(const void *a, const void *b); - - /* Print on stdout, for debugging. */ - void (*print)(const void *rec, int hash_size); }; /* returns true for recognized block types. Block start with the block type. */ @@ -136,7 +133,6 @@ void reftable_record_init(struct reftable_record *rec, uint8_t typ); /* see struct record_vtable */ int reftable_record_cmp(struct reftable_record *a, struct reftable_record *b); int reftable_record_equal(struct reftable_record *a, struct reftable_record *b, int hash_size); -void reftable_record_print(struct reftable_record *rec, int hash_size); void reftable_record_key(struct reftable_record *rec, struct strbuf *dest); void reftable_record_copy_from(struct reftable_record *rec, struct reftable_record *src, int hash_size); diff --git a/reftable/reftable-generic.h b/reftable/reftable-generic.h index 65670ea093..b8b1323a33 100644 --- a/reftable/reftable-generic.h +++ b/reftable/reftable-generic.h @@ -41,7 +41,4 @@ uint64_t reftable_table_min_update_index(struct reftable_table *tab); int reftable_table_read_ref(struct reftable_table *tab, const char *name, struct reftable_ref_record *ref); -/* dump table contents onto stdout for debugging */ -int reftable_table_print(struct reftable_table *tab); - #endif diff --git a/reftable/reftable-reader.h b/reftable/reftable-reader.h index a32f31d648..7c7d171651 100644 --- a/reftable/reftable-reader.h +++ b/reftable/reftable-reader.h @@ -64,8 +64,6 @@ uint64_t reftable_reader_min_update_index(struct reftable_reader *r); void reftable_table_from_reader(struct reftable_table *tab, struct reftable_reader *reader); -/* print table onto stdout for debugging. */ -int reftable_reader_print_file(const char *tablename); /* print blocks onto stdout for debugging. */ int reftable_reader_print_blocks(const char *tablename); diff --git a/reftable/reftable-record.h b/reftable/reftable-record.h index ff486eb1f7..2d42463c58 100644 --- a/reftable/reftable-record.h +++ b/reftable/reftable-record.h @@ -60,10 +60,6 @@ const unsigned char *reftable_ref_record_val2(const struct reftable_ref_record * /* returns whether 'ref' represents a deletion */ int reftable_ref_record_is_deletion(const struct reftable_ref_record *ref); -/* prints a reftable_ref_record onto stdout. Useful for debugging. */ -void reftable_ref_record_print(const struct reftable_ref_record *ref, - uint32_t hash_id); - /* frees and nulls all pointer values inside `ref`. */ void reftable_ref_record_release(struct reftable_ref_record *ref); @@ -111,8 +107,4 @@ void reftable_log_record_release(struct reftable_log_record *log); int reftable_log_record_equal(const struct reftable_log_record *a, const struct reftable_log_record *b, int hash_size); -/* dumps a reftable_log_record on stdout, for debugging/testing. */ -void reftable_log_record_print(struct reftable_log_record *log, - uint32_t hash_id); - #endif diff --git a/reftable/reftable-stack.h b/reftable/reftable-stack.h index 09e97c9991..f4f8cabc7f 100644 --- a/reftable/reftable-stack.h +++ b/reftable/reftable-stack.h @@ -140,7 +140,4 @@ struct reftable_compaction_stats { struct reftable_compaction_stats * reftable_stack_compaction_stats(struct reftable_stack *st); -/* print the entire stack represented by the directory */ -int reftable_stack_print_directory(const char *stackdir, uint32_t hash_id); - #endif diff --git a/reftable/stack.c b/reftable/stack.c index d08ec00959..bedd503e7e 100644 --- a/reftable/stack.c +++ b/reftable/stack.c @@ -1603,23 +1603,3 @@ int reftable_stack_clean(struct reftable_stack *st) reftable_addition_destroy(add); return err; } - -int reftable_stack_print_directory(const char *stackdir, uint32_t hash_id) -{ - struct reftable_stack *stack = NULL; - struct reftable_write_options opts = { .hash_id = hash_id }; - struct reftable_merged_table *merged = NULL; - struct reftable_table table = { NULL }; - - int err = reftable_new_stack(&stack, stackdir, &opts); - if (err < 0) - goto done; - - merged = reftable_stack_merged_table(stack); - reftable_table_from_merged_table(&table, merged); - err = reftable_table_print(&table); -done: - if (stack) - reftable_stack_destroy(stack); - return err; -} diff --git a/reftable/stack_test.c b/reftable/stack_test.c index dbca9eaf4a..42044ed8a3 100644 --- a/reftable/stack_test.c +++ b/reftable/stack_test.c @@ -179,13 +179,6 @@ static void test_reftable_stack_add_one(void) EXPECT(0 == strcmp("master", dest.value.symref)); EXPECT(st->readers_len > 0); - printf("testing print functionality:\n"); - err = reftable_stack_print_directory(dir, GIT_SHA1_FORMAT_ID); - EXPECT_ERR(err); - - err = reftable_stack_print_directory(dir, GIT_SHA256_FORMAT_ID); - EXPECT(err == REFTABLE_FORMAT_ERROR); - #ifndef GIT_WINDOWS_NATIVE strbuf_addstr(&scratch, dir); strbuf_addstr(&scratch, "/tables.list"); From patchwork Tue Aug 13 06:24:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761371 Received: from fout1-smtp.messagingengine.com (fout1-smtp.messagingengine.com [103.168.172.144]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A93D63AC0D for ; Tue, 13 Aug 2024 06:24:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723530282; cv=none; b=dgqYKxTwWRxnePSXuqMZivGm3ziGsHO5x8g0KahNqL2DvtQbmrlm1pPJJs/UZyKXhIJGhozJH5d6Tkm7NfybzszqNNpOvDFHlWua11ecBgkouKczFgHsxjpRmujXVOkFo1ly3E4j7w589Lwo+IwqIwUAhku5RoJXr3fZLabl6r0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723530282; c=relaxed/simple; bh=jkARksfYu/IXmrW/sTl+U6GM67f7miMGrL1AhOoL7y8=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=RZITGAIld3+fun3oQHK/gBqyBaxaPFJa3R7nediUKzvXpyQuq8OHasTZnLaBakjl/wCAuHzaC6vLveFIHo7yvbP5FApc3DM+r7C02B4zAP7EkjOdmqEpti+4+NnzFTiQGhoNwbtnUv7JCyFernuf1WgVskDuuAsAv3llIXNaWPw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=g1gKTJ9Z; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ONhR16L8; arc=none smtp.client-ip=103.168.172.144 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="g1gKTJ9Z"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ONhR16L8" Received: from phl-compute-03.internal (phl-compute-03.nyi.internal [10.202.2.43]) by mailfout.nyi.internal (Postfix) with ESMTP id B3E8C138FD3B for ; Tue, 13 Aug 2024 02:24:39 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Tue, 13 Aug 2024 02:24:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1723530279; x=1723616679; bh=61OkuW5hQO oufv6pqEyV3z+wZObJ4PUfFQD5irt4KuA=; b=g1gKTJ9ZdelRB2wOeHxrKBwVWE 3KB9vOioZKndt+2toUdOIL1qAWwk0O8kwiHXq6TZAezc3XwGcpK1aYMxIEcF/LsI a1MmUaklepl/1GcFZC+hMGrJZ3A0367pmZny2R0WuAyLUmInb77/kOBb3F/VzZtD 5dtAp5wM45X6jVAcFTaIhYR4RcMkSvxo1YfB1NwCS0HFoDlXTUQ1zOcCKyrgHHYL oOP+4JErMdn+fPF1ty/YRhMJ1eiXUfY7Ub4bE5uSwExU8B6Wyx7/7mHxxnLsggH0 s/+cXzful+I9Fe8WYx6zPz5ea1uWRMZkByOeaC4oyZ7MNU9aUlMia9UPGKJw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1723530279; x=1723616679; bh=61OkuW5hQOoufv6pqEyV3z+wZObJ 4PUfFQD5irt4KuA=; b=ONhR16L8vCvsSCHE/9uZpYRUHrg26v4oP1HVBAqYcOoi M7DQm9t0oXV1CtO+wWIMNWuTXaYTh8LpVvmmW75/NJNWkEYBrXv/O9cMIR9yyR/z /bLUm9M9wXf1gxr36Ceoin5j1KKnACwdxCqEMbEltxX9HTwvgPt62moDhyBElGYt dV4jj53eo5EJ/H1oLD6t97sFIVaCPObU4u014NdHuI7SA0CsUAGXK6A9HF9r2VWh uiFqjgFEjZ1CHFIBkSI/dz+X/MZITJc732OmRq978b1L5FppcBkpXxRcaW1iKThr lBfQ6h/NKlpl5YMbrOgZcyovg7Q6hIH7w3ZBpxtFqg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtuddguddtlecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhepfffhvf fukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhn hhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrhhnpeekieekhfefge etfefgfeehheekveelgffgtdevleeihfeijeeffeehudehkedvteenucffohhmrghinhep ghhoohhglhgvrdgtohhmnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepuddpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 13 Aug 2024 02:24:39 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 668d41f3 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 13 Aug 2024 06:24:23 +0000 (UTC) Date: Tue, 13 Aug 2024 08:24:37 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 09/10] reftable/dump: move code into "t/helper/test-reftable.c" Message-ID: <4184f46f92c16654ebc2523028a203eb2e1e4f7a.1723528765.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The code in "reftable/dump.c" is only ever used by our test-tool to implement the "reftable" subcommand. It also feels very unlikely that it will ever be useful to any other potential user of the reftable library, which makes it a weird candidate to have in the library interface. Inline the code into "t/helper/test-reftable.c". Signed-off-by: Patrick Steinhardt --- Makefile | 1 - reftable/dump.c | 73 ---------------------------------------- t/helper/test-reftable.c | 47 +++++++++++++++++++++++++- 3 files changed, 46 insertions(+), 75 deletions(-) delete mode 100644 reftable/dump.c diff --git a/Makefile b/Makefile index 3863e60b66..343f19a488 100644 --- a/Makefile +++ b/Makefile @@ -2680,7 +2680,6 @@ REFTABLE_OBJS += reftable/tree.o REFTABLE_OBJS += reftable/writer.o REFTABLE_TEST_OBJS += reftable/block_test.o -REFTABLE_TEST_OBJS += reftable/dump.o REFTABLE_TEST_OBJS += reftable/pq_test.o REFTABLE_TEST_OBJS += reftable/readwrite_test.o REFTABLE_TEST_OBJS += reftable/stack_test.o diff --git a/reftable/dump.c b/reftable/dump.c deleted file mode 100644 index 35a1731da9..0000000000 --- a/reftable/dump.c +++ /dev/null @@ -1,73 +0,0 @@ -/* -Copyright 2020 Google LLC - -Use of this source code is governed by a BSD-style -license that can be found in the LICENSE file or at -https://developers.google.com/open-source/licenses/bsd -*/ - -#include "git-compat-util.h" -#include "hash.h" - -#include "reftable-blocksource.h" -#include "reftable-error.h" -#include "reftable-record.h" -#include "reftable-tests.h" -#include "reftable-writer.h" -#include "reftable-iterator.h" -#include "reftable-reader.h" -#include "reftable-stack.h" - -#include -#include -#include -#include -#include - -static void print_help(void) -{ - printf("usage: dump [-cst] arg\n\n" - "options: \n" - " -c compact\n" - " -b dump blocks\n" - " -t dump table\n" - " -s dump stack\n" - " -6 sha256 hash format\n" - " -h this help\n" - "\n"); -} - -int reftable_dump_main(int argc, char *const *argv) -{ - int err = 0; - int opt_dump_blocks = 0; - const char *arg = NULL, *argv0 = argv[0]; - - for (; argc > 1; argv++, argc--) - if (*argv[1] != '-') - break; - else if (!strcmp("-b", argv[1])) - opt_dump_blocks = 1; - else if (!strcmp("-?", argv[1]) || !strcmp("-h", argv[1])) { - print_help(); - return 2; - } - - if (argc != 2) { - fprintf(stderr, "need argument\n"); - print_help(); - return 2; - } - - arg = argv[1]; - - if (opt_dump_blocks) - err = reftable_reader_print_blocks(arg); - - if (err < 0) { - fprintf(stderr, "%s: %s: %s\n", argv0, arg, - reftable_error_str(err)); - return 1; - } - return 0; -} diff --git a/t/helper/test-reftable.c b/t/helper/test-reftable.c index 9d378427da..cf93d30910 100644 --- a/t/helper/test-reftable.c +++ b/t/helper/test-reftable.c @@ -1,4 +1,6 @@ #include "reftable/system.h" +#include "reftable/reftable-error.h" +#include "reftable/reftable-reader.h" #include "reftable/reftable-tests.h" #include "test-tool.h" @@ -13,7 +15,50 @@ int cmd__reftable(int argc, const char **argv) return 0; } +static void print_help(void) +{ + printf("usage: dump [-cst] arg\n\n" + "options: \n" + " -c compact\n" + " -b dump blocks\n" + " -t dump table\n" + " -s dump stack\n" + " -6 sha256 hash format\n" + " -h this help\n" + "\n"); +} + int cmd__dump_reftable(int argc, const char **argv) { - return reftable_dump_main(argc, (char *const *)argv); + int err = 0; + int opt_dump_blocks = 0; + const char *arg = NULL, *argv0 = argv[0]; + + for (; argc > 1; argv++, argc--) + if (*argv[1] != '-') + break; + else if (!strcmp("-b", argv[1])) + opt_dump_blocks = 1; + else if (!strcmp("-?", argv[1]) || !strcmp("-h", argv[1])) { + print_help(); + return 2; + } + + if (argc != 2) { + fprintf(stderr, "need argument\n"); + print_help(); + return 2; + } + + arg = argv[1]; + + if (opt_dump_blocks) + err = reftable_reader_print_blocks(arg); + + if (err < 0) { + fprintf(stderr, "%s: %s: %s\n", argv0, arg, + reftable_error_str(err)); + return 1; + } + return 0; } From patchwork Tue Aug 13 06:24:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13761372 Received: from fout1-smtp.messagingengine.com (fout1-smtp.messagingengine.com [103.168.172.144]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D48E3A28B for ; Tue, 13 Aug 2024 06:24:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723530290; cv=none; b=RiNRgdqvmqZSV4KewFhyinZ4kFN+wQWe/v42D4poY1LYrRXHK1yHTvcBd/BSzZkAmmlHg4lFdwCszyIu+f/005f0myNWcFH7E057gpCqvMizDn081dCHzxD+C048U+5iYChep+NGLHCU9HMDzPU22qcYh8nRdUUU+PQmCBN827M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723530290; c=relaxed/simple; bh=Vn9wleb72ed7VV7sxY0UMODh/WarwA4HmPehjUor2QE=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=RCMqX/LXuZUOfFXD2di2Nl3UOgzxxAJLJU0Dm/aA6r2VM7S7nuU7LptNuc/ppTdka7qgyHfXZxn1VLbFol76oFCJ/l0BDRLvg71Afi59vZMXhHexbKfJWFBtwpOh/jmhBvkKRyMv6i+Yyw4k5btxjqNd3IM+u8KpMxqftKK3CJs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=gbSSGHeZ; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Vmsxyhbj; arc=none smtp.client-ip=103.168.172.144 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="gbSSGHeZ"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Vmsxyhbj" Received: from phl-compute-05.internal (phl-compute-05.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id 8BA44138FD36 for ; Tue, 13 Aug 2024 02:24:47 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Tue, 13 Aug 2024 02:24:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1723530287; x=1723616687; bh=IasAY38QGz tRIP7BltkufyxcloA3sR/po7ZkxtTffVc=; b=gbSSGHeZ0CooLXbpYv2RQZ2mGZ Cmm2iD3u9xSJVbxZT/ZhZ74ILnH6zHXTSJgwzGvHt6vFYnqRfZw1m40A9b79LWs7 yprjstmw14gGW2UntIw66Ib2IUPRMSTZHbFnGn4hH9c3pH5rZLnNXX6RwIz2VLXD dxkw3RalQbrR2uJFsiG+DUkZBrftWljboNBp8GuB5e7fIMOZzzC/hHcMpbYGRFBz raDOIQVKzrtQuv/zRVPn/MNNgruwDpwc7AIFPTcwrTL4+C/AWhVzFQ+PRSTic3cg i6T5PJLBBhQ/7apLAkO/ZtVSus9LuF1c9HECAzXXapVHCjqF6D4mvcXhUsug== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1723530287; x=1723616687; bh=IasAY38QGztRIP7BltkufyxcloA3 sR/po7ZkxtTffVc=; b=VmsxyhbjtMETgQiGWDu9IDqMqsjwjRcTiHk0hv8JfOAJ murBWhN+Ne/RqdQwhkwmUUBkfXyL1ZmsSvZR/YW0Owen4CeCoXrHkx2WLgIvYiw7 KoDDRpZH2vZQarJwHq/y3eQnj3CZVEaPRxfqns/3LY2SYA26oWVTH86DlI0QwJIw T9gp9poUpEbRCp51I3OFWlnoWW1/JHhJe3Ngv1qhhVUZPmBwT+fNe9+m/tc9h6in EAwD8AOMISUCYl5/34qc5ZhCukZF+Y1gWFIXg0sjiS++RH1czCeNRKJ1C60jbNOx //jvDNtiA3HO4Eto9RH8wiW49uBs31l2CyLF5ieoHw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddtuddguddtlecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecunecujfgurhepfffhvf fukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhn hhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrhhnpeekieekhfefge etfefgfeehheekveelgffgtdevleeihfeijeeffeehudehkedvteenucffohhmrghinhep ghhoohhglhgvrdgtohhmnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphhssehpkhhsrdhimhdpnhgspghrtghpthhtohepuddpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 13 Aug 2024 02:24:46 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 53e3087b (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Tue, 13 Aug 2024 06:24:30 +0000 (UTC) Date: Tue, 13 Aug 2024 08:24:41 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 10/10] reftable/generic: drop interface Message-ID: <723495adf624cbc483b9c5d9fa4b5b6078e46168.1723528765.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The `reftable_table` interface provides a generic infrastructure that can abstract away whether the underlying table is a single table, or a merged table. This abstraction can make it rather hard to reason about the code. We didn't ever use it to implement the reftable backend, and with the preceding patches in this patch series we in fact don't use it at all anymore. Furthermore, it became somewhat useless with the recent refactorings that made it possible to seek reftable iterators multiple times, as these now provide generic access to tables for us. The interface is thus redundant and only brings unnecessary complexity with it. Remove the `struct reftable_table` interface and its associated functions. Signed-off-by: Patrick Steinhardt --- Makefile | 1 - reftable/generic.c | 77 -------------------------------- reftable/generic.h | 27 ----------- reftable/iter.c | 1 - reftable/iter.h | 1 - reftable/merged.c | 38 ---------------- reftable/reader.c | 41 ----------------- reftable/reftable-generic.h | 44 ------------------ reftable/reftable-merged.h | 6 --- reftable/reftable-reader.h | 7 --- reftable/stack.c | 1 - t/unit-tests/t-reftable-merged.c | 1 - 12 files changed, 245 deletions(-) delete mode 100644 reftable/generic.c delete mode 100644 reftable/generic.h delete mode 100644 reftable/reftable-generic.h diff --git a/Makefile b/Makefile index 343f19a488..41dfa0bad2 100644 --- a/Makefile +++ b/Makefile @@ -2674,7 +2674,6 @@ REFTABLE_OBJS += reftable/merged.o REFTABLE_OBJS += reftable/pq.o REFTABLE_OBJS += reftable/reader.o REFTABLE_OBJS += reftable/record.o -REFTABLE_OBJS += reftable/generic.o REFTABLE_OBJS += reftable/stack.o REFTABLE_OBJS += reftable/tree.o REFTABLE_OBJS += reftable/writer.o diff --git a/reftable/generic.c b/reftable/generic.c deleted file mode 100644 index 495ee9af6b..0000000000 --- a/reftable/generic.c +++ /dev/null @@ -1,77 +0,0 @@ -/* -Copyright 2020 Google LLC - -Use of this source code is governed by a BSD-style -license that can be found in the LICENSE file or at -https://developers.google.com/open-source/licenses/bsd -*/ - -#include "constants.h" -#include "record.h" -#include "generic.h" -#include "iter.h" -#include "reftable-iterator.h" -#include "reftable-generic.h" - -void table_init_iter(struct reftable_table *tab, - struct reftable_iterator *it, - uint8_t typ) -{ - - tab->ops->init_iter(tab->table_arg, it, typ); -} - -void reftable_table_init_ref_iter(struct reftable_table *tab, - struct reftable_iterator *it) -{ - table_init_iter(tab, it, BLOCK_TYPE_REF); -} - -void reftable_table_init_log_iter(struct reftable_table *tab, - struct reftable_iterator *it) -{ - table_init_iter(tab, it, BLOCK_TYPE_LOG); -} - -int reftable_table_read_ref(struct reftable_table *tab, const char *name, - struct reftable_ref_record *ref) -{ - struct reftable_iterator it = { NULL }; - int err; - - reftable_table_init_ref_iter(tab, &it); - - err = reftable_iterator_seek_ref(&it, name); - if (err) - goto done; - - err = reftable_iterator_next_ref(&it, ref); - if (err) - goto done; - - if (strcmp(ref->refname, name) || - reftable_ref_record_is_deletion(ref)) { - reftable_ref_record_release(ref); - err = 1; - goto done; - } - -done: - reftable_iterator_destroy(&it); - return err; -} - -uint64_t reftable_table_max_update_index(struct reftable_table *tab) -{ - return tab->ops->max_update_index(tab->table_arg); -} - -uint64_t reftable_table_min_update_index(struct reftable_table *tab) -{ - return tab->ops->min_update_index(tab->table_arg); -} - -uint32_t reftable_table_hash_id(struct reftable_table *tab) -{ - return tab->ops->hash_id(tab->table_arg); -} diff --git a/reftable/generic.h b/reftable/generic.h deleted file mode 100644 index 837fbb8df2..0000000000 --- a/reftable/generic.h +++ /dev/null @@ -1,27 +0,0 @@ -/* -Copyright 2020 Google LLC - -Use of this source code is governed by a BSD-style -license that can be found in the LICENSE file or at -https://developers.google.com/open-source/licenses/bsd -*/ - -#ifndef GENERIC_H -#define GENERIC_H - -#include "record.h" -#include "reftable-generic.h" - -/* generic interface to reftables */ -struct reftable_table_vtable { - void (*init_iter)(void *tab, struct reftable_iterator *it, uint8_t typ); - uint32_t (*hash_id)(void *tab); - uint64_t (*min_update_index)(void *tab); - uint64_t (*max_update_index)(void *tab); -}; - -void table_init_iter(struct reftable_table *tab, - struct reftable_iterator *it, - uint8_t typ); - -#endif diff --git a/reftable/iter.c b/reftable/iter.c index 844853fad2..4eb7fafd2f 100644 --- a/reftable/iter.c +++ b/reftable/iter.c @@ -11,7 +11,6 @@ license that can be found in the LICENSE file or at #include "system.h" #include "block.h" -#include "generic.h" #include "constants.h" #include "reader.h" #include "reftable-error.h" diff --git a/reftable/iter.h b/reftable/iter.h index 3b401f1259..befc4597df 100644 --- a/reftable/iter.h +++ b/reftable/iter.h @@ -14,7 +14,6 @@ license that can be found in the LICENSE file or at #include "record.h" #include "reftable-iterator.h" -#include "reftable-generic.h" /* * The virtual function table for implementing generic reftable iterators. diff --git a/reftable/merged.c b/reftable/merged.c index 2e72eab306..128a810c55 100644 --- a/reftable/merged.c +++ b/reftable/merged.c @@ -13,7 +13,6 @@ license that can be found in the LICENSE file or at #include "pq.h" #include "reader.h" #include "record.h" -#include "generic.h" #include "reftable-merged.h" #include "reftable-error.h" #include "system.h" @@ -270,40 +269,3 @@ uint32_t reftable_merged_table_hash_id(struct reftable_merged_table *mt) { return mt->hash_id; } - -static void reftable_merged_table_init_iter_void(void *tab, - struct reftable_iterator *it, - uint8_t typ) -{ - merged_table_init_iter(tab, it, typ); -} - -static uint32_t reftable_merged_table_hash_id_void(void *tab) -{ - return reftable_merged_table_hash_id(tab); -} - -static uint64_t reftable_merged_table_min_update_index_void(void *tab) -{ - return reftable_merged_table_min_update_index(tab); -} - -static uint64_t reftable_merged_table_max_update_index_void(void *tab) -{ - return reftable_merged_table_max_update_index(tab); -} - -static struct reftable_table_vtable merged_table_vtable = { - .init_iter = reftable_merged_table_init_iter_void, - .hash_id = reftable_merged_table_hash_id_void, - .min_update_index = reftable_merged_table_min_update_index_void, - .max_update_index = reftable_merged_table_max_update_index_void, -}; - -void reftable_table_from_merged_table(struct reftable_table *tab, - struct reftable_merged_table *merged) -{ - assert(!tab->ops); - tab->ops = &merged_table_vtable; - tab->table_arg = merged; -} diff --git a/reftable/reader.c b/reftable/reader.c index fbd93b88df..082cf00b60 100644 --- a/reftable/reader.c +++ b/reftable/reader.c @@ -11,11 +11,9 @@ license that can be found in the LICENSE file or at #include "system.h" #include "block.h" #include "constants.h" -#include "generic.h" #include "iter.h" #include "record.h" #include "reftable-error.h" -#include "reftable-generic.h" uint64_t block_source_size(struct reftable_block_source *source) { @@ -759,45 +757,6 @@ uint64_t reftable_reader_min_update_index(struct reftable_reader *r) return r->min_update_index; } -/* generic table interface. */ - -static void reftable_reader_init_iter_void(void *tab, - struct reftable_iterator *it, - uint8_t typ) -{ - reader_init_iter(tab, it, typ); -} - -static uint32_t reftable_reader_hash_id_void(void *tab) -{ - return reftable_reader_hash_id(tab); -} - -static uint64_t reftable_reader_min_update_index_void(void *tab) -{ - return reftable_reader_min_update_index(tab); -} - -static uint64_t reftable_reader_max_update_index_void(void *tab) -{ - return reftable_reader_max_update_index(tab); -} - -static struct reftable_table_vtable reader_vtable = { - .init_iter = reftable_reader_init_iter_void, - .hash_id = reftable_reader_hash_id_void, - .min_update_index = reftable_reader_min_update_index_void, - .max_update_index = reftable_reader_max_update_index_void, -}; - -void reftable_table_from_reader(struct reftable_table *tab, - struct reftable_reader *reader) -{ - assert(!tab->ops); - tab->ops = &reader_vtable; - tab->table_arg = reader; -} - int reftable_reader_print_blocks(const char *tablename) { struct { diff --git a/reftable/reftable-generic.h b/reftable/reftable-generic.h deleted file mode 100644 index b8b1323a33..0000000000 --- a/reftable/reftable-generic.h +++ /dev/null @@ -1,44 +0,0 @@ -/* -Copyright 2020 Google LLC - -Use of this source code is governed by a BSD-style -license that can be found in the LICENSE file or at -https://developers.google.com/open-source/licenses/bsd -*/ - -#ifndef REFTABLE_GENERIC_H -#define REFTABLE_GENERIC_H - -#include "reftable-iterator.h" - -struct reftable_table_vtable; - -/* - * Provides a unified API for reading tables, either merged tables, or single - * readers. */ -struct reftable_table { - struct reftable_table_vtable *ops; - void *table_arg; -}; - -void reftable_table_init_ref_iter(struct reftable_table *tab, - struct reftable_iterator *it); - -void reftable_table_init_log_iter(struct reftable_table *tab, - struct reftable_iterator *it); - -/* returns the hash ID from a generic reftable_table */ -uint32_t reftable_table_hash_id(struct reftable_table *tab); - -/* returns the max update_index covered by this table. */ -uint64_t reftable_table_max_update_index(struct reftable_table *tab); - -/* returns the min update_index covered by this table. */ -uint64_t reftable_table_min_update_index(struct reftable_table *tab); - -/* convenience function to read a single ref. Returns < 0 for error, 0 - for success, and 1 if ref not found. */ -int reftable_table_read_ref(struct reftable_table *tab, const char *name, - struct reftable_ref_record *ref); - -#endif diff --git a/reftable/reftable-merged.h b/reftable/reftable-merged.h index 03c2619c0f..16d19f8df2 100644 --- a/reftable/reftable-merged.h +++ b/reftable/reftable-merged.h @@ -26,8 +26,6 @@ license that can be found in the LICENSE file or at /* A merged table is implements seeking/iterating over a stack of tables. */ struct reftable_merged_table; -/* A generic reftable; see below. */ -struct reftable_table; struct reftable_reader; /* @@ -60,8 +58,4 @@ void reftable_merged_table_free(struct reftable_merged_table *m); /* return the hash ID of the merged table. */ uint32_t reftable_merged_table_hash_id(struct reftable_merged_table *m); -/* create a generic table from reftable_merged_table */ -void reftable_table_from_merged_table(struct reftable_table *tab, - struct reftable_merged_table *table); - #endif diff --git a/reftable/reftable-reader.h b/reftable/reftable-reader.h index 7c7d171651..69621c5b0f 100644 --- a/reftable/reftable-reader.h +++ b/reftable/reftable-reader.h @@ -23,9 +23,6 @@ /* The reader struct is a handle to an open reftable file. */ struct reftable_reader; -/* Generic table. */ -struct reftable_table; - /* reftable_new_reader opens a reftable for reading. If successful, * returns 0 code and sets pp. The name is used for creating a * stack. Typically, it is the basename of the file. The block source @@ -60,10 +57,6 @@ uint64_t reftable_reader_max_update_index(struct reftable_reader *r); /* return the min_update_index for a table */ uint64_t reftable_reader_min_update_index(struct reftable_reader *r); -/* creates a generic table from a file reader. */ -void reftable_table_from_reader(struct reftable_table *tab, - struct reftable_reader *reader); - /* print blocks onto stdout for debugging. */ int reftable_reader_print_blocks(const char *tablename); diff --git a/reftable/stack.c b/reftable/stack.c index bedd503e7e..d3a95d2f1d 100644 --- a/reftable/stack.c +++ b/reftable/stack.c @@ -14,7 +14,6 @@ license that can be found in the LICENSE file or at #include "merged.h" #include "reader.h" #include "reftable-error.h" -#include "reftable-generic.h" #include "reftable-record.h" #include "reftable-merged.h" #include "writer.h" diff --git a/t/unit-tests/t-reftable-merged.c b/t/unit-tests/t-reftable-merged.c index 577b1a5be8..93345c6c8b 100644 --- a/t/unit-tests/t-reftable-merged.c +++ b/t/unit-tests/t-reftable-merged.c @@ -12,7 +12,6 @@ license that can be found in the LICENSE file or at #include "reftable/merged.h" #include "reftable/reader.h" #include "reftable/reftable-error.h" -#include "reftable/reftable-generic.h" #include "reftable/reftable-merged.h" #include "reftable/reftable-writer.h"