]> git.ipfire.org Git - thirdparty/git.git/commitdiff
introduce CHECKOUT_INIT
authorRené Scharfe <l.s.r@web.de>
Thu, 22 Sep 2016 16:11:33 +0000 (18:11 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 22 Sep 2016 20:42:18 +0000 (13:42 -0700)
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>
apply.c
builtin/checkout-index.c
builtin/checkout.c
cache.h
unpack-trees.c

diff --git a/apply.c b/apply.c
index e32702153c787747ba423fbe60697ab2ce4db3a3..b03d274b522b87e8666bc3703bf0c5f1c9fc9e5b 100644 (file)
--- a/apply.c
+++ b/apply.c
@@ -3334,10 +3334,8 @@ static void prepare_fn_table(struct apply_state *state, struct patch *patch)
 static int checkout_target(struct index_state *istate,
                           struct cache_entry *ce, struct stat *st)
 {
-       struct checkout costate;
+       struct checkout costate = CHECKOUT_INIT;
 
-       memset(&costate, 0, sizeof(costate));
-       costate.base_dir = "";
        costate.refresh_cache = 1;
        costate.istate = istate;
        if (checkout_entry(ce, &costate, NULL) || lstat(ce->name, st))
index 92c69672e96f6e7fc6bbe7b783c551474224f18b..30a49d9f424c0a1e04b321b5eb0a5e25462a53af 100644 (file)
@@ -16,7 +16,7 @@ static int checkout_stage; /* default to checkout stage0 */
 static int to_tempfile;
 static char topath[4][TEMPORARY_FILENAME_LENGTH + 1];
 
-static struct checkout state;
+static struct checkout state = CHECKOUT_INIT;
 
 static void write_tempfile_record(const char *name, const char *prefix)
 {
index 9941abc3acdfa035387606f7ecc8f33905f80e7d..4c8627208708adad9da51bb9b98917c48a5d838a 100644 (file)
@@ -239,7 +239,7 @@ static int checkout_paths(const struct checkout_opts *opts,
                          const char *revision)
 {
        int pos;
-       struct checkout state;
+       struct checkout state = CHECKOUT_INIT;
        static char *ps_matched;
        struct object_id rev;
        struct commit *head;
@@ -352,7 +352,6 @@ static int checkout_paths(const struct checkout_opts *opts,
                return 1;
 
        /* Now we are committed to check them out */
-       memset(&state, 0, sizeof(state));
        state.force = 1;
        state.refresh_cache = 1;
        state.istate = &the_index;
diff --git a/cache.h b/cache.h
index d0494c85338b9063b3abe6e2081c921617ca0203..5d9116c0c4ddc5efb546e51019c304aea887bb22 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -1354,6 +1354,7 @@ struct checkout {
                 not_new:1,
                 refresh_cache:1;
 };
+#define CHECKOUT_INIT { NULL, "" }
 
 #define TEMPORARY_FILENAME_LENGTH 25
 extern int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath);
index 3db3f02577a432ddec187873397e63e4c9f5af3e..ea6bdd20e0491554e88f4b84bd3b6354867021bc 100644 (file)
@@ -1094,12 +1094,10 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
        int i, ret;
        static struct cache_entry *dfc;
        struct exclude_list el;
-       struct checkout state;
+       struct checkout state = CHECKOUT_INIT;
 
        if (len > MAX_UNPACK_TREES)
                die("unpack_trees takes at most %d trees", MAX_UNPACK_TREES);
-       memset(&state, 0, sizeof(state));
-       state.base_dir = "";
        state.force = 1;
        state.quiet = 1;
        state.refresh_cache = 1;