pub struct ShadowRepo { /* private fields */ }Expand description
A shared shadow bare git repository for a workspace.
Per-session checkpoint chains live under refs/sessions/<sid>/HEAD.
Implementations§
Source§impl ShadowRepo
impl ShadowRepo
Sourcepub fn open(workspace: impl Into<PathBuf>) -> Result<Self>
pub fn open(workspace: impl Into<PathBuf>) -> Result<Self>
Open or create the shadow repo for workspace. Idempotent.
Returns an error if git is not on PATH.
Sourcepub fn open_at(
workspace: impl Into<PathBuf>,
shadow_dir: impl Into<PathBuf>,
) -> Result<Self>
pub fn open_at( workspace: impl Into<PathBuf>, shadow_dir: impl Into<PathBuf>, ) -> Result<Self>
Open or create a shadow repo with an explicit shadow_dir,
bypassing paths::user_data_dir() resolution.
Used by tests so they don’t have to mutate RECURSIVE_HOME
(and thus don’t need the cross-module env lock), letting
checkpoint tests run in parallel. Production callers should
stick to [open].
Sourcepub fn snapshot_for_session(
&self,
session_id: &str,
message: &str,
) -> Result<CheckpointId>
pub fn snapshot_for_session( &self, session_id: &str, message: &str, ) -> Result<CheckpointId>
Snapshot the current workspace state and advance
refs/sessions/<session_id>/HEAD to the new commit.
Per-session temporary index files prevent concurrent snapshots from racing each other.
Sourcepub fn list_for_session(&self, session_id: &str) -> Result<Vec<CheckpointInfo>>
pub fn list_for_session(&self, session_id: &str) -> Result<Vec<CheckpointInfo>>
List checkpoints for session_id in reverse chronological order.
Sourcepub fn read_file_at(
&self,
checkpoint: &CheckpointId,
path: &str,
) -> Result<Option<Vec<u8>>>
pub fn read_file_at( &self, checkpoint: &CheckpointId, path: &str, ) -> Result<Option<Vec<u8>>>
Read a single file’s contents at checkpoint.
Returns Ok(None) if the file did not exist at that checkpoint.
Sourcepub fn restore_paths(
&self,
checkpoint: &CheckpointId,
paths: &[String],
) -> Result<RestoreStats>
pub fn restore_paths( &self, checkpoint: &CheckpointId, paths: &[String], ) -> Result<RestoreStats>
Restore only the given workspace-relative file paths to
their state at checkpoint. Files not in paths remain
untouched. Files present in the workspace but not in the
checkpoint tree are deleted (when listed in paths).
Sourcepub fn diff(
&self,
a: &CheckpointId,
b: Option<&CheckpointId>,
paths: &[String],
) -> Result<String>
pub fn diff( &self, a: &CheckpointId, b: Option<&CheckpointId>, paths: &[String], ) -> Result<String>
Diff between two checkpoints (or a vs current workspace if
b is None), optionally limited to paths.
Sourcepub fn changed_paths(
&self,
a: &CheckpointId,
b: &CheckpointId,
) -> Result<Vec<String>>
pub fn changed_paths( &self, a: &CheckpointId, b: &CheckpointId, ) -> Result<Vec<String>>
List file paths changed between checkpoints a and b.
Used for “shell-diff” attribution after run_shell calls.
Sourcepub fn gc(&self) -> Result<()>
pub fn gc(&self) -> Result<()>
Run git garbage collection on the shadow repo, pruning all unreachable objects immediately. This reclaims disk space after rewinds (which orphan commits) and after the pathspec exclusion fixes (which left large build-artifact blobs in the object store from earlier snapshots).
The operation is intentionally best-effort: if git gc fails (e.g. another process holds a lock) we log a warning and continue rather than propagating an error that would break the caller’s primary workflow.