Skip to content

Commit 72d84ea

Browse files
derrickstoleegitster
authored andcommitted
unpack-trees: fix nested sparse-dir search
The iterated search in find_cache_entry() was recently modified to include a loop that searches backwards for a sparse directory entry that matches the given traverse_info and name_entry. However, the string comparison failed to actually concatenate those two strings, so this failed to find a sparse directory when it was not a top-level directory. This caused some errors in rare cases where a 'git checkout' spanned a diff that modified files within the sparse directory entry, but we could not correctly find the entry. Helped-by: Johannes Schindelin <[email protected]> Helped-by: René Scharfe <[email protected]> Signed-off-by: Derrick Stolee <[email protected]> Reviewed-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e27eab4 commit 72d84ea

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

unpack-trees.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,7 +1255,7 @@ static int sparse_dir_matches_path(const struct cache_entry *ce,
12551255
static struct cache_entry *find_cache_entry(struct traverse_info *info,
12561256
const struct name_entry *p)
12571257
{
1258-
struct cache_entry *ce;
1258+
const char *path;
12591259
int pos = find_cache_pos(info, p->path, p->pathlen);
12601260
struct unpack_trees_options *o = info->data;
12611261

@@ -1281,9 +1281,11 @@ static struct cache_entry *find_cache_entry(struct traverse_info *info,
12811281
* paths (e.g. "subdir-").
12821282
*/
12831283
while (pos >= 0) {
1284-
ce = o->src_index->cache[pos];
1284+
struct cache_entry *ce = o->src_index->cache[pos];
12851285

1286-
if (strncmp(ce->name, p->path, p->pathlen))
1286+
if (!skip_prefix(ce->name, info->traverse_path, &path) ||
1287+
strncmp(path, p->path, p->pathlen) ||
1288+
path[p->pathlen] != '/')
12871289
return NULL;
12881290

12891291
if (S_ISSPARSEDIR(ce->ce_mode) &&

0 commit comments

Comments
 (0)