From patchwork Fri Oct 29 13:51:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12592727 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2EDB1C433EF for ; Fri, 29 Oct 2021 13:51:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 113886115B for ; Fri, 29 Oct 2021 13:51:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230521AbhJ2NyB (ORCPT ); Fri, 29 Oct 2021 09:54:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230296AbhJ2Nx6 (ORCPT ); Fri, 29 Oct 2021 09:53:58 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37AD7C061570 for ; Fri, 29 Oct 2021 06:51:30 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id k7so16197207wrd.13 for ; Fri, 29 Oct 2021 06:51:30 -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=fBwFOyZpb1FNiGNmlBqIz8szMCFUAyTVo8d9LrANmrg=; b=Kf7qRSzrhBhTVOLR+opMDn+DgdahYWCMdBdgIx4Xz+tiwXOjwhUIBry4bNm6sLu6Bw 9Sr5JB1DpQ4y2552Zrus4T9FrhUYqcpwWC+raaPyBEAEMNe8yTKN8M8uIreS9KXLToBq hm2zzJfIRfDiAM51+CxAP9mlqU43CAVP2DfHC5nXUARKI2zZMVpl1RGeIz8jtZjo3fVd /MDBmXCcHiWFWkwLsvXTUSjdyE0VpV0Hnj/V9yEjz44APMtN3k095x7CbXN2C3U98WT4 O7oOVbHG9Rjv+8OLtCA0sofqLU+uNfrLtH1wLq3VuyIyx75F/cvv/oig4+G403BPDsV9 9Ulg== 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=fBwFOyZpb1FNiGNmlBqIz8szMCFUAyTVo8d9LrANmrg=; b=OuwJiZ2Tggw3PxS7ywaN0Zre3eovvKpKEKw+2pPnKuDX6pFWeMssyedD41UfLNmkIt JxJYrlpPnGyYauL4z6uwO7BRN32HatyyccIovgnUBbTKg3UbA1PGJBNWal6CTDMAVYcJ 71ee8qLCpz8roWXa/ISFmUUbpeMoTHEGYYinpUG7xuhxpqOkjpmFMrh18fjbJAaj1tnz g0CtEdC/anfLg/R+Trr+KHnw9TNqu8w4rymsZFF+kEpcIN/vmOBWJ5PkErI/R7+/wYGR FLvAhQjtgYBk/3R6Owx7W6gNN9jv5EJr9PoFIPtrqkyJmsMNEaq0WpHOMHB5bSFYHg7t fIrw== X-Gm-Message-State: AOAM533M0+2fGyguqogZjHnn2iaYI6eFblUMLqmK0Y8sLCSEADzv3Wvz XAEGzz1pzyy9NpF+adTPvujpXlEmkrM= X-Google-Smtp-Source: ABdhPJwZR20usDSmwfcd8beGDtlQcmo0VEtlzzhLspIeM34o7s6tUPbwi40x9HxvFsYsjWyg3LSOZQ== X-Received: by 2002:adf:a402:: with SMTP id d2mr15184493wra.266.1635515488864; Fri, 29 Oct 2021 06:51:28 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id d9sm1774471wre.52.2021.10.29.06.51.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Oct 2021 06:51:28 -0700 (PDT) Message-Id: <6974ce7e7f568444518f9ff405747653516b2613.1635515487.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 29 Oct 2021 13:51:23 +0000 Subject: [PATCH v4 1/4] test-read-cache.c: prepare_repo_settings after config init Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: stolee@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 Move `prepare_repo_settings` after the git directory has been set up in `test-read-cache.c`. The git directory settings must be initialized to properly assign repo settings using the worktree-level git config. Signed-off-by: Victoria Dye --- t/helper/test-read-cache.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c index b52c174acc7..0d9f08931a1 100644 --- a/t/helper/test-read-cache.c +++ b/t/helper/test-read-cache.c @@ -39,8 +39,6 @@ int cmd__read_cache(int argc, const char **argv) int table = 0, expand = 0; initialize_the_repository(); - prepare_repo_settings(r); - r->settings.command_requires_full_index = 0; for (++argv, --argc; *argv && starts_with(*argv, "--"); ++argv, --argc) { if (skip_prefix(*argv, "--print-and-refresh=", &name)) @@ -56,6 +54,9 @@ int cmd__read_cache(int argc, const char **argv) setup_git_directory(); git_config(git_default_config, NULL); + prepare_repo_settings(r); + r->settings.command_requires_full_index = 0; + for (i = 0; i < cnt; i++) { repo_read_index(r); From patchwork Fri Oct 29 13:51:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12592729 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D6A77C433F5 for ; Fri, 29 Oct 2021 13:51:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BB19961100 for ; Fri, 29 Oct 2021 13:51:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231260AbhJ2NyC (ORCPT ); Fri, 29 Oct 2021 09:54:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229603AbhJ2NyA (ORCPT ); Fri, 29 Oct 2021 09:54:00 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5085C061570 for ; Fri, 29 Oct 2021 06:51:30 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id m22so16365613wrb.0 for ; Fri, 29 Oct 2021 06:51:30 -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=+eg35DJMCdU5TsE9YAXGI0p0oomtGVacKPQUl53M+C0=; b=EWsglNEiuWAXzUfiYJxM+x+QU7lVL29IeIqP6N1niotX6S9mWKb3nUxunjbIg2ZMPA Zl5rIR8oL9IVyqfNgvdvlfnTfnWnwpMd1NHgsbv/b5BhiTjvHba9hrYDSuW4tpOaIr1e HzprehDKtp3RbxPovNAmGysZdhKbYSSPLeTPR+gzPYlYC1X/d4BGaqFW4wczgxtLHEjw 0o0zSNcUDqRW7chwKd9HBZJsrnwGfW+Q3Yd4RvaFy4kndHaP2OMtX1PC0rANJSxWsYtK BN7XLC1aEjAmNlirvLrX/QDcV31vuX3bpegF26eDIKxBAo52XPXNyfJ5Ga+1y2mGwFU5 KIZg== 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=+eg35DJMCdU5TsE9YAXGI0p0oomtGVacKPQUl53M+C0=; b=W3/RfSjtbyIBgjo+hep3ogWZXK7DrlU9pMYc3YvUzNZovLQZ+vdXebl7eztRLpCt84 djgaQ7jC+VwVzvMnbaZ7de4AS7urkjK4p+dEP9yL60uAvsHH+/tObuMrg5+d5z4nrbkC 4cHqdYH5NpXkh6DyBoJhgQyGWtI5Uh/2Qng++THbjLA2EzvGgrn6r8tYnUqcYtuzU3ZU XyzzdqyWu4Lb0CFyFdzMhyGcV+sDvIcL+YrlEwelUe9kXxFhbnA5VRw1+lr4YpX68zRw B8rAZ4TN+YjLOWEUTKUSF1NWe4uuUyx6+0FOoiAxDiHRw7v/LtsqFx6fX+FkdAv+7FBw X6NQ== X-Gm-Message-State: AOAM533EPudUa0+6Za9ryPKhvcZltQ/kbjwtxOtzlpULYcYXV9RG/blA s4kVKenDqp261Zlj/GHbGxLhvFc95bE= X-Google-Smtp-Source: ABdhPJyAV9YODI6ANTKQn5yn98/A+lcUudZy+Vob5Q8n+CjF/YyEt5KmJ3ma7iheMLmdS2ZVl6g+nw== X-Received: by 2002:a05:6000:44:: with SMTP id k4mr14597513wrx.68.1635515489452; Fri, 29 Oct 2021 06:51:29 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id f8sm5766575wrj.41.2021.10.29.06.51.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Oct 2021 06:51:29 -0700 (PDT) Message-Id: <91351ac4bded2c19264cd2009e90ee71fcf67b81.1635515487.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 29 Oct 2021 13:51:24 +0000 Subject: [PATCH v4 2/4] sparse-index: avoid unnecessary cache tree clearing Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: stolee@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 When converting a full index to sparse, clear and recreate the cache tree only if the cache tree is not fully valid. The convert_to_sparse operation should exit silently if a cache tree update cannot be successfully completed (e.g., due to a conflicted entry state). However, because this failure scenario only occurs when at least a portion of the cache tree is invalid, we can save ourselves the cost of clearing and recreating the cache tree by skipping the check when the cache tree is fully valid. Helped-by: Derrick Stolee Co-authored-by: Junio C Hamano Signed-off-by: Victoria Dye --- sparse-index.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/sparse-index.c b/sparse-index.c index 7b7ff79e044..85613cd8a3a 100644 --- a/sparse-index.c +++ b/sparse-index.c @@ -175,17 +175,20 @@ int convert_to_sparse(struct index_state *istate, int flags) if (index_has_unmerged_entries(istate)) return 0; - /* Clear and recompute the cache-tree */ - cache_tree_free(&istate->cache_tree); - /* - * Silently return if there is a problem with the cache tree update, - * which might just be due to a conflict state in some entry. - * - * This might create new tree objects, so be sure to use - * WRITE_TREE_MISSING_OK. - */ - if (cache_tree_update(istate, WRITE_TREE_MISSING_OK)) - return 0; + if (!cache_tree_fully_valid(istate->cache_tree)) { + /* Clear and recompute the cache-tree */ + cache_tree_free(&istate->cache_tree); + + /* + * Silently return if there is a problem with the cache tree update, + * which might just be due to a conflict state in some entry. + * + * This might create new tree objects, so be sure to use + * WRITE_TREE_MISSING_OK. + */ + if (cache_tree_update(istate, WRITE_TREE_MISSING_OK)) + return 0; + } remove_fsmonitor(istate); From patchwork Fri Oct 29 13:51:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12592733 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D1C8FC433EF for ; Fri, 29 Oct 2021 13:51:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B640861184 for ; Fri, 29 Oct 2021 13:51:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231481AbhJ2NyE (ORCPT ); Fri, 29 Oct 2021 09:54:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231328AbhJ2NyB (ORCPT ); Fri, 29 Oct 2021 09:54:01 -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 910BBC061714 for ; Fri, 29 Oct 2021 06:51:31 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id i5so8610633wrb.2 for ; Fri, 29 Oct 2021 06:51:31 -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=EhqpCoJT+8YeldSMIWB/k40BGZlaaKWhf6LrVKaEhLE=; b=p1F7RNzwssFvv6nWrWjllnxf9hnTXn7dvy+X/mhdYHowRZkD0toqm6SOkNpwIV/LMB aGweFCKxgB0ieaHheVUOu/IGKy1DU64Lh/5AKBK7dPeyysF0yxhRILTQ01S9zcRcoruA 2kfLsmghw7EohPhtkQQpxQRJhjs4kD4VswRFGILwcoC72aDmg4oncEAfOJelfWc9bPWw mIKpHI/iqfVePGy3dQD/TTDXLve+4iQAxj1QDO4OWstKY7VDA2WLzdowofDrJ0Hsch9T hh6AI93Xcj2rkb9E2A2yNfPvF6VWO746UXCcOOM6YxMj+wkmVZj7FbnT7ZTJ7eAYjC9x uOMg== 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=EhqpCoJT+8YeldSMIWB/k40BGZlaaKWhf6LrVKaEhLE=; b=N3p1Qq8+2P3g8mbn2x2cMAydeEtayMtlWxFuI9gVXWUumEtrQTsq633TqRVvmYs7m7 LjRnUytNgXdppAdrQZq1CNiFtLsVWrg4606hS533FwuA1rPdtkfrtKdhlz6YSgU6ySZn hiKuJcUrKnnmXAxnOTHL3Z83XQM9uxZ/nnW+8pPypX/lHr1fhaRB3M8C6Udu3PCI6ZG7 g0VqOw+9EiC3QcSWiCUbaN9joa0u74JdKRch3RSd9k2rxRkwL0CV3HVatIcWJfwJ9F1s XYpMbRk3eYFwP7Qa94AleBZI8ehlZ09aiYrWEXR8tVq4sd7Tp/EWMOmxJixYEQdjRa6X Fs3g== X-Gm-Message-State: AOAM532pRe7WbOBDObNme7ZOD6mPskK8aWeyeOEKx/0yeGZsLqCCm5o/ FwPFzdj1zmMKqPS2x8bhprowVA014uU= X-Google-Smtp-Source: ABdhPJzwJ/yKrsIYyab36fGgn1LEfIlFWeJCbxlsL3tVHp5g7+VXr6Xg3vgDtSxUxsBXKDULc+sHBA== X-Received: by 2002:a5d:444c:: with SMTP id x12mr14398189wrr.38.1635515490223; Fri, 29 Oct 2021 06:51:30 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id g3sm7305030wri.45.2021.10.29.06.51.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Oct 2021 06:51:29 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Fri, 29 Oct 2021 13:51:25 +0000 Subject: [PATCH v4 3/4] sparse-index: add ensure_correct_sparsity function Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: stolee@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 The `ensure_correct_sparsity` function is intended to provide a means of aligning the in-core index with the sparsity required by the repository settings and other properties of the index. The function first checks whether a sparse index is allowed (per repository & sparse checkout pattern settings). If the sparse index may be used, the index is converted to sparse; otherwise, it is explicitly expanded with `ensure_full_index`. Helped-by: Junio C Hamano Signed-off-by: Victoria Dye --- sparse-index.c | 33 +++++++++++++++++++++++++++++---- sparse-index.h | 1 + 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/sparse-index.c b/sparse-index.c index 85613cd8a3a..a1d505d50e9 100644 --- a/sparse-index.c +++ b/sparse-index.c @@ -122,17 +122,17 @@ static int index_has_unmerged_entries(struct index_state *istate) return 0; } -int convert_to_sparse(struct index_state *istate, int flags) +static int is_sparse_index_allowed(struct index_state *istate, int flags) { - int test_env; - if (istate->sparse_index || !istate->cache_nr || - !core_apply_sparse_checkout || !core_sparse_checkout_cone) + if (!core_apply_sparse_checkout || !core_sparse_checkout_cone) return 0; if (!istate->repo) istate->repo = the_repository; if (!(flags & SPARSE_INDEX_MEMORY_ONLY)) { + int test_env; + /* * The sparse index is not (yet) integrated with a split index. */ @@ -168,6 +168,19 @@ int convert_to_sparse(struct index_state *istate, int flags) if (!istate->sparse_checkout_patterns->use_cone_patterns) return 0; + return 1; +} + +int convert_to_sparse(struct index_state *istate, int flags) +{ + /* + * If the index is already sparse, empty, or otherwise + * cannot be converted to sparse, do not convert. + */ + if (istate->sparse_index || !istate->cache_nr || + !is_sparse_index_allowed(istate, flags)) + return 0; + /* * NEEDSWORK: If we have unmerged entries, then stay full. * Unmerged entries prevent the cache-tree extension from working. @@ -316,6 +329,18 @@ void ensure_full_index(struct index_state *istate) trace2_region_leave("index", "ensure_full_index", istate->repo); } +void ensure_correct_sparsity(struct index_state *istate) +{ + /* + * If the index can be sparse, make it sparse. Otherwise, + * ensure the index is full. + */ + if (is_sparse_index_allowed(istate, 0)) + convert_to_sparse(istate, 0); + else + ensure_full_index(istate); +} + /* * This static global helps avoid infinite recursion between * expand_to_path() and index_file_exists(). diff --git a/sparse-index.h b/sparse-index.h index 9f3d7bc7faf..656bd835b25 100644 --- a/sparse-index.h +++ b/sparse-index.h @@ -4,6 +4,7 @@ struct index_state; #define SPARSE_INDEX_MEMORY_ONLY (1 << 0) int convert_to_sparse(struct index_state *istate, int flags); +void ensure_correct_sparsity(struct index_state *istate); /* * Some places in the codebase expect to search for a specific path. From patchwork Fri Oct 29 13:51:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12592731 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0BFF6C433EF for ; Fri, 29 Oct 2021 13:51:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E8067611C0 for ; Fri, 29 Oct 2021 13:51:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231449AbhJ2NyD (ORCPT ); Fri, 29 Oct 2021 09:54:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231403AbhJ2NyB (ORCPT ); Fri, 29 Oct 2021 09:54:01 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E5F1C061767 for ; Fri, 29 Oct 2021 06:51:32 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id o14so16201316wra.12 for ; Fri, 29 Oct 2021 06:51:32 -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=qkq4mQztxITq/GOSkhCIwELaNOZlIiv3dFjIv3bSuQU=; b=DogJS+ZmsmzMLxsPcZT1Zk2Gb8RDe2BC/r/jxGCoZiJSVonYWfbMbHW5D+UXg0YLH4 Y8PYCqSGgnDQoQZ2aTH5RZ22hy0931C7Qz+uh+H/Gu6rcbfPMjRVjz9iCLqUy3GalBCi gWpG7SusRTRvjaL2EuLI35fvkoliAQX+zDV0Sx2fPWntzgzXFGmYgKcnczJptvJj3J6C NjiV7twHIIsLj8aJvZozIvYeVHzK5AHsCsBic9pcp+9TTagdQPA7iUJsxGSo6z7O8DBx 18DCIAVcptngosDOs8wFXTWQTElttJ197G9KQn+/xplbjSqkLMOxJasQhDV4uwR8zLp6 58sg== 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=qkq4mQztxITq/GOSkhCIwELaNOZlIiv3dFjIv3bSuQU=; b=EZwZckDc3wjqp5fvVTfdEROEcahpoYBQdsYa+7GVp9EVIu2Ii9CsL6VhQ/iAbtUq7X ElbC/bvw7wJpYmHA3i/4LBHdBjMLSDstyfjsNp/7lifypBKJU7eWSh5wlL1CXCyNaYRh 8yZKIM7wdc3bPqVKXFbZKxuxFNV1XSlStoGDctUqGTFz3h8Sgrf7RDVg41iChx6CVMrl dG2Qgn+733SQ6TbwuI1f7BzUdRnbV1b/b4DMniQr/IbIL+W/0zrtk8ChV0/eQqhdysaJ +3ZsAO4MCMOa16PKm9ixcVM1akpp88CX/MdssGugo6ldtbubWKLV2QFA+hC1ueGgYJzQ wDyA== X-Gm-Message-State: AOAM532Fs2TmKsHrEpNPsIzbF4Ym61fAhcK4VitWpt593rmxn0abUrWO HuDvMGCaaBIjxQP5XZFkhPBYb5VMq9E= X-Google-Smtp-Source: ABdhPJzhee+weqPRkq/F8pjRjj+Pyov5ImrENkPxVOP2/zyQDdTml4AdX/KghqmWIbattXnWkiWenA== X-Received: by 2002:a5d:4405:: with SMTP id z5mr7587233wrq.415.1635515491024; Fri, 29 Oct 2021 06:51:31 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c15sm5717862wrs.19.2021.10.29.06.51.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Oct 2021 06:51:30 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Fri, 29 Oct 2021 13:51:26 +0000 Subject: [PATCH v4 4/4] sparse-index: update do_read_index to ensure correct sparsity Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: stolee@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 If `command_requires_full_index` is false, ensure correct in-core index sparsity on read by calling `ensure_correct_sparsity`. This change is meant to update the how the index is read in a command after sparse index-related repository settings are modified. Previously, for example, if `index.sparse` were changed from `true` to `false`, the in-core index on the next command would be sparse. The index would only be expanded to full when it was next written to disk. By adding a call to `ensure_correct_sparsity`, the in-core index now matches the sparsity dictated by the relevant repository settings as soon as it is read into memory, rather than when it is later written to disk. Helped-by: Junio C Hamano Co-authored-by: Derrick Stolee Signed-off-by: Victoria Dye --- read-cache.c | 8 ++++++ t/t1092-sparse-checkout-compatibility.sh | 31 ++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/read-cache.c b/read-cache.c index a78b88a41bf..b3772ba70a1 100644 --- a/read-cache.c +++ b/read-cache.c @@ -2337,9 +2337,17 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist) if (!istate->repo) istate->repo = the_repository; + + /* + * If the command explicitly requires a full index, force it + * to be full. Otherwise, correct the sparsity based on repository + * settings and other properties of the index (if necessary). + */ prepare_repo_settings(istate->repo); if (istate->repo->settings.command_requires_full_index) ensure_full_index(istate); + else + ensure_correct_sparsity(istate); return istate->cache_nr; diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh index ca91c6a67f8..59accde1fa3 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -694,6 +694,37 @@ test_expect_success 'sparse-index is expanded and converted back' ' test_region index ensure_full_index trace2.txt ' +test_expect_success 'index.sparse disabled inline uses full index' ' + init_repos && + + # When index.sparse is disabled inline with `git status`, the + # index is expanded at the beginning of the execution then never + # converted back to sparse. It is then written to disk as a full index. + rm -f trace2.txt && + GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \ + git -C sparse-index -c index.sparse=false status && + ! test_region index convert_to_sparse trace2.txt && + test_region index ensure_full_index trace2.txt && + + # Since index.sparse is set to true at a repo level, the index + # is converted from full to sparse when read, then never expanded + # over the course of `git status`. It is written to disk as a sparse + # index. + rm -f trace2.txt && + GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \ + git -C sparse-index status && + test_region index convert_to_sparse trace2.txt && + ! test_region index ensure_full_index trace2.txt && + + # Now that the index has been written to disk as sparse, it is not + # converted to sparse (or expanded to full) when read by `git status`. + rm -f trace2.txt && + GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \ + git -C sparse-index status && + ! test_region index convert_to_sparse trace2.txt && + ! test_region index ensure_full_index trace2.txt +' + ensure_not_expanded () { rm -f trace2.txt && echo >>sparse-index/untracked.txt &&