Getting svn diff to display C ++ function during commit

Whenever I execute a commit cycle in svn, I learn diff when writing my comments. I thought it would be very nice to show the actual function in which I made changes when I showed diff.

I checked this page , which said that the -p option would show the C function that the change is in. When I tried using the -p option with some C ++ code, however it usually returns an access specifier (private, public, secure, etc.), which is not very convenient.

I noticed that there is the -F option for diff, which does the same thing as -p, but accepts a user-defined regular expression. I was wondering: is there a simple regular expression to match a C ++ function? This seems to be all that is needed to make it work.

I would spend some time on this, but working in crunch mode, and it seemed like something that many people might find useful, so I decided I posted it here.

EDIT: I'm not looking for something that would be cleverly regx, but something that just finds the closest function definition over the diff scope. The fact that he will not be close to perfection anywhere, and something is bad, everything is fine with me. As long as this works correctly, perhaps 60% of the time will be a significant improvement in IMHO performance.

+6
c ++ linux regex svn diff
source share
4 answers

Is there a simple regex to match a C ++ function? Not.

Is there a (complex) regex for C ++ matching. Maybe, or could write it.

But I would say that regular expressions cannot be easy before such a task (if you want some kind of excat match), and they are not a suitable tool for such a task.

Just think of a case like this. How would you handle this.

void (*function(int, void (*)(int)))(int); func1(int), func2(double); double func3(int); 

The only real solution is to use the parser with yacc / lex. Which for your use case, of course, does nothing.

So either crack some incomplete regular expression that matches most function signatures in your code

+3
source share

If you intend to apply this only to your commits, I would recommend making it a habit to add a commit comment to a function, for example:

 void something () { ... some thing = 1; ... } 

to

 void something () // last change by me: a better value for thing { ... some thing = 2; ... } 

will display the function and your comment with changes for you. As a bonus, other people will be able to understand what you are doing.

+2
source share

TortoiseSVN uses the following regular expressions to support autocomplete in its commit dialog for C ++ files:

 .h, .hpp, .hxx = ^\s*(?:class|struct)\s+([\w_]+)|\W([\w_]+)\( .cpp, .c, .cxx = \W(([\w_]+)::([\w_]+))|\W([\w_]+)\( 

I do not know how accurate they are.

+1
source share

I do not know the option in SVN that will do this, and the regex-based solution is likely to be one or more of the following:

  • a nightmare for coding and support, with many special cases
  • incorrect and missing a few valid C ++ functions

To do this, you need some kind of parser. Technically, you can list all possible cases of regular expressions, but writing a parser is the right way to solve this problem. If you have time to overturn your decision, I would take a look at ANTLR, they have several C / C ++ grammars available on this page:

ANTLR Grammar Lists

+1
source share

All Articles