hgext/inhibit.py
changeset 1241 3625d006e81b
parent 1240 e1347ce2f954
child 1247 f96dad835054
--- 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):