inhibit: Add -D option to the bookmark command
authorLaurent Charignon <lcharignon@fb.com>
Tue, 31 Mar 2015 14:17:46 -0700
changeset 1241 3625d006e81b
parent 1240 e1347ce2f954
child 1242 cf846d47bb7e
inhibit: Add -D option to the bookmark command The -D option for bookmark is similar to the -B option for strip. It deletes the bookmark and prunes the changes underneath it that are not reachable.
hgext/inhibit.py
tests/test-inhibit.t
--- a/hgext/inhibit.py	Wed Apr 01 13:51:21 2015 -0700
+++ b/hgext/inhibit.py	Tue Mar 31 14:17:46 2015 -0700
@@ -30,6 +30,7 @@
 from mercurial import error
 from mercurial import commands
 from mercurial import bookmarks
+from mercurial.i18n import _
 
 cmdtable = {}
 command = cmdutil.command(cmdtable)
@@ -73,6 +74,29 @@
     _inhibitmarkers(repo, bkmstorenodes)
     return orig(bkmstoreinst, *args, **kwargs)
 
+def _bookmark(orig, ui, repo, *bookmarks, **opts):
+    """ Add a -D option to the bookmark command, map it to prune -B """
+    def getdefaultopts(module, command):
+        """ Get default options of a command from a module """
+        cmds = [v for k,v in module.cmdtable.items() if command in k]
+        assert len(cmds) == 1, "Ambiguous command"
+        # Options of the first command that matched
+        cmdopts = cmds[0][1]
+        optsdict = {}
+        for d in cmdopts:
+            optsdict[d[1]] = d[2]
+        return optsdict
+
+    haspruneopt = opts.get('prune', False)
+
+    if not haspruneopt:
+        return orig(ui, repo, *bookmarks, **opts)
+    # Call prune -B
+    evolve = extensions.find('evolve')
+    optsdict = getdefaultopts(evolve, 'prune|obsolete')
+    optsdict['bookmark'] = bookmarks[0]
+    evolve.cmdprune(ui, repo, **optsdict)
+
 # obsolescence inhibitor
 ########################
 
@@ -182,6 +206,11 @@
     # wrap both to add inhibition markers.
     extensions.wrapfunction(bookmarks.bmstore, 'recordchange', _bookmarkchanged)
     extensions.wrapfunction(bookmarks.bmstore, 'write', _bookmarkchanged)
+    # Add bookmark -D option
+    entry = extensions.wrapcommand(commands.table, 'bookmark', _bookmark)
+    entry[1].append(('D','prune',None,
+                    _('delete the bookmark and prune the commits underneath')))
+
 
 
 def gethashsymbols(tree):
--- a/tests/test-inhibit.t	Wed Apr 01 13:51:21 2015 -0700
+++ b/tests/test-inhibit.t	Tue Mar 31 14:17:46 2015 -0700
@@ -261,9 +261,32 @@
   |/
   o  0:54ccbc537fc2 add cA
   
-  $ hg bookmark -d book1
-  $ hg prune --hidden 1::
-  3 changesets pruned
+
+Removing a bookmark with bookmark -D should prune the changes underneath
+that are not reachable from another bookmark or head
+
+  $ hg bookmark -r 1 book2
+  $ hg bookmark -D book1
+  bookmark 'book1' deleted
+  1 changesets pruned
+  $ hg log -G
+  @  9:55c73a90e4b4 add cJ
+  |
+  | o  7:18214586bf78 add cJ
+  |/
+  o  6:cf5c4f4554ce add cH
+  |
+  o  5:5419eb264a33 add cG
+  |
+  o  4:98065434e5c6 add cE
+  |
+  | o  1:02bcbc3f6e56 add cB
+  |/
+  o  0:54ccbc537fc2 add cA
+  
+  $ hg bookmark -D book2
+  bookmark 'book2' deleted
+  1 changesets pruned
   $ hg log -G
   @  9:55c73a90e4b4 add cJ
   |