Skip to content

Commit 03f15a7

Browse files
tgummerergitster
authored andcommitted
read-cache: fix reading of split index
The split index extension uses ewah bitmaps to mark index entries as deleted, instead of removing them from the index directly. This can result in an on-disk index, in which entries of stage #0 and higher stages appear, which are removed later when the index bases are merged. 15999d0 read_index_from(): catch out of order entries when reading an index file introduces a check which checks if the entries are in order after each index entry is read in do_read_index. This check may however fail when a split index is read. Fix this by moving checking the index after we know there is no split index or after the split index bases are successfully merged instead. Signed-off-by: Thomas Gummerer <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9874fca commit 03f15a7

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

read-cache.c

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,18 +1480,25 @@ static struct cache_entry *create_from_disk(struct ondisk_cache_entry *ondisk,
14801480
return ce;
14811481
}
14821482

1483-
static void check_ce_order(struct cache_entry *ce, struct cache_entry *next_ce)
1484-
{
1485-
int name_compare = strcmp(ce->name, next_ce->name);
1486-
if (0 < name_compare)
1487-
die("unordered stage entries in index");
1488-
if (!name_compare) {
1489-
if (!ce_stage(ce))
1490-
die("multiple stage entries for merged file '%s'",
1491-
ce->name);
1492-
if (ce_stage(ce) > ce_stage(next_ce))
1493-
die("unordered stage entries for '%s'",
1494-
ce->name);
1483+
static void check_ce_order(struct index_state *istate)
1484+
{
1485+
unsigned int i;
1486+
1487+
for (i = 1; i < istate->cache_nr; i++) {
1488+
struct cache_entry *ce = istate->cache[i - 1];
1489+
struct cache_entry *next_ce = istate->cache[i];
1490+
int name_compare = strcmp(ce->name, next_ce->name);
1491+
1492+
if (0 < name_compare)
1493+
die("unordered stage entries in index");
1494+
if (!name_compare) {
1495+
if (!ce_stage(ce))
1496+
die("multiple stage entries for merged file '%s'",
1497+
ce->name);
1498+
if (ce_stage(ce) > ce_stage(next_ce))
1499+
die("unordered stage entries for '%s'",
1500+
ce->name);
1501+
}
14951502
}
14961503
}
14971504

@@ -1556,9 +1563,6 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
15561563
ce = create_from_disk(disk_ce, &consumed, previous_name);
15571564
set_index_entry(istate, i, ce);
15581565

1559-
if (i > 0)
1560-
check_ce_order(istate->cache[i - 1], ce);
1561-
15621566
src_offset += consumed;
15631567
}
15641568
strbuf_release(&previous_name_buf);
@@ -1602,11 +1606,10 @@ int read_index_from(struct index_state *istate, const char *path)
16021606

16031607
ret = do_read_index(istate, path, 0);
16041608
split_index = istate->split_index;
1605-
if (!split_index)
1606-
return ret;
1607-
1608-
if (is_null_sha1(split_index->base_sha1))
1609+
if (!split_index || is_null_sha1(split_index->base_sha1)) {
1610+
check_ce_order(istate);
16091611
return ret;
1612+
}
16101613

16111614
if (split_index->base)
16121615
discard_index(split_index->base);
@@ -1622,6 +1625,7 @@ int read_index_from(struct index_state *istate, const char *path)
16221625
sha1_to_hex(split_index->base_sha1)),
16231626
sha1_to_hex(split_index->base->sha1));
16241627
merge_base_index(istate);
1628+
check_ce_order(istate);
16251629
return ret;
16261630
}
16271631

0 commit comments

Comments
 (0)