Refactoring merged code - ReSharper meets SemanticMerge

  • 41,042 views
Uploaded on

These are the slides used for the ReSharper + SemanticMerge webinar run with JetBrains on June 17th 2014. …

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

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
41,042
On Slideshare
0
From Embeds
0
Number of Embeds
28

Actions

Shares
Downloads
2
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide
  • 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

Transcript

  • 1. No fear refactoring in the DVCS age ReSharper + SemanticMerge pablo santos @psluaces @semanticmerge
  • 2. Agenda • Introduce SemanticMerge • Walk through different refactor and merge cases using ReSharper + Semantic • Q&A
  • 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. 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. 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. Case0 – Add the same method twice
  • 7. Case0 –What a conventional 3-way merge tool does? • No conflict! • And two methods!!
  • 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. Case0 –What SemanticMerge does • It *knows* about the methods so…
  • 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. Case 1 – Cleaned up code (II)
  • 12. Case 1 – Cleaned up code (III) – ReSharper settings
  • 13. Case 2 - Split a class in subclasses
  • 14. Case 2 - Splitting a class in subclasses (II) • Refactor the file with ReSharper, two developers in parallel
  • 15. Case 2 - Splitting a class in subclasses (III - merge)
  • 16. Case 3 – Divergent move
  • 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. 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. 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. 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. 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. 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. 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. 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. Multi-file SemanticMerge