Skip to content

Commit

Permalink
treewide: custom reasons for expanding index
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
derrickstolee authored and mjcheetham committed Dec 3, 2024
1 parent 6be537d commit 5872e4d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 7 deletions.
4 changes: 3 additions & 1 deletion builtin/update-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion merge-ort.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
4 changes: 3 additions & 1 deletion read-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
4 changes: 3 additions & 1 deletion sparse-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,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;
}

Expand Down
10 changes: 9 additions & 1 deletion t/t1092-sparse-checkout-compatibility.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" <ls-files-trace
test_trace2_data "sparse-index" "expansion-reason" "ls-files" <ls-files-trace &&
mkdir -p sparse-index/folder2 &&
echo >sparse-index/folder2/a &&
GIT_TRACE2_EVENT="$(pwd)/status-trace" \
git -C sparse-index status &&
test_trace2_data "sparse-index" "skip-worktree sparsedir" "folder2/" <status-trace &&
test_trace2_data "sparse-index" "expansion-reason" \
"failed to clear skip-worktree while sparse" <status-trace
'

test_done
6 changes: 4 additions & 2 deletions unpack-trees.c
Original file line number Diff line number Diff line change
Expand Up @@ -1890,8 +1890,10 @@ static void update_sparsity_for_prefix(const char *prefix,
* the 'ensure_full_index(...)' below.
*/
if (!path_in_cone_mode_sparse_checkout(ce_prefix.buf, istate) &&
index_name_pos(istate, ce_prefix.buf, ce_prefix.len) >= 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);
}
Expand Down

0 comments on commit 5872e4d

Please sign in to comment.