[PATCH] localrepo: move current bookmark to latest rev of the current branch

David Soria Parra dsp at php.net
Sat Mar 12 08:35:25 CST 2011


# HG changeset patch
# User David Soria Parra <dsp at php.net>
# Date 1299940401 -3600
# Branch stable
# Node ID ac72cfb7afd08f7a4dd7bb468697ab2eb2f02dd4
# Parent  8e94a1b4e9a48ec37c54eea39b4076ba302d085f
localrepo: move current bookmark to latest rev of the current branch

Move the current bookmark to the latest rev on the current branch if
we use addchangectx (e.g. hg unbundle). The bookmark will be pointing
to the same rev that hg update will take you to.

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1915,9 +1915,15 @@
                 self.hook("incoming", node=hex(cl.node(i)),
                           source=srctype, url=url)
 
-        # FIXME - why does this care about tip?
-        if newheads == oldheads:
-            bookmarks.update(self, self.dirstate.parents(), self['tip'].node())
+        wc = self['.']
+        try:
+            node = self.branchtags()[wc.branch()]
+        except KeyError:
+            if wc.branch() == "default": # no default branch!
+                node = repo.lookup("tip") # update to tip
+            else:
+                raise util.Abort(_("branch %s not found") % wc.branch())
+        bookmarks.update(self, wc.node(), node)
 
         # never return 0 here:
         if newheads < oldheads:
diff --git a/tests/test-bookmarks.t b/tests/test-bookmarks.t
--- a/tests/test-bookmarks.t
+++ b/tests/test-bookmarks.t
@@ -222,6 +222,37 @@
   abort: bookmark 'foo:bar' contains illegal character
   [255]
 
+create bundle with two heads
+
+  $ hg clone . tobundle
+  updating to branch default
+  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ echo x > tobundle/x
+  $ hg -R tobundle add tobundle/x
+  $ hg -R tobundle commit -m'x'
+  $ hg -R tobundle update -r -2
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ echo y > tobundle/y
+  $ hg -R tobundle branch test
+  marked working directory as branch test
+  $ hg -R tobundle add tobundle/y
+  $ hg -R tobundle commit -m'y'
+  $ hg -R tobundle bundle tobundle.hg
+  searching for changes
+  2 changesets found
+  $ hg unbundle tobundle.hg
+  adding changesets
+  adding manifests
+  adding file changes
+  added 2 changesets with 2 changes to 2 files (+1 heads)
+  (run 'hg heads' to see heads, 'hg merge' to merge)
+  $ hg update
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg bookmarks
+     X2                        1:925d80f479bb
+     Y                         2:db815d6d32e6
+   * Z                         3:125c9a1d6df6
+     x  y                      2:db815d6d32e6
 the bookmark extension should be ignored now that it is part of core
 
   $ echo "[extensions]" >> $HGRCPATH
@@ -229,18 +260,18 @@
   $ hg bookmarks
      X2                        1:925d80f479bb
      Y                         2:db815d6d32e6
-   * Z                         2:db815d6d32e6
+   * Z                         3:125c9a1d6df6
      x  y                      2:db815d6d32e6
 test summary
 
   $ hg summary
-  parent: 2:db815d6d32e6 tip Y Z x  y
-   2
+  parent: 3:125c9a1d6df6  Z
+   x
   branch: default
-  commit: (clean)
+  commit: 1 unknown (clean)
   update: 1 new changesets, 2 branch heads (merge)
 
 test id
 
   $ hg id
-  db815d6d32e6 tip Y/Z/x  y
+  125c9a1d6df6 Z


More information about the Mercurial-devel mailing list