These are the slides used for the ReSharper + SemanticMerge webinar run with JetBrains on June 17th 2014.
http://info.jetbrains.com/Webinar_ReSharper-SemanticMerge-Registration.html
4. 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 ;-)
5. 3-way merge - reminder
Theirs Yours
S
Source Destination
D
Base
Base
B
Result
R
0
main
1 3
4
task001
2 5 6
7
Base
Source
Destination
6. 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
8. Case0 –What a conventional 3-way merge tool
does?
• No conflict!
• And two methods!!
9. 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
11. 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… :-)
18. 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
19. 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?
20. 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
21. How can
semanticmerge affect
development?
1) It helps simplifying the mergesTODAY
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.
22. 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]
24. 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
25. Evil twin namespace 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
The case just shows how to developers added (in parallel) the same method in two different locations. SemanticMerge is able to detect the situation and include only one of the two, while a regular merge tool would incorrectly add the two.
This is a typical cleanup scenario: you just go to ‘code cleanup’ in ReSharper and get some methods rearranged. Then later someone else, concurrently, modifies a methods on its ‘original’ location. Regular merge tools would have a really bad time merging this… But Semantic can merge automatically since it ‘understands’ the code structure.
Splitting in subclasses is a rich scenario involving complex modifications.
The scenario starts with a single ‘socket’ class that will be split into two: ClientSocket and ServerSocket plus the old ‘Socket’ being renamed to ‘DNS’.
Understanding the scenario is not hard for a programmer, but a text-based mergetool will turn the merge into a real pain.
ReSharper can easily perform the refactor in a few clicks. We will simulate two developes working in parallel, one creating the ClientSocket while the second creates the ServerSocket. Then the code will be merged by Semantic.
Jump to demo mode and go step by step refactoring the code with ReSharper, showing how to developers make the changes in parallel (simulated).
Note: need to decide the version control. Git would be fine. Plastic can do too.
The goal is to show how Semantic can seamlessly merge the refactor created by ReSharper
This case will continue where the ‘split class in subclasses’ left. What if now the developers move a method to two different subclasses and also modify it?
Demo:
Perform the refactor (move methods) with ReSharper
Merge with Semantic