tests/test-convert-hg-sink.t
author Pierre-Yves David <pierre-yves.david@octobus.net>
Mon, 14 Dec 2020 11:32:24 +0100
changeset 46149 294d5aca4ff5
parent 42361 c0e1ea0c4cee
permissions -rw-r--r--
copies: iterate over children directly (instead of parents) Before this change we would gather all parent → child edges and iterate on all parent, gathering copy information for children and aggregating them from there. They are not strict requirement for edges to be processed in that specific order. We could also simply iterate over all "children" revision and aggregate data from both parents at the same time. This patch does that. It make various things simpler: * since both parents are processed at the same time, we no longer need to cache data for merge (see next changeset for details), * we no longer need nested loop to process data, * we no longer need to store partial merge data for a rev from distinct loop interaction to another when processing merges, * we no longer need to build a full parent -> children mapping (we only rely on a simpler "parent -> number of children" map (for memory efficiency), * the data access pattern is now simpler (from lower revisions to higher revisions) and entirely predicable. That predictability open the way to prefetching and parallel processing. So that new iterations order requires simpler code and open the way to interesting optimisation. The effect on performance is quite good. In the worse case, we don't see any significant negative impact. And in the best case, the reduction of roundtrip to Python provide us with a significant speed. Some example below: Repo Case Source-Rev Dest-Rev # of revisions old time new time Difference Factor time per rev --------------------------------------------------------------------------------------------------------------------------------------------------------------- mozilla-try x00000_revs_x00000_added_0_copies dc8a3ca7010e d16fde900c9c : 34414 revs, 0.962867 s, 0.502584 s, -0.460283 s, × 0.5220, 14 µs/rev mozilla-try x0000_revs_xx000_added_x_copies 156f6e2674f2 4d0f2c178e66 : 8598 revs, 0.110717 s, 0.076323 s, -0.034394 s, × 0.6894, 8 µs/rev # full comparison between the previous changeset and this one Repo Case Source-Rev Dest-Rev # of revisions old time new time Difference Factor time per rev --------------------------------------------------------------------------------------------------------------------------------------------------------------- mercurial x_revs_x_added_0_copies ad6b123de1c7 39cfcef4f463 : 1 revs, 0.000048 s, 0.000041 s, -0.000007 s, × 0.8542, 41 µs/rev mercurial x_revs_x_added_x_copies 2b1c78674230 0c1d10351869 : 6 revs, 0.000153 s, 0.000102 s, -0.000051 s, × 0.6667, 17 µs/rev mercurial x000_revs_x000_added_x_copies 81f8ff2a9bf2 dd3267698d84 : 1032 revs, 0.004209 s, 0.004254 s, +0.000045 s, × 1.0107, 4 µs/rev pypy x_revs_x_added_0_copies aed021ee8ae8 099ed31b181b : 9 revs, 0.000203 s, 0.000282 s, +0.000079 s, × 1.3892, 31 µs/rev pypy x_revs_x000_added_0_copies 4aa4e1f8e19a 359343b9ac0e : 1 revs, 0.000059 s, 0.000048 s, -0.000011 s, × 0.8136, 48 µs/rev pypy x_revs_x_added_x_copies ac52eb7bbbb0 72e022663155 : 7 revs, 0.000194 s, 0.000211 s, +0.000017 s, × 1.0876, 30 µs/rev pypy x_revs_x00_added_x_copies c3b14617fbd7 ace7255d9a26 : 1 revs, 0.000380 s, 0.000375 s, -0.000005 s, × 0.9868, 375 µs/rev pypy x_revs_x000_added_x000_copies df6f7a526b60 a83dc6a2d56f : 6 revs, 0.010588 s, 0.010574 s, -0.000014 s, × 0.9987, 1762 µs/rev pypy x000_revs_xx00_added_0_copies 89a76aede314 2f22446ff07e : 4785 revs, 0.048961 s, 0.049974 s, +0.001013 s, × 1.0207, 10 µs/rev pypy x000_revs_x000_added_x_copies 8a3b5bfd266e 2c68e87c3efe : 6780 revs, 0.083612 s, 0.084300 s, +0.000688 s, × 1.0082, 12 µs/rev pypy x000_revs_x000_added_x000_copies 89a76aede314 7b3dda341c84 : 5441 revs, 0.058579 s, 0.060128 s, +0.001549 s, × 1.0264, 11 µs/rev pypy x0000_revs_x_added_0_copies d1defd0dc478 c9cb1334cc78 : 43645 revs, 0.736783 s, 0.686542 s, -0.050241 s, × 0.9318, 15 µs/rev pypy x0000_revs_xx000_added_0_copies bf2c629d0071 4ffed77c095c : 2 revs, 0.022050 s, 0.009277 s, -0.012773 s, × 0.4207, 4638 µs/rev pypy x0000_revs_xx000_added_x000_copies 08ea3258278e d9fa043f30c0 : 11316 revs, 0.120800 s, 0.114733 s, -0.006067 s, × 0.9498, 10 µs/rev netbeans x_revs_x_added_0_copies fb0955ffcbcd a01e9239f9e7 : 2 revs, 0.000140 s, 0.000081 s, -0.000059 s, × 0.5786, 40 µs/rev netbeans x_revs_x000_added_0_copies 6f360122949f 20eb231cc7d0 : 2 revs, 0.000114 s, 0.000107 s, -0.000007 s, × 0.9386, 53 µs/rev netbeans x_revs_x_added_x_copies 1ada3faf6fb6 5a39d12eecf4 : 3 revs, 0.000224 s, 0.000173 s, -0.000051 s, × 0.7723, 57 µs/rev netbeans x_revs_x00_added_x_copies 35be93ba1e2c 9eec5e90c05f : 9 revs, 0.000723 s, 0.000698 s, -0.000025 s, × 0.9654, 77 µs/rev netbeans x000_revs_xx00_added_0_copies eac3045b4fdd 51d4ae7f1290 : 1421 revs, 0.009665 s, 0.009248 s, -0.000417 s, × 0.9569, 6 µs/rev netbeans x000_revs_x000_added_x_copies e2063d266acd 6081d72689dc : 1533 revs, 0.014820 s, 0.015446 s, +0.000626 s, × 1.0422, 10 µs/rev netbeans x000_revs_x000_added_x000_copies ff453e9fee32 411350406ec2 : 5750 revs, 0.076049 s, 0.074373 s, -0.001676 s, × 0.9780, 12 µs/rev netbeans x0000_revs_xx000_added_x000_copies 588c2d1ced70 1aad62e59ddd : 66949 revs, 0.683603 s, 0.639870 s, -0.043733 s, × 0.9360, 9 µs/rev mozilla-central x_revs_x_added_0_copies 3697f962bb7b 7015fcdd43a2 : 2 revs, 0.000161 s, 0.000088 s, -0.000073 s, × 0.5466, 44 µs/rev mozilla-central x_revs_x000_added_0_copies dd390860c6c9 40d0c5bed75d : 8 revs, 0.000234 s, 0.000199 s, -0.000035 s, × 0.8504, 24 µs/rev mozilla-central x_revs_x_added_x_copies 8d198483ae3b 14207ffc2b2f : 9 revs, 0.000247 s, 0.000171 s, -0.000076 s, × 0.6923, 19 µs/rev mozilla-central x_revs_x00_added_x_copies 98cbc58cc6bc 446a150332c3 : 7 revs, 0.000630 s, 0.000592 s, -0.000038 s, × 0.9397, 84 µs/rev mozilla-central x_revs_x000_added_x000_copies 3c684b4b8f68 0a5e72d1b479 : 3 revs, 0.003286 s, 0.003151 s, -0.000135 s, × 0.9589, 1050 µs/rev mozilla-central x_revs_x0000_added_x0000_copies effb563bb7e5 c07a39dc4e80 : 6 revs, 0.062441 s, 0.061612 s, -0.000829 s, × 0.9867, 10268 µs/rev mozilla-central x000_revs_xx00_added_0_copies 6100d773079a 04a55431795e : 1593 revs, 0.005423 s, 0.005381 s, -0.000042 s, × 0.9923, 3 µs/rev mozilla-central x000_revs_x000_added_x_copies 9f17a6fc04f9 2d37b966abed : 41 revs, 0.005919 s, 0.003742 s, -0.002177 s, × 0.6322, 91 µs/rev mozilla-central x000_revs_x000_added_x000_copies 7c97034feb78 4407bd0c6330 : 7839 revs, 0.062597 s, 0.061983 s, -0.000614 s, × 0.9902, 7 µs/rev mozilla-central x0000_revs_xx000_added_0_copies 9eec5917337d 67118cc6dcad : 615 revs, 0.043551 s, 0.019861 s, -0.023690 s, × 0.4560, 32 µs/rev mozilla-central x0000_revs_xx000_added_x000_copies f78c615a656c 96a38b690156 : 30263 revs, 0.192475 s, 0.188101 s, -0.004374 s, × 0.9773, 6 µs/rev mozilla-central x00000_revs_x0000_added_x0000_copies 6832ae71433c 4c222a1d9a00 : 153721 revs, 1.955575 s, 1.806696 s, -0.148879 s, × 0.9239, 11 µs/rev mozilla-central x00000_revs_x00000_added_x000_copies 76caed42cf7c 1daa622bbe42 : 204976 revs, 2.886501 s, 2.682987 s, -0.203514 s, × 0.9295, 13 µs/rev mozilla-try x_revs_x_added_0_copies aaf6dde0deb8 9790f499805a : 2 revs, 0.001181 s, 0.000852 s, -0.000329 s, × 0.7214, 426 µs/rev mozilla-try x_revs_x000_added_0_copies d8d0222927b4 5bb8ce8c7450 : 2 revs, 0.001189 s, 0.000859 s, -0.000330 s, × 0.7225, 429 µs/rev mozilla-try x_revs_x_added_x_copies 092fcca11bdb 936255a0384a : 4 revs, 0.000563 s, 0.000150 s, -0.000413 s, × 0.2664, 37 µs/rev mozilla-try x_revs_x00_added_x_copies b53d2fadbdb5 017afae788ec : 2 revs, 0.001548 s, 0.001158 s, -0.000390 s, × 0.7481, 579 µs/rev mozilla-try x_revs_x000_added_x000_copies 20408ad61ce5 6f0ee96e21ad : 1 revs, 0.027782 s, 0.027240 s, -0.000542 s, × 0.9805, 27240 µs/rev mozilla-try x_revs_x0000_added_x0000_copies effb563bb7e5 c07a39dc4e80 : 6 revs, 0.062781 s, 0.062824 s, +0.000043 s, × 1.0007, 10470 µs/rev mozilla-try x000_revs_xx00_added_0_copies 6100d773079a 04a55431795e : 1593 revs, 0.005778 s, 0.005463 s, -0.000315 s, × 0.9455, 3 µs/rev mozilla-try x000_revs_x000_added_x_copies 9f17a6fc04f9 2d37b966abed : 41 revs, 0.006192 s, 0.004238 s, -0.001954 s, × 0.6844, 103 µs/rev mozilla-try x000_revs_x000_added_x000_copies 1346fd0130e4 4c65cbdabc1f : 6657 revs, 0.065391 s, 0.064113 s, -0.001278 s, × 0.9805, 9 µs/rev mozilla-try x0000_revs_x_added_0_copies 63519bfd42ee a36a2a865d92 : 40314 revs, 0.317216 s, 0.294063 s, -0.023153 s, × 0.9270, 7 µs/rev mozilla-try x0000_revs_x_added_x_copies 9fe69ff0762d bcabf2a78927 : 38690 revs, 0.303119 s, 0.281493 s, -0.021626 s, × 0.9287, 7 µs/rev mozilla-try x0000_revs_xx000_added_x_copies 156f6e2674f2 4d0f2c178e66 : 8598 revs, 0.110717 s, 0.076323 s, -0.034394 s, × 0.6894, 8 µs/rev mozilla-try x0000_revs_xx000_added_0_copies 9eec5917337d 67118cc6dcad : 615 revs, 0.045739 s, 0.020390 s, -0.025349 s, × 0.4458, 33 µs/rev mozilla-try x0000_revs_xx000_added_x000_copies 89294cd501d9 7ccb2fc7ccb5 : 97052 revs, 3.098021 s, 3.023879 s, -0.074142 s, × 0.9761, 31 µs/rev mozilla-try x0000_revs_x0000_added_x0000_copies e928c65095ed e951f4ad123a : 52031 revs, 0.771480 s, 0.735549 s, -0.035931 s, × 0.9534, 14 µs/rev mozilla-try x00000_revs_x_added_0_copies 6a320851d377 1ebb79acd503 : 363753 revs, 18.813422 s, 18.568900 s, -0.244522 s, × 0.9870, 51 µs/rev mozilla-try x00000_revs_x00000_added_0_copies dc8a3ca7010e d16fde900c9c : 34414 revs, 0.962867 s, 0.502584 s, -0.460283 s, × 0.5220, 14 µs/rev mozilla-try x00000_revs_x_added_x_copies 5173c4b6f97c 95d83ee7242d : 362229 revs, 18.684923 s, 18.356645 s, -0.328278 s, × 0.9824, 50 µs/rev mozilla-try x00000_revs_x000_added_x_copies 9126823d0e9c ca82787bb23c : 359344 revs, 18.296305 s, 18.250393 s, -0.045912 s, × 0.9975, 50 µs/rev mozilla-try x00000_revs_x0000_added_x0000_copies 8d3fafa80d4b eb884023b810 : 192665 revs, 3.061887 s, 2.792459 s, -0.269428 s, × 0.9120, 14 µs/rev mozilla-try x00000_revs_x00000_added_x0000_copies 1b661134e2ca 1ae03d022d6d : 228985 revs, 103.869641 s, 107.697264 s, +3.827623 s, × 1.0369, 470 µs/rev mozilla-try x00000_revs_x00000_added_x000_copies 9b2a99adc05e 8e29777b48e6 : 382065 revs, 64.262957 s, 63.961040 s, -0.301917 s, × 0.9953, 167 µs/rev Differential Revision: https://phab.mercurial-scm.org/D9422


  $ cat >> $HGRCPATH <<EOF
  > [extensions]
  > convert=
  > [convert]
  > hg.saverev=False
  > EOF
  $ hg init orig
  $ cd orig
  $ echo foo > foo
  $ echo bar > bar
  $ hg ci -qAm 'add foo and bar'
  $ hg rm foo
  $ hg ci -m 'remove foo'
  $ mkdir foo
  $ echo file > foo/file
  $ hg ci -qAm 'add foo/file'
  $ hg tag some-tag
  $ hg tag -l local-tag
  $ echo '1234567890123456789012345678901234567890 missing_tag' >> .hgtags
  $ hg ci -m 'add a missing tag'
  $ hg log
  changeset:   4:3fb95ee23a66
  tag:         tip
  user:        test
  date:        Thu Jan 01 00:00:00 1970 +0000
  summary:     add a missing tag
  
  changeset:   3:593cbf6fb2b4
  tag:         local-tag
  user:        test
  date:        Thu Jan 01 00:00:00 1970 +0000
  summary:     Added tag some-tag for changeset ad681a868e44
  
  changeset:   2:ad681a868e44
  tag:         some-tag
  user:        test
  date:        Thu Jan 01 00:00:00 1970 +0000
  summary:     add foo/file
  
  changeset:   1:cbba8ecc03b7
  user:        test
  date:        Thu Jan 01 00:00:00 1970 +0000
  summary:     remove foo
  
  changeset:   0:327daa9251fa
  user:        test
  date:        Thu Jan 01 00:00:00 1970 +0000
  summary:     add foo and bar
  
  $ hg phase --public -r tip
  $ cd ..
  $ hg convert orig new 2>&1 | grep -v 'subversion python bindings could not be loaded'
  initializing destination new repository
  scanning source...
  sorting...
  converting...
  4 add foo and bar
  3 remove foo
  2 add foo/file
  1 Added tag some-tag for changeset ad681a868e44
  0 add a missing tag
  missing tag entry: "1234567890123456789012345678901234567890 missing_tag"
  $ cd new
  $ hg log -G --template '{rev} {node|short} ({phase}) "{desc}"\n'
  o  4 3fb95ee23a66 (public) "add a missing tag"
  |
  o  3 593cbf6fb2b4 (public) "Added tag some-tag for changeset ad681a868e44"
  |
  o  2 ad681a868e44 (public) "add foo/file"
  |
  o  1 cbba8ecc03b7 (public) "remove foo"
  |
  o  0 327daa9251fa (public) "add foo and bar"
  

  $ hg out ../orig
  comparing with ../orig
  searching for changes
  no changes found
  [1]

dirstate should be empty:

  $ hg debugstate
  $ hg parents -q
  $ hg up -C
  3 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg copy bar baz

put something in the dirstate:

  $ hg debugstate > debugstate
  $ grep baz debugstate
  a   0         -1 unset               baz
  copy: bar -> baz

add a new revision in the original repo

  $ cd ../orig
  $ echo baz > baz
  $ hg ci -qAm 'add baz'
  $ cd ..
  $ hg convert orig new 2>&1 | grep -v 'subversion python bindings could not be loaded'
  scanning source...
  sorting...
  converting...
  0 add baz
  $ cd new
  $ hg out ../orig
  comparing with ../orig
  searching for changes
  no changes found
  [1]

dirstate should be the same (no output below):

  $ hg debugstate > new-debugstate
  $ diff debugstate new-debugstate

no copies

  $ hg up -C
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg debugrename baz
  baz not renamed
  $ cd ..

test tag rewriting

  $ cat > filemap <<EOF
  > exclude foo
  > EOF
  $ hg convert --filemap filemap orig new-filemap 2>&1 | grep -v 'subversion python bindings could not be loaded'
  initializing destination new-filemap repository
  scanning source...
  sorting...
  converting...
  5 add foo and bar
  4 remove foo
  3 add foo/file
  2 Added tag some-tag for changeset ad681a868e44
  1 add a missing tag
  missing tag entry: "1234567890123456789012345678901234567890 missing_tag"
  0 add baz
  $ cd new-filemap
  $ hg tags
  tip                                3:7bb553f2c68a
  some-tag                           0:ba8636729451
  $ cd ..


Test cases for hg-hg roundtrip

Helper

  $ glog()
  > {
  >     hg log -G --template '{rev} {node|short} ({phase}) "{desc}" files: {files}\n' $*
  > }

Create a tricky source repo

  $ hg init source
  $ cd source

  $ echo 0 > 0
  $ hg ci -Aqm '0: add 0'
  $ echo a > a
  $ mkdir dir
  $ echo b > dir/b
  $ hg ci -qAm '1: add a and dir/b'
  $ echo c > dir/c
  $ hg ci -qAm '2: add dir/c'
  $ hg copy a e
  $ echo b >> b
  $ hg ci -qAm '3: copy a to e, change b'
  $ hg up -qr -3
  $ echo a >> a
  $ hg ci -qAm '4: change a'
  $ hg merge
  merging a and e to e
  2 files updated, 1 files merged, 0 files removed, 0 files unresolved
  (branch merge, don't forget to commit)
  $ hg copy b dir/d
  $ hg ci -qAm '5: merge 2 and 3, copy b to dir/d'
  $ echo a >> a
  $ hg ci -qAm '6: change a'

  $ hg mani
  0
  a
  b
  dir/b
  dir/c
  dir/d
  e
  $ hg phase --public -r tip
  $ glog
  @  6 0613c8e59a3d (public) "6: change a" files: a
  |
  o    5 717e9b37cdb7 (public) "5: merge 2 and 3, copy b to dir/d" files: dir/d e
  |\
  | o  4 86a55cb968d5 (public) "4: change a" files: a
  | |
  o |  3 0e6e235919dd (public) "3: copy a to e, change b" files: b e
  | |
  o |  2 0394b0d5e4f7 (public) "2: add dir/c" files: dir/c
  |/
  o  1 333546584845 (public) "1: add a and dir/b" files: a dir/b
  |
  o  0 d1a24e2ebd23 (public) "0: add 0" files: 0
  
  $ cd ..

Convert excluding rev 0 and dir/ (and thus rev2):

  $ cat << EOF > filemap
  > exclude dir
  > EOF

  $ hg convert --filemap filemap source dest --config convert.hg.revs=1::
  initializing destination dest repository
  scanning source...
  sorting...
  converting...
  5 1: add a and dir/b
  4 2: add dir/c
  3 3: copy a to e, change b
  2 4: change a
  1 5: merge 2 and 3, copy b to dir/d
  0 6: change a

Verify that conversion skipped rev 2:

  $ glog -R dest
  o  4 78814e84a217 (draft) "6: change a" files: a
  |
  o    3 f7cff662c5e5 (draft) "5: merge 2 and 3, copy b to dir/d" files: e
  |\
  | o  2 ab40a95b0072 (draft) "4: change a" files: a
  | |
  o |  1 bd51f17597bf (draft) "3: copy a to e, change b" files: b e
  |/
  o  0 a4a1dae0fe35 (draft) "1: add a and dir/b" files: 0 a
  

Verify mapping correct in both directions:

  $ cat source/.hg/shamap
  a4a1dae0fe3514cefd9b8541b7abbc8f44f946d5 333546584845f70c4cfecb992341aaef0e708166
  bd51f17597bf32268e68a560b206898c3960cda2 0e6e235919dd8e9285ba8eb5adf703af9ad99378
  ab40a95b00725307e79c2fd271000aa8af9759f4 86a55cb968d51770cba2a1630d6cc637b574580a
  f7cff662c5e581e6f3f1a85ffdd2bcb35825f6ba 717e9b37cdb7eb9917ca8e30aa3f986e6d5b177d
  78814e84a217894517c2de392b903ed05e6871a4 0613c8e59a3ddb9789072ef52f1ed13496489bb4
  $ cat dest/.hg/shamap
  333546584845f70c4cfecb992341aaef0e708166 a4a1dae0fe3514cefd9b8541b7abbc8f44f946d5
  0394b0d5e4f761ced559fd0bbdc6afc16cb3f7d1 a4a1dae0fe3514cefd9b8541b7abbc8f44f946d5
  0e6e235919dd8e9285ba8eb5adf703af9ad99378 bd51f17597bf32268e68a560b206898c3960cda2
  86a55cb968d51770cba2a1630d6cc637b574580a ab40a95b00725307e79c2fd271000aa8af9759f4
  717e9b37cdb7eb9917ca8e30aa3f986e6d5b177d f7cff662c5e581e6f3f1a85ffdd2bcb35825f6ba
  0613c8e59a3ddb9789072ef52f1ed13496489bb4 78814e84a217894517c2de392b903ed05e6871a4

Verify meta data converted correctly:

  $ hg -R dest log -r 1 --debug -p --git
  changeset:   1:bd51f17597bf32268e68a560b206898c3960cda2
  phase:       draft
  parent:      0:a4a1dae0fe3514cefd9b8541b7abbc8f44f946d5
  parent:      -1:0000000000000000000000000000000000000000
  manifest:    1:040c72ed9b101773c24ac314776bfc846943781f
  user:        test
  date:        Thu Jan 01 00:00:00 1970 +0000
  files+:      b e
  extra:       branch=default
  description:
  3: copy a to e, change b
  
  
  diff --git a/b b/b
  new file mode 100644
  --- /dev/null
  +++ b/b
  @@ -0,0 +1,1 @@
  +b
  diff --git a/a b/e
  copy from a
  copy to e
  
Verify files included and excluded correctly:

  $ hg -R dest manifest -r tip
  0
  a
  b
  e


Make changes in dest and convert back:

  $ hg -R dest up -q
  $ echo dest > dest/dest
  $ hg -R dest ci -Aqm 'change in dest'
  $ hg -R dest tip
  changeset:   5:a2e0e3cc6d1d
  tag:         tip
  user:        test
  date:        Thu Jan 01 00:00:00 1970 +0000
  summary:     change in dest
  

(converting merges back after using a filemap will probably cause chaos so we
exclude merges.)

  $ hg convert dest source --config convert.hg.revs='!merge()'
  scanning source...
  sorting...
  converting...
  0 change in dest

Verify the conversion back:

  $ hg -R source log --debug -r tip
  changeset:   7:e6d364a69ff1248b2099e603b0c145504cade6f0
  tag:         tip
  phase:       draft
  parent:      6:0613c8e59a3ddb9789072ef52f1ed13496489bb4
  parent:      -1:0000000000000000000000000000000000000000
  manifest:    7:aa3e9542f3b76d4f1f1b2e9c7ce9dbb48b6a95ec
  user:        test
  date:        Thu Jan 01 00:00:00 1970 +0000
  files+:      dest
  extra:       branch=default
  description:
  change in dest
  
  
Files that had been excluded are still present:

  $ hg -R source manifest -r tip
  0
  a
  b
  dest
  dir/b
  dir/c
  dir/d
  e

More source changes

  $ cd source
  $ echo 1 >> a
  $ hg ci -m '8: source first branch'
  created new head
  $ hg up -qr -2
  $ echo 2 >> a
  $ hg ci -m '9: source second branch'
  $ hg merge -q --tool internal:local
  $ hg ci -m '10: source merge'
  $ echo >> a
  $ hg ci -m '11: source change'

  $ hg mani
  0
  a
  b
  dest
  dir/b
  dir/c
  dir/d
  e

  $ glog -r 6:
  @  11 0c8927d1f7f4 (draft) "11: source change" files: a
  |
  o    10 9ccb7ee8d261 (draft) "10: source merge" files: a
  |\
  | o  9 f131b1518dba (draft) "9: source second branch" files: a
  | |
  o |  8 669cf0e74b50 (draft) "8: source first branch" files: a
  | |
  | o  7 e6d364a69ff1 (draft) "change in dest" files: dest
  |/
  o  6 0613c8e59a3d (public) "6: change a" files: a
  |
  ~
  $ cd ..

  $ hg convert --filemap filemap source dest --config convert.hg.revs=3:
  scanning source...
  sorting...
  converting...
  3 8: source first branch
  2 9: source second branch
  1 10: source merge
  0 11: source change

  $ glog -R dest
  o  9 8432d597b263 (draft) "11: source change" files: a
  |
  o    8 632ffacdcd6f (draft) "10: source merge" files: a
  |\
  | o  7 049cfee90ee6 (draft) "9: source second branch" files: a
  | |
  o |  6 9b6845e036e5 (draft) "8: source first branch" files: a
  | |
  | @  5 a2e0e3cc6d1d (draft) "change in dest" files: dest
  |/
  o  4 78814e84a217 (draft) "6: change a" files: a
  |
  o    3 f7cff662c5e5 (draft) "5: merge 2 and 3, copy b to dir/d" files: e
  |\
  | o  2 ab40a95b0072 (draft) "4: change a" files: a
  | |
  o |  1 bd51f17597bf (draft) "3: copy a to e, change b" files: b e
  |/
  o  0 a4a1dae0fe35 (draft) "1: add a and dir/b" files: 0 a
  
  $ cd ..

Two way tests

  $ hg init 0
  $ echo f > 0/f
  $ echo a > 0/a-only
  $ echo b > 0/b-only
  $ hg -R 0 ci -Aqm0

  $ cat << EOF > filemap-a
  > exclude b-only
  > EOF
  $ cat << EOF > filemap-b
  > exclude a-only
  > EOF
  $ hg convert --filemap filemap-a 0 a
  initializing destination a repository
  scanning source...
  sorting...
  converting...
  0 0
  $ hg -R a up -q
  $ echo a > a/f
  $ hg -R a ci -ma

  $ hg convert --filemap filemap-b 0 b
  initializing destination b repository
  scanning source...
  sorting...
  converting...
  0 0
  $ hg -R b up -q
  $ echo b > b/f
  $ hg -R b ci -mb

  $ tail 0/.hg/shamap
  86f3f774ffb682bffb5dc3c1d3b3da637cb9a0d6 8a028c7c77f6c7bd6d63bc3f02ca9f779eabf16a
  dd9f218eb91fb857f2a62fe023e1d64a4e7812fe 8a028c7c77f6c7bd6d63bc3f02ca9f779eabf16a
  $ tail a/.hg/shamap
  8a028c7c77f6c7bd6d63bc3f02ca9f779eabf16a 86f3f774ffb682bffb5dc3c1d3b3da637cb9a0d6
  $ tail b/.hg/shamap
  8a028c7c77f6c7bd6d63bc3f02ca9f779eabf16a dd9f218eb91fb857f2a62fe023e1d64a4e7812fe

  $ hg convert a 0
  scanning source...
  sorting...
  converting...
  0 a

  $ hg convert b 0
  scanning source...
  sorting...
  converting...
  0 b

  $ hg -R 0 log -G
  o  changeset:   2:637fbbbe96b6
  |  tag:         tip
  |  parent:      0:8a028c7c77f6
  |  user:        test
  |  date:        Thu Jan 01 00:00:00 1970 +0000
  |  summary:     b
  |
  | o  changeset:   1:ec7b9c96e692
  |/   user:        test
  |    date:        Thu Jan 01 00:00:00 1970 +0000
  |    summary:     a
  |
  @  changeset:   0:8a028c7c77f6
     user:        test
     date:        Thu Jan 01 00:00:00 1970 +0000
     summary:     0
  
  $ hg convert --filemap filemap-b 0 a --config convert.hg.revs=1::
  scanning source...
  sorting...
  converting...

  $ hg -R 0 up -r1
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ echo f >> 0/f
  $ hg -R 0 ci -mx

  $ hg convert --filemap filemap-b 0 a --config convert.hg.revs=1::
  scanning source...
  sorting...
  converting...
  0 x

  $ hg -R a log -G -T '{rev} {desc|firstline} ({files})\n'
  o  2 x (f)
  |
  @  1 a (f)
  |
  o  0 0 (a-only f)
  
  $ hg -R a mani -r tip
  a-only
  f

An additional round, demonstrating that unchanged files don't get converted

  $ echo f >> 0/f
  $ echo f >> 0/a-only
  $ hg -R 0 ci -m "extra f+a-only change"

  $ hg convert --filemap filemap-b 0 a --config convert.hg.revs=1::
  scanning source...
  sorting...
  converting...
  0 extra f+a-only change

  $ hg -R a log -G -T '{rev} {desc|firstline} ({files})\n'
  o  3 extra f+a-only change (f)
  |
  o  2 x (f)
  |
  @  1 a (f)
  |
  o  0 0 (a-only f)
  

Conversion after rollback

  $ hg -R a rollback -f
  repository tip rolled back to revision 2 (undo convert)

  $ hg convert --filemap filemap-b 0 a --config convert.hg.revs=1::
  scanning source...
  sorting...
  converting...
  0 extra f+a-only change

  $ hg -R a log -G -T '{rev} {desc|firstline} ({files})\n'
  o  3 extra f+a-only change (f)
  |
  o  2 x (f)
  |
  @  1 a (f)
  |
  o  0 0 (a-only f)
  
Convert with --full adds and removes files that didn't change

  $ echo f >> 0/f
  $ hg -R 0 ci -m "f"
  $ hg convert --filemap filemap-b --full 0 a --config convert.hg.revs=1::
  scanning source...
  sorting...
  converting...
  0 f
  $ hg -R a status --change tip
  M f
  A b-only
  R a-only

Recorded {files} list does not get confused about flags on merge commits

#if execbit
  $ cd ..
  $ hg init merge-flags-orig
  $ cd merge-flags-orig
  $ echo 0 > 0
  $ hg ci -Aqm 'add 0'
  $ echo a > a
  $ chmod +x a
  $ hg ci -qAm 'add executable file'
  $ hg co -q 0
  $ echo b > b
  $ hg ci -qAm 'add file'
  $ hg merge -q
  $ hg ci -m 'merge'
  $ hg log -G -T '{rev} {desc}\n'
  @    3 merge
  |\
  | o  2 add file
  | |
  o |  1 add executable file
  |/
  o  0 add 0
  

# No files changed
  $ hg log -r 3 -T '{files}\n'
  

  $ cd ..
  $ hg convert merge-flags-orig merge-flags-new -q
  $ cd merge-flags-new
  $ hg log -G -T '{rev} {desc}\n'
  o    3 merge
  |\
  | o  2 add file
  | |
  o |  1 add executable file
  |/
  o  0 add 0
  

# Still no files
  $ hg log -r 3 -T '{files}\n'
  

#endif