Mercurial > public > mercurial-scm > hg-stable
changeset 52259:1fef0d25dcde stable
usage: refactor usage.resources config parsing
This makes get_resource_profile less confusing. Before, RESOURCE_DEFAULT was a
special indirect value which meant to use DEFAULT_RESOURCE. I removed it while
preserving the same behavior.
The motivation for this is that the Rust implementation gets the default logic
wrong due to confusion about defaults. I will fix it in a follow-up commit.
author | Mitchell Kember <mkember@janestreet.com> |
---|---|
date | Tue, 14 Jan 2025 16:50:59 -0500 |
parents | 416421c8cf46 |
children | 6499af83735a |
files | mercurial/scmutil.py |
diffstat | 1 files changed, 12 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/scmutil.py Wed Jan 15 16:28:06 2025 +0100 +++ b/mercurial/scmutil.py Tue Jan 14 16:50:59 2025 -0500 @@ -2497,10 +2497,8 @@ RESOURCE_HIGH: int = 3 RESOURCE_MEDIUM: int = 2 RESOURCE_LOW: int = 1 -RESOURCE_DEFAULT: int = 0 RESOURCE_MAPPING: Dict[bytes, int] = { - b'default': RESOURCE_DEFAULT, b'low': RESOURCE_LOW, b'medium': RESOURCE_MEDIUM, b'high': RESOURCE_HIGH, @@ -2515,13 +2513,16 @@ """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 + + def config(section, name): + value_name = ui.config(section, name, default=b'default') + return RESOURCE_MAPPING.get(value_name) + 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 + value = config(b'usage', b'resources.%s' % dimension) + if value is not None: + return value + value = config(b'usage', b'resources') + if value is not None: + return value + return DEFAULT_RESOURCE