Skip to content

Commit

Permalink
xdiff: factor out match_func_rec()
Browse files Browse the repository at this point in the history
Add match_func_rec(), a helper that wraps accessing a record and calling
the appropriate function for checking if it contains a function line.

Signed-off-by: Rene Scharfe <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
rscharfe authored and gitster committed May 31, 2016
1 parent d3621de commit ff2981f
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions xdiff/xemit.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@ static long def_ff(const char *rec, long len, char *buf, long sz, void *priv)
return -1;
}

static long match_func_rec(xdfile_t *xdf, xdemitconf_t const *xecfg, long ri,
char *buf, long sz)
{
const char *rec;
long len = xdl_get_rec(xdf, ri, &rec);
if (!xecfg->find_func)
return def_ff(rec, len, buf, sz, xecfg->find_func_priv);
return xecfg->find_func(rec, len, buf, sz, xecfg->find_func_priv);
}

struct func_line {
long len;
char buf[80];
Expand All @@ -128,17 +138,14 @@ struct func_line {
static long get_func_line(xdfenv_t *xe, xdemitconf_t const *xecfg,
struct func_line *func_line, long start, long limit)
{
find_func_t ff = xecfg->find_func ? xecfg->find_func : def_ff;
long l, size, step = (start > limit) ? -1 : 1;
char *buf, dummy[1];

buf = func_line ? func_line->buf : dummy;
size = func_line ? sizeof(func_line->buf) : sizeof(dummy);

for (l = start; l != limit && 0 <= l && l < xe->xdf1.nrec; l += step) {
const char *rec;
long reclen = xdl_get_rec(&xe->xdf1, l, &rec);
long len = ff(rec, reclen, buf, size, xecfg->find_func_priv);
long len = match_func_rec(&xe->xdf1, xecfg, l, buf, size);
if (len >= 0) {
if (func_line)
func_line->len = len;
Expand Down

0 comments on commit ff2981f

Please sign in to comment.