5

How can we ignore coding convention while generating diff using svn?

To elaborate, I do not want to distinguish between the following two coding styles

while (variableIter.hasNext())
{
    lModel = variableIter.next();
}

AND

while (variableIter.hasNext()) {
    lModel = variableIter
   .next();
}

If I run a svn diff, I'll get the following diff:

 -            while (variableIter.hasNext())
 -            {
 -                lModel = variableIter.next();
 +            while (variableIter.hasNext()) {
 +               lModel = variableIter
 +               .next();

But I do not want this to be part of the diff. I'd like svn to ignore this kind of coding style differences. So, is there any option in svn which can help me do this? OR is there a script or something I could run on the svn generated diff to spit out only real changes and not the coding style changes?

TIA

1

2 Answers 2

1

I don't know if svn has a builtin function to do that. Anyway you could use some tool to uniformily indent your code before submitting, like the indent tool for C (http://www.gnu.org/software/indent/).

Or you can try to launch the diff with this option: svn diff -x -w

Sign up to request clarification or add additional context in comments.

8 Comments

The thing is the code that I had checked out was very poorly formatted and I used eclipse to format it properly. Now I need to send in the diff for code-review and I can't send in the entire diff with these coding-style differences as it runs into a couple thousand lines. I just want to send in diff corresponding to actual changes in the code that I have made. Hope this explains the exact problem I'm facing right now.
@texens: try to check svn diff -x -w. It should ignore white spaces and endlines.
@texens - I understand, that my advise is too late but never mix refactoring & reformatting with anything else in a single commit. Moreover, the "poorly formatted" code that you've changed using Eclipse automatic formatting tool could have carried additional semantics that you've destroyed. And yes, take previous revision, apply formatting only, commit, then apply your changes and commit again. Don't hack Subversion :)
@0verbose: Yes, that was the first thing I tried. I also tried -x --ignore-eol-style. But unfortunately none of them seem to do what I want. This is perhaps due to the fact that svn diff compares character to character on a per line basis. And when the characters move from one line to another (which is the case in the current question), there is hardly any way you can ignore it. Maybe, we need to have a script or a third party application to do the aforementioned job as I can't see how svn diff can do this job due to the constraints put by its design.
@bobah: Yes, I have realized that, the hard way :| I have a diff file 9000 lines long and I'm going to have to travel through the whole diff file and manually delete the unwanted differences that have been generated by svn diff due to the difference in coding-style :(
|
0

I can't help with the diff produced directly by subversion.

But once you realize the differences you are seeing are formatting related, then you might swith to an alternative diff'ing tools. See our Smart Differencer tools. These tools are language-specific. They work by parsing the language and build abstract syntax trees, and then comparing the trees. That makes them completely whitespace (and comment) insenstitive; reformatting the code doesn't show up as a difference. The diffs are reported as language elements (operand, expression, statement, declaration, block, method, class, ...) and editing actions (move, delete, insert, copy, rename-variable-within block and are precise to the start line/column and end line/column.

We presently have SmartDifferencers for many languages, including C, C++, C#, Java, JavaScript, PHP.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.