##// END OF EJS Templates
fix: make Fixer initialization more explicit for clarity...
Martin von Zweigbergk -
r43490:2e3aa8ed default draft
parent child Browse files
Show More
@@ -132,11 +132,9 b' import subprocess'
132 from mercurial.i18n import _
132 from mercurial.i18n import _
133 from mercurial.node import nullrev
133 from mercurial.node import nullrev
134 from mercurial.node import wdirrev
134 from mercurial.node import wdirrev
135 from mercurial.pycompat import setattr
136
135
137 from mercurial.utils import (
136 from mercurial.utils import (
138 procutil,
137 procutil,
139 stringutil,
140 )
138 )
141
139
142 from mercurial import (
140 from mercurial import (
@@ -172,9 +170,9 b' FIXER_ATTRS = {'
172 b'linerange': None,
170 b'linerange': None,
173 b'pattern': None,
171 b'pattern': None,
174 b'priority': 0,
172 b'priority': 0,
175 b'metadata': b'false',
173 b'metadata': False,
176 b'skipclean': b'true',
174 b'skipclean': True,
177 b'enabled': b'true',
175 b'enabled': True,
178 }
176 }
179
177
180 for key, default in FIXER_ATTRS.items():
178 for key, default in FIXER_ATTRS.items():
@@ -793,29 +791,27 b' def getfixers(ui):'
793 """
791 """
794 fixers = {}
792 fixers = {}
795 for name in fixernames(ui):
793 for name in fixernames(ui):
796 fixers[name] = Fixer()
794 enabled = ui.configbool(b'fix', name + b':enabled')
797 for key in FIXER_ATTRS:
795 command = ui.config(b'fix', name + b':command')
798 setattr(
796 pattern = ui.config(b'fix', name + b':pattern')
799 fixers[name],
797 linerange = ui.config(b'fix', name + b':linerange')
800 pycompat.sysstr(b'_' + key),
798 priority = ui.configint(b'fix', name + b':priority')
801 ui.config(b'fix', name + b':' + key),
799 metadata = ui.configbool(b'fix', name + b':metadata')
802 )
800 skipclean = ui.configbool(b'fix', name + b':skipclean')
803 fixers[name]._priority = int(fixers[name]._priority)
804 fixers[name]._metadata = stringutil.parsebool(fixers[name]._metadata)
805 fixers[name]._skipclean = stringutil.parsebool(fixers[name]._skipclean)
806 fixers[name]._enabled = stringutil.parsebool(fixers[name]._enabled)
807 # Don't use a fixer if it has no pattern configured. It would be
801 # Don't use a fixer if it has no pattern configured. It would be
808 # dangerous to let it affect all files. It would be pointless to let it
802 # dangerous to let it affect all files. It would be pointless to let it
809 # affect no files. There is no reasonable subset of files to use as the
803 # affect no files. There is no reasonable subset of files to use as the
810 # default.
804 # default.
811 if fixers[name]._pattern is None:
805 if pattern is None:
812 ui.warn(
806 ui.warn(
813 _(b'fixer tool has no pattern configuration: %s\n') % (name,)
807 _(b'fixer tool has no pattern configuration: %s\n') % (name,)
814 )
808 )
815 del fixers[name]
809 elif not enabled:
816 elif not fixers[name]._enabled:
817 ui.debug(b'ignoring disabled fixer tool: %s\n' % (name,))
810 ui.debug(b'ignoring disabled fixer tool: %s\n' % (name,))
818 del fixers[name]
811 else:
812 fixers[name] = Fixer(
813 command, pattern, linerange, priority, metadata, skipclean
814 )
819 return collections.OrderedDict(
815 return collections.OrderedDict(
820 sorted(fixers.items(), key=lambda item: item[1]._priority, reverse=True)
816 sorted(fixers.items(), key=lambda item: item[1]._priority, reverse=True)
821 )
817 )
@@ -833,6 +829,16 b' def fixernames(ui):'
833 class Fixer(object):
829 class Fixer(object):
834 """Wraps the raw config values for a fixer with methods"""
830 """Wraps the raw config values for a fixer with methods"""
835
831
832 def __init__(
833 self, command, pattern, linerange, priority, metadata, skipclean
834 ):
835 self._command = command
836 self._pattern = pattern
837 self._linerange = linerange
838 self._priority = priority
839 self._metadata = metadata
840 self._skipclean = skipclean
841
836 def affects(self, opts, fixctx, path):
842 def affects(self, opts, fixctx, path):
837 """Should this fixer run on the file at the given path and context?"""
843 """Should this fixer run on the file at the given path and context?"""
838 return self._pattern is not None and scmutil.match(
844 return self._pattern is not None and scmutil.match(
General Comments 0
You need to be logged in to leave comments. Login now