xdiff: add hunk_func()
authorRené Scharfe <rene.scharfe@lsrfire.ath.cx>
Wed, 9 May 2012 20:20:55 +0000 (22:20 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 9 May 2012 21:00:15 +0000 (14:00 -0700)
Add a way to register a callback function that is gets passed the
start line and line count of each hunk of a diff.  Only standard
types are used.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
xdiff/xdiff.h
xdiff/xdiffi.c

index 09215afe6e0250fd29897390f074234a7b89f4d8..33c010b1f117154501a3043d2328fd0b2517204e 100644 (file)
@@ -86,6 +86,10 @@ typedef struct s_xdemitcb {
 
 typedef long (*find_func_t)(const char *line, long line_len, char *buffer, long buffer_size, void *priv);
 
+typedef int (*xdl_emit_hunk_consume_func_t)(long start_a, long count_a,
+                                           long start_b, long count_b,
+                                           void *cb_data);
+
 typedef struct s_xdemitconf {
        long ctxlen;
        long interhunkctxlen;
@@ -93,6 +97,7 @@ typedef struct s_xdemitconf {
        find_func_t find_func;
        void *find_func_priv;
        void (*emit_func)();
+       xdl_emit_hunk_consume_func_t hunk_func;
 } xdemitconf_t;
 
 typedef struct s_bdiffparam {
index bc889e87894fbd261db8aaf29723e8df35f913da..4d671f4371fab0e9f3b250a4a3e133ae0374f57d 100644 (file)
@@ -538,6 +538,20 @@ void xdl_free_script(xdchange_t *xscr) {
        }
 }
 
+static int xdl_call_hunk_func(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
+                             xdemitconf_t const *xecfg)
+{
+       xdchange_t *xch, *xche;
+
+       for (xch = xscr; xch; xch = xche->next) {
+               xche = xdl_get_hunk(xch, xecfg);
+               if (xecfg->hunk_func(xch->i1, xche->i1 + xche->chg1 - xch->i1,
+                                    xch->i2, xche->i2 + xche->chg2 - xch->i2,
+                                    ecb->priv) < 0)
+                       return -1;
+       }
+       return 0;
+}
 
 int xdl_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
             xdemitconf_t const *xecfg, xdemitcb_t *ecb) {
@@ -546,6 +560,9 @@ int xdl_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
        emit_func_t ef = xecfg->emit_func ?
                (emit_func_t)xecfg->emit_func : xdl_emit_diff;
 
+       if (xecfg->hunk_func)
+               ef = xdl_call_hunk_func;
+
        if (xdl_do_diff(mf1, mf2, xpp, &xe) < 0) {
 
                return -1;