Merge internals

Matt Mackall mpm at selenic.com
Tue Jul 3 09:20:11 CDT 2007


On Tue, Jul 03, 2007 at 12:29:56PM +0200, a rmand wrote:
> I hope I can post my question about the internal workings (design) of
> Mercurial here as the information I am looking for is similar to the
> information provided in the "DeveloperInfo" section of the website.
> 
> My question is basically: how does merging several changesets work? Does
> Mercurial merge the difference between applying all the changesets pulled in
> and the common root to the working directory (like SVN)? Or does Mercurial
> try to apply the patches one by one (like Darcs does)? And if the first is
> the case, how are renames handled?

At the file level, Mercurial uses an external 3-way merge tool with
the common ancestor.

At the directory level, it resolves adds, removes, renames and copies
relative to the ancestor changeset. If one side renames or copies a
file, any changes the other side made to the file "simultaneously" get
merged into it.

> To make things a bit more clear, here is an example:
> 
> # Initial version
> 
> a.txt
> -------------
> line 1
> line 2
> line 3
> 
> $ hg commit
> 
> #  Clone of version 1 (Clone A) - Commit 1
> 
> $ hg clone /path/to/initial version/
> $ hg rename a.txt b.txt
> $ hg commit
> 
> #  Clone of version 1 (Clone A) - Commit 2
> 
> b.txt -> c.txt
> -------------
> line 1
> line 1.5
> line 2
> line 3
> 
> $ hg rename b.txt c.txt
> $ hg commit
> 
> #  Clone of version 1 (Clone B) - Commit 1
> 
> $ hg clone /path/to/initial version/
> 
> a.txt
> -------------
> line 1
> line 2
> line 3
> line 4
> 
> $ hg commit
> 
> Now suppose all the changes are committed and the owner of repository "Clone
> B" pulls in the changes from repository "Clone A" ($ hg pull /path/to/Clone
> A/). How would Mercurial proceed in merging the patches?
> 
> 1) Mercurial calculates that file a.txt and file c.txt are in fact the same
> and runs an external merge (so Mercurial does not care about the contents of
> the files)

This one.

-- 
Mathematics is the supreme nostalgia of our time.


More information about the Mercurial-devel mailing list