comparison hgext/fix.py @ 43058:808a57a08470

fix: add :enabled sub-config for fixer tools This allows distributing opt-in fixer tool configurations in .hgrc files. This may be useful for adding default configs in core, or for orgranizations that want to provide configs to their users. Tools are still enabled by default because it would be confusing to add a config and find that it has no effect until you add enabled=true. Differential Revision: https://phab.mercurial-scm.org/D6975
author Danny Hooper <hooper@google.com>
date Sat, 05 Oct 2019 07:10:34 -0700
parents e9f503074044
children 2372284d9457
comparison
equal deleted inserted replaced
43057:c5c502bd1f70 43058:808a57a08470
171 'linerange': None, 171 'linerange': None,
172 'pattern': None, 172 'pattern': None,
173 'priority': 0, 173 'priority': 0,
174 'metadata': 'false', 174 'metadata': 'false',
175 'skipclean': 'true', 175 'skipclean': 'true',
176 'enabled': 'true',
176 } 177 }
177 178
178 for key, default in FIXER_ATTRS.items(): 179 for key, default in FIXER_ATTRS.items():
179 configitem('fix', '.*(:%s)?' % key, default=default, generic=True) 180 configitem('fix', '.*(:%s)?' % key, default=default, generic=True)
180 181
724 setattr(fixers[name], pycompat.sysstr('_' + key), 725 setattr(fixers[name], pycompat.sysstr('_' + key),
725 attrs.get(key, default)) 726 attrs.get(key, default))
726 fixers[name]._priority = int(fixers[name]._priority) 727 fixers[name]._priority = int(fixers[name]._priority)
727 fixers[name]._metadata = stringutil.parsebool(fixers[name]._metadata) 728 fixers[name]._metadata = stringutil.parsebool(fixers[name]._metadata)
728 fixers[name]._skipclean = stringutil.parsebool(fixers[name]._skipclean) 729 fixers[name]._skipclean = stringutil.parsebool(fixers[name]._skipclean)
730 fixers[name]._enabled = stringutil.parsebool(fixers[name]._enabled)
729 # Don't use a fixer if it has no pattern configured. It would be 731 # Don't use a fixer if it has no pattern configured. It would be
730 # dangerous to let it affect all files. It would be pointless to let it 732 # dangerous to let it affect all files. It would be pointless to let it
731 # affect no files. There is no reasonable subset of files to use as the 733 # affect no files. There is no reasonable subset of files to use as the
732 # default. 734 # default.
733 if fixers[name]._pattern is None: 735 if fixers[name]._pattern is None:
734 ui.warn( 736 ui.warn(
735 _('fixer tool has no pattern configuration: %s\n') % (name,)) 737 _('fixer tool has no pattern configuration: %s\n') % (name,))
738 del fixers[name]
739 elif not fixers[name]._enabled:
740 ui.debug('ignoring disabled fixer tool: %s\n' % (name,))
736 del fixers[name] 741 del fixers[name]
737 return collections.OrderedDict( 742 return collections.OrderedDict(
738 sorted(fixers.items(), key=lambda item: item[1]._priority, 743 sorted(fixers.items(), key=lambda item: item[1]._priority,
739 reverse=True)) 744 reverse=True))
740 745