delete_ref(): handle special case more explicitly
[gitweb.git] / refs.c
diff --git a/refs.c b/refs.c
index 26d1ac1e32eb4fc4c6729abcf0354dbad6177d1b..9b7bdd4198efe43d4eec0c149e7d3127ffd354cc 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -2801,15 +2801,23 @@ static int delete_ref_loose(struct ref_lock *lock, int flag, struct strbuf *err)
        return 0;
 }
 
-int delete_ref(const char *refname, const unsigned char *sha1, unsigned int flags)
+int delete_ref(const char *refname, const unsigned char *old_sha1,
+              unsigned int flags)
 {
        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,
-                                  (sha1 && !is_null_sha1(sha1)) ? sha1 : NULL,
+           ref_transaction_delete(transaction, refname, old_sha1,
                                   flags, NULL, &err) ||
            ref_transaction_commit(transaction, &err)) {
                error("%s", err.buf);