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 <rctay89@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Tay Ray Chuan committed
Jul 7, 2011 at 12:23 UTC
1d26b252f1128f7b31885811d7f481b6b7612bd7
3 files changed
+35
-25
xdiff/xpatience.c
+2
-25
@@ -287,34 +287,11 @@ static int walk_common_sequence(struct hashmap *map, struct entry *first,
287
static int fall_back_to_classic_diff(struct hashmap *map,
288
int line1, int count1, int line2, int count2)
289
{
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;
290
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;
291
xpp.flags = map->xpp->flags & ~XDF_PATIENCE_DIFF;
309
- if (xdl_do_diff(&subfile1, &subfile2, &xpp, &env) < 0)
310
- return -1;
292
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);
295
}
296
297
/*
xdiff/xutils.c
+31
@@ -402,3 +402,34 @@ int xdl_emit_hunk_hdr(long s1, long c1, long s2, long c2,
402
403
return 0;
404
}
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
+2
@@ -41,6 +41,8 @@ int xdl_num_out(char *out, long val);
41
long xdl_atol(char const *str, char const **next);
42
int xdl_emit_hunk_hdr(long s1, long c1, long s2, long c2,
43
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);
46
47
48