Skip to main content

UncommittedDiff

Struct UncommittedDiff 

Source
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>

Source

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).
Source

pub fn index(&self) -> &Index

The index every comparison uses.

Source

pub fn staged_entries(&self, renames: RenameDetection) -> Result<Vec<DiffEntry>>

Index against HEAD’s tree (grit diff --staged), sorted by path.

An unborn HEAD compares against the empty tree, so every index entry is added.

§Parameters
  • renames - rename detection between deleted and added paths.
§Errors

Returns HEAD resolution, config, and object read errors.

Source

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.

Source

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; None for the empty tree (an unborn HEAD).
  • 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.

Source

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. from resolve_diff_request.
  • pathspecs - repository-relative pathspecs; empty means every path.
  • options - only renames and filter are 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.

Source

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.

Source

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.

Auto Trait Implementations§

§

impl<'repo> !RefUnwindSafe for UncommittedDiff<'repo>

§

impl<'repo> !UnwindSafe for UncommittedDiff<'repo>

§

impl<'repo> Freeze for UncommittedDiff<'repo>

§

impl<'repo> Send for UncommittedDiff<'repo>

§

impl<'repo> Sync for UncommittedDiff<'repo>

§

impl<'repo> Unpin for UncommittedDiff<'repo>

§

impl<'repo> UnsafeUnpin for UncommittedDiff<'repo>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.