Skip to content

Commit 1d26b25

Browse files
rctaygitster
authored andcommitted
xdiff/xpatience: factor out fall-back-diff function
This is in preparation for the histogram diff algorithm, which will also re-use much of the code to call the default Meyers diff algorithm. Signed-off-by: Tay Ray Chuan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 159607a commit 1d26b25

File tree

3 files changed

+35
-25
lines changed

3 files changed

+35
-25
lines changed

xdiff/xpatience.c

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -287,34 +287,11 @@ static int walk_common_sequence(struct hashmap *map, struct entry *first,
287287
static int fall_back_to_classic_diff(struct hashmap *map,
288288
int line1, int count1, int line2, int count2)
289289
{
290-
/*
291-
* This probably does not work outside Git, since
292-
* we have a very simple mmfile structure.
293-
*
294-
* Note: ideally, we would reuse the prepared environment, but
295-
* the libxdiff interface does not (yet) allow for diffing only
296-
* ranges of lines instead of the whole files.
297-
*/
298-
mmfile_t subfile1, subfile2;
299290
xpparam_t xpp;
300-
xdfenv_t env;
301-
302-
subfile1.ptr = (char *)map->env->xdf1.recs[line1 - 1]->ptr;
303-
subfile1.size = map->env->xdf1.recs[line1 + count1 - 2]->ptr +
304-
map->env->xdf1.recs[line1 + count1 - 2]->size - subfile1.ptr;
305-
subfile2.ptr = (char *)map->env->xdf2.recs[line2 - 1]->ptr;
306-
subfile2.size = map->env->xdf2.recs[line2 + count2 - 2]->ptr +
307-
map->env->xdf2.recs[line2 + count2 - 2]->size - subfile2.ptr;
308291
xpp.flags = map->xpp->flags & ~XDF_PATIENCE_DIFF;
309-
if (xdl_do_diff(&subfile1, &subfile2, &xpp, &env) < 0)
310-
return -1;
311292

312-
memcpy(map->env->xdf1.rchg + line1 - 1, env.xdf1.rchg, count1);
313-
memcpy(map->env->xdf2.rchg + line2 - 1, env.xdf2.rchg, count2);
314-
315-
xdl_free_env(&env);
316-
317-
return 0;
293+
return xdl_fall_back_diff(map->env, &xpp,
294+
line1, count1, line2, count2);
318295
}
319296

320297
/*

xdiff/xutils.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,3 +402,34 @@ int xdl_emit_hunk_hdr(long s1, long c1, long s2, long c2,
402402

403403
return 0;
404404
}
405+
406+
int xdl_fall_back_diff(xdfenv_t *diff_env, xpparam_t const *xpp,
407+
int line1, int count1, int line2, int count2)
408+
{
409+
/*
410+
* This probably does not work outside Git, since
411+
* we have a very simple mmfile structure.
412+
*
413+
* Note: ideally, we would reuse the prepared environment, but
414+
* the libxdiff interface does not (yet) allow for diffing only
415+
* ranges of lines instead of the whole files.
416+
*/
417+
mmfile_t subfile1, subfile2;
418+
xdfenv_t env;
419+
420+
subfile1.ptr = (char *)diff_env->xdf1.recs[line1 - 1]->ptr;
421+
subfile1.size = diff_env->xdf1.recs[line1 + count1 - 2]->ptr +
422+
diff_env->xdf1.recs[line1 + count1 - 2]->size - subfile1.ptr;
423+
subfile2.ptr = (char *)diff_env->xdf2.recs[line2 - 1]->ptr;
424+
subfile2.size = diff_env->xdf2.recs[line2 + count2 - 2]->ptr +
425+
diff_env->xdf2.recs[line2 + count2 - 2]->size - subfile2.ptr;
426+
if (xdl_do_diff(&subfile1, &subfile2, xpp, &env) < 0)
427+
return -1;
428+
429+
memcpy(diff_env->xdf1.rchg + line1 - 1, env.xdf1.rchg, count1);
430+
memcpy(diff_env->xdf2.rchg + line2 - 1, env.xdf2.rchg, count2);
431+
432+
xdl_free_env(&env);
433+
434+
return 0;
435+
}

xdiff/xutils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ int xdl_num_out(char *out, long val);
4141
long xdl_atol(char const *str, char const **next);
4242
int xdl_emit_hunk_hdr(long s1, long c1, long s2, long c2,
4343
const char *func, long funclen, xdemitcb_t *ecb);
44+
int xdl_fall_back_diff(xdfenv_t *diff_env, xpparam_t const *xpp,
45+
int line1, int count1, int line2, int count2);
4446

4547

4648

0 commit comments

Comments
 (0)