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

[PATCH v2 13/16] repo-settings: introduce function to clear struct

From
Patrick Steinhardt <ps@pks.im>
Date
Feb 7, 2025, 11:03 UTC
Message-ID
<20250207-b4-pks-path-drop-the-repository-v2-13-13cad3c11b8a@pks.im>
In-Reply-To
<20250207-b4-pks-path-drop-the-repository-v2-0-13cad3c11b8a@pks.im>

We don't provide a way to clear a `struct repo_settings`, and instead open-code this in `repo_clear()`. This is mixing up concerns and means that developers have to touch multiple files whenever they add a new field to the structure in case the associated resources need to be released.

Provide a new `repo_settings_clear()` function to improve this.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 repo-settings.c | 10 ++++++++--
 repo-settings.h |  1 +
 repository.c    |  2 +-
 3 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/repo-settings.c b/repo-settings.c
index 9d16d5399e..719cd7c85c 100644
--- a/repo-settings.c
+++ b/repo-settings.c
@@ -21,7 +21,6 @@ static void repo_cfg_int(struct repository *r, const char *key, int *dest,
 
 void prepare_repo_settings(struct repository *r)
 {
-	const struct repo_settings defaults = REPO_SETTINGS_INIT;
 	int experimental;
 	int value;
 	const char *strval;
@@ -35,7 +34,7 @@ void prepare_repo_settings(struct repository *r)
 	if (r->settings.initialized)
 		return;
 
-	memcpy(&r->settings, &defaults, sizeof(defaults));
+	repo_settings_clear(r);
 	r->settings.initialized++;
 
 	/* Booleans config or default, cascades to other settings */
@@ -143,6 +142,13 @@ void prepare_repo_settings(struct repository *r)
 		r->settings.packed_git_limit = ulongval;
 }
 
+void repo_settings_clear(struct repository *r)
+{
+	struct repo_settings empty = REPO_SETTINGS_INIT;
+	FREE_AND_NULL(r->settings.fsmonitor);
+	r->settings = empty;
+}
+
 enum log_refs_config repo_settings_get_log_all_ref_updates(struct repository *repo)
 {
 	const char *value;
diff --git a/repo-settings.h b/repo-settings.h
index 93ea0c3274..c4f7e3bd8a 100644
--- a/repo-settings.h
+++ b/repo-settings.h
@@ -73,6 +73,7 @@ struct repo_settings {
 }
 
 void prepare_repo_settings(struct repository *r);
+void repo_settings_clear(struct repository *r);
 
 /* Read the value for "core.logAllRefUpdates". */
 enum log_refs_config repo_settings_get_log_all_ref_updates(struct repository *repo);
diff --git a/repository.c b/repository.c
index 648cd88474..6cbaf2e3da 100644
--- a/repository.c
+++ b/repository.c
@@ -380,7 +380,7 @@ void repo_clear(struct repository *repo)
 	parsed_object_pool_clear(repo->parsed_objects);
 	FREE_AND_NULL(repo->parsed_objects);
 
-	FREE_AND_NULL(repo->settings.fsmonitor);
+	repo_settings_clear(repo);
 
 	if (repo->config) {
 		git_configset_clear(repo->config);
-- 
2.48.1.538.gc4cfc42d60.dirty
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 21 of 28 in “path: remove dependency on `the_repository`”
  1. 00/16 path: remove dependency on `the_repository`Patrick Steinhardt, Feb 7, 2025
  2. 01/16 path: refactor `repo_common_path()` family of functionsPatrick Steinhardt, Feb 7, 2025
  3. 02/16 path: refactor `repo_git_path()` family of functionsPatrick Steinhardt, Feb 7, 2025
  4. 03/16 path: refactor `repo_worktree_path()` family of functionsPatrick Steinhardt, Feb 7, 2025
  5. 04/16 submodule: refactor `submodule_to_gitdir()` to accept a repoPatrick Steinhardt, Feb 7, 2025
  6. 05/16 path: refactor `repo_submodule_path()` family of functionsPatrick Steinhardt, Feb 7, 2025
  7. 06/16 path: drop unused `strbuf_git_path()` functionPatrick Steinhardt, Feb 7, 2025
  8. 07/16 path: drop `git_pathdup()` in favor of `repo_git_path()`Patrick Steinhardt, Feb 7, 2025
  9. 08/16 path: drop `git_path_buf()` in favor of `repo_git_path_replace()`Patrick Steinhardt, Feb 7, 2025
  10. 09/16 worktree: return allocated string from `get_worktree_git_dir()`Patrick Steinhardt, Feb 7, 2025
  11. 10/16 path: drop `git_common_path()` in favor of `repo_common_path()`Patrick Steinhardt, Feb 7, 2025
  12. 11/16 rerere: let `rerere_path()` write paths into a caller-provided bufferPatrick Steinhardt, Feb 7, 2025
  13. Jeff KingFeb 22, 2025
  14. Junio C HamanoFeb 24, 2025
  15. Jeff KingFeb 24, 2025
  16. Junio C HamanoFeb 24, 2025
  17. Jeff KingFeb 24, 2025
  18. Junio C HamanoFeb 24, 2025
  19. Patrick SteinhardtFeb 25, 2025
  20. 12/16 path: drop `git_path()` in favor of `repo_git_path()`Patrick Steinhardt, Feb 7, 2025
  21. 13/16 repo-settings: introduce function to clear structPatrick Steinhardt, Feb 7, 2025
  22. 14/16 environment: move access to "core.hooksPath" into repo settingsPatrick Steinhardt, Feb 7, 2025
  23. 15/16 environment: move access to "core.sharedRepository" into repo settingsPatrick Steinhardt, Feb 7, 2025
  24. 16/16 path: adjust last remaining users of `the_repository`Patrick Steinhardt, Feb 7, 2025
  25. Karthik NayakFeb 7, 2025
  26. shejialuoFeb 8, 2025
  27. Junio C HamanoFeb 10, 2025
  28. shejialuoFeb 11, 2025

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.