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
This commit is contained in:
38
read-cache.c
38
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)
|
||||
|
Reference in New Issue
Block a user