tests/test-racy-mutations.t
author Martin von Zweigbergk <martinvonz@google.com>
Tue, 18 Jan 2022 13:05:21 -0800
changeset 49060 f3aafd785e65
parent 48816 bd752712ccaf
child 48833 dd384ad01d88
permissions -rw-r--r--
filemerge: add support for partial conflict resolution by external tool A common class of merge conflicts is in imports/#includes/etc. It's relatively easy to write a tool that can resolve these conflicts, perhaps by naively just unioning the statements and leaving any cleanup to other tools to do later [1]. Such specialized tools cannot generally resolve all conflicts in a file, of course. Let's therefore call them "partial merge tools". Note that the internal simplemerge algorithm is such a partial merge tool - one that only resolves trivial "conflicts" where one side is unchanged or both sides change in the same way. One can also imagine having smarter language-aware partial tools that merge the AST. It may be useful for such tools to interactively let the user resolve any conflicts it can't resolve itself. However, having the option of implementing it as a partial merge tool means that the developer doesn't *need* to create a UI for it. Instead, the user can resolve any remaining conflicts with their regular merge tool (e.g. `:merge3` or `meld). We don't currently have a way to let the user define such partial merge tools. That's what this patch addresses. It lets the user configure partial merge tools to run. Each tool can be configured to run only on files matching certain patterns (e.g. "*.py"). The tool takes three inputs (local, base, other) and resolves conflicts by updating these in place. For example, let's say the inputs are these: base: ``` import sys def main(): print('Hello') ``` local: ``` import os import sys def main(): print('Hi') ``` other: ``` import re import sys def main(): print('Howdy') ``` A partial merge tool could now resolve the conflicting imports by replacing the import statements in *all* files by the following snippet, while leaving the remainder of the files unchanged. ``` import os import re import sys ``` As a result, simplemerge and any regular merge tool that runs after the partial merge tool(s) will consider the imports to be non-conflicting and will only present the conflict in `main()` to the user. Differential Revision: https://phab.mercurial-scm.org/D12356
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
46646
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
     1
#testcases skip-detection fail-if-detected
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
     2
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
     3
Test situations that "should" only be reproducible:
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
     4
- on networked filesystems, or
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
     5
- user using `hg debuglocks` to eliminate the lock file, or
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
     6
- something (that doesn't respect the lock file) writing to the .hg directory
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
     7
while we're running
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
     8
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
     9
  $ hg init a
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    10
  $ cd a
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    11
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    12
  $ cat > "$TESTTMP/waitlock_editor.sh" <<EOF
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    13
  >     [ -n "\${WAITLOCK_ANNOUNCE:-}" ] && touch "\${WAITLOCK_ANNOUNCE}"
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    14
  >     f="\${WAITLOCK_FILE}"
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    15
  >     start=\`date +%s\`
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    16
  >     timeout=5
48816
bd752712ccaf test: use `wait-on-file` in `test-racy-mutations.t`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47225
diff changeset
    17
  >     $RUNTESTDIR/testlib/wait-on-file "\$timeout" "\$f"
46646
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    18
  >     if [ \$# -gt 1 ]; then
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    19
  >         cat "\$@"
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    20
  >     fi
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    21
  > EOF
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    22
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    23
Things behave differently if we don't already have a 00changelog.i file when
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    24
this all starts, so let's make one.
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    25
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    26
  $ echo r0 > r0
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    27
  $ hg commit -qAm 'r0'
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    28
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    29
Start an hg commit that will take a while
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    30
  $ EDITOR_STARTED="$(pwd)/.editor_started"
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    31
  $ MISCHIEF_MANAGED="$(pwd)/.mischief_managed"
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    32
  $ JOBS_FINISHED="$(pwd)/.jobs_finished"
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    33
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    34
#if fail-if-detected
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    35
  $ cat >> .hg/hgrc << EOF
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    36
  > [debug]
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    37
  > revlog.verifyposition.changelog = fail
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    38
  > EOF
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    39
#endif
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    40
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    41
  $ echo foo > foo
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    42
  $ (WAITLOCK_ANNOUNCE="${EDITOR_STARTED}" \
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    43
  >      WAITLOCK_FILE="${MISCHIEF_MANAGED}" \
47034
a12819559ccb tests: invoke some shell scripts through the shell interpreter for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 46646
diff changeset
    44
  >           HGEDITOR="sh $TESTTMP/waitlock_editor.sh" \
46646
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    45
  >           hg commit -qAm 'r1 (foo)' --edit foo > .foo_commit_out 2>&1 ; touch "${JOBS_FINISHED}") &
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    46
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    47
Wait for the "editor" to actually start
47034
a12819559ccb tests: invoke some shell scripts through the shell interpreter for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 46646
diff changeset
    48
  $ WAITLOCK_FILE="${EDITOR_STARTED}" sh "$TESTTMP/waitlock_editor.sh"
46646
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    49
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    50
Break the locks, and make another commit.
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    51
  $ hg debuglocks -LW
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    52
  $ echo bar > bar
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    53
  $ hg commit -qAm 'r2 (bar)' bar
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    54
  $ hg debugrevlogindex -c
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    55
     rev linkrev nodeid       p1           p2
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    56
       0       0 222799e2f90b 000000000000 000000000000
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    57
       1       1 6f124f6007a0 222799e2f90b 000000000000
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    58
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    59
Awaken the editor from that first commit
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    60
  $ touch "${MISCHIEF_MANAGED}"
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    61
And wait for it to finish
47034
a12819559ccb tests: invoke some shell scripts through the shell interpreter for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 46646
diff changeset
    62
  $ WAITLOCK_FILE="${JOBS_FINISHED}" sh "$TESTTMP/waitlock_editor.sh"
46646
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    63
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    64
#if skip-detection
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    65
(Ensure there was no output)
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    66
  $ cat .foo_commit_out
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    67
And observe a corrupted repository -- rev 2's linkrev is 1, which should never
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    68
happen for the changelog (the linkrev should always refer to itself).
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    69
  $ hg debugrevlogindex -c
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    70
     rev linkrev nodeid       p1           p2
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    71
       0       0 222799e2f90b 000000000000 000000000000
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    72
       1       1 6f124f6007a0 222799e2f90b 000000000000
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    73
       2       1 ac80e6205bb2 222799e2f90b 000000000000
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    74
#endif
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    75
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    76
#if fail-if-detected
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    77
  $ cat .foo_commit_out
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    78
  transaction abort!
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    79
  rollback completed
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    80
  note: commit message saved in .hg/last-message.txt
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    81
  note: use 'hg commit --logfile .hg/last-message.txt --edit' to reuse it
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    82
  abort: 00changelog.i: file cursor at position 249, expected 121
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    83
And no corruption in the changelog.
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    84
  $ hg debugrevlogindex -c
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    85
     rev linkrev nodeid       p1           p2
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    86
       0       0 222799e2f90b 000000000000 000000000000
47225
906a7bcaac86 revlog: introduce a mandatory `_writing` context to update revlog content
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47034
diff changeset
    87
       1       1 6f124f6007a0 222799e2f90b 000000000000 (missing-correct-output !)
46646
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    88
And, because of transactions, there's none in the manifestlog either.
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    89
  $ hg debugrevlogindex -m
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    90
     rev linkrev nodeid       p1           p2
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    91
       0       0 7b7020262a56 000000000000 000000000000
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    92
       1       1 ad3fe36d86d9 7b7020262a56 000000000000
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    93
#endif
e9901d01d135 revlog: add a mechanism to verify expected file position before appending
Kyle Lippincott <spectral@google.com>
parents:
diff changeset
    94