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 for additional safety.

Signed-off-by: Thomas Gummerer <t.gumme...@gmail.com>
---
 Documentation/git.txt | 5 +++++
 read-cache.c          | 9 +++++++--
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/Documentation/git.txt b/Documentation/git.txt
index 10cddb5..2b2aad5 100644
--- a/Documentation/git.txt
+++ b/Documentation/git.txt
@@ -703,6 +703,11 @@ Git so take care if using Cogito etc.
        index file. If not specified, the default of `$GIT_DIR/index`
        is used.
 
+'GIT_INDEX_VERSION'::
+       This environment variable allows the specification of an index
+       version for new repositories.  It won't affect existing index
+       files.  By default index file version 3 is used.
+
 'GIT_OBJECT_DIRECTORY'::
        If the object storage directory is specified via this
        environment variable then the sha1 directories are created
diff --git a/read-cache.c b/read-cache.c
index 46551af..04430e5 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1233,8 +1233,13 @@ static struct cache_entry *refresh_cache_entry(struct 
cache_entry *ce, int reall
 void initialize_index(struct index_state *istate, int version)
 {
        istate->initialized = 1;
-       if (!version)
-               version = INDEX_FORMAT_DEFAULT;
+       if (!version) {
+               char *envversion = getenv("GIT_INDEX_VERSION");
+               if (!envversion)
+                       version = INDEX_FORMAT_DEFAULT;
+               else
+                       version = atoi(envversion);
+       }
        istate->version = version;
        set_istate_ops(istate);
 }
-- 
1.8.4.2

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to