Skip to content

Commit 62f0b39

Browse files
pcloudsgitster
authored andcommitted
refs: add refs_head_ref()
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 29babbe commit 62f0b39

2 files changed

Lines changed: 15 additions & 10 deletions

File tree

refs.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,27 +1248,30 @@ int refs_rename_ref_available(struct ref_store *refs,
12481248
return ok;
12491249
}
12501250

1251-
int head_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)
1251+
int refs_head_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data)
12521252
{
12531253
struct object_id oid;
12541254
int flag;
12551255

1256-
if (submodule) {
1257-
if (resolve_gitlink_ref(submodule, "HEAD", oid.hash) == 0)
1258-
return fn("HEAD", &oid, 0, cb_data);
1259-
1260-
return 0;
1261-
}
1262-
1263-
if (!read_ref_full("HEAD", RESOLVE_REF_READING, oid.hash, &flag))
1256+
if (!refs_read_ref_full(refs, "HEAD", RESOLVE_REF_READING,
1257+
oid.hash, &flag))
12641258
return fn("HEAD", &oid, flag, cb_data);
12651259

12661260
return 0;
12671261
}
12681262

1263+
int head_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)
1264+
{
1265+
struct ref_store *refs = get_submodule_ref_store(submodule);
1266+
1267+
if (!refs)
1268+
return -1;
1269+
return refs_head_ref(refs, fn, cb_data);
1270+
}
1271+
12691272
int head_ref(each_ref_fn fn, void *cb_data)
12701273
{
1271-
return head_ref_submodule(NULL, fn, cb_data);
1274+
return refs_head_ref(get_main_ref_store(), fn, cb_data);
12721275
}
12731276

12741277
struct ref_iterator *refs_ref_iterator_begin(

refs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ typedef int each_ref_fn(const char *refname,
275275
* modifies the reference also returns a nonzero value to immediately
276276
* stop the iteration. Returned references are sorted.
277277
*/
278+
int refs_head_ref(struct ref_store *refs,
279+
each_ref_fn fn, void *cb_data);
278280
int refs_for_each_ref(struct ref_store *refs,
279281
each_ref_fn fn, void *cb_data);
280282
int refs_for_each_ref_in(struct ref_store *refs, const char *prefix,

0 commit comments

Comments
 (0)