From patchwork Thu Apr 2 07:09:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 11470195 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 0F56A15AB for ; Thu, 2 Apr 2020 07:09:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D7ACC2078B for ; Thu, 2 Apr 2020 07:09:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="NpDY+N3Q"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="XCYYyMPK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387538AbgDBHJu (ORCPT ); Thu, 2 Apr 2020 03:09:50 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:56341 "EHLO out3-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725789AbgDBHJt (ORCPT ); Thu, 2 Apr 2020 03:09:49 -0400 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 3B98F5C028F; Thu, 2 Apr 2020 03:09:48 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Thu, 02 Apr 2020 03:09:48 -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=O6AMiESRLD83K6zQxtKvWe18N/H t4Wi3hNEvQO1P7BU=; b=NpDY+N3QzES65ay6Yb0yrL8h6QMbtFOqnBgnmvv2leG FvDhKpAb3RhCt9LDkKJvIlT495pwBnUf1v4yeerpsEDkQx1A910O3tyX+LdecLAJ Tajzb7jx7/mC9XNNLJis7+8B+2mDn6J8cycutzEAyav+r097VQMH9X79E268+nTO wC6c4NbY7mDa7MJvSjPPNMGozDyxEpn0riIzNEhuLlF70jptchvdLZQGbCs+sKkh C8U7YkpYetOKUd6fW92jqv96QqyCi0IjLuOoLXOGLrj31p+C/JrK0w0gu4ApBVDx ysNAHq2Cr1RELCOC4CsZK8zzyYGoLHknO7Z+vGq6uzw== 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=O6AMiE SRLD83K6zQxtKvWe18N/Ht4Wi3hNEvQO1P7BU=; b=XCYYyMPKoogM3ZUsBrBHyR 5wfaLSyG+LVt4tcnPi9vmHkPcU9wbidIfxlsqVWnwWR4A9E+nLxiBsfRtPwfIqkN H8L4bkJnGlEtk54RFjug/YjGSaZoFedvm5SP8Dsn3X5aEc179AAkmoUc7fqwtYWj ozHRMoybBH+ixDB5/yhcjqnq/YnOJdYFrGw6/SQPNp+CDmNVhUa/SwlG+DCQyLxE /GX8CNVS4RB8jF21uBYfK4FISaYVug4jAIdJs/Oa7xWzLTqLD1R6LBOePbE3tKDP V3l1+/a8jCdreIeErLSaMMGdhUccigwIqZIXs2QqygqSypqg6UIUOlUqUZI9Ryjw == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedrtdefgdduudejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrghtrhhi tghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucfkphepkeelrdduvd drleegrddvkeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhr ohhmpehpshesphhkshdrihhm X-ME-Proxy: Received: from vm-mail.pks.im (x590c5e1c.dyn.telefonica.de [89.12.94.28]) by mail.messagingengine.com (Postfix) with ESMTPA id 87F5E306CD98; Thu, 2 Apr 2020 03:09:47 -0400 (EDT) Received: from localhost (ncase [10.192.0.11]) by vm-mail.pks.im (OpenSMTPD) with ESMTPSA id 45aaa4b8 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 2 Apr 2020 07:09:46 +0000 (UTC) Date: Thu, 2 Apr 2020 09:09:53 +0200 From: Patrick Steinhardt To: git Cc: Christian Couder , Junio C Hamano Subject: [PATCH v3 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 381d347fb4..0f34b68904 100644 --- a/builtin/update-ref.c +++ b/builtin/update-ref.c @@ -332,15 +332,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; @@ -367,6 +373,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); } @@ -401,21 +412,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; }