Re: [PATCH v3 2/3] sparse-index: add ensure_correct_sparsity function
- From
Derrick Stolee <stolee@gmail.com>
- Date
- Oct 27, 2021, 20:07 UTC
- Message-ID
- <bf73e2d2-a2ab-8364-d505-1bd5bba3efd2@gmail.com>
- In-Reply-To
- <9d6511db0728e9880a96f3d9e3a025a9ddc5bc9e.1635358812.git.gitgitgadget@gmail.com>
On 10/27/2021 2:20 PM, Victoria Dye via GitGitGadget wrote:
> From: Victoria Dye <vdye@github.com>
> +static int is_sparse_index_allowed(struct index_state *istate, int flags)
I agree this name is better.
Show 16 quoted lines
> {
> - 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.
Show 15 quoted lines
> 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;Show 11 quoted lines
> +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