From patchwork Thu Apr 7 16:37:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12805500 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 69C61C433F5 for ; Thu, 7 Apr 2022 16:37:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345761AbiDGQj3 (ORCPT ); Thu, 7 Apr 2022 12:39:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241362AbiDGQj0 (ORCPT ); Thu, 7 Apr 2022 12:39:26 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9299917B0C3 for ; Thu, 7 Apr 2022 09:37:26 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id q19so8674607wrc.6 for ; Thu, 07 Apr 2022 09:37:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=OcKuP5szKC9QdBAWkLw/2yWtY9M4uWGL+c5sLoq0NEA=; b=Oxo3tgZY7O3gutochnabTn6IghP/C78FCPhX+YQGOaxRrTZHU7L9rdti681cJU677F 9r9VR2wF5Yryxps3Ugx9GqRQh7yJRZbBVOr5P86yNpOisRiC1qNVpqtiibjUp5U7Sqfp nq8kcG2AuJU6VOMhP3TeuqrG5cWPHGo9dcCwuBEHnVTpixb8j2IeMmECe7SJPO/jrCkm CztQqs07Qvey4Wj4Gh4f9nZWvXsvCab37mLauEZqF3WbFdhhyXIAcWvjIXdsLlg4WwLp NgsDR2tWHkTJcJqTcKJ2KcUzmlHdzl0cVgdGTtKxyEHyITTrAZ4uAXc9SCU9DViCHk4g mHkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=OcKuP5szKC9QdBAWkLw/2yWtY9M4uWGL+c5sLoq0NEA=; b=QIJedaQ0AcU23/3k6RUG1HpLuL+9ZscCOGa25sanl2RMHuCbKKoNKryeCquyAc6JZ6 D4C6jCoePUMbmSpuw6ik+joZRa+eP0ARmVMq8MonIMawN/oOaVGh/+mGsk+QxFOm6oGR 0ILA17CdWQSDKaiCq5ZFQbghMPMQvxlzQe99LDZdAQubdoxxiuZTuBXI15aSSIhAELcK t1NALru1Q8CPiLNsBJAVlqmDbz+5tAVXhm4yfToIie9hCqkvBtTz7wR9S7ORU7mUV3v0 v9eS8XqKJ4XFs1lCd3is3hSSSzGBq3ZL49BtYX1ZVxBbvuZtDuVBUUyP5A01lIzkiEom 54CA== X-Gm-Message-State: AOAM5339Hd5f7KFUIIqqqjEXiJd7+TqUYLpgroqx+zaR0ZrICw/kv3e6 AwQxfRkadlEdTLAHYEI0hRg9B1vcF3w= X-Google-Smtp-Source: ABdhPJz4JkAtIxc6CP4mRgsqtxGvuINruv1S/R9x3XY3jtlWlwvdOMCMPy8GOPwxAvFX7nPn62fe+Q== X-Received: by 2002:a05:6000:3c7:b0:207:8c51:c07b with SMTP id b7-20020a05600003c700b002078c51c07bmr2371383wrg.17.1649349444882; Thu, 07 Apr 2022 09:37:24 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o17-20020a05600c4fd100b0038cd5074c83sm8597977wmq.34.2022.04.07.09.37.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 09:37:24 -0700 (PDT) Message-Id: <8c2fdb5a4fc3317c05324da54692036e36fc15f3.1649349442.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 07 Apr 2022 16:37:19 +0000 Subject: [PATCH 1/4] t1092: add compatibility tests for 'git show' Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: gitster@pobox.com, vdye@github.com, shaoxuan.yuan02@gmail.com, Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee Signed-off-by: Derrick Stolee --- t/t1092-sparse-checkout-compatibility.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh index 236ab530284..74792b5ebbc 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -1151,6 +1151,22 @@ test_expect_success 'clean' ' test_sparse_match test_path_is_dir folder1 ' +test_expect_success 'show (cached blobs/trees)' ' + init_repos && + + test_all_match git show :a && + test_all_match git show :deep/a && + test_sparse_match git show :folder1/a && + + # Asking "git show" for directories in the index + # does not work as implemented. The error message is + # different for a full checkout and a sparse checkout + # when the directory is outside of the cone. + test_all_match test_must_fail git show :deep/ && + test_must_fail git -C full-checkout show :folder1/ && + test_sparse_match test_must_fail git show :folder1/ +' + test_expect_success 'submodule handling' ' init_repos && From patchwork Thu Apr 7 16:37:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12805501 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 0F928C433EF for ; Thu, 7 Apr 2022 16:37:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345771AbiDGQja (ORCPT ); Thu, 7 Apr 2022 12:39:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345764AbiDGQj2 (ORCPT ); Thu, 7 Apr 2022 12:39:28 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93FA917E340 for ; Thu, 7 Apr 2022 09:37:27 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id p26-20020a05600c1d9a00b0038ccbff1951so4608365wms.1 for ; Thu, 07 Apr 2022 09:37:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=DzmUocZ4iuz9olzctKUfnjsf3/S6kuVMOEw1uEfYFOA=; b=aksUgH0vUkebEX+5Aguszj9/CTmqb23wV7dcoZPK5iEOMU0BotDk/aPolNSIO1EgB0 m+uDNWbQPFytpkriQrWZiBOIbZ4R6jQlgZO+R04HPQwRm+3wxX7aiVMQdxCnVUwRhN6t pWuXEODawGoFbUPKw9XY4KE66vLY/1Csbnzt98m1fISak0anka3U5Yp9IbrcJlUWOMKn C6Bon0yDp3hUdhWmoPlCUZYQPyw1WnqYGBZWD+XY+8bjeEOMu2dkU/s4OSFrFZhHDBjq L0MjOfHnQuVq9JQ7NC3Lb1gV7fKGqdG2bu6Q8bweH/Olp5qvlQkHQIIwpYaQh/onvJSw cu7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=DzmUocZ4iuz9olzctKUfnjsf3/S6kuVMOEw1uEfYFOA=; b=I64Szm6qOOmhgEvteT/ExEMKyHY2p6htyMH/xcDal6Xp9k2qtsok7CtK0lA8C6icB5 qoR1s6egWOmFDZaL+GArO44jATkY4XOp3lUp6bfJ07L6Lj+YDy9/2fyyoJlsTlSfn0EL akpoDU1YAYeXSEq4yTzqnuS9oYWWVaTfyRA9qBkws+/BPQHEW7ORhUty39dg2iSV22i3 KAOBgy7L/Arr8rHTbY64C2U7X7bYEl+GnBfDQliNX+13FJIE12GDKjLTJHGSTkE3pxz6 BnbIttcprFcTzFaStovBYJ1RX+Tigcdeetfdw4uic1kwEoG2oYxLnDH0cRJDdvUQLf0A sVew== X-Gm-Message-State: AOAM533JqG/DHkwkXlIV+eetFqlD9qpeTDvf7uM+uxxBuo4mo8DJw7Wh m6Sp4FHO4COOa1RzxsUirwSpOBj3lB8= X-Google-Smtp-Source: ABdhPJwbG/NDvxCoGrgGZG/nfY50naCIt6MDj4qr4HR6CdVbmaqt5RBV2rm41vdzyzSIVAAf+1ziKg== X-Received: by 2002:a1c:7411:0:b0:38c:b51e:8d7b with SMTP id p17-20020a1c7411000000b0038cb51e8d7bmr12991414wmc.148.1649349445865; Thu, 07 Apr 2022 09:37:25 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o8-20020a5d6488000000b002051f1028f6sm20766167wri.111.2022.04.07.09.37.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 09:37:25 -0700 (PDT) Message-Id: <27ab853a9b4f0a50880c92dd8949d6fe9b7f00ba.1649349442.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 07 Apr 2022 16:37:20 +0000 Subject: [PATCH 2/4] show: integrate with the sparse index Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: gitster@pobox.com, vdye@github.com, shaoxuan.yuan02@gmail.com, Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee The 'git show' command can take an input to request the state of an object in the index. This can lead to parsing the index in order to load a specific file entry. Without the change presented here, a sparse index would expand to a full one, taking much longer than usual to access a simple file. There is one behavioral change that happens here, though: we now can find a sparse directory entry within the index! Commands that previously failed because we could not find an entry in the worktree or index now succeed because we _do_ find an entry in the index. There might be more work to do to make other situations succeed when looking for an indexed tree, perhaps by looking at or updating the cache-tree extension as needed. These situations include having a full index or asking for a directory that is within the sparse-checkout cone (and hence is not a sparse directory entry in the index). For now, we demonstrate how the sparse index integration is extremely simple for files outside of the cone as well as directories within the cone. A later change will resolve this behavior around sparse directories. Signed-off-by: Derrick Stolee --- builtin/log.c | 5 +++++ t/t1092-sparse-checkout-compatibility.sh | 23 +++++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/builtin/log.c b/builtin/log.c index c211d66d1d0..8e2e9912ab9 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -661,6 +661,11 @@ int cmd_show(int argc, const char **argv, const char *prefix) init_log_defaults(); git_config(git_log_config, NULL); + if (the_repository->gitdir) { + prepare_repo_settings(the_repository); + the_repository->settings.command_requires_full_index = 0; + } + memset(&match_all, 0, sizeof(match_all)); repo_init_revisions(the_repository, &rev, prefix); git_config(grep_config, &rev.grep_filter); diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh index 74792b5ebbc..f6a14e08b81 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -1159,12 +1159,20 @@ test_expect_success 'show (cached blobs/trees)' ' test_sparse_match git show :folder1/a && # Asking "git show" for directories in the index - # does not work as implemented. The error message is - # different for a full checkout and a sparse checkout - # when the directory is outside of the cone. + # changes depending on the existence of a sparse index. test_all_match test_must_fail git show :deep/ && test_must_fail git -C full-checkout show :folder1/ && - test_sparse_match test_must_fail git show :folder1/ + test_must_fail git -C sparse-checkout show :folder1/ && + + git -C sparse-index show :folder1/ >actual && + git -C full-checkout show HEAD:folder1 >expect && + + # The output of "git show" includes the way we referenced the + # objects, so strip that out. + test_line_count = 4 actual && + tail -n 2 actual >actual-trunc && + tail -n 2 expect >expect-trunc && + test_cmp expect-trunc actual-trunc ' test_expect_success 'submodule handling' ' @@ -1388,6 +1396,13 @@ test_expect_success 'sparse index is not expanded: diff' ' ensure_not_expanded diff --cached ' +test_expect_success 'sparse index is not expanded: show' ' + init_repos && + + ensure_not_expanded show :a && + ensure_not_expanded show :deep/a +' + test_expect_success 'sparse index is not expanded: update-index' ' init_repos && From patchwork Thu Apr 7 16:37:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12805502 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 8DB48C433EF for ; Thu, 7 Apr 2022 16:37:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345764AbiDGQje (ORCPT ); Thu, 7 Apr 2022 12:39:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230315AbiDGQj3 (ORCPT ); Thu, 7 Apr 2022 12:39:29 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B403E17ECD2 for ; Thu, 7 Apr 2022 09:37:28 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id m30so8723128wrb.1 for ; Thu, 07 Apr 2022 09:37:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=Zqtjsthut8K8Cn5UbpKqIla74vKiYg8A4Ppw1nqvEY0=; b=CZMyz0rJCQYuLDmCIlBA4NKUHXp+p5OSQLNgVR8uRUbhnK9zTYEg+Uc49OOFnz/n5W WYDShKw/qGLwoOJ4T9GQm+d2UWZnj9CiMZi7j1jaZQqm1UJDenWVbRRw1SwmxPs22dbp V911RIOe5MoMVv1AKbvjQyUplH6cTn+W/2bWzDX0f7nsdUuDdhh4/Ktybz5UDOo6wGIt tso25xm/x9Byjxhq7D11hYIGh9jUsJihaOXoY5Lru7kCPji6XBoS0GGeCJ7IOGGuh6e6 TasO8G1E73pwe3faJx2ahrUj1ENVCcl026uZm1+2LQInQoAwOkE8q9kF7rpgaP0rgxl4 Uqhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=Zqtjsthut8K8Cn5UbpKqIla74vKiYg8A4Ppw1nqvEY0=; b=dnOjcU+A7ODCp3q8nyvB5tSy5oajQCE4DQH6kbvZu6eRa0Hqh/VU3tUDBcHqtwzVBQ LSHcOLFpDN946i1z84cpMY2ZOV4NvJTWbI/41BXiNPq5/Bxp62+EewBwk/gdJ7Tmfc4c e7NWxd9JHp/hWjMOO6QqV0Ea0FoC/AoP3mufeAILK8SfRNCZb8qrwGy53tZx/LjpKzD+ oiqwTbwN/uaFqLln1unb0CBCoUM5ZJh3WXhKnUVZ4g+UQbgA6jPed9r2X2uNPSeVB8ZO 74Wk42ni8/Bp2zyKUZzwe/DGR9bCdMBwfCH/Kc93s7UxdX/ZNLVHGhf54Kq+MXsLYjye vHCw== X-Gm-Message-State: AOAM533pw/1HLMLaeiR+8/T5XkZFYXngYE8pJfqbnaPaalgi8gQdpwpH v+BTCrPujAz2snPIXLoWfOW8CtKIUuM= X-Google-Smtp-Source: ABdhPJxhQ+kLaYmTrFqxPQNU7D3Lmke9r/i9t78dxoqrl4/gCb58I51XalrBE3TVVCTvNT2ZXKixDA== X-Received: by 2002:a05:6000:10c7:b0:206:135e:c84e with SMTP id b7-20020a05600010c700b00206135ec84emr11161327wrx.12.1649349446859; Thu, 07 Apr 2022 09:37:26 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id r4-20020a1c4404000000b0038e6fb9b4fesm8041341wma.48.2022.04.07.09.37.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 09:37:26 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Thu, 07 Apr 2022 16:37:21 +0000 Subject: [PATCH 3/4] object-name: reject trees found in the index Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: gitster@pobox.com, vdye@github.com, shaoxuan.yuan02@gmail.com, Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee The get_oid_with_context_1() method is used when parsing revision arguments. One particular case is to take a ":" string and search the index for the given path. In the case of a sparse index, this might find a sparse directory entry, in which case the contained object is a tree. In the case of a full index, this search within the index would fail. In order to maintain identical return state as in a full index, inspect the discovered cache entry to see if it is a sparse directory and reject it. This requires being careful around the only_to_die option to be sure we die only at the correct time. This changes the behavior of 'git show :', but does not bring it entirely into alignment with a full index case. It specifically hits the wrong error message within diagnose_invalid_index_path(). That error message will be corrected in a future change. Signed-off-by: Derrick Stolee --- object-name.c | 19 ++++++++++++++++++- t/t1092-sparse-checkout-compatibility.sh | 11 ++--------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/object-name.c b/object-name.c index f0e327f91f5..2dc5d2549b8 100644 --- a/object-name.c +++ b/object-name.c @@ -1881,6 +1881,20 @@ static char *resolve_relative_path(struct repository *r, const char *rel) rel); } +static int reject_tree_in_index(struct repository *repo, + int only_to_die, + const struct cache_entry *ce, + int stage, + const char *prefix, + const char *cp) +{ + if (!S_ISSPARSEDIR(ce->ce_mode)) + return 0; + if (only_to_die) + diagnose_invalid_index_path(repo, stage, prefix, cp); + return -1; +} + static enum get_oid_result get_oid_with_context_1(struct repository *repo, const char *name, unsigned flags, @@ -1955,9 +1969,12 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo, memcmp(ce->name, cp, namelen)) break; if (ce_stage(ce) == stage) { + free(new_path); + if (reject_tree_in_index(repo, only_to_die, ce, + stage, prefix, cp)) + return -1; oidcpy(oid, &ce->oid); oc->mode = ce->ce_mode; - free(new_path); return 0; } pos++; diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh index f6a14e08b81..9d32361110d 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -1164,15 +1164,8 @@ test_expect_success 'show (cached blobs/trees)' ' test_must_fail git -C full-checkout show :folder1/ && test_must_fail git -C sparse-checkout show :folder1/ && - git -C sparse-index show :folder1/ >actual && - git -C full-checkout show HEAD:folder1 >expect && - - # The output of "git show" includes the way we referenced the - # objects, so strip that out. - test_line_count = 4 actual && - tail -n 2 actual >actual-trunc && - tail -n 2 expect >expect-trunc && - test_cmp expect-trunc actual-trunc + test_must_fail git -C sparse-index show :folder1/ 2>err && + grep "is in the index, but not at stage 0" err ' test_expect_success 'submodule handling' ' From patchwork Thu Apr 7 16:37:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12805503 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 585C2C433FE for ; Thu, 7 Apr 2022 16:37:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232422AbiDGQjf (ORCPT ); Thu, 7 Apr 2022 12:39:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345765AbiDGQja (ORCPT ); Thu, 7 Apr 2022 12:39:30 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF79617E340 for ; Thu, 7 Apr 2022 09:37:29 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id w4so8633712wrg.12 for ; Thu, 07 Apr 2022 09:37:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=/C88YZUqkIZYHLcMzWANK+XL38MQDB2HjuEiQi7yNZ8=; b=Y+w7VApTLTFE//+qZf87SMvxlsToOYHwfdKFwu7o7LrNy+x0KKNlecFkAHJ7/krBpu 8MQO9ljP6Guzf/GYmN5094aabGu73AvCgCTxxzk55yYHLECvuFQ8nFgPGc535LtTYm9y 43N/WXLCp2Z4+fPSJCLnAi4mPJfqD92KokvOAgkzeJmCCJLX3YgIxUF70I2WHuTSm6xH NLl16/wovHKcYK+vynfDhW6KXrR2fOMBlIzThJ/QW9toTfCj7Xc1u55t6ru4ncy6eOQ/ /ZR/KeLgUnMqzEL6NJT1W3X6QlODZygVIMH03cci8F4i/Ec2G71a7jeLmeC2Ys4mmZPo 6sSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=/C88YZUqkIZYHLcMzWANK+XL38MQDB2HjuEiQi7yNZ8=; b=1vHdUUwcINOyLyO2UhFtYDc1Bo2uRCO4HZohRas1fzw3GLRa/NMfgwcdy7PaZhHLfx o53iTfgjvnaOh+RNOUBm5/6O+jGTC3Mqdq5IWVirm7WAribJOVY8Ac2Pf4NrnGTXbikv yyOnuzdR1L0cneDWwFQ96A4/ncsirZpxEaFy6tJPVOHB2n9vhLU3MudloNNGrvCLPt6A R2obDHjSiYq8NN/maZJe5ja8+6ZWkEXUTeyW1SwZy0StJLTOAJzxdHZPpxWFRKX38Ghb vGDnN/Q6lxwcScVg4PHFMWuj7ZG3lsllx4TQ9qxLymdPTYgqSkWP7+9HGhYdNrMi3U4A Sj2A== X-Gm-Message-State: AOAM530L/2IuMYDsfI1aj9XtHxHF2KQR3t/ITq4y6zyYpF61X7Qlb6R/ QeduxyVHw2RtbZW5bAwigWjGsS9yxLU= X-Google-Smtp-Source: ABdhPJyCcMjXg6nQuD+3mPw3BsVOY0khgonct2sUy6RpsOKGj3ZI9/7psGi5BPJUqIEFb5Qv9BsGTQ== X-Received: by 2002:adf:f58e:0:b0:206:162b:7b85 with SMTP id f14-20020adff58e000000b00206162b7b85mr11668534wro.261.1649349447942; Thu, 07 Apr 2022 09:37:27 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id k11-20020a5d6d4b000000b0020599079f68sm17394281wri.106.2022.04.07.09.37.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 09:37:27 -0700 (PDT) Message-Id: <99c09ccc2406e4f54c620bd7fb2d1205386e23a6.1649349442.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 07 Apr 2022 16:37:22 +0000 Subject: [PATCH 4/4] object-name: diagnose trees in index properly Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: gitster@pobox.com, vdye@github.com, shaoxuan.yuan02@gmail.com, Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee When running 'git show :' where '' is a directory, then there is a subtle difference between a full checkout and a sparse checkout. The error message from diagnose_invalid_index_path() reports whether the path is on disk or not. The full checkout will have the directory on disk, but the path will not be in the index. The sparse checokut could have the directory not exist, specifically when that directory is outside of the sparse-checkout cone. In the case of a sparse index, we have yet another state: the path can be a sparse directory in the index. In this case, the error message from diagnose_invalid_index_path() would erroneously say "path '' is in the index, but not at stage 0", which is false. Add special casing around sparse directory entries so we get to the correct error message. This requires two checks in order to get parity with the normal sparse-checkout case. Signed-off-by: Derrick Stolee --- object-name.c | 6 ++++-- t/t1092-sparse-checkout-compatibility.sh | 13 +++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/object-name.c b/object-name.c index 2dc5d2549b8..4d2746574cd 100644 --- a/object-name.c +++ b/object-name.c @@ -1832,7 +1832,8 @@ static void diagnose_invalid_index_path(struct repository *r, pos = -pos - 1; if (pos < istate->cache_nr) { ce = istate->cache[pos]; - if (ce_namelen(ce) == namelen && + if (!S_ISSPARSEDIR(ce->ce_mode) && + ce_namelen(ce) == namelen && !memcmp(ce->name, filename, namelen)) die(_("path '%s' is in the index, but not at stage %d\n" "hint: Did you mean ':%d:%s'?"), @@ -1848,7 +1849,8 @@ static void diagnose_invalid_index_path(struct repository *r, pos = -pos - 1; if (pos < istate->cache_nr) { ce = istate->cache[pos]; - if (ce_namelen(ce) == fullname.len && + if (!S_ISSPARSEDIR(ce->ce_mode) && + ce_namelen(ce) == fullname.len && !memcmp(ce->name, fullname.buf, fullname.len)) die(_("path '%s' is in the index, but not '%s'\n" "hint: Did you mean ':%d:%s' aka ':%d:./%s'?"), diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh index 9d32361110d..921cafb950a 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -1164,8 +1164,17 @@ test_expect_success 'show (cached blobs/trees)' ' test_must_fail git -C full-checkout show :folder1/ && test_must_fail git -C sparse-checkout show :folder1/ && - test_must_fail git -C sparse-index show :folder1/ 2>err && - grep "is in the index, but not at stage 0" err + test_sparse_match test_must_fail git show :folder1/ && + + # Change the sparse cone for an extra case: + run_on_sparse git sparse-checkout set deep/deeper1 && + + # deep/deeper2 is a sparse directory in the sparse index. + test_sparse_match test_must_fail git show :deep/deeper2/ && + + # deep/deeper2/deepest is not in the sparse index, but + # will trigger an index expansion. + test_sparse_match test_must_fail git show :deep/deeper2/deepest/ ' test_expect_success 'submodule handling' '