From mboxrd@z Thu Jan 1 00:00:00 1970 From: peter at colberg.org (Peter Colberg) Date: Mon, 7 Dec 2015 14:28:09 -0500 Subject: [PATCH] ui-repolist: return HTTP 404 if no repositories found In-Reply-To: <1449516489-2091-1-git-send-email-peter@colberg.org> References: <1449516489-2091-1-git-send-email-peter@colberg.org> Message-ID: <1449516489-2091-2-git-send-email-peter@colberg.org> --- ui-repolist.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/ui-repolist.c b/ui-repolist.c index a2e9e07..f86c6b7 100644 --- a/ui-repolist.c +++ b/ui-repolist.c @@ -106,6 +106,15 @@ static int is_in_url(struct cgit_repo *repo) return 0; } +static int is_visible(struct cgit_repo *repo) +{ + if (repo->hide || repo->ignore) + return 0; + if (!(is_match(repo) && is_in_url(repo))) + return 0; + return 1; +} + static void print_sort_header(const char *title, const char *sort) { char *currenturl = cgit_currenturl(); @@ -252,10 +261,23 @@ static int sort_repolist(char *field) void cgit_print_repolist(void) { - int i, columns = 3, hits = 0, header = 0; + int i, columns = 3, found = 0, hits = 0, header = 0; char *last_section = NULL; char *section; int sorted = 0; + struct cgit_repo *repo; + + for (i = 0; i < cgit_repolist.count; i++) { + repo = &cgit_repolist.repos[i]; + if (is_visible(repo)) { + found = 1; + break; + } + } + if (!found) { + cgit_print_error_page(404, "Not found", "No repositories found"); + return; + } if (ctx.cfg.enable_index_links) ++columns; @@ -278,9 +300,7 @@ void cgit_print_repolist(void) html(""); for (i = 0; i < cgit_repolist.count; i++) { ctx.repo = &cgit_repolist.repos[i]; - if (ctx.repo->hide || ctx.repo->ignore) - continue; - if (!(is_match(ctx.repo) && is_in_url(ctx.repo))) + if (!is_visible(ctx.repo)) continue; hits++; if (hits <= ctx.qry.ofs) @@ -340,9 +360,7 @@ void cgit_print_repolist(void) html("\n"); } html("
"); - if (!hits) - cgit_print_error("No repositories found"); - else if (hits > ctx.cfg.max_repo_count) + if (hits > ctx.cfg.max_repo_count) print_pager(hits, ctx.cfg.max_repo_count, ctx.qry.search, ctx.qry.sort); cgit_print_docend(); } -- 2.6.2