From patchwork Tue Jan 4 17:36:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12703724 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 5674EC433F5 for ; Tue, 4 Jan 2022 17:37:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235799AbiADRhH (ORCPT ); Tue, 4 Jan 2022 12:37:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235767AbiADRhE (ORCPT ); Tue, 4 Jan 2022 12:37:04 -0500 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 692B8C061761 for ; Tue, 4 Jan 2022 09:37:04 -0800 (PST) Received: by mail-wm1-x32c.google.com with SMTP id l4so23745931wmq.3 for ; Tue, 04 Jan 2022 09:37:04 -0800 (PST) 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=6m2WCFlbDEH3Qi6Apwp4WNApLrFFTqGiR5cvu5IYYvw=; b=Oex9vZkahlmHqldm3LzqORKW5JZe3TtDVEQolrzO0MMqfnFScRbpomIyrLeyDDctrw 1DAFBc2wYmkljcQwDEGN38rkxgeOe78xxFwAUFA0scHTES2rLjGNsR79hdxywA6SogXP AvNwns4sLMzy/MGihRVhPq6z04q/ca6IETsHcHka5kQObYyLnTd2iLwBLgL8iC5o7ePz 4z8HknwX3GKr2GeAL0seXSfqGvNxY7dMliW5tmmleShAZ+VirIoh/1wBQvAm+qZoNffd LI7lvVyeeRZq1/QtGBM795RRVE6ozo4YNYOaKBiTzbvhiyzVK8+EW1KfuZU+X4hPpauN w0Yw== 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=6m2WCFlbDEH3Qi6Apwp4WNApLrFFTqGiR5cvu5IYYvw=; b=4K4rDZbvh5S0fw24znpDt+vpLUjmf0QQytu+CIHrNA0X9Dp/xy70h9tOHZ0Cmtdfy2 cBm+YTWuD3YDBupPE0sAYoBkls69qrxxMsYGom8rYXGklgZG/GUqb2+rAhB0W2HbvR0V YR4R8DxdhBMlZ1jSg0kdQeR9gAWAiQz6dj0zvu/D7e8AmnH7SSeyddkvri0f/E4+YGde hyUPXk7ea7RgDiivacSaxQ1W1MPuMh3rsWVLfYELspROy6orahsNDCQrbk+ApUpZAxoz Lafp8MV/eQq2052ZklBbWSrBvnLoeqdsgXTfWntYHN0h8DbG+9twDAv3mGheJQXiABos Aezg== X-Gm-Message-State: AOAM530gSPc2zmXwX7r8x/FnF+PTNsUqQ7Km6e3xEUeMiT09s2nPFvQM 7MM0gCJqi0fPvEvPaXEUIgQVcR1f+fA= X-Google-Smtp-Source: ABdhPJy0OPGpqXTBaxmKrDki+lIbYRT636CU3JTrQ8tg05yz5hxHl/wMNu1LiS7UoUYMTsUfA4phpQ== X-Received: by 2002:a05:600c:3844:: with SMTP id s4mr42700143wmr.124.1641317822717; Tue, 04 Jan 2022 09:37:02 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id r20sm5567wmd.37.2022.01.04.09.37.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jan 2022 09:37:02 -0800 (PST) Message-Id: In-Reply-To: References: Date: Tue, 04 Jan 2022 17:36:52 +0000 Subject: [PATCH 1/9] reset: fix validation in sparse index test Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: stolee@gmail.com, newren@gmail.com, gitster@pobox.com, Victoria Dye , Victoria Dye Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Victoria Dye From: Victoria Dye Update t1092 test 'reset with pathspecs outside sparse definition' to verify index contents. The use of `rev-parse` verifies the contents of HEAD, not the index, providing no real validation of the reset results. Conversely, `ls-files` reports the contents of the index (OIDs, flags, filenames), which are then compared across checkouts to ensure compatible index states. Fixes 741a2c9ffa (reset: expand test coverage for sparse checkouts, 2021-09-27). Signed-off-by: Victoria Dye --- t/t1092-sparse-checkout-compatibility.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh index 49f70a65692..d5167e7ed69 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -596,13 +596,11 @@ test_expect_success 'reset with pathspecs outside sparse definition' ' test_sparse_match git reset update-folder1 -- folder1 && git -C full-checkout reset update-folder1 -- folder1 && - test_sparse_match git status --porcelain=v2 && - test_all_match git rev-parse HEAD:folder1 && + test_all_match git ls-files -s -- folder1 && test_sparse_match git reset update-folder2 -- folder2/a && git -C full-checkout reset update-folder2 -- folder2/a && - test_sparse_match git status --porcelain=v2 && - test_all_match git rev-parse HEAD:folder2/a + test_all_match git ls-files -s -- folder2/a ' test_expect_success 'reset with wildcard pathspec' ' From patchwork Tue Jan 4 17:36:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12703725 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 12453C433EF for ; Tue, 4 Jan 2022 17:37:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235809AbiADRhI (ORCPT ); Tue, 4 Jan 2022 12:37:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235660AbiADRhF (ORCPT ); Tue, 4 Jan 2022 12:37:05 -0500 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17A79C061761 for ; Tue, 4 Jan 2022 09:37:05 -0800 (PST) Received: by mail-wm1-x32b.google.com with SMTP id k66-20020a1ca145000000b00345fa984108so1838135wme.2 for ; Tue, 04 Jan 2022 09:37:05 -0800 (PST) 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=7Y1eVqZYE9BacgGrfH4O//tMC0Ck7M/KSJNB61BWioo=; b=PDjnaXRL4DyTNOilngmCcvGg58xaPM+u5JldREuWXnVq+3sUMsunw79E0JbRKY6a7T 3TftDp+zej05B5c0onGCvfR+pQn3EbtkJ1NRji4supcILpg3eUDrYya/kDvbU8t0gHqk H4A4cmoK/LJdzOIjaxMgJfxIXU71ywSoRVyVyFNRh8QmAnSBbT1aigoFr5Pw7OcyIXxc E1o77ooKwUVXsJ2/ow/2t+sLsxD+gxWfPDAaFBIALIdMEju+zcgGhxD7awaMwKDMRB0Z BjDkZAiLnf2KGfRrHbIKyZVehDYf0x5GzTM+XqwA8XbyuTVTsBwCA757D7aXt6ypuNkc 4haQ== 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=7Y1eVqZYE9BacgGrfH4O//tMC0Ck7M/KSJNB61BWioo=; b=FNMk4DgFUKF5vB9l7r+Bq0Ma45DInbg5mmHZFAoNtDRlsvkD+4kysXxIfRq6DFDKvS 2UNWEVLg6mm7m9CFAM4spbTpFpJII5rL/SImhcGbdDZLVf/RCPpU8sFwM49118L3NVCJ kFhZE1yceZA1uFP0H5/vq/9sqcKqo4rtMgFQ4s87prR/OaYMw4bFYe+QtXPU/saarXmh USqqsbkLOFQuhZ/C68Pe76hkeKGm2ZisvhTDWRzxRTg1FPn6PS1tNyEXDeNqn3LgRSHO 1dSXspTUKLe08OD3f1wFzv0AJCgaThutBy9FRmveqM9ThHHqbx8kP4315Xi/h0t0atnX LoTw== X-Gm-Message-State: AOAM5325iPZg8tg5ET+GzKub5LlVRn1+VDqZm/8PK2kNsJRpp5OueVa1 FQPcqvz4OxkSmay4eGGnbJcXGS+fjyM= X-Google-Smtp-Source: ABdhPJxdZLzM7loakHtXUwd+dCbH8nlhvDr0Bi0GX4iIY6WIph86+WgBU/gWOWCVeRosdMWJzUWYCA== X-Received: by 2002:a05:600c:34ca:: with SMTP id d10mr43963766wmq.133.1641317823426; Tue, 04 Jan 2022 09:37:03 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z5sm37599015wru.87.2022.01.04.09.37.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jan 2022 09:37:03 -0800 (PST) Message-Id: <0194d894c2f9c5ae4bbaac4cd6fca89933a04789.1641317820.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 04 Jan 2022 17:36:53 +0000 Subject: [PATCH 2/9] reset: reorder wildcard pathspec conditions Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: stolee@gmail.com, newren@gmail.com, gitster@pobox.com, Victoria Dye , Victoria Dye Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Victoria Dye From: Victoria Dye Rearrange conditions in method determining whether index expansion is necessary when a pathspec is specified for `git reset`, placing less expensive condition first. Additionally, add details & examples to related code comments to help with readability. Helped-by: Elijah Newren Signed-off-by: Victoria Dye --- builtin/reset.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/builtin/reset.c b/builtin/reset.c index b1ff699b43a..79b40385b99 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -204,10 +204,16 @@ static int pathspec_needs_expanded_index(const struct pathspec *pathspec) /* * Special case: if the pattern is a path inside the cone * followed by only wildcards, the pattern cannot match - * partial sparse directories, so we don't expand the index. + * partial sparse directories, so we know we don't need to + * expand the index. + * + * Examples: + * - in-cone/foo***: doesn't need expanded index + * - not-in-cone/bar*: may need expanded index + * - **.c: may need expanded index */ - if (path_in_cone_mode_sparse_checkout(item.original, &the_index) && - strspn(item.original + item.nowildcard_len, "*") == item.len - item.nowildcard_len) + if (strspn(item.original + item.nowildcard_len, "*") == item.len - item.nowildcard_len && + path_in_cone_mode_sparse_checkout(item.original, &the_index)) continue; for (pos = 0; pos < active_nr; pos++) { From patchwork Tue Jan 4 17:36:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12703726 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 C16E4C433F5 for ; Tue, 4 Jan 2022 17:37:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235819AbiADRhK (ORCPT ); Tue, 4 Jan 2022 12:37:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235792AbiADRhG (ORCPT ); Tue, 4 Jan 2022 12:37:06 -0500 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A71EAC061784 for ; Tue, 4 Jan 2022 09:37:05 -0800 (PST) Received: by mail-wr1-x429.google.com with SMTP id q16so77677534wrg.7 for ; Tue, 04 Jan 2022 09:37:05 -0800 (PST) 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=nYf5xAjH38pG53d5lWxnBkNiDBQQR8OOEeDq2g67RQA=; b=kaJRpEvOiJgLTRcVdOXZHwTbiveIulEF46Y/5cDX5nTbmVpxD9kKLYErp+Ly1XEmBk vCIS/DpSjMPtPlNTzqWNkllAnu/4iOUCPHGDLQhgl+eTIXhly23rtTSUkggeBd6Ff03p z4cekQHln9Ghc1H03CGO+QK8ugqj6DdbpQ6BKw2ilG68zfBac6lHucl2ZkEMZ+tmdr7q BW/GBHrgc+rq5KcWzMVZZLhS0pXxddUTUDr6n0uRYbbtQylAH1ZzMdP1aa5wN//cTgYM wHDAIYb5m0IUhSQConPoxaYxH+iiLVfjHy18RcEZ6kFVWFVKVroyhfDNuPNmp6/L5CWy 9sKA== 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=nYf5xAjH38pG53d5lWxnBkNiDBQQR8OOEeDq2g67RQA=; b=RtFbQaxQwA9uVFasqi2kepsVXFshdD7r5dQvtpGgzWX6HipYOpszpbR8u8v/zkKm7A 3H39Hv90H7KEBksv0biis8db/kOoMItUaqNsCBBOaMfpLfiihJ12ef8iAzZzdSQ8qItv K0luFIar31o0Z1PsEYx8jGk4OIAqMwEqIN1brVPHn7bj61M5KhyGigofAhQilpdj/g9R oErc9lsy+/E7dN+RLt/Q0VibJSdzSGeH7vB02tDbBjqExAMDFne5uyX4pf/O7L8Bk1WF Tq2lplMpXIIA2KGaulxLGiqGXXOPmBAyPXOKw7TMMn+8iGgnqx1z/oNR+gm0sY9z4yPZ qyZA== X-Gm-Message-State: AOAM5323fPXesUQMqysFq5yHWgPwjamXCG6XaSR/40GouWpTBJpjezlI 3v0jxN//xv7jbN7A2To8entHQN6MNFw= X-Google-Smtp-Source: ABdhPJyx5BC7f0gw0ce/l4vw0X7xOEPxOdMSn6HYWJDwpLDuI7nKbOcUyWo5XCB9vvSVhTuEH7DO0w== X-Received: by 2002:a5d:456a:: with SMTP id a10mr44302515wrc.670.1641317824155; Tue, 04 Jan 2022 09:37:04 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id p5sm39957790wrn.111.2022.01.04.09.37.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jan 2022 09:37:03 -0800 (PST) Message-Id: <52aec13d18e339024e350733ee9d0b5c6b9008e6.1641317820.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 04 Jan 2022 17:36:54 +0000 Subject: [PATCH 3/9] clean: integrate with sparse index Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: stolee@gmail.com, newren@gmail.com, gitster@pobox.com, Victoria Dye , Victoria Dye Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Victoria Dye From: Victoria Dye Remove full index requirement for `git clean` and test to ensure the index is not expanded in `git clean`. Add to existing test for `git clean` to verify cleanup of untracked files in sparse directories is consistent between sparse index and non-sparse index checkouts. Signed-off-by: Victoria Dye --- builtin/clean.c | 3 +++ t/t1092-sparse-checkout-compatibility.sh | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/builtin/clean.c b/builtin/clean.c index 98a2860409b..5628fc7103e 100644 --- a/builtin/clean.c +++ b/builtin/clean.c @@ -983,6 +983,9 @@ int cmd_clean(int argc, const char **argv, const char *prefix) dir.flags |= DIR_KEEP_UNTRACKED_CONTENTS; } + prepare_repo_settings(the_repository); + the_repository->settings.command_requires_full_index = 0; + if (read_cache() < 0) die(_("index file corrupt")); diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh index d5167e7ed69..05587361452 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -764,23 +764,42 @@ test_expect_success 'clean' ' test_all_match git commit -m "ignore bogus files" && run_on_sparse mkdir folder1 && + run_on_all mkdir -p deep/untracked-deep && run_on_all touch folder1/bogus && + run_on_all touch folder1/untracked && + run_on_all touch deep/untracked-deep/bogus && + run_on_all touch deep/untracked-deep/untracked && test_all_match git status --porcelain=v2 && test_all_match git clean -f && test_all_match git status --porcelain=v2 && test_sparse_match ls && test_sparse_match ls folder1 && + run_on_all test_path_exists folder1/bogus && + run_on_all test_path_is_missing folder1/untracked && + run_on_all test_path_exists deep/untracked-deep/bogus && + run_on_all test_path_exists deep/untracked-deep/untracked && + + test_all_match git clean -fd && + test_all_match git status --porcelain=v2 && + test_sparse_match ls && + test_sparse_match ls folder1 && + run_on_all test_path_exists folder1/bogus && + run_on_all test_path_exists deep/untracked-deep/bogus && + run_on_all test_path_is_missing deep/untracked-deep/untracked && test_all_match git clean -xf && test_all_match git status --porcelain=v2 && test_sparse_match ls && test_sparse_match ls folder1 && + run_on_all test_path_is_missing folder1/bogus && + run_on_all test_path_exists deep/untracked-deep/bogus && test_all_match git clean -xdf && test_all_match git status --porcelain=v2 && test_sparse_match ls && test_sparse_match ls folder1 && + run_on_all test_path_is_missing deep/untracked-deep/bogus && test_sparse_match test_path_is_dir folder1 ' @@ -920,6 +939,8 @@ test_expect_success 'sparse-index is not expanded' ' # Wildcard identifies only full sparse directories, no index expansion ensure_not_expanded reset deepest -- folder\* && + ensure_not_expanded clean -fd && + ensure_not_expanded checkout -f update-deep && test_config -C sparse-index pull.twohead ort && ( From patchwork Tue Jan 4 17:36:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12703727 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 34C1CC433F5 for ; Tue, 4 Jan 2022 17:37:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235806AbiADRhM (ORCPT ); Tue, 4 Jan 2022 12:37:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235795AbiADRhG (ORCPT ); Tue, 4 Jan 2022 12:37:06 -0500 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 60426C061761 for ; Tue, 4 Jan 2022 09:37:06 -0800 (PST) Received: by mail-wr1-x433.google.com with SMTP id r17so77630302wrc.3 for ; Tue, 04 Jan 2022 09:37:06 -0800 (PST) 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=r+HDwPBBJOFCam6auFZ9MSDne2TvgbgGFhd94QCrogs=; b=f4hAtTrb/hN11XliGhtyk9mxbmdgbhOi93AusdHUeXo0Ze0agN/ae8LUmpgspPb2m6 IC1zXGUiWpj7aFriTnIyJSxpWtU3+81KvuYULTxkMdKpgAZB0n/8Xu5oGih3GXt2fFvq CpQydEF64qQZvlgE+uxOXxFKBnZscokxHjPg5QxFPoo0edW3oWdhwCjolFJAS06oax/q 9vOqb9SuvZqHgKfjHut6/+jQsCLsGT+CR4lVmEQK1AwOJBb3L0AeVejMo1p4dljroVGA rP8FT2ydTDABz1+oqo6e06cBG7rpwWbSIDgiIkLgjYKMOPOLt1o9N/tkN698tNcGGDGc AEDQ== 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=r+HDwPBBJOFCam6auFZ9MSDne2TvgbgGFhd94QCrogs=; b=Nqqz+PEHAW9qoUZXR7g2/OUAVPb9R250dt8BkVPxFDfzGlCC4nw/fhg3WrlrupgV8R QtxsbUoV1oQ0AsiEbXvU7pNGpS21tq/UbGHOInXzNbTrcSnnUMQjMx9p5mCAvX0hlWnK ex68XZPfNlwGOelugTr8CufcM/jBc5jXUkWILXYa7Qwi3avWwvs7a7MtyeT30Tfz2FWn Oh+t0+niGlmbq15o7dxvFrSoR9wPDnCNKP9MzBECEtcR2LenZrm392vozCeHVbhL77dg OQVwBOTTwNN5v0aUSHrQ4IaheoCX32MI1N1L0ZOX/XzXDQKo17eEMLn7IZcWdJl9AWc/ kxkw== X-Gm-Message-State: AOAM530dj5EuVfCs+M4ZO9jEZ8leWHM/ibcGANbhSJcKFxTCOuMrPxeL 8iz5g+/HQyIqx4afY+x3nXpxgXaLPhI= X-Google-Smtp-Source: ABdhPJyj6GL1H+ODYwLNnnur5Jbgv6zJ3M8RzdKSck92eD5IAxScYtL3yjybp6VetuAVZrE8NjqHSw== X-Received: by 2002:a5d:6d8c:: with SMTP id l12mr44375295wrs.365.1641317824829; Tue, 04 Jan 2022 09:37:04 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id e13sm27898wmq.10.2022.01.04.09.37.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jan 2022 09:37:04 -0800 (PST) Message-Id: In-Reply-To: References: Date: Tue, 04 Jan 2022 17:36:55 +0000 Subject: [PATCH 4/9] checkout-index: expand sparse checkout compatibility tests Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: stolee@gmail.com, newren@gmail.com, gitster@pobox.com, Victoria Dye , Victoria Dye Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Victoria Dye From: Victoria Dye Add tests to cover `checkout-index`, with a focus on cases interesting in a sparse checkout (e.g., files specified outside sparse checkout definition). New tests are intended to serve as a baseline for expected behavior and performance when integrating `checkout-index` with the sparse index. Signed-off-by: Victoria Dye --- t/perf/p2000-sparse-operations.sh | 1 + t/t1092-sparse-checkout-compatibility.sh | 54 ++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/t/perf/p2000-sparse-operations.sh b/t/perf/p2000-sparse-operations.sh index cb777c74a24..54f8602f3c1 100755 --- a/t/perf/p2000-sparse-operations.sh +++ b/t/perf/p2000-sparse-operations.sh @@ -117,5 +117,6 @@ test_perf_on_all git diff test_perf_on_all git diff --cached test_perf_on_all git blame $SPARSE_CONE/a test_perf_on_all git blame $SPARSE_CONE/f3/a +test_perf_on_all git checkout-index -f --all test_done diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh index 05587361452..db7ad41109b 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -755,6 +755,60 @@ test_expect_success 'cherry-pick with conflicts' ' test_all_match test_must_fail git cherry-pick to-cherry-pick ' +test_expect_success 'checkout-index inside sparse definition' ' + init_repos && + + run_on_all rm -f deep/a && + test_all_match git checkout-index -- deep/a && + test_all_match git status --porcelain=v2 && + + echo test >>new-a && + run_on_all cp ../new-a a && + test_all_match test_must_fail git checkout-index -- a && + test_all_match git checkout-index -f -- a && + test_all_match git status --porcelain=v2 +' + +test_expect_success 'checkout-index outside sparse definition' ' + init_repos && + + # File does not exist on disk yet for sparse checkouts, so checkout-index + # succeeds without -f + test_sparse_match git checkout-index -- folder1/a && + test_cmp sparse-checkout/folder1/a sparse-index/folder1/a && + test_cmp sparse-checkout/folder1/a full-checkout/folder1/a && + + run_on_sparse rm -rf folder1 && + echo test >new-a && + run_on_sparse mkdir -p folder1 && + run_on_all cp ../new-a folder1/a && + + test_all_match test_must_fail git checkout-index -- folder1/a && + test_all_match git checkout-index -f -- folder1/a && + test_cmp sparse-checkout/folder1/a sparse-index/folder1/a && + test_cmp sparse-checkout/folder1/a full-checkout/folder1/a +' + +test_expect_success 'checkout-index with folders' ' + init_repos && + + # Inside checkout definition + test_all_match test_must_fail git checkout-index -f -- deep/ && + + # Outside checkout definition + test_all_match test_must_fail git checkout-index -f -- folder1/ +' + +# NEEDSWORK: even in sparse checkouts, checkout-index --all will create all +# files (even those outside the sparse definition) on disk. However, these files +# don't appear in the percentage of tracked files in git status. +test_expect_failure 'checkout-index --all' ' + init_repos && + + test_all_match git checkout-index --all && + test_sparse_match test_path_is_missing folder1 +' + test_expect_success 'clean' ' init_repos && From patchwork Tue Jan 4 17:36:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12703728 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 446B7C433EF for ; Tue, 4 Jan 2022 17:37:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235855AbiADRhO (ORCPT ); Tue, 4 Jan 2022 12:37:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235801AbiADRhH (ORCPT ); Tue, 4 Jan 2022 12:37:07 -0500 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 F3416C061784 for ; Tue, 4 Jan 2022 09:37:06 -0800 (PST) Received: by mail-wr1-x432.google.com with SMTP id s1so77668342wra.6 for ; Tue, 04 Jan 2022 09:37:06 -0800 (PST) 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=b3gnaly0SbDZimTJYjT7z4OkRmcrHnGxz9j7WSSRCTU=; b=mPga0qRWn9YPxtW0LZVAA7pbgyDkYlONwpwdj1RIDkf/OL332OxoJUlS3w2qBbaXKS mocQ3whZZ71mDRV5oFF/G8JqAMSB6YelxebUdGvV4OIYiSmY/X7HoclmAvrRcBcX//Sg V5ZZjXnpHn+I3t2k6Rdeufh4SsQyH/KkFR4Qz1TwReZgVuPUgLe0eeKczkfjZjI8hMe+ aGxFETcG07LjYb2ThJJgj8ofxuckuOnKevQN73/z5K0ANypXrQY+lnnDLbOXsZ+fP+SR LV/hwxAQPj+GHg0MLM8h1rSwFzbN3qYCG79H866qaLyt+QvgWsKbunZmLa8/woVzDNF0 27PA== 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=b3gnaly0SbDZimTJYjT7z4OkRmcrHnGxz9j7WSSRCTU=; b=GpFn9UR4KnGU0gcnv238rucP0GN9yFd/Ldg9RKW+e/Lz7rMQm054O10Ma65hSP1jlT /RBRdMPLBYuX2DV8yhymcpIXKOVHafazOJwWZ3cX0me+NieSRTueAU/r1TwlofUkXpJ1 TRSibpZgn1Xe9WzQpwwh/f9iscldkj1UdwEDV9GGk7OkGS5grpBVnddWXW+azMKK2a0m wTN+2m4OjyVICofAngolEH1iFbX8xeodWlz9Rv8mL/kj9qmgSg3rlUifap01CUDfEFgG qGm7z1A9qmQpfdSZ+KG2l5BCvjARAi5BWagSQ15fL1yPg3JORzGM+qSH0oY/wuzQTWnL fWoQ== X-Gm-Message-State: AOAM530bjwg8eeQTE/lnjiXqtx7gl1ZE52Zzbf4f5mN7Wu8IgnxgtlqN D7H3fDeWgY2wWWFREzpg/ndQrJYhOOw= X-Google-Smtp-Source: ABdhPJymJIliEYxHx9q0d0I5cnFsK/LdQAQLKn3PkhpVDzncaG7+jYEbPLtreljtZfQu+gPOazhrWA== X-Received: by 2002:adf:e791:: with SMTP id n17mr41161194wrm.719.1641317825403; Tue, 04 Jan 2022 09:37:05 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id y3sm38664303wrq.12.2022.01.04.09.37.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jan 2022 09:37:05 -0800 (PST) Message-Id: In-Reply-To: References: Date: Tue, 04 Jan 2022 17:36:56 +0000 Subject: [PATCH 5/9] checkout-index: add --ignore-skip-worktree-bits option Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: stolee@gmail.com, newren@gmail.com, gitster@pobox.com, Victoria Dye , Victoria Dye Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Victoria Dye From: Victoria Dye Update `checkout-index --all` to no longer refresh files that have the `skip-worktree` bit set. The newly-added `--ignore-skip-worktree-bits` option, when used with `--all`, maintains the old behavior and checks out all files regardless of `skip-worktree`. The ability to toggle whether files should be checked-out based on `skip-worktree` already exists in `git checkout` and `git restore` (both of which have an `--ignore-skip-worktree-bits` option). Adding the option to `checkout-index` (and changing the corresponding default behavior to respect the `skip-worktree` bit) is especially helpful for sparse-checkout: it prevents inadvertent creation of *all* files outside the sparse definition on disk and eliminates the need to expand a sparse index by default when using the `--all` option. Internal usage of `checkout-index` in `git stash` and `git filter-branch` do not make explicit use of files with `skip-worktree` enabled, so `--ignore-skip-worktree-bits` is not added to them. Signed-off-by: Victoria Dye --- Documentation/git-checkout-index.txt | 11 +++++++++-- builtin/checkout-index.c | 12 ++++++++++-- t/t1092-sparse-checkout-compatibility.sh | 10 +++++----- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/Documentation/git-checkout-index.txt b/Documentation/git-checkout-index.txt index 4d33e7be0f5..2815f3d4b19 100644 --- a/Documentation/git-checkout-index.txt +++ b/Documentation/git-checkout-index.txt @@ -12,6 +12,7 @@ SYNOPSIS 'git checkout-index' [-u] [-q] [-a] [-f] [-n] [--prefix=] [--stage=|all] [--temp] + [--ignore-skip-worktree-bits] [-z] [--stdin] [--] [...] @@ -37,8 +38,9 @@ OPTIONS -a:: --all:: - checks out all files in the index. Cannot be used - together with explicit filenames. + checks out all files in the index except for those with the + skip-worktree bit set (see `--ignore-skip-worktree-bits`). + Cannot be used together with explicit filenames. -n:: --no-create:: @@ -59,6 +61,11 @@ OPTIONS write the content to temporary files. The temporary name associations will be written to stdout. +--ignore-skip-worktree-bits:: + Check out all files, including those with the skip-worktree bit + set. Note: may only be used with `--all`; skip-worktree is + ignored when explicit filenames are specified. + --stdin:: Instead of taking list of paths from the command line, read list of paths from the standard input. Paths are diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c index e21620d964e..2053a80103a 100644 --- a/builtin/checkout-index.c +++ b/builtin/checkout-index.c @@ -7,6 +7,7 @@ #define USE_THE_INDEX_COMPATIBILITY_MACROS #include "builtin.h" #include "config.h" +#include "dir.h" #include "lockfile.h" #include "quote.h" #include "cache-tree.h" @@ -116,7 +117,7 @@ static int checkout_file(const char *name, const char *prefix) return -1; } -static int checkout_all(const char *prefix, int prefix_length) +static int checkout_all(const char *prefix, int prefix_length, int ignore_skip_worktree) { int i, errs = 0; struct cache_entry *last_ce = NULL; @@ -125,6 +126,8 @@ static int checkout_all(const char *prefix, int prefix_length) ensure_full_index(&the_index); for (i = 0; i < active_nr ; i++) { struct cache_entry *ce = active_cache[i]; + if (!ignore_skip_worktree && ce_skip_worktree(ce)) + continue; if (ce_stage(ce) != checkout_stage && (CHECKOUT_ALL != checkout_stage || !ce_stage(ce))) continue; @@ -176,6 +179,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix) int i; struct lock_file lock_file = LOCK_INIT; int all = 0; + int ignore_skip_worktree = 0; int read_from_stdin = 0; int prefix_length; int force = 0, quiet = 0, not_new = 0; @@ -185,6 +189,8 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix) struct option builtin_checkout_index_options[] = { OPT_BOOL('a', "all", &all, N_("check out all files in the index")), + OPT_BOOL(0, "ignore-skip-worktree-bits", &ignore_skip_worktree, + N_("do not skip files with skip-worktree set")), OPT__FORCE(&force, N_("force overwrite of existing files"), 0), OPT__QUIET(&quiet, N_("no warning for existing files and files not in index")), @@ -247,6 +253,8 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix) if (all) die("git checkout-index: don't mix '--all' and explicit filenames"); + if (ignore_skip_worktree) + die("git checkout-index: don't mix '--ignore-skip-worktree-bits' and explicit filenames"); if (read_from_stdin) die("git checkout-index: don't mix '--stdin' and explicit filenames"); p = prefix_path(prefix, prefix_length, arg); @@ -280,7 +288,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix) } if (all) - err |= checkout_all(prefix, prefix_length); + err |= checkout_all(prefix, prefix_length, ignore_skip_worktree); if (pc_workers > 1) err |= run_parallel_checkout(&state, pc_workers, pc_threshold, diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh index db7ad41109b..fad61d96107 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -799,14 +799,14 @@ test_expect_success 'checkout-index with folders' ' test_all_match test_must_fail git checkout-index -f -- folder1/ ' -# NEEDSWORK: even in sparse checkouts, checkout-index --all will create all -# files (even those outside the sparse definition) on disk. However, these files -# don't appear in the percentage of tracked files in git status. -test_expect_failure 'checkout-index --all' ' +test_expect_success 'checkout-index --all' ' init_repos && test_all_match git checkout-index --all && - test_sparse_match test_path_is_missing folder1 + test_sparse_match test_path_is_missing folder1 && + + test_all_match git checkout-index --ignore-skip-worktree-bits --all && + test_all_match test_path_exists folder1 ' test_expect_success 'clean' ' From patchwork Tue Jan 4 17:36:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12703729 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 4955EC433FE for ; Tue, 4 Jan 2022 17:37:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235865AbiADRhP (ORCPT ); Tue, 4 Jan 2022 12:37:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235802AbiADRhI (ORCPT ); Tue, 4 Jan 2022 12:37:08 -0500 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C035CC061761 for ; Tue, 4 Jan 2022 09:37:07 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id r17so77630395wrc.3 for ; Tue, 04 Jan 2022 09:37:07 -0800 (PST) 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=3TI+OW+dvOnQ18MHZSF2GtHsiaIDojtYMQWA72iibOQ=; b=MiUq/Tt51FUTR49oGEYxa5pyQG/OyuNG8+972g81PVi+1sMBD4Kpg+alGG+igaDciJ DjheHs4cfUtdeBheGnenfFxhms6pIBjdv8CeFE+hK3OQjU94UwxktvcJ5FK8H/Ugooqf yZez4TqXG4MUXg151072+W12aEtUqfOMiYGZQN94Zf0r8xiL+izexpriTIcsODvDi1sp OdfoWUQLlpWXCSRHYBO4lSYGBAN4UNNdqoDpekYAHhlcW41XQUj3Ulo/Tu06+6mkuRO7 24upqpQCLuZ9qE+Bm0UWXTX05nLnPtr33qdUBl/labA4girQbm7IsnDUEdcYeEBpiaHo 3q0g== 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=3TI+OW+dvOnQ18MHZSF2GtHsiaIDojtYMQWA72iibOQ=; b=Qp8lYnlYBF0E7HQbDCWTl2e2+M9pF4oDpiSsjWcN+qU4FbrQvnaEdwbPK/bHx4dyaD xzarAFNZjvGZFKIISCVnz+3uQ9hWzDu44YntmUyEnk8i/g877cZz5P2MzmxoEyvVesxy cZNAsU/fjSNNEQZrdUIxoU4YWxzcG/gs67tPJSS2dsJYUdT03WCkBk2ScHebg0gzFAOu RDkx0lZwZK3OIIHnBR8R+tnnmOTuxXvCdPWlr9bAxO3MqVhIQStHvFHzObd1kvhZK4Er cS+kQFTuy65KeExf0X9C0sVV7Md2H5SJ7GSqodCAmRvLS9KqBysj31AwmVsBTZcGICYk KoOQ== X-Gm-Message-State: AOAM532PVSx53tDAdqGmIh+sHoNiAcZs/Tq07hXZ/gPIT02MPw8JJrx+ X3i5IB5O0LMFbVkStokC7WTd+zfnDIw= X-Google-Smtp-Source: ABdhPJz2S6XYWHOtfCCFtWYxzowbpRZKpXdsgLuFtjHHG/wz6HugyIrryOGzCosyW2IkB0h63e5vkQ== X-Received: by 2002:adf:9bdb:: with SMTP id e27mr43774587wrc.417.1641317826108; Tue, 04 Jan 2022 09:37:06 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o3sm25082wmr.15.2022.01.04.09.37.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jan 2022 09:37:05 -0800 (PST) Message-Id: <18c00fc9dd373bd5cfb527cb7d672a5a1b3b0588.1641317820.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 04 Jan 2022 17:36:57 +0000 Subject: [PATCH 6/9] checkout-index: integrate with sparse index Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: stolee@gmail.com, newren@gmail.com, gitster@pobox.com, Victoria Dye , Victoria Dye Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Victoria Dye From: Victoria Dye Add repository settings to allow usage of the sparse index. When using the `--all` option, sparse directories are ignored by default due to the `skip-worktree` flag, so there is no need to expand the index. If `--ignore-skip-worktree-bits` is specified, the index is expanded in order to check out all files. When checking out individual files, existing behavior in a full index is to exit with an error if a directory is specified (as the directory name will not match an index entry). However, it is possible in a sparse index to match a directory name to a sparse directory index entry, but checking out that sparse directory still results in an error on checkout. To reduce some potential confusion for users, `checkout_file(...)` explicitly exits with an informative error if provided with a sparse directory name. The test corresponding to this scenario verifies the error message, which now differs between sparse index and non-sparse index checkouts. Signed-off-by: Victoria Dye --- builtin/checkout-index.c | 28 ++++++++++++++++++++++-- t/t1092-sparse-checkout-compatibility.sh | 11 +++++++++- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c index 2053a80103a..9c5657ccf22 100644 --- a/builtin/checkout-index.c +++ b/builtin/checkout-index.c @@ -66,6 +66,7 @@ static int checkout_file(const char *name, const char *prefix) int namelen = strlen(name); int pos = cache_name_pos(name, namelen); int has_same_name = 0; + int is_file = 0; int did_checkout = 0; int errs = 0; @@ -79,6 +80,9 @@ static int checkout_file(const char *name, const char *prefix) break; has_same_name = 1; pos++; + if (S_ISSPARSEDIR(ce->ce_mode)) + break; + is_file = 1; if (ce_stage(ce) != checkout_stage && (CHECKOUT_ALL != checkout_stage || !ce_stage(ce))) continue; @@ -107,6 +111,8 @@ static int checkout_file(const char *name, const char *prefix) fprintf(stderr, "git checkout-index: %s ", name); if (!has_same_name) fprintf(stderr, "is not in the cache"); + else if (!is_file) + fprintf(stderr, "is a sparse directory"); else if (checkout_stage) fprintf(stderr, "does not exist at stage %d", checkout_stage); @@ -122,10 +128,25 @@ static int checkout_all(const char *prefix, int prefix_length, int ignore_skip_w int i, errs = 0; struct cache_entry *last_ce = NULL; - /* TODO: audit for interaction with sparse-index. */ - ensure_full_index(&the_index); for (i = 0; i < active_nr ; i++) { struct cache_entry *ce = active_cache[i]; + + if (S_ISSPARSEDIR(ce->ce_mode)) { + if (!ce_skip_worktree(ce)) + BUG("sparse directory '%s' does not have skip-worktree set", ce->name); + + /* + * If the current entry is a sparse directory and skip-worktree + * entries are being checked out, expand the index and continue + * the loop on the current index position (now pointing to the + * first entry inside the expanded sparse directory). + */ + if (ignore_skip_worktree) { + ensure_full_index(&the_index); + ce = active_cache[i]; + } + } + if (!ignore_skip_worktree && ce_skip_worktree(ce)) continue; if (ce_stage(ce) != checkout_stage @@ -218,6 +239,9 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix) git_config(git_default_config, NULL); prefix_length = prefix ? strlen(prefix) : 0; + prepare_repo_settings(the_repository); + the_repository->settings.command_requires_full_index = 0; + if (read_cache() < 0) { die("invalid cache"); } diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh index fad61d96107..6ecf1f2bf8e 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -796,7 +796,14 @@ test_expect_success 'checkout-index with folders' ' test_all_match test_must_fail git checkout-index -f -- deep/ && # Outside checkout definition - test_all_match test_must_fail git checkout-index -f -- folder1/ + # Note: although all tests fail (as expected), the messaging differs. For + # non-sparse index checkouts, the error is that the "file" does not appear + # in the index; for sparse checkouts, the error is explicitly that the + # entry is a sparse directory. + run_on_all test_must_fail git checkout-index -f -- folder1/ && + test_cmp full-checkout-err sparse-checkout-err && + ! test_cmp full-checkout-err sparse-index-err && + grep "is a sparse directory" sparse-index-err ' test_expect_success 'checkout-index --all' ' @@ -965,6 +972,8 @@ test_expect_success 'sparse-index is not expanded' ' echo >>sparse-index/untracked.txt && ensure_not_expanded add . && + ensure_not_expanded checkout-index -f a && + ensure_not_expanded checkout-index -f --all && for ref in update-deep update-folder1 update-folder2 update-deep do echo >>sparse-index/README.md && From patchwork Tue Jan 4 17:36:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12703730 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 4A8D4C433F5 for ; Tue, 4 Jan 2022 17:37:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235844AbiADRhQ (ORCPT ); Tue, 4 Jan 2022 12:37:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235816AbiADRhI (ORCPT ); Tue, 4 Jan 2022 12:37:08 -0500 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69161C061799 for ; Tue, 4 Jan 2022 09:37:08 -0800 (PST) Received: by mail-wr1-x429.google.com with SMTP id t26so77637068wrb.4 for ; Tue, 04 Jan 2022 09:37:08 -0800 (PST) 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=PAqOT23epdiguINfFEHggxfPg7Qga4S5NUH6UrpRNnM=; b=i6zZxRTQHhBw0QmE7hiol7XbUdUonnX3xbl2Qpukm3kyTJr2H01wPySGLWR2DbuvJs PsBU0VgWObSPEPTypoo9tcogFQ7I6+pHMKCpdiUXmOd1R5rmkhHLXQuqebdotaCVkk7g HWKvqqoTDoSv8BDBj+g2Wzy7wp+0wHCqZb5d4p9GEfTe1kguAv61PJY1L6M8fenr7kok sMw7BRdk9OllfHwYts5OIU0w0MERhGqJLSKBa3sgA1uNHeJpC7GWdWnCh3ZX/RrQdNWB p8fd6YCv2jlnTyAMqA3Mp8qUHJxQT/sOadPEPTy6Mnjg8sTzrK3dcThjU9mwjgHtCt4E CrNw== 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=PAqOT23epdiguINfFEHggxfPg7Qga4S5NUH6UrpRNnM=; b=cuDaUPvwlH0ghkotVGLoNqb5K0W8joxRCWinc4izN7X6CT3ltbVyYdsT1C5Ubl5snA i4GLiGavog37h9M3JD4hph22aig2jw+RLTgUyRxiDiGkVk82MI+8thlNOFs4mUwtoGc5 j3dhbP/nmIdorsbZtW8b9vbcd1sP0i7gV5o9QSGKKSgfy/Sk4R5miaMobaiAXTo4Y+wN jZVVXAcdvXXe+J8wqXXpMI3/3jqqiGWsnpxR3PvMakxKfFHnSXBtFZcyvabmWKAhTmQr C615l+BW74JaJuNm8kQVnjmv5RYjI6gDdiR3ZnyAKX89dqAzHUDwP2Eo0370jFly0abr djBw== X-Gm-Message-State: AOAM530u1eswKNvDJHpJuFDYnrjPJI69V8DyT+jAIK7ILPb/SDgxJDcd YfBysztNowJIUdG6NABrvGxOnHstQZE= X-Google-Smtp-Source: ABdhPJw9SYO/Oyp1KeXfFxp7RTu9gyF0GM2lHt/ixc02EBGTKpFp3BuWBzb5p8GAsWq+ya+2ggkcxQ== X-Received: by 2002:a5d:47c2:: with SMTP id o2mr43119852wrc.416.1641317826847; Tue, 04 Jan 2022 09:37:06 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id f16sm15395wmg.27.2022.01.04.09.37.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jan 2022 09:37:06 -0800 (PST) Message-Id: <3b734f89c0f2f473d71a5d3c85faec6d48a0e350.1641317820.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 04 Jan 2022 17:36:58 +0000 Subject: [PATCH 7/9] update-index: add tests for sparse-checkout compatibility Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: stolee@gmail.com, newren@gmail.com, gitster@pobox.com, Victoria Dye , Victoria Dye Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Victoria Dye From: Victoria Dye Introduce tests for a variety of `git update-index` use cases, including performance scenarios. Tests for `update-index add/remove` are specifically focused on how `git stash` uses `git update-index` as a subcommand to prepare for sparse index integration with `stash` in a future series. Co-authored-by: Derrick Stolee Signed-off-by: Victoria Dye --- t/perf/p2000-sparse-operations.sh | 1 + t/t1092-sparse-checkout-compatibility.sh | 125 +++++++++++++++++++++++ 2 files changed, 126 insertions(+) diff --git a/t/perf/p2000-sparse-operations.sh b/t/perf/p2000-sparse-operations.sh index 54f8602f3c1..7dbed330160 100755 --- a/t/perf/p2000-sparse-operations.sh +++ b/t/perf/p2000-sparse-operations.sh @@ -118,5 +118,6 @@ test_perf_on_all git diff --cached test_perf_on_all git blame $SPARSE_CONE/a test_perf_on_all git blame $SPARSE_CONE/f3/a test_perf_on_all git checkout-index -f --all +test_perf_on_all git update-index --add --remove test_done diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh index 6ecf1f2bf8e..6804ab23a27 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -630,6 +630,131 @@ test_expect_success 'reset with wildcard pathspec' ' test_all_match git ls-files -s -- folder1 ' +test_expect_success 'update-index modify outside sparse definition' ' + init_repos && + + write_script edit-contents <<-\EOF && + echo text >>$1 + EOF + + # Create & modify folder1/a + run_on_sparse mkdir -p folder1 && + run_on_sparse cp ../initial-repo/folder1/a folder1/a && + run_on_all ../edit-contents folder1/a && + + # If file has skip-worktree enabled, update-index does not modify the + # index entry + test_sparse_match git update-index folder1/a && + test_sparse_match git status --porcelain=v2 && + test_must_be_empty sparse-checkout-out && + + # When skip-worktree is disabled (even on files outside sparse cone), file + # is updated in the index + test_sparse_match git update-index --no-skip-worktree folder1/a && + test_all_match git status --porcelain=v2 && + test_all_match git update-index folder1/a && + test_all_match git status --porcelain=v2 +' + +test_expect_success 'update-index --add outside sparse definition' ' + init_repos && + + write_script edit-contents <<-\EOF && + echo text >>$1 + EOF + + # Create folder1, add new file + run_on_sparse mkdir -p folder1 && + run_on_all ../edit-contents folder1/b && + + # Similar to `git add`, the untracked out-of-cone file is added to the index + # identically across sparse and non-sparse checkouts + test_all_match git update-index --add folder1/b && + test_all_match git status --porcelain=v2 +' + +test_expect_success 'update-index --remove outside sparse definition' ' + init_repos && + + # When `--ignore-skip-worktree-entries` is specified, out-of-cone files are + # not removed from the index if they do not exist on disk + test_sparse_match git update-index --remove --ignore-skip-worktree-entries folder1/a && + test_all_match git status --porcelain=v2 && + + # When the flag is _not_ specified, out-of-cone, not-on-disk files are + # removed from the index + rm full-checkout/folder1/a && + test_all_match git update-index --remove folder1/a && + test_all_match git status --porcelain=v2 && + + # NOTE: --force-remove supercedes --ignore-skip-worktree-entries, removing + # a skip-worktree file from the index (and disk) when both are specified + test_all_match git update-index --force-remove --ignore-skip-worktree-entries folder1/a && + test_all_match git status --porcelain=v2 +' + +test_expect_success 'update-index with directories' ' + init_repos && + + # update-index will exit silently when provided with a directory name + # containing a trailing slash + test_all_match git update-index deep/ folder1/ && + grep "Ignoring path deep/" sparse-checkout-err && + grep "Ignoring path folder1/" sparse-checkout-err && + + # When update-index is given a directory name WITHOUT a trailing slash, it will + # behave in different ways depending on the status of the directory on disk: + # * if it exists, the command exits with an error ("add individual files instead") + # * if it does NOT exist (e.g., in a sparse-checkout), it is assumed to be a + # file and either triggers an error ("does not exist and --remove not passed") + # or is ignored completely (when using --remove) + test_all_match test_must_fail git update-index deep && + run_on_all test_must_fail git update-indexe folder1 && + test_must_fail git -C full-checkout update-index --remove folder1 && + test_sparse_match git update-index --remove folder1 && + test_all_match git status --porcelain=v2 +' + +test_expect_success 'update-index --again file outside sparse definition' ' + init_repos && + + write_script edit-contents <<-\EOF && + echo text >>$1 + EOF + + test_all_match git checkout -b test-reupdate && + + # Update HEAD without modifying the index to introduce a difference in + # folder1/a + test_sparse_match git reset --soft update-folder1 && + + # Because folder1/a differs in the index vs HEAD, + # `git update-index --remove --again` will effectively perform + # `git update-index --remove folder1/a` and remove the folder1/a + test_sparse_match git update-index --remove --again && + test_sparse_match git status --porcelain=v2 +' + +test_expect_success 'update-index --cacheinfo' ' + init_repos && + + deep_a_oid=$(git -C full-checkout rev-parse update-deep:deep/a) && + folder2_oid=$(git -C full-checkout rev-parse update-folder2:folder2) && + folder1_a_oid=$(git -C full-checkout rev-parse update-folder1:folder1/a) && + + test_all_match git update-index --cacheinfo 100644 $deep_a_oid deep/a && + test_all_match git status --porcelain=v2 && + + # Cannot add sparse directory, even in sparse index case + test_all_match test_must_fail git update-index --add --cacheinfo 040000 $folder2_oid folder2/ && + + # Sparse match only - because folder1/a is outside the sparse checkout + # definition (and thus not on-disk), it will appear "deleted" in + # unstaged changes. + test_all_match git update-index --add --cacheinfo 100644 $folder1_a_oid folder1/a && + test_sparse_match git status --porcelain=v2 +' + test_expect_success 'merge, cherry-pick, and rebase' ' init_repos && From patchwork Tue Jan 4 17:36:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12703731 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 2B369C433EF for ; Tue, 4 Jan 2022 17:37:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235881AbiADRhS (ORCPT ); Tue, 4 Jan 2022 12:37:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235820AbiADRhK (ORCPT ); Tue, 4 Jan 2022 12:37:10 -0500 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B53BC06179B for ; Tue, 4 Jan 2022 09:37:09 -0800 (PST) Received: by mail-wr1-x434.google.com with SMTP id o3so19458078wrh.10 for ; Tue, 04 Jan 2022 09:37:08 -0800 (PST) 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=bQGAMdsnsZf9gd+pRoCKK4mgwMk5BiSZ1vBBtyZvhEI=; b=UzuMHhaueEc4/jJunBTgDtEZvYSP2sBEUz+HQKwAg5UMGUtE9sknhLoJ2KC2QQhgZN yXZ1iYvniZdZRGAEyO1bb69tj1vqThv1Sr1++DXWUUsfQwfKSMftmNcKaUcFZiV9py6A C/nNv9aU/DhAyhEvw0rF+mquRorEXoKcqPP+cDhrhtJB0sl54o9KAwwV6itfk3CLSNrg vGoag5h/NvtA6Jpz+lYUOFINAeBQeMDm4v/buq2YE4NzkbAMyX1o+RxqVTo/H4r8C4ht HEV+f3bpOEmPBwDFQHx6Nx86No6Cko+hEQ7b7cE0szrLz1siSLxfO7R613sbuXY6WIWw sUIw== 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=bQGAMdsnsZf9gd+pRoCKK4mgwMk5BiSZ1vBBtyZvhEI=; b=J+bibXZjEJcEyO8Oxc6uL4iydwG+yTMgsR8z7XKqjbQCX3nHAtJdwVqMoqdO4s8aos SyHU5Ktr7Dkoj3X8cjKWAKs+AIO8UgmAVrZp7/M/42nsA8ShHck2/EYhz6PxR/9L54t+ 8Hzu97z105w0/Ww4KqzK6T4t3IlLm3P6nDKgrwc+Cg3mC8DWtINzjR1iZk/HJz8LgLyQ APST0YByfv8PY4l8p3D63x3f4d1KYqOYy74nAJYdnBDJQV1lOMElVZtzs7OUtBzAmd1U GPHI0MM6HhiXKq53t2IUunC+3+zFxNnkPqrFJQngC6ta4HFoKW4JsuSqIhoBk31DPWdC gGfQ== X-Gm-Message-State: AOAM530T5603i34vV2FXx4z6YipYwlNTIU6IEORVumOaeTL5ZanZY5s0 DsTl4W/90hnvtrz3vc1LQnZJ7y/lWP4= X-Google-Smtp-Source: ABdhPJynlZ902mw5hPnTOaC0xSfnDU1+qlD4MviqRwV+2CucBOw5wUGrm5i6AGk9Pg+Yr0RrmttR6A== X-Received: by 2002:a5d:51c9:: with SMTP id n9mr43466710wrv.694.1641317827513; Tue, 04 Jan 2022 09:37:07 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id p18sm23741wms.16.2022.01.04.09.37.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jan 2022 09:37:07 -0800 (PST) Message-Id: In-Reply-To: References: Date: Tue, 04 Jan 2022 17:36:59 +0000 Subject: [PATCH 8/9] update-index: integrate with sparse index Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: stolee@gmail.com, newren@gmail.com, gitster@pobox.com, Victoria Dye , Victoria Dye Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Victoria Dye From: Victoria Dye Enable usage of the sparse index with `update-index`. Most variations of `update-index` work without explicitly expanding the index or making any other updates in or outside of `update-index.c`. The one usage requiring additional changes is `--cacheinfo`; if a file inside a sparse directory was specified, the index would not be expanded until after the cache tree is invalidated, leading to a mismatch between the index and cache tree. This scenario is handled by rearranging `add_index_entry_with_check`, allowing `index_name_stage_pos` to expand the index *before* attempting to invalidate the relevant cache tree path, avoiding cache tree/index corruption. Signed-off-by: Victoria Dye --- builtin/update-index.c | 3 +++ read-cache.c | 10 +++++++--- t/t1092-sparse-checkout-compatibility.sh | 12 ++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/builtin/update-index.c b/builtin/update-index.c index 187203e8bb5..605cc693bbd 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -1077,6 +1077,9 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) git_config(git_default_config, NULL); + prepare_repo_settings(r); + the_repository->settings.command_requires_full_index = 0; + /* we will diagnose later if it turns out that we need to update it */ newfd = hold_locked_index(&lock_file, 0); if (newfd < 0) diff --git a/read-cache.c b/read-cache.c index cbe73f14e5e..b4600e954b6 100644 --- a/read-cache.c +++ b/read-cache.c @@ -1339,9 +1339,6 @@ static int add_index_entry_with_check(struct index_state *istate, struct cache_e int skip_df_check = option & ADD_CACHE_SKIP_DFCHECK; int new_only = option & ADD_CACHE_NEW_ONLY; - if (!(option & ADD_CACHE_KEEP_CACHE_TREE)) - cache_tree_invalidate_path(istate, ce->name); - /* * If this entry's path sorts after the last entry in the index, * we can avoid searching for it. @@ -1352,6 +1349,13 @@ static int add_index_entry_with_check(struct index_state *istate, struct cache_e else pos = index_name_stage_pos(istate, ce->name, ce_namelen(ce), ce_stage(ce), EXPAND_SPARSE); + /* + * Cache tree path should be invalidated only after index_name_stage_pos, + * in case it expands a sparse index. + */ + if (!(option & ADD_CACHE_KEEP_CACHE_TREE)) + cache_tree_invalidate_path(istate, ce->name); + /* existing match? Just replace it. */ if (pos >= 0) { if (!new_only) diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh index 6804ab23a27..bc0741c970d 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -1216,6 +1216,18 @@ test_expect_success 'sparse index is not expanded: blame' ' done ' +test_expect_success 'sparse index is not expanded: update-index' ' + init_repos && + + echo "test" >sparse-index/README.md && + echo "test2" >sparse-index/a && + rm -f sparse-index/deep/a && + + ensure_not_expanded update-index --add README.md && + ensure_not_expanded update-index a && + ensure_not_expanded update-index --remove deep/a +' + # NEEDSWORK: a sparse-checkout behaves differently from a full checkout # in this scenario, but it shouldn't. test_expect_success 'reset mixed and checkout orphan' ' From patchwork Tue Jan 4 17:37:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12703732 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 21D4BC433EF for ; Tue, 4 Jan 2022 17:37:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235826AbiADRhT (ORCPT ); Tue, 4 Jan 2022 12:37:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235792AbiADRhK (ORCPT ); Tue, 4 Jan 2022 12:37:10 -0500 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 A98FBC06179C for ; Tue, 4 Jan 2022 09:37:09 -0800 (PST) Received: by mail-wr1-x42e.google.com with SMTP id t26so77637153wrb.4 for ; Tue, 04 Jan 2022 09:37:09 -0800 (PST) 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=pTpoUXeXgrXUcRnuUUYzoXFaL7nXDUg6tUh+tbzPw3U=; b=nB72icQjt0nIO56pgEj3CARq51/lFfmowwYDug6evuoay2PAbkba5O00BjKGcG0nVq gGEqsXSR2XVxmfUeiIngkF3CRMeLHn5Y2B/rsqIC43cNqq0u3ahWrnM+MFJAe7yJSuL2 XVXgFqftMnLtTl41OSSLkRxpfrKE/ItT5odMF9TsubUscJ2eu9M1cdu3ERi4o8FXnpYd chkXbsh7HtbrZGYlJd4yEyTX1exwYSv8s1K/YZa6b/cEniVX7SPfKg89qdESLv/JxQJN /5uCYEzWlnmybM6fsr3lKfhqfSdh0V4srkXtzTGovqvKCyDWSN8alBlRuh69p/YJrg/G 6VXQ== 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=pTpoUXeXgrXUcRnuUUYzoXFaL7nXDUg6tUh+tbzPw3U=; b=ZxExBVj5sqcD23BkwNwo1JC+49YuL0dycBrjQeOulGaDtSvXQbfNgtRUn02PVDw/u2 IcPdClLIG+DJaSvCAXfBSCiMqQ0pCU3RbVRMIsbfT+YSyZbQlDYAgxnaPND+DauKc5vL kkp6nPyGGryDDt5kv+H/ZA5IOp0ZxHTXavM/wcZ6qI6FRPeAHzwctxk6Lplb8Tu2Cbe+ 0zoCeQx1nAkF22k7vcu0kt/bOnTx/Y2lfPsNNVYPDB2Jiawqv9J9ErKRcVv8xdz2czT4 ImlVUl9RWzZJmMP5tEb8HqAH6eANj0boQ+JVeH2OnZ/XETc4MJAQlEm902BkiC70KYWE saPQ== X-Gm-Message-State: AOAM5305VSpba0sI1BZ/1rQ5gPLS2jWHLjJw6DP7RgqyHgBzL7P90qxJ 1HmIWvLS8afCfAC15UAt/U6xLjaoXfE= X-Google-Smtp-Source: ABdhPJxgLa8tXKviBgkfI36TXL5Z/hycxXdoWN8WozgCI60FWBhkfqGmtHtnFvUM6u1Vl8cwcojq7g== X-Received: by 2002:adf:e788:: with SMTP id n8mr45083506wrm.685.1641317828124; Tue, 04 Jan 2022 09:37:08 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id f10sm24116wmq.16.2022.01.04.09.37.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jan 2022 09:37:07 -0800 (PST) Message-Id: In-Reply-To: References: Date: Tue, 04 Jan 2022 17:37:00 +0000 Subject: [PATCH 9/9] update-index: reduce scope of index expansion in do_reupdate Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: stolee@gmail.com, newren@gmail.com, gitster@pobox.com, Victoria Dye , Victoria Dye Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Victoria Dye From: Victoria Dye Expand the full index (and redo reupdate operation) only if a sparse directory in the index differs from HEAD. Only the index entries that differ between the index and HEAD are updated when performing `git update-index --again`, so unmodified sparse directories are safely skipped. The index does need to be expanded when sparse directories contain changes, though, because `update_one(...)` will not operate on sparse directory index entries. Because the index should only be expanded if a sparse directory is modified, add a test ensuring the index is not expanded when differences only exist within the sparse cone. Signed-off-by: Victoria Dye --- builtin/update-index.c | 14 +++++++++++--- t/t1092-sparse-checkout-compatibility.sh | 5 ++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/builtin/update-index.c b/builtin/update-index.c index 605cc693bbd..52ecc714d99 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -606,7 +606,7 @@ static struct cache_entry *read_one_ent(const char *which, error("%s: not in %s branch.", path, which); return NULL; } - if (mode == S_IFDIR) { + if (!the_index.sparse_index && mode == S_IFDIR) { if (which) error("%s: not a blob in %s branch.", path, which); return NULL; @@ -743,8 +743,6 @@ static int do_reupdate(int ac, const char **av, */ has_head = 0; redo: - /* TODO: audit for interaction with sparse-index. */ - ensure_full_index(&the_index); for (pos = 0; pos < active_nr; pos++) { const struct cache_entry *ce = active_cache[pos]; struct cache_entry *old = NULL; @@ -761,6 +759,16 @@ static int do_reupdate(int ac, const char **av, discard_cache_entry(old); continue; /* unchanged */ } + + /* At this point, we know the contents of the sparse directory are + * modified with respect to HEAD, so we expand the index and restart + * to process each path individually + */ + if (S_ISSPARSEDIR(ce->ce_mode)) { + ensure_full_index(&the_index); + goto redo; + } + /* Be careful. The working tree may not have the * path anymore, in which case, under 'allow_remove', * or worse yet 'allow_replace', active_nr may decrease. diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh index bc0741c970d..0863c9747c4 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -1225,7 +1225,10 @@ test_expect_success 'sparse index is not expanded: update-index' ' ensure_not_expanded update-index --add README.md && ensure_not_expanded update-index a && - ensure_not_expanded update-index --remove deep/a + ensure_not_expanded update-index --remove deep/a && + + ensure_not_expanded reset --soft update-deep && + ensure_not_expanded update-index --add --remove --again ' # NEEDSWORK: a sparse-checkout behaves differently from a full checkout