Skip to content

Commit a5e2499

Browse files
mhaggergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fae46aa commit a5e2499

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

refs.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2218,9 +2218,14 @@ static void unlock_ref(struct ref_lock *lock)
22182218
free(lock);
22192219
}
22202220

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)
22242229
{
22252230
if (read_ref_full(lock->ref_name,
22262231
mustexist ? RESOLVE_REF_READING : 0,
@@ -2229,16 +2234,16 @@ static struct ref_lock *verify_lock(struct ref_lock *lock,
22292234
error("Can't verify ref %s", lock->ref_name);
22302235
unlock_ref(lock);
22312236
errno = save_errno;
2232-
return NULL;
2237+
return -1;
22332238
}
22342239
if (hashcmp(lock->old_sha1, old_sha1)) {
22352240
error("Ref %s is at %s but expected %s", lock->ref_name,
22362241
sha1_to_hex(lock->old_sha1), sha1_to_hex(old_sha1));
22372242
unlock_ref(lock);
22382243
errno = EBUSY;
2239-
return NULL;
2244+
return -1;
22402245
}
2241-
return lock;
2246+
return 0;
22422247
}
22432248

22442249
static int remove_empty_directories(const char *file)
@@ -2466,7 +2471,9 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
24662471
goto error_return;
24672472
}
24682473
}
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;
24702477

24712478
error_return:
24722479
unlock_ref(lock);

0 commit comments

Comments
 (0)