git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/3] setup: initialize is_bare_cfg

From
John Cai via GitGitGadget <gitgitgadget@gmail.com>
Date
Nov 6, 2024, 20:48 UTC
Message-ID
<19c97feb06ef2f01f89b462678fe304b58fcba37.1730926082.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1826.git.git.1730926082.gitgitgadget@gmail.com>
From: John Cai <jcai@gitlab.com>

A subsequent commit will BUG() when the is_bare_cfg member is uninitialized. Since there are still some codepaths that initializing the is_bare_cfg variable, initialize them.

Signed-off-by: John Cai <johncai86@gmail.com>
---
 setup.c | 7 +++++++
 1 file changed, 7 insertions(+)
diff --git a/setup.c b/setup.c
index 6bc4aef3a8b..5680976c598 100644
--- a/setup.c
+++ b/setup.c
@@ -741,6 +741,7 @@ static int check_repository_format_gently(const char *gitdir, struct repository_
 
 	if (verify_repository_format(candidate, &err) < 0) {
 		if (nongit_ok) {
+			the_repository->is_bare_cfg = 1;
 			warning("%s", err.buf);
 			strbuf_release(&err);
 			*nongit_ok = -1;
@@ -1017,6 +1018,7 @@ static const char *setup_explicit_git_dir(const char *gitdirenv,
 		if (nongit_ok) {
 			*nongit_ok = 1;
 			free(gitfile);
+			the_repository->is_bare_cfg = 0;
 			return NULL;
 		}
 		die(_("not a git repository: '%s'"), gitdirenv);
@@ -1069,6 +1071,7 @@ static const char *setup_explicit_git_dir(const char *gitdirenv,
 
 	/* set_git_work_tree() must have been called by now */
 	worktree = repo_get_work_tree(the_repository);
+	the_repository->is_bare_cfg = 0;
 
 	/* both repo_get_work_tree() and cwd are already normalized */
 	if (!strcmp(cwd->buf, worktree)) { /* cwd == worktree */
@@ -1125,6 +1128,9 @@ static const char *setup_discovered_git_dir(const char *gitdir,
 
 	/* #0, #1, #5, #8, #9, #12, #13 */
 	set_git_work_tree(".");
+
+	if (the_repository->is_bare_cfg < 0)
+		the_repository->is_bare_cfg = 0;
 	if (strcmp(gitdir, DEFAULT_GIT_DIR_ENVIRONMENT))
 		set_git_dir(gitdir, 0);
 	inside_git_dir = 0;
@@ -1767,6 +1773,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
 			die(_("not a git repository (or any of the parent directories): %s"),
 			    DEFAULT_GIT_DIR_ENVIRONMENT);
 		*nongit_ok = 1;
+		the_repository->is_bare_cfg = 1;
 		break;
 	case GIT_DIR_HIT_MOUNT_POINT:
 		if (!nongit_ok)
-- 
gitgitgadget
Previous: shejialuoNext: Junio C Hamano
Message 7 of 11 in “Remove is_bare_repository_cfg global state”
  1. 0/3 Remove is_bare_repository_cfg global stateJohn Cai via GitGitGadget, Nov 6, 2024
  2. 1/3 git: remove is_bare_repository_cfg global variableJohn Cai via GitGitGadget, Nov 6, 2024
  3. Junio C HamanoNov 7, 2024
  4. shejialuoNov 7, 2024
  5. Junio C HamanoNov 8, 2024
  6. shejialuoNov 16, 2024
  7. 2/3 setup: initialize is_bare_cfgJohn Cai via GitGitGadget, Nov 6, 2024
  8. Junio C HamanoNov 7, 2024
  9. 3/3 repository: BUG when is_bare_cfg is not initializedJohn Cai via GitGitGadget, Nov 6, 2024
  10. Junio C HamanoNov 26, 2024
  11. (RFH Windows breakage) Re: [PATCH 0/3] Remove is_bare_repository_cfg global stateJunio C Hamano, Dec 11, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.