@@ -1486,18 +1486,25 @@ static struct cache_entry *create_from_disk(struct ondisk_cache_entry *ondisk,
14861486 return ce ;
14871487}
14881488
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+ }
15011508 }
15021509}
15031510
@@ -1562,9 +1569,6 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
15621569 ce = create_from_disk (disk_ce , & consumed , previous_name );
15631570 set_index_entry (istate , i , ce );
15641571
1565- if (i > 0 )
1566- check_ce_order (istate -> cache [i - 1 ], ce );
1567-
15681572 src_offset += consumed ;
15691573 }
15701574 strbuf_release (& previous_name_buf );
@@ -1608,11 +1612,10 @@ int read_index_from(struct index_state *istate, const char *path)
16081612
16091613 ret = do_read_index (istate , path , 0 );
16101614 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 );
16151617 return ret ;
1618+ }
16161619
16171620 if (split_index -> base )
16181621 discard_index (split_index -> base );
@@ -1628,6 +1631,7 @@ int read_index_from(struct index_state *istate, const char *path)
16281631 sha1_to_hex (split_index -> base_sha1 )),
16291632 sha1_to_hex (split_index -> base -> sha1 ));
16301633 merge_base_index (istate );
1634+ check_ce_order (istate );
16311635 return ret ;
16321636}
16331637
0 commit comments