@@ -29,7 +29,7 @@ pub enum Error {
29
29
/// The outcome produced by [`tree()`](crate::tree()).
30
30
#[ derive( Clone ) ]
31
31
pub 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
33
33
/// conflicts which could be resolved automatically.
34
34
///
35
35
/// This means, if all of their changes were conflicting, this will be equivalent to the *base* tree.
@@ -61,7 +61,7 @@ impl Outcome<'_> {
61
61
/// Return `true` if there is any conflict that would still need to be resolved as they would yield undesirable trees.
62
62
/// This is based on `how` to determine what should be considered unresolved.
63
63
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) )
65
65
}
66
66
}
67
67
@@ -70,7 +70,7 @@ impl Outcome<'_> {
70
70
#[ derive( Debug , Clone ) ]
71
71
pub struct Conflict {
72
72
/// 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.
74
74
/// On failure, one can examine `ours` and `theirs` to potentially find a custom solution.
75
75
/// Note that the descriptions of resolutions or resolution failures may be swapped compared
76
76
/// to the actual changes. This is due to changes like `modification|deletion` being treated the
@@ -81,13 +81,17 @@ pub struct Conflict {
81
81
pub ours : Change ,
82
82
/// The change representing *their* side.
83
83
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()`].
84
86
map : ConflictMapping ,
85
87
}
86
88
87
- /// A utility to help define which side is what.
89
+ /// A utility to help define which side is what in the [`Conflict`] type .
88
90
#[ derive( Debug , Clone , Copy ) ]
89
91
enum ConflictMapping {
92
+ /// The sides are as described in the field documentation, i.e. `ours` is `ours`.
90
93
Original ,
94
+ /// The sides are the opposite of the field documentation. i.e. `ours` is `theirs` and `theirs` is `ours`.
91
95
Swapped ,
92
96
}
93
97
@@ -104,6 +108,28 @@ impl ConflictMapping {
104
108
}
105
109
106
110
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
+
107
133
/// Returns the changes of fields `ours` and `theirs` so they match their description in the
108
134
/// [`Resolution`] or [`ResolutionFailure`] respectively.
109
135
/// Without this, the sides may appear swapped as `ours|theirs` is treated the same as `theirs/ours`
@@ -236,11 +262,8 @@ pub struct Options {
236
262
/// The context to use when invoking merge-drivers.
237
263
pub blob_merge_command_ctx : gix_command:: Context ,
238
264
/// 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.
244
267
pub fail_on_conflict : Option < UnresolvedConflict > ,
245
268
/// This value also affects the size of merge-conflict markers, to allow differentiating
246
269
/// merge conflicts on each level, for any value greater than 0, with values `N` causing `N*2`
0 commit comments