Xmerge to merge refactored code

July 26, 2010

It's been a funny week. We first announced 3.0, then announced Xdiff, later crunched Subversion and now we're finally explaining a little bit about what Xmerge is about.

Merging moved code


If you need to know what we're doing with diff and merge stuff, I'd strongly recommend you to read the post about Xdiff first. There's even a short screencast if you don't feel like reading :P.

Well, basically Xmerge applies the tech. we developed for Xdiff into the merge process. The scenario is simple:

  • You've a file with some code
  • You go and move a method from the top to the bottom of the file.
  • While you're doing this, on my own task branch, I go and change the method on its "original" location.
  • Then we go and merge! Result? Nightmare unless you've Xmerge! :-P

    Original code


    Let's start with a very simple piece of code like the one below



    Someone moves the multiply method down


    The "multiply" method is private and I do like to see privates at the bottom, so I just go and move it down.

    Then I check the differences with Plastic:



    And meanwhile someone refactors the method


    The multiply method is not exactly the best code ever written, right? :) Let's just change a few things.



    Branching structure before merging


    Here's the branching structure as Plastic renders it just before merging.



    Running xmerge


    When you merge both branches back into /main (well, the first one you choose won't complain, it will be a direct merge) you'll get a nice conflict like the one below.

    The extremely nice thing about xmerge is that it will show a Xmerge button telling you there's an option to help you solving your problems. Just click it! (click on the image below to enlarge).



    So, what's going on here?

    Xmerge detects the code-block you're trying to merge has been moved. So it will detect where it is and will launch a "submerge" with just the right contributors (the ancestor and contributors plus the result). You can easily resolve the conflict there and when done, the result will be pasted back into the original merge window. Cool?



    The cross-merged result


    Here it goes:



    And now the movie


    Some of you will prefer to watch the movie than reading the book, so here it goes :P

    Make it full screen! It was recorded at 1024x768 so you should be able to see all the details.



    Conclusion


    Well, it is not the easiest thing to explain, so feel free to ask!!!

    This is our second step on Xmerge technology, the first generation (since Plastic 2.8) was able to run the "submerge" but you had to find the moved code yourself. Now with all the Xdiff technology we're able to perform the detection ourselves.

    Hope you like it! And be sure there's more to come!
  • 3 comments :

    Adam said...

    Doesn't git do this by tracking content?

    pablo said...

    Hi Adam,

    No, it's not the same.

    Git is able to tell you, with git blame (the long scan) which code has been moved between files on the same commit. And it needs the code to match exactly, it won't track modified code after the move.

    Xmerge is all about merging, nothing to do with content tracking.

    And, Xmerge is able to locate code (as I showed on the video) that has been not only moved but also modified, out of the scope of Git.

    Anonymous said...

    1) Hope you've patented this technique (not really, since I'm opposed to software patents) and/or are not infringing on someone else (why is no one else doing this already?)

    2) More encouragement to give away free separate from your SCM server for brand recognition / to sell separately.

    Real Time Web Analytics