unpack-trees: avoid the_index in verify_absent()

Both functions that are updated in this commit are called by verify_absent(), which is part of the "unpack-trees" operation that is supposed to work on any index file specified by the caller. Thanks to Brandon [1] [2], an implicit dependency on the_index is exposed. This commit fixes it. In both functions, it makes sense to use src_index to check for exclusion because it's almost unchanged and should give us the same outcome as if running the exclude check before the unpack. It's "almost unchanged" because we do invalidate cache-tree and untracked cache in the source index. But this should not affect how exclude machinery uses the index: to see if a file is tracked, and to read a blob from the index instead of worktree if it's marked skip-worktree (i.e. it's not available in worktree) [1] a0bba65b10 (dir: convert is_excluded to take an index - 2017-05-05 [2] 2c1eb10454 (dir: convert read_directory to take an index - 2017-05-05) Helped-by: Elijah Newren <newren@gmail.com> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Aug 13, 2018 at 18:14 UTC c7f3259d0d343f17848b0135612f61c075c47690
1 file changed +2 -2
unpack-trees.c
+2 -2
@@ -1658,7 +1658,7 @@ static int verify_clean_subdirectory(const struct cache_entry *ce,
1658 memset(&d, 0, sizeof(d));
1659 if (o->dir)
1660 d.exclude_per_dir = o->dir->exclude_per_dir;
1661 - i = read_directory(&d, &the_index, pathbuf, namelen+1, NULL);
1661 + i = read_directory(&d, o->src_index, pathbuf, namelen+1, NULL);
1662 if (i)
1663 return o->gently ? -1 :
1664 add_rejected_path(o, ERROR_NOT_UPTODATE_DIR, ce->name);
@@ -1700,7 +1700,7 @@ static int check_ok_to_remove(const char *name, int len, int dtype,
1700 return 0;
1701
1702 if (o->dir &&
1703 - is_excluded(o->dir, &the_index, name, &dtype))
1703 + is_excluded(o->dir, o->src_index, name, &dtype))
1704 /*
1705 * ce->name is explicitly excluded, so it is Ok to
1706 * overwrite it.