Skip to content

Commit

Permalink
xdiff: add hunk_func()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
René Scharfe authored and Junio C Hamano committed May 9, 2012
1 parent a3935e6 commit 467d348
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions xdiff/xdiff.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,18 @@ 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;
unsigned long flags;
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 {
Expand Down
17 changes: 17 additions & 0 deletions xdiff/xdiffi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down

0 comments on commit 467d348

Please sign in to comment.