Skip to main content

Diff

Struct Diff 

Source
pub struct Diff<'repo> { /* private fields */ }
Expand description

Compare trees, the index, and the working tree for one repository.

Implementations§

Source§

impl Diff<'_>

Source

pub fn commit_files_many( &self, oids: &[ObjectId], pathspecs: &[String], opts: CommitFilesManyOptions, config: &ConfigSet, thread_policy: &ThreadPolicy, ) -> Result<Vec<CommitFilesResult>>

Build per-commit file diffs for a slice of commit oids, preserving input order.

Parent trees are resolved once and reused across consecutive commits (same as super::write_commits_log_patch). When oids are newest-first and history is linear, each commit’s first parent is the next oid and its tree is reused without an extra read. Work runs in parallel when ThreadPolicy allows and the batch is large enough to amortize pool startup.

§Errors

Propagates object read, tree diff, and parallel pool errors.

Source

pub fn commit_files_many_work( &self, inputs: &[CommitFilesManyInput], pathspecs: &[String], opts: CommitFilesManyOptions, config: &ConfigSet, thread_policy: &ThreadPolicy, ) -> Result<Vec<CommitFilesResult>>

Like Self::commit_files_many when commit trees and parents are already loaded.

§Errors

Propagates object read, tree diff, and parallel pool errors.

Source§

impl<'repo> Diff<'repo>

Source

pub fn new(repo: &'repo Repository) -> Self

Bind diff helpers to repo.

Source

pub fn repository(&self) -> &'repo Repository

Underlying repository.

Source

pub fn tree_to_tree( &self, old_tree: Option<&ObjectId>, new_tree: Option<&ObjectId>, ) -> Result<Vec<DiffEntry>>

Diff two tree oids (either side may be None for an empty tree).

§Errors

Propagates ODB read and tree walk errors.

§Examples

See the library guide on diffing.

Source

pub fn index_to_tree( &self, index: &Index, tree_oid: Option<&ObjectId>, ignore_submodules: bool, ) -> Result<Vec<DiffEntry>>

Diff the index against a tree (typically HEAD’s tree).

§Errors

Propagates ODB and index diff errors.

Source

pub fn worktree_to_index( &self, index: &mut Index, ignore_submodule_untracked: bool, simplify_gitlinks: bool, ) -> Result<Vec<DiffEntry>>

Diff the working tree against the index.

§Errors

Returns an error when the repository has no work tree or diff I/O fails.

Source

pub fn files( &self, target: &DiffTarget, pathspecs: &[String], opts: &DiffOptions, ) -> Result<Vec<FileDiff>>

Structured per-file diffs for target, honoring pathspecs and line-diff opts.

§Errors

Propagates index, ODB, and worktree diff failures.

Source§

impl<'repo> Diff<'repo>

Source

pub fn has_changes( &self, target: &DiffTarget, pathspecs: &[String], opts: DiffOptions, ) -> Result<bool>

Whether the selected diff has any real changes, stopping at the first one.

Worktree targets honor the index stat cache and only hash blob content when needed. When whitespace ignore flags are set on opts, content is compared under those rules; a change that differs only in ignored whitespace returns false.

§Errors

Propagates repository, ODB, and diff errors.

Trait Implementations§

Source§

impl<'repo> Clone for Diff<'repo>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'repo> Copy for Diff<'repo>

Source§

impl<'repo> Debug for Diff<'repo>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

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

§

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

§

impl<'repo> Freeze for Diff<'repo>

§

impl<'repo> Send for Diff<'repo>

§

impl<'repo> Sync for Diff<'repo>

§

impl<'repo> Unpin for Diff<'repo>

§

impl<'repo> UnsafeUnpin for Diff<'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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.