Code formatting and source control vary

Which version control tools have a diff tool that ignores spaces, curly braces, etc. when calculating the difference between verified versions? I seem to remember that Clearcase diff did this, but Visual SourceSafe (or at least the version I used) did not.

I ask, probably quite typical. Four completely intelligent developers on a team have four completely different ways to format their code. After checking the code, the last modified by someone else, each of them immediately starts some kind of macro program or editor to format things the way they like. They make real changes to the code. They check their changes. They go on vacation. Two days later, this program, which worked perfectly for two years, explodes. The developer, assigned to the error, makes the difference between the versions and discovers 204 differences, only 3 of which have any meaning, since the diff algorithm is lame.

Yes, you may have coding standards. Most of them consider them terrible. A solution in which everyone can have their own cake and eat, also seems much more preferable.

==========

EDIT: Thanks to everyone for the great suggestions.

What I subtract from this:

(1) A preferred source control system with diversity types.

(2) Find the diff with the appropriate parameters.

(3) Use a good source code formatting program and leave it to the registration standard.

Sounds like a plan. Thanks again.

+7
version-control
source share
6 answers

Perhaps you need to choose one format and run some indentation tool before checking it so that everyone can check, reformat their own preferences, make changes, reformat them back to the official standard and then register?

A few additional steps, but they already use indentation tools when working. Perhaps this could be a running registration script?

Edit: this may also solve the parenthesis problem.

(I did not try this solution myself, hence the "perhapes" and "maybes", but I was in projects with the same problems and it is a pain to try to get through the differences with hundreds of irrelevant changes that are not limited to spaces, but include the formatting itself. )

+2
source share

Git has the following options:

  • --ignore-space-at-eol

    Ignore space changes in EOL.

  • -b, --ignore-space-change

    Ignore changes in the number of spaces. This ignores the spaces at the end of the line and considers all other sequences of one or more space characters to be equivalent.

  • -w, --ignore-all-space

    Ignore spaces when comparing strings. This ignores the differences, even if one line has spaces, where the other line has no.

I'm not sure if curly brace changes can be ignored with Git diff.

If this is C / C ++ code, you can define Astyle and then convert the source code to the binding style of the one you want using Astyle . A git diff then produce a normal output.

+4
source share

Choose one (terrible) coding standard, write it down in some official coding standards document and continue your life, messy mess is not a productive job.

And remember that you are a professional developer, it is your job to complete the project, changing something in the code because of personal style preferences, it hurts the project - it will not only make it harder, more difficult to find problems if your source There are errors in the formatting or the compiler (and your “bizarre decomposition” tool will not save you when two employees start fighting for the corps).

And if someone simply does not agree to work with the chosen style, just remind him (or her) that he programs as a profession not as a hobby, see http://www.ericsink.com/entries/No_Great_Hackers.html

+4
source share

Subversion seems to support this, either initially in recent versions, or using an alternative diff such as Gnu Diff.

0
source share

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

0
source share

As explained in Is it possible for git -merge to ignore the difference in line endings? , it’s more important to associate a suitable comparison tool with your favorite VCS, rather than relying on the correct VCS option (even if Git has some options regarding spaces, such as those mentioned in Alan's answer , it will not always be as complete as we would like) .

DiffMerge is more complete for these “ignore” options, since it can not only ignore spaces, but also other “options” based on the programming language used in this file.

0
source share

All Articles