aboutsummaryrefslogtreecommitdiff
path: root/xdiff/xutils.c
diff options
context:
space:
mode:
authorTay Ray Chuan <rctay89@gmail.com>2011-07-07 12:23:57 +0800
committerJunio C Hamano <gitster@pobox.com>2011-07-07 09:41:24 -0700
commit1d26b252f1128f7b31885811d7f481b6b7612bd7 (patch)
tree36aca90d478d89489ac8901981c4fd9544a57ba8 /xdiff/xutils.c
parent159607a8f1ad16c0a04e0f17d5f8a35299696bc6 (diff)
downloadgit-1d26b252f1128f7b31885811d7f481b6b7612bd7.tar.gz
git-1d26b252f1128f7b31885811d7f481b6b7612bd7.tar.xz
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>
Diffstat (limited to 'xdiff/xutils.c')
-rw-r--r--xdiff/xutils.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/xdiff/xutils.c b/xdiff/xutils.c
index ab6503460..ded7c327d 100644
--- a/xdiff/xutils.c
+++ b/xdiff/xutils.c
@@ -402,3 +402,34 @@ int xdl_emit_hunk_hdr(long s1, long c1, long s2, long c2,
return 0;
}
+
+int xdl_fall_back_diff(xdfenv_t *diff_env, xpparam_t const *xpp,
+ int line1, int count1, int line2, int count2)
+{
+ /*
+ * This probably does not work outside Git, since
+ * we have a very simple mmfile structure.
+ *
+ * Note: ideally, we would reuse the prepared environment, but
+ * the libxdiff interface does not (yet) allow for diffing only
+ * ranges of lines instead of the whole files.
+ */
+ mmfile_t subfile1, subfile2;
+ xdfenv_t env;
+
+ subfile1.ptr = (char *)diff_env->xdf1.recs[line1 - 1]->ptr;
+ subfile1.size = diff_env->xdf1.recs[line1 + count1 - 2]->ptr +
+ diff_env->xdf1.recs[line1 + count1 - 2]->size - subfile1.ptr;
+ subfile2.ptr = (char *)diff_env->xdf2.recs[line2 - 1]->ptr;
+ subfile2.size = diff_env->xdf2.recs[line2 + count2 - 2]->ptr +
+ diff_env->xdf2.recs[line2 + count2 - 2]->size - subfile2.ptr;
+ if (xdl_do_diff(&subfile1, &subfile2, xpp, &env) < 0)
+ return -1;
+
+ memcpy(diff_env->xdf1.rchg + line1 - 1, env.xdf1.rchg, count1);
+ memcpy(diff_env->xdf2.rchg + line2 - 1, env.xdf2.rchg, count2);
+
+ xdl_free_env(&env);
+
+ return 0;
+}