Re: [PATCH v3 2/3] sparse-index: add ensure_correct_sparsity function

From
Derrick Stolee <hidden>
Date
2021-10-27 20:07:16
Reply to
Victoria Dye via GitGitGadget, 2021-10-27
On 10/27/2021 2:20 PM, Victoria Dye via GitGitGadget wrote:
From: Victoria Dye <redacted>
+static int is_sparse_index_allowed(struct index_state *istate, int flags)
I agree this name is better.
quoted hunk ↗ jump to hunk
 {
-	int test_env;
-	if (istate->sparse_index || !istate->cache_nr ||
-	    !core_apply_sparse_checkout || !core_sparse_checkout_cone)
+	if (!core_apply_sparse_checkout || !core_sparse_checkout_cone)
 		return 0;
 
 	if (!istate->repo)
 		istate->repo = the_repository;
 
 	if (!(flags & SPARSE_INDEX_MEMORY_ONLY)) {
+		int test_env;
+
 		/*
 		 * The sparse index is not (yet) integrated with a split index.
 		 */
Nice that most of the implementation comes over without showing
up in the diff.
quoted hunk ↗ jump to hunk
 	if (!istate->sparse_checkout_patterns->use_cone_patterns)
 		return 0;
 
+	return 1;
+}
+
+int convert_to_sparse(struct index_state *istate, int flags)
+{
+	/*
+	 * If the index is already sparse, empty, or otherwise
+	 * cannot be converted to sparse, do not convert.
+	 */
+	if (istate->sparse_index || !istate->cache_nr ||
+	    !is_sparse_index_allowed(istate, flags))
+		return 0;
quoted hunk ↗ jump to hunk
+void ensure_correct_sparsity(struct index_state *istate)
+{
+	/*
+	 * If the index can be sparse, make it sparse. Otherwise,
+	 * ensure the index is full.
+	 */
+	if (is_sparse_index_allowed(istate, 0))
+		convert_to_sparse(istate, 0);
+	else
+		ensure_full_index(istate);
+}
These two methods become very simple. Excellent.

-Stolee
Thread (27 messages) 27 messages, 4 authors, last reply 2021-11-23
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help