@@ -19,6 +19,10 @@ impl Merge {
19
19
/// The `merge.<driver>.recursive` key.
20
20
pub const DRIVER_RECURSIVE : keys:: String = keys:: String :: new_string ( "recursive" , & config:: Tree :: MERGE )
21
21
. with_subsection_requirement ( Some ( SubSectionRequirement :: Parameter ( "driver" ) ) ) ;
22
+ /// The `merge.conflictStyle` key.
23
+ #[ cfg( feature = "blob-merge" ) ]
24
+ pub const CONFLICT_STYLE : ConflictStyle =
25
+ ConflictStyle :: new_with_validate ( "conflictStyle" , & config:: Tree :: MERGE , validate:: ConflictStyle ) ;
22
26
}
23
27
24
28
impl Section for Merge {
@@ -36,3 +40,49 @@ impl Section for Merge {
36
40
]
37
41
}
38
42
}
43
+
44
+ /// The `merge.conflictStyle` key.
45
+ #[ cfg( feature = "blob-merge" ) ]
46
+ pub type ConflictStyle = keys:: Any < validate:: ConflictStyle > ;
47
+
48
+ #[ cfg( feature = "blob-merge" ) ]
49
+ mod conflict_style {
50
+ use crate :: { bstr:: BStr , config, config:: tree:: sections:: merge:: ConflictStyle } ;
51
+ use gix_merge:: blob:: builtin_driver:: text;
52
+ use std:: borrow:: Cow ;
53
+
54
+ impl ConflictStyle {
55
+ /// Derive the diff algorithm identified by `name`, case-insensitively.
56
+ pub fn try_into_conflict_style (
57
+ & ' static self ,
58
+ name : Cow < ' _ , BStr > ,
59
+ ) -> Result < text:: ConflictStyle , config:: key:: GenericErrorWithValue > {
60
+ let style = if name. as_ref ( ) == "merge" {
61
+ text:: ConflictStyle :: Merge
62
+ } else if name. as_ref ( ) == "diff3" {
63
+ text:: ConflictStyle :: Diff3
64
+ } else if name. as_ref ( ) == "zdiff3" {
65
+ text:: ConflictStyle :: ZealousDiff3
66
+ } else {
67
+ return Err ( config:: key:: GenericErrorWithValue :: from_value ( self , name. into_owned ( ) ) ) ;
68
+ } ;
69
+ Ok ( style)
70
+ }
71
+ }
72
+ }
73
+
74
+ #[ cfg( feature = "blob-merge" ) ]
75
+ mod validate {
76
+ use crate :: {
77
+ bstr:: BStr ,
78
+ config:: tree:: { keys, Merge } ,
79
+ } ;
80
+
81
+ pub struct ConflictStyle ;
82
+ impl keys:: Validate for ConflictStyle {
83
+ fn validate ( & self , value : & BStr ) -> Result < ( ) , Box < dyn std:: error:: Error + Send + Sync + ' static > > {
84
+ Merge :: CONFLICT_STYLE . try_into_conflict_style ( value. into ( ) ) ?;
85
+ Ok ( ( ) )
86
+ }
87
+ }
88
+ }
0 commit comments