xdiff: factor out is_func_rec()

Add a helper for checking if a given record is a function line. It frees callers from having to deal with the buffer arguments of match_func_rec(). Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Nov 18, 2017 at 19:04 UTC cde32bf62f74758d3bad685f9fef6aea4e10d106
1 file changed +7 -3
xdiff/xemit.c
+7 -3
@@ -121,6 +121,12 @@ static long match_func_rec(xdfile_t *xdf, xdemitconf_t const *xecfg, long ri,
121 return xecfg->find_func(rec, len, buf, sz, xecfg->find_func_priv);
122 }
123
124 +static int is_func_rec(xdfile_t *xdf, xdemitconf_t const *xecfg, long ri)
125 +{
126 + char dummy[1];
127 + return match_func_rec(xdf, xecfg, ri, dummy, sizeof(dummy)) >= 0;
128 +}
129 +
130 struct func_line {
131 long len;
132 char buf[80];
@@ -178,7 +184,6 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
184
185 /* Appended chunk? */
186 if (i1 >= xe->xdf1.nrec) {
181 - char dummy[1];
187 long i2 = xch->i2;
188
189 /*
@@ -186,8 +191,7 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
191 * a whole function was added.
192 */
193 while (i2 < xe->xdf2.nrec) {
189 - if (match_func_rec(&xe->xdf2, xecfg, i2,
190 - dummy, sizeof(dummy)) >= 0)
194 + if (is_func_rec(&xe->xdf2, xecfg, i2))
195 goto post_context_calculation;
196 i2++;
197 }