aboutsummaryrefslogtreecommitdiff
path: root/xdiff-interface.c
diff options
context:
space:
mode:
authorBrandon Casey <casey@nrlssc.navy.mil>2008-10-01 14:28:26 -0500
committerJunio C Hamano <gitster@pobox.com>2008-10-16 08:31:56 -0700
commit563d5a2c84fb5daf77dd8bfe569e92566a8fd52b (patch)
tree36c847c21a3e882bd2db3ef33c83722bf11c8518 /xdiff-interface.c
parentb19d288b4d440c76348b519d06a4ed7b62c93611 (diff)
downloadgit-563d5a2c84fb5daf77dd8bfe569e92566a8fd52b.tar.gz
git-563d5a2c84fb5daf77dd8bfe569e92566a8fd52b.tar.xz
xdiff-interface.c: strip newline (and cr) from line before pattern matching
POSIX doth sayeth: "In the regular expression processing described in IEEE Std 1003.1-2001, the <newline> is regarded as an ordinary character and both a period and a non-matching list can match one. ... Those utilities (like grep) that do not allow <newline>s to match are responsible for eliminating any <newline> from strings before matching against the RE." Thus far git has not been removing the trailing newline from strings matched against regular expression patterns. This has the effect that (quoting Jonathan del Strother) "... a line containing just 'FUNCNAME' (terminated by a newline) will be matched by the pattern '^(FUNCNAME.$)' but not '^(FUNCNAME$)'", and more simply not '^FUNCNAME$'. Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'xdiff-interface.c')
-rw-r--r--xdiff-interface.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/xdiff-interface.c b/xdiff-interface.c
index 2c81f40cb..3bf83f81e 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(&reg->re,