[PATCH] Return "404 Not found" if a repo doesn't exist (any more).

Adam Sjøgren asjo at koldfront.dk
Sat Dec 1 23:02:17 CET 2012


If a repository disappears, cgit says "No repositories found" and
returns "200 OK" [to the webcrawler] for pages referring to, say,
commits in the, now, missing repository.

This, slightly awkward, patch makes it return "404 Not found" in this
case. There is probably a better way to do this.

---
 ui-repolist.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/ui-repolist.c b/ui-repolist.c
index dead1bf..ca65d44 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -247,6 +247,17 @@ void cgit_print_repolist()
 	if (ctx.cfg.enable_index_links)
 		columns++;
 
+	for (i=0; i<cgit_repolist.count; i++) {
+		if (!(is_match(&cgit_repolist.repos[i]) && is_in_url(&cgit_repolist.repos[i])))
+			continue;
+		hits++;
+        }
+
+	if (!hits) {
+                ctx.page.status = 404;
+                ctx.page.statusmsg = "Not found";
+        }
+
 	ctx.page.title = ctx.cfg.root_title;
 	cgit_print_http_headers(&ctx);
 	cgit_print_docstart(&ctx);
-- 
1.7.2.5

-- 
 "Tell them to give it to Donovan."                           Adam Sjøgren
                                                         asjo at koldfront.dk





More information about the CGit mailing list