Re: [PATCH v2 03/12] delete_ref(): handle special case more explicitly
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jun 15, 2015, 18:22 UTC
- Message-ID
- <xmqqbnggal2a.fsf@gitster.dls.corp.google.com>
- In-Reply-To
- <0c66a6bd6e49b9c28fa3617ee50de746ef4ea9a3.1434206062.git.mhagger@alum.mit.edu>
Michael Haggerty <mhagger@alum.mit.edu> writes:
Show 8 quoted lines
> delete_ref() uses a different convention for its old_sha1 parameter > than, say, ref_transaction_delete(): NULL_SHA1 means not to check the > old value. Make this fact a little bit clearer in the code by handling > it in explicit, commented code rather than burying it in a conditional > expression. > > Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> > ---
I think this is a very sensible first step, but I wonder if delete_ref() should be taught the difference between "we do not expect anything" and "we expect it not to exist".
Show 27 quoted lines
> refs.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/refs.c b/refs.c
> index b575bb8..f0b6cec 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -2795,10 +2795,17 @@ int delete_ref(const char *refname, const unsigned char *old_sha1,
> struct ref_transaction *transaction;
> struct strbuf err = STRBUF_INIT;
>
> + /*
> + * Treat NULL_SHA1 and NULL alike, to mean "we don't care what
> + * the old value of the reference was (or even if it didn't
> + * exist)":
> + */
> + if (old_sha1 && is_null_sha1(old_sha1))
> + old_sha1 = NULL;
> +
> transaction = ref_transaction_begin(&err);
> if (!transaction ||
> - ref_transaction_delete(transaction, refname,
> - (old_sha1 && !is_null_sha1(old_sha1)) ? old_sha1 : NULL,
> + ref_transaction_delete(transaction, refname, old_sha1,
> flags, NULL, &err) ||
> ref_transaction_commit(transaction, &err)) {
> error("%s", err.buf);