repack, prune: drop GIT_REF_PARANOIA settings

Now that GIT_REF_PARANOIA is the default, we don't need to selectively enable it for destructive operations. In fact, it's harmful to do so, because it overrides any GIT_REF_PARANOIA=0 setting that the user may have provided (because they're trying to work around some corruption). With these uses gone, we can further clean up the ref_paranoia global, and make it a static variable inside the refs code. Signed-off-by: Jeff King <peff@peff.net> Reviewed-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Sep 24, 2021 at 14:46 UTC 5d1f5b8cd4bec8fbb405e32b1208955c93240f17
5 files changed +2 -13
builtin/prune.c
-1
@@ -143,7 +143,6 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
143 expire = TIME_MAX;
144 save_commit_buffer = 0;
145 read_replace_refs = 0;
146 - ref_paranoia = 1;
146 repo_init_revisions(the_repository, &revs, prefix);
147
148 argc = parse_options(argc, argv, prefix, options, prune_usage, 0);
builtin/repack.c
-3
@@ -586,15 +586,12 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
586 strvec_pushf(&cmd.args,
587 "--unpack-unreachable=%s",
588 unpack_unreachable);
589 - strvec_push(&cmd.env_array, "GIT_REF_PARANOIA=1");
589 } else if (pack_everything & LOOSEN_UNREACHABLE) {
590 strvec_push(&cmd.args,
591 "--unpack-unreachable");
592 } else if (keep_unreachable) {
593 strvec_push(&cmd.args, "--keep-unreachable");
594 strvec_push(&cmd.args, "--pack-loose-unreachable");
596 - } else {
597 - strvec_push(&cmd.env_array, "GIT_REF_PARANOIA=1");
595 }
596 }
597 } else if (geometry) {
cache.h
-8
@@ -994,14 +994,6 @@ extern const char *core_fsmonitor;
994 extern int core_apply_sparse_checkout;
995 extern int core_sparse_checkout_cone;
996
997 -/*
998 - * Include broken refs in all ref iterations, which will
999 - * generally choke dangerous operations rather than letting
1000 - * them silently proceed without taking the broken ref into
1001 - * account.
1002 - */
1003 -extern int ref_paranoia;
1004 -
997 /*
998 * Returns the boolean value of $GIT_OPTIONAL_LOCKS (or the default value).
999 */
environment.c
-1
@@ -31,7 +31,6 @@ int prefer_symlink_refs;
31 int is_bare_repository_cfg = -1; /* unspecified */
32 int warn_ambiguous_refs = 1;
33 int warn_on_object_refname_ambiguity = 1;
34 -int ref_paranoia = -1;
34 int repository_format_precious_objects;
35 int repository_format_worktree_config;
36 const char *git_commit_encoding;
refs.c
+2
@@ -1419,6 +1419,8 @@ struct ref_iterator *refs_ref_iterator_begin(
1419 struct ref_iterator *iter;
1420
1421 if (!(flags & DO_FOR_EACH_INCLUDE_BROKEN)) {
1422 + static int ref_paranoia = -1;
1423 +
1424 if (ref_paranoia < 0)
1425 ref_paranoia = git_env_bool("GIT_REF_PARANOIA", 1);
1426 if (ref_paranoia) {