@@ -29,7 +29,7 @@ pub enum Error {
2929/// The outcome produced by [`tree()`](crate::tree()).
3030#[ derive( Clone ) ]
3131pub struct Outcome < ' a > {
32- /// The ready-made (but unwritten) which is the *base* tree, including all non-conflicting changes, and the changes that had
32+ /// The ready-made (but unwritten) *base* tree, including all non-conflicting changes, and the changes that had
3333 /// conflicts which could be resolved automatically.
3434 ///
3535 /// This means, if all of their changes were conflicting, this will be equivalent to the *base* tree.
@@ -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
@@ -70,7 +70,7 @@ impl Outcome<'_> {
7070#[ derive( Debug , Clone ) ]
7171pub struct Conflict {
7272 /// A record on how the conflict resolution succeeded with `Ok(_)` or failed with `Err(_)`.
73- /// In case of `Err(_)`, no write
73+ /// Note that in case of `Err(_)`, edits may still have been made to the tree to aid resolution.
7474 /// On failure, one can examine `ours` and `theirs` to potentially find a custom solution.
7575 /// Note that the descriptions of resolutions or resolution failures may be swapped compared
7676 /// to the actual changes. This is due to changes like `modification|deletion` being treated the
@@ -81,13 +81,17 @@ pub struct Conflict {
8181 pub ours : Change ,
8282 /// The change representing *their* side.
8383 pub theirs : Change ,
84+ /// Determine how to interpret the `ours` and `theirs` fields. This is used to implement [`Self::changes_in_resolution()`]
85+ /// and [`Self::into_parts_by_resolution()`].
8486 map : ConflictMapping ,
8587}
8688
87- /// A utility to help define which side is what.
89+ /// A utility to help define which side is what in the [`Conflict`] type .
8890#[ derive( Debug , Clone , Copy ) ]
8991enum ConflictMapping {
92+ /// The sides are as described in the field documentation, i.e. `ours` is `ours`.
9093 Original ,
94+ /// The sides are the opposite of the field documentation. i.e. `ours` is `theirs` and `theirs` is `ours`.
9195 Swapped ,
9296}
9397
@@ -104,6 +108,28 @@ impl ConflictMapping {
104108}
105109
106110impl 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+
107133 /// Returns the changes of fields `ours` and `theirs` so they match their description in the
108134 /// [`Resolution`] or [`ResolutionFailure`] respectively.
109135 /// Without this, the sides may appear swapped as `ours|theirs` is treated the same as `theirs/ours`
@@ -236,11 +262,8 @@ pub struct Options {
236262 /// The context to use when invoking merge-drivers.
237263 pub blob_merge_command_ctx : gix_command:: Context ,
238264 /// If `Some(what-is-unresolved)`, the first unresolved conflict will cause the entire merge to stop.
239- /// This is useful to see if there is any conflict, without performing the whole operation.
240- // TODO: Maybe remove this if the cost of figuring out conflicts is so low - after all, the data structures
241- // and initial diff is the expensive thing right now, which are always done upfront.
242- // However, this could change once we know do everything during the traversal, which probably doesn't work
243- // without caching stuff and is too complicated to actually do.
265+ /// This is useful to see if there is any conflict, without performing the whole operation, something
266+ /// that can be very relevant during merges that would cause a lot of blob-diffs.
244267 pub fail_on_conflict : Option < UnresolvedConflict > ,
245268 /// This value also affects the size of merge-conflict markers, to allow differentiating
246269 /// merge conflicts on each level, for any value greater than 0, with values `N` causing `N*2`
0 commit comments