Patchwork [2,of,2,STABLE] registrar: host "dynamicdefault" constant by configitem object

login
register
mail settings
Submitter Yuya Nishihara
Date Oct. 21, 2017, 5:16 a.m.
Message ID <dc05c59e3f1714c4face.1508562993@mimosa>
Download mbox | patch
Permalink /patch/25264/
State Accepted
Headers show

Comments

Yuya Nishihara - Oct. 21, 2017, 5:16 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1508559200 -32400
#      Sat Oct 21 13:13:20 2017 +0900
# Branch stable
# Node ID dc05c59e3f1714c4faceb4c1eed66a5afe0ec000
# Parent  3600f7eaed2124e575af498043c6401233b8b2ba
registrar: host "dynamicdefault" constant by configitem object

This is the common pattern seen in the other registrar classes.
Augie Fackler - Oct. 22, 2017, 7:26 p.m.
> On Oct 21, 2017, at 1:16 AM, Yuya Nishihara <yuya@tcha.org> wrote:
> 
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1508559200 -32400
> #      Sat Oct 21 13:13:20 2017 +0900
> # Branch stable
> # Node ID dc05c59e3f1714c4faceb4c1eed66a5afe0ec000
> # Parent  3600f7eaed2124e575af498043c6401233b8b2ba
> registrar: host "dynamicdefault" constant by configitem object

queued, thanks

> 
> This is the common pattern seen in the other registrar classes.
> 
> diff --git a/hgext/bugzilla.py b/hgext/bugzilla.py
> --- a/hgext/bugzilla.py
> +++ b/hgext/bugzilla.py
> @@ -301,7 +301,6 @@ from mercurial.i18n import _
> from mercurial.node import short
> from mercurial import (
>     cmdutil,
> -    configitems,
>     error,
>     mail,
>     registrar,
> @@ -354,7 +353,7 @@ configitem('bugzilla', 'host',
>     default='localhost',
> )
> configitem('bugzilla', 'notify',
> -    default=configitems.dynamicdefault,
> +    default=configitem.dynamicdefault,
> )
> configitem('bugzilla', 'password',
>     default=None,
> diff --git a/hgext/histedit.py b/hgext/histedit.py
> --- a/hgext/histedit.py
> +++ b/hgext/histedit.py
> @@ -190,7 +190,6 @@ from mercurial.i18n import _
> from mercurial import (
>     bundle2,
>     cmdutil,
> -    configitems,
>     context,
>     copies,
>     destutil,
> @@ -221,7 +220,7 @@ configitem('experimental', 'histedit.aut
>     default=False,
> )
> configitem('histedit', 'defaultrev',
> -    default=configitems.dynamicdefault,
> +    default=configitem.dynamicdefault,
> )
> configitem('histedit', 'dropmissing',
>     default=False,
> diff --git a/hgext/largefiles/__init__.py b/hgext/largefiles/__init__.py
> --- a/hgext/largefiles/__init__.py
> +++ b/hgext/largefiles/__init__.py
> @@ -107,7 +107,6 @@ command.
> from __future__ import absolute_import
> 
> from mercurial import (
> -    configitems,
>     hg,
>     localrepo,
>     registrar,
> @@ -131,7 +130,7 @@ configtable = {}
> configitem = registrar.configitem(configtable)
> 
> configitem('largefiles', 'minsize',
> -    default=configitems.dynamicdefault,
> +    default=configitem.dynamicdefault,
> )
> configitem('largefiles', 'patterns',
>     default=list,
> diff --git a/mercurial/configitems.py b/mercurial/configitems.py
> --- a/mercurial/configitems.py
> +++ b/mercurial/configitems.py
> @@ -106,7 +106,10 @@ dynamicdefault = object()
> # Registering actual config items
> 
> def getitemregister(configtable):
> -    return functools.partial(_register, configtable)
> +    f = functools.partial(_register, configtable)
> +    # export pseudo enum as configitem.*
> +    f.dynamicdefault = dynamicdefault
> +    return f
> 
> coreconfigitem = getitemregister(coreitems)
> 
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Boris Feld - Oct. 23, 2017, 8:12 a.m.
On Sat, 2017-10-21 at 14:16 +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1508559200 -32400
> #      Sat Oct 21 13:13:20 2017 +0900
> # Branch stable
> # Node ID dc05c59e3f1714c4faceb4c1eed66a5afe0ec000
> # Parent  3600f7eaed2124e575af498043c6401233b8b2ba
> registrar: host "dynamicdefault" constant by configitem object
> 
> This is the common pattern seen in the other registrar classes.

Ha good idea, importing the extra module was annoying. Thanks!

Patch

diff --git a/hgext/bugzilla.py b/hgext/bugzilla.py
--- a/hgext/bugzilla.py
+++ b/hgext/bugzilla.py
@@ -301,7 +301,6 @@  from mercurial.i18n import _
 from mercurial.node import short
 from mercurial import (
     cmdutil,
-    configitems,
     error,
     mail,
     registrar,
@@ -354,7 +353,7 @@  configitem('bugzilla', 'host',
     default='localhost',
 )
 configitem('bugzilla', 'notify',
-    default=configitems.dynamicdefault,
+    default=configitem.dynamicdefault,
 )
 configitem('bugzilla', 'password',
     default=None,
diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -190,7 +190,6 @@  from mercurial.i18n import _
 from mercurial import (
     bundle2,
     cmdutil,
-    configitems,
     context,
     copies,
     destutil,
@@ -221,7 +220,7 @@  configitem('experimental', 'histedit.aut
     default=False,
 )
 configitem('histedit', 'defaultrev',
-    default=configitems.dynamicdefault,
+    default=configitem.dynamicdefault,
 )
 configitem('histedit', 'dropmissing',
     default=False,
diff --git a/hgext/largefiles/__init__.py b/hgext/largefiles/__init__.py
--- a/hgext/largefiles/__init__.py
+++ b/hgext/largefiles/__init__.py
@@ -107,7 +107,6 @@  command.
 from __future__ import absolute_import
 
 from mercurial import (
-    configitems,
     hg,
     localrepo,
     registrar,
@@ -131,7 +130,7 @@  configtable = {}
 configitem = registrar.configitem(configtable)
 
 configitem('largefiles', 'minsize',
-    default=configitems.dynamicdefault,
+    default=configitem.dynamicdefault,
 )
 configitem('largefiles', 'patterns',
     default=list,
diff --git a/mercurial/configitems.py b/mercurial/configitems.py
--- a/mercurial/configitems.py
+++ b/mercurial/configitems.py
@@ -106,7 +106,10 @@  dynamicdefault = object()
 # Registering actual config items
 
 def getitemregister(configtable):
-    return functools.partial(_register, configtable)
+    f = functools.partial(_register, configtable)
+    # export pseudo enum as configitem.*
+    f.dynamicdefault = dynamicdefault
+    return f
 
 coreconfigitem = getitemregister(coreitems)