Skip to content

Commit ee986cf

Browse files
derrickstoleedscho
authored andcommitted
treewide: custom reasons for expanding index
These cases that call ensure_full_index() are likely to be due to a data shape issue on a user's machine, so take the extra time to format a message that can be placed in their trace2 output and hopefully identify the problem that is leading to this slow behavior. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent f73dfc2 commit ee986cf

File tree

6 files changed

+24
-7
lines changed

6 files changed

+24
-7
lines changed

builtin/update-index.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,9 @@ static int do_reupdate(const char **paths,
714714
* to process each path individually
715715
*/
716716
if (S_ISSPARSEDIR(ce->ce_mode)) {
717-
ensure_full_index(the_repository->index);
717+
const char *fmt = "update-index:modified sparse dir '%s'";
718+
ensure_full_index_with_reason(the_repository->index,
719+
fmt, ce->name);
718720
goto redo;
719721
}
720722

merge-ort.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4569,7 +4569,8 @@ static int record_conflicted_index_entries(struct merge_options *opt)
45694569
*/
45704570
strmap_for_each_entry(&opt->priv->conflicted, &iter, e) {
45714571
if (!path_in_sparse_checkout(e->key, index)) {
4572-
ensure_full_index(index);
4572+
const char *fmt = "merge-ort: path outside sparse checkout (%s)";
4573+
ensure_full_index_with_reason(index, fmt, e->key);
45734574
break;
45744575
}
45754576
}

read-cache.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,9 @@ static int index_name_stage_pos(struct index_state *istate,
555555
if (S_ISSPARSEDIR(ce->ce_mode) &&
556556
ce_namelen(ce) < namelen &&
557557
!strncmp(name, ce->name, ce_namelen(ce))) {
558-
ensure_full_index(istate);
558+
const char *fmt = "searching for '%s' and found parent dir '%s'";
559+
ensure_full_index_with_reason(istate, fmt,
560+
name, ce->name);
559561
return index_name_stage_pos(istate, name, namelen, stage, search_mode);
560562
}
561563
}

sparse-index.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,9 @@ void expand_to_path(struct index_state *istate,
758758
* in the index, perhaps it exists within this
759759
* sparse-directory. Expand accordingly.
760760
*/
761-
ensure_full_index(istate);
761+
const char *fmt = "found index entry for '%s'";
762+
ensure_full_index_with_reason(istate, fmt,
763+
path_mutable.buf);
762764
break;
763765
}
764766

t/t1092-sparse-checkout-compatibility.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2654,7 +2654,15 @@ test_expect_success 'ensure_full_index_with_reason' '
26542654
26552655
GIT_TRACE2_EVENT="$(pwd)/ls-files-trace" \
26562656
git -C sparse-index ls-files --no-sparse HEAD &&
2657-
test_trace2_data "sparse-index" "expansion-reason" "ls-files" <ls-files-trace
2657+
test_trace2_data "sparse-index" "expansion-reason" "ls-files" <ls-files-trace &&
2658+
2659+
mkdir -p sparse-index/folder2 &&
2660+
echo >sparse-index/folder2/a &&
2661+
GIT_TRACE2_EVENT="$(pwd)/status-trace" \
2662+
git -C sparse-index status &&
2663+
test_trace2_data "sparse-index" "skip-worktree sparsedir" "folder2/" <status-trace &&
2664+
test_trace2_data "sparse-index" "expansion-reason" \
2665+
"failed to clear skip-worktree while sparse" <status-trace
26582666
'
26592667

26602668
test_done

unpack-trees.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,8 +1893,10 @@ static void update_sparsity_for_prefix(const char *prefix,
18931893
* the 'ensure_full_index(...)' below.
18941894
*/
18951895
if (!path_in_cone_mode_sparse_checkout(ce_prefix.buf, istate) &&
1896-
index_name_pos(istate, ce_prefix.buf, ce_prefix.len) >= 0)
1897-
ensure_full_index(istate);
1896+
index_name_pos(istate, ce_prefix.buf, ce_prefix.len) >= 0) {
1897+
const char *fmt = "could not find '%s' in index";
1898+
ensure_full_index_with_reason(istate, fmt, ce_prefix.buf);
1899+
}
18981900

18991901
strbuf_release(&ce_prefix);
19001902
}

0 commit comments

Comments
 (0)