Skip to content

Commit

Permalink
Allow alternate "low-level" emit function from xdl_diff
Browse files Browse the repository at this point in the history
For some users (e.g. git blame), getting textual patch output is just
extra work, as they can get all the information they need from the low-
level diff structures.  Allow for an alternate low-level emit function
to be defined to allow bypassing the textual patch generation; set
xemitconf_t's emit_func member to enable this.

The (void (*)()) type is pretty ugly, but the alternative would be to
include most of the private xdiff headers in xdiff.h to get the types
required for the "proper" function prototype.  Also, a (void *) won't
work, as ANSI C doesn't allow a function pointer to be cast to an
object pointer.

Signed-off-by: Brian Downing <bdowning@lavos.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
bdowning authored and gitster committed Oct 25, 2008
1 parent 9ccd0a8 commit ef2e62f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions xdiff/xdiff.h
Expand Up @@ -87,6 +87,7 @@ typedef struct s_xdemitconf {
unsigned long flags; unsigned long flags;
find_func_t find_func; find_func_t find_func;
void *find_func_priv; void *find_func_priv;
void (*emit_func)();
} xdemitconf_t; } xdemitconf_t;


typedef struct s_bdiffparam { typedef struct s_bdiffparam {
Expand Down
4 changes: 3 additions & 1 deletion xdiff/xdiffi.c
Expand Up @@ -538,6 +538,8 @@ int xdl_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
xdemitconf_t const *xecfg, xdemitcb_t *ecb) { xdemitconf_t const *xecfg, xdemitcb_t *ecb) {
xdchange_t *xscr; xdchange_t *xscr;
xdfenv_t xe; xdfenv_t xe;
emit_func_t ef = xecfg->emit_func ?
(emit_func_t)xecfg->emit_func : xdl_emit_diff;


if (xdl_do_diff(mf1, mf2, xpp, &xe) < 0) { if (xdl_do_diff(mf1, mf2, xpp, &xe) < 0) {


Expand All @@ -551,7 +553,7 @@ int xdl_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
return -1; return -1;
} }
if (xscr) { if (xscr) {
if (xdl_emit_diff(&xe, xscr, ecb, xecfg) < 0) { if (ef(&xe, xscr, ecb, xecfg) < 0) {


xdl_free_script(xscr); xdl_free_script(xscr);
xdl_free_env(&xe); xdl_free_env(&xe);
Expand Down
3 changes: 1 addition & 2 deletions xdiff/xemit.c
Expand Up @@ -27,7 +27,6 @@


static long xdl_get_rec(xdfile_t *xdf, long ri, char const **rec); static long xdl_get_rec(xdfile_t *xdf, long ri, char const **rec);
static int xdl_emit_record(xdfile_t *xdf, long ri, char const *pre, xdemitcb_t *ecb); static int xdl_emit_record(xdfile_t *xdf, long ri, char const *pre, xdemitcb_t *ecb);
static xdchange_t *xdl_get_hunk(xdchange_t *xscr, xdemitconf_t const *xecfg);






Expand Down Expand Up @@ -58,7 +57,7 @@ static int xdl_emit_record(xdfile_t *xdf, long ri, char const *pre, xdemitcb_t *
* Starting at the passed change atom, find the latest change atom to be included * Starting at the passed change atom, find the latest change atom to be included
* inside the differential hunk according to the specified configuration. * inside the differential hunk according to the specified configuration.
*/ */
static xdchange_t *xdl_get_hunk(xdchange_t *xscr, xdemitconf_t const *xecfg) { xdchange_t *xdl_get_hunk(xdchange_t *xscr, xdemitconf_t const *xecfg) {
xdchange_t *xch, *xchp; xdchange_t *xch, *xchp;


for (xchp = xscr, xch = xscr->next; xch; xchp = xch, xch = xch->next) for (xchp = xscr, xch = xscr->next; xch; xchp = xch, xch = xch->next)
Expand Down
3 changes: 3 additions & 0 deletions xdiff/xemit.h
Expand Up @@ -24,7 +24,10 @@
#define XEMIT_H #define XEMIT_H




typedef int (*emit_func_t)(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
xdemitconf_t const *xecfg);


xdchange_t *xdl_get_hunk(xdchange_t *xscr, xdemitconf_t const *xecfg);
int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb, int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
xdemitconf_t const *xecfg); xdemitconf_t const *xecfg);


Expand Down

0 comments on commit ef2e62f

Please sign in to comment.