git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vadim Zeitlin <vz-git@zeitlins.org>
To: git@vger.kernel.org
Subject: Re: [PATCH] Avoid false positives in label detection in cpp diff hunk header regex.
Date: Sat, 23 Mar 2013 09:48:30 +0000 (UTC)	[thread overview]
Message-ID: <loom.20130323T101131-456@post.gmane.org> (raw)
In-Reply-To: m2y5de34bz.fsf@linux-m68k.org

Andreas Schwab <schwab <at> linux-m68k.org> writes:

> Vadim Zeitlin <vz-git <at> zeitlins.org> writes:
> 
> >   "!^[ \t]*[A-Za-z_][A-Za-z_0-9]+[ \t]*:([^:]|$)\n"
> 
> That would fail to match single-character identifiers.

 Oops, yes, you're right, of course, sorry. I have no idea why did I write
that we needed to change this "*" to "+", the only explanation I see is that
it was simply too late at night when I did it. So the final version of the
exclusion regex is

	"!^[ \t]*[A-Za-z_][A-Za-z_0-9]*[ \t]*:([^:]|$)\n"


 But I feel like I'm still missing something about what is going on here.
Because after looking carefully at the (positive) regex for matching function
and method names, which is

	"^([A-Za-z_][A-Za-z_0-9]*([ \t*]+[A-Za-z_][A-Za-z_0-9]*"
	"([ \t]*::[ \t]*[^[:space:]]+)?){1,}[ \t]*\\([^;]*)$\n"

(split over 2 lines for readability), I actually don't understand how does it
manage to match my declaration. Yet match it does, I do get

@@ -438,6 +438,10 @@ firebird_statement_backend::execute(int number)

in my diff. But how is this possible? The "[ \t*]+" part has nowhere to match
but between "int" and "number" but it can't match there because there must be
only alphanumeric characters before it. Yet, not only it does match but if I
test with GNU grep -E, it matches too (after replacing "\\(" with just "\("
and removing "\n"). However if I test with perl or "sed -r", it does *not*
match. Can anyone see what's going on here?


 FWIW I've started looking into this because I thought that the current
regex wouldn't detect something like

	foo::nested_type foo::method()

as a start of a method. However it does detect this just fine as well which
I can't understand at all. I'm out of lame excuses (it's not too late here
yet...) so I just hope that I'm missing something about the way Git creates
hunk headers and not some obvious problem with the regex itself because
I've been staring at it for half an hour but still can't see how does it
manage to match here. Could anyone who does see it please explain?

 Thanks in advance,
VZ

      reply	other threads:[~2013-03-23  9:49 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-22 13:43 [PATCH] Avoid false positives in label detection in cpp diff hunk header regex Vadim Zeitlin
2013-03-22 15:02 ` Junio C Hamano
2013-03-22 17:27   ` Vadim Zeitlin
2013-03-22 21:55   ` Johannes Sixt
2013-03-22 22:32     ` Junio C Hamano
2013-03-22 23:11       ` Johannes Sixt
2013-03-23  0:38         ` Vadim Zeitlin
2013-03-23  8:31           ` Andreas Schwab
2013-03-23  9:48             ` Vadim Zeitlin [this message]

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=loom.20130323T101131-456@post.gmane.org \
    --to=vz-git@zeitlins.org \
    --cc=git@vger.kernel.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).