| 1 |
A script that implements uppercasing of specific lines in a file. This |
| 2 |
approximates the behavior of code formatters well enough for our tests. |
| 3 |
|
| 4 |
$ UPPERCASEPY="$TESTTMP/uppercase.py" |
| 5 |
$ cat > $UPPERCASEPY <<EOF |
| 6 |
> import re |
| 7 |
> import sys |
| 8 |
> from mercurial.utils.procutil import setbinary |
| 9 |
> setbinary(sys.stdin) |
| 10 |
> setbinary(sys.stdout) |
| 11 |
> stdin = getattr(sys.stdin, 'buffer', sys.stdin) |
| 12 |
> stdout = getattr(sys.stdout, 'buffer', sys.stdout) |
| 13 |
> lines = set() |
| 14 |
> def format(text): |
| 15 |
> return re.sub(b' +', b' ', text.upper()) |
| 16 |
> for arg in sys.argv[1:]: |
| 17 |
> if arg == 'all': |
| 18 |
> stdout.write(format(stdin.read())) |
| 19 |
> sys.exit(0) |
| 20 |
> else: |
| 21 |
> first, last = arg.split('-') |
| 22 |
> lines.update(range(int(first), int(last) + 1)) |
| 23 |
> for i, line in enumerate(stdin.readlines()): |
| 24 |
> if i + 1 in lines: |
| 25 |
> stdout.write(format(line)) |
| 26 |
> else: |
| 27 |
> stdout.write(line) |
| 28 |
> EOF |
| 29 |
$ TESTLINES="foo\nbar\nbaz\nqux\n" |
| 30 |
$ printf $TESTLINES | "$PYTHON" $UPPERCASEPY |
| 31 |
foo |
| 32 |
bar |
| 33 |
baz |
| 34 |
qux |
| 35 |
$ printf $TESTLINES | "$PYTHON" $UPPERCASEPY all |
| 36 |
FOO |
| 37 |
BAR |
| 38 |
BAZ |
| 39 |
QUX |
| 40 |
$ printf $TESTLINES | "$PYTHON" $UPPERCASEPY 1-1 |
| 41 |
FOO |
| 42 |
bar |
| 43 |
baz |
| 44 |
qux |
| 45 |
$ printf $TESTLINES | "$PYTHON" $UPPERCASEPY 1-2 |
| 46 |
FOO |
| 47 |
BAR |
| 48 |
baz |
| 49 |
qux |
| 50 |
$ printf $TESTLINES | "$PYTHON" $UPPERCASEPY 2-3 |
| 51 |
foo |
| 52 |
BAR |
| 53 |
BAZ |
| 54 |
qux |
| 55 |
$ printf $TESTLINES | "$PYTHON" $UPPERCASEPY 2-2 4-4 |
| 56 |
foo |
| 57 |
BAR |
| 58 |
baz |
| 59 |
QUX |
| 60 |
|
| 61 |
Set up the config with two simple fixers: one that fixes specific line ranges, |
| 62 |
and one that always fixes the whole file. They both "fix" files by converting |
| 63 |
letters to uppercase. They use different file extensions, so each test case can |
| 64 |
choose which behavior to use by naming files. |
| 65 |
|
| 66 |
$ cat >> $HGRCPATH <<EOF |
| 67 |
> [extensions] |
| 68 |
> fix = |
| 69 |
> [experimental] |
| 70 |
> evolution.createmarkers=True |
| 71 |
> evolution.allowunstable=True |
| 72 |
> [fix] |
| 73 |
> uppercase-whole-file:command="$PYTHON" $UPPERCASEPY all |
| 74 |
> uppercase-whole-file:pattern=set:**.whole |
| 75 |
> uppercase-changed-lines:command="$PYTHON" $UPPERCASEPY |
| 76 |
> uppercase-changed-lines:linerange={first}-{last} |
| 77 |
> uppercase-changed-lines:pattern=set:**.changed |
| 78 |
> EOF |
| 79 |
|
| 80 |
Help text for fix. |
| 81 |
|
| 82 |
$ hg help fix |
| 83 |
hg fix [OPTION]... [FILE]... |
| 84 |
|
| 85 |
rewrite file content in changesets or working directory |
| 86 |
|
| 87 |
Runs any configured tools to fix the content of files. (See 'hg help -e fix' |
| 88 |
for details about configuring tools.) Only affects files with changes, unless |
| 89 |
file arguments are provided. Only affects changed lines of files, unless the |
| 90 |
--whole flag is used. Some tools may always affect the whole file regardless |
| 91 |
of --whole. |
| 92 |
|
| 93 |
If --working-dir is used, files with uncommitted changes in the working copy |
| 94 |
will be fixed. Note that no backup are made. |
| 95 |
|
| 96 |
If revisions are specified with --source, those revisions and their |
| 97 |
descendants will be checked, and they may be replaced with new revisions that |
| 98 |
have fixed file content. By automatically including the descendants, no |
| 99 |
merging, rebasing, or evolution will be required. If an ancestor of the |
| 100 |
working copy is included, then the working copy itself will also be fixed, and |
| 101 |
the working copy will be updated to the fixed parent. |
| 102 |
|
| 103 |
When determining what lines of each file to fix at each revision, the whole |
| 104 |
set of revisions being fixed is considered, so that fixes to earlier revisions |
| 105 |
are not forgotten in later ones. The --base flag can be used to override this |
| 106 |
default behavior, though it is not usually desirable to do so. |
| 107 |
|
| 108 |
(use 'hg help -e fix' to show help for the fix extension) |
| 109 |
|
| 110 |
options ([+] can be repeated): |
| 111 |
|
| 112 |
--all fix all non-public non-obsolete revisions |
| 113 |
--base REV [+] revisions to diff against (overrides automatic selection, |
| 114 |
and applies to every revision being fixed) |
| 115 |
-s --source REV [+] fix the specified revisions and their descendants |
| 116 |
-w --working-dir fix the working directory |
| 117 |
--whole always fix every line of a file |
| 118 |
|
| 119 |
(some details hidden, use --verbose to show complete help) |
| 120 |
|
| 121 |
$ hg help -e fix |
| 122 |
fix extension - rewrite file content in changesets or working copy |
| 123 |
(EXPERIMENTAL) |
| 124 |
|
| 125 |
Provides a command that runs configured tools on the contents of modified |
| 126 |
files, writing back any fixes to the working copy or replacing changesets. |
| 127 |
|
| 128 |
Fixer tools are run in the repository's root directory. This allows them to |
| 129 |
read configuration files from the working copy, or even write to the working |
| 130 |
copy. The working copy is not updated to match the revision being fixed. In |
| 131 |
fact, several revisions may be fixed in parallel. Writes to the working copy |
| 132 |
are not amended into the revision being fixed; fixer tools MUST always read |
| 133 |
content to be fixed from stdin, and write fixed file content back to stdout. |
| 134 |
|
| 135 |
Here is an example configuration that causes 'hg fix' to apply automatic |
| 136 |
formatting fixes to modified lines in C++ code: |
| 137 |
|
| 138 |
[fix] |
| 139 |
clang-format:command=clang-format --assume-filename={rootpath} |
| 140 |
clang-format:linerange=--lines={first}:{last} |
| 141 |
clang-format:pattern=set:**.cpp or **.hpp |
| 142 |
|
| 143 |
The :command suboption forms the first part of the shell command that will be |
| 144 |
used to fix a file. The content of the file is passed on standard input, and |
| 145 |
the fixed file content is expected on standard output. Any output on standard |
| 146 |
error will be displayed as a warning. If the exit status is not zero, the file |
| 147 |
will not be affected. A placeholder warning is displayed if there is a non- |
| 148 |
zero exit status but no standard error output. Some values may be substituted |
| 149 |
into the command: |
| 150 |
|
| 151 |
{rootpath} The path of the file being fixed, relative to the repo root |
| 152 |
{basename} The name of the file being fixed, without the directory path |
| 153 |
|
| 154 |
If the :linerange suboption is set, the tool will only be run if there are |
| 155 |
changed lines in a file. The value of this suboption is appended to the shell |
| 156 |
command once for every range of changed lines in the file. Some values may be |
| 157 |
substituted into the command: |
| 158 |
|
| 159 |
{first} The 1-based line number of the first line in the modified range |
| 160 |
{last} The 1-based line number of the last line in the modified range |
| 161 |
|
| 162 |
Deleted sections of a file will be ignored by :linerange, because there is no |
| 163 |
corresponding line range in the version being fixed. |
| 164 |
|
| 165 |
By default, tools that set :linerange will only be executed if there is at |
| 166 |
least one changed line range. This is meant to prevent accidents like running |
| 167 |
a code formatter in such a way that it unexpectedly reformats the whole file. |
| 168 |
If such a tool needs to operate on unchanged files, it should set the |
| 169 |
:skipclean suboption to false. |
| 170 |
|
| 171 |
The :pattern suboption determines which files will be passed through each |
| 172 |
configured tool. See 'hg help patterns' for possible values. However, all |
| 173 |
patterns are relative to the repo root, even if that text says they are |
| 174 |
relative to the current working directory. If there are file arguments to 'hg |
| 175 |
fix', the intersection of these patterns is used. |
| 176 |
|
| 177 |
There is also a configurable limit for the maximum size of file that will be |
| 178 |
processed by 'hg fix': |
| 179 |
|
| 180 |
[fix] |
| 181 |
maxfilesize = 2MB |
| 182 |
|
| 183 |
Normally, execution of configured tools will continue after a failure |
| 184 |
(indicated by a non-zero exit status). It can also be configured to abort |
| 185 |
after the first such failure, so that no files will be affected if any tool |
| 186 |
fails. This abort will also cause 'hg fix' to exit with a non-zero status: |
| 187 |
|
| 188 |
[fix] |
| 189 |
failure = abort |
| 190 |
|
| 191 |
When multiple tools are configured to affect a file, they execute in an order |
| 192 |
defined by the :priority suboption. The priority suboption has a default value |
| 193 |
of zero for each tool. Tools are executed in order of descending priority. The |
| 194 |
execution order of tools with equal priority is unspecified. For example, you |
| 195 |
could use the 'sort' and 'head' utilities to keep only the 10 smallest numbers |
| 196 |
in a text file by ensuring that 'sort' runs before 'head': |
| 197 |
|
| 198 |
[fix] |
| 199 |
sort:command = sort -n |
| 200 |
head:command = head -n 10 |
| 201 |
sort:pattern = numbers.txt |
| 202 |
head:pattern = numbers.txt |
| 203 |
sort:priority = 2 |
| 204 |
head:priority = 1 |
| 205 |
|
| 206 |
To account for changes made by each tool, the line numbers used for |
| 207 |
incremental formatting are recomputed before executing the next tool. So, each |
| 208 |
tool may see different values for the arguments added by the :linerange |
| 209 |
suboption. |
| 210 |
|
| 211 |
Each fixer tool is allowed to return some metadata in addition to the fixed |
| 212 |
file content. The metadata must be placed before the file content on stdout, |
| 213 |
separated from the file content by a zero byte. The metadata is parsed as a |
| 214 |
JSON value (so, it should be UTF-8 encoded and contain no zero bytes). A fixer |
| 215 |
tool is expected to produce this metadata encoding if and only if the |
| 216 |
:metadata suboption is true: |
| 217 |
|
| 218 |
[fix] |
| 219 |
tool:command = tool --prepend-json-metadata |
| 220 |
tool:metadata = true |
| 221 |
|
| 222 |
The metadata values are passed to hooks, which can be used to print summaries |
| 223 |
or perform other post-fixing work. The supported hooks are: |
| 224 |
|
| 225 |
"postfixfile" |
| 226 |
Run once for each file in each revision where any fixer tools made changes |
| 227 |
to the file content. Provides "$HG_REV" and "$HG_PATH" to identify the file, |
| 228 |
and "$HG_METADATA" with a map of fixer names to metadata values from fixer |
| 229 |
tools that affected the file. Fixer tools that didn't affect the file have a |
| 230 |
value of None. Only fixer tools that executed are present in the metadata. |
| 231 |
|
| 232 |
"postfix" |
| 233 |
Run once after all files and revisions have been handled. Provides |
| 234 |
"$HG_REPLACEMENTS" with information about what revisions were created and |
| 235 |
made obsolete. Provides a boolean "$HG_WDIRWRITTEN" to indicate whether any |
| 236 |
files in the working copy were updated. Provides a list "$HG_METADATA" |
| 237 |
mapping fixer tool names to lists of metadata values returned from |
| 238 |
executions that modified a file. This aggregates the same metadata |
| 239 |
previously passed to the "postfixfile" hook. |
| 240 |
|
| 241 |
You can specify a list of directories to search the tool command in using the |
| 242 |
'fix.extra-bin-paths' configuration. |
| 243 |
|
| 244 |
list of commands: |
| 245 |
|
| 246 |
fix rewrite file content in changesets or working directory |
| 247 |
|
| 248 |
(use 'hg help -v -e fix' to show built-in aliases and global options) |
| 249 |
|
| 250 |
There is no default behavior in the absence of --rev and --working-dir. |
| 251 |
|
| 252 |
$ hg init badusage |
| 253 |
$ cd badusage |
| 254 |
|
| 255 |
$ hg fix |
| 256 |
abort: no changesets specified |
| 257 |
(use --source or --working-dir) |
| 258 |
[255] |
| 259 |
$ hg fix --whole |
| 260 |
abort: no changesets specified |
| 261 |
(use --source or --working-dir) |
| 262 |
[255] |
| 263 |
$ hg fix --base 0 |
| 264 |
abort: no changesets specified |
| 265 |
(use --source or --working-dir) |
| 266 |
[255] |
| 267 |
|
| 268 |
Fixing a public revision isn't allowed. It should abort early enough that |
| 269 |
nothing happens, even to the working directory. |
| 270 |
|
| 271 |
$ printf "hello\n" > hello.whole |
| 272 |
$ hg commit -Aqm "hello" |
| 273 |
$ hg phase -r 0 --public |
| 274 |
$ hg fix -r 0 |
| 275 |
abort: cannot fix public changesets: 6470986d2e7b |
| 276 |
(see 'hg help phases' for details) |
| 277 |
[10] |
| 278 |
$ hg fix -r 0 --working-dir |
| 279 |
abort: cannot fix public changesets: 6470986d2e7b |
| 280 |
(see 'hg help phases' for details) |
| 281 |
[10] |
| 282 |
$ hg cat -r tip hello.whole |
| 283 |
hello |
| 284 |
$ cat hello.whole |
| 285 |
hello |
| 286 |
|
| 287 |
$ cd .. |
| 288 |
|
| 289 |
Fixing a clean working directory should do nothing. Even the --whole flag |
| 290 |
shouldn't cause any clean files to be fixed. Specifying a clean file explicitly |
| 291 |
should only fix it if the fixer always fixes the whole file. The combination of |
| 292 |
an explicit filename and --whole should format the entire file regardless. |
| 293 |
|
| 294 |
$ hg init fixcleanwdir |
| 295 |
$ cd fixcleanwdir |
| 296 |
|
| 297 |
$ printf "hello\n" > hello.changed |
| 298 |
$ printf "world\n" > hello.whole |
| 299 |
$ hg commit -Aqm "foo" |
| 300 |
$ hg fix --working-dir |
| 301 |
$ hg diff |
| 302 |
$ hg fix --working-dir --whole |
| 303 |
$ hg diff |
| 304 |
$ hg fix --working-dir * |
| 305 |
$ cat * |
| 306 |
hello |
| 307 |
WORLD |
| 308 |
$ hg revert --all --no-backup |
| 309 |
reverting hello.whole |
| 310 |
$ hg fix --working-dir * --whole |
| 311 |
$ cat * |
| 312 |
HELLO |
| 313 |
WORLD |
| 314 |
|
| 315 |
The same ideas apply to fixing a revision, so we create a revision that doesn't |
| 316 |
modify either of the files in question and try fixing it. This also tests that |
| 317 |
we ignore a file that doesn't match any configured fixer. |
| 318 |
|
| 319 |
$ hg revert --all --no-backup |
| 320 |
reverting hello.changed |
| 321 |
reverting hello.whole |
| 322 |
$ printf "unimportant\n" > some.file |
| 323 |
$ hg commit -Aqm "some other file" |
| 324 |
|
| 325 |
$ hg fix -r . |
| 326 |
$ hg cat -r tip * |
| 327 |
hello |
| 328 |
world |
| 329 |
unimportant |
| 330 |
$ hg fix -r . --whole |
| 331 |
$ hg cat -r tip * |
| 332 |
hello |
| 333 |
world |
| 334 |
unimportant |
| 335 |
$ hg fix -r . * |
| 336 |
$ hg cat -r tip * |
| 337 |
hello |
| 338 |
WORLD |
| 339 |
unimportant |
| 340 |
$ hg fix -r . * --whole --config experimental.evolution.allowdivergence=true |
| 341 |
2 new content-divergent changesets |
| 342 |
$ hg cat -r tip * |
| 343 |
HELLO |
| 344 |
WORLD |
| 345 |
unimportant |
| 346 |
|
| 347 |
$ cd .. |
| 348 |
|
| 349 |
Fixing the working directory should still work if there are no revisions. |
| 350 |
|
| 351 |
$ hg init norevisions |
| 352 |
$ cd norevisions |
| 353 |
|
| 354 |
$ printf "something\n" > something.whole |
| 355 |
$ hg add |
| 356 |
adding something.whole |
| 357 |
$ hg fix --working-dir |
| 358 |
$ cat something.whole |
| 359 |
SOMETHING |
| 360 |
|
| 361 |
$ cd .. |
| 362 |
|
| 363 |
Test that the working copy is reported clean if formatting of the parent makes |
| 364 |
it clean. |
| 365 |
$ hg init wc-already-formatted |
| 366 |
$ cd wc-already-formatted |
| 367 |
|
| 368 |
$ printf "hello world\n" > hello.whole |
| 369 |
$ hg commit -Am initial |
| 370 |
adding hello.whole |
| 371 |
$ hg fix -w * |
| 372 |
$ hg st |
| 373 |
M hello.whole |
| 374 |
$ hg fix -s . * |
| 375 |
$ hg st |
| 376 |
$ hg diff |
| 377 |
|
| 378 |
$ cd .. |
| 379 |
|
| 380 |
Test the effect of fixing the working directory for each possible status, with |
| 381 |
and without providing explicit file arguments. |
| 382 |
|
| 383 |
$ hg init implicitlyfixstatus |
| 384 |
$ cd implicitlyfixstatus |
| 385 |
|
| 386 |
$ printf "modified\n" > modified.whole |
| 387 |
$ printf "removed\n" > removed.whole |
| 388 |
$ printf "deleted\n" > deleted.whole |
| 389 |
$ printf "clean\n" > clean.whole |
| 390 |
$ printf "ignored.whole" > .hgignore |
| 391 |
$ hg commit -Aqm "stuff" |
| 392 |
|
| 393 |
$ printf "modified!!!\n" > modified.whole |
| 394 |
$ printf "unknown\n" > unknown.whole |
| 395 |
$ printf "ignored\n" > ignored.whole |
| 396 |
$ printf "added\n" > added.whole |
| 397 |
$ hg add added.whole |
| 398 |
$ hg remove removed.whole |
| 399 |
$ rm deleted.whole |
| 400 |
|
| 401 |
$ hg status --all |
| 402 |
M modified.whole |
| 403 |
A added.whole |
| 404 |
R removed.whole |
| 405 |
! deleted.whole |
| 406 |
? unknown.whole |
| 407 |
I ignored.whole |
| 408 |
C .hgignore |
| 409 |
C clean.whole |
| 410 |
|
| 411 |
$ hg fix --working-dir |
| 412 |
|
| 413 |
$ hg status --all |
| 414 |
M modified.whole |
| 415 |
A added.whole |
| 416 |
R removed.whole |
| 417 |
! deleted.whole |
| 418 |
? unknown.whole |
| 419 |
I ignored.whole |
| 420 |
C .hgignore |
| 421 |
C clean.whole |
| 422 |
|
| 423 |
$ cat *.whole |
| 424 |
ADDED |
| 425 |
clean |
| 426 |
ignored |
| 427 |
MODIFIED!!! |
| 428 |
unknown |
| 429 |
|
| 430 |
$ printf "modified!!!\n" > modified.whole |
| 431 |
$ printf "added\n" > added.whole |
| 432 |
|
| 433 |
Listing the files explicitly causes untracked files to also be fixed, but |
| 434 |
ignored files are still unaffected. |
| 435 |
|
| 436 |
$ hg fix --working-dir *.whole |
| 437 |
|
| 438 |
$ hg status --all |
| 439 |
M clean.whole |
| 440 |
M modified.whole |
| 441 |
A added.whole |
| 442 |
R removed.whole |
| 443 |
! deleted.whole |
| 444 |
? unknown.whole |
| 445 |
I ignored.whole |
| 446 |
C .hgignore |
| 447 |
|
| 448 |
$ cat *.whole |
| 449 |
ADDED |
| 450 |
CLEAN |
| 451 |
ignored |
| 452 |
MODIFIED!!! |
| 453 |
UNKNOWN |
| 454 |
|
| 455 |
$ cd .. |
| 456 |
|
| 457 |
Test that incremental fixing works on files with additions, deletions, and |
| 458 |
changes in multiple line ranges. Note that deletions do not generally cause |
| 459 |
neighboring lines to be fixed, so we don't return a line range for purely |
| 460 |
deleted sections. In the future we should support a :deletion config that |
| 461 |
allows fixers to know where deletions are located. |
| 462 |
|
| 463 |
$ hg init incrementalfixedlines |
| 464 |
$ cd incrementalfixedlines |
| 465 |
|
| 466 |
$ printf "a\nb\nc\nd\ne\nf\ng\n" > foo.txt |
| 467 |
$ hg commit -Aqm "foo" |
| 468 |
$ printf "zz\na\nc\ndd\nee\nff\nf\ngg\n" > foo.txt |
| 469 |
|
| 470 |
$ hg --config "fix.fail:command=echo" \ |
| 471 |
> --config "fix.fail:linerange={first}:{last}" \ |
| 472 |
> --config "fix.fail:pattern=foo.txt" \ |
| 473 |
> fix --working-dir |
| 474 |
$ cat foo.txt |
| 475 |
1:1 4:6 8:8 |
| 476 |
|
| 477 |
$ cd .. |
| 478 |
|
| 479 |
Test that --whole fixes all lines regardless of the diffs present. |
| 480 |
|
| 481 |
$ hg init wholeignoresdiffs |
| 482 |
$ cd wholeignoresdiffs |
| 483 |
|
| 484 |
$ printf "a\nb\nc\nd\ne\nf\ng\n" > foo.changed |
| 485 |
$ hg commit -Aqm "foo" |
| 486 |
$ printf "zz\na\nc\ndd\nee\nff\nf\ngg\n" > foo.changed |
| 487 |
|
| 488 |
$ hg fix --working-dir |
| 489 |
$ cat foo.changed |
| 490 |
ZZ |
| 491 |
a |
| 492 |
c |
| 493 |
DD |
| 494 |
EE |
| 495 |
FF |
| 496 |
f |
| 497 |
GG |
| 498 |
|
| 499 |
$ hg fix --working-dir --whole |
| 500 |
$ cat foo.changed |
| 501 |
ZZ |
| 502 |
A |
| 503 |
C |
| 504 |
DD |
| 505 |
EE |
| 506 |
FF |
| 507 |
F |
| 508 |
GG |
| 509 |
|
| 510 |
$ cd .. |
| 511 |
|
| 512 |
We should do nothing with symlinks, and their targets should be unaffected. Any |
| 513 |
other behavior would be more complicated to implement and harder to document. |
| 514 |
|
| 515 |
#if symlink |
| 516 |
$ hg init dontmesswithsymlinks |
| 517 |
$ cd dontmesswithsymlinks |
| 518 |
|
| 519 |
$ printf "hello\n" > hello.whole |
| 520 |
$ ln -s hello.whole hellolink |
| 521 |
$ hg add |
| 522 |
adding hello.whole |
| 523 |
adding hellolink |
| 524 |
$ hg fix --working-dir hellolink |
| 525 |
$ hg status |
| 526 |
A hello.whole |
| 527 |
A hellolink |
| 528 |
|
| 529 |
$ cd .. |
| 530 |
#endif |
| 531 |
|
| 532 |
We should allow fixers to run on binary files, even though this doesn't sound |
| 533 |
like a common use case. There's not much benefit to disallowing it, and users |
| 534 |
can add "and not binary()" to their filesets if needed. The Mercurial |
| 535 |
philosophy is generally to not handle binary files specially anyway. |
| 536 |
|
| 537 |
$ hg init cantouchbinaryfiles |
| 538 |
$ cd cantouchbinaryfiles |
| 539 |
|
| 540 |
$ printf "hello\0\n" > hello.whole |
| 541 |
$ hg add |
| 542 |
adding hello.whole |
| 543 |
$ hg fix --working-dir 'set:binary()' |
| 544 |
$ cat hello.whole |
| 545 |
HELLO\x00 (esc) |
| 546 |
|
| 547 |
$ cd .. |
| 548 |
|
| 549 |
We have a config for the maximum size of file we will attempt to fix. This can |
| 550 |
be helpful to avoid running unsuspecting fixer tools on huge inputs, which |
| 551 |
could happen by accident without a well considered configuration. A more |
| 552 |
precise configuration could use the size() fileset function if one global limit |
| 553 |
is undesired. |
| 554 |
|
| 555 |
$ hg init maxfilesize |
| 556 |
$ cd maxfilesize |
| 557 |
|
| 558 |
$ printf "this file is huge\n" > hello.whole |
| 559 |
$ hg add |
| 560 |
adding hello.whole |
| 561 |
$ hg --config fix.maxfilesize=10 fix --working-dir |
| 562 |
ignoring file larger than 10 bytes: hello.whole |
| 563 |
$ cat hello.whole |
| 564 |
this file is huge |
| 565 |
|
| 566 |
$ cd .. |
| 567 |
|
| 568 |
If we specify a file to fix, other files should be left alone, even if they |
| 569 |
have changes. |
| 570 |
|
| 571 |
$ hg init fixonlywhatitellyouto |
| 572 |
$ cd fixonlywhatitellyouto |
| 573 |
|
| 574 |
$ printf "fix me!\n" > fixme.whole |
| 575 |
$ printf "not me.\n" > notme.whole |
| 576 |
$ hg add |
| 577 |
adding fixme.whole |
| 578 |
adding notme.whole |
| 579 |
$ hg fix --working-dir fixme.whole |
| 580 |
$ cat *.whole |
| 581 |
FIX ME! |
| 582 |
not me. |
| 583 |
|
| 584 |
$ cd .. |
| 585 |
|
| 586 |
If we try to fix a missing file, we still fix other files. |
| 587 |
|
| 588 |
$ hg init fixmissingfile |
| 589 |
$ cd fixmissingfile |
| 590 |
|
| 591 |
$ printf "fix me!\n" > foo.whole |
| 592 |
$ hg add |
| 593 |
adding foo.whole |
| 594 |
$ hg fix --working-dir foo.whole bar.whole |
| 595 |
bar.whole: $ENOENT$ |
| 596 |
$ cat *.whole |
| 597 |
FIX ME! |
| 598 |
|
| 599 |
$ cd .. |
| 600 |
|
| 601 |
Specifying a directory name should fix all its files and subdirectories. |
| 602 |
|
| 603 |
$ hg init fixdirectory |
| 604 |
$ cd fixdirectory |
| 605 |
|
| 606 |
$ mkdir -p dir1/dir2 |
| 607 |
$ printf "foo\n" > foo.whole |
| 608 |
$ printf "bar\n" > dir1/bar.whole |
| 609 |
$ printf "baz\n" > dir1/dir2/baz.whole |
| 610 |
$ hg add |
| 611 |
adding dir1/bar.whole |
| 612 |
adding dir1/dir2/baz.whole |
| 613 |
adding foo.whole |
| 614 |
$ hg fix --working-dir dir1 |
| 615 |
$ cat foo.whole dir1/bar.whole dir1/dir2/baz.whole |
| 616 |
foo |
| 617 |
BAR |
| 618 |
BAZ |
| 619 |
|
| 620 |
$ cd .. |
| 621 |
|
| 622 |
Fixing a file in the working directory that needs no fixes should not actually |
| 623 |
write back to the file, so for example the mtime shouldn't change. |
| 624 |
|
| 625 |
$ hg init donttouchunfixedfiles |
| 626 |
$ cd donttouchunfixedfiles |
| 627 |
|
| 628 |
$ printf "NO FIX NEEDED\n" > foo.whole |
| 629 |
$ hg add |
| 630 |
adding foo.whole |
| 631 |
$ cp -p foo.whole foo.whole.orig |
| 632 |
$ cp -p foo.whole.orig foo.whole |
| 633 |
$ sleep 2 # mtime has a resolution of one or two seconds. |
| 634 |
$ hg fix --working-dir |
| 635 |
$ f foo.whole.orig --newer foo.whole |
| 636 |
foo.whole.orig: newer than foo.whole |
| 637 |
|
| 638 |
$ cd .. |
| 639 |
|
| 640 |
When a fixer prints to stderr, we don't assume that it has failed. We show the |
| 641 |
error messages to the user, and we still let the fixer affect the file it was |
| 642 |
fixing if its exit code is zero. Some code formatters might emit error messages |
| 643 |
on stderr and nothing on stdout, which would cause us the clear the file, |
| 644 |
except that they also exit with a non-zero code. We show the user which fixer |
| 645 |
emitted the stderr, and which revision, but we assume that the fixer will print |
| 646 |
the filename if it is relevant (since the issue may be non-specific). There is |
| 647 |
also a config to abort (without affecting any files whatsoever) if we see any |
| 648 |
tool with a non-zero exit status. |
| 649 |
|
| 650 |
$ hg init showstderr |
| 651 |
$ cd showstderr |
| 652 |
|
| 653 |
$ printf "hello\n" > hello.txt |
| 654 |
$ hg add |
| 655 |
adding hello.txt |
| 656 |
$ cat > $TESTTMP/work.sh <<'EOF' |
| 657 |
> printf 'HELLO\n' |
| 658 |
> printf "$@: some\nerror that didn't stop the tool" >&2 |
| 659 |
> exit 0 # success despite the stderr output |
| 660 |
> EOF |
| 661 |
$ hg --config "fix.work:command=sh $TESTTMP/work.sh {rootpath}" \ |
| 662 |
> --config "fix.work:pattern=hello.txt" \ |
| 663 |
> fix --working-dir |
| 664 |
[wdir] work: hello.txt: some |
| 665 |
[wdir] work: error that didn't stop the tool |
| 666 |
$ cat hello.txt |
| 667 |
HELLO |
| 668 |
|
| 669 |
$ printf "goodbye\n" > hello.txt |
| 670 |
$ printf "foo\n" > foo.whole |
| 671 |
$ hg add |
| 672 |
adding foo.whole |
| 673 |
$ cat > $TESTTMP/fail.sh <<'EOF' |
| 674 |
> printf 'GOODBYE\n' |
| 675 |
> printf "$@: some\nerror that did stop the tool\n" >&2 |
| 676 |
> exit 42 # success despite the stdout output |
| 677 |
> EOF |
| 678 |
$ hg --config "fix.fail:command=sh $TESTTMP/fail.sh {rootpath}" \ |
| 679 |
> --config "fix.fail:pattern=hello.txt" \ |
| 680 |
> --config "fix.failure=abort" \ |
| 681 |
> fix --working-dir |
| 682 |
[wdir] fail: hello.txt: some |
| 683 |
[wdir] fail: error that did stop the tool |
| 684 |
abort: no fixes will be applied |
| 685 |
(use --config fix.failure=continue to apply any successful fixes anyway) |
| 686 |
[255] |
| 687 |
$ cat hello.txt |
| 688 |
goodbye |
| 689 |
$ cat foo.whole |
| 690 |
foo |
| 691 |
|
| 692 |
$ hg --config "fix.fail:command=sh $TESTTMP/fail.sh {rootpath}" \ |
| 693 |
> --config "fix.fail:pattern=hello.txt" \ |
| 694 |
> fix --working-dir |
| 695 |
[wdir] fail: hello.txt: some |
| 696 |
[wdir] fail: error that did stop the tool |
| 697 |
$ cat hello.txt |
| 698 |
goodbye |
| 699 |
$ cat foo.whole |
| 700 |
FOO |
| 701 |
|
| 702 |
$ hg --config "fix.fail:command=exit 42" \ |
| 703 |
> --config "fix.fail:pattern=hello.txt" \ |
| 704 |
> fix --working-dir |
| 705 |
[wdir] fail: exited with status 42 |
| 706 |
|
| 707 |
$ cd .. |
| 708 |
|
| 709 |
Fixing the working directory and its parent revision at the same time should |
| 710 |
check out the replacement revision for the parent. This prevents any new |
| 711 |
uncommitted changes from appearing. We test this for a clean working directory |
| 712 |
and a dirty one. In both cases, all lines/files changed since the grandparent |
| 713 |
will be fixed. The grandparent is the "baserev" for both the parent and the |
| 714 |
working copy. |
| 715 |
|
| 716 |
$ hg init fixdotandcleanwdir |
| 717 |
$ cd fixdotandcleanwdir |
| 718 |
|
| 719 |
$ printf "hello\n" > hello.whole |
| 720 |
$ printf "world\n" > world.whole |
| 721 |
$ hg commit -Aqm "the parent commit" |
| 722 |
|
| 723 |
$ hg parents --template '{rev} {desc}\n' |
| 724 |
0 the parent commit |
| 725 |
$ hg fix --working-dir -r . |
| 726 |
$ hg parents --template '{rev} {desc}\n' |
| 727 |
1 the parent commit |
| 728 |
$ hg cat -r . *.whole |
| 729 |
HELLO |
| 730 |
WORLD |
| 731 |
$ cat *.whole |
| 732 |
HELLO |
| 733 |
WORLD |
| 734 |
$ hg status |
| 735 |
|
| 736 |
$ cd .. |
| 737 |
|
| 738 |
Same test with a dirty working copy. |
| 739 |
|
| 740 |
$ hg init fixdotanddirtywdir |
| 741 |
$ cd fixdotanddirtywdir |
| 742 |
|
| 743 |
$ printf "hello\n" > hello.whole |
| 744 |
$ printf "world\n" > world.whole |
| 745 |
$ hg commit -Aqm "the parent commit" |
| 746 |
|
| 747 |
$ printf "hello,\n" > hello.whole |
| 748 |
$ printf "world!\n" > world.whole |
| 749 |
|
| 750 |
$ hg parents --template '{rev} {desc}\n' |
| 751 |
0 the parent commit |
| 752 |
$ hg fix --working-dir -r . |
| 753 |
$ hg parents --template '{rev} {desc}\n' |
| 754 |
1 the parent commit |
| 755 |
$ hg cat -r . *.whole |
| 756 |
HELLO |
| 757 |
WORLD |
| 758 |
$ cat *.whole |
| 759 |
HELLO, |
| 760 |
WORLD! |
| 761 |
$ hg status |
| 762 |
M hello.whole |
| 763 |
M world.whole |
| 764 |
|
| 765 |
$ cd .. |
| 766 |
|
| 767 |
When we have a chain of commits that change mutually exclusive lines of code, |
| 768 |
we should be able to do incremental fixing that causes each commit in the chain |
| 769 |
to include fixes made to the previous commits. This prevents children from |
| 770 |
backing out the fixes made in their parents. A dirty working directory is |
| 771 |
conceptually similar to another commit in the chain. |
| 772 |
|
| 773 |
$ hg init incrementallyfixchain |
| 774 |
$ cd incrementallyfixchain |
| 775 |
|
| 776 |
$ cat > file.changed <<EOF |
| 777 |
> first |
| 778 |
> second |
| 779 |
> third |
| 780 |
> fourth |
| 781 |
> fifth |
| 782 |
> EOF |
| 783 |
$ hg commit -Aqm "the common ancestor (the baserev)" |
| 784 |
$ cat > file.changed <<EOF |
| 785 |
> first (changed) |
| 786 |
> second |
| 787 |
> third |
| 788 |
> fourth |
| 789 |
> fifth |
| 790 |
> EOF |
| 791 |
$ hg commit -Aqm "the first commit to fix" |
| 792 |
$ cat > file.changed <<EOF |
| 793 |
> first (changed) |
| 794 |
> second |
| 795 |
> third (changed) |
| 796 |
> fourth |
| 797 |
> fifth |
| 798 |
> EOF |
| 799 |
$ hg commit -Aqm "the second commit to fix" |
| 800 |
$ cat > file.changed <<EOF |
| 801 |
> first (changed) |
| 802 |
> second |
| 803 |
> third (changed) |
| 804 |
> fourth |
| 805 |
> fifth (changed) |
| 806 |
> EOF |
| 807 |
|
| 808 |
$ hg fix -r . -r '.^' --working-dir |
| 809 |
|
| 810 |
$ hg parents --template '{rev}\n' |
| 811 |
4 |
| 812 |
$ hg cat -r '.^^' file.changed |
| 813 |
first |
| 814 |
second |
| 815 |
third |
| 816 |
fourth |
| 817 |
fifth |
| 818 |
$ hg cat -r '.^' file.changed |
| 819 |
FIRST (CHANGED) |
| 820 |
second |
| 821 |
third |
| 822 |
fourth |
| 823 |
fifth |
| 824 |
$ hg cat -r . file.changed |
| 825 |
FIRST (CHANGED) |
| 826 |
second |
| 827 |
THIRD (CHANGED) |
| 828 |
fourth |
| 829 |
fifth |
| 830 |
$ cat file.changed |
| 831 |
FIRST (CHANGED) |
| 832 |
second |
| 833 |
THIRD (CHANGED) |
| 834 |
fourth |
| 835 |
FIFTH (CHANGED) |
| 836 |
|
| 837 |
$ cd .. |
| 838 |
|
| 839 |
If we incrementally fix a merge commit, we should fix any lines that changed |
| 840 |
versus either parent. You could imagine only fixing the intersection or some |
| 841 |
other subset, but this is necessary if either parent is being fixed. It |
| 842 |
prevents us from forgetting fixes made in either parent. |
| 843 |
|
| 844 |
$ hg init incrementallyfixmergecommit |
| 845 |
$ cd incrementallyfixmergecommit |
| 846 |
|
| 847 |
$ printf "a\nb\nc\n" > file.changed |
| 848 |
$ hg commit -Aqm "ancestor" |
| 849 |
|
| 850 |
$ printf "aa\nb\nc\n" > file.changed |
| 851 |
$ hg commit -m "change a" |
| 852 |
|
| 853 |
$ hg checkout '.^' |
| 854 |
1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
| 855 |
$ printf "a\nb\ncc\n" > file.changed |
| 856 |
$ hg commit -m "change c" |
| 857 |
created new head |
| 858 |
|
| 859 |
$ hg merge |
| 860 |
merging file.changed |
| 861 |
0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
| 862 |
(branch merge, don't forget to commit) |
| 863 |
$ hg commit -m "merge" |
| 864 |
$ hg cat -r . file.changed |
| 865 |
aa |
| 866 |
b |
| 867 |
cc |
| 868 |
|
| 869 |
$ hg fix -r . --working-dir |
| 870 |
$ hg cat -r . file.changed |
| 871 |
AA |
| 872 |
b |
| 873 |
CC |
| 874 |
|
| 875 |
$ cd .. |
| 876 |
|
| 877 |
We should be allowed to fix the working (and only the working copy) while |
| 878 |
merging. |
| 879 |
|
| 880 |
$ hg init fixworkingcopywhilemerging |
| 881 |
$ cd fixworkingcopywhilemerging |
| 882 |
|
| 883 |
$ printf "a\nb\nc\n" > file.changed |
| 884 |
$ hg commit -Aqm "ancestor" |
| 885 |
|
| 886 |
$ printf "aa\nb\nc\n" > file.changed |
| 887 |
$ hg commit -m "change a" |
| 888 |
|
| 889 |
$ hg checkout '.^' |
| 890 |
1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
| 891 |
$ printf "a\nb\ncc\n" > file.changed |
| 892 |
$ hg commit -m "change c" |
| 893 |
created new head |
| 894 |
|
| 895 |
$ hg merge |
| 896 |
merging file.changed |
| 897 |
0 files updated, 1 files merged, 0 files removed, 0 files unresolved |
| 898 |
(branch merge, don't forget to commit) |
| 899 |
$ cat file.changed |
| 900 |
aa |
| 901 |
b |
| 902 |
cc |
| 903 |
Not allowed to fix a parent of the working copy while merging |
| 904 |
$ hg fix -r . --working-dir |
| 905 |
abort: outstanding uncommitted merge |
| 906 |
(use 'hg commit' or 'hg merge --abort') |
| 907 |
[20] |
| 908 |
$ hg fix --working-dir |
| 909 |
$ cat file.changed |
| 910 |
AA |
| 911 |
b |
| 912 |
CC |
| 913 |
|
| 914 |
$ cd .. |
| 915 |
|
| 916 |
Abort fixing revisions if there is an unfinished operation. We don't want to |
| 917 |
make things worse by editing files or stripping/obsoleting things. Also abort |
| 918 |
fixing the working directory if there are unresolved merge conflicts. |
| 919 |
|
| 920 |
$ hg init abortunresolved |
| 921 |
$ cd abortunresolved |
| 922 |
|
| 923 |
$ echo "foo1" > foo.whole |
| 924 |
$ hg commit -Aqm "foo 1" |
| 925 |
|
| 926 |
$ hg update null |
| 927 |
0 files updated, 0 files merged, 1 files removed, 0 files unresolved |
| 928 |
$ echo "foo2" > foo.whole |
| 929 |
$ hg commit -Aqm "foo 2" |
| 930 |
|
| 931 |
$ hg --config extensions.rebase= rebase -r 1 -d 0 |
| 932 |
rebasing 1:c3b6dc0e177a tip "foo 2" |
| 933 |
merging foo.whole |
| 934 |
warning: conflicts while merging foo.whole! (edit, then use 'hg resolve --mark') |
| 935 |
unresolved conflicts (see 'hg resolve', then 'hg rebase --continue') |
| 936 |
[240] |
| 937 |
|
| 938 |
$ hg --config extensions.rebase= fix --working-dir |
| 939 |
abort: unresolved conflicts |
| 940 |
(use 'hg resolve') |
| 941 |
[255] |
| 942 |
|
| 943 |
$ hg --config extensions.rebase= fix -r . |
| 944 |
abort: rebase in progress |
| 945 |
(use 'hg rebase --continue', 'hg rebase --abort', or 'hg rebase --stop') |
| 946 |
[20] |
| 947 |
|
| 948 |
$ cd .. |
| 949 |
|
| 950 |
When fixing a file that was renamed, we should diff against the source of the |
| 951 |
rename for incremental fixing and we should correctly reproduce the rename in |
| 952 |
the replacement revision. |
| 953 |
|
| 954 |
$ hg init fixrenamecommit |
| 955 |
$ cd fixrenamecommit |
| 956 |
|
| 957 |
$ printf "a\nb\nc\n" > source.changed |
| 958 |
$ hg commit -Aqm "source revision" |
| 959 |
$ hg move source.changed dest.changed |
| 960 |
$ printf "a\nb\ncc\n" > dest.changed |
| 961 |
$ hg commit -m "dest revision" |
| 962 |
|
| 963 |
$ hg fix -r . |
| 964 |
$ hg log -r tip --copies --template "{file_copies}\n" |
| 965 |
dest.changed (source.changed) |
| 966 |
$ hg cat -r tip dest.changed |
| 967 |
a |
| 968 |
b |
| 969 |
CC |
| 970 |
|
| 971 |
$ cd .. |
| 972 |
|
| 973 |
When fixing revisions that remove files we must ensure that the replacement |
| 974 |
actually removes the file, whereas it could accidentally leave it unchanged or |
| 975 |
write an empty string to it. |
| 976 |
|
| 977 |
$ hg init fixremovedfile |
| 978 |
$ cd fixremovedfile |
| 979 |
|
| 980 |
$ printf "foo\n" > foo.whole |
| 981 |
$ printf "bar\n" > bar.whole |
| 982 |
$ hg commit -Aqm "add files" |
| 983 |
$ hg remove bar.whole |
| 984 |
$ hg commit -m "remove file" |
| 985 |
$ hg status --change . |
| 986 |
R bar.whole |
| 987 |
$ hg fix -r . foo.whole |
| 988 |
$ hg status --change tip |
| 989 |
M foo.whole |
| 990 |
R bar.whole |
| 991 |
|
| 992 |
$ cd .. |
| 993 |
|
| 994 |
If fixing a revision finds no fixes to make, no replacement revision should be |
| 995 |
created. |
| 996 |
|
| 997 |
$ hg init nofixesneeded |
| 998 |
$ cd nofixesneeded |
| 999 |
|
| 1000 |
$ printf "FOO\n" > foo.whole |
| 1001 |
$ hg commit -Aqm "add file" |
| 1002 |
$ hg log --template '{rev}\n' |
| 1003 |
0 |
| 1004 |
$ hg fix -r . |
| 1005 |
$ hg log --template '{rev}\n' |
| 1006 |
0 |
| 1007 |
|
| 1008 |
$ cd .. |
| 1009 |
|
| 1010 |
If fixing a commit reverts all the changes in the commit, we replace it with a |
| 1011 |
commit that changes no files. |
| 1012 |
|
| 1013 |
$ hg init nochangesleft |
| 1014 |
$ cd nochangesleft |
| 1015 |
|
| 1016 |
$ printf "FOO\n" > foo.whole |
| 1017 |
$ hg commit -Aqm "add file" |
| 1018 |
$ printf "foo\n" > foo.whole |
| 1019 |
$ hg commit -m "edit file" |
| 1020 |
$ hg status --change . |
| 1021 |
M foo.whole |
| 1022 |
$ hg fix -r . |
| 1023 |
$ hg status --change tip |
| 1024 |
|
| 1025 |
$ cd .. |
| 1026 |
|
| 1027 |
If we fix a parent and child revision together, the child revision must be |
| 1028 |
replaced if the parent is replaced, even if the diffs of the child needed no |
| 1029 |
fixes. However, we're free to not replace revisions that need no fixes and have |
| 1030 |
no ancestors that are replaced. |
| 1031 |
|
| 1032 |
$ hg init mustreplacechild |
| 1033 |
$ cd mustreplacechild |
| 1034 |
|
| 1035 |
$ printf "FOO\n" > foo.whole |
| 1036 |
$ hg commit -Aqm "add foo" |
| 1037 |
$ printf "foo\n" > foo.whole |
| 1038 |
$ hg commit -m "edit foo" |
| 1039 |
$ printf "BAR\n" > bar.whole |
| 1040 |
$ hg commit -Aqm "add bar" |
| 1041 |
|
| 1042 |
$ hg log --graph --template '{rev} {files}' |
| 1043 |
@ 2 bar.whole |
| 1044 |
| |
| 1045 |
o 1 foo.whole |
| 1046 |
| |
| 1047 |
o 0 foo.whole |
| 1048 |
|
| 1049 |
$ hg fix -r 0:2 |
| 1050 |
$ hg log --graph --template '{rev} {files}' |
| 1051 |
o 4 bar.whole |
| 1052 |
| |
| 1053 |
o 3 |
| 1054 |
| |
| 1055 |
| @ 2 bar.whole |
| 1056 |
| | |
| 1057 |
| x 1 foo.whole |
| 1058 |
|/ |
| 1059 |
o 0 foo.whole |
| 1060 |
|
| 1061 |
|
| 1062 |
$ cd .. |
| 1063 |
|
| 1064 |
It's also possible that the child needs absolutely no changes, but we still |
| 1065 |
need to replace it to update its parent. If we skipped replacing the child |
| 1066 |
because it had no file content changes, it would become an orphan for no good |
| 1067 |
reason. |
| 1068 |
|
| 1069 |
$ hg init mustreplacechildevenifnop |
| 1070 |
$ cd mustreplacechildevenifnop |
| 1071 |
|
| 1072 |
$ printf "Foo\n" > foo.whole |
| 1073 |
$ hg commit -Aqm "add a bad foo" |
| 1074 |
$ printf "FOO\n" > foo.whole |
| 1075 |
$ hg commit -m "add a good foo" |
| 1076 |
$ hg fix -r . -r '.^' |
| 1077 |
$ hg log --graph --template '{rev} {desc}' |
| 1078 |
o 3 add a good foo |
| 1079 |
| |
| 1080 |
o 2 add a bad foo |
| 1081 |
|
| 1082 |
@ 1 add a good foo |
| 1083 |
| |
| 1084 |
x 0 add a bad foo |
| 1085 |
|
| 1086 |
|
| 1087 |
$ cd .. |
| 1088 |
|
| 1089 |
Similar to the case above, the child revision may become empty as a result of |
| 1090 |
fixing its parent. We should still create an empty replacement child. |
| 1091 |
TODO: determine how this should interact with ui.allowemptycommit given that |
| 1092 |
the empty replacement could have children. |
| 1093 |
|
| 1094 |
$ hg init mustreplacechildevenifempty |
| 1095 |
$ cd mustreplacechildevenifempty |
| 1096 |
|
| 1097 |
$ printf "foo\n" > foo.whole |
| 1098 |
$ hg commit -Aqm "add foo" |
| 1099 |
$ printf "Foo\n" > foo.whole |
| 1100 |
$ hg commit -m "edit foo" |
| 1101 |
$ hg fix -r . -r '.^' |
| 1102 |
$ hg log --graph --template '{rev} {desc}\n' --stat |
| 1103 |
o 3 edit foo |
| 1104 |
| |
| 1105 |
o 2 add foo |
| 1106 |
foo.whole | 1 + |
| 1107 |
1 files changed, 1 insertions(+), 0 deletions(-) |
| 1108 |
|
| 1109 |
@ 1 edit foo |
| 1110 |
| foo.whole | 2 +- |
| 1111 |
| 1 files changed, 1 insertions(+), 1 deletions(-) |
| 1112 |
| |
| 1113 |
x 0 add foo |
| 1114 |
foo.whole | 1 + |
| 1115 |
1 files changed, 1 insertions(+), 0 deletions(-) |
| 1116 |
|
| 1117 |
|
| 1118 |
$ cd .. |
| 1119 |
|
| 1120 |
Fixing a secret commit should replace it with another secret commit. |
| 1121 |
|
| 1122 |
$ hg init fixsecretcommit |
| 1123 |
$ cd fixsecretcommit |
| 1124 |
|
| 1125 |
$ printf "foo\n" > foo.whole |
| 1126 |
$ hg commit -Aqm "add foo" --secret |
| 1127 |
$ hg fix -r . |
| 1128 |
$ hg log --template '{rev} {phase}\n' |
| 1129 |
1 secret |
| 1130 |
0 secret |
| 1131 |
|
| 1132 |
$ cd .. |
| 1133 |
|
| 1134 |
We should also preserve phase when fixing a draft commit while the user has |
| 1135 |
their default set to secret. |
| 1136 |
|
| 1137 |
$ hg init respectphasesnewcommit |
| 1138 |
$ cd respectphasesnewcommit |
| 1139 |
|
| 1140 |
$ printf "foo\n" > foo.whole |
| 1141 |
$ hg commit -Aqm "add foo" |
| 1142 |
$ hg --config phases.newcommit=secret fix -r . |
| 1143 |
$ hg log --template '{rev} {phase}\n' |
| 1144 |
1 draft |
| 1145 |
0 draft |
| 1146 |
|
| 1147 |
$ cd .. |
| 1148 |
|
| 1149 |
Debug output should show what fixer commands are being subprocessed, which is |
| 1150 |
useful for anyone trying to set up a new config. |
| 1151 |
|
| 1152 |
$ hg init debugoutput |
| 1153 |
$ cd debugoutput |
| 1154 |
|
| 1155 |
$ printf "foo\nbar\nbaz\n" > foo.changed |
| 1156 |
$ hg commit -Aqm "foo" |
| 1157 |
$ printf "Foo\nbar\nBaz\n" > foo.changed |
| 1158 |
$ hg --debug fix --working-dir |
| 1159 |
fixing: f65cf3136d41+ - uppercase-changed-lines - foo.changed |
| 1160 |
subprocess: * $TESTTMP/uppercase.py 1-1 3-3 (glob) |
| 1161 |
|
| 1162 |
$ cd .. |
| 1163 |
|
| 1164 |
Fixing an obsolete revision can cause divergence, so we abort unless the user |
| 1165 |
configures to allow it. This is not yet smart enough to know whether there is a |
| 1166 |
successor, but even then it is not likely intentional or idiomatic to fix an |
| 1167 |
obsolete revision. |
| 1168 |
|
| 1169 |
$ hg init abortobsoleterev |
| 1170 |
$ cd abortobsoleterev |
| 1171 |
|
| 1172 |
$ printf "foo\n" > foo.changed |
| 1173 |
$ hg commit -Aqm "foo" |
| 1174 |
$ hg ci --amend -m rewritten |
| 1175 |
$ hg --hidden fix -r 0 |
| 1176 |
abort: cannot fix b87e30dbf19b, as that creates content-divergence with 2e007a78dfb8 |
| 1177 |
(add --verbose for details or see 'hg help evolution.instability') |
| 1178 |
[10] |
| 1179 |
|
| 1180 |
$ hg --hidden fix -r 0 --config experimental.evolution.allowdivergence=true |
| 1181 |
2 new content-divergent changesets |
| 1182 |
$ hg cat -r tip foo.changed |
| 1183 |
FOO |
| 1184 |
|
| 1185 |
$ cd .. |
| 1186 |
|
| 1187 |
Test all of the available substitution values for fixer commands. |
| 1188 |
|
| 1189 |
$ hg init substitution |
| 1190 |
$ cd substitution |
| 1191 |
|
| 1192 |
$ mkdir foo |
| 1193 |
$ printf "hello\ngoodbye\n" > foo/bar |
| 1194 |
$ hg add |
| 1195 |
adding foo/bar |
| 1196 |
$ hg --config "fix.fail:command=printf '%s\n' '{rootpath}' '{basename}'" \ |
| 1197 |
> --config "fix.fail:linerange='{first}' '{last}'" \ |
| 1198 |
> --config "fix.fail:pattern=foo/bar" \ |
| 1199 |
> fix --working-dir |
| 1200 |
$ cat foo/bar |
| 1201 |
foo/bar |
| 1202 |
bar |
| 1203 |
1 |
| 1204 |
2 |
| 1205 |
|
| 1206 |
$ cd .. |
| 1207 |
|
| 1208 |
The --base flag should allow picking the revisions to diff against for changed |
| 1209 |
files and incremental line formatting. |
| 1210 |
|
| 1211 |
$ hg init baseflag |
| 1212 |
$ cd baseflag |
| 1213 |
|
| 1214 |
$ printf "one\ntwo\n" > foo.changed |
| 1215 |
$ printf "bar\n" > bar.changed |
| 1216 |
$ hg commit -Aqm "first" |
| 1217 |
$ printf "one\nTwo\n" > foo.changed |
| 1218 |
$ hg commit -m "second" |
| 1219 |
$ hg fix -w --base . |
| 1220 |
$ hg status |
| 1221 |
$ hg fix -w --base null |
| 1222 |
$ cat foo.changed |
| 1223 |
ONE |
| 1224 |
TWO |
| 1225 |
$ cat bar.changed |
| 1226 |
BAR |
| 1227 |
|
| 1228 |
$ cd .. |
| 1229 |
|
| 1230 |
If the user asks to fix the parent of another commit, they are asking to create |
| 1231 |
an orphan. We must respect experimental.evolution.allowunstable. |
| 1232 |
|
| 1233 |
$ hg init allowunstable |
| 1234 |
$ cd allowunstable |
| 1235 |
|
| 1236 |
$ printf "one\n" > foo.whole |
| 1237 |
$ hg commit -Aqm "first" |
| 1238 |
$ printf "two\n" > foo.whole |
| 1239 |
$ hg commit -m "second" |
| 1240 |
$ hg --config experimental.evolution.allowunstable=False fix -r '.^' |
| 1241 |
abort: cannot fix changeset, as that will orphan 1 descendants |
| 1242 |
(see 'hg help evolution.instability') |
| 1243 |
[10] |
| 1244 |
$ hg fix -r '.^' |
| 1245 |
1 new orphan changesets |
| 1246 |
$ hg cat -r 2 foo.whole |
| 1247 |
ONE |
| 1248 |
|
| 1249 |
$ cd .. |
| 1250 |
|
| 1251 |
The --base flag affects the set of files being fixed. So while the --whole flag |
| 1252 |
makes the base irrelevant for changed line ranges, it still changes the |
| 1253 |
meaning and effect of the command. In this example, no files or lines are fixed |
| 1254 |
until we specify the base, but then we do fix unchanged lines. |
| 1255 |
|
| 1256 |
$ hg init basewhole |
| 1257 |
$ cd basewhole |
| 1258 |
$ printf "foo1\n" > foo.changed |
| 1259 |
$ hg commit -Aqm "first" |
| 1260 |
$ printf "foo2\n" >> foo.changed |
| 1261 |
$ printf "bar\n" > bar.changed |
| 1262 |
$ hg commit -Aqm "second" |
| 1263 |
|
| 1264 |
$ hg fix --working-dir --whole |
| 1265 |
$ cat *.changed |
| 1266 |
bar |
| 1267 |
foo1 |
| 1268 |
foo2 |
| 1269 |
|
| 1270 |
$ hg fix --working-dir --base 0 --whole |
| 1271 |
$ cat *.changed |
| 1272 |
BAR |
| 1273 |
FOO1 |
| 1274 |
FOO2 |
| 1275 |
|
| 1276 |
$ cd .. |
| 1277 |
|
| 1278 |
The execution order of tools can be controlled. This example doesn't work if |
| 1279 |
you sort after truncating, but the config defines the correct order while the |
| 1280 |
definitions are out of order (which might imply the incorrect order given the |
| 1281 |
implementation of fix). The goal is to use multiple tools to select the lowest |
| 1282 |
5 numbers in the file. |
| 1283 |
|
| 1284 |
$ hg init priorityexample |
| 1285 |
$ cd priorityexample |
| 1286 |
|
| 1287 |
$ cat >> .hg/hgrc <<EOF |
| 1288 |
> [fix] |
| 1289 |
> head:command = head -n 5 |
| 1290 |
> head:pattern = numbers.txt |
| 1291 |
> head:priority = 1 |
| 1292 |
> sort:command = sort -n |
| 1293 |
> sort:pattern = numbers.txt |
| 1294 |
> sort:priority = 2 |
| 1295 |
> EOF |
| 1296 |
|
| 1297 |
$ printf "8\n2\n3\n6\n7\n4\n9\n5\n1\n0\n" > numbers.txt |
| 1298 |
$ hg add -q |
| 1299 |
$ hg fix -w |
| 1300 |
$ cat numbers.txt |
| 1301 |
0 |
| 1302 |
1 |
| 1303 |
2 |
| 1304 |
3 |
| 1305 |
4 |
| 1306 |
|
| 1307 |
And of course we should be able to break this by reversing the execution order. |
| 1308 |
Test negative priorities while we're at it. |
| 1309 |
|
| 1310 |
$ cat >> .hg/hgrc <<EOF |
| 1311 |
> [fix] |
| 1312 |
> head:priority = -1 |
| 1313 |
> sort:priority = -2 |
| 1314 |
> EOF |
| 1315 |
$ printf "8\n2\n3\n6\n7\n4\n9\n5\n1\n0\n" > numbers.txt |
| 1316 |
$ hg fix -w |
| 1317 |
$ cat numbers.txt |
| 1318 |
2 |
| 1319 |
3 |
| 1320 |
6 |
| 1321 |
7 |
| 1322 |
8 |
| 1323 |
|
| 1324 |
$ cd .. |
| 1325 |
|
| 1326 |
It's possible for repeated applications of a fixer tool to create cycles in the |
| 1327 |
generated content of a file. For example, two users with different versions of |
| 1328 |
a code formatter might fight over the formatting when they run hg fix. In the |
| 1329 |
absence of other changes, this means we could produce commits with the same |
| 1330 |
hash in subsequent runs of hg fix. This is a problem unless we support |
| 1331 |
obsolescence cycles well. We avoid this by adding an extra field to the |
| 1332 |
successor which forces it to have a new hash. That's why this test creates |
| 1333 |
three revisions instead of two. |
| 1334 |
|
| 1335 |
$ hg init cyclictool |
| 1336 |
$ cd cyclictool |
| 1337 |
|
| 1338 |
$ cat >> .hg/hgrc <<EOF |
| 1339 |
> [fix] |
| 1340 |
> swapletters:command = tr ab ba |
| 1341 |
> swapletters:pattern = foo |
| 1342 |
> EOF |
| 1343 |
|
| 1344 |
$ echo ab > foo |
| 1345 |
$ hg commit -Aqm foo |
| 1346 |
|
| 1347 |
$ hg fix -r 0 |
| 1348 |
$ hg fix -r 1 |
| 1349 |
|
| 1350 |
$ hg cat -r 0 foo --hidden |
| 1351 |
ab |
| 1352 |
$ hg cat -r 1 foo --hidden |
| 1353 |
ba |
| 1354 |
$ hg cat -r 2 foo |
| 1355 |
ab |
| 1356 |
|
| 1357 |
$ cd .. |
| 1358 |
|
| 1359 |
We run fixer tools in the repo root so they can look for config files or other |
| 1360 |
important things in the working directory. This does NOT mean we are |
| 1361 |
reconstructing a working copy of every revision being fixed; we're just giving |
| 1362 |
the tool knowledge of the repo's location in case it can do something |
| 1363 |
reasonable with that. |
| 1364 |
|
| 1365 |
$ hg init subprocesscwd |
| 1366 |
$ cd subprocesscwd |
| 1367 |
|
| 1368 |
$ cat >> .hg/hgrc <<EOF |
| 1369 |
> [fix] |
| 1370 |
> printcwd:command = "$PYTHON" -c "import os; print(os.getcwd())" |
| 1371 |
> printcwd:pattern = relpath:foo/bar |
| 1372 |
> filesetpwd:command = "$PYTHON" -c "import os; print('fs: ' + os.getcwd())" |
| 1373 |
> filesetpwd:pattern = set:**quux |
| 1374 |
> EOF |
| 1375 |
|
| 1376 |
$ mkdir foo |
| 1377 |
$ printf "bar\n" > foo/bar |
| 1378 |
$ printf "quux\n" > quux |
| 1379 |
$ hg commit -Aqm blah |
| 1380 |
|
| 1381 |
$ hg fix -w -r . foo/bar |
| 1382 |
$ hg cat -r tip foo/bar |
| 1383 |
$TESTTMP/subprocesscwd |
| 1384 |
$ cat foo/bar |
| 1385 |
$TESTTMP/subprocesscwd |
| 1386 |
|
| 1387 |
$ cd foo |
| 1388 |
|
| 1389 |
$ hg fix -w -r . bar |
| 1390 |
$ hg cat -r tip bar ../quux |
| 1391 |
$TESTTMP/subprocesscwd |
| 1392 |
quux |
| 1393 |
$ cat bar ../quux |
| 1394 |
$TESTTMP/subprocesscwd |
| 1395 |
quux |
| 1396 |
$ echo modified > bar |
| 1397 |
$ hg fix -w bar |
| 1398 |
$ cat bar |
| 1399 |
$TESTTMP/subprocesscwd |
| 1400 |
|
| 1401 |
Apparently fixing p1() and its descendants doesn't include wdir() unless |
| 1402 |
explicitly stated. |
| 1403 |
|
| 1404 |
$ hg fix -r '.::' |
| 1405 |
$ hg cat -r . ../quux |
| 1406 |
quux |
| 1407 |
$ hg cat -r tip ../quux |
| 1408 |
fs: $TESTTMP/subprocesscwd |
| 1409 |
$ cat ../quux |
| 1410 |
quux |
| 1411 |
|
| 1412 |
Clean files are not fixed unless explicitly named |
| 1413 |
$ echo 'dirty' > ../quux |
| 1414 |
|
| 1415 |
$ hg fix --working-dir |
| 1416 |
$ cat ../quux |
| 1417 |
fs: $TESTTMP/subprocesscwd |
| 1418 |
|
| 1419 |
$ cd ../.. |
| 1420 |
|
| 1421 |
Tools configured without a pattern are ignored. It would be too dangerous to |
| 1422 |
run them on all files, because this might happen while testing a configuration |
| 1423 |
that also deletes all of the file content. There is no reasonable subset of the |
| 1424 |
files to use as a default. Users should be explicit about what files are |
| 1425 |
affected by a tool. This test also confirms that we don't crash when the |
| 1426 |
pattern config is missing, and that we only warn about it once. |
| 1427 |
|
| 1428 |
$ hg init nopatternconfigured |
| 1429 |
$ cd nopatternconfigured |
| 1430 |
|
| 1431 |
$ printf "foo" > foo |
| 1432 |
$ printf "bar" > bar |
| 1433 |
$ hg add -q |
| 1434 |
$ hg fix --debug --working-dir --config "fix.nopattern:command=echo fixed" |
| 1435 |
fixer tool has no pattern configuration: nopattern |
| 1436 |
$ cat foo bar |
| 1437 |
foobar (no-eol) |
| 1438 |
$ hg fix --debug --working-dir --config "fix.nocommand:pattern=foo.bar" |
| 1439 |
fixer tool has no command configuration: nocommand |
| 1440 |
|
| 1441 |
$ cd .. |
| 1442 |
|
| 1443 |
Tools can be disabled. Disabled tools do nothing but print a debug message. |
| 1444 |
|
| 1445 |
$ hg init disabled |
| 1446 |
$ cd disabled |
| 1447 |
|
| 1448 |
$ printf "foo\n" > foo |
| 1449 |
$ hg add -q |
| 1450 |
$ hg fix --debug --working-dir --config "fix.disabled:command=echo fixed" \ |
| 1451 |
> --config "fix.disabled:pattern=foo" \ |
| 1452 |
> --config "fix.disabled:enabled=false" |
| 1453 |
ignoring disabled fixer tool: disabled |
| 1454 |
$ cat foo |
| 1455 |
foo |
| 1456 |
|
| 1457 |
$ cd .. |
| 1458 |
|
| 1459 |
Test that we can configure a fixer to affect all files regardless of the cwd. |
| 1460 |
The way we invoke matching must not prohibit this. |
| 1461 |
|
| 1462 |
$ hg init affectallfiles |
| 1463 |
$ cd affectallfiles |
| 1464 |
|
| 1465 |
$ mkdir foo bar |
| 1466 |
$ printf "foo" > foo/file |
| 1467 |
$ printf "bar" > bar/file |
| 1468 |
$ printf "baz" > baz_file |
| 1469 |
$ hg add -q |
| 1470 |
|
| 1471 |
$ cd bar |
| 1472 |
$ hg fix --working-dir --config "fix.cooltool:command=echo fixed" \ |
| 1473 |
> --config "fix.cooltool:pattern=glob:**" |
| 1474 |
$ cd .. |
| 1475 |
|
| 1476 |
$ cat foo/file |
| 1477 |
fixed |
| 1478 |
$ cat bar/file |
| 1479 |
fixed |
| 1480 |
$ cat baz_file |
| 1481 |
fixed |
| 1482 |
|
| 1483 |
$ cd .. |
| 1484 |
|
| 1485 |
Tools should be able to run on unchanged files, even if they set :linerange. |
| 1486 |
This includes a corner case where deleted chunks of a file are not considered |
| 1487 |
changes. |
| 1488 |
|
| 1489 |
$ hg init skipclean |
| 1490 |
$ cd skipclean |
| 1491 |
|
| 1492 |
$ printf "a\nb\nc\n" > foo |
| 1493 |
$ printf "a\nb\nc\n" > bar |
| 1494 |
$ printf "a\nb\nc\n" > baz |
| 1495 |
$ hg commit -Aqm "base" |
| 1496 |
|
| 1497 |
$ printf "a\nc\n" > foo |
| 1498 |
$ printf "a\nx\nc\n" > baz |
| 1499 |
|
| 1500 |
$ cat >> print.py <<EOF |
| 1501 |
> import sys |
| 1502 |
> for a in sys.argv[1:]: |
| 1503 |
> print(a) |
| 1504 |
> EOF |
| 1505 |
|
| 1506 |
$ hg fix --working-dir foo bar baz \ |
| 1507 |
> --config "fix.changedlines:command=\"$PYTHON\" print.py \"Line ranges:\"" \ |
| 1508 |
> --config 'fix.changedlines:linerange="{first} through {last}"' \ |
| 1509 |
> --config 'fix.changedlines:pattern=glob:**' \ |
| 1510 |
> --config 'fix.changedlines:skipclean=false' |
| 1511 |
|
| 1512 |
$ cat foo |
| 1513 |
Line ranges: |
| 1514 |
$ cat bar |
| 1515 |
Line ranges: |
| 1516 |
$ cat baz |
| 1517 |
Line ranges: |
| 1518 |
2 through 2 |
| 1519 |
|
| 1520 |
$ cd .. |
| 1521 |
|
| 1522 |
Test various cases around merges. We were previously dropping files if they were |
| 1523 |
created on only the p2 side of the merge, so let's test permutations of: |
| 1524 |
* added, was fixed |
| 1525 |
* added, considered for fixing but was already good |
| 1526 |
* added, not considered for fixing |
| 1527 |
* modified, was fixed |
| 1528 |
* modified, considered for fixing but was already good |
| 1529 |
* modified, not considered for fixing |
| 1530 |
|
| 1531 |
Before the bug was fixed where we would drop files, this test demonstrated the |
| 1532 |
following issues: |
| 1533 |
* new_in_r1.ignored, new_in_r1_already_good.changed, and |
| 1534 |
> mod_in_r1_already_good.changed were NOT in the manifest for the merge commit |
| 1535 |
* mod_in_r1.ignored had its contents from r0, NOT r1. |
| 1536 |
|
| 1537 |
We're also setting a named branch for every commit to demonstrate that the |
| 1538 |
branch is kept intact and there aren't issues updating to another branch in the |
| 1539 |
middle of fix. |
| 1540 |
|
| 1541 |
$ hg init merge_keeps_files |
| 1542 |
$ cd merge_keeps_files |
| 1543 |
$ for f in r0 mod_in_r1 mod_in_r2 mod_in_merge mod_in_child; do |
| 1544 |
> for c in changed whole ignored; do |
| 1545 |
> printf "hello\n" > $f.$c |
| 1546 |
> done |
| 1547 |
> printf "HELLO\n" > "mod_in_${f}_already_good.changed" |
| 1548 |
> done |
| 1549 |
$ hg branch -q r0 |
| 1550 |
$ hg ci -Aqm 'r0' |
| 1551 |
$ hg phase -p |
| 1552 |
$ make_test_files() { |
| 1553 |
> printf "world\n" >> "mod_in_$1.changed" |
| 1554 |
> printf "world\n" >> "mod_in_$1.whole" |
| 1555 |
> printf "world\n" >> "mod_in_$1.ignored" |
| 1556 |
> printf "WORLD\n" >> "mod_in_$1_already_good.changed" |
| 1557 |
> printf "new in $1\n" > "new_in_$1.changed" |
| 1558 |
> printf "new in $1\n" > "new_in_$1.whole" |
| 1559 |
> printf "new in $1\n" > "new_in_$1.ignored" |
| 1560 |
> printf "ALREADY GOOD, NEW IN THIS REV\n" > "new_in_$1_already_good.changed" |
| 1561 |
> } |
| 1562 |
$ make_test_commit() { |
| 1563 |
> make_test_files "$1" |
| 1564 |
> hg branch -q "$1" |
| 1565 |
> hg ci -Aqm "$2" |
| 1566 |
> } |
| 1567 |
$ make_test_commit r1 "merge me, pt1" |
| 1568 |
$ hg co -q ".^" |
| 1569 |
$ make_test_commit r2 "merge me, pt2" |
| 1570 |
$ hg merge -qr 1 |
| 1571 |
$ make_test_commit merge "evil merge" |
| 1572 |
$ make_test_commit child "child of merge" |
| 1573 |
$ make_test_files wdir |
| 1574 |
$ hg fix -r 'not public()' -w |
| 1575 |
$ hg log -G -T'{rev}:{shortest(node,8)}: branch:{branch} desc:{desc}' |
| 1576 |
@ 8:c22ce900: branch:child desc:child of merge |
| 1577 |
| |
| 1578 |
o 7:5a30615a: branch:merge desc:evil merge |
| 1579 |
|\ |
| 1580 |
| o 6:4e5acdc4: branch:r2 desc:merge me, pt2 |
| 1581 |
| | |
| 1582 |
o | 5:eea01878: branch:r1 desc:merge me, pt1 |
| 1583 |
|/ |
| 1584 |
o 0:0c548d87: branch:r0 desc:r0 |
| 1585 |
|
| 1586 |
$ hg files -r tip |
| 1587 |
mod_in_child.changed |
| 1588 |
mod_in_child.ignored |
| 1589 |
mod_in_child.whole |
| 1590 |
mod_in_child_already_good.changed |
| 1591 |
mod_in_merge.changed |
| 1592 |
mod_in_merge.ignored |
| 1593 |
mod_in_merge.whole |
| 1594 |
mod_in_merge_already_good.changed |
| 1595 |
mod_in_mod_in_child_already_good.changed |
| 1596 |
mod_in_mod_in_merge_already_good.changed |
| 1597 |
mod_in_mod_in_r1_already_good.changed |
| 1598 |
mod_in_mod_in_r2_already_good.changed |
| 1599 |
mod_in_r0_already_good.changed |
| 1600 |
mod_in_r1.changed |
| 1601 |
mod_in_r1.ignored |
| 1602 |
mod_in_r1.whole |
| 1603 |
mod_in_r1_already_good.changed |
| 1604 |
mod_in_r2.changed |
| 1605 |
mod_in_r2.ignored |
| 1606 |
mod_in_r2.whole |
| 1607 |
mod_in_r2_already_good.changed |
| 1608 |
new_in_child.changed |
| 1609 |
new_in_child.ignored |
| 1610 |
new_in_child.whole |
| 1611 |
new_in_child_already_good.changed |
| 1612 |
new_in_merge.changed |
| 1613 |
new_in_merge.ignored |
| 1614 |
new_in_merge.whole |
| 1615 |
new_in_merge_already_good.changed |
| 1616 |
new_in_r1.changed |
| 1617 |
new_in_r1.ignored |
| 1618 |
new_in_r1.whole |
| 1619 |
new_in_r1_already_good.changed |
| 1620 |
new_in_r2.changed |
| 1621 |
new_in_r2.ignored |
| 1622 |
new_in_r2.whole |
| 1623 |
new_in_r2_already_good.changed |
| 1624 |
r0.changed |
| 1625 |
r0.ignored |
| 1626 |
r0.whole |
| 1627 |
$ for f in "$(hg files -r tip)"; do hg cat -r tip $f -T'{path}:\n{data}\n'; done |
| 1628 |
mod_in_child.changed: |
| 1629 |
hello |
| 1630 |
WORLD |
| 1631 |
|
| 1632 |
mod_in_child.ignored: |
| 1633 |
hello |
| 1634 |
world |
| 1635 |
|
| 1636 |
mod_in_child.whole: |
| 1637 |
HELLO |
| 1638 |
WORLD |
| 1639 |
|
| 1640 |
mod_in_child_already_good.changed: |
| 1641 |
WORLD |
| 1642 |
|
| 1643 |
mod_in_merge.changed: |
| 1644 |
hello |
| 1645 |
WORLD |
| 1646 |
|
| 1647 |
mod_in_merge.ignored: |
| 1648 |
hello |
| 1649 |
world |
| 1650 |
|
| 1651 |
mod_in_merge.whole: |
| 1652 |
HELLO |
| 1653 |
WORLD |
| 1654 |
|
| 1655 |
mod_in_merge_already_good.changed: |
| 1656 |
WORLD |
| 1657 |
|
| 1658 |
mod_in_mod_in_child_already_good.changed: |
| 1659 |
HELLO |
| 1660 |
|
| 1661 |
mod_in_mod_in_merge_already_good.changed: |
| 1662 |
HELLO |
| 1663 |
|
| 1664 |
mod_in_mod_in_r1_already_good.changed: |
| 1665 |
HELLO |
| 1666 |
|
| 1667 |
mod_in_mod_in_r2_already_good.changed: |
| 1668 |
HELLO |
| 1669 |
|
| 1670 |
mod_in_r0_already_good.changed: |
| 1671 |
HELLO |
| 1672 |
|
| 1673 |
mod_in_r1.changed: |
| 1674 |
hello |
| 1675 |
WORLD |
| 1676 |
|
| 1677 |
mod_in_r1.ignored: |
| 1678 |
hello |
| 1679 |
world |
| 1680 |
|
| 1681 |
mod_in_r1.whole: |
| 1682 |
HELLO |
| 1683 |
WORLD |
| 1684 |
|
| 1685 |
mod_in_r1_already_good.changed: |
| 1686 |
WORLD |
| 1687 |
|
| 1688 |
mod_in_r2.changed: |
| 1689 |
hello |
| 1690 |
WORLD |
| 1691 |
|
| 1692 |
mod_in_r2.ignored: |
| 1693 |
hello |
| 1694 |
world |
| 1695 |
|
| 1696 |
mod_in_r2.whole: |
| 1697 |
HELLO |
| 1698 |
WORLD |
| 1699 |
|
| 1700 |
mod_in_r2_already_good.changed: |
| 1701 |
WORLD |
| 1702 |
|
| 1703 |
new_in_child.changed: |
| 1704 |
NEW IN CHILD |
| 1705 |
|
| 1706 |
new_in_child.ignored: |
| 1707 |
new in child |
| 1708 |
|
| 1709 |
new_in_child.whole: |
| 1710 |
NEW IN CHILD |
| 1711 |
|
| 1712 |
new_in_child_already_good.changed: |
| 1713 |
ALREADY GOOD, NEW IN THIS REV |
| 1714 |
|
| 1715 |
new_in_merge.changed: |
| 1716 |
NEW IN MERGE |
| 1717 |
|
| 1718 |
new_in_merge.ignored: |
| 1719 |
new in merge |
| 1720 |
|
| 1721 |
new_in_merge.whole: |
| 1722 |
NEW IN MERGE |
| 1723 |
|
| 1724 |
new_in_merge_already_good.changed: |
| 1725 |
ALREADY GOOD, NEW IN THIS REV |
| 1726 |
|
| 1727 |
new_in_r1.changed: |
| 1728 |
NEW IN R1 |
| 1729 |
|
| 1730 |
new_in_r1.ignored: |
| 1731 |
new in r1 |
| 1732 |
|
| 1733 |
new_in_r1.whole: |
| 1734 |
NEW IN R1 |
| 1735 |
|
| 1736 |
new_in_r1_already_good.changed: |
| 1737 |
ALREADY GOOD, NEW IN THIS REV |
| 1738 |
|
| 1739 |
new_in_r2.changed: |
| 1740 |
NEW IN R2 |
| 1741 |
|
| 1742 |
new_in_r2.ignored: |
| 1743 |
new in r2 |
| 1744 |
|
| 1745 |
new_in_r2.whole: |
| 1746 |
NEW IN R2 |
| 1747 |
|
| 1748 |
new_in_r2_already_good.changed: |
| 1749 |
ALREADY GOOD, NEW IN THIS REV |
| 1750 |
|
| 1751 |
r0.changed: |
| 1752 |
hello |
| 1753 |
|
| 1754 |
r0.ignored: |
| 1755 |
hello |
| 1756 |
|
| 1757 |
r0.whole: |
| 1758 |
hello |
| 1759 |
|
| 1760 |
|
| 1761 |
We should execute the fixer tools as few times as possible, because they might |
| 1762 |
be slow or expensive to execute. The inputs to each execution are effectively |
| 1763 |
the file path, file content, and line ranges. So, we should be able to re-use |
| 1764 |
results whenever those inputs are repeated. That saves a lot of work when |
| 1765 |
fixing chains of commits that all have the same file revision for a path being |
| 1766 |
fixed. |
| 1767 |
|
| 1768 |
$ hg init numberofinvocations |
| 1769 |
$ cd numberofinvocations |
| 1770 |
|
| 1771 |
$ printf "bar1" > bar.log |
| 1772 |
$ printf "baz1" > baz.log |
| 1773 |
$ printf "foo1" > foo.log |
| 1774 |
$ printf "qux1" > qux.log |
| 1775 |
$ hg commit -Aqm "commit1" |
| 1776 |
|
| 1777 |
$ printf "bar2" > bar.log |
| 1778 |
$ printf "baz2" > baz.log |
| 1779 |
$ printf "foo2" > foo.log |
| 1780 |
$ hg commit -Aqm "commit2" |
| 1781 |
|
| 1782 |
$ printf "bar3" > bar.log |
| 1783 |
$ printf "baz3" > baz.log |
| 1784 |
$ hg commit -Aqm "commit3" |
| 1785 |
|
| 1786 |
$ printf "bar4" > bar.log |
| 1787 |
|
| 1788 |
$ LOGFILE=$TESTTMP/log |
| 1789 |
$ LOGGER=$TESTTMP/log.py |
| 1790 |
$ cat >> $LOGGER <<EOF |
| 1791 |
> # Appends the input file's name to the log file. |
| 1792 |
> import sys |
| 1793 |
> with open(r'$LOGFILE', 'a') as f: |
| 1794 |
> f.write(sys.argv[1] + '\n') |
| 1795 |
> sys.stdout.write(sys.stdin.read()) |
| 1796 |
> EOF |
| 1797 |
|
| 1798 |
$ hg fix --working-dir -r "all()" \ |
| 1799 |
> --config "fix.log:command=\"$PYTHON\" \"$LOGGER\" {rootpath}" \ |
| 1800 |
> --config "fix.log:pattern=glob:**.log" |
| 1801 |
|
| 1802 |
$ cat $LOGFILE | sort | uniq -c |
| 1803 |
\s*4 bar.log (re) |
| 1804 |
\s*4 baz.log (re) |
| 1805 |
\s*3 foo.log (re) |
| 1806 |
\s*2 qux.log (re) |
| 1807 |
|
| 1808 |
$ cd .. |
| 1809 |
|
| 1810 |
For tools that support line ranges, it's wrong to blindly re-use fixed file |
| 1811 |
content for the same file revision if it appears twice with different baserevs, |
| 1812 |
because the line ranges could be different. Since computing line ranges is |
| 1813 |
ambiguous, this isn't a matter of correctness, but it affects the usability of |
| 1814 |
this extension. It could maybe be simpler if baserevs were computed on a |
| 1815 |
per-file basis to make this situation impossible to construct. |
| 1816 |
|
| 1817 |
In the following example, we construct two subgraphs with the same file |
| 1818 |
revisions, and fix different sub-subgraphs to get different baserevs and |
| 1819 |
different changed line ranges. The key precondition is that revisions 1 and 4 |
| 1820 |
have the same file revision, and the key result is that their successors don't |
| 1821 |
have the same file content, because we want to fix different areas of that same |
| 1822 |
file revision's content. |
| 1823 |
|
| 1824 |
$ hg init differentlineranges |
| 1825 |
$ cd differentlineranges |
| 1826 |
|
| 1827 |
$ printf "a\nb\n" > file.changed |
| 1828 |
$ hg commit -Aqm "0 ab" |
| 1829 |
$ printf "a\nx\n" > file.changed |
| 1830 |
$ hg commit -Aqm "1 ax" |
| 1831 |
$ hg remove file.changed |
| 1832 |
$ hg commit -Aqm "2 removed" |
| 1833 |
$ hg revert file.changed -r 0 |
| 1834 |
$ hg commit -Aqm "3 ab (reverted)" |
| 1835 |
$ hg revert file.changed -r 1 |
| 1836 |
$ hg commit -Aqm "4 ax (reverted)" |
| 1837 |
|
| 1838 |
$ hg manifest --debug --template "{hash}\n" -r 0; \ |
| 1839 |
> hg manifest --debug --template "{hash}\n" -r 3 |
| 1840 |
418f692145676128d2fb518b027ddbac624be76e |
| 1841 |
418f692145676128d2fb518b027ddbac624be76e |
| 1842 |
$ hg manifest --debug --template "{hash}\n" -r 1; \ |
| 1843 |
> hg manifest --debug --template "{hash}\n" -r 4 |
| 1844 |
09b8b3ce5a507caaa282f7262679e6d04091426c |
| 1845 |
09b8b3ce5a507caaa282f7262679e6d04091426c |
| 1846 |
|
| 1847 |
$ hg fix --working-dir -r 1+3+4 |
| 1848 |
3 new orphan changesets |
| 1849 |
|
| 1850 |
$ hg cat file.changed -r "successors(1)" --hidden |
| 1851 |
a |
| 1852 |
X |
| 1853 |
$ hg cat file.changed -r "successors(4)" --hidden |
| 1854 |
A |
| 1855 |
X |
| 1856 |
|
| 1857 |
$ cd .. |