Skip to content

Commit 68e3d62

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6fe1b14 commit 68e3d62

File tree

5 files changed

+5
-9
lines changed

5 files changed

+5
-9
lines changed

apply.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3334,10 +3334,8 @@ static void prepare_fn_table(struct apply_state *state, struct patch *patch)
33343334
static int checkout_target(struct index_state *istate,
33353335
struct cache_entry *ce, struct stat *st)
33363336
{
3337-
struct checkout costate;
3337+
struct checkout costate = CHECKOUT_INIT;
33383338

3339-
memset(&costate, 0, sizeof(costate));
3340-
costate.base_dir = "";
33413339
costate.refresh_cache = 1;
33423340
costate.istate = istate;
33433341
if (checkout_entry(ce, &costate, NULL) || lstat(ce->name, st))

builtin/checkout-index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ static int checkout_stage; /* default to checkout stage0 */
1616
static int to_tempfile;
1717
static char topath[4][TEMPORARY_FILENAME_LENGTH + 1];
1818

19-
static struct checkout state;
19+
static struct checkout state = CHECKOUT_INIT;
2020

2121
static void write_tempfile_record(const char *name, const char *prefix)
2222
{

builtin/checkout.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ static int checkout_paths(const struct checkout_opts *opts,
239239
const char *revision)
240240
{
241241
int pos;
242-
struct checkout state;
242+
struct checkout state = CHECKOUT_INIT;
243243
static char *ps_matched;
244244
struct object_id rev;
245245
struct commit *head;
@@ -352,7 +352,6 @@ static int checkout_paths(const struct checkout_opts *opts,
352352
return 1;
353353

354354
/* Now we are committed to check them out */
355-
memset(&state, 0, sizeof(state));
356355
state.force = 1;
357356
state.refresh_cache = 1;
358357
state.istate = &the_index;

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,6 +1354,7 @@ struct checkout {
13541354
not_new:1,
13551355
refresh_cache:1;
13561356
};
1357+
#define CHECKOUT_INIT { NULL, "" }
13571358

13581359
#define TEMPORARY_FILENAME_LENGTH 25
13591360
extern int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath);

unpack-trees.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,12 +1094,10 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
10941094
int i, ret;
10951095
static struct cache_entry *dfc;
10961096
struct exclude_list el;
1097-
struct checkout state;
1097+
struct checkout state = CHECKOUT_INIT;
10981098

10991099
if (len > MAX_UNPACK_TREES)
11001100
die("unpack_trees takes at most %d trees", MAX_UNPACK_TREES);
1101-
memset(&state, 0, sizeof(state));
1102-
state.base_dir = "";
11031101
state.force = 1;
11041102
state.quiet = 1;
11051103
state.refresh_cache = 1;

0 commit comments

Comments
 (0)