unpack-trees: factor progress setup out of check_updates

This makes check_updates shorter and easier to understand. Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stefan Beller committed Jan 9, 2017 at 11:46 UTC 384f1a167bdf0b68f90ec54e9845c1b4a68cb670
1 file changed +20 -12
unpack-trees.c
+20 -12
@@ -218,9 +218,27 @@ 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)
221 +static struct progress *get_progress(struct unpack_trees_options *o)
222 {
223 unsigned cnt = 0, total = 0;
224 + struct index_state *index = &o->result;
225 +
226 + if (!o->update || !o->verbose_update)
227 + return NULL;
228 +
229 + for (; cnt < index->cache_nr; cnt++) {
230 + const struct cache_entry *ce = index->cache[cnt];
231 + if (ce->ce_flags & (CE_UPDATE | CE_WT_REMOVE))
232 + total++;
233 + }
234 +
235 + return start_progress_delay(_("Checking out files"),
236 + total, 50, 1);
237 +}
238 +
239 +static int check_updates(struct unpack_trees_options *o)
240 +{
241 + unsigned cnt = 0;
242 int errs = 0;
243 struct progress *progress = NULL;
244 struct index_state *index = &o->result;
@@ -232,17 +250,7 @@ static int check_updates(struct unpack_trees_options *o)
250 state.refresh_cache = 1;
251 state.istate = index;
252
235 - if (o->update && o->verbose_update) {
236 - for (total = cnt = 0; cnt < index->cache_nr; cnt++) {
237 - const struct cache_entry *ce = index->cache[cnt];
238 - if (ce->ce_flags & (CE_UPDATE | CE_WT_REMOVE))
239 - total++;
240 - }
241 -
242 - progress = start_progress_delay(_("Checking out files"),
243 - total, 50, 1);
244 - cnt = 0;
245 - }
253 + progress = get_progress(o);
254
255 if (o->update)
256 git_attr_set_direction(GIT_ATTR_CHECKOUT, index);