Issues with hg update -C and bookmarks

Matt Mackall mpm at selenic.com
Tue Jul 14 23:55:21 UTC 2015


On Wed, 2015-07-15 at 00:17 +0200, Marc Strapetz wrote:
> On 14.07.2015 20:55, Matt Mackall wrote:
> > On Tue, 2015-07-14 at 16:21 +0200, Marc Strapetz wrote:
> >> With the following setup:
> >>
> >> $ hg init
> >> $ touch x
> >> $ hg commit -A "initial import"
> >> $ touch y
> >> $ hg commit -A -m "y added"
> >> $ hg checkout 0
> >> $ touch z
> >> $ hg commit -A -m "z added"
> >> $ hg up 1
> >> $ hg bookmark bm
> >>
> >> There will be default with two diverged heads at r1 and r2 and a
> >> bookmark on r1.
> >>
> >> $ hg summary
> >> parent: 1:4009599f6088
> >>    y added
> >> branch: default
> >> bookmarks: *bm
> >> ...
> >>
> >> Starting from this setup, following behavior is rather unexpected to me:
> >>
> >> (1) hg update -C . will loose the active bookmark
> >>
> >> $ hg update -C .
> >
> > You've supplied an explicit revision to go to. In other words "go to the
> > revision named '.' (and take me off my bookmark)". This is maybe
> > suboptimal for '.'... but is the right behavior for every other type of
> > name.
> 
> We are using "hg update -C ." to discard a merge. Current workaround is 
> to explicitly specify the active bookmark (so no real problem).
> 
> > Vaguely recent Mercurial (3.0.1 or later) will tell you it's
> > deactivating the bookmark.
> 
> Yes, this message is reported.

..but unhelpfully edited out of your report, leading me to conclude
you're using an old version with a bunch of known bugs that we've long
since fixed in this area.

> >> (2) hg upgdate -C checks out r2 (expected), but leaves bookmark bm
> >> active (unexpected)
> >>
> >> $ hg update -C
> >> $ hg summary
> >> parent: 2:eb990d6c7e06 tip
> >>    z added
> >> branch: default
> >> commit: (clean)
> >> update: 1 new changesets, 2 branch heads (merge)
> >
> > Ignoring the -C for now, bare "hg update" says "take me to the head of
> > what I'm working on". Without branches, this means the branch head of
> > the branch you're on. With bookmarks, this currently means a descendant
> > of the bookmark, by analogy.
> >
> >> $ hg bookmarks
> >>    * bm                        1:4009599f6088
> >
> > Yeah, that's weird. But you also have an old hg, so...
> 
> :) Mercurial 3.4.2, released on 2015-07-01?

I've managed to reproduce this behavior. To do so, I needed a repository
that looks like this:

o-o-o-o-o-o-o <- branch tip
   \
    o-o-o
    ^
 bookmark

$ hg update
abort: not a linear update
(merge or update --check to force update)

Not particularly good advice, but now I see why you're using -C: it
bypasses the message and lets you jump across branches.. but leaves the
current bookmark active.

The origin of this behavior comes from the linear case. If we instead
have this shape:

o-o-o-o-o-o-o <- branch tip
  ^
bookmark

..you can update without -C, and the bookmark remains active and moves
to the branch tip. Whether this makes sense is open to debate, but
obviously it only can make sense for linear, non-forced updates.
However, the code in question doesn't have an alternate case to
deactivate bookmarks. You're apparently the first person to notice. I've
just sent a patch to fix that.

-- 
Mathematics is the supreme nostalgia of our time.




More information about the Mercurial mailing list