sparse-index: add SPARSE_INDEX_MEMORY_ONLY flag

The convert_to_sparse() method checks for the GIT_TEST_SPARSE_INDEX
environment variable or the "index.sparse" config setting before
converting the index to a sparse one. This is for ease of use since all
current consumers are preparing to compress the index before writing it
to disk. If these settings are not enabled, then convert_to_sparse()
silently returns without doing anything.

We will add a consumer in the next change that wants to use the sparse
index as an in-memory data structure, regardless of whether the on-disk
format should be sparse.

To that end, create the SPARSE_INDEX_MEMORY_ONLY flag that will skip
these config checks when enabled. All current consumers are modified to
pass '0' in the new 'flags' parameter.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Reviewed-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Derrick Stolee
2021-09-08 01:42:32 +00:00
committed by Junio C Hamano
parent 77efbb366a
commit ce7a9f0141
3 changed files with 26 additions and 18 deletions

View File

@ -2,7 +2,8 @@
#define SPARSE_INDEX_H__
struct index_state;
int convert_to_sparse(struct index_state *istate);
#define SPARSE_INDEX_MEMORY_ONLY (1 << 0)
int convert_to_sparse(struct index_state *istate, int flags);
/*
* Some places in the codebase expect to search for a specific path.