Skip to content

Commit c806889

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 d3def43 + 65156ac commit c806889

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
@@ -155,7 +155,7 @@ static int checkout_all(struct index_state *index, const char *prefix, int prefi
155155
* first entry inside the expanded sparse directory).
156156
*/
157157
if (ignore_skip_worktree) {
158-
ensure_full_index(index);
158+
ensure_full_index_with_reason(index, "checkout-index");
159159
ce = index->cache[i];
160160
}
161161
}

builtin/commit.c

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

387387
/* TODO: audit for interaction with sparse-index. */
388-
ensure_full_index(the_repository->index);
388+
ensure_full_index_unaudited(the_repository->index);
389389
for (i = 0; i < the_repository->index->cache_nr; i++) {
390390
const struct cache_entry *ce = the_repository->index->cache[i];
391391
struct string_list_item *item;
@@ -1135,7 +1135,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
11351135
int i, ita_nr = 0;
11361136

11371137
/* TODO: audit for interaction with sparse-index. */
1138-
ensure_full_index(the_repository->index);
1138+
ensure_full_index_unaudited(the_repository->index);
11391139
for (i = 0; i < the_repository->index->cache_nr; i++)
11401140
if (ce_intent_to_add(the_repository->index->cache[i]))
11411141
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
@@ -815,7 +815,7 @@ static void fsck_index(struct index_state *istate, const char *index_path,
815815
unsigned int i;
816816

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

builtin/ls-files.c

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

416416
if (!show_sparse_dirs)
417-
ensure_full_index(repo->index);
417+
ensure_full_index_with_reason(repo->index, "ls-files");
418418

419419
for (i = 0; i < repo->index->cache_nr; i++) {
420420
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
@@ -231,7 +231,8 @@ int cmd_read_tree(int argc,
231231
setup_work_tree();
232232

233233
if (opts.skip_sparse_checkout)
234-
ensure_full_index(the_repository->index);
234+
ensure_full_index_with_reason(the_repository->index,
235+
"read-tree");
235236

236237
if (opts.merge) {
237238
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
@@ -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 (unsigned int 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)