]> granicus.if.org Git - cgit/commitdiff
Add cgit_for_each_namespaced_ref_in helper
authorRichard Maw <richard.maw@gmail.com>
Sat, 25 Jun 2016 21:49:35 +0000 (22:49 +0100)
committerRichard Maw <richard.maw@gmail.com>
Wed, 13 Jul 2016 19:09:37 +0000 (20:09 +0100)
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>
cgit.h
shared.c

diff --git a/cgit.h b/cgit.h
index 93de0ea7bd4c6ed06f3eec089f29739db1cd632b..f0d25d65a2d1942a211f63e7792f118aeb0fa41e 100644 (file)
--- 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 */
index 81a5cd8ecac3479fb7cb832855e0682ad78849cd..54940b302e2725cd542e65c878fcd07127c22a4a 100644 (file)
--- 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;
+}