public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Olamide Caleb Bello <belkid98@gmail.com>
Cc: git@vger.kernel.org,  toon@iotcl.com,  phillip.wood123@gmail.com,
	christian.couder@gmail.com,  usmanakinyemi202@gmail.com,
	kaartic.sivaraam@gmail.com,  me@ttaylorr.com,
	 karthik.188@gmail.com
Subject: Re: [Outreachy PATCH v5 3/3] environment: move "branch.autoSetupMerge" into `struct repo_config_values`
Date: Fri, 30 Jan 2026 12:15:28 -0800	[thread overview]
Message-ID: <xmqq5x8i7t7j.fsf@gitster.g> (raw)
In-Reply-To: <xmqqikcj842o.fsf@gitster.g> (Junio C. Hamano's message of "Fri, 30 Jan 2026 08:20:47 -0800")

Junio C Hamano <gitster@pobox.com> writes:

> 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

  reply	other threads:[~2026-01-30 20:15 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-12 12:59 [Outreachy PATCH RFC 0/3] store git_default_config() parsed values in new config struct Olamide Caleb Bello
2026-01-12 12:59 ` [Outreachy PATCH RFC 1/3] environment: stop storing `core.attributesFile` globally Olamide Caleb Bello
2026-01-12 14:29   ` Phillip Wood
2026-01-12 15:05     ` Bello Olamide
2026-01-12 12:59 ` [Outreachy PATCH RFC 2/3] environment: stop using core.sparseCheckout globally Olamide Caleb Bello
2026-01-12 12:59 ` [Outreachy PATCH RFC 3/3] environment: move "branch.autoSetupMerge" into `struct config_values` Olamide Caleb Bello
2026-01-13 16:43 ` [Outreachy PATCH v2 0/3] store git_default_config() parsed values in new config struct Olamide Caleb Bello
2026-01-13 16:44   ` [Outreachy PATCH v2 1/3] environment: stop storing `core.attributesFile` globally Olamide Caleb Bello
2026-01-13 19:26     ` Junio C Hamano
2026-01-14  6:59       ` Bello Olamide
2026-01-13 16:44   ` [Outreachy PATCH v2 2/3] environment: environment: stop using core.sparseCheckout globally Olamide Caleb Bello
2026-01-13 19:38     ` Junio C Hamano
2026-01-14  7:16       ` Bello Olamide
2026-01-13 16:44   ` [Outreachy PATCH v2 3/3] environment: move "branch.autoSetupMerge" into `struct repo_config_values` Olamide Caleb Bello
2026-01-13 19:53     ` Junio C Hamano
2026-01-14  7:40       ` Bello Olamide
2026-01-15 22:17   ` [Outreachy PATCH v2 0/3] store git_default_config() parsed values in new config struct Bello Olamide
2026-01-17 20:59   ` [Outreachy PATCH v3 0/3] store repo specific config values in new `struct repo_config_values` Olamide Caleb Bello
2026-01-17 20:59     ` [Outreachy PATCH v3 1/3] environment: stop storing `core.attributesFile` globally Olamide Caleb Bello
2026-01-22 12:13       ` Toon Claes
2026-01-22 15:08         ` Bello Olamide
2026-01-22 14:40       ` Phillip Wood
2026-01-22 15:11         ` Bello Olamide
2026-01-17 20:59     ` [Outreachy PATCH v3 2/3] environment: environment: stop using core.sparseCheckout globally Olamide Caleb Bello
2026-01-22 12:13       ` Toon Claes
2026-01-22 15:17         ` Bello Olamide
2026-01-22 14:41       ` Phillip Wood
2026-01-22 15:29         ` Bello Olamide
2026-01-23 10:43           ` Phillip Wood
2026-01-23 13:24             ` Bello Olamide
2026-01-17 20:59     ` [Outreachy PATCH v3 3/3] environment: move "branch.autoSetupMerge" into `struct repo_config_values` Olamide Caleb Bello
2026-01-22 14:41       ` Phillip Wood
2026-01-22 15:29         ` Bello Olamide
2026-01-20 15:19     ` [Outreachy PATCH v3 0/3] store repo specific config values in new " Bello Olamide
2026-01-24 11:55     ` [Outreachy PATCH v4 " Olamide Caleb Bello
2026-01-24 11:55       ` [Outreachy PATCH v4 1/3] environment: stop storing `core.attributesFile` globally Olamide Caleb Bello
2026-01-24 11:55       ` [Outreachy PATCH v4 2/3] environment: stop using core.sparseCheckout globally Olamide Caleb Bello
2026-01-24 11:55       ` [Outreachy PATCH v4 3/3] environment: move "branch.autoSetupMerge" into `struct repo_config_values` Olamide Caleb Bello
2026-01-24 12:21       ` [Outreachy PATCH v5 0/3] store repo specific config values in new " Olamide Caleb Bello
2026-01-24 12:21         ` [Outreachy PATCH v5 1/3] environment: stop storing `core.attributesFile` globally Olamide Caleb Bello
2026-01-29 18:01           ` Junio C Hamano
2026-01-24 12:21         ` [Outreachy PATCH v5 2/3] environment: stop using core.sparseCheckout globally Olamide Caleb Bello
2026-01-29 18:12           ` Junio C Hamano
2026-01-24 12:21         ` [Outreachy PATCH v5 3/3] environment: move "branch.autoSetupMerge" into `struct repo_config_values` Olamide Caleb Bello
2026-01-29 18:37           ` Junio C Hamano
2026-01-30 16:20             ` Junio C Hamano
2026-01-30 20:15               ` Junio C Hamano [this message]
2026-01-29  8:29         ` [Outreachy PATCH v5 0/3] store repo specific config values in new " Bello Olamide
2026-02-03 15:42         ` [Outreachy PATCH v6 " Olamide Caleb Bello
2026-02-03 15:42           ` [Outreachy PATCH v6 1/3] environment: stop storing `core.attributesFile` globally Olamide Caleb Bello
2026-02-04 16:39             ` Phillip Wood
2026-02-09  8:47               ` Bello Olamide
2026-02-07  1:14             ` Junio C Hamano
2026-02-08 11:14               ` Phillip Wood
2026-02-09  8:54                 ` Bello Olamide
2026-02-10  8:40                 ` Bello Olamide
2026-02-03 15:42           ` [Outreachy PATCH v6 2/3] environment: stop using core.sparseCheckout globally Olamide Caleb Bello
2026-02-04 16:55             ` Phillip Wood
2026-02-03 15:42           ` [Outreachy PATCH v6 3/3] environment: move "branch.autoSetupMerge" into `struct repo_config_values` Olamide Caleb Bello
2026-02-04 16:57           ` [Outreachy PATCH v6 0/3] store repo specific config values in new " Phillip Wood
2026-02-16 16:38         ` [Outreachy PATCH v7 " Olamide Caleb Bello
2026-02-16 16:38           ` [Outreachy PATCH v7 1/3] environment: stop storing `core.attributesFile` globally Olamide Caleb Bello
2026-02-16 16:38           ` [Outreachy PATCH v7 2/3] environment: stop using core.sparseCheckout globally Olamide Caleb Bello
2026-02-26 12:57             ` Christian Couder
2026-02-26 15:23               ` Junio C Hamano
2026-02-26 16:24                 ` Bello Olamide
2026-02-16 16:38           ` [Outreachy PATCH v7 3/3] environment: move "branch.autoSetupMerge" into `struct repo_config_values` Olamide Caleb Bello
2026-02-17 20:08           ` [Outreachy PATCH v7 0/3] store repo specific config values in new " Junio C Hamano
2026-02-18 11:27             ` Bello Olamide
2026-02-26 13:03             ` Christian Couder
2026-02-26 15:19               ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq5x8i7t7j.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=belkid98@gmail.com \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=kaartic.sivaraam@gmail.com \
    --cc=karthik.188@gmail.com \
    --cc=me@ttaylorr.com \
    --cc=phillip.wood123@gmail.com \
    --cc=toon@iotcl.com \
    --cc=usmanakinyemi202@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox