summaryrefslogtreecommitdiff
path: root/read-cache.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2014-03-14 14:26:50 -0700
committerJunio C Hamano <gitster@pobox.com>2014-03-14 14:26:50 -0700
commit13b49f1e7463c46272c0b3b9b1952dc519086b6d (patch)
tree3d0f6d4dcf53afc524eac847f4a12204d134cbe3 /read-cache.c
parent0963008cbf266db8001521c87084cea353005020 (diff)
parent3c09d6845d253f9d8a75f3a36278c69e01b073e9 (diff)
downloadgit-13b49f1e7463c46272c0b3b9b1952dc519086b6d.tar.gz
Merge branch 'tg/index-v4-format'
* tg/index-v4-format: read-cache: add index.version config variable test-lib: allow setting the index format version introduce GIT_INDEX_VERSION environment variable
Diffstat (limited to 'read-cache.c')
-rw-r--r--read-cache.c38
1 files changed, 37 insertions, 1 deletions
diff --git a/read-cache.c b/read-cache.c
index fb440b4d9d..f23c44a81a 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1220,6 +1220,42 @@ 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;
+ unsigned int version = INDEX_FORMAT_DEFAULT;
+
+ if (!envversion) {
+ git_config(index_format_config, &version);
+ 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);
+ return INDEX_FORMAT_DEFAULT;
+ }
+ return version;
+ }
+
+ 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
@@ -1776,7 +1812,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)