[PATCH v3 09/21] Look up refs in namespace with cgit_get_sha1

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

This causes all ref resolving to look for the requested branch
inside the current namespace.

Previously any form of git revision would be accepted,
but ref resolving isn't namespace aware
and it would be infeasible to replicate all its behaviour,
so we stick to providing the most common cases
of a sha1, an absolute ref, or a partial ref.

Signed-off-by: Richard Maw <richard.maw at gmail.com>
 shared.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/shared.c b/shared.c
index 77cb120..4c7bb9c 100644
--- a/shared.c
+++ b/shared.c
@@ -669,5 +669,19 @@ int cgit_namespaced_dwim_ref(const char *name, unsigned char *sha1, char **ref)
 int cgit_get_sha1(const char *name, unsigned char *sha1)
+	/* TODO: If libgit's get_sha1_with_context gains a flag for namespace support,
+	         change this function to call that appropriately. */
+	if (ctx.repo->namespace) {
+		/* If we have a namespace, we can get either a sha1,
+		   or a possibly abbreviated ref.
+		   Advanced ref forms are not supported at this time
+		   as this would require reimplementing all of ref parsing.
+		   If get_sha1_with_context grows support for a namespaced flag
+		   then this code may go away. */
+		if (get_sha1_hex(name, sha1) == 0)
+			return 0;
+		return cgit_namespaced_dwim_ref(name, sha1, NULL) == 0;
+	}
 	return get_sha1(name, sha1);

More information about the CGit mailing list