Does merge direction matter in Mercurial?

Take a simple example: I'm working on the default branch, have some changesets committed locally, and I pulled a few more from the master repository. I've been working for a few days in my isolated local repository, so there's quite a few changes to merge before I can push my results back into master.

default ---o-o-o-o-o-o-o-o-o-o-o  (pulled stuff)
            \
             o----o------------o  (my stuff)

I can do two things now.

Option #1:

hg pull
hg merge

Result #1:

default ---o-o-o-o-o-o-o-o-o-o-o
            \                   \
             o----o------------o-O

Option #2:

hg pull
hg update
hg merge

Result #2:

default ---o-o-o-o-o-o-o-o-o-o-o-O
            \                   /
             o----o------------o

These two results look isomorphic to me, but in practice it seems that option #2 results in way smaller changesets (because it only applies my few changes to the mainline instead of applying all the mainline changes to my few).

My question is: does this matter? Should I care about the direction of my merges? Am I saving space if I do this? (Doing hg log --patch --rev tip after the merge suggests so.)

Upvotes: 16

Views: 1153

Answers (2)

Rafael Piccolo
Rafael Piccolo

Reputation: 2338

There is also a difference if you are using Bookmarks. When doing a merge, the branch that you are is the branch that is receiving the changes, so the new changeset will be part of that branch. Supose you have this situation:

default ---o-o-o-o-o-o-o-o-o-o-o   -- Head: Rev 200
            \
             o----o------------o   -- Head: Rev 195, Bookmark: my-stuff

If you merge Rev 200 into Rev 195, the bookmark my-stuff will move on to Rev 201, as you are generating a new changeset in the same branch that has the bookmark.

On the other hand, if you merge 195 into 200, you are generating a changeset in the branch that don't have the bookmark. The my-stuff bookmark will remain in Rev 195.

Upvotes: 2

Ry4an Brase
Ry4an Brase

Reputation: 78330

They're (effectively) identical. You see a difference in the hg log --patch --rev X output size because log shows the diff of the result and (arbitrarily) its 'left' parent (officially p1), but that's not how it's stored (Mercurial has a binary diff storage format that isn't patch/diff based) and it's now how it's computed (p1, p2, and most-recent-common-ancestor are all used).

The only real difference is, if you're using named branches, the branch name will be that of the left parent.

Upvotes: 14

Related Questions