]> git.ipfire.org Git - thirdparty/git.git/commitdiff
fsmonitor: refactor bit invalidation in refresh callback
authorJeff Hostetler <jeffhostetler@github.com>
Mon, 26 Feb 2024 21:39:24 +0000 (21:39 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 6 Mar 2024 17:10:06 +0000 (09:10 -0800)
Refactor code in the fsmonitor_refresh_callback() call chain dealing
with invalidating the CE_FSMONITOR_VALID bit and add a trace message.

During the refresh, we clear the CE_FSMONITOR_VALID bit in response to
data from the FSMonitor daemon (so that a later phase will lstat() and
verify the true state of the file).

Create a new function to clear the bit and add some unique tracing for
it to help debug edge cases.

This is similar to the existing `mark_fsmonitor_invalid()` function,
but it also does untracked-cache invalidation and we've already
handled that in the refresh-callback handlers, so but we don't need
to repeat that.

Signed-off-by: Jeff Hostetler <jeffhostetler@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
fsmonitor.c

index 739ddbf7aca2a643366b43b68c33010714282d36..3c87449be876ca765942ed999def2f41d1ea482d 100644 (file)
@@ -183,6 +183,22 @@ static int query_fsmonitor_hook(struct repository *r,
        return result;
 }
 
+/*
+ * Invalidate the FSM bit on this CE.  This is like mark_fsmonitor_invalid()
+ * but we've already handled the untracked-cache, so let's not repeat that
+ * work.  This also lets us have a different trace message so that we can
+ * see everything that was done as part of the refresh-callback.
+ */
+static void invalidate_ce_fsm(struct cache_entry *ce)
+{
+       if (ce->ce_flags & CE_FSMONITOR_VALID) {
+               trace_printf_key(&trace_fsmonitor,
+                                "fsmonitor_refresh_callback INV: '%s'",
+                                ce->name);
+               ce->ce_flags &= ~CE_FSMONITOR_VALID;
+       }
+}
+
 static size_t handle_path_with_trailing_slash(
        struct index_state *istate, const char *name, int pos);
 
@@ -219,7 +235,7 @@ static size_t handle_path_without_trailing_slash(
                 * cache-entry with the same pathname, nor for a cone
                 * at that directory. (That is, assume no D/F conflicts.)
                 */
-               istate->cache[pos]->ce_flags &= ~CE_FSMONITOR_VALID;
+               invalidate_ce_fsm(istate->cache[pos]);
                return 1;
        } else {
                size_t nr_in_cone;
@@ -297,7 +313,7 @@ static size_t handle_path_with_trailing_slash(
        for (i = pos; i < istate->cache_nr; i++) {
                if (!starts_with(istate->cache[i]->name, name))
                        break;
-               istate->cache[i]->ce_flags &= ~CE_FSMONITOR_VALID;
+               invalidate_ce_fsm(istate->cache[i]);
                nr_in_cone++;
        }