comparison tests/test-strip.t @ 33087:fcd1c483f5ea

strip: add a delayedstrip method that works in a transaction For long, the fact that strip does not work inside a transaction and some code has to work with both obsstore and fallback to strip lead to duplicated code like: with repo.transaction(): .... if obsstore: obsstore.createmarkers(...) if not obsstore: repair.strip(...) Things get more complex when you want to call something which may call strip under the hood. Like you cannot simply write: with repo.transaction(): .... rebasemod.rebase(...) # may call "strip", so this doesn't work But you do want rebase to run inside a same transaction if possible, so the code may look like: with repo.transaction(): .... if obsstore: rebasemod.rebase(...) obsstore.createmarkers(...) if not obsstore: rebasemod.rebase(...) repair.strip(...) That's ugly and error-prone. Ideally it's possible to just write: with repo.transaction(): rebasemod.rebase(...) saferemovenodes(...) This patch is the first step towards that. It adds a "delayedstrip" method to repair.py which maintains a postclose callback in the transaction object.
author Jun Wu <quark@fb.com>
date Sun, 25 Jun 2017 10:38:45 -0700
parents 8e3021fd1a44
children 65cadeea6c22
comparison
equal deleted inserted replaced
33086:eb4c49f55f1f 33087:fcd1c483f5ea
1 $ echo "[format]" >> $HGRCPATH 1 $ echo "[format]" >> $HGRCPATH
2 $ echo "usegeneraldelta=yes" >> $HGRCPATH 2 $ echo "usegeneraldelta=yes" >> $HGRCPATH
3 $ echo "[extensions]" >> $HGRCPATH 3 $ echo "[extensions]" >> $HGRCPATH
4 $ echo "strip=" >> $HGRCPATH 4 $ echo "strip=" >> $HGRCPATH
5 $ echo "drawdag=$TESTDIR/drawdag.py" >> $HGRCPATH
5 6
6 $ restore() { 7 $ restore() {
7 > hg unbundle -q .hg/strip-backup/* 8 > hg unbundle -q .hg/strip-backup/*
8 > rm .hg/strip-backup/* 9 > rm .hg/strip-backup/*
9 > } 10 > }
938 saved backup bundle to $TESTTMP/issue4736/.hg/strip-backup/5c51d8d6557d-70daef06-backup.hg (glob) 939 saved backup bundle to $TESTTMP/issue4736/.hg/strip-backup/5c51d8d6557d-70daef06-backup.hg (glob)
939 strip failed, backup bundle stored in '$TESTTMP/issue4736/.hg/strip-backup/5c51d8d6557d-70daef06-backup.hg' (glob) 940 strip failed, backup bundle stored in '$TESTTMP/issue4736/.hg/strip-backup/5c51d8d6557d-70daef06-backup.hg' (glob)
940 abort: boom 941 abort: boom
941 [255] 942 [255]
942 943
943 944 Use delayedstrip to strip inside a transaction
945
946 $ cd $TESTTMP
947 $ hg init delayedstrip
948 $ cd delayedstrip
949 $ hg debugdrawdag <<'EOS'
950 > D
951 > |
952 > C F H # Commit on top of "I",
953 > | |/| # Strip B+D+I+E+G+H+Z
954 > I B E G
955 > \|/
956 > A Z
957 > EOS
958
959 $ hg up -C I
960 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
961 $ echo 3 >> I
962 $ cat > $TESTTMP/delayedstrip.py <<EOF
963 > from mercurial import repair, commands
964 > def reposetup(ui, repo):
965 > def getnodes(expr):
966 > return [repo.changelog.node(r) for r in repo.revs(expr)]
967 > with repo.wlock():
968 > with repo.lock():
969 > with repo.transaction('delayedstrip'):
970 > repair.delayedstrip(ui, repo, getnodes('B+I+Z+D+E'), 'J')
971 > repair.delayedstrip(ui, repo, getnodes('G+H+Z'), 'I')
972 > commands.commit(ui, repo, message='J', date='0 0')
973 > EOF
974 $ hg log -r . -T '\n' --config extensions.t=$TESTTMP/delayedstrip.py
975 warning: orphaned descendants detected, not stripping 08ebfeb61bac, 112478962961, 7fb047a69f22
976 saved backup bundle to $TESTTMP/delayedstrip/.hg/strip-backup/f585351a92f8-81fa23b0-I.hg (glob)
977
978 $ hg log -G -T '{rev}:{node|short} {desc}' -r 'sort(all(), topo)'
979 @ 6:2f2d51af6205 J
980 |
981 o 3:08ebfeb61bac I
982 |
983 | o 5:64a8289d2492 F
984 | |
985 | o 2:7fb047a69f22 E
986 |/
987 | o 4:26805aba1e60 C
988 | |
989 | o 1:112478962961 B
990 |/
991 o 0:426bada5c675 A
992