Skip to content

Commit 589570d

Browse files
committed
unpack-trees.c: use path_excluded() in check_ok_to_remove()
This function is responsible for determining if a path that is not tracked is ignored and allow "checkout" to overwrite it as needed. It used excluded() without checking if higher level directory in the path is ignored; correct it to use path_excluded() for this check. Signed-off-by: Junio C Hamano <[email protected]> --- * There are uses of lower-level interface excluded_from_list() in the codepath for narrow-checkout hack; they are supposed to be already checking each level as they descend, and are not touched with this patch.
1 parent eb69934 commit 589570d

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

unpack-trees.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,10 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
10161016
o->el = &el;
10171017
}
10181018

1019+
if (o->dir) {
1020+
o->path_exclude_check = xmalloc(sizeof(struct path_exclude_check));
1021+
path_exclude_check_init(o->path_exclude_check, o->dir);
1022+
}
10191023
memset(&o->result, 0, sizeof(o->result));
10201024
o->result.initialized = 1;
10211025
o->result.timestamp.sec = o->src_index->timestamp.sec;
@@ -1140,6 +1144,10 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
11401144

11411145
done:
11421146
free_excludes(&el);
1147+
if (o->path_exclude_check) {
1148+
path_exclude_check_clear(o->path_exclude_check);
1149+
free(o->path_exclude_check);
1150+
}
11431151
return ret;
11441152

11451153
return_failed:
@@ -1355,7 +1363,8 @@ static int check_ok_to_remove(const char *name, int len, int dtype,
13551363
if (ignore_case && icase_exists(o, name, len, st))
13561364
return 0;
13571365

1358-
if (o->dir && excluded(o->dir, name, &dtype))
1366+
if (o->dir &&
1367+
path_excluded(o->path_exclude_check, name, -1, &dtype))
13591368
/*
13601369
* ce->name is explicitly excluded, so it is Ok to
13611370
* overwrite it.

unpack-trees.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ struct unpack_trees_options {
5252
const char *prefix;
5353
int cache_bottom;
5454
struct dir_struct *dir;
55+
struct path_exclude_check *path_exclude_check;
5556
struct pathspec *pathspec;
5657
merge_fn_t fn;
5758
const char *msgs[NB_UNPACK_TREES_ERROR_TYPES];

0 commit comments

Comments
 (0)