[PATCH 1 of 2 evolve-ext-V2] directaccess: change rule from opt-in to opt-out

Laurent Charignon lcharignon at fb.com
Tue Jun 16 18:46:25 UTC 2015


# HG changeset patch
# User Laurent Charignon <lcharignon at fb.com>
# Date 1434474528 25200
#      Tue Jun 16 10:08:48 2015 -0700
# Node ID 0878226593514af85c74897b290af6f99902eb47
# Parent  5c13945b32fc4bcb4998a1bdd0b669ac43c26574
directaccess: change rule from opt-in to opt-out

Before this patch we would opt-in commands for direct access and the default
filter for new repository was 'visible'.
With this patch, the default filter for new repos is
'visible-directaccess-warn'. It means that by default all the commands have
directaccess with warnings.

diff --git a/hgext/directaccess.py b/hgext/directaccess.py
--- a/hgext/directaccess.py
+++ b/hgext/directaccess.py
@@ -12,18 +12,19 @@ from mercurial import branchmap
 from mercurial import revset
 from mercurial import error
 from mercurial import commands
+from mercurial import hg
 from mercurial.i18n import _
 
 cmdtable = {}
 command = cmdutil.command(cmdtable)
 
-# List of commands where no warning is shown for direct access
+# By default, all the commands have directaccess with warnings
+# List of commands that have no directaccess and directaccess with no warning
 directaccesslevel = [
-    # warning or not, extension (None if core), command name
-    (False, None, 'update'), 
-    (False, None, 'export'),
-    (True,  'rebase', 'rebase'),
-    (False,  'evolve', 'prune'),
+    # 'nowarning' or 'error', (None if core) or extension name, command name
+    ('nowarning', None, 'update'),
+    ('nowarning', None, 'export'),
+    ('nowarning',  'evolve', 'prune'),
 ]
 
 def reposetup(ui, repo):
@@ -49,19 +50,19 @@ def setupdirectaccess():
     for warn, ext, cmd in directaccesslevel:
         try:
             cmdtable = extensions.find(ext).cmdtable if ext else commands.table
-            wrapper = wrapwithwarning if warn else wrapwithoutwarning
+            wrapper = wrapwitherror if warn == 'error' else wrapwithoutwarning
             extensions.wrapcommand(cmdtable, cmd, wrapper)
         except (error.UnknownCommand, KeyError):
             pass
 
-def wrapwithoutwarning(orig, ui, repo, *args, **kwargs):
-    if repo and repo.filtername == 'visible':
-        repo = repo.filtered("visible-directaccess-nowarn")
+def wrapwitherror(orig, ui, repo, *args, **kwargs):
+    if repo and repo.filtername == 'visible-directaccess-warn':
+        repo = repo.filtered('visible')
     return orig(ui, repo, *args, **kwargs)
 
-def wrapwithwarning(orig, ui, repo, *args, **kwargs):
-    if repo and repo.filtername == 'visible':
-        repo = repo.filtered("visible-directaccess-warn")
+def wrapwithoutwarning(orig, ui, repo, *args, **kwargs):
+    if repo and repo.filtername == 'visible-directaccess-warn':
+        repo = repo.filtered("visible-directaccess-nowarn")
     return orig(ui, repo, *args, **kwargs)
 
 def uisetup(ui):
@@ -85,8 +86,14 @@ def uisetup(ui):
         order.remove('directaccess')
         extensions._order = order
 
+def _repository(orig, *args, **kwargs):
+    """Make visible-directaccess-warn the default filter for new repos"""
+    repo = orig(*args, **kwargs)
+    return repo.filtered("visible-directaccess-warn")
+
 def extsetup(ui):
     extensions.wrapfunction(revset, 'posttreebuilthook', _posttreebuilthook)
+    extensions.wrapfunction(hg, 'repository', _repository)
     setupdirectaccess()
 
 def gethashsymbols(tree):


More information about the Mercurial-devel mailing list