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

3

21

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.
Futurity answered 10/10, 2008 at 22:50 Comment(0)
E
11

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

Evelineevelinn answered 10/10, 2008 at 22:57 Comment(4)
Sounds good, thanks. Then the next question is: does anyone know a merger which can ignore whitespaces? On another question I found a few visual merge tools that look good (meld, tortoisesvn) but does anyone know of a command-line one?Futurity
you can look into winmerge ( winmerge.org ) It is opensource and you can easily use it in tortoiseSVN as diff/merge viewerEvelineevelinn
I've been looking into this on Linux, and it appears there is no easy way to do this. E.g., you can tell it to use "diff3" but it has no parameter to ignore whitespace. But you can pass that a parameter to use a different "diff" program. So, you have it call "diff -b". But then you can not do that recursively (apparently) from the SVN command (i.e., svn (using diff3 (using (diff -b)))). The solution I'm going to investigate next is creating a shell script that calls "diff3" using "diff" to ignore whitespace. Then I'll have SVN use the shell script.Diao
UPDATE: this strategy appears to go into an infinite recursion loop. Or maybe I just didn't wait long enough.Diao
H
5

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.

Hooghly answered 10/10, 2008 at 23:16 Comment(0)
P
0

TortoiseMerge doesn't have any CLA (Command Line Arguments) to ignore the whitespace and ignore the case. After searching a lot it seems that it can be achieved still by tweaking the registry values.

/* DisableWhitespaceDifferences and DisableCaseDifferences. 
* The settings for TortoiseMerge is stored in Registry in CurrentUser\Software\TortoiseMerge\
* DWORDS stored the property values.
* 
* IgnoreWS         :   Set to 1 to ignore the whitespace differences. 
*                      Set to 0 to allow the whitespace differences.             
* IgnoreEOL        :   Set to 1 to ignore the End of Line differences. 
*                      Set to 0 to allow the End of Line differences.             
* CaseInsensitive  :   Set to 1 to ignore the Case differences. 
*                      Set to 0 to allow the Case differences.             
*/

// Get the key from the registry
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\TortoiseMerge", true))
{
   if (key != null)
   {
        // Set the IgnoreWS and IgnoreEOL DWORDs based on DisableWhitespaceDifferences is set or not
        key.SetValue("IgnoreWS", DisableWhitespaceDifferences ? 1 : 0, RegistryValueKind.DWord);
        key.SetValue("IgnoreEOL", DisableWhitespaceDifferences ? 1 : 0, RegistryValueKind.DWord);

        // Set the CaseInsensitive DWORD based on DisableCaseDifferences is set or not
        key.SetValue("CaseInsensitive", DisableCaseDifferences ? 1 : 0, RegistryValueKind.DWord);

        // close key
        key.Close();
    }
}
Pendent answered 27/10, 2014 at 5:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.