aboutsummaryrefslogtreecommitdiff
diff options
from:
to:
context:
space:
mode:
authorGravatar Saya Andy <saya.andy@posteo.com> 2026-07-30 12:24:02 +0700
committerGravatar Saya Andy <saya.andy@posteo.com> 2026-07-30 12:24:02 +0700
commitdbed2ecdf824d154f7d69a624013a02e6e0966be (patch)
tree1f6458384bdc31b2fc30de0b920e22805a933e01
parent26fbed3bc58600adc092ab41e094e0fcae60f3b2 (diff)
downloadcgitext-dbed2ecdf824d154f7d69a624013a02e6e0966be.tar.gz
cgitext-dbed2ecdf824d154f7d69a624013a02e6e0966be.zip
ui-shared: don't list branches when there is no repository
print_header() fills the branch switcher from the main ref store whenever ctx.repo is set. For a request which prints a page before prepare_repo_cmd() has cleared ctx.repo -- an unknown page name for a repository whose repo.path is broken, for instance -- the ref store has never been initialized, and get_main_ref_store() aborts after the response has already begun: BUG: refs.c:2301: reference backend is unknown get_main_ref_store print_header at ui-shared.c:1057 cgit_print_error_page(fmt="Invalid request") Add cgit_have_repository() to say whether the repository for this request was opened, and skip the switcher when it was not. Signed-off-by: Saya Andy <saya.andy@posteo.com>
-rw-r--r--cgit.h2
-rw-r--r--shared.c12
-rw-r--r--ui-shared.c2
3 files changed, 15 insertions, 1 deletions
diff --git a/cgit.h b/cgit.h
index 7d7ece7..b8b7712 100644
--- a/cgit.h
+++ b/cgit.h
@@ -334,6 +334,8 @@ extern struct cgit_repo *cgit_get_repoinfo(const char *url);
extern void cgit_repo_config(struct cgit_repo *repo, const char *name,
const char *value);
+extern int cgit_have_repository(void);
+
extern int chk_zero(int result, char *msg);
extern int chk_positive(int result, char *msg);
extern int chk_non_negative(int result, char *msg);
diff --git a/shared.c b/shared.c
index a39394d..e79c3da 100644
--- a/shared.c
+++ b/shared.c
@@ -13,6 +13,18 @@
struct cgit_repolist cgit_repolist;
struct cgit_context ctx;
+/* Returns true when the git repository belonging to this request was opened
+ * successfully. Some requests print a page for a repository which could not
+ * be opened, e.g. because repo.path is wrong, and the object database and
+ * ref stores must not be touched in that case: they would abort with
+ * "reference backend is unknown" or dereference the not yet known hash
+ * algorithm.
+ */
+int cgit_have_repository(void)
+{
+ return startup_info->have_repository;
+}
+
int chk_zero(int result, char *msg)
{
if (result != 0)
diff --git a/ui-shared.c b/ui-shared.c
index 9f7625c..a6a828d 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -1042,7 +1042,7 @@ static void print_header(void)
cgit_index_link("index", NULL, NULL, NULL, NULL, 0, 1);
html(" : ");
cgit_summary_link(ctx.repo->name, NULL, NULL, NULL);
- if (ctx.env.authenticated) {
+ if (ctx.env.authenticated && cgit_have_repository()) {
html("</td><td class='form'>");
html("<form method='get'>\n");
cgit_add_hidden_formfields(0, 1, ctx.qry.page);