Skip to content

Commit 8582af3

Browse files
derrickstoleedscho
authored andcommitted
treewide: add reasons for expanding index
These locations that previously called ensure_full_index() are now updated to call the ..._with_reason() varation using fixed strings that should be enough to identify the reason for the expansion. This will help users use tracing to determine why the index is expanding in their scenarios. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 9dbe49e commit 8582af3

12 files changed

+31
-16
lines changed

builtin/checkout-index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ static int checkout_all(struct index_state *index, const char *prefix, int prefi
155155
* first entry inside the expanded sparse directory).
156156
*/
157157
if (ignore_skip_worktree) {
158-
ensure_full_index(index);
158+
ensure_full_index_with_reason(index, "checkout-index");
159159
ce = index->cache[i];
160160
}
161161
}

builtin/ls-files.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ static void show_files(struct repository *repo, struct dir_struct *dir)
414414
return;
415415

416416
if (!show_sparse_dirs)
417-
ensure_full_index(repo->index);
417+
ensure_full_index_with_reason(repo->index, "ls-files");
418418

419419
for (i = 0; i < repo->index->cache_nr; i++) {
420420
const struct cache_entry *ce = repo->index->cache[i];

builtin/read-tree.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ int cmd_read_tree(int argc,
231231
setup_work_tree();
232232

233233
if (opts.skip_sparse_checkout)
234-
ensure_full_index(the_repository->index);
234+
ensure_full_index_with_reason(the_repository->index,
235+
"read-tree");
235236

236237
if (opts.merge) {
237238
switch (stage - 1) {

builtin/reset.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,8 @@ static int read_from_tree(const struct pathspec *pathspec,
262262
opt.add_remove = diff_addremove;
263263

264264
if (pathspec->nr && pathspec_needs_expanded_index(the_repository->index, pathspec))
265-
ensure_full_index(the_repository->index);
265+
ensure_full_index_with_reason(the_repository->index,
266+
"reset pathspec");
266267

267268
if (do_diff_cache(tree_oid, &opt))
268269
return 1;

builtin/rm.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,8 @@ int cmd_rm(int argc,
310310
seen = xcalloc(pathspec.nr, 1);
311311

312312
if (pathspec_needs_expanded_index(the_repository->index, &pathspec))
313-
ensure_full_index(the_repository->index);
313+
ensure_full_index_with_reason(the_repository->index,
314+
"rm pathspec");
314315

315316
for (unsigned int i = 0; i < the_repository->index->cache_nr; i++) {
316317
const struct cache_entry *ce = the_repository->index->cache[i];

builtin/sparse-checkout.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ static void clean_tracked_sparse_directories(struct repository *r)
208208
strbuf_release(&path);
209209

210210
if (was_full)
211-
ensure_full_index(r->index);
211+
ensure_full_index_with_reason(r->index,
212+
"sparse-checkout:was full");
212213
}
213214

214215
static int update_working_directory(struct pattern_list *pl)
@@ -438,7 +439,8 @@ static int update_modes(int *cone_mode, int *sparse_index)
438439
the_repository->index->updated_workdir = 1;
439440

440441
if (!*sparse_index)
441-
ensure_full_index(the_repository->index);
442+
ensure_full_index_with_reason(the_repository->index,
443+
"sparse-checkout:disabling sparse index");
442444
}
443445

444446
return 0;

read-cache.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2348,7 +2348,7 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
23482348
*/
23492349
prepare_repo_settings(istate->repo);
23502350
if (istate->repo->settings.command_requires_full_index)
2351-
ensure_full_index(istate);
2351+
ensure_full_index_with_reason(istate, "incompatible builtin");
23522352
else
23532353
ensure_correct_sparsity(istate);
23542354

@@ -3180,7 +3180,7 @@ static int do_write_locked_index(struct index_state *istate,
31803180
"%s", get_lock_file_path(lock));
31813181

31823182
if (was_full)
3183-
ensure_full_index(istate);
3183+
ensure_full_index_with_reason(istate, "re-expanding after write");
31843184

31853185
if (ret)
31863186
return ret;
@@ -3295,7 +3295,7 @@ static int write_shared_index(struct index_state *istate,
32953295
the_repository, "%s", get_tempfile_path(*temp));
32963296

32973297
if (was_full)
3298-
ensure_full_index(istate);
3298+
ensure_full_index_with_reason(istate, "re-expanding after write");
32993299

33003300
if (ret)
33013301
return ret;

repository.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ int repo_read_index(struct repository *repo)
434434

435435
prepare_repo_settings(repo);
436436
if (repo->settings.command_requires_full_index)
437-
ensure_full_index(repo->index);
437+
ensure_full_index_with_reason(repo->index, "incompatible builtin");
438438

439439
/*
440440
* If sparse checkouts are in use, check whether paths with the

sequencer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2607,7 +2607,7 @@ static int read_and_refresh_cache(struct repository *r,
26072607
* expand the sparse index.
26082608
*/
26092609
if (opts->strategy && strcmp(opts->strategy, "ort"))
2610-
ensure_full_index(r->index);
2610+
ensure_full_index_with_reason(r->index, "non-ort merge strategy");
26112611
return 0;
26122612
}
26132613

sparse-index.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,8 @@ void ensure_correct_sparsity(struct index_state *istate)
490490
if (is_sparse_index_allowed(istate, 0))
491491
convert_to_sparse(istate, 0);
492492
else
493-
ensure_full_index(istate);
493+
ensure_full_index_with_reason(istate,
494+
"sparse index not allowed");
494495
}
495496

496497
struct path_found_data {
@@ -693,7 +694,8 @@ void clear_skip_worktree_from_present_files(struct index_state *istate)
693694
return;
694695

695696
if (clear_skip_worktree_from_present_files_sparse(istate)) {
696-
ensure_full_index(istate);
697+
ensure_full_index_with_reason(istate,
698+
"failed to clear skip-worktree while sparse");
697699
clear_skip_worktree_from_present_files_full(istate);
698700
}
699701
}

0 commit comments

Comments
 (0)