* Update SKIP_WORKTREE bits according to sparsity patterns, and update * working directory to match. * * CE_NEW_SKIP_WORKTREE is used internally. */
| 2127 | * CE_NEW_SKIP_WORKTREE is used internally. |
| 2128 | */ |
| 2129 | enum update_sparsity_result update_sparsity(struct unpack_trees_options *o, |
| 2130 | struct pattern_list *pl) |
| 2131 | { |
| 2132 | enum update_sparsity_result ret = UPDATE_SPARSITY_SUCCESS; |
| 2133 | int i; |
| 2134 | unsigned old_show_all_errors; |
| 2135 | int free_pattern_list = 0; |
| 2136 | |
| 2137 | old_show_all_errors = o->internal.show_all_errors; |
| 2138 | o->internal.show_all_errors = 1; |
| 2139 | index_state_init(&o->internal.result, o->src_index->repo); |
| 2140 | |
| 2141 | /* Sanity checks */ |
| 2142 | if (!o->update || o->index_only || o->skip_sparse_checkout) |
| 2143 | BUG("update_sparsity() is for reflecting sparsity patterns in working directory"); |
| 2144 | if (o->src_index != o->dst_index || o->fn) |
| 2145 | BUG("update_sparsity() called wrong"); |
| 2146 | |
| 2147 | trace_performance_enter(); |
| 2148 | |
| 2149 | /* If we weren't given patterns, use the recorded ones */ |
| 2150 | if (!pl) { |
| 2151 | free_pattern_list = 1; |
| 2152 | pl = xcalloc(1, sizeof(*pl)); |
| 2153 | populate_from_existing_patterns(o, pl); |
| 2154 | } |
| 2155 | o->internal.pl = pl; |
| 2156 | |
| 2157 | /* Expand sparse directories as needed */ |
| 2158 | expand_index(o->src_index, o->internal.pl); |
| 2159 | |
| 2160 | /* Set NEW_SKIP_WORKTREE on existing entries. */ |
| 2161 | mark_all_ce_unused(o->src_index); |
| 2162 | mark_new_skip_worktree(o->internal.pl, o->src_index, 0, |
| 2163 | CE_NEW_SKIP_WORKTREE, o->verbose_update); |
| 2164 | |
| 2165 | /* Then loop over entries and update/remove as needed */ |
| 2166 | ret = UPDATE_SPARSITY_SUCCESS; |
| 2167 | for (i = 0; i < o->src_index->cache_nr; i++) { |
| 2168 | struct cache_entry *ce = o->src_index->cache[i]; |
| 2169 | |
| 2170 | |
| 2171 | if (ce_stage(ce)) { |
| 2172 | /* -1 because for loop will increment by 1 */ |
| 2173 | i += warn_conflicted_path(o->src_index, i, o) - 1; |
| 2174 | ret = UPDATE_SPARSITY_WARNINGS; |
| 2175 | continue; |
| 2176 | } |
| 2177 | |
| 2178 | if (apply_sparse_checkout(o->src_index, ce, o)) |
| 2179 | ret = UPDATE_SPARSITY_WARNINGS; |
| 2180 | } |
| 2181 | |
| 2182 | if (check_updates(o, o->src_index)) |
| 2183 | ret = UPDATE_SPARSITY_WORKTREE_UPDATE_FAILURES; |
| 2184 | |
| 2185 | display_warning_msgs(o); |
| 2186 | o->internal.show_all_errors = old_show_all_errors; |
no test coverage detected