Skip to content

Commit ce400c9

Browse files
committed
Merge branch 'ab/cache-api-cleanup-users'
Updates the users of the cache API. * ab/cache-api-cleanup-users: treewide: always have a valid "index_state.repo" member
2 parents 5dec958 + 6269f8e commit ce400c9

15 files changed

+30
-58
lines changed

apply.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4105,7 +4105,7 @@ static int preimage_oid_in_gitlink_patch(struct patch *p, struct object_id *oid)
41054105
static int build_fake_ancestor(struct apply_state *state, struct patch *list)
41064106
{
41074107
struct patch *patch;
4108-
struct index_state result = INDEX_STATE_INIT;
4108+
struct index_state result = INDEX_STATE_INIT(state->repo);
41094109
struct lock_file lock = LOCK_INIT;
41104110
int res;
41114111

builtin/difftool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
361361
struct hashmap symlinks2 = HASHMAP_INIT(pair_cmp, NULL);
362362
struct hashmap_iter iter;
363363
struct pair_entry *entry;
364-
struct index_state wtindex = INDEX_STATE_INIT;
364+
struct index_state wtindex = INDEX_STATE_INIT(the_repository);
365365
struct checkout lstate, rstate;
366366
int err = 0;
367367
struct child_process cmd = CHILD_PROCESS_INIT;

builtin/sparse-checkout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ static int update_working_directory(struct pattern_list *pl)
217217
o.head_idx = -1;
218218
o.src_index = r->index;
219219
o.dst_index = r->index;
220-
index_state_init(&o.result);
220+
index_state_init(&o.result, r);
221221
o.skip_sparse_checkout = 0;
222222
o.pl = pl;
223223

builtin/stash.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ static int save_untracked_files(struct stash_info *info, struct strbuf *msg,
11371137
int ret = 0;
11381138
struct strbuf untracked_msg = STRBUF_INIT;
11391139
struct child_process cp_upd_index = CHILD_PROCESS_INIT;
1140-
struct index_state istate = INDEX_STATE_INIT;
1140+
struct index_state istate = INDEX_STATE_INIT(the_repository);
11411141

11421142
cp_upd_index.git_cmd = 1;
11431143
strvec_pushl(&cp_upd_index.args, "update-index", "-z", "--add",
@@ -1176,7 +1176,7 @@ static int stash_staged(struct stash_info *info, struct strbuf *out_patch,
11761176
{
11771177
int ret = 0;
11781178
struct child_process cp_diff_tree = CHILD_PROCESS_INIT;
1179-
struct index_state istate = INDEX_STATE_INIT;
1179+
struct index_state istate = INDEX_STATE_INIT(the_repository);
11801180

11811181
if (write_index_as_tree(&info->w_tree, &istate, the_repository->index_file,
11821182
0, NULL)) {
@@ -1209,7 +1209,7 @@ static int stash_patch(struct stash_info *info, const struct pathspec *ps,
12091209
int ret = 0;
12101210
struct child_process cp_read_tree = CHILD_PROCESS_INIT;
12111211
struct child_process cp_diff_tree = CHILD_PROCESS_INIT;
1212-
struct index_state istate = INDEX_STATE_INIT;
1212+
struct index_state istate = INDEX_STATE_INIT(the_repository);
12131213
char *old_index_env = NULL, *old_repo_index_file;
12141214

12151215
remove_path(stash_index_path.buf);
@@ -1271,7 +1271,7 @@ static int stash_working_tree(struct stash_info *info, const struct pathspec *ps
12711271
struct rev_info rev;
12721272
struct child_process cp_upd_index = CHILD_PROCESS_INIT;
12731273
struct strbuf diff_output = STRBUF_INIT;
1274-
struct index_state istate = INDEX_STATE_INIT;
1274+
struct index_state istate = INDEX_STATE_INIT(the_repository);
12751275

12761276
init_revisions(&rev, NULL);
12771277
copy_pathspec(&rev.prune_data, ps);

builtin/worktree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ static int unlock_worktree(int ac, const char **av, const char *prefix)
923923

924924
static void validate_no_submodules(const struct worktree *wt)
925925
{
926-
struct index_state istate = INDEX_STATE_INIT;
926+
struct index_state istate = INDEX_STATE_INIT(the_repository);
927927
struct strbuf path = STRBUF_INIT;
928928
int i, found_submodules = 0;
929929

cache.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,13 @@ struct index_state {
367367
* If the variable won't be used again, use release_index() to free()
368368
* its resources. If it needs to be used again use discard_index(),
369369
* which does the same thing, but will use use index_state_init() at
370-
* the end.
370+
* the end. The discard_index() will use its own "istate->repo" as the
371+
* "r" argument to index_state_init() in that case.
371372
*/
372-
#define INDEX_STATE_INIT { 0 }
373-
void index_state_init(struct index_state *istate);
373+
#define INDEX_STATE_INIT(r) { \
374+
.repo = (r), \
375+
}
376+
void index_state_init(struct index_state *istate, struct repository *r);
374377
void release_index(struct index_state *istate);
375378

376379
/* Name hashing */

fsmonitor-settings.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,6 @@ static void lookup_fsmonitor_settings(struct repository *r)
143143

144144
enum fsmonitor_mode fsm_settings__get_mode(struct repository *r)
145145
{
146-
if (!r)
147-
r = the_repository;
148146
if (!r->settings.fsmonitor)
149147
lookup_fsmonitor_settings(r);
150148

@@ -153,8 +151,6 @@ enum fsmonitor_mode fsm_settings__get_mode(struct repository *r)
153151

154152
const char *fsm_settings__get_hook_path(struct repository *r)
155153
{
156-
if (!r)
157-
r = the_repository;
158154
if (!r->settings.fsmonitor)
159155
lookup_fsmonitor_settings(r);
160156

@@ -174,8 +170,6 @@ void fsm_settings__set_ipc(struct repository *r)
174170
* Caller requested IPC explicitly, so avoid (possibly
175171
* recursive) config lookup.
176172
*/
177-
if (!r)
178-
r = the_repository;
179173
if (!r->settings.fsmonitor)
180174
r->settings.fsmonitor = alloc_settings();
181175

@@ -197,8 +191,6 @@ void fsm_settings__set_hook(struct repository *r, const char *path)
197191
* Caller requested hook explicitly, so avoid (possibly
198192
* recursive) config lookup.
199193
*/
200-
if (!r)
201-
r = the_repository;
202194
if (!r->settings.fsmonitor)
203195
r->settings.fsmonitor = alloc_settings();
204196

@@ -210,8 +202,6 @@ void fsm_settings__set_hook(struct repository *r, const char *path)
210202

211203
void fsm_settings__set_disabled(struct repository *r)
212204
{
213-
if (!r)
214-
r = the_repository;
215205
if (!r->settings.fsmonitor)
216206
r->settings.fsmonitor = alloc_settings();
217207

@@ -223,8 +213,6 @@ void fsm_settings__set_disabled(struct repository *r)
223213
void fsm_settings__set_incompatible(struct repository *r,
224214
enum fsmonitor_reason reason)
225215
{
226-
if (!r)
227-
r = the_repository;
228216
if (!r->settings.fsmonitor)
229217
r->settings.fsmonitor = alloc_settings();
230218

@@ -235,8 +223,6 @@ void fsm_settings__set_incompatible(struct repository *r,
235223

236224
enum fsmonitor_reason fsm_settings__get_reason(struct repository *r)
237225
{
238-
if (!r)
239-
r = the_repository;
240226
if (!r->settings.fsmonitor)
241227
lookup_fsmonitor_settings(r);
242228

fsmonitor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ void refresh_fsmonitor(struct index_state *istate)
304304
char *buf;
305305
unsigned int i;
306306
int is_trivial = 0;
307-
struct repository *r = istate->repo ? istate->repo : the_repository;
307+
struct repository *r = istate->repo;
308308
enum fsmonitor_mode fsm_mode = fsm_settings__get_mode(r);
309309
enum fsmonitor_reason reason = fsm_settings__get_reason(r);
310310

merge-recursive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ static int unpack_trees_start(struct merge_options *opt,
412412
{
413413
int rc;
414414
struct tree_desc t[3];
415-
struct index_state tmp_index = INDEX_STATE_INIT;
415+
struct index_state tmp_index = INDEX_STATE_INIT(opt->repo);
416416

417417
memset(&opt->priv->unpack_opts, 0, sizeof(opt->priv->unpack_opts));
418418
if (opt->priv->call_depth)

read-cache.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2300,8 +2300,6 @@ static void set_new_index_sparsity(struct index_state *istate)
23002300
* If the index's repo exists, mark it sparse according to
23012301
* repo settings.
23022302
*/
2303-
if (!istate->repo)
2304-
return;
23052303
prepare_repo_settings(istate->repo);
23062304
if (!istate->repo->settings.command_requires_full_index &&
23072305
is_sparse_index_allowed(istate, 0))
@@ -2330,8 +2328,6 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
23302328
fd = open(path, O_RDONLY);
23312329
if (fd < 0) {
23322330
if (!must_exist && errno == ENOENT) {
2333-
if (!istate->repo)
2334-
istate->repo = the_repository;
23352331
set_new_index_sparsity(istate);
23362332
return 0;
23372333
}
@@ -2433,9 +2429,6 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
24332429
trace2_data_intmax("index", the_repository, "read/cache_nr",
24342430
istate->cache_nr);
24352431

2436-
if (!istate->repo)
2437-
istate->repo = the_repository;
2438-
24392432
/*
24402433
* If the command explicitly requires a full index, force it
24412434
* to be full. Otherwise, correct the sparsity based on repository
@@ -2501,7 +2494,7 @@ int read_index_from(struct index_state *istate, const char *path,
25012494
release_index(split_index->base);
25022495
else
25032496
ALLOC_ARRAY(split_index->base, 1);
2504-
index_state_init(split_index->base);
2497+
index_state_init(split_index->base, istate->repo);
25052498

25062499
base_oid_hex = oid_to_hex(&split_index->base_oid);
25072500
base_path = xstrfmt("%s/sharedindex.%s", gitdir, base_oid_hex);
@@ -2540,9 +2533,9 @@ int is_index_unborn(struct index_state *istate)
25402533
return (!istate->cache_nr && !istate->timestamp.sec);
25412534
}
25422535

2543-
void index_state_init(struct index_state *istate)
2536+
void index_state_init(struct index_state *istate, struct repository *r)
25442537
{
2545-
struct index_state blank = INDEX_STATE_INIT;
2538+
struct index_state blank = INDEX_STATE_INIT(r);
25462539
memcpy(istate, &blank, sizeof(*istate));
25472540
}
25482541

@@ -2579,7 +2572,7 @@ void release_index(struct index_state *istate)
25792572
void discard_index(struct index_state *istate)
25802573
{
25812574
release_index(istate);
2582-
index_state_init(istate);
2575+
index_state_init(istate, istate->repo);
25832576
}
25842577

25852578
/*
@@ -2933,7 +2926,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
29332926
int ieot_entries = 1;
29342927
struct index_entry_offset_table *ieot = NULL;
29352928
int nr, nr_threads;
2936-
struct repository *r = istate->repo ? istate->repo : the_repository;
2929+
struct repository *r = istate->repo;
29372930

29382931
f = hashfd(tempfile->fd, tempfile->filename.buf);
29392932

0 commit comments

Comments
 (0)