Skip to content

Commit 67fa50e

Browse files
committed
feat: when blob-merging, clarify if something would have conflicted.
1 parent cf0c7ee commit 67fa50e

File tree

4 files changed

+30
-19
lines changed

4 files changed

+30
-19
lines changed

gix-merge/src/blob/builtin_driver/text/function.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,17 @@ pub fn merge<'a>(
3131
current: &'a [u8],
3232
ancestor: &'a [u8],
3333
other: &'a [u8],
34-
opts: Options,
34+
Options {
35+
diff_algorithm,
36+
conflict,
37+
}: Options,
3538
) -> Resolution {
3639
out.clear();
3740
input.update_before(tokens(ancestor));
3841
input.update_after(tokens(current));
3942

4043
let hunks = imara_diff::diff(
41-
opts.diff_algorithm,
44+
diff_algorithm,
4245
input,
4346
CollectHunks {
4447
side: Side::Current,
@@ -50,7 +53,7 @@ pub fn merge<'a>(
5053
input.update_after(tokens(other));
5154

5255
let mut hunks = imara_diff::diff(
53-
opts.diff_algorithm,
56+
diff_algorithm,
5457
input,
5558
CollectHunks {
5659
side: Side::Other,
@@ -86,7 +89,7 @@ pub fn merge<'a>(
8689
fill_ancestor(&extended_range, &mut current_hunks);
8790
fill_ancestor(&extended_range, &mut intersecting);
8891
}
89-
match opts.conflict {
92+
match conflict {
9093
Conflict::Keep { style, marker_size } => {
9194
let marker_size = marker_size.get();
9295
let (hunks_front_and_back, num_hunks_front) = match style {
@@ -170,14 +173,15 @@ pub fn merge<'a>(
170173
ancestor_integrated_until = last_hunk.before.end;
171174
}
172175
Conflict::ResolveWithOurs | Conflict::ResolveWithTheirs => {
176+
resolution = Resolution::CompleteWithAutoResolvedConflict;
173177
let (our_hunks, their_hunks) = match filled_hunks_side {
174178
Side::Current => (&current_hunks, &intersecting),
175179
Side::Other => (&intersecting, &current_hunks),
176180
Side::Ancestor => {
177181
unreachable!("initial hunks are never ancestors")
178182
}
179183
};
180-
let hunks_to_write = if opts.conflict == Conflict::ResolveWithOurs {
184+
let hunks_to_write = if conflict == Conflict::ResolveWithOurs {
181185
our_hunks
182186
} else {
183187
their_hunks
@@ -191,6 +195,7 @@ pub fn merge<'a>(
191195
}
192196
}
193197
Conflict::ResolveWithUnion => {
198+
resolution = Resolution::CompleteWithAutoResolvedConflict;
194199
let (hunks_front_and_back, num_hunks_front) =
195200
zealously_contract_hunks(&mut current_hunks, &mut intersecting, input, &current_tokens);
196201

gix-merge/src/blob/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ pub mod platform;
1515
/// Define if a merge is conflicted or not.
1616
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
1717
pub enum Resolution {
18-
/// Everything could be resolved during the merge.
19-
///
20-
/// Conflicts may have been resolved automatically, depending on the options.
18+
/// Everything could be resolved during the merge, and there was no conflict.
2119
Complete,
20+
/// Conflicts were resolved automatically, even thought the result is complete
21+
/// and free of conflict markers.
22+
/// This can only be the case for text-file content merges.
23+
CompleteWithAutoResolvedConflict,
2224
/// A conflict is still present in the form of conflict markers.
23-
///
24-
/// Note that this won't be the case if conflicts were automatically resolved.
2525
Conflict,
2626
}
2727

gix-merge/tests/merge/blob/builtin_driver.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,17 @@ mod text {
160160
if is_case_diverging(&case, diverging) {
161161
num_diverging += 1;
162162
} else {
163-
let expected_resolution = if case.expected.contains_str("<<<<<<<") {
164-
Resolution::Conflict
163+
if case.expected.contains_str("<<<<<<<") {
164+
assert_eq!(actual, Resolution::Conflict, "{}: resolution mismatch", case.name,);
165165
} else {
166-
Resolution::Complete
166+
assert!(
167+
matches!(
168+
actual,
169+
Resolution::Complete | Resolution::CompleteWithAutoResolvedConflict
170+
),
171+
"{}: resolution mismatch",
172+
case.name
173+
);
167174
};
168175
assert_str_eq!(
169176
out.as_bstr().to_str_lossy(),
@@ -173,7 +180,6 @@ mod text {
173180
out.as_bstr()
174181
);
175182
assert_eq!(out.as_bstr(), case.expected);
176-
assert_eq!(actual, expected_resolution, "{}: resolution mismatch", case.name,);
177183
}
178184
}
179185

gix-merge/tests/merge/blob/platform.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,25 +125,25 @@ theirs
125125
let res = platform_ref.merge(&mut buf, default_labels(), &Default::default())?;
126126
assert_eq!(
127127
res,
128-
(Pick::Buffer, Resolution::Complete),
129-
"it's actually unclear now if there ever was a conflict, but we *could* compute it"
128+
(Pick::Buffer, Resolution::CompleteWithAutoResolvedConflict),
129+
"we can determine that there was a conflict, despite the resolution being complete"
130130
);
131131
assert_eq!(buf.as_bstr(), "ours");
132132

133133
platform_ref.options.text.conflict = builtin_driver::text::Conflict::ResolveWithTheirs;
134134
let res = platform_ref.merge(&mut buf, default_labels(), &Default::default())?;
135-
assert_eq!(res, (Pick::Buffer, Resolution::Complete));
135+
assert_eq!(res, (Pick::Buffer, Resolution::CompleteWithAutoResolvedConflict));
136136
assert_eq!(buf.as_bstr(), "theirs");
137137

138138
platform_ref.options.text.conflict = builtin_driver::text::Conflict::ResolveWithUnion;
139139
let res = platform_ref.merge(&mut buf, default_labels(), &Default::default())?;
140-
assert_eq!(res, (Pick::Buffer, Resolution::Complete));
140+
assert_eq!(res, (Pick::Buffer, Resolution::CompleteWithAutoResolvedConflict));
141141
assert_eq!(buf.as_bstr(), "ours\ntheirs");
142142

143143
platform_ref.driver = DriverChoice::BuiltIn(BuiltinDriver::Union);
144144
platform_ref.options.text.conflict = builtin_driver::text::Conflict::default();
145145
let res = platform_ref.merge(&mut buf, default_labels(), &Default::default())?;
146-
assert_eq!(res, (Pick::Buffer, Resolution::Complete));
146+
assert_eq!(res, (Pick::Buffer, Resolution::CompleteWithAutoResolvedConflict));
147147
assert_eq!(buf.as_bstr(), "ours\ntheirs");
148148

149149
platform_ref.driver = DriverChoice::BuiltIn(BuiltinDriver::Binary);

0 commit comments

Comments
 (0)