From patchwork Wed Jun 28 12:17:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: configitems: support callable as a default value From: Pierre-Yves David X-Patchwork-Id: 21797 Message-Id: <2aff498b940b59f6ec18.1498652237@nodosa.octopoid.net> To: mercurial-devel@mercurial-scm.org Date: Wed, 28 Jun 2017 14:17:17 +0200 # HG changeset patch # User Pierre-Yves David # Date 1498650620 -7200 # Wed Jun 28 13:50:20 2017 +0200 # Node ID 2aff498b940b59f6ec1872096ba0d02dc362696c # Parent 1f704b77446b3e22c4352ebb85d51bfca837a3a7 # EXP-Topic config.register # Available At https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ # hg pull https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ -r 2aff498b940b configitems: support callable as a default value Yuya pointed out that using mutable value as the default could be problematic. To work around this we now support callable object as default value. This allows for creating new mutable objects on demand when needed. diff --git a/mercurial/configitems.py b/mercurial/configitems.py --- a/mercurial/configitems.py +++ b/mercurial/configitems.py @@ -60,7 +60,7 @@ coreconfigitem('patch', 'fuzz', default=2, ) coreconfigitem('ui', 'clonebundleprefers', - default=[], + default=list, ) coreconfigitem('ui', 'interactive', default=None, diff --git a/mercurial/ui.py b/mercurial/ui.py --- a/mercurial/ui.py +++ b/mercurial/ui.py @@ -455,6 +455,8 @@ class ui(object): if default is _unset: if item is None: value = default + elif callable(item.default): + value = item.default() else: value = item.default elif item is not None: