From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by dcvr.yhbt.net (Postfix) with ESMTP id 182B31F513 for ; Fri, 18 Aug 2023 23:38:28 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=pass (1024-bit key; unprotected) header.d=pobox.com header.i=@pobox.com header.a=rsa-sha256 header.s=sasl header.b=QOWLKCAm; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242814AbjHRXhz (ORCPT ); Fri, 18 Aug 2023 19:37:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242769AbjHRXhg (ORCPT ); Fri, 18 Aug 2023 19:37:36 -0400 Received: from pb-smtp1.pobox.com (pb-smtp1.pobox.com [64.147.108.70]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D580420C for ; Fri, 18 Aug 2023 16:37:34 -0700 (PDT) Received: from pb-smtp1.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 4ABA31A3B54; Fri, 18 Aug 2023 19:37:34 -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=6cUyhkD72BiUtI8oHTlZaQcwD o0CjWeruwuCrTCDqWw=; b=QOWLKCAmgiztziff9rj45oCb/f5jBCv9b38MEuT5R FZRJMCxNu3l91waEnhiPYsKKZYytejxw9Eyfx4DtdBfHOqdLZej1aU98UWy+SHQn g/Rv20WqAhCyLmMFnbm/I2nfXMXHvoPOrVBqnck3zFJja32MUxr33Qp9SIL2WM43 +A= Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 4342A1A3B53; Fri, 18 Aug 2023 19:37:34 -0400 (EDT) (envelope-from gitster@pobox.com) Received: from pobox.com (unknown [34.83.58.166]) (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 A9AC11A3B52; Fri, 18 Aug 2023 19:37:33 -0400 (EDT) (envelope-from gitster@pobox.com) From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH v2 2/3] update-index: add --show-index-version Date: Fri, 18 Aug 2023 16:37:28 -0700 Message-ID: <20230818233729.2766281-3-gitster@pobox.com> X-Mailer: git-send-email 2.42.0-rc2-7-gf9972720e9 In-Reply-To: <20230818233729.2766281-1-gitster@pobox.com> References: <20230818233729.2766281-1-gitster@pobox.com> MIME-Version: 1.0 X-Pobox-Relay-ID: 34952E6E-3E20-11EE-9029-78DCEB2EC81B-77302942!pb-smtp1.pobox.com Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org "git update-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. Signed-off-by: Junio C Hamano --- Documentation/git-update-index.txt | 6 +++++- builtin/update-index.c | 19 +++++++++++++------ t/t2107-update-index-basic.sh | 16 ++++++++++++++++ 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/Documentation/git-update-index.txt b/Documentation/git-updat= e-index.txt index a367f8d65a..3f204891ce 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` option, also reports 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 t= o JGit in 2020. Older editions of this manual page called it "relatively young", but it should be considered mature technology these days. =20 +--show-index-version:: + Report the index format version used by the on-disk index file. + See `--index-version` above. =20 -z:: Only meaningful with `--stdin` or `--index-info`; paths are diff --git a/builtin/update-index.c b/builtin/update-index.c index 5fab9ad2ec..e713e2a04c 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -1089,6 +1089,8 @@ int cmd_update_index(int argc, const char **argv, c= onst 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_("show 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) =20 getline_fn =3D 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 !=3D preferred_index_format) - the_index.cache_changed |=3D SOMETHING_CHANGED; - the_index.version =3D preferred_index_format; + } else { + if (the_index.version !=3D preferred_index_format) + the_index.cache_changed |=3D SOMETHING_CHANGED; + report(_("index-version: was %d, set to %d"), + the_index.version, preferred_index_format); + the_index.version =3D preferred_index_format; + } } =20 if (read_from_stdin) { diff --git a/t/t2107-update-index-basic.sh b/t/t2107-update-index-basic.s= h index 89b285fa3a..c78d1e9396 100755 --- a/t/t2107-update-index-basic.sh +++ b/t/t2107-update-index-basic.sh @@ -111,4 +111,20 @@ test_expect_success '--chmod=3D+x and chmod=3D-x in = the same argument list' ' test_cmp expect actual ' =20 +test_expect_success '--index-version' ' + git commit --allow-empty -m snap && + git reset --hard && + + git update-index --index-version 2 >actual && + test_must_be_empty actual && + + git update-index --show-index-version >actual && + echo 2 >expect && + test_cmp expect actual && + + git update-index --index-version 4 --verbose >actual && + echo "index-version: was 2, set to 4" >expect && + test_cmp expect actual +' + test_done --=20 2.42.0-rc2-7-gf9972720e9