Skip to content

Commit cde32bf

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent eced93b commit cde32bf

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

xdiff/xemit.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ static long match_func_rec(xdfile_t *xdf, xdemitconf_t const *xecfg, long ri,
121121
return xecfg->find_func(rec, len, buf, sz, xecfg->find_func_priv);
122122
}
123123

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+
124130
struct func_line {
125131
long len;
126132
char buf[80];
@@ -178,16 +184,14 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
178184

179185
/* Appended chunk? */
180186
if (i1 >= xe->xdf1.nrec) {
181-
char dummy[1];
182187
long i2 = xch->i2;
183188

184189
/*
185190
* We don't need additional context if
186191
* a whole function was added.
187192
*/
188193
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))
191195
goto post_context_calculation;
192196
i2++;
193197
}

0 commit comments

Comments
 (0)