summaryrefslogtreecommitdiff
path: root/xdiff/xemit.c
diff options
context:
space:
mode:
authorLibravatar René Scharfe <l.s.r@web.de>2016-05-28 16:58:47 +0200
committerLibravatar Junio C Hamano <gitster@pobox.com>2016-05-31 13:08:56 -0700
commitff2981f724c617d377229666e6deae257de5e239 (patch)
tree3c26e1ff7cd12d525c3f031e6b2a9149ac21ef6e /xdiff/xemit.c
parentt4051: rewrite, add more tests (diff)
downloadtgif-ff2981f724c617d377229666e6deae257de5e239.tar.xz
xdiff: factor out match_func_rec()
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 <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'xdiff/xemit.c')
-rw-r--r--xdiff/xemit.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/xdiff/xemit.c b/xdiff/xemit.c
index 993724b11c..0c8763710d 100644
--- a/xdiff/xemit.c
+++ b/xdiff/xemit.c
@@ -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];
@@ -128,7 +138,6 @@ 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];
@@ -136,9 +145,7 @@ static long get_func_line(xdfenv_t *xe, xdemitconf_t const *xecfg,
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;