From patchwork Wed Mar 25 09:54:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 11457353 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 520D192A for ; Wed, 25 Mar 2020 09:54:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 286B62078D for ; Wed, 25 Mar 2020 09:54:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="ijOnzR3r"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="umKQaVsD" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727260AbgCYJyS (ORCPT ); Wed, 25 Mar 2020 05:54:18 -0400 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:55539 "EHLO out5-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726043AbgCYJyR (ORCPT ); Wed, 25 Mar 2020 05:54:17 -0400 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 665AC5C0227; Wed, 25 Mar 2020 05:54:16 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Wed, 25 Mar 2020 05:54:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm3; bh=qjE1dLyd86/2PFfowjUBjXBk9l+ Qv3TEJ4R+NS9QVbw=; b=ijOnzR3rWDrN0F0x5L86EaebKH06vYIYOCxBA01qm/E 0AVxiAgM7tLTidLXy1/reipimfI6xFZfsBVp16UDiuyY/uGltuXWekQ2h96sKIUM t9X7tR93Hf7f5LymZxINywGxJ3bQvsNMEokfQph3ESw77ZFNErnuUzq8cuBd6S2l jSAAcOuVbpPIdkN20mIElgVPwW0e4sFNZJw9cAc3FcH/P1w3IWPYB9R2nCKkPYTF rtKQq4LiBccrbMhpC3eNIA89ZNugjuv/w5Q2I2UAbVCsDxRb3dRNxDlHGRFb4Gnd 4urrIf/dLlWzDJ+pKcrDgpZv08OFsiEj9rqYJiwfTgQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=qjE1dL yd86/2PFfowjUBjXBk9l+Qv3TEJ4R+NS9QVbw=; b=umKQaVsD+JCblDiALgq40i NIXd6VYaLbImaVATcfSu1FQMWf8GKI1GsOfl4tj3mCTFgL/I8lVmWEPOuIYE67D6 oG/6gqRB5HLwl9A+bdCyrapwFqo405jvAVw+Xui7aWChE07X82Us3h4RwXcaMTwf ptHy3rr7+B2IICV1n6bwHm2Et1bmkq7sJrv8sAp8v3VJW//Qo/L8HDovj30Mqdcg zzaYQgR7eCHVUfUJcO0DfZiIgcWgZjXXxmEekwRN6kcrT/R7PVFpmCrCTwbHlAyL JoeosEH6YWacxl0QJ11Vy1Wh3eEKimXRweGDwgkUoejQe1zqryZL1TeOOEy9deHg == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrudehfedgtdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrghtrhhi tghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucfkphepjeejrddufe drudekhedrjedvnecuvehluhhsthgvrhfuihiivgepieenucfrrghrrghmpehmrghilhhf rhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Received: from vm-mail.pks.im (x4d0db948.dyn.telefonica.de [77.13.185.72]) by mail.messagingengine.com (Postfix) with ESMTPA id CDC57328005A; Wed, 25 Mar 2020 05:54:15 -0400 (EDT) Received: from localhost (ncase [10.192.0.11]) by vm-mail.pks.im (OpenSMTPD) with ESMTPSA id 9faa6cd2 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 25 Mar 2020 09:54:14 +0000 (UTC) Date: Wed, 25 Mar 2020 10:54:16 +0100 From: Patrick Steinhardt To: git Cc: Christian Couder Subject: [PATCH 7/9] update-ref: move transaction handling into `update_refs_stdin()` Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org While the actual logic to update the transaction is handled in `update_refs_stdin()`, the transaction itself is started and committed in `cmd_update_ref()` itself. This makes it hard to handle transaction abortion and commits as part of `update_refs_stdin()` itself, which is required in order to introduce transaction handling features to `git update-refs --stdin`. Refactor the code to move all transaction handling into `update_refs_stdin()` to prepare for transaction handling features. Signed-off-by: Patrick Steinhardt --- builtin/update-ref.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/builtin/update-ref.c b/builtin/update-ref.c index 6f036ae765..5f97bb0b75 100644 --- a/builtin/update-ref.c +++ b/builtin/update-ref.c @@ -346,15 +346,21 @@ static const struct parse_cmd { { "option", parse_cmd_option }, }; -static void update_refs_stdin(struct ref_transaction *transaction) +static void update_refs_stdin(void) { - struct strbuf input = STRBUF_INIT; + struct strbuf input = STRBUF_INIT, err = STRBUF_INIT; + struct ref_transaction *transaction; const char *next; int i; if (strbuf_read(&input, 0, 1000) < 0) die_errno("could not read from stdin"); next = input.buf; + + transaction = ref_transaction_begin(&err); + if (!transaction) + die("%s", err.buf); + /* Read each line dispatch its command */ while (next < input.buf + input.len) { const struct parse_cmd *cmd = NULL; @@ -382,6 +388,11 @@ static void update_refs_stdin(struct ref_transaction *transaction) next++; } + if (ref_transaction_commit(transaction, &err)) + die("%s", err.buf); + + ref_transaction_free(transaction); + strbuf_release(&err); strbuf_release(&input); } @@ -416,21 +427,11 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix) } if (read_stdin) { - struct strbuf err = STRBUF_INIT; - struct ref_transaction *transaction; - - transaction = ref_transaction_begin(&err); - if (!transaction) - die("%s", err.buf); if (delete || argc > 0) usage_with_options(git_update_ref_usage, options); if (end_null) line_termination = '\0'; - update_refs_stdin(transaction); - if (ref_transaction_commit(transaction, &err)) - die("%s", err.buf); - ref_transaction_free(transaction); - strbuf_release(&err); + update_refs_stdin(); return 0; }