unpack-trees: move checkout state into check_updates
PATCH 1/1 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.
--- unpack-trees.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
unpack-trees.c +8 -9
@@ -224,14 +224,18 @@ static void unlink_entry(const struct cache_entry *ce)schedule_dir_for_removal (ce->name,ce_namelen (ce)); } -static int check_updates (struct unpack_trees_options *o, -const struct checkout *state) +static int check_updates (struct unpack_trees_options *o) {unsigned cnt =0 , total =0 ;struct progress *progress =NULL ;struct index_state *index = &o->result;int i;int errs =0 ; +struct checkout state =CHECKOUT_INIT ; + state.force =1 ; + state.quiet =1 ; + state.refresh_cache =1 ; + state.istate = &o->result;if (o->update && o->verbose_update) {for (total = cnt =0 ; cnt < index->cache_nr; cnt++) {
@@ -270,7 +274,7 @@ static int check_updates(struct unpack_trees_options *o,display_progress (progress, ++cnt); ce->ce_flags &= ~CE_UPDATE ;if (o->update && !o->dry_run) { - errs |=checkout_entry (ce, state,NULL ); + errs |=checkout_entry (ce, &state,NULL ); } } }
@@ -1100,14 +1104,9 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_optionsint i, ret;static struct cache_entry *dfc;struct exclude_list el; -struct checkout state =CHECKOUT_INIT ;if (len >MAX_UNPACK_TREES )die ("unpack_trees takes at most %d trees" ,MAX_UNPACK_TREES ); - state.force =1 ; - state.quiet =1 ; - state.refresh_cache =1 ; - state.istate = &o->result;memset (&el,0 ,sizeof (el));if (!core_apply_sparse_checkout || !o->update)
@@ -1244,7 +1243,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options } o->src_index =NULL ; - ret =check_updates (o, &state) ? (-2 ) :0 ; + ret =check_updates (o) ? (-2 ) :0 ;if (o->dst_index) {if (!ret) {if (!o->result.cache_tree)
Signature · 1 line
2.11.0.rc2.51.g8b63c0e.dirty
Am 29.12.2016 um 00:26 schrieb Stefan Beller:
Quoted 9 lines
The checkout state was introduced via
16da134b1f9(read-trees: refactor theunpack_trees()part, 2006-07-30). An attempt to refactor the checkout state was done inb56aa5b268e(unpack-trees: pass checkout state explicitly tocheck_updates(), 2016-09-13), but we can go even further.The
struct checkout stateis not used inunpack_treesapart from initializing it, so move it into the function that makes use of it, which ischeck_updates.
Thanks for catching this, the result looks nicer.
Quoted 17 lines
Signed-off-by Stefan Beller <[email protected]>--- unpack-trees.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)unpack-trees.c +1
-2@@ -224,14 +224,18 @@ static void unlink_entry(const struct cache_entry *ce)schedule_dir_for_removal (ce->name,ce_namelen (ce)); } -static int check_updates (struct unpack_trees_options *o, -const struct checkout *state) +static int check_updates (struct unpack_trees_options *o) {
unpack-trees.c static void unlink_entry(const struct cache_entry *ce) · line 238
Quoted 10 lines
unpack-trees.c +5
-0unsigned cnt =0 , total =0 ;struct progress *progress =NULL ;struct index_state *index = &o->result;int i;int errs =0 ; +struct checkout state =CHECKOUT_INIT ; + state.force =1 ; + state.quiet =1 ; + state.refresh_cache =1 ; + state.istate = &o->result;
And here (as well as in two more places in this function) we could use "index" instead of "&o->result". Not sure if it's worth a patch, though.
Quoted 37 lines
unpack-trees.c +2
-7if (o->update && o->verbose_update) {for (total = cnt =0 ; cnt < index->cache_nr; cnt++) {@@ -270,7 +274,7 @@ static int check_updates(struct unpack_trees_options *o,display_progress (progress, ++cnt); ce->ce_flags &= ~CE_UPDATE ;if (o->update && !o->dry_run) { - errs |=checkout_entry (ce, state,NULL ); + errs |=checkout_entry (ce, &state,NULL ); } } }@@ -1100,14 +1104,9 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_optionsint i, ret;static struct cache_entry *dfc;struct exclude_list el; -struct checkout state =CHECKOUT_INIT ;if (len >MAX_UNPACK_TREES )die ("unpack_trees takes at most %d trees" ,MAX_UNPACK_TREES ); - state.force =1 ; - state.quiet =1 ; - state.refresh_cache =1 ; - state.istate = &o->result;memset (&el,0 ,sizeof (el));if (!core_apply_sparse_checkout || !o->update)@@ -1244,7 +1243,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options } o->src_index =NULL ; - ret =check_updates (o, &state) ? (-2 ) :0 ; + ret =check_updates (o) ? (-2 ) :0 ;if (o->dst_index) {if (!ret) {if (!o->result.cache_tree)