From 67f9786c148c2f62772853ec3fee374a72b83399 Mon Sep 17 00:00:00 2001 From: Derrick Stolee Date: Mon, 30 Sep 2024 16:59:07 -0400 Subject: [PATCH] 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 Signed-off-by: Johannes Schindelin --- builtin/update-index.c | 4 +++- merge-ort.c | 3 ++- read-cache.c | 4 +++- sparse-index.c | 4 +++- t/t1092-sparse-checkout-compatibility.sh | 10 +++++++++- unpack-trees.c | 6 ++++-- 6 files changed, 24 insertions(+), 7 deletions(-) diff --git a/builtin/update-index.c b/builtin/update-index.c index c838c8e6a30073..a1e20bfce9ac37 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -711,7 +711,9 @@ static int do_reupdate(const char **paths, * to process each path individually */ if (S_ISSPARSEDIR(ce->ce_mode)) { - ensure_full_index(the_repository->index); + const char *fmt = "update-index:modified sparse dir '%s'"; + ensure_full_index_with_reason(the_repository->index, + fmt, ce->name); goto redo; } diff --git a/merge-ort.c b/merge-ort.c index 11029c10be3d2b..143bf85475cb55 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -4533,7 +4533,8 @@ static int record_conflicted_index_entries(struct merge_options *opt) */ strmap_for_each_entry(&opt->priv->conflicted, &iter, e) { if (!path_in_sparse_checkout(e->key, index)) { - ensure_full_index(index); + const char *fmt = "merge-ort: path outside sparse checkout (%s)"; + ensure_full_index_with_reason(index, fmt, e->key); break; } } diff --git a/read-cache.c b/read-cache.c index 85ddd222a314fd..33e9fa6c44a2c2 100644 --- a/read-cache.c +++ b/read-cache.c @@ -554,7 +554,9 @@ static int index_name_stage_pos(struct index_state *istate, if (S_ISSPARSEDIR(ce->ce_mode) && ce_namelen(ce) < namelen && !strncmp(name, ce->name, ce_namelen(ce))) { - ensure_full_index(istate); + const char *fmt = "searching for '%s' and found parent dir '%s'"; + ensure_full_index_with_reason(istate, fmt, + name, ce->name); return index_name_stage_pos(istate, name, namelen, stage, search_mode); } } diff --git a/sparse-index.c b/sparse-index.c index 51e6eefa02ba38..f4ea5cded939aa 100644 --- a/sparse-index.c +++ b/sparse-index.c @@ -757,7 +757,9 @@ void expand_to_path(struct index_state *istate, * in the index, perhaps it exists within this * sparse-directory. Expand accordingly. */ - ensure_full_index(istate); + const char *fmt = "found index entry for '%s'"; + ensure_full_index_with_reason(istate, fmt, + path_mutable.buf); break; } diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh index 683158d56c5519..894ece6fe4e8ca 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -2505,7 +2505,15 @@ test_expect_success 'ensure_full_index_with_reason' ' GIT_TRACE2_EVENT="$(pwd)/ls-files-trace" \ git -C sparse-index ls-files --no-sparse HEAD && - test_trace2_data "sparse-index" "expansion-reason" "ls-files" sparse-index/folder2/a && + GIT_TRACE2_EVENT="$(pwd)/status-trace" \ + git -C sparse-index status && + test_trace2_data "sparse-index" "skip-worktree sparsedir" "folder2/" = 0) - ensure_full_index(istate); + index_name_pos(istate, ce_prefix.buf, ce_prefix.len) >= 0) { + const char *fmt = "could not find '%s' in index"; + ensure_full_index_with_reason(istate, fmt, ce_prefix.buf); + } strbuf_release(&ce_prefix); }