Skip to content

Commit 1190d47

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 <stolee@gmail.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent af8dfd8 commit 1190d47

12 files changed

Lines changed: 31 additions & 16 deletions

‎builtin/checkout-index.c‎

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

‎builtin/ls-files.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ static void show_files(struct repository *repo, struct dir_struct *dir)
425425
* so expansion will leave the first 'i' entries
426426
* alone.
427427
*/
428-
ensure_full_index(repo->index);
428+
ensure_full_index_with_reason(repo->index, "ls-files");
429429
ce = repo->index->cache[i];
430430
}
431431

‎builtin/read-tree.c‎

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

234234
if (opts.skip_sparse_checkout)
235-
ensure_full_index(the_repository->index);
235+
ensure_full_index_with_reason(the_repository->index,
236+
"read-tree");
236237

237238
if (opts.merge) {
238239
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
@@ -311,7 +311,8 @@ int cmd_rm(int argc,
311311
seen = xcalloc(pathspec.nr, 1);
312312

313313
if (pathspec_needs_expanded_index(the_repository->index, &pathspec))
314-
ensure_full_index(the_repository->index);
314+
ensure_full_index_with_reason(the_repository->index,
315+
"rm pathspec");
315316

316317
for (unsigned int i = 0; i < the_repository->index->cache_nr; i++) {
317318
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
@@ -209,7 +209,8 @@ static void clean_tracked_sparse_directories(struct repository *r)
209209
strbuf_release(&path);
210210

211211
if (was_full)
212-
ensure_full_index(r->index);
212+
ensure_full_index_with_reason(r->index,
213+
"sparse-checkout:was full");
213214
}
214215

215216
static int update_working_directory(struct repository *r,
@@ -441,7 +442,8 @@ static int update_modes(struct repository *repo, int *cone_mode, int *sparse_ind
441442
repo->index->updated_workdir = 1;
442443

443444
if (!*sparse_index)
444-
ensure_full_index(repo->index);
445+
ensure_full_index_with_reason(repo->index,
446+
"sparse-checkout:disabling sparse index");
445447
}
446448

447449
return 0;

‎read-cache.c‎

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

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

31813181
if (was_full)
3182-
ensure_full_index(istate);
3182+
ensure_full_index_with_reason(istate, "re-expanding after write");
31833183

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

32963296
if (was_full)
3297-
ensure_full_index(istate);
3297+
ensure_full_index_with_reason(istate, "re-expanding after write");
32983298

32993299
if (ret)
33003300
return ret;

‎repository.c‎

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

431431
prepare_repo_settings(repo);
432432
if (repo->settings.command_requires_full_index)
433-
ensure_full_index(repo->index);
433+
ensure_full_index_with_reason(repo->index, "incompatible builtin");
434434

435435
/*
436436
* 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
@@ -2605,7 +2605,7 @@ static int read_and_refresh_cache(struct repository *r,
26052605
* expand the sparse index.
26062606
*/
26072607
if (opts->strategy && strcmp(opts->strategy, "ort"))
2608-
ensure_full_index(r->index);
2608+
ensure_full_index_with_reason(r->index, "non-ort merge strategy");
26092609
return 0;
26102610
}
26112611

‎sparse-index.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,8 @@ void ensure_correct_sparsity(struct index_state *istate)
492492
if (is_sparse_index_allowed(istate, 0))
493493
convert_to_sparse(istate, 0);
494494
else
495-
ensure_full_index(istate);
495+
ensure_full_index_with_reason(istate,
496+
"sparse index not allowed");
496497
}
497498

498499
struct path_found_data {
@@ -695,7 +696,8 @@ void clear_skip_worktree_from_present_files(struct index_state *istate)
695696
return;
696697

697698
if (clear_skip_worktree_from_present_files_sparse(istate)) {
698-
ensure_full_index(istate);
699+
ensure_full_index_with_reason(istate,
700+
"failed to clear skip-worktree while sparse");
699701
clear_skip_worktree_from_present_files_full(istate);
700702
}
701703
}

0 commit comments

Comments
 (0)