Skip to content

Commit b0ece4b

Browse files
committed
sparse-index: add SPARSE_INDEX_IGNORE_CONFIG 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_IGNORE_CONFIG 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>
1 parent c9e100e commit b0ece4b

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

read-cache.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3069,7 +3069,7 @@ static int do_write_locked_index(struct index_state *istate, struct lock_file *l
30693069
int ret;
30703070
int was_full = !istate->sparse_index;
30713071

3072-
ret = convert_to_sparse(istate);
3072+
ret = convert_to_sparse(istate, 0);
30733073

30743074
if (ret) {
30753075
warning(_("failed to convert to a sparse-index"));
@@ -3182,7 +3182,7 @@ static int write_shared_index(struct index_state *istate,
31823182
int ret, was_full = !istate->sparse_index;
31833183

31843184
move_cache_to_base_index(istate);
3185-
convert_to_sparse(istate);
3185+
convert_to_sparse(istate, 0);
31863186

31873187
trace2_region_enter_printf("index", "shared/do_write_index",
31883188
the_repository, "%s", get_tempfile_path(*temp));

sparse-index.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ static int index_has_unmerged_entries(struct index_state *istate)
124124
return 0;
125125
}
126126

127-
int convert_to_sparse(struct index_state *istate)
127+
int convert_to_sparse(struct index_state *istate, int flags)
128128
{
129129
int test_env;
130130

@@ -135,20 +135,22 @@ int convert_to_sparse(struct index_state *istate)
135135
if (!istate->repo)
136136
istate->repo = the_repository;
137137

138-
/*
139-
* The GIT_TEST_SPARSE_INDEX environment variable triggers the
140-
* index.sparse config variable to be on.
141-
*/
142-
test_env = git_env_bool("GIT_TEST_SPARSE_INDEX", -1);
143-
if (test_env >= 0)
144-
set_sparse_index_config(istate->repo, test_env);
138+
if (!(flags & SPARSE_INDEX_IGNORE_CONFIG)) {
139+
/*
140+
* The GIT_TEST_SPARSE_INDEX environment variable triggers the
141+
* index.sparse config variable to be on.
142+
*/
143+
test_env = git_env_bool("GIT_TEST_SPARSE_INDEX", -1);
144+
if (test_env >= 0)
145+
set_sparse_index_config(istate->repo, test_env);
145146

146-
/*
147-
* Only convert to sparse if index.sparse is set.
148-
*/
149-
prepare_repo_settings(istate->repo);
150-
if (!istate->repo->settings.sparse_index)
151-
return 0;
147+
/*
148+
* Only convert to sparse if index.sparse is set.
149+
*/
150+
prepare_repo_settings(istate->repo);
151+
if (!istate->repo->settings.sparse_index)
152+
return 0;
153+
}
152154

153155
if (init_sparse_checkout_patterns(istate) < 0)
154156
return 0;

sparse-index.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
#define SPARSE_INDEX_H__
33

44
struct index_state;
5-
int convert_to_sparse(struct index_state *istate);
5+
#define SPARSE_INDEX_IGNORE_CONFIG (1 << 0)
6+
int convert_to_sparse(struct index_state *istate, int flags);
67

78
/*
89
* Some places in the codebase expect to search for a specific path.

0 commit comments

Comments
 (0)