From patchwork Wed Oct 13 20:31:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Hostetler X-Patchwork-Id: 12556891 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 082D9C4332F for ; Wed, 13 Oct 2021 20:31:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DD55D610E5 for ; Wed, 13 Oct 2021 20:31:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229730AbhJMUd5 (ORCPT ); Wed, 13 Oct 2021 16:33:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229615AbhJMUdy (ORCPT ); Wed, 13 Oct 2021 16:33:54 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C06BC061746 for ; Wed, 13 Oct 2021 13:31:50 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id r7so12374697wrc.10 for ; Wed, 13 Oct 2021 13:31:50 -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=SbbdgLi1cHIa2BbYx4STh/bPoVh7i9SdShiJl1YSCVc=; b=qhLFc3b1EwRUG+ABE24ZmwptquItd5itHZqrof30ypd6zX7SzSF2F6NYtXr6TqS8ex JX2LCJgLO9RfkKNZNjQpiAJecWsWRB05F3p3RbkV8l4zHdu6E8koy2ol4z1KI+SbQHLB irWqxYgc85zCLlhh9W7I4z2f7yQe691wKFwPr1tF0mkUDUEoLvAwvAICTjL+TfK9Fi34 8HSkLkz1qLKMIj5DTLNT9/7t+YLAnou1x/8IPJvxSgZ10vuj10Z4q27gLr/Omw8Zu2W7 BrYej8wvIYiA/U8vN8BHy4NyfjQwX7TV6DCcrc5VrE25piXn7G2ZbPEZLezHTRbfQVEO 89xA== 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=SbbdgLi1cHIa2BbYx4STh/bPoVh7i9SdShiJl1YSCVc=; b=mUtypCAMRdgtqL7EGgbsOWtP7Vn19lr2GHWTXKgttaXQZTjidioIuJGkjZbrUK4A0P CTFPebNB3xn9D1d1ufpKATmLbWnr8IrR/euei+qniG+wrdlY9TqKWfKc6rTenZU/X2d8 9yAI6Dpg0nqrg2wXHVurh4IZwUMG77RtZsbSyDEl5hK/zqo5RZa9u4eRqGt2tjCqkDUB sUNLsSu9vFnNNCheSOpKy9y/PYyP8IQBf06Y6rFJVe3zeAg5uoPcfS7op6rTLdXj514h rUsLJHTDp0JSWoa3KuQaAWgdzQjolp+/mb5YxPhv7DinhvedsiJC2pPYwtfA6ExmnlPT RNYQ== X-Gm-Message-State: AOAM531kdEJ184pOXZ25P9kSmABq7M7n5q/S5i86iHFIgEh6eKt4/sAt eeeGQOFZI14ULXzdAy04iAXsvZ55Jew= X-Google-Smtp-Source: ABdhPJzMcx+oZIVQVW5MRKTAYGyzvfsjATsUTH0BsFGTk+YqALm3reOTFqJAZM4mJbQaZiI4gTORjA== X-Received: by 2002:a05:600c:b43:: with SMTP id k3mr1476648wmr.142.1634157109289; Wed, 13 Oct 2021 13:31:49 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id y191sm6919753wmc.36.2021.10.13.13.31.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Oct 2021 13:31:49 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Wed, 13 Oct 2021 20:31:43 +0000 Subject: [PATCH v3 1/5] fsmonitor: enhance existing comments Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Jeff Hostetler , Jeff Hostetler , Jeff Hostetler Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Jeff Hostetler From: Jeff Hostetler Signed-off-by: Jeff Hostetler --- fsmonitor.c | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/fsmonitor.c b/fsmonitor.c index ab9bfc60b34..ec4c46407c5 100644 --- a/fsmonitor.c +++ b/fsmonitor.c @@ -301,9 +301,25 @@ void refresh_fsmonitor(struct index_state *istate) core_fsmonitor, query_success ? "success" : "failure"); } - /* a fsmonitor process can return '/' to indicate all entries are invalid */ + /* + * The response from FSMonitor (excluding the header token) is + * either: + * + * [a] a (possibly empty) list of NUL delimited relative + * pathnames of changed paths. This list can contain + * files and directories. Directories have a trailing + * slash. + * + * [b] a single '/' to indicate the provider had no + * information and that we should consider everything + * invalid. We call this a trivial response. + */ if (query_success && query_result.buf[bol] != '/') { - /* Mark all entries returned by the monitor as dirty */ + /* + * Mark all pathnames returned by the monitor as dirty. + * + * This updates both the cache-entries and the untracked-cache. + */ buf = query_result.buf; for (i = bol; i < query_result.len; i++) { if (buf[i] != '\0') @@ -318,11 +334,15 @@ void refresh_fsmonitor(struct index_state *istate) if (istate->untracked) istate->untracked->use_fsmonitor = 1; } else { - - /* We only want to run the post index changed hook if we've actually changed entries, so keep track - * if we actually changed entries or not */ + /* + * We received a trivial response, so invalidate everything. + * + * We only want to run the post index changed hook if + * we've actually changed entries, so keep track if we + * actually changed entries or not. + */ int is_cache_changed = 0; - /* Mark all entries invalid */ + for (i = 0; i < istate->cache_nr; i++) { if (istate->cache[i]->ce_flags & CE_FSMONITOR_VALID) { is_cache_changed = 1; @@ -330,7 +350,10 @@ void refresh_fsmonitor(struct index_state *istate) } } - /* If we're going to check every file, ensure we save the results */ + /* + * If we're going to check every file, ensure we save + * the results. + */ if (is_cache_changed) istate->cache_changed |= FSMONITOR_CHANGED; From patchwork Wed Oct 13 20:31:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Hostetler X-Patchwork-Id: 12556889 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 56A6FC433F5 for ; Wed, 13 Oct 2021 20:31:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 33E08610D0 for ; Wed, 13 Oct 2021 20:31:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229725AbhJMUd4 (ORCPT ); Wed, 13 Oct 2021 16:33:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229629AbhJMUdz (ORCPT ); Wed, 13 Oct 2021 16:33:55 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4FA19C061749 for ; Wed, 13 Oct 2021 13:31:51 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id i12so12339151wrb.7 for ; Wed, 13 Oct 2021 13:31:51 -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=LDTU64WFptNk/iCaHfjIEBqLqjrKE0oTr84qceM5FAQ=; b=lb6mv1ihSDWShqAPhSVNJtHUMxYTPg1AI/kdE+oLJpZuQKWXGHxGR2CkMCcKqAIteF IZoenbhmPISZsWN8enlYBZzKu4smkOlhw8d5xnBaPTZf7X8sTpe6H+EPRLHVPFP8i5ag 1IZkuDfeswHvgT+wFbUCPz4acOYtG8z3yVlS66cLkhHzuc36EmmDG37QKyUBmkDchdye 7iQ5EHwU70f3fj5dQ+qT0fq3OJkG1fIcC4CXlAoZIQ0Cs/m45QxLaXaMLlhZBH6Ead+t yBW+pGy3mrAqvx2ljdkjkeu0fgPVlyde/r4dxTS951D2niGtDMgk9yT4WrgPdZFv2QuA DDaw== 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=LDTU64WFptNk/iCaHfjIEBqLqjrKE0oTr84qceM5FAQ=; b=Ttz6N1YVcl/4h/rhOIm3i/kkaAlFtlhijXMuC6/4/nYL9DWuFqoz16qv93BZfE9zWA TehLNacbNhEaVYdqu7pg7JDiAX+7nCHkyjdgju77cW7OHthqJvEymat9WYjB0hQbmEci NJTfnIe+/bPH8DqmABeTHEnLnk4qdEIOpUfK/0LvGcNM4yHhs5WcvtUEgHr2FyzB0hK1 393h3urQR0kUIRDcBFYLxHzHOeSjyGegUNU0MJQyIpbLRdMNyK5OmrOFWRndcyzp3q3A u39jTs+LkG/+vNOh/sEtGmjQStYTx4lQQaTtjDyKQX3ICPEl8bBy5EyKM70lVTGZ2Q5k FU3A== X-Gm-Message-State: AOAM5311NYvTi7+9Q91pD6XlfFL8pLffgKSg3sjOJan8vU+6G34+vTLw gvi1rfrSs2worCX9SVWTv1BLXiQqxBg= X-Google-Smtp-Source: ABdhPJyVSTgFSvwBPuEKlh4B1SZDPuRd1aUqDedoDd/WCGsZT4pATgVDMBnncS7nyIfDE5wjia21Sg== X-Received: by 2002:a05:6000:1563:: with SMTP id 3mr1609615wrz.152.1634157109852; Wed, 13 Oct 2021 13:31:49 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id t11sm529628wrz.65.2021.10.13.13.31.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Oct 2021 13:31:49 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Wed, 13 Oct 2021 20:31:44 +0000 Subject: [PATCH v3 2/5] fsmonitor-ipc: create client routines for git-fsmonitor--daemon Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Jeff Hostetler , Jeff Hostetler , Jeff Hostetler Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Jeff Hostetler From: Jeff Hostetler Create fsmonitor_ipc__*() client routines to spawn the built-in file system monitor daemon and send it an IPC request using the `Simple IPC` API. Stub in empty fsmonitor_ipc__*() functions for unsupported platforms. Signed-off-by: Jeff Hostetler --- Makefile | 1 + fsmonitor-ipc.c | 176 ++++++++++++++++++++++++++++++++++++++++++++++++ fsmonitor-ipc.h | 48 +++++++++++++ 3 files changed, 225 insertions(+) create mode 100644 fsmonitor-ipc.c create mode 100644 fsmonitor-ipc.h diff --git a/Makefile b/Makefile index 381bed2c1d2..d51fd8b33ce 100644 --- a/Makefile +++ b/Makefile @@ -897,6 +897,7 @@ LIB_OBJS += fetch-pack.o LIB_OBJS += fmt-merge-msg.o LIB_OBJS += fsck.o LIB_OBJS += fsmonitor.o +LIB_OBJS += fsmonitor-ipc.o LIB_OBJS += gettext.o LIB_OBJS += gpg-interface.o LIB_OBJS += graph.o diff --git a/fsmonitor-ipc.c b/fsmonitor-ipc.c new file mode 100644 index 00000000000..ccc32d2a17e --- /dev/null +++ b/fsmonitor-ipc.c @@ -0,0 +1,176 @@ +#include "cache.h" +#include "fsmonitor.h" +#include "simple-ipc.h" +#include "fsmonitor-ipc.h" +#include "run-command.h" +#include "strbuf.h" +#include "trace2.h" + +#ifdef HAVE_FSMONITOR_DAEMON_BACKEND + +int fsmonitor_ipc__is_supported(void) +{ + return 1; +} + +GIT_PATH_FUNC(fsmonitor_ipc__get_path, "fsmonitor--daemon.ipc") + +enum ipc_active_state fsmonitor_ipc__get_state(void) +{ + return ipc_get_active_state(fsmonitor_ipc__get_path()); +} + +static int spawn_daemon(void) +{ + const char *args[] = { "fsmonitor--daemon", "start", NULL }; + + return run_command_v_opt_tr2(args, RUN_COMMAND_NO_STDIN | RUN_GIT_CMD, + "fsmonitor"); +} + +int fsmonitor_ipc__send_query(const char *since_token, + struct strbuf *answer) +{ + int ret = -1; + int tried_to_spawn = 0; + enum ipc_active_state state = IPC_STATE__OTHER_ERROR; + struct ipc_client_connection *connection = NULL; + struct ipc_client_connect_options options + = IPC_CLIENT_CONNECT_OPTIONS_INIT; + const char *tok = since_token ? since_token : ""; + size_t tok_len = since_token ? strlen(since_token) : 0; + + options.wait_if_busy = 1; + options.wait_if_not_found = 0; + + trace2_region_enter("fsm_client", "query", NULL); + trace2_data_string("fsm_client", NULL, "query/command", tok); + +try_again: + state = ipc_client_try_connect(fsmonitor_ipc__get_path(), &options, + &connection); + + switch (state) { + case IPC_STATE__LISTENING: + ret = ipc_client_send_command_to_connection( + connection, tok, tok_len, answer); + ipc_client_close_connection(connection); + + trace2_data_intmax("fsm_client", NULL, + "query/response-length", answer->len); + + if (fsmonitor_is_trivial_response(answer)) + trace2_data_intmax("fsm_client", NULL, + "query/trivial-response", 1); + + goto done; + + case IPC_STATE__NOT_LISTENING: + case IPC_STATE__PATH_NOT_FOUND: + if (tried_to_spawn) + goto done; + + tried_to_spawn++; + if (spawn_daemon()) + goto done; + + /* + * Try again, but this time give the daemon a chance to + * actually create the pipe/socket. + * + * Granted, the daemon just started so it can't possibly have + * any FS cached yet, so we'll always get a trivial answer. + * BUT the answer should include a new token that can serve + * as the basis for subsequent requests. + */ + options.wait_if_not_found = 1; + goto try_again; + + case IPC_STATE__INVALID_PATH: + ret = error(_("fsmonitor_ipc__send_query: invalid path '%s'"), + fsmonitor_ipc__get_path()); + goto done; + + case IPC_STATE__OTHER_ERROR: + default: + ret = error(_("fsmonitor_ipc__send_query: unspecified error on '%s'"), + fsmonitor_ipc__get_path()); + goto done; + } + +done: + trace2_region_leave("fsm_client", "query", NULL); + + return ret; +} + +int fsmonitor_ipc__send_command(const char *command, + struct strbuf *answer) +{ + struct ipc_client_connection *connection = NULL; + struct ipc_client_connect_options options + = IPC_CLIENT_CONNECT_OPTIONS_INIT; + int ret; + enum ipc_active_state state; + const char *c = command ? command : ""; + size_t c_len = command ? strlen(command) : 0; + + strbuf_reset(answer); + + options.wait_if_busy = 1; + options.wait_if_not_found = 0; + + state = ipc_client_try_connect(fsmonitor_ipc__get_path(), &options, + &connection); + if (state != IPC_STATE__LISTENING) { + die("fsmonitor--daemon is not running"); + return -1; + } + + ret = ipc_client_send_command_to_connection(connection, c, c_len, + answer); + ipc_client_close_connection(connection); + + if (ret == -1) { + die("could not send '%s' command to fsmonitor--daemon", c); + return -1; + } + + return 0; +} + +#else + +/* + * A trivial implementation of the fsmonitor_ipc__ API for unsupported + * platforms. + */ + +int fsmonitor_ipc__is_supported(void) +{ + return 0; +} + +const char *fsmonitor_ipc__get_path(void) +{ + return NULL; +} + +enum ipc_active_state fsmonitor_ipc__get_state(void) +{ + return IPC_STATE__OTHER_ERROR; +} + +int fsmonitor_ipc__send_query(const char *since_token, + struct strbuf *answer) +{ + return -1; +} + +int fsmonitor_ipc__send_command(const char *command, + struct strbuf *answer) +{ + return -1; +} + +#endif diff --git a/fsmonitor-ipc.h b/fsmonitor-ipc.h new file mode 100644 index 00000000000..b6a7067c3af --- /dev/null +++ b/fsmonitor-ipc.h @@ -0,0 +1,48 @@ +#ifndef FSMONITOR_IPC_H +#define FSMONITOR_IPC_H + +#include "simple-ipc.h" + +/* + * Returns true if built-in file system monitor daemon is defined + * for this platform. + */ +int fsmonitor_ipc__is_supported(void); + +/* + * Returns the pathname to the IPC named pipe or Unix domain socket + * where a `git-fsmonitor--daemon` process will listen. This is a + * per-worktree value. + * + * Returns NULL if the daemon is not supported on this platform. + */ +const char *fsmonitor_ipc__get_path(void); + +/* + * Try to determine whether there is a `git-fsmonitor--daemon` process + * listening on the IPC pipe/socket. + */ +enum ipc_active_state fsmonitor_ipc__get_state(void); + +/* + * Connect to a `git-fsmonitor--daemon` process via simple-ipc + * and ask for the set of changed files since the given token. + * + * Spawn a daemon process in the background if necessary. + * + * Returns -1 on error; 0 on success. + */ +int fsmonitor_ipc__send_query(const char *since_token, + struct strbuf *answer); + +/* + * Connect to a `git-fsmonitor--daemon` process via simple-ipc and + * send a command verb. If no daemon is available, we DO NOT try to + * start one. + * + * Returns -1 on error; 0 on success. + */ +int fsmonitor_ipc__send_command(const char *command, + struct strbuf *answer); + +#endif /* FSMONITOR_IPC_H */ From patchwork Wed Oct 13 20:31:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Hostetler X-Patchwork-Id: 12556893 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 2E720C433EF for ; Wed, 13 Oct 2021 20:31:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0DD80610CE for ; Wed, 13 Oct 2021 20:31:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229745AbhJMUd6 (ORCPT ); Wed, 13 Oct 2021 16:33:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229690AbhJMUdz (ORCPT ); Wed, 13 Oct 2021 16:33:55 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D2D7C061570 for ; Wed, 13 Oct 2021 13:31:52 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id e12so12386288wra.4 for ; Wed, 13 Oct 2021 13:31:52 -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=zpmP3W/LX3GbBYXKGLBxOhIX0wdI/YWEVsIwtSrziJw=; b=fFkny/51iSyjWqwmAnlTK9QGw3XwN/qdbd5IN2pZqJSbPET2TnaKT6km+R9Neb/Trt jeXYJSu4W9ETIxJPN/TwQSDrcNgVqjy5JufLEWXOXDZuXcHVuX4YesTwRxJTSdkg/Xay haJ5qFLfIyAG7pwL3BvZXbYGEe6n+WaafteZctPCUMDV7rQFx9oJrEcVQ7CJdz/Fto2b r1wyttcfYq6X4MHEWgtdWRiklCz9cDSTmnbRb8zxcOBsQ0JhIeAuy3pzBaeHL7UZGblB X96ScHUEICUYPfndlw0DalUYr0M1b3VzkHZnmirqfPU6KNRC70IkpR8V7ThsRS53pB+c a0pw== 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=zpmP3W/LX3GbBYXKGLBxOhIX0wdI/YWEVsIwtSrziJw=; b=bkMTbbUkossXl2HY0nmxMjg1jNhPoMVOp+sPJbvnsINUzVxi/dqTjw30kXndBvwsQH +mzoKfbwIxJTERYcX4qUfHZFFf9uWjIpJCZQZFml1pc3uhCpMWROlOLZc3vgen7fTJz2 matj76hc3u4+SIbYbvKjYqchKa6EsAKUj8ZKF1SM6pq1CO1b3TOds/OS0WxoS+UWedqz LMdmftnkYyK3cpzfcP3NfccjHys4oRuBTYRg0gMyW9W3mVk2XrHsfvBrDe4P/vYmt+h3 gSdNyVQcunF2cO2LuGI72FuwTM9lMDzkcDkmwRg426DH09sCX6phvGduml1oPzSI1fc9 gYCw== X-Gm-Message-State: AOAM530oRF8XO0hhwlzWOrz+vkOVZCigojBI7vhgyiIdY3lEBzQKjoZ8 kExB4wQwgI7jX8+uQfHvT/Rs2aJrGyE= X-Google-Smtp-Source: ABdhPJz6ovKmHYf2fKM3xHEiE87+b33BiODyzQbz1M3AgGcWzNgPMprsuh4uADArms09IZ2JMYVi5Q== X-Received: by 2002:a1c:29c7:: with SMTP id p190mr1440150wmp.65.1634157110595; Wed, 13 Oct 2021 13:31:50 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c17sm5990821wmr.15.2021.10.13.13.31.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Oct 2021 13:31:50 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Wed, 13 Oct 2021 20:31:45 +0000 Subject: [PATCH v3 3/5] fsmonitor: config settings are repository-specific Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Jeff Hostetler , Jeff Hostetler , Jeff Hostetler Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Jeff Hostetler From: Jeff Hostetler Move fsmonitor config settings to a new and opaque `struct fsmonitor_settings` structure. Add a lazily-loaded pointer to this into `struct repo_settings` Create an `enum fsmonitor_mode` type in `struct fsmonitor_settings` to represent the state of fsmonitor. This lets us represent which, if any, fsmonitor provider (hook or IPC) is enabled. Create `fsm_settings__get_*()` getters to lazily look up fsmonitor- related config settings. Add support for the new `core.useBuiltinFSMonitor` config setting. Get rid of the `core_fsmonitor` global variable. Move the code to lookup the existing `core.fsmonitor` config value into the fsmonitor settings. Create a hook pathname variable in `struct fsmonitor-settings` and only set it when in hook mode. The existing `core_fsmonitor` global variable was used to store the pathname to the fsmonitor hook *and* it was used as a boolean to see if fsmonitor was enabled. This dual usage and global visibility leads to confusion when we add the IPC-based provider. So lets hide the details in fsmonitor-settings.c and let it decide which provider to use in the case of multiple settings. This avoids cluttering up repo-settings.c with these private details. A future commit in builtin-fsmonitor series will add the ability to disqualify worktrees for various reasons, such as being mounted from a remote volume, where fsmonitor should not be started. Having the config settings hidden in fsmonitor-settings.c allows such worktree restrictions to override the config values used. Signed-off-by: Jeff Hostetler --- Makefile | 1 + builtin/update-index.c | 19 +++++++-- cache.h | 1 - config.c | 14 ------ config.h | 1 - environment.c | 1 - fsmonitor-settings.c | 97 ++++++++++++++++++++++++++++++++++++++++++ fsmonitor-settings.h | 21 +++++++++ fsmonitor.c | 63 ++++++++++++++++----------- fsmonitor.h | 18 ++++++-- repository.h | 3 ++ t/README | 4 +- 12 files changed, 192 insertions(+), 51 deletions(-) create mode 100644 fsmonitor-settings.c create mode 100644 fsmonitor-settings.h diff --git a/Makefile b/Makefile index d51fd8b33ce..29ed7c4aba6 100644 --- a/Makefile +++ b/Makefile @@ -898,6 +898,7 @@ LIB_OBJS += fmt-merge-msg.o LIB_OBJS += fsck.o LIB_OBJS += fsmonitor.o LIB_OBJS += fsmonitor-ipc.o +LIB_OBJS += fsmonitor-settings.o LIB_OBJS += gettext.o LIB_OBJS += gpg-interface.o LIB_OBJS += graph.o diff --git a/builtin/update-index.c b/builtin/update-index.c index 187203e8bb5..79db3ff37e2 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -1214,14 +1214,25 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) } if (fsmonitor > 0) { - if (git_config_get_fsmonitor() == 0) + enum fsmonitor_mode fsm_mode = fsm_settings__get_mode(r); + + if (fsm_mode == FSMONITOR_MODE_DISABLED) { + warning(_("core.useBuiltinFSMonitor is unset; " + "set it if you really want to enable the " + "builtin fsmonitor")); warning(_("core.fsmonitor is unset; " - "set it if you really want to " - "enable fsmonitor")); + "set it if you really want to enable the " + "hook-based fsmonitor")); + } add_fsmonitor(&the_index); report(_("fsmonitor enabled")); } else if (!fsmonitor) { - if (git_config_get_fsmonitor() == 1) + enum fsmonitor_mode fsm_mode = fsm_settings__get_mode(r); + if (fsm_mode == FSMONITOR_MODE_IPC) + warning(_("core.useBuiltinFSMonitor is set; " + "remove it if you really want to " + "disable fsmonitor")); + if (fsm_mode == FSMONITOR_MODE_HOOK) warning(_("core.fsmonitor is set; " "remove it if you really want to " "disable fsmonitor")); diff --git a/cache.h b/cache.h index d092820c943..8f4e3c8bd1d 100644 --- a/cache.h +++ b/cache.h @@ -989,7 +989,6 @@ extern int core_preload_index; extern int precomposed_unicode; extern int protect_hfs; extern int protect_ntfs; -extern const char *core_fsmonitor; extern int core_apply_sparse_checkout; extern int core_sparse_checkout_cone; diff --git a/config.c b/config.c index 2dcbe901b6b..6b6e9cacac3 100644 --- a/config.c +++ b/config.c @@ -2502,20 +2502,6 @@ int git_config_get_max_percent_split_change(void) return -1; /* default value */ } -int git_config_get_fsmonitor(void) -{ - if (git_config_get_pathname("core.fsmonitor", &core_fsmonitor)) - core_fsmonitor = getenv("GIT_TEST_FSMONITOR"); - - if (core_fsmonitor && !*core_fsmonitor) - core_fsmonitor = NULL; - - if (core_fsmonitor) - return 1; - - return 0; -} - int git_config_get_index_threads(int *dest) { int is_bool, val; diff --git a/config.h b/config.h index f119de01309..69d733824a0 100644 --- a/config.h +++ b/config.h @@ -610,7 +610,6 @@ int git_config_get_pathname(const char *key, const char **dest); int git_config_get_index_threads(int *dest); int git_config_get_split_index(void); int git_config_get_max_percent_split_change(void); -int git_config_get_fsmonitor(void); /* This dies if the configured or default date is in the future */ int git_config_get_expiry(const char *key, const char **output); diff --git a/environment.c b/environment.c index 9da7f3c1a19..68f90632245 100644 --- a/environment.c +++ b/environment.c @@ -82,7 +82,6 @@ int protect_hfs = PROTECT_HFS_DEFAULT; #define PROTECT_NTFS_DEFAULT 1 #endif int protect_ntfs = PROTECT_NTFS_DEFAULT; -const char *core_fsmonitor; /* * The character that begins a commented line in user-editable file diff --git a/fsmonitor-settings.c b/fsmonitor-settings.c new file mode 100644 index 00000000000..2770266f5ee --- /dev/null +++ b/fsmonitor-settings.c @@ -0,0 +1,97 @@ +#include "cache.h" +#include "config.h" +#include "repository.h" +#include "fsmonitor-settings.h" + +/* + * We keep this structure defintion private and have getters + * for all fields so that we can lazy load it as needed. + */ +struct fsmonitor_settings { + enum fsmonitor_mode mode; + char *hook_path; +}; + +void fsm_settings__set_ipc(struct repository *r) +{ + struct fsmonitor_settings *s = r->settings.fsmonitor; + + s->mode = FSMONITOR_MODE_IPC; +} + +void fsm_settings__set_hook(struct repository *r, const char *path) +{ + struct fsmonitor_settings *s = r->settings.fsmonitor; + + s->mode = FSMONITOR_MODE_HOOK; + s->hook_path = strdup(path); +} + +void fsm_settings__set_disabled(struct repository *r) +{ + struct fsmonitor_settings *s = r->settings.fsmonitor; + + s->mode = FSMONITOR_MODE_DISABLED; + FREE_AND_NULL(s->hook_path); +} + +static int check_for_ipc(struct repository *r) +{ + int value; + + if (!repo_config_get_bool(r, "core.usebuiltinfsmonitor", &value) && + value) { + fsm_settings__set_ipc(r); + return 1; + } + + return 0; +} + +static int check_for_hook(struct repository *r) +{ + const char *const_str; + + if (repo_config_get_pathname(r, "core.fsmonitor", &const_str)) + const_str = getenv("GIT_TEST_FSMONITOR"); + + if (const_str && *const_str) { + fsm_settings__set_hook(r, const_str); + return 1; + } + + return 0; +} + +static void lookup_fsmonitor_settings(struct repository *r) +{ + struct fsmonitor_settings *s; + + CALLOC_ARRAY(s, 1); + + r->settings.fsmonitor = s; + + if (check_for_ipc(r)) + return; + + if (check_for_hook(r)) + return; + + fsm_settings__set_disabled(r); +} + +enum fsmonitor_mode fsm_settings__get_mode(struct repository *r) +{ + if (!r->settings.fsmonitor) + lookup_fsmonitor_settings(r); + + return r->settings.fsmonitor->mode; +} + +const char *fsm_settings__get_hook_path(struct repository *r) +{ + if (!r->settings.fsmonitor) + lookup_fsmonitor_settings(r); + + return r->settings.fsmonitor->hook_path; +} diff --git a/fsmonitor-settings.h b/fsmonitor-settings.h new file mode 100644 index 00000000000..50b29234616 --- /dev/null +++ b/fsmonitor-settings.h @@ -0,0 +1,21 @@ +#ifndef FSMONITOR_SETTINGS_H +#define FSMONITOR_SETTINGS_H + +struct repository; + +enum fsmonitor_mode { + FSMONITOR_MODE_DISABLED = 0, + FSMONITOR_MODE_HOOK = 1, /* core.fsmonitor */ + FSMONITOR_MODE_IPC = 2, /* core.useBuiltinFSMonitor */ +}; + +void fsm_settings__set_ipc(struct repository *r); +void fsm_settings__set_hook(struct repository *r, const char *path); +void fsm_settings__set_disabled(struct repository *r); + +enum fsmonitor_mode fsm_settings__get_mode(struct repository *r); +const char *fsm_settings__get_hook_path(struct repository *r); + +struct fsmonitor_settings; + +#endif /* FSMONITOR_SETTINGS_H */ diff --git a/fsmonitor.c b/fsmonitor.c index ec4c46407c5..63174630c0e 100644 --- a/fsmonitor.c +++ b/fsmonitor.c @@ -3,6 +3,7 @@ #include "dir.h" #include "ewah/ewok.h" #include "fsmonitor.h" +#include "fsmonitor-ipc.h" #include "run-command.h" #include "strbuf.h" @@ -148,15 +149,18 @@ void write_fsmonitor_extension(struct strbuf *sb, struct index_state *istate) /* * Call the query-fsmonitor hook passing the last update token of the saved results. */ -static int query_fsmonitor(int version, const char *last_update, struct strbuf *query_result) +static int query_fsmonitor_hook(struct repository *r, + int version, + const char *last_update, + struct strbuf *query_result) { struct child_process cp = CHILD_PROCESS_INIT; int result; - if (!core_fsmonitor) + if (fsm_settings__get_mode(r) != FSMONITOR_MODE_HOOK) return -1; - strvec_push(&cp.args, core_fsmonitor); + strvec_push(&cp.args, fsm_settings__get_hook_path(r)); strvec_pushf(&cp.args, "%d", version); strvec_pushf(&cp.args, "%s", last_update); cp.use_shell = 1; @@ -238,17 +242,28 @@ void refresh_fsmonitor(struct index_state *istate) struct strbuf last_update_token = STRBUF_INIT; char *buf; unsigned int i; + struct repository *r = istate->repo ? istate->repo : the_repository; + enum fsmonitor_mode fsm_mode = fsm_settings__get_mode(r); - if (!core_fsmonitor || istate->fsmonitor_has_run_once) + if (fsm_mode <= FSMONITOR_MODE_DISABLED || + istate->fsmonitor_has_run_once) return; - hook_version = fsmonitor_hook_version(); - istate->fsmonitor_has_run_once = 1; trace_printf_key(&trace_fsmonitor, "refresh fsmonitor"); + + if (fsm_mode == FSMONITOR_MODE_IPC) { + /* TODO */ + return; + } + + assert(fsm_mode == FSMONITOR_MODE_HOOK); + + hook_version = fsmonitor_hook_version(); + /* - * This could be racy so save the date/time now and query_fsmonitor + * This could be racy so save the date/time now and query_fsmonitor_hook * should be inclusive to ensure we don't miss potential changes. */ last_update = getnanotime(); @@ -256,13 +271,14 @@ void refresh_fsmonitor(struct index_state *istate) strbuf_addf(&last_update_token, "%"PRIu64"", last_update); /* - * If we have a last update token, call query_fsmonitor for the set of + * If we have a last update token, call query_fsmonitor_hook for the set of * changes since that token, else assume everything is possibly dirty * and check it all. */ if (istate->fsmonitor_last_update) { if (hook_version == -1 || hook_version == HOOK_INTERFACE_VERSION2) { - query_success = !query_fsmonitor(HOOK_INTERFACE_VERSION2, + query_success = !query_fsmonitor_hook( + r, HOOK_INTERFACE_VERSION2, istate->fsmonitor_last_update, &query_result); if (query_success) { @@ -292,13 +308,17 @@ void refresh_fsmonitor(struct index_state *istate) } if (hook_version == HOOK_INTERFACE_VERSION1) { - query_success = !query_fsmonitor(HOOK_INTERFACE_VERSION1, + query_success = !query_fsmonitor_hook( + r, HOOK_INTERFACE_VERSION1, istate->fsmonitor_last_update, &query_result); } - trace_performance_since(last_update, "fsmonitor process '%s'", core_fsmonitor); - trace_printf_key(&trace_fsmonitor, "fsmonitor process '%s' returned %s", - core_fsmonitor, query_success ? "success" : "failure"); + trace_performance_since(last_update, "fsmonitor process '%s'", + fsm_settings__get_hook_path(r)); + trace_printf_key(&trace_fsmonitor, + "fsmonitor process '%s' returned %s", + fsm_settings__get_hook_path(r), + query_success ? "success" : "failure"); } /* @@ -434,7 +454,8 @@ void remove_fsmonitor(struct index_state *istate) void tweak_fsmonitor(struct index_state *istate) { unsigned int i; - int fsmonitor_enabled = git_config_get_fsmonitor(); + struct repository *r = istate->repo ? istate->repo : the_repository; + int fsmonitor_enabled = (fsm_settings__get_mode(r) > FSMONITOR_MODE_DISABLED); if (istate->fsmonitor_dirty) { if (fsmonitor_enabled) { @@ -454,16 +475,8 @@ void tweak_fsmonitor(struct index_state *istate) istate->fsmonitor_dirty = NULL; } - switch (fsmonitor_enabled) { - case -1: /* keep: do nothing */ - break; - case 0: /* false */ - remove_fsmonitor(istate); - break; - case 1: /* true */ + if (fsmonitor_enabled) add_fsmonitor(istate); - break; - default: /* unknown value: do nothing */ - break; - } + else + remove_fsmonitor(istate); } diff --git a/fsmonitor.h b/fsmonitor.h index f20d72631d7..f9201411aa7 100644 --- a/fsmonitor.h +++ b/fsmonitor.h @@ -3,6 +3,7 @@ #include "cache.h" #include "dir.h" +#include "fsmonitor-settings.h" extern struct trace_key trace_fsmonitor; @@ -57,7 +58,11 @@ int fsmonitor_is_trivial_response(const struct strbuf *query_result); */ static inline int is_fsmonitor_refreshed(const struct index_state *istate) { - return !core_fsmonitor || istate->fsmonitor_has_run_once; + struct repository *r = istate->repo ? istate->repo : the_repository; + enum fsmonitor_mode fsm_mode = fsm_settings__get_mode(r); + + return fsm_mode <= FSMONITOR_MODE_DISABLED || + istate->fsmonitor_has_run_once; } /* @@ -67,7 +72,11 @@ static inline int is_fsmonitor_refreshed(const struct index_state *istate) */ static inline void mark_fsmonitor_valid(struct index_state *istate, struct cache_entry *ce) { - if (core_fsmonitor && !(ce->ce_flags & CE_FSMONITOR_VALID)) { + struct repository *r = istate->repo ? istate->repo : the_repository; + enum fsmonitor_mode fsm_mode = fsm_settings__get_mode(r); + + if (fsm_mode > FSMONITOR_MODE_DISABLED && + !(ce->ce_flags & CE_FSMONITOR_VALID)) { istate->cache_changed = 1; ce->ce_flags |= CE_FSMONITOR_VALID; trace_printf_key(&trace_fsmonitor, "mark_fsmonitor_clean '%s'", ce->name); @@ -83,7 +92,10 @@ static inline void mark_fsmonitor_valid(struct index_state *istate, struct cache */ static inline void mark_fsmonitor_invalid(struct index_state *istate, struct cache_entry *ce) { - if (core_fsmonitor) { + struct repository *r = istate->repo ? istate->repo : the_repository; + enum fsmonitor_mode fsm_mode = fsm_settings__get_mode(r); + + if (fsm_mode > FSMONITOR_MODE_DISABLED) { ce->ce_flags &= ~CE_FSMONITOR_VALID; untracked_cache_invalidate_path(istate, ce->name, 1); trace_printf_key(&trace_fsmonitor, "mark_fsmonitor_invalid '%s'", ce->name); diff --git a/repository.h b/repository.h index a057653981c..89a1873ade7 100644 --- a/repository.h +++ b/repository.h @@ -4,6 +4,7 @@ #include "path.h" struct config_set; +struct fsmonitor_settings; struct git_hash_algo; struct index_state; struct lock_file; @@ -34,6 +35,8 @@ struct repo_settings { int command_requires_full_index; int sparse_index; + struct fsmonitor_settings *fsmonitor; /* lazy loaded */ + int index_version; enum untracked_cache_setting core_untracked_cache; diff --git a/t/README b/t/README index b92155a822e..6dc4a1d10cf 100644 --- a/t/README +++ b/t/README @@ -405,8 +405,8 @@ every 'git commit-graph write', as if the `--changed-paths` option was passed in. GIT_TEST_FSMONITOR=$PWD/t7519/fsmonitor-all exercises the fsmonitor -code path for utilizing a file system monitor to speed up detecting -new or changed files. +code path for utilizing a (hook based) file system monitor to speed up +detecting new or changed files. GIT_TEST_INDEX_VERSION= exercises the index read/write code path for the index version specified. Can be set to any valid version From patchwork Wed Oct 13 20:31:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Hostetler X-Patchwork-Id: 12556895 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 7BB45C433FE for ; Wed, 13 Oct 2021 20:31:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 58984610E5 for ; Wed, 13 Oct 2021 20:31:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229769AbhJMUeA (ORCPT ); Wed, 13 Oct 2021 16:34:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229721AbhJMUd4 (ORCPT ); Wed, 13 Oct 2021 16:33:56 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77A8BC061746 for ; Wed, 13 Oct 2021 13:31:52 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id e12so12386387wra.4 for ; Wed, 13 Oct 2021 13:31:52 -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=OPR/cD4g5iSikjECMnICO/QPaQt/LlN2JVqikY/G/54=; b=VYs4Xmrl+Ofoo7+qhT0kESE8JUC7abEUY1xcec9ktVxRizdyeqC0ovUiDP0NDt/tho lIs62fZ4JFXEvx8/uAIwqI4IMQVYZCZXv8LRuoQWXQQxSS29D2vqZnvlM/+ezvydtL9B a8X/kLODcAmOizRMdspdtaV/yOw+JPbhTBmCClKRK5AjoxxIt40scXDimH9DAdNOGfvE 4S9sF1bGARpu5Jo2c+zVY30/DBBAck79JD4BPmuiigrM1R143azdiQDCV63SS9a939z9 qYX0r1zUjCn+X+e3Vbfg4/4IFAVzDTc1BDr+xdyOGOcgHkQTveU+K/zw7Ku7veeJw+40 LUMQ== 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=OPR/cD4g5iSikjECMnICO/QPaQt/LlN2JVqikY/G/54=; b=PRWl0YKowq7V7YJwBdzleZ1b3Uni/SDqw4yrjKuADFptNK1pinidMlAnRQSOvo2RkO E3K5oLl2LTiSvsopnYM7wfaM5fM6a+Su9jAnTjVqCddhnhq70ZY0NSWvGHlHa/qjoSos 9OwS0WnXusU8Z0pGkYpxR7PfdYoVQRrIUiV+Fh60/Fmpn6xYCcPVER148rQGGOSx5s9r iIVbWprE5nGcK9m1SBVvsP3vjMTjdUSyOa/YP2ws23hHmpO+V0IVgPUHU/FSRgIAP8yL qfOO+a8tY87oL7LG40g36j6o5JD73wIA+g4KqoPZy2afikkHhip5P82ZOhJlPW1snHoK kA1A== X-Gm-Message-State: AOAM533MeXtM6qShGXD4z3AmkxvPf4Bh4NHWyGPXedBDJq33SmI3Tq1p SHLRvr93C9TukfkaAxfz24PtVzzEWvA= X-Google-Smtp-Source: ABdhPJxahKpVDhmIqQN77Hm/U3N1+donqA6OlxzrU7fW7m0wwMDrGk549wvzIOPhYjhVMTsCHrIZgQ== X-Received: by 2002:a05:6000:18cf:: with SMTP id w15mr1549199wrq.314.1634157111167; Wed, 13 Oct 2021 13:31:51 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id f127sm5897268wmf.16.2021.10.13.13.31.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Oct 2021 13:31:50 -0700 (PDT) Message-Id: <4d8d812be084459b850f11c811bbfc02c4c6f8c4.1634157108.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 13 Oct 2021 20:31:46 +0000 Subject: [PATCH v3 4/5] fsmonitor: use IPC to query the builtin FSMonitor daemon Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Jeff Hostetler , Jeff Hostetler , Jeff Hostetler Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Jeff Hostetler From: Jeff Hostetler Use simple IPC to directly communicate with the new builtin file system monitor daemon when `core.useBuiltinFSMonitor` is set. The `core.fsmonitor` setting has already been defined as a HOOK pathname. Historically, this has been set to a HOOK script that will talk with Watchman. For compatibility reasons, we do not want to overload that definition (and cause problems if users have multiple versions of Git installed). Signed-off-by: Johannes Schindelin Signed-off-by: Jeff Hostetler --- fsmonitor.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/fsmonitor.c b/fsmonitor.c index 63174630c0e..695fb0ce4e7 100644 --- a/fsmonitor.c +++ b/fsmonitor.c @@ -254,8 +254,37 @@ void refresh_fsmonitor(struct index_state *istate) trace_printf_key(&trace_fsmonitor, "refresh fsmonitor"); if (fsm_mode == FSMONITOR_MODE_IPC) { - /* TODO */ - return; + query_success = !fsmonitor_ipc__send_query( + istate->fsmonitor_last_update ? + istate->fsmonitor_last_update : "builtin:fake", + &query_result); + if (query_success) { + /* + * The response contains a series of nul terminated + * strings. The first is the new token. + * + * Use `char *buf` as an interlude to trick the CI + * static analysis to let us use `strbuf_addstr()` + * here (and only copy the token) rather than + * `strbuf_addbuf()`. + */ + buf = query_result.buf; + strbuf_addstr(&last_update_token, buf); + bol = last_update_token.len + 1; + } else { + /* + * The builtin daemon is not available on this + * platform -OR- we failed to get a response. + * + * Generate a fake token (rather than a V1 + * timestamp) for the index extension. (If + * they switch back to the hook API, we don't + * want ambiguous state.) + */ + strbuf_addstr(&last_update_token, "builtin:fake"); + } + + goto apply_results; } assert(fsm_mode == FSMONITOR_MODE_HOOK); @@ -321,6 +350,7 @@ void refresh_fsmonitor(struct index_state *istate) query_success ? "success" : "failure"); } +apply_results: /* * The response from FSMonitor (excluding the header token) is * either: From patchwork Wed Oct 13 20:31:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Hostetler X-Patchwork-Id: 12556897 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 5E5D1C433EF for ; Wed, 13 Oct 2021 20:31:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 40873610EA for ; Wed, 13 Oct 2021 20:31:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229785AbhJMUeC (ORCPT ); Wed, 13 Oct 2021 16:34:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229726AbhJMUd4 (ORCPT ); Wed, 13 Oct 2021 16:33:56 -0400 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 20658C061570 for ; Wed, 13 Oct 2021 13:31:53 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id i12so12339474wrb.7 for ; Wed, 13 Oct 2021 13:31:53 -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=rgNztFjSIfkFrumoWBCPgDcO19sT/SrE7dYPYozTBh8=; b=gSqz708Sj7ksvbm133sxKGlCtPvtMNZBFVsAHD16/KuE5IaTNFd1zsJrCc0BfyBEQy QqRAkMOxDZ0xzpeiqCrGuwLibqEWbkgDgPsu5Tap6nKhonKd9+Dv5WyMMjX3xg9mxQiP aBGpcdoFQcbzAlre+xySP3NhjxcaIUET8x+U6BPuqvLpzj531+Iw2t9dONZ6pdIouw2b siuu4Vxe9jM+2dX69OTTlbu9U4r1xWrWuvbcf3hNieWvklVwpnYouycVms63CNzqdfV1 6QgOPwshWpAS/ZIBoDgaclteXYOKXutO7nVEXZ8wJiHQz5hm6r3P5L1FpfhfmGqtDOxt a/fA== 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=rgNztFjSIfkFrumoWBCPgDcO19sT/SrE7dYPYozTBh8=; b=zSJ+OZ9k559aBoB/R4nZMOODR0mNIQAI2/5Acqfap+y5xp5bHUDUUKlSemjKMoeO6O 3QA3xfQjWwDazrHg1YFicS/2f4iZRs6L3ty73LB/5a6FntwfhBfctFOJM06ejMmiHQTS TexgLSb+cWBTi9Iz0nl4WGpwHLLX2N4YkbYeVJ9SvVh/J1nlZnenOvDH/pjhMWlLiZ5l FRFvZdwjRfzA8wGFbGVMQLtoI+RnDS9R+Qw3Vyf/CMDG0PtNJcdFhZxgxct/AOxU0XPN T/XN4wBjAshb6BJbGyEtXoTwmx4kBcCTeBZycbTo3gsjtBu22WkRq05Gpw2B8tfxJDl9 651A== X-Gm-Message-State: AOAM531FUCINJyozfMMwuCPBzlDYrgIhvCFJUeTcI4YSyYBgNL+nDW6h tUQ4R3fCsAJGL9TnM1j+Q8AVNJBkSlk= X-Google-Smtp-Source: ABdhPJytTTdre9lJ+DdksX3qOBBrDhLCxf9K8rquFIE+ltfl5E+ESk1ExF3jUeFyNsly6LQcma7r+A== X-Received: by 2002:a05:600c:3b1a:: with SMTP id m26mr14528786wms.130.1634157111728; Wed, 13 Oct 2021 13:31:51 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id w5sm488827wrq.86.2021.10.13.13.31.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Oct 2021 13:31:51 -0700 (PDT) Message-Id: <45a86cef8d75911e3448dc9e3cb3d4f7c0ee76a0.1634157108.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 13 Oct 2021 20:31:47 +0000 Subject: [PATCH v3 5/5] fsmonitor: update fsmonitor config documentation Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Jeff Hostetler , Jeff Hostetler , Jeff Hostetler Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Jeff Hostetler From: Jeff Hostetler Update references to `core.fsmonitor` and `core.fsmonitorHookVersion` and pointers to `Watchman` to mention the new `core.useBuiltinFSMonitor` value. Signed-off-by: Jeff Hostetler --- Documentation/config/core.txt | 56 ++++++++++++++++++++++-------- Documentation/git-update-index.txt | 27 +++++++------- Documentation/githooks.txt | 3 +- 3 files changed, 59 insertions(+), 27 deletions(-) diff --git a/Documentation/config/core.txt b/Documentation/config/core.txt index c04f62a54a1..4f6e519bc02 100644 --- a/Documentation/config/core.txt +++ b/Documentation/config/core.txt @@ -62,22 +62,50 @@ core.protectNTFS:: Defaults to `true` on Windows, and `false` elsewhere. core.fsmonitor:: - If set, the value of this variable is used as a command which - will identify all files that may have changed since the - requested date/time. This information is used to speed up git by - avoiding unnecessary processing of files that have not changed. - See the "fsmonitor-watchman" section of linkgit:githooks[5]. + If set, this variable contains the pathname of the "fsmonitor" + hook command. ++ +This hook command is used to identify all files that may have changed +since the requested date/time. This information is used to speed up +git by avoiding unnecessary scanning of files that have not changed. ++ +See the "fsmonitor-watchman" section of linkgit:githooks[5]. ++ +Note: The value of this config setting is ignored if the +built-in file system monitor is enabled (see `core.useBuiltinFSMonitor`). core.fsmonitorHookVersion:: - Sets the version of hook that is to be used when calling fsmonitor. - There are currently versions 1 and 2. When this is not set, - version 2 will be tried first and if it fails then version 1 - will be tried. Version 1 uses a timestamp as input to determine - which files have changes since that time but some monitors - like watchman have race conditions when used with a timestamp. - Version 2 uses an opaque string so that the monitor can return - something that can be used to determine what files have changed - without race conditions. + Sets the protocol version to be used when invoking the + "fsmonitor" hook. ++ +There are currently versions 1 and 2. When this is not set, +version 2 will be tried first and if it fails then version 1 +will be tried. Version 1 uses a timestamp as input to determine +which files have changes since that time but some monitors +like Watchman have race conditions when used with a timestamp. +Version 2 uses an opaque string so that the monitor can return +something that can be used to determine what files have changed +without race conditions. ++ +Note: The value of this config setting is ignored if the +built-in file system monitor is enabled (see `core.useBuiltinFSMonitor`). + +core.useBuiltinFSMonitor:: + If set to true, enable the built-in file system monitor + daemon for this working directory (linkgit:git-fsmonitor--daemon[1]). ++ +Like hook-based file system monitors, the built-in file system monitor +can speed up Git commands that need to refresh the Git index +(e.g. `git status`) in a working directory with many files. The +built-in monitor eliminates the need to install and maintain an +external third-party tool. ++ +The built-in file system monitor is currently available only on a +limited set of supported platforms. Currently, this includes Windows +and MacOS. ++ +Note: if this config setting is set to `true`, the values of +`core.fsmonitor` and `core.fsmonitorHookVersion` are ignored. core.trustctime:: If false, the ctime differences between the index and the diff --git a/Documentation/git-update-index.txt b/Documentation/git-update-index.txt index 2853f168d97..c7c31b3fcf9 100644 --- a/Documentation/git-update-index.txt +++ b/Documentation/git-update-index.txt @@ -498,7 +498,9 @@ FILE SYSTEM MONITOR This feature is intended to speed up git operations for repos that have large working directories. -It enables git to work together with a file system monitor (see the +It enables git to work together with a file system monitor (see +linkgit:git-fsmonitor--daemon[1] +and the "fsmonitor-watchman" section of linkgit:githooks[5]) that can inform it as to what files have been modified. This enables git to avoid having to lstat() every file to find modified files. @@ -508,17 +510,18 @@ performance by avoiding the cost of scanning the entire working directory looking for new files. If you want to enable (or disable) this feature, it is easier to use -the `core.fsmonitor` configuration variable (see -linkgit:git-config[1]) than using the `--fsmonitor` option to -`git update-index` in each repository, especially if you want to do so -across all repositories you use, because you can set the configuration -variable in your `$HOME/.gitconfig` just once and have it affect all -repositories you touch. - -When the `core.fsmonitor` configuration variable is changed, the -file system monitor is added to or removed from the index the next time -a command reads the index. When `--[no-]fsmonitor` are used, the file -system monitor is immediately added to or removed from the index. +the `core.fsmonitor` or `core.useBuiltinFSMonitor` configuration +variable (see linkgit:git-config[1]) than using the `--fsmonitor` +option to `git update-index` in each repository, especially if you +want to do so across all repositories you use, because you can set the +configuration variable in your `$HOME/.gitconfig` just once and have +it affect all repositories you touch. + +When the `core.fsmonitor` or `core.useBuiltinFSMonitor` configuration +variable is changed, the file system monitor is added to or removed +from the index the next time a command reads the index. When +`--[no-]fsmonitor` are used, the file system monitor is immediately +added to or removed from the index. CONFIGURATION ------------- diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt index b51959ff941..b7d5e926f7b 100644 --- a/Documentation/githooks.txt +++ b/Documentation/githooks.txt @@ -593,7 +593,8 @@ fsmonitor-watchman This hook is invoked when the configuration option `core.fsmonitor` is set to `.git/hooks/fsmonitor-watchman` or `.git/hooks/fsmonitor-watchmanv2` -depending on the version of the hook to use. +depending on the version of the hook to use, unless overridden via +`core.useBuiltinFSMonitor` (see linkgit:git-config[1]). Version 1 takes two arguments, a version (1) and the time in elapsed nanoseconds since midnight, January 1, 1970.