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

texens
  • 3,277
  • 3
  • 19
  • 21
  • 2
    possible duplicate of [Semantic Diff Utilities](http://stackoverflow.com/questions/523307/semantic-diff-utilities) – Greg Hewgill Mar 14 '11 at 07:55

2 Answers2

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

Heisenbug
  • 37,414
  • 27
  • 126
  • 181
  • 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 Mar 14 '11 at 08:04
  • 1
    @texens: try to check svn diff -x -w. It should ignore white spaces and endlines. – Heisenbug Mar 14 '11 at 08:09
  • 3
    @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 :) – bobah Mar 14 '11 at 08:23
  • @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. – texens Mar 14 '11 at 08:26
  • @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 :( – texens Mar 14 '11 at 08:28
  • @texens. So why don't you reformat all your source files and then reimported to eclipse already formatted before committing? – Heisenbug Mar 14 '11 at 08:28
  • @0verbose: I can't format the svn codebase as it is used by dozens of people. If I push in changes (even if it is just formatting changes), I'll end up receiving a ton of emails asking me for justification for making changes across so many files. Definitely not something I'd like to do right away :| – texens Mar 14 '11 at 08:35
  • @texens: if you can't do that don't try to reformat anything. If you don't like coding styles used by your team, let complain about that. It's called convetion because it must be accepted by all programmers involved. – Heisenbug Mar 14 '11 at 08:47
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.

Ira Baxter
  • 88,629
  • 18
  • 158
  • 311