Skip to content

Commit b7ac150

Browse files
dschomjcheetham
authored andcommitted
Sparse Index: log why the index is being expanded (git#691)
I will intend to send this upstream after the 2.47.0 release cycle, but this should get to our microsoft/git users for maximum impact. Customers have been struggling with explaining why the sparse index expansion advice message is showing up. The advice to run 'git clean' has not always helped folks, and sometimes it is very unclear why we are running into trouble. These changes introduce a way to log a reason for the expansion into the trace2 logs so it can be found by requesting that a user enable tracing. While testing this, I created the most standard case that happens, which is to have an existing directory match a sparse directory in the index. In this case, it showed that two log messages were required. See the last commit for this new log message. Together, these two places show this kind of message in the `GIT_TRACE2_PERF` output (trimmed for clarity): ``` region_enter | index | label:clear_skip_worktree_from_present_files_sparse data | sparse-index | ..skip-worktree sparsedir:<my-sparse-path>/ data | index | ..sparse_path_count:362 data | index | ..sparse_lstat_count:732 region_leave | index | label:clear_skip_worktree_from_present_files_sparse data | sparse-index | expansion-reason:failed to clear skip-worktree while sparse ``` I added some tests to demonstrate that these logs are recorded, but it also seems difficult to hit some of these cases.
2 parents f665caa + 4736f84 commit b7ac150

26 files changed

+111
-37
lines changed

Documentation/technical/sparse-index.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,10 @@ Here are some commands that might be useful to update:
206206
* `git am`
207207
* `git clean`
208208
* `git stash`
209+
210+
In order to help identify the cases where remaining index expansion is
211+
occurring in user machines, calls to `ensure_full_index()` have been
212+
replaced with `ensure_full_index_with_reason()` or with
213+
`ensure_full_index_unaudited()`. These versions add tracing that should
214+
help identify the reason for the index expansion without needing full
215+
access to someone's repository.

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/commit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ static int list_paths(struct string_list *list, const char *with_tree,
382382
}
383383

384384
/* TODO: audit for interaction with sparse-index. */
385-
ensure_full_index(the_repository->index);
385+
ensure_full_index_unaudited(the_repository->index);
386386
for (i = 0; i < the_repository->index->cache_nr; i++) {
387387
const struct cache_entry *ce = the_repository->index->cache[i];
388388
struct string_list_item *item;
@@ -1123,7 +1123,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
11231123
int i, ita_nr = 0;
11241124

11251125
/* TODO: audit for interaction with sparse-index. */
1126-
ensure_full_index(the_repository->index);
1126+
ensure_full_index_unaudited(the_repository->index);
11271127
for (i = 0; i < the_repository->index->cache_nr; i++)
11281128
if (ce_intent_to_add(the_repository->index->cache[i]))
11291129
ita_nr++;

builtin/difftool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
588588
ret = run_command(&cmd);
589589

590590
/* TODO: audit for interaction with sparse-index. */
591-
ensure_full_index(&wtindex);
591+
ensure_full_index_unaudited(&wtindex);
592592

593593
/*
594594
* If the diff includes working copy files and those

builtin/fsck.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ static void fsck_index(struct index_state *istate, const char *index_path,
818818
unsigned int i;
819819

820820
/* TODO: audit for interaction with sparse-index. */
821-
ensure_full_index(istate);
821+
ensure_full_index_unaudited(istate);
822822
for (i = 0; i < istate->cache_nr; i++) {
823823
unsigned int mode;
824824
struct blob *blob;

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/merge-index.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static void merge_all(void)
6464
{
6565
int i;
6666
/* TODO: audit for interaction with sparse-index. */
67-
ensure_full_index(the_repository->index);
67+
ensure_full_index_unaudited(the_repository->index);
6868
for (i = 0; i < the_repository->index->cache_nr; i++) {
6969
const struct cache_entry *ce = the_repository->index->cache[i];
7070
if (!ce_stage(ce))
@@ -91,7 +91,7 @@ int cmd_merge_index(int argc,
9191
repo_read_index(the_repository);
9292

9393
/* TODO: audit for interaction with sparse-index. */
94-
ensure_full_index(the_repository->index);
94+
ensure_full_index_unaudited(the_repository->index);
9595

9696
i = 1;
9797
if (!strcmp(argv[i], "-o")) {

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];

0 commit comments

Comments
 (0)