diff options
| -rw-r--r-- | source/cgit.c | 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -rw-r--r-- | source/cgit.h | 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -rw-r--r-- | source/cgit.mk | 1 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -rw-r--r-- | source/ui-empty.c | 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -rw-r--r-- | source/ui-empty.h | 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -rw-r--r-- | source/ui-shared.c | 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
6 files changed, 70 insertions, 20 deletions
diff --git a/source/cgit.c b/source/cgit.c index 412d5f3..1ab77a4 100644 --- a/source/cgit.c +++ b/source/cgit.c @@ -16,6 +16,7 @@ #include "ui-shared.h" #include "ui-stats.h" #include "ui-blob.h" +#include "ui-empty.h" #include "ui-summary.h" #include "scan-tree.h" @@ -603,17 +604,6 @@ static void choose_readme(struct cgit_repo *repo) string_list_append(&repo->readme, filename)->util = ref; } -static void print_no_repo_clone_urls(const char *url) -{ - html("<tr><td><a rel='vcs-git' href='"); - html_url_path(url); - html("' title='"); - html_attr(ctx.repo->name); - html(" Git repository'>"); - html_txt(url); - html("</a></td></tr>\n"); -} - static void prepare_repo_env(int *nongit) { /* The path to the git repository. */ @@ -656,16 +646,15 @@ static int prepare_repo_cmd(int nongit) } if (!ctx.qry.head) { + ctx.empty_repo = 1; + // Before the document starts, since the <head> carries + // <link rel='vcs-git'> and those clone urls expand macros such + // as $CGIT_REPO_URL out of this environment. + cgit_prepare_repo_env(ctx.repo); cgit_print_http_headers(); cgit_print_docstart(); cgit_print_pageheader(); - cgit_print_error("Repository seems to be empty"); - if (!strcmp(ctx.qry.page, "summary")) { - html("<table class='list'><tr class='nohover'><td> </td></tr><tr class='nohover'><th class='left'>Clone</th></tr>\n"); - cgit_prepare_repo_env(ctx.repo); - cgit_add_clone_urls(print_no_repo_clone_urls); - html("</table>\n"); - } + cgit_print_empty_repo(); cgit_print_docend(); return 1; } diff --git a/source/cgit.h b/source/cgit.h index c41854e..d33a46b 100644 --- a/source/cgit.h +++ b/source/cgit.h @@ -318,6 +318,9 @@ struct cgit_context { struct cgit_config cfg; struct cgit_repo *repo; struct cgit_page page; + // Set once the repository is known to hold no commits, so the page + // header can drop the tabs that cannot render anything. + int empty_repo; }; typedef int (*write_archive_fn_t)(const char *, const char *); diff --git a/source/cgit.mk b/source/cgit.mk index b2d7dfc..3234148 100644 --- a/source/cgit.mk +++ b/source/cgit.mk @@ -106,6 +106,7 @@ CGIT_OBJ_NAMES += ui-blob.o CGIT_OBJ_NAMES += ui-clone.o CGIT_OBJ_NAMES += ui-commit.o CGIT_OBJ_NAMES += ui-diff.o +CGIT_OBJ_NAMES += ui-empty.o CGIT_OBJ_NAMES += ui-log.o CGIT_OBJ_NAMES += ui-patch.o CGIT_OBJ_NAMES += ui-plain.o diff --git a/source/ui-empty.c b/source/ui-empty.c new file mode 100644 index 0000000..cb91fbc --- /dev/null +++ b/source/ui-empty.c @@ -0,0 +1,41 @@ +/* + * ui-empty.c: page shown for a repository that holds no commits + * + * Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com> + * + * Licensed under GNU General Public License v2 + * (see LICENSE.txt for full license text) + */ + +#include "cgit.h" +#include "ui-empty.h" +#include "html.h" +#include "ui-shared.h" + +static void print_clone_url(const char *url) +{ + html("<tr><td><a rel='vcs-git' href='"); + html_url_path(url); + html("' title='"); + html_attr(ctx.repo->name); + html(" Git repository'>"); + html_txt(url); + html("</a></td></tr>\n"); +} + +/* + * The caller has already prepared the repo environment, which the clone urls + * need for macro expansion. + */ +void cgit_print_empty_repo(void) +{ + cgit_print_error("Repository seems to be empty"); + + if (!ctx.repo->clone_url && !ctx.cfg.clone_prefix) + return; + + html("<table summary='clone urls' class='list nowrap'>"); + html("<tr class='nohover'><th class='left'>Clone</th></tr>\n"); + cgit_add_clone_urls(print_clone_url); + html("</table>\n"); +} diff --git a/source/ui-empty.h b/source/ui-empty.h new file mode 100644 index 0000000..dda303a --- /dev/null +++ b/source/ui-empty.h @@ -0,0 +1,6 @@ +#ifndef UI_EMPTY_H +#define UI_EMPTY_H + +extern void cgit_print_empty_repo(void); + +#endif /* UI_EMPTY_H */ diff --git a/source/ui-shared.c b/source/ui-shared.c index d023243..e53d1e5 100644 --- a/source/ui-shared.c +++ b/source/ui-shared.c @@ -1086,7 +1086,9 @@ static void print_header(void) html_txt(ctx.cfg.root_title); html("</h1>\n"); - if (ctx.repo && ctx.env.authenticated) { + // A repository with no commits has no branches to list, so the + // switcher would be an empty select next to a switch button. + if (ctx.repo && ctx.env.authenticated && !ctx.empty_repo) { html("<form class='branch-switch' method='get'>\n"); cgit_add_hidden_formfields(0, 1, ctx.qry.page); html("<select name='h' aria-label='Branch' data-autosubmit='1'>\n"); @@ -1127,7 +1129,15 @@ void cgit_print_pageheader(void) if (ctx.env.authenticated) html("<nav class='tabs'>\n"); - if (ctx.env.authenticated && ctx.repo) { + if (ctx.env.authenticated && ctx.repo && ctx.empty_repo) { + // Every other tab needs a commit to render, and the search form + // has nothing to search, so a repository with no commits gets + // summary alone rather than a row of links to the same notice. + html("<ul>\n<li>"); + cgit_summary_link("summary", "Repository summary", hc("summary"), + ctx.qry.head); + html("</li>\n</ul>\n"); + } else if (ctx.env.authenticated && ctx.repo) { const char *vp = ctx.qry.vpath; html("<ul>\n"); if (ctx.repo->readme.nr) { |
