1
1
use anyhow:: Context ;
2
2
use gix:: bstr:: { BString , ByteSlice } ;
3
3
use 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 ;
5
6
use gix:: objs:: tree:: EntryMode ;
6
7
use gix:: odb:: store:: RefreshMode ;
7
8
use gix:: prelude:: ObjectIdExt ;
@@ -163,14 +164,6 @@ pub fn file(
163
164
164
165
let outcome = resource_cache. prepare_diff ( ) ?;
165
166
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
-
174
167
use gix:: diff:: blob:: platform:: prepare_diff:: Operation ;
175
168
176
169
let algorithm = match outcome. operation {
@@ -184,13 +177,25 @@ pub fn file(
184
177
}
185
178
} ;
186
179
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) ?;
188
193
189
194
out. write_all ( unified_diff. as_bytes ( ) ) ?;
190
195
191
196
Ok ( ( ) )
192
197
}
193
198
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)
196
201
}
0 commit comments