pub struct Repository { /* private fields */ }Expand description
The Suture Repository.
Implementations§
Source§impl Repository
impl Repository
Sourcepub fn init(path: &Path, author: &str) -> Result<Self, RepoError>
pub fn init(path: &Path, author: &str) -> Result<Self, RepoError>
Initialize a new Suture repository at the given path.
Sourcepub fn open(path: &Path) -> Result<Self, RepoError>
pub fn open(path: &Path) -> Result<Self, RepoError>
Reconstructs the full DAG from the metadata database by loading all stored patches and their edges.
Sourcepub fn open_in_memory() -> Result<Self, RepoError>
pub fn open_in_memory() -> Result<Self, RepoError>
Open an in-memory repository for testing or embedded use.
Creates a repository backed entirely by in-memory storage. No filesystem I/O occurs except for the initial tempdir creation. The CAS uses a temporary directory that is cleaned up on drop.
Sourcepub fn create_branch(
&mut self,
name: &str,
target: Option<&str>,
) -> Result<(), RepoError>
pub fn create_branch( &mut self, name: &str, target: Option<&str>, ) -> Result<(), RepoError>
Create a new branch.
Sourcepub fn head(&self) -> Result<(String, PatchId), RepoError>
pub fn head(&self) -> Result<(String, PatchId), RepoError>
Get the current branch and its target.
Reads the head_branch config key to determine which branch is
currently checked out. Falls back to “main” if not set.
Sourcepub fn list_branches(&self) -> Vec<(String, PatchId)>
pub fn list_branches(&self) -> Vec<(String, PatchId)>
List all branches.
Sourcepub fn delete_branch(&mut self, name: &str) -> Result<(), RepoError>
pub fn delete_branch(&mut self, name: &str) -> Result<(), RepoError>
Delete a branch. Cannot delete the currently checked-out branch.
Sourcepub fn get_config(&self, key: &str) -> Result<Option<String>, RepoError>
pub fn get_config(&self, key: &str) -> Result<Option<String>, RepoError>
Get a configuration value.
Lookup order:
.suture/configfile (repo-level TOML config)- SQLite config table (set via
suture config key=value) - Global config
~/.config/suture/config.toml
Sourcepub fn set_config(&mut self, key: &str, value: &str) -> Result<(), RepoError>
pub fn set_config(&mut self, key: &str, value: &str) -> Result<(), RepoError>
Set a configuration value.
Sourcepub fn list_config(&self) -> Result<Vec<(String, String)>, RepoError>
pub fn list_config(&self) -> Result<Vec<(String, String)>, RepoError>
List all configuration key-value pairs.
Sourcepub fn create_tag(
&mut self,
name: &str,
target: Option<&str>,
) -> Result<(), RepoError>
pub fn create_tag( &mut self, name: &str, target: Option<&str>, ) -> Result<(), RepoError>
Create a tag pointing to a patch ID (or HEAD).
Tags are stored as config entries tag.<name> pointing to a patch hash.
Sourcepub fn delete_tag(&mut self, name: &str) -> Result<(), RepoError>
pub fn delete_tag(&mut self, name: &str) -> Result<(), RepoError>
Delete a tag. Returns an error if the tag does not exist.
List all tags as (name, target_patch_id).
Sourcepub fn resolve_tag(&self, name: &str) -> Result<Option<PatchId>, RepoError>
pub fn resolve_tag(&self, name: &str) -> Result<Option<PatchId>, RepoError>
Resolve a tag name to a patch ID.
Sourcepub fn add_note(&self, patch_id: &PatchId, note: &str) -> Result<(), RepoError>
pub fn add_note(&self, patch_id: &PatchId, note: &str) -> Result<(), RepoError>
Add a note to a commit.
Sourcepub fn list_notes(&self, patch_id: &PatchId) -> Result<Vec<String>, RepoError>
pub fn list_notes(&self, patch_id: &PatchId) -> Result<Vec<String>, RepoError>
List notes for a commit.
Sourcepub fn remove_note(
&self,
patch_id: &PatchId,
index: usize,
) -> Result<(), RepoError>
pub fn remove_note( &self, patch_id: &PatchId, index: usize, ) -> Result<(), RepoError>
Remove a note from a commit. Returns an error if the index is out of range.
Sourcepub fn patches_since(&self, since_id: &PatchId) -> Vec<Patch>
pub fn patches_since(&self, since_id: &PatchId) -> Vec<Patch>
Get patches created after a given patch ID (ancestry walk).
Returns patches reachable from branch tips but NOT ancestors of since_id.
Sourcepub fn status(&self) -> Result<RepoStatus, RepoError>
pub fn status(&self) -> Result<RepoStatus, RepoError>
Get repository status.
Sourcepub fn add(&self, path: &str) -> Result<(), RepoError>
pub fn add(&self, path: &str) -> Result<(), RepoError>
Add a file to the staging area (working set).
Sourcepub fn commit(&mut self, message: &str) -> Result<PatchId, RepoError>
pub fn commit(&mut self, message: &str) -> Result<PatchId, RepoError>
Create a commit from the working set.
pub fn has_uncommitted_changes(&self) -> Result<bool, RepoError>
pub fn stash_push(&mut self, message: Option<&str>) -> Result<usize, RepoError>
pub fn stash_pop(&mut self) -> Result<(), RepoError>
pub fn stash_apply(&mut self, index: usize) -> Result<(), RepoError>
pub fn stash_list(&self) -> Result<Vec<StashEntry>, RepoError>
pub fn stash_drop(&mut self, index: usize) -> Result<(), RepoError>
Sourcepub fn snapshot_head(&self) -> Result<FileTree, RepoError>
pub fn snapshot_head(&self) -> Result<FileTree, RepoError>
Build a FileTree snapshot for the HEAD commit.
Returns a cached snapshot if the HEAD has not changed since the last call, making this O(1) instead of O(n) where n = total patches.
Sourcepub fn invalidate_head_cache(&self)
pub fn invalidate_head_cache(&self)
Invalidate the cached HEAD snapshot and branch name.
Must be called after any operation that changes the HEAD pointer, including branch updates from external sources (e.g., fetch/pull).
Sourcepub fn snapshot(&self, patch_id: &PatchId) -> Result<FileTree, RepoError>
pub fn snapshot(&self, patch_id: &PatchId) -> Result<FileTree, RepoError>
Build a FileTree snapshot for a specific patch.
Tries loading from SQLite first (O(1)), falls back to patch replay (O(n)).
Sourcepub fn sync_working_tree(&self, old_tree: &FileTree) -> Result<(), RepoError>
pub fn sync_working_tree(&self, old_tree: &FileTree) -> Result<(), RepoError>
Sync the working tree to match the current HEAD snapshot.
Compares old_tree (the state before the operation) against the
current HEAD snapshot and applies file additions, modifications,
deletions, and renames to disk.
Update the working tree to match the current HEAD snapshot.
Compares old_tree (the state before the operation) against the
current HEAD snapshot and applies file additions, modifications,
deletions, and renames to disk.
Sourcepub fn checkout(&mut self, branch_name: &str) -> Result<FileTree, RepoError>
pub fn checkout(&mut self, branch_name: &str) -> Result<FileTree, RepoError>
Checkout a branch, updating the working tree to match its tip state.
This operation:
- Builds the target FileTree from the branch’s patch chain
- Compares against the current working tree
- Updates files (add/modify/delete) to match the target
- Updates the HEAD reference
Refuses to checkout if there are uncommitted staged changes.
Sourcepub fn diff(
&self,
from: Option<&str>,
to: Option<&str>,
) -> Result<Vec<DiffEntry>, RepoError>
pub fn diff( &self, from: Option<&str>, to: Option<&str>, ) -> Result<Vec<DiffEntry>, RepoError>
Compute the diff between two commits or branches.
If from is None, compares the empty tree to to.
Sourcepub fn diff_staged(&self) -> Result<Vec<DiffEntry>, RepoError>
pub fn diff_staged(&self) -> Result<Vec<DiffEntry>, RepoError>
Show staged changes (diff of staged files vs HEAD).
Sourcepub fn reset(
&mut self,
target: &str,
mode: ResetMode,
) -> Result<PatchId, RepoError>
pub fn reset( &mut self, target: &str, mode: ResetMode, ) -> Result<PatchId, RepoError>
Reset HEAD to a specific commit.
Resolves target (hex hash or branch name), moves the current branch
pointer, and optionally clears staging and/or restores the working tree
depending on mode.
Returns the resolved target patch ID.
Sourcepub fn revert(
&mut self,
patch_id: &PatchId,
message: Option<&str>,
) -> Result<PatchId, RepoError>
pub fn revert( &mut self, patch_id: &PatchId, message: Option<&str>, ) -> Result<PatchId, RepoError>
Revert a commit by creating a new patch that undoes its changes.
The revert creates inverse patches (Delete for Create, etc.) and commits them on top of HEAD, then syncs the working tree.
Sourcepub fn squash(
&mut self,
count: usize,
message: &str,
) -> Result<PatchId, RepoError>
pub fn squash( &mut self, count: usize, message: &str, ) -> Result<PatchId, RepoError>
Squash the last N patches on the current branch into a single patch.
Returns the new tip patch ID.
Sourcepub fn merge_plan(
&self,
branch_a: &str,
branch_b: &str,
) -> Result<MergeResult, RepoError>
pub fn merge_plan( &self, branch_a: &str, branch_b: &str, ) -> Result<MergeResult, RepoError>
Compute a merge plan between two branches.
Sourcepub fn preview_merge(
&self,
source_branch: &str,
) -> Result<MergeExecutionResult, RepoError>
pub fn preview_merge( &self, source_branch: &str, ) -> Result<MergeExecutionResult, RepoError>
Execute a merge of source_branch into the current HEAD branch.
For clean merges (no conflicts):
- Collect unique patches from both branches (after LCA)
- Apply the source branch’s tree onto HEAD’s working tree
- Create a merge commit (patch with two parents)
- Update the working tree to reflect the merge result
For merges with conflicts:
- Apply all non-conflicting patches from source
- Return a
MergeExecutionResultwith conflict details - The caller can then resolve conflicts and commit
Preview a merge without modifying the repository.
Returns the same MergeExecutionResult that execute_merge would produce,
but without creating any patches, moving branches, or writing files.
The merge_patch_id and unresolved_conflicts fields are computed
heuristically (the patch ID is a placeholder since no patch is actually created).
Sourcepub fn execute_merge(
&mut self,
source_branch: &str,
) -> Result<MergeExecutionResult, RepoError>
pub fn execute_merge( &mut self, source_branch: &str, ) -> Result<MergeExecutionResult, RepoError>
Execute a merge: applies patches from source_branch into the current branch.
Sourcepub fn cherry_pick(&mut self, patch_id: &PatchId) -> Result<PatchId, RepoError>
pub fn cherry_pick(&mut self, patch_id: &PatchId) -> Result<PatchId, RepoError>
Cherry-pick a patch onto the current HEAD branch.
Creates a new patch with the same changes (operation_type, touch_set, target_path, payload) but with the current HEAD as its parent.
Sourcepub fn rebase(&mut self, target_branch: &str) -> Result<RebaseResult, RepoError>
pub fn rebase(&mut self, target_branch: &str) -> Result<RebaseResult, RepoError>
Rebase the current branch onto a target branch.
Finds commits unique to the current branch (after the LCA with target), then replays them onto the target branch tip. Updates the current branch pointer to the new tip.
Sourcepub fn commit_groups(&self, patches: &[Patch]) -> Vec<Vec<Patch>>
pub fn commit_groups(&self, patches: &[Patch]) -> Vec<Vec<Patch>>
Group a patch chain into logical commits.
A “logical commit” is a contiguous chain of per-file patches that share the same message. Returns groups in oldest-first order (root to tip).
Sourcepub fn patches_since_base(&self, base: &PatchId) -> Vec<Patch>
pub fn patches_since_base(&self, base: &PatchId) -> Vec<Patch>
Get patches between a base commit and HEAD (exclusive of base).
Walks the first-parent chain from HEAD back to base, collecting
all patches that are NOT ancestors of base.
Sourcepub fn generate_rebase_todo(&self, base: &PatchId) -> Result<String, RepoError>
pub fn generate_rebase_todo(&self, base: &PatchId) -> Result<String, RepoError>
Generate a TODO file for interactive rebase.
Returns the TODO file content as a string.
Sourcepub fn parse_rebase_todo(
&self,
todo_content: &str,
base: &PatchId,
) -> Result<RebasePlan, RepoError>
pub fn parse_rebase_todo( &self, todo_content: &str, base: &PatchId, ) -> Result<RebasePlan, RepoError>
Parse a TODO file into a rebase plan.
Sourcepub fn rebase_interactive(
&mut self,
plan: &RebasePlan,
onto: &PatchId,
) -> Result<PatchId, RepoError>
pub fn rebase_interactive( &mut self, plan: &RebasePlan, onto: &PatchId, ) -> Result<PatchId, RepoError>
Execute an interactive rebase plan.
Replays commits according to the plan, handling pick/reword/edit/squash/drop. Returns the new tip patch ID.
Sourcepub fn load_rebase_state(&self) -> Result<Option<RebaseState>, RepoError>
pub fn load_rebase_state(&self) -> Result<Option<RebaseState>, RepoError>
Load interactive rebase state.
Sourcepub fn rebase_abort(&mut self) -> Result<(), RepoError>
pub fn rebase_abort(&mut self) -> Result<(), RepoError>
Abort an in-progress interactive rebase.
Restores the branch to its original position before rebase started.
Sourcepub fn blame(&self, path: &str) -> Result<Vec<BlameEntry>, RepoError>
pub fn blame(&self, path: &str) -> Result<Vec<BlameEntry>, RepoError>
Show per-line commit attribution for a file.
Returns a vector of BlameEntry tuples, one per line in the file at HEAD.
Sourcepub fn log(&self, branch: Option<&str>) -> Result<Vec<Patch>, RepoError>
pub fn log(&self, branch: Option<&str>) -> Result<Vec<Patch>, RepoError>
Get the patch history (log) for a branch (first-parent chain only).
Sourcepub fn log_all(&self, branch: Option<&str>) -> Result<Vec<Patch>, RepoError>
pub fn log_all(&self, branch: Option<&str>) -> Result<Vec<Patch>, RepoError>
Get the full patch history for a branch, including all reachable commits (not just the first-parent chain). Merged branch commits are included.
Sourcepub fn meta(&self) -> &MetadataStore
pub fn meta(&self) -> &MetadataStore
Get a reference to the metadata store.
Sourcepub fn add_remote(&self, name: &str, url: &str) -> Result<(), RepoError>
pub fn add_remote(&self, name: &str, url: &str) -> Result<(), RepoError>
Add a remote Hub.
Stores the remote URL in metadata config as “remote.
Sourcepub fn list_remotes(&self) -> Result<Vec<(String, String)>, RepoError>
pub fn list_remotes(&self) -> Result<Vec<(String, String)>, RepoError>
List configured remotes.
Sourcepub fn is_worktree(&self) -> bool
pub fn is_worktree(&self) -> bool
Check whether this repository is a linked worktree.
Sourcepub fn add_worktree(
&mut self,
name: &str,
path: &Path,
branch: Option<&str>,
) -> Result<(), RepoError>
pub fn add_worktree( &mut self, name: &str, path: &Path, branch: Option<&str>, ) -> Result<(), RepoError>
Add a worktree. Creates a new directory linked to this repo’s data.
Sourcepub fn list_worktrees(&self) -> Result<Vec<WorktreeEntry>, RepoError>
pub fn list_worktrees(&self) -> Result<Vec<WorktreeEntry>, RepoError>
List all worktrees. Returns the main worktree plus any linked worktrees.
Sourcepub fn remove_worktree(&mut self, name: &str) -> Result<(), RepoError>
pub fn remove_worktree(&mut self, name: &str) -> Result<(), RepoError>
Remove a worktree by name. Deletes the worktree directory and cleans up the main repo’s config entries.
Sourcepub fn rename_file(
&self,
old_path: &str,
new_path: &str,
) -> Result<(), RepoError>
pub fn rename_file( &self, old_path: &str, new_path: &str, ) -> Result<(), RepoError>
Rename a tracked file. Stages both the deletion of the old path and the addition of the new path.
Sourcepub fn get_remote_url(&self, name: &str) -> Result<String, RepoError>
pub fn get_remote_url(&self, name: &str) -> Result<String, RepoError>
Get the URL for a remote.
Sourcepub fn all_patches(&self) -> Vec<Patch>
pub fn all_patches(&self) -> Vec<Patch>
Get all patches in the DAG as a Vec.
Sourcepub fn gc(&self) -> Result<GcResult, RepoError>
pub fn gc(&self) -> Result<GcResult, RepoError>
Remove unreachable patches from the repository.
Patches not reachable from any branch tip are deleted from the metadata store (patches, edges, signatures tables). The in-memory DAG is not updated; reopen the repository after GC to get a clean DAG.
Sourcepub fn fsck(&self) -> Result<FsckResult, RepoError>
pub fn fsck(&self) -> Result<FsckResult, RepoError>
Verify repository integrity.
Checks DAG consistency (parent references), branch integrity (branch targets exist), blob references (CAS has blobs referenced by patches), and HEAD consistency.
Auto Trait Implementations§
impl !Freeze for Repository
impl !RefUnwindSafe for Repository
impl Send for Repository
impl !Sync for Repository
impl Unpin for Repository
impl UnsafeUnpin for Repository
impl !UnwindSafe for Repository
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more