views:

194

answers:

6

What source control products have a "diff" facility that ignores white space, braces, etc., in calculating the difference between checked-in versions? I seem to remember that Clearcase's diff did this but Visual SourceSafe (or at least the version I used) did not.

The reason I ask is probably pretty typical. Four perfectly reasonable developers on a team have four entirely different ways of formatting their code. Upon checking out the code last changed by someone else, each will immediately run some kind of program or editor macro to format things the way they like. They make actual code changes. They check-in their changes. They go on vacation. Two days later that program, which had been running fine for two years, blows up. The developer assigned to the bug does a diff between versions and finds 204 differences, only 3 of which are of any significance, because the diff algorithm is lame.

Yes, you can have coding standards. Most everyone finds them dreadful. A solution where everyone can have their cake and eat it too seems far more preferable.

=========

EDIT: Thanks to everyone for some great suggestions.

What I take away from this is:

(1) A source control system with plug-in type diffs is preferable.

(2) Find a diff with suitable options.

(3) Use a good source formatting program and settle on a check-in standard.

Sounds like a plan. Thanks again.

+2  A: 

Maybe you should choose one format and run some indentation tool before checking in so that each person can check out, reformat to his/her own preferences, do the changes, reformat back to the official standard and then check in?

A couple of extra steps but they already use indentation tools when working. Maybe it can be a triggered check-in script?

Edit: this would perhaps also solve the brace problem.

(I haven't tried this solution myself, hence the "perhapes" and "maybes", but I have been in projects with the same problems, and it is a pain to try to go through diffs with hundreds of irrelevant changes that are not limited to whitespace, but includes the formatting itself.)

FeatureCreep
No, just get your team on the same page. http://stackoverflow.com/questions/903754/do-you-still-limit-line-length-in-code/904008#904008
bendin
@bendin, what do you mean?
FeatureCreep
A: 

Subversion apparently supports this, either natively in the latest versions, or by using an alternate diff like Gnu Diff.

Robert Harvey
+2  A: 

Git does have these options:

  • --ignore-space-at-eol

    Ignore changes in whitespace at EOL.

  • -b, --ignore-space-change

    Ignore changes in amount of whitespace. This ignores whitespace at line end, and considers all other sequences of one or more whitespace characters to be equivalent.

  • -w, --ignore-all-space

    Ignore whitespace when comparing lines. This ignores differences even if one line has whitespace where the other line has none.

I am not sure if brace changes can be ignored using Git's diff.

If it is C/C++ code, you can define Astyle rules and then convert the source code's brace style to the one that you want, using Astyle. A git diff will then produce sane output.

Alan Haggai Alavi
A: 

Beyond Compare does this (and much much more) and you can integrate it either in Subversion or Sourcesafe as an external diff tool.

A: 

As explained in Is it possible for git-merge to ignore line-ending differences?, it is more a matter to associate the right diff tool to your favorite VCS, rather than to rely on the right VCS option (even if Git does have some options regarding whitespace, like the one mentioned in Alan's answer, it will always be not as complete as one would like).

DiffMerge is the more complete on those "ignore" options, as it can not only ignore spaces but also other "variations" based on the programming language used in a given file.

VonC
+2  A: 

Choose one (dreadful) coding standard, write it down in some official coding standards document, and get on with your life, messing with whitespace is not productive work.

And remember you are a professional developer, it's your job to get the project done, changing anything in the code because of a personal style preference hurts the project - it wont only make diff-ing more difficult, it can also introduce hard to find problems if your source formatter or compiler has bugs (and your fancy diff tool won't save you when two co-worker start fighting over casing).

And if someone just doesn't agree to work with the selected style just remind him (or her) that he is programming as a profession not as an hobby, see http://www.ericsink.com/entries/No_Great_Hackers.html

Nir
+1 - try this with Python code and watch the sparks fly!
rq