Expand description
State persistence: state.json v2 read/write/migrate.
State lives at <repo>/.git/iso-code/state.json and is rewritten via a
write-temp → fsync → rename sequence for crash safety. The file lock is
scoped strictly around each read-modify-write. Unknown fields are preserved
through a #[serde(flatten)] catch-all to keep newer writers forward
compatible with older readers.
Structs§
- Active
Worktree Entry - An active worktree entry in state.json.
- Config
Snapshot - Snapshot of config written into state.json for diagnostics.
- GcHistory
Entry - A single GC history record.
- Stale
Worktree Entry - A stale (evicted) worktree entry in state.json.
- StateV2
- Top-level state file (v2).
Functions§
- compute_
repo_ id - Compute the repo_id: sha256 hex of the absolute canonicalized repo path.
- ensure_
state_ dir - Ensure the state directory exists. Called from Manager::new().
- migrate
- Schema migration dispatcher. Upgrades older state files to the current schema version in-place before they are returned to callers.
- read_
state - Read and parse state.json, migrating from v1 if needed. If the file is missing, returns a fresh empty state.
- state_
dir - Return the state directory:
<repo>/.git/iso-code/. RespectsISO_CODE_HOMEenv var override andConfig.home_override. - state_
json_ path - Return the state.json path.
- state_
lock_ path - Return the state.lock path.
- with_
state - Read-modify-write helper: acquires state.lock, reads state, applies the closure, then writes back. The lock is released as soon as this function returns — callers must not perform long-running work inside the closure.
- with_
state_ timeout - Like
with_statebut takes an explicit lock acquisition timeout. - write_
state - Atomically write state.json: write tmp -> fsync -> rename.