Comments
Patch
@@ -3626,3 +3626,47 @@
if not (byte & 0x80):
return result
shift += 7
+
+
+def estimatememory(ui):
+ """Provide an estimate for the available system memory in Bytes.
+
+ If no estimate can be provided on the platform, returns None.
+ """
+ value = ui.config(b'ui', b'available-memory')
+ if value is not None:
+ try:
+ return sizetoint(value)
+ except error.ParseError:
+ raise error.ConfigError(
+ _(b"ui.available-memory value is invalid ('%s')") % value
+ )
+ try:
+ pagesize = os.sysconf(os.sysconf_names['SC_PAGE_SIZE'])
+ pages = os.sysconf(os.sysconf_names['SC_PHYS_PAGES'])
+ return pagesize * pages
+ except OSError:
+ pass
+ except KeyError:
+ pass
+ if pycompat.sysplatform.startswith(b'win'):
+ from ctypes import c_long as DWORD, c_ulonglong as DWORDLONG
+ from ctypes.wintypes import Structure, byref, sizeof, windll
+
+ class MEMORYSTATUSEX(Structure):
+ _fields_ = [
+ ('dwLength', DWORD),
+ ('dwMemoryLoad', DWORD),
+ ('ullTotalPhys', DWORDLONG),
+ ('ullAvailPhys', DWORDLONG),
+ ('ullTotalPageFile', DWORDLONG),
+ ('ullAvailPageFile', DWORDLONG),
+ ('ullTotalVirtual', DWORDLONG),
+ ('ullAvailVirtual', DWORDLONG),
+ ('ullExtendedVirtual', DWORDLONG),
+ ]
+
+ x = MEMORYSTATUSEX()
+ x.dwLength = sizeof(x)
+ windll.kernel32.GlobalMemoryStatusEx(byref(x))
+ return x.ullAvailPhys
@@ -1231,6 +1231,10 @@
b'ui', b'askusername', default=False,
)
coreconfigitem(
+ b'ui', b'available-memory', default=None,
+)
+
+coreconfigitem(
b'ui', b'clonebundlefallback', default=False,
)
coreconfigitem(