Normally your own namespace is known and you only need to skip that prefix,
but when you need to classify the type of a ref
it helps to be able to consider what type of ref it would be
if it were outside of a namespace.
---
 git-compat-util.h | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/git-compat-util.h b/git-compat-util.h
index db9c22d..c5e0a34 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -501,6 +501,25 @@ static inline int skip_prefix_mem(const char *buf, size_t 
len,
        return 0;
 }
 
+static inline int skip_namespace(const char *refname, const char **out)
+{
+       const char *c = refname;
+
+       while (skip_prefix(c, "refs/namespaces/", &c)) {
+               c = strchr(c, '/');
+               if (!c)
+                       return 0;
+
+               c++;
+       }
+
+       if (c == refname)
+               return 0;
+
+       *out = c;
+       return 1;
+}
+
 /*
  * If buf ends with suffix, return 1 and subtract the length of the suffix
  * from *len. Otherwise, return 0 and leave *len untouched.
-- 
2.9.0

Reply via email to