verify_lock(): return 0/-1 rather than struct ref_lock *

Its return value wasn't conveying any extra information, but it made the reader wonder whether the ref_lock that it returned might be different than the one that was passed to it. So change the function to the traditional "return 0 on success or a negative value on error". Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael Haggerty committed May 23, 2015 at 01:34 UTC a5e2499e5421c88ec2403087597613d60b8f3077
1 file changed +14 -7
refs.c
+14 -7
@@ -2218,9 +2218,14 @@ static void unlock_ref(struct ref_lock *lock)
2218 free(lock);
2219 }
2220
2221 -/* This function should make sure errno is meaningful on error */
2222 -static struct ref_lock *verify_lock(struct ref_lock *lock,
2223 - const unsigned char *old_sha1, int mustexist)
2221 +/*
2222 + * Verify that the reference locked by lock has the value old_sha1.
2223 + * Fail if the reference doesn't exist and mustexist is set. Return 0
2224 + * on success or a negative value on error. This function should make
2225 + * sure errno is meaningful on error.
2226 + */
2227 +static int verify_lock(struct ref_lock *lock,
2228 + const unsigned char *old_sha1, int mustexist)
2229 {
2230 if (read_ref_full(lock->ref_name,
2231 mustexist ? RESOLVE_REF_READING : 0,
@@ -2229,16 +2234,16 @@ static struct ref_lock *verify_lock(struct ref_lock *lock,
2234 error("Can't verify ref %s", lock->ref_name);
2235 unlock_ref(lock);
2236 errno = save_errno;
2232 - return NULL;
2237 + return -1;
2238 }
2239 if (hashcmp(lock->old_sha1, old_sha1)) {
2240 error("Ref %s is at %s but expected %s", lock->ref_name,
2241 sha1_to_hex(lock->old_sha1), sha1_to_hex(old_sha1));
2242 unlock_ref(lock);
2243 errno = EBUSY;
2239 - return NULL;
2244 + return -1;
2245 }
2241 - return lock;
2246 + return 0;
2247 }
2248
2249 static int remove_empty_directories(const char *file)
@@ -2466,7 +2471,9 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
2471 goto error_return;
2472 }
2473 }
2469 - return old_sha1 ? verify_lock(lock, old_sha1, mustexist) : lock;
2474 + if (old_sha1 && verify_lock(lock, old_sha1, mustexist))
2475 + return NULL;
2476 + return lock;
2477
2478 error_return:
2479 unlock_ref(lock);