Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
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 an...
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
D...
Can be used with any version control
• Git
• Mercurial
• Perforce
• TFS
• And Plastic SCM
(Free trial available and very a...
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 te...
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.
• Whi...
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 au...
Case 5 – Move/delete conflict
• What happens if you move a method inside a class
• That is deleted on a different branch?
...
Detect conflicts that regular tools can’t
• What if the same method is modified concurrently at different lines?
• Semanti...
How can
semanticmerge affect
development?
1) It helps simplifying the mergesTODAY
already.
2) But more importantly it enab...
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]
i...
Process
base
base tree
source destination
Parser
source tree destination tree
Differ Differ
Merger
src-base diffs dst-base...
Some complex cases – cyclic move
namespace Testnamespace Test
namespace Test
class Socket
class Socket
class DNS
class DNS...
Evil twin namespace Test
class Socket
base
source
method Connect
namespace Test
class Socket
method Connect
namespace Test...
Multi-file
SemanticMerge
Refactoring merged code - ReSharper meets SemanticMerge
Refactoring merged code - ReSharper meets SemanticMerge
Upcoming SlideShare
Loading in …5
×

Refactoring merged code - ReSharper meets SemanticMerge

43,755 views

Published on

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

Published in: Technology
  • Be the first to comment

Refactoring merged code - ReSharper meets SemanticMerge

  1. 1. No fear refactoring in the DVCS age ReSharper + SemanticMerge pablo santos @psluaces @semanticmerge
  2. 2. Agenda • Introduce SemanticMerge • Walk through different refactor and merge cases using ReSharper + Semantic • Q&A
  3. 3. 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 ;-)
  4. 4. 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
  5. 5. 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
  6. 6. Case0 – Add the same method twice
  7. 7. Case0 –What a conventional 3-way merge tool does? • No conflict! • And two methods!!
  8. 8. 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
  9. 9. Case0 –What SemanticMerge does • It *knows* about the methods so…
  10. 10. 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… :-)
  11. 11. Case 1 – Cleaned up code (II)
  12. 12. Case 1 – Cleaned up code (III) – ReSharper settings
  13. 13. Case 2 - Split a class in subclasses
  14. 14. Case 2 - Splitting a class in subclasses (II) • Refactor the file with ReSharper, two developers in parallel
  15. 15. Case 2 - Splitting a class in subclasses (III - merge)
  16. 16. Case 3 – Divergent move
  17. 17. 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
  18. 18. 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?
  19. 19. 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
  20. 20. 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.
  21. 21. 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]
  22. 22. Process base base tree source destination Parser source tree destination tree Differ Differ Merger src-base diffs dst-base diffs result automatic conflicts manual conflicts source ops to apply
  23. 23. 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
  24. 24. 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
  25. 25. Multi-file SemanticMerge

×