Skip to content

Commit 384f1a1

Browse files
stefanbellergitster
authored andcommitted
unpack-trees: factor progress setup out of check_updates
This makes check_updates shorter and easier to understand. Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c4bfc77 commit 384f1a1

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

unpack-trees.c

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,27 @@ static void unlink_entry(const struct cache_entry *ce)
218218
schedule_dir_for_removal(ce->name, ce_namelen(ce));
219219
}
220220

221-
static int check_updates(struct unpack_trees_options *o)
221+
static struct progress *get_progress(struct unpack_trees_options *o)
222222
{
223223
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;
224242
int errs = 0;
225243
struct progress *progress = NULL;
226244
struct index_state *index = &o->result;
@@ -232,17 +250,7 @@ static int check_updates(struct unpack_trees_options *o)
232250
state.refresh_cache = 1;
233251
state.istate = index;
234252

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);
246254

247255
if (o->update)
248256
git_attr_set_direction(GIT_ATTR_CHECKOUT, index);

0 commit comments

Comments
 (0)