Skip to content

Commit 2332092

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 9cb2790 commit 2332092

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
@@ -4534,7 +4534,8 @@ static int record_conflicted_index_entries(struct merge_options *opt)
45344534
*/
45354535
strmap_for_each_entry(&opt->priv->conflicted, &iter, e) {
45364536
if (!path_in_sparse_checkout(e->key, index)) {
4537-
ensure_full_index(index);
4537+
const char *fmt = "merge-ort: path outside sparse checkout (%s)";
4538+
ensure_full_index_with_reason(index, fmt, e->key);
45384539
break;
45394540
}
45404541
}

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
@@ -2505,7 +2505,15 @@ test_expect_success 'ensure_full_index_with_reason' '
25052505
25062506
GIT_TRACE2_EVENT="$(pwd)/ls-files-trace" \
25072507
git -C sparse-index ls-files --no-sparse HEAD &&
2508-
test_trace2_data "sparse-index" "expansion-reason" "ls-files" <ls-files-trace
2508+
test_trace2_data "sparse-index" "expansion-reason" "ls-files" <ls-files-trace &&
2509+
2510+
mkdir -p sparse-index/folder2 &&
2511+
echo >sparse-index/folder2/a &&
2512+
GIT_TRACE2_EVENT="$(pwd)/status-trace" \
2513+
git -C sparse-index status &&
2514+
test_trace2_data "sparse-index" "skip-worktree sparsedir" "folder2/" <status-trace &&
2515+
test_trace2_data "sparse-index" "expansion-reason" \
2516+
"failed to clear skip-worktree while sparse" <status-trace
25092517
'
25102518

25112519
test_done

unpack-trees.c

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

18971899
strbuf_release(&ce_prefix);
18981900
}

0 commit comments

Comments
 (0)