[PATCH v3 16/21] Add namespace support to dumb-clone

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


This requires namespacing the HEAD symbolic ref
and the list of refs.

Sending HEAD required some tweaking,
since the file itself refers to a namespaced ref,
but we want to provide the ref with its namespace stripped off.

Signed-off-by: Richard Maw <richard.maw at gmail.com>
---
 ui-clone.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/ui-clone.c b/ui-clone.c
index 5f6606a..14380bf 100644
--- a/ui-clone.c
+++ b/ui-clone.c
@@ -85,7 +85,9 @@ void cgit_clone_info(void)
 	ctx.page.mimetype = "text/plain";
 	ctx.page.filename = "info/refs";
 	cgit_print_http_headers();
-	for_each_ref(print_ref_info, NULL);
+	/* NOTE: we pass an empty prefix because we want to enumerate everything
+	   not just all refs under $namespace/refs/ */
+	cgit_for_each_namespaced_ref_in("", print_ref_info, NULL);
 }
 
 void cgit_clone_objects(void)
@@ -105,5 +107,17 @@ void cgit_clone_objects(void)
 
 void cgit_clone_head(void)
 {
-	send_file(git_path("%s", "HEAD"));
+	unsigned char unused[20];
+	char *ref = cgit_namespaced_resolve_ref("HEAD", 0, unused, NULL);
+
+	if (!ref) {
+		cgit_print_error_page(404, "Not found", "Not found");
+		return;
+	}
+
+	ctx.page.mimetype = "application/octet-stream";
+	ctx.page.filename = xstrdup("HEAD");
+	cgit_print_http_headers();
+	htmlf("ref: %s\n", strip_namespace(ref));
+	free(ref);
 }
-- 
2.9.0



More information about the CGit mailing list