Merge branch 'tg/fix-check-order-with-split-index' into maint

The split-index mode introduced at v2.3.0-rc0~41 was broken in the
codepath to protect us against a broken reimplementation of Git
that writes an invalid index with duplicated index entries, etc.

* tg/fix-check-order-with-split-index:
  read-cache: fix reading of split index
This commit is contained in:
Junio C Hamano
2015-03-28 09:33:07 -07:00

View File

@ -1486,9 +1486,15 @@ static struct cache_entry *create_from_disk(struct ondisk_cache_entry *ondisk,
return ce; return ce;
} }
static void check_ce_order(struct cache_entry *ce, struct cache_entry *next_ce) static void check_ce_order(struct index_state *istate)
{ {
unsigned int i;
for (i = 1; i < istate->cache_nr; i++) {
struct cache_entry *ce = istate->cache[i - 1];
struct cache_entry *next_ce = istate->cache[i];
int name_compare = strcmp(ce->name, next_ce->name); int name_compare = strcmp(ce->name, next_ce->name);
if (0 < name_compare) if (0 < name_compare)
die("unordered stage entries in index"); die("unordered stage entries in index");
if (!name_compare) { if (!name_compare) {
@ -1500,6 +1506,7 @@ static void check_ce_order(struct cache_entry *ce, struct cache_entry *next_ce)
ce->name); ce->name);
} }
} }
}
/* remember to discard_cache() before reading a different cache! */ /* remember to discard_cache() before reading a different cache! */
int do_read_index(struct index_state *istate, const char *path, int must_exist) int do_read_index(struct index_state *istate, const char *path, int must_exist)
@ -1562,9 +1569,6 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
ce = create_from_disk(disk_ce, &consumed, previous_name); ce = create_from_disk(disk_ce, &consumed, previous_name);
set_index_entry(istate, i, ce); set_index_entry(istate, i, ce);
if (i > 0)
check_ce_order(istate->cache[i - 1], ce);
src_offset += consumed; src_offset += consumed;
} }
strbuf_release(&previous_name_buf); strbuf_release(&previous_name_buf);
@ -1608,11 +1612,10 @@ int read_index_from(struct index_state *istate, const char *path)
ret = do_read_index(istate, path, 0); ret = do_read_index(istate, path, 0);
split_index = istate->split_index; split_index = istate->split_index;
if (!split_index) if (!split_index || is_null_sha1(split_index->base_sha1)) {
return ret; check_ce_order(istate);
if (is_null_sha1(split_index->base_sha1))
return ret; return ret;
}
if (split_index->base) if (split_index->base)
discard_index(split_index->base); discard_index(split_index->base);
@ -1628,6 +1631,7 @@ int read_index_from(struct index_state *istate, const char *path)
sha1_to_hex(split_index->base_sha1)), sha1_to_hex(split_index->base_sha1)),
sha1_to_hex(split_index->base->sha1)); sha1_to_hex(split_index->base->sha1));
merge_base_index(istate); merge_base_index(istate);
check_ce_order(istate);
return ret; return ret;
} }