Subject: Re: [RFC/PATCH] diff: simplify cpp funcname regex

From: René Scharfe <[email-masked]>
Date: Tue, 18 Mar 2014 12:00:17 +0100

Am 18.03.2014 09:02, schrieb Johannes Sixt:
> Cc René; do you have any comments regarding grep --function-context?
>
> Am 3/18/2014 6:24, schrieb Jeff King:
>> On Fri, Mar 14, 2014 at 07:56:46AM +0100, Johannes Sixt wrote:
>>
>>> Consider this code:
>>>
>>>    void above()
>>>    {}
>>>    static int Y;
>>>    static int A;
>>>    int bar()
>>>    {
>>>      return X;
>>>    }
>>>    void below()
>>>    {}
>>
>> Thanks, this example is very helpful.
>>
>>> When you 'git grep --function-context X', then you get this output with
>>> the current pattern, you proposal, and my proposal (file name etc omitted
>>> for brevity):
>>>
>>>    int bar()
>>>    {
>>>      return X;
>>>    }
>>
>> Right, that makes sense to me.
>>
>>> When you 'git grep --function-context Y', what do you want to see? With
>>> the current pattern, and with your pattern that forbids semicolon we get:
>>>
>>>    void above()
>>>    {}
>>>    static int Y;
>>>    static int A;
>>>
>>> and with my simple pattern, which allows semicolon, we get merely
>>>
>>>    static int Y;
>>>
>>> because the line itself is a hunk header (and we do not look back any
>>> further) and the next line is as well. That is not exactly "function
>>> context", and that is what I'm a bit worried about.

In global context there is no "function context", of course, so the 
latter makes sense.

"grep --function-context" is about useful context and its implementation 
piggy-backs on the hunk header definitions.  If those are useful then 
the grep output should be fine as well.  IAW: No worries, go ahead. :)

However, I only use the defaults heuristic (which shows just the Y-line 
as well) and don't know C++, so I my opinion on this matter isn't worth 
that much.

René