Skip to content

Commit 534667e

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 d317712 commit 534667e

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
@@ -706,7 +706,9 @@ static int do_reupdate(const char **paths,
706706
* to process each path individually
707707
*/
708708
if (S_ISSPARSEDIR(ce->ce_mode)) {
709-
ensure_full_index(the_repository->index);
709+
const char *fmt = "update-index:modified sparse dir '%s'";
710+
ensure_full_index_with_reason(the_repository->index,
711+
fmt, ce->name);
710712
goto redo;
711713
}
712714

merge-ort.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4594,7 +4594,8 @@ static int record_conflicted_index_entries(struct merge_options *opt)
45944594
*/
45954595
strmap_for_each_entry(&opt->priv->conflicted, &iter, e) {
45964596
if (!path_in_sparse_checkout(e->key, index)) {
4597-
ensure_full_index(index);
4597+
const char *fmt = "merge-ort: path outside sparse checkout (%s)";
4598+
ensure_full_index_with_reason(index, fmt, e->key);
45984599
break;
45994600
}
46004601
}

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
@@ -760,7 +760,9 @@ void expand_to_path(struct index_state *istate,
760760
* in the index, perhaps it exists within this
761761
* sparse-directory. Expand accordingly.
762762
*/
763-
ensure_full_index(istate);
763+
const char *fmt = "found index entry for '%s'";
764+
ensure_full_index_with_reason(istate, fmt,
765+
path_mutable.buf);
764766
break;
765767
}
766768

t/t1092-sparse-checkout-compatibility.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2667,7 +2667,15 @@ test_expect_success 'ensure_full_index_with_reason' '
26672667
26682668
GIT_TRACE2_EVENT="$(pwd)/ls-files-trace" \
26692669
git -C sparse-index ls-files --no-sparse HEAD &&
2670-
test_trace2_data "sparse-index" "expansion-reason" "ls-files" <ls-files-trace
2670+
test_trace2_data "sparse-index" "expansion-reason" "ls-files" <ls-files-trace &&
2671+
2672+
mkdir -p sparse-index/folder2 &&
2673+
echo >sparse-index/folder2/a &&
2674+
GIT_TRACE2_EVENT="$(pwd)/status-trace" \
2675+
git -C sparse-index status &&
2676+
test_trace2_data "sparse-index" "skip-worktree sparsedir" "folder2/" <status-trace &&
2677+
test_trace2_data "sparse-index" "expansion-reason" \
2678+
"failed to clear skip-worktree while sparse" <status-trace
26712679
'
26722680

26732681
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)