Skip to content

Commit

Permalink
Merge branch 'vd/cache-bottom-fix'
Browse files Browse the repository at this point in the history
Correct a bug in unpack-trees introduced earlier.

* vd/cache-bottom-fix:
  Revert "unpack-trees: improve performance of next_cache_entry"
  unpack-trees: increment cache_bottom for sparse directories
  t1092: add sparse directory before cone in test repo
  • Loading branch information
gitster committed Mar 29, 2022
2 parents 3d8046a + 99430aa commit d629667
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 26 deletions.
7 changes: 6 additions & 1 deletion t/t1092-sparse-checkout-compatibility.sh
Expand Up @@ -16,7 +16,9 @@ test_expect_success 'setup' '
echo "after deep" >e &&
echo "after folder1" >g &&
echo "after x" >z &&
mkdir folder1 folder2 deep x &&
mkdir folder1 folder2 deep before x &&
echo "before deep" >before/a &&
echo "before deep again" >before/b &&
mkdir deep/deeper1 deep/deeper2 deep/before deep/later &&
mkdir deep/deeper1/deepest &&
mkdir deep/deeper1/deepest2 &&
Expand Down Expand Up @@ -254,6 +256,7 @@ test_expect_success 'root directory cannot be sparse' '
# Verify sparse directories still present, root directory is not sparse
cat >expect <<-EOF &&
before/
folder1/
folder2/
x/
Expand Down Expand Up @@ -1444,6 +1447,7 @@ test_expect_success 'ls-files' '
cat >expect <<-\EOF &&
a
before/
deep/
e
folder1-
Expand Down Expand Up @@ -1491,6 +1495,7 @@ test_expect_success 'ls-files' '
cat >expect <<-\EOF &&
a
before/
deep/
e
folder1-
Expand Down
39 changes: 14 additions & 25 deletions unpack-trees.c
Expand Up @@ -595,13 +595,6 @@ static void mark_ce_used(struct cache_entry *ce, struct unpack_trees_options *o)
{
ce->ce_flags |= CE_UNPACKED;

/*
* If this is a sparse directory, don't advance cache_bottom.
* That will be advanced later using the cache-tree data.
*/
if (S_ISSPARSEDIR(ce->ce_mode))
return;

if (o->cache_bottom < o->src_index->cache_nr &&
o->src_index->cache[o->cache_bottom] == ce) {
int bottom = o->cache_bottom;
Expand Down Expand Up @@ -651,24 +644,17 @@ static void mark_ce_used_same_name(struct cache_entry *ce,
}
}

static struct cache_entry *next_cache_entry(struct unpack_trees_options *o, int *hint)
static struct cache_entry *next_cache_entry(struct unpack_trees_options *o)
{
const struct index_state *index = o->src_index;
int pos = o->cache_bottom;

if (*hint > pos)
pos = *hint;

while (pos < index->cache_nr) {
struct cache_entry *ce = index->cache[pos];
if (!(ce->ce_flags & CE_UNPACKED)) {
*hint = pos + 1;
if (!(ce->ce_flags & CE_UNPACKED))
return ce;
}
pos++;
}

*hint = pos;
return NULL;
}

Expand Down Expand Up @@ -1416,13 +1402,12 @@ static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str

/* Are we supposed to look at the index too? */
if (o->merge) {
int hint = -1;
while (1) {
int cmp;
struct cache_entry *ce;

if (o->diff_index_cached)
ce = next_cache_entry(o, &hint);
ce = next_cache_entry(o);
else
ce = find_cache_entry(info, p);

Expand Down Expand Up @@ -1478,7 +1463,14 @@ static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str
* it does not do any look-ahead, so this is safe.
*/
if (matches) {
o->cache_bottom += matches;
/*
* Only increment the cache_bottom if the
* directory isn't a sparse directory index
* entry (if it is, it was already incremented)
* in 'mark_ce_used()'
*/
if (!src[0] || !S_ISSPARSEDIR(src[0]->ce_mode))
o->cache_bottom += matches;
return mask;
}
}
Expand Down Expand Up @@ -1777,7 +1769,7 @@ static int verify_absent(const struct cache_entry *,
int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options *o)
{
struct repository *repo = the_repository;
int i, hint, ret;
int i, ret;
static struct cache_entry *dfc;
struct pattern_list pl;
int free_pattern_list = 0;
Expand Down Expand Up @@ -1869,15 +1861,13 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
info.pathspec = o->pathspec;

if (o->prefix) {
hint = -1;

/*
* Unpack existing index entries that sort before the
* prefix the tree is spliced into. Note that o->merge
* is always true in this case.
*/
while (1) {
struct cache_entry *ce = next_cache_entry(o, &hint);
struct cache_entry *ce = next_cache_entry(o);
if (!ce)
break;
if (ce_in_traverse_path(ce, &info))
Expand All @@ -1898,9 +1888,8 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options

/* Any left-over entries in the index? */
if (o->merge) {
hint = -1;
while (1) {
struct cache_entry *ce = next_cache_entry(o, &hint);
struct cache_entry *ce = next_cache_entry(o);
if (!ce)
break;
if (unpack_index_entry(ce, o) < 0)
Expand Down

0 comments on commit d629667

Please sign in to comment.