diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2017-08-23 19:36:55 +0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-08-24 14:47:31 -0700 |
commit | 62f0b399e00f38751834e688677ab49fcccd28fe (patch) | |
tree | 414855e81317cc367d0e6edc5bb066835af5b6ff | |
parent | 29babbeeb32fb4e8b892940e69207ec7de2e7a63 (diff) | |
download | git-62f0b399e00f38751834e688677ab49fcccd28fe.tar.gz |
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>
-rw-r--r-- | refs.c | 23 | ||||
-rw-r--r-- | refs.h | 2 |
2 files changed, 15 insertions, 10 deletions
@@ -1248,27 +1248,30 @@ int refs_rename_ref_available(struct ref_store *refs, return ok; } -int head_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data) +int refs_head_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data) { struct object_id oid; int flag; - if (submodule) { - if (resolve_gitlink_ref(submodule, "HEAD", oid.hash) == 0) - return fn("HEAD", &oid, 0, cb_data); - - return 0; - } - - if (!read_ref_full("HEAD", RESOLVE_REF_READING, oid.hash, &flag)) + if (!refs_read_ref_full(refs, "HEAD", RESOLVE_REF_READING, + oid.hash, &flag)) return fn("HEAD", &oid, flag, cb_data); return 0; } +int head_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data) +{ + struct ref_store *refs = get_submodule_ref_store(submodule); + + if (!refs) + return -1; + return refs_head_ref(refs, fn, cb_data); +} + int head_ref(each_ref_fn fn, void *cb_data) { - return head_ref_submodule(NULL, fn, cb_data); + return refs_head_ref(get_main_ref_store(), fn, cb_data); } struct ref_iterator *refs_ref_iterator_begin( @@ -275,6 +275,8 @@ typedef int each_ref_fn(const char *refname, * modifies the reference also returns a nonzero value to immediately * stop the iteration. Returned references are sorted. */ +int refs_head_ref(struct ref_store *refs, + each_ref_fn fn, void *cb_data); int refs_for_each_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data); int refs_for_each_ref_in(struct ref_store *refs, const char *prefix, |