Re: [PATCH 2/3] fsmonitor: add assertion that fsmonitor is valid to check_removed
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Mar 14, 2021, 22:35 UTC
- Message-ID
- <CAPig+cT9aAPGzysqAz2OBrZP-7Ci+h+W5wFgnRm8bsde9K6zdw@mail.gmail.com>
- In-Reply-To
- <dda5b537a3f0706ebf933e2b2efd996267e9d9b1.1615760258.git.gitgitgadget@gmail.com>
On Sun, Mar 14, 2021 at 6:19 PM Nipunn Koorapati via GitGitGadget <gitgitgadget@gmail.com> wrote:
Show 17 quoted lines
> Validate that fsmonitor is valid to futureproof against bugs where
> check_removed might be called from places that haven't refreshed.
>
> Signed-off-by: Nipunn Koorapati <nipunn@dropbox.com>
> ---
> diff --git a/fsmonitor.h b/fsmonitor.h
> @@ -49,6 +49,17 @@ void refresh_fsmonitor(struct index_state *istate);
> +/*
> + * Check if refresh_fsmonitor has been called at least once.
> + * refresh_fsmonitor is idempotent. Returns true if fsmonitor is
> + * not enabled (since the state will be "fresh" w/ CE_FSMONITOR_VALID unset)
> + * This version is useful for assertions
> + */
> +static inline int is_fsmonitor_refreshed(const struct index_state *istate)
> +{
> + return !core_fsmonitor || istate->fsmonitor_has_run_once;
> +}Unusual 4-space indentation rather than typical 1-tab.