diff options
author | Derrick Stolee <dstolee@microsoft.com> | 2021-03-30 15:10:57 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2021-03-30 21:57:47 +0200 |
commit | 13e133124728736db605e8ad6d2a844c380cb735 (patch) | |
tree | 491966d5ed9507834f4a51f3e9df438cac0a9658 /unpack-trees.c | |
parent | submodule: sparse-index should not collapse links (diff) | |
download | git-13e133124728736db605e8ad6d2a844c380cb735.tar.xz git-13e133124728736db605e8ad6d2a844c380cb735.zip |
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 <dstolee@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'unpack-trees.c')
-rw-r--r-- | unpack-trees.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/unpack-trees.c b/unpack-trees.c index 4dd9921907..0b888dab22 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -746,9 +746,13 @@ static int index_pos_by_traverse_info(struct name_entry *names, strbuf_make_traverse_path(&name, info, names->path, names->pathlen); strbuf_addch(&name, '/'); pos = index_name_pos(o->src_index, name.buf, name.len); - if (pos >= 0) - BUG("This is a directory and should not exist in index"); - pos = -pos - 1; + if (pos >= 0) { + if (!o->src_index->sparse_index || + !(o->src_index->cache[pos]->ce_flags & CE_SKIP_WORKTREE)) + BUG("This is a directory and should not exist in index"); + } else { + pos = -pos - 1; + } if (pos >= o->src_index->cache_nr || !starts_with(o->src_index->cache[pos]->name, name.buf) || (pos > 0 && starts_with(o->src_index->cache[pos-1]->name, name.buf))) |