git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Avoid false positives in label detection in cpp diff hunk header regex.

From
VZVadim Zeitlin <vz-git@zeitlins.org>
Date
Mar 23, 2013, 09:48 UTC
Message-ID
<loom.20130323T101131-456@post.gmane.org>
In-Reply-To
<m2y5de34bz.fsf@linux-m68k.org>
Andreas Schwab <schwab <at> linux-m68k.org> writes:
Show 5 quoted lines
> 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
Previous: Andreas Schwab
Message 9 of 9 in “Avoid false positives in label detection in cpp diff hunk header regex.”
  1. Avoid false positives in label detection in cpp diff hunk header regex.Vadim Zeitlin, Mar 22, 2013
  2. Junio C HamanoMar 22, 2013
  3. Vadim ZeitlinMar 22, 2013
  4. Johannes SixtMar 22, 2013
  5. Junio C HamanoMar 22, 2013
  6. Johannes SixtMar 22, 2013
  7. Vadim ZeitlinMar 23, 2013
  8. Andreas SchwabMar 23, 2013
  9. Vadim ZeitlinMar 23, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.