pub struct FileDiff {
pub old_path: Option<RepoPath>,
pub path: RepoPath,
pub status: FileStatus,
pub staged: StageState,
pub hunks: Vec<Hunk>,
pub binary: bool,
pub mode: Option<ModeChange>,
pub no_newline_at_end: bool,
pub omitted_bytes: Option<u64>,
pub old_source: SourceResult,
pub new_source: SourceResult,
}Expand description
One changed file.
old_source and new_source hold the complete versions of each side.
When both are available the hunks are derived from them, so equal sides
imply equal hunks; otherwise the hunks are the patch as supplied.
Fields§
§old_path: Option<RepoPath>§path: RepoPath§status: FileStatus§staged: StageState§hunks: Vec<Hunk>§binary: bool§mode: Option<ModeChange>§no_newline_at_end: bool§omitted_bytes: Option<u64>§old_source: SourceResult§new_source: SourceResultImplementations§
Source§impl FileDiff
impl FileDiff
Sourcepub fn path_for_side(&self, side: DiffSide) -> &RepoPath
pub fn path_for_side(&self, side: DiffSide) -> &RepoPath
Returns the repository path used by one side of this file version.
Sourcepub fn from_texts<T>(path: T, old: &str, new: &str) -> Result<Self, DiffError>
pub fn from_texts<T>(path: T, old: &str, new: &str) -> Result<Self, DiffError>
Builds a one-file diff from complete old and new text snapshots.
§Errors
Returns an error when path is not a valid repository-relative path.
Sourcepub fn with_sources(self, old: SourceResult, new: SourceResult) -> Self
pub fn with_sources(self, old: SourceResult, new: SourceResult) -> Self
Attaches captured source versions, re-deriving the hunks from them when both sides are known. Git metadata such as status, staging, mode, and paths is kept as supplied; a binary file keeps its patch untouched.
Sourcepub const fn uncaptured_source(
status: FileStatus,
side: DiffSide,
) -> SourceResult
pub const fn uncaptured_source( status: FileStatus, side: DiffSide, ) -> SourceResult
The source result recorded for a side of a file whose complete versions were not captured.
§Errors
Always an unavailable reason: SourceUnavailable::Absent where the
status says the side cannot exist, SourceUnavailable::NotCaptured
otherwise.
Sourcepub const fn source(&self, side: DiffSide) -> &SourceResult
pub const fn source(&self, side: DiffSide) -> &SourceResult
Returns the complete source result for one side.
Sourcepub fn source_document(&self, side: DiffSide) -> Option<&Arc<SourceDocument>>
pub fn source_document(&self, side: DiffSide) -> Option<&Arc<SourceDocument>>
Returns the complete source document for one side when it is available.
Returns why one side has no complete source document.
Sourcepub fn content_id(&self) -> Fingerprint
pub fn content_id(&self) -> Fingerprint
Content identity used to decide whether presentation state derived from this file, such as revealed gaps, still applies after a replacement.
The identity covers both sides. When either side is unavailable the hunks are the content and are covered too; when both are available the hunks are derived from them and add nothing.