1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-06-08 14:46:11 +02:00

delete_ref(): handle special case more explicitly

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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Michael Haggerty 2015-06-22 16:02:54 +02:00 committed by Junio C Hamano
parent b4c4af832b
commit fc67a0825c

11
refs.c
View File

@ -2807,10 +2807,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);