[PATCH] ui-repolist: return HTTP 404 if no repositories found
Peter Colberg
peter at colberg.org
Mon Dec 7 20:28:09 CET 2015
---
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("<table summary='repository list' class='list nowrap'>");
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("</tr>\n");
}
html("</table>");
- 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
More information about the CGit
mailing list