introduce GIT_INDEX_VERSION environment variable
[gitweb.git] / read-cache.c
index 33dd676ccbbd24e0bace49347f1f5d81b5099bcc..efc4aaed98af84a4f1cffb87416f0730b73bbaef 100644 (file)
@@ -1219,6 +1219,25 @@ static struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int reall
 
 #define INDEX_FORMAT_DEFAULT 3
 
+static unsigned int get_index_format_default(void)
+{
+       char *envversion = getenv("GIT_INDEX_VERSION");
+       if (!envversion) {
+               return INDEX_FORMAT_DEFAULT;
+       } else {
+               char *endp;
+               unsigned int version = strtoul(envversion, &endp, 10);
+
+               if (*endp ||
+                   version < INDEX_FORMAT_LB || INDEX_FORMAT_UB < version) {
+                       warning(_("GIT_INDEX_VERSION set, but the value is invalid.\n"
+                                 "Using version %i"), INDEX_FORMAT_DEFAULT);
+                       version = INDEX_FORMAT_DEFAULT;
+               }
+               return version;
+       }
+}
+
 /*
  * dev/ino/uid/gid/size are also just tracked to the low 32 bits
  * Again - this is just a (very strong in practice) heuristic that
@@ -1795,7 +1814,7 @@ int write_index(struct index_state *istate, int newfd)
        }
 
        if (!istate->version)
-               istate->version = INDEX_FORMAT_DEFAULT;
+               istate->version = get_index_format_default();
 
        /* demote version 3 to version 2 when the latter suffices */
        if (istate->version == 3 || istate->version == 2)