Patchwork [evolve-ext] inhibit: move transaction wrapping outside of repo setup

login
register
mail settings
Submitter Laurent Charignon
Date June 16, 2015, 5:04 p.m.
Message ID <577fd643ac5eaaf4dec1.1434474248@lcharignon-mbp.dhcp.thefacebook.com>
Download mbox | patch
Permalink /patch/9678/
State Accepted
Headers show

Comments

Laurent Charignon - June 16, 2015, 5:04 p.m.
# HG changeset patch
# User Laurent Charignon <lcharignon@fb.com>
# Date 1434415091 25200
#      Mon Jun 15 17:38:11 2015 -0700
# Node ID 577fd643ac5eaaf4dec17bc7bb8516920897af17
# Parent  5c13945b32fc4bcb4998a1bdd0b669ac43c26574
inhibit: move transaction wrapping outside of repo setup

Before this patch, transaction wrapping code was done in reposetup. It happened
to cause stackoverflows in repos with a lot of subreps.

This patch moves the wrapping to extsetup and avoids this problem.
Laurent Charignon - June 16, 2015, 5:06 p.m.
Please disregard this patch, I made an accidental amend before sending it.

> On Jun 16, 2015, at 10:04 AM, Laurent Charignon <lcharignon@fb.com> wrote:
> 
> # HG changeset patch
> # User Laurent Charignon <lcharignon@fb.com>
> # Date 1434415091 25200
> #      Mon Jun 15 17:38:11 2015 -0700
> # Node ID 577fd643ac5eaaf4dec17bc7bb8516920897af17
> # Parent  5c13945b32fc4bcb4998a1bdd0b669ac43c26574
> inhibit: move transaction wrapping outside of repo setup
> 
> Before this patch, transaction wrapping code was done in reposetup. It happened
> to cause stackoverflows in repos with a lot of subreps.
> 
> This patch moves the wrapping to extsetup and avoids this problem.
> 
> diff --git a/hgext/directaccess.py b/hgext/directaccess.py
> --- a/hgext/directaccess.py
> +++ b/hgext/directaccess.py
> @@ -11,21 +11,25 @@ from mercurial import repoview
> from mercurial import branchmap
> from mercurial import revset
> from mercurial import error
> -from mercurial import commands
> +from mercurial import commands, hg
> from mercurial.i18n import _
> 
> cmdtable = {}
> command = cmdutil.command(cmdtable)
> 
> -# List of commands where no warning is shown for direct access
> -directaccesslevel = [
> -    # warning or not, extension (None if core), command name
> -    (False, None, 'update'), 
> -    (False, None, 'export'),
> -    (True,  'rebase', 'rebase'),
> -    (False,  'evolve', 'prune'),
> +# List of commands that have restricted / or no directaccess
> +directaccesswarning = [
> +    # (None if core) or extension name, command name
> +    ('rebase', 'rebase'),
> ]
> 
> +directaccessforbidden = [
> +    # (None if core) or extension name, command name
> +    (None, 'serve'),
> +    (None, 'push'),
> +]
> +
> +
> def reposetup(ui, repo):
>     repo._explicitaccess = set()
> 
> @@ -46,13 +50,13 @@ def setupdirectaccess():
>     branchmap.subsettable['visible-directaccess-nowarn'] = 'visible'
>     branchmap.subsettable['visible-directaccess-warn'] = 'visible'
> 
> -    for warn, ext, cmd in directaccesslevel:
> -        try:
> -            cmdtable = extensions.find(ext).cmdtable if ext else commands.table
> -            wrapper = wrapwithwarning if warn else wrapwithoutwarning
> -            extensions.wrapcommand(cmdtable, cmd, wrapper)
> -        except (error.UnknownCommand, KeyError):
> -            pass
> +    #for warn, ext, cmd in directaccesslevel:
> +    #    try:
> +    #        cmdtable = extensions.find(ext).cmdtable if ext else commands.table
> +    #        wrapper = wrapwithwarning if warn 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':
> @@ -85,8 +89,13 @@ def uisetup(ui):
>         order.remove('directaccess')
>         extensions._order = order
> 
> +def _repository(orig, *args, **kwargs):
> +    repo = orig(*args, **kwargs)
> +    return repo.filtered("visible-directaccess-nowarn")
> +
> def extsetup(ui):
>     extensions.wrapfunction(revset, 'posttreebuilthook', _posttreebuilthook)
> +    extensions.wrapfunction(hg, 'repository', _repository)
>     setupdirectaccess()
> 
> def gethashsymbols(tree):
> diff --git a/hgext/inhibit.py b/hgext/inhibit.py
> --- a/hgext/inhibit.py
> +++ b/hgext/inhibit.py
> @@ -48,9 +48,6 @@ def reposetup(ui, repo):
>             return newnode
> 
>     repo.__class__ = obsinhibitedrepo
> -    # Wrapping this to inhibit obsolete revs resulting from a transaction
> -    extensions.wrapfunction(localrepo.localrepository,
> -                            'transaction', transactioncallback)
> 
> def _update(orig, ui, repo, *args, **kwargs):
>     """
> @@ -199,6 +196,11 @@ def extsetup(ui):
>     except KeyError:
>         errormsg = _('Cannot use inhibit without the direct access extension')
>         raise error.Abort(errormsg)
> +
> +    # Wrapping this to inhibit obsolete revs resulting from a transaction
> +    extensions.wrapfunction(localrepo.localrepository,
> +                            'transaction', transactioncallback)
> +
>     obsolete.cachefuncs['obsolete'] = _computeobsoleteset
>     # wrap create marker to make it able to lift the inhibition
>     extensions.wrapfunction(obsolete, 'createmarkers', _createmarkers)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff --git a/hgext/directaccess.py b/hgext/directaccess.py
--- a/hgext/directaccess.py
+++ b/hgext/directaccess.py
@@ -11,21 +11,25 @@  from mercurial import repoview
 from mercurial import branchmap
 from mercurial import revset
 from mercurial import error
-from mercurial import commands
+from mercurial import commands, hg
 from mercurial.i18n import _
 
 cmdtable = {}
 command = cmdutil.command(cmdtable)
 
-# List of commands where no warning is shown for direct access
-directaccesslevel = [
-    # warning or not, extension (None if core), command name
-    (False, None, 'update'), 
-    (False, None, 'export'),
-    (True,  'rebase', 'rebase'),
-    (False,  'evolve', 'prune'),
+# List of commands that have restricted / or no directaccess
+directaccesswarning = [
+    # (None if core) or extension name, command name
+    ('rebase', 'rebase'),
 ]
 
+directaccessforbidden = [
+    # (None if core) or extension name, command name
+    (None, 'serve'),
+    (None, 'push'),
+]
+
+
 def reposetup(ui, repo):
     repo._explicitaccess = set()
 
@@ -46,13 +50,13 @@  def setupdirectaccess():
     branchmap.subsettable['visible-directaccess-nowarn'] = 'visible'
     branchmap.subsettable['visible-directaccess-warn'] = 'visible'
 
-    for warn, ext, cmd in directaccesslevel:
-        try:
-            cmdtable = extensions.find(ext).cmdtable if ext else commands.table
-            wrapper = wrapwithwarning if warn else wrapwithoutwarning
-            extensions.wrapcommand(cmdtable, cmd, wrapper)
-        except (error.UnknownCommand, KeyError):
-            pass
+    #for warn, ext, cmd in directaccesslevel:
+    #    try:
+    #        cmdtable = extensions.find(ext).cmdtable if ext else commands.table
+    #        wrapper = wrapwithwarning if warn 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':
@@ -85,8 +89,13 @@  def uisetup(ui):
         order.remove('directaccess')
         extensions._order = order
 
+def _repository(orig, *args, **kwargs):
+    repo = orig(*args, **kwargs)
+    return repo.filtered("visible-directaccess-nowarn")
+
 def extsetup(ui):
     extensions.wrapfunction(revset, 'posttreebuilthook', _posttreebuilthook)
+    extensions.wrapfunction(hg, 'repository', _repository)
     setupdirectaccess()
 
 def gethashsymbols(tree):
diff --git a/hgext/inhibit.py b/hgext/inhibit.py
--- a/hgext/inhibit.py
+++ b/hgext/inhibit.py
@@ -48,9 +48,6 @@  def reposetup(ui, repo):
             return newnode
 
     repo.__class__ = obsinhibitedrepo
-    # Wrapping this to inhibit obsolete revs resulting from a transaction
-    extensions.wrapfunction(localrepo.localrepository,
-                            'transaction', transactioncallback)
 
 def _update(orig, ui, repo, *args, **kwargs):
     """
@@ -199,6 +196,11 @@  def extsetup(ui):
     except KeyError:
         errormsg = _('Cannot use inhibit without the direct access extension')
         raise error.Abort(errormsg)
+
+    # Wrapping this to inhibit obsolete revs resulting from a transaction
+    extensions.wrapfunction(localrepo.localrepository,
+                            'transaction', transactioncallback)
+
     obsolete.cachefuncs['obsolete'] = _computeobsoleteset
     # wrap create marker to make it able to lift the inhibition
     extensions.wrapfunction(obsolete, 'createmarkers', _createmarkers)