##// END OF EJS Templates
fix: allow tools to use :linerange, but also run if a file is unchanged...
Danny Hooper -
r42983:69b37b72 default draft
parent child Browse files
Show More
@@ -36,6 +36,15 b' substituted into the command::'
36 36 {first} The 1-based line number of the first line in the modified range
37 37 {last} The 1-based line number of the last line in the modified range
38 38
39 Deleted sections of a file will be ignored by :linerange, because there is no
40 corresponding line range in the version being fixed.
41
42 By default, tools that set :linerange will only be executed if there is at least
43 one changed line range. This is meant to prevent accidents like running a code
44 formatter in such a way that it unexpectedly reformats the whole file. If such a
45 tool needs to operate on unchanged files, it should set the :skipclean suboption
46 to false.
47
39 48 The :pattern suboption determines which files will be passed through each
40 49 configured tool. See :hg:`help patterns` for possible values. If there are file
41 50 arguments to :hg:`fix`, the intersection of these patterns is used.
@@ -126,6 +135,7 b' from mercurial.node import wdirrev'
126 135
127 136 from mercurial.utils import (
128 137 procutil,
138 stringutil,
129 139 )
130 140
131 141 from mercurial import (
@@ -162,6 +172,7 b' FIXER_ATTRS = {'
162 172 'pattern': None,
163 173 'priority': 0,
164 174 'metadata': False,
175 'skipclean': 'true',
165 176 }
166 177
167 178 for key, default in FIXER_ATTRS.items():
@@ -713,6 +724,7 b' def getfixers(ui):'
713 724 setattr(fixers[name], pycompat.sysstr('_' + key),
714 725 attrs.get(key, default))
715 726 fixers[name]._priority = int(fixers[name]._priority)
727 fixers[name]._skipclean = stringutil.parsebool(fixers[name]._skipclean)
716 728 # Don't use a fixer if it has no pattern configured. It would be
717 729 # dangerous to let it affect all files. It would be pointless to let it
718 730 # affect no files. There is no reasonable subset of files to use as the
@@ -756,7 +768,7 b' class Fixer(object):'
756 768 {'rootpath': path, 'basename': os.path.basename(path)})]
757 769 if self._linerange:
758 770 ranges = rangesfn()
759 if not ranges:
771 if self._skipclean and not ranges:
760 772 # No line ranges to fix, so don't run the fixer.
761 773 return None
762 774 for first, last in ranges:
@@ -147,6 +147,15 b' Help text for fix.'
147 147 {first} The 1-based line number of the first line in the modified range
148 148 {last} The 1-based line number of the last line in the modified range
149 149
150 Deleted sections of a file will be ignored by :linerange, because there is no
151 corresponding line range in the version being fixed.
152
153 By default, tools that set :linerange will only be executed if there is at
154 least one changed line range. This is meant to prevent accidents like running
155 a code formatter in such a way that it unexpectedly reformats the whole file.
156 If such a tool needs to operate on unchanged files, it should set the
157 :skipclean suboption to false.
158
150 159 The :pattern suboption determines which files will be passed through each
151 160 configured tool. See 'hg help patterns' for possible values. If there are file
152 161 arguments to 'hg fix', the intersection of these patterns is used.
@@ -1356,3 +1365,34 b' The way we invoke matching must not proh'
1356 1365 fixed
1357 1366
1358 1367 $ cd ..
1368
1369 Tools should be able to run on unchanged files, even if they set :linerange.
1370 This includes a corner case where deleted chunks of a file are not considered
1371 changes.
1372
1373 $ hg init skipclean
1374 $ cd skipclean
1375
1376 $ printf "a\nb\nc\n" > foo
1377 $ printf "a\nb\nc\n" > bar
1378 $ printf "a\nb\nc\n" > baz
1379 $ hg commit -Aqm "base"
1380
1381 $ printf "a\nc\n" > foo
1382 $ printf "a\nx\nc\n" > baz
1383
1384 $ hg fix --working-dir foo bar baz \
1385 > --config 'fix.changedlines:command=printf "Line ranges:\n"; ' \
1386 > --config 'fix.changedlines:linerange=printf "{first} through {last}\n"; ' \
1387 > --config 'fix.changedlines:pattern=rootglob:**' \
1388 > --config 'fix.changedlines:skipclean=false'
1389
1390 $ cat foo
1391 Line ranges:
1392 $ cat bar
1393 Line ranges:
1394 $ cat baz
1395 Line ranges:
1396 2 through 2
1397
1398 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now