Mercurial > public > mercurial-scm > hg-stable
diff mercurial/ui.py @ 45062:02b17231f6c3
util: provide a helper function to estimate RAM size
For POSIX systems, it uses sysconf. For Windows, it uses the win32 API
directly.
Differential Revision: https://phab.mercurial-scm.org/D8644
author | Joerg Sonnenberger <joerg@bec.de> |
---|---|
date | Tue, 09 Jun 2020 11:22:31 +0200 |
parents | b4b6ff83ed9c |
children | 14ac6a74e7e7 ed84a4d48910 |
line wrap: on
line diff
--- a/mercurial/ui.py Thu Jul 02 19:59:59 2020 +0200 +++ b/mercurial/ui.py Tue Jun 09 11:22:31 2020 +0200 @@ -2119,6 +2119,22 @@ if (b'ui', b'quiet') in overrides: self.fixconfig(section=b'ui') + def estimatememory(self): + """Provide an estimate for the available system memory in Bytes. + + This can be overriden via ui.available-memory. It returns None, if + no estimate can be computed. + """ + value = self.config(b'ui', b'available-memory') + if value is not None: + try: + return util.sizetoint(value) + except error.ParseError: + raise error.ConfigError( + _(b"ui.available-memory value is invalid ('%s')") % value + ) + return util._estimatememory() + class paths(dict): """Represents a collection of paths and their configs.