* [PATCH 0/5] xdiff: replace emit_func() with type-safe
@ 2012-05-09 20:19 René Scharfe
2012-05-09 20:20 ` [PATCH 1/5] xdiff: add hunk_func() René Scharfe
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: René Scharfe @ 2012-05-09 20:19 UTC (permalink / raw)
To: git discussion list; +Cc: Junio C Hamano
Commit ef2e62fe added the ability to bypass the creation of textual diffs
and to access diff data directly, through the added emit_func member of
xdemitconf_t. This function pointer has a type of "void (*)()", because
"int (*)(xdfenv_t *, xdchange_t *, xdemitcb_t *, xdemitconf_t const *)"
(its real type) would be difficult to export due to the many internal
types in that signature.
This feature is currently used twice in git blame, through the function
xdi_diff_hunks(). Both cases only need to know which lines are affected
by the different hunks of a diff, i.e. the numbers shown in hunk headers
of unified diffs.
This patch series adds a simpler mechanism to accommodate these two
callers, in a type-safe way, without exporting too many internal types
of libxdiff. The last patch removes the old functions.
xdiff: add hunk_func()
blame: use hunk_func(), part 1
blame: use hunk_func(), part 2
blame: factor out helper for calling xdi_diff()
xdiff: remove emit_func() and xdi_diff_hunks()
builtin/blame.c | 53 +++++++++++++++++++++++++++++++----------------------
xdiff-interface.c | 44 --------------------------------------------
xdiff-interface.h | 4 ----
xdiff/xdiff.h | 6 +++++-
xdiff/xdiffi.c | 17 +++++++++++++++--
5 files changed, 51 insertions(+), 73 deletions(-)
--
1.7.10.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/5] xdiff: add hunk_func()
2012-05-09 20:19 [PATCH 0/5] xdiff: replace emit_func() with type-safe René Scharfe
@ 2012-05-09 20:20 ` René Scharfe
2012-05-09 20:21 ` [PATCH 2/5] blame: use hunk_func(), part 1 René Scharfe
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: René Scharfe @ 2012-05-09 20:20 UTC (permalink / raw)
To: git discussion list; +Cc: Junio C Hamano
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>
---
xdiff/xdiff.h | 5 +++++
xdiff/xdiffi.c | 17 +++++++++++++++++
2 files changed, 22 insertions(+)
diff --git a/xdiff/xdiff.h b/xdiff/xdiff.h
index 09215af..33c010b 100644
--- a/xdiff/xdiff.h
+++ b/xdiff/xdiff.h
@@ -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 {
diff --git a/xdiff/xdiffi.c b/xdiff/xdiffi.c
index bc889e8..4d671f4 100644
--- a/xdiff/xdiffi.c
+++ b/xdiff/xdiffi.c
@@ -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;
--
1.7.10.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/5] blame: use hunk_func(), part 1
2012-05-09 20:19 [PATCH 0/5] xdiff: replace emit_func() with type-safe René Scharfe
2012-05-09 20:20 ` [PATCH 1/5] xdiff: add hunk_func() René Scharfe
@ 2012-05-09 20:21 ` René Scharfe
2012-05-09 20:22 ` [PATCH 3/5] blame: use hunk_func(), part 2 René Scharfe
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: René Scharfe @ 2012-05-09 20:21 UTC (permalink / raw)
To: git discussion list; +Cc: Junio C Hamano
Use blame_chunk_cb() directly as hunk_func() callback, without detour
through xdi_diff_hunks().
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
builtin/blame.c | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/builtin/blame.c b/builtin/blame.c
index 324d476..9ae5cf3 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -759,12 +759,14 @@ struct blame_chunk_cb_data {
long tlno;
};
-static void blame_chunk_cb(void *data, long same, long p_next, long t_next)
+static int blame_chunk_cb(long start_a, long count_a,
+ long start_b, long count_b, void *data)
{
struct blame_chunk_cb_data *d = data;
- blame_chunk(d->sb, d->tlno, d->plno, same, d->target, d->parent);
- d->plno = p_next;
- d->tlno = t_next;
+ blame_chunk(d->sb, d->tlno, d->plno, start_b, d->target, d->parent);
+ d->plno = start_a + count_a;
+ d->tlno = start_b + count_b;
+ return 0;
}
/*
@@ -781,6 +783,8 @@ static int pass_blame_to_parent(struct scoreboard *sb,
struct blame_chunk_cb_data d;
xpparam_t xpp;
xdemitconf_t xecfg;
+ xdemitcb_t ecb;
+
memset(&d, 0, sizeof(d));
d.sb = sb; d.target = target; d.parent = parent;
last_in_target = find_last_in_target(sb, target);
@@ -795,7 +799,10 @@ static int pass_blame_to_parent(struct scoreboard *sb,
xpp.flags = xdl_opts;
memset(&xecfg, 0, sizeof(xecfg));
xecfg.ctxlen = 0;
- xdi_diff_hunks(&file_p, &file_o, blame_chunk_cb, &d, &xpp, &xecfg);
+ xecfg.hunk_func = blame_chunk_cb;
+ memset(&ecb, 0, sizeof(ecb));
+ ecb.priv = &d;
+ xdi_diff(&file_p, &file_o, &xpp, &xecfg, &ecb);
/* The rest (i.e. anything after tlno) are the same as the parent */
blame_chunk(sb, d.tlno, d.plno, last_in_target, target, parent);
--
1.7.10.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/5] blame: use hunk_func(), part 2
2012-05-09 20:19 [PATCH 0/5] xdiff: replace emit_func() with type-safe René Scharfe
2012-05-09 20:20 ` [PATCH 1/5] xdiff: add hunk_func() René Scharfe
2012-05-09 20:21 ` [PATCH 2/5] blame: use hunk_func(), part 1 René Scharfe
@ 2012-05-09 20:22 ` René Scharfe
2012-05-09 20:23 ` [PATCH 4/5] blame: factor out helper for calling xdi_diff() René Scharfe
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: René Scharfe @ 2012-05-09 20:22 UTC (permalink / raw)
To: git discussion list; +Cc: Junio C Hamano
Use handle_split_cb() directly as hunk_func() callback, without going
through xdi_diff_hunks().
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
builtin/blame.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/builtin/blame.c b/builtin/blame.c
index 9ae5cf3..c83fc7c 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -906,12 +906,15 @@ struct handle_split_cb_data {
long tlno;
};
-static void handle_split_cb(void *data, long same, long p_next, long t_next)
+static int handle_split_cb(long start_a, long count_a,
+ long start_b, long count_b, void *data)
{
struct handle_split_cb_data *d = data;
- handle_split(d->sb, d->ent, d->tlno, d->plno, same, d->parent, d->split);
- d->plno = p_next;
- d->tlno = t_next;
+ handle_split(d->sb, d->ent, d->tlno, d->plno, start_b, d->parent,
+ d->split);
+ d->plno = start_a + count_a;
+ d->tlno = start_b + count_b;
+ return 0;
}
/*
@@ -931,6 +934,8 @@ static void find_copy_in_blob(struct scoreboard *sb,
struct handle_split_cb_data d;
xpparam_t xpp;
xdemitconf_t xecfg;
+ xdemitcb_t ecb;
+
memset(&d, 0, sizeof(d));
d.sb = sb; d.ent = ent; d.parent = parent; d.split = split;
/*
@@ -954,8 +959,11 @@ static void find_copy_in_blob(struct scoreboard *sb,
xpp.flags = xdl_opts;
memset(&xecfg, 0, sizeof(xecfg));
xecfg.ctxlen = 1;
+ xecfg.hunk_func = handle_split_cb;
+ memset(&ecb, 0, sizeof(ecb));
+ ecb.priv = &d;
memset(split, 0, sizeof(struct blame_entry [3]));
- xdi_diff_hunks(file_p, &file_o, handle_split_cb, &d, &xpp, &xecfg);
+ xdi_diff(file_p, &file_o, &xpp, &xecfg, &ecb);
/* remainder, if any, all match the preimage */
handle_split(sb, ent, d.tlno, d.plno, ent->num_lines, parent, split);
}
--
1.7.10.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 4/5] blame: factor out helper for calling xdi_diff()
2012-05-09 20:19 [PATCH 0/5] xdiff: replace emit_func() with type-safe René Scharfe
` (2 preceding siblings ...)
2012-05-09 20:22 ` [PATCH 3/5] blame: use hunk_func(), part 2 René Scharfe
@ 2012-05-09 20:23 ` René Scharfe
2012-05-09 20:24 ` [PATCH 5/5] xdiff: remove emit_func() and xdi_diff_hunks() René Scharfe
2012-05-18 8:28 ` [PATCH 0/5] xdiff: replace emit_func() with type-safe Thomas Rast
5 siblings, 0 replies; 7+ messages in thread
From: René Scharfe @ 2012-05-09 20:23 UTC (permalink / raw)
To: git discussion list; +Cc: Junio C Hamano
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
builtin/blame.c | 38 ++++++++++++++++----------------------
1 file changed, 16 insertions(+), 22 deletions(-)
diff --git a/builtin/blame.c b/builtin/blame.c
index c83fc7c..778d661 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -88,6 +88,20 @@ struct origin {
char path[FLEX_ARRAY];
};
+static int diff_hunks(mmfile_t *file_a, mmfile_t *file_b, long ctxlen,
+ xdl_emit_hunk_consume_func_t hunk_func, void *cb_data)
+{
+ xpparam_t xpp = {0};
+ xdemitconf_t xecfg = {0};
+ xdemitcb_t ecb = {0};
+
+ xpp.flags = xdl_opts;
+ xecfg.ctxlen = ctxlen;
+ xecfg.hunk_func = hunk_func;
+ ecb.priv = cb_data;
+ return xdi_diff(file_a, file_b, &xpp, &xecfg, &ecb);
+}
+
/*
* Prepare diff_filespec and convert it using diff textconv API
* if the textconv driver exists.
@@ -781,9 +795,6 @@ static int pass_blame_to_parent(struct scoreboard *sb,
int last_in_target;
mmfile_t file_p, file_o;
struct blame_chunk_cb_data d;
- xpparam_t xpp;
- xdemitconf_t xecfg;
- xdemitcb_t ecb;
memset(&d, 0, sizeof(d));
d.sb = sb; d.target = target; d.parent = parent;
@@ -795,14 +806,7 @@ static int pass_blame_to_parent(struct scoreboard *sb,
fill_origin_blob(&sb->revs->diffopt, target, &file_o);
num_get_patch++;
- memset(&xpp, 0, sizeof(xpp));
- xpp.flags = xdl_opts;
- memset(&xecfg, 0, sizeof(xecfg));
- xecfg.ctxlen = 0;
- xecfg.hunk_func = blame_chunk_cb;
- memset(&ecb, 0, sizeof(ecb));
- ecb.priv = &d;
- xdi_diff(&file_p, &file_o, &xpp, &xecfg, &ecb);
+ diff_hunks(&file_p, &file_o, 0, blame_chunk_cb, &d);
/* The rest (i.e. anything after tlno) are the same as the parent */
blame_chunk(sb, d.tlno, d.plno, last_in_target, target, parent);
@@ -932,9 +936,6 @@ static void find_copy_in_blob(struct scoreboard *sb,
int cnt;
mmfile_t file_o;
struct handle_split_cb_data d;
- xpparam_t xpp;
- xdemitconf_t xecfg;
- xdemitcb_t ecb;
memset(&d, 0, sizeof(d));
d.sb = sb; d.ent = ent; d.parent = parent; d.split = split;
@@ -955,15 +956,8 @@ static void find_copy_in_blob(struct scoreboard *sb,
* file_o is a part of final image we are annotating.
* file_p partially may match that image.
*/
- memset(&xpp, 0, sizeof(xpp));
- xpp.flags = xdl_opts;
- memset(&xecfg, 0, sizeof(xecfg));
- xecfg.ctxlen = 1;
- xecfg.hunk_func = handle_split_cb;
- memset(&ecb, 0, sizeof(ecb));
- ecb.priv = &d;
memset(split, 0, sizeof(struct blame_entry [3]));
- xdi_diff(file_p, &file_o, &xpp, &xecfg, &ecb);
+ diff_hunks(file_p, &file_o, 1, handle_split_cb, &d);
/* remainder, if any, all match the preimage */
handle_split(sb, ent, d.tlno, d.plno, ent->num_lines, parent, split);
}
--
1.7.10.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 5/5] xdiff: remove emit_func() and xdi_diff_hunks()
2012-05-09 20:19 [PATCH 0/5] xdiff: replace emit_func() with type-safe René Scharfe
` (3 preceding siblings ...)
2012-05-09 20:23 ` [PATCH 4/5] blame: factor out helper for calling xdi_diff() René Scharfe
@ 2012-05-09 20:24 ` René Scharfe
2012-05-18 8:28 ` [PATCH 0/5] xdiff: replace emit_func() with type-safe Thomas Rast
5 siblings, 0 replies; 7+ messages in thread
From: René Scharfe @ 2012-05-09 20:24 UTC (permalink / raw)
To: git discussion list; +Cc: Junio C Hamano
The functions are unused now, remove them.
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
xdiff-interface.c | 44 --------------------------------------------
xdiff-interface.h | 4 ----
xdiff/xdiff.h | 1 -
xdiff/xdiffi.c | 6 +-----
4 files changed, 1 insertion(+), 54 deletions(-)
diff --git a/xdiff-interface.c b/xdiff-interface.c
index 0e2c169..ecfa05f 100644
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
@@ -156,50 +156,6 @@ int xdi_diff_outf(mmfile_t *mf1, mmfile_t *mf2,
return ret;
}
-struct xdiff_emit_hunk_state {
- xdiff_emit_hunk_consume_fn consume;
- void *consume_callback_data;
-};
-
-static int process_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
- xdemitconf_t const *xecfg)
-{
- long s1, s2, same, p_next, t_next;
- xdchange_t *xch, *xche;
- struct xdiff_emit_hunk_state *state = ecb->priv;
- xdiff_emit_hunk_consume_fn fn = state->consume;
- void *consume_callback_data = state->consume_callback_data;
-
- for (xch = xscr; xch; xch = xche->next) {
- xche = xdl_get_hunk(xch, xecfg);
-
- s1 = XDL_MAX(xch->i1 - xecfg->ctxlen, 0);
- s2 = XDL_MAX(xch->i2 - xecfg->ctxlen, 0);
- same = s2 + XDL_MAX(xch->i1 - s1, 0);
- p_next = xche->i1 + xche->chg1;
- t_next = xche->i2 + xche->chg2;
-
- fn(consume_callback_data, same, p_next, t_next);
- }
- return 0;
-}
-
-int xdi_diff_hunks(mmfile_t *mf1, mmfile_t *mf2,
- xdiff_emit_hunk_consume_fn fn, void *consume_callback_data,
- xpparam_t const *xpp, xdemitconf_t *xecfg)
-{
- struct xdiff_emit_hunk_state state;
- xdemitcb_t ecb;
-
- memset(&state, 0, sizeof(state));
- memset(&ecb, 0, sizeof(ecb));
- state.consume = fn;
- state.consume_callback_data = consume_callback_data;
- xecfg->emit_func = (void (*)())process_diff;
- ecb.priv = &state;
- return xdi_diff(mf1, mf2, xpp, xecfg, &ecb);
-}
-
int read_mmfile(mmfile_t *ptr, const char *filename)
{
struct stat st;
diff --git a/xdiff-interface.h b/xdiff-interface.h
index 49d1116..eff7762 100644
--- a/xdiff-interface.h
+++ b/xdiff-interface.h
@@ -4,15 +4,11 @@
#include "xdiff/xdiff.h"
typedef void (*xdiff_emit_consume_fn)(void *, char *, unsigned long);
-typedef void (*xdiff_emit_hunk_consume_fn)(void *, long, long, long);
int xdi_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, xdemitconf_t const *xecfg, xdemitcb_t *ecb);
int xdi_diff_outf(mmfile_t *mf1, mmfile_t *mf2,
xdiff_emit_consume_fn fn, void *consume_callback_data,
xpparam_t const *xpp, xdemitconf_t const *xecfg);
-int xdi_diff_hunks(mmfile_t *mf1, mmfile_t *mf2,
- xdiff_emit_hunk_consume_fn fn, void *consume_callback_data,
- xpparam_t const *xpp, xdemitconf_t *xecfg);
int parse_hunk_header(char *line, int len,
int *ob, int *on,
int *nb, int *nn);
diff --git a/xdiff/xdiff.h b/xdiff/xdiff.h
index 33c010b..219a3bb 100644
--- a/xdiff/xdiff.h
+++ b/xdiff/xdiff.h
@@ -96,7 +96,6 @@ typedef struct s_xdemitconf {
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;
diff --git a/xdiff/xdiffi.c b/xdiff/xdiffi.c
index 4d671f4..1b7012a 100644
--- a/xdiff/xdiffi.c
+++ b/xdiff/xdiffi.c
@@ -557,11 +557,7 @@ int xdl_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
xdemitconf_t const *xecfg, xdemitcb_t *ecb) {
xdchange_t *xscr;
xdfenv_t xe;
- 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;
+ emit_func_t ef = xecfg->hunk_func ? xdl_call_hunk_func : xdl_emit_diff;
if (xdl_do_diff(mf1, mf2, xpp, &xe) < 0) {
--
1.7.10.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 0/5] xdiff: replace emit_func() with type-safe
2012-05-09 20:19 [PATCH 0/5] xdiff: replace emit_func() with type-safe René Scharfe
` (4 preceding siblings ...)
2012-05-09 20:24 ` [PATCH 5/5] xdiff: remove emit_func() and xdi_diff_hunks() René Scharfe
@ 2012-05-18 8:28 ` Thomas Rast
5 siblings, 0 replies; 7+ messages in thread
From: Thomas Rast @ 2012-05-18 8:28 UTC (permalink / raw)
To: René Scharfe; +Cc: git discussion list, Junio C Hamano
René Scharfe <rene.scharfe@lsrfire.ath.cx> writes:
> Commit ef2e62fe added the ability to bypass the creation of textual diffs
> and to access diff data directly, through the added emit_func member of
> xdemitconf_t. This function pointer has a type of "void (*)()", because
> "int (*)(xdfenv_t *, xdchange_t *, xdemitcb_t *, xdemitconf_t const *)"
> (its real type) would be difficult to export due to the many internal
> types in that signature.
>
> This feature is currently used twice in git blame, through the function
> xdi_diff_hunks(). Both cases only need to know which lines are affected
> by the different hunks of a diff, i.e. the numbers shown in hunk headers
> of unified diffs.
>
> This patch series adds a simpler mechanism to accommodate these two
> callers, in a type-safe way, without exporting too many internal types
> of libxdiff. The last patch removes the old functions.
Cool, thanks a lot, this will come in handy when I finally get around to
finishing log -L.
--
Thomas Rast
trast@{inf,student}.ethz.ch
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2012-05-18 8:28 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-09 20:19 [PATCH 0/5] xdiff: replace emit_func() with type-safe René Scharfe
2012-05-09 20:20 ` [PATCH 1/5] xdiff: add hunk_func() René Scharfe
2012-05-09 20:21 ` [PATCH 2/5] blame: use hunk_func(), part 1 René Scharfe
2012-05-09 20:22 ` [PATCH 3/5] blame: use hunk_func(), part 2 René Scharfe
2012-05-09 20:23 ` [PATCH 4/5] blame: factor out helper for calling xdi_diff() René Scharfe
2012-05-09 20:24 ` [PATCH 5/5] xdiff: remove emit_func() and xdi_diff_hunks() René Scharfe
2012-05-18 8:28 ` [PATCH 0/5] xdiff: replace emit_func() with type-safe Thomas Rast
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.