From mboxrd@z Thu Jan 1 00:00:00 1970 From: richard.maw at gmail.com (Richard Maw) Date: Mon, 1 Aug 2016 22:35:41 +0100 Subject: [PATCH v3 09/21] Look up refs in namespace with cgit_get_sha1 In-Reply-To: <20160801213553.16807-1-richard.maw@gmail.com> References: <20160801213553.16807-1-richard.maw@gmail.com> Message-ID: <20160801213553.16807-10-richard.maw@gmail.com> 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 --- 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); } -- 2.9.0