{"thread":{"id":"55582","subject":"[PATCH] fsmonitor: only enable it in non-bare repositories","startedAt":"2021-04-29T07:46:07Z","lastAt":"2021-05-11T19:24:11Z","messageCount":7,"participants":["Johannes Schindelin via GitGitGadget","Junio C Hamano","Ævar Arnfjörð Bjarmason","Jeff Hostetler"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"423247","messageId":"pull.942.git.1619682362363.gitgitgadget@gmail.com","threadId":"55582","inReplyTo":null,"subject":"[PATCH] fsmonitor: only enable it in non-bare repositories","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2021-04-29T07:46:01Z","receivedAt":"2021-04-29T07:46:07Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"From: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nThe entire point of the FSMonitor is to monitor the worktree changes in\na more efficient manner than `lstat()`ing all worktree files every time\nwe refresh the index.\n\nBut if there is no worktree, FSMonitor has nothing to monitor.\n\nSo let's ignore if an FSMonitor is configured (e.g. in `~/.gitconfig`)\nand we're running in a repository without worktree.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n    fsmonitor: only enable it in non-bare repositories\n    \n    Since I released Git for Windows v2.31.0, with brief interruption of two\n    weeks, I enabled the built-in FSMonitor via my user config, and today\n    was the first time I did anything in a bare repository. I was somewhat\n    surprised that FSMonitor gave me trouble there, as the FSMonitor does\n    not even make sense there...\n    \n    This patch applies on top of jh/rfc-builtin-fsmonitor (not because it\n    fixes a problem in the built-in FSMonitor, the bug existed for a long,\n    long time before those patches, but because it would otherwise cause\n    merge conflicts with that patch series).\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-942%2Fdscho%2Fbare-repositories-need-no-fsmonitor-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-942/dscho/bare-repositories-need-no-fsmonitor-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/942\n\n config.c | 6 ++++++\n 1 file changed, 6 insertions(+)\n\ndiff --git a/config.c b/config.c\nindex 53e7dedc60de..fc5e744d81ca 100644\n--- a/config.c\n+++ b/config.c\n@@ -2515,6 +2515,12 @@ int git_config_get_max_percent_split_change(void)\n \n int repo_config_get_fsmonitor(struct repository *r)\n {\n+\tif (!r->worktree) {\n+\t\t/* FSMonitor makes no sense in bare repositories */\n+\t\tcore_fsmonitor = 0;\n+\t\treturn 1;\n+\t}\n+\n \tif (r->settings.use_builtin_fsmonitor > 0) {\n \t\tcore_fsmonitor = \"(built-in daemon)\";\n \t\treturn 1;\n\nbase-commit: 14d50074ff19e68e7a8d718b22d138882087bbc9\n-- \ngitgitgadget\n"},{"id":"423337","messageId":"xmqq8s4zdghd.fsf@gitster.g","threadId":"55582","inReplyTo":"pull.942.git.1619682362363.gitgitgadget@gmail.com","subject":"Re: [PATCH] fsmonitor: only enable it in non-bare repositories","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-04-30T13:55:26Z","receivedAt":"2021-04-30T13:55:29Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Johannes Schindelin via GitGitGadget\" <gitgitgadget@gmail.com>\nwrites:\n\n> From: Johannes Schindelin <johannes.schindelin@gmx.de>\n>\n> The entire point of the FSMonitor is to monitor the worktree changes in\n> a more efficient manner than `lstat()`ing all worktree files every time\n> we refresh the index.\n>\n> But if there is no worktree, FSMonitor has nothing to monitor.\n>\n> So let's ignore if an FSMonitor is configured (e.g. in `~/.gitconfig`)\n> and we're running in a repository without worktree.\n>\n> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> ---\n>     fsmonitor: only enable it in non-bare repositories\n>     \n>     Since I released Git for Windows v2.31.0, with brief interruption of two\n>     weeks, I enabled the built-in FSMonitor via my user config, and today\n>     was the first time I did anything in a bare repository. I was somewhat\n>     surprised that FSMonitor gave me trouble there, as the FSMonitor does\n>     not even make sense there...\n>     \n>     This patch applies on top of jh/rfc-builtin-fsmonitor (not because it\n>     fixes a problem in the built-in FSMonitor, the bug existed for a long,\n>     long time before those patches, but because it would otherwise cause\n>     merge conflicts with that patch series).\n>\n> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-942%2Fdscho%2Fbare-repositories-need-no-fsmonitor-v1\n> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-942/dscho/bare-repositories-need-no-fsmonitor-v1\n> Pull-Request: https://github.com/gitgitgadget/git/pull/942\n>\n>  config.c | 6 ++++++\n>  1 file changed, 6 insertions(+)\n>\n> diff --git a/config.c b/config.c\n> index 53e7dedc60de..fc5e744d81ca 100644\n> --- a/config.c\n> +++ b/config.c\n> @@ -2515,6 +2515,12 @@ int git_config_get_max_percent_split_change(void)\n>  \n>  int repo_config_get_fsmonitor(struct repository *r)\n>  {\n> +\tif (!r->worktree) {\n> +\t\t/* FSMonitor makes no sense in bare repositories */\n> +\t\tcore_fsmonitor = 0;\n\nUse NULL instead of integer 0 to mollify SP.\n\n\n> +\t\treturn 1;\n> +\t}\n> +\n>  \tif (r->settings.use_builtin_fsmonitor > 0) {\n>  \t\tcore_fsmonitor = \"(built-in daemon)\";\n>  \t\treturn 1;\n>\n> base-commit: 14d50074ff19e68e7a8d718b22d138882087bbc9\n"},{"id":"423473","messageId":"pull.942.v2.git.1620033105872.gitgitgadget@gmail.com","threadId":"55582","inReplyTo":"pull.942.git.1619682362363.gitgitgadget@gmail.com","subject":"[PATCH v2] fsmonitor: only enable it in non-bare repositories","fromName":"Johannes Schindelin via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2021-05-03T09:11:45Z","receivedAt":"2021-05-03T09:11:51Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"From: Johannes Schindelin <johannes.schindelin@gmx.de>\n\nThe entire point of the FSMonitor is to monitor the worktree changes in\na more efficient manner than `lstat()`ing all worktree files every time\nwe refresh the index.\n\nBut if there is no worktree, FSMonitor has nothing to monitor.\n\nSo let's ignore if an FSMonitor is configured (e.g. in `~/.gitconfig`)\nand we're running in a repository without worktree.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n    fsmonitor: only enable it in non-bare repositories\n    \n    For quite a while now, I run with the built-in FSMonitor via my user\n    config. Happily, the only issue I ran into was that FSMonitor tried to\n    run in a bare repository the other day. But an FSMonitor makes only\n    sense if we have a worktree. So let's disable it automatically in bare\n    repositories.\n    \n    This patch applies near the top of jh/rfc-builtin-fsmonitor. I would\n    like to keep it as a separate topic because the built-in FSMonitor did\n    not introduce this bug. This bug has been in Git's FSMonitor feature for\n    a long, long time.\n    \n    Changes since v1:\n    \n     * Using NULL instead of 0 (d'oh!)\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-942%2Fdscho%2Fbare-repositories-need-no-fsmonitor-v2\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-942/dscho/bare-repositories-need-no-fsmonitor-v2\nPull-Request: https://github.com/gitgitgadget/git/pull/942\n\nRange-diff vs v1:\n\n 1:  3a93be538d33 ! 1:  95333bbf45d5 fsmonitor: only enable it in non-bare repositories\n     @@ config.c: int git_config_get_max_percent_split_change(void)\n       {\n      +\tif (!r->worktree) {\n      +\t\t/* FSMonitor makes no sense in bare repositories */\n     -+\t\tcore_fsmonitor = 0;\n     ++\t\tcore_fsmonitor = NULL;\n      +\t\treturn 1;\n      +\t}\n      +\n\n\n config.c | 6 ++++++\n 1 file changed, 6 insertions(+)\n\ndiff --git a/config.c b/config.c\nindex 53e7dedc60de..90ce4c23d3dc 100644\n--- a/config.c\n+++ b/config.c\n@@ -2515,6 +2515,12 @@ int git_config_get_max_percent_split_change(void)\n \n int repo_config_get_fsmonitor(struct repository *r)\n {\n+\tif (!r->worktree) {\n+\t\t/* FSMonitor makes no sense in bare repositories */\n+\t\tcore_fsmonitor = NULL;\n+\t\treturn 1;\n+\t}\n+\n \tif (r->settings.use_builtin_fsmonitor > 0) {\n \t\tcore_fsmonitor = \"(built-in daemon)\";\n \t\treturn 1;\n\nbase-commit: 14d50074ff19e68e7a8d718b22d138882087bbc9\n-- \ngitgitgadget\n"},{"id":"423488","messageId":"87mttbx6ie.fsf@evledraar.gmail.com","threadId":"55582","inReplyTo":"pull.942.git.1619682362363.gitgitgadget@gmail.com","subject":"Re: [PATCH] fsmonitor: only enable it in non-bare repositories","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2021-05-03T13:58:48Z","receivedAt":"2021-05-03T13:59:43Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Thu, Apr 29 2021, Johannes Schindelin via GitGitGadget wrote:\n\n> From: Johannes Schindelin <johannes.schindelin@gmx.de>\n>\n> The entire point of the FSMonitor is to monitor the worktree changes in\n> a more efficient manner than `lstat()`ing all worktree files every time\n> we refresh the index.\n>\n> But if there is no worktree, FSMonitor has nothing to monitor.\n>\n> So let's ignore if an FSMonitor is configured (e.g. in `~/.gitconfig`)\n> and we're running in a repository without worktree.\n>\n> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> ---\n>     fsmonitor: only enable it in non-bare repositories\n>     \n>     Since I released Git for Windows v2.31.0, with brief interruption of two\n>     weeks, I enabled the built-in FSMonitor via my user config, and today\n>     was the first time I did anything in a bare repository. I was somewhat\n>     surprised that FSMonitor gave me trouble there, as the FSMonitor does\n>     not even make sense there...\n>     \n>     This patch applies on top of jh/rfc-builtin-fsmonitor (not because it\n>     fixes a problem in the built-in FSMonitor, the bug existed for a long,\n>     long time before those patches, but because it would otherwise cause\n>     merge conflicts with that patch series).\n>\n> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-942%2Fdscho%2Fbare-repositories-need-no-fsmonitor-v1\n> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-942/dscho/bare-repositories-need-no-fsmonitor-v1\n> Pull-Request: https://github.com/gitgitgadget/git/pull/942\n>\n>  config.c | 6 ++++++\n>  1 file changed, 6 insertions(+)\n>\n> diff --git a/config.c b/config.c\n> index 53e7dedc60de..fc5e744d81ca 100644\n> --- a/config.c\n> +++ b/config.c\n> @@ -2515,6 +2515,12 @@ int git_config_get_max_percent_split_change(void)\n>  \n>  int repo_config_get_fsmonitor(struct repository *r)\n>  {\n> +\tif (!r->worktree) {\n> +\t\t/* FSMonitor makes no sense in bare repositories */\n> +\t\tcore_fsmonitor = 0;\n> +\t\treturn 1;\n> +\t}\n> +\n>  \tif (r->settings.use_builtin_fsmonitor > 0) {\n>  \t\tcore_fsmonitor = \"(built-in daemon)\";\n>  \t\treturn 1;\n>\n> base-commit: 14d50074ff19e68e7a8d718b22d138882087bbc9\n\nThis is surely a correct fix for now, but wouldn't it in the future also\nbe useful to run it in bare repositories e.g. to be able cache lookups\nfor non-existing loose objects?\n"},{"id":"423512","messageId":"810dc60c-3730-b5f3-34f6-5cc2ddc9942a@jeffhostetler.com","threadId":"55582","inReplyTo":"87mttbx6ie.fsf@evledraar.gmail.com","subject":"Re: [PATCH] fsmonitor: only enable it in non-bare repositories","fromName":"Jeff Hostetler","fromEmail":"git@jeffhostetler.com","sentAt":"2021-05-03T17:27:50Z","receivedAt":"2021-05-03T17:27:53Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"\n\nOn 5/3/21 9:58 AM, Ævar Arnfjörð Bjarmason wrote:\n> \n> On Thu, Apr 29 2021, Johannes Schindelin via GitGitGadget wrote:\n> \n>> From: Johannes Schindelin <johannes.schindelin@gmx.de>\n>>\n>> The entire point of the FSMonitor is to monitor the worktree changes in\n>> a more efficient manner than `lstat()`ing all worktree files every time\n>> we refresh the index.\n>>\n>> But if there is no worktree, FSMonitor has nothing to monitor.\n>>\n>> So let's ignore if an FSMonitor is configured (e.g. in `~/.gitconfig`)\n>> and we're running in a repository without worktree.\n>>\n>> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n>> ---\n...\n>>\n>> base-commit: 14d50074ff19e68e7a8d718b22d138882087bbc9\n> \n> This is surely a correct fix for now, but wouldn't it in the future also\n> be useful to run it in bare repositories e.g. to be able cache lookups\n> for non-existing loose objects?\n> \n\nNo, the FSMonitor feature only expects data for paths within the\nworking directory.  (And is independent of whether the FS change\ndata is provided by my fsmonitor--daemon or provided by a hook-based\nprovider, such as Watchman.)  The FSMonitor feature uses that data to\nshortcut scans of the working directory.\n\nThere is no interaction with the contents of the .git/objects\ndirectory and I'm not sure how that would work.\n\nJeff\n\n\n\n\n\n"},{"id":"423568","messageId":"87k0oex1yi.fsf@evledraar.gmail.com","threadId":"55582","inReplyTo":"810dc60c-3730-b5f3-34f6-5cc2ddc9942a@jeffhostetler.com","subject":"Re: [PATCH] fsmonitor: only enable it in non-bare repositories","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2021-05-03T17:56:35Z","receivedAt":"2021-05-04T09:50:37Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"On Mon, May 03 2021, Jeff Hostetler wrote:\n\n> On 5/3/21 9:58 AM, Ævar Arnfjörð Bjarmason wrote:\n>> On Thu, Apr 29 2021, Johannes Schindelin via GitGitGadget wrote:\n>> \n>>> From: Johannes Schindelin <johannes.schindelin@gmx.de>\n>>>\n>>> The entire point of the FSMonitor is to monitor the worktree changes in\n>>> a more efficient manner than `lstat()`ing all worktree files every time\n>>> we refresh the index.\n>>>\n>>> But if there is no worktree, FSMonitor has nothing to monitor.\n>>>\n>>> So let's ignore if an FSMonitor is configured (e.g. in `~/.gitconfig`)\n>>> and we're running in a repository without worktree.\n>>>\n>>> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n>>> ---\n> ...\n>>>\n>>> base-commit: 14d50074ff19e68e7a8d718b22d138882087bbc9\n>> This is surely a correct fix for now, but wouldn't it in the future\n>> also\n>> be useful to run it in bare repositories e.g. to be able cache lookups\n>> for non-existing loose objects?\n>> \n>\n> No, the FSMonitor feature only expects data for paths within the\n> working directory.  (And is independent of whether the FS change\n> data is provided by my fsmonitor--daemon or provided by a hook-based\n> provider, such as Watchman.)  The FSMonitor feature uses that data to\n> shortcut scans of the working directory.\n\nIndeed, hence \"in the future\". I'm not suggesting that it'll do anything\nuseful by watching anything in the .git directory now, but that it might\nbe an interesting thing to explore.\n\n> There is no interaction with the contents of the .git/objects\n> directory and I'm not sure how that would work.\n\nWe'd watch .git/objects and .git/objects/{aa..ff}, then when about to\ncheck for a loose object we'd avoid hitting the FS.\n\nI don't know how useful that is post-61c7711cfea (sha1-file: use loose\nobject cache for quick existence check, 2018-11-12), but e.g. on NFS\nthis sort of thing still mattered. I had a \"bigger hammer\" approach with\n[1] that ran (and still does, I believe) on a big corporate\ninstallation.\n\nMore generally, if you strace .git access during repo operations you'll\nfind we're doing all sorts of existence checks etc. all the time. Loose\nobjects, refs, seeing what packs there are (better with the MIDX, but do\nwe still fall back?) etc. If we had up-to-date inotify/fsmonitor info we\ncould ask the daemon about it.\n\n1. https://lore.kernel.org/git/20181028225023.26427-5-avarab@gmail.com/\n"},{"id":"424185","messageId":"e5e162b7-231c-29e1-174c-10d2c151769e@jeffhostetler.com","threadId":"55582","inReplyTo":"87k0oex1yi.fsf@evledraar.gmail.com","subject":"Re: [PATCH] fsmonitor: only enable it in non-bare repositories","fromName":"Jeff Hostetler","fromEmail":"git@jeffhostetler.com","sentAt":"2021-05-11T19:24:09Z","receivedAt":"2021-05-11T19:24:11Z","isPatch":true,"sender":{"key":"git@jeffhostetler.com","avatar":null},"body":"\n\nOn 5/3/21 1:56 PM, Ævar Arnfjörð Bjarmason wrote:\n> On Mon, May 03 2021, Jeff Hostetler wrote:\n> \n>> On 5/3/21 9:58 AM, Ævar Arnfjörð Bjarmason wrote:\n>>> On Thu, Apr 29 2021, Johannes Schindelin via GitGitGadget wrote:\n>>>\n>>>> From: Johannes Schindelin <johannes.schindelin@gmx.de>\n>>>>\n>>>> The entire point of the FSMonitor is to monitor the worktree changes in\n>>>> a more efficient manner than `lstat()`ing all worktree files every time\n>>>> we refresh the index.\n>>>>\n>>>> But if there is no worktree, FSMonitor has nothing to monitor.\n>>>>\n>>>> So let's ignore if an FSMonitor is configured (e.g. in `~/.gitconfig`)\n>>>> and we're running in a repository without worktree.\n>>>>\n>>>> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n>>>> ---\n>> ...\n>>>>\n>>>> base-commit: 14d50074ff19e68e7a8d718b22d138882087bbc9\n>>> This is surely a correct fix for now, but wouldn't it in the future\n>>> also\n>>> be useful to run it in bare repositories e.g. to be able cache lookups\n>>> for non-existing loose objects?\n>>>\n>>\n>> No, the FSMonitor feature only expects data for paths within the\n>> working directory.  (And is independent of whether the FS change\n>> data is provided by my fsmonitor--daemon or provided by a hook-based\n>> provider, such as Watchman.)  The FSMonitor feature uses that data to\n>> shortcut scans of the working directory.\n> \n> Indeed, hence \"in the future\". I'm not suggesting that it'll do anything\n> useful by watching anything in the .git directory now, but that it might\n> be an interesting thing to explore.\n> \n>> There is no interaction with the contents of the .git/objects\n>> directory and I'm not sure how that would work.\n> \n> We'd watch .git/objects and .git/objects/{aa..ff}, then when about to\n> check for a loose object we'd avoid hitting the FS.\n> \n> I don't know how useful that is post-61c7711cfea (sha1-file: use loose\n> object cache for quick existence check, 2018-11-12), but e.g. on NFS\n> this sort of thing still mattered. I had a \"bigger hammer\" approach with\n> [1] that ran (and still does, I believe) on a big corporate\n> installation.\n> \n> More generally, if you strace .git access during repo operations you'll\n> find we're doing all sorts of existence checks etc. all the time. Loose\n> objects, refs, seeing what packs there are (better with the MIDX, but do\n> we still fall back?) etc. If we had up-to-date inotify/fsmonitor info we\n> could ask the daemon about it.\n> \n> 1. https://lore.kernel.org/git/20181028225023.26427-5-avarab@gmail.com/\n> \n\nInteresting.\n\nThat's certainly something to look into later.  I know there is\ncode in the object lookup code to rescan/reload the packfiles or\nloose objects (under the assumption that another process just created\na new packfile (and after our process loaded the packed-git list)).\nSuch a daemon might be helpful to improve something like that.\n\nBut I can't think about any of that right now.  I'd like to finish the\ncurrent fsmonitor--daemon patch series and let it settle down\nbefore starting to think about an orthogonal use case such as this.\n\nThanks\nJeff\n"}]}