Skip to content

Commit ef2e62f

Browse files
bdowninggitster
authored andcommitted
Allow alternate "low-level" emit function from xdl_diff
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>
1 parent 9ccd0a8 commit ef2e62f

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
lines changed

xdiff/xdiff.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ typedef struct s_xdemitconf {
8787
unsigned long flags;
8888
find_func_t find_func;
8989
void *find_func_priv;
90+
void (*emit_func)();
9091
} xdemitconf_t;
9192

9293
typedef struct s_bdiffparam {

xdiff/xdiffi.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,8 @@ int xdl_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
538538
xdemitconf_t const *xecfg, xdemitcb_t *ecb) {
539539
xdchange_t *xscr;
540540
xdfenv_t xe;
541+
emit_func_t ef = xecfg->emit_func ?
542+
(emit_func_t)xecfg->emit_func : xdl_emit_diff;
541543

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

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

556558
xdl_free_script(xscr);
557559
xdl_free_env(&xe);

xdiff/xemit.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

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

3231

3332

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

6463
for (xchp = xscr, xch = xscr->next; xch; xchp = xch, xch = xch->next)

xdiff/xemit.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
#define XEMIT_H
2525

2626

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

30+
xdchange_t *xdl_get_hunk(xdchange_t *xscr, xdemitconf_t const *xecfg);
2831
int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
2932
xdemitconf_t const *xecfg);
3033

0 commit comments

Comments
 (0)