Re: xfuncname problems with C++
- From
- Robert Dailey <rcdailey.lists@gmail.com>
- Date
- Jan 2, 2015, 17:03 UTC
- Message-ID
- <CAHd499C_Z_npG3ibv_gJSU7kqrT6=DRCV8TU9_sjz9zzQ7vC-Q@mail.gmail.com>
- In-Reply-To
- <CAHd499Cn8C51i_+Dm4h_U4X_Jc-nhNMjoufiZRdn5LGxFqD_HA@mail.gmail.com>
On Fri, Jan 2, 2015 at 10:49 AM, Robert Dailey <rcdailey.lists@gmail.com> wrote:
Show 33 quoted lines
> 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:]]*$"