Skip to content

Commit aafbda8

Browse files
committed
Merge branch 'backport-sparse-index-advice'
This backports the `ds/advice-sparse-index-expansion` patches into `microsoft/git` which _just_ missed the v2.46.0 window. Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 49cd044 + 43daded commit aafbda8

File tree

7 files changed

+53
-1
lines changed

7 files changed

+53
-1
lines changed

Documentation/config/advice.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ advice.*::
119119
skippedCherryPicks::
120120
Shown when linkgit:git-rebase[1] skips a commit that has already
121121
been cherry-picked onto the upstream branch.
122+
sparseIndexExpanded::
123+
Shown when a sparse index is expanded to a full index, which is likely
124+
due to an unexpected set of files existing outside of the
125+
sparse-checkout.
122126
statusAheadBehind::
123127
Shown when linkgit:git-status[1] computes the ahead/behind
124128
counts for a local ref compared to its remote tracking ref,

advice.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ static struct {
7979
[ADVICE_SEQUENCER_IN_USE] = { "sequencerInUse" },
8080
[ADVICE_SET_UPSTREAM_FAILURE] = { "setUpstreamFailure" },
8181
[ADVICE_SKIPPED_CHERRY_PICKS] = { "skippedCherryPicks" },
82+
[ADVICE_SPARSE_INDEX_EXPANDED] = { "sparseIndexExpanded" },
8283
[ADVICE_STATUS_AHEAD_BEHIND_WARNING] = { "statusAheadBehindWarning" },
8384
[ADVICE_STATUS_HINTS] = { "statusHints" },
8485
[ADVICE_STATUS_U_OPTION] = { "statusUoption" },

advice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ enum advice_type {
4646
ADVICE_SEQUENCER_IN_USE,
4747
ADVICE_SET_UPSTREAM_FAILURE,
4848
ADVICE_SKIPPED_CHERRY_PICKS,
49+
ADVICE_SPARSE_INDEX_EXPANDED,
4950
ADVICE_STATUS_AHEAD_BEHIND_WARNING,
5051
ADVICE_STATUS_HINTS,
5152
ADVICE_STATUS_U_OPTION,

sparse-index.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@
1212
#include "config.h"
1313
#include "dir.h"
1414
#include "fsmonitor-ll.h"
15+
#include "advice.h"
16+
17+
/**
18+
* This global is used by expand_index() to determine if we should give the
19+
* advice for advice.sparseIndexExpanded when expanding a sparse index to a full
20+
* one. However, this is sometimes done on purpose, such as in the sparse-checkout
21+
* builtin, even when index.sparse=false. This may be disabled in
22+
* convert_to_sparse().
23+
*/
24+
static int give_advice_on_expansion = 1;
25+
#define ADVICE_MSG \
26+
"The sparse index is expanding to a full index, a slow operation.\n" \
27+
"Your working directory likely has contents that are outside of\n" \
28+
"your sparse-checkout patterns. Use 'git sparse-checkout list' to\n" \
29+
"see your sparse-checkout definition and compare it to your working\n" \
30+
"directory contents. Running 'git clean' may assist in this cleanup."
1531

1632
struct modify_index_context {
1733
struct index_state *write;
@@ -183,6 +199,12 @@ int convert_to_sparse(struct index_state *istate, int flags)
183199
!is_sparse_index_allowed(istate, flags))
184200
return 0;
185201

202+
/*
203+
* If we are purposefully collapsing a full index, then don't give
204+
* advice when it is expanded later.
205+
*/
206+
give_advice_on_expansion = 0;
207+
186208
/*
187209
* NEEDSWORK: If we have unmerged entries, then stay full.
188210
* Unmerged entries prevent the cache-tree extension from working.
@@ -328,6 +350,12 @@ void expand_index(struct index_state *istate, struct pattern_list *pl)
328350
pl = NULL;
329351
}
330352

353+
if (!pl && give_advice_on_expansion) {
354+
give_advice_on_expansion = 0;
355+
advise_if_enabled(ADVICE_SPARSE_INDEX_EXPANDED,
356+
_(ADVICE_MSG));
357+
}
358+
331359
/*
332360
* A NULL pattern set indicates we are expanding a full index, so
333361
* we use a special region name that indicates the full expansion.

t/t1091-sparse-checkout-builtin.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,7 @@ test_expect_success 'pattern-checks: contained glob characters' '
702702

703703
test_expect_success BSLASHPSPEC 'pattern-checks: escaped characters' '
704704
git clone repo escaped &&
705+
git -C escaped config advice.sparseIndexExpanded false &&
705706
TREEOID=$(git -C escaped rev-parse HEAD:folder1) &&
706707
NEWTREE=$(git -C escaped mktree <<-EOF
707708
$(git -C escaped ls-tree HEAD)

t/t1092-sparse-checkout-compatibility.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,10 @@ init_repos () {
159159
git -C sparse-checkout sparse-checkout set deep &&
160160
git -C sparse-index sparse-checkout init --cone --sparse-index &&
161161
test_cmp_config -C sparse-index true index.sparse &&
162-
git -C sparse-index sparse-checkout set deep
162+
git -C sparse-index sparse-checkout set deep &&
163+
164+
# Disable this message to keep stderr the same.
165+
git -C sparse-index config advice.sparseIndexExpanded false
163166
}
164167

165168
init_repos_as_submodules () {
@@ -2331,4 +2334,15 @@ test_expect_success 'sparse-index is not expanded: check-attr' '
23312334
ensure_not_expanded check-attr -a --cached -- folder1/a
23322335
'
23332336

2337+
test_expect_success 'advice.sparseIndexExpanded' '
2338+
init_repos &&
2339+
2340+
git -C sparse-index config --unset advice.sparseIndexExpanded &&
2341+
git -C sparse-index sparse-checkout set deep/deeper1 &&
2342+
mkdir -p sparse-index/deep/deeper2/deepest &&
2343+
touch sparse-index/deep/deeper2/deepest/bogus &&
2344+
git -C sparse-index status 2>err &&
2345+
grep "The sparse index is expanding to a full index" err
2346+
'
2347+
23342348
test_done

t/t7002-mv-sparse-checkout.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ test_expect_success 'mv refuses to move sparse-to-non-sparse' '
156156

157157
test_expect_success 'recursive mv refuses to move (possible) sparse' '
158158
test_when_finished rm -rf b c e sub2 &&
159+
160+
git config advice.sparseIndexExpanded false &&
161+
159162
git reset --hard &&
160163
# Without cone mode, "sub" and "sub2" do not match
161164
git sparse-checkout set sub/dir sub2/dir &&

0 commit comments

Comments
 (0)