config: allow disabling commands
Now that upstream Mercurial has multiple options for obsolete configuration, we
can allow enabling and disabling of evolve commands.
--- a/hgext/evolve.py Sat Mar 07 02:32:43 2015 -0800
+++ b/hgext/evolve.py Wed Oct 15 15:41:26 2014 -0700
@@ -44,6 +44,8 @@
except (ImportError, AttributeError):
gboptslist = gboptsmap = None
+# Flags for enabling optional parts of evolve
+commandopt = 'commands'
from mercurial import base85
from mercurial import bookmarks
@@ -353,6 +355,17 @@
evolveopts = ['all']
ui.setconfig('experimental', 'evolution', evolveopts)
+@eh.uisetup
+def _configurecmdoptions(ui):
+ # Unregister evolve commands if the command capability is not specified.
+ #
+ # This must be in the same function as the option configuration above to
+ # guarantee it happens after the above configuration, but before the
+ # extsetup functions.
+ evolveopts = ui.configlist('experimental', 'evolution')
+ if evolveopts and (commandopt not in evolveopts and
+ 'all' not in evolveopts):
+ cmdtable.clear()
#####################################################################
### experimental behavior ###
@@ -959,7 +972,11 @@
This function is loosely based on the extensions.wrapcommand function.
'''
- aliases, entry = cmdutil.findcmd(newalias, cmdtable)
+ try:
+ aliases, entry = cmdutil.findcmd(newalias, cmdtable)
+ except error.UnknownCommand:
+ # Commands may be disabled
+ return
for alias, e in cmdtable.iteritems():
if e is entry:
break
@@ -2335,8 +2352,12 @@
@eh.extsetup
def oldevolveextsetup(ui):
for cmd in ['kill', 'uncommit', 'touch', 'fold']:
- entry = extensions.wrapcommand(cmdtable, cmd,
- warnobserrors)
+ try:
+ entry = extensions.wrapcommand(cmdtable, cmd,
+ warnobserrors)
+ except error.UnknownCommand:
+ # Commands may be disabled
+ continue
entry = cmdutil.findcmd('commit', commands.table)[1]
entry[1].append(('o', 'obsolete', [],
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-options.t Wed Oct 15 15:41:26 2014 -0700
@@ -0,0 +1,30 @@
+ $ cat >> $HGRCPATH <<EOF
+ > [ui]
+ > logtemplate={rev}:{node|short}[{bookmarks}] ({obsolete}/{phase}) {desc|firstline}\n
+ > [extensions]
+ > EOF
+ $ echo "evolve=$(echo $(dirname $TESTDIR))/hgext/evolve.py" >> $HGRCPATH
+
+ $ mkcommit() {
+ > echo "$1" > "$1"
+ > hg add "$1"
+ > hg ci -m "add $1"
+ > }
+
+ $ hg init repo
+ $ cd repo
+ $ mkcommit a
+ $ mkcommit b
+
+test disabling commands
+
+ $ cat >> .hg/hgrc <<EOF
+ > [experimental]
+ > evolution=createmarkers
+ > allowunstable
+ > exchange
+ > EOF
+ $ hg prune | head -n 2
+ hg: unknown command 'prune'
+ Mercurial Distributed SCM
+