Re: [PATCH] Avoid false positives in label detection in cpp diff hunk header regex.
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Mar 22, 2013, 15:02 UTC
- Message-ID
- <7vehf78olw.fsf@alter.siamese.dyndns.org>
- In-Reply-To
- <loom.20130322T144107-601@post.gmane.org>
Vadim Zeitlin <vz-git@zeitlins.org> writes:
Show 25 quoted lines
> A C++ method start such as
>
> void
> foo::bar()
>
> wasn't recognized by cpp diff driver as it mistakenly included "foo::bar" as a
> label. However the colon in a label can't be followed by another colon, so
> recognize this case specially to correctly detect C++ methods using this style.
>
> Signed-off-by: Vadim Zeitlin <vz-git@zeitlins.org>
> ---
> userdiff.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/userdiff.c b/userdiff.c
> index ea43a03..9415586 100644
> --- a/userdiff.c
> +++ b/userdiff.c
> @@ -125,7 +125,7 @@ PATTERNS("tex",
> "^(\\\\((sub)*section|chapter|part)\\*{0,1}\\{.*)$",
> "\\\\[a-zA-Z@]+|\\\\.|[a-zA-Z0-9\x80-\xff]+"),
> PATTERNS("cpp",
> /* Jump targets or access declarations */
> - "!^[ \t]*[A-Za-z_][A-Za-z_0-9]*:.*$\n"
> + "!^[ \t]*[A-Za-z_][A-Za-z_0-9]*:([^:].*$|$)\n"Hmm. Wouldn't "find a word (possibly after indentation), colon and then either a non-colon or end of line" be sufficient and simpler? iow, something like...
"!^[ \t]*[A-Za-z_][A-Za-z_0-9]*:([^:]|$)"
Show 6 quoted lines
> /* C/++ functions/methods at top level */
> "^([A-Za-z_][A-Za-z_0-9]*([ \t*]+[A-Za-z_][A-Za-z_0-9]*([ \t]*::[
> \t]*[^[:space:]]+)?){1,}[ \t]*\\([^;]*)$\n"
> /* compound type at top level */
> --
> 1.8.2.135.g7b592fa