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

Re: [Outreachy PATCH v5 3/3] environment: move "branch.autoSetupMerge" into `struct repo_config_values`

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 30, 2026, 20:15 UTC
Message-ID
<xmqq5x8i7t7j.fsf@gitster.g>
In-Reply-To
<xmqqikcj842o.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
Show 11 quoted lines
> So, we need to take it as a given that repo_config_values_init()
> needs to exist.  Under that condition, I wonder if we can somehow
> have a cheap way to assert the following two things:
>
>  * Before a repository instance is used, repo_config_values_init()
>    has been called on it, as using an instance without initializing
>    is a no-no.
>
>  * repo_config_values_init() is never called twice on a repository
>    instance, as the second call will wipe what the first call and
>    subsequent reading of the configuration files have done.

Something like this squashed into your [1/3] would give us these two assertions, but I am not sure if it is a good idea or if I am overly paranoid.

The main ideas are:
 * "struct repository" now knows if it has been initialized via its
   "bool initialized" member.
 * "initialize_repository()" detects double initialization of the
   repository struct itself.
 * "repo_config_values" member in "struct repository" has been
   renamed to make it clear it is "private", and there is an
   accessor function of the same name.  It barfs if you ask the
   address of repo_config_values in a repository instance that
   hasn't been initialized.
 * Any code outside what implement the above are supposed to call
   repo_config_values() on the repository they are working in, to
   request the address of the repo_config_values instance to use.

It didn't barf when I ran all the tests, which means there isn't anybody who calls initialize_repository() twice in the current code.

I am not sure if this is being overly paranoid, or exercising a reasonable caution, but anyway,...

 attr.c        |  3 ++-
 environment.c |  2 +-
 environment.h |  3 +++
 repository.c  | 13 ++++++++++++-
 repository.h  |  5 ++++-
 5 files changed, 22 insertions(+), 4 deletions(-)
diff --git c/attr.c w/attr.c
index b8b70e6dce..cd39e6d2bf 100644
--- c/attr.c
+++ w/attr.c
@@ -881,7 +881,8 @@ const char *git_attr_system_file(void)
 
 const char *git_attr_global_file(void)
 {
-	struct repo_config_values *cfg = &the_repository->config_values;
+	struct repo_config_values *cfg = repo_config_values(the_repository);
+
 	if (!cfg->attributes_file)
 		cfg->attributes_file = xdg_config_home("attributes");
 
diff --git c/environment.c w/environment.c
index c876589b05..208a52ce11 100644
--- c/environment.c
+++ w/environment.c
@@ -302,7 +302,7 @@ static enum fsync_component parse_fsync_components(const char *var, const char *
 int git_default_core_config(const char *var, const char *value,
 			    const struct config_context *ctx, void *cb)
 {
-	struct repo_config_values *cfg = &the_repository->config_values;
+	struct repo_config_values *cfg = repo_config_values(the_repository);
 
 	/* This needs a better name */
 	if (!strcmp(var, "core.filemode")) {
diff --git c/environment.h w/environment.h
index 2b861a61de..254fec6b7c 100644
--- c/environment.h
+++ w/environment.h
@@ -84,11 +84,14 @@ extern const char * const local_repo_env[];
 
 struct strvec;
 
+struct repository;
 struct repo_config_values {
 	/* section "core" config values */
 	char *attributes_file;
 };
 
+struct repo_config_values *repo_config_values(struct repository *);
+
 /*
  * Wrapper of getenv() that returns a strdup value. This value is kept
  * in argv to be freed later.
diff --git c/repository.c w/repository.c
index d308cd78bf..4cb487b5b2 100644
--- c/repository.c
+++ w/repository.c
@@ -50,14 +50,25 @@ static void set_default_hash_algo(struct repository *repo)
 	repo_set_hash_algo(repo, algo);
 }
 
+struct repo_config_values *repo_config_values(struct repository *repo)
+{
+	if (!repo->initialized)
+		BUG("config values from uninitialied repository?");
+	return &repo->config_values_private_;
+}
+
 void initialize_repository(struct repository *repo)
 {
+	if (repo->initialized)
+		BUG("repository initialized already!");
+	repo->initialized = true;
+
 	repo->remote_state = remote_state_new();
 	repo->parsed_objects = parsed_object_pool_new(repo);
 	ALLOC_ARRAY(repo->index, 1);
 	index_state_init(repo->index, repo);
 	repo->check_deprecated_config = true;
-	repo_config_values_init(&repo->config_values);
+	repo_config_values_init(repo_config_values(repo));
 
 	/*
 	 * When a command runs inside a repository, it learns what
diff --git c/repository.h w/repository.h
index 638a142577..9717e45000 100644
--- c/repository.h
+++ w/repository.h
@@ -150,7 +150,7 @@ struct repository {
 	const struct git_hash_algo *compat_hash_algo;
 
 	/* Repository's config values parsed by git_default_config() */
-	struct repo_config_values config_values;
+	struct repo_config_values config_values_private_;
 
 	/* Repository's reference storage format, as serialized on disk. */
 	enum ref_storage_format ref_storage_format;
@@ -175,6 +175,9 @@ struct repository {
 
 	/* Should repo_config() check for deprecated settings */
 	bool check_deprecated_config;
+
+	/* Has this repository instance been initialized? */
+	bool initialized;
 };
 
 #ifdef USE_THE_REPOSITORY_VARIABLE
Previous: Junio C HamanoNext: Bello Olamide
Message 47 of 71 in “store git_default_config() parsed values in new config struct”
  1. 0/3 store git_default_config() parsed values in new config structOlamide Caleb Bello, Jan 12, 2026
  2. 1/3 environment: stop storing `core.attributesFile` globallyOlamide Caleb Bello, Jan 12, 2026
  3. Phillip WoodJan 12, 2026
  4. Bello OlamideJan 12, 2026
  5. 2/3 environment: stop using core.sparseCheckout globallyOlamide Caleb Bello, Jan 12, 2026
  6. 3/3 environment: move "branch.autoSetupMerge" into `struct config_values`Olamide Caleb Bello, Jan 12, 2026
  7. 0/3 store git_default_config() parsed values in new config structOlamide Caleb Bello, Jan 13, 2026
  8. 1/3 environment: stop storing `core.attributesFile` globallyOlamide Caleb Bello, Jan 13, 2026
  9. Junio C HamanoJan 13, 2026
  10. Bello OlamideJan 14, 2026
  11. 2/3 environment: environment: stop using core.sparseCheckout globallyOlamide Caleb Bello, Jan 13, 2026
  12. Junio C HamanoJan 13, 2026
  13. Bello OlamideJan 14, 2026
  14. 3/3 environment: move "branch.autoSetupMerge" into `struct repo_config_values`Olamide Caleb Bello, Jan 13, 2026
  15. Junio C HamanoJan 13, 2026
  16. Bello OlamideJan 14, 2026
  17. Bello OlamideJan 15, 2026
  18. 0/3 store repo specific config values in new `struct repo_config_values`Olamide Caleb Bello, Jan 17, 2026
  19. 1/3 environment: stop storing `core.attributesFile` globallyOlamide Caleb Bello, Jan 17, 2026
  20. Toon ClaesJan 22, 2026
  21. Bello OlamideJan 22, 2026
  22. Phillip WoodJan 22, 2026
  23. Bello OlamideJan 22, 2026
  24. 2/3 environment: environment: stop using core.sparseCheckout globallyOlamide Caleb Bello, Jan 17, 2026
  25. Toon ClaesJan 22, 2026
  26. Bello OlamideJan 22, 2026
  27. Phillip WoodJan 22, 2026
  28. Bello OlamideJan 22, 2026
  29. Phillip WoodJan 23, 2026
  30. Bello OlamideJan 23, 2026
  31. 3/3 environment: move "branch.autoSetupMerge" into `struct repo_config_values`Olamide Caleb Bello, Jan 17, 2026
  32. Phillip WoodJan 22, 2026
  33. Bello OlamideJan 22, 2026
  34. Bello OlamideJan 20, 2026
  35. 0/3 store repo specific config values in new `struct repo_config_values`Olamide Caleb Bello, Jan 24, 2026
  36. 1/3 environment: stop storing `core.attributesFile` globallyOlamide Caleb Bello, Jan 24, 2026
  37. 2/3 environment: stop using core.sparseCheckout globallyOlamide Caleb Bello, Jan 24, 2026
  38. 3/3 environment: move "branch.autoSetupMerge" into `struct repo_config_values`Olamide Caleb Bello, Jan 24, 2026
  39. 0/3 store repo specific config values in new `struct repo_config_values`Olamide Caleb Bello, Jan 24, 2026
  40. 1/3 environment: stop storing `core.attributesFile` globallyOlamide Caleb Bello, Jan 24, 2026
  41. Junio C HamanoJan 29, 2026
  42. 2/3 environment: stop using core.sparseCheckout globallyOlamide Caleb Bello, Jan 24, 2026
  43. Junio C HamanoJan 29, 2026
  44. 3/3 environment: move "branch.autoSetupMerge" into `struct repo_config_values`Olamide Caleb Bello, Jan 24, 2026
  45. Junio C HamanoJan 29, 2026
  46. Junio C HamanoJan 30, 2026
  47. Junio C HamanoJan 30, 2026
  48. Bello OlamideJan 29, 2026
  49. 0/3 store repo specific config values in new `struct repo_config_values`Olamide Caleb Bello, Feb 3, 2026
  50. 1/3 environment: stop storing `core.attributesFile` globallyOlamide Caleb Bello, Feb 3, 2026
  51. Phillip WoodFeb 4, 2026
  52. Bello OlamideFeb 9, 2026
  53. Junio C HamanoFeb 7, 2026
  54. Phillip WoodFeb 8, 2026
  55. Bello OlamideFeb 9, 2026
  56. Bello OlamideFeb 10, 2026
  57. 2/3 environment: stop using core.sparseCheckout globallyOlamide Caleb Bello, Feb 3, 2026
  58. Phillip WoodFeb 4, 2026
  59. 3/3 environment: move "branch.autoSetupMerge" into `struct repo_config_values`Olamide Caleb Bello, Feb 3, 2026
  60. Phillip WoodFeb 4, 2026
  61. 0/3 store repo specific config values in new `struct repo_config_values`Olamide Caleb Bello, Feb 16, 2026
  62. 1/3 environment: stop storing `core.attributesFile` globallyOlamide Caleb Bello, Feb 16, 2026
  63. 2/3 environment: stop using core.sparseCheckout globallyOlamide Caleb Bello, Feb 16, 2026
  64. Christian CouderFeb 26, 2026
  65. Junio C HamanoFeb 26, 2026
  66. Bello OlamideFeb 26, 2026
  67. 3/3 environment: move "branch.autoSetupMerge" into `struct repo_config_values`Olamide Caleb Bello, Feb 16, 2026
  68. Junio C HamanoFeb 17, 2026
  69. Bello OlamideFeb 18, 2026
  70. Christian CouderFeb 26, 2026
  71. Junio C HamanoFeb 26, 2026

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.