From 04988c8d182da945cd9420274f33487157c5636f Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Mon, 27 Sep 2021 16:33:41 +0000 Subject: unpack-trees: introduce preserve_ignored to unpack_trees_options Currently, every caller of unpack_trees() that wants to ensure ignored files are overwritten by default needs to: * allocate unpack_trees_options.dir * flip the DIR_SHOW_IGNORED flag in unpack_trees_options.dir->flags * call setup_standard_excludes AND then after the call to unpack_trees() needs to * call dir_clear() * deallocate unpack_trees_options.dir That's a fair amount of boilerplate, and every caller uses identical code. Make this easier by instead introducing a new boolean value where the default value (0) does what we want so that new callers of unpack_trees() automatically get the appropriate behavior. And move all the handling of unpack_trees_options.dir into unpack_trees() itself. While preserve_ignored = 0 is the behavior we feel is the appropriate default, we defer fixing commands to use the appropriate default until a later commit. So, this commit introduces several locations where we manually set preserve_ignored=1. This makes it clear where code paths were previously preserving ignored files when they should not have been; a future commit will flip these to instead use a value of 0 to get the behavior we want. Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- merge-recursive.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'merge-recursive.c') diff --git a/merge-recursive.c b/merge-recursive.c index 2b791d1afb..94112aaabe 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -411,9 +411,7 @@ static int unpack_trees_start(struct merge_options *opt, else { opt->priv->unpack_opts.update = 1; /* FIXME: should only do this if !overwrite_ignore */ - CALLOC_ARRAY(opt->priv->unpack_opts.dir, 1); - opt->priv->unpack_opts.dir->flags |= DIR_SHOW_IGNORED; - setup_standard_excludes(opt->priv->unpack_opts.dir); + opt->priv->unpack_opts.preserve_ignored = 0; } opt->priv->unpack_opts.merge = 1; opt->priv->unpack_opts.head_idx = 2; @@ -428,10 +426,6 @@ static int unpack_trees_start(struct merge_options *opt, init_tree_desc_from_tree(t+2, merge); rc = unpack_trees(3, t, &opt->priv->unpack_opts); - if (opt->priv->unpack_opts.dir) { - dir_clear(opt->priv->unpack_opts.dir); - FREE_AND_NULL(opt->priv->unpack_opts.dir); - } cache_tree_free(&opt->repo->index->cache_tree); /* -- cgit v1.2.3