]> git.ipfire.org Git - thirdparty/git.git/commitdiff
repository: create disable_replace_refs()
authorDerrick Stolee <derrickstolee@github.com>
Tue, 6 Jun 2023 13:24:35 +0000 (13:24 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 12 Jun 2023 20:34:55 +0000 (13:34 -0700)
Several builtins depend on being able to disable the replace references
so we actually operate on each object individually. These currently do
so by directly mutating the 'read_replace_refs' global.

A future change will move this global into a different place, so it will
be necessary to change all of these lines. However, we can simplify that
transition by abstracting the purpose of these global assignments with a
method call.

We will need to keep this read_replace_refs global forever, as we want
to make sure that we never use replace refs throughout the life of the
process if this method is called. Future changes may present a
repository-scoped version of the variable to represent that repository's
core.useReplaceRefs config value, but a zero-valued read_replace_refs
will always override such a setting.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
13 files changed:
builtin/cat-file.c
builtin/commit-graph.c
builtin/fsck.c
builtin/index-pack.c
builtin/pack-objects.c
builtin/prune.c
builtin/replace.c
builtin/unpack-objects.c
builtin/upload-pack.c
environment.c
git.c
replace-object.c
replace-object.h

index 0bafc14e6c03ac1c034e64878b884ebcb15128af..27f070267a41d76b305ee3e5397d8b095692448c 100644 (file)
@@ -805,7 +805,7 @@ static int batch_objects(struct batch_options *opt)
                if (repo_has_promisor_remote(the_repository))
                        warning("This repository uses promisor remotes. Some objects may not be loaded.");
 
-               read_replace_refs = 0;
+               disable_replace_refs();
 
                cb.opt = opt;
                cb.expand = &data;
index a3d00fa232b51a0ed6581a2638ca65bf50db3023..dd732b3534884a20c61f7fd6379eb4400de75ec5 100644 (file)
@@ -324,7 +324,7 @@ int cmd_commit_graph(int argc, const char **argv, const char *prefix)
 
        git_config(git_default_config, NULL);
 
-       read_replace_refs = 0;
+       disable_replace_refs();
        save_commit_buffer = 0;
 
        argc = parse_options(argc, argv, prefix, options,
index 2cd461b84c11db2b34b61ca01a9246bb70ac39a6..a2fe760cc0e56d1894404bd094b011dd7c5df914 100644 (file)
@@ -927,7 +927,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
        fetch_if_missing = 0;
 
        errors_found = 0;
-       read_replace_refs = 0;
+       disable_replace_refs();
        save_commit_buffer = 0;
 
        argc = parse_options(argc, argv, prefix, fsck_opts, fsck_usage, 0);
index bb67e16655994ceee8116a6325ead1daf1d8e860..d0d8067510b3dc9240097ff5c090e17e1002e1e7 100644 (file)
@@ -1752,7 +1752,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
        if (argc == 2 && !strcmp(argv[1], "-h"))
                usage(index_pack_usage);
 
-       read_replace_refs = 0;
+       disable_replace_refs();
        fsck_options.walk = mark_link;
 
        reset_pack_idx_option(&opts);
index a5b466839bad1b4529b9aafc822fc6d3e516448e..e23fe82ca1afd21d552c7e889f9b0b623e059e27 100644 (file)
@@ -4284,7 +4284,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
        if (DFS_NUM_STATES > (1 << OE_DFS_STATE_BITS))
                BUG("too many dfs states, increase OE_DFS_STATE_BITS");
 
-       read_replace_refs = 0;
+       disable_replace_refs();
 
        sparse = git_env_bool("GIT_TEST_PACK_SPARSE", -1);
        if (the_repository->gitdir) {
index 5dc9b20720006700584069a3b6aa1211088ff5d7..287720173761ac978b98468aa410dee439ee8e46 100644 (file)
@@ -164,7 +164,7 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
 
        expire = TIME_MAX;
        save_commit_buffer = 0;
-       read_replace_refs = 0;
+       disable_replace_refs();
        repo_init_revisions(the_repository, &revs, prefix);
 
        argc = parse_options(argc, argv, prefix, options, prune_usage, 0);
index 981f1894436dd3c3d2df15c0926e2a808557703d..abff800276c83ca15658702e62a2d4aef9f383b1 100644 (file)
@@ -566,7 +566,7 @@ int cmd_replace(int argc, const char **argv, const char *prefix)
                OPT_END()
        };
 
-       read_replace_refs = 0;
+       disable_replace_refs();
        git_config(git_default_config, NULL);
 
        argc = parse_options(argc, argv, prefix, options, git_replace_usage, 0);
index 2c52c3a741fbd49d7782f6388e2ebe38f54cb8fb..0b4fe803cc1814ea5b9ab3b90255b1cdd7e21172 100644 (file)
@@ -609,7 +609,7 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix UNUSED)
        int i;
        struct object_id oid;
 
-       read_replace_refs = 0;
+       disable_replace_refs();
 
        git_config(git_default_config, NULL);
 
index beb9dd08610000f94d2365437e43bf0518c20c55..81d2008e01774d34bc14a523b2431fa598f474d2 100644 (file)
@@ -36,7 +36,7 @@ int cmd_upload_pack(int argc, const char **argv, const char *prefix)
        };
 
        packet_trace_identity("upload-pack");
-       read_replace_refs = 0;
+       disable_replace_refs();
 
        argc = parse_options(argc, argv, prefix, options, upload_pack_usage, 0);
 
index 8a96997539ab4edd2216aa3be1747aa947297300..3b4d87c322fdc856389f363b3d77220f2b6ed8ca 100644 (file)
@@ -185,7 +185,7 @@ void setup_git_env(const char *git_dir)
        strvec_clear(&to_free);
 
        if (getenv(NO_REPLACE_OBJECTS_ENVIRONMENT))
-               read_replace_refs = 0;
+               disable_replace_refs();
        replace_ref_base = getenv(GIT_REPLACE_REF_BASE_ENVIRONMENT);
        git_replace_ref_base = xstrdup(replace_ref_base ? replace_ref_base
                                                          : "refs/replace/");
diff --git a/git.c b/git.c
index 45899be82658d725ac87c8d2328483089bcefd1c..3252d4c7661aa79159477c37e24c4f6e4676c556 100644 (file)
--- a/git.c
+++ b/git.c
@@ -185,7 +185,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
                        if (envchanged)
                                *envchanged = 1;
                } else if (!strcmp(cmd, "--no-replace-objects")) {
-                       read_replace_refs = 0;
+                       disable_replace_refs();
                        setenv(NO_REPLACE_OBJECTS_ENVIRONMENT, "1", 1);
                        if (envchanged)
                                *envchanged = 1;
index e98825d5852d80f6799904e4b0280f438375b75a..ceec81c940ceffd8339b1d8e7a3c4f800d49301c 100644 (file)
@@ -84,3 +84,8 @@ const struct object_id *do_lookup_replace_object(struct repository *r,
        }
        die(_("replace depth too high for object %s"), oid_to_hex(oid));
 }
+
+void disable_replace_refs(void)
+{
+       read_replace_refs = 0;
+}
index 500482b02b38ce30ee51a005d00ca00e76033f19..7786d4152b053767ce633e94e0b003cd1d6626f5 100644 (file)
@@ -48,4 +48,12 @@ static inline const struct object_id *lookup_replace_object(struct repository *r
        return do_lookup_replace_object(r, oid);
 }
 
+/*
+ * Some commands override config and environment settings for using
+ * replace references. Use this method to disable the setting and ensure
+ * those other settings will not override this choice. This applies
+ * globally to all in-process repositories.
+ */
+void disable_replace_refs(void);
+
 #endif /* REPLACE_OBJECT_H */