xdiff: add hunk_func()
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>
René Scharfe committed
May 9, 2012 at 22:20 UTC
467d348c19b2ce82753bb9b5a873f6d129eb04e2
2 files changed
+22
xdiff/xdiff.h
+5
@@ -86,6 +86,10 @@ typedef struct s_xdemitcb {
86
87
typedef long (*find_func_t)(const char *line, long line_len, char *buffer, long buffer_size, void *priv);
88
89
+typedef int (*xdl_emit_hunk_consume_func_t)(long start_a, long count_a,
90
+ long start_b, long count_b,
91
+ void *cb_data);
92
+
93
typedef struct s_xdemitconf {
94
long ctxlen;
95
long interhunkctxlen;
@@ -93,6 +97,7 @@ typedef struct s_xdemitconf {
97
find_func_t find_func;
98
void *find_func_priv;
99
void (*emit_func)();
100
+ xdl_emit_hunk_consume_func_t hunk_func;
101
} xdemitconf_t;
102
103
typedef struct s_bdiffparam {
xdiff/xdiffi.c
+17
@@ -538,6 +538,20 @@ void xdl_free_script(xdchange_t *xscr) {
538
}
539
}
540
541
+static int xdl_call_hunk_func(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
542
+ xdemitconf_t const *xecfg)
543
+{
544
+ xdchange_t *xch, *xche;
545
+
546
+ for (xch = xscr; xch; xch = xche->next) {
547
+ xche = xdl_get_hunk(xch, xecfg);
548
+ if (xecfg->hunk_func(xch->i1, xche->i1 + xche->chg1 - xch->i1,
549
+ xch->i2, xche->i2 + xche->chg2 - xch->i2,
550
+ ecb->priv) < 0)
551
+ return -1;
552
+ }
553
+ return 0;
554
+}
555
556
int xdl_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
557
xdemitconf_t const *xecfg, xdemitcb_t *ecb) {
@@ -546,6 +560,9 @@ int xdl_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
560
emit_func_t ef = xecfg->emit_func ?
561
(emit_func_t)xecfg->emit_func : xdl_emit_diff;
562
563
+ if (xecfg->hunk_func)
564
+ ef = xdl_call_hunk_func;
565
+
566
if (xdl_do_diff(mf1, mf2, xpp, &xe) < 0) {
567
568
return -1;