resolve_missing_loose_ref(): simplify semantics

Make resolve_missing_loose_ref() only responsible for looking up a
packed reference, without worrying about whether we want to read or
write the reference and without setting errno on failure. Move the other
logic to the caller.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: David Turner <dturner@twopensource.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Michael Haggerty 2016-04-07 15:02:55 -04:00 committed by Junio C Hamano
parent 757552db57
commit 419c6f4c76

View File

@ -1368,11 +1368,9 @@ static struct ref_entry *get_packed_ref(const char *refname)
} }
/* /*
* A loose ref file doesn't exist; check for a packed ref. The * A loose ref file doesn't exist; check for a packed ref.
* options are forwarded from resolve_safe_unsafe().
*/ */
static int resolve_missing_loose_ref(const char *refname, static int resolve_missing_loose_ref(const char *refname,
int resolve_flags,
unsigned char *sha1, unsigned char *sha1,
int *flags) int *flags)
{ {
@ -1389,14 +1387,8 @@ static int resolve_missing_loose_ref(const char *refname,
*flags |= REF_ISPACKED; *flags |= REF_ISPACKED;
return 0; return 0;
} }
/* The reference is not a packed reference, either. */ /* refname is not a packed reference. */
if (resolve_flags & RESOLVE_REF_READING) { return -1;
errno = ENOENT;
return -1;
} else {
hashclr(sha1);
return 0;
}
} }
/* This function needs to return a meaningful errno on failure */ /* This function needs to return a meaningful errno on failure */
@ -1461,9 +1453,13 @@ static const char *resolve_ref_1(const char *refname,
if (lstat(path, &st) < 0) { if (lstat(path, &st) < 0) {
if (errno != ENOENT) if (errno != ENOENT)
return NULL; return NULL;
if (resolve_missing_loose_ref(refname, resolve_flags, if (resolve_missing_loose_ref(refname, sha1, flags)) {
sha1, flags)) if (resolve_flags & RESOLVE_REF_READING) {
return NULL; errno = ENOENT;
return NULL;
}
hashclr(sha1);
}
if (bad_name) { if (bad_name) {
hashclr(sha1); hashclr(sha1);
if (flags) if (flags)