use crate::content_diff::{BinaryMode, DiffError, DiffLimits};
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
#[non_exhaustive]
pub enum Favor {
#[default]
Conflict,
Ours,
Theirs,
Union,
}
#[derive(Clone, Copy, Debug, Default)]
#[non_exhaustive]
pub struct ContentOptions {
pub binary: BinaryMode,
pub favor: Favor,
pub whitespace: super::Whitespace,
pub limits: DiffLimits,
}
impl ContentOptions {
#[must_use]
pub fn with_binary(mut self, binary: BinaryMode) -> Self {
self.binary = binary;
self
}
#[must_use]
pub fn with_favor(mut self, favor: Favor) -> Self {
self.favor = favor;
self
}
#[must_use]
pub fn with_whitespace(mut self, whitespace: super::Whitespace) -> Self {
self.whitespace = whitespace;
self
}
#[must_use]
pub fn with_limits(mut self, limits: DiffLimits) -> Self {
self.limits = limits;
self
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum ContentHunk {
Resolved(Vec<u8>),
Conflict {
base: Vec<u8>,
ours: Vec<u8>,
theirs: Vec<u8>,
},
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ContentMerge {
pub(crate) hunks: Vec<ContentHunk>,
pub(crate) binary: bool,
}
impl ContentMerge {
pub fn hunks(&self) -> &[ContentHunk] {
&self.hunks
}
pub fn is_clean(&self) -> bool {
self.hunks
.iter()
.all(|h| matches!(h, ContentHunk::Resolved(_)))
}
pub fn is_binary(&self) -> bool {
self.binary
}
}
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
#[non_exhaustive]
pub enum ConflictStyle {
#[default]
Merge,
Diff3,
Zdiff3,
}
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct MarkerOptions {
pub style: ConflictStyle,
pub width: std::num::NonZeroUsize,
pub ours: Vec<u8>,
pub base: Vec<u8>,
pub theirs: Vec<u8>,
}
impl Default for MarkerOptions {
fn default() -> Self {
Self {
style: ConflictStyle::Merge,
width: std::num::NonZeroUsize::new(7).unwrap(),
ours: b"ours".to_vec(),
base: b"base".to_vec(),
theirs: b"theirs".to_vec(),
}
}
}
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
#[error("comparing merge inputs")]
Diff(#[from] DiffError),
}