Skip to content

Commit 0e3b630

Browse files
committed
sparse-index: introduce partially-sparse indexes
A future change will present a temporary, in-memory mode where the index can both contain sparse directory entries but also not be completely collapsed to the smallest possible sparse directories. This will be necessary for modifying the sparse-checkout definition while using a sparse index. For now, convert the single-bit member 'sparse_index' in 'struct index_state' to be a an 'enum sparse_index_mode' with three modes: * COMPLETELY_FULL (0): No sparse directories exist. * COMPLETELY_SPARSE (1): Sparse directories may exist. Files outside the sparse-checkout cone are reduced to sparse directory entries whenever possible. * PARTIALLY_SPARSE (2): Sparse directories may exist. Some file entries outside the sparse-checkout cone may exist. Running convert_to_sparse() may further reduce those files to sparse directory entries. The main reason to store this extra information is to allow convert_to_sparse() to short-circuit when the index is already in COMPLETELY_SPARSE mode but to actually do the necessary work when in PARTIALLY_SPARSE mode. The PARTIALLY_SPARSE mode will be used in an upcoming change. Signed-off-by: Derrick Stolee <[email protected]>
1 parent 97b9575 commit 0e3b630

File tree

4 files changed

+30
-14
lines changed

4 files changed

+30
-14
lines changed

builtin/sparse-checkout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ static void clean_tracked_sparse_directories(struct repository *r)
132132
* sparse index will not delete directories that contain
133133
* conflicted entries or submodules.
134134
*/
135-
if (!r->index->sparse_index) {
135+
if (r->index->sparse_index == COMPLETELY_FULL) {
136136
/*
137137
* If something, such as a merge conflict or other concern,
138138
* prevents us from converting to a sparse index, then do

cache.h

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,28 @@ struct untracked_cache;
311311
struct progress;
312312
struct pattern_list;
313313

314+
enum sparse_index_mode {
315+
/*
316+
* COMPLETELY_FULL: there are no sparse directories
317+
* in the index at all.
318+
*/
319+
COMPLETELY_FULL = 0,
320+
321+
/*
322+
* COLLAPSED: the index has already been collapsed to sparse
323+
* directories whereever possible.
324+
*/
325+
COLLAPSED = 1,
326+
327+
/*
328+
* PARTIALLY_SPARSE: the sparse directories that exist are
329+
* outside the sparse-checkout boundary, but it is possible
330+
* that some file entries could collapse to sparse directory
331+
* entries.
332+
*/
333+
PARTIALLY_SPARSE = 2,
334+
};
335+
314336
struct index_state {
315337
struct cache_entry **cache;
316338
unsigned int version;
@@ -324,14 +346,8 @@ struct index_state {
324346
drop_cache_tree : 1,
325347
updated_workdir : 1,
326348
updated_skipworktree : 1,
327-
fsmonitor_has_run_once : 1,
328-
329-
/*
330-
* sparse_index == 1 when sparse-directory
331-
* entries exist. Requires sparse-checkout
332-
* in cone mode.
333-
*/
334-
sparse_index : 1;
349+
fsmonitor_has_run_once : 1;
350+
enum sparse_index_mode sparse_index;
335351
struct hashmap name_hash;
336352
struct hashmap dir_hash;
337353
struct object_id oid;

read-cache.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ static const char *alternate_index_output;
108108
static void set_index_entry(struct index_state *istate, int nr, struct cache_entry *ce)
109109
{
110110
if (S_ISSPARSEDIR(ce->ce_mode))
111-
istate->sparse_index = 1;
111+
istate->sparse_index = COLLAPSED;
112112

113113
istate->cache[nr] = ce;
114114
add_name_hash(istate, ce);
@@ -1828,7 +1828,7 @@ static int read_index_extension(struct index_state *istate,
18281828
break;
18291829
case CACHE_EXT_SPARSE_DIRECTORIES:
18301830
/* no content, only an indicator */
1831-
istate->sparse_index = 1;
1831+
istate->sparse_index = COLLAPSED;
18321832
break;
18331833
default:
18341834
if (*ext < 'A' || 'Z' < *ext)
@@ -3109,7 +3109,7 @@ static int do_write_locked_index(struct index_state *istate, struct lock_file *l
31093109
unsigned flags)
31103110
{
31113111
int ret;
3112-
int was_full = !istate->sparse_index;
3112+
int was_full = istate->sparse_index == COMPLETELY_FULL;
31133113

31143114
ret = convert_to_sparse(istate, 0);
31153115

sparse-index.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ int convert_to_sparse(struct index_state *istate, int flags)
128128
{
129129
int test_env;
130130

131-
if (istate->sparse_index || !istate->cache_nr ||
131+
if (istate->sparse_index == COLLAPSED || !istate->cache_nr ||
132132
!core_apply_sparse_checkout || !core_sparse_checkout_cone)
133133
return 0;
134134

@@ -205,7 +205,7 @@ int convert_to_sparse(struct index_state *istate, int flags)
205205
FREE_AND_NULL(istate->fsmonitor_dirty);
206206
FREE_AND_NULL(istate->fsmonitor_last_update);
207207

208-
istate->sparse_index = 1;
208+
istate->sparse_index = COLLAPSED;
209209
trace2_region_leave("index", "convert_to_sparse", istate->repo);
210210
return 0;
211211
}

0 commit comments

Comments
 (0)