summaryrefslogtreecommitdiff
path: root/read-cache.c
diff options
context:
space:
mode:
authorThomas Gummerer <t.gummerer@gmail.com>2014-02-23 20:49:57 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-02-24 17:48:40 (GMT)
commit136347d718320c56030e3b7a3437259e99c4c41b (patch)
tree269f8c0287bef262d7751e0913dfaedadf9b6e34 /read-cache.c
parent5f95c9f850b19b368c43ae399cc831b17a26a5ac (diff)
downloadgit-136347d718320c56030e3b7a3437259e99c4c41b.zip
git-136347d718320c56030e3b7a3437259e99c4c41b.tar.gz
git-136347d718320c56030e3b7a3437259e99c4c41b.tar.bz2
introduce GIT_INDEX_VERSION environment variable
Respect a GIT_INDEX_VERSION environment variable, when a new index is initialized. Setting the environment variable will not cause existing index files to be converted to another format, but will only affect newly written index files. This can be used to initialize repositories with index-v4. Helped-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
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 33dd676..efc4aae 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)