Skip to content

Commit d629667

Browse files
committed
Merge branch 'vd/cache-bottom-fix'
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
2 parents 3d8046a + 99430aa commit d629667

File tree

2 files changed

+20
-26
lines changed

2 files changed

+20
-26
lines changed

t/t1092-sparse-checkout-compatibility.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ test_expect_success 'setup' '
1616
echo "after deep" >e &&
1717
echo "after folder1" >g &&
1818
echo "after x" >z &&
19-
mkdir folder1 folder2 deep x &&
19+
mkdir folder1 folder2 deep before x &&
20+
echo "before deep" >before/a &&
21+
echo "before deep again" >before/b &&
2022
mkdir deep/deeper1 deep/deeper2 deep/before deep/later &&
2123
mkdir deep/deeper1/deepest &&
2224
mkdir deep/deeper1/deepest2 &&
@@ -254,6 +256,7 @@ test_expect_success 'root directory cannot be sparse' '
254256
255257
# Verify sparse directories still present, root directory is not sparse
256258
cat >expect <<-EOF &&
259+
before/
257260
folder1/
258261
folder2/
259262
x/
@@ -1444,6 +1447,7 @@ test_expect_success 'ls-files' '
14441447
14451448
cat >expect <<-\EOF &&
14461449
a
1450+
before/
14471451
deep/
14481452
e
14491453
folder1-
@@ -1491,6 +1495,7 @@ test_expect_success 'ls-files' '
14911495
14921496
cat >expect <<-\EOF &&
14931497
a
1498+
before/
14941499
deep/
14951500
e
14961501
folder1-

unpack-trees.c

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -595,13 +595,6 @@ static void mark_ce_used(struct cache_entry *ce, struct unpack_trees_options *o)
595595
{
596596
ce->ce_flags |= CE_UNPACKED;
597597

598-
/*
599-
* If this is a sparse directory, don't advance cache_bottom.
600-
* That will be advanced later using the cache-tree data.
601-
*/
602-
if (S_ISSPARSEDIR(ce->ce_mode))
603-
return;
604-
605598
if (o->cache_bottom < o->src_index->cache_nr &&
606599
o->src_index->cache[o->cache_bottom] == ce) {
607600
int bottom = o->cache_bottom;
@@ -651,24 +644,17 @@ static void mark_ce_used_same_name(struct cache_entry *ce,
651644
}
652645
}
653646

654-
static struct cache_entry *next_cache_entry(struct unpack_trees_options *o, int *hint)
647+
static struct cache_entry *next_cache_entry(struct unpack_trees_options *o)
655648
{
656649
const struct index_state *index = o->src_index;
657650
int pos = o->cache_bottom;
658651

659-
if (*hint > pos)
660-
pos = *hint;
661-
662652
while (pos < index->cache_nr) {
663653
struct cache_entry *ce = index->cache[pos];
664-
if (!(ce->ce_flags & CE_UNPACKED)) {
665-
*hint = pos + 1;
654+
if (!(ce->ce_flags & CE_UNPACKED))
666655
return ce;
667-
}
668656
pos++;
669657
}
670-
671-
*hint = pos;
672658
return NULL;
673659
}
674660

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

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

14241409
if (o->diff_index_cached)
1425-
ce = next_cache_entry(o, &hint);
1410+
ce = next_cache_entry(o);
14261411
else
14271412
ce = find_cache_entry(info, p);
14281413

@@ -1478,7 +1463,14 @@ static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str
14781463
* it does not do any look-ahead, so this is safe.
14791464
*/
14801465
if (matches) {
1481-
o->cache_bottom += matches;
1466+
/*
1467+
* Only increment the cache_bottom if the
1468+
* directory isn't a sparse directory index
1469+
* entry (if it is, it was already incremented)
1470+
* in 'mark_ce_used()'
1471+
*/
1472+
if (!src[0] || !S_ISSPARSEDIR(src[0]->ce_mode))
1473+
o->cache_bottom += matches;
14821474
return mask;
14831475
}
14841476
}
@@ -1777,7 +1769,7 @@ static int verify_absent(const struct cache_entry *,
17771769
int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options *o)
17781770
{
17791771
struct repository *repo = the_repository;
1780-
int i, hint, ret;
1772+
int i, ret;
17811773
static struct cache_entry *dfc;
17821774
struct pattern_list pl;
17831775
int free_pattern_list = 0;
@@ -1869,15 +1861,13 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
18691861
info.pathspec = o->pathspec;
18701862

18711863
if (o->prefix) {
1872-
hint = -1;
1873-
18741864
/*
18751865
* Unpack existing index entries that sort before the
18761866
* prefix the tree is spliced into. Note that o->merge
18771867
* is always true in this case.
18781868
*/
18791869
while (1) {
1880-
struct cache_entry *ce = next_cache_entry(o, &hint);
1870+
struct cache_entry *ce = next_cache_entry(o);
18811871
if (!ce)
18821872
break;
18831873
if (ce_in_traverse_path(ce, &info))
@@ -1898,9 +1888,8 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
18981888

18991889
/* Any left-over entries in the index? */
19001890
if (o->merge) {
1901-
hint = -1;
19021891
while (1) {
1903-
struct cache_entry *ce = next_cache_entry(o, &hint);
1892+
struct cache_entry *ce = next_cache_entry(o);
19041893
if (!ce)
19051894
break;
19061895
if (unpack_index_entry(ce, o) < 0)

0 commit comments

Comments
 (0)