changeset 15606:2ad4e9b44d8b

convert: simplify getargmax() with propertycache
author Patrick Mezard <pmezard@gmail.com>
date Fri, 02 Dec 2011 18:36:32 +0100
parents 2ad5b8937d0d
children ec8a49c46d7e
files hgext/convert/common.py
diffstat 1 files changed, 8 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/convert/common.py	Fri Dec 02 17:38:07 2011 +0100
+++ b/hgext/convert/common.py	Fri Dec 02 18:36:32 2011 +0100
@@ -11,6 +11,8 @@
 from mercurial import util
 from mercurial.i18n import _
 
+propertycache = util.propertycache
+
 def encodeargs(args):
     def encodearg(s):
         lines = base64.encodestring(s)
@@ -321,14 +323,12 @@
         self.checkexit(status, ''.join(output))
         return output
 
-    def getargmax(self):
-        if '_argmax' in self.__dict__:
-            return self._argmax
-
+    @propertycache
+    def argmax(self):
         # POSIX requires at least 4096 bytes for ARG_MAX
-        self._argmax = 4096
+        argmax = 4096
         try:
-            self._argmax = os.sysconf("SC_ARG_MAX")
+            argmax = os.sysconf("SC_ARG_MAX")
         except:
             pass
 
@@ -339,13 +339,11 @@
 
         # Since ARG_MAX is for command line _and_ environment, lower our limit
         # (and make happy Windows shells while doing this).
-
-        self._argmax = self._argmax / 2 - 1
-        return self._argmax
+        return argmax / 2 - 1
 
     def limit_arglist(self, arglist, cmd, closestdin, *args, **kwargs):
         cmdlen = len(self._cmdline(cmd, closestdin, *args, **kwargs))
-        limit = self.getargmax() - cmdlen
+        limit = self.argmax - cmdlen
         bytes = 0
         fl = []
         for fn in arglist: