| 1 |
============================================== |
| 2 |
Test merge algorithm with "relaxed block sync" |
| 3 |
============================================== |
| 4 |
|
| 5 |
Setup |
| 6 |
===== |
| 7 |
|
| 8 |
$ cat >> $HGRCPATH << EOF |
| 9 |
> [experimental] |
| 10 |
> relaxed-block-sync-merge=yes |
| 11 |
> [ui] |
| 12 |
> merge=:merge3 |
| 13 |
> EOF |
| 14 |
$ unset HGMERGE |
| 15 |
|
| 16 |
$ hg init repo |
| 17 |
$ cd repo |
| 18 |
|
| 19 |
$ m=../scratch |
| 20 |
$ mkdir "$m" |
| 21 |
|
| 22 |
# For the purpose of this test, we use a file [listing] that has one line |
| 23 |
# per file of [scratch] directory. |
| 24 |
# This way, the patches can be represented as bash scripts. |
| 25 |
# |
| 26 |
# Adding a line is then just "touch", removing a line is "rm", and |
| 27 |
# modifying a line is "echo modfied > file1". |
| 28 |
|
| 29 |
# Make_change takes a "patch script", as described above, and |
| 30 |
# produces a file [listing] with the coresponding contents |
| 31 |
# past applying the patch to a fixed base state. |
| 32 |
$ make_change() { |
| 33 |
> cmd=$1 |
| 34 |
> rm -r ../scratch |
| 35 |
> mkdir ../scratch |
| 36 |
> (cat listing 2>/dev/null || true) | while IFS=' :' read k v; do echo "$v" > ../scratch/"$k"; done |
| 37 |
> |
| 38 |
> ( |
| 39 |
> cd ../scratch |
| 40 |
> eval "$cmd" >&2 |
| 41 |
> for f in *; do val=$(cat "$f"); printf "$f: $val\n"; done) > listing |
| 42 |
> } |
| 43 |
|
| 44 |
# mk_rev takes a [base] and a patch, and produces a child revision of [base] |
| 45 |
# corresponding to that patch. |
| 46 |
$ mk_rev() { |
| 47 |
> base=$1 |
| 48 |
> cmd=$2 |
| 49 |
> (hg update -C "$base" -q |
| 50 |
> make_change "$cmd" |
| 51 |
> (hg commit -qAm _ 2>&1) | grep -v 'commit already existed') >&2 |
| 52 |
> hg log -r . -T '{rev}' |
| 53 |
> } |
| 54 |
|
| 55 |
$ test() { |
| 56 |
> cmd1=$1 |
| 57 |
> cmd2=$2 |
| 58 |
> r2=$(mk_rev 0 "$cmd2") |
| 59 |
> r1=$(mk_rev 0 "$cmd1") |
| 60 |
> # already at r1 |
| 61 |
> hg merge -q "$r2" |
| 62 |
> cat listing |
| 63 |
> } |
| 64 |
|
| 65 |
$ rev0=$(mk_rev 'rev(-1)' 'echo val1 > key1; echo val2 > key2; echo val3 > key3; ') |
| 66 |
$ cat listing |
| 67 |
key1: val1 |
| 68 |
key2: val2 |
| 69 |
key3: val3 |
| 70 |
|
| 71 |
Actual testing |
| 72 |
============== |
| 73 |
|
| 74 |
easy merge: no need for relaxed block sync: |
| 75 |
------------------------------------------- |
| 76 |
|
| 77 |
$ test 'echo modified1 > key1' 'echo modified3 > key3' |
| 78 |
key1: modified1 |
| 79 |
key2: val2 |
| 80 |
key3: modified3 |
| 81 |
|
| 82 |
Add adjacent to modify: |
| 83 |
----------------------- |
| 84 |
|
| 85 |
$ test 'echo modified > key3' 'echo val4 > key4' |
| 86 |
key1: val1 |
| 87 |
key2: val2 |
| 88 |
key3: modified |
| 89 |
key4: val4 |
| 90 |
|
| 91 |
Modify adjacent to modify: |
| 92 |
-------------------------- |
| 93 |
|
| 94 |
$ test 'echo modified3 > key3' 'echo modified2 > key2' |
| 95 |
key1: val1 |
| 96 |
key2: modified2 |
| 97 |
key3: modified3 |
| 98 |
|
| 99 |
Remove adjacent to modify: |
| 100 |
-------------------------- |
| 101 |
|
| 102 |
$ test 'rm key2' 'echo modified > key1' |
| 103 |
key1: modified |
| 104 |
key3: val3 |
| 105 |
|
| 106 |
Add adjacent to remove: |
| 107 |
----------------------- |
| 108 |
|
| 109 |
$ test 'rm key2' 'touch key1a' |
| 110 |
key1: val1 |
| 111 |
key1a: |
| 112 |
key3: val3 |
| 113 |
|
| 114 |
Remove adjacent to remove: |
| 115 |
-------------------------- |
| 116 |
|
| 117 |
$ test 'rm key2' 'rm key1' |
| 118 |
key3: val3 |
| 119 |
|
| 120 |
It even works if you're sandwiched between additions above and below: |
| 121 |
|
| 122 |
$ test 'echo val-changed-3 > key3' 'touch key2a; touch key4' |
| 123 |
key1: val1 |
| 124 |
key2: val2 |
| 125 |
key2a: |
| 126 |
key3: val-changed-3 |
| 127 |
key4: |
| 128 |
|
| 129 |
Add adjacent to add: |
| 130 |
-------------------- |
| 131 |
|
| 132 |
Add adjacent to add is still disallowed because we don't know what order to add |
| 133 |
lines in: |
| 134 |
|
| 135 |
$ test 'touch key1a' 'touch key1b' |
| 136 |
warning: conflicts while merging listing! (edit, then use 'hg resolve --mark') |
| 137 |
key1: val1 |
| 138 |
<<<<<<< working copy: 744662bcc33a - test: _ |
| 139 |
key1a: |
| 140 |
||||||| common ancestor: b1791e356cd4 - test: _ |
| 141 |
======= |
| 142 |
key1b: |
| 143 |
>>>>>>> merge rev: 06735b47f956 - test: _ |
| 144 |
key2: val2 |
| 145 |
key3: val3 |
| 146 |
|
| 147 |
Add kinda-adjacent to add can still work if there's an |
| 148 |
adjacent line that helps resolve the order ambiguity: |
| 149 |
|
| 150 |
$ test 'touch key1a; rm key2' 'touch key2a' |
| 151 |
key1: val1 |
| 152 |
key1a: |
| 153 |
key2a: |
| 154 |
key3: val3 |