Mercurial > hg
comparison tests/test-fix.t @ 40566:b9557567cc3f
fix: add suboption for configuring execution order of tools
This could be accomplished by using wrapper scripts, but that would diminish
the usefulness of the incremental formatting logic. Configuring execution order
along with other things in the hgrc is probably more convenient anyway.
This change highlights some awkwardness with suboptions and default values,
which should be addressed separately.
Differential Revision: https://phab.mercurial-scm.org/D5237
author | Danny Hooper <hooper@google.com> |
---|---|
date | Tue, 06 Nov 2018 15:50:41 -0800 |
parents | 0df4d93fdc27 |
children | 19e1c26213f1 |
comparison
equal
deleted
inserted
replaced
40565:71b8ad0ef3e0 | 40566:b9557567cc3f |
---|---|
163 fails. This abort will also cause 'hg fix' to exit with a non-zero status: | 163 fails. This abort will also cause 'hg fix' to exit with a non-zero status: |
164 | 164 |
165 [fix] | 165 [fix] |
166 failure = abort | 166 failure = abort |
167 | 167 |
168 When multiple tools are configured to affect a file, they execute in an order | |
169 defined by the :priority suboption. The priority suboption has a default value | |
170 of zero for each tool. Tools are executed in order of descending priority. The | |
171 execution order of tools with equal priority is unspecified. For example, you | |
172 could use the 'sort' and 'head' utilities to keep only the 10 smallest numbers | |
173 in a text file by ensuring that 'sort' runs before 'head': | |
174 | |
175 [fix] | |
176 sort:command = sort --numeric-sort | |
177 head:command = head --lines=10 | |
178 sort:pattern = numbers.txt | |
179 head:pattern = numbers.txt | |
180 sort:priority = 2 | |
181 head:priority = 1 | |
182 | |
183 To account for changes made by each tool, the line numbers used for | |
184 incremental formatting are recomputed before executing the next tool. So, each | |
185 tool may see different values for the arguments added by the :linerange | |
186 suboption. | |
187 | |
168 list of commands: | 188 list of commands: |
169 | 189 |
170 fix rewrite file content in changesets or working directory | 190 fix rewrite file content in changesets or working directory |
171 | 191 |
172 (use 'hg help -v -e fix' to show built-in aliases and global options) | 192 (use 'hg help -v -e fix' to show built-in aliases and global options) |
1125 $ cat bar.txt | 1145 $ cat bar.txt |
1126 second | 1146 second |
1127 first | 1147 first |
1128 | 1148 |
1129 $ cd .. | 1149 $ cd .. |
1150 | |
1151 The execution order of tools can be controlled. This example doesn't work if | |
1152 you sort after truncating, but the config defines the correct order while the | |
1153 definitions are out of order (which might imply the incorrect order given the | |
1154 implementation of fix). The goal is to use multiple tools to select the lowest | |
1155 5 numbers in the file. | |
1156 | |
1157 $ hg init priorityexample | |
1158 $ cd priorityexample | |
1159 | |
1160 $ cat >> .hg/hgrc <<EOF | |
1161 > [fix] | |
1162 > head:command = head --lines=5 | |
1163 > head:pattern = numbers.txt | |
1164 > head:priority = 1 | |
1165 > sort:command = sort --numeric-sort | |
1166 > sort:pattern = numbers.txt | |
1167 > sort:priority = 2 | |
1168 > EOF | |
1169 | |
1170 $ printf "8\n2\n3\n6\n7\n4\n9\n5\n1\n0\n" > numbers.txt | |
1171 $ hg add -q | |
1172 $ hg fix -w | |
1173 $ cat numbers.txt | |
1174 0 | |
1175 1 | |
1176 2 | |
1177 3 | |
1178 4 | |
1179 | |
1180 And of course we should be able to break this by reversing the execution order. | |
1181 Test negative priorities while we're at it. | |
1182 | |
1183 $ cat >> .hg/hgrc <<EOF | |
1184 > [fix] | |
1185 > head:priority = -1 | |
1186 > sort:priority = -2 | |
1187 > EOF | |
1188 $ printf "8\n2\n3\n6\n7\n4\n9\n5\n1\n0\n" > numbers.txt | |
1189 $ hg fix -w | |
1190 $ cat numbers.txt | |
1191 2 | |
1192 3 | |
1193 6 | |
1194 7 | |
1195 8 | |
1196 | |
1197 $ cd .. |