11use anyhow:: Context ;
22use gix:: bstr:: { BString , ByteSlice } ;
33use gix:: diff:: blob:: intern:: TokenSource ;
4- use gix:: diff:: blob:: UnifiedDiffBuilder ;
4+ use gix:: diff:: blob:: unified_diff:: { ContextSize , NewlineSeparator } ;
5+ use gix:: diff:: blob:: UnifiedDiff ;
56use gix:: objs:: tree:: EntryMode ;
67use gix:: odb:: store:: RefreshMode ;
78use gix:: prelude:: ObjectIdExt ;
@@ -163,14 +164,6 @@ pub fn file(
163164
164165 let outcome = resource_cache. prepare_diff ( ) ?;
165166
166- let old_data = String :: from_utf8_lossy ( outcome. old . data . as_slice ( ) . unwrap_or_default ( ) ) ;
167- let new_data = String :: from_utf8_lossy ( outcome. new . data . as_slice ( ) . unwrap_or_default ( ) ) ;
168-
169- let input =
170- gix:: diff:: blob:: intern:: InternedInput :: new ( tokens_for_diffing ( & old_data) , tokens_for_diffing ( & new_data) ) ;
171-
172- let unified_diff_builder = UnifiedDiffBuilder :: new ( & input) ;
173-
174167 use gix:: diff:: blob:: platform:: prepare_diff:: Operation ;
175168
176169 let algorithm = match outcome. operation {
@@ -184,13 +177,25 @@ pub fn file(
184177 }
185178 } ;
186179
187- let unified_diff = gix:: diff:: blob:: diff ( algorithm, & input, unified_diff_builder) ;
180+ let interner = gix:: diff:: blob:: intern:: InternedInput :: new (
181+ tokens_for_diffing ( outcome. old . data . as_slice ( ) . unwrap_or_default ( ) ) ,
182+ tokens_for_diffing ( outcome. new . data . as_slice ( ) . unwrap_or_default ( ) ) ,
183+ ) ;
184+
185+ let unified_diff = UnifiedDiff :: new (
186+ & interner,
187+ String :: new ( ) ,
188+ NewlineSeparator :: AfterHeaderAndLine ( "\n " ) ,
189+ ContextSize :: symmetrical ( 3 ) ,
190+ ) ;
191+
192+ let unified_diff = gix:: diff:: blob:: diff ( algorithm, & interner, unified_diff) ?;
188193
189194 out. write_all ( unified_diff. as_bytes ( ) ) ?;
190195
191196 Ok ( ( ) )
192197}
193198
194- pub ( crate ) fn tokens_for_diffing ( data : & str ) -> impl TokenSource < Token = & str > {
195- gix:: diff:: blob:: sources:: lines ( data)
199+ pub ( crate ) fn tokens_for_diffing ( data : & [ u8 ] ) -> impl TokenSource < Token = & [ u8 ] > {
200+ gix:: diff:: blob:: sources:: byte_lines ( data)
196201}
0 commit comments