pub type OnOpen = Arc<dyn Fn(&Path, Option<&Path>) -> Result<(), String> + Send + Sync>;Expand description
A hook run against a project’s graph.db path the first time it is opened —
used by serve --sync-on-access to (re)build a stale or missing graph before
it is served (ADR-0008). Returns a human-readable error on failure.
The --sync-on-access hook: (graph.db, the recorded working-tree root).
§Why the root is passed rather than derived from the db path
Because it cannot be derived. The store lives at <git dir>/roteiro/graph.db,
and for a linked worktree the git dir is <main>/.git/worktrees/<name> —
so the “three parents up is the repository” shortcut a caller would otherwise
reach for lands on <main>/.git/worktrees, which is not a repository at all.
Discovering from there walks up and finds the main checkout, so the hook
would rebuild the wrong repository’s graph and write it to the wrong store,
silently (issue #837).
The registry already knows the answer — build_registry records
repo.workdir() beside the db path it derived from repo.git_dir() — so this
hands the value over instead of asking the callee to reconstruct it.
None whenever the source has no working-tree root to record. Two cases,
not one: a Workspace::from_named_dbs source, which records no root at all,
and a bare repository passed to Workspace::from_repo_paths, because
build_registry records repo.workdir() and a bare repo has none. A hook
that assumed from_named_dbs were the only nameless case would be wrong about
the second, so it is named here.
Re-exported from the crate root (crate::OnOpen) because
Workspace::with_on_open is public and takes it: a caller outside this crate
could otherwise not name the type its own argument has.
Aliased Type§
pub struct OnOpen { /* private fields */ }