Merge branch 'jc/update-index-show-index-version'
"git update-index" learns "--show-index-version" to inspect the index format version used by the on-disk index file. * jc/update-index-show-index-version: test-tool: retire "index-version" update-index: add --show-index-version update-index doc: v4 is OK with JGit and libgit2maint
commit
3c2af826a3
|
@ -162,13 +162,19 @@ you will need to handle the situation manually.
|
||||||
Write the resulting index out in the named on-disk format version.
|
Write the resulting index out in the named on-disk format version.
|
||||||
Supported versions are 2, 3 and 4. The current default version is 2
|
Supported versions are 2, 3 and 4. The current default version is 2
|
||||||
or 3, depending on whether extra features are used, such as
|
or 3, depending on whether extra features are used, such as
|
||||||
`git add -N`.
|
`git add -N`. With `--verbose`, also report the version the index
|
||||||
|
file uses before and after this command.
|
||||||
+
|
+
|
||||||
Version 4 performs a simple pathname compression that reduces index
|
Version 4 performs a simple pathname compression that reduces index
|
||||||
size by 30%-50% on large repositories, which results in faster load
|
size by 30%-50% on large repositories, which results in faster load
|
||||||
time. Version 4 is relatively young (first released in 1.8.0 in
|
time. Git supports it since version 1.8.0, released in October 2012,
|
||||||
October 2012). Other Git implementations such as JGit and libgit2
|
and support for it was added to libgit2 in 2016 and to JGit in 2020.
|
||||||
may not support it yet.
|
Older versions of this manual page called it "relatively young", but
|
||||||
|
it should be considered mature technology these days.
|
||||||
|
|
||||||
|
--show-index-version::
|
||||||
|
Report the index format version used by the on-disk index file.
|
||||||
|
See `--index-version` above.
|
||||||
|
|
||||||
-z::
|
-z::
|
||||||
Only meaningful with `--stdin` or `--index-info`; paths are
|
Only meaningful with `--stdin` or `--index-info`; paths are
|
||||||
|
|
1
Makefile
1
Makefile
|
@ -808,7 +808,6 @@ TEST_BUILTINS_OBJS += test-hash-speed.o
|
||||||
TEST_BUILTINS_OBJS += test-hash.o
|
TEST_BUILTINS_OBJS += test-hash.o
|
||||||
TEST_BUILTINS_OBJS += test-hashmap.o
|
TEST_BUILTINS_OBJS += test-hashmap.o
|
||||||
TEST_BUILTINS_OBJS += test-hexdump.o
|
TEST_BUILTINS_OBJS += test-hexdump.o
|
||||||
TEST_BUILTINS_OBJS += test-index-version.o
|
|
||||||
TEST_BUILTINS_OBJS += test-json-writer.o
|
TEST_BUILTINS_OBJS += test-json-writer.o
|
||||||
TEST_BUILTINS_OBJS += test-lazy-init-name-hash.o
|
TEST_BUILTINS_OBJS += test-lazy-init-name-hash.o
|
||||||
TEST_BUILTINS_OBJS += test-match-trees.o
|
TEST_BUILTINS_OBJS += test-match-trees.o
|
||||||
|
|
|
@ -1090,6 +1090,8 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
|
||||||
resolve_undo_clear_callback),
|
resolve_undo_clear_callback),
|
||||||
OPT_INTEGER(0, "index-version", &preferred_index_format,
|
OPT_INTEGER(0, "index-version", &preferred_index_format,
|
||||||
N_("write index in this format")),
|
N_("write index in this format")),
|
||||||
|
OPT_SET_INT(0, "show-index-version", &preferred_index_format,
|
||||||
|
N_("report on-disk index format version"), -1),
|
||||||
OPT_BOOL(0, "split-index", &split_index,
|
OPT_BOOL(0, "split-index", &split_index,
|
||||||
N_("enable or disable split index")),
|
N_("enable or disable split index")),
|
||||||
OPT_BOOL(0, "untracked-cache", &untracked_cache,
|
OPT_BOOL(0, "untracked-cache", &untracked_cache,
|
||||||
|
@ -1182,15 +1184,20 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
|
||||||
|
|
||||||
getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf;
|
getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf;
|
||||||
if (preferred_index_format) {
|
if (preferred_index_format) {
|
||||||
if (preferred_index_format < INDEX_FORMAT_LB ||
|
if (preferred_index_format < 0) {
|
||||||
INDEX_FORMAT_UB < preferred_index_format)
|
printf(_("%d\n"), the_index.version);
|
||||||
|
} else if (preferred_index_format < INDEX_FORMAT_LB ||
|
||||||
|
INDEX_FORMAT_UB < preferred_index_format) {
|
||||||
die("index-version %d not in range: %d..%d",
|
die("index-version %d not in range: %d..%d",
|
||||||
preferred_index_format,
|
preferred_index_format,
|
||||||
INDEX_FORMAT_LB, INDEX_FORMAT_UB);
|
INDEX_FORMAT_LB, INDEX_FORMAT_UB);
|
||||||
|
} else {
|
||||||
if (the_index.version != preferred_index_format)
|
if (the_index.version != preferred_index_format)
|
||||||
the_index.cache_changed |= SOMETHING_CHANGED;
|
the_index.cache_changed |= SOMETHING_CHANGED;
|
||||||
the_index.version = preferred_index_format;
|
report(_("index-version: was %d, set to %d"),
|
||||||
|
the_index.version, preferred_index_format);
|
||||||
|
the_index.version = preferred_index_format;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (read_from_stdin) {
|
if (read_from_stdin) {
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
#include "test-tool.h"
|
|
||||||
#include "read-cache-ll.h"
|
|
||||||
|
|
||||||
int cmd__index_version(int argc UNUSED, const char **argv UNUSED)
|
|
||||||
{
|
|
||||||
struct cache_header hdr;
|
|
||||||
int version;
|
|
||||||
|
|
||||||
memset(&hdr,0,sizeof(hdr));
|
|
||||||
if (read(0, &hdr, sizeof(hdr)) != sizeof(hdr))
|
|
||||||
return 0;
|
|
||||||
version = ntohl(hdr.hdr_version);
|
|
||||||
printf("%d\n", version);
|
|
||||||
return 0;
|
|
||||||
}
|
|
|
@ -38,7 +38,6 @@ static struct test_cmd cmds[] = {
|
||||||
{ "hashmap", cmd__hashmap },
|
{ "hashmap", cmd__hashmap },
|
||||||
{ "hash-speed", cmd__hash_speed },
|
{ "hash-speed", cmd__hash_speed },
|
||||||
{ "hexdump", cmd__hexdump },
|
{ "hexdump", cmd__hexdump },
|
||||||
{ "index-version", cmd__index_version },
|
|
||||||
{ "json-writer", cmd__json_writer },
|
{ "json-writer", cmd__json_writer },
|
||||||
{ "lazy-init-name-hash", cmd__lazy_init_name_hash },
|
{ "lazy-init-name-hash", cmd__lazy_init_name_hash },
|
||||||
{ "match-trees", cmd__match_trees },
|
{ "match-trees", cmd__match_trees },
|
||||||
|
|
|
@ -32,7 +32,6 @@ int cmd__getcwd(int argc, const char **argv);
|
||||||
int cmd__hashmap(int argc, const char **argv);
|
int cmd__hashmap(int argc, const char **argv);
|
||||||
int cmd__hash_speed(int argc, const char **argv);
|
int cmd__hash_speed(int argc, const char **argv);
|
||||||
int cmd__hexdump(int argc, const char **argv);
|
int cmd__hexdump(int argc, const char **argv);
|
||||||
int cmd__index_version(int argc, const char **argv);
|
|
||||||
int cmd__json_writer(int argc, const char **argv);
|
int cmd__json_writer(int argc, const char **argv);
|
||||||
int cmd__lazy_init_name_hash(int argc, const char **argv);
|
int cmd__lazy_init_name_hash(int argc, const char **argv);
|
||||||
int cmd__match_trees(int argc, const char **argv);
|
int cmd__match_trees(int argc, const char **argv);
|
||||||
|
|
|
@ -118,7 +118,7 @@ test_index_version () {
|
||||||
fi &&
|
fi &&
|
||||||
git add a &&
|
git add a &&
|
||||||
echo $EXPECTED_OUTPUT_VERSION >expect &&
|
echo $EXPECTED_OUTPUT_VERSION >expect &&
|
||||||
test-tool index-version <.git/index >actual &&
|
git update-index --show-index-version >actual &&
|
||||||
test_cmp expect actual
|
test_cmp expect actual
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ test_expect_success 'enable split index' '
|
||||||
git config splitIndex.maxPercentChange 100 &&
|
git config splitIndex.maxPercentChange 100 &&
|
||||||
git update-index --split-index &&
|
git update-index --split-index &&
|
||||||
test-tool dump-split-index .git/index >actual &&
|
test-tool dump-split-index .git/index >actual &&
|
||||||
indexversion=$(test-tool index-version <.git/index) &&
|
indexversion=$(git update-index --show-index-version) &&
|
||||||
|
|
||||||
# NEEDSWORK: Stop hard-coding checksums.
|
# NEEDSWORK: Stop hard-coding checksums.
|
||||||
if test "$indexversion" = "4"
|
if test "$indexversion" = "4"
|
||||||
|
|
|
@ -39,7 +39,7 @@ test_expect_success 'setup' '
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'index is at version 2' '
|
test_expect_success 'index is at version 2' '
|
||||||
test "$(test-tool index-version < .git/index)" = 2
|
test "$(git update-index --show-index-version)" = 2
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'update-index --skip-worktree' '
|
test_expect_success 'update-index --skip-worktree' '
|
||||||
|
@ -48,7 +48,7 @@ test_expect_success 'update-index --skip-worktree' '
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'index is at version 3 after having some skip-worktree entries' '
|
test_expect_success 'index is at version 3 after having some skip-worktree entries' '
|
||||||
test "$(test-tool index-version < .git/index)" = 3
|
test "$(git update-index --show-index-version)" = 3
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'ls-files -t' '
|
test_expect_success 'ls-files -t' '
|
||||||
|
@ -61,7 +61,7 @@ test_expect_success 'update-index --no-skip-worktree' '
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'index version is back to 2 when there is no skip-worktree entry' '
|
test_expect_success 'index version is back to 2 when there is no skip-worktree entry' '
|
||||||
test "$(test-tool index-version < .git/index)" = 2
|
test "$(git update-index --show-index-version)" = 2
|
||||||
'
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|
|
@ -111,4 +111,35 @@ test_expect_success '--chmod=+x and chmod=-x in the same argument list' '
|
||||||
test_cmp expect actual
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success '--index-version' '
|
||||||
|
git commit --allow-empty -m snap &&
|
||||||
|
git reset --hard &&
|
||||||
|
git rm -f -r --cached . &&
|
||||||
|
|
||||||
|
# The default index version is 2 --- update this test
|
||||||
|
# when you change it in the code
|
||||||
|
git update-index --show-index-version >actual &&
|
||||||
|
echo 2 >expect &&
|
||||||
|
test_cmp expect actual &&
|
||||||
|
|
||||||
|
# The next test wants us to be using version 2
|
||||||
|
git update-index --index-version 2 &&
|
||||||
|
|
||||||
|
git update-index --index-version 4 --verbose >actual &&
|
||||||
|
echo "index-version: was 2, set to 4" >expect &&
|
||||||
|
test_cmp expect actual &&
|
||||||
|
|
||||||
|
git update-index --index-version 4 --verbose >actual &&
|
||||||
|
echo "index-version: was 4, set to 4" >expect &&
|
||||||
|
test_cmp expect actual &&
|
||||||
|
|
||||||
|
git update-index --index-version 2 --verbose >actual &&
|
||||||
|
echo "index-version: was 4, set to 2" >expect &&
|
||||||
|
test_cmp expect actual &&
|
||||||
|
|
||||||
|
# non-verbose should be silent
|
||||||
|
git update-index --index-version 4 >actual &&
|
||||||
|
test_must_be_empty actual
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|
Loading…
Reference in New Issue