File Merge: How did we get ourselves into this mess

[article]

can see, Jane and Joe have each inserted a one-line comment.  By right-clicking on each change, the developer can choose whether to apply that change to the middle pane.  In this example, the two changes don't conflict.  There is no reason that the resulting file cannot incorporate both changes.

The following picture shows an example of changes which are conflicting.

Both Jane and Joe have tried to change the wording of this comment.  In the original file, the word used in the comment was "Global".  Jane decided to change this word to "Worldwide", but Joe has changed it to the word "Rampant".  These two changes are conflicting, as indicated by the yellow background color being used to display them.  Automerge cannot automatically handle cases like these.  Only a human being can decide which change to keep.

The visual merge tool makes it easy to handle this situation.  I can decide which change I want to keep and apply it to the center pane.

A visual merge tool can make file merging a lot easier by quickly showing the developer exactly what has changed and allowing him to specify which changes should be applied to get the final merged result.

However, as useful as these kinds of tools can be, they're not magic.

Redo one set of changes by hand
Some situations are so complicated that a visual merge tool just isn't very helpful.  In the worst case scenario, Joe might have to manually redo one set of  changes.

This situation recently happened here at SourceGear.  We currently have Vault development happening in two separate branches: 

  •     When we shipped version 2.0, we created a branch for maintenance of the 2.0 release.  This is the tree where we develop minor bug fix releases like 2.0.1.
  •     Our "trunk" is the place where active development of the next major release is taking place.

Obviously we want any bug fixes that happen in the 2.0 branch to also happen in the trunk so that they can be included in our upcoming 2.1 release.  We use Vault's "Merge Branches" command to migrate changes from one place to the other.

I will talk more about branching and merging in a later chapter.  For now, suffice it to say that the merging of branches can create exactly the same kind of three-way merge situation that we've been discussing in this chapter.

In this case, we ended up with a very difficult merge in the sections of code that deal with logins.  

  •    In the 2.0 branch, we implemented a fix to prevent dictionary attacks on passwords.  We considered this a bug fix, since it is related to the security of our product.  In concept this change was simple.  We simply block login for any account which is seeing too many failed login attempts.  However, implementing this mini-feature required a surprising number of lines to be changed.
  •    In the trunk, we added the ability for Vault to authenticate logins against Active Directory.

In other words, we made substantial changes to the login code in both these branches.  When it came time to merge, the DiffMerge was extremely colorful.

In this case, it was actually simpler to just start with the trunk version and reimplement the dictionary attack code.  This may seem crazy, but it's actually not that bad.  Redoing the changes takes a lot less time than coding the feature the first time.  We could still copy and paste code from the 2.0 version. 

Getting back to the primary example, Joe has a choice to make.  His current working file already contains his own set

About the author

TechWell Contributor's picture TechWell Contributor

The opinions and positions expressed within these guest posts are those of the author alone and do not represent those of the TechWell Community Sites. Guest authors represent that they have the right to distribute this content and that such content is not violating the legal rights of others. If you would like to contribute content to a TechWell Community Site, email editors@techwell.com.

AgileConnection is one of the growing communities of the TechWell network.

Featuring fresh, insightful stories, TechWell.com is the place to go for what is happening in software development and delivery.  Join the conversation now!

Upcoming Events

Nov 09
Nov 09
Apr 13
May 03