Patchwork [05,of,10] config: use the new '_unset' value for 'configbytes'

login
register
mail settings
Submitter Pierre-Yves David
Date June 18, 2017, 6:55 p.m.
Message ID <fa4f7a297bc32124742d.1497812115@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/21484/
State Accepted
Headers show

Comments

Pierre-Yves David - June 18, 2017, 6:55 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@octobus.net>
# Date 1497696831 -7200
#      Sat Jun 17 12:53:51 2017 +0200
# Node ID fa4f7a297bc32124742d631460fa44677854f202
# Parent  11f995470103d355c41e2bfc7b37160175f026cd
# 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 fa4f7a297bc3
config: use the new '_unset' value for 'configbytes'

This should let 'configbytes' delegates all special processing of the default
config value to the main 'config' method.
Gregory Szorc - June 21, 2017, 3:06 a.m.
On Sun, Jun 18, 2017 at 11:55 AM, Pierre-Yves David <
pierre-yves.david@ens-lyon.org> wrote:

> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@octobus.net>
> # Date 1497696831 -7200
> #      Sat Jun 17 12:53:51 2017 +0200
> # Node ID fa4f7a297bc32124742d631460fa44677854f202
> # Parent  11f995470103d355c41e2bfc7b37160175f026cd
> # 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 fa4f7a297bc3
> config: use the new '_unset' value for 'configbytes'
>
> This should let 'configbytes' delegates all special processing of the
> default
> config value to the main 'config' method.
>
> diff --git a/mercurial/ui.py b/mercurial/ui.py
> --- a/mercurial/ui.py
> +++ b/mercurial/ui.py
> @@ -558,7 +558,7 @@ class ui(object):
>          return self.configwith(int, section, name, default, 'integer',
>                                 untrusted)
>
> -    def configbytes(self, section, name, default=0, untrusted=False):
> +    def configbytes(self, section, name, default=_unset, untrusted=False):
>          """parse a configuration element as a quantity in bytes
>
>          Units can be specified as b (bytes), k or kb (kilobytes), m or
> @@ -580,11 +580,13 @@ class ui(object):
>          ConfigError: foo.invalid is not a byte quantity ('somevalue')
>          """
>
> -        value = self.config(section, name, None, untrusted)
> +        value = self.config(section, name, default, untrusted)
>          if value is None:
> -            if not isinstance(default, str):
> -                return default
> +            if default is _unset:
> +                default = 0
>              value = default
> +        if not isinstance(value, str):
>

I suspect this should be bytes not str for Python 3 compatibility. But I'll
leave it as a follow-up because it was an outstanding problem.


> +            return value
>          try:
>              return util.sizetoint(value)
>          except error.ParseError:
>

Patch

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -558,7 +558,7 @@  class ui(object):
         return self.configwith(int, section, name, default, 'integer',
                                untrusted)
 
-    def configbytes(self, section, name, default=0, untrusted=False):
+    def configbytes(self, section, name, default=_unset, untrusted=False):
         """parse a configuration element as a quantity in bytes
 
         Units can be specified as b (bytes), k or kb (kilobytes), m or
@@ -580,11 +580,13 @@  class ui(object):
         ConfigError: foo.invalid is not a byte quantity ('somevalue')
         """
 
-        value = self.config(section, name, None, untrusted)
+        value = self.config(section, name, default, untrusted)
         if value is None:
-            if not isinstance(default, str):
-                return default
+            if default is _unset:
+                default = 0
             value = default
+        if not isinstance(value, str):
+            return value
         try:
             return util.sizetoint(value)
         except error.ParseError: