Add cgit_for_each_namespaced_ref_in helper

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 <richard.maw@gmail.com>
This commit is contained in:
Richard Maw 2016-06-25 22:49:35 +01:00
parent d25bfb99f9
commit 5817a8f703
2 changed files with 12 additions and 0 deletions

2
cgit.h
View File

@ -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 */

View File

@ -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;
}