unpack-trees: move checkout state into check_updates

The checkout state was introduced via 16da134b1f9 (read-trees: refactor the unpack_trees() part, 2006-07-30). An attempt to refactor the checkout state was done in b56aa5b268e (unpack-trees: pass checkout state explicitly to check_updates(), 2016-09-13), but we can go even further. The `struct checkout state` is not used in unpack_trees apart from initializing it, so move it into the function that makes use of it, which is `check_updates`. Signed-off-by: Stefan Beller <sbeller@google.com> Reviewed-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stefan Beller committed Jan 9, 2017 at 11:46 UTC 30ac275b1c893697e25abefbd872de534bb8c046
1 file changed +12 -12
unpack-trees.c
+12 -12
@@ -218,14 +218,19 @@ static void unlink_entry(const struct cache_entry *ce)
218 schedule_dir_for_removal(ce->name, ce_namelen(ce));
219 }
220
221 -static int check_updates(struct unpack_trees_options *o,
222 - const struct checkout *state)
221 +static int check_updates(struct unpack_trees_options *o)
222 {
223 unsigned cnt = 0, total = 0;
224 + int errs = 0;
225 struct progress *progress = NULL;
226 struct index_state *index = &o->result;
227 + struct checkout state = CHECKOUT_INIT;
228 int i;
228 - int errs = 0;
229 +
230 + state.force = 1;
231 + state.quiet = 1;
232 + state.refresh_cache = 1;
233 + state.istate = index;
234
235 if (o->update && o->verbose_update) {
236 for (total = cnt = 0; cnt < index->cache_nr; cnt++) {
@@ -240,7 +245,7 @@ static int check_updates(struct unpack_trees_options *o,
245 }
246
247 if (o->update)
243 - git_attr_set_direction(GIT_ATTR_CHECKOUT, &o->result);
248 + git_attr_set_direction(GIT_ATTR_CHECKOUT, index);
249 for (i = 0; i < index->cache_nr; i++) {
250 const struct cache_entry *ce = index->cache[i];
251
@@ -251,7 +256,7 @@ static int check_updates(struct unpack_trees_options *o,
256 continue;
257 }
258 }
254 - remove_marked_cache_entries(&o->result);
259 + remove_marked_cache_entries(index);
260 remove_scheduled_dirs();
261
262 for (i = 0; i < index->cache_nr; i++) {
@@ -264,7 +269,7 @@ static int check_updates(struct unpack_trees_options *o,
269 display_progress(progress, ++cnt);
270 ce->ce_flags &= ~CE_UPDATE;
271 if (o->update && !o->dry_run) {
267 - errs |= checkout_entry(ce, state, NULL);
272 + errs |= checkout_entry(ce, &state, NULL);
273 }
274 }
275 }
@@ -1094,14 +1099,9 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
1099 int i, ret;
1100 static struct cache_entry *dfc;
1101 struct exclude_list el;
1097 - struct checkout state = CHECKOUT_INIT;
1102
1103 if (len > MAX_UNPACK_TREES)
1104 die("unpack_trees takes at most %d trees", MAX_UNPACK_TREES);
1101 - state.force = 1;
1102 - state.quiet = 1;
1103 - state.refresh_cache = 1;
1104 - state.istate = &o->result;
1105
1106 memset(&el, 0, sizeof(el));
1107 if (!core_apply_sparse_checkout || !o->update)
@@ -1238,7 +1238,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
1238 }
1239
1240 o->src_index = NULL;
1241 - ret = check_updates(o, &state) ? (-2) : 0;
1241 + ret = check_updates(o) ? (-2) : 0;
1242 if (o->dst_index) {
1243 if (!ret) {
1244 if (!o->result.cache_tree)