]> git.ipfire.org Git - thirdparty/git.git/commitdiff
repository: move 'repository_format_precious_objects' to repo scope
authorAyush Chandekar <ayu.chandekar@gmail.com>
Fri, 4 Jul 2025 14:12:34 +0000 (19:42 +0530)
committerJunio C Hamano <gitster@pobox.com>
Mon, 7 Jul 2025 15:31:13 +0000 (08:31 -0700)
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>
builtin/gc.c
builtin/prune.c
builtin/repack.c
environment.c
environment.h
repository.c
repository.h
setup.c

index 845876ff02869beba3ad7a2ca07fb6cc7f03cc73..ec10b81dcc36f693284a2d9d606c3683c122bfb1 100644 (file)
@@ -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;
index e930caa0c0af0e1ba2be153497da4e3e1c29e01d..dab3c19b6fdd3270da6c3ac1c53e3ebfe548bcb2 100644 (file)
@@ -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--) {
index 5ddc6e7f9573d42b4fabb6b8ce969dc7b2cc5c9d..d0e4fa6bed16e3a9ea78a6333c53046959ee070f 100644 (file)
@@ -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",
index 7bf0390a3355d3838c1b3baab93051bed5686790..7c2480b22e599192adc822b012e45a51b3578453 100644 (file)
@@ -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;
index 9a3d05d414a7ad316a4b45a7498e6773457e8afd..3d806ced6e45524f884aa291930b738955115227 100644 (file)
@@ -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);
 
index 9b3d6665fc6d4f5cb203ac0f557b9fd62e63a968..62709d1c916e1bbd5a148ffe0739fae21d41984b 100644 (file)
@@ -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;
index c4c92b2ab9c9e3b425dc2974636e33d1f4089c69..ad23a243c6ab9234db2ff12e3722137e738e94b7 100644 (file)
@@ -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 f93bd6a24a5d9c166fd22165786efe86d605df75..3ea01e9331149c7990ded7e0ebb8ab857edc997d 100644 (file)
--- 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;
                }
        }
        /*