Patchwork [2,of,2] ui: use util.sizetoint in configbytes

login
register
mail settings
Submitter Bryan O'Sullivan
Date May 14, 2013, 6:23 p.m.
Message ID <d77922fd8798acbf6daa.1368555789@australite.thefacebook.com>
Download mbox | patch
Permalink /patch/1635/
State Accepted
Commit 9311cd5c09ed4d686ded5cb5180ce244b425b4a2
Headers show

Comments

Bryan O'Sullivan - May 14, 2013, 6:23 p.m.
# HG changeset patch
# User Bryan O'Sullivan <bryano@fb.com>
# Date 1368555217 25200
#      Tue May 14 11:13:37 2013 -0700
# Node ID d77922fd8798acbf6daa0435eb7a7b1c13e3918b
# Parent  c681f9e76c4dd51825986923623b42566d9d9ad0
ui: use util.sizetoint in configbytes

Patch

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -6,7 +6,7 @@ 
 # GNU General Public License version 2 or any later version.
 
 from i18n import _
-import errno, getpass, os, re, socket, sys, tempfile, traceback
+import errno, getpass, os, socket, sys, tempfile, traceback
 import config, scmutil, util, error, formatter
 
 class ui(object):
@@ -284,22 +284,16 @@  class ui(object):
         ConfigError: foo.invalid is not a byte quantity ('somevalue')
         """
 
-        orig = string = self.config(section, name)
-        if orig is None:
+        value = self.config(section, name)
+        if value is None:
             if not isinstance(default, str):
                 return default
-            orig = string = default
-        multiple = 1
-        m = re.match(r'([^kmbg]+?)\s*([kmg]?)b?$', string, re.I)
-        if m:
-            string, key = m.groups()
-            key = key.lower()
-            multiple = dict(k=1024, m=1048576, g=1073741824).get(key, 1)
+            value = default
         try:
-            return int(float(string) * multiple)
-        except ValueError:
+            return util.sizetoint(value)
+        except error.ParseError:
             raise error.ConfigError(_("%s.%s is not a byte quantity ('%s')")
-                                    % (section, name, orig))
+                                    % (section, name, value))
 
     def configlist(self, section, name, default=None, untrusted=False):
         """parse a configuration element as a list of comma/space separated