зеркало из https://github.com/microsoft/git.git
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>
This commit is contained in:
Родитель
5f95c9f850
Коммит
136347d718
|
@ -720,6 +720,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 [23] is used.
|
||||
|
||||
'GIT_OBJECT_DIRECTORY'::
|
||||
If the object storage directory is specified via this
|
||||
environment variable then the sha1 directories are created
|
||||
|
|
21
read-cache.c
21
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)
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
#!/bin/sh
|
||||
|
||||
test_description='index file specific tests'
|
||||
|
||||
. ./test-lib.sh
|
||||
|
||||
test_expect_success 'setup' '
|
||||
echo 1 >a
|
||||
'
|
||||
|
||||
test_expect_success 'bogus GIT_INDEX_VERSION issues warning' '
|
||||
(
|
||||
rm -f .git/index &&
|
||||
GIT_INDEX_VERSION=2bogus &&
|
||||
export GIT_INDEX_VERSION &&
|
||||
git add a 2>&1 | sed "s/[0-9]//" >actual.err &&
|
||||
sed -e "s/ Z$/ /" <<-\EOF >expect.err &&
|
||||
warning: GIT_INDEX_VERSION set, but the value is invalid.
|
||||
Using version Z
|
||||
EOF
|
||||
test_i18ncmp expect.err actual.err
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success 'out of bounds GIT_INDEX_VERSION issues warning' '
|
||||
(
|
||||
rm -f .git/index &&
|
||||
GIT_INDEX_VERSION=1 &&
|
||||
export GIT_INDEX_VERSION &&
|
||||
git add a 2>&1 | sed "s/[0-9]//" >actual.err &&
|
||||
sed -e "s/ Z$/ /" <<-\EOF >expect.err &&
|
||||
warning: GIT_INDEX_VERSION set, but the value is invalid.
|
||||
Using version Z
|
||||
EOF
|
||||
test_i18ncmp expect.err actual.err
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success 'no warning with bogus GIT_INDEX_VERSION and existing index' '
|
||||
(
|
||||
GIT_INDEX_VERSION=1 &&
|
||||
export GIT_INDEX_VERSION &&
|
||||
git add a 2>actual.err &&
|
||||
>expect.err &&
|
||||
test_i18ncmp expect.err actual.err
|
||||
)
|
||||
'
|
||||
|
||||
test_done
|
Загрузка…
Ссылка в новой задаче