Expand description
Cross-process file-watcher convenience for the change-event surface.
watch_mem_repo starts a notify-backed file-system watcher
against <gitdir>/refs/heads/ and surfaces a
std::sync::mpsc::Receiver of MemChangedEvents. Consumers
that do not share the writer’s crate::Engine instance (the
bridge HEAD-watcher, the macOS live-update path, audit-log workers,
webhook notifiers) consume events through this surface; the wire
shape matches the in-process callback API exactly so the same
downstream code paths work for both sources.
Gated behind the file-watcher Cargo feature — notify is a
non-trivial dependency and consumers that only need the in-process
crate::Engine::subscribe_mem_changes path should not pay for
it. Without the feature enabled the module disappears entirely.
§Design
watch_mem_repospawns a background thread running the notify-event loop and returns aMemRepoWatcherhandle that owns thenotify::PollWatcher(chosen overRecommendedWatcherfor cross-platform determinism — see the rationale at thePollWatcher::newcall site). A per-memHashMap<mem_name, last_seen_sha>(a sharedArc<Mutex<…>>seeded before the thread starts) lets each emitted event’spreviousfield reflect the actual transition.- On startup the thread scans the existing
refs/heads/tree and seeds the SHA map without emitting synthetic history events — consumers see changes from this point forward, never replay. - Per file-system event the thread re-reads the touched ref file
(or the directory holding it for hierarchical layouts) and emits
a
MemChangedEventif the SHA changed. Notify can deliver bursts; the SHA-comparison gate deduplicates them. - The returned
MemRepoWatcherhandle owns the notify watcher; dropping it cancels the watch and the background thread joins on its event channel disconnecting.
§Limitations
- Reads loose refs only (the typical case for an actively-written
mem-repo). Packed refs (
<gitdir>/packed-refs) are not parsed in v1 — production deployments that compact refs need a follow-up. Loose refs created after compaction still surface normally. - Read-only consumers must poll [
crate::ops::changes_since] for any history that landed before the watcher started.
Structs§
- MemRepo
Watcher - RAII handle returned by
watch_mem_repo. Dropping the handle stops the watcher (the underlying notify watcher is dropped, cancelling the OS-level subscription, and the background thread exits when its event channel disconnects).
Enums§
- File
Watcher Error - Errors surfaced by
watch_mem_repo.
Functions§
- watch_
mem_ repo - Start a file-system watcher on
<gitdir>/refs/heads/and surface a receiver ofMemChangedEvents. See the module docs for the design and the limitations (loose-refs only, no synthetic replay).