From patchwork Tue Apr 26 20:43:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12827960 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 027FBC433F5 for ; Tue, 26 Apr 2022 20:43:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355117AbiDZUqg (ORCPT ); Tue, 26 Apr 2022 16:46:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350152AbiDZUqd (ORCPT ); Tue, 26 Apr 2022 16:46:33 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B749813A4C6 for ; Tue, 26 Apr 2022 13:43:24 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id w4so27021603wrg.12 for ; Tue, 26 Apr 2022 13:43:24 -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=eKhNkyMhgRnfUGNoBVKfSsj+CNHjdsl8iQZxz5mS1aZ1TxEUcWGl8S3eELp0OkGtbq be8m0bUe34lgyg9kcc2TZXf75MYDLzOPfOebjpLk9RiTiqs3bH51Wdo++XelM6qSSWdy oq3V3oHvNXfMs7o5qayITzC28rOSI3sKvSLi5p6VfofVVdg0n0V88AL4FCz0kNvKu3su C+5154NEDmr7tLHHcMnGdFxr3481ttr3CI4zHULacUu/g17KbsBiNDxILBfDDLjsztdr RRcFBi3+gOJ02Arqd2q54LXX1ygCTeXvjnb5LQ+xs68r+/l/tVZkfsTCe+MdNQdRMXZz zjjw== 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=sp0Jcxwm7OC7AgzNitCeslIagg68Bfiy31CW2SXfYnPoeoCQaEKz7TG69TwFyc4vQt k5Iq10nM6Mb1A0SZkgzWa7UJp2l0pSGQyS5fP102L116E0hBUF7tAk4eJpnuqa/whI07 dsh6Y5+zTNe7+LsfaLQvfpQjcoPbWFjfoV7cY1S0XKq8oRpki/yH9u3Oc9WF2faVJbbL oSVFaftLzuOwli9neeZ3rY/7v9uJJCwQ1PtqNYv3xR6ZoukEdieJ0LzSn1kEytjXSML4 5kqidMqUzRpEmNGdxyHbQBQiWzeHs0bY6OLWJSJ6hCHZKpBDHqs42eWa1MOpzXajky2t rvGA== X-Gm-Message-State: AOAM533QKEYXfJKtiDum3veEsFTLuFDRaKrvCQkmwsAPl4F88NTMK+KK irIMacw1k0U2kkN8eGbBhROlN4r2so4= X-Google-Smtp-Source: ABdhPJyP8CzccI/VI71TjIvzslkuc5AEbWBW07eKRESvDYCZ8vLoSBMu3Sj6uf3MdDC5gAyEmAY02w== X-Received: by 2002:a05:6000:3cc:b0:20a:df53:9a0e with SMTP id b12-20020a05600003cc00b0020adf539a0emr7535894wrg.264.1651005803043; Tue, 26 Apr 2022 13:43:23 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o6-20020adfca06000000b0020ae96f6ba8sm1510729wrh.65.2022.04.26.13.43.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Apr 2022 13:43:22 -0700 (PDT) Message-Id: <8c2fdb5a4fc3317c05324da54692036e36fc15f3.1651005800.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 26 Apr 2022 20:43:16 +0000 Subject: [PATCH v2 1/5] 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, Philip Oakley , Josh Steadmon , 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 Tue Apr 26 20:43:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12827961 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 A3D0AC433F5 for ; Tue, 26 Apr 2022 20:43:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355123AbiDZUqi (ORCPT ); Tue, 26 Apr 2022 16:46:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355093AbiDZUqe (ORCPT ); Tue, 26 Apr 2022 16:46:34 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C60E613AB5A for ; Tue, 26 Apr 2022 13:43:25 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id 129so39647wmz.0 for ; Tue, 26 Apr 2022 13:43:25 -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=U8VIyeB5pUxVlY98wG9v1/OCleHuGbhOKK2qfZecUFg=; b=D1PDYhzD77IMfaT+fCV2lihdFSLtUTROPn8mfNtcGPEkxH5KyVerzAqwAkzNhTRhtq gNd2hUNTSczgNaUnfC0Ueu6jvN/pmCLMESX219uO6JhWbIZEjwNxjn7NTtEQPQUBMR8M Ifxkf+vLRHCqhikzlF6T1/kAcMLkZZ7QbIQ0WxatcRvkWMNYmeyPZ8/55/IVVaZahJpK 6B47bsGau6xFc8j1Wzxrrsk9Q06tsmRqeHxqGpv+2FOuL409Z/F3pwdjBISfGUnbR48P XQSktJmI+i3TL9AWjuGUITSUvnTEwryt3V7Wm0kmkOQRG8OB3zerJkwYa0VOVYjbRVNl wj5w== 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=U8VIyeB5pUxVlY98wG9v1/OCleHuGbhOKK2qfZecUFg=; b=gM9tQii0gi0XjwFLyxEOpjprsFM5J9CK6ykxU2kcaDFT1bjCOIHqRk6XpSvj3BM46l OgJMBBeMM7duigkU6DfLEsoK0pgLFTAZLUJ30R1tFEtS4LCqbu14ac37Y8g5vsr+QHoD kXXa+lJYI6ppiwmbo3PEZ21TqQ6k93pI9V5vNokakI/YM4r56331uYn6wmme767xsgqH Nsg5zVxYXfAeQmOPAZnKgO/9e1l/3R6e+Eoxp8jtiRJhrfSsFJWjxMMKYxWW0DpkXSAY 2RFsksI7jyQwgSBcCtTxVDVTkTJEVnfccHoM3HxdCHA16Dn046eUR05EwKEMMFcaw6dS hbwQ== X-Gm-Message-State: AOAM531IKwC3e2xid+RftfuPoeDlHJuOfEV/6xxoujAJvm15ifiq9veB 0Xdv7I7lCPel4wZLIi960Z2vKAWMDr0= X-Google-Smtp-Source: ABdhPJx9PCzW753WsAkQZyUwmuut6ibWs+06xuEp3cHV+bM6yax5sRa507EKAR4+iKxdZVieX6KE2g== X-Received: by 2002:a05:600c:3ca3:b0:392:990b:af11 with SMTP id bg35-20020a05600c3ca300b00392990baf11mr22923881wmb.173.1651005804109; Tue, 26 Apr 2022 13:43:24 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id w12-20020adf8bcc000000b002060e3da33fsm12148381wra.66.2022.04.26.13.43.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Apr 2022 13:43:23 -0700 (PDT) Message-Id: <2e9d47ab09ba8bca0166ca21bd936f2b4b5bb75e.1651005800.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 26 Apr 2022 20:43:17 +0000 Subject: [PATCH v2 2/5] 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, Philip Oakley , Josh Steadmon , 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 | 24 ++++++++++++++++++++---- 2 files changed, 25 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..3506c0216f0 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -1159,12 +1159,21 @@ 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. + # had different behavior 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 +1397,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 Tue Apr 26 20:43:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12827962 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 03E04C433EF for ; Tue, 26 Apr 2022 20:43:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355124AbiDZUqj (ORCPT ); Tue, 26 Apr 2022 16:46:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355112AbiDZUqf (ORCPT ); Tue, 26 Apr 2022 16:46:35 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA71213BD5C for ; Tue, 26 Apr 2022 13:43:26 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id i5so8015541wrc.13 for ; Tue, 26 Apr 2022 13:43: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=gYlLzFMHqODA8gTlaQ/jbLsyHtI/RYrbZiZNYlxIPPI=; b=HUrMyxSj0GlzMSdx7ZtMP9sUEXwDAk3FNTAOfiAzC6/KikPabfrgL1Y+gYftvUqTvz zguQvjCxTItpspS4F0rjoH8k9n4fukxyh/KfMlYdFFH71MjHFRo7taJIcbqpVczkLJUG i57Rju9OpicA7UPmASieCKwkyMUgxCuBqiDEcff7t8yGnCmIa/dWU2BqpE+UmgS/8b9n L3yOJHdvxtJA4SDY60URpSUKI6C+eEqI0E3GSS6PE2gim3alUILjQd0Lxs4USHhU075T bKAtrZgiif3+Qh7gNa8IIjIS16zW0L1aJdI9Czccbjx4p4Pj+Gv37ou+KQ+Rs3Vf9+J7 oHPQ== 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=gYlLzFMHqODA8gTlaQ/jbLsyHtI/RYrbZiZNYlxIPPI=; b=wcneqYZYSizxboQ4cYfsgxfn69i5qWcyVAqD916pfcHmM7Ux7VYz7L/YOLdzByEduc YXh7/vj3KDAuOFuyh8dfyvyiQx04gLC6nLmTHcR9lHGmCLiO0BOwfzNGiU+6ecycEdzc DKdDMH6YM2UPly92BIjinjfQGi/uLTSBHxAw+m4CwPkjNJonclkL3ou+mkbDma4VJELu N2rJJ2KITJBBvm8lFhXiilCmz+Ut9i/2XAhl/ob9J88/1UF+jjinhByUVKBnN58BM1Fe H5SA52gRw7glSaCvh1utRHT2PM+vaciiWbsb3z3HQxemU/Agadn2jKFhv5hCWJVr165o lXLw== X-Gm-Message-State: AOAM530ht83AxYGQH4j2yCiEH5A0Vqwt6V65O7CWR/cZ/4A1A+U7qmkF xQMjft7bViXw/R/irPP5pNwqh8YQgDE= X-Google-Smtp-Source: ABdhPJys7Alq6fwBs842i066mPMODuBDPrAXZdUoKOJluYzy67fP7TBvP3ln9dnLQE7Cv1zWxG1vkg== X-Received: by 2002:a5d:4311:0:b0:205:f439:cbf0 with SMTP id h17-20020a5d4311000000b00205f439cbf0mr20187817wrq.164.1651005805050; Tue, 26 Apr 2022 13:43:25 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id r14-20020a0560001b8e00b00205918bd86esm12231608wru.78.2022.04.26.13.43.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Apr 2022 13:43:24 -0700 (PDT) Message-Id: <5a7561637f0d845df23b47c9bed2ba74bbc5f07c.1651005800.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 26 Apr 2022 20:43:18 +0000 Subject: [PATCH v2 3/5] 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, Philip Oakley , Josh Steadmon , 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 3506c0216f0..08c9cfd359e 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -1165,15 +1165,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 Tue Apr 26 20:43: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: 12827963 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 647B0C433EF for ; Tue, 26 Apr 2022 20:43:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355112AbiDZUqq (ORCPT ); Tue, 26 Apr 2022 16:46:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355118AbiDZUqg (ORCPT ); Tue, 26 Apr 2022 16:46:36 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDEE913C2B0 for ; Tue, 26 Apr 2022 13:43:27 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id bg25so11543wmb.4 for ; Tue, 26 Apr 2022 13:43: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=t/VUuHcA6LJhMV7Mx2fkYJRQHiQGtg82S/Ba52cN1qA=; b=fp3eu5RzJx0BHRZV4B1TyVmsxfpH3qSxkzNPF80cqdlaUfD2RbHdxijVmfUkJ32vG7 ZUl56tm/XXeiF7J33mTco2KQLlW7QkFk6qsadiOfrpWpd27nFJw2/bZ6vkJh4GtXBmVR XgdkjXm6vp4fbZNnTIEN5Z8KwZUemtwM2EgvKiaxxZtQLAlLn/2kIsJet2/Il7FSb1UD 0lBuUcapvURDEFQhQt54q/0su+qoBjU7SNBkJkw5YW/kyOaoR2cBUIXx6kdUeXRk6/L3 v/YLvNZfjdVd0vNBZjH8WHVLiVWBbCRKGb5MfnZLv49zujwkHeoB6BuSENIsGUvOzZC6 K2hQ== 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=t/VUuHcA6LJhMV7Mx2fkYJRQHiQGtg82S/Ba52cN1qA=; b=cNUypbeyVA08A7+jjRkj6O9GjDTlZKjglNmsO6YvinarSdUlqJQXsbuIpq1XdNsOSd yPbO10DMFcaVl2u5njYDTvd40sH/0ZKZ2TcM/bc0iz9judAg+noegWpTPzEGZhRGvRaR MGtQB57LnUQXvNAKMIDO4ms+0r4CYX+PdKvG63L4gdof9IgQR0JdsKJBtyGHy0rBW6ch 4LcyT4RqwITqnCuS3GIkmk4pffmH+EI98AlyuDt4p6YZWRGWMVFSGeI1XdUgdHmaX+8A 9B71vUpzSYswtoS2NWlQbfR/0UlO7a1+YiZKGFSYI2nQVmT/O0JYT10QZJN89cn/obv2 ukqQ== X-Gm-Message-State: AOAM532KIKkrL8DIWfT19vJGmxrEuWhqxlo3fb6GG7YEeCnJnclU2nxf f6ne09wsAitQn7Fle8XquU9398tW4+w= X-Google-Smtp-Source: ABdhPJzYIwdfjOgy08REixBT3TR6N5yl2Fxa3ENN9uHOK0nhvSAfiUB3u5AjDQbwW2Z9IrhR1q7PBw== X-Received: by 2002:a7b:cd97:0:b0:38f:f785:ff8 with SMTP id y23-20020a7bcd97000000b0038ff7850ff8mr31590091wmj.44.1651005806106; Tue, 26 Apr 2022 13:43:26 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id f13-20020a0560001a8d00b0020aab7cefc4sm12460288wry.46.2022.04.26.13.43.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Apr 2022 13:43:25 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Tue, 26 Apr 2022 20:43:19 +0000 Subject: [PATCH v2 4/5] 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, Philip Oakley , Josh Steadmon , 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 checkout 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 | 18 ++++++++++++------ 2 files changed, 16 insertions(+), 8 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 08c9cfd359e..fa1d5603605 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -1158,15 +1158,21 @@ test_expect_success 'show (cached blobs/trees)' ' test_all_match git show :deep/a && test_sparse_match git show :folder1/a && - # Asking "git show" for directories in the index - # had different behavior depending on the existence - # of a sparse index. + # The error message differs depending on whether + # the directory exists in the worktree. test_all_match test_must_fail git show :deep/ && test_must_fail git -C full-checkout show :folder1/ && - test_must_fail git -C sparse-checkout show :folder1/ && + test_sparse_match test_must_fail git show :folder1/ && - test_must_fail git -C sparse-index show :folder1/ 2>err && - grep "is in the index, but not at stage 0" err + # 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' ' From patchwork Tue Apr 26 20:43: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: 12827964 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 6FCE4C433FE for ; Tue, 26 Apr 2022 20:43:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355128AbiDZUqs (ORCPT ); Tue, 26 Apr 2022 16:46:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355122AbiDZUqh (ORCPT ); Tue, 26 Apr 2022 16:46:37 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC8DE13C65D for ; Tue, 26 Apr 2022 13:43:28 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id j15so13821305wrb.2 for ; Tue, 26 Apr 2022 13:43: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=GfXMeHCQb9cUCMVaqBi6pfGj7gRjow9+K2YTy4zFUtI=; b=imMhMY4t6r6OzN0F2OgLkO4E88gCnq8ZkN0qo0R0hzpALJ6Oisvl/LP0meH9Sys3UE JC6Cjxn5beAwsdRMC10B0Hun/ODC6VXx4MdVvuxAXqZa2wvUpxxECUOlkrLNPkvx987m OJAtKU7I9w/MablmRr1V3QmrZ15kU3zBYXUiLWJMOYiGnZ2d8sI/YFTAfpjRs5tDdqS+ BO9eB2Qo2b68j26E7WeQ5QACNOQCrF5DHliqggJvFXkgOGJvNlRM8e6rqh2epLUIAfLn o8LzdfdSSQCncntv8aj9sHvoGPShzgZEYZvmLpwoqS9GoKIZWFUde83JNbXTnvQy7MHF LEBw== 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=GfXMeHCQb9cUCMVaqBi6pfGj7gRjow9+K2YTy4zFUtI=; b=JghR5xyAFEjtThZiAKAd9pkM0ZwwBXDGP2VDfGT0BmbBrL4/YxGJuysrpu13AAlvbZ ZRlvB73piIGZAqjheuVjudpJrjSVaTUj6IJ5gF/eh185QKIVv1Vx9a8eFpi0BA4oPXjy PZ5FVfmiqc24yQ81aBR+G6UgMcqpQK73JKI+I6gP76tJSGR+l8MHcapCT0GKCPRIAGAO HWGcP/PRYLsf97cwkN5j0U8ShL0UI7/n716v2Bbwwj+MoeAvXAGRgb2oUPYz/5aaPs29 Ug0y2RecJn4Y951f5qOL9601pMMYmPvOYLEgLKKan4fcy3MiWoVxrr2nv0+TBB9NZsHe MIjA== X-Gm-Message-State: AOAM532IwHRy8EE7iPQfkbU+W7r+lbf2DLadw1kQLwvrJnfUK/AAk+HP UNdikiIQ3FDquNLiFH+imWw/4fL7Jd0= X-Google-Smtp-Source: ABdhPJwOeydAAsbBUwahqFVmTAGGRSaYAgZ9gRo04jiTZ7x88HPIJZaWK+efTcs9OT/SX/0K7vq64A== X-Received: by 2002:a5d:64e6:0:b0:20a:d88b:f631 with SMTP id g6-20020a5d64e6000000b0020ad88bf631mr11056166wri.441.1651005807038; Tue, 26 Apr 2022 13:43:27 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o9-20020adf8b89000000b0020adeb916d8sm5081299wra.30.2022.04.26.13.43.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Apr 2022 13:43:26 -0700 (PDT) Message-Id: <69efe637a18786b289db79971e9e49137306b57c.1651005800.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 26 Apr 2022 20:43:20 +0000 Subject: [PATCH v2 5/5] rev-parse: integrate with sparse index Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: gitster@pobox.com, vdye@github.com, shaoxuan.yuan02@gmail.com, Philip Oakley , Josh Steadmon , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee It is not obvious that the 'git rev-parse' builtin would use the sparse index, but it is possible to parse paths out of the index using the ":" syntax. The 'git rev-parse' output is only the OID of the object found at that location, but otherwise behaves similarly to 'git show :'. This includes the failure conditions on directories and the error messages depending on whether a path is in the worktree or not. The only code change required is to change the command_requires_full_index setting in builtin/rev-parse.c, and we can re-use many existing 'git show' tests for the rev-parse case. Signed-off-by: Derrick Stolee --- builtin/rev-parse.c | 3 ++ t/t1092-sparse-checkout-compatibility.sh | 45 +++++++++++++----------- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index 8480a59f573..4fc6185b2d1 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -723,6 +723,9 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) prefix = setup_git_directory(); git_config(git_default_config, NULL); did_repo_setup = 1; + + prepare_repo_settings(the_repository); + the_repository->settings.command_requires_full_index = 0; } if (!strcmp(arg, "--")) { diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh index fa1d5603605..93bcfd20bbc 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -1151,29 +1151,32 @@ test_expect_success 'clean' ' test_sparse_match test_path_is_dir folder1 ' -test_expect_success 'show (cached blobs/trees)' ' - init_repos && +for builtin in show rev-parse +do + test_expect_success "$builtin (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 && + test_all_match git $builtin :a && + test_all_match git $builtin :deep/a && + test_sparse_match git $builtin :folder1/a && - # The error message differs depending on whether - # the directory exists in the worktree. - 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/ && + # The error message differs depending on whether + # the directory exists in the worktree. + test_all_match test_must_fail git $builtin :deep/ && + test_must_fail git -C full-checkout $builtin :folder1/ && + test_sparse_match test_must_fail git $builtin :folder1/ && - # Change the sparse cone for an extra case: - run_on_sparse git sparse-checkout set deep/deeper1 && + # 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 is a sparse directory in the sparse index. + test_sparse_match test_must_fail git $builtin :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/ -' + # deep/deeper2/deepest is not in the sparse index, but + # will trigger an index expansion. + test_sparse_match test_must_fail git $builtin :deep/deeper2/deepest/ + " +done test_expect_success 'submodule handling' ' init_repos && @@ -1396,11 +1399,13 @@ test_expect_success 'sparse index is not expanded: diff' ' ensure_not_expanded diff --cached ' -test_expect_success 'sparse index is not expanded: show' ' +test_expect_success 'sparse index is not expanded: show and rev-parse' ' init_repos && ensure_not_expanded show :a && - ensure_not_expanded show :deep/a + ensure_not_expanded show :deep/a && + ensure_not_expanded rev-parse :a && + ensure_not_expanded rev-parse :deep/a ' test_expect_success 'sparse index is not expanded: update-index' '