From: Patrick Steinhardt <ps@pks.im>
To: "marzi.esipreh via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org,
"Eric Sunshine [ ]" <sunshine@sunshineco.com>,
"Ævar Arnfjörð Bjarmason [ ]" <avarab@gmail.com>,
"Glen Choo [ ]" <chooglen@google.com>,
"Johannes Schindelin [ ]" <Johannes.Schindelin@gmx.de>,
"Taylor Blau [ ]" <me@ttaylorr.com>, marzi <m.ispare63@gmail.com>,
"marzi.esipreh" <marzi.esipreh@uber.com>
Subject: Re: [PATCH 7/7] fsmonitor: addressed comments for patch 1352
Date: Thu, 15 Feb 2024 14:49:38 +0100 [thread overview]
Message-ID: <Zc4WcgJbH73uyRtc@tanuki> (raw)
In-Reply-To: <74a4fa335a7c2014a35be8556887170169360b36.1707992978.git.gitgitgadget@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 12768 bytes --]
On Thu, Feb 15, 2024 at 10:29:38AM +0000, marzi.esipreh via GitGitGadget wrote:
> From: "marzi.esipreh" <marzi.esipreh@uber.com>
>
> addressed comments on 1352, rebased, resolved conflicts
Please squash these changes into the preceding commits whereever
required.
Patrick
>
> Signed-off-by: Marzieh Esipreh <m.ispare63@gmail.com>
> ---
> compat/fsmonitor/fsm-health-linux.c | 2 +-
> compat/fsmonitor/fsm-ipc-unix.c | 6 +-
> compat/fsmonitor/fsm-listen-linux.c | 170 ++++++++++++------------
> compat/fsmonitor/fsm-path-utils-linux.c | 1 +
> compat/fsmonitor/fsm-settings-unix.c | 3 +
> 5 files changed, 95 insertions(+), 87 deletions(-)
>
> diff --git a/compat/fsmonitor/fsm-health-linux.c b/compat/fsmonitor/fsm-health-linux.c
> index b9f709e8548..4c291f8a066 100644
> --- a/compat/fsmonitor/fsm-health-linux.c
> +++ b/compat/fsmonitor/fsm-health-linux.c
> @@ -1,4 +1,4 @@
> -#include "cache.h"
> +#include "git-compat-util.h"
> #include "config.h"
> #include "fsmonitor.h"
> #include "fsm-health.h"
> diff --git a/compat/fsmonitor/fsm-ipc-unix.c b/compat/fsmonitor/fsm-ipc-unix.c
> index eb25123fa12..70afddfd298 100644
> --- a/compat/fsmonitor/fsm-ipc-unix.c
> +++ b/compat/fsmonitor/fsm-ipc-unix.c
> @@ -1,10 +1,12 @@
> -#include "cache.h"
> +#include "git-compat-util.h"
> #include "config.h"
> #include "hex.h"
> #include "strbuf.h"
> #include "fsmonitor.h"
> #include "fsmonitor-ipc.h"
> #include "fsmonitor-path-utils.h"
> +#include "gettext.h"
> +#include "path.h"
>
> static GIT_PATH_FUNC(fsmonitor_ipc__get_default_path, "fsmonitor--daemon.ipc")
>
> @@ -17,7 +19,7 @@ const char *fsmonitor_ipc__get_path(struct repository *r)
> unsigned char hash[GIT_MAX_RAWSZ];
>
> if (!r)
> - BUG("No repository passed into fsmonitor_ipc__get_path");
> + BUG("no repository passed into fsmonitor_ipc__get_path");
>
> if (ipc_path)
> return ipc_path;
> diff --git a/compat/fsmonitor/fsm-listen-linux.c b/compat/fsmonitor/fsm-listen-linux.c
> index e8548e4e009..84d8fb28d5d 100644
> --- a/compat/fsmonitor/fsm-listen-linux.c
> +++ b/compat/fsmonitor/fsm-listen-linux.c
> @@ -1,7 +1,10 @@
> -#include "cache.h"
> +#include "git-compat-util.h"
> +#include "config.h"
> #include "fsmonitor.h"
> #include "fsm-listen.h"
> #include "fsmonitor--daemon.h"
> +#include "gettext.h"
> +#include "simple-ipc.h"
> #include <dirent.h>
> #include <fcntl.h>
> #include <sys/inotify.h>
> @@ -129,15 +132,15 @@ static void remove_watch(struct watch_entry *w,
> hashmap_entry_init(&k1.ent, memhash(&w->wd, sizeof(int)));
> w1 = hashmap_remove_entry(&data->watches, &k1, ent, NULL);
> if (!w1)
> - BUG("Double remove of watch for '%s'", w->dir);
> + BUG("double remove of watch for '%s'", w->dir);
>
> if (w1->cookie)
> - BUG("Removing watch for '%s' which has a pending rename", w1->dir);
> + BUG("removing watch for '%s' which has a pending rename", w1->dir);
>
> hashmap_entry_init(&k2.ent, memhash(w->dir, strlen(w->dir)));
> w2 = hashmap_remove_entry(&data->revwatches, &k2, ent, NULL);
> if (!w2)
> - BUG("Double remove of reverse watch for '%s'", w->dir);
> + BUG("double remove of reverse watch for '%s'", w->dir);
>
> /* w1->dir and w2->dir are interned strings, we don't own them */
> free(w1);
> @@ -187,7 +190,7 @@ static void add_dir_rename(uint32_t cookie, const char *path,
> hashmap_entry_init(&k.ent, memhash(path, strlen(path)));
> w = hashmap_get_entry(&data->revwatches, &k, ent, NULL);
> if (!w) /* should never happen */
> - BUG("No watch for '%s'", path);
> + BUG("no watch for '%s'", path);
> w->cookie = cookie;
>
> /* add the pending rename to match against later */
> @@ -224,10 +227,10 @@ static void rename_dir(uint32_t cookie, const char *path,
> remove_watch(w, data);
> add_watch(path, data);
> } else {
> - BUG("No matching watch");
> + BUG("no matching watch");
> }
> } else {
> - BUG("No matching cookie");
> + BUG("no matching cookie");
> }
> }
>
> @@ -249,7 +252,7 @@ static int register_inotify(const char *path,
> if (!dir)
> return error_errno("opendir('%s') failed", path);
>
> - while ((de = readdir_skip_dot_and_dotdot(dir)) != NULL) {
> + while ((de = readdir_skip_dot_and_dotdot(dir))) {
> strbuf_reset(¤t);
> strbuf_addf(¤t, "%s/%s", path, de->d_name);
> if (lstat(current.buf, &fs)) {
> @@ -353,7 +356,7 @@ static void log_mask_set(const char *path, u_int32_t mask)
> if (mask & IN_IGNORED)
> strbuf_addstr(&msg, "IN_IGNORED|");
> if (mask & IN_ISDIR)
> - strbuf_addstr(&msg, "IN_ISDIR|");
> + strbuf_addstr(&msg, "IN_ISDIR");
>
> trace_printf_key(&trace_fsmonitor, "inotify_event: '%s', mask=%#8.8x %s",
> path, mask, msg.buf);
> @@ -373,8 +376,10 @@ int fsm_listen__ctor(struct fsmonitor_daemon_state *state)
> data->shutdown = SHUTDOWN_ERROR;
>
> fd = inotify_init1(O_NONBLOCK);
> - if (fd < 0)
> + if (fd < 0) {
> + FREE_AND_NULL(data);
> return error_errno("inotify_init1() failed");
> + }
>
> data->fd_inotify = fd;
>
> @@ -386,12 +391,10 @@ int fsm_listen__ctor(struct fsmonitor_daemon_state *state)
> ret = -1;
> else if (register_inotify(state->path_worktree_watch.buf, state, NULL))
> ret = -1;
> - else if (state->nr_paths_watching > 1) {
> - if (add_watch(state->path_gitdir_watch.buf, data))
> - ret = -1;
> - else if (register_inotify(state->path_gitdir_watch.buf, state, NULL))
> - ret = -1;
> - }
> + else if (state->nr_paths_watching > 1 &&
> + (add_watch(state->path_gitdir_watch.buf, data) ||
> + register_inotify(state->path_gitdir_watch.buf, state, NULL)))
> + ret = -1;
>
> if (!ret) {
> state->listen_error_code = 0;
> @@ -449,80 +452,80 @@ static int process_event(const char *path,
> const char *last_sep;
>
> switch (fsmonitor_classify_path_absolute(state, path)) {
> - case IS_INSIDE_DOT_GIT_WITH_COOKIE_PREFIX:
> - case IS_INSIDE_GITDIR_WITH_COOKIE_PREFIX:
> - /* Use just the filename of the cookie file. */
> - last_sep = find_last_dir_sep(path);
> - string_list_append(cookie_list,
> - last_sep ? last_sep + 1 : path);
> - break;
> - case IS_INSIDE_DOT_GIT:
> - case IS_INSIDE_GITDIR:
> - break;
> - case IS_DOT_GIT:
> - case IS_GITDIR:
> - /*
> - * If .git directory is deleted or renamed away,
> - * we have to quit.
> - */
> - if (em_dir_deleted(event->mask)) {
> - trace_printf_key(&trace_fsmonitor,
> - "event: gitdir removed");
> - state->listen_data->shutdown = SHUTDOWN_FORCE;
> - goto done;
> - }
> + case IS_INSIDE_DOT_GIT_WITH_COOKIE_PREFIX:
> + case IS_INSIDE_GITDIR_WITH_COOKIE_PREFIX:
> + /* Use just the filename of the cookie file. */
> + last_sep = find_last_dir_sep(path);
> + string_list_append(cookie_list,
> + last_sep ? last_sep + 1 : path);
> + break;
> + case IS_INSIDE_DOT_GIT:
> + case IS_INSIDE_GITDIR:
> + break;
> + case IS_DOT_GIT:
> + case IS_GITDIR:
> + /*
> + * If .git directory is deleted or renamed away,
> + * we have to quit.
> + */
> + if (em_dir_deleted(event->mask)) {
> + trace_printf_key(&trace_fsmonitor,
> + "event: gitdir removed");
> + state->listen_data->shutdown = SHUTDOWN_FORCE;
> + goto done;
> + }
>
> - if (em_dir_renamed(event->mask)) {
> - trace_printf_key(&trace_fsmonitor,
> - "event: gitdir renamed");
> - state->listen_data->shutdown = SHUTDOWN_FORCE;
> - goto done;
> - }
> - break;
> - case IS_WORKDIR_PATH:
> - /* normal events in the working directory */
> - if (trace_pass_fl(&trace_fsmonitor))
> - log_mask_set(path, event->mask);
> + if (em_dir_renamed(event->mask)) {
> + trace_printf_key(&trace_fsmonitor,
> + "event: gitdir renamed");
> + state->listen_data->shutdown = SHUTDOWN_FORCE;
> + goto done;
> + }
> + break;
> + case IS_WORKDIR_PATH:
> + /* normal events in the working directory */
> + if (trace_pass_fl(&trace_fsmonitor))
> + log_mask_set(path, event->mask);
>
> - rel = path + state->path_worktree_watch.len + 1;
> - fsmonitor_batch__add_path(batch, rel);
> + rel = path + state->path_worktree_watch.len + 1;
> + fsmonitor_batch__add_path(batch, rel);
>
> - if (em_dir_deleted(event->mask))
> - break;
> + if (em_dir_deleted(event->mask))
> + break;
>
> - /* received IN_MOVE_FROM, add tracking for expected IN_MOVE_TO */
> - if (em_rename_dir_from(event->mask))
> - add_dir_rename(event->cookie, path, state->listen_data);
> + /* received IN_MOVE_FROM, add tracking for expected IN_MOVE_TO */
> + if (em_rename_dir_from(event->mask))
> + add_dir_rename(event->cookie, path, state->listen_data);
>
> - /* received IN_MOVE_TO, update watch to reflect new path */
> - if (em_rename_dir_to(event->mask)) {
> - rename_dir(event->cookie, path, state->listen_data);
> - if (register_inotify(path, state, batch)) {
> - state->listen_data->shutdown = SHUTDOWN_ERROR;
> - goto done;
> - }
> + /* received IN_MOVE_TO, update watch to reflect new path */
> + if (em_rename_dir_to(event->mask)) {
> + rename_dir(event->cookie, path, state->listen_data);
> + if (register_inotify(path, state, batch)) {
> + state->listen_data->shutdown = SHUTDOWN_ERROR;
> + goto done;
> }
> + }
>
> - if (em_dir_created(event->mask)) {
> - if (add_watch(path, state->listen_data)) {
> - state->listen_data->shutdown = SHUTDOWN_ERROR;
> - goto done;
> - }
> - if (register_inotify(path, state, batch)) {
> - state->listen_data->shutdown = SHUTDOWN_ERROR;
> - goto done;
> - }
> + if (em_dir_created(event->mask)) {
> + if (add_watch(path, state->listen_data)) {
> + state->listen_data->shutdown = SHUTDOWN_ERROR;
> + goto done;
> }
> - break;
> - case IS_OUTSIDE_CONE:
> - default:
> - trace_printf_key(&trace_fsmonitor,
> - "ignoring '%s'", path);
> - break;
> + if (register_inotify(path, state, batch)) {
> + state->listen_data->shutdown = SHUTDOWN_ERROR;
> + goto done;
> + }
> + }
> + break;
> + case IS_OUTSIDE_CONE:
> + default:
> + trace_printf_key(&trace_fsmonitor,
> + "ignoring '%s'", path);
> + break;
> }
> return 0;
> -done:
> - return -1;
> + done:
> + return -1;
> }
>
> /*
> @@ -531,7 +534,7 @@ static int process_event(const char *path,
> */
> static void handle_events(struct fsmonitor_daemon_state *state)
> {
> - /* See https://man7.org/linux/man-pages/man7/inotify.7.html */
> + /* See https://man7.org/linux/man-pages/man7/inotify.7.html */
> char buf[4096]
> __attribute__ ((aligned(__alignof__(struct inotify_event))));
>
> @@ -539,13 +542,12 @@ static void handle_events(struct fsmonitor_daemon_state *state)
> struct fsmonitor_batch *batch = NULL;
> struct string_list cookie_list = STRING_LIST_INIT_DUP;
> struct watch_entry k, *w;
> - struct strbuf path;
> const struct inotify_event *event;
> int fd = state->listen_data->fd_inotify;
> ssize_t len;
> char *ptr, *p;
>
> - strbuf_init(&path, PATH_MAX);
> + struct strbuf path = STRBUF_INIT;
>
> for(;;) {
> len = read(fd, buf, sizeof(buf));
> @@ -581,7 +583,7 @@ static void handle_events(struct fsmonitor_daemon_state *state)
>
> w = hashmap_get_entry(&watches, &k, ent, NULL);
> if (!w) /* should never happen */
> - BUG("No watch for '%s'", event->name);
> + BUG("no watch for '%s'", event->name);
>
> /* directory watch was removed */
> if (em_remove_watch(event->mask)) {
> diff --git a/compat/fsmonitor/fsm-path-utils-linux.c b/compat/fsmonitor/fsm-path-utils-linux.c
> index c21d1349532..0e3b33ffa48 100644
> --- a/compat/fsmonitor/fsm-path-utils-linux.c
> +++ b/compat/fsmonitor/fsm-path-utils-linux.c
> @@ -3,6 +3,7 @@
> #include "fsmonitor.h"
> #include "fsmonitor-path-utils.h"
> #include "fsm-path-utils-linux.h"
> +#include "gettext.h"
> #include <errno.h>
> #include <mntent.h>
> #include <sys/mount.h>
> diff --git a/compat/fsmonitor/fsm-settings-unix.c b/compat/fsmonitor/fsm-settings-unix.c
> index d16dca89416..c9b75aa44fe 100644
> --- a/compat/fsmonitor/fsm-settings-unix.c
> +++ b/compat/fsmonitor/fsm-settings-unix.c
> @@ -1,6 +1,9 @@
> +#include "git-compat-util.h"
> +#include "config.h"
> #include "fsmonitor.h"
> #include "fsmonitor-ipc.h"
> #include "fsmonitor-path-utils.h"
> +#include <stdint.h>
>
> /*
> * For the builtin FSMonitor, we create the Unix domain socket for the
> --
> gitgitgadget
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2024-02-15 13:49 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-15 10:29 [PATCH 0/7] fsmonitor: completing a stale patch that Implements fsmonitor for Linux marzi via GitGitGadget
2024-02-15 10:29 ` [PATCH 1/7] fsmonitor: rebase with master Eric DeCosta via GitGitGadget
2024-02-15 13:49 ` Patrick Steinhardt
2024-02-15 10:29 ` [PATCH 2/7] fsmonitor: determine if filesystem is local or remote Eric DeCosta via GitGitGadget
2024-02-15 11:24 ` Jean-Noël Avila
2024-02-15 13:49 ` Patrick Steinhardt
2024-02-15 10:29 ` [PATCH 3/7] fsmonitor: implement filesystem change listener for Linux Eric DeCosta via GitGitGadget
2024-02-15 13:49 ` Patrick Steinhardt
2024-02-15 10:29 ` [PATCH 4/7] fsmonitor: enable fsmonitor " Eric DeCosta via GitGitGadget
2024-02-15 10:29 ` [PATCH 5/7] fsmonitor: test updates Eric DeCosta via GitGitGadget
2024-02-15 10:29 ` [PATCH 6/7] fsmonitor: update doc for Linux Eric DeCosta via GitGitGadget
2024-02-15 10:29 ` [PATCH 7/7] fsmonitor: addressed comments for patch 1352 marzi.esipreh via GitGitGadget
2024-02-15 13:49 ` Patrick Steinhardt [this message]
2025-01-31 3:28 ` [PATCH 0/7] fsmonitor: completing a stale patch that Implements fsmonitor for Linux Manoraj K
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Zc4WcgJbH73uyRtc@tanuki \
--to=ps@pks.im \
--cc=Johannes.Schindelin@gmx.de \
--cc=avarab@gmail.com \
--cc=chooglen@google.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=m.ispare63@gmail.com \
--cc=marzi.esipreh@uber.com \
--cc=me@ttaylorr.com \
--cc=sunshine@sunshineco.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox