@@ -285,8 +285,24 @@ void expand_to_pattern_list(struct index_state *istate,
285
285
* continue. A NULL pattern set indicates a full expansion to a
286
286
* full index.
287
287
*/
288
- if (pl && !pl -> use_cone_patterns )
288
+ if (pl && !pl -> use_cone_patterns ) {
289
289
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
+ }
290
306
291
307
/*
292
308
* 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,
305
321
full = xcalloc (1 , sizeof (struct index_state ));
306
322
memcpy (full , istate , sizeof (struct index_state ));
307
323
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
+
308
331
/* then change the necessary things */
309
- full -> sparse_index = 0 ;
310
332
full -> cache_alloc = (3 * istate -> cache_alloc ) / 2 ;
311
333
full -> cache_nr = 0 ;
312
334
ALLOC_ARRAY (full -> cache , full -> cache_alloc );
@@ -323,6 +345,14 @@ void expand_to_pattern_list(struct index_state *istate,
323
345
set_index_entry (full , full -> cache_nr ++ , ce );
324
346
continue ;
325
347
}
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
+
326
356
if (!(ce -> ce_flags & CE_SKIP_WORKTREE ))
327
357
warning (_ ("index entry is a directory, but not sparse (%08x)" ),
328
358
ce -> ce_flags );
@@ -348,7 +378,7 @@ void expand_to_pattern_list(struct index_state *istate,
348
378
/* Copy back into original index. */
349
379
memcpy (& istate -> name_hash , & full -> name_hash , sizeof (full -> name_hash ));
350
380
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 ;
352
382
free (istate -> cache );
353
383
istate -> cache = full -> cache ;
354
384
istate -> cache_nr = full -> cache_nr ;
@@ -362,7 +392,7 @@ void expand_to_pattern_list(struct index_state *istate,
362
392
363
393
/* Clear and recompute the cache-tree */
364
394
cache_tree_free (& istate -> cache_tree );
365
- cache_tree_update (istate , 0 );
395
+ cache_tree_update (istate , WRITE_TREE_MISSING_OK );
366
396
367
397
trace2_region_leave ("index" ,
368
398
pl ? "expand_to_pattern_list" : "ensure_full_index" ,
0 commit comments