Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can CVS and Subversion be set to ignore whitespace in merging?

CVS and Subversion both have a handy merge feature so that when you update a source file that you have modified, it merges in changes that others have made on the same file.

However, if your changes and the other ones are incompatible - generally if you have both changed the same parts of the code - it will create a conflict. Both stretches of source code will be included into the merged file and you need to manually sort out which changes to keep. All fine so far.

My problem is that some of us use different development environments (Netbeans versus vi if you must know) and Netbeans has an auto-indenting feature which re-indents the code. Therefore, when we merge changes, we sometimes get huge conflicts which are mostly caused by simple changes in indentation and are not genuine changes to code. Often these create hundreds of lines of apparent conflicts which have to be manually resolved, but usually they come down to just a few lines of real changes. A similar situation occurs when someone's editor changes unix to Windows newlines or vice versa.

So - can I set merge to ignore these "conflicts" when comparing the two versions? Diff has the --ignore-space-change or -b option and I would like to have essentially the same feature available in cvs or svn. We use each tool on different projects so I would be happy to have the answer for either or both.

Two final notes:

  • clearly the merge process would have to make an arbitrary choice as to which version of the whitespace to use in the merged file. I'm fine with that - we can always reformat it again later.
  • I could avoid some of this by being more disciplined and checking in more often - acknowledged and understood. But I am not perfect.
like image 943
Leigh Caldwell Avatar asked Oct 10 '08 22:10

Leigh Caldwell


2 Answers

For SVN: In commandline tool, there is the option -x which you can set to "b" or "w" to ignore space changes resp. all spaces.
You can also supply a third party tool for doing the merges. So if you have a merger which ignores whitespaces, you can use this one. TortoiseSVN, as always, is a frontend to all parameters, so it will support for ignoring whitespaces as well.

The svn merge command is described here. The option you need is --diff3-cmd

like image 146
Peter Parker Avatar answered Nov 13 '22 03:11

Peter Parker


For Windows users, you can use TortoiseSVN (a Windows Explorer shell extension for Subversion) which comes with merge features that support what you are describing:

Ignore line endings excludes changes which are due solely to difference in line-end style.

Compare whitespaces includes all changes in indentation and inline whitespace as added/removed lines.

Ignore whitespace changes excludes changes which are due solely to a change in the amount or type of whitespace, eg. changing the indentation or changing tabs to spaces. Adding whitespace where there was none before, or removing a whitespace completely is still shown as a change.

Ignore all whitespaces excludes all whitespace-only changes.

like image 26
J c Avatar answered Nov 13 '22 03:11

J c