Struct git2::Diff

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

The diff object that contains all individual file deltas.

This is an opaque structure which will be allocated by one of the diff generator functions on the Repository structure (e.g. diff_tree_to_tree or other diff_* functions).

Implementations§

source§

impl<'repo> Diff<'repo>

source

pub fn merge(&mut self, from: &Diff<'repo>) -> Result<(), Error>

Merge one diff into another.

This merges items from the “from” list into the “self” list. The resulting diff will have all items that appear in either list. If an item appears in both lists, then it will be “merged” to appear as if the old version was from the “onto” list and the new version is from the “from” list (with the exception that if the item has a pending DELETE in the middle, then it will show as deleted).

source

pub fn deltas(&self) -> Deltas<'_>

Returns an iterator over the deltas in this diff.

source

pub fn get_delta(&self, i: usize) -> Option<DiffDelta<'_>>

Return the diff delta for an entry in the diff list.

source

pub fn is_sorted_icase(&self) -> bool

Check if deltas are sorted case sensitively or insensitively.

source

pub fn print<F>(&self, format: DiffFormat, cb: F) -> Result<(), Error>
where F: FnMut(DiffDelta<'_>, Option<DiffHunk<'_>>, DiffLine<'_>) -> bool,

Iterate over a diff generating formatted text output.

Returning false from the callback will terminate the iteration and return an error from this function.

source

pub fn foreach( &self, file_cb: &mut (dyn FnMut(DiffDelta<'_>, f32) -> bool + '_), binary_cb: Option<&mut (dyn FnMut(DiffDelta<'_>, DiffBinary<'_>) -> bool + '_)>, hunk_cb: Option<&mut (dyn FnMut(DiffDelta<'_>, DiffHunk<'_>) -> bool + '_)>, line_cb: Option<&mut (dyn FnMut(DiffDelta<'_>, Option<DiffHunk<'_>>, DiffLine<'_>) -> bool + '_)> ) -> Result<(), Error>

Loop over all deltas in a diff issuing callbacks.

Returning false from any callback will terminate the iteration and return an error from this function.

source

pub fn stats(&self) -> Result<DiffStats, Error>

Accumulate diff statistics for all patches.

source

pub fn find_similar( &mut self, opts: Option<&mut DiffFindOptions> ) -> Result<(), Error>

Transform a diff marking file renames, copies, etc.

This modifies a diff in place, replacing old entries that look like renames or copies with new entries reflecting those changes. This also will, if requested, break modified files into add/remove pairs if the amount of change is above a threshold.

source

pub fn patchid( &self, opts: Option<&mut DiffPatchidOptions> ) -> Result<Oid, Error>

Create a patch ID from a diff.

source§

impl Diff<'static>

source

pub fn from_buffer(buffer: &[u8]) -> Result<Diff<'static>, Error>

Read the contents of a git patch file into a git_diff object.

The diff object produced is similar to the one that would be produced if you actually produced it computationally by comparing two trees, however there may be subtle differences. For example, a patch file likely contains abbreviated object IDs, so the object IDs parsed by this function will also be abbreviated.

Trait Implementations§

source§

impl<'repo> Drop for Diff<'repo>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

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

Auto Trait Implementations§

§

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

§

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

§

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

§

impl<'repo> UnwindSafe 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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.