{"thread":{"id":"44134","subject":"[PATCH] introduce CHECKOUT_INIT","startedAt":"2016-09-22T16:11:50Z","lastAt":"2016-09-22T16:11:50Z","messageCount":1,"participants":["René Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"302377","messageId":"c2defe5a-3a49-d776-7806-f3abfbd79770@web.de","threadId":"44134","inReplyTo":null,"subject":"[PATCH] introduce CHECKOUT_INIT","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2016-09-22T16:11:33Z","receivedAt":"2016-09-22T16:11:50Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Add a static initializer for struct checkout and use it throughout the\ncode base.  It's shorter, avoids a memset(3) call and makes sure the\nbase_dir member is initialized to a valid (empty) string.\n\nSigned-off-by: Rene Scharfe <l.s.r@web.de>\n---\n apply.c                  | 4 +---\n builtin/checkout-index.c | 2 +-\n builtin/checkout.c       | 3 +--\n cache.h                  | 1 +\n unpack-trees.c           | 4 +---\n 5 files changed, 5 insertions(+), 9 deletions(-)\n\ndiff --git a/apply.c b/apply.c\nindex e327021..b03d274 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -3334,10 +3334,8 @@ static void prepare_fn_table(struct apply_state *state, struct patch *patch)\n static int checkout_target(struct index_state *istate,\n \t\t\t   struct cache_entry *ce, struct stat *st)\n {\n-\tstruct checkout costate;\n+\tstruct checkout costate = CHECKOUT_INIT;\n \n-\tmemset(&costate, 0, sizeof(costate));\n-\tcostate.base_dir = \"\";\n \tcostate.refresh_cache = 1;\n \tcostate.istate = istate;\n \tif (checkout_entry(ce, &costate, NULL) || lstat(ce->name, st))\ndiff --git a/builtin/checkout-index.c b/builtin/checkout-index.c\nindex 92c6967..30a49d9 100644\n--- a/builtin/checkout-index.c\n+++ b/builtin/checkout-index.c\n@@ -16,7 +16,7 @@ static int checkout_stage; /* default to checkout stage0 */\n static int to_tempfile;\n static char topath[4][TEMPORARY_FILENAME_LENGTH + 1];\n \n-static struct checkout state;\n+static struct checkout state = CHECKOUT_INIT;\n \n static void write_tempfile_record(const char *name, const char *prefix)\n {\ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex 9941abc..4c86272 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -239,7 +239,7 @@ static int checkout_paths(const struct checkout_opts *opts,\n \t\t\t  const char *revision)\n {\n \tint pos;\n-\tstruct checkout state;\n+\tstruct checkout state = CHECKOUT_INIT;\n \tstatic char *ps_matched;\n \tstruct object_id rev;\n \tstruct commit *head;\n@@ -352,7 +352,6 @@ static int checkout_paths(const struct checkout_opts *opts,\n \t\treturn 1;\n \n \t/* Now we are committed to check them out */\n-\tmemset(&state, 0, sizeof(state));\n \tstate.force = 1;\n \tstate.refresh_cache = 1;\n \tstate.istate = &the_index;\ndiff --git a/cache.h b/cache.h\nindex d0494c8..5d9116c 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1354,6 +1354,7 @@ struct checkout {\n \t\t not_new:1,\n \t\t refresh_cache:1;\n };\n+#define CHECKOUT_INIT { NULL, \"\" }\n \n #define TEMPORARY_FILENAME_LENGTH 25\n extern int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath);\ndiff --git a/unpack-trees.c b/unpack-trees.c\nindex 3db3f02..ea6bdd2 100644\n--- a/unpack-trees.c\n+++ b/unpack-trees.c\n@@ -1094,12 +1094,10 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options\n \tint i, ret;\n \tstatic struct cache_entry *dfc;\n \tstruct exclude_list el;\n-\tstruct checkout state;\n+\tstruct checkout state = CHECKOUT_INIT;\n \n \tif (len > MAX_UNPACK_TREES)\n \t\tdie(\"unpack_trees takes at most %d trees\", MAX_UNPACK_TREES);\n-\tmemset(&state, 0, sizeof(state));\n-\tstate.base_dir = \"\";\n \tstate.force = 1;\n \tstate.quiet = 1;\n \tstate.refresh_cache = 1;\n-- \n2.10.0\n\n"}]}