summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2016-04-07 15:02:55 -0400
committerJunio C Hamano <gitster@pobox.com>2016-04-10 11:35:13 -0700
commit419c6f4c76c5950a33ed2cedbce9c6f7d66773f6 (patch)
treebd632defe38ae1d4747ad4e48f78a3868c1d0cc3
parent757552db5794056cdeccab827745f3de1fb82f4b (diff)
downloadgit-419c6f4c76c5950a33ed2cedbce9c6f7d66773f6.tar.gz
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>
-rw-r--r--refs/files-backend.c24
1 files changed, 10 insertions, 14 deletions
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 9676ec2fd1..c0cf6fd6c0 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -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
- * options are forwarded from resolve_safe_unsafe().
+ * A loose ref file doesn't exist; check for a packed ref.
*/
static int resolve_missing_loose_ref(const char *refname,
- int resolve_flags,
unsigned char *sha1,
int *flags)
{
@@ -1389,14 +1387,8 @@ static int resolve_missing_loose_ref(const char *refname,
*flags |= REF_ISPACKED;
return 0;
}
- /* The reference is not a packed reference, either. */
- if (resolve_flags & RESOLVE_REF_READING) {
- errno = ENOENT;
- return -1;
- } else {
- hashclr(sha1);
- return 0;
- }
+ /* refname is not a packed reference. */
+ return -1;
}
/* 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 (errno != ENOENT)
return NULL;
- if (resolve_missing_loose_ref(refname, resolve_flags,
- sha1, flags))
- return NULL;
+ if (resolve_missing_loose_ref(refname, sha1, flags)) {
+ if (resolve_flags & RESOLVE_REF_READING) {
+ errno = ENOENT;
+ return NULL;
+ }
+ hashclr(sha1);
+ }
if (bad_name) {
hashclr(sha1);
if (flags)