summaryrefslogtreecommitdiff
path: root/sparse-index.c
diff options
context:
space:
mode:
Diffstat (limited to 'sparse-index.c')
-rw-r--r--sparse-index.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/sparse-index.c b/sparse-index.c
index e48e40cae7..8f4a43c182 100644
--- a/sparse-index.c
+++ b/sparse-index.c
@@ -12,6 +12,22 @@
#include "config.h"
#include "dir.h"
#include "fsmonitor-ll.h"
+#include "advice.h"
+
+/**
+ * This global is used by expand_index() to determine if we should give the
+ * advice for advice.sparseIndexExpanded when expanding a sparse index to a full
+ * one. However, this is sometimes done on purpose, such as in the sparse-checkout
+ * builtin, even when index.sparse=false. This may be disabled in
+ * convert_to_sparse().
+ */
+static int give_advice_on_expansion = 1;
+#define ADVICE_MSG \
+ "The sparse index is expanding to a full index, a slow operation.\n" \
+ "Your working directory likely has contents that are outside of\n" \
+ "your sparse-checkout patterns. Use 'git sparse-checkout list' to\n" \
+ "see your sparse-checkout definition and compare it to your working\n" \
+ "directory contents. Running 'git clean' may assist in this cleanup."
struct modify_index_context {
struct index_state *write;
@@ -184,6 +200,12 @@ int convert_to_sparse(struct index_state *istate, int flags)
return 0;
/*
+ * If we are purposefully collapsing a full index, then don't give
+ * advice when it is expanded later.
+ */
+ give_advice_on_expansion = 0;
+
+ /*
* NEEDSWORK: If we have unmerged entries, then stay full.
* Unmerged entries prevent the cache-tree extension from working.
*/
@@ -328,6 +350,12 @@ void expand_index(struct index_state *istate, struct pattern_list *pl)
pl = NULL;
}
+ if (!pl && give_advice_on_expansion) {
+ give_advice_on_expansion = 0;
+ advise_if_enabled(ADVICE_SPARSE_INDEX_EXPANDED,
+ _(ADVICE_MSG));
+ }
+
/*
* A NULL pattern set indicates we are expanding a full index, so
* we use a special region name that indicates the full expansion.