| 199 | } |
| 200 | |
| 201 | int convert_to_sparse(struct index_state *istate, int flags) |
| 202 | { |
| 203 | /* |
| 204 | * If the index is already sparse, empty, or otherwise |
| 205 | * cannot be converted to sparse, do not convert. |
| 206 | */ |
| 207 | if (istate->sparse_index == INDEX_COLLAPSED || !istate->cache_nr || |
| 208 | !is_sparse_index_allowed(istate, flags)) |
| 209 | return 0; |
| 210 | |
| 211 | /* |
| 212 | * If we are purposefully collapsing a full index, then don't give |
| 213 | * advice when it is expanded later. |
| 214 | */ |
| 215 | give_advice_on_expansion = 0; |
| 216 | |
| 217 | /* |
| 218 | * NEEDSWORK: If we have unmerged entries, then stay full. |
| 219 | * Unmerged entries prevent the cache-tree extension from working. |
| 220 | */ |
| 221 | if (index_has_unmerged_entries(istate)) |
| 222 | return 0; |
| 223 | |
| 224 | if (!cache_tree_fully_valid(istate->cache_tree)) { |
| 225 | /* Clear and recompute the cache-tree */ |
| 226 | cache_tree_free(&istate->cache_tree); |
| 227 | |
| 228 | /* |
| 229 | * Silently return if there is a problem with the cache tree update, |
| 230 | * which might just be due to a conflict state in some entry. |
| 231 | * |
| 232 | * This might create new tree objects, so be sure to use |
| 233 | * WRITE_TREE_MISSING_OK. |
| 234 | */ |
| 235 | if (cache_tree_update(istate, WRITE_TREE_MISSING_OK)) |
| 236 | return 0; |
| 237 | } |
| 238 | |
| 239 | remove_fsmonitor(istate); |
| 240 | |
| 241 | trace2_region_enter("index", "convert_to_sparse", istate->repo); |
| 242 | istate->cache_nr = convert_to_sparse_rec(istate, |
| 243 | 0, 0, istate->cache_nr, |
| 244 | "", 0, istate->cache_tree); |
| 245 | |
| 246 | /* Clear and recompute the cache-tree */ |
| 247 | cache_tree_free(&istate->cache_tree); |
| 248 | cache_tree_update(istate, 0); |
| 249 | |
| 250 | istate->fsmonitor_has_run_once = 0; |
| 251 | ewah_free(istate->fsmonitor_dirty); |
| 252 | istate->fsmonitor_dirty = NULL; |
| 253 | FREE_AND_NULL(istate->fsmonitor_last_update); |
| 254 | |
| 255 | istate->sparse_index = INDEX_COLLAPSED; |
| 256 | trace2_region_leave("index", "convert_to_sparse", istate->repo); |
| 257 | return 0; |
| 258 | } |
no test coverage detected