[PATCH] configitems: support callable as a default value

Pierre-Yves David pierre-yves.david at ens-lyon.org
Wed Jun 28 12:17:17 UTC 2017


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at octobus.net>
# 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:


More information about the Mercurial-devel mailing list