@@ -5,12 +5,14 @@ use gix_merge::blob::Platform;
55mod merge {
66 use crate :: blob:: platform:: new_platform;
77 use crate :: blob:: util:: ObjectDb ;
8+ use crate :: hex_to_id;
89 use bstr:: { BStr , ByteSlice } ;
910 use gix_merge:: blob:: builtin_driver:: text:: ConflictStyle ;
1011 use gix_merge:: blob:: platform:: builtin_merge:: Pick ;
1112 use gix_merge:: blob:: platform:: DriverChoice ;
1213 use gix_merge:: blob:: { builtin_driver, pipeline, platform, BuiltinDriver , Resolution , ResourceKind } ;
1314 use gix_object:: tree:: EntryKind ;
15+ use std:: convert:: Infallible ;
1416 use std:: process:: Stdio ;
1517
1618 #[ test]
@@ -66,8 +68,9 @@ mod merge {
6668 #[ test]
6769 fn builtin_with_conflict ( ) -> crate :: Result {
6870 let mut platform = new_platform ( None , pipeline:: Mode :: ToGit ) ;
71+ let non_existing_ancestor_id = hex_to_id ( "ffffffffffffffffffffffffffffffffffffffff" ) ;
6972 platform. set_resource (
70- gix_hash :: Kind :: Sha1 . null ( ) ,
73+ non_existing_ancestor_id ,
7174 EntryKind :: Blob ,
7275 "b" . into ( ) ,
7376 ResourceKind :: CommonAncestorOrBase ,
@@ -152,20 +155,56 @@ theirs
152155 ) ;
153156 assert ! ( buf. is_empty( ) , "it tells us where to get the content from" ) ;
154157 assert_eq ! (
155- platform_ref. buffer_by_pick( res. 0 ) . unwrap( ) . as_bstr( ) ,
158+ platform_ref. buffer_by_pick( res. 0 ) . unwrap( ) . unwrap ( ) . as_bstr( ) ,
156159 "ours" ,
157160 "getting access to the content is simplified"
158161 ) ;
162+ assert_eq ! (
163+ platform_ref
164+ . id_by_pick( res. 0 , & buf, |_buf| -> Result <_, Infallible > {
165+ panic!( "no need to write buffer" )
166+ } )
167+ . unwrap( )
168+ . unwrap( ) ,
169+ hex_to_id( "424860eef4edb9f5a2dacbbd6dc8c2d2e7645035" ) ,
170+ "there is no need to write a buffer here, it just returns one of our inputs"
171+ ) ;
159172
160- for ( expected, expected_pick, resolve) in [
161- ( "ours" , Pick :: Ours , builtin_driver:: binary:: ResolveWith :: Ours ) ,
162- ( "theirs" , Pick :: Theirs , builtin_driver:: binary:: ResolveWith :: Theirs ) ,
163- ( "b\n " , Pick :: Ancestor , builtin_driver:: binary:: ResolveWith :: Ancestor ) ,
173+ for ( expected, expected_pick, resolve, expected_id) in [
174+ (
175+ "ours" ,
176+ Pick :: Ours ,
177+ builtin_driver:: binary:: ResolveWith :: Ours ,
178+ hex_to_id ( "424860eef4edb9f5a2dacbbd6dc8c2d2e7645035" ) ,
179+ ) ,
180+ (
181+ "theirs" ,
182+ Pick :: Theirs ,
183+ builtin_driver:: binary:: ResolveWith :: Theirs ,
184+ hex_to_id ( "228068dbe790983c15535164cd483eb77ade97e4" ) ,
185+ ) ,
186+ (
187+ "b\n " ,
188+ Pick :: Ancestor ,
189+ builtin_driver:: binary:: ResolveWith :: Ancestor ,
190+ non_existing_ancestor_id,
191+ ) ,
164192 ] {
165193 platform_ref. options . resolve_binary_with = Some ( resolve) ;
166194 let res = platform_ref. merge ( & mut buf, default_labels ( ) , & Default :: default ( ) ) ?;
167195 assert_eq ! ( res, ( expected_pick, Resolution :: Complete ) ) ;
168- assert_eq ! ( platform_ref. buffer_by_pick( res. 0 ) . unwrap( ) . as_bstr( ) , expected) ;
196+ assert_eq ! ( platform_ref. buffer_by_pick( res. 0 ) . unwrap( ) . unwrap( ) . as_bstr( ) , expected) ;
197+
198+ assert_eq ! (
199+ platform_ref
200+ . id_by_pick( res. 0 , & buf, |_buf| -> Result <_, Infallible > {
201+ panic!( "no need to write buffer" )
202+ } )
203+ . unwrap( )
204+ . unwrap( ) ,
205+ expected_id,
206+ "{expected}: each input has an id, so it's just returned as is without handling buffers"
207+ ) ;
169208 }
170209
171210 Ok ( ( ) )
@@ -234,6 +273,18 @@ theirs
234273 ( Pick :: Buffer , Resolution :: Complete ) ,
235274 "merge drivers deal with binary themselves"
236275 ) ;
276+ assert_eq ! (
277+ platform_ref. buffer_by_pick( res. 0 ) ,
278+ Ok ( None ) ,
279+ "This indicates the buffer must be read"
280+ ) ;
281+
282+ let marker = hex_to_id ( "ffffffffffffffffffffffffffffffffffffffff" ) ;
283+ assert_eq ! (
284+ platform_ref. id_by_pick( res. 0 , & buf, |_buf| Ok :: <_, Infallible >( marker) ) ,
285+ Ok ( Some ( marker) ) ,
286+ "the id is created by hashing the merge buffer"
287+ ) ;
237288 let mut lines = cleaned_driver_lines ( & buf) ?;
238289 for tmp_file in lines. by_ref ( ) . take ( 3 ) {
239290 assert ! ( tmp_file. contains_str( & b".tmp" [ ..] ) , "{tmp_file}" ) ;
0 commit comments