From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jonathan Nieder Subject: [PATCH 02/22] refs.c: update ref_transaction_delete to check for error and return status Date: Tue, 2 Sep 2014 14:00:15 -0700 Message-ID: <20140902210015.GC18279@google.com> References: <20140820231723.GF20185@google.com> <20140826000354.GW20185@google.com> <20140826221448.GY20185@google.com> <20140827002804.GA20185@google.com> <20140902205841.GA18279@google.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Ronnie Sahlberg , "git@vger.kernel.org" , Michael Haggerty To: Junio C Hamano X-From: git-owner@vger.kernel.org Tue Sep 02 23:00:27 2014 Return-path: Envelope-to: gcvg-git-2@plane.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XOvBi-0000oN-IP for gcvg-git-2@plane.gmane.org; Tue, 02 Sep 2014 23:00:26 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755255AbaIBVAU (ORCPT ); Tue, 2 Sep 2014 17:00:20 -0400 Received: from mail-pd0-f170.google.com ([209.85.192.170]:53408 "EHLO mail-pd0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755231AbaIBVAT (ORCPT ); Tue, 2 Sep 2014 17:00:19 -0400 Received: by mail-pd0-f170.google.com with SMTP id r10so9463937pdi.15 for ; Tue, 02 Sep 2014 14:00:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=Pp3AlUdByIjYOMDhUJXSzRAOhrrKEnpM+MkK9dbl8+o=; b=Ogjg/Gs5WPzeow1Ay9PX/kziz69IUdkKo8XOKLKsI/zsy1489aaHcfgqconsWuc7qk 3YlG6axCAxtPE27tTc59HhNb28F1IAWSH005ORFMn8Ih+NLbvbGJRE5YHjnMoiB9OTAa Sl2w+6mcxvtwoxjejb/DY3Vo23Xxf7s9DpS0WSWUgDDax7k9Q+oc3lQEy3QtTtv2u97I cyNGBbBS5BlP+kQHMREAS2ZDOtND2SODB/3wnrC3k+LqqAusnGuR7uJs6+E2Hg15m5XQ bBGc9MWIDDTNXPB9+HBv4cFjiORnGu8QWgRfvleaYPezwIKH6NMOyzJ9LYzRySSff+2e 4L7A== X-Received: by 10.70.45.97 with SMTP id l1mr8171403pdm.148.1409691618986; Tue, 02 Sep 2014 14:00:18 -0700 (PDT) Received: from google.com (aiede.mtv.corp.google.com [172.27.69.120]) by mx.google.com with ESMTPSA id cf4sm4821538pbb.87.2014.09.02.14.00.17 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 02 Sep 2014 14:00:18 -0700 (PDT) Content-Disposition: inline In-Reply-To: <20140902205841.GA18279@google.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: From: Ronnie Sahlberg Date: Wed, 16 Apr 2014 15:27:45 -0700 Change ref_transaction_delete() to do basic error checking and return non-zero on error. Update all callers to check the return for ref_transaction_delete(). There are currently no conditions in _delete that will return error but there will be in the future. Add an err argument that will be updated on failure. Signed-off-by: Ronnie Sahlberg Reviewed-by: Michael Haggerty Signed-off-by: Jonathan Nieder --- builtin/update-ref.c | 5 +++-- refs.c | 16 +++++++++++----- refs.h | 12 ++++++++---- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/builtin/update-ref.c b/builtin/update-ref.c index 41121fa..7c9c248 100644 --- a/builtin/update-ref.c +++ b/builtin/update-ref.c @@ -258,8 +258,9 @@ static const char *parse_cmd_delete(struct strbuf *input, const char *next) if (*next != line_termination) die("delete %s: extra input: %s", refname, next); - ref_transaction_delete(transaction, refname, old_sha1, - update_flags, have_old); + if (ref_transaction_delete(transaction, refname, old_sha1, + update_flags, have_old, &err)) + die("%s", err.buf); update_flags = 0; free(refname); diff --git a/refs.c b/refs.c index c49f1c6..40f04f4 100644 --- a/refs.c +++ b/refs.c @@ -3469,19 +3469,25 @@ int ref_transaction_create(struct ref_transaction *transaction, return 0; } -void ref_transaction_delete(struct ref_transaction *transaction, - const char *refname, - const unsigned char *old_sha1, - int flags, int have_old) +int ref_transaction_delete(struct ref_transaction *transaction, + const char *refname, + const unsigned char *old_sha1, + int flags, int have_old, + struct strbuf *err) { - struct ref_update *update = add_update(transaction, refname); + struct ref_update *update; + if (have_old && !old_sha1) + die("BUG: have_old is true but old_sha1 is NULL"); + + update = add_update(transaction, refname); update->flags = flags; update->have_old = have_old; if (have_old) { assert(!is_null_sha1(old_sha1)); hashcpy(update->old_sha1, old_sha1); } + return 0; } int update_ref(const char *action, const char *refname, diff --git a/refs.h b/refs.h index b648819..71389a1 100644 --- a/refs.h +++ b/refs.h @@ -308,11 +308,15 @@ int ref_transaction_create(struct ref_transaction *transaction, * Add a reference deletion to transaction. If have_old is true, then * old_sha1 holds the value that the reference should have had before * the update (which must not be the null SHA-1). + * Function returns 0 on success and non-zero on failure. A failure to delete + * means that the transaction as a whole has failed and will need to be + * rolled back. */ -void ref_transaction_delete(struct ref_transaction *transaction, - const char *refname, - const unsigned char *old_sha1, - int flags, int have_old); +int ref_transaction_delete(struct ref_transaction *transaction, + const char *refname, + const unsigned char *old_sha1, + int flags, int have_old, + struct strbuf *err); /* * Commit all of the changes that have been queued in transaction, as -- 2.1.0.rc2.206.gedb03e5