Mercurial > hg
comparison tests/test-strip.t @ 33088:65cadeea6c22
scmutil: add a cleanupnodes method for developers
It's now common that an old node gets replaced by zero or more new nodes,
that could happen with amend, rebase, histedit, etc. And it's a common
requirement to do bookmark movements, strip or obsolete nodes and even
moving working copy parent.
Previously, amend, rebase, history have their own logic doing the above.
This patch is an attempt to unify them and future code.
This enables new developers to be able to do "replace X with Y" thing
correctly, without any knowledge about bookmarks, strip or obsstore.
The next step will be migrating rebase to the new API, so it works inside a
transaction, and its code could be simplified.
author | Jun Wu <quark@fb.com> |
---|---|
date | Sun, 25 Jun 2017 13:31:56 -0700 |
parents | fcd1c483f5ea |
children | 4bae3c117b57 |
comparison
equal
deleted
inserted
replaced
33087:fcd1c483f5ea | 33088:65cadeea6c22 |
---|---|
953 > | |/| # Strip B+D+I+E+G+H+Z | 953 > | |/| # Strip B+D+I+E+G+H+Z |
954 > I B E G | 954 > I B E G |
955 > \|/ | 955 > \|/ |
956 > A Z | 956 > A Z |
957 > EOS | 957 > EOS |
958 $ cp -R . ../scmutilcleanup | |
958 | 959 |
959 $ hg up -C I | 960 $ hg up -C I |
960 2 files updated, 0 files merged, 0 files removed, 0 files unresolved | 961 2 files updated, 0 files merged, 0 files removed, 0 files unresolved |
961 $ echo 3 >> I | 962 $ echo 3 >> I |
962 $ cat > $TESTTMP/delayedstrip.py <<EOF | 963 $ cat > $TESTTMP/delayedstrip.py <<EOF |
988 | | | 989 | | |
989 | o 1:112478962961 B | 990 | o 1:112478962961 B |
990 |/ | 991 |/ |
991 o 0:426bada5c675 A | 992 o 0:426bada5c675 A |
992 | 993 |
994 Test high-level scmutil.cleanupnodes API | |
995 | |
996 $ cd $TESTTMP/scmutilcleanup | |
997 $ hg debugdrawdag <<'EOS' | |
998 > D2 F2 G2 # D2, F2, G2 are replacements for D, F, G | |
999 > | | | | |
1000 > C H G | |
1001 > EOS | |
1002 $ for i in B C D F G I Z; do | |
1003 > hg bookmark -i -r $i b-$i | |
1004 > done | |
1005 $ cp -R . ../scmutilcleanup.obsstore | |
1006 | |
1007 $ cat > $TESTTMP/scmutilcleanup.py <<EOF | |
1008 > from mercurial import scmutil | |
1009 > def reposetup(ui, repo): | |
1010 > def nodes(expr): | |
1011 > return [repo.changelog.node(r) for r in repo.revs(expr)] | |
1012 > def node(expr): | |
1013 > return nodes(expr)[0] | |
1014 > with repo.wlock(): | |
1015 > with repo.lock(): | |
1016 > with repo.transaction('delayedstrip'): | |
1017 > mapping = {node('F'): [node('F2')], | |
1018 > node('D'): [node('D2')], | |
1019 > node('G'): [node('G2')]} | |
1020 > scmutil.cleanupnodes(repo, mapping, 'replace') | |
1021 > scmutil.cleanupnodes(repo, nodes('((B::)+I+Z)-D2'), 'replace') | |
1022 > EOF | |
1023 $ hg log -r . -T '\n' --config extensions.t=$TESTTMP/scmutilcleanup.py | |
1024 warning: orphaned descendants detected, not stripping 112478962961, 1fc8102cda62, 26805aba1e60 | |
1025 saved backup bundle to $TESTTMP/scmutilcleanup/.hg/strip-backup/f585351a92f8-73fb7c03-replace.hg (glob) | |
1026 | |
1027 $ hg log -G -T '{rev}:{node|short} {desc} {bookmarks}' -r 'sort(all(), topo)' | |
1028 o 8:1473d4b996d1 G2 b-G | |
1029 | | |
1030 | o 7:d94e89b773b6 F2 b-F | |
1031 | | | |
1032 | o 5:7fe5bac4c918 H | |
1033 |/| | |
1034 | o 3:7fb047a69f22 E | |
1035 | | | |
1036 | | o 6:7c78f703e465 D2 b-D | |
1037 | | | | |
1038 | | o 4:26805aba1e60 C | |
1039 | | | | |
1040 | | o 2:112478962961 B | |
1041 | |/ | |
1042 o | 1:1fc8102cda62 G | |
1043 / | |
1044 o 0:426bada5c675 A b-B b-C b-I | |
1045 | |
1046 $ hg bookmark | |
1047 b-B 0:426bada5c675 | |
1048 b-C 0:426bada5c675 | |
1049 b-D 6:7c78f703e465 | |
1050 b-F 7:d94e89b773b6 | |
1051 b-G 8:1473d4b996d1 | |
1052 b-I 0:426bada5c675 | |
1053 b-Z -1:000000000000 | |
1054 | |
1055 Test the above using obsstore "by the way". Not directly related to strip, but | |
1056 we have reusable code here | |
1057 | |
1058 $ cd $TESTTMP/scmutilcleanup.obsstore | |
1059 $ cat >> .hg/hgrc <<EOF | |
1060 > [experimental] | |
1061 > evolution=all | |
1062 > evolution.track-operation=1 | |
1063 > EOF | |
1064 | |
1065 $ hg log -r . -T '\n' --config extensions.t=$TESTTMP/scmutilcleanup.py | |
1066 | |
1067 $ rm .hg/localtags | |
1068 $ hg log -G -T '{rev}:{node|short} {desc} {bookmarks}' -r 'sort(all(), topo)' | |
1069 o 12:1473d4b996d1 G2 b-G | |
1070 | | |
1071 | o 11:d94e89b773b6 F2 b-F | |
1072 | | | |
1073 | o 8:7fe5bac4c918 H | |
1074 |/| | |
1075 | o 4:7fb047a69f22 E | |
1076 | | | |
1077 | | o 10:7c78f703e465 D2 b-D | |
1078 | | | | |
1079 | | x 6:26805aba1e60 C | |
1080 | | | | |
1081 | | x 3:112478962961 B | |
1082 | |/ | |
1083 x | 1:1fc8102cda62 G | |
1084 / | |
1085 o 0:426bada5c675 A b-B b-C b-I | |
1086 | |
1087 $ hg debugobsolete | |
1088 1fc8102cda6204549f031015641606ccf5513ec3 1473d4b996d1d1b121de6b39fab6a04fbf9d873e 0 (Thu Jan 01 00:00:00 1970 +0000) {'operation': 'replace', 'user': 'test'} | |
1089 64a8289d249234b9886244d379f15e6b650b28e3 d94e89b773b67e72642a931159ada8d1a9246998 0 (Thu Jan 01 00:00:00 1970 +0000) {'operation': 'replace', 'user': 'test'} | |
1090 f585351a92f85104bff7c284233c338b10eb1df7 7c78f703e465d73102cc8780667ce269c5208a40 0 (Thu Jan 01 00:00:00 1970 +0000) {'operation': 'replace', 'user': 'test'} | |
1091 48b9aae0607f43ff110d84e6883c151942add5ab 0 {0000000000000000000000000000000000000000} (Thu Jan 01 00:00:00 1970 +0000) {'operation': 'replace', 'user': 'test'} | |
1092 112478962961147124edd43549aedd1a335e44bf 0 {426bada5c67598ca65036d57d9e4b64b0c1ce7a0} (Thu Jan 01 00:00:00 1970 +0000) {'operation': 'replace', 'user': 'test'} | |
1093 08ebfeb61bac6e3f12079de774d285a0d6689eba 0 {426bada5c67598ca65036d57d9e4b64b0c1ce7a0} (Thu Jan 01 00:00:00 1970 +0000) {'operation': 'replace', 'user': 'test'} | |
1094 26805aba1e600a82e93661149f2313866a221a7b 0 {112478962961147124edd43549aedd1a335e44bf} (Thu Jan 01 00:00:00 1970 +0000) {'operation': 'replace', 'user': 'test'} |