@@ -218,40 +218,52 @@ static void unlink_entry(const struct cache_entry *ce)
218
218
schedule_dir_for_removal (ce -> name , ce_namelen (ce ));
219
219
}
220
220
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 )
223
222
{
224
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 ;
225
243
struct progress * progress = NULL ;
226
244
struct index_state * index = & o -> result ;
245
+ struct checkout state = CHECKOUT_INIT ;
227
246
int i ;
228
- int errs = 0 ;
229
247
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 ;
236
252
237
- progress = start_progress_delay (_ ("Checking out files" ),
238
- total , 50 , 1 );
239
- cnt = 0 ;
240
- }
253
+ progress = get_progress (o );
241
254
242
255
if (o -> update )
243
- git_attr_set_direction (GIT_ATTR_CHECKOUT , & o -> result );
256
+ git_attr_set_direction (GIT_ATTR_CHECKOUT , index );
244
257
for (i = 0 ; i < index -> cache_nr ; i ++ ) {
245
258
const struct cache_entry * ce = index -> cache [i ];
246
259
247
260
if (ce -> ce_flags & CE_WT_REMOVE ) {
248
261
display_progress (progress , ++ cnt );
249
262
if (o -> update && !o -> dry_run )
250
263
unlink_entry (ce );
251
- continue ;
252
264
}
253
265
}
254
- remove_marked_cache_entries (& o -> result );
266
+ remove_marked_cache_entries (index );
255
267
remove_scheduled_dirs ();
256
268
257
269
for (i = 0 ; i < index -> cache_nr ; i ++ ) {
@@ -264,7 +276,7 @@ static int check_updates(struct unpack_trees_options *o,
264
276
display_progress (progress , ++ cnt );
265
277
ce -> ce_flags &= ~CE_UPDATE ;
266
278
if (o -> update && !o -> dry_run ) {
267
- errs |= checkout_entry (ce , state , NULL );
279
+ errs |= checkout_entry (ce , & state , NULL );
268
280
}
269
281
}
270
282
}
@@ -1094,14 +1106,9 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
1094
1106
int i , ret ;
1095
1107
static struct cache_entry * dfc ;
1096
1108
struct exclude_list el ;
1097
- struct checkout state = CHECKOUT_INIT ;
1098
1109
1099
1110
if (len > MAX_UNPACK_TREES )
1100
1111
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
1112
1106
1113
memset (& el , 0 , sizeof (el ));
1107
1114
if (!core_apply_sparse_checkout || !o -> update )
@@ -1238,7 +1245,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
1238
1245
}
1239
1246
1240
1247
o -> src_index = NULL ;
1241
- ret = check_updates (o , & state ) ? (-2 ) : 0 ;
1248
+ ret = check_updates (o ) ? (-2 ) : 0 ;
1242
1249
if (o -> dst_index ) {
1243
1250
if (!ret ) {
1244
1251
if (!o -> result .cache_tree )
0 commit comments