[PATCH 1 of 2] bookmarks: Allow named branches to supersede bookmark names when setting

Will Maier willmaier at ml1.net
Sun Oct 31 00:17:47 UTC 2010


# HG changeset patch
# User Will Maier <willmaier at ml1.net>
# Date 1288478250 18000
# Node ID 9a8f2500aa73d2673bd2224708b7e3c3a6108901
# Parent  6bf8d48bec8e1ab2e0462ce14a914d06e64f7117
bookmarks: Allow named branches to supersede bookmark names when setting.

If a bookmark has the same name as a branch (ie, the bookmark was created with
-f or predates the branch), use the branch's revision when setting the bookmark.
Previously, setting a bookmark to a branch with the same name was a no-op.

diff --git a/hgext/bookmarks.py b/hgext/bookmarks.py
--- a/hgext/bookmarks.py
+++ b/hgext/bookmarks.py
@@ -146,12 +146,17 @@ def bookmark(ui, repo, mark=None, rev=No
                                "whitespace"))
         if mark in marks and not force:
             raise util.Abort(_("a bookmark of the same name already exists"))
-        if ((mark in repo.branchtags() or mark == repo.dirstate.branch())
+        branchtags = repo.branchtags()
+        if ((mark in branchtags or mark == repo.dirstate.branch())
             and not force):
             raise util.Abort(
                 _("a bookmark cannot have the name of an existing branch"))
         if rev:
-            marks[mark] = repo.lookup(rev)
+            if rev in branchtags:
+                rev = branchtags[rev]
+            else:
+                rev = repo.lookup(rev)
+            marks[mark] = rev
         else:
             marks[mark] = repo.changectx('.').node()
         setcurrent(repo, mark)



More information about the Mercurial mailing list