* xfuncname problems with C++
@ 2015-01-02 16:49 Robert Dailey
2015-01-02 17:03 ` Robert Dailey
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Robert Dailey @ 2015-01-02 16:49 UTC (permalink / raw)
To: Git
I have a function like so:
void MyClass::SomeFunction(int someParameter)
{
// Stuff changed in here
}
When I do `git diff` on the file containing this function, I get a
chunk showing some changed code in this function somewhere in the
middle of the body. However, the chunk header shows my root namespace
name in the file instead of the function header:
@@ -144,15 +149,22 @@ namespace Utils
What I expect to see:
@@ -144,15 +149,22 @@ void MyClass::SomeFunction(int someParameter)
I've tried various regular expressions that work in regex testers I
use against this function signature, however they do not work when I
apply them to my config:
[diff "cpp"]
xfuncname =
"^\\s*[\\w_][\\w\\d_]*\\s*.*\\s*[\\w_][\\w\\d_]*\\s*\\(.*\\)\\s*$"
File name is "foo.cpp", I even added it to my git attributes file:
*.cpp diff=cpp
Using the regex above, my chunk headers come back blank. Why is it
showing namespace? How do I make this match the nearest function
header?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: xfuncname problems with C++
2015-01-02 16:49 xfuncname problems with C++ Robert Dailey
@ 2015-01-02 17:03 ` Robert Dailey
2015-01-02 20:31 ` Johannes Sixt
2015-01-02 20:19 ` Jonathan Nieder
2015-01-02 20:25 ` Johannes Sixt
2 siblings, 1 reply; 7+ messages in thread
From: Robert Dailey @ 2015-01-02 17:03 UTC (permalink / raw)
To: Git
On Fri, Jan 2, 2015 at 10:49 AM, Robert Dailey <rcdailey.lists@gmail.com> wrote:
> I have a function like so:
>
> void MyClass::SomeFunction(int someParameter)
> {
> // Stuff changed in here
> }
>
> When I do `git diff` on the file containing this function, I get a
> chunk showing some changed code in this function somewhere in the
> middle of the body. However, the chunk header shows my root namespace
> name in the file instead of the function header:
>
> @@ -144,15 +149,22 @@ namespace Utils
>
> What I expect to see:
>
> @@ -144,15 +149,22 @@ void MyClass::SomeFunction(int someParameter)
>
> I've tried various regular expressions that work in regex testers I
> use against this function signature, however they do not work when I
> apply them to my config:
>
> [diff "cpp"]
> xfuncname =
> "^\\s*[\\w_][\\w\\d_]*\\s*.*\\s*[\\w_][\\w\\d_]*\\s*\\(.*\\)\\s*$"
>
> File name is "foo.cpp", I even added it to my git attributes file:
>
> *.cpp diff=cpp
>
> Using the regex above, my chunk headers come back blank. Why is it
> showing namespace? How do I make this match the nearest function
> header?
Oopsie, I didn't realize the regex must be POSIX compatible. I've
updated the regex to this:
https://www.regex101.com/r/kP3dM6
The test seems to work; however git gives me an error with the regex
when I do a diff:
$ git diff Core
fatal: Invalid regexp to look for hunk header:
^[[:space:]]*[[:word:]_][[:word:][:digit:]_]*[[:space:]]*.*[[:space:]]*[[:word:]_][[:word:][:digit:]_]*[[:space:]]*\(.*\)[[:space:]]*$
Here is how it is stored in my .gitconfig:
[diff "cpp"]
xfuncname =
"^[[:space:]]*[[:word:]_][[:word:][:digit:]_]*[[:space:]]*.*[[:space:]]*[[:word:]_][[:word:][:digit:]_]*[[:space:]]*\\(.*\\)[[:space:]]*$"
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: xfuncname problems with C++
2015-01-02 16:49 xfuncname problems with C++ Robert Dailey
2015-01-02 17:03 ` Robert Dailey
@ 2015-01-02 20:19 ` Jonathan Nieder
2015-01-02 20:25 ` Johannes Sixt
2 siblings, 0 replies; 7+ messages in thread
From: Jonathan Nieder @ 2015-01-02 20:19 UTC (permalink / raw)
To: Robert Dailey; +Cc: Git
Hi,
Robert Dailey wrote:
> I have a function like so:
>
> void MyClass::SomeFunction(int someParameter)
> {
> // Stuff changed in here
> }
>
> When I do `git diff` on the file containing this function, I get a
> chunk showing some changed code in this function somewhere in the
> middle of the body. However, the chunk header shows my root namespace
> name in the file instead of the function header:
>
> @@ -144,15 +149,22 @@ namespace Utils
>
> What I expect to see:
>
> @@ -144,15 +149,22 @@ void MyClass::SomeFunction(int someParameter)
What version of git are you using? Could you give a full copy of the
diff so we can have more context (feeling free to mark parts of it as
CENSORED where appropriate, but keeping leading whitespace and the
first +/- column)?
Thanks,
Jonathan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: xfuncname problems with C++
2015-01-02 16:49 xfuncname problems with C++ Robert Dailey
2015-01-02 17:03 ` Robert Dailey
2015-01-02 20:19 ` Jonathan Nieder
@ 2015-01-02 20:25 ` Johannes Sixt
2 siblings, 0 replies; 7+ messages in thread
From: Johannes Sixt @ 2015-01-02 20:25 UTC (permalink / raw)
To: Robert Dailey; +Cc: Git
Am 02.01.2015 um 17:49 schrieb Robert Dailey:
> I have a function like so:
>
> void MyClass::SomeFunction(int someParameter)
> {
> // Stuff changed in here
> }
>
> When I do `git diff` on the file containing this function, I get a
> chunk showing some changed code in this function somewhere in the
> middle of the body. However, the chunk header shows my root namespace
> name in the file instead of the function header:
>
> @@ -144,15 +149,22 @@ namespace Utils
>
> What I expect to see:
>
> @@ -144,15 +149,22 @@ void MyClass::SomeFunction(int someParameter)
>
> I've tried various regular expressions that work in regex testers I
> use against this function signature, however they do not work when I
> apply them to my config:
>
> [diff "cpp"]
> xfuncname =
> "^\\s*[\\w_][\\w\\d_]*\\s*.*\\s*[\\w_][\\w\\d_]*\\s*\\(.*\\)\\s*$"
>
> File name is "foo.cpp", I even added it to my git attributes file:
>
> *.cpp diff=cpp
>
> Using the regex above, my chunk headers come back blank. Why is it
> showing namespace? How do I make this match the nearest function
> header?
>
Is the line that contains 'void MyClass::...' before line 149? Does the
word 'void' begin at the left-most column?
-- Hannes
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: xfuncname problems with C++
2015-01-02 17:03 ` Robert Dailey
@ 2015-01-02 20:31 ` Johannes Sixt
2015-01-02 21:27 ` Robert Dailey
0 siblings, 1 reply; 7+ messages in thread
From: Johannes Sixt @ 2015-01-02 20:31 UTC (permalink / raw)
To: Robert Dailey, Git
Am 02.01.2015 um 18:03 schrieb Robert Dailey:
> On Fri, Jan 2, 2015 at 10:49 AM, Robert Dailey <rcdailey.lists@gmail.com> wrote:
>> I have a function like so:
>>
>> void MyClass::SomeFunction(int someParameter)
>> {
>> // Stuff changed in here
>> }
>>
>> When I do `git diff` on the file containing this function, I get a
>> chunk showing some changed code in this function somewhere in the
>> middle of the body. However, the chunk header shows my root namespace
>> name in the file instead of the function header:
>>
>> @@ -144,15 +149,22 @@ namespace Utils
>>
>> What I expect to see:
>>
>> @@ -144,15 +149,22 @@ void MyClass::SomeFunction(int someParameter)
>>
>> I've tried various regular expressions that work in regex testers I
>> use against this function signature, however they do not work when I
>> apply them to my config:
>>
>> [diff "cpp"]
>> xfuncname =
>> "^\\s*[\\w_][\\w\\d_]*\\s*.*\\s*[\\w_][\\w\\d_]*\\s*\\(.*\\)\\s*$"
>>
>> File name is "foo.cpp", I even added it to my git attributes file:
>>
>> *.cpp diff=cpp
>>
>> Using the regex above, my chunk headers come back blank. Why is it
>> showing namespace? How do I make this match the nearest function
>> header?
>
> Oopsie, I didn't realize the regex must be POSIX compatible. I've
> updated the regex to this:
> https://www.regex101.com/r/kP3dM6
>
> The test seems to work; however git gives me an error with the regex
> when I do a diff:
>
> $ git diff Core
> fatal: Invalid regexp to look for hunk header:
> ^[[:space:]]*[[:word:]_][[:word:][:digit:]_]*[[:space:]]*.*[[:space:]]*[[:word:]_][[:word:][:digit:]_]*[[:space:]]*\(.*\)[[:space:]]*$
>
> Here is how it is stored in my .gitconfig:
>
> [diff "cpp"]
> xfuncname =
> "^[[:space:]]*[[:word:]_][[:word:][:digit:]_]*[[:space:]]*.*[[:space:]]*[[:word:]_][[:word:][:digit:]_]*[[:space:]]*\\(.*\\)[[:space:]]*$"
>
Perhaps there is a pair of parentheses missing that capture text for the
hunk header? I you intended that to be the part inside \(...\), then
that is wrong. Use unescapted parentheses.
There are two catch-all .* in your pattern. That is very suspicious,
particularly since the first one is outside the meant-to-be capturing
parentheses.
-- Hannes
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: xfuncname problems with C++
2015-01-02 20:31 ` Johannes Sixt
@ 2015-01-02 21:27 ` Robert Dailey
2015-01-02 22:05 ` Jonathan Nieder
0 siblings, 1 reply; 7+ messages in thread
From: Robert Dailey @ 2015-01-02 21:27 UTC (permalink / raw)
To: Johannes Sixt; +Cc: Git
On Fri, Jan 2, 2015 at 2:31 PM, Johannes Sixt <j6t@kdbg.org> wrote:
> Am 02.01.2015 um 18:03 schrieb Robert Dailey:
>> On Fri, Jan 2, 2015 at 10:49 AM, Robert Dailey <rcdailey.lists@gmail.com> wrote:
>>> I have a function like so:
>>>
>>> void MyClass::SomeFunction(int someParameter)
>>> {
>>> // Stuff changed in here
>>> }
>>>
>>> When I do `git diff` on the file containing this function, I get a
>>> chunk showing some changed code in this function somewhere in the
>>> middle of the body. However, the chunk header shows my root namespace
>>> name in the file instead of the function header:
>>>
>>> @@ -144,15 +149,22 @@ namespace Utils
>>>
>>> What I expect to see:
>>>
>>> @@ -144,15 +149,22 @@ void MyClass::SomeFunction(int someParameter)
>>>
>>> I've tried various regular expressions that work in regex testers I
>>> use against this function signature, however they do not work when I
>>> apply them to my config:
>>>
>>> [diff "cpp"]
>>> xfuncname =
>>> "^\\s*[\\w_][\\w\\d_]*\\s*.*\\s*[\\w_][\\w\\d_]*\\s*\\(.*\\)\\s*$"
>>>
>>> File name is "foo.cpp", I even added it to my git attributes file:
>>>
>>> *.cpp diff=cpp
>>>
>>> Using the regex above, my chunk headers come back blank. Why is it
>>> showing namespace? How do I make this match the nearest function
>>> header?
>>
>> Oopsie, I didn't realize the regex must be POSIX compatible. I've
>> updated the regex to this:
>> https://www.regex101.com/r/kP3dM6
>>
>> The test seems to work; however git gives me an error with the regex
>> when I do a diff:
>>
>> $ git diff Core
>> fatal: Invalid regexp to look for hunk header:
>> ^[[:space:]]*[[:word:]_][[:word:][:digit:]_]*[[:space:]]*.*[[:space:]]*[[:word:]_][[:word:][:digit:]_]*[[:space:]]*\(.*\)[[:space:]]*$
>>
>> Here is how it is stored in my .gitconfig:
>>
>> [diff "cpp"]
>> xfuncname =
>> "^[[:space:]]*[[:word:]_][[:word:][:digit:]_]*[[:space:]]*.*[[:space:]]*[[:word:]_][[:word:][:digit:]_]*[[:space:]]*\\(.*\\)[[:space:]]*$"
>>
>
> Perhaps there is a pair of parentheses missing that capture text for the
> hunk header? I you intended that to be the part inside \(...\), then
> that is wrong. Use unescapted parentheses.
>
> There are two catch-all .* in your pattern. That is very suspicious,
> particularly since the first one is outside the meant-to-be capturing
> parentheses.
My regex actually is intended to not have any capture groups. Is that
required? The documentation I read didn't mention any requirements, so
I am not sure.
The 'void' does not start on the leftmost column, due to tabbing there
can be any number of whitespace (the regex should account for this).
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: xfuncname problems with C++
2015-01-02 21:27 ` Robert Dailey
@ 2015-01-02 22:05 ` Jonathan Nieder
0 siblings, 0 replies; 7+ messages in thread
From: Jonathan Nieder @ 2015-01-02 22:05 UTC (permalink / raw)
To: Robert Dailey; +Cc: Johannes Sixt, Git
Robert Dailey wrote:
> The 'void' does not start on the leftmost column, due to tabbing there
> can be any number of whitespace (the regex should account for this).
Ah, that explains it. The default C++ pattern assumes the 'void'
starts at the leftmost column, so that the funcname header represents
whatever top-level construct forms the context (e.g., "class foo {").
(Jump targets or access declarations)
!^[ \t]*[A-Za-z_][A-Za-z_0-9]*:[[:space:]]*($|/[/*])
(functions/methods, variables, and compounds at top level)
^((::[[:space:]]*)?[A-Za-z_].*)$
Thanks,
Jonathan
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2015-01-02 22:06 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-02 16:49 xfuncname problems with C++ Robert Dailey
2015-01-02 17:03 ` Robert Dailey
2015-01-02 20:31 ` Johannes Sixt
2015-01-02 21:27 ` Robert Dailey
2015-01-02 22:05 ` Jonathan Nieder
2015-01-02 20:19 ` Jonathan Nieder
2015-01-02 20:25 ` Johannes Sixt
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).