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::{
25 builtin_driver::binary::{Pick, ResolveWith},
26 Resolution,
27 };
28
29 /// As this algorithm doesn't look at the actual data, it returns a choice solely based on logic.
30 /// This also means that the caller has to assure this only gets called if the input *doesn't* match.
31 ///
32 /// It always results in a conflict with `current` being picked unless `on_conflict` is not `None`,
33 /// which is when we always return [`Resolution::CompleteWithAutoResolvedConflict`].
34 pub fn merge(on_conflict: Option<ResolveWith>) -> (Pick, Resolution) {
35 match on_conflict {
36 None => (Pick::Ours, Resolution::Conflict),
37 Some(resolve) => (
38 match resolve {
39 ResolveWith::Ours => Pick::Ours,
40 ResolveWith::Theirs => Pick::Theirs,
41 ResolveWith::Ancestor => Pick::Ancestor,
42 },
43 Resolution::CompleteWithAutoResolvedConflict,
44 ),
45 }
46 }
47}