about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-02-12 23:23:47 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2018-02-12 23:25:29 +0100
commit03f6e34bb9d683723cfc4fe58ee5bb983b95e173 (patch)
tree70167b3349351bfb5e189267e4390d33b3474f1f
parentui-blame: Allow syntax highlighting (diff)
downloadcgit-pink-03f6e34bb9d683723cfc4fe58ee5bb983b95e173.tar.gz
cgit-pink-03f6e34bb9d683723cfc4fe58ee5bb983b95e173.zip
cgit: prepare repo before error pages
This fixes a crash when showing a list of all heads in the <select> box
in the header.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to '')
-rw-r--r--cgit.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/cgit.c b/cgit.c
index a3702c2..bd9cb3f 100644
--- a/cgit.c
+++ b/cgit.c
@@ -561,12 +561,8 @@ static void print_no_repo_clone_urls(const char *url)
         html("</a></td></tr>\n");
 }
 
-static int prepare_repo_cmd(void)
+static void prepare_repo_env(int *nongit)
 {
-	struct object_id oid;
-	int nongit = 0;
-	int rc;
-
 	/* The path to the git repository. */
 	setenv("GIT_DIR", ctx.repo->path, 1);
 
@@ -579,8 +575,13 @@ static int prepare_repo_cmd(void)
 	/* Setup the git directory and initialize the notes system. Both of these
 	 * load local configuration from the git repository, so we do them both while
 	 * the HOME variables are unset. */
-	setup_git_directory_gently(&nongit);
+	setup_git_directory_gently(nongit);
 	init_display_notes(NULL);
+}
+static int prepare_repo_cmd(int nongit)
+{
+	struct object_id oid;
+	int rc;
 
 	if (nongit) {
 		const char *name = ctx.repo->name;
@@ -700,6 +701,7 @@ static inline void authenticate_cookie(void)
 static void process_request(void)
 {
 	struct cgit_cmd *cmd;
+	int nongit = 0;
 
 	/* If we're not yet authenticated, no matter what page we're on,
 	 * display the authentication body from the auth_filter. This should
@@ -715,6 +717,9 @@ static void process_request(void)
 		return;
 	}
 
+	if (ctx.repo)
+		prepare_repo_env(&nongit);
+
 	cmd = cgit_get_cmd();
 	if (!cmd) {
 		ctx.page.title = "cgit error";
@@ -740,7 +745,7 @@ static void process_request(void)
 	 */
 	ctx.qry.vpath = cmd->want_vpath ? ctx.qry.path : NULL;
 
-	if (ctx.repo && prepare_repo_cmd())
+	if (ctx.repo && prepare_repo_cmd(nongit))
 		return;
 
 	cmd->fn();
00'>2022-07-13Set push.autoSetupRemoteJune McEnroe 2022-07-08Remove TOURJune McEnroe There is not that much distinct stuff here anymore. 2022-07-03Add The Bone Shard EmperorJune McEnroe Suffers a little bit from middle book but I really enjoyed it. Read it faster than the first one too, despite its length. 2022-06-25Bump xterm font size to 12June McEnroe 2022-06-10Handle subshells (and functions) inside substitutionsJune McEnroe 2022-06-10Switch to jorts Install scriptJune McEnroe 2022-06-08Indicate if still reading or no resultsJune McEnroe 2022-06-08Add Maiden, Mother, CroneJune McEnroe Mixed bag like most collections of short stories. Some of them are pretty good. The author of the worst written story also has the worst written bio. 2022-06-05FIRST SHOW IN 2.5 YEARS BABEY!!!June McEnroe 2022-06-03Set line number on File linesJune McEnroe 2022-06-03Stop polling stdin after EOFJune McEnroe 2022-06-02Set TABSIZE=4June McEnroe Absolutely indiscriminately. 2022-06-02Do basic match highlightingJune McEnroe 2022-06-02Clean up parsing a littleJune McEnroe 2022-06-02Don't duplicate path stringJune McEnroe 2022-06-02Use stderr instead of /dev/tty, realloc buffer if lines too longJune McEnroe For some reason I haven't been able to figure out, trying to poll /dev/tty returns POLLNVAL (and this was using 100% CPU looping), but using stderr instead works fine. 2022-06-02Add initial working version of qfJune McEnroe 2022-05-29Set prompt for okshJune McEnroe