From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS53758 23.128.96.0/24 X-Spam-Status: No, score=-3.7 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by dcvr.yhbt.net (Postfix) with ESMTP id 701371F9F4 for ; Wed, 14 Jul 2021 13:14:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239458AbhGNNPz (ORCPT ); Wed, 14 Jul 2021 09:15:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239451AbhGNNPs (ORCPT ); Wed, 14 Jul 2021 09:15:48 -0400 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 337C5C061766 for ; Wed, 14 Jul 2021 06:12:56 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id d2so3242876wrn.0 for ; Wed, 14 Jul 2021 06:12:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=+zCswDbBE6VAPxz4AwOZEa5RZC32g05Cgk4luWVMlJQ=; b=c9Fo3XtTXi9lORPNrmVzhgMBXFBevSOn5r1mIT1eNGrGiqtGPS6iu/dPxK9KzzVj5Q eTZ2ADK+c3bBVZ5eKRT69Ib4UxSyq9qdwXBnYiYHqam+M1sXDltaPH/JEsVWj5KDrOOG QjiNrxhxJAe0EfZeIPEOmV4hy26nWRek0TloUpIkPeIIgY2O/vbmBMBeiLOlCUzKPqjE mckpBRCWT3BpcSAl+QbF2o4HNh5kdoatJy5ZXucSEC7wxeB/g89kUlbMQ9sU9mRLMlru 3TNOxG+vXR1h4SCCDLFu0f5LwA6Uww0noiZ1jCiGUvkfdogrcuWjucrNk9ZX4Dj3jyYS RZ+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=+zCswDbBE6VAPxz4AwOZEa5RZC32g05Cgk4luWVMlJQ=; b=I0+z9Y76nSfo5ditqDUIN4kIXzs2Qz8Kdqf+/wcqTRVGxD0uQ2iLQf1XmPTvtmfkfV dwjATDeUw/TPeSXcxH7q5GQ1TngSwq/LOU20J0nSg8M3KTMSTVDaBvqMfUiB7ITLP0rE BpYUu9E3M7M6Y+PoyYIDV9flxIvWX0tbigipYr1aW9URGjS1vxwxNflK7n1ZHA7A79PU Xhl/QIyqtEaazLaWDZ0GijCkA5ktP3dOJr2Rcq20F4GiyHtFDGlOUaK1BLPjzQWdgnd4 7W+fLeugYawAy3JlDoYFnn/S5mN6jEJZlevwWFMNcZ+pkMre77iy3Sqz1FQv7QKak9P1 7O1g== X-Gm-Message-State: AOAM533z3QRDRxaptKNUk+6QKG2NgNl4TK4gihRHwPmKorLwLMgTPJvI woxUZ80rMBlXo1zken/5PBnplczaUIM= X-Google-Smtp-Source: ABdhPJwzJvqwfuXVlLfBawhTPjS+9bXwuxqOS1HR9rfDns/B84y+zPG3O6WDfhFjV1xG5h2VtB/YXQ== X-Received: by 2002:a5d:51d2:: with SMTP id n18mr13159471wrv.72.1626268374885; Wed, 14 Jul 2021 06:12:54 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a64sm2020413wme.8.2021.07.14.06.12.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 06:12:54 -0700 (PDT) Message-Id: <1d4b1f8aea0183a00f8c20226cca5e9c387e4adc.1626268360.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Date: Wed, 14 Jul 2021 13:12:39 +0000 Subject: [PATCH v9 15/16] fsmonitor: integrate with sparse index Fcc: Sent Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MIME-Version: 1.0 To: git@vger.kernel.org Cc: gitster@pobox.com, newren@gmail.com, Matheus Tavares Bernardino , Derrick Stolee , git@jeffhostetler.com, johannes.schindelin@gmx.de, Bagas Sanjaya , Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee If we need to expand a sparse-index into a full one, then the FS Monitor bitmap is going to be incorrect. Ensure that we start fresh at such an event. While this is currently a performance drawback, the eventual hope of the sparse-index feature is that these expansions will be rare and hence we will be able to keep the FS Monitor data accurate across multiple Git commands. These tests are added to demonstrate that the behavior is the same across a full index and a sparse index, but also that file modifications to a tracked directory outside of the sparse cone will trigger ensure_full_index(). Reviewed-by: Elijah Newren Signed-off-by: Derrick Stolee --- sparse-index.c | 7 ++++++ t/t7519-status-fsmonitor.sh | 49 +++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/sparse-index.c b/sparse-index.c index ef53bd2198b..53c8f711ccc 100644 --- a/sparse-index.c +++ b/sparse-index.c @@ -186,6 +186,10 @@ int convert_to_sparse(struct index_state *istate) cache_tree_free(&istate->cache_tree); cache_tree_update(istate, 0); + istate->fsmonitor_has_run_once = 0; + FREE_AND_NULL(istate->fsmonitor_dirty); + FREE_AND_NULL(istate->fsmonitor_last_update); + istate->sparse_index = 1; trace2_region_leave("index", "convert_to_sparse", istate->repo); return 0; @@ -282,6 +286,9 @@ void ensure_full_index(struct index_state *istate) istate->cache = full->cache; istate->cache_nr = full->cache_nr; istate->cache_alloc = full->cache_alloc; + istate->fsmonitor_has_run_once = 0; + FREE_AND_NULL(istate->fsmonitor_dirty); + FREE_AND_NULL(istate->fsmonitor_last_update); strbuf_release(&base); free(full); diff --git a/t/t7519-status-fsmonitor.sh b/t/t7519-status-fsmonitor.sh index 637391c6ce4..deea88d4431 100755 --- a/t/t7519-status-fsmonitor.sh +++ b/t/t7519-status-fsmonitor.sh @@ -73,6 +73,7 @@ test_expect_success 'setup' ' expect* actual* marker* + trace2* EOF ' @@ -383,4 +384,52 @@ test_expect_success 'status succeeds after staging/unstaging' ' ) ' +# Usage: +# check_sparse_index_behavior [!] +# If "!" is supplied, then we verify that we do not call ensure_full_index +# during a call to 'git status'. Otherwise, we verify that we _do_ call it. +check_sparse_index_behavior () { + git status --porcelain=v2 >expect && + git sparse-checkout init --cone --sparse-index && + git sparse-checkout set dir1 dir2 && + GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \ + git status --porcelain=v2 >actual && + test_region $1 index ensure_full_index trace2.txt && + test_region fsm_hook query trace2.txt && + test_cmp expect actual && + rm trace2.txt && + git sparse-checkout disable +} + +test_expect_success 'status succeeds with sparse index' ' + git reset --hard && + + test_config core.fsmonitor "$TEST_DIRECTORY/t7519/fsmonitor-all" && + check_sparse_index_behavior ! && + + write_script .git/hooks/fsmonitor-test<<-\EOF && + printf "last_update_token\0" + EOF + git config core.fsmonitor .git/hooks/fsmonitor-test && + check_sparse_index_behavior ! && + + write_script .git/hooks/fsmonitor-test<<-\EOF && + printf "last_update_token\0" + printf "dir1/modified\0" + EOF + check_sparse_index_behavior ! && + + cp -r dir1 dir1a && + git add dir1a && + git commit -m "add dir1a" && + + # This one modifies outside the sparse-checkout definition + # and hence we expect to expand the sparse-index. + write_script .git/hooks/fsmonitor-test<<-\EOF && + printf "last_update_token\0" + printf "dir1a/modified\0" + EOF + check_sparse_index_behavior +' + test_done -- gitgitgadget