[PATCH v3 13/21] Add cgit_for_each_namespaced_ref_in helper

Richard Maw richard.maw at gmail.com
Mon Aug 1 23:35:45 CEST 2016


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 at gmail.com>
---
 cgit.h   |  2 ++
 shared.c | 11 +++++++++++
 2 files changed, 13 insertions(+)

diff --git a/cgit.h b/cgit.h
index f4c444e..e915490 100644
--- a/cgit.h
+++ b/cgit.h
@@ -398,4 +398,6 @@ extern int cgit_namespaced_dwim_ref(const char *name, unsigned char *sha1, char
 
 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 4c7bb9c..687aa4a 100644
--- a/shared.c
+++ b/shared.c
@@ -685,3 +685,14 @@ 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)
+{
+	/* TODO: If libgit gets a for_each_namespaced_ref_in then remove this */
+	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



More information about the CGit mailing list