Skip to content

Commit 41a1461

Browse files
committed
sparse-index: complete partial expansion
To complete the implementation of expand_to_pattern_list(), we need to detect when a sparse directory entry should remain sparse. This avoids a full expansion, so we now need to use the PARTIALLY_SPARSE mode to indicate this state. There still are no callers to this method, but we will add one in the next change. Signed-off-by: Derrick Stolee <[email protected]>
1 parent 829c32a commit 41a1461

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

sparse-index.c

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,24 @@ void expand_to_pattern_list(struct index_state *istate,
285285
* continue. A NULL pattern set indicates a full expansion to a
286286
* full index.
287287
*/
288-
if (pl && !pl->use_cone_patterns)
288+
if (pl && !pl->use_cone_patterns) {
289289
pl = NULL;
290+
} else {
291+
/*
292+
* We might contract file entries into sparse-directory
293+
* entries, and for that we will need the cache tree to
294+
* be recomputed.
295+
*/
296+
cache_tree_free(&istate->cache_tree);
297+
298+
/*
299+
* If there is a problem creating the cache tree, then we
300+
* need to expand to a full index since we cannot satisfy
301+
* the current request as a sparse index.
302+
*/
303+
if (cache_tree_update(istate, WRITE_TREE_MISSING_OK))
304+
pl = NULL;
305+
}
290306

291307
/*
292308
* A NULL pattern set indicates we are expanding a full index, so
@@ -305,8 +321,14 @@ void expand_to_pattern_list(struct index_state *istate,
305321
full = xcalloc(1, sizeof(struct index_state));
306322
memcpy(full, istate, sizeof(struct index_state));
307323

324+
/*
325+
* This slightly-misnamed 'full' index might still be sparse if we
326+
* are only modifying the list of sparse directories. This hinges
327+
* on whether we have a non-NULL pattern list.
328+
*/
329+
full->sparse_index = pl ? PARTIALLY_SPARSE : COMPLETELY_FULL;
330+
308331
/* then change the necessary things */
309-
full->sparse_index = 0;
310332
full->cache_alloc = (3 * istate->cache_alloc) / 2;
311333
full->cache_nr = 0;
312334
ALLOC_ARRAY(full->cache, full->cache_alloc);
@@ -323,6 +345,14 @@ void expand_to_pattern_list(struct index_state *istate,
323345
set_index_entry(full, full->cache_nr++, ce);
324346
continue;
325347
}
348+
349+
/* We now have a sparse directory entry. Should we expand? */
350+
if (pl &&
351+
path_matches_cone_mode_pattern_list(ce->name, ce->ce_namelen, pl) <= 0) {
352+
set_index_entry(full, full->cache_nr++, ce);
353+
continue;
354+
}
355+
326356
if (!(ce->ce_flags & CE_SKIP_WORKTREE))
327357
warning(_("index entry is a directory, but not sparse (%08x)"),
328358
ce->ce_flags);
@@ -348,7 +378,7 @@ void expand_to_pattern_list(struct index_state *istate,
348378
/* Copy back into original index. */
349379
memcpy(&istate->name_hash, &full->name_hash, sizeof(full->name_hash));
350380
memcpy(&istate->dir_hash, &full->dir_hash, sizeof(full->dir_hash));
351-
istate->sparse_index = 0;
381+
istate->sparse_index = pl ? PARTIALLY_SPARSE : COMPLETELY_FULL;
352382
free(istate->cache);
353383
istate->cache = full->cache;
354384
istate->cache_nr = full->cache_nr;
@@ -362,7 +392,7 @@ void expand_to_pattern_list(struct index_state *istate,
362392

363393
/* Clear and recompute the cache-tree */
364394
cache_tree_free(&istate->cache_tree);
365-
cache_tree_update(istate, 0);
395+
cache_tree_update(istate, WRITE_TREE_MISSING_OK);
366396

367397
trace2_region_leave("index",
368398
pl ? "expand_to_pattern_list" : "ensure_full_index",

0 commit comments

Comments
 (0)