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

Re: [Outreachy PATCH v6 1/3] environment: stop storing `core.attributesFile` globally

From
PWPhillip Wood <phillip.wood123@gmail.com>
Date
Feb 4, 2026, 16:39 UTC
Message-ID
<c95a7730-7b14-4be0-a4e4-861b2f5430ea@gmail.com>
In-Reply-To
<7e3082125df08d3e5fb2195d73698c4c28c6645e.1770127568.git.belkid98@gmail.com>
On 03/02/2026 15:42, Olamide Caleb Bello wrote:
Show 15 quoted lines
> The `core.attributeFile` config value is parsed in
> git_default_core_config(), loaded eagerly and stored in the global
> variable `git_attributes_file`. Storing this value in a global variable
> can lead to it being overwritten by another repository when more than one
> Git repository run in the same Git process.
> 
> Create a new struct `repo_config_values` to hold this value and
> other repository dependent values parsed by `git_default_config()`.
> This will ensure the current behaviour remains the same while also
> enabling the libification of Git.
> 
> An accessor function 'repo_config_values()' is created and used to access
> the new struct member of the repository struct.
> This is to ensure that we detect if the struct repository has been
> initialized and also prevent double initialization of the repository.
Sounds sensible. This paragraph could be reflowed.
> It is important to note that `git_default_config()` is a wrapper to other
> `git_default_*_config()` functions such as `git_default_core_config()`.
> Therefore to access and modify this global variable,
> the change has to be made `git_default_core_config()`.

I'm not sure what this paragraph is saying with regard to the changes in this patch.

Show 11 quoted lines
> --- a/environment.c
> +++ b/environment.c
> @@ -756,3 +757,8 @@ int git_default_config(const char *var, const char *value,
>   	/* Add other config variables here and to Documentation/config.adoc. */
>   	return 0;
>   }
> +
> +void repo_config_values_init(struct repo_config_values *cfg)
> +{
> +	cfg->attributes_file = NULL;
> +}

Should we be free()ing cfg->attributes_file when the repository instance is free()d? At the moment we're using "the_repository" which points to a static instance so it does not make any practical difference but once we start storing the config per-repository instance we will need to free the config when the repository instance is free()d.

Show 12 quoted lines
> diff --git a/repository.c b/repository.c
> index c7e75215ac..a9b727540f 100644
> --- a/repository.c
> +++ b/repository.c
> @@ -50,13 +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 uninitialized repository");

This check and the one in initialize_repository() below assume that the repository instance is zeroed out when it is created, that's a reasonable requirement but we should probably document it as our other data structures tend not to require that they're zeroed out before they are initialized. For example

	struct strbuf buf;
	strbuf_init(&buf, 0);

is perfectly fine as strbuf_init() does not assume the instance passed to it has been zeroed out.

As we only support retrieving values from "the_repository" at the moment we should perhaps add

	if (repo != the_repository)
		BUG("trying to read config from wrong repository instance");
Everything else looks fine to me
Thanks
Phillip
Show 50 quoted lines
> +	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));
>   
>   	/*
>   	 * When a command runs inside a repository, it learns what
> diff --git a/repository.h b/repository.h
> index 6063c4b846..9717e45000 100644
> --- a/repository.h
> +++ b/repository.h
> @@ -3,6 +3,7 @@
>   
>   #include "strmap.h"
>   #include "repo-settings.h"
> +#include "environment.h"
>   
>   struct config_set;
>   struct git_hash_algo;
> @@ -148,6 +149,9 @@ struct repository {
>   	/* Repository's compatibility hash algorithm. */
>   	const struct git_hash_algo *compat_hash_algo;
>   
> +	/* Repository's config values parsed by git_default_config() */
> +	struct repo_config_values config_values_private_;
> +
>   	/* Repository's reference storage format, as serialized on disk. */
>   	enum ref_storage_format ref_storage_format;
>   
> @@ -171,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: Olamide Caleb BelloNext: Bello Olamide
Message 51 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.