Signed-off-by: Nguyễn Thái Ngọc Duy <pclo...@gmail.com> --- refs.c | 39 +++++++++++++++++++++++++++++++-------- refs.h | 5 +++++ 2 files changed, 36 insertions(+), 8 deletions(-)
diff --git a/refs.c b/refs.c index fc6cca3db..37b03d4ff 100644 --- a/refs.c +++ b/refs.c @@ -300,34 +300,52 @@ void warn_dangling_symrefs(FILE *fp, const char *msg_fmt, const struct string_li for_each_rawref(warn_if_dangling_symref, &data); } +int refs_for_each_tag_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data) +{ + return refs_for_each_ref_in(refs, "refs/tags/", fn, cb_data); +} + int for_each_tag_ref(each_ref_fn fn, void *cb_data) { - return for_each_ref_in("refs/tags/", fn, cb_data); + return refs_for_each_tag_ref(get_main_ref_store(), fn, cb_data); } int for_each_tag_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data) { - return for_each_ref_in_submodule(submodule, "refs/tags/", fn, cb_data); + return refs_for_each_tag_ref(get_submodule_ref_store(submodule), + fn, cb_data); +} + +int refs_for_each_branch_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data) +{ + return refs_for_each_ref_in(refs, "refs/heads/", fn, cb_data); } int for_each_branch_ref(each_ref_fn fn, void *cb_data) { - return for_each_ref_in("refs/heads/", fn, cb_data); + return refs_for_each_branch_ref(get_main_ref_store(), fn, cb_data); } int for_each_branch_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data) { - return for_each_ref_in_submodule(submodule, "refs/heads/", fn, cb_data); + return refs_for_each_branch_ref(get_submodule_ref_store(submodule), + fn, cb_data); +} + +int refs_for_each_remote_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data) +{ + return refs_for_each_ref_in(refs, "refs/remotes/", fn, cb_data); } int for_each_remote_ref(each_ref_fn fn, void *cb_data) { - return for_each_ref_in("refs/remotes/", fn, cb_data); + return refs_for_each_remote_ref(get_main_ref_store(), fn, cb_data); } int for_each_remote_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data) { - return for_each_ref_in_submodule(submodule, "refs/remotes/", fn, cb_data); + return refs_for_each_remote_ref(get_submodule_ref_store(submodule), + fn, cb_data); } int head_ref_namespaced(each_ref_fn fn, void *cb_data) @@ -1200,10 +1218,15 @@ int for_each_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data) "", fn, 0, 0, cb_data); } +int refs_for_each_ref_in(struct ref_store *refs, const char *prefix, + each_ref_fn fn, void *cb_data) +{ + return do_for_each_ref(refs, prefix, fn, strlen(prefix), 0, cb_data); +} + int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data) { - return do_for_each_ref(get_main_ref_store(), - prefix, fn, strlen(prefix), 0, cb_data); + return refs_for_each_ref_in(get_main_ref_store(), prefix, fn, cb_data); } int for_each_fullref_in(const char *prefix, each_ref_fn fn, void *cb_data, unsigned int broken) diff --git a/refs.h b/refs.h index 8e3b4e839..8fc82deda 100644 --- a/refs.h +++ b/refs.h @@ -575,5 +575,10 @@ int refs_read_ref(struct ref_store *refs, const char *refname, unsigned char *sha1); 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, + each_ref_fn fn, void *cb_data); +int refs_for_each_tag_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data); +int refs_for_each_branch_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data); +int refs_for_each_remote_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data); #endif /* REFS_H */ -- 2.11.0.157.gd943d85