@@ -218,40 +218,52 @@ 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 ,
222- const struct checkout * state )
221+ static struct progress * get_progress (struct unpack_trees_options * o )
223222{
224223 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 ;
225243 struct progress * progress = NULL ;
226244 struct index_state * index = & o -> result ;
245+ struct checkout state = CHECKOUT_INIT ;
227246 int i ;
228- int errs = 0 ;
229247
230- if (o -> update && o -> verbose_update ) {
231- for (total = cnt = 0 ; cnt < index -> cache_nr ; cnt ++ ) {
232- const struct cache_entry * ce = index -> cache [cnt ];
233- if (ce -> ce_flags & (CE_UPDATE | CE_WT_REMOVE ))
234- total ++ ;
235- }
248+ state .force = 1 ;
249+ state .quiet = 1 ;
250+ state .refresh_cache = 1 ;
251+ state .istate = index ;
236252
237- progress = start_progress_delay (_ ("Checking out files" ),
238- total , 50 , 1 );
239- cnt = 0 ;
240- }
253+ progress = get_progress (o );
241254
242255 if (o -> update )
243- git_attr_set_direction (GIT_ATTR_CHECKOUT , & o -> result );
256+ git_attr_set_direction (GIT_ATTR_CHECKOUT , index );
244257 for (i = 0 ; i < index -> cache_nr ; i ++ ) {
245258 const struct cache_entry * ce = index -> cache [i ];
246259
247260 if (ce -> ce_flags & CE_WT_REMOVE ) {
248261 display_progress (progress , ++ cnt );
249262 if (o -> update && !o -> dry_run )
250263 unlink_entry (ce );
251- continue ;
252264 }
253265 }
254- remove_marked_cache_entries (& o -> result );
266+ remove_marked_cache_entries (index );
255267 remove_scheduled_dirs ();
256268
257269 for (i = 0 ; i < index -> cache_nr ; i ++ ) {
@@ -264,7 +276,7 @@ static int check_updates(struct unpack_trees_options *o,
264276 display_progress (progress , ++ cnt );
265277 ce -> ce_flags &= ~CE_UPDATE ;
266278 if (o -> update && !o -> dry_run ) {
267- errs |= checkout_entry (ce , state , NULL );
279+ errs |= checkout_entry (ce , & state , NULL );
268280 }
269281 }
270282 }
@@ -1094,14 +1106,9 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
10941106 int i , ret ;
10951107 static struct cache_entry * dfc ;
10961108 struct exclude_list el ;
1097- struct checkout state = CHECKOUT_INIT ;
10981109
10991110 if (len > MAX_UNPACK_TREES )
11001111 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 ;
11051112
11061113 memset (& el , 0 , sizeof (el ));
11071114 if (!core_apply_sparse_checkout || !o -> update )
@@ -1238,7 +1245,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
12381245 }
12391246
12401247 o -> src_index = NULL ;
1241- ret = check_updates (o , & state ) ? (-2 ) : 0 ;
1248+ ret = check_updates (o ) ? (-2 ) : 0 ;
12421249 if (o -> dst_index ) {
12431250 if (!ret ) {
12441251 if (!o -> result .cache_tree )
0 commit comments