Skip to content

Commit 14cc99a

Browse files
committed
add platform tests and implementation
That way, the platform can be used to perform actual merges. This will also be a good chance to try the API.
1 parent a6f3e30 commit 14cc99a

File tree

13 files changed

+986
-1077
lines changed

13 files changed

+986
-1077
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ use crate::blob::builtin_driver::text::utils::{
33
hunks_differ_in_diff3, take_intersecting, tokens, write_ancestor, write_conflict_marker, write_hunks,
44
zealously_contract_hunks, CollectHunks, Hunk, Side,
55
};
6-
use crate::blob::builtin_driver::text::{ConflictStyle, Options, ResolveWith};
6+
use crate::blob::builtin_driver::text::{ConflictStyle, Labels, Options, ResolveWith};
77
use crate::blob::Resolution;
8-
use bstr::BStr;
98

109
/// Merge `current` and `other` with `ancestor` as base according to `opts`.
1110
///
12-
/// Use `current_label`, `other_label` and `ancestor_label` to annotate conflict sections.
11+
/// Use `labels` to annotate conflict sections.
1312
///
1413
/// `input` is for reusing memory for lists of tokens, but note that it grows indefinitely
1514
/// while tokens for `current`, `ancestor` and `other` are added.
@@ -23,12 +22,14 @@ use bstr::BStr;
2322
pub fn merge<'a>(
2423
out: &mut Vec<u8>,
2524
input: &mut imara_diff::intern::InternedInput<&'a [u8]>,
25+
Labels {
26+
ancestor: ancestor_label,
27+
current: current_label,
28+
other: other_label,
29+
}: Labels<'_>,
2630
current: &'a [u8],
27-
current_label: Option<&BStr>,
2831
ancestor: &'a [u8],
29-
ancestor_label: Option<&BStr>,
3032
other: &'a [u8],
31-
other_label: Option<&BStr>,
3233
opts: Options,
3334
) -> Resolution {
3435
out.clear();

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use bstr::BStr;
2+
13
/// The way the built-in [text driver](crate::blob::BuiltinDriver::Text) will express
24
/// merge conflicts in the resulting file.
35
#[derive(Default, Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
@@ -48,6 +50,16 @@ pub enum ConflictStyle {
4850
ZealousDiff3,
4951
}
5052

53+
/// The set of labels to annotate conflict markers with.
54+
///
55+
/// That way it becomes clearer where the content of conflicts are originating from.
56+
#[derive(Default, Copy, Clone, Debug, Eq, PartialEq)]
57+
pub struct Labels<'a> {
58+
pub ancestor: Option<&'a BStr>,
59+
pub current: Option<&'a BStr>,
60+
pub other: Option<&'a BStr>,
61+
}
62+
5163
/// Options for the builtin [text driver](crate::blob::BuiltinDriver::Text).
5264
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
5365
pub struct Options {

gix-merge/src/blob/mod.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// TODO: remove this - only needed while &mut Vec<u8> isn't used.
22
#![allow(clippy::ptr_arg)]
33

4+
use crate::blob::platform::{DriverChoice, ResourceRef};
45
use bstr::BString;
56
use std::path::PathBuf;
67

@@ -157,3 +158,24 @@ pub struct Platform {
157158
/// The way we convert resources into mergeable states.
158159
filter_mode: pipeline::Mode,
159160
}
161+
162+
/// The product of a [`prepare_merge()`](Platform::prepare_merge()) call to finally
163+
/// perform the merge and retrieve the merge results.
164+
#[derive(Copy, Clone)]
165+
pub struct PlatformRef<'parent> {
166+
/// The platform that hosts the resources, used to access drivers.
167+
pub(super) parent: &'parent Platform,
168+
/// The current or our side of the merge operation.
169+
pub current: ResourceRef<'parent>,
170+
/// The ancestor or base of the merge operation.
171+
pub ancestor: ResourceRef<'parent>,
172+
/// The other or their side of the merge operation.
173+
pub other: ResourceRef<'parent>,
174+
/// Which driver to use according to the resource's configuration,
175+
/// using the path of `current` to read git-attributes.
176+
pub driver: DriverChoice,
177+
/// Possibly processed options for use when performing the actual merge.
178+
///
179+
/// They may be inspected before the merge, or altered at will.
180+
pub options: platform::merge::Options,
181+
}

0 commit comments

Comments
 (0)