# HG changeset patch # User Kevin Bullock # Date 1375411394 18000 # Node ID f37b5a17e6a0ee17afde2cdde5393dd74715fb58 # Parent 3d19b81366410f8bb72dbde8969be124fe612def bookmarks: pull --update updates to active bookmark if it moved (issue4007) This makes `hg pull --update` behave the same wrt the active bookmark as `hg pull && hg update` does as of 2096e025a728. A helper function, bookmarks.calculateupdate, is added to prevent code duplication between postincoming and update. diff -r 3d19b8136641 -r f37b5a17e6a0 mercurial/bookmarks.py --- a/mercurial/bookmarks.py Thu Aug 01 20:06:00 2013 -0500 +++ b/mercurial/bookmarks.py Thu Aug 01 21:43:14 2013 -0500 @@ -170,6 +170,19 @@ deleted = True return deleted +def calculateupdate(ui, repo, checkout): + '''Return a tuple (targetrev, movemarkfrom) indicating the rev to + check out and where to move the active bookmark from, if needed.''' + movemarkfrom = None + if checkout is None: + curmark = repo._bookmarkcurrent + if iscurrent(repo): + movemarkfrom = repo['.'].node() + elif curmark: + ui.status(_("updating to active bookmark %s\n") % curmark) + checkout = curmark + return (checkout, movemarkfrom) + def update(repo, parents, node): deletefrom = parents marks = repo._bookmarks diff -r 3d19b8136641 -r f37b5a17e6a0 mercurial/commands.py --- a/mercurial/commands.py Thu Aug 01 20:06:00 2013 -0500 +++ b/mercurial/commands.py Thu Aug 01 21:43:14 2013 -0500 @@ -4520,7 +4520,7 @@ if modheads == 0: return if optupdate: - movemarkfrom = repo['.'].node() + checkout, movemarkfrom = bookmarks.calculateupdate(ui, repo, checkout) try: ret = hg.update(repo, checkout) except util.Abort, inst: @@ -5829,14 +5829,7 @@ cmdutil.clearunfinished(repo) # with no argument, we also move the current bookmark, if any - movemarkfrom = None - if rev is None: - curmark = repo._bookmarkcurrent - if bookmarks.iscurrent(repo): - movemarkfrom = repo['.'].node() - elif curmark: - ui.status(_("updating to active bookmark %s\n") % curmark) - rev = curmark + rev, movemarkfrom = bookmarks.calculateupdate(ui, repo, rev) # if we defined a bookmark, we have to remember the original bookmark name brev = rev diff -r 3d19b8136641 -r f37b5a17e6a0 tests/test-bookmarks.t --- a/tests/test-bookmarks.t Thu Aug 01 20:06:00 2013 -0500 +++ b/tests/test-bookmarks.t Thu Aug 01 21:43:14 2013 -0500 @@ -507,19 +507,37 @@ * Z 3:125c9a1d6df6 x y 2:db815d6d32e6 +pull --update works the same as pull && update + + $ hg bookmark -r3 Y + moving bookmark 'Y' forward from db815d6d32e6 + $ hg -R cloned-bookmarks-update update Y + 0 files updated, 0 files merged, 0 files removed, 0 files unresolved + $ hg -R cloned-bookmarks-update pull --update . + pulling from . + searching for changes + adding changesets + adding manifests + adding file changes + added 2 changesets with 2 changes to 2 files (+1 heads) + updating bookmark Y + updating bookmark Z + updating to active bookmark Y + 1 files updated, 0 files merged, 0 files removed, 0 files unresolved + test wrongly formated bookmark $ echo '' >> .hg/bookmarks $ hg bookmarks X2 1:925d80f479bb - Y 2:db815d6d32e6 + Y 3:125c9a1d6df6 * Z 3:125c9a1d6df6 x y 2:db815d6d32e6 $ echo "Ican'thasformatedlines" >> .hg/bookmarks $ hg bookmarks malformed line in .hg/bookmarks: "Ican'thasformatedlines" X2 1:925d80f479bb - Y 2:db815d6d32e6 + Y 3:125c9a1d6df6 * Z 3:125c9a1d6df6 x y 2:db815d6d32e6