@@ -269,7 +269,7 @@ int write_archive_entries(struct archiver_args *args,
write_archive_entry_fn_t write_entry)
{
struct archiver_context context;
- struct unpack_trees_options opts;
+ struct unpack_trees_options opts = UNPACK_TREES_OPTIONS_INIT;
struct tree_desc t;
int err;
struct strbuf path_in_archive = STRBUF_INIT;
@@ -300,7 +300,6 @@ int write_archive_entries(struct archiver_args *args,
* Setup index and instruct attr to read index only
*/
if (!args->worktree_attributes) {
- memset(&opts, 0, sizeof(opts));
opts.index_only = 1;
opts.head_idx = -1;
opts.src_index = args->repo->index;
@@ -1901,7 +1901,7 @@ static void am_resolve(struct am_state *state)
static int fast_forward_to(struct tree *head, struct tree *remote, int reset)
{
struct lock_file lock_file = LOCK_INIT;
- struct unpack_trees_options opts;
+ struct unpack_trees_options opts = UNPACK_TREES_OPTIONS_INIT;
struct tree_desc t[2];
if (parse_tree(head) || parse_tree(remote))
@@ -1911,7 +1911,6 @@ static int fast_forward_to(struct tree *head, struct tree *remote, int reset)
refresh_cache(REFRESH_QUIET);
- memset(&opts, 0, sizeof(opts));
opts.head_idx = 1;
opts.src_index = &the_index;
opts.dst_index = &the_index;
@@ -1940,7 +1939,7 @@ static int fast_forward_to(struct tree *head, struct tree *remote, int reset)
static int merge_tree(struct tree *tree)
{
struct lock_file lock_file = LOCK_INIT;
- struct unpack_trees_options opts;
+ struct unpack_trees_options opts = UNPACK_TREES_OPTIONS_INIT;
struct tree_desc t[1];
if (parse_tree(tree))
@@ -1948,7 +1947,6 @@ static int merge_tree(struct tree *tree)
hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);
- memset(&opts, 0, sizeof(opts));
opts.head_idx = 1;
opts.src_index = &the_index;
opts.dst_index = &the_index;
@@ -639,10 +639,9 @@ static int reset_tree(struct tree *tree, const struct checkout_opts *o,
int worktree, int *writeout_error,
struct branch_info *info)
{
- struct unpack_trees_options opts;
+ struct unpack_trees_options opts = UNPACK_TREES_OPTIONS_INIT;
struct tree_desc tree_desc;
- memset(&opts, 0, sizeof(opts));
opts.head_idx = -1;
opts.update = worktree;
opts.skip_unmerged = !worktree;
@@ -719,9 +718,8 @@ static int merge_working_tree(const struct checkout_opts *opts,
} else {
struct tree_desc trees[2];
struct tree *tree;
- struct unpack_trees_options topts;
+ struct unpack_trees_options topts = UNPACK_TREES_OPTIONS_INIT;
- memset(&topts, 0, sizeof(topts));
topts.head_idx = -1;
topts.src_index = &the_index;
topts.dst_index = &the_index;
@@ -655,7 +655,7 @@ static int checkout(int submodule_progress)
struct object_id oid;
char *head;
struct lock_file lock_file = LOCK_INIT;
- struct unpack_trees_options opts;
+ struct unpack_trees_options opts = UNPACK_TREES_OPTIONS_INIT;
struct tree *tree;
struct tree_desc t;
int err = 0;
@@ -683,7 +683,6 @@ static int checkout(int submodule_progress)
hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);
- memset(&opts, 0, sizeof opts);
opts.update = 1;
opts.merge = 1;
opts.clone = 1;
@@ -303,7 +303,7 @@ static void add_remove_files(struct string_list *list)
static void create_base_index(const struct commit *current_head)
{
struct tree *tree;
- struct unpack_trees_options opts;
+ struct unpack_trees_options opts = UNPACK_TREES_OPTIONS_INIT;
struct tree_desc t;
if (!current_head) {
@@ -311,7 +311,6 @@ static void create_base_index(const struct commit *current_head)
return;
}
- memset(&opts, 0, sizeof(opts));
opts.head_idx = 1;
opts.index_only = 1;
opts.merge = 1;
@@ -670,9 +670,8 @@ static int read_tree_trivial(struct object_id *common, struct object_id *head,
int i, nr_trees = 0;
struct tree *trees[MAX_UNPACK_TREES];
struct tree_desc t[MAX_UNPACK_TREES];
- struct unpack_trees_options opts;
+ struct unpack_trees_options opts = UNPACK_TREES_OPTIONS_INIT;
- memset(&opts, 0, sizeof(opts));
opts.head_idx = 2;
opts.src_index = &the_index;
opts.dst_index = &the_index;
@@ -116,7 +116,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)
int i, stage = 0;
struct object_id oid;
struct tree_desc t[MAX_UNPACK_TREES];
- struct unpack_trees_options opts;
+ struct unpack_trees_options opts = UNPACK_TREES_OPTIONS_INIT;
int prefix_set = 0;
struct lock_file lock_file = LOCK_INIT;
const struct option read_tree_options[] = {
@@ -158,7 +158,6 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)
OPT_END()
};
- memset(&opts, 0, sizeof(opts));
opts.head_idx = -1;
opts.src_index = &the_index;
opts.dst_index = &the_index;
@@ -51,10 +51,9 @@ static int reset_index(const char *ref, const struct object_id *oid, int reset_t
int i, nr = 0;
struct tree_desc desc[2];
struct tree *tree;
- struct unpack_trees_options opts;
+ struct unpack_trees_options opts = UNPACK_TREES_OPTIONS_INIT;
int ret = -1;
- memset(&opts, 0, sizeof(opts));
opts.head_idx = 1;
opts.src_index = &the_index;
opts.dst_index = &the_index;
@@ -195,7 +195,7 @@ static void clean_tracked_sparse_directories(struct repository *r)
static int update_working_directory(struct pattern_list *pl)
{
enum update_sparsity_result result;
- struct unpack_trees_options o;
+ struct unpack_trees_options o = UNPACK_TREES_OPTIONS_INIT;
struct lock_file lock_file = LOCK_INIT;
struct repository *r = the_repository;
@@ -205,7 +205,6 @@ static int update_working_directory(struct pattern_list *pl)
r->index->sparse_checkout_patterns = pl;
- memset(&o, 0, sizeof(o));
o.verbose_update = isatty(2);
o.update = 1;
o.head_idx = -1;
@@ -233,7 +233,7 @@ static int clear_stash(int argc, const char **argv, const char *prefix)
static int reset_tree(struct object_id *i_tree, int update, int reset)
{
int nr_trees = 1;
- struct unpack_trees_options opts;
+ struct unpack_trees_options opts = UNPACK_TREES_OPTIONS_INIT;
struct tree_desc t[MAX_UNPACK_TREES];
struct tree *tree;
struct lock_file lock_file = LOCK_INIT;
@@ -244,8 +244,6 @@ static int reset_tree(struct object_id *i_tree, int update, int reset)
hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR);
- memset(&opts, 0, sizeof(opts));
-
tree = parse_tree_indirect(i_tree);
if (parse_tree(tree))
return -1;
@@ -799,7 +797,7 @@ static void diff_include_untracked(const struct stash_info *info, struct diff_op
const struct object_id *oid[] = { &info->w_commit, &info->u_tree };
struct tree *tree[ARRAY_SIZE(oid)];
struct tree_desc tree_desc[ARRAY_SIZE(oid)];
- struct unpack_trees_options unpack_tree_opt = { 0 };
+ struct unpack_trees_options unpack_tree_opt = UNPACK_TREES_OPTIONS_INIT;
int i;
for (i = 0; i < ARRAY_SIZE(oid); i++) {
@@ -526,13 +526,12 @@ static int diff_cache(struct rev_info *revs,
{
struct tree *tree;
struct tree_desc t;
- struct unpack_trees_options opts;
+ struct unpack_trees_options opts = UNPACK_TREES_OPTIONS_INIT;
tree = parse_tree_indirect(tree_oid);
if (!tree)
return error("bad tree object %s",
tree_name ? tree_name : oid_to_hex(tree_oid));
- memset(&opts, 0, sizeof(opts));
opts.head_idx = 1;
opts.index_only = cached;
opts.diff_index_cached = (cached &&
@@ -4021,9 +4021,8 @@ static int checkout(struct merge_options *opt,
/* Switch the index/working copy from old to new */
int ret;
struct tree_desc trees[2];
- struct unpack_trees_options unpack_opts;
+ struct unpack_trees_options unpack_opts = UNPACK_TREES_OPTIONS_INIT;
- memset(&unpack_opts, 0, sizeof(unpack_opts));
unpack_opts.head_idx = -1;
unpack_opts.src_index = opt->repo->index;
unpack_opts.dst_index = opt->repo->index;
@@ -50,7 +50,7 @@ int checkout_fast_forward(struct repository *r,
int overwrite_ignore)
{
struct tree *trees[MAX_UNPACK_TREES];
- struct unpack_trees_options opts;
+ struct unpack_trees_options opts = UNPACK_TREES_OPTIONS_INIT;
struct tree_desc t[MAX_UNPACK_TREES];
int i, nr_trees = 0;
struct dir_struct dir = DIR_INIT;
@@ -79,7 +79,6 @@ int checkout_fast_forward(struct repository *r,
init_tree_desc(t+i, trees[i]->buffer, trees[i]->size);
}
- memset(&opts, 0, sizeof(opts));
if (overwrite_ignore) {
dir.flags |= DIR_SHOW_IGNORED;
setup_standard_excludes(&dir);
@@ -21,7 +21,7 @@ int reset_head(struct repository *r, struct object_id *oid, const char *action,
struct object_id head_oid;
struct tree_desc desc[2] = { { NULL }, { NULL } };
struct lock_file lock = LOCK_INIT;
- struct unpack_trees_options unpack_tree_opts = { 0 };
+ struct unpack_trees_options unpack_tree_opts = UNPACK_TREES_OPTIONS_INIT;
struct tree *tree;
const char *reflog_action;
struct strbuf msg = STRBUF_INIT;
@@ -3652,7 +3652,7 @@ static int do_reset(struct repository *r,
struct lock_file lock = LOCK_INIT;
struct tree_desc desc;
struct tree *tree;
- struct unpack_trees_options unpack_tree_opts;
+ struct unpack_trees_options unpack_tree_opts = UNPACK_TREES_OPTIONS_INIT;
int ret = 0;
if (repo_hold_locked_index(r, &lock, LOCK_REPORT_ON_ERROR) < 0)
@@ -3691,7 +3691,6 @@ static int do_reset(struct repository *r,
}
}
- memset(&unpack_tree_opts, 0, sizeof(unpack_tree_opts));
setup_unpack_trees_porcelain(&unpack_tree_opts, "reset");
unpack_tree_opts.head_idx = 1;
unpack_tree_opts.src_index = r->index;
@@ -91,6 +91,8 @@ struct unpack_trees_options {
struct checkout_metadata meta;
};
+#define UNPACK_TREES_OPTIONS_INIT { 0 }
+
int unpack_trees(unsigned n, struct tree_desc *t,
struct unpack_trees_options *options);
Almost all users of "struct unpack_trees_options" allocate it on the stack already, let's provide an *_INIT macro for them to use. This will make later changes that would like to initialize other members of the struct easier[1][2], but for now we're keeping it compatible with a memset() to "0" with an "{ 0 }" initialization. This covers all callers except a special-case in "merge-recursive.c", which will be dealt with in a subsequent commit. 1. https://lore.kernel.org/git/87k0ixrv23.fsf@evledraar.gmail.com/ 2. https://lore.kernel.org/git/87fstlrumj.fsf@evledraar.gmail.com/ Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- archive.c | 3 +-- builtin/am.c | 6 ++---- builtin/checkout.c | 6 ++---- builtin/clone.c | 3 +-- builtin/commit.c | 3 +-- builtin/merge.c | 3 +-- builtin/read-tree.c | 3 +-- builtin/reset.c | 3 +-- builtin/sparse-checkout.c | 3 +-- builtin/stash.c | 6 ++---- diff-lib.c | 3 +-- merge-ort.c | 3 +-- merge.c | 3 +-- reset.c | 2 +- sequencer.c | 3 +-- unpack-trees.h | 2 ++ 16 files changed, 20 insertions(+), 35 deletions(-)