Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting svn diff to show C++ function during commit

Whenever I do a commit cycle in svn, I examine the diff when writing my comments. I thought it would be really nice to show the actual function that I made the modifications in when showing the diff.

I checked out this page, which mentioned that the -p option will show the C function that the change is in. When I tried using the -p option with some C++ code, however, it usually returns the access specifier (private, public, protected, etc), which isn't terribly handy.

I did notice that there is a -F option for diff that does the same as -p, but takes a user-specified regex. I was wondering: is there a simple regex to match a C++ function? It seems like that would be all that is necessary to get this to work.

I'd spend some time looking at this myself, but work is in crunch-mode and this seemed like something that a lot of people would find useful, so I figured I'd post it here.

EDIT: I'm not looking for something that's a slam-dunk catch-all regex, but something that would simply find the nearest function definition above the area diff would show. The fact that it would be nowhere near perfect, and somewhat buggy is okay with me. Just as long as it works right maybe like 60% of the time would be a significant productivity improvement IMHO.

like image 453
J. Polfer Avatar asked Jun 17 '09 14:06

J. Polfer


2 Answers

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

Is there a (complex) regex to match a C++. Maybe or could be possible to write one.

But I would say regular expressions neither are easily up to such a task (given you want some kind of excat match) nor are they the right tool for such a task.

Just think about case like this one. How would you handle this stuff.

void (*function(int, void (*)(int)))(int);

func1(int), func2(double); double func3(int);

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

So either hack together some incomplete regex which fits most functions signatures in your code

like image 166
jitter Avatar answered Oct 24 '22 14:10

jitter


If you're going to be applying this only to your commits I would recommend making a habit of adding a commit comment to the function, e.g:

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

to

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

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

like image 23
ilya n. Avatar answered Oct 24 '22 14:10

ilya n.