From 136347d718320c56030e3b7a3437259e99c4c41b Mon Sep 17 00:00:00 2001 From: Thomas Gummerer Date: Sun, 23 Feb 2014 21:49:57 +0100 Subject: 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 Signed-off-by: Thomas Gummerer Signed-off-by: Junio C Hamano --- read-cache.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'read-cache.c') diff --git a/read-cache.c b/read-cache.c index 33dd676cc..efc4aaed9 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) -- cgit v1.2.1 From 3c09d6845d253f9d8a75f3a36278c69e01b073e9 Mon Sep 17 00:00:00 2001 From: Thomas Gummerer Date: Sun, 23 Feb 2014 21:49:59 +0100 Subject: read-cache: add index.version config variable Add a config variable that allows setting the default index version when initializing a new index file. Similar to the GIT_INDEX_VERSION environment variable this only affects new index files. Signed-off-by: Thomas Gummerer Signed-off-by: Junio C Hamano --- read-cache.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'read-cache.c') diff --git a/read-cache.c b/read-cache.c index efc4aaed9..6bc972479 100644 --- a/read-cache.c +++ b/read-cache.c @@ -1219,23 +1219,40 @@ static struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int reall #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"); - if (!envversion) { - return INDEX_FORMAT_DEFAULT; - } else { - char *endp; - unsigned int version = strtoul(envversion, &endp, 10); + char *endp; + unsigned int version = INDEX_FORMAT_DEFAULT; - if (*endp || - version < INDEX_FORMAT_LB || INDEX_FORMAT_UB < version) { - warning(_("GIT_INDEX_VERSION set, but the value is invalid.\n" + 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); - version = 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; } /* -- cgit v1.2.1