Skip to content

Commit 9e106c4

Browse files
committed
feat: add Conflict::is_unresolved() as utility to see if multiple of them are considered unresolved.
1 parent 5b428a9 commit 9e106c4

File tree

2 files changed

+25
-26
lines changed

2 files changed

+25
-26
lines changed

gix-merge/src/tree/function.rs

+2-25
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ use crate::tree::utils::{
33
to_components, track, unique_path_in_tree, ChangeList, ChangeListRef, PossibleConflict, TrackedChange, TreeNodes,
44
};
55
use crate::tree::ConflictMapping::{Original, Swapped};
6-
use crate::tree::{
7-
Conflict, ConflictMapping, ContentMerge, Error, Options, Outcome, Resolution, ResolutionFailure, UnresolvedConflict,
8-
};
6+
use crate::tree::{Conflict, ConflictMapping, ContentMerge, Error, Options, Outcome, Resolution, ResolutionFailure};
97
use bstr::{BString, ByteSlice};
108
use gix_diff::tree::recorder::Location;
119
use gix_diff::tree_with_rewrites::Change;
@@ -129,7 +127,7 @@ where
129127
let mut failed_on_first_conflict = false;
130128
let mut should_fail_on_conflict = |conflict: Conflict| -> bool {
131129
if let Some(how) = options.fail_on_conflict {
132-
if conflict.resolution.is_err() || is_unresolved(std::slice::from_ref(&conflict), how) {
130+
if conflict.resolution.is_err() || conflict.is_unresolved(how) {
133131
failed_on_first_conflict = true;
134132
}
135133
}
@@ -1002,27 +1000,6 @@ where
10021000
})
10031001
}
10041002

1005-
pub(super) fn is_unresolved(conflicts: &[Conflict], how: UnresolvedConflict) -> bool {
1006-
match how {
1007-
UnresolvedConflict::ConflictMarkers => conflicts.iter().any(|c| {
1008-
c.resolution.is_err()
1009-
|| c.content_merge().map_or(false, |info| {
1010-
matches!(info.resolution, crate::blob::Resolution::Conflict)
1011-
})
1012-
}),
1013-
UnresolvedConflict::Renames => conflicts.iter().any(|c| match &c.resolution {
1014-
Ok(success) => match success {
1015-
Resolution::SourceLocationAffectedByRename { .. }
1016-
| Resolution::OursModifiedTheirsRenamedAndChangedThenRename { .. } => true,
1017-
Resolution::OursModifiedTheirsModifiedThenBlobContentMerge { merged_blob } => {
1018-
matches!(merged_blob.resolution, crate::blob::Resolution::Conflict)
1019-
}
1020-
},
1021-
Err(_failure) => true,
1022-
}),
1023-
}
1024-
}
1025-
10261003
fn involves_submodule(a: &EntryMode, b: &EntryMode) -> bool {
10271004
a.is_commit() || b.is_commit()
10281005
}

gix-merge/src/tree/mod.rs

+23-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl Outcome<'_> {
6161
/// Return `true` if there is any conflict that would still need to be resolved as they would yield undesirable trees.
6262
/// This is based on `how` to determine what should be considered unresolved.
6363
pub fn has_unresolved_conflicts(&self, how: UnresolvedConflict) -> bool {
64-
function::is_unresolved(&self.conflicts, how)
64+
self.conflicts.iter().any(|c| c.is_unresolved(how))
6565
}
6666
}
6767

@@ -108,6 +108,28 @@ impl ConflictMapping {
108108
}
109109

110110
impl Conflict {
111+
/// Return `true` if this instance is considered unresolved based on the criterion specified by `how`.
112+
pub fn is_unresolved(&self, how: UnresolvedConflict) -> bool {
113+
match how {
114+
UnresolvedConflict::ConflictMarkers => {
115+
self.resolution.is_err()
116+
|| self.content_merge().map_or(false, |info| {
117+
matches!(info.resolution, crate::blob::Resolution::Conflict)
118+
})
119+
}
120+
UnresolvedConflict::Renames => match &self.resolution {
121+
Ok(success) => match success {
122+
Resolution::SourceLocationAffectedByRename { .. }
123+
| Resolution::OursModifiedTheirsRenamedAndChangedThenRename { .. } => true,
124+
Resolution::OursModifiedTheirsModifiedThenBlobContentMerge { merged_blob } => {
125+
matches!(merged_blob.resolution, crate::blob::Resolution::Conflict)
126+
}
127+
},
128+
Err(_failure) => true,
129+
},
130+
}
131+
}
132+
111133
/// Returns the changes of fields `ours` and `theirs` so they match their description in the
112134
/// [`Resolution`] or [`ResolutionFailure`] respectively.
113135
/// Without this, the sides may appear swapped as `ours|theirs` is treated the same as `theirs/ours`

0 commit comments

Comments
 (0)