Skip to content

Commit 467d348

Browse files
René Scharfegitster
authored andcommitted
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>
1 parent a3935e6 commit 467d348

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

xdiff/xdiff.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,18 @@ typedef struct s_xdemitcb {
8686

8787
typedef long (*find_func_t)(const char *line, long line_len, char *buffer, long buffer_size, void *priv);
8888

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+
8993
typedef struct s_xdemitconf {
9094
long ctxlen;
9195
long interhunkctxlen;
9296
unsigned long flags;
9397
find_func_t find_func;
9498
void *find_func_priv;
9599
void (*emit_func)();
100+
xdl_emit_hunk_consume_func_t hunk_func;
96101
} xdemitconf_t;
97102

98103
typedef struct s_bdiffparam {

xdiff/xdiffi.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,20 @@ void xdl_free_script(xdchange_t *xscr) {
538538
}
539539
}
540540

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+
}
541555

542556
int xdl_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
543557
xdemitconf_t const *xecfg, xdemitcb_t *ecb) {
@@ -546,6 +560,9 @@ int xdl_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
546560
emit_func_t ef = xecfg->emit_func ?
547561
(emit_func_t)xecfg->emit_func : xdl_emit_diff;
548562

563+
if (xecfg->hunk_func)
564+
ef = xdl_call_hunk_func;
565+
549566
if (xdl_do_diff(mf1, mf2, xpp, &xe) < 0) {
550567

551568
return -1;

0 commit comments

Comments
 (0)