From patchwork Sat Mar 16 09:49:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Johannes Schindelin via GitGitGadget X-Patchwork-Id: 10855819 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4D6D617E6 for ; Sat, 16 Mar 2019 09:49:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 340D628D88 for ; Sat, 16 Mar 2019 09:49:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 23C4928D11; Sat, 16 Mar 2019 09:49:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9CDBB28D11 for ; Sat, 16 Mar 2019 09:49:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726649AbfCPJtJ (ORCPT ); Sat, 16 Mar 2019 05:49:09 -0400 Received: from mail-ed1-f68.google.com ([209.85.208.68]:41210 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726099AbfCPJtJ (ORCPT ); Sat, 16 Mar 2019 05:49:09 -0400 Received: by mail-ed1-f68.google.com with SMTP id a25so2381319edc.8 for ; Sat, 16 Mar 2019 02:49:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:in-reply-to:references:from:subject:mime-version :content-transfer-encoding:fcc:content-transfer-encoding:to:cc; bh=qwR0KLqxg7h1WadVbWudj5IsygqBpmHAmss4CehjvS8=; b=XKPDwVtz13DfvR7tIlQVh3IGe9jG/e8A/PkaSUw3upId1aVl+9OtcFMPvQRx+BZSBs xLvpNCP14V98qMoCbELwX5FMITL4XV9qSCwKRhQDmPvEt73Sced7qQnndG/u2L0u19x7 /Vwdm4L9EYgdWFp+j696sgOnC5VSJOuanQk3mNCStgKTvsoYLNk94qGxAu/Sb8Wav3Ah LBYicfF/x0gu+/XsIyJuI1WnVS6rxglJvlf+28QQzmtIFOoqVQqhAh0zXHUd3Uk2uwmp DDdw4I57hwun1klS+TvkzqUUWmrdlsT2MUeGCbJqlPpNZUFREUVzhncIklzkrjQ9PCje 45nQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:in-reply-to:references:from :subject:mime-version:content-transfer-encoding:fcc :content-transfer-encoding:to:cc; bh=qwR0KLqxg7h1WadVbWudj5IsygqBpmHAmss4CehjvS8=; b=kvBdxx8cjj6Ntkpiv3UnXXhe/vzVQ7nBof1VsQT6q2iMcYyKDRqtU7GaAEHyH4MavZ 7K++pQsrddyHRoBKmysYhcXh9Agu3ItNWNFO0GZSujfn+fpyZTNXwblPogLV8THxy8mO QUl7g71G+gJx9qkveRzI+AFi2aIMBgjeo/SJv1GtT35U1GxBzgmRYx8288HPh0lfCxpN ZwJWhdNFydAKBCk/dHUeUX8tMUL5Wlh44F38a6KfUzdZz+LQd+xtxyp6IYukJdB8/BEs oCzV5mYkcRbW1HlNKTTaetZ1UDGA2o2ajnQrlOUcVNXGcp7Cr14tb3+czfFdWuGUVXLj U1VA== X-Gm-Message-State: APjAAAVrfc9ayFt30DjXCx+b7TmvrkADbl/n8YITBq2AhxN5Fnidp+VI mx3zYGI29adXKQ+toiRTXrbR4anF X-Google-Smtp-Source: APXvYqx2+5jxegrN6gsm45E1oJGC86yhBh6jUCOPLghZLmGQd7XnM4R3teUPJcdPEnOXp2d/I8caLA== X-Received: by 2002:a50:9863:: with SMTP id h32mr5978471edb.291.1552729747135; Sat, 16 Mar 2019 02:49:07 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id l26sm945383eja.29.2019.03.16.02.49.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 16 Mar 2019 02:49:06 -0700 (PDT) Date: Sat, 16 Mar 2019 02:49:06 -0700 (PDT) X-Google-Original-Date: Sat, 16 Mar 2019 09:49:04 GMT Message-Id: In-Reply-To: References: From: "Johannes Schindelin via GitGitGadget" Subject: [PATCH 1/2] fsmonitor: demonstrate that it is not refreshed after discard_index() MIME-Version: 1.0 Fcc: Sent To: git@vger.kernel.org Cc: Ben Peart , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Junio C Hamano , Johannes Schindelin Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Johannes Schindelin This one is tricky. When `core.fsmonitor` is set, a `refresh_index()` will not perform a full scan of files that might be modified, but will query the fsmonitor and refresh only the ones that have been actually touched. Due to implementation details, the fsmonitor is queried in `refresh_cache_ent()`, but of course it only has to be queried once, so we set a flag when we did that. But when the index was discarded, we did not re-set that flag. So far, this is only covered by our test suite when running with GIT_TEST_FSMONITOR=$PWD/t7519/fsmonitor-all, and only due to the way the built-in stash interacts with the recursive merge machinery. Let's introduce a straight-forward regression test for this. We simply extend the "read & discard index" loop in `test-tool read-cache` to optionally refresh the index, report on a given file's status, and then modify that file. Due to the bug described above, only the first refresh will actually query the fsmonitor; subsequent loop iterations will not. This problem was reported by Ævar Arnfjörð Bjarmason. Signed-off-by: Johannes Schindelin --- t/helper/test-read-cache.c | 24 +++++++++++++++++++++++- t/t7519-status-fsmonitor.sh | 10 ++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c index d674c88ba0..7e79b555de 100644 --- a/t/helper/test-read-cache.c +++ b/t/helper/test-read-cache.c @@ -1,14 +1,36 @@ #include "test-tool.h" #include "cache.h" +#include "config.h" int cmd__read_cache(int argc, const char **argv) { - int i, cnt = 1; + int i, cnt = 1, namelen; + const char *name = NULL; + + if (argc > 1 && skip_prefix(argv[1], "--print-and-refresh=", &name)) { + namelen = strlen(name); + argc--; + argv++; + } + if (argc == 2) cnt = strtol(argv[1], NULL, 0); setup_git_directory(); + git_config(git_default_config, NULL); for (i = 0; i < cnt; i++) { read_cache(); + if (name) { + int pos; + + refresh_index(&the_index, REFRESH_QUIET, + NULL, NULL, NULL); + pos = index_name_pos(&the_index, name, namelen); + if (pos < 0) + die("%s not in index", name); + printf("%s is%s up to date\n", name, + ce_uptodate(the_index.cache[pos]) ? "" : " not"); + write_file(name, "%d\n", i); + } discard_cache(); } return 0; diff --git a/t/t7519-status-fsmonitor.sh b/t/t7519-status-fsmonitor.sh index 3e0a61db23..918bc323ab 100755 --- a/t/t7519-status-fsmonitor.sh +++ b/t/t7519-status-fsmonitor.sh @@ -346,4 +346,14 @@ test_expect_success UNTRACKED_CACHE 'ignore .git changes when invalidating UNTR' test_cmp before after ' +test_expect_failure 'discard_index() also discards fsmonitor info' ' + test_when_finished \ + "git config core.monitor .git/hooks/fsmonitor-test" && + test_config core.fsmonitor "$TEST_DIRECTORY/t7519/fsmonitor-all" && + test_might_fail git update-index --refresh && + test-tool read-cache --print-and-refresh=tracked 2 >actual && + printf "tracked is%s up to date\n" "" " not" >expect && + test_cmp expect actual +' + test_done From patchwork Sat Mar 16 09:49:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin via GitGitGadget X-Patchwork-Id: 10855823 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 79E5D6C2 for ; Sat, 16 Mar 2019 09:49:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5EFAC28CDD for ; Sat, 16 Mar 2019 09:49:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 534C528D11; Sat, 16 Mar 2019 09:49:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BD36328D4F for ; Sat, 16 Mar 2019 09:49:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726663AbfCPJtJ (ORCPT ); Sat, 16 Mar 2019 05:49:09 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:33293 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726084AbfCPJtJ (ORCPT ); Sat, 16 Mar 2019 05:49:09 -0400 Received: by mail-ed1-f66.google.com with SMTP id q3so2965842edg.0 for ; Sat, 16 Mar 2019 02:49:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:in-reply-to:references:from:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=xwoLhNt8mcE+FN2e+t63DUPxgpdTQXnSE2JK5vBUT2E=; b=jijjAhMtuLQaTTL45DFv9tJzTw/GF8QBgnhH5evN6d/kTTkDufn5sSoVz6qQnbeRTD f8USgPTnrH+9kPc2+rbEx7a+NgWGQ3wO5bm0HAx7gRuDCfkOfSbJBxbNrzOPFFr2vcS7 mZnaLu4vAIWuvSXzpfMOhQjmgqtP0ZLlTGMmEG7yBv4u4vV72mrQeHSTK/Op/GRMniWa ZwRbPBMILB0vQj57QkWxnIAtE6xYcg5C29Y8id4KDNIpQrLZPZd90jowt5vsrWbds6Sl fKqX6bdVuPhickb0gMJMC3O7C6b24ZWnwtENTjvMnyya3bhw7kfs6LpYkD47VUC/T4Jv +wJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:in-reply-to:references:from :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=xwoLhNt8mcE+FN2e+t63DUPxgpdTQXnSE2JK5vBUT2E=; b=S7q8BJuwbJiw3mw2zs3lkPoUfppg4Hic9kLg1UR75le+XMNDhfj4/BMMlWkQQOUf8N HLhfNcAGGXo6o7+sMWpUdPkxdfIkMZkZwqXeKHuTN5DtEKc8L3IkmZk1VCbqQrZQVz84 YXJ/stEJ68qS084ECRgzHxenLoTO1Xhzcbh5yJhzu4yZ8MSz7Af6BJcPs7/ISLNuYsev N/7Bk/3RNM+QMkNipekGJbrdaiwZDNBSoSplJyX2xr/AJbIv3ZYc5K3Hc+eRDXrlRbSU 4OO10X2rUEhCcKfQs14jONXGtIh/+v99SS3I8XEaGkWic4GkGROhAxd/UcPiG/+BES1R A/ew== X-Gm-Message-State: APjAAAWifpmGL6MX6LBMuqt2FRcm4t63rQgyAPnPmM84UhMGI1zvI2Nx eWYQ3UtHvgzpQIayTS33PkRSiGDZ X-Google-Smtp-Source: APXvYqyGE6CFR8zOje3lQ2+o0PTX4VnEVJwPg5dHQrGf3LsI+HARurtIvOG207n2z9yL42EcSaiUXg== X-Received: by 2002:a17:906:54b:: with SMTP id k11mr4958006eja.131.1552729747816; Sat, 16 Mar 2019 02:49:07 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id l15sm962360ejn.77.2019.03.16.02.49.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 16 Mar 2019 02:49:07 -0700 (PDT) Date: Sat, 16 Mar 2019 02:49:07 -0700 (PDT) X-Google-Original-Date: Sat, 16 Mar 2019 09:49:05 GMT Message-Id: <1d626237762f29d6f617f706a06a024811993185.1552729745.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Johannes Schindelin via GitGitGadget" Subject: [PATCH 2/2] fsmonitor: force a refresh after the index was discarded Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Ben Peart , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Junio C Hamano , Johannes Schindelin Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Johannes Schindelin With this change, the `index_state` struct becomes the new home for the flag that says whether the fsmonitor hook has been run, i.e. it is now per-index. It also gets re-set when the index is discarded, fixing the bug where fsmonitor-enabled Git would miss updates under certain circumstances. Signed-off-by: Johannes Schindelin --- cache.h | 3 ++- fsmonitor.c | 5 ++--- read-cache.c | 1 + t/t7519-status-fsmonitor.sh | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/cache.h b/cache.h index abd518a9a2..8d07c29c2a 100644 --- a/cache.h +++ b/cache.h @@ -339,7 +339,8 @@ struct index_state { struct cache_time timestamp; unsigned name_hash_initialized : 1, initialized : 1, - drop_cache_tree : 1; + drop_cache_tree : 1, + fsmonitor_has_run_once : 1; struct hashmap name_hash; struct hashmap dir_hash; struct object_id oid; diff --git a/fsmonitor.c b/fsmonitor.c index 665bd2d425..1dee0aded1 100644 --- a/fsmonitor.c +++ b/fsmonitor.c @@ -129,7 +129,6 @@ static void fsmonitor_refresh_callback(struct index_state *istate, const char *n void refresh_fsmonitor(struct index_state *istate) { - static int has_run_once = 0; struct strbuf query_result = STRBUF_INIT; int query_success = 0; size_t bol; /* beginning of line */ @@ -137,9 +136,9 @@ void refresh_fsmonitor(struct index_state *istate) char *buf; int i; - if (!core_fsmonitor || has_run_once) + if (!core_fsmonitor || istate->fsmonitor_has_run_once) return; - has_run_once = 1; + istate->fsmonitor_has_run_once = 1; trace_printf_key(&trace_fsmonitor, "refresh fsmonitor"); /* diff --git a/read-cache.c b/read-cache.c index 4dc6de1b55..0bf39e177a 100644 --- a/read-cache.c +++ b/read-cache.c @@ -2335,6 +2335,7 @@ int discard_index(struct index_state *istate) free_name_hash(istate); cache_tree_free(&(istate->cache_tree)); istate->initialized = 0; + istate->fsmonitor_has_run_once = 0; FREE_AND_NULL(istate->cache); istate->cache_alloc = 0; discard_split_index(istate); diff --git a/t/t7519-status-fsmonitor.sh b/t/t7519-status-fsmonitor.sh index 918bc323ab..72b9ed3e45 100755 --- a/t/t7519-status-fsmonitor.sh +++ b/t/t7519-status-fsmonitor.sh @@ -346,7 +346,7 @@ test_expect_success UNTRACKED_CACHE 'ignore .git changes when invalidating UNTR' test_cmp before after ' -test_expect_failure 'discard_index() also discards fsmonitor info' ' +test_expect_success 'discard_index() also discards fsmonitor info' ' test_when_finished \ "git config core.monitor .git/hooks/fsmonitor-test" && test_config core.fsmonitor "$TEST_DIRECTORY/t7519/fsmonitor-all" &&