aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2025-07-14 11:19:23 -0700
committerJunio C Hamano <gitster@pobox.com>2025-07-14 11:19:23 -0700
commitf96878e5d32ac78820401e7061ac5090deeb94ee (patch)
tree4312492d440a1c09922b8973dbe875ad86b2cf61
parent45c50a10cfd770531097d0bf50f3f1189792ebec (diff)
parent7cd03a555a0d951759a5bce201ad0686c0fc8b12 (diff)
downloadgit-f96878e5d32ac78820401e7061ac5090deeb94ee.tar.gz
Merge branch 'ac/prune-wo-the-repository'
Some code paths in the "git prune" used to ignore passed in repository object and used the_repository singleton instance instead, which has been corrected. * ac/prune-wo-the-repository: builtin/prune: stop depending on 'the_repository' repository: move 'repository_format_precious_objects' to repo scope
-rw-r--r--builtin/gc.c2
-rw-r--r--builtin/prune.c27
-rw-r--r--builtin/repack.c2
-rw-r--r--environment.c1
-rw-r--r--environment.h2
-rw-r--r--repository.c1
-rw-r--r--repository.h1
-rw-r--r--setup.c5
-rwxr-xr-xt/t1517-outside-repo.sh7
9 files changed, 27 insertions, 21 deletions
diff --git a/builtin/gc.c b/builtin/gc.c
index 523e3de111..0a583912e3 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -1005,7 +1005,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;
diff --git a/builtin/prune.c b/builtin/prune.c
index e930caa0c0..320e9c2341 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -1,4 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
#define DISABLE_SIGN_COMPARE_WARNINGS
#include "builtin.h"
@@ -64,7 +63,7 @@ static void perform_reachability_traversal(struct rev_info *revs)
return;
if (show_progress)
- progress = start_delayed_progress(the_repository,
+ progress = start_delayed_progress(revs->repo,
_("Checking connectivity"), 0);
mark_reachable_objects(revs, 1, expire, progress);
stop_progress(&progress);
@@ -78,7 +77,7 @@ static int is_object_reachable(const struct object_id *oid,
perform_reachability_traversal(revs);
- obj = lookup_object(the_repository, oid);
+ obj = lookup_object(revs->repo, oid);
return obj && (obj->flags & SEEN);
}
@@ -99,8 +98,7 @@ static int prune_object(const struct object_id *oid, const char *fullpath,
if (st.st_mtime > expire)
return 0;
if (show_only || verbose) {
- enum object_type type = oid_object_info(the_repository, oid,
- NULL);
+ enum object_type type = oid_object_info(revs->repo, oid, NULL);
printf("%s %s\n", oid_to_hex(oid),
(type > 0) ? type_name(type) : "unknown");
}
@@ -154,7 +152,7 @@ static void remove_temporary_files(const char *path)
int cmd_prune(int argc,
const char **argv,
const char *prefix,
- struct repository *repo UNUSED)
+ struct repository *repo)
{
struct rev_info revs;
int exclude_promisor_objects = 0;
@@ -173,20 +171,19 @@ int cmd_prune(int argc,
expire = TIME_MAX;
save_commit_buffer = 0;
disable_replace_refs();
- repo_init_revisions(the_repository, &revs, prefix);
argc = parse_options(argc, argv, prefix, options, prune_usage, 0);
- if (repository_format_precious_objects)
+ repo_init_revisions(repo, &revs, prefix);
+ if (repo->repository_format_precious_objects)
die(_("cannot prune in a precious-objects repo"));
while (argc--) {
struct object_id oid;
const char *name = *argv++;
- if (!repo_get_oid(the_repository, name, &oid)) {
- struct object *object = parse_object_or_die(the_repository, &oid,
- name);
+ if (!repo_get_oid(repo, name, &oid)) {
+ struct object *object = parse_object_or_die(repo, &oid, name);
add_pending_object(&revs, object, "");
}
else
@@ -200,16 +197,16 @@ int cmd_prune(int argc,
revs.exclude_promisor_objects = 1;
}
- for_each_loose_file_in_objdir(repo_get_object_directory(the_repository),
+ for_each_loose_file_in_objdir(repo_get_object_directory(repo),
prune_object, prune_cruft, prune_subdir, &revs);
prune_packed_objects(show_only ? PRUNE_PACKED_DRY_RUN : 0);
- remove_temporary_files(repo_get_object_directory(the_repository));
- s = mkpathdup("%s/pack", repo_get_object_directory(the_repository));
+ remove_temporary_files(repo_get_object_directory(repo));
+ s = mkpathdup("%s/pack", repo_get_object_directory(repo));
remove_temporary_files(s);
free(s);
- if (is_repository_shallow(the_repository)) {
+ if (is_repository_shallow(repo)) {
perform_reachability_traversal(&revs);
prune_shallow(show_only ? PRUNE_SHOW_ONLY : 0);
}
diff --git a/builtin/repack.c b/builtin/repack.c
index 5ddc6e7f95..d0e4fa6bed 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -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",
diff --git a/environment.c b/environment.c
index 7bf0390a33..7c2480b22e 100644
--- a/environment.c
+++ b/environment.c
@@ -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;
diff --git a/environment.h b/environment.h
index 9a3d05d414..3d806ced6e 100644
--- a/environment.h
+++ b/environment.h
@@ -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);
diff --git a/repository.c b/repository.c
index 9b3d6665fc..62709d1c91 100644
--- a/repository.c
+++ b/repository.c
@@ -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;
diff --git a/repository.h b/repository.h
index c4c92b2ab9..ad23a243c6 100644
--- a/repository.h
+++ b/repository.h
@@ -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 f93bd6a24a..3ea01e9331 100644
--- 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;
}
}
/*
diff --git a/t/t1517-outside-repo.sh b/t/t1517-outside-repo.sh
index 6824581317..8f59b867f2 100755
--- a/t/t1517-outside-repo.sh
+++ b/t/t1517-outside-repo.sh
@@ -114,4 +114,11 @@ test_expect_success 'update-server-info does not crash with -h' '
test_grep "[Uu]sage: git update-server-info " usage
'
+test_expect_success 'prune does not crash with -h' '
+ test_expect_code 129 git prune -h >usage &&
+ test_grep "[Uu]sage: git prune " usage &&
+ test_expect_code 129 nongit git prune -h >usage &&
+ test_grep "[Uu]sage: git prune " usage
+'
+
test_done