Thread (30 messages) flat view 30 messages, 4 authors, 2016-06-15
STALE3730d

Revision v1 of 2 in this series.

Revisions (2)
  1. v1 current
  2. v2 [diff vs current]

[PATCH 03/13] delete_ref(): handle special case more explicitly

From: Michael Haggerty <hidden>
Date: 2016-06-15 23:05:11
Subsystem: the rest · Maintainer: Linus Torvalds

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 <redacted>
---
 refs.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/refs.c b/refs.c
index b575bb8..f9d87b6 100644
--- a/refs.c
+++ b/refs.c
@@ -2795,10 +2795,13 @@ int delete_ref(const char *refname, const unsigned char *old_sha1,
 	struct ref_transaction *transaction;
 	struct strbuf err = STRBUF_INIT;
 
+	/* Treat NULL_SHA1 as "don't care" */
+	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);
-- 
2.1.4
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help