Ian Ringrose
Ian Ringrose

Reputation: 51927

Is there a 3 way merger tool that “understands” common refactoring?

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.

Upvotes: 5

Views: 280

Answers (6)

Ian Ringrose
Ian Ringrose

Reputation: 51927

There are now some better merge tools (for example SemanticMerge) that are based on language parsing, designed to deal with code that has been moved and modified. JetBrains (the create of ReShaper) has just posted a blog on this.

There has been lots of research on this over the years, at last some products are coming to market.

Upvotes: 0

pablo
pablo

Reputation: 6402

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.

Upvotes: 0

Andrew Aylett
Andrew Aylett

Reputation: 40740

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.

Upvotes: 2

Carlos Tasada
Carlos Tasada

Reputation: 4444

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.

Upvotes: -1

hlovdal
hlovdal

Reputation: 28228

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."

Upvotes: 2

AnthonyLambert
AnthonyLambert

Reputation: 8830

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.

Upvotes: 0

Related Questions