Skip to content

Commit 3df0b6b

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 <stolee@gmail.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent cfaf999 commit 3df0b6b

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
@@ -711,7 +711,9 @@ static int do_reupdate(const char **paths,
711711
* to process each path individually
712712
*/
713713
if (S_ISSPARSEDIR(ce->ce_mode)) {
714-
ensure_full_index(the_repository->index);
714+
const char *fmt = "update-index:modified sparse dir '%s'";
715+
ensure_full_index_with_reason(the_repository->index,
716+
fmt, ce->name);
715717
goto redo;
716718
}
717719

merge-ort.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4533,7 +4533,8 @@ static int record_conflicted_index_entries(struct merge_options *opt)
45334533
*/
45344534
strmap_for_each_entry(&opt->priv->conflicted, &iter, e) {
45354535
if (!path_in_sparse_checkout(e->key, index)) {
4536-
ensure_full_index(index);
4536+
const char *fmt = "merge-ort: path outside sparse checkout (%s)";
4537+
ensure_full_index_with_reason(index, fmt, e->key);
45374538
break;
45384539
}
45394540
}

read-cache.c

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

sparse-index.c

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

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
@@ -1890,8 +1890,10 @@ static void update_sparsity_for_prefix(const char *prefix,
18901890
* the 'ensure_full_index(...)' below.
18911891
*/
18921892
if (!path_in_cone_mode_sparse_checkout(ce_prefix.buf, istate) &&
1893-
index_name_pos(istate, ce_prefix.buf, ce_prefix.len) >= 0)
1894-
ensure_full_index(istate);
1893+
index_name_pos(istate, ce_prefix.buf, ce_prefix.len) >= 0) {
1894+
const char *fmt = "could not find '%s' in index";
1895+
ensure_full_index_with_reason(istate, fmt, ce_prefix.buf);
1896+
}
18951897

18961898
strbuf_release(&ce_prefix);
18971899
}

0 commit comments

Comments
 (0)