Skip to main content

RepoBackend

Trait RepoBackend 

Source
pub trait RepoBackend {
Show 22 methods // Required methods fn path(&self) -> &str; fn commits(&self) -> &[CommitInfo]; fn changed_files(&self, index: usize) -> Vec<FileChange>; fn commit_diff(&self, index: usize) -> Diff; fn file_diff(&self, index: usize, path: &str) -> Diff; fn working_status(&self, amend: bool) -> WorkingStatus; fn working_diff(&self, path: &str, staged: bool, amend: bool) -> Diff; fn stage(&self, path: &str) -> Result<(), String>; fn unstage(&self, path: &str, amend: bool) -> Result<(), String>; fn revert(&self, path: &str) -> Result<(), String>; fn delete_untracked(&self, path: &str) -> Result<(), String>; fn commit(&self, message: &str, amend: bool) -> Result<(), String>; fn head_message(&self) -> Option<String>; // Provided methods fn commit_file_blobs(&self, index: usize, path: &str) -> BlobPair { ... } fn branches(&self) -> Vec<BranchInfo> { ... } fn branch_files(&self, branch: &BranchInfo) -> Vec<FileChange> { ... } fn branch_diff(&self, branch: &BranchInfo) -> Diff { ... } fn branch_file_diff(&self, branch: &BranchInfo, path: &str) -> Diff { ... } fn branch_file_blobs(&self, branch: &BranchInfo, path: &str) -> BlobPair { ... } fn working_file_blobs( &self, path: &str, staged: bool, amend: bool, ) -> BlobPair { ... } fn apply_to_index(&self, patch: &str) -> Result<(), String> { ... } fn signature(&self) -> Option<(String, String)> { ... }
}
Expand description

The interface the UI layer depends on. Implemented by the live Git2Backend and the in-memory FixtureBackend.

Required Methods§

Source

fn path(&self) -> &str

Human-readable path to the repository (shown in the title bar).

Source

fn commits(&self) -> &[CommitInfo]

All commits, newest first (reverse-topological, like git log).

Source

fn changed_files(&self, index: usize) -> Vec<FileChange>

Files changed by the commit at index, against its first parent.

Source

fn commit_diff(&self, index: usize) -> Diff

Unified diff of the whole commit against its first parent.

Source

fn file_diff(&self, index: usize, path: &str) -> Diff

Unified diff for a single file within the commit.

Source

fn working_status(&self, amend: bool) -> WorkingStatus

The current working-tree status: staged and unstaged changes.

When amend is set the staged side is computed against HEAD’s parent instead of HEAD, so the changes already in the last commit show up as staged (they will be part of the amended commit) and can be unstaged to drop them — exactly how git gui’s amend mode behaves.

Source

fn working_diff(&self, path: &str, staged: bool, amend: bool) -> Diff

Diff for a single working-tree path. With staged false this is the working copy against the index (git diff); with staged true it is the index against the staged base — HEAD normally, HEAD’s parent when amend is set.

Source

fn stage(&self, path: &str) -> Result<(), String>

Stage a path (git add <path>), staging a deletion if the file is gone from the working tree. Returns a human-readable error on failure.

Source

fn unstage(&self, path: &str, amend: bool) -> Result<(), String>

Unstage a path. Normally resets the index entry to HEAD (git reset HEAD -- <path>); when amend is set it resets to HEAD’s parent, removing the path’s change from the commit being amended.

Source

fn revert(&self, path: &str) -> Result<(), String>

Revert (discard) the unstaged working-tree changes to path, restoring the working copy from the index — git checkout -- <path>, the destructive half of git gui’s “Revert Changes”. Only the working-vs-index delta is dropped; any staged changes to the same path are preserved. Untracked files have no index entry to restore from; use delete_untracked for those.

Source

fn delete_untracked(&self, path: &str) -> Result<(), String>

Delete an untracked file from the working tree. This is the “revert” a brand-new file gets: it isn’t in the index or HEAD, so the only way to undo its appearance is to remove it. The content is gone for good — git never had a copy. The caller is responsible for only passing untracked paths.

Source

fn commit(&self, message: &str, amend: bool) -> Result<(), String>

Commit the staged changes with message. When amend is set, replace the current HEAD commit instead of adding a new one.

Source

fn head_message(&self) -> Option<String>

The full message of the current HEAD commit, used to pre-fill the editor when amending. None if there is no commit yet.

Provided Methods§

Source

fn commit_file_blobs(&self, index: usize, path: &str) -> BlobPair

Raw bytes of a file’s two sides in the commit at index versus its first parent — the binary/image analogue of file_diff. The graphical diff uses this to compare images instead of rendering a useless “Binary files differ” text line. The default returns an empty pair, so backends without blob access simply never offer an image diff.

Source

fn branches(&self) -> Vec<BranchInfo>

All local and remote branches for review mode’s branch list: the checked-out branch first, then the remaining local branches, then the remote-tracking ones, each group sorted by name. A remote-tracking branch whose local tracks it and sits at the same tip is folded into the local’s row (see BranchInfo::upstream) rather than listed twice. The default is empty, for backends without branch access.

Source

fn branch_files(&self, branch: &BranchInfo) -> Vec<FileChange>

Files changed by everything branch contains: the aggregated diff from the branch’s review base (see BranchInfo::base_id) to its tip.

Source

fn branch_diff(&self, branch: &BranchInfo) -> Diff

Unified diff of everything branch contains, against its review base.

Source

fn branch_file_diff(&self, branch: &BranchInfo, path: &str) -> Diff

Unified diff for a single file within branch’s aggregated diff.

Source

fn branch_file_blobs(&self, branch: &BranchInfo, path: &str) -> BlobPair

Raw bytes of a file’s two sides in branch’s aggregated diff — the review base’s copy (old) versus the tip’s (new); the binary/image analogue of branch_file_diff.

Source

fn working_file_blobs(&self, path: &str, staged: bool, amend: bool) -> BlobPair

Raw bytes of a working-tree file’s two sides, mirroring working_diff: with staged false it is the index copy (old) versus the working copy on disk (new); with staged true it is the staged base — HEAD, or HEAD’s parent when amend is set — (old) versus the index copy (new). The binary/image analogue of working_diff; the default returns an empty pair.

Source

fn apply_to_index(&self, patch: &str) -> Result<(), String>

Apply a unified-diff patch directly to the index (git apply --cached), the mechanism behind partial (line-range) staging and unstaging. The patch is always oriented to apply forward to the current index — the stage-vs-unstage direction is baked in by build_partial_patch. The default implementation rejects it; backends that can model partial application override it.

Source

fn signature(&self) -> Option<(String, String)>

The configured commit identity as (name, email), used by the commit screen’s “Sign Off” shortcut to append a Signed-off-by trailer. None when no identity is configured.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§