@@ -1486,18 +1486,25 @@ static struct cache_entry *create_from_disk(struct ondisk_cache_entry *ondisk,
1486
1486
return ce ;
1487
1487
}
1488
1488
1489
- static void check_ce_order (struct cache_entry * ce , struct cache_entry * next_ce )
1490
- {
1491
- int name_compare = strcmp (ce -> name , next_ce -> name );
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 );
1489
+ static void check_ce_order (struct index_state * istate )
1490
+ {
1491
+ unsigned int i ;
1492
+
1493
+ for (i = 1 ; i < istate -> cache_nr ; i ++ ) {
1494
+ struct cache_entry * ce = istate -> cache [i - 1 ];
1495
+ struct cache_entry * next_ce = istate -> cache [i ];
1496
+ int name_compare = strcmp (ce -> name , next_ce -> name );
1497
+
1498
+ if (0 < name_compare )
1499
+ die ("unordered stage entries in index" );
1500
+ if (!name_compare ) {
1501
+ if (!ce_stage (ce ))
1502
+ die ("multiple stage entries for merged file '%s'" ,
1503
+ ce -> name );
1504
+ if (ce_stage (ce ) > ce_stage (next_ce ))
1505
+ die ("unordered stage entries for '%s'" ,
1506
+ ce -> name );
1507
+ }
1501
1508
}
1502
1509
}
1503
1510
@@ -1562,9 +1569,6 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
1562
1569
ce = create_from_disk (disk_ce , & consumed , previous_name );
1563
1570
set_index_entry (istate , i , ce );
1564
1571
1565
- if (i > 0 )
1566
- check_ce_order (istate -> cache [i - 1 ], ce );
1567
-
1568
1572
src_offset += consumed ;
1569
1573
}
1570
1574
strbuf_release (& previous_name_buf );
@@ -1608,11 +1612,10 @@ int read_index_from(struct index_state *istate, const char *path)
1608
1612
1609
1613
ret = do_read_index (istate , path , 0 );
1610
1614
split_index = istate -> split_index ;
1611
- if (!split_index )
1612
- return ret ;
1613
-
1614
- if (is_null_sha1 (split_index -> base_sha1 ))
1615
+ if (!split_index || is_null_sha1 (split_index -> base_sha1 )) {
1616
+ check_ce_order (istate );
1615
1617
return ret ;
1618
+ }
1616
1619
1617
1620
if (split_index -> base )
1618
1621
discard_index (split_index -> base );
@@ -1628,6 +1631,7 @@ int read_index_from(struct index_state *istate, const char *path)
1628
1631
sha1_to_hex (split_index -> base_sha1 )),
1629
1632
sha1_to_hex (split_index -> base -> sha1 ));
1630
1633
merge_base_index (istate );
1634
+ check_ce_order (istate );
1631
1635
return ret ;
1632
1636
}
1633
1637
0 commit comments