repository: move 'repository_format_precious_objects' to repo scope
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ayush Chandekar committed
Jul 4, 2025 at 19:42 UTC
44e300a97480ef272a596e02b912b72528043193
8 files changed
+9
-7
builtin/gc.c
+1
-1
@@ -998,7 +998,7 @@ int cmd_gc(int argc,
998
if (opts.detach <= 0 && !skip_foreground_tasks)
999
gc_foreground_tasks(&opts, &cfg);
1000
1001
- if (!repository_format_precious_objects) {
1001
+ if (!the_repository->repository_format_precious_objects) {
1002
struct child_process repack_cmd = CHILD_PROCESS_INIT;
1003
1004
repack_cmd.git_cmd = 1;
builtin/prune.c
+1
-1
@@ -177,7 +177,7 @@ int cmd_prune(int argc,
177
178
argc = parse_options(argc, argv, prefix, options, prune_usage, 0);
179
180
- if (repository_format_precious_objects)
180
+ if (the_repository->repository_format_precious_objects)
181
die(_("cannot prune in a precious-objects repo"));
182
183
while (argc--) {
builtin/repack.c
+1
-1
@@ -1240,7 +1240,7 @@ int cmd_repack(int argc,
1240
po_args.depth = xstrdup_or_null(opt_depth);
1241
po_args.threads = xstrdup_or_null(opt_threads);
1242
1243
- if (delete_redundant && repository_format_precious_objects)
1243
+ if (delete_redundant && the_repository->repository_format_precious_objects)
1244
die(_("cannot delete packs in a precious-objects repo"));
1245
1246
die_for_incompatible_opt3(unpack_unreachable || (pack_everything & LOOSEN_UNREACHABLE), "-A",
environment.c
-1
@@ -37,7 +37,6 @@ int ignore_case;
37
int assume_unchanged;
38
int is_bare_repository_cfg = -1; /* unspecified */
39
int warn_on_object_refname_ambiguity = 1;
40
-int repository_format_precious_objects;
40
char *git_commit_encoding;
41
char *git_log_output_encoding;
42
char *apply_default_whitespace;
environment.h
-2
@@ -189,8 +189,6 @@ extern enum object_creation_mode object_creation_mode;
189
190
extern int grafts_keep_true_parents;
191
192
-extern int repository_format_precious_objects;
193
-
192
const char *get_log_output_encoding(void);
193
const char *get_commit_output_encoding(void);
194
repository.c
+1
@@ -284,6 +284,7 @@ int repo_init(struct repository *repo,
284
repo_set_ref_storage_format(repo, format.ref_storage_format);
285
repo->repository_format_worktree_config = format.worktree_config;
286
repo->repository_format_relative_worktrees = format.relative_worktrees;
287
+ repo->repository_format_precious_objects = format.precious_objects;
288
289
/* take ownership of format.partial_clone */
290
repo->repository_format_partial_clone = format.partial_clone;
repository.h
+1
@@ -151,6 +151,7 @@ struct repository {
151
/* Configurations */
152
int repository_format_worktree_config;
153
int repository_format_relative_worktrees;
154
+ int repository_format_precious_objects;
155
156
/* Indicate if a repository has a different 'commondir' from 'gitdir' */
157
unsigned different_commondir:1;
setup.c
+4
-1
@@ -753,7 +753,8 @@ static int check_repository_format_gently(const char *gitdir, struct repository_
753
die("%s", err.buf);
754
}
755
756
- repository_format_precious_objects = candidate->precious_objects;
756
+ the_repository->repository_format_precious_objects = candidate->precious_objects;
757
+
758
string_list_clear(&candidate->unknown_extensions, 0);
759
string_list_clear(&candidate->v1_only_extensions, 0);
760
@@ -1864,6 +1865,8 @@ const char *setup_git_directory_gently(int *nongit_ok)
1865
the_repository->repository_format_partial_clone =
1866
repo_fmt.partial_clone;
1867
repo_fmt.partial_clone = NULL;
1868
+ the_repository->repository_format_precious_objects =
1869
+ repo_fmt.precious_objects;
1870
}
1871
}
1872
/*