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