Skip to content

Commit 3c2af82

Browse files
committed
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 libgit2
2 parents 767e4d6 + 83708f8 commit 3c2af82

10 files changed

+59
-33
lines changed

Documentation/git-update-index.txt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,19 @@ you will need to handle the situation manually.
162162
Write the resulting index out in the named on-disk format version.
163163
Supported versions are 2, 3 and 4. The current default version is 2
164164
or 3, depending on whether extra features are used, such as
165-
`git add -N`.
165+
`git add -N`. With `--verbose`, also report the version the index
166+
file uses before and after this command.
166167
+
167168
Version 4 performs a simple pathname compression that reduces index
168169
size by 30%-50% on large repositories, which results in faster load
169-
time. Version 4 is relatively young (first released in 1.8.0 in
170-
October 2012). Other Git implementations such as JGit and libgit2
171-
may not support it yet.
170+
time. Git supports it since version 1.8.0, released in October 2012,
171+
and support for it was added to libgit2 in 2016 and to JGit in 2020.
172+
Older versions of this manual page called it "relatively young", but
173+
it should be considered mature technology these days.
174+
175+
--show-index-version::
176+
Report the index format version used by the on-disk index file.
177+
See `--index-version` above.
172178

173179
-z::
174180
Only meaningful with `--stdin` or `--index-info`; paths are

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,6 @@ TEST_BUILTINS_OBJS += test-hash-speed.o
808808
TEST_BUILTINS_OBJS += test-hash.o
809809
TEST_BUILTINS_OBJS += test-hashmap.o
810810
TEST_BUILTINS_OBJS += test-hexdump.o
811-
TEST_BUILTINS_OBJS += test-index-version.o
812811
TEST_BUILTINS_OBJS += test-json-writer.o
813812
TEST_BUILTINS_OBJS += test-lazy-init-name-hash.o
814813
TEST_BUILTINS_OBJS += test-match-trees.o

builtin/update-index.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,6 +1090,8 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
10901090
resolve_undo_clear_callback),
10911091
OPT_INTEGER(0, "index-version", &preferred_index_format,
10921092
N_("write index in this format")),
1093+
OPT_SET_INT(0, "show-index-version", &preferred_index_format,
1094+
N_("report on-disk index format version"), -1),
10931095
OPT_BOOL(0, "split-index", &split_index,
10941096
N_("enable or disable split index")),
10951097
OPT_BOOL(0, "untracked-cache", &untracked_cache,
@@ -1182,15 +1184,20 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
11821184

11831185
getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf;
11841186
if (preferred_index_format) {
1185-
if (preferred_index_format < INDEX_FORMAT_LB ||
1186-
INDEX_FORMAT_UB < preferred_index_format)
1187+
if (preferred_index_format < 0) {
1188+
printf(_("%d\n"), the_index.version);
1189+
} else if (preferred_index_format < INDEX_FORMAT_LB ||
1190+
INDEX_FORMAT_UB < preferred_index_format) {
11871191
die("index-version %d not in range: %d..%d",
11881192
preferred_index_format,
11891193
INDEX_FORMAT_LB, INDEX_FORMAT_UB);
1190-
1191-
if (the_index.version != preferred_index_format)
1192-
the_index.cache_changed |= SOMETHING_CHANGED;
1193-
the_index.version = preferred_index_format;
1194+
} else {
1195+
if (the_index.version != preferred_index_format)
1196+
the_index.cache_changed |= SOMETHING_CHANGED;
1197+
report(_("index-version: was %d, set to %d"),
1198+
the_index.version, preferred_index_format);
1199+
the_index.version = preferred_index_format;
1200+
}
11941201
}
11951202

11961203
if (read_from_stdin) {

t/helper/test-index-version.c

Lines changed: 0 additions & 15 deletions
This file was deleted.

t/helper/test-tool.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ static struct test_cmd cmds[] = {
3838
{ "hashmap", cmd__hashmap },
3939
{ "hash-speed", cmd__hash_speed },
4040
{ "hexdump", cmd__hexdump },
41-
{ "index-version", cmd__index_version },
4241
{ "json-writer", cmd__json_writer },
4342
{ "lazy-init-name-hash", cmd__lazy_init_name_hash },
4443
{ "match-trees", cmd__match_trees },

t/helper/test-tool.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ int cmd__getcwd(int argc, const char **argv);
3232
int cmd__hashmap(int argc, const char **argv);
3333
int cmd__hash_speed(int argc, const char **argv);
3434
int cmd__hexdump(int argc, const char **argv);
35-
int cmd__index_version(int argc, const char **argv);
3635
int cmd__json_writer(int argc, const char **argv);
3736
int cmd__lazy_init_name_hash(int argc, const char **argv);
3837
int cmd__match_trees(int argc, const char **argv);

t/t1600-index.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ test_index_version () {
118118
fi &&
119119
git add a &&
120120
echo $EXPECTED_OUTPUT_VERSION >expect &&
121-
test-tool index-version <.git/index >actual &&
121+
git update-index --show-index-version >actual &&
122122
test_cmp expect actual
123123
)
124124
}

t/t1700-split-index.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ test_expect_success 'enable split index' '
4343
git config splitIndex.maxPercentChange 100 &&
4444
git update-index --split-index &&
4545
test-tool dump-split-index .git/index >actual &&
46-
indexversion=$(test-tool index-version <.git/index) &&
46+
indexversion=$(git update-index --show-index-version) &&
4747
4848
# NEEDSWORK: Stop hard-coding checksums.
4949
if test "$indexversion" = "4"

t/t2104-update-index-skip-worktree.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ test_expect_success 'setup' '
3939
'
4040

4141
test_expect_success 'index is at version 2' '
42-
test "$(test-tool index-version < .git/index)" = 2
42+
test "$(git update-index --show-index-version)" = 2
4343
'
4444

4545
test_expect_success 'update-index --skip-worktree' '
@@ -48,7 +48,7 @@ test_expect_success 'update-index --skip-worktree' '
4848
'
4949

5050
test_expect_success 'index is at version 3 after having some skip-worktree entries' '
51-
test "$(test-tool index-version < .git/index)" = 3
51+
test "$(git update-index --show-index-version)" = 3
5252
'
5353

5454
test_expect_success 'ls-files -t' '
@@ -61,7 +61,7 @@ test_expect_success 'update-index --no-skip-worktree' '
6161
'
6262

6363
test_expect_success 'index version is back to 2 when there is no skip-worktree entry' '
64-
test "$(test-tool index-version < .git/index)" = 2
64+
test "$(git update-index --show-index-version)" = 2
6565
'
6666

6767
test_done

t/t2107-update-index-basic.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,35 @@ test_expect_success '--chmod=+x and chmod=-x in the same argument list' '
111111
test_cmp expect actual
112112
'
113113

114+
test_expect_success '--index-version' '
115+
git commit --allow-empty -m snap &&
116+
git reset --hard &&
117+
git rm -f -r --cached . &&
118+
119+
# The default index version is 2 --- update this test
120+
# when you change it in the code
121+
git update-index --show-index-version >actual &&
122+
echo 2 >expect &&
123+
test_cmp expect actual &&
124+
125+
# The next test wants us to be using version 2
126+
git update-index --index-version 2 &&
127+
128+
git update-index --index-version 4 --verbose >actual &&
129+
echo "index-version: was 2, set to 4" >expect &&
130+
test_cmp expect actual &&
131+
132+
git update-index --index-version 4 --verbose >actual &&
133+
echo "index-version: was 4, set to 4" >expect &&
134+
test_cmp expect actual &&
135+
136+
git update-index --index-version 2 --verbose >actual &&
137+
echo "index-version: was 4, set to 2" >expect &&
138+
test_cmp expect actual &&
139+
140+
# non-verbose should be silent
141+
git update-index --index-version 4 >actual &&
142+
test_must_be_empty actual
143+
'
144+
114145
test_done

0 commit comments

Comments
 (0)