Skip to content

Commit

Permalink
verify_lock(): on errors, let the caller unlock the lock
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Michael Haggerty authored and Junio C Hamano committed May 27, 2015
1 parent a5e2499 commit f41d632
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2232,14 +2232,12 @@ static int verify_lock(struct ref_lock *lock,
lock->old_sha1, NULL)) {
int save_errno = errno;
error("Can't verify ref %s", lock->ref_name);
unlock_ref(lock);
errno = save_errno;
return -1;
}
if (hashcmp(lock->old_sha1, old_sha1)) {
error("Ref %s is at %s but expected %s", lock->ref_name,
sha1_to_hex(lock->old_sha1), sha1_to_hex(old_sha1));
unlock_ref(lock);
errno = EBUSY;
return -1;
}
Expand Down Expand Up @@ -2471,8 +2469,10 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,
goto error_return;
}
}
if (old_sha1 && verify_lock(lock, old_sha1, mustexist))
return NULL;
if (old_sha1 && verify_lock(lock, old_sha1, mustexist)) {
last_errno = errno;
goto error_return;
}
return lock;

error_return:
Expand Down

0 comments on commit f41d632

Please sign in to comment.