index-pack: fix compilation with NO_PTHREADS
[gitweb.git] / read-cache.c
index 6f0057fe66a59e1239703ee4458de200304f727a..2fc1182f2267b3e9aed799eaf7df234cd36fefb9 100644 (file)
@@ -1246,24 +1246,16 @@ static struct cache_entry *refresh_cache_entry(struct cache_entry *ce,
 
 #define INDEX_FORMAT_DEFAULT 3
 
-static int index_format_config(const char *var, const char *value, void *cb)
-{
-       unsigned int *version = cb;
-       if (!strcmp(var, "index.version")) {
-               *version = git_config_int(var, value);
-               return 0;
-       }
-       return 1;
-}
-
 static unsigned int get_index_format_default(void)
 {
        char *envversion = getenv("GIT_INDEX_VERSION");
        char *endp;
+       int value;
        unsigned int version = INDEX_FORMAT_DEFAULT;
 
        if (!envversion) {
-               git_config(index_format_config, &version);
+               if (!git_config_get_int("index.version", &value))
+                       version = value;
                if (version < INDEX_FORMAT_LB || INDEX_FORMAT_UB < version) {
                        warning(_("index.version set, but the value is invalid.\n"
                                  "Using version %i"), INDEX_FORMAT_DEFAULT);
@@ -1473,6 +1465,21 @@ static struct cache_entry *create_from_disk(struct ondisk_cache_entry *ondisk,
        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 do_read_index(struct index_state *istate, const char *path, int must_exist)
 {
@@ -1534,6 +1541,9 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
                ce = create_from_disk(disk_ce, &consumed, previous_name);
                set_index_entry(istate, i, ce);
 
+               if (i > 0)
+                       check_ce_order(istate->cache[i - 1], ce);
+
                src_offset += consumed;
        }
        strbuf_release(&previous_name_buf);
@@ -2180,7 +2190,6 @@ int read_index_unmerged(struct index_state *istate)
                if (add_index_entry(istate, new_ce, 0))
                        return error("%s: cannot drop to stage #0",
                                     new_ce->name);
-               i = index_name_pos(istate, new_ce->name, len);
        }
        return unmerged;
 }