No fear refactoring in the DVCS age
ReSharper + SemanticMerge
pablo santos @psluaces@semanticmerge
Agenda
• Introduce SemanticMerge• Walk through different refactor and merge cases
using ReSharper + Semantic• Q&A
What is semanticmerge?
• It is refactor-aware and programming language-aware.
• Handles merging at the structure level and not textblock level.
• It means: • It first parses the code – creates intermediate
trees.• Then calculates diff pairs: base-src, base-dst.• Then looks for conflicts between pairs.
• Enabling eXtreme Refactoring was always the goal :-)
• It is a 3-way merge tool (handles src, dst and base).
I guess you all know by now ;-)
3-way merge - reminder
Theirs Yours
SSource Destination
D
Base
BaseB
ResultR
0
main
1 3
4
task001
2 5 6
7
Base
Source
Destination
Can be used with any version control• Git• Mercurial• Perforce• TFS• And Plastic SCM
(Free trial available and very affordable)
http://www.semanticmerge.com/index.html#documentation
Case0 – Add the same method twice
Case0 – What a conventional 3-way merge tool does?
• No conflict!• And two methods!!
Case0 – What will a conventional 3-way merge tool do?• No conflict!• And two methods!!
• It simply finds two blocks of text being added … Doesn’t care about the code structure
Case0 – What SemanticMerge does• It *knows* about the methods so…
Case 1 – Cleaned up code
• Typical case where an Open Source contributor “helps” rearranging a class with ReSharper.• While another contributor was making changes in
the original file.• Merge will be a nightmare… :-)
Case 1 – Cleaned up code (II)
Case 1 – Cleaned up code (III) – ReSharper settings
Case 2 - Split a class in subclasses
Case 2 - Splitting a class in subclasses (II)• Refactor the file with ReSharper, two developers in
parallel
Case 2 - Splitting a class in subclasses (III - merge)
Case 3 – Divergent move
Case 4 – Code format changes
Semantic is able to discard the changes made on source (method call in multiple lines) and automatically accept the new param instead of raising a conflict resolution
Case 5 – Move/delete conflict
• What happens if you move a method inside a class• That is deleted on a different branch?• How the merge deals with this scenario?
Detect conflicts that regular tools can’t• What if the same method is modified concurrently
at different lines?• Semantic detects the case and can force the
conflict resolution to be manual – a regular text based merge tool can’t do that because it doesn’t have the context
How can semanticmerge affect development?
1) It helps simplifying the merges TODAY already.
2) But more importantly it enables new scenarios that you’re not doing today: clean up the code, move methods, split classes… and just be able to merge it back.
Creating a tree-like view of the code
namespace Sample [4-26]
int Add(int a, int b) [8-12]
int Mul(int a, int b) [14-18]
int Subst(int a, int b) [20-24]
using System [1]
using System.Text [2]
class Math [6-25]
Processbase
base tree
source destination
Parser
source tree destination tree
Diff er Diff er
Merger
src-base diff s dst-base diff s
result
automatic confl icts
manual confl icts
source ops to apply
Some complex cases – cyclic move
namespace Testnamespace Test
namespace Test
class Socket
class Socket
class DNS
class DNS
class Socket
base
source destination
class Utils
class Utils
class DNSclass Utils
Evil twinnamespace Test
class Socket
base
source
method Connect
namespace Test
class Socket
method Connect
namespace Test
class Socket
method Connect
destination
method Send method Send
Two methods with exactly the same signature can’t be added on the same
location -> conflict
Multi-file SemanticMerge
Top Related