Patchwork [evolve-ext] config: allow disabling commands

login
register
mail settings
Submitter Durham Goode
Date March 20, 2015, 12:47 a.m.
Message ID <3098ba6fe08f61cdeb86.1426812460@dev2000.prn2.facebook.com>
Download mbox | patch
Permalink /patch/8188/
State Accepted
Delegated to: Pierre-Yves David
Headers show

Comments

Durham Goode - March 20, 2015, 12:47 a.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1413412886 25200
#      Wed Oct 15 15:41:26 2014 -0700
# Node ID 3098ba6fe08f61cdeb86d06c44c6b39f6a84d087
# Parent  cd7074949c86348df35ffbd554a54809ce2dc689
config: allow disabling commands

Now that upstream Mercurial has multiple options for obsolete configuration, we
can allow enabling and disabling of evolve commands.
Pierre-Yves David - April 1, 2015, 5:42 p.m.
On 03/19/2015 05:47 PM, Durham Goode wrote:
> # HG changeset patch
> # User Durham Goode <durham@fb.com>
> # Date 1413412886 25200
> #      Wed Oct 15 15:41:26 2014 -0700
> # Node ID 3098ba6fe08f61cdeb86d06c44c6b39f6a84d087
> # Parent  cd7074949c86348df35ffbd554a54809ce2dc689
> config: allow disabling commands

I finally pushed that soryr for the delay

I renamed 'commands' to 'allnewcommands'

Patch

diff --git a/hgext/evolve.py b/hgext/evolve.py
--- a/hgext/evolve.py
+++ b/hgext/evolve.py
@@ -42,6 +42,8 @@  try:
 except (ImportError, AttributeError):
     gboptslist = gboptsmap = None
 
+# Flags for enabling optional parts of evolve
+commandopt = 'commands'
 
 from mercurial import base85
 from mercurial import bookmarks
@@ -337,6 +339,17 @@  def _configureoptions(ui, repo):
         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                                         ###
@@ -943,7 +956,11 @@  def _deprecatealias(oldalias, newalias):
 
     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
@@ -2273,8 +2290,12 @@  def graftwrapper(orig, ui, repo, *revs, 
 @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', [],
diff --git a/tests/test-options.t b/tests/test-options.t
new file mode 100644
--- /dev/null
+++ b/tests/test-options.t
@@ -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
+