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

[GSOC PATCH v3 1/2] repository: move 'repository_format_precious_objects' to repo scope

From
Ayush Chandekar <ayu.chandekar@gmail.com>
Date
Jul 4, 2025, 14:12 UTC
Message-ID
<a828ade541b9255a655ad6d4cb3b6a64c900627f.1751630981.git.ayu.chandekar@gmail.com>
In-Reply-To
<cover.1751630981.git.ayu.chandekar@gmail.com>

The 'extensions.preciousObjects' setting when set true, prevents operations that might drop objects from the object storage. This setting is populated in the global variable 'repository_format_precious_objects'.

Move this global variable to repo scope by adding it to 'struct repository and also refactor all the occurences accordingly.

This change is part of an ongoing effort to eliminate global variables, improve modularity and help libify the codebase.

Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Ghanshyam Thakkar <shyamthakkar001@gmail.com>
Signed-off-by: Ayush Chandekar <ayu.chandekar@gmail.com>
---
 builtin/gc.c     | 2 +-
 builtin/prune.c  | 2 +-
 builtin/repack.c | 2 +-
 environment.c    | 1 -
 environment.h    | 2 --
 repository.c     | 1 +
 repository.h     | 1 +
 setup.c          | 5 ++++-
 8 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/builtin/gc.c b/builtin/gc.c
index 845876ff02..ec10b81dcc 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -998,7 +998,7 @@ int cmd_gc(int argc,
 	if (opts.detach <= 0 && !skip_foreground_tasks)
 		gc_foreground_tasks(&opts, &cfg);
 
-	if (!repository_format_precious_objects) {
+	if (!the_repository->repository_format_precious_objects) {
 		struct child_process repack_cmd = CHILD_PROCESS_INIT;
 
 		repack_cmd.git_cmd = 1;
diff --git a/builtin/prune.c b/builtin/prune.c
index e930caa0c0..dab3c19b6f 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -177,7 +177,7 @@ int cmd_prune(int argc,
 
 	argc = parse_options(argc, argv, prefix, options, prune_usage, 0);
 
-	if (repository_format_precious_objects)
+	if (the_repository->repository_format_precious_objects)
 		die(_("cannot prune in a precious-objects repo"));
 
 	while (argc--) {
diff --git a/builtin/repack.c b/builtin/repack.c
index 5ddc6e7f95..d0e4fa6bed 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -1240,7 +1240,7 @@ int cmd_repack(int argc,
 	po_args.depth = xstrdup_or_null(opt_depth);
 	po_args.threads = xstrdup_or_null(opt_threads);
 
-	if (delete_redundant && repository_format_precious_objects)
+	if (delete_redundant && the_repository->repository_format_precious_objects)
 		die(_("cannot delete packs in a precious-objects repo"));
 
 	die_for_incompatible_opt3(unpack_unreachable || (pack_everything & LOOSEN_UNREACHABLE), "-A",
diff --git a/environment.c b/environment.c
index 7bf0390a33..7c2480b22e 100644
--- a/environment.c
+++ b/environment.c
@@ -37,7 +37,6 @@ int ignore_case;
 int assume_unchanged;
 int is_bare_repository_cfg = -1; /* unspecified */
 int warn_on_object_refname_ambiguity = 1;
-int repository_format_precious_objects;
 char *git_commit_encoding;
 char *git_log_output_encoding;
 char *apply_default_whitespace;
diff --git a/environment.h b/environment.h
index 9a3d05d414..3d806ced6e 100644
--- a/environment.h
+++ b/environment.h
@@ -189,8 +189,6 @@ extern enum object_creation_mode object_creation_mode;
 
 extern int grafts_keep_true_parents;
 
-extern int repository_format_precious_objects;
-
 const char *get_log_output_encoding(void);
 const char *get_commit_output_encoding(void);
 
diff --git a/repository.c b/repository.c
index 9b3d6665fc..62709d1c91 100644
--- a/repository.c
+++ b/repository.c
@@ -284,6 +284,7 @@ int repo_init(struct repository *repo,
 	repo_set_ref_storage_format(repo, format.ref_storage_format);
 	repo->repository_format_worktree_config = format.worktree_config;
 	repo->repository_format_relative_worktrees = format.relative_worktrees;
+	repo->repository_format_precious_objects = format.precious_objects;
 
 	/* take ownership of format.partial_clone */
 	repo->repository_format_partial_clone = format.partial_clone;
diff --git a/repository.h b/repository.h
index c4c92b2ab9..ad23a243c6 100644
--- a/repository.h
+++ b/repository.h
@@ -151,6 +151,7 @@ struct repository {
 	/* Configurations */
 	int repository_format_worktree_config;
 	int repository_format_relative_worktrees;
+	int repository_format_precious_objects;
 
 	/* Indicate if a repository has a different 'commondir' from 'gitdir' */
 	unsigned different_commondir:1;
diff --git a/setup.c b/setup.c
index f93bd6a24a..3ea01e9331 100644
--- a/setup.c
+++ b/setup.c
@@ -753,7 +753,8 @@ static int check_repository_format_gently(const char *gitdir, struct repository_
 		die("%s", err.buf);
 	}
 
-	repository_format_precious_objects = candidate->precious_objects;
+	the_repository->repository_format_precious_objects = candidate->precious_objects;
+
 	string_list_clear(&candidate->unknown_extensions, 0);
 	string_list_clear(&candidate->v1_only_extensions, 0);
 
@@ -1864,6 +1865,8 @@ const char *setup_git_directory_gently(int *nongit_ok)
 			the_repository->repository_format_partial_clone =
 				repo_fmt.partial_clone;
 			repo_fmt.partial_clone = NULL;
+			the_repository->repository_format_precious_objects =
+				repo_fmt.precious_objects;
 		}
 	}
 	/*
-- 
2.49.0
Previous: Ayush ChandekarNext: Ayush Chandekar
Message 26 of 29 in “builtin/prune: remove dependency on global variables and 'the_repository'”
  1. 0/2 builtin/prune: remove dependency on global variables and 'the_repository'Ayush Chandekar, Jun 8, 2025
  2. 1/2 repository: move 'repository_format_precious_objects' to repo scopeAyush Chandekar, Jun 8, 2025
  3. shejialuoJun 28, 2025
  4. Ayush ChandekarJun 28, 2025
  5. 2/2 builtin/prune: stop depending on 'the_repository'Ayush Chandekar, Jun 8, 2025
  6. shejialuoJun 28, 2025
  7. Ayush ChandekarJun 28, 2025
  8. Ayush ChandekarJun 25, 2025
  9. 0/2 builtin/prune: remove dependency on global variables and 'the_repository'Ayush Chandekar, Jun 30, 2025
  10. 1/2 repository: move 'repository_format_precious_objects' to repo scopeAyush Chandekar, Jun 30, 2025
  11. Patrick SteinhardtJul 1, 2025
  12. Ayush ChandekarJul 1, 2025
  13. Patrick SteinhardtJul 2, 2025
  14. 2/2 builtin/prune: stop depending on 'the_repository'Ayush Chandekar, Jun 30, 2025
  15. Patrick SteinhardtJul 1, 2025
  16. Junio C HamanoJul 1, 2025
  17. Ayush ChandekarJul 1, 2025
  18. Usman AkinyemiJul 1, 2025
  19. Ayush ChandekarJul 1, 2025
  20. Patrick SteinhardtJul 2, 2025
  21. Usman AkinyemiJul 2, 2025
  22. Ben KnobleJul 2, 2025
  23. Junio C HamanoJul 2, 2025
  24. Ayush ChandekarJul 2, 2025
  25. 0/2 builtin/prune: remove dependency on global variables and 'the_repository'Ayush Chandekar, Jul 4, 2025
  26. 1/2 repository: move 'repository_format_precious_objects' to repo scopeAyush Chandekar, Jul 4, 2025
  27. 2/2 builtin/prune: stop depending on 'the_repository'Ayush Chandekar, Jul 4, 2025
  28. Patrick SteinhardtJul 7, 2025
  29. Ayush ChandekarJul 8, 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.