Patchwork [2,of,5,v2] ui: rewrite configint in terms of configwith

login
register
mail settings
Submitter Bryan O'Sullivan
Date Feb. 13, 2017, 6:39 a.m.
Message ID <270342e743efcba76028.1486967994@bryano-mbp.local>
Download mbox | patch
Permalink /patch/18432/
State Accepted
Headers show

Comments

Bryan O'Sullivan - Feb. 13, 2017, 6:39 a.m.
# HG changeset patch
# User Bryan O'Sullivan <bryano@fb.com>
# Date 1486964695 28800
#      Sun Feb 12 21:44:55 2017 -0800
# Node ID 270342e743efcba76028840c357bb930cd1166f4
# Parent  0be0dffb7a83d1a973a0913230223cfd456a3148
ui: rewrite configint in terms of configwith

Patch

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -453,17 +453,11 @@  class ui(object):
         >>> u.configint(s, 'invalid')
         Traceback (most recent call last):
             ...
-        ConfigError: foo.invalid is not an integer ('somevalue')
+        ConfigError: foo.invalid is not a valid integer ('somevalue')
         """
 
-        v = self.config(section, name, None, untrusted)
-        if v is None:
-            return default
-        try:
-            return int(v)
-        except ValueError:
-            raise error.ConfigError(_("%s.%s is not an integer ('%s')")
-                                    % (section, name, v))
+        return self.configwith(int, section, name, default, 'integer',
+                               untrusted)
 
     def configbytes(self, section, name, default=0, untrusted=False):
         """parse a configuration element as a quantity in bytes
diff --git a/tests/test-convert-git.t b/tests/test-convert-git.t
--- a/tests/test-convert-git.t
+++ b/tests/test-convert-git.t
@@ -330,7 +330,7 @@  since bar is not touched in this commit,
 
 input validation
   $ hg convert --config convert.git.similarity=foo --datesort git-repo2 fullrepo
-  abort: convert.git.similarity is not an integer ('foo')
+  abort: convert.git.similarity is not a valid integer ('foo')
   [255]
   $ hg convert --config convert.git.similarity=-1 --datesort git-repo2 fullrepo
   abort: similarity must be between 0 and 100