git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Jonathan del Strother" <maillist@steelskies.com>
To: "Brandon Casey" <casey@nrlssc.navy.mil>
Cc: "Git Mailing List" <git@vger.kernel.org>,
	"Miklos Vajna" <vmiklos@frugalware.org>,
	"Johannes Schindelin" <Johannes.Schindelin@gmx.de>,
	"Junio C Hamano" <gitster@pobox.com>,
	"Andreas Ericsson" <ae@op5.se>
Subject: Re: [PATCH] xdiff-interface.c: strip newline (and cr) from line before pattern matching
Date: Thu, 2 Oct 2008 11:29:27 +0100	[thread overview]
Message-ID: <57518fd10810020329w257d91f1u3e2205fdaed888eb@mail.gmail.com> (raw)
In-Reply-To: <o5dqpNECJusQHKCTvRWiIqN2ZJ7w-fyC-0vM99FajJIgLsOwP3RNug@cipher.nrlssc.navy.mil>

On Wed, Oct 1, 2008 at 8:28 PM, Brandon Casey <casey@nrlssc.navy.mil> wrote:
> 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>
> ---
>
>
> This could be a little simpler if I knew what was guaranteed from xdiff.
> Such as whether the len elements of line were guaranteed to be newline
> terminated, or be greater than zero. But, the code in def_ff() in xemit.c
> is wrapped in 'if (len > 0)', so..
>
> -brandon
>
>
>  xdiff-interface.c |   12 +++++++++++-
>  1 files changed, 11 insertions(+), 1 deletions(-)
>
> diff --git a/xdiff-interface.c b/xdiff-interface.c
> index 8bab82e..61f5dab 100644
> --- a/xdiff-interface.c
> +++ b/xdiff-interface.c
> @@ -191,12 +191,22 @@ 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 i;
>        int result = -1;
>
> +       /* 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 (!regexec(&reg->re, line_buffer, 2, pmatch, 0)) {
> --
> 1.6.0.2.323.g7c850
>
>

Looks good to me, or at least, works as advertised with a bunch of my
funcname patterns.

  parent reply	other threads:[~2008-10-02 10:30 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-16 23:21 [PATCH] Teach git diff about Objective-C syntax Jonathan del Strother
2008-09-16 23:39 ` Miklos Vajna
2008-09-17  0:07   ` Jonathan del Strother
2008-09-17 10:49     ` Jonathan del Strother
2008-09-17 11:06       ` Johannes Schindelin
2008-09-17 12:26         ` Jonathan del Strother
2008-09-17 13:29           ` Jonathan del Strother
2008-09-17 15:03             ` Andreas Ericsson
2008-09-17 15:31               ` Jonathan del Strother
2008-09-17 15:55                 ` Miklos Vajna
2008-09-17 19:14                   ` Jonathan del Strother
2008-09-17 20:44                     ` Junio C Hamano
2008-09-17 23:30                       ` Jonathan del Strother
2008-09-30 23:46                         ` [PATCH v2] " Jonathan del Strother
2008-10-01  0:52                           ` Brandon Casey
2008-10-01 19:28                             ` [PATCH] xdiff-interface.c: strip newline (and cr) from line before pattern matching Brandon Casey
2008-10-01 20:05                               ` Johannes Schindelin
2008-10-02 10:29                               ` Jonathan del Strother [this message]
2008-10-02 10:40                           ` [PATCH v2] Teach git diff about Objective-C syntax Jonathan del Strother
2008-09-18  6:50                     ` [PATCH] " Andreas Ericsson
2008-09-17 13:37         ` Jonathan del Strother
2008-09-17 14:28           ` Johannes Schindelin
2008-09-17 14:32             ` Jonathan del Strother

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=57518fd10810020329w257d91f1u3e2205fdaed888eb@mail.gmail.com \
    --to=maillist@steelskies.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=ae@op5.se \
    --cc=casey@nrlssc.navy.mil \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=vmiklos@frugalware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).