verify_lock(): on errors, let the caller unlock the lock
The caller already knows how to do it, so always do it in the same place. 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
f41d6329704a8c3f7286f52c3589d381ac0bc79d
1 file changed
+4
-4
refs.c
+4
-4
@@ -2232,14 +2232,12 @@ static int verify_lock(struct ref_lock *lock,
2232
lock->old_sha1, NULL)) {
2233
int save_errno = errno;
2234
error("Can't verify ref %s", lock->ref_name);
2235
- unlock_ref(lock);
2235
errno = save_errno;
2236
return -1;
2237
}
2238
if (hashcmp(lock->old_sha1, old_sha1)) {
2239
error("Ref %s is at %s but expected %s", lock->ref_name,
2240
sha1_to_hex(lock->old_sha1), sha1_to_hex(old_sha1));
2242
- unlock_ref(lock);
2241
errno = EBUSY;
2242
return -1;
2243
}
@@ -2471,8 +2469,10 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
2469
goto error_return;
2470
}
2471
}
2474
- if (old_sha1 && verify_lock(lock, old_sha1, mustexist))
2475
- return NULL;
2472
+ if (old_sha1 && verify_lock(lock, old_sha1, mustexist)) {
2473
+ last_errno = errno;
2474
+ goto error_return;
2475
+ }
2476
return lock;
2477
2478
error_return: