44#include "diff.h"
55#include "diffcore.h"
66#include "quote.h"
7- #include "xdiff/xdiff .h"
7+ #include "xdiff-interface .h"
88
99static int uninteresting (struct diff_filepair * p )
1010{
@@ -195,8 +195,8 @@ static void append_lost(struct sline *sline, int n, const char *line, int len)
195195}
196196
197197struct combine_diff_state {
198- char * remainder ;
199- unsigned long remainder_size ;
198+ struct xdiff_emit_state xm ;
199+
200200 unsigned int lno , ob , on , nb , nn ;
201201 unsigned long nmask ;
202202 int num_parent ;
@@ -205,10 +205,9 @@ struct combine_diff_state {
205205 struct sline * lost_bucket ;
206206};
207207
208- static void consume_line (struct combine_diff_state * state ,
209- char * line ,
210- unsigned long len )
208+ static void consume_line (void * state_ , char * line , unsigned long len )
211209{
210+ struct combine_diff_state * state = state_ ;
212211 if (5 < len && !memcmp ("@@ -" , line , 4 )) {
213212 if (parse_hunk_header (line , len ,
214213 & state -> ob , & state -> on ,
@@ -249,41 +248,6 @@ static void consume_line(struct combine_diff_state *state,
249248 }
250249}
251250
252- static int combine_diff_outf (void * priv_ , mmbuffer_t * mb , int nbuf )
253- {
254- struct combine_diff_state * priv = priv_ ;
255- int i ;
256- for (i = 0 ; i < nbuf ; i ++ ) {
257- if (mb [i ].ptr [mb [i ].size - 1 ] != '\n' ) {
258- /* Incomplete line */
259- priv -> remainder = realloc (priv -> remainder ,
260- priv -> remainder_size +
261- mb [i ].size );
262- memcpy (priv -> remainder + priv -> remainder_size ,
263- mb [i ].ptr , mb [i ].size );
264- priv -> remainder_size += mb [i ].size ;
265- continue ;
266- }
267-
268- /* we have a complete line */
269- if (!priv -> remainder ) {
270- consume_line (priv , mb [i ].ptr , mb [i ].size );
271- continue ;
272- }
273- priv -> remainder = realloc (priv -> remainder ,
274- priv -> remainder_size +
275- mb [i ].size );
276- memcpy (priv -> remainder + priv -> remainder_size ,
277- mb [i ].ptr , mb [i ].size );
278- consume_line (priv , priv -> remainder ,
279- priv -> remainder_size + mb [i ].size );
280- free (priv -> remainder );
281- priv -> remainder = NULL ;
282- priv -> remainder_size = 0 ;
283- }
284- return 0 ;
285- }
286-
287251static void combine_diff (const unsigned char * parent , mmfile_t * result_file ,
288252 struct sline * sline , int cnt , int n , int num_parent )
289253{
@@ -304,19 +268,17 @@ static void combine_diff(const unsigned char *parent, mmfile_t *result_file,
304268 xpp .flags = XDF_NEED_MINIMAL ;
305269 xecfg .ctxlen = 0 ;
306270 xecfg .flags = 0 ;
307- ecb .outf = combine_diff_outf ;
271+ ecb .outf = xdiff_outf ;
308272 ecb .priv = & state ;
309273 memset (& state , 0 , sizeof (state ));
274+ state .xm .consume = consume_line ;
310275 state .nmask = nmask ;
311276 state .sline = sline ;
312277 state .lno = 1 ;
313278 state .num_parent = num_parent ;
314279 state .n = n ;
315280
316281 xdl_diff (& parent_file , result_file , & xpp , & xecfg , & ecb );
317- if (state .remainder && state .remainder_size )
318- consume_line (& state , state .remainder , state .remainder_size );
319- free (state .remainder );
320282 free (parent_file .ptr );
321283
322284 /* Assign line numbers for this parent.
0 commit comments