1- use gix_diff:: blob:: intern:: TokenSource ;
2- use gix_diff:: blob:: unified_diff:: ContextSize ;
3- use gix_diff:: blob:: { Algorithm , UnifiedDiff } ;
1+ use gix_diff:: blob:: v2:: { Algorithm , BasicLineDiffPrinter , Diff , InternedInput , UnifiedDiffConfig } ;
2+ use gix_object:: bstr:: ByteSlice ;
43use gix_testtools:: bstr:: { BString , ByteVec } ;
54use pretty_assertions:: StrComparison ;
65
@@ -39,37 +38,23 @@ fn baseline() -> gix_testtools::Result {
3938 let old_data = std:: fs:: read ( asset_dir. join ( format ! ( "{old_blob_id}.blob" ) ) ) ?;
4039 let new_data = std:: fs:: read ( asset_dir. join ( format ! ( "{new_blob_id}.blob" ) ) ) ?;
4140
42- let interner = gix_diff:: blob:: intern:: InternedInput :: new (
43- tokens_for_diffing ( old_data. as_slice ( ) ) ,
44- tokens_for_diffing ( new_data. as_slice ( ) ) ,
45- ) ;
46-
47- let actual = gix_diff:: blob:: diff (
48- algorithm,
49- & interner,
50- UnifiedDiff :: new (
51- & interner,
52- baseline:: DiffHunkRecorder :: new ( ) ,
53- ContextSize :: symmetrical ( 3 ) ,
54- ) ,
55- ) ?;
41+ let input = InternedInput :: new ( old_data. to_str ( ) . unwrap ( ) , new_data. to_str ( ) . unwrap ( ) ) ;
42+
43+ let mut diff = Diff :: compute ( algorithm, & input) ;
44+ diff. postprocess_lines ( & input) ;
45+
46+ let actual = diff
47+ . unified_diff (
48+ & BasicLineDiffPrinter ( & input. interner ) ,
49+ UnifiedDiffConfig :: default ( ) ,
50+ & input,
51+ )
52+ . to_string ( ) ;
5653
5754 let baseline_path = worktree_path. join ( & file_name) ;
5855 let baseline = std:: fs:: read ( baseline_path) ?;
5956 let baseline = baseline:: Baseline :: new ( & baseline) ;
6057
61- let actual = actual
62- . iter ( )
63- . fold ( BString :: default ( ) , |mut acc, diff_hunk| {
64- acc. push_str ( diff_hunk. header . to_string ( ) . as_str ( ) ) ;
65- acc. push ( b'\n' ) ;
66-
67- acc. extend_from_slice ( & diff_hunk. lines ) ;
68-
69- acc
70- } )
71- . to_string ( ) ;
72-
7358 let baseline = baseline
7459 . fold ( BString :: default ( ) , |mut acc, diff_hunk| {
7560 acc. push_str ( diff_hunk. header . to_string ( ) . as_str ( ) ) ;
@@ -119,15 +104,11 @@ fn baseline() -> gix_testtools::Result {
119104 Ok ( ( ) )
120105}
121106
122- fn tokens_for_diffing ( data : & [ u8 ] ) -> impl TokenSource < Token = & [ u8 ] > {
123- gix_diff:: blob:: sources:: byte_lines ( data)
124- }
125-
126107mod baseline {
127108 use gix_object:: bstr:: ByteSlice ;
128109 use std:: iter:: Peekable ;
129110
130- use gix_diff:: blob:: unified_diff:: { ConsumeHunk , HunkHeader } ;
111+ use gix_diff:: blob:: unified_diff:: HunkHeader ;
131112 use gix_object:: bstr:: { self , BString } ;
132113
133114 static START_OF_HEADER : & [ u8 ; 4 ] = b"@@ -" ;
@@ -138,47 +119,6 @@ mod baseline {
138119 pub lines : BString ,
139120 }
140121
141- pub struct DiffHunkRecorder {
142- inner : Vec < DiffHunk > ,
143- }
144-
145- impl DiffHunkRecorder {
146- pub fn new ( ) -> Self {
147- Self { inner : Vec :: new ( ) }
148- }
149- }
150-
151- impl ConsumeHunk for DiffHunkRecorder {
152- type Out = Vec < DiffHunk > ;
153-
154- fn consume_hunk (
155- & mut self ,
156- header : HunkHeader ,
157- lines : & [ ( gix_diff:: blob:: unified_diff:: DiffLineKind , & [ u8 ] ) ] ,
158- ) -> std:: io:: Result < ( ) > {
159- let mut buf = Vec :: new ( ) ;
160-
161- for & ( kind, line) in lines {
162- buf. push ( kind. to_prefix ( ) as u8 ) ;
163- buf. extend_from_slice ( line) ;
164- buf. push ( b'\n' ) ;
165- }
166-
167- let diff_hunk = DiffHunk {
168- header,
169- lines : buf. into ( ) ,
170- } ;
171-
172- self . inner . push ( diff_hunk) ;
173-
174- Ok ( ( ) )
175- }
176-
177- fn finish ( self ) -> Self :: Out {
178- self . inner
179- }
180- }
181-
182122 type Lines < ' a > = Peekable < bstr:: Lines < ' a > > ;
183123
184124 pub struct Baseline < ' a > {
0 commit comments