From patchwork Mon Mar 30 13:46:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 11465547 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 6CE53913 for ; Mon, 30 Mar 2020 13:46:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4A5E92073B for ; Mon, 30 Mar 2020 13:46:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="Bse7eXCX"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Bpwc3FqI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728541AbgC3Nqw (ORCPT ); Mon, 30 Mar 2020 09:46:52 -0400 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]:49943 "EHLO wout4-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726028AbgC3Nqw (ORCPT ); Mon, 30 Mar 2020 09:46:52 -0400 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 2126C3AA; Mon, 30 Mar 2020 09:46:51 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Mon, 30 Mar 2020 09:46:51 -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=rvkbuvO/T48iVrK35BqJQX1qixd Qr/h01VE4EvYSVSY=; b=Bse7eXCXnYoBY8NDk7bLiEvPnmPS7/j5po12OXovGir R+/lnyomTSSOguEokgTqByypYij+SAICxiSYcCJ+EXXFiO6s2Lhddlf7MezPPbX7 SIEylvk/uJRnBrulXFSZAerILGwd14irYONyUDa/iucSTt9d9bAm+BGs6B5SzFld lM633Gg0rAQ/7R2IxxA5Uczlwoh4dK9zfwipb8hmO/aUqt2flpwijCBsNogzJwZx 0mqBV40xA6wxMEhwNQ9bNcMTyS0xoQvcvrrqGmw9fzZuiiirTISVIoKQoEEUMi65 Odrw83cq9J6nMMf7LpyEcqYXfq4iu2pPmL7da8JSAXA== 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=rvkbuv O/T48iVrK35BqJQX1qixdQr/h01VE4EvYSVSY=; b=Bpwc3FqIGFrcRAby1MPjKY VTE7UUq4X8EuUh8lNyxpYH99wKlpNqGQcEmMm1bsBeO3THBki7tEakj5T6ckk9fm VMfm6HMAWIYf2CZan0Se31jTBp6XalgkbUHCI5Geo11J/OGKhbz78RLlceHSsyT8 kxWXsBA7EtDM8HU3DV4PEGD7TmFok0nh4LCERq4kRT4qv/ewoaPVX0soBK+A8dUw Xpw/4FK8XGhVhwxmvmv1cgKDElRrpnCsm8tV+0bjq+StFXYvmC6MtHlwR1AUMAiw vpS5/gntKiKB2Ey+6tQ6csXjbCffP7PFAwGsK5fg2ZpwXuVUprLbdK4RBEYUM/Pg == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrudeihedgieekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefrrghtrhhi tghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucfkphepjeekrdehge drvddvtddruddtvdenucevlhhushhtvghrufhiiigvpeejnecurfgrrhgrmhepmhgrihhl fhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Received: from vm-mail.pks.im (x4e36dc66.dyn.telefonica.de [78.54.220.102]) by mail.messagingengine.com (Postfix) with ESMTPA id 0E4233280064; Mon, 30 Mar 2020 09:46:49 -0400 (EDT) Received: from localhost (ncase [10.192.0.11]) by vm-mail.pks.im (OpenSMTPD) with ESMTPSA id 794be5cf (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 30 Mar 2020 13:46:48 +0000 (UTC) Date: Mon, 30 Mar 2020 15:46:52 +0200 From: Patrick Steinhardt To: git Cc: Christian Couder , Junio C Hamano Subject: [PATCH v2 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 139c3b11fa..1a7906545d 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; @@ -389,6 +395,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); } @@ -423,21 +434,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; }