Skip to content

Commit 7a919dc

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 1991d52 commit 7a919dc

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
@@ -156,7 +156,8 @@ static int checkout_all(const char *prefix, int prefix_length)
156156
* first entry inside the expanded sparse directory).
157157
*/
158158
if (ignore_skip_worktree) {
159-
ensure_full_index(the_repository->index);
159+
ensure_full_index_with_reason(the_repository->index,
160+
"checkout-index");
160161
ce = the_repository->index->cache[i];
161162
}
162163
}

builtin/ls-files.c

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

415415
if (!show_sparse_dirs)
416-
ensure_full_index(repo->index);
416+
ensure_full_index_with_reason(repo->index, "ls-files");
417417

418418
for (i = 0; i < repo->index->cache_nr; i++) {
419419
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
@@ -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
@@ -313,7 +313,8 @@ int cmd_rm(int argc,
313313
seen = xcalloc(pathspec.nr, 1);
314314

315315
if (pathspec_needs_expanded_index(the_repository->index, &pathspec))
316-
ensure_full_index(the_repository->index);
316+
ensure_full_index_with_reason(the_repository->index,
317+
"rm pathspec");
317318

318319
for (i = 0; i < the_repository->index->cache_nr; i++) {
319320
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
@@ -207,7 +207,8 @@ static void clean_tracked_sparse_directories(struct repository *r)
207207
strbuf_release(&path);
208208

209209
if (was_full)
210-
ensure_full_index(r->index);
210+
ensure_full_index_with_reason(r->index,
211+
"sparse-checkout:was full");
211212
}
212213

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

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

443445
return 0;

read-cache.c

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

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

32103210
if (was_full)
3211-
ensure_full_index(istate);
3211+
ensure_full_index_with_reason(istate, "re-expanding after write");
32123212

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

33213321
if (was_full)
3322-
ensure_full_index(istate);
3322+
ensure_full_index_with_reason(istate, "re-expanding after write");
33233323

33243324
if (ret)
33253325
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
@@ -797,7 +797,7 @@ static int do_recursive_merge(struct repository *r,
797797
merge_switch_to_result(&o, head_tree, &result, 1, show_output);
798798
clean = result.clean;
799799
} else {
800-
ensure_full_index(r->index);
800+
ensure_full_index_with_reason(r->index, "non-ort merge strategy");
801801
clean = merge_trees(&o, head_tree, next_tree, base_tree);
802802
if (is_rebase_i(opts) && clean <= 0)
803803
fputs(o.obuf.buf, stdout);
@@ -2574,7 +2574,7 @@ static int read_and_refresh_cache(struct repository *r,
25742574
* expand the sparse index.
25752575
*/
25762576
if (opts->strategy && strcmp(opts->strategy, "ort"))
2577-
ensure_full_index(r->index);
2577+
ensure_full_index_with_reason(r->index, "non-ort merge strategy");
25782578
return 0;
25792579
}
25802580

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
}

t/t1092-sparse-checkout-compatibility.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2500,4 +2500,12 @@ test_expect_success 'cat-file --batch' '
25002500
ensure_expanded cat-file --batch <in
25012501
'
25022502

2503+
test_expect_success 'ensure_full_index_with_reason' '
2504+
init_repos &&
2505+
2506+
GIT_TRACE2_EVENT="$(pwd)/ls-files-trace" \
2507+
git -C sparse-index ls-files --no-sparse HEAD &&
2508+
test_trace2_data "sparse-index" "expansion-reason" "ls-files" <ls-files-trace
2509+
'
2510+
25032511
test_done

unpack-trees.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,9 +1936,9 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
19361936

19371937
prepare_repo_settings(repo);
19381938
if (repo->settings.command_requires_full_index) {
1939-
ensure_full_index(o->src_index);
1939+
ensure_full_index_with_reason(o->src_index, "incompatible builtin");
19401940
if (o->dst_index)
1941-
ensure_full_index(o->dst_index);
1941+
ensure_full_index_with_reason(o->dst_index, "incompatible builtin");
19421942
}
19431943

19441944
if (o->reset == UNPACK_RESET_OVERWRITE_UNTRACKED &&

0 commit comments

Comments
 (0)