@@ -1220,6 +1220,42 @@ static struct cache_entry *refresh_cache_entry(struct cache_entry *ce,
12201220
12211221#define INDEX_FORMAT_DEFAULT 3
12221222
1223+ static int index_format_config (const char * var , const char * value , void * cb )
1224+ {
1225+ unsigned int * version = cb ;
1226+ if (!strcmp (var , "index.version" )) {
1227+ * version = git_config_int (var , value );
1228+ return 0 ;
1229+ }
1230+ return 1 ;
1231+ }
1232+
1233+ static unsigned int get_index_format_default (void )
1234+ {
1235+ char * envversion = getenv ("GIT_INDEX_VERSION" );
1236+ char * endp ;
1237+ unsigned int version = INDEX_FORMAT_DEFAULT ;
1238+
1239+ if (!envversion ) {
1240+ git_config (index_format_config , & version );
1241+ if (version < INDEX_FORMAT_LB || INDEX_FORMAT_UB < version ) {
1242+ warning (_ ("index.version set, but the value is invalid.\n"
1243+ "Using version %i" ), INDEX_FORMAT_DEFAULT );
1244+ return INDEX_FORMAT_DEFAULT ;
1245+ }
1246+ return version ;
1247+ }
1248+
1249+ version = strtoul (envversion , & endp , 10 );
1250+ if (* endp ||
1251+ version < INDEX_FORMAT_LB || INDEX_FORMAT_UB < version ) {
1252+ warning (_ ("GIT_INDEX_VERSION set, but the value is invalid.\n"
1253+ "Using version %i" ), INDEX_FORMAT_DEFAULT );
1254+ version = INDEX_FORMAT_DEFAULT ;
1255+ }
1256+ return version ;
1257+ }
1258+
12231259/*
12241260 * dev/ino/uid/gid/size are also just tracked to the low 32 bits
12251261 * Again - this is just a (very strong in practice) heuristic that
@@ -1776,7 +1812,7 @@ int write_index(struct index_state *istate, int newfd)
17761812 }
17771813
17781814 if (!istate -> version )
1779- istate -> version = INDEX_FORMAT_DEFAULT ;
1815+ istate -> version = get_index_format_default () ;
17801816
17811817 /* demote version 3 to version 2 when the latter suffices */
17821818 if (istate -> version == 3 || istate -> version == 2 )
0 commit comments