get_packed_ref(): return a ref_entry
Instead of copying the reference's SHA1 into a caller-supplied variable, just return the ref_entry itself (or NULL if there is no such entry). This change will allow the function to be used from elsewhere. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Apr 22, 2013 at 21:52 UTC
63331581aba9537a83d2e9fe21ffab305d9f8ad6
1 file changed
+9
-11
refs.c
+9
-11
@@ -1101,18 +1101,12 @@ int resolve_gitlink_ref(const char *path, const char *refname, unsigned char *sh
1101
}
1102
1103
/*
1104
- * Try to read ref from the packed references. On success, set sha1
1105
- * and return 0; otherwise, return -1.
1104
+ * Return the ref_entry for the given refname from the packed
1105
+ * references. If it does not exist, return NULL.
1106
*/
1107
-static int get_packed_ref(const char *refname, unsigned char *sha1)
1107
+static struct ref_entry *get_packed_ref(const char *refname)
1108
{
1109
- struct ref_dir *packed = get_packed_refs(get_ref_cache(NULL));
1110
- struct ref_entry *entry = find_ref(packed, refname);
1111
- if (entry) {
1112
- hashcpy(sha1, entry->u.value.sha1);
1113
- return 0;
1114
- }
1115
- return -1;
1109
+ return find_ref(get_packed_refs(get_ref_cache(NULL)), refname);
1110
}
1111
1112
const char *resolve_ref_unsafe(const char *refname, unsigned char *sha1, int reading, int *flag)
@@ -1140,13 +1134,17 @@ const char *resolve_ref_unsafe(const char *refname, unsigned char *sha1, int rea
1134
git_snpath(path, sizeof(path), "%s", refname);
1135
1136
if (lstat(path, &st) < 0) {
1137
+ struct ref_entry *entry;
1138
+
1139
if (errno != ENOENT)
1140
return NULL;
1141
/*
1142
* The loose reference file does not exist;
1143
* check for a packed reference.
1144
*/
1149
- if (!get_packed_ref(refname, sha1)) {
1145
+ entry = get_packed_ref(refname);
1146
+ if (entry) {
1147
+ hashcpy(sha1, entry->u.value.sha1);
1148
if (flag)
1149
*flag |= REF_ISPACKED;
1150
return refname;