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:
Junio C Hamano 2014-03-14 14:26:50 -07:00
Родитель 0963008cbf 3c09d6845d
Коммит 13b49f1e74
8 изменённых файлов: 142 добавлений и 1 удалений

Просмотреть файл

@ -1607,6 +1607,10 @@ imap::
The configuration variables in the 'imap' section are described
in linkgit:git-imap-send[1].
index.version::
Specify the version with which new index files should be
initialized. This does not affect existing repositories.
init.templatedir::
Specify the directory from which templates will be copied.
(See the "TEMPLATE DIRECTORY" section of linkgit:git-init[1].)

Просмотреть файл

@ -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

Просмотреть файл

@ -334,6 +334,10 @@ all::
# Define DEFAULT_HELP_FORMAT to "man", "info" or "html"
# (defaults to "man") if you want to have a different default when
# "git help" is called without a parameter specifying the format.
#
# Define TEST_GIT_INDEX_VERSION to 2, 3 or 4 to run the test suite
# with a different indexfile format version. If it isn't set the index
# file format used is index-v[23].
GIT-VERSION-FILE: FORCE
@$(SHELL_PATH) ./GIT-VERSION-GEN
@ -2212,6 +2216,9 @@ endif
ifdef GIT_PERF_MAKE_OPTS
@echo GIT_PERF_MAKE_OPTS=\''$(subst ','\'',$(subst ','\'',$(GIT_PERF_MAKE_OPTS)))'\' >>$@
endif
ifdef TEST_GIT_INDEX_VERSION
@echo TEST_GIT_INDEX_VERSION=\''$(subst ','\'',$(subst ','\'',$(TEST_GIT_INDEX_VERSION)))'\' >>$@
endif
### Detect Python interpreter path changes
ifndef NO_PYTHON

Просмотреть файл

@ -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)

76
t/t1600-index.sh Executable file
Просмотреть файл

@ -0,0 +1,76 @@
#!/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_expect_success 'out of bounds index.version issues warning' '
(
sane_unset GIT_INDEX_VERSION &&
rm -f .git/index &&
git config --add index.version 1 &&
git add a 2>&1 | sed "s/[0-9]//" >actual.err &&
sed -e "s/ Z$/ /" <<-\EOF >expect.err &&
warning: index.version set, but the value is invalid.
Using version Z
EOF
test_i18ncmp expect.err actual.err
)
'
test_expect_success 'GIT_INDEX_VERSION takes precedence over config' '
(
rm -f .git/index &&
GIT_INDEX_VERSION=4 &&
export GIT_INDEX_VERSION &&
git config --add index.version 2 &&
git add a 2>&1 &&
echo 4 >expect &&
test-index-version <.git/index >actual &&
test_cmp expect actual
)
'
test_done

Просмотреть файл

@ -7,6 +7,8 @@ test_description='skip-worktree bit test'
. ./test-lib.sh
test_set_index_version 3
cat >expect.full <<EOF
H 1
H 2

Просмотреть файл

@ -32,6 +32,11 @@ test_set_editor () {
export EDITOR
}
test_set_index_version () {
GIT_INDEX_VERSION="$1"
export GIT_INDEX_VERSION
}
test_decode_color () {
awk '
function name(n) {

Просмотреть файл

@ -108,6 +108,12 @@ export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME
export EDITOR
if test -n "${TEST_GIT_INDEX_VERSION:+isset}"
then
GIT_INDEX_VERSION="$TEST_GIT_INDEX_VERSION"
export GIT_INDEX_VERSION
fi
# Add libc MALLOC and MALLOC_PERTURB test
# only if we are not executing the test with valgrind
if expr " $GIT_TEST_OPTS " : ".* --valgrind " >/dev/null ||