introduce CHECKOUT_INIT

Add a static initializer for struct checkout and use it throughout the code base. It's shorter, avoids a memset(3) call and makes sure the base_dir member is initialized to a valid (empty) string. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Sep 22, 2016 at 18:11 UTC 68e3d6292f27f123c072175748183c9cb9bc1c70
5 files changed +5 -9
apply.c
+1 -3
@@ -3334,10 +3334,8 @@ static void prepare_fn_table(struct apply_state *state, struct patch *patch)
3334 static int checkout_target(struct index_state *istate,
3335 struct cache_entry *ce, struct stat *st)
3336 {
3337 - struct checkout costate;
3337 + struct checkout costate = CHECKOUT_INIT;
3338
3339 - memset(&costate, 0, sizeof(costate));
3340 - costate.base_dir = "";
3339 costate.refresh_cache = 1;
3340 costate.istate = istate;
3341 if (checkout_entry(ce, &costate, NULL) || lstat(ce->name, st))
builtin/checkout-index.c
+1 -1
@@ -16,7 +16,7 @@ static int checkout_stage; /* default to checkout stage0 */
16 static int to_tempfile;
17 static char topath[4][TEMPORARY_FILENAME_LENGTH + 1];
18
19 -static struct checkout state;
19 +static struct checkout state = CHECKOUT_INIT;
20
21 static void write_tempfile_record(const char *name, const char *prefix)
22 {
builtin/checkout.c
+1 -2
@@ -239,7 +239,7 @@ static int checkout_paths(const struct checkout_opts *opts,
239 const char *revision)
240 {
241 int pos;
242 - struct checkout state;
242 + struct checkout state = CHECKOUT_INIT;
243 static char *ps_matched;
244 struct object_id rev;
245 struct commit *head;
@@ -352,7 +352,6 @@ static int checkout_paths(const struct checkout_opts *opts,
352 return 1;
353
354 /* Now we are committed to check them out */
355 - memset(&state, 0, sizeof(state));
355 state.force = 1;
356 state.refresh_cache = 1;
357 state.istate = &the_index;
cache.h
+1
@@ -1354,6 +1354,7 @@ struct checkout {
1354 not_new:1,
1355 refresh_cache:1;
1356 };
1357 +#define CHECKOUT_INIT { NULL, "" }
1358
1359 #define TEMPORARY_FILENAME_LENGTH 25
1360 extern int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath);
unpack-trees.c
+1 -3
@@ -1094,12 +1094,10 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
1094 int i, ret;
1095 static struct cache_entry *dfc;
1096 struct exclude_list el;
1097 - struct checkout state;
1097 + struct checkout state = CHECKOUT_INIT;
1098
1099 if (len > MAX_UNPACK_TREES)
1100 die("unpack_trees takes at most %d trees", MAX_UNPACK_TREES);
1101 - memset(&state, 0, sizeof(state));
1102 - state.base_dir = "";
1101 state.force = 1;
1102 state.quiet = 1;
1103 state.refresh_cache = 1;