From mboxrd@z Thu Jan 1 00:00:00 1970 From: richard.maw at gmail.com (Richard Maw) Date: Fri, 15 Jul 2016 23:59:54 +0100 Subject: [PATCH 08/16] Add cgit_for_each_namespaced_ref_in helper In-Reply-To: <20160715230002.29547-1-richard.maw@gmail.com> References: <20160715230002.29547-1-richard.maw@gmail.com> Message-ID: <20160715230002.29547-9-richard.maw@gmail.com> libgit has a for_each_namespaced_ref, but lacks equivalents for just branches, tags or remotes. Rather than implementing all of those helpers, it's more convenient to implement just one that prepends the namespace to the provided ref base. Signed-off-by: Richard Maw --- cgit.h | 2 ++ shared.c | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/cgit.h b/cgit.h index 93de0ea..f0d25d6 100644 --- a/cgit.h +++ b/cgit.h @@ -394,4 +394,6 @@ extern char *get_mimetype_for_filename(const char *filename); extern int cgit_get_sha1(const char *name, unsigned char *sha1); +extern int cgit_for_each_namespaced_ref_in(const char *prefix, each_ref_fn fn, void *cb_data); + #endif /* CGIT_H */ diff --git a/shared.c b/shared.c index 81a5cd8..54940b3 100644 --- a/shared.c +++ b/shared.c @@ -651,3 +651,13 @@ int cgit_get_sha1(const char *name, unsigned char *sha1) return get_sha1(name, sha1); } } + +int cgit_for_each_namespaced_ref_in(const char *prefix, each_ref_fn fn, void *cb_data) +{ + struct strbuf strbuf = STRBUF_INIT; + int ret; + strbuf_addf(&strbuf, "%s%s", get_git_namespace(), prefix); + ret = for_each_ref_in(strbuf.buf, fn, cb_data); + strbuf_release(&strbuf); + return ret; +} -- 2.9.0