Skip to content

Commit 5d93460

Browse files
avargitster
authored andcommitted
xdiff-interface: replace discard_hunk_line() with a flag
Remove the dummy discard_hunk_line() function added in 3b40a09 (diff: avoid generating unused hunk header lines, 2018-11-02) in favor of having a new XDL_EMIT_NO_HUNK_HDR flag, for use along with the two existing and similar XDL_EMIT_* flags. Unlike the recently amended xdiff_emit_line_fn interface which'll be called in a loop in xdl_emit_diff(), the hunk header is only emitted once. It makes more sense to pass this as a flag than provide a dummy callback because that function may be able to skip doing certain work if it knows the caller is doing nothing with the hunk header. It would be possible to do so in the case of -U0 now, but the benefit of doing so is so small that I haven't bothered. But this leaves the door open to that, and more importantly makes the API use more intuitive. The reason we're putting a flag in the gap between 1<<0 and 1<<2 is that the old 1<<1 flag was removed in 907681e (xdiff: drop XDL_EMIT_COMMON, 2016-02-23) without re-ordering the remaining flags. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 22233d4 commit 5d93460

File tree

6 files changed

+9
-19
lines changed

6 files changed

+9
-19
lines changed

diff.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3725,7 +3725,8 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
37253725
xpp.anchors_nr = o->anchors_nr;
37263726
xecfg.ctxlen = o->context;
37273727
xecfg.interhunkctxlen = o->interhunkcontext;
3728-
if (xdi_diff_outf(&mf1, &mf2, discard_hunk_line,
3728+
xecfg.flags = XDL_EMIT_NO_HUNK_HDR;
3729+
if (xdi_diff_outf(&mf1, &mf2, NULL,
37293730
diffstat_consume, diffstat, &xpp, &xecfg))
37303731
die("unable to generate diffstat for %s", one->path);
37313732

@@ -6233,8 +6234,8 @@ static int diff_get_patch_id(struct diff_options *options, struct object_id *oid
62336234

62346235
xpp.flags = 0;
62356236
xecfg.ctxlen = 3;
6236-
xecfg.flags = 0;
6237-
if (xdi_diff_outf(&mf1, &mf2, discard_hunk_line,
6237+
xecfg.flags = XDL_EMIT_NO_HUNK_HDR;
6238+
if (xdi_diff_outf(&mf1, &mf2, NULL,
62386239
patch_id_consume, &data, &xpp, &xecfg))
62396240
return error("unable to generate patch-id diff for %s",
62406241
p->one->path);

diffcore-pickaxe.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,15 @@ static int diff_grep(mmfile_t *one, mmfile_t *two,
5353
memset(&xecfg, 0, sizeof(xecfg));
5454
ecbdata.regexp = regexp;
5555
ecbdata.hit = 0;
56+
xecfg.flags = XDL_EMIT_NO_HUNK_HDR;
5657
xecfg.ctxlen = o->context;
5758
xecfg.interhunkctxlen = o->interhunkcontext;
5859

5960
/*
6061
* An xdiff error might be our "data->hit" from above. See the
6162
* comment for xdiff_emit_line_fn in xdiff-interface.h
6263
*/
63-
ret = xdi_diff_outf(one, two, discard_hunk_line, diffgrep_consume,
64+
ret = xdi_diff_outf(one, two, NULL, diffgrep_consume,
6465
&ecbdata, &xpp, &xecfg);
6566
if (ecbdata.hit)
6667
return 1;

xdiff-interface.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,6 @@ int xdi_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, xdemitconf_t co
126126
return xdl_diff(&a, &b, xpp, xecfg, xecb);
127127
}
128128

129-
void discard_hunk_line(void *priv,
130-
long ob, long on, long nb, long nn,
131-
const char *func, long funclen)
132-
{
133-
}
134-
135129
int xdi_diff_outf(mmfile_t *mf1, mmfile_t *mf2,
136130
xdiff_emit_hunk_fn hunk_fn,
137131
xdiff_emit_line_fn line_fn,

xdiff-interface.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,6 @@ void xdiff_clear_find_func(xdemitconf_t *xecfg);
5353
int git_xmerge_config(const char *var, const char *value, void *cb);
5454
extern int git_xmerge_style;
5555

56-
/*
57-
* Can be used as a no-op hunk_fn for xdi_diff_outf(), since a NULL
58-
* one just sends the hunk line to the line_fn callback).
59-
*/
60-
void discard_hunk_line(void *priv,
61-
long ob, long on, long nb, long nn,
62-
const char *func, long funclen);
63-
6456
/*
6557
* Compare the strings l1 with l2 which are of size s1 and s2 respectively.
6658
* Returns 1 if the strings are deemed equal, 0 otherwise.

xdiff/xdiff.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ extern "C" {
5050

5151
/* xdemitconf_t.flags */
5252
#define XDL_EMIT_FUNCNAMES (1 << 0)
53+
#define XDL_EMIT_NO_HUNK_HDR (1 << 1)
5354
#define XDL_EMIT_FUNCCONTEXT (1 << 2)
5455

5556
/* merge simplification levels */

xdiff/xemit.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,8 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
278278
s1 - 1, funclineprev);
279279
funclineprev = s1 - 1;
280280
}
281-
if (xdl_emit_hunk_hdr(s1 + 1, e1 - s1, s2 + 1, e2 - s2,
281+
if (!(xecfg->flags & XDL_EMIT_NO_HUNK_HDR) &&
282+
xdl_emit_hunk_hdr(s1 + 1, e1 - s1, s2 + 1, e2 - s2,
282283
func_line.buf, func_line.len, ecb) < 0)
283284
return -1;
284285

0 commit comments

Comments
 (0)