diff options
-rwxr-xr-x | t/t4018-diff-funcname.sh | 2 | ||||
-rw-r--r-- | xdiff-interface.c | 12 |
2 files changed, 12 insertions, 2 deletions
diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh index 40a805a866..398bf4b5d8 100755 --- a/t/t4018-diff-funcname.sh +++ b/t/t4018-diff-funcname.sh @@ -69,7 +69,7 @@ test_expect_success 'last regexp must not be negated' ' grep "fatal: Last expression must not be negated:" ' -test_expect_failure 'pattern which matches to end of line' ' +test_expect_success 'pattern which matches to end of line' ' git config diff.java.funcname "Beer$" && git diff --no-index Beer.java Beer-correct.java | grep "^@@.*@@ Beer" diff --git a/xdiff-interface.c b/xdiff-interface.c index 2c81f40cb6..3bf83f81e3 100644 --- a/xdiff-interface.c +++ b/xdiff-interface.c @@ -179,11 +179,21 @@ struct ff_regs { static long ff_regexp(const char *line, long len, char *buffer, long buffer_size, void *priv) { - char *line_buffer = xstrndup(line, len); /* make NUL terminated */ + char *line_buffer; struct ff_regs *regs = priv; regmatch_t pmatch[2]; int result = 0, i; + /* Exclude terminating newline (and cr) from matching */ + if (len > 0 && line[len-1] == '\n') { + if (len > 1 && line[len-2] == '\r') + len -= 2; + else + len--; + } + + line_buffer = xstrndup(line, len); /* make NUL terminated */ + for (i = 0; i < regs->nr; i++) { struct ff_reg *reg = regs->array + i; if (reg->negate ^ !!regexec(®->re, |