| 321 | } |
| 322 | |
| 323 | void expand_index(struct index_state *istate, struct pattern_list *pl) |
| 324 | { |
| 325 | int i; |
| 326 | struct index_state *full; |
| 327 | struct strbuf base = STRBUF_INIT; |
| 328 | const char *tr_region; |
| 329 | struct modify_index_context ctx; |
| 330 | |
| 331 | /* |
| 332 | * If the index is already full, then keep it full. We will convert |
| 333 | * it to a sparse index on write, if possible. |
| 334 | */ |
| 335 | if (istate->sparse_index == INDEX_EXPANDED) |
| 336 | return; |
| 337 | |
| 338 | /* |
| 339 | * If our index is sparse, but our new pattern set does not use |
| 340 | * cone mode patterns, then we need to expand the index before we |
| 341 | * continue. A NULL pattern set indicates a full expansion to a |
| 342 | * full index. |
| 343 | */ |
| 344 | if (pl && !pl->use_cone_patterns) { |
| 345 | pl = NULL; |
| 346 | } else { |
| 347 | /* |
| 348 | * We might contract file entries into sparse-directory |
| 349 | * entries, and for that we will need the cache tree to |
| 350 | * be recomputed. |
| 351 | */ |
| 352 | cache_tree_free(&istate->cache_tree); |
| 353 | |
| 354 | /* |
| 355 | * If there is a problem creating the cache tree, then we |
| 356 | * need to expand to a full index since we cannot satisfy |
| 357 | * the current request as a sparse index. |
| 358 | */ |
| 359 | if (cache_tree_update(istate, 0)) |
| 360 | pl = NULL; |
| 361 | } |
| 362 | |
| 363 | if (!pl && give_advice_on_expansion) { |
| 364 | give_advice_on_expansion = 0; |
| 365 | advise_if_enabled(ADVICE_SPARSE_INDEX_EXPANDED, |
| 366 | _(ADVICE_MSG)); |
| 367 | } |
| 368 | |
| 369 | /* |
| 370 | * A NULL pattern set indicates we are expanding a full index, so |
| 371 | * we use a special region name that indicates the full expansion. |
| 372 | * This is used by test cases, but also helps to differentiate the |
| 373 | * two cases. |
| 374 | */ |
| 375 | tr_region = pl ? "expand_index" : "ensure_full_index"; |
| 376 | trace2_region_enter("index", tr_region, istate->repo); |
| 377 | |
| 378 | /* initialize basics of new index */ |
| 379 | full = xcalloc(1, sizeof(struct index_state)); |
| 380 | memcpy(full, istate, sizeof(struct index_state)); |
no test coverage detected