path: root/builtin/read-tree.c
diff options
authorElijah Newren <>2021-09-27 16:33:41 (GMT)
committerJunio C Hamano <>2021-09-27 20:38:37 (GMT)
commit04988c8d182da945cd9420274f33487157c5636f (patch)
tree32ab1cf9026d6e4a05fae3096a7ae2e38bdf4222 /builtin/read-tree.c
parent491a7575f188cbf6cfb5be75981a40beb4c22b44 (diff)
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 <>
Diffstat (limited to 'builtin/read-tree.c')
1 files changed, 3 insertions, 10 deletions
diff --git a/builtin/read-tree.c b/builtin/read-tree.c
index 73cb957..443d206 100644
--- a/builtin/read-tree.c
+++ b/builtin/read-tree.c
@@ -201,11 +201,9 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)
if ((opts.update || opts.index_only) && !opts.merge)
die("%s is meaningless without -m, --reset, or --prefix",
opts.update ? "-u" : "-i");
- if (opts.update && !opts.reset) {
- CALLOC_ARRAY(opts.dir, 1);
- opts.dir->flags |= DIR_SHOW_IGNORED;
- setup_standard_excludes(opts.dir);
- }
+ if (opts.update && !opts.reset)
+ opts.preserve_ignored = 0;
+ /* otherwise, opts.preserve_ignored is irrelevant */
if (opts.merge && !opts.index_only)
@@ -245,11 +243,6 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)
if (unpack_trees(nr_trees, t, &opts))
return 128;
- if (opts.dir) {
- dir_clear(opts.dir);
- FREE_AND_NULL(opts.dir);
- }
if (opts.debug_unpack || opts.dry_run)
return 0; /* do not write the index out */