confused about switching branches

Sanjoy Mahajan sanjoy at mrao.cam.ac.uk
Mon Aug 22 00:01:13 CDT 2005


I'm going through the 'notes.txt' and clarifying what I find
confusing, eventually to put it on the Wiki.  By doing small
experiments, and using 'hg debugstate' a lot, I've understood matters
until about halfway through, i.e. until the nuts and bolts of merging:

  It decides when a merge is necessary by first determining if there
  are any uncommitted changes in the working directory. This
  effectively makes the working directory a branch off the checked in
  version it's based on. Then it also determines if the working
  directory is a direct ancestor or descendent of the second version
  we're attempting to checkout. If neither is true, we simply replace
  the working directory version with the new version. Otherwise we
  perform a merge between the two versions.

A small experiment (v0.6b) suggests otherwise.  The changeset graph
(from 'hg debugstatedot') looks like:

-1 -> 0 -> 1 -> 2 -> 3 -> 5 -> more stuff
                 \-> 4 - /    

(i.e. 2 branched into 3 and 4, which both merged to 5).  2->3 created
the file 'b' and 3->4 created 'c', then these two states were merged
to get 5, which has b and c.  Suppose I start with revision 5.  If I
try to switch to 4, no luck.  But switching to 3 works fine.
Shouldn't neither or both work, since they are symmetric:

  $ hg checkout 5
   force None allow None moddirstate True linear True
   ancestor 9473b4923fd2 local 9473b4923fd2 remote 9473b4923fd2
  $ hg status
  $ hg checkout -C 4
   force 1 allow None moddirstate True linear False
   ancestor 013db5d4833f local 9473b4923fd2 remote 013db5d4833f
  local created b, keeping
  this update spans a branch affecting the following files:
  aborting update spanning branches!
  (use update -m to perform a branch merge)
  $ hg checkout -C 3
   force 1 allow None moddirstate True linear True
   ancestor ec5d5e251bdf local 9473b4923fd2 remote ec5d5e251bdf
  remote deleted c
   remote b is newer, get

Why does it think 'linear False' with the 'hg checkout -C 4'?  4 and 5
are linearly connected, as are 3 and 5.  The update() function in
hg.py (line 1258) has a possibly related asymmetry:

        p1, p2 = pl[0], node

Why is the pl[0] parent preferred over the pl[1] one?

-Sanjoy


More information about the Mercurial mailing list