Skip to content

Commit 3c0cb0c

Browse files
mhaggergitster
authored andcommitted
read_loose_refs(): read refs using resolve_ref_recursively()
There is no need to call read_ref_full() or resolve_gitlink_ref() from read_loose_refs(), because we already have a ref_store object in hand. So we can call resolve_ref_recursively() ourselves. Happily, this unifies the code for the submodule vs. non-submodule cases. This requires resolve_ref_recursively() to be exposed to the refs subsystem, though not to non-refs code. Signed-off-by: Michael Haggerty <[email protected]> Reviewed-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9c7d772 commit 3c0cb0c

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

refs.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,10 +1230,10 @@ int for_each_rawref(each_ref_fn fn, void *cb_data)
12301230
}
12311231

12321232
/* This function needs to return a meaningful errno on failure */
1233-
static const char *resolve_ref_recursively(struct ref_store *refs,
1234-
const char *refname,
1235-
int resolve_flags,
1236-
unsigned char *sha1, int *flags)
1233+
const char *resolve_ref_recursively(struct ref_store *refs,
1234+
const char *refname,
1235+
int resolve_flags,
1236+
unsigned char *sha1, int *flags)
12371237
{
12381238
static struct strbuf sb_refname = STRBUF_INIT;
12391239
int unused_flags;

refs/files-backend.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,20 +1267,10 @@ static void read_loose_refs(const char *dirname, struct ref_dir *dir)
12671267
create_dir_entry(refs, refname.buf,
12681268
refname.len, 1));
12691269
} else {
1270-
int read_ok;
1271-
1272-
if (refs->submodule) {
1273-
hashclr(sha1);
1274-
flag = 0;
1275-
read_ok = !resolve_gitlink_ref(refs->submodule,
1276-
refname.buf, sha1);
1277-
} else {
1278-
read_ok = !read_ref_full(refname.buf,
1279-
RESOLVE_REF_READING,
1280-
sha1, &flag);
1281-
}
1282-
1283-
if (!read_ok) {
1270+
if (!resolve_ref_recursively(&refs->base,
1271+
refname.buf,
1272+
RESOLVE_REF_READING,
1273+
sha1, &flag)) {
12841274
hashclr(sha1);
12851275
flag |= REF_ISBROKEN;
12861276
} else if (is_null_sha1(sha1)) {

refs/refs-internal.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,4 +650,9 @@ void base_ref_store_init(struct ref_store *refs,
650650
*/
651651
struct ref_store *get_ref_store(const char *submodule);
652652

653+
const char *resolve_ref_recursively(struct ref_store *refs,
654+
const char *refname,
655+
int resolve_flags,
656+
unsigned char *sha1, int *flags);
657+
653658
#endif /* REFS_REFS_INTERNAL_H */

0 commit comments

Comments
 (0)