##// 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 132 from mercurial.i18n import _
133 133 from mercurial.node import nullrev
134 134 from mercurial.node import wdirrev
135 from mercurial.pycompat import setattr
136 135
137 from mercurial.utils import (
138 procutil,
139 stringutil,
140 )
136 from mercurial.utils import procutil
141 137
142 138 from mercurial import (
143 139 cmdutil,
@@ -172,9 +168,9 b' FIXER_ATTRS = {'
172 168 b'linerange': None,
173 169 b'pattern': None,
174 170 b'priority': 0,
175 b'metadata': b'false',
176 b'skipclean': b'true',
177 b'enabled': b'true',
171 b'metadata': False,
172 b'skipclean': True,
173 b'enabled': True,
178 174 }
179 175
180 176 for key, default in FIXER_ATTRS.items():
@@ -793,29 +789,27 b' def getfixers(ui):'
793 789 """
794 790 fixers = {}
795 791 for name in fixernames(ui):
796 fixers[name] = Fixer()
797 for key in FIXER_ATTRS:
798 setattr(
799 fixers[name],
800 pycompat.sysstr(b'_' + key),
801 ui.config(b'fix', name + b':' + key),
802 )
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)
792 enabled = ui.configbool(b'fix', name + b':enabled')
793 command = ui.config(b'fix', name + b':command')
794 pattern = ui.config(b'fix', name + b':pattern')
795 linerange = ui.config(b'fix', name + b':linerange')
796 priority = ui.configint(b'fix', name + b':priority')
797 metadata = ui.configbool(b'fix', name + b':metadata')
798 skipclean = ui.configbool(b'fix', name + b':skipclean')
807 799 # Don't use a fixer if it has no pattern configured. It would be
808 800 # dangerous to let it affect all files. It would be pointless to let it
809 801 # affect no files. There is no reasonable subset of files to use as the
810 802 # default.
811 if fixers[name]._pattern is None:
803 if pattern is None:
812 804 ui.warn(
813 805 _(b'fixer tool has no pattern configuration: %s\n') % (name,)
814 806 )
815 del fixers[name]
816 elif not fixers[name]._enabled:
807 elif not enabled:
817 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 813 return collections.OrderedDict(
820 814 sorted(fixers.items(), key=lambda item: item[1]._priority, reverse=True)
821 815 )
@@ -833,6 +827,16 b' def fixernames(ui):'
833 827 class Fixer(object):
834 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 840 def affects(self, opts, fixctx, path):
837 841 """Should this fixer run on the file at the given path and context?"""
838 842 return self._pattern is not None and scmutil.match(
General Comments 0
You need to be logged in to leave comments. Login now