Semanticmerge

Post on 24-May-2015

221 views 0 download

Tags:

Transcript of Semanticmerge

SemanticMergeApril 30th 2013

Pablo Santosprincipal engineer

@psluaces

Violeta Sánchezsemanticmerge project leader

@vio_woman

What is semanticmerge?

• It is a 3-way merge tool (handles src, dst and base).

• That 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 :-)

I guess you all know by now ;-)

How can semanticmerge affect development?We were always motivated by “the cost of change” and how refactoring can greatly help keeping code quality high and reducing maintenance costs.

SemanticMerge is all about helping teams to clean up the code, keep it readable and simple, without restrictions: do it in parallel, fine!

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.

A little bit of history…

• Programmers always asked us: does Plastic mergetool understand code?

• So semanticmerge is just something everyone had in mind for years… but it didn’t exist.

• Looking back we now say “why we didn’t do it before”, but it was not that simple…

• The entire “merge-engine” is based on what we developed (and learnt) with Plastic SCM 4.0 (check merge-machine: http://plasticscm.com/mergemachine/index.html

• But applied to “structures inside the file” instead of directories and files (although the principles are similar).

• It all started with Xdiff/Xmerge which is included in Plastic SCM and now inside SemanticMerge too…

Xmerge – our first step towards semantic• Check - http://plasticscm.com/features/xmerge.aspx

• It is all about finding moves based on text-block similarity (language-agnostic!).

• And also dealing with cases during merge.

Core concepts

• It merges on a “method by method” basis (or any other structure).

• It means it won’t get fooled by a method that was moved and modified:

Core concepts – GUI approach

• We couldn’t stick to “regular” 3-way merge tool layouts.• Because then we’d end up with the same problems: • Moves can’t be clearly rendered.• Files rearranged end up being messy with crossing lines

to show the moved elements.

Core concepts – GUI approach• So we wanted to come up with something different.

• Suppose you moved all methods around and then modified one of them…

• What you simply want to know is something like:• Method foo() modified.• Method bar() moved.• Method sum() moved.

• Instead of a huge number of text blocks trying to be matched…

• The main idea was: simplify and show only relevant info, then let users go into bigger detail later on.

GUI design

• Let’s go again for a case like this:

GUI design

• And check how it looks like in SemanticMerge

GUI design• Method1() was modified twice and moved, and that

is what gests highlighted on the GUI:

• The icons indicate the two “changed” (“c” on left and right) and “moved on source” (left) with an “m”

GUI designThe idea of the icons at the two sides of the “conflict” actually comes from what we call the “visual diff” which is something we will be adding on upcoming releases of SemanticMerge:

Our end goal is to have a better way to “understand” what is going on and how the different methods and classes were modified, moved and so on…

Let’s check some examples…• A refactor in SimpleFileSystem.cs

The “src” changes can be tracked by Xdiff

But even better tracked by SematicDiff

Destination change is slightly more complexStill SemanticDiff shows what happened (detects the methods as moved up).

And the modified method “WriteSelector()”.

Text-based diff can be ok (with Xdiff technology) as soon as the “order” of elements remains, but if you cross the positions it is not understandable anymore.

And let’s check the merge!

And let’s check the merge!

• Only one merge conflict (method modified twice) compared to the merge nightmare of a conventional merge tool!

• The text-based merge will run at the method level, greatly simplifying the operation.

• The location of the WriteSelector method moved divergently can be changed with “rearrange” once the conflict is fixed (by default it keeps “dst” if the moves are inside the same scope).

Another case… splitting the Socket class

Next steps• Release VB.net support ASAP.

• Release Java support (under testing for months already).

• Then we’ve to decide:• C/C++ support is a huge requirement (we started already).• Mac OS X GUI seems to be big (together with JavaScript support).• Linux GUI.• We’d like to add some “graphical merging” features…• Tons of improvements: usability (rearrange), more cases (moved and blanks,

indentation), better text editor (with indentation options and more)…• Multi-file semanticmerge support. *The* big feature ;-)

• Let users add their own languages – what if we let you add your own parsers?? :-)

User Feedback • 248 votes – Linux and Mac OS X (!!) – we will be giving a try to the MacOS X UI quite soon.

• 160 votes – JavaScript – we need to find a good parser.

• 124 votes – C++ - the rising star – we already started, with libclang.

• 111 votes – XML files – there are good tools out there like Altova’s but we can give a try to the Semantic approach here.

• 87 votes – Amazing Visual Studio support – we need more feedback here.

• More languages: Python, C, Ruby, Objective-C, Scala, F#, PHP, Delphi – our plan is to open up the intermediate tree so more languages can be added by contributors.

Top entries from UserVoice

http://plasticscm.uservoice.com/forums/196398-mergebegins

Questions??thanks!

do not forget to follow us at: @semanticmerge & @plasticscm