pub struct UncommittedDiff<'repo> { /* private fields */ }Expand description
Staged, unstaged, and working-tree diffs over one loaded index.
Every method reuses the same Index and, once a working-tree method needs them, the same
WorktreeRules, so collecting entries and then loading their contents reads neither twice.
Working-tree scans may refresh stat data on the in-memory index; nothing is written to disk.
Obtain one from Diff::uncommitted or
UncommittedDiff::new.
Implementations§
Source§impl<'repo> UncommittedDiff<'repo>
impl<'repo> UncommittedDiff<'repo>
Sourcepub fn new(repo: &'repo Repository, index: Index) -> Self
pub fn new(repo: &'repo Repository, index: Index) -> Self
Diff repo against an index the caller already loaded.
§Parameters
repo- repository to diff.index- its index (normally the on-disk index).
Sourcepub fn staged_entries(&self, renames: RenameDetection) -> Result<Vec<DiffEntry>>
pub fn staged_entries(&self, renames: RenameDetection) -> Result<Vec<DiffEntry>>
Sourcepub fn unstaged_entries(
&mut self,
renames: RenameDetection,
) -> Result<Vec<DiffEntry>>
pub fn unstaged_entries( &mut self, renames: RenameDetection, ) -> Result<Vec<DiffEntry>>
Working tree against the index (grit diff --unstaged), sorted by path.
Like Git’s diff-files, a working-tree side that was not hashed carries a null
new_oid; a tracked file whose size changed is reported that way without reading it.
§Parameters
renames- rename detection between deleted and added paths.
§Errors
Returns Error::RequiresWorkTree in a bare repository, plus worktree rule, I/O, and
object read errors.
Sourcepub fn worktree_entries(
&mut self,
base_tree: Option<&ObjectId>,
renames: RenameDetection,
) -> Result<Vec<DiffEntry>>
pub fn worktree_entries( &mut self, base_tree: Option<&ObjectId>, renames: RenameDetection, ) -> Result<Vec<DiffEntry>>
Working tree and index together against base_tree (grit diff, grit diff --against),
sorted by path.
§Parameters
base_tree- tree to compare with;Nonefor the empty tree (an unbornHEAD).renames- rename detection between deleted and added paths.
§Errors
Returns Error::RequiresWorkTree in a bare repository, plus worktree rule, I/O, and
object read errors.
Sourcepub fn entries(
&mut self,
target: &DiffTarget,
pathspecs: &[String],
options: &DiffOptions,
) -> Result<DiffEntriesResult>
pub fn entries( &mut self, target: &DiffTarget, pathspecs: &[String], options: &DiffOptions, ) -> Result<DiffEntriesResult>
Changed paths for any DiffTarget, limited to pathspecs and to the statuses in
options.filter (--diff-filter), sorted by path. No contents are loaded.
DiffTarget::WorktreeVsHead compares with HEAD’s tree (the empty tree when unborn).
Commit and tree targets ignore the index, so prefer Diff::entries
for them; it does not load one.
§Parameters
target- what to compare, e.g. fromresolve_diff_request.pathspecs- repository-relative pathspecs; empty means every path.options- onlyrenamesandfilterare used.
§Errors
Returns Error::RequiresWorkTree for a working-tree target in a bare repository, plus
HEAD resolution, pathspec, worktree rule, I/O, and object read errors.
Sourcepub fn peer_changes<'a>(
&mut self,
side: DiffSide,
pathspecs: &[String],
renames: RenameDetection,
primary_paths: impl IntoIterator<Item = &'a str>,
) -> Result<Vec<FileChange>>
pub fn peer_changes<'a>( &mut self, side: DiffSide, pathspecs: &[String], renames: RenameDetection, primary_paths: impl IntoIterator<Item = &'a str>, ) -> Result<Vec<FileChange>>
Changes on the other side of the index for the paths in primary_paths, which feed
hunk_ids_with_duplicate_peers so hunk ids
stay stable when an identical hunk moves between the staged and unstaged sides.
For DiffSide::Staged primaries this loads the unstaged changes on those paths; for
DiffSide::Unstaged the staged ones. DiffSide::Other has no peer side. A path
matches when it is the peer’s display path or, for a rename, its old path. No
--diff-filter applies: ids must not depend on which statuses are shown.
§Parameters
side- the side the primary changes came from.pathspecs- the pathspecs the primary changes were limited to.renames- rename detection, as for the primary changes.primary_paths- display paths of the primary changes.
§Errors
Returns Error::RequiresWorkTree for staged primaries in a bare repository, plus the
errors of Self::entries and of loading the changes.
Sourcepub fn load_worktree_changes(
&mut self,
entries: Vec<DiffEntry>,
) -> Result<Vec<FileChange>>
pub fn load_worktree_changes( &mut self, entries: Vec<DiffEntry>, ) -> Result<Vec<FileChange>>
Load entries from Self::unstaged_entries or Self::worktree_entries: old sides
from the object database, new sides from the working tree (with gitlinks showing the
submodule’s checked-out commit and -dirty state).
§Errors
Returns Error::RequiresWorkTree in a bare repository, plus I/O, filter, and object
read errors.