Skip to content

Commit 13e1331

Browse files
derrickstoleegitster
authored andcommitted
unpack-trees: allow sparse directories
The index_pos_by_traverse_info() currently throws a BUG() when a directory entry exists exactly in the index. We need to consider that it is possible to have a directory in a sparse index as long as that entry is itself marked with the skip-worktree bit. The 'pos' variable is assigned a negative value if an exact match is not found. Since a directory name can be an exact match, it is no longer an error to have a nonnegative 'pos' value. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f442313 commit 13e1331

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

unpack-trees.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -746,9 +746,13 @@ static int index_pos_by_traverse_info(struct name_entry *names,
746746
strbuf_make_traverse_path(&name, info, names->path, names->pathlen);
747747
strbuf_addch(&name, '/');
748748
pos = index_name_pos(o->src_index, name.buf, name.len);
749-
if (pos >= 0)
750-
BUG("This is a directory and should not exist in index");
751-
pos = -pos - 1;
749+
if (pos >= 0) {
750+
if (!o->src_index->sparse_index ||
751+
!(o->src_index->cache[pos]->ce_flags & CE_SKIP_WORKTREE))
752+
BUG("This is a directory and should not exist in index");
753+
} else {
754+
pos = -pos - 1;
755+
}
752756
if (pos >= o->src_index->cache_nr ||
753757
!starts_with(o->src_index->cache[pos]->name, name.buf) ||
754758
(pos > 0 && starts_with(o->src_index->cache[pos-1]->name, name.buf)))

0 commit comments

Comments
 (0)