From patchwork Thu Feb 1 07:52:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13540763 Received: from wfhigh3-smtp.messagingengine.com (wfhigh3-smtp.messagingengine.com [64.147.123.154]) (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 7AB531586FE for ; Thu, 1 Feb 2024 07:52:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.154 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706773930; cv=none; b=urL96k/MjqqYvMk4OXBVLiTZdaqX2Rx5J8DKyRlr/mJaX63gpzxcQX9Cy2+l9B6N1HTPZyQB6+NObEwRBCC3bGD3NF1Pqly2ec5rYX53YahtK19mR9M96ZYWwVMIu1hY7gU1f7pN0ESUDOQLtTA2himFcztZxDr9X0xVrPrNi7g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706773930; c=relaxed/simple; bh=cbX34zuD64EuECwd3TsXdFD3/b8P9/v/p2nmTe1YxEs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=goRELJsfc9H+UrIJrr+6Lz3tiTrfsrC7QfEu9izREZ9Nq/BOYC+PcyGnprlD9Ep/N4/dasxF+8YqDfZ7SA2zaQ7isa0/p/hRzSD30SLD9EJTOKWaktLfMNopgKQb731baRkGpb3Aad2AtmAKBCop6un75EEY54c5Xsk2o8dUCBk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none 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=QKag0iiP; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=WO1Lv6Sp; arc=none smtp.client-ip=64.147.123.154 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none 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="QKag0iiP"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="WO1Lv6Sp" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfhigh.west.internal (Postfix) with ESMTP id 2D94F180007C; Thu, 1 Feb 2024 02:52:08 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Thu, 01 Feb 2024 02:52:08 -0500 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=fm3; t=1706773927; x=1706860327; bh=IFt0NGLBHF AUz1Wj8tfSBcQpb4lj0WEM+nLD5hv7Knc=; b=QKag0iiP9/BpIthAG6l1Lg3HFP g4rbAqT3142as0GYTBrizHo/41bcXVPrD0f5p+IobXk170+SK+BZ6CnO0Y7MjoIA /qNMw34yf/B4abImGCJgTyJ5hxZCoCSribcC/3s4pter8X1JWaB1UgscpK/N8zOh PhUcMJqdSUzwsMA/zRgvLElV7PdFi5nGtlKBLsYio0O/I5KuwRcjv5AIVyUd23q7 flGqaUoG/vzsxDBHem5xwUVCHChDELurgdIyzvxDjbeXAKiiTqxCC2qjMDajUelj yev+NM6ncTh67JETQJTjlZZq/fbnGgUo3XF8H/a4eiyLddrY565VSYvn0bgw== 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= fm3; t=1706773927; x=1706860327; bh=IFt0NGLBHFAUz1Wj8tfSBcQpb4lj 0WEM+nLD5hv7Knc=; b=WO1Lv6SpbfCJs67xIGqhIdEXwmwNvdCyJeH2QsXQCgT7 I0m2fR8uRLJrPvEcZSulR+2VDhRuVXCmB5s+X5LG0O2tG/Y4L0J76kUoYDhvS9BJ VvAtyXodfp8Oz8aXAIR+qX8ig+ZQa/XtxbizqjM6C3z9C7IjZcQ9fQgCpraUKaMn QT+gqfcHFJlrmg8LLzleNq2Esr7zO8OAfh0W6QHGf1ddJMPSHn34oPRElyiwdE0J KQmU8hLR7WGNoQimFVR587NbC/6Fp3U9NqrWi7FjRYY/kPbtc0/TzsLNAo6SdRw3 GMAo/UNwVC/uxSDQnmH74gnSfshc4ijv6oGEUzClRg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrfedutddgudduudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrght rhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtth gvrhhnpeeukedtvedtffevleejtefgheehieegkeeluddvfeefgeehgfeltddtheejleff teenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpsh esphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 1 Feb 2024 02:52:06 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 8d790735 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 1 Feb 2024 07:48:44 +0000 (UTC) Date: Thu, 1 Feb 2024 08:52:04 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Toon Claes , Kristoffer Haugsbakk Subject: [PATCH v2 3/5] reftable/writer: simplify writing index 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: When finishing the current section some index records might be written for the section to the table. The logic that adds these records to the writer duplicates what we already have in `writer_add_record()`, making this more complicated than it really has to be. Simplify the code by using `writer_add_record()` instead. While at it, drop the unneeded braces around a loop to make the code conform to our code style better. Signed-off-by: Patrick Steinhardt --- reftable/writer.c | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/reftable/writer.c b/reftable/writer.c index 5a0b87b406..b5bcce0292 100644 --- a/reftable/writer.c +++ b/reftable/writer.c @@ -412,26 +412,14 @@ static int writer_finish_section(struct reftable_writer *w) .idx = idx[i], }, }; - if (block_writer_add(w->block_writer, &rec) == 0) { - continue; - } - err = writer_flush_block(w); + err = writer_add_record(w, &rec); if (err < 0) return err; - - writer_reinit_block_writer(w, BLOCK_TYPE_INDEX); - - err = block_writer_add(w->block_writer, &rec); - if (err != 0) { - /* write into fresh block should always succeed - */ - abort(); - } } - for (i = 0; i < idx_len; i++) { + + for (i = 0; i < idx_len; i++) strbuf_release(&idx[i].last_key); - } reftable_free(idx); }