fabricatio_checkpoint.rust
Classes
Stores checkpoint information for a specific worktree directory. |
|
Manages shadow Git repositories for file checkpointing. |
Functions
|
Removes all store repositories under the given root path whose working directories no longer exist. |
Package Contents
- class fabricatio_checkpoint.rust.CheckPointStore
Stores checkpoint information for a specific worktree directory.
This class manages the shadow repository and provides methods for saving checkpoints, rolling back files, and retrieving commit history.
- property workspace: pathlib.Path
The worktree directory being tracked.
- save(commit_msg: str | None = None) str
Saves the current state of the worktree as a new commit.
This method stages all changes in the worktree directory and creates a new commit in the shadow repository. It acts as a checkpoint that can later be restored.
- Parameters:
commit_msg – Optional commit message; defaults to empty string if not provided.
- Returns:
The commit ID (OID) as a string.
Note
If there are no changes to commit, this method returns the ID of the last commit (the HEAD).
- head() str
Retrieves the ID of the current HEAD commit.
This method retrieves the ID of the current HEAD commit in the shadow repository.
- Returns:
The commit ID (OID) as a string.
- commits() list[str]
Lists all commit IDs in the shadow repository’s history.
This method retrieves the complete commit history from the current HEAD backwards through the parent commits. The commits are returned in reverse chronological order (newest first).
- Returns:
A list of commit IDs (OIDs as strings) in reverse chronological order.
- reset(commit_id: str) None
Resets the worktree to a specific commit.
Performs a hard reset of the worktree directory to match the state at the specified commit. This discards all changes in the working directory and index, making them match the commit.
- Parameters:
commit_id – The commit ID (OID as string) to reset to.
- rollback(commit_id: str, file_path: str | os.PathLike | pathlib.Path) None
Restores a specific file from a commit.
This rolls back a single file to its state at the specified commit, checking out that file from the commit’s tree.
- Parameters:
commit_id – The commit ID (OID as string) to restore from.
file_path – The relative path to the file within the worktree.
- get_file_diff(commit_id: str, file_path: str | os.PathLike | pathlib.Path) str
Retrieves the diff for a specific file at a given commit.
Compares the file state at the specified commit with its state in the parent commit, returning a patch-format diff string. If the commit has no parent (initial commit), it compares against an empty tree.
- Parameters:
commit_id – The commit ID (OID as string) to get the diff from.
file_path – The relative path to the file within the worktree.
- Returns:
A string containing the unified diff in patch format.
- class fabricatio_checkpoint.rust.CheckpointService
Manages shadow Git repositories for file checkpointing.
A shadow repository manager creates and maintains separate bare Git repositories for each worktree directory. This enables independent version control and checkpointing without interfering with any existing Git repositories in the worktree.
- get_store(worktree_dir: str | os.PathLike | pathlib.Path) CheckPointStore
Gets or creates a shadow repository for the given worktree directory.
This method first checks the cache for an existing repository. If not found, it either opens an existing bare repository from disk or creates a new one.
- Parameters:
worktree_dir – The directory to be tracked by the shadow repository.
- Returns:
A CheckPointStore instance for the specified worktree.
- workspaces() list[pathlib.Path]
Returns a list of all managed workspaces.
- Returns:
A list of paths to managed workspace directories.
- fabricatio_checkpoint.rust.prune_stores(stores_root: str | os.PathLike | pathlib.Path) None
Removes all store repositories under the given root path whose working directories no longer exist.
This function: 1. Iterates through all directories under the stores_root 2. Attempts to open each as a git repository 3. Checks if the repository’s working directory still exists 4. If the working directory doesn’t exist, removes the entire repository directory
This is used to clean up shadow repositories whose original workspaces have been deleted.