Skip to main content

FileMerge

Struct FileMerge 

Source
pub struct FileMerge {
    pub path: String,
    pub chunks: Vec<MergeChunk>,
    pub states: Vec<ChunkState>,
    pub cursor: usize,
    pub scroll: usize,
    pub ours_label: Option<String>,
    pub theirs_label: Option<String>,
    /* private fields */
}
Expand description

一个文本文件的合并会话:块列表 + 各块解决状态 + 光标。

Fields§

§path: String

文件路径(git 模式为仓库根相对;单文件模式为输入路径)

§chunks: Vec<MergeChunk>

合并块,首尾相接覆盖整个文件

§states: Vec<ChunkState>

与 chunks 一一对应的解决状态

§cursor: usize

光标所在块下标(始终指向非 Stable 块;无改动块时为 0)

§scroll: usize

视口滚动行偏移(由 UI 维护)

§ours_label: Option<String>

本地侧栏头标签(分支名)

§theirs_label: Option<String>

远端侧栏头标签(分支名)

Implementations§

Source§

impl FileMerge

Source

pub fn from_three_way( path: String, base: &str, ours: &str, theirs: &str, ) -> Self

由三份完整文本构建(git 三方模式)。

Source

pub fn from_result( path: String, result: MergeResult, ends_with_newline: bool, ) -> Self

由已计算好的合并结果构建(冲突文件解析模式)。

Source

pub fn chunk_resolved(&self, idx: usize) -> bool

某块是否已处理完毕(被覆写,或所有有效侧均非待处理)。

Source

pub fn pending_conflicts(&self) -> usize

未处理完的冲突块数量(写盘的先决条件是归零)。

Source

pub fn pending_changes(&self) -> usize

未处理完的改动块总数(含非冲突,状态条展示用)。

Source

pub fn ready_to_write(&self) -> bool

文件是否可写盘:所有冲突块已解决(非冲突块保持待处理 = 保留 base)。

Source

pub fn current_content(&self, idx: usize) -> Vec<String>

某块当前在结果中的内容:覆写 > 按取用顺序拼接 > base。

Source

pub fn resolved_content(&self) -> String

导出整个文件的最终内容(按块拼接 + 末尾换行策略)。

Source

pub fn apply(&mut self, side: Side)

取用某一侧:内容按点击顺序追加(冲突两侧先后取用 =「两者都要」); agree 块两侧内容一致,取任一侧即整块完成。

Source

pub fn ignore(&mut self, side: Side)

忽略某一侧(该侧改动不进入结果);agree 块忽略即整块保留 base。

Source

pub fn undo(&mut self)

撤销当前块的全部决定,回到待处理。

Source

pub fn undo_all(&mut self)

撤销本文件所有块的决定(含 $EDITOR 覆写),全部回到待处理。

Source

pub fn set_override(&mut self, lines: Vec<String>)

用 $EDITOR 编辑后的内容覆写当前块(视为已解决)。

Source

pub fn apply_all_nonconflict(&mut self)

一键取用所有非冲突改动(ours/theirs/agree)。

Source

pub fn next_change(&mut self)

移到下一个改动块(跳过 Stable)。

Source

pub fn prev_change(&mut self)

移到上一个改动块(跳过 Stable)。

Source

pub fn next_conflict(&mut self)

跳到下一个未解决的冲突块(到底后从头环绕)。

Source

pub fn prev_conflict(&mut self)

跳到上一个未解决的冲突块(到头后从尾环绕)。

Trait Implementations§

Source§

impl Debug for FileMerge

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. 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.