summaryrefslogtreecommitdiff
path: root/read-cache.c
diff options
context:
space:
mode:
Diffstat (limited to 'read-cache.c')
-rw-r--r--read-cache.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/read-cache.c b/read-cache.c
index 33dd676ccb..efc4aaed98 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -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)