Struct git2::Patch

source ·
pub struct Patch<'buffers> { /* private fields */ }
Expand description

A structure representing the text changes in a single diff delta.

This is an opaque structure.

Implementations§

source§

impl<'buffers> Patch<'buffers>

source

pub fn from_diff( diff: &Diff<'buffers>, idx: usize, ) -> Result<Option<Self>, Error>

Return a Patch for one file in a Diff.

Returns Ok(None) for an unchanged or binary file.

source

pub fn from_blobs( old_blob: &Blob<'buffers>, old_path: Option<&Path>, new_blob: &Blob<'buffers>, new_path: Option<&Path>, opts: Option<&mut DiffOptions>, ) -> Result<Self, Error>

Generate a Patch by diffing two blobs.

source

pub fn from_blob_and_buffer( old_blob: &Blob<'buffers>, old_path: Option<&Path>, new_buffer: &'buffers [u8], new_path: Option<&Path>, opts: Option<&mut DiffOptions>, ) -> Result<Self, Error>

Generate a Patch by diffing a blob and a buffer.

source

pub fn from_buffers( old_buffer: &'buffers [u8], old_path: Option<&Path>, new_buffer: &'buffers [u8], new_path: Option<&Path>, opts: Option<&mut DiffOptions>, ) -> Result<Self, Error>

Generate a Patch by diffing two buffers.

source

pub fn delta(&self) -> DiffDelta<'buffers>

Get the DiffDelta associated with the Patch.

source

pub fn num_hunks(&self) -> usize

Get the number of hunks in the Patch.

source

pub fn line_stats(&self) -> Result<(usize, usize, usize), Error>

Get the number of lines of context, additions, and deletions in the Patch.

source

pub fn hunk( &self, hunk_idx: usize, ) -> Result<(DiffHunk<'buffers>, usize), Error>

Get a DiffHunk and its total line count from the Patch.

source

pub fn num_lines_in_hunk(&self, hunk_idx: usize) -> Result<usize, Error>

Get the number of lines in a hunk.

source

pub fn line_in_hunk( &self, hunk_idx: usize, line_of_hunk: usize, ) -> Result<DiffLine<'buffers>, Error>

Get a DiffLine from a hunk of the Patch.

source

pub fn size( &self, include_context: bool, include_hunk_headers: bool, include_file_headers: bool, ) -> usize

Get the size of a Patch’s diff data in bytes.

source

pub fn print( &mut self, line_cb: &mut (dyn FnMut(DiffDelta<'_>, Option<DiffHunk<'_>>, DiffLine<'_>) -> bool + '_), ) -> Result<(), Error>

Print the Patch to text via a callback.

source

pub fn to_buf(&mut self) -> Result<Buf, Error>

Get the Patch text as a Buf.

Trait Implementations§

source§

impl<'buffers> Debug for Patch<'buffers>

source§

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

Formats the value using the given formatter. Read more
source§

impl<'buffers> Drop for Patch<'buffers>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<'buffers> Send for Patch<'buffers>

Auto Trait Implementations§

§

impl<'buffers> Freeze for Patch<'buffers>

§

impl<'buffers> RefUnwindSafe for Patch<'buffers>

§

impl<'buffers> !Sync for Patch<'buffers>

§

impl<'buffers> Unpin for Patch<'buffers>

§

impl<'buffers> UnwindSafe for Patch<'buffers>

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.