use std::path::PathBuf;
use super::super::path_ops::PathOperation;
#[derive(Debug, Clone)]
pub struct Conflict {
pub path: PathBuf,
pub base: PathOperation,
pub incoming: PathOperation,
}
impl Conflict {
pub fn new(path: PathBuf, base: PathOperation, incoming: PathOperation) -> Self {
Self {
path,
base,
incoming,
}
}
pub fn is_concurrent(&self) -> bool {
self.base.id.timestamp == self.incoming.id.timestamp
}
pub fn crdt_winner(&self) -> &PathOperation {
if self.incoming.id > self.base.id {
&self.incoming
} else {
&self.base
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Resolution {
UseBase,
UseIncoming,
KeepBoth,
SkipBoth,
RenameIncoming {
new_path: PathBuf,
},
}
#[derive(Debug, Clone)]
pub struct MergeResult {
pub operations_added: usize,
pub conflicts_resolved: Vec<ResolvedConflict>,
pub unresolved_conflicts: Vec<Conflict>,
}
impl MergeResult {
pub fn new() -> Self {
Self {
operations_added: 0,
conflicts_resolved: Vec::new(),
unresolved_conflicts: Vec::new(),
}
}
pub fn has_unresolved(&self) -> bool {
!self.unresolved_conflicts.is_empty()
}
pub fn total_conflicts(&self) -> usize {
self.conflicts_resolved.len() + self.unresolved_conflicts.len()
}
}
impl Default for MergeResult {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone)]
pub struct ResolvedConflict {
pub conflict: Conflict,
pub resolution: Resolution,
}