Merge branch 'jp/index-with-corrupt-stages'
authorJunio C Hamano <gitster@pobox.com>
Fri, 19 Sep 2014 18:38:34 +0000 (11:38 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 19 Sep 2014 18:38:34 +0000 (11:38 -0700)
A broken reimplementation of Git could write an invalid index that
records both stage #0 and higher stage entries for the same path.
Notice and reject such an index, as there is no sensible fallback
(we do not know if the broken tool wanted to resolve and forgot to
remove higher stage entries, or if it wanted to unresolve and
forgot to remove the stage#0 entry).

* jp/index-with-corrupt-stages:
read_index_unmerged(): remove unnecessary loop index adjustment
read_index_from(): catch out of order entries when reading an index file

1  2 
read-cache.c
diff --cc read-cache.c
index b5917e0c0743af3c831f9571e19e269e8a1f6014,771d424b94acd1f6253efbaee44fca43de9076fa..2fc1182f2267b3e9aed799eaf7df234cd36fefb9
@@@ -1465,8 -1438,23 +1465,23 @@@ static struct cache_entry *create_from_
        return ce;
  }
  
+ static void check_ce_order(struct cache_entry *ce, struct cache_entry *next_ce)
+ {
+       int name_compare = strcmp(ce->name, next_ce->name);
+       if (0 < name_compare)
+               die("unordered stage entries in index");
+       if (!name_compare) {
+               if (!ce_stage(ce))
+                       die("multiple stage entries for merged file '%s'",
+                               ce->name);
+               if (ce_stage(ce) > ce_stage(next_ce))
+                       die("unordered stage entries for '%s'",
+                               ce->name);
+       }
+ }
  /* remember to discard_cache() before reading a different cache! */
 -int read_index_from(struct index_state *istate, const char *path)
 +int do_read_index(struct index_state *istate, const char *path, int must_exist)
  {
        int fd, i;
        struct stat st;