Skip to content

Commit e811530

Browse files
hanwengitster
authored andcommitted
refs: read FETCH_HEAD and MERGE_HEAD generically
The FETCH_HEAD and MERGE_HEAD refs must be stored in a file, regardless of the type of ref backend. This is because they can hold more than just a single ref. To accomodate them for alternate ref backends, read them from a file generically in refs_read_raw_ref() Signed-off-by: Han-Wen Nienhuys <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5085aef commit e811530

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

refs.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1634,11 +1634,37 @@ int for_each_rawref(each_ref_fn fn, void *cb_data)
16341634
return refs_for_each_rawref(get_main_ref_store(the_repository), fn, cb_data);
16351635
}
16361636

1637+
static int refs_read_special_head(struct ref_store *ref_store,
1638+
const char *refname, struct object_id *oid,
1639+
struct strbuf *referent, unsigned int *type)
1640+
{
1641+
struct strbuf full_path = STRBUF_INIT;
1642+
struct strbuf content = STRBUF_INIT;
1643+
int result = -1;
1644+
strbuf_addf(&full_path, "%s/%s", ref_store->gitdir, refname);
1645+
1646+
if (strbuf_read_file(&content, full_path.buf, 0) < 0)
1647+
goto done;
1648+
1649+
result = parse_loose_ref_contents(content.buf, oid, referent, type);
1650+
1651+
done:
1652+
strbuf_release(&full_path);
1653+
strbuf_release(&content);
1654+
return result;
1655+
}
1656+
16371657
int refs_read_raw_ref(struct ref_store *ref_store,
16381658
const char *refname, struct object_id *oid,
16391659
struct strbuf *referent, unsigned int *type)
16401660
{
1641-
return ref_store->be->read_raw_ref(ref_store, refname, oid, referent, type);
1661+
if (!strcmp(refname, "FETCH_HEAD") || !strcmp(refname, "MERGE_HEAD")) {
1662+
return refs_read_special_head(ref_store, refname, oid, referent,
1663+
type);
1664+
}
1665+
1666+
return ref_store->be->read_raw_ref(ref_store, refname, oid, referent,
1667+
type);
16421668
}
16431669

16441670
/* This function needs to return a meaningful errno on failure */

0 commit comments

Comments
 (0)