Skip to content

Commit cfaf999

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 0c19f8e commit cfaf999

File tree

12 files changed

+33
-17
lines changed

12 files changed

+33
-17
lines changed

builtin/checkout-index.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ static int checkout_all(const char *prefix, int prefix_length)
153153
* first entry inside the expanded sparse directory).
154154
*/
155155
if (ignore_skip_worktree) {
156-
ensure_full_index(the_repository->index);
156+
ensure_full_index_with_reason(the_repository->index,
157+
"checkout-index");
157158
ce = the_repository->index->cache[i];
158159
}
159160
}

builtin/ls-files.c

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

412412
if (!show_sparse_dirs)
413-
ensure_full_index(repo->index);
413+
ensure_full_index_with_reason(repo->index, "ls-files");
414414

415415
for (i = 0; i < repo->index->cache_nr; i++) {
416416
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
@@ -226,7 +226,8 @@ int cmd_read_tree(int argc,
226226
setup_work_tree();
227227

228228
if (opts.skip_sparse_checkout)
229-
ensure_full_index(the_repository->index);
229+
ensure_full_index_with_reason(the_repository->index,
230+
"read-tree");
230231

231232
if (opts.merge) {
232233
switch (stage - 1) {

builtin/reset.c

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

262262
if (pathspec->nr && pathspec_needs_expanded_index(the_repository->index, pathspec))
263-
ensure_full_index(the_repository->index);
263+
ensure_full_index_with_reason(the_repository->index,
264+
"reset pathspec");
264265

265266
if (do_diff_cache(tree_oid, &opt))
266267
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 (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
@@ -205,7 +205,8 @@ static void clean_tracked_sparse_directories(struct repository *r)
205205
strbuf_release(&path);
206206

207207
if (was_full)
208-
ensure_full_index(r->index);
208+
ensure_full_index_with_reason(r->index,
209+
"sparse-checkout:was full");
209210
}
210211

211212
static int update_working_directory(struct pattern_list *pl)
@@ -435,7 +436,8 @@ static int update_modes(int *cone_mode, int *sparse_index)
435436
the_repository->index->updated_workdir = 1;
436437

437438
if (!*sparse_index)
438-
ensure_full_index(the_repository->index);
439+
ensure_full_index_with_reason(the_repository->index,
440+
"sparse-checkout:disabling sparse index");
439441
}
440442

441443
return 0;

read-cache.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2375,7 +2375,7 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
23752375
*/
23762376
prepare_repo_settings(istate->repo);
23772377
if (istate->repo->settings.command_requires_full_index)
2378-
ensure_full_index(istate);
2378+
ensure_full_index_with_reason(istate, "incompatible builtin");
23792379
else
23802380
ensure_correct_sparsity(istate);
23812381

@@ -3207,7 +3207,7 @@ static int do_write_locked_index(struct index_state *istate,
32073207
"%s", get_lock_file_path(lock));
32083208

32093209
if (was_full)
3210-
ensure_full_index(istate);
3210+
ensure_full_index_with_reason(istate, "re-expanding after write");
32113211

32123212
if (ret)
32133213
return ret;
@@ -3318,7 +3318,7 @@ static int write_shared_index(struct index_state *istate,
33183318
the_repository, "%s", get_tempfile_path(*temp));
33193319

33203320
if (was_full)
3321-
ensure_full_index(istate);
3321+
ensure_full_index_with_reason(istate, "re-expanding after write");
33223322

33233323
if (ret)
33243324
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ static int do_recursive_merge(struct repository *r,
796796
merge_switch_to_result(&o, head_tree, &result, 1, show_output);
797797
clean = result.clean;
798798
} else {
799-
ensure_full_index(r->index);
799+
ensure_full_index_with_reason(r->index, "non-ort merge strategy");
800800
clean = merge_trees(&o, head_tree, next_tree, base_tree);
801801
if (is_rebase_i(opts) && clean <= 0)
802802
fputs(o.obuf.buf, stdout);
@@ -2573,7 +2573,7 @@ static int read_and_refresh_cache(struct repository *r,
25732573
* expand the sparse index.
25742574
*/
25752575
if (opts->strategy && strcmp(opts->strategy, "ort"))
2576-
ensure_full_index(r->index);
2576+
ensure_full_index_with_reason(r->index, "non-ort merge strategy");
25772577
return 0;
25782578
}
25792579

sparse-index.c

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

495496
struct path_found_data {
@@ -692,7 +693,8 @@ void clear_skip_worktree_from_present_files(struct index_state *istate)
692693
return;
693694

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

0 commit comments

Comments
 (0)