views:

108

answers:

5

When a simple refactoring like “rename field” has been done on one branch it can be very hard to merge the changes into the other branches. (Extract method is much harder as the merge tools don’t seem to match the unchanged blocks well)

Now in my dreams, I am thinking of a tool that can record (or work out) what well defined refactoring operations have been done on one branch and then “replay” them on the other branch, rather than trying to merge every line the refactoring has affected.

see also "Is there an intelligent 3rd merge tool that understands VB.NET" for the other half of my pain!


Also has anyone try something like MolhadoRef (blog article about MolhadoRef and Refactoring-aware SCM), This is, in theory, refactoring-aware source control.

A: 

Araxis Merge doesn't understand common refactoring but it is the only three way merge tool that I've used. It is available for both the Mac and Windows, and it supports an Automation API so I would imagine that you could do what you want with that if you were so inclined. For the record I have no connection with Araxis other than I've used their product.

Tony Lambert
we have found that Araxis Merge is one of the best conventional merge tools. (The Automation API will not help, as it needs the refactoring tool to "own" the problem)
Ian Ringrose
A: 

In Linux you can use Meld or in Windows Winmerge.

In any case, both tools only "understand" about lines of text. Refactoring requires a way of understanding the code, which is beyond any merging/comparing tool that I known.

Carlos Tasada
+2  A: 

You could use coccinelle to do the same kind of refactoring operations on different branches. It will not record or figure out what is being done by itself, you have to explicitly tell it what to do, but other than that it will more or less effortlessly do the same refactoring on as many branches you point it to.

This tool have been used in the linux kernel for updating API usage etc.

To quote from its web page:

"Coccinelle is a program matching and transformation engine which provides the language SmPL (Semantic Patch Language) for specifying desired matches and transformations in C code."

hlovdal
pity it does not work for C# or VB.NET but at least someone else has thought about the problem.
Ian Ringrose
+2  A: 

Darcs supports a 'token replace' operation in a commit, which replaces all instances of one token with another, and merges as you'd want it to.

Andrew Aylett
the problem with "token replace" is that scope needs to be taken into acount for a safe rename
Ian Ringrose
A: 

Plastic SCM (www.plasticscm.com) 3-way merge tool implements Xmerge which is the only one able to assist you merging code that has been moved.

pablo