# HG changeset patch # User Pierre-Yves David # Date 1696857136 -7200 # Node ID 83c6dceeb10d44248bb9915a482a914ff35b1045 # Parent d737bc8a36c96b3de3045aa23b5a9a0641a0ac82 usage: add configuration option to adjust resources usage They currently do nothing, but this open the way to actually use them. diff -r d737bc8a36c9 -r 83c6dceeb10d mercurial/configitems.toml --- a/mercurial/configitems.toml Mon Oct 09 15:06:21 2023 +0200 +++ b/mercurial/configitems.toml Mon Oct 09 15:12:16 2023 +0200 @@ -2501,6 +2501,64 @@ """ [[items]] +section = "usage" +name = "resources" +default = "default" +documentation = """How aggressive Mercurial can be with resource usage: + +Currently recognised values are: +- default: the default value currently is equivalent to medium, +- high: allows for higher cpu, memory and disk-space usage to improve the performance of some operations. +- medium: aims at a moderate resource usage, +- low: reduces resources usage when possible, decreasing overall performance. + +For finer configuration, see also `usage.resources.cpu`, +`usage.resources.disk` and `usage.resources.memory`. +""" + +[[items]] +section = "usage" +name = "resources.cpu" +default = "default" +documentation = """How aggressive Mercurial can be in terms of cpu usage: + +Currently recognised values are: +- default: the default value, inherits the value from `usage.resources`, +- high: allows for more aggressive cpu usage, improving storage quality and + the performance of some operations at the expense of machine load +- medium: aims at a moderate cpu usage, +- low: reduces cpu usage when possible, potentially at the expense of + slower operations, increased storage and exchange payload. + +""" + +[[items]] +section = "usage" +name = "resources.disk" +default = "default" +documentation = """How aggressive Mercurial can be in terms of disk usage: + +Currently recognised values are: +- default: the default value, inherits the value from `usage.resources`, +- high: allows for more disk space usage where it can improve the performance, +- medium: aims at a moderate disk usage, +- low: reduces disk usage when possible, decreasing performance in some occasion. +""" + +[[items]] +section = "usage" +name = "resources.memory" +default = "default" +documentation = """How aggressive Mercurial can be in terms of memory usage: + +Currently recognised values are: +- default: the default value, inherits the value from `usage.resources`, +- high: allows for more aggressive memory usage to improve overall performance, +- medium: aims at a moderate memory usage, +- low: reduces memory usage when possible at the cost of overall performance. +""" + +[[items]] section = "verify" name = "skipflags" default = 0 diff -r d737bc8a36c9 -r 83c6dceeb10d mercurial/helptext/config.txt --- a/mercurial/helptext/config.txt Mon Oct 09 15:06:21 2023 +0200 +++ b/mercurial/helptext/config.txt Mon Oct 09 15:12:16 2023 +0200 @@ -3005,6 +3005,52 @@ Currently recognised values are: - default: an all purpose repository +``resources`` + How aggressive Mercurial can be with resource usage: + + Currently recognised values are: + - default: the default value currently is equivalent to medium, + - high: allows for higher cpu, memory and disk-space usage to improve + performance of some operations. + - medium: aims at a moderate resource usage, + - low: reduces resources usage when possible, decreasing overall + performance. + + For finer configuration, see also `usage.resources.cpu`, + `usage.resources.disk` and `usage.resources.memory`. + +``resources.cpu`` + How aggressive Mercurial can be in terms of cpu usage: + + Currently recognised values are: + - default: the default value, inherits the value from `usage.resources`, + - high: allows for more aggressive cpu usage, improving storage quality and + the performance of some operations at the expense of machine load + - medium: aims at a moderate cpu usage, + - low: reduces cpu usage when possible, potentially at the expense of + slower operations, increased storage and exchange payload. + +``resources.disk`` + How aggressive Mercurial can be in terms of disk usage: + + Currently recognised values are: + - default: the default value, inherits the value from `usage.resources`, + - high: allows for more disk space usage where it can improve performance, + - medium: aims at a moderate disk usage, + - low: reduces disk usage when possible, decreasing performance in some + occasion. + +``resources.memory`` + How aggressive Mercurial can be in terms of memory usage: + + Currently recognised values are: + - default: the default value, inherits the value from `usage.resources`, + - high: allows for more aggressive memory usage to improve overall + performance, + - medium: aims at a moderate memory usage, + - low: reduces memory usage when possible at the cost of overall + performance. + ``command-templates`` --------------------- diff -r d737bc8a36c9 -r 83c6dceeb10d mercurial/scmutil.py --- a/mercurial/scmutil.py Mon Oct 09 15:06:21 2023 +0200 +++ b/mercurial/scmutil.py Mon Oct 09 15:12:16 2023 +0200 @@ -2325,3 +2325,34 @@ schemes. """ return userlist == [b'*'] or username in userlist + + +RESOURCE_HIGH = 3 +RESOURCE_MEDIUM = 2 +RESOURCE_LOW = 1 +RESOURCE_DEFAULT = 0 + +RESOURCE_MAPPING = { + b'default': RESOURCE_DEFAULT, + b'low': RESOURCE_LOW, + b'medium': RESOURCE_MEDIUM, + b'high': RESOURCE_HIGH, +} + +DEFAULT_RESOURCE = RESOURCE_MEDIUM + + +def get_resource_profile(ui, dimension=None): + """return the resource profile for a dimension + + If no dimension is specified, the generic value is returned""" + generic_name = ui.config(b'usage', b'resources') + value = RESOURCE_MAPPING.get(generic_name, RESOURCE_DEFAULT) + if value == RESOURCE_DEFAULT: + value = DEFAULT_RESOURCE + if dimension is not None: + sub_name = ui.config(b'usage', b'resources.%s' % dimension) + sub_value = RESOURCE_MAPPING.get(sub_name, RESOURCE_DEFAULT) + if sub_value != RESOURCE_DEFAULT: + value = sub_value + return value