Skip to content

Commit 90f112f

Browse files
committed
Sparse Index: log why the index is being expanded (#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 4c76659 + b4cd555 commit 90f112f

25 files changed

+108
-35
lines changed

Documentation/technical/sparse-index.adoc

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

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

389389
/* TODO: audit for interaction with sparse-index. */
390-
ensure_full_index(the_repository->index);
390+
ensure_full_index_unaudited(the_repository->index);
391391
for (i = 0; i < the_repository->index->cache_nr; i++) {
392392
const struct cache_entry *ce = the_repository->index->cache[i];
393393
struct string_list_item *item;
@@ -1151,7 +1151,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
11511151
int i, ita_nr = 0;
11521152

11531153
/* TODO: audit for interaction with sparse-index. */
1154-
ensure_full_index(the_repository->index);
1154+
ensure_full_index_unaudited(the_repository->index);
11551155
for (i = 0; i < the_repository->index->cache_nr; i++)
11561156
if (ce_intent_to_add(the_repository->index->cache[i]))
11571157
ita_nr++;

builtin/difftool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ static int run_dir_diff(struct repository *repo,
607607
ret = run_command(&cmd);
608608

609609
/* TODO: audit for interaction with sparse-index. */
610-
ensure_full_index(&wtindex);
610+
ensure_full_index_unaudited(&wtindex);
611611

612612
/*
613613
* 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
@@ -817,7 +817,7 @@ static void fsck_index(struct index_state *istate, const char *index_path,
817817
unsigned int i;
818818

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

builtin/ls-files.c

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

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

420420
for (i = 0; i < repo->index->cache_nr; i++) {
421421
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
@@ -66,7 +66,7 @@ static void merge_all(void)
6666
{
6767
int i;
6868
/* TODO: audit for interaction with sparse-index. */
69-
ensure_full_index(the_repository->index);
69+
ensure_full_index_unaudited(the_repository->index);
7070
for (i = 0; i < the_repository->index->cache_nr; i++) {
7171
const struct cache_entry *ce = the_repository->index->cache[i];
7272
if (!ce_stage(ce))
@@ -98,7 +98,7 @@ int cmd_merge_index(int argc,
9898
repo_read_index(the_repository);
9999

100100
/* TODO: audit for interaction with sparse-index. */
101-
ensure_full_index(the_repository->index);
101+
ensure_full_index_unaudited(the_repository->index);
102102

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

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

0 commit comments

Comments
 (0)