{"thread":{"id":"60127","subject":"[PATCH v2 0/3] \"update-index --show-index-version\"","startedAt":"2023-08-18T23:38:27Z","lastAt":"2023-11-14T02:55:35Z","messageCount":17,"participants":["Junio C Hamano","Linus Arver","Teng Long"],"isPatch":true,"patchVersion":2,"patchTotal":3},"messages":[{"id":"480794","messageId":"20230818233729.2766281-1-gitster@pobox.com","threadId":"60127","inReplyTo":null,"subject":"[PATCH v2 0/3] \"update-index --show-index-version\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-08-18T23:37:26Z","receivedAt":"2023-08-18T23:38:27Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Even though there is \"test-tool index-version\", there wasn't an\nofficially supported way for end-users to inspect the index version\nof an on-disk index.  Let's have one.\n\nJunio C Hamano (3):\n  update-index doc: v4 is OK with JGit and libgit2\n  update-index: add --show-index-version\n  test-tool: retire \"index-version\"\n\n Documentation/git-update-index.txt    | 14 ++++++++++----\n Makefile                              |  1 -\n builtin/update-index.c                | 19 +++++++++++++------\n t/helper/test-index-version.c         | 15 ---------------\n t/helper/test-tool.c                  |  1 -\n t/helper/test-tool.h                  |  1 -\n t/t1600-index.sh                      |  2 +-\n t/t1700-split-index.sh                |  2 +-\n t/t2104-update-index-skip-worktree.sh |  6 +++---\n t/t2107-update-index-basic.sh         | 16 ++++++++++++++++\n 10 files changed, 44 insertions(+), 33 deletions(-)\n delete mode 100644 t/helper/test-index-version.c\n\n-- \n2.42.0-rc2-7-gf9972720e9\n\n"},{"id":"480795","messageId":"20230818233729.2766281-2-gitster@pobox.com","threadId":"60127","inReplyTo":"20230818233729.2766281-1-gitster@pobox.com","subject":"[PATCH v2 1/3] update-index doc: v4 is OK with JGit and libgit2","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-08-18T23:37:27Z","receivedAt":"2023-08-18T23:38:27Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Being invented in late 2012 no longer makes the index v4 format\n\"relatively young\".\n\nThe support for the index version 4 was added to libgit2 with their\n5625d86b (index: support index v4, 2016-05-17) and to JGit with\ntheir e9cb0a8e (DirCache: support index V4, 2020-08-10).\n\nLet's update the paragraph that discouraged its use for folks overly\ncautious about cross-tool compatibility.\n\nHelped-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n Documentation/git-update-index.txt | 8 +++++---\n 1 file changed, 5 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/git-update-index.txt b/Documentation/git-update-index.txt\nindex f4bb9c5daf..a367f8d65a 100644\n--- a/Documentation/git-update-index.txt\n+++ b/Documentation/git-update-index.txt\n@@ -166,9 +166,11 @@ you will need to handle the situation manually.\n +\n Version 4 performs a simple pathname compression that reduces index\n size by 30%-50% on large repositories, which results in faster load\n-time. Version 4 is relatively young (first released in 1.8.0 in\n-October 2012). Other Git implementations such as JGit and libgit2\n-may not support it yet.\n+time.  Git supports it since version 1.8.0, released in October 2012,\n+and support for it was added to libgit2 in 2016 and to JGit in 2020.\n+Older editions of this manual page called it \"relatively young\", but\n+it should be considered mature technology these days.\n+\n \n -z::\n \tOnly meaningful with `--stdin` or `--index-info`; paths are\n-- \n2.42.0-rc2-7-gf9972720e9\n\n"},{"id":"480796","messageId":"20230818233729.2766281-3-gitster@pobox.com","threadId":"60127","inReplyTo":"20230818233729.2766281-1-gitster@pobox.com","subject":"[PATCH v2 2/3] update-index: add --show-index-version","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-08-18T23:37:28Z","receivedAt":"2023-08-18T23:38:27Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"git update-index --version N\" is used to set the index format\nversion to a specific version, but there was no way to query the\ncurrent version used in the on-disk index file.\n\nTeach the command a new \"--show-index-version\" option, and also\nteach the \"--index-version N\" option to report what the version was\nwhen run with the \"--verbose\" option.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n Documentation/git-update-index.txt |  6 +++++-\n builtin/update-index.c             | 19 +++++++++++++------\n t/t2107-update-index-basic.sh      | 16 ++++++++++++++++\n 3 files changed, 34 insertions(+), 7 deletions(-)\n\ndiff --git a/Documentation/git-update-index.txt b/Documentation/git-update-index.txt\nindex a367f8d65a..3f204891ce 100644\n--- a/Documentation/git-update-index.txt\n+++ b/Documentation/git-update-index.txt\n@@ -162,7 +162,8 @@ you will need to handle the situation manually.\n \tWrite the resulting index out in the named on-disk format version.\n \tSupported versions are 2, 3 and 4. The current default version is 2\n \tor 3, depending on whether extra features are used, such as\n-\t`git add -N`.\n+\t`git add -N`.  With `--verbose` option, also reports the\n+\tversion the index file uses before and after this command.\n +\n Version 4 performs a simple pathname compression that reduces index\n size by 30%-50% on large repositories, which results in faster load\n@@ -171,6 +172,9 @@ and support for it was added to libgit2 in 2016 and to JGit in 2020.\n Older editions of this manual page called it \"relatively young\", but\n it should be considered mature technology these days.\n \n+--show-index-version::\n+\tReport the index format version used by the on-disk index file.\n+\tSee `--index-version` above.\n \n -z::\n \tOnly meaningful with `--stdin` or `--index-info`; paths are\ndiff --git a/builtin/update-index.c b/builtin/update-index.c\nindex 5fab9ad2ec..e713e2a04c 100644\n--- a/builtin/update-index.c\n+++ b/builtin/update-index.c\n@@ -1089,6 +1089,8 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)\n \t\t\tresolve_undo_clear_callback),\n \t\tOPT_INTEGER(0, \"index-version\", &preferred_index_format,\n \t\t\tN_(\"write index in this format\")),\n+\t\tOPT_SET_INT(0, \"show-index-version\", &preferred_index_format,\n+\t\t\t    N_(\"show index format version\"), -1),\n \t\tOPT_BOOL(0, \"split-index\", &split_index,\n \t\t\tN_(\"enable or disable split index\")),\n \t\tOPT_BOOL(0, \"untracked-cache\", &untracked_cache,\n@@ -1181,15 +1183,20 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)\n \n \tgetline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf;\n \tif (preferred_index_format) {\n-\t\tif (preferred_index_format < INDEX_FORMAT_LB ||\n-\t\t    INDEX_FORMAT_UB < preferred_index_format)\n+\t\tif (preferred_index_format < 0) {\n+\t\t\tprintf(_(\"%d\\n\"), the_index.version);\n+\t\t} else if (preferred_index_format < INDEX_FORMAT_LB ||\n+\t\t\t   INDEX_FORMAT_UB < preferred_index_format) {\n \t\t\tdie(\"index-version %d not in range: %d..%d\",\n \t\t\t    preferred_index_format,\n \t\t\t    INDEX_FORMAT_LB, INDEX_FORMAT_UB);\n-\n-\t\tif (the_index.version != preferred_index_format)\n-\t\t\tthe_index.cache_changed |= SOMETHING_CHANGED;\n-\t\tthe_index.version = preferred_index_format;\n+\t\t} else {\n+\t\t\tif (the_index.version != preferred_index_format)\n+\t\t\t\tthe_index.cache_changed |= SOMETHING_CHANGED;\n+\t\t\treport(_(\"index-version: was %d, set to %d\"),\n+\t\t\t       the_index.version, preferred_index_format);\n+\t\t\tthe_index.version = preferred_index_format;\n+\t\t}\n \t}\n \n \tif (read_from_stdin) {\ndiff --git a/t/t2107-update-index-basic.sh b/t/t2107-update-index-basic.sh\nindex 89b285fa3a..c78d1e9396 100755\n--- a/t/t2107-update-index-basic.sh\n+++ b/t/t2107-update-index-basic.sh\n@@ -111,4 +111,20 @@ test_expect_success '--chmod=+x and chmod=-x in the same argument list' '\n \ttest_cmp expect actual\n '\n \n+test_expect_success '--index-version' '\n+\tgit commit --allow-empty -m snap &&\n+\tgit reset --hard &&\n+\n+\tgit update-index --index-version 2 >actual &&\n+\ttest_must_be_empty actual &&\n+\n+\tgit update-index --show-index-version >actual &&\n+\techo 2 >expect &&\n+\ttest_cmp expect actual &&\n+\n+\tgit update-index --index-version 4 --verbose >actual &&\n+\techo \"index-version: was 2, set to 4\" >expect &&\n+\ttest_cmp expect actual\n+'\n+\n test_done\n-- \n2.42.0-rc2-7-gf9972720e9\n\n"},{"id":"480797","messageId":"20230818233729.2766281-4-gitster@pobox.com","threadId":"60127","inReplyTo":"20230818233729.2766281-1-gitster@pobox.com","subject":"[PATCH v2 3/3] test-tool: retire \"index-version\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-08-18T23:37:29Z","receivedAt":"2023-08-18T23:38:27Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"As \"git update-index --show-index-version\" can do the same thing,\nthe test-tool lost its reason to exist.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n Makefile                              |  1 -\n t/helper/test-index-version.c         | 15 ---------------\n t/helper/test-tool.c                  |  1 -\n t/helper/test-tool.h                  |  1 -\n t/t1600-index.sh                      |  2 +-\n t/t1700-split-index.sh                |  2 +-\n t/t2104-update-index-skip-worktree.sh |  6 +++---\n 7 files changed, 5 insertions(+), 23 deletions(-)\n delete mode 100644 t/helper/test-index-version.c\n\ndiff --git a/Makefile b/Makefile\nindex e440728c24..5323c76aa0 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -808,7 +808,6 @@ TEST_BUILTINS_OBJS += test-hash-speed.o\n TEST_BUILTINS_OBJS += test-hash.o\n TEST_BUILTINS_OBJS += test-hashmap.o\n TEST_BUILTINS_OBJS += test-hexdump.o\n-TEST_BUILTINS_OBJS += test-index-version.o\n TEST_BUILTINS_OBJS += test-json-writer.o\n TEST_BUILTINS_OBJS += test-lazy-init-name-hash.o\n TEST_BUILTINS_OBJS += test-match-trees.o\ndiff --git a/t/helper/test-index-version.c b/t/helper/test-index-version.c\ndeleted file mode 100644\nindex a06c45c1f8..0000000000\n--- a/t/helper/test-index-version.c\n+++ /dev/null\n@@ -1,15 +0,0 @@\n-#include \"test-tool.h\"\n-#include \"cache.h\"\n-\n-int cmd__index_version(int argc UNUSED, const char **argv UNUSED)\n-{\n-\tstruct cache_header hdr;\n-\tint version;\n-\n-\tmemset(&hdr,0,sizeof(hdr));\n-\tif (read(0, &hdr, sizeof(hdr)) != sizeof(hdr))\n-\t\treturn 0;\n-\tversion = ntohl(hdr.hdr_version);\n-\tprintf(\"%d\\n\", version);\n-\treturn 0;\n-}\ndiff --git a/t/helper/test-tool.c b/t/helper/test-tool.c\nindex abe8a785eb..621ac3dd10 100644\n--- a/t/helper/test-tool.c\n+++ b/t/helper/test-tool.c\n@@ -38,7 +38,6 @@ static struct test_cmd cmds[] = {\n \t{ \"hashmap\", cmd__hashmap },\n \t{ \"hash-speed\", cmd__hash_speed },\n \t{ \"hexdump\", cmd__hexdump },\n-\t{ \"index-version\", cmd__index_version },\n \t{ \"json-writer\", cmd__json_writer },\n \t{ \"lazy-init-name-hash\", cmd__lazy_init_name_hash },\n \t{ \"match-trees\", cmd__match_trees },\ndiff --git a/t/helper/test-tool.h b/t/helper/test-tool.h\nindex ea2672436c..a641c3a81d 100644\n--- a/t/helper/test-tool.h\n+++ b/t/helper/test-tool.h\n@@ -32,7 +32,6 @@ int cmd__getcwd(int argc, const char **argv);\n int cmd__hashmap(int argc, const char **argv);\n int cmd__hash_speed(int argc, const char **argv);\n int cmd__hexdump(int argc, const char **argv);\n-int cmd__index_version(int argc, const char **argv);\n int cmd__json_writer(int argc, const char **argv);\n int cmd__lazy_init_name_hash(int argc, const char **argv);\n int cmd__match_trees(int argc, const char **argv);\ndiff --git a/t/t1600-index.sh b/t/t1600-index.sh\nindex 9368d82f7d..62e7fd1596 100755\n--- a/t/t1600-index.sh\n+++ b/t/t1600-index.sh\n@@ -118,7 +118,7 @@ test_index_version () {\n \t\tfi &&\n \t\tgit add a &&\n \t\techo $EXPECTED_OUTPUT_VERSION >expect &&\n-\t\ttest-tool index-version <.git/index >actual &&\n+\t\tgit update-index --show-index-version >actual &&\n \t\ttest_cmp expect actual\n \t)\n }\ndiff --git a/t/t1700-split-index.sh b/t/t1700-split-index.sh\nindex b4ab166369..a7b7263b35 100755\n--- a/t/t1700-split-index.sh\n+++ b/t/t1700-split-index.sh\n@@ -43,7 +43,7 @@ test_expect_success 'enable split index' '\n \tgit config splitIndex.maxPercentChange 100 &&\n \tgit update-index --split-index &&\n \ttest-tool dump-split-index .git/index >actual &&\n-\tindexversion=$(test-tool index-version <.git/index) &&\n+\tindexversion=$(git update-index --show-index-version) &&\n \n \t# NEEDSWORK: Stop hard-coding checksums.\n \tif test \"$indexversion\" = \"4\"\ndiff --git a/t/t2104-update-index-skip-worktree.sh b/t/t2104-update-index-skip-worktree.sh\nindex b8686aabd3..0bab134d71 100755\n--- a/t/t2104-update-index-skip-worktree.sh\n+++ b/t/t2104-update-index-skip-worktree.sh\n@@ -39,7 +39,7 @@ test_expect_success 'setup' '\n '\n \n test_expect_success 'index is at version 2' '\n-\ttest \"$(test-tool index-version < .git/index)\" = 2\n+\ttest \"$(git update-index --show-index-version)\" = 2\n '\n \n test_expect_success 'update-index --skip-worktree' '\n@@ -48,7 +48,7 @@ test_expect_success 'update-index --skip-worktree' '\n '\n \n test_expect_success 'index is at version 3 after having some skip-worktree entries' '\n-\ttest \"$(test-tool index-version < .git/index)\" = 3\n+\ttest \"$(git update-index --show-index-version)\" = 3\n '\n \n test_expect_success 'ls-files -t' '\n@@ -61,7 +61,7 @@ test_expect_success 'update-index --no-skip-worktree' '\n '\n \n test_expect_success 'index version is back to 2 when there is no skip-worktree entry' '\n-\ttest \"$(test-tool index-version < .git/index)\" = 2\n+\ttest \"$(git update-index --show-index-version)\" = 2\n '\n \n test_done\n-- \n2.42.0-rc2-7-gf9972720e9\n\n"},{"id":"481741","messageId":"owlyfs3kkmzd.fsf@fine.c.googlers.com","threadId":"60127","inReplyTo":"20230818233729.2766281-2-gitster@pobox.com","subject":"Re: [PATCH v2 1/3] update-index doc: v4 is OK with JGit and libgit2","fromName":"Linus Arver","fromEmail":"linusa@google.com","sentAt":"2023-09-12T04:57:10Z","receivedAt":"2023-09-12T05:00:58Z","isPatch":true,"sender":{"key":"linus@ucla.edu","avatar":null},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> [...]\n> diff --git a/Documentation/git-update-index.txt b/Documentation/git-update-index.txt\n> index f4bb9c5daf..a367f8d65a 100644\n> --- a/Documentation/git-update-index.txt\n> +++ b/Documentation/git-update-index.txt\n> @@ -166,9 +166,11 @@ you will need to handle the situation manually.\n>  +\n>  Version 4 performs a simple pathname compression that reduces index\n>  size by 30%-50% on large repositories, which results in faster load\n> -time. Version 4 is relatively young (first released in 1.8.0 in\n> -October 2012). Other Git implementations such as JGit and libgit2\n> -may not support it yet.\n> +time.  Git supports it since version 1.8.0, released in October 2012,\n> +and support for it was added to libgit2 in 2016 and to JGit in 2020.\n> +Older editions of this manual page called it \"relatively young\", but\n\nNit: s/editions/versions because typically \"edition\" means a version of\nphysically published text (such as books). Also I don't think we use the\nword \"edition\" anywhere else in our codebase.\n"},{"id":"481742","messageId":"owlybke8kkcf.fsf@fine.c.googlers.com","threadId":"60127","inReplyTo":"20230818233729.2766281-3-gitster@pobox.com","subject":"Re: [PATCH v2 2/3] update-index: add --show-index-version","fromName":"Linus Arver","fromEmail":"linusa@google.com","sentAt":"2023-09-12T05:54:08Z","receivedAt":"2023-09-12T05:54:11Z","isPatch":true,"sender":{"key":"linus@ucla.edu","avatar":null},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> \"git update-index --version N\" is used to set the index format\n\ns/--version/--index-version\n\n> version to a specific version, but there was no way to query the\n> current version used in the on-disk index file.\n>\n> Teach the command a new \"--show-index-version\" option, and also\n> teach the \"--index-version N\" option to report what the version was\n> when run with the \"--verbose\" option.\n>\n> Signed-off-by: Junio C Hamano <gitster@pobox.com>\n> ---\n>  Documentation/git-update-index.txt |  6 +++++-\n>  builtin/update-index.c             | 19 +++++++++++++------\n>  t/t2107-update-index-basic.sh      | 16 ++++++++++++++++\n>  3 files changed, 34 insertions(+), 7 deletions(-)\n>\n> diff --git a/Documentation/git-update-index.txt b/Documentation/git-update-index.txt\n> index a367f8d65a..3f204891ce 100644\n> --- a/Documentation/git-update-index.txt\n> +++ b/Documentation/git-update-index.txt\n> @@ -162,7 +162,8 @@ you will need to handle the situation manually.\n>  \tWrite the resulting index out in the named on-disk format version.\n>  \tSupported versions are 2, 3 and 4. The current default version is 2\n>  \tor 3, depending on whether extra features are used, such as\n> -\t`git add -N`.\n> +\t`git add -N`.  With `--verbose` option, also reports the\n\nHow about\n\n    `git add -N`.  With `--verbose`, also report the\n\n> +\tversion the index file uses before and after this command.\n>  +\n>  Version 4 performs a simple pathname compression that reduces index\n>  size by 30%-50% on large repositories, which results in faster load\n> @@ -171,6 +172,9 @@ and support for it was added to libgit2 in 2016 and to JGit in 2020.\n>  Older editions of this manual page called it \"relatively young\", but\n>  it should be considered mature technology these days.\n>\n> +--show-index-version::\n> +\tReport the index format version used by the on-disk index file.\n> +\tSee `--index-version` above.\n\nLooks good.\n\n>  -z::\n>  \tOnly meaningful with `--stdin` or `--index-info`; paths are\n> diff --git a/builtin/update-index.c b/builtin/update-index.c\n> index 5fab9ad2ec..e713e2a04c 100644\n> --- a/builtin/update-index.c\n> +++ b/builtin/update-index.c\n> @@ -1089,6 +1089,8 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)\n>  \t\t\tresolve_undo_clear_callback),\n>  \t\tOPT_INTEGER(0, \"index-version\", &preferred_index_format,\n>  \t\t\tN_(\"write index in this format\")),\n> +\t\tOPT_SET_INT(0, \"show-index-version\", &preferred_index_format,\n> +\t\t\t    N_(\"show index format version\"), -1),\n\nHow about\n\n    \"show on-disk index format version\"\n\nfor the help text? Also \"report\" may be preferable instead of \"show\" for\nconsistency with the manpage.\n\nAlso, I think it would be easier to read if we didn't overload\npreferred_index_format here and instead used a new variable (perhaps named\n\"show_index_format\").\n\nAnd I just realized that we are now using not only \"show\" and \"report\"\ninterchangeably in this patch, but also \"format\" and \"version\" ---\nit would be nice to clean up as #leftoverbits.\n\n>  \t\tOPT_BOOL(0, \"split-index\", &split_index,\n>  \t\t\tN_(\"enable or disable split index\")),\n>  \t\tOPT_BOOL(0, \"untracked-cache\", &untracked_cache,\n> @@ -1181,15 +1183,20 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)\n>\n>  \tgetline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf;\n>  \tif (preferred_index_format) {\n> -\t\tif (preferred_index_format < INDEX_FORMAT_LB ||\n> -\t\t    INDEX_FORMAT_UB < preferred_index_format)\n> +\t\tif (preferred_index_format < 0) {\n> +\t\t\tprintf(_(\"%d\\n\"), the_index.version);\n> +\t\t} else if (preferred_index_format < INDEX_FORMAT_LB ||\n> +\t\t\t   INDEX_FORMAT_UB < preferred_index_format) {\n>  \t\t\tdie(\"index-version %d not in range: %d..%d\",\n>  \t\t\t    preferred_index_format,\n>  \t\t\t    INDEX_FORMAT_LB, INDEX_FORMAT_UB);\n> -\n> -\t\tif (the_index.version != preferred_index_format)\n> -\t\t\tthe_index.cache_changed |= SOMETHING_CHANGED;\n> -\t\tthe_index.version = preferred_index_format;\n> +\t\t} else {\n> +\t\t\tif (the_index.version != preferred_index_format)\n> +\t\t\t\tthe_index.cache_changed |= SOMETHING_CHANGED;\n> +\t\t\treport(_(\"index-version: was %d, set to %d\"),\n> +\t\t\t       the_index.version, preferred_index_format);\n> +\t\t\tthe_index.version = preferred_index_format;\n> +\t\t}\n>  \t}\n\nLooks good. But if you decide to use a new variable like\n\"show_index_format\" as suggested above, you might want to refactor this\nout to a separate function. Then you could obviously do away with the\nchained if/else and replace them with early returns, which would be\neasier to read.\n\n>  \tif (read_from_stdin) {\n> diff --git a/t/t2107-update-index-basic.sh b/t/t2107-update-index-basic.sh\n> index 89b285fa3a..c78d1e9396 100755\n> --- a/t/t2107-update-index-basic.sh\n> +++ b/t/t2107-update-index-basic.sh\n> @@ -111,4 +111,20 @@ test_expect_success '--chmod=+x and chmod=-x in the same argument list' '\n>  \ttest_cmp expect actual\n>  '\n>\n> +test_expect_success '--index-version' '\n> +\tgit commit --allow-empty -m snap &&\n> +\tgit reset --hard &&\n\nNot sure why this \"git reset --hard\" is needed here --- is it to clear\nout state from previous test cases? If so, perhaps it's better to run\nthis as the very first command in this test case?\n\nBut this also makes me wonder why \"git commit --allow-empty -m snap\" is\neven necessary (if we already have a git repo)?\n\n> +\tgit update-index --index-version 2 >actual &&\n> +\ttest_must_be_empty actual &&\n\nBefore we do \"--index-version 2\", it may be desirable to run the\n\"--show-index-version\" flag first to see what we have before modifying\nit with \"2\".\n\n> +\tgit update-index --show-index-version >actual &&\n> +\techo 2 >expect &&\n> +\ttest_cmp expect actual &&\n> +\n> +\tgit update-index --index-version 4 --verbose >actual &&\n> +\techo \"index-version: was 2, set to 4\" >expect &&\n> +\ttest_cmp expect actual\n> +'\n\nHow about adding this check below to check what happens if the newly-set\nversion is the same as the existing version?\n\n        git update-index --index-version 4 --verbose >actual &&\n        echo \"index-version: was 4, set to 4\" >expect &&\n        test_cmp expect actual\n\nAnd also how about a similar check, but for downgrading from a higher\nversion number to a lower one?\n\n        git update-index --index-version 2 --verbose >actual &&\n        echo \"index-version: was 4, set to 2\" >expect &&\n        test_cmp expect actual\n\n> +\n>  test_done\n> --\n> 2.42.0-rc2-7-gf9972720e9\n"},{"id":"481743","messageId":"owly8r9bly64.fsf@fine.c.googlers.com","threadId":"60127","inReplyTo":"20230818233729.2766281-4-gitster@pobox.com","subject":"Re: [PATCH v2 3/3] test-tool: retire \"index-version\"","fromName":"Linus Arver","fromEmail":"linusa@google.com","sentAt":"2023-09-12T06:10:11Z","receivedAt":"2023-09-12T06:10:57Z","isPatch":true,"sender":{"key":"linus@ucla.edu","avatar":null},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> As \"git update-index --show-index-version\" can do the same thing,\n> the test-tool lost its reason to exist.\n\nI think you meant\n\n    the equivalent functionality in test-tool ...\n\nand not that the test-tool (in its entirety) lost its reason to exist.\n\nThe rest of the patch LGTM.\n"},{"id":"481777","messageId":"xmqq7covpb4q.fsf@gitster.g","threadId":"60127","inReplyTo":"owlyfs3kkmzd.fsf@fine.c.googlers.com","subject":"Re: [PATCH v2 1/3] update-index doc: v4 is OK with JGit and libgit2","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-09-12T17:14:13Z","receivedAt":"2023-09-12T17:14:21Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Linus Arver <linusa@google.com> writes:\n\n> Junio C Hamano <gitster@pobox.com> writes:\n> ...\n>> +Older editions of this manual page called it \"relatively young\", but\n>\n> Nit: s/editions/versions because typically \"edition\" means a version of\n> physically published text (such as books).\n\nThis text belonging to the manual, that was exactly the reason why I\nused that word, but ...\n\n> Also I don't think we use the\n> word \"edition\" anywhere else in our codebase.\n\n... I think \"version\" is just fine.  Will fix.\n\nThanks.\n"},{"id":"481785","messageId":"xmqqbke7nrlz.fsf@gitster.g","threadId":"60127","inReplyTo":"owlybke8kkcf.fsf@fine.c.googlers.com","subject":"Re: [PATCH v2 2/3] update-index: add --show-index-version","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-09-12T19:01:12Z","receivedAt":"2023-09-12T19:01:21Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Linus Arver <linusa@google.com> writes:\n\n> Junio C Hamano <gitster@pobox.com> writes:\n>\n>> \"git update-index --version N\" is used to set the index format\n>\n> s/--version/--index-version\n\nGood eyes.\n\n>> +\t`git add -N`.  With `--verbose` option, also reports the\n>\n> How about\n>\n>     `git add -N`.  With `--verbose`, also report the\n\nYup, that is much better.\n\n>>  \t\tOPT_INTEGER(0, \"index-version\", &preferred_index_format,\n>>  \t\t\tN_(\"write index in this format\")),\n>> +\t\tOPT_SET_INT(0, \"show-index-version\", &preferred_index_format,\n>> +\t\t\t    N_(\"show index format version\"), -1),\n>\n> How about\n>\n>     \"show on-disk index format version\"\n\nOK.  The entry before that says \"write\" and it makes it clear enough\nthat it is talking about the \"on-disk\" thing, hence \"write index\" is\nsufficient.  The readers, who do not know the \"format version\"\nmatters only on-disk and does not matter once the index data gets\nslurped into memory, would benefit with \"on-disk index\" here.  I\nwill also take your \"show\" -> \"report\" suggestion.\n\n>> diff --git a/t/t2107-update-index-basic.sh b/t/t2107-update-index-basic.sh\n>> index 89b285fa3a..c78d1e9396 100755\n>> --- a/t/t2107-update-index-basic.sh\n>> +++ b/t/t2107-update-index-basic.sh\n>> @@ -111,4 +111,20 @@ test_expect_success '--chmod=+x and chmod=-x in the same argument list' '\n>>  \ttest_cmp expect actual\n>>  '\n>>\n>> +test_expect_success '--index-version' '\n>> +\tgit commit --allow-empty -m snap &&\n>> +\tgit reset --hard &&\n>\n> Not sure why this \"git reset --hard\" is needed here --- is it to clear\n> out state from previous test cases? If so, perhaps it's better to run\n> this as the very first command in this test case?\n>\n> But this also makes me wonder why \"git commit --allow-empty -m snap\" is\n> even necessary (if we already have a git repo)?\n\nThere is no commit yet in this repository at this point, which means\nthat \"reset --hard [HEAD]\" cannot be the first command.  There are\nnewly added paths in the index, some of which are further modified\nin the working tree.  Creating a snapshot commit will record what is\nin the index, and a hard reset will make the contents of the working\ntree match exactly what was in the index, reverting the modification\nmade to some paths in the working tree.\n\nHaving said that, we may further want to tighten these \"clean the\nslate\" steps for later tests (read on).\n\n>> +\tgit update-index --index-version 2 >actual &&\n>> +\ttest_must_be_empty actual &&\n>\n> Before we do \"--index-version 2\", it may be desirable to run the\n> \"--show-index-version\" flag first to see what we have before modifying\n> it with \"2\".\n\nThat was what I specifically wanted to avoid.  I am not interested\nin testing what the default version of the day is.  The only thing\nthis invocation cares about is to (try to) use the version 2; it\nwill be detected as a failure if the next show-index-version\nreported something else ...\n\n>> +\tgit update-index --show-index-version >actual &&\n>> +\techo 2 >expect &&\n>> +\ttest_cmp expect actual &&\n\n... which is checked here.\n\n>> +\tgit update-index --index-version 4 --verbose >actual &&\n>> +\techo \"index-version: was 2, set to 4\" >expect &&\n>> +\ttest_cmp expect actual\n\nAnd how a transition is reported with --verbose is tested here.\n\n>> +'\n>\n> How about adding this check below to check what happens if the newly-set\n> version is the same as the existing version?\n>\n>         git update-index --index-version 4 --verbose >actual &&\n>         echo \"index-version: was 4, set to 4\" >expect &&\n>         test_cmp expect actual\n>\n> And also how about a similar check, but for downgrading from a higher\n> version number to a lower one?\n>\n>         git update-index --index-version 2 --verbose >actual &&\n>         echo \"index-version: was 4, set to 2\" >expect &&\n>         test_cmp expect actual\n\nI assumed that the flipping between versions without --verbose had\nadequate coverage and the tests this patch adds were solely about\nreporting with the \"--verbose\" option.  It seems there is no such\ntest coverage, so these may want to be added.  Perhaps we should\nflip from 2 to 4 _without_ verbose and make sure we are still silent\nas well.\n\nTesting downgrading an index with unspecified [*] contents from 3\n(or higher) to 2 would be unwise, as such a conversion may or may\nnot work depending on the contents.  I will tighten the \"clean the\nslate\" steps and add downgrades to the list, as the initial \"try to\nset to 2\" may not even work with unknown contents in the index.\n\nThanks.\n\n\n[Footnote] \n\n* This is in a very late part of the test script and the state\n  previous tests left us will change over time.\n"},{"id":"481787","messageId":"20230912193235.776292-1-gitster@pobox.com","threadId":"60127","inReplyTo":"20230818233729.2766281-1-gitster@pobox.com","subject":"[PATCH v3 0/3] \"update-index --show-index-version\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-09-12T19:32:32Z","receivedAt":"2023-09-12T19:32:43Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Even though there is \"test-tool index-version\", there wasn't an\nofficially supported way for end-users to inspect the index version\nof an on-disk index.  Let's have one.\n\nThis iteration takes suggestions by Linus Arver; the tests added by\n[2/3] have been clarified.\n\nJunio C Hamano (3):\n  update-index doc: v4 is OK with JGit and libgit2\n  update-index: add --show-index-version\n  test-tool: retire \"index-version\"\n\n Documentation/git-update-index.txt    | 14 ++++++++----\n Makefile                              |  1 -\n builtin/update-index.c                | 19 ++++++++++------\n t/helper/test-index-version.c         | 15 -------------\n t/helper/test-tool.c                  |  1 -\n t/helper/test-tool.h                  |  1 -\n t/t1600-index.sh                      |  2 +-\n t/t1700-split-index.sh                |  2 +-\n t/t2104-update-index-skip-worktree.sh |  6 +++---\n t/t2107-update-index-basic.sh         | 31 +++++++++++++++++++++++++++\n 10 files changed, 59 insertions(+), 33 deletions(-)\n delete mode 100644 t/helper/test-index-version.c\n\nRange-diff against v2:\n1:  7bc7f7877d ! 1:  224a72529a update-index doc: v4 is OK with JGit and libgit2\n    @@ Commit message\n         cautious about cross-tool compatibility.\n     \n         Helped-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>\n    +    Helped-by: Linus Arver <linusa@google.com>\n         Signed-off-by: Junio C Hamano <gitster@pobox.com>\n     \n      ## Documentation/git-update-index.txt ##\n    @@ Documentation/git-update-index.txt: you will need to handle the situation manual\n     -may not support it yet.\n     +time.  Git supports it since version 1.8.0, released in October 2012,\n     +and support for it was added to libgit2 in 2016 and to JGit in 2020.\n    -+Older editions of this manual page called it \"relatively young\", but\n    ++Older versions of this manual page called it \"relatively young\", but\n     +it should be considered mature technology these days.\n     +\n      \n2:  33c924f893 ! 2:  bd3fc76b3f update-index: add --show-index-version\n    @@ Metadata\n      ## Commit message ##\n         update-index: add --show-index-version\n     \n    -    \"git update-index --version N\" is used to set the index format\n    +    \"git update-index --index-version N\" is used to set the index format\n         version to a specific version, but there was no way to query the\n         current version used in the on-disk index file.\n     \n    @@ Commit message\n         teach the \"--index-version N\" option to report what the version was\n         when run with the \"--verbose\" option.\n     \n    +    Helped-by: Linus Arver <linusa@google.com>\n         Signed-off-by: Junio C Hamano <gitster@pobox.com>\n     \n      ## Documentation/git-update-index.txt ##\n    @@ Documentation/git-update-index.txt: you will need to handle the situation manual\n      \tSupported versions are 2, 3 and 4. The current default version is 2\n      \tor 3, depending on whether extra features are used, such as\n     -\t`git add -N`.\n    -+\t`git add -N`.  With `--verbose` option, also reports the\n    -+\tversion the index file uses before and after this command.\n    ++\t`git add -N`.  With `--verbose`, also report the version the index\n    ++\tfile uses before and after this command.\n      +\n      Version 4 performs a simple pathname compression that reduces index\n      size by 30%-50% on large repositories, which results in faster load\n     @@ Documentation/git-update-index.txt: and support for it was added to libgit2 in 2016 and to JGit in 2020.\n    - Older editions of this manual page called it \"relatively young\", but\n    + Older versions of this manual page called it \"relatively young\", but\n      it should be considered mature technology these days.\n      \n     +--show-index-version::\n    @@ builtin/update-index.c: int cmd_update_index(int argc, const char **argv, const\n      \t\tOPT_INTEGER(0, \"index-version\", &preferred_index_format,\n      \t\t\tN_(\"write index in this format\")),\n     +\t\tOPT_SET_INT(0, \"show-index-version\", &preferred_index_format,\n    -+\t\t\t    N_(\"show index format version\"), -1),\n    ++\t\t\t    N_(\"report on-disk index format version\"), -1),\n      \t\tOPT_BOOL(0, \"split-index\", &split_index,\n      \t\t\tN_(\"enable or disable split index\")),\n      \t\tOPT_BOOL(0, \"untracked-cache\", &untracked_cache,\n    @@ t/t2107-update-index-basic.sh: test_expect_success '--chmod=+x and chmod=-x in t\n     +test_expect_success '--index-version' '\n     +\tgit commit --allow-empty -m snap &&\n     +\tgit reset --hard &&\n    ++\tgit rm -f -r --cached . &&\n     +\n    -+\tgit update-index --index-version 2 >actual &&\n    -+\ttest_must_be_empty actual &&\n    -+\n    ++\t# The default index version is 2 --- update this test\n    ++\t# when you change it in the code\n     +\tgit update-index --show-index-version >actual &&\n     +\techo 2 >expect &&\n     +\ttest_cmp expect actual &&\n     +\n    ++\t# The next test wants us to be using version 2\n    ++\tgit update-index --index-version 2 &&\n    ++\n     +\tgit update-index --index-version 4 --verbose >actual &&\n     +\techo \"index-version: was 2, set to 4\" >expect &&\n    -+\ttest_cmp expect actual\n    ++\ttest_cmp expect actual &&\n    ++\n    ++\tgit update-index --index-version 4 --verbose >actual &&\n    ++\techo \"index-version: was 4, set to 4\" >expect &&\n    ++\ttest_cmp expect actual &&\n    ++\n    ++\tgit update-index --index-version 2 --verbose >actual &&\n    ++\techo \"index-version: was 4, set to 2\" >expect &&\n    ++\ttest_cmp expect actual &&\n    ++\n    ++\t# non-verbose should be silent\n    ++\tgit update-index --index-version 4 >actual &&\n    ++\ttest_must_be_empty actual\n     +'\n     +\n      test_done\n3:  137ec82973 ! 3:  d1144a8240 test-tool: retire \"index-version\"\n    @@ Commit message\n         test-tool: retire \"index-version\"\n     \n         As \"git update-index --show-index-version\" can do the same thing,\n    -    the test-tool lost its reason to exist.\n    +    the 'index-version' subcommand in the test-tool lost its reason to\n    +    exist.  Remove it and replace its use with the end-user facing\n    +    'git update-index --show-index-version'.\n     \n    +    Helped-by: Linus Arver <linusa@google.com>\n         Signed-off-by: Junio C Hamano <gitster@pobox.com>\n     \n      ## Makefile ##\n-- \n2.42.0-158-g94e83dcf5b\n\n"},{"id":"481788","messageId":"20230912193235.776292-2-gitster@pobox.com","threadId":"60127","inReplyTo":"20230912193235.776292-1-gitster@pobox.com","subject":"[PATCH v3 1/3] update-index doc: v4 is OK with JGit and libgit2","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-09-12T19:32:33Z","receivedAt":"2023-09-12T19:32:45Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Being invented in late 2012 no longer makes the index v4 format\n\"relatively young\".\n\nThe support for the index version 4 was added to libgit2 with their\n5625d86b (index: support index v4, 2016-05-17) and to JGit with\ntheir e9cb0a8e (DirCache: support index V4, 2020-08-10).\n\nLet's update the paragraph that discouraged its use for folks overly\ncautious about cross-tool compatibility.\n\nHelped-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>\nHelped-by: Linus Arver <linusa@google.com>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n Documentation/git-update-index.txt | 8 +++++---\n 1 file changed, 5 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/git-update-index.txt b/Documentation/git-update-index.txt\nindex f4bb9c5daf..71d6ef9457 100644\n--- a/Documentation/git-update-index.txt\n+++ b/Documentation/git-update-index.txt\n@@ -166,9 +166,11 @@ you will need to handle the situation manually.\n +\n Version 4 performs a simple pathname compression that reduces index\n size by 30%-50% on large repositories, which results in faster load\n-time. Version 4 is relatively young (first released in 1.8.0 in\n-October 2012). Other Git implementations such as JGit and libgit2\n-may not support it yet.\n+time.  Git supports it since version 1.8.0, released in October 2012,\n+and support for it was added to libgit2 in 2016 and to JGit in 2020.\n+Older versions of this manual page called it \"relatively young\", but\n+it should be considered mature technology these days.\n+\n \n -z::\n \tOnly meaningful with `--stdin` or `--index-info`; paths are\n-- \n2.42.0-158-g94e83dcf5b\n\n"},{"id":"481789","messageId":"20230912193235.776292-3-gitster@pobox.com","threadId":"60127","inReplyTo":"20230912193235.776292-1-gitster@pobox.com","subject":"[PATCH v3 2/3] update-index: add --show-index-version","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-09-12T19:32:34Z","receivedAt":"2023-09-12T19:32:53Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"git update-index --index-version N\" is used to set the index format\nversion to a specific version, but there was no way to query the\ncurrent version used in the on-disk index file.\n\nTeach the command a new \"--show-index-version\" option, and also\nteach the \"--index-version N\" option to report what the version was\nwhen run with the \"--verbose\" option.\n\nHelped-by: Linus Arver <linusa@google.com>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n Documentation/git-update-index.txt |  6 +++++-\n builtin/update-index.c             | 19 ++++++++++++------\n t/t2107-update-index-basic.sh      | 31 ++++++++++++++++++++++++++++++\n 3 files changed, 49 insertions(+), 7 deletions(-)\n\ndiff --git a/Documentation/git-update-index.txt b/Documentation/git-update-index.txt\nindex 71d6ef9457..1271486ae9 100644\n--- a/Documentation/git-update-index.txt\n+++ b/Documentation/git-update-index.txt\n@@ -162,7 +162,8 @@ you will need to handle the situation manually.\n \tWrite the resulting index out in the named on-disk format version.\n \tSupported versions are 2, 3 and 4. The current default version is 2\n \tor 3, depending on whether extra features are used, such as\n-\t`git add -N`.\n+\t`git add -N`.  With `--verbose`, also report the version the index\n+\tfile uses before and after this command.\n +\n Version 4 performs a simple pathname compression that reduces index\n size by 30%-50% on large repositories, which results in faster load\n@@ -171,6 +172,9 @@ and support for it was added to libgit2 in 2016 and to JGit in 2020.\n Older versions of this manual page called it \"relatively young\", but\n it should be considered mature technology these days.\n \n+--show-index-version::\n+\tReport the index format version used by the on-disk index file.\n+\tSee `--index-version` above.\n \n -z::\n \tOnly meaningful with `--stdin` or `--index-info`; paths are\ndiff --git a/builtin/update-index.c b/builtin/update-index.c\nindex 5fab9ad2ec..8c3454c1c1 100644\n--- a/builtin/update-index.c\n+++ b/builtin/update-index.c\n@@ -1089,6 +1089,8 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)\n \t\t\tresolve_undo_clear_callback),\n \t\tOPT_INTEGER(0, \"index-version\", &preferred_index_format,\n \t\t\tN_(\"write index in this format\")),\n+\t\tOPT_SET_INT(0, \"show-index-version\", &preferred_index_format,\n+\t\t\t    N_(\"report on-disk index format version\"), -1),\n \t\tOPT_BOOL(0, \"split-index\", &split_index,\n \t\t\tN_(\"enable or disable split index\")),\n \t\tOPT_BOOL(0, \"untracked-cache\", &untracked_cache,\n@@ -1181,15 +1183,20 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)\n \n \tgetline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf;\n \tif (preferred_index_format) {\n-\t\tif (preferred_index_format < INDEX_FORMAT_LB ||\n-\t\t    INDEX_FORMAT_UB < preferred_index_format)\n+\t\tif (preferred_index_format < 0) {\n+\t\t\tprintf(_(\"%d\\n\"), the_index.version);\n+\t\t} else if (preferred_index_format < INDEX_FORMAT_LB ||\n+\t\t\t   INDEX_FORMAT_UB < preferred_index_format) {\n \t\t\tdie(\"index-version %d not in range: %d..%d\",\n \t\t\t    preferred_index_format,\n \t\t\t    INDEX_FORMAT_LB, INDEX_FORMAT_UB);\n-\n-\t\tif (the_index.version != preferred_index_format)\n-\t\t\tthe_index.cache_changed |= SOMETHING_CHANGED;\n-\t\tthe_index.version = preferred_index_format;\n+\t\t} else {\n+\t\t\tif (the_index.version != preferred_index_format)\n+\t\t\t\tthe_index.cache_changed |= SOMETHING_CHANGED;\n+\t\t\treport(_(\"index-version: was %d, set to %d\"),\n+\t\t\t       the_index.version, preferred_index_format);\n+\t\t\tthe_index.version = preferred_index_format;\n+\t\t}\n \t}\n \n \tif (read_from_stdin) {\ndiff --git a/t/t2107-update-index-basic.sh b/t/t2107-update-index-basic.sh\nindex 89b285fa3a..22f4c92399 100755\n--- a/t/t2107-update-index-basic.sh\n+++ b/t/t2107-update-index-basic.sh\n@@ -111,4 +111,35 @@ test_expect_success '--chmod=+x and chmod=-x in the same argument list' '\n \ttest_cmp expect actual\n '\n \n+test_expect_success '--index-version' '\n+\tgit commit --allow-empty -m snap &&\n+\tgit reset --hard &&\n+\tgit rm -f -r --cached . &&\n+\n+\t# The default index version is 2 --- update this test\n+\t# when you change it in the code\n+\tgit update-index --show-index-version >actual &&\n+\techo 2 >expect &&\n+\ttest_cmp expect actual &&\n+\n+\t# The next test wants us to be using version 2\n+\tgit update-index --index-version 2 &&\n+\n+\tgit update-index --index-version 4 --verbose >actual &&\n+\techo \"index-version: was 2, set to 4\" >expect &&\n+\ttest_cmp expect actual &&\n+\n+\tgit update-index --index-version 4 --verbose >actual &&\n+\techo \"index-version: was 4, set to 4\" >expect &&\n+\ttest_cmp expect actual &&\n+\n+\tgit update-index --index-version 2 --verbose >actual &&\n+\techo \"index-version: was 4, set to 2\" >expect &&\n+\ttest_cmp expect actual &&\n+\n+\t# non-verbose should be silent\n+\tgit update-index --index-version 4 >actual &&\n+\ttest_must_be_empty actual\n+'\n+\n test_done\n-- \n2.42.0-158-g94e83dcf5b\n\n"},{"id":"481790","messageId":"20230912193235.776292-4-gitster@pobox.com","threadId":"60127","inReplyTo":"20230912193235.776292-1-gitster@pobox.com","subject":"[PATCH v3 3/3] test-tool: retire \"index-version\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-09-12T19:32:35Z","receivedAt":"2023-09-12T19:32:56Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"As \"git update-index --show-index-version\" can do the same thing,\nthe 'index-version' subcommand in the test-tool lost its reason to\nexist.  Remove it and replace its use with the end-user facing\n'git update-index --show-index-version'.\n\nHelped-by: Linus Arver <linusa@google.com>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n Makefile                              |  1 -\n t/helper/test-index-version.c         | 15 ---------------\n t/helper/test-tool.c                  |  1 -\n t/helper/test-tool.h                  |  1 -\n t/t1600-index.sh                      |  2 +-\n t/t1700-split-index.sh                |  2 +-\n t/t2104-update-index-skip-worktree.sh |  6 +++---\n 7 files changed, 5 insertions(+), 23 deletions(-)\n delete mode 100644 t/helper/test-index-version.c\n\ndiff --git a/Makefile b/Makefile\nindex e440728c24..5323c76aa0 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -808,7 +808,6 @@ TEST_BUILTINS_OBJS += test-hash-speed.o\n TEST_BUILTINS_OBJS += test-hash.o\n TEST_BUILTINS_OBJS += test-hashmap.o\n TEST_BUILTINS_OBJS += test-hexdump.o\n-TEST_BUILTINS_OBJS += test-index-version.o\n TEST_BUILTINS_OBJS += test-json-writer.o\n TEST_BUILTINS_OBJS += test-lazy-init-name-hash.o\n TEST_BUILTINS_OBJS += test-match-trees.o\ndiff --git a/t/helper/test-index-version.c b/t/helper/test-index-version.c\ndeleted file mode 100644\nindex a06c45c1f8..0000000000\n--- a/t/helper/test-index-version.c\n+++ /dev/null\n@@ -1,15 +0,0 @@\n-#include \"test-tool.h\"\n-#include \"cache.h\"\n-\n-int cmd__index_version(int argc UNUSED, const char **argv UNUSED)\n-{\n-\tstruct cache_header hdr;\n-\tint version;\n-\n-\tmemset(&hdr,0,sizeof(hdr));\n-\tif (read(0, &hdr, sizeof(hdr)) != sizeof(hdr))\n-\t\treturn 0;\n-\tversion = ntohl(hdr.hdr_version);\n-\tprintf(\"%d\\n\", version);\n-\treturn 0;\n-}\ndiff --git a/t/helper/test-tool.c b/t/helper/test-tool.c\nindex abe8a785eb..621ac3dd10 100644\n--- a/t/helper/test-tool.c\n+++ b/t/helper/test-tool.c\n@@ -38,7 +38,6 @@ static struct test_cmd cmds[] = {\n \t{ \"hashmap\", cmd__hashmap },\n \t{ \"hash-speed\", cmd__hash_speed },\n \t{ \"hexdump\", cmd__hexdump },\n-\t{ \"index-version\", cmd__index_version },\n \t{ \"json-writer\", cmd__json_writer },\n \t{ \"lazy-init-name-hash\", cmd__lazy_init_name_hash },\n \t{ \"match-trees\", cmd__match_trees },\ndiff --git a/t/helper/test-tool.h b/t/helper/test-tool.h\nindex ea2672436c..a641c3a81d 100644\n--- a/t/helper/test-tool.h\n+++ b/t/helper/test-tool.h\n@@ -32,7 +32,6 @@ int cmd__getcwd(int argc, const char **argv);\n int cmd__hashmap(int argc, const char **argv);\n int cmd__hash_speed(int argc, const char **argv);\n int cmd__hexdump(int argc, const char **argv);\n-int cmd__index_version(int argc, const char **argv);\n int cmd__json_writer(int argc, const char **argv);\n int cmd__lazy_init_name_hash(int argc, const char **argv);\n int cmd__match_trees(int argc, const char **argv);\ndiff --git a/t/t1600-index.sh b/t/t1600-index.sh\nindex 9368d82f7d..62e7fd1596 100755\n--- a/t/t1600-index.sh\n+++ b/t/t1600-index.sh\n@@ -118,7 +118,7 @@ test_index_version () {\n \t\tfi &&\n \t\tgit add a &&\n \t\techo $EXPECTED_OUTPUT_VERSION >expect &&\n-\t\ttest-tool index-version <.git/index >actual &&\n+\t\tgit update-index --show-index-version >actual &&\n \t\ttest_cmp expect actual\n \t)\n }\ndiff --git a/t/t1700-split-index.sh b/t/t1700-split-index.sh\nindex b4ab166369..a7b7263b35 100755\n--- a/t/t1700-split-index.sh\n+++ b/t/t1700-split-index.sh\n@@ -43,7 +43,7 @@ test_expect_success 'enable split index' '\n \tgit config splitIndex.maxPercentChange 100 &&\n \tgit update-index --split-index &&\n \ttest-tool dump-split-index .git/index >actual &&\n-\tindexversion=$(test-tool index-version <.git/index) &&\n+\tindexversion=$(git update-index --show-index-version) &&\n \n \t# NEEDSWORK: Stop hard-coding checksums.\n \tif test \"$indexversion\" = \"4\"\ndiff --git a/t/t2104-update-index-skip-worktree.sh b/t/t2104-update-index-skip-worktree.sh\nindex b8686aabd3..0bab134d71 100755\n--- a/t/t2104-update-index-skip-worktree.sh\n+++ b/t/t2104-update-index-skip-worktree.sh\n@@ -39,7 +39,7 @@ test_expect_success 'setup' '\n '\n \n test_expect_success 'index is at version 2' '\n-\ttest \"$(test-tool index-version < .git/index)\" = 2\n+\ttest \"$(git update-index --show-index-version)\" = 2\n '\n \n test_expect_success 'update-index --skip-worktree' '\n@@ -48,7 +48,7 @@ test_expect_success 'update-index --skip-worktree' '\n '\n \n test_expect_success 'index is at version 3 after having some skip-worktree entries' '\n-\ttest \"$(test-tool index-version < .git/index)\" = 3\n+\ttest \"$(git update-index --show-index-version)\" = 3\n '\n \n test_expect_success 'ls-files -t' '\n@@ -61,7 +61,7 @@ test_expect_success 'update-index --no-skip-worktree' '\n '\n \n test_expect_success 'index version is back to 2 when there is no skip-worktree entry' '\n-\ttest \"$(test-tool index-version < .git/index)\" = 2\n+\ttest \"$(git update-index --show-index-version)\" = 2\n '\n \n test_done\n-- \n2.42.0-158-g94e83dcf5b\n\n"},{"id":"481831","messageId":"owlypm2ljmzi.fsf@fine.c.googlers.com","threadId":"60127","inReplyTo":"20230912193235.776292-1-gitster@pobox.com","subject":"Re: [PATCH v3 0/3] \"update-index --show-index-version\"","fromName":"Linus Arver","fromEmail":"linusa@google.com","sentAt":"2023-09-14T06:19:13Z","receivedAt":"2023-09-14T06:19:19Z","isPatch":true,"sender":{"key":"linus@ucla.edu","avatar":null},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n>\n> This iteration takes suggestions by Linus Arver; the tests added by\n> [2/3] have been clarified.\n>\n\nThis version LGTM, thanks!\n"},{"id":"481846","messageId":"xmqqjzssk4dm.fsf@gitster.g","threadId":"60127","inReplyTo":"owlypm2ljmzi.fsf@fine.c.googlers.com","subject":"Re: [PATCH v3 0/3] \"update-index --show-index-version\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-09-14T18:15:49Z","receivedAt":"2023-09-14T18:15:56Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Linus Arver <linusa@google.com> writes:\n\n> Junio C Hamano <gitster@pobox.com> writes:\n>\n>>\n>> This iteration takes suggestions by Linus Arver; the tests added by\n>> [2/3] have been clarified.\n>>\n>\n> This version LGTM, thanks!\n\nThanks.\n"},{"id":"484838","messageId":"20231114021839.8275-1-tenglong.tl@alibaba-inc.com","threadId":"60127","inReplyTo":"20230912193235.776292-3-gitster@pobox.com","subject":"[PATCH v3 2/3] update-index: add --show-index-version","fromName":"Teng Long","fromEmail":"dyroneteng@gmail.com","sentAt":"2023-11-14T02:18:38Z","receivedAt":"2023-11-14T02:18:51Z","isPatch":true,"sender":{"key":"dyroneteng@gmail.com","avatar":"https://avatars.githubusercontent.com/u/7803958?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> @@ -1181,15 +1183,20 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)\n>  \n>  \tgetline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf;\n>  \tif (preferred_index_format) {\n> -\t\tif (preferred_index_format < INDEX_FORMAT_LB ||\n> -\t\t    INDEX_FORMAT_UB < preferred_index_format)\n> +\t\tif (preferred_index_format < 0) {\n> +\t\t\tprintf(_(\"%d\\n\"), the_index.version);\n\nMaybe the \"%d\\n\" shouldn't be translated? :)\n\nThanks.\n"},{"id":"484843","messageId":"xmqq7cml11sv.fsf@gitster.g","threadId":"60127","inReplyTo":"20231114021839.8275-1-tenglong.tl@alibaba-inc.com","subject":"Re: [PATCH v3 2/3] update-index: add --show-index-version","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-11-14T02:55:28Z","receivedAt":"2023-11-14T02:55:35Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Teng Long <dyroneteng@gmail.com> writes:\n\n> Junio C Hamano <gitster@pobox.com> writes:\n>\n>> @@ -1181,15 +1183,20 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)\n>>  \n>>  \tgetline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf;\n>>  \tif (preferred_index_format) {\n>> -\t\tif (preferred_index_format < INDEX_FORMAT_LB ||\n>> -\t\t    INDEX_FORMAT_UB < preferred_index_format)\n>> +\t\tif (preferred_index_format < 0) {\n>> +\t\t\tprintf(_(\"%d\\n\"), the_index.version);\n>\n> Maybe the \"%d\\n\" shouldn't be translated? :)\n\nExcellent.\n"}]}