From patchwork Thu Aug 22 06:34:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13772705 Received: from fout6-smtp.messagingengine.com (fout6-smtp.messagingengine.com [103.168.172.149]) (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 D4B633F9F9 for ; Thu, 22 Aug 2024 06:34:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724308484; cv=none; b=q5+Z/4grWCaFFw8IGDGxRG4cO4zB4ku7MtxedT0XWaWzOBg4wrdV7WUIIUHsg2/jRrt4h5KxiOhSwM6VP0977S15gnM57zqe0PyZYRzHKlcwP6s8jSKUQlRzrzRGzvHHE1CIYN0Us18pSsPtotLWOxhgu8wB/Six78VhyBcbyNQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724308484; c=relaxed/simple; bh=9AMmEU6dn6hK4aEZwweXr6TDxZaIUUXGWOsHyZBTwq0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=akw8ci5T43anl1ueATRHej8bsE5RR8fy4KPq8vYcboQklEPJcSQodSh7fKV/pqg8NXo7qmC/NKNbZZOX+F0WCsxXADjGLDgX9R/ehWuL3mc3m8w7D6wTKPnBHYUs8c8tJ1gOxSifE9raO38jSNLwVUqxgLu/Aiz9a6HCyq93vNs= 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=YaIHD3Ob; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=sw++VSmy; arc=none smtp.client-ip=103.168.172.149 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="YaIHD3Ob"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="sw++VSmy" Received: from phl-compute-01.internal (phl-compute-01.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id EEB83138FF1D; Thu, 22 Aug 2024 02:34:41 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Thu, 22 Aug 2024 02:34:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=fm1; t=1724308481; x=1724394881; bh=PWVhlmu27/ zqKL6sLqTigT4B710qyT6FlT5NXxYYrhM=; b=YaIHD3ObzwJtqNxktA5VZOLGIQ BXwJKP7UyjRUpCP+HRfKMhxEOKO7DcmJk7RP/YwOsb3Qt2KGBsLvvbOz1wx0oytR G3acnYQjiiiZeUDSzB3VRWtSRZdjCKtKPqKDqfQWbKKvRZPrYNmfG6IKeU9RpgMM rmjA0mBTb3sPxI0mAMbdm9vJBdAY/8C+FXXHQCMA69/xzrjt76hs8op4Bejx8adK d1wjBml83bx1SqGqhvimXMeLyTMKyatAy4I4VlkHHYaSSKRI1usz4AlnNAMLVMyZ gEJ0SbIcGaKSDN6/KIZUU3upwBoPZvIKVZqiDqEyHj4Orq6ktYuZB8qvgYaQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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= fm1; t=1724308481; x=1724394881; bh=PWVhlmu27/zqKL6sLqTigT4B710q yT6FlT5NXxYYrhM=; b=sw++VSmy51j3rYAQ3NoSE9C2kakCTCT5VMar0iex0fKD xrmv1P1N1ekTJXEK9C6Ap5Vx8Ou+q2/cIVqCAESDT3vGvm9diJVl/8+gYUc08ui8 dGrZpD0JlbTIiSAl0aMsj89hRrlx4dGwwmnOgsGc6jGpg+26S3DoocsusmShbZTc rTw68TRqkO2dTkx/CrP9HQdWm3MY7Wg0Pu7/1K8mi1YRhQPHVr9ZBU3ES71Jg2db pJk8qZeFgKmsRNP90KIjHBjxpc07Ko/hkk/ILotJ/nMOvJQT2UK0GRDbTACQGH/q KuZh/AYdl0Sc3cRwh2P8tTfrjPTuqpwFqtZN5oyIvQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudduledguddutdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehttdertddttddv necuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrih hmqeenucggtffrrghtthgvrhhnpeevkeekfffhiedtleduiefgjedttedvledvudehgfeu gedugffhueekhfejvdektdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopeefpdhmohguvgep shhmthhpohhuthdprhgtphhtthhopehjlhhtohgslhgvrhesghhmrghilhdrtghomhdprh gtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepkhgr rhhthhhikhdrudekkeesghhmrghilhdrtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 22 Aug 2024 02:34:40 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id e767441b (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 22 Aug 2024 06:34:06 +0000 (UTC) Date: Thu, 22 Aug 2024 08:34:38 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: karthik nayak , Justin Tobler Subject: [PATCH v3 01/15] reftable/merged: expose functions to initialize iterators Message-ID: <472c169b501d060a90607c6ca9552eee807cb286.1724308389.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 6adce44f4b6..8d78b3da719 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 14d5fc9f05c..4deb0ad22e1 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 Thu Aug 22 06:34: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: 13772706 Received: from fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.152]) (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 183DE13AD09 for ; Thu, 22 Aug 2024 06:34:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724308486; cv=none; b=B+09UN8k+1WLyn6UkRoqKi5GDprJmu0BRXuond27eOXaLj5NfzpZkb59OV21RH/aO9J4yUA+v8YI7aTr/FJsNJJLQMDPdP6kSym34chlYf+qt5QE740fJ4YSgdyZ2uDJ8urRi+nSA8GbL3h70IfYadD7xxataXMSApaCU5cGBH4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724308486; c=relaxed/simple; bh=k8K5egnsrHCHtiTVqRX2DyBDZZDvrdp66KZWFbxUzxo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=oH0LxlnD2Jmw4ZlB0M/+KD2MBPkfe6ICyfQ8eiOs3NInviPMf8MmzzJEiLHCwsnw5OgXmur3xQQ0ke8AijpwvbDKw0qKAG+Xa302m4JdVMCM7MgkE5FrBa0fu4cxWFpucZrkqn/Gsbx4tesAZmDAVuh3Gvfg5JAnfbJ+lIHD9D8= 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=f76wijhx; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=nwrvwK79; arc=none smtp.client-ip=103.168.172.152 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="f76wijhx"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="nwrvwK79" Received: from phl-compute-02.internal (phl-compute-02.nyi.internal [10.202.2.42]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 246321151AF6; Thu, 22 Aug 2024 02:34:44 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Thu, 22 Aug 2024 02:34:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=fm1; t=1724308484; x=1724394884; bh=La6XQSuAU7 J2ndW6r0VbWV/h8+/xIZa76tPG36Md55I=; b=f76wijhx/lwSsumZJnKgojEz7T fJAR4M32Tc/jA4MjasdOvIAEfqgWo8WlY5SZJTg/CieT/tK64h/gQR6UxREXTzLn b9JKkWf+86HBSKuqFmmyScfNDnUnoFaDaZYhcrXH2u6zzXd9Yn/jFfQ/SnWGi7L8 c1/XfvdGiV4hn1f1Os0E+eaVOdp/VJqk9tBbs9G+8A+sVk9USe/6lCXaUv3pdBk4 /TJWs1+cwp3w+iGUihO6di7ifx2U5FjLq2TuK8y7X8wgqoq+Kwe/TbvS81OcBD67 2LEWg3HM7Bdk8NJEJ2T0VSIUXGSiImVVq1PrLdStjma+d2COQjtFPdbnM/HQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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= fm1; t=1724308484; x=1724394884; bh=La6XQSuAU7J2ndW6r0VbWV/h8+/x IZa76tPG36Md55I=; b=nwrvwK79xM8ThFEBB5X2IVqwgOUCHk490gflfbHcDgSq Id0IcnScn5rtn2148nIEWsa515+t3ECD2eStOtSumVGZGSa/jZCsoKkr39UWuCKt RKCGvJPY+UUPRLbUujX3q1XLxgcFPxXjBakeYVFY1D1B/73aDIxMaLrIhfa1YZS7 +PFlGvpo9t28C7ebP0PFtqzw0bQe241swbkdnWpH0igeQL9ZgcZkm78qlvNw2F08 6Nuc2/MtuMWkrJ0sGHRJ103v0XgI7AOgpF0rDxxAFIIPd99Ig9aT/aTGQ5CjnmyY wSls+LIKEYpLEnbHJuv7UJljcc/C0f5p/lxK+lWpuw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudduledguddutdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehttdertddttddv necuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrih hmqeenucggtffrrghtthgvrhhnpeevkeekfffhiedtleduiefgjedttedvledvudehgfeu gedugffhueekhfejvdektdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopeefpdhmohguvgep shhmthhpohhuthdprhgtphhtthhopehkrghrthhhihhkrddukeeksehgmhgrihhlrdgtoh hmpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtghpthhtohep ghhithesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 22 Aug 2024 02:34:43 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id acbff932 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 22 Aug 2024 06:34:09 +0000 (UTC) Date: Thu, 22 Aug 2024 08:34:41 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: karthik nayak , Justin Tobler Subject: [PATCH v3 02/15] reftable/merged: rename `reftable_new_merged_table()` 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: 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 8d78b3da719..25d414ec415 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 4deb0ad22e1..72762483b9e 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 2071e428a80..64c7fdf8c49 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 b6263ee8b5a..210603e8c78 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 Thu Aug 22 06:34:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13772707 Received: from fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.152]) (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 309E613CFBC for ; Thu, 22 Aug 2024 06:34:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724308490; cv=none; b=EIQ2NMMlVoonHnea4FBlXKKt7G9YPZN3JnZ0h3hPBiALVuNosjqr7AHHkVQOMax34oFZOXy857vu70a8cUaAaq3Bmt8xAkZxzQ6pkTwsCnwOtjHGC4nFi3OazeviK211ALsuWMc7O2ScqQ9bsOQpGhSnJkKgYTj5qygSV13Q23g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724308490; c=relaxed/simple; bh=rKLdSlTk64q+klhkKrT69naaSGahPFo21ohKVCTYoh4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=IZ/4gg9LcJIXouuwTU+vzh8olbN1X8bSvq2fEP1FmtHam8zCM6mJUO6BJKpMsW4HnnMp56/T1aoTE0MYHIoXw1CGgsiM4n7WSiqTmN23t7+0fxPv5AUlHv3XdFJtyrSIn06linWcUK8ooB2iS0HNJo9AgSJ8pgD1+vjD1+3U/Lc= 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=pIzWb3Hv; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=c86/u8CP; arc=none smtp.client-ip=103.168.172.152 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="pIzWb3Hv"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="c86/u8CP" Received: from phl-compute-04.internal (phl-compute-04.nyi.internal [10.202.2.44]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 61AF61151AFF; Thu, 22 Aug 2024 02:34:47 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-04.internal (MEProxy); Thu, 22 Aug 2024 02:34:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=fm1; t=1724308487; x=1724394887; bh=Xl4Tsdf2tq hSzxJIf+Cbd7ceXKouc7iNT2aXQhiaSEM=; b=pIzWb3HvYbK+SsdBVW3K90p2Qy ltrAEjrVF9dDW526BngH8jsf19Uhj3tJcQpD9xOndKOK/9B9cYW1tj0vDdBDwWQX ZfK8Yvfez4bZSXPEiYVYvsDWbYcnpTD+uRBeSwwx/YDsiH9uFfCPd8isWm/yvz25 r3HzpRck8ytfvVnJe4e4G8DAk5PZy1xqgNVMHo/ih4ldw8rjdDgyBmop145vwt/D s0farfl6pTJ8sQtBOlzx9DuGh9QVv0vubT9wleZVgEBNG/iB18x9f0JOwBuVS+Jj 6sepO5yZwetYXjdzITSz+TTnGSm0ciF37ncDJ4It7faVKSMJ4Vy+8RmtGWww== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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= fm1; t=1724308487; x=1724394887; bh=Xl4Tsdf2tqhSzxJIf+Cbd7ceXKou c7iNT2aXQhiaSEM=; b=c86/u8CPo6uRpU/XaFfKOZ+0FimowL1PrKqG/sNEhjDT nGWXilIr+duJ0vMPjs809ICquIPVbv/536JEC/AQNgD7jPwgYg6X2I+pMLfFd6hU BwFTPywNeOWSdFBb1g0YxTjon5CQ+afKDwEOThm2BjAI1qjtfPbnsgcL7qWmJi+Q 6KptXzBWHgHrxLQ2a4eMV1+IJaT/Gx15eddg9H84uOxu1DBEZ0OAUWS4MNG5P7r2 DNcfO1CUVXk23jWWF7gpQtGs7knhO2g5Hxp+tDVTeueShl2E/z/bE+4qc5p5Cskm tOUwHUqv3M/uxh7xSS2ORdeBO+X2GLuZ1fbXmd7LkQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudduledguddutdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehttdertddttddv necuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrih hmqeenucggtffrrghtthgvrhhnpeevkeekfffhiedtleduiefgjedttedvledvudehgfeu gedugffhueekhfejvdektdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopeefpdhmohguvgep shhmthhpohhuthdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpd hrtghpthhtohepkhgrrhhthhhikhdrudekkeesghhmrghilhdrtghomhdprhgtphhtthho pehjlhhtohgslhgvrhesghhmrghilhdrtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 22 Aug 2024 02:34:46 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 28fd460f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 22 Aug 2024 06:34:11 +0000 (UTC) Date: Thu, 22 Aug 2024 08:34:44 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: karthik nayak , Justin Tobler Subject: [PATCH v3 03/15] reftable/merged: stop using generic tables in the merged table Message-ID: <58e91ab4b3415bb1fade8183964fcedd39eb6e4b.1724308389.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 25d414ec415..2e72eab3069 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 2efe571da67..de5fd33f010 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 29c99e22694..f7ae35da728 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 e869165f234..a2c204d523c 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 72762483b9e..03c2619c0ff 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 64c7fdf8c49..7f4e267ea98 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 8c36590ff0f..dbca9eaf4a8 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 210603e8c78..577b1a5be87 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 Thu Aug 22 06:34:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13772708 Received: from fout6-smtp.messagingengine.com (fout6-smtp.messagingengine.com [103.168.172.149]) (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 826441D12EA for ; Thu, 22 Aug 2024 06:34:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724308496; cv=none; b=TNsSBzdP8JpZbQtLIqMaM9CElIaC2x4ayENez6TJ9BA9e826GuwlWLMUcHGajVMn7Hu2B07szFfXWpUEoiJV+3cHEC1txbWFbvssHAHdaueJ0XtipcYCr/xAnz9dCXzGhkzfW0eGCwKe0Kwv1mch2ISHgafeiRVTon3fQidEfkI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724308496; c=relaxed/simple; bh=UxRpOy6Mq6ysAvZR8f2w2uh+lQi7AnOO7nOuCfzK+y0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=aTv63zZsD/q3jv8Yp7VHLI2PXre7kBZH0UnB9aKB81KbNlWzeWzVt9y7J4cQTXLWIU7+6NBczu22u+PM8Ysb9yeo78GupgmZrEOtS/ZLKXW1CgO+ag0Z6+BOA7o4hG20XNdx7iTlnO6gPzCynzARHevRPseSp4i8kc5UCUWn720= 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=NXLhcICA; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=tMswq3Tm; arc=none smtp.client-ip=103.168.172.149 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="NXLhcICA"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="tMswq3Tm" Received: from phl-compute-04.internal (phl-compute-04.nyi.internal [10.202.2.44]) by mailfout.nyi.internal (Postfix) with ESMTP id 8BA19138EFB6; Thu, 22 Aug 2024 02:34:53 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-04.internal (MEProxy); Thu, 22 Aug 2024 02:34:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=fm1; t=1724308493; x=1724394893; bh=ur3hq+hIxF NYpjL2vYA9Vxe4vvq7J2BF6v13qi6lO/E=; b=NXLhcICANmGH59V8E1MuvdVtRK uezjCRYDLf7iaTKCR+NFJKUKIXFpcS7nV22SMl9ocP6uV1JXr8uxLrz9Hvm99IgD KxNm3BJfb4jDMOKWCvwkRT23lrcaAjDoWqpuBaAwznHQSaa+/EE6PNZk9lH6e8qK utABeDHUrCwA2TdZj7/Kv+hTbr0rY4aJy+CIeFTPPKlq7ZSTe2ThQY6MVX8mgmvj 0QaQX/kSZR5Q8x2apKHO4gjSCztvSVFFSCdvSK+d83zyJ6oyc2mIYajbc9HQcSbS Tk5IzYsTR8Ke2bZsXNcIgegJ170juF8pAgieWR19t116hAJjoYJ/pg/rbG0Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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= fm1; t=1724308493; x=1724394893; bh=ur3hq+hIxFNYpjL2vYA9Vxe4vvq7 J2BF6v13qi6lO/E=; b=tMswq3TmeNdYVEyUx0jDVqel3YUCD5kExAFhLBFj+PxY T6S9LeYS5Wd6Wqmmfrry78a8Dss1G4JMnfOW66cby7/A3TLGCjPds36usztJjnY8 F7hqKe5sbmfWLASvTvWf4DVLkU1ff9aCuBbY8HB+Tv1TXlNIGAdReWyjVCffll5V ZTZwAlgyLOcxOxOwfQiHYmD/jPo6PHMqDjJM0BgP0Wc9WlFTKgOd2BqnbD7q0mma yKIWID8mYOe1IVDnw8n3wgJsKQeLge5QN2zFSnEWexTHAtmy2Wt/YA97L/oeXF1a m5+Vk/zubYv3UkHQgzW0F7SgulQuHdiOXEdxtZYkfw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudduledguddutdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehttdertddttddv necuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrih hmqeenucggtffrrghtthgvrhhnpeevkeekfffhiedtleduiefgjedttedvledvudehgfeu gedugffhueekhfejvdektdenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmh grihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopeefpdhmohguvgep shhmthhpohhuthdprhgtphhtthhopehkrghrthhhihhkrddukeeksehgmhgrihhlrdgtoh hmpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtghpthhtohep ghhithesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 22 Aug 2024 02:34:52 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 54ac6c20 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 22 Aug 2024 06:34:18 +0000 (UTC) Date: Thu, 22 Aug 2024 08:34:48 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: karthik nayak , Justin Tobler Subject: [PATCH v3 04/15] reftable/stack: open-code reading refs Message-ID: <6ba3fcee4115fbf4e46a6a2a31f0b3c01b0903dd.1724308389.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: 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 7f4e267ea98..d08ec009590 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 Thu Aug 22 06:34:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13772709 Received: from fout6-smtp.messagingengine.com (fout6-smtp.messagingengine.com [103.168.172.149]) (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 A174613CFBC for ; Thu, 22 Aug 2024 06:34:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724308499; cv=none; b=mShDsZwxC2R7uWT5TKJSs9ar6hcGIFx/wztZiPABAd9CE5MJO39qwskfYq8b63/yAzF/fuUsT5Lelokn3kzvXrhuxWf6BmKEJt6hD2hZqPdhDsUESAUYFaxbGg/2DfyjDUBuO0MWakkeshw79rJyS2YPO8yzNp+GDNjWjZZ+bOk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724308499; c=relaxed/simple; bh=2lJM8vuWbhHQKA72BI+rCmnPTU/nKSQGL406KbOeul8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qMa/9M2Y+3wVPvgmHnF9i6Vw5EQVyrtzD7iRbisrWWp8rJ5LjZaN4Hy3iIGnSn+bXIQuRvZ8gjc5R1wY6+vWPoCQgYvm0wivk9NFUYUXBjFVX6P2A3nM9sx/w2yxToo+xtqv+iueVEqQWz3b5e4Q57AnWNvVl+YE+OaBDQ4nAgs= 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=YtUyUBXd; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Z5TKdYo1; arc=none smtp.client-ip=103.168.172.149 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="YtUyUBXd"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Z5TKdYo1" Received: from phl-compute-04.internal (phl-compute-04.nyi.internal [10.202.2.44]) by mailfout.nyi.internal (Postfix) with ESMTP id CAD59138EFB6; Thu, 22 Aug 2024 02:34:56 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-04.internal (MEProxy); Thu, 22 Aug 2024 02:34:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=fm1; t=1724308496; x=1724394896; bh=tC4C+l13sw Ggk+vR8ccpCoHTmJphLgzXXq5+iMfABr8=; b=YtUyUBXdwMsTSvgCjoisZE/T8w 2hq3W9/P2YF/z9nHkhUNSNQiZ/an0nAMoULSZDMpaSpFsEMDY/YnC8EXshUFfBHQ n1K9FbojfG5+m0px3LTrYrK0JUNjtZUKcwEiTqXmdcVQT9fx+fSehWYJ1z5O6478 wOi8VX7Hlm+WgbSHv1JZlRuj56Pmoao2FXyIRyNqG6r3UPmn2rNaPNem4314DtfU ojy9Cr3nzuhCoqBmM8Qf3jY088tswy1EKfYg4FqGhQYVh7tA4OIilhClpfI19qZQ W7ZcWQ4KQlcpCt00/Boziq0kl9W6JTIYsSoRK3YOw7LwKI9XLwVOe74v0eig== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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= fm1; t=1724308496; x=1724394896; bh=tC4C+l13swGgk+vR8ccpCoHTmJph LgzXXq5+iMfABr8=; b=Z5TKdYo1YFatjpgr9gqyCugqo34bhzDBh1cjUrTx74+q +7rD9mIoctIHQxXLGraEsMcZyqeabt/ylBBkna8SAeLHKY6o3sMukzHlcvwF8xW1 yXMTDHMZoT0T6Vs6rNLMDTUobecnOq43jtX5QL2buVKUgLfEuu+gNW76LIGT9Q/c 6cqJitriaoMPfMTDagGwX2cKU2/i2fyZ76rBOriiC70acXFpxJuHd4x/N0eu8Cqz uEXe7zclZEvZ3N9aYLwJlrs+mhrVAY6vjnePB8twtYUB+zg/0IqdqEczqph1p58+ a7uUED6HJ03GWXFB/f4BI6o7ga7cxZSIEFhvZmp4kA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudduledguddutdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehttdertddttddv necuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrih hmqeenucggtffrrghtthgvrhhnpeffleeghfeufeetueetvdffkeeggffgteevjedvvdek iefgvdeiueduvdekveekteenucffohhmrghinhepvhgrlhdvrdhtrghrghgvthenucevlh hushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdr ihhmpdhnsggprhgtphhtthhopeefpdhmohguvgepshhmthhpohhuthdprhgtphhtthhope hjlhhtohgslhgvrhesghhmrghilhdrtghomhdprhgtphhtthhopehgihhtsehvghgvrhdr khgvrhhnvghlrdhorhhgpdhrtghpthhtohepkhgrrhhthhhikhdrudekkeesghhmrghilh drtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 22 Aug 2024 02:34:55 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id bd1a8bb2 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 22 Aug 2024 06:34:21 +0000 (UTC) Date: Thu, 22 Aug 2024 08:34:54 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: karthik nayak , Justin Tobler Subject: [PATCH v3 05/15] 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 the 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 fddea31e517..a7484aba60d 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 537431baba0..b75d7ac2ac0 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 f7ae35da728..e3f58542297 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 Thu Aug 22 06:34:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13772710 Received: from fout6-smtp.messagingengine.com (fout6-smtp.messagingengine.com [103.168.172.149]) (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 E9E0F14A4CC for ; Thu, 22 Aug 2024 06:35:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724308502; cv=none; b=CI0EMUkYltlCs2VbIFEoyyJ96RHOi+8ZPV7gSuXdgudHrDiL8zr79eqTB9wz88HA+F/ddYJIIW0Xqvf/sYtYs4GTitzOn8Tiwh0aw5ZDTT0z0seGAeEBjyi9hpyW8EeYD6CKd4Ylfd+Zb1b6cxG+idUW8cmj8YSjC7geNcxYqc0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724308502; c=relaxed/simple; bh=kNis1eq4lla1BL/F/4PHkaIFD4umzOpCq9Rr08cp8NY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=iKnuwnAGOLBkvYL66q/EovlA50ZXboINqGJDjYcloZil90sy9f9N0oVoJ4Zq1iiKn2tsQ4QvIe33hmjxcVuKO5SsDhOr8NBgDyGzXUM8bSmZ9ZU2+dKTi5zb26RWS+cBdDSMfdRRnff6Z7ZOoMajaM2Vc/s/k125oEF1AGwfypM= 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=GT2iUV6r; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Pscb/fCk; arc=none smtp.client-ip=103.168.172.149 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="GT2iUV6r"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Pscb/fCk" Received: from phl-compute-04.internal (phl-compute-04.nyi.internal [10.202.2.44]) by mailfout.nyi.internal (Postfix) with ESMTP id 08A9E138FFC3; Thu, 22 Aug 2024 02:35:00 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-04.internal (MEProxy); Thu, 22 Aug 2024 02:35:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=fm1; t=1724308500; x=1724394900; bh=uZrnfNthAt 0jsomMgF5TCKHZ2DQlZyVc9uGsjk32CJA=; b=GT2iUV6ryYndxzHNtBKuvLWy8F pAhdoEUSDm7JDeuaXx0t+c+snEozsb46gUZzf31tlHelGk2n3mh6EL6hanh+b59t 2pW2eZ6fmpHDNmGe9S96XkuE8UNQG9EGd7enNdbCfLIwOSKOrcRK+exq8cXg2MWH kHWTf5aGtNmTFEg0a86POEDGV9wMaqtizacVeLiZTEnIfN6crICIqRQFs9CaEdq2 ZOzqL30HYl6j5d2cg8N1R1BeGKNXfSCowkLiYE6zZaCOgIIih1kM/PNmfNB0TapT /ad/MBC8WgRMNEAVwl0ZCC5kZ/jp8lp5g61uMqy32YePX2+UmC/myMu49HVQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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= fm1; t=1724308500; x=1724394900; bh=uZrnfNthAt0jsomMgF5TCKHZ2DQl ZyVc9uGsjk32CJA=; b=Pscb/fCkg7C6eMoq5vQ3ODK/+h52Zt6d/fRjdPzBsTqt KohO6HN8f5tKNKNoXlWAnnNPXx06+TbiYOWmMP+yCW+LHuBVsLb7Q4NDJHFiUYtB gKQpukHYH5X/ZAqjl0MGkoDatEeVZh3pVv9CklKnIZRWE3GBkDrv++GHG2utuF4F gT4BrL3jQiV86lYC3ZOyMZU57gesmUL3TqwcePXowKAdAEfpAa9OydZUIDC446yl 0en2CrFWeQ3uxyGPhp78MUclJNXDI2cPUrbirGCny5NhXn2jNWcjmzSA8BmYF3jh lHJyh4FS0L28Rd3QkZXwQPWZKkGctetopP84+60aWw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudduledguddutdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehttdertddttddv necuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrih hmqeenucggtffrrghtthgvrhhnpeevkeekfffhiedtleduiefgjedttedvledvudehgfeu gedugffhueekhfejvdektdenucevlhhushhtvghrufhiiigvpedvnecurfgrrhgrmhepmh grihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopeefpdhmohguvgep shhmthhpohhuthdprhgtphhtthhopehkrghrthhhihhkrddukeeksehgmhgrihhlrdgtoh hmpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthho pehjlhhtohgslhgvrhesghhmrghilhdrtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 22 Aug 2024 02:34:58 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 4fb5befe (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 22 Aug 2024 06:34:24 +0000 (UTC) Date: Thu, 22 Aug 2024 08:34:57 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: karthik nayak , Justin Tobler Subject: [PATCH v3 06/15] reftable/generic: move generic iterator code into iterator interface Message-ID: <103262dc79c300c861c677437e036ca904bfc7ef.1724308389.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. While at it, remove some unneeded braces to conform to our coding style. Signed-off-by: Patrick Steinhardt --- reftable/generic.c | 107 +-------------------------------------------- reftable/generic.h | 10 ----- reftable/iter.c | 105 ++++++++++++++++++++++++++++++++++++++++++++ reftable/iter.h | 27 ++++++++++++ 4 files changed, 133 insertions(+), 116 deletions(-) diff --git a/reftable/generic.c b/reftable/generic.c index 28ae26145e6..6ecf9b880f7 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 8341fa570e0..837fbb8df20 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 a7484aba60d..225feb78714 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,71 @@ 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 b75d7ac2ac0..3b401f12590 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 Thu Aug 22 06:35:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13772711 Received: from fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.152]) (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 79D3914A4E0 for ; Thu, 22 Aug 2024 06:35:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724308505; cv=none; b=Hd2hzMllx/KufyPel1aIavF+J+XrqAz+J8R597VrfLoXMgV6LV9T+PpjL2Y8oFeblAzP2jTfyt8bWsY1vLJTrRLam0bZgILyVXoZJdeMkYhfsqX5Kf3pZnjT6EtyZBVla3xBdFfaKgPCYMsYAdi/zmRL3vTLAKVp4gvoAxs3rNw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724308505; c=relaxed/simple; bh=cY7jiUdNccPCVsQZl9kOP2J2lRJmGGadu2bnjXE+xHE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qfwNdtbkyu2y0Ozv7/tPmYA8t9rPBVi0WIttVlXLkpJCA9i4W5BphHasvL0TuyIFopE6xpKfjeugQIwJcylkqPkqdGfOFGan5nS5RKFA+9FTkEFAVd9K44/N1VdcQ37/tv63iVENLqVBQG7E1xE9RRCXMlqWvFDFN1PQh8uBiOM= 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=U51b34jf; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Z61eW2vs; arc=none smtp.client-ip=103.168.172.152 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="U51b34jf"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Z61eW2vs" Received: from phl-compute-02.internal (phl-compute-02.nyi.internal [10.202.2.42]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 3D7F71151AF6; Thu, 22 Aug 2024 02:35:02 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Thu, 22 Aug 2024 02:35:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=fm1; t=1724308502; x=1724394902; bh=KMmhErjqdL gavUUkjCPNFfDarxV40ugUdlGRjmvO+qc=; b=U51b34jfbVbe30O7LdwJZlVUaE O5Tk5P0MhejVXSrpLt9kX7yV3MdKhl09+Zj9chTHHvSf5zFWkFs29fGqUm6VaHUg t6DX00yKgJUhZv3hHFvQ5H7DBxjb8PpVrJXGeDRr81Q98bemnckuFfkm66qJ6tNz dDb+MXWL8VAQJJXNoa4j+JFwMDOj3QXW+C+ST5AlPNgWLbK4BO7TPZaWCPoWpZ/0 hhmGxfNr2DGWRa+yUSsCWX4Bdcd2cnCzkIu1farw6P5z/wKkin9A1xl/mxxtJFEv jc/A2Jzw1nkQl88YRrcmm97m2/eejzheARf5bg3g0Yo2vAI2upjU/q5ZtWCA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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= fm1; t=1724308502; x=1724394902; bh=KMmhErjqdLgavUUkjCPNFfDarxV4 0ugUdlGRjmvO+qc=; b=Z61eW2vsokZbrctN1C8n20sEQMc0/aWId5M6QmH8A1gr oVy1XrpzwuM7ZKqtjKgq8St/cnbYtM11ovNMFwUbGy8P/xTA7bEi/CLlb8BIu40n NQWbMWaM2eTK6uZEUWzVRFtHYlrQfb05q/uZrgsUD09uGTYdWH8uDTy6BJ55DZ7v 5o1B1MxvrKVglDfiIB7dd0Xr6aA6IcFyBIRBmMxuB45uGnBmY4EA/0HoIBXT3Fyy jSSmlbrzYFQvoGp9oVisKGv+wDnpxCKkpmHvmto11EwtLfAv/uxCqumOqwnxXBXw mbuQ09LQhqCNqBNByttreAgcwmtXoK4mhmVPTXGfmw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudduledguddutdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehttdertddttddv necuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrih hmqeenucggtffrrghtthgvrhhnpeevkeekfffhiedtleduiefgjedttedvledvudehgfeu gedugffhueekhfejvdektdenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmh grihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopeefpdhmohguvgep shhmthhpohhuthdprhgtphhtthhopehkrghrthhhihhkrddukeeksehgmhgrihhlrdgtoh hmpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtghpthhtohep ghhithesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 22 Aug 2024 02:35:01 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id af51f47a (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 22 Aug 2024 06:34:27 +0000 (UTC) Date: Thu, 22 Aug 2024 08:35:00 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: karthik nayak , Justin Tobler Subject: [PATCH v3 07/15] reftable/dump: drop unused `compact_stack()` Message-ID: <4011fa65d81928348e2e4d107279d04ed9fd7324.1724308389.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 | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/reftable/dump.c b/reftable/dump.c index dd65d9e8bb7..391d93de6a4 100644 --- a/reftable/dump.c +++ b/reftable/dump.c @@ -24,30 +24,10 @@ 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" + printf("usage: dump [-st] arg\n\n" "options: \n" - " -c compact\n" " -b dump blocks\n" " -t dump table\n" " -s dump stack\n" @@ -62,7 +42,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 +56,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 +75,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 Thu Aug 22 06:35:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13772712 Received: from fout6-smtp.messagingengine.com (fout6-smtp.messagingengine.com [103.168.172.149]) (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 1B31514BF98 for ; Thu, 22 Aug 2024 06:35:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724308507; cv=none; b=HNFXl63mCh6S6VMBhjbNEvisC6FNDDn/B1F047dxIT5yzjyMi8CFSE9UdrUnLXQuxQBluFi0LJBMQtAA40XMezw9jpMIy8pKZIZPWy06YIWIHIPLatPa5ZpI2M4B7G3QgF4uAfC0fkvI4Uu3MKGT7aYhRHVZuxyMdCVg5ggCGnw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724308507; c=relaxed/simple; bh=9KT4AzA9oraOcRLcRyYD1j8e9cdbJLhiLFjYm8CF7hU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=aLD6Q+q6b/eA0BqkkjMMnFZkKduNJNcB9/usxz+y9x7vfJWsnTUWsIlOdf8zvuzUUfazqsotYQCltycPS/fTtZiteBhg1q/155YxtDQ3uuBfMASlpYp4IQHfmOpG/AP2sxvHy3/bO9MFCzTfe3NSM8cWoZNgTAZV0sUhkZAuaCo= 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=Gq4Fo9Ps; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=jCZBNtkp; arc=none smtp.client-ip=103.168.172.149 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="Gq4Fo9Ps"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="jCZBNtkp" Received: from phl-compute-04.internal (phl-compute-04.nyi.internal [10.202.2.44]) by mailfout.nyi.internal (Postfix) with ESMTP id 6FE6C138592E; Thu, 22 Aug 2024 02:35:05 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-04.internal (MEProxy); Thu, 22 Aug 2024 02:35:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=fm1; t=1724308505; x=1724394905; bh=o72FovIsJO d+87xrR3CrsPz8nNj3nDgqpbLM4Gy40eo=; b=Gq4Fo9Pscp5LmcW8ZO/IORhKyj OJg+D9c6EVeHIrZlSnqpsAxVxk6ZD0bNvzxW69qyRDLxKoy1XcEOPCLe7u1+b1JD zuMLrN6yLQBVB6dItIlNs1AWdphRP+ykJAH3aj06unbziUS0klFxFIeWVIiu8qCq +kw6ysRTPCZclzMmPtNqNLxWHs17NXRWC3PfjoYyaHBJfqb4wamO23jfteihWc8N l0cghn5ik09Q2sh+eu35uRxleaACDop3hqolp58AX2zY31NVCaPXg7fl1Uwwcw59 GB2wgsb7MV83+2pmzFUzGUE6uDR2h6CHdAMveYkiXdmDTGaYoJhn2rOseEYg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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= fm1; t=1724308505; x=1724394905; bh=o72FovIsJOd+87xrR3CrsPz8nNj3 nDgqpbLM4Gy40eo=; b=jCZBNtkpSoeYWBJdoiG7TE0fp9zfk46u0YCXcVnkmteF shkr/wPHYI6vPwOODVklZy78A+uQJa4d9xhdSv9X58mlvKZ6iw8UPQtcnartGeA8 iVmMXJ2/X7Og+pCjT0WrAh41RvKq/sfMsV6QduFpJLrUY8YQVbOoKM8Z488JKUe3 dBp1A39iug0GHEbkBPvoIROqQoV/MxWNzw5WbsBWCANaZMLqsRkkyE8l1Oyja8ei FpUbqY/ZX5IM9KkF9g8gide8PL5yrrg9qydHrK+ROK2bPnUYZ1FrCmfSu8LfdCQ7 GohLOhP8ZG43Ru2BxwK9976I/f8Veef1QunSX2hjXQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudduledguddutdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehttdertddttddv necuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrih hmqeenucggtffrrghtthgvrhhnpeeuieeuudfhvefhkeeigfekgfegleejtdffteehheet hffhvdeludekkeffhfffvdenucffohhmrghinhepghhoohhglhgvrdgtohhmnecuvehluh hsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhi mhdpnhgspghrtghpthhtohepfedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepkh grrhhthhhikhdrudekkeesghhmrghilhdrtghomhdprhgtphhtthhopehgihhtsehvghgv rhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrd gtohhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 22 Aug 2024 02:35:04 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id be3f7ba0 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 22 Aug 2024 06:34:30 +0000 (UTC) Date: Thu, 22 Aug 2024 08:35:02 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: karthik nayak , Justin Tobler Subject: [PATCH v3 08/15] t/helper: inline `reftable_dump_main()` 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 printing functionality part of `reftable/dump.c` is really only used by our "dump-reftable" test helper. It is certainly not generic logic that is useful to anybody outside of Git, and the format it generates is quite specific. Still, parts of it are used in our test suite and the output may be useful to take a peek into reftable stacks, tables and blocks. So while it does not make sense to expose this as part of the reftable library, it does make sense to keep it around. Inline the `reftable_dump_main()` function into the "dump-reftable" test helper. This clarifies that its format is subject to change and not part of our public interface. Furthermore, this allows us to iterate on the implementation in subsequent patches. Signed-off-by: Patrick Steinhardt --- Makefile | 1 - reftable/dump.c | 86 --------------------------------------- reftable/reftable-tests.h | 1 - t/helper/test-reftable.c | 61 ++++++++++++++++++++++++++- 4 files changed, 60 insertions(+), 89 deletions(-) delete mode 100644 reftable/dump.c diff --git a/Makefile b/Makefile index 3863e60b664..343f19a488b 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 391d93de6a4..00000000000 --- a/reftable/dump.c +++ /dev/null @@ -1,86 +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 [-st] arg\n\n" - "options: \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; - 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--) - if (*argv[1] != '-') - 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; - } - - 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); - } 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, - reftable_error_str(err)); - return 1; - } - return 0; -} diff --git a/reftable/reftable-tests.h b/reftable/reftable-tests.h index d5e03dcc1b6..d005a8bb9e1 100644 --- a/reftable/reftable-tests.h +++ b/reftable/reftable-tests.h @@ -16,6 +16,5 @@ int record_test_main(int argc, const char **argv); int readwrite_test_main(int argc, const char **argv); int stack_test_main(int argc, const char **argv); int tree_test_main(int argc, const char **argv); -int reftable_dump_main(int argc, char *const *argv); #endif diff --git a/t/helper/test-reftable.c b/t/helper/test-reftable.c index 9d378427da9..7f37d0cd34b 100644 --- a/t/helper/test-reftable.c +++ b/t/helper/test-reftable.c @@ -1,4 +1,7 @@ #include "reftable/system.h" +#include "reftable/reftable-error.h" +#include "reftable/reftable-reader.h" +#include "reftable/reftable-stack.h" #include "reftable/reftable-tests.h" #include "test-tool.h" @@ -13,7 +16,63 @@ int cmd__reftable(int argc, const char **argv) return 0; } +static void print_help(void) +{ + printf("usage: dump [-st] arg\n\n" + "options: \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; + 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--) + if (*argv[1] != '-') + 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; + } + + 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); + } 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, + reftable_error_str(err)); + return 1; + } + return 0; } From patchwork Thu Aug 22 06:35:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13772713 Received: from fout6-smtp.messagingengine.com (fout6-smtp.messagingengine.com [103.168.172.149]) (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 5319113BC3D for ; Thu, 22 Aug 2024 06:35:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724308512; cv=none; b=NFb/HdzjA6zocKrkgB9i8orctFZ4+Ev/6XFBFg60ML04/NG9GhxjZgTjLZxa+alD/OKFgOj5Ql6b0al4WrmTsJTsILFGR0QpXOjwg9LfY6k/ohsSBUDjFX76yGmUWDFnoidBbYHwyx1rcjXr56sXB8EAMoVTB/pXQjztGigMkIE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724308512; c=relaxed/simple; bh=48Kf6WTw+hqwBqGB+p/UyWH4G79KYYPomfGjesLdM6M=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=q+uRaxqtgHVZMpMe7tkaZ++5QtWckPixtz9mYG6PBNGDbSpJno2biRtyqtQrwFtM20znD7xMC87pdVZHFF6PS3a8ouSzSrK/jna9UrxjqKpU0GOAoFcV5wDj5gwOBt04S4EqglqfjkSA1KG7g1jBrWthDfp02w2sS+dNEwPwpEQ= 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=AcMalZ8Q; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=be/KH3m2; arc=none smtp.client-ip=103.168.172.149 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="AcMalZ8Q"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="be/KH3m2" Received: from phl-compute-04.internal (phl-compute-04.nyi.internal [10.202.2.44]) by mailfout.nyi.internal (Postfix) with ESMTP id A01DF138592E; Thu, 22 Aug 2024 02:35:10 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-04.internal (MEProxy); Thu, 22 Aug 2024 02:35:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=fm1; t=1724308510; x=1724394910; bh=NPNSutiB4g 1wvpQR1kGgWngYJU0Haz4HkZySik9SPJs=; b=AcMalZ8QLgd9lDOSsqr/NyJZEm 6hkXXFcsgsrjpUa7seB9Oncx+aQbnebBDd5kdTNhqg3cHQicGchDqMT/DS2q1zH8 8ApB7uSq4+f0rgcNRsbwsMYpS0DH9Bq0yMzqdevl94rbPsnJrGoeJJeun8ydDhqv WMhHDj32LwF3BNY0SqxZXzyCxI1sEDNDVUuc4NpexiAiZa8t6iJ2+tQ0j6v2Sb9e bBXvFQPdaE4bHUoo0N/CtLSeyGnlQ6UAxS28ohhw7pRGSEZl5m1kVgsIfJVEFysC ievswb4yPsudIr//Yu84TiycBlw40pMdFQ5xh4A8WRVb9Mo497knca3M6ejw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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= fm1; t=1724308510; x=1724394910; bh=NPNSutiB4g1wvpQR1kGgWngYJU0H az4HkZySik9SPJs=; b=be/KH3m2ESe/qEH/1J3p4kVCW62Trh1wIUruW7bv2/XB fwiYQW1a1eQtUzz1vsw+ExKWSU6fGV/mPGdIexYCXJEmLsA/QYZI4DCqSUu5Y6QI EztXFMI4mihmF9W9+Grr+pHjlQ2qXz2lvPN55UZYxj9TYDG6u4kfRIX8hryCnZDx F5rK3pCRvJtiK/lA++iSRPkZsfaDxxi0KCM3zwLj/dBVmwz7e1TpBPYJLRg9fJdB n3jiTkIe5J88DrjMcvJ6+pds+PhfVWttFdLY5Pe4IEjIFNx1jJ52tlhwmpIHm1gA cQ8fLZR92Dsnq7LlzDDz4CtqQTIIl/bE9+1XGgDX3g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudduledguddutdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehttdertddttddv necuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrih hmqeenucggtffrrghtthgvrhhnpeevkeekfffhiedtleduiefgjedttedvledvudehgfeu gedugffhueekhfejvdektdenucevlhhushhtvghrufhiiigvpeefnecurfgrrhgrmhepmh grihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopeefpdhmohguvgep shhmthhpohhuthdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpd hrtghpthhtohepkhgrrhhthhhikhdrudekkeesghhmrghilhdrtghomhdprhgtphhtthho pehjlhhtohgslhgvrhesghhmrghilhdrtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 22 Aug 2024 02:35:09 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 85d74ec1 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 22 Aug 2024 06:34:35 +0000 (UTC) Date: Thu, 22 Aug 2024 08:35:05 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: karthik nayak , Justin Tobler Subject: [PATCH v3 09/15] t/helper: inline `reftable_reader_print_file()` 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: Move `reftable_reader_print_file()` into the "dump-reftable" helper. This follows the same reasoning as the preceding commit. Signed-off-by: Patrick Steinhardt --- reftable/reader.c | 21 --------------------- reftable/reftable-reader.h | 2 -- t/helper/test-reftable.c | 23 ++++++++++++++++++++++- 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/reftable/reader.c b/reftable/reader.c index e3f58542297..fbd93b88dff 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/reftable-reader.h b/reftable/reftable-reader.h index a32f31d6486..7c7d1716516 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/t/helper/test-reftable.c b/t/helper/test-reftable.c index 7f37d0cd34b..19367c25f9a 100644 --- a/t/helper/test-reftable.c +++ b/t/helper/test-reftable.c @@ -1,5 +1,6 @@ #include "reftable/system.h" #include "reftable/reftable-error.h" +#include "reftable/reftable-generic.h" #include "reftable/reftable-reader.h" #include "reftable/reftable-stack.h" #include "reftable/reftable-tests.h" @@ -28,6 +29,26 @@ static void print_help(void) "\n"); } +static int dump_reftable(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 cmd__dump_reftable(int argc, const char **argv) { int err = 0; @@ -64,7 +85,7 @@ int cmd__dump_reftable(int argc, const char **argv) if (opt_dump_blocks) { err = reftable_reader_print_blocks(arg); } else if (opt_dump_table) { - err = reftable_reader_print_file(arg); + err = dump_reftable(arg); } else if (opt_dump_stack) { err = reftable_stack_print_directory(arg, opt_hash_id); } From patchwork Thu Aug 22 06:35: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: 13772714 Received: from fout6-smtp.messagingengine.com (fout6-smtp.messagingengine.com [103.168.172.149]) (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 B38D213CFBB for ; Thu, 22 Aug 2024 06:35:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724308517; cv=none; b=gegpHY2kRQFY9KVK4qlUoNl+ZeZFXqsKVrsSES2ylppvzInc4feifrqvbTao47RwdKLR+A56lzzJTP7rqkq85EPQ/Be/LekNirF6uCEyRkn4e2IyONLp3f7o7rX83SkKZ6WaZLB4bvVii/aZuFoLV5LKxSxnE7me1qXogEscimY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724308517; c=relaxed/simple; bh=kBe3EzKn2Bd1uMyTgATbudChpB1k107AytiCQusESws=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=pnJ3j/2as+P1DhRGeDXdooV7xM1s+76l5xuNBABz0kzsQePxzw29H03NZWLTHpUMTDKWwpFV5XOJpqRFQWTnq8OpAXDgimIPzWLPSXWSXSxD/JfEa1JNvSMbB+mj4e6j2SxolPRGDJcVFe7gffcFVSV6KUNTe4jYMmFzon2mDBg= 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=f3fEDp3Z; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=sJtH7o9m; arc=none smtp.client-ip=103.168.172.149 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="f3fEDp3Z"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="sJtH7o9m" Received: from phl-compute-04.internal (phl-compute-04.nyi.internal [10.202.2.44]) by mailfout.nyi.internal (Postfix) with ESMTP id CBB14138EFB6; Thu, 22 Aug 2024 02:35:14 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-04.internal (MEProxy); Thu, 22 Aug 2024 02:35:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=fm1; t=1724308514; x=1724394914; bh=utK2VRBCxF JYa69lguubEG+J35Ad/UePl4MznHM4MyA=; b=f3fEDp3Zxbzg9K8NQyfbxAcimP i6nvfpg87uAh++c/g+X4w1MpezM07Lt7h1/eKOpOsBNUO/vPeMDZIRnqlqHvUlbj w71+Y/pQptP2VVCutC1PLPyx/G8FooWSHJGb4idT0SI2U+Qija9pxHzCWU1aF2qY 3z2qyUzWmF0UhXD+/4m6TZOZThQlNuArRvSuH0ty/d6Qrj0tHpXYSyN43HYKCb03 R9IXpLd1JTeuxtFugoTjewia0GitGIaDE56JdwMwT/3qcyo97MoMSJJRCstr7ZLS lm9XKpbxbexvgsuLtpmS8sIlJU0iLx2DvmO2QuxzrnRGef2DemOhqeZfyHSQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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= fm1; t=1724308514; x=1724394914; bh=utK2VRBCxFJYa69lguubEG+J35Ad /UePl4MznHM4MyA=; b=sJtH7o9m+zJd82H6Y+RQy8Eci6kgZL5mbv21dOq64iBV wIKGggMPX0oq9BKvyUP2HcpwD2xJQnHsCUPWT0HBgK7VZ7QrhS7/7S+NNrzgK5OV SGUlaxKPF8iqb8nP7cN774vOwjrQ/7HOlnTQgpAiwgM0/Q5t/BjLOfspypSo2Nlm YGdS+xp0tD22juFxXrdpW+s+44ltW0xALn9rGBPtukLO+BhXrmfQN1DurYvzYsjD zFnVgsH87271t8IYmnS2s7sF+bCslTkkZcLR5PFaMMLkaXYlBvDttFKGkdChJWBS T7NeL8H3Tjn2TdJ1LwQzb1FKTqHHDTvBTg8M3X47OQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudduledguddutdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehttdertddttddv necuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrih hmqeenucggtffrrghtthgvrhhnpeevkeekfffhiedtleduiefgjedttedvledvudehgfeu gedugffhueekhfejvdektdenucevlhhushhtvghrufhiiigvpeefnecurfgrrhgrmhepmh grihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopeefpdhmohguvgep shhmthhpohhuthdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpd hrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtghpthhtohepkhgr rhhthhhikhdrudekkeesghhmrghilhdrtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 22 Aug 2024 02:35:13 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id ec903025 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 22 Aug 2024 06:34:39 +0000 (UTC) Date: Thu, 22 Aug 2024 08:35:12 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: karthik nayak , Justin Tobler Subject: [PATCH v3 10/15] t/helper: inline `reftable_stack_print_directory()` Message-ID: <242c179df5fdfaafdb133e4c5af37c1fd860c5ce.1724308389.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 `reftable_stack_print_directory()` into the "dump-reftable" helper. This follows the same reasoning as the preceding commit. Note that this requires us to remove the tests for this functionality in `reftable/stack_test.c`. The test does not really add much anyway, because all it verifies is that we do not crash or run into an error, and it specifically doesn't check the outputted data. Also, as the code is now part of the test helper, it doesn't make much sense to have a unit test for it in the first place. Signed-off-by: Patrick Steinhardt --- reftable/reftable-stack.h | 3 --- reftable/stack.c | 20 -------------------- reftable/stack_test.c | 7 ------- t/helper/test-reftable.c | 23 ++++++++++++++++++++++- 4 files changed, 22 insertions(+), 31 deletions(-) diff --git a/reftable/reftable-stack.h b/reftable/reftable-stack.h index 09e97c99915..f4f8cabc7fb 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 d08ec009590..bedd503e7e1 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 dbca9eaf4a8..42044ed8a3e 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"); diff --git a/t/helper/test-reftable.c b/t/helper/test-reftable.c index 19367c25f9a..db62ea8dc3b 100644 --- a/t/helper/test-reftable.c +++ b/t/helper/test-reftable.c @@ -1,6 +1,7 @@ #include "reftable/system.h" #include "reftable/reftable-error.h" #include "reftable/reftable-generic.h" +#include "reftable/reftable-merged.h" #include "reftable/reftable-reader.h" #include "reftable/reftable-stack.h" #include "reftable/reftable-tests.h" @@ -29,6 +30,26 @@ static void print_help(void) "\n"); } +static int dump_stack(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; +} + static int dump_reftable(const char *tablename) { struct reftable_block_source src = { NULL }; @@ -87,7 +108,7 @@ int cmd__dump_reftable(int argc, const char **argv) } else if (opt_dump_table) { err = dump_reftable(arg); } else if (opt_dump_stack) { - err = reftable_stack_print_directory(arg, opt_hash_id); + err = dump_stack(arg, opt_hash_id); } if (err < 0) { From patchwork Thu Aug 22 06:35:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13772715 Received: from fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.152]) (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 D394B14F138 for ; Thu, 22 Aug 2024 06:35:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724308520; cv=none; b=m/YLGro1cMSZNM1qW3ial9rxwxOP9Ge8AdW/4OYfaD9kwvHZ5Sl5LMMs4WCrj6HzB+cR9IPFvbyX776QEIpHfyz2eUbsz5WfpPZhnyx+PpWFxp44P/Ii9vhrVNIw6/MQVwW/tgfYZf35URnGCApz0Qh2Fvi0CuSEiVH6AMtzjBU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724308520; c=relaxed/simple; bh=JgKj1Aa9yUWGk/3/J14PocxDq0yttPGEAe+8SKh57F4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Wz99/2vOOh+Ib4HQOkUnO2SLd3Mh6V/wweE9wgG2+zs7/Ks9Xbdr+J0ghsW6XAswLpyk1At+4CF6+NOEdXnSQJ+x6w+LLNjwOKCxindosiDi06y5nzGN4gMzt9ipGXLYwGCKBE2KxIJOnV4OyhyqGwxEji2U07HxVyrSywZL/+w= 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=b6BKFMlh; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=EZS+0Xvy; arc=none smtp.client-ip=103.168.172.152 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="b6BKFMlh"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="EZS+0Xvy" Received: from phl-compute-02.internal (phl-compute-02.nyi.internal [10.202.2.42]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 03F911151C11; Thu, 22 Aug 2024 02:35:18 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Thu, 22 Aug 2024 02:35:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=fm1; t=1724308517; x=1724394917; bh=j28WK6mDeG HWF8/XAlSF/jVi0yi90iFz3naMJuhkkZM=; b=b6BKFMlh/HQ/sGbSK/PxU/BfkW c2ingHcyxUVUm2mCgfkFubkBU4YWgtxiZLA+9yu/QeU+nnzz2BO56CFrz2UChMx2 DEv9AEh8qDVliTXQjzXBKOw4CYUpgkWcPiBWrs6kFTQY44VkbwUgHdn7/CeqS+2b B4+GzAtJP/4IG9ZnhWi+6jO11kAPpPOmYKbJnNYzL40IrcCsQHBGDxCrBmjjQayW dSsqtjin/ZfSn5uK6ox7ZWJlAk+RhFCYF7PYkJH99TzzVjMEc1OF5DUDVcHXKG28 u2UG3WKfxezEHySd9bGNn5TWKrFHIGKP/04BefS/U3ukwFyGiWrkYcR1fSLg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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= fm1; t=1724308517; x=1724394917; bh=j28WK6mDeGHWF8/XAlSF/jVi0yi9 0iFz3naMJuhkkZM=; b=EZS+0Xvy4u3/q58o0JCjp8FrEsfoGiCbF7gqzUtlTikF NwM3a9JQw8Ko06Lvobr8PuzOkTiyUkz5MlQc6axUN8nTac96m2pVSrGPGUadsZkj 1AMuo2m1TOF1oDGK2+yhMp/fh6MDxjBhotqWd2W7kLRioKFzEnkj/K2Hwsn+cSjk WMFSmvETGf9ycyF3Z0zHm40tE+bNJFyCdss3ov/4+0aBUdxrkiLifbmJDAA6YQzB bYMQrsLaFEImHslUIwgJEA5Ey0SFyzHKDtKpZdsk07jg7v0M1ndP4P3MLoRM1U1q 3GNQeTonbEz8QJpCAQeQROByk7pGUxf4AiX37vokcg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudduledguddutdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehttdertddttddv necuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrih hmqeenucggtffrrghtthgvrhhnpeevkeekfffhiedtleduiefgjedttedvledvudehgfeu gedugffhueekhfejvdektdenucevlhhushhtvghrufhiiigvpedvnecurfgrrhgrmhepmh grihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopeefpdhmohguvgep shhmthhpohhuthdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpd hrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtghpthhtohepkhgr rhhthhhikhdrudekkeesghhmrghilhdrtghomh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 22 Aug 2024 02:35:16 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id fe72c824 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 22 Aug 2024 06:34:42 +0000 (UTC) Date: Thu, 22 Aug 2024 08:35:15 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: karthik nayak , Justin Tobler Subject: [PATCH v3 11/15] t/helper: inline `reftable_table_print()` 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: Move `reftable_table_print()` into the "dump-reftable" helper. This follows the same reasoning as the preceding commit. Signed-off-by: Patrick Steinhardt --- reftable/generic.c | 47 --------------------------------- reftable/reftable-generic.h | 3 --- t/helper/test-reftable.c | 52 +++++++++++++++++++++++++++++++++++-- 3 files changed, 50 insertions(+), 52 deletions(-) diff --git a/reftable/generic.c b/reftable/generic.c index 6ecf9b880f7..495ee9af6b0 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/reftable-generic.h b/reftable/reftable-generic.h index 65670ea093b..b8b1323a331 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/t/helper/test-reftable.c b/t/helper/test-reftable.c index db62ea8dc3b..82159fa51f4 100644 --- a/t/helper/test-reftable.c +++ b/t/helper/test-reftable.c @@ -30,6 +30,54 @@ static void print_help(void) "\n"); } +static int dump_table(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; +} + static int dump_stack(const char *stackdir, uint32_t hash_id) { struct reftable_stack *stack = NULL; @@ -43,7 +91,7 @@ static int dump_stack(const char *stackdir, uint32_t hash_id) merged = reftable_stack_merged_table(stack); reftable_table_from_merged_table(&table, merged); - err = reftable_table_print(&table); + err = dump_table(&table); done: if (stack) reftable_stack_destroy(stack); @@ -64,7 +112,7 @@ static int dump_reftable(const char *tablename) goto done; reftable_table_from_reader(&tab, r); - err = reftable_table_print(&tab); + err = dump_table(&tab); done: reftable_reader_free(r); return err; From patchwork Thu Aug 22 06:35:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13772716 Received: from fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.152]) (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 1A26214F138 for ; Thu, 22 Aug 2024 06:35:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724308524; cv=none; b=DZ1ayYYIjcPYpN/5PblngBaZO9sZyrGIo8Tkmg4hjdocj8I4aDprkhqLwgQaLsMImkBbudI2jUfYNo0o9LEHlHznFClrK1bKfR0zC6xqtCpZOaMbxinDE/Ayk4cY/DISgIEY7/4ml6dgPkAwHCz/fIxDSrU/lNDZrDUkIFVdK4E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724308524; c=relaxed/simple; bh=LcSxVzmmWAQ6i8vqs/M6zriyybkkWjemQ9+bd8tDVMU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=AVY9whHk22YMfxcCnJsuEYckzp3u6LIIYShCWYsuyhvQv3W41fHUkGEnpf0fiWhe72crOG62IOT/EfIb+qkuPMtyVb2V+IyYLJ9rwF0iiEYJglE5JpBl3BA1zLwtTnZiTlfSRwv/7jvcroN/B9bV3OLG/akgT6EGF9Uypj+Wilw= 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=qMFN8isE; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=gGOX+fCg; arc=none smtp.client-ip=103.168.172.152 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="qMFN8isE"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="gGOX+fCg" Received: from phl-compute-07.internal (phl-compute-07.nyi.internal [10.202.2.47]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 3C5381151AF6; Thu, 22 Aug 2024 02:35:21 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-07.internal (MEProxy); Thu, 22 Aug 2024 02:35:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=fm1; t=1724308521; x=1724394921; bh=ZztTG6Tilb FBcBYG4zD6gPvBQaYUN5UFBFv3nvc/tjU=; b=qMFN8isEWnbIBmZNLKBWkMGXl/ tjcX1ljmtiRq2nAOqNj3s7ZvS/V61vsbJl6Dy15KNROtD9Y3vpU90wl7oPLw4/LK xd5UONR3t6RWYVRPK08iQPgyNI/GCg3iwFOVYIqPLRrdJffda9Pdg+BDE1Po5XwM g6TOTWSliMpRR2c4GgASP1jkDaQ441ru0Dcvbl441V9R4j7lSTzmlHq01g5X2YBs kjhv8NzITk8JL4Sf0eHx62oTt903cL2Xk/LMEd8ZitmsoCFaKckIAcxFNiN+17QE RFATRnO2rysOBijA9JnxZ2Do2nyEtSdBRer4dKPODlYcbH2jAUYLeXHvlKiw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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= fm1; t=1724308521; x=1724394921; bh=ZztTG6TilbFBcBYG4zD6gPvBQaYU N5UFBFv3nvc/tjU=; b=gGOX+fCgHbWOwPGvTOG8ixH6saZzm3ydLHPmc0GWaCMF 0XN6R6VkkFUYjMjEFlFPr8nJHsfY2G/pbgUp+1G7WAhGKZjVAeX0TI0/TiuhfEQY ZZ1jcTzT9vAy5Uk8JFv6F4gciYrLawFlegqQ9Oxjt9dfCQp6MniqQZ+iLUiwVjvV 7qbjkuutQa+IaS8vGKMuQNGjyZpvzkHzOhYBJlyALqgHcEg2YIewxlaryyPMmsep bWAMl3AAZNY0ikob//aI1rIeMkkTa1uraRI6gv+SrLStWE+JnxLPdeff+iRJtQ7x TTmPjY0GVdXvhw0LX6XlwHuDW/V8mP0rJTqVbKGztg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudduledguddutdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehttdertddttddv necuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrih hmqeenucggtffrrghtthgvrhhnpeetgeeutedufeeiheejvdeuvdetuefhveegvedvtddv udevtefgffejteekvdfhtdenucffohhmrghinhepvhgrlhdvrdhtrghrghgvthdpuhhpug grthgvrdhnrghmvgdpuhhpuggrthgvrdgvmhgrihhlpdhuphgurghtvgdrthiipdhuphgu rghtvgdrnhgvfienucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfh hrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopeefpdhmohguvgepshhmthhp ohhuthdprhgtphhtthhopehjlhhtohgslhgvrhesghhmrghilhdrtghomhdprhgtphhtth hopehkrghrthhhihhkrddukeeksehgmhgrihhlrdgtohhmpdhrtghpthhtohepghhithes vhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 22 Aug 2024 02:35:20 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 2dfafab1 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 22 Aug 2024 06:34:45 +0000 (UTC) Date: Thu, 22 Aug 2024 08:35:18 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: karthik nayak , Justin Tobler Subject: [PATCH v3 12/15] t/helper: inline printing of reftable records 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: Move printing of reftable records into the "dump-reftable" helper. This follows the same reasoning as the preceding commit. Signed-off-by: Patrick Steinhardt --- reftable/record.c | 127 ------------------------------------- reftable/record.h | 1 - reftable/reftable-record.h | 8 --- t/helper/test-reftable.c | 77 +++++++++++++++++++--- 4 files changed, 69 insertions(+), 144 deletions(-) diff --git a/reftable/record.c b/reftable/record.c index a2cba5ef747..e26bd4bc8d9 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 d778133e6ec..5003bacdb0c 100644 --- a/reftable/record.h +++ b/reftable/record.h @@ -136,7 +136,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-record.h b/reftable/reftable-record.h index ff486eb1f75..2d42463c581 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/t/helper/test-reftable.c b/t/helper/test-reftable.c index 82159fa51f4..cb22d7537a9 100644 --- a/t/helper/test-reftable.c +++ b/t/helper/test-reftable.c @@ -30,12 +30,33 @@ static void print_help(void) "\n"); } +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 int dump_table(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 hash_len = hash_size(hash_id); int err; reftable_table_init_ref_iter(tab, &it); @@ -45,14 +66,35 @@ static int dump_table(struct reftable_table *tab) return err; while (1) { + char hex[GIT_MAX_HEXSZ + 1] = { 0 }; /* BUG */ + err = reftable_iterator_next_ref(&it, &ref); - if (err > 0) { + if (err > 0) break; - } - if (err < 0) { + if (err < 0) return err; + + 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_len); + printf("val 2 %s", hex); + hex_format(hex, ref.value.val2.target_value, + hash_len); + printf("(T %s)", hex); + break; + case REFTABLE_REF_VAL1: + hex_format(hex, ref.value.val1, hash_len); + printf("val 1 %s", hex); + break; + case REFTABLE_REF_DELETION: + printf("delete"); + break; } - reftable_ref_record_print(&ref, hash_id); + printf("}\n"); } reftable_iterator_destroy(&it); reftable_ref_record_release(&ref); @@ -64,14 +106,33 @@ static int dump_table(struct reftable_table *tab) return err; while (1) { + char hex[GIT_MAX_HEXSZ + 1] = { 0 }; + err = reftable_iterator_next_log(&it, &log); - if (err > 0) { + if (err > 0) break; - } - if (err < 0) { + if (err < 0) return err; + + 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_len); + printf("%s => ", hex); + hex_format(hex, log.value.update.new_hash, hash_len); + printf("%s\n\n%s\n}\n", hex, + log.value.update.message ? log.value.update.message : ""); + break; } - reftable_log_record_print(&log, hash_id); } reftable_iterator_destroy(&it); reftable_log_record_release(&log); From patchwork Thu Aug 22 06:35:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13772717 Received: from fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.152]) (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 60DF51531C0 for ; Thu, 22 Aug 2024 06:35:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724308526; cv=none; b=KMFSFsolWRv2TqD9J8RrzCnTc+H+5CV9YONs21IE3YCMtLWP0asB04+Irm9Pm+UoV1h6AlCs1yztacE7UcwY/ACQGcU0iDbJhU+tMXhtMPqPXmapAnPLU6SL5sc0MdgBV0ybP/FsCJmJ2pDS5lzEUl84a45NKCtdA7jneNlBpnc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724308526; c=relaxed/simple; bh=EuUGExPjVxOfWARmE63th2NOSib52j1v/PuSh4etJDo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=FYUySRy7vBkrXs4KzRZeyE2rFwCa51rZ0cEOmwgZp+AMcSs57i7IqN8cLgTEGjIUlHc7HWD2eGbJm7UpCbyLkU9FR081zLY2FiDTQKmEN6LGaNT9jv4Cyz0c0UfYLcK0u2vYDIqw4yMpcGy8Rmsxs3gFHzsAwvk49GGg2swpiSM= 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=BSX7ay5B; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=mLayEAbE; arc=none smtp.client-ip=103.168.172.152 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="BSX7ay5B"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="mLayEAbE" Received: from phl-compute-02.internal (phl-compute-02.nyi.internal [10.202.2.42]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 733561151863; Thu, 22 Aug 2024 02:35:24 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Thu, 22 Aug 2024 02:35:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=fm1; t=1724308524; x=1724394924; bh=YHxMY53l8G B/sThGFbmnQ2rHvt78gDq+BLMlHEfGuEA=; b=BSX7ay5BCtce43Aahf8DMv6pQf 8ZbSbJsBNTcIVQV1J53Di+oOGK4bReC8VxzQY9rVgLBvBYO73BqjAv9RF/3PdAvl ibqGFsEPHLpGbOT86WzefddEha5/zAWtb0kARBDJZ+sIzNEb/shbUDXuOP2pwInV CnONUsGffEnsxrh35gVzMYLd+3gKcJrnsj1l/UabWHovtdzWpsBtvY0ToWQ9acfo WdcXZBoSVfOPforTXFZwrFHEgr86GQ3416of10nFIUvAF+/Pmxt7rboZGiYQFEl3 S5AAR5Jwp+FAL0gaHXWtjQTUJ4y+HMrJclMeDoTUYGFhRskAu9k34CEKNDDw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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= fm1; t=1724308524; x=1724394924; bh=YHxMY53l8GB/sThGFbmnQ2rHvt78 gDq+BLMlHEfGuEA=; b=mLayEAbEwuwGdzUMndnZYQqXpwaTKVmVov2klPIKnepq AtyTTkG2/zhQaJMSUzB2cswghWfn7k4XV+TfeH4jbu0hv5Cgdg1AwChfOKZWfDUG BQWVYInSHeiIpQjWgUehtOk0lKQwULnyeSOw9br4x6wEePNsdhc6BSSMY9qK+gMa 6i3V2sxcbn/eUCUjI1Rs/k/odFdBt4ApUr0ofzphSANzl7NPDWxiJQNMLAFNVwQB JmK4rnzAtjzy0INEk7d6doop7B59ZvlQCfuym1eaPSbZO/EIU0ZOwZysFnks/Cuc krm9AuI/mrgPkbApCJwotgaqhd9Dcv9Xwgr8i6Bfkg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudduledguddutdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehttdertddttddv necuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrih hmqeenucggtffrrghtthgvrhhnpefgteduleethfettddthfefvdffvdffvddtleehfffh jeehtedvkeeileeuveeigeenucffohhmrghinhepvhgrlhdvrdhtrghrghgvthdpuhhpug grthgvrdgvmhgrihhlpdhuphgurghtvgdrthiipdhuphgurghtvgdrnhgvfienucevlhhu shhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrih hmpdhnsggprhgtphhtthhopeefpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehk rghrthhhihhkrddukeeksehgmhgrihhlrdgtohhmpdhrtghpthhtohepjhhlthhosghlvg hrsehgmhgrihhlrdgtohhmpdhrtghpthhtohepghhithesvhhgvghrrdhkvghrnhgvlhdr ohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 22 Aug 2024 02:35:23 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id b79b0f51 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 22 Aug 2024 06:34:48 +0000 (UTC) Date: Thu, 22 Aug 2024 08:35:21 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: karthik nayak , Justin Tobler Subject: [PATCH v3 13/15] t/helper: use `hash_to_hex_algop()` to print hashes Message-ID: <0a3c619e8425ac0d710f827be915931f003c00ad.1724308389.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" test helper uses a hand-crafted version to convert from a raw hash to its hex variant. This was done because this code used to be part of the reftable library, where we do not use most functions from the Git core. Now that the code is integrated into the "dump-reftable" helper though, that limitation went away. Let's thus use `hash_to_hex_algop()` instead. Signed-off-by: Patrick Steinhardt --- t/helper/test-reftable.c | 48 +++++++++------------------------------- 1 file changed, 11 insertions(+), 37 deletions(-) diff --git a/t/helper/test-reftable.c b/t/helper/test-reftable.c index cb22d7537a9..234fb80010f 100644 --- a/t/helper/test-reftable.c +++ b/t/helper/test-reftable.c @@ -1,3 +1,6 @@ +#include "git-compat-util.h" +#include "hash.h" +#include "hex.h" #include "reftable/system.h" #include "reftable/reftable-error.h" #include "reftable/reftable-generic.h" @@ -30,33 +33,12 @@ static void print_help(void) "\n"); } -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 int dump_table(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 hash_len = hash_size(hash_id); + const struct git_hash_algo *algop; int err; reftable_table_init_ref_iter(tab, &it); @@ -65,9 +47,9 @@ static int dump_table(struct reftable_table *tab) if (err < 0) return err; - while (1) { - char hex[GIT_MAX_HEXSZ + 1] = { 0 }; /* BUG */ + algop = &hash_algos[hash_algo_by_id(reftable_table_hash_id(tab))]; + while (1) { err = reftable_iterator_next_ref(&it, &ref); if (err > 0) break; @@ -80,15 +62,11 @@ static int dump_table(struct reftable_table *tab) printf("=> %s", ref.value.symref); break; case REFTABLE_REF_VAL2: - hex_format(hex, ref.value.val2.value, hash_len); - printf("val 2 %s", hex); - hex_format(hex, ref.value.val2.target_value, - hash_len); - printf("(T %s)", hex); + printf("val 2 %s", hash_to_hex_algop(ref.value.val2.value, algop)); + printf("(T %s)", hash_to_hex_algop(ref.value.val2.target_value, algop)); break; case REFTABLE_REF_VAL1: - hex_format(hex, ref.value.val1, hash_len); - printf("val 1 %s", hex); + printf("val 1 %s", hash_to_hex_algop(ref.value.val1, algop)); break; case REFTABLE_REF_DELETION: printf("delete"); @@ -106,8 +84,6 @@ static int dump_table(struct reftable_table *tab) return err; while (1) { - char hex[GIT_MAX_HEXSZ + 1] = { 0 }; - err = reftable_iterator_next_log(&it, &log); if (err > 0) break; @@ -126,10 +102,8 @@ static int dump_table(struct reftable_table *tab) 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_len); - printf("%s => ", hex); - hex_format(hex, log.value.update.new_hash, hash_len); - printf("%s\n\n%s\n}\n", hex, + printf("%s => ", hash_to_hex_algop(log.value.update.old_hash, algop)); + printf("%s\n\n%s\n}\n", hash_to_hex_algop(log.value.update.new_hash, algop), log.value.update.message ? log.value.update.message : ""); break; } From patchwork Thu Aug 22 06:35:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13772718 Received: from fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.152]) (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 62D321487F9 for ; Thu, 22 Aug 2024 06:35:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724308531; cv=none; b=P2R6XZstE2f8DcN5c079KmpWOC6/zoyhmOIDBTEltFAie2n5r3x8REjT0z2OhW2y2vX/2y9ap9SSVv84rc7OsuBWgNg+oF/Bil/6apZ5O0SW3XjUwTASjFpt+2ihaXwHaV1Ox9mRmAONGRd8ASvvEZRQorzKhnXfjc5g8Q3qLfQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724308531; c=relaxed/simple; bh=HXaYwMm0emX9TDOvEcQoMqTc+6N5lzbBbDiSEqNI73I=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=WYspobBoVlQy8tKSzDvneuiiC7g+CZE0Kxa9YDD92I8KCOOLOBrqmhAir+7zwhj6+8gZ6wQN5cMw+Q3d9zipJJcWORfDQg0BtZs7+XU2EHnPrtccR4egfYTZXjOBdnxllcqXI2DSZV8Axs/JaM4KSld+m+r8DfQaXaYOM2k0Mbs= 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=f4J3Lp6o; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=K5NK5fEu; arc=none smtp.client-ip=103.168.172.152 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="f4J3Lp6o"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="K5NK5fEu" Received: from phl-compute-04.internal (phl-compute-04.nyi.internal [10.202.2.44]) by mailfhigh.nyi.internal (Postfix) with ESMTP id A3A5E1151AFF; Thu, 22 Aug 2024 02:35:29 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-04.internal (MEProxy); Thu, 22 Aug 2024 02:35:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=fm1; t=1724308529; x=1724394929; bh=9jNogeP9qC ouxRjRwy1Wl1chF9oyTsFasgZrjg+sFW4=; b=f4J3Lp6oVfCddWYdhEyxOxuB9A IAf5/cehZ2IPz/wO8FnVfgQ22g8h09z3GGPTeZ/kT8IhpAhNEzCkGVMK1ao455Sa iCEGoow4t00yRcZUMI6904IWhoggfq0T9Tb4FCYtoaQB6hgU9Pjcc+td4/cmRTL1 Mi5aKxTW4dXMU2/swMbWUqP9SfWupGAU/wCDOFjccEMFRELYYPMLiP66+CW8qtmR ieHtKHUZFKQx2DPixuD5jq7NnEg32Wwwv6VwOPgdxwMrfBt/59PJQRCDqh+yA8Ah DVwx7XwM8QlTC4IjXuqmggiowJFFGuXNUx6XuRf3e17Qrm9fRxpqxb4ZODOw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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= fm1; t=1724308529; x=1724394929; bh=9jNogeP9qCouxRjRwy1Wl1chF9oy TsFasgZrjg+sFW4=; b=K5NK5fEuqqXKNphyAaVdfqL/kCJx0rnhUTq2QBJ6EPG3 Zbho+WKBFc8z0bX/MU4QpOLIB/j/ofEtMNiIvf/wEogzyuAO2LXqlZ4mtK9waxFx YUcFiAUGi/naTSSOkuBo2YdxYQODVwGd61E3qS3oHbLLkDno7b2HIpibfjn1cdw+ nWK+Iw62AA04GPJvUgEPajrE1Y58pqzsuHvaoy8cEZUbOocDeUEl8qo7NkEG90qz xS40hKbGD/SDH/3OKk82QvmnG8a+e2QfF8rWSGB0M+dGtM5L9A/cKSxA6CQqvtDK 2phHeQjSLVqWFTrdbOYeTropKXEtpN05eAeggdDAqw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudduledguddutdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehttdertddttddv necuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrih hmqeenucggtffrrghtthgvrhhnpeevkeekfffhiedtleduiefgjedttedvledvudehgfeu gedugffhueekhfejvdektdenucevlhhushhtvghrufhiiigvpeehnecurfgrrhgrmhepmh grihhlfhhrohhmpehpshesphhkshdrihhmpdhnsggprhgtphhtthhopeefpdhmohguvgep shhmthhpohhuthdprhgtphhtthhopehkrghrthhhihhkrddukeeksehgmhgrihhlrdgtoh hmpdhrtghpthhtohepjhhlthhosghlvghrsehgmhgrihhlrdgtohhmpdhrtghpthhtohep ghhithesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 22 Aug 2024 02:35:28 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 5c786b8f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 22 Aug 2024 06:34:53 +0000 (UTC) Date: Thu, 22 Aug 2024 08:35:24 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: karthik nayak , Justin Tobler Subject: [PATCH v3 14/15] t/helper: refactor to not use `struct reftable_table` Message-ID: <8eab399dfc6e0b3abaa9d8fe291850d692e019b4.1724308389.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 `struct reftable_table` interface in our "reftable" test helper gets used such that we can easily print either a single table, or a merged stack. This generic interface is about to go away. Prepare the code for this change by using merged tables instead. When printing the stack we've already got one. When using a single table, we can create a merged table from it to adapt. This removes the last user of the generic interface. Signed-off-by: Patrick Steinhardt --- t/helper/test-reftable.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/t/helper/test-reftable.c b/t/helper/test-reftable.c index 234fb80010f..c1942156b50 100644 --- a/t/helper/test-reftable.c +++ b/t/helper/test-reftable.c @@ -3,7 +3,6 @@ #include "hex.h" #include "reftable/system.h" #include "reftable/reftable-error.h" -#include "reftable/reftable-generic.h" #include "reftable/reftable-merged.h" #include "reftable/reftable-reader.h" #include "reftable/reftable-stack.h" @@ -33,7 +32,7 @@ static void print_help(void) "\n"); } -static int dump_table(struct reftable_table *tab) +static int dump_table(struct reftable_merged_table *mt) { struct reftable_iterator it = { NULL }; struct reftable_ref_record ref = { NULL }; @@ -41,13 +40,12 @@ static int dump_table(struct reftable_table *tab) const struct git_hash_algo *algop; int err; - reftable_table_init_ref_iter(tab, &it); - + reftable_merged_table_init_ref_iterator(mt, &it); err = reftable_iterator_seek_ref(&it, ""); if (err < 0) return err; - algop = &hash_algos[hash_algo_by_id(reftable_table_hash_id(tab))]; + algop = &hash_algos[hash_algo_by_id(reftable_merged_table_hash_id(mt))]; while (1) { err = reftable_iterator_next_ref(&it, &ref); @@ -77,8 +75,7 @@ static int dump_table(struct reftable_table *tab) reftable_iterator_destroy(&it); reftable_ref_record_release(&ref); - reftable_table_init_log_iter(tab, &it); - + reftable_merged_table_init_log_iterator(mt, &it); err = reftable_iterator_seek_log(&it, ""); if (err < 0) return err; @@ -118,15 +115,13 @@ static int dump_stack(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 = dump_table(&table); + err = dump_table(merged); done: if (stack) reftable_stack_destroy(stack); @@ -135,10 +130,12 @@ static int dump_stack(const char *stackdir, uint32_t hash_id) static int dump_reftable(const char *tablename) { - struct reftable_block_source src = { NULL }; - int err = reftable_block_source_from_file(&src, tablename); + struct reftable_block_source src = { 0 }; + struct reftable_merged_table *mt = NULL; struct reftable_reader *r = NULL; - struct reftable_table tab = { NULL }; + int err; + + err = reftable_block_source_from_file(&src, tablename); if (err < 0) goto done; @@ -146,9 +143,15 @@ static int dump_reftable(const char *tablename) if (err < 0) goto done; - reftable_table_from_reader(&tab, r); - err = dump_table(&tab); + err = reftable_merged_table_new(&mt, &r, 1, + reftable_reader_hash_id(r)); + if (err < 0) + goto done; + + err = dump_table(mt); + done: + reftable_merged_table_free(mt); reftable_reader_free(r); return err; } From patchwork Thu Aug 22 06:35: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: 13772719 Received: from fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.152]) (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 9A9DE1531DD for ; Thu, 22 Aug 2024 06:35:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.152 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724308534; cv=none; b=kDuZTmQDeKK1ijnEO9s3BnbSWyK6PaLieU1TnslXyd3KobYOwCITByks6CHiD8lHXjIM0bSEAuy6c7RUcL12UEZ3Xjik2C5oDddjZfx7x4t7NcouEEVMtk3VRqzpyPFKtLA+bH+A0rhnTg6KG6rLpkIOfYsDlW4020M4BMKZW6E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724308534; c=relaxed/simple; bh=oU8p9FYXWfXU19Bcbefcs8O2kCC8cDY43dXuk5nlswY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=cqkCScDJQM6iUyRienSAKsKUeDmEOtnRBP4GNlp0DS49i2c8N/d5R7L2aAzL9tD7DXT3ZaZie0PmBubOvwFBCRZFh8xC+2m9QRnLgwipvTJYWaCziPap4gnxPyOEVz418ptgjFpEL0Dx6M+BYdPYPtoMjsbrIKXAAYp23L/ipk0= 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=gk5Lvfiv; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=j+4pP+YF; arc=none smtp.client-ip=103.168.172.152 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="gk5Lvfiv"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="j+4pP+YF" Received: from phl-compute-02.internal (phl-compute-02.nyi.internal [10.202.2.42]) by mailfhigh.nyi.internal (Postfix) with ESMTP id BEC721151AF6; Thu, 22 Aug 2024 02:35:31 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Thu, 22 Aug 2024 02:35:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=fm1; t=1724308531; x=1724394931; bh=TD8ITKIMpy uKUcmkR4eZDrsevvHko7HwcZ4qC/BosjQ=; b=gk5LvfivDc2/bJbUeAaK/R8A4M KGyS7gDyCfGs6boJ75OSuSzYlSy7Cpv4K2t93aA2e8xQ4uMHycURDHUkkpnrpd5d Fz0Vvo3hlVBDgEF13izCEdWvHE8fU2u6I8PP/GXe+JPVrIMycS134CtmLEjMrdhS u+o+Nj1AY6zl+3eaWYlS7C51kWsyqaAmGVGqopo51vM5P5abGl2QvCIKzSRsHXs5 cjw2lsWLZmoXAz3GbJraizxt+PlNUJGqigrZYaX1uGUeukzI61AXgah0qUY5LuXq rD0SWWoivgf0Mbq9QMFfj7lAM6qaetfzpksjny2xQ1SjVy+hwIQcehkkyFVw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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= fm1; t=1724308531; x=1724394931; bh=TD8ITKIMpyuKUcmkR4eZDrsevvHk o7HwcZ4qC/BosjQ=; b=j+4pP+YF3ko4ZLZPn+3VkElU6xI6Yf9YVPSgkPX/tztb qp3S1XTDl+bjbSqmVkmORIA1GUHD5eTcRVilj8das+WEtbHg7VBmenoh7Z3GXyY5 DcKwDyXeAr9cm9Zg6N+SfDWsn7x0WlXV6yy21MWH5wJDGY2+LYPcwmwGHaxyoqAX /B2LkWBB9VPYC111h7V3ZVG7IbOQcn06EpVDgZTJduePmKSPqe9jdNveu8ABpyiD IPwtpd980yCV9cIIe6dx6RqBUSa/3M1ZpgZYw/XbY5gQ94KxxisvVbOH4Ipo0wEz Mi2jJ1kOGlgbLKUS8FgwI/1AaYRTFls6dPhALgjpTQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudduledgudduudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpeffhffvvefukfhfgggtuggjsehttdertddttddv necuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrih hmqeenucggtffrrghtthgvrhhnpeeuieeuudfhvefhkeeigfekgfegleejtdffteehheet hffhvdeludekkeffhfffvdenucffohhmrghinhepghhoohhglhgvrdgtohhmnecuvehluh hsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkhhsrdhi mhdpnhgspghrtghpthhtohepfedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepkh grrhhthhhikhdrudekkeesghhmrghilhdrtghomhdprhgtphhtthhopehjlhhtohgslhgv rhesghhmrghilhdrtghomhdprhgtphhtthhopehgihhtsehvghgvrhdrkhgvrhhnvghlrd horhhg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 22 Aug 2024 02:35:30 -0400 (EDT) Received: by vm-mail (OpenSMTPD) with ESMTPSA id e5b15d9f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 22 Aug 2024 06:34:56 +0000 (UTC) Date: Thu, 22 Aug 2024 08:35:29 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: karthik nayak , Justin Tobler Subject: [PATCH v3 15/15] reftable/generic: drop interface 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 `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 343f19a488b..41dfa0bad2c 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 495ee9af6b0..00000000000 --- 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 837fbb8df20..00000000000 --- 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 225feb78714..97a4642ed57 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 3b401f12590..befc4597df1 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 2e72eab3069..128a810c55d 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 fbd93b88dff..082cf00b606 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 b8b1323a331..00000000000 --- 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 03c2619c0ff..16d19f8df20 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 7c7d1716516..69621c5b0fc 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 bedd503e7e1..d3a95d2f1d7 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 577b1a5be87..93345c6c8be 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"