gix_merge/blob/builtin_driver/
binary.rs

1/// What to do when having to pick a side to resolve a conflict.
2#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
3pub enum ResolveWith {
4    /// Chose the ancestor to resolve a conflict.
5    Ancestor,
6    /// Chose our side to resolve a conflict.
7    Ours,
8    /// Chose their side to resolve a conflict.
9    Theirs,
10}
11
12/// Tell the caller of [`merge()`](function::merge) which side was picked.
13#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
14pub enum Pick {
15    /// Chose the ancestor.
16    Ancestor,
17    /// Chose our side.
18    Ours,
19    /// Chose their side.
20    Theirs,
21}
22
23pub(super) mod function {
24    use crate::blob::builtin_driver::binary::{Pick, ResolveWith};
25    use crate::blob::Resolution;
26
27    /// As this algorithm doesn't look at the actual data, it returns a choice solely based on logic.
28    /// This also means that the caller has to assure this only gets called if the input *doesn't* match.
29    ///
30    /// It always results in a conflict with `current` being picked unless `on_conflict` is not `None`,
31    /// which is when we always return [`Resolution::CompleteWithAutoResolvedConflict`].
32    pub fn merge(on_conflict: Option<ResolveWith>) -> (Pick, Resolution) {
33        match on_conflict {
34            None => (Pick::Ours, Resolution::Conflict),
35            Some(resolve) => (
36                match resolve {
37                    ResolveWith::Ours => Pick::Ours,
38                    ResolveWith::Theirs => Pick::Theirs,
39                    ResolveWith::Ancestor => Pick::Ancestor,
40                },
41                Resolution::CompleteWithAutoResolvedConflict,
42            ),
43        }
44    }
45}