From patchwork Tue Sep 12 19:32:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13382082 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 365BDEE3F0F for ; Tue, 12 Sep 2023 19:32:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237662AbjILTcr (ORCPT ); Tue, 12 Sep 2023 15:32:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237640AbjILTcp (ORCPT ); Tue, 12 Sep 2023 15:32:45 -0400 Received: from pb-smtp2.pobox.com (pb-smtp2.pobox.com [64.147.108.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2A94CF for ; Tue, 12 Sep 2023 12:32:41 -0700 (PDT) Received: from pb-smtp2.pobox.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 295A819BDB3; Tue, 12 Sep 2023 15:32:41 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=mZyYNllfeSfywgCTqNYUbzM3V IOolQSRLgp5gdQkVKc=; b=RekdwNe97TddIiMzNO52rXjxnU3VR2VbBZXDVCHQY ARIMcxhwHgc/SQsnJZZ+EG087NtztSNFR7Q4s+mc9o+WwYXtblvii30ucBPhbNoy cYPI9TkP8qTa/BxXRy1y86FRFW5pJ2o5sy6DBzL1d+HgwiCUuCGhXU0AnWDngxG/ GY= Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id 2286B19BDB2; Tue, 12 Sep 2023 15:32:41 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.125.153.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp2.pobox.com (Postfix) with ESMTPSA id 8A0E119BDB1; Tue, 12 Sep 2023 15:32:40 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH v3 1/3] update-index doc: v4 is OK with JGit and libgit2 Date: Tue, 12 Sep 2023 12:32:33 -0700 Message-ID: <20230912193235.776292-2-gitster@pobox.com> X-Mailer: git-send-email 2.42.0-158-g94e83dcf5b In-Reply-To: <20230912193235.776292-1-gitster@pobox.com> References: <20230818233729.2766281-1-gitster@pobox.com> <20230912193235.776292-1-gitster@pobox.com> MIME-Version: 1.0 X-Pobox-Relay-ID: 231EA82C-51A3-11EE-9CC7-25B3960A682E-77302942!pb-smtp2.pobox.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Being invented in late 2012 no longer makes the index v4 format "relatively young". The support for the index version 4 was added to libgit2 with their 5625d86b (index: support index v4, 2016-05-17) and to JGit with their e9cb0a8e (DirCache: support index V4, 2020-08-10). Let's update the paragraph that discouraged its use for folks overly cautious about cross-tool compatibility. Helped-by: Oswald Buddenhagen Helped-by: Linus Arver Signed-off-by: Junio C Hamano --- Documentation/git-update-index.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Documentation/git-update-index.txt b/Documentation/git-update-index.txt index f4bb9c5daf..71d6ef9457 100644 --- a/Documentation/git-update-index.txt +++ b/Documentation/git-update-index.txt @@ -166,9 +166,11 @@ you will need to handle the situation manually. + Version 4 performs a simple pathname compression that reduces index 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 -October 2012). Other Git implementations such as JGit and libgit2 -may not support it yet. +time. Git supports it since version 1.8.0, released in October 2012, +and support for it was added to libgit2 in 2016 and to JGit in 2020. +Older versions of this manual page called it "relatively young", but +it should be considered mature technology these days. + -z:: Only meaningful with `--stdin` or `--index-info`; paths are From patchwork Tue Sep 12 19:32:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13382083 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C53C3EE3F0F for ; Tue, 12 Sep 2023 19:32:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237681AbjILTc4 (ORCPT ); Tue, 12 Sep 2023 15:32:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237671AbjILTcy (ORCPT ); Tue, 12 Sep 2023 15:32:54 -0400 Received: from pb-smtp21.pobox.com (pb-smtp21.pobox.com [173.228.157.53]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81E24E50 for ; Tue, 12 Sep 2023 12:32:46 -0700 (PDT) Received: from pb-smtp21.pobox.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id 0BA7E18299; Tue, 12 Sep 2023 15:32:46 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=cg6Hu9GK9XVINhl0alptALxxr ILsMKJDvHg3FRDYNes=; b=Wg0QQVp1vVKffWCaMubAjbfTlSOnNoHkUXSD437Hn ebsPSZrf5aWOfVpOfucayGZasxuPna/T5yQQcUMzORF30Y4sZWkMLvPH9p+Fa+Lw nR4uCQ2+soF9dCP5JW8MlmHmPyuJQeJx2XdLVWjdPgCH2U2sCCIToVWnb0BwQl3A gM= Received: from pb-smtp21.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id 03A8C18298; Tue, 12 Sep 2023 15:32:46 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.125.153.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp21.pobox.com (Postfix) with ESMTPSA id 7FC7B18297; Tue, 12 Sep 2023 15:32:42 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH v3 2/3] update-index: add --show-index-version Date: Tue, 12 Sep 2023 12:32:34 -0700 Message-ID: <20230912193235.776292-3-gitster@pobox.com> X-Mailer: git-send-email 2.42.0-158-g94e83dcf5b In-Reply-To: <20230912193235.776292-1-gitster@pobox.com> References: <20230818233729.2766281-1-gitster@pobox.com> <20230912193235.776292-1-gitster@pobox.com> MIME-Version: 1.0 X-Pobox-Relay-ID: 24494662-51A3-11EE-8F5A-A19503B9AAD1-77302942!pb-smtp21.pobox.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org "git update-index --index-version N" is used to set the index format version to a specific version, but there was no way to query the current version used in the on-disk index file. Teach the command a new "--show-index-version" option, and also teach the "--index-version N" option to report what the version was when run with the "--verbose" option. Helped-by: Linus Arver Signed-off-by: Junio C Hamano --- Documentation/git-update-index.txt | 6 +++++- builtin/update-index.c | 19 ++++++++++++------ t/t2107-update-index-basic.sh | 31 ++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 7 deletions(-) diff --git a/Documentation/git-update-index.txt b/Documentation/git-update-index.txt index 71d6ef9457..1271486ae9 100644 --- a/Documentation/git-update-index.txt +++ b/Documentation/git-update-index.txt @@ -162,7 +162,8 @@ you will need to handle the situation manually. 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 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 size by 30%-50% on large repositories, which results in faster load @@ -171,6 +172,9 @@ and support for it was added to libgit2 in 2016 and to JGit in 2020. 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:: Only meaningful with `--stdin` or `--index-info`; paths are diff --git a/builtin/update-index.c b/builtin/update-index.c index 5fab9ad2ec..8c3454c1c1 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -1089,6 +1089,8 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) resolve_undo_clear_callback), OPT_INTEGER(0, "index-version", &preferred_index_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, N_("enable or disable split index")), OPT_BOOL(0, "untracked-cache", &untracked_cache, @@ -1181,15 +1183,20 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf; if (preferred_index_format) { - if (preferred_index_format < INDEX_FORMAT_LB || - INDEX_FORMAT_UB < preferred_index_format) + if (preferred_index_format < 0) { + 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", preferred_index_format, INDEX_FORMAT_LB, INDEX_FORMAT_UB); - - if (the_index.version != preferred_index_format) - the_index.cache_changed |= SOMETHING_CHANGED; - the_index.version = preferred_index_format; + } else { + if (the_index.version != preferred_index_format) + the_index.cache_changed |= SOMETHING_CHANGED; + report(_("index-version: was %d, set to %d"), + the_index.version, preferred_index_format); + the_index.version = preferred_index_format; + } } if (read_from_stdin) { diff --git a/t/t2107-update-index-basic.sh b/t/t2107-update-index-basic.sh index 89b285fa3a..22f4c92399 100755 --- a/t/t2107-update-index-basic.sh +++ b/t/t2107-update-index-basic.sh @@ -111,4 +111,35 @@ test_expect_success '--chmod=+x and chmod=-x in the same argument list' ' 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 From patchwork Tue Sep 12 19:32:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13382084 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 00EE2EE3F0C for ; Tue, 12 Sep 2023 19:32:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237677AbjILTdA (ORCPT ); Tue, 12 Sep 2023 15:33:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237721AbjILTc4 (ORCPT ); Tue, 12 Sep 2023 15:32:56 -0400 Received: from pb-smtp1.pobox.com (pb-smtp1.pobox.com [64.147.108.70]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C215C1719 for ; Tue, 12 Sep 2023 12:32:49 -0700 (PDT) Received: from pb-smtp1.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 756851B4D58; Tue, 12 Sep 2023 15:32:46 -0400 (EDT) (envelope-from gitster@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=sasl; bh=8oMHeLJ3R9jnuUrahKNm5kbjt aWnA8A6i431j6iCyx4=; b=scml1zeTO/DqmIwk3Q09CksYZ59VbkkIBTt/MElaE ZGEojPpWZOL6+TDBzvcsdlW3Y9Ga0JtZW1pJefOQuODV33lDlQlo7AdiRoijUQ3E YM7yVP7YZgso+BofS7ONx1m/K88nfc3pC1/EEqI1TxDiLvYK+ZooBQ263FLnTx1L 14= Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 6D5131B4D56; Tue, 12 Sep 2023 15:32:46 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.125.153.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp1.pobox.com (Postfix) with ESMTPSA id D680B1B4D55; Tue, 12 Sep 2023 15:32:45 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH v3 3/3] test-tool: retire "index-version" Date: Tue, 12 Sep 2023 12:32:35 -0700 Message-ID: <20230912193235.776292-4-gitster@pobox.com> X-Mailer: git-send-email 2.42.0-158-g94e83dcf5b In-Reply-To: <20230912193235.776292-1-gitster@pobox.com> References: <20230818233729.2766281-1-gitster@pobox.com> <20230912193235.776292-1-gitster@pobox.com> MIME-Version: 1.0 X-Pobox-Relay-ID: 264994DA-51A3-11EE-84A6-78DCEB2EC81B-77302942!pb-smtp1.pobox.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As "git update-index --show-index-version" can do the same thing, the 'index-version' subcommand in the test-tool lost its reason to exist. Remove it and replace its use with the end-user facing 'git update-index --show-index-version'. Helped-by: Linus Arver Signed-off-by: Junio C Hamano --- Makefile | 1 - t/helper/test-index-version.c | 15 --------------- t/helper/test-tool.c | 1 - t/helper/test-tool.h | 1 - t/t1600-index.sh | 2 +- t/t1700-split-index.sh | 2 +- t/t2104-update-index-skip-worktree.sh | 6 +++--- 7 files changed, 5 insertions(+), 23 deletions(-) delete mode 100644 t/helper/test-index-version.c diff --git a/Makefile b/Makefile index e440728c24..5323c76aa0 100644 --- a/Makefile +++ b/Makefile @@ -808,7 +808,6 @@ TEST_BUILTINS_OBJS += test-hash-speed.o TEST_BUILTINS_OBJS += test-hash.o TEST_BUILTINS_OBJS += test-hashmap.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-lazy-init-name-hash.o TEST_BUILTINS_OBJS += test-match-trees.o diff --git a/t/helper/test-index-version.c b/t/helper/test-index-version.c deleted file mode 100644 index a06c45c1f8..0000000000 --- a/t/helper/test-index-version.c +++ /dev/null @@ -1,15 +0,0 @@ -#include "test-tool.h" -#include "cache.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; -} diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c index abe8a785eb..621ac3dd10 100644 --- a/t/helper/test-tool.c +++ b/t/helper/test-tool.c @@ -38,7 +38,6 @@ static struct test_cmd cmds[] = { { "hashmap", cmd__hashmap }, { "hash-speed", cmd__hash_speed }, { "hexdump", cmd__hexdump }, - { "index-version", cmd__index_version }, { "json-writer", cmd__json_writer }, { "lazy-init-name-hash", cmd__lazy_init_name_hash }, { "match-trees", cmd__match_trees }, diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h index ea2672436c..a641c3a81d 100644 --- a/t/helper/test-tool.h +++ b/t/helper/test-tool.h @@ -32,7 +32,6 @@ int cmd__getcwd(int argc, const char **argv); int cmd__hashmap(int argc, const char **argv); int cmd__hash_speed(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__lazy_init_name_hash(int argc, const char **argv); int cmd__match_trees(int argc, const char **argv); diff --git a/t/t1600-index.sh b/t/t1600-index.sh index 9368d82f7d..62e7fd1596 100755 --- a/t/t1600-index.sh +++ b/t/t1600-index.sh @@ -118,7 +118,7 @@ test_index_version () { fi && git add a && echo $EXPECTED_OUTPUT_VERSION >expect && - test-tool index-version <.git/index >actual && + git update-index --show-index-version >actual && test_cmp expect actual ) } diff --git a/t/t1700-split-index.sh b/t/t1700-split-index.sh index b4ab166369..a7b7263b35 100755 --- a/t/t1700-split-index.sh +++ b/t/t1700-split-index.sh @@ -43,7 +43,7 @@ test_expect_success 'enable split index' ' git config splitIndex.maxPercentChange 100 && git update-index --split-index && 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. if test "$indexversion" = "4" diff --git a/t/t2104-update-index-skip-worktree.sh b/t/t2104-update-index-skip-worktree.sh index b8686aabd3..0bab134d71 100755 --- a/t/t2104-update-index-skip-worktree.sh +++ b/t/t2104-update-index-skip-worktree.sh @@ -39,7 +39,7 @@ test_expect_success 'setup' ' ' 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' ' @@ -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 "$(test-tool index-version < .git/index)" = 3 + test "$(git update-index --show-index-version)" = 3 ' 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 "$(test-tool index-version < .git/index)" = 2 + test "$(git update-index --show-index-version)" = 2 ' test_done