Skip to main content

FilePatch

Struct FilePatch 

Source
pub struct FilePatch {
Show 23 fields pub diff_old_path: Option<String>, pub diff_new_path: Option<String>, pub old_path: Option<String>, pub new_path: Option<String>, pub saw_old_header: bool, pub saw_new_header: bool, pub old_mode: Option<String>, pub new_mode: Option<String>, pub old_mode_line: Option<usize>, pub new_mode_line: Option<usize>, pub is_new: bool, pub is_deleted: bool, pub is_rename: bool, pub is_copy: bool, pub similarity_index: Option<u32>, pub dissimilarity_index: Option<u32>, pub old_oid: Option<String>, pub new_oid: Option<String>, pub binary_patch: Option<BinaryPatchPayload>, pub is_binary: bool, pub hunks: Vec<Hunk>, pub ws_rule: u32, pub is_toplevel_relative: bool,
}
Expand description

Represents one file in a unified diff.

Fields§

§diff_old_path: Option<String>

Path from diff --git old side (a/...) when present.

§diff_new_path: Option<String>

Path from diff --git new side (b/...) when present.

§old_path: Option<String>

Path on the old side (None for new files).

§new_path: Option<String>

Path on the new side (None for deleted files).

§saw_old_header: bool

Whether an explicit --- header line was present.

§saw_new_header: bool

Whether an explicit +++ header line was present.

§old_mode: Option<String>

Old mode from extended header.

§new_mode: Option<String>

New mode from extended header.

§old_mode_line: Option<usize>

Source line (1-based) of old mode / deleted file mode for diagnostics.

§new_mode_line: Option<usize>

Source line (1-based) of new mode / new file mode for diagnostics.

§is_new: bool

Whether this file is being newly created.

§is_deleted: bool

Whether this file is being deleted.

§is_rename: bool

Whether this is a rename.

§is_copy: bool

Whether this is a copy.

§similarity_index: Option<u32>

Similarity index (e.g., 90 for 90%).

§dissimilarity_index: Option<u32>

Dissimilarity index for rewrites.

§old_oid: Option<String>

Old blob OID from the index header (abbreviated).

§new_oid: Option<String>

New blob OID from the index header (abbreviated).

§binary_patch: Option<BinaryPatchPayload>

Parsed binary patch payload (GIT binary patch) if present.

§is_binary: bool

Whether this is a binary change (GIT binary patch payload or a Binary files ... differ marker); stat/numstat show Bin / -.

§hunks: Vec<Hunk>

Hunks to apply.

§ws_rule: u32

Merged core.whitespace + whitespace attribute (Git ws_rule); 0 before assignment.

§is_toplevel_relative: bool

Git patch->is_toplevel_relative: set for diff --git patches only. When false, paths are prefixed with the setup directory (work-tree-relative CWD) like prefix_patch in Git.

Implementations§

Source§

impl FilePatch

Source

pub fn effective_path(&self) -> Option<&str>

Effective path for the file. For deletions, use old_path (new is /dev/null). For additions, use new_path (old is /dev/null). Otherwise prefer new_path.

Source

pub fn source_path(&self) -> Option<&str>

Source path to read preimage content from.

For rename/copy patches this is the old path, otherwise this is the effective path.

Source

pub fn target_path(&self) -> Option<&str>

Destination path to write postimage content to.

For additions/renames/copies this is the new path, otherwise this is the effective path.

True when this patch touches a gitlink/submodule (mode 160000).

Source

pub fn worktree_rel_operational( &self, adjusted: &str, setup_prefix: &str, ) -> String

Work-tree-relative path for filesystem IO and .gitattributes (Git prefix_patch).

Trait Implementations§

Source§

impl Clone for FilePatch

Source§

fn clone(&self) -> FilePatch

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 Debug for FilePatch

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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 = 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>,

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.