]> Kevux Git Server - rit/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 845876f..ec10b81 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 e930caa..dab3c19 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 5ddc6e7..d0e4fa6 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 7bf0390..7c2480b 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 9a3d05d..3d806ce 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 9b3d666..62709d1 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 c4c92b2..ad23a24 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 f93bd6a..3ea01e9 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;
                }
        }
        /*