[PATCH 1 of 4 evolve-ext] evolve: mechanism to load some commands selectively

Laurent Charignon lcharignon at fb.com
Thu Jun 4 18:52:14 UTC 2015


# HG changeset patch
# User Laurent Charignon <lcharignon at fb.com>
# Date 1432164945 25200
#      Wed May 20 16:35:45 2015 -0700
# Node ID 8f30edd12b336ecdaec68439d0a92085b6ed8340
# Parent  b00c2fe51ac8ecb2ef92c5ddab7e45792d87ed07
evolve: mechanism to load some commands selectively

This patch introduces a new config option to load evolve's command selectively.
It is part of a sequence of patches to make evolve's command respect the value
of experimental.evolution. Once these commands are ready and actually respect
the flag, they are safe to use and can be enabled with the mechanism developed
in this patch.

diff --git a/hgext/evolve.py b/hgext/evolve.py
--- a/hgext/evolve.py
+++ b/hgext/evolve.py
@@ -45,9 +45,6 @@
 except (ImportError, AttributeError):
     gboptslist = gboptsmap = None
 
-# Flags for enabling optional parts of evolve
-commandopt = 'allnewcommands'
-
 from mercurial import bookmarks
 from mercurial import cmdutil
 from mercurial import commands
@@ -365,10 +362,23 @@
     # 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.
+    evolvecommands = ui.configlist('experimental', 'evolutioncommands')
     evolveopts = ui.configlist('experimental', 'evolution')
-    if evolveopts and (commandopt not in evolveopts and
-                       'all' not in evolveopts):
-        cmdtable.clear()
+    if not evolveopts or 'all' in evolveopts:
+        # Evolve is fully loaded, don't disable commands
+        return
+    else:
+        whitelist = set()
+        for cmd in evolvecommands:
+            matchingevolvecommands = [e for e in cmdtable.keys() if cmd in e]
+            if not matchingevolvecommands:
+                raise error.Abort(_('Unknown command'))
+            elif len(matchingevolvecommands) > 1:
+                raise error.Abort(_('Ambiguous command specification'))
+            else:
+                whitelist.add(matchingevolvecommands[0])
+        for disabledcmd in set(cmdtable) - whitelist:
+            del cmdtable[disabledcmd]
 
 #####################################################################
 ### experimental behavior                                         ###
diff --git a/tests/test-evolve.t b/tests/test-evolve.t
--- a/tests/test-evolve.t
+++ b/tests/test-evolve.t
@@ -1022,5 +1022,97 @@
   |
   o  0	: a0 - test
   
+Enabling commands selectively, no command enabled, next and fold and unknown
+  $ cat >> $HGRCPATH <<EOF
+  > [experimental]
+  > evolution=createmarkers
+  > EOF
+  $ hg next
+  hg: unknown command 'next'
+  Mercurial Distributed SCM
+  
+  basic commands:
+  
+   add           add the specified files on the next commit
+   annotate      show changeset information by line for each file
+   clone         make a copy of an existing repository
+   commit        commit the specified files or all outstanding changes
+   diff          diff repository (or selected files)
+   export        dump the header and diffs for one or more changesets
+   forget        forget the specified files on the next commit
+   init          create a new repository in the given directory
+   log           show revision history of entire repository or files
+   merge         merge another revision into working directory
+   pull          pull changes from the specified source
+   push          push changes to the specified destination
+   remove        remove the specified files on the next commit
+   serve         start stand-alone webserver
+   status        show changed files in the working directory
+   summary       summarize working directory state
+   update        update working directory (or switch revisions)
+  
+  (use "hg help" for the full list of commands or "hg -v" for details)
+  [255]
+  $ hg fold
+  hg: unknown command 'fold'
+  Mercurial Distributed SCM
+  
+  basic commands:
+  
+   add           add the specified files on the next commit
+   annotate      show changeset information by line for each file
+   clone         make a copy of an existing repository
+   commit        commit the specified files or all outstanding changes
+   diff          diff repository (or selected files)
+   export        dump the header and diffs for one or more changesets
+   forget        forget the specified files on the next commit
+   init          create a new repository in the given directory
+   log           show revision history of entire repository or files
+   merge         merge another revision into working directory
+   pull          pull changes from the specified source
+   push          push changes to the specified destination
+   remove        remove the specified files on the next commit
+   serve         start stand-alone webserver
+   status        show changed files in the working directory
+   summary       summarize working directory state
+   update        update working directory (or switch revisions)
+  
+  (use "hg help" for the full list of commands or "hg -v" for details)
+  [255]
+Enabling commands selectively, only fold enabled, next is still unknown
+  $ cat >> $HGRCPATH <<EOF
+  > [experimental]
+  > evolution=createmarkers
+  > evolutioncommands=fold
+  > EOF
+  $ hg fold
+  abort: no revisions specified
+  [255]
+  $ hg next
+  hg: unknown command 'next'
+  Mercurial Distributed SCM
+  
+  basic commands:
+  
+   add           add the specified files on the next commit
+   annotate      show changeset information by line for each file
+   clone         make a copy of an existing repository
+   commit        commit the specified files or all outstanding changes
+   diff          diff repository (or selected files)
+   export        dump the header and diffs for one or more changesets
+   fold          fold multiple revisions into a single one
+   forget        forget the specified files on the next commit
+   init          create a new repository in the given directory
+   log           show revision history of entire repository or files
+   merge         merge another revision into working directory
+   pull          pull changes from the specified source
+   push          push changes to the specified destination
+   remove        remove the specified files on the next commit
+   serve         start stand-alone webserver
+   status        show changed files in the working directory
+   summary       summarize working directory state
+   update        update working directory (or switch revisions)
+  
+  (use "hg help" for the full list of commands or "hg -v" for details)
+  [255]
 
-


More information about the Mercurial-devel mailing list