From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jonathan Nieder Subject: [PATCH 02/20] refs.c: update ref_transaction_delete to check for error and return status Date: Tue, 26 Aug 2014 17:29:44 -0700 Message-ID: <20140827002944.GC20185@google.com> References: <20140820231723.GF20185@google.com> <20140826000354.GW20185@google.com> <20140826221448.GY20185@google.com> <20140827002804.GA20185@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 Wed Aug 27 02:29:54 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 1XMR7Z-0005KM-Qv for gcvg-git-2@plane.gmane.org; Wed, 27 Aug 2014 02:29:54 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756011AbaH0A3u (ORCPT ); Tue, 26 Aug 2014 20:29:50 -0400 Received: from mail-pd0-f174.google.com ([209.85.192.174]:55039 "EHLO mail-pd0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755893AbaH0A3t (ORCPT ); Tue, 26 Aug 2014 20:29:49 -0400 Received: by mail-pd0-f174.google.com with SMTP id fp1so23554574pdb.19 for ; Tue, 26 Aug 2014 17:29:49 -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=a7YdeiCzFmHrOF960O3aSkLH+0GuZSFzBdKCZ83K27M=; b=LCN6SSKG9RRM6Wynn1Cnxu+VSM4U2k3T94L58+mNhtMT5gf8z81r33wfYHHHAWWqHD r0Fg0TJwrSTnPfGFpEkDImDu6aqYb19oYbVSi+pbywgHhNz0dIenRzhUs6k6N14DCFuA 9lev0BrAwbZJfNrBogX+p6tHi4x0uKDWJ46pWkvq950va3u70ErZXY65UIlxgHvp9hNW nB5YKn+MNwacKSG/e4DqLuT6HqekMk7ZrCy+Ub6n4fLFLJOkASwl3TiVt6gEe/CP3rg4 c2FSzcgVBD4t8apuW1VaRYb7eUSQNjtzPf/lZbMSf4o6o0Oeph9V+rH8q/HQTmg+CZjc Ld+A== X-Received: by 10.68.65.101 with SMTP id w5mr37147786pbs.5.1409099389279; Tue, 26 Aug 2014 17:29:49 -0700 (PDT) Received: from google.com ([2620:0:1000:5b00:4ba:9bd4:148:77e4]) by mx.google.com with ESMTPSA id to4sm4515849pbc.39.2014.08.26.17.29.46 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 26 Aug 2014 17:29:47 -0700 (PDT) Content-Disposition: inline In-Reply-To: <20140827002804.GA20185@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 of 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 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