Skip to content

Commit f96878e

Browse files
committed
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
2 parents 45c50a1 + 7cd03a5 commit f96878e

File tree

9 files changed

+27
-21
lines changed

9 files changed

+27
-21
lines changed

builtin/gc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ int cmd_gc(int argc,
10051005
if (opts.detach <= 0 && !skip_foreground_tasks)
10061006
gc_foreground_tasks(&opts, &cfg);
10071007

1008-
if (!repository_format_precious_objects) {
1008+
if (!the_repository->repository_format_precious_objects) {
10091009
struct child_process repack_cmd = CHILD_PROCESS_INIT;
10101010

10111011
repack_cmd.git_cmd = 1;

builtin/prune.c

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#define USE_THE_REPOSITORY_VARIABLE
21
#define DISABLE_SIGN_COMPARE_WARNINGS
32

43
#include "builtin.h"
@@ -64,7 +63,7 @@ static void perform_reachability_traversal(struct rev_info *revs)
6463
return;
6564

6665
if (show_progress)
67-
progress = start_delayed_progress(the_repository,
66+
progress = start_delayed_progress(revs->repo,
6867
_("Checking connectivity"), 0);
6968
mark_reachable_objects(revs, 1, expire, progress);
7069
stop_progress(&progress);
@@ -78,7 +77,7 @@ static int is_object_reachable(const struct object_id *oid,
7877

7978
perform_reachability_traversal(revs);
8079

81-
obj = lookup_object(the_repository, oid);
80+
obj = lookup_object(revs->repo, oid);
8281
return obj && (obj->flags & SEEN);
8382
}
8483

@@ -99,8 +98,7 @@ static int prune_object(const struct object_id *oid, const char *fullpath,
9998
if (st.st_mtime > expire)
10099
return 0;
101100
if (show_only || verbose) {
102-
enum object_type type = oid_object_info(the_repository, oid,
103-
NULL);
101+
enum object_type type = oid_object_info(revs->repo, oid, NULL);
104102
printf("%s %s\n", oid_to_hex(oid),
105103
(type > 0) ? type_name(type) : "unknown");
106104
}
@@ -154,7 +152,7 @@ static void remove_temporary_files(const char *path)
154152
int cmd_prune(int argc,
155153
const char **argv,
156154
const char *prefix,
157-
struct repository *repo UNUSED)
155+
struct repository *repo)
158156
{
159157
struct rev_info revs;
160158
int exclude_promisor_objects = 0;
@@ -173,20 +171,19 @@ int cmd_prune(int argc,
173171
expire = TIME_MAX;
174172
save_commit_buffer = 0;
175173
disable_replace_refs();
176-
repo_init_revisions(the_repository, &revs, prefix);
177174

178175
argc = parse_options(argc, argv, prefix, options, prune_usage, 0);
179176

180-
if (repository_format_precious_objects)
177+
repo_init_revisions(repo, &revs, prefix);
178+
if (repo->repository_format_precious_objects)
181179
die(_("cannot prune in a precious-objects repo"));
182180

183181
while (argc--) {
184182
struct object_id oid;
185183
const char *name = *argv++;
186184

187-
if (!repo_get_oid(the_repository, name, &oid)) {
188-
struct object *object = parse_object_or_die(the_repository, &oid,
189-
name);
185+
if (!repo_get_oid(repo, name, &oid)) {
186+
struct object *object = parse_object_or_die(repo, &oid, name);
190187
add_pending_object(&revs, object, "");
191188
}
192189
else
@@ -200,16 +197,16 @@ int cmd_prune(int argc,
200197
revs.exclude_promisor_objects = 1;
201198
}
202199

203-
for_each_loose_file_in_objdir(repo_get_object_directory(the_repository),
200+
for_each_loose_file_in_objdir(repo_get_object_directory(repo),
204201
prune_object, prune_cruft, prune_subdir, &revs);
205202

206203
prune_packed_objects(show_only ? PRUNE_PACKED_DRY_RUN : 0);
207-
remove_temporary_files(repo_get_object_directory(the_repository));
208-
s = mkpathdup("%s/pack", repo_get_object_directory(the_repository));
204+
remove_temporary_files(repo_get_object_directory(repo));
205+
s = mkpathdup("%s/pack", repo_get_object_directory(repo));
209206
remove_temporary_files(s);
210207
free(s);
211208

212-
if (is_repository_shallow(the_repository)) {
209+
if (is_repository_shallow(repo)) {
213210
perform_reachability_traversal(&revs);
214211
prune_shallow(show_only ? PRUNE_SHOW_ONLY : 0);
215212
}

builtin/repack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1240,7 +1240,7 @@ int cmd_repack(int argc,
12401240
po_args.depth = xstrdup_or_null(opt_depth);
12411241
po_args.threads = xstrdup_or_null(opt_threads);
12421242

1243-
if (delete_redundant && repository_format_precious_objects)
1243+
if (delete_redundant && the_repository->repository_format_precious_objects)
12441244
die(_("cannot delete packs in a precious-objects repo"));
12451245

12461246
die_for_incompatible_opt3(unpack_unreachable || (pack_everything & LOOSEN_UNREACHABLE), "-A",

environment.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ int ignore_case;
3737
int assume_unchanged;
3838
int is_bare_repository_cfg = -1; /* unspecified */
3939
int warn_on_object_refname_ambiguity = 1;
40-
int repository_format_precious_objects;
4140
char *git_commit_encoding;
4241
char *git_log_output_encoding;
4342
char *apply_default_whitespace;

environment.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,6 @@ extern enum object_creation_mode object_creation_mode;
189189

190190
extern int grafts_keep_true_parents;
191191

192-
extern int repository_format_precious_objects;
193-
194192
const char *get_log_output_encoding(void);
195193
const char *get_commit_output_encoding(void);
196194

repository.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ int repo_init(struct repository *repo,
284284
repo_set_ref_storage_format(repo, format.ref_storage_format);
285285
repo->repository_format_worktree_config = format.worktree_config;
286286
repo->repository_format_relative_worktrees = format.relative_worktrees;
287+
repo->repository_format_precious_objects = format.precious_objects;
287288

288289
/* take ownership of format.partial_clone */
289290
repo->repository_format_partial_clone = format.partial_clone;

repository.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ struct repository {
151151
/* Configurations */
152152
int repository_format_worktree_config;
153153
int repository_format_relative_worktrees;
154+
int repository_format_precious_objects;
154155

155156
/* Indicate if a repository has a different 'commondir' from 'gitdir' */
156157
unsigned different_commondir:1;

setup.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,8 @@ static int check_repository_format_gently(const char *gitdir, struct repository_
753753
die("%s", err.buf);
754754
}
755755

756-
repository_format_precious_objects = candidate->precious_objects;
756+
the_repository->repository_format_precious_objects = candidate->precious_objects;
757+
757758
string_list_clear(&candidate->unknown_extensions, 0);
758759
string_list_clear(&candidate->v1_only_extensions, 0);
759760

@@ -1864,6 +1865,8 @@ const char *setup_git_directory_gently(int *nongit_ok)
18641865
the_repository->repository_format_partial_clone =
18651866
repo_fmt.partial_clone;
18661867
repo_fmt.partial_clone = NULL;
1868+
the_repository->repository_format_precious_objects =
1869+
repo_fmt.precious_objects;
18671870
}
18681871
}
18691872
/*

t/t1517-outside-repo.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,11 @@ test_expect_success 'update-server-info does not crash with -h' '
114114
test_grep "[Uu]sage: git update-server-info " usage
115115
'
116116

117+
test_expect_success 'prune does not crash with -h' '
118+
test_expect_code 129 git prune -h >usage &&
119+
test_grep "[Uu]sage: git prune " usage &&
120+
test_expect_code 129 nongit git prune -h >usage &&
121+
test_grep "[Uu]sage: git prune " usage
122+
'
123+
117124
test_done

0 commit comments

Comments
 (0)