Skip to content

Commit 3b40a09

Browse files
peffgitster
authored andcommitted
diff: avoid generating unused hunk header lines
Some callers of xdi_diff_outf() do not look at the generated hunk header lines at all. By plugging in a no-op hunk callback, this tells xdiff not to even bother formatting them. This patch introduces a stock no-op callback and uses it with a few callers whose line callbacks explicitly ignore hunk headers (because they look only for +/- lines). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9346d6d commit 3b40a09

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

diff.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3604,8 +3604,8 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
36043604
xpp.anchors_nr = o->anchors_nr;
36053605
xecfg.ctxlen = o->context;
36063606
xecfg.interhunkctxlen = o->interhunkcontext;
3607-
if (xdi_diff_outf(&mf1, &mf2, NULL, diffstat_consume,
3608-
diffstat, &xpp, &xecfg))
3607+
if (xdi_diff_outf(&mf1, &mf2, discard_hunk_line,
3608+
diffstat_consume, diffstat, &xpp, &xecfg))
36093609
die("unable to generate diffstat for %s", one->path);
36103610
}
36113611

diffcore-pickaxe.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ static int diff_grep(mmfile_t *one, mmfile_t *two,
6262
ecbdata.hit = 0;
6363
xecfg.ctxlen = o->context;
6464
xecfg.interhunkctxlen = o->interhunkcontext;
65-
if (xdi_diff_outf(one, two, NULL, diffgrep_consume, &ecbdata, &xpp, &xecfg))
65+
if (xdi_diff_outf(one, two, discard_hunk_line, diffgrep_consume,
66+
&ecbdata, &xpp, &xecfg))
6667
return 0;
6768
return ecbdata.hit;
6869
}

xdiff-interface.c

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

160+
void discard_hunk_line(void *priv,
161+
long ob, long on, long nb, long nn,
162+
const char *func, long funclen)
163+
{
164+
}
165+
160166
int xdi_diff_outf(mmfile_t *mf1, mmfile_t *mf2,
161167
xdiff_emit_hunk_fn hunk_fn,
162168
xdiff_emit_line_fn line_fn,

xdiff-interface.h

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

38+
/*
39+
* Can be used as a no-op hunk_fn for xdi_diff_outf(), since a NULL
40+
* one just sends the hunk line to the line_fn callback).
41+
*/
42+
void discard_hunk_line(void *priv,
43+
long ob, long on, long nb, long nn,
44+
const char *func, long funclen);
45+
3846
/*
3947
* Compare the strings l1 with l2 which are of size s1 and s2 respectively.
4048
* Returns 1 if the strings are deemed equal, 0 otherwise.

0 commit comments

Comments
 (0)