|
12 | 12 | #include "config.h" |
13 | 13 | #include "dir.h" |
14 | 14 | #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." |
15 | 31 |
|
16 | 32 | struct modify_index_context { |
17 | 33 | struct index_state *write; |
@@ -183,6 +199,12 @@ int convert_to_sparse(struct index_state *istate, int flags) |
183 | 199 | !is_sparse_index_allowed(istate, flags)) |
184 | 200 | return 0; |
185 | 201 |
|
| 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 | + |
186 | 208 | /* |
187 | 209 | * NEEDSWORK: If we have unmerged entries, then stay full. |
188 | 210 | * Unmerged entries prevent the cache-tree extension from working. |
@@ -328,6 +350,12 @@ void expand_index(struct index_state *istate, struct pattern_list *pl) |
328 | 350 | pl = NULL; |
329 | 351 | } |
330 | 352 |
|
| 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 | + |
331 | 359 | /* |
332 | 360 | * A NULL pattern set indicates we are expanding a full index, so |
333 | 361 | * we use a special region name that indicates the full expansion. |
|
0 commit comments