tests/test-strip.t
changeset 35830 e689d8b22728
parent 35709 1a09dad8b85a
child 35846 c4c1e3334bcb
equal deleted inserted replaced
35829:c87926ebe096 35830:e689d8b22728
   891   > from mercurial import extensions, localrepo
   891   > from mercurial import extensions, localrepo
   892   > def transactioncallback(orig, repo, desc, *args, **kwargs):
   892   > def transactioncallback(orig, repo, desc, *args, **kwargs):
   893   >     def test(transaction):
   893   >     def test(transaction):
   894   >         # observe cache inconsistency
   894   >         # observe cache inconsistency
   895   >         try:
   895   >         try:
   896   >             [repo.changelog.node(r) for r in repo.revs("not public()")]
   896   >             [repo.changelog.node(r) for r in repo.revs(b"not public()")]
   897   >         except IndexError:
   897   >         except IndexError:
   898   >             repo.ui.status("Index error!\n")
   898   >             repo.ui.status(b"Index error!\n")
   899   >     transaction = orig(repo, desc, *args, **kwargs)
   899   >     transaction = orig(repo, desc, *args, **kwargs)
   900   >     # warm up the phase cache
   900   >     # warm up the phase cache
   901   >     list(repo.revs("not public()"))
   901   >     list(repo.revs(b"not public()"))
   902   >     if desc != 'strip':
   902   >     if desc != 'strip':
   903   >          transaction.addpostclose("phase invalidation test", test)
   903   >          transaction.addpostclose(b"phase invalidation test", test)
   904   >     return transaction
   904   >     return transaction
   905   > def extsetup(ui):
   905   > def extsetup(ui):
   906   >     extensions.wrapfunction(localrepo.localrepository, "transaction",
   906   >     extensions.wrapfunction(localrepo.localrepository, b"transaction",
   907   >                             transactioncallback)
   907   >                             transactioncallback)
   908   > EOF
   908   > EOF
   909   $ hg up -C 2
   909   $ hg up -C 2
   910   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   910   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   911   $ echo k > k
   911   $ echo k > k
   928   > from mercurial import error
   928   > from mercurial import error
   929   > def reposetup(ui, repo):
   929   > def reposetup(ui, repo):
   930   >     class crashstriprepo(repo.__class__):
   930   >     class crashstriprepo(repo.__class__):
   931   >         def transaction(self, desc, *args, **kwargs):
   931   >         def transaction(self, desc, *args, **kwargs):
   932   >             tr = super(crashstriprepo, self).transaction(desc, *args, **kwargs)
   932   >             tr = super(crashstriprepo, self).transaction(desc, *args, **kwargs)
   933   >             if desc == 'strip':
   933   >             if desc == b'strip':
   934   >                 def crash(tra): raise error.Abort('boom')
   934   >                 def crash(tra): raise error.Abort(b'boom')
   935   >                 tr.addpostclose('crash', crash)
   935   >                 tr.addpostclose(b'crash', crash)
   936   >             return tr
   936   >             return tr
   937   >     repo.__class__ = crashstriprepo
   937   >     repo.__class__ = crashstriprepo
   938   > EOF
   938   > EOF
   939   $ hg strip tip --config extensions.crash=$TESTTMP/crashstrip.py
   939   $ hg strip tip --config extensions.crash=$TESTTMP/crashstrip.py
   940   saved backup bundle to $TESTTMP/issue4736/.hg/strip-backup/5c51d8d6557d-70daef06-backup.hg
   940   saved backup bundle to $TESTTMP/issue4736/.hg/strip-backup/5c51d8d6557d-70daef06-backup.hg
  1173   $ cat > $TESTTMP/delayedstrip.py <<EOF
  1173   $ cat > $TESTTMP/delayedstrip.py <<EOF
  1174   > from __future__ import absolute_import
  1174   > from __future__ import absolute_import
  1175   > from mercurial import commands, registrar, repair
  1175   > from mercurial import commands, registrar, repair
  1176   > cmdtable = {}
  1176   > cmdtable = {}
  1177   > command = registrar.command(cmdtable)
  1177   > command = registrar.command(cmdtable)
  1178   > @command('testdelayedstrip')
  1178   > @command(b'testdelayedstrip')
  1179   > def testdelayedstrip(ui, repo):
  1179   > def testdelayedstrip(ui, repo):
  1180   >     def getnodes(expr):
  1180   >     def getnodes(expr):
  1181   >         return [repo.changelog.node(r) for r in repo.revs(expr)]
  1181   >         return [repo.changelog.node(r) for r in repo.revs(expr)]
  1182   >     with repo.wlock():
  1182   >     with repo.wlock():
  1183   >         with repo.lock():
  1183   >         with repo.lock():
  1184   >             with repo.transaction('delayedstrip'):
  1184   >             with repo.transaction(b'delayedstrip'):
  1185   >                 repair.delayedstrip(ui, repo, getnodes('B+I+Z+D+E'), 'J')
  1185   >                 repair.delayedstrip(ui, repo, getnodes(b'B+I+Z+D+E'), b'J')
  1186   >                 repair.delayedstrip(ui, repo, getnodes('G+H+Z'), 'I')
  1186   >                 repair.delayedstrip(ui, repo, getnodes(b'G+H+Z'), b'I')
  1187   >                 commands.commit(ui, repo, message='J', date='0 0')
  1187   >                 commands.commit(ui, repo, message=b'J', date=b'0 0')
  1188   > EOF
  1188   > EOF
  1189   $ hg testdelayedstrip --config extensions.t=$TESTTMP/delayedstrip.py
  1189   $ hg testdelayedstrip --config extensions.t=$TESTTMP/delayedstrip.py
  1190   warning: orphaned descendants detected, not stripping 08ebfeb61bac, 112478962961, 7fb047a69f22
  1190   warning: orphaned descendants detected, not stripping 08ebfeb61bac, 112478962961, 7fb047a69f22
  1191   saved backup bundle to $TESTTMP/delayedstrip/.hg/strip-backup/f585351a92f8-17475721-I.hg
  1191   saved backup bundle to $TESTTMP/delayedstrip/.hg/strip-backup/f585351a92f8-17475721-I.hg
  1192 
  1192 
  1223 
  1223 
  1224   $ cat > $TESTTMP/scmutilcleanup.py <<EOF
  1224   $ cat > $TESTTMP/scmutilcleanup.py <<EOF
  1225   > from mercurial import registrar, scmutil
  1225   > from mercurial import registrar, scmutil
  1226   > cmdtable = {}
  1226   > cmdtable = {}
  1227   > command = registrar.command(cmdtable)
  1227   > command = registrar.command(cmdtable)
  1228   > @command('testnodescleanup')
  1228   > @command(b'testnodescleanup')
  1229   > def testnodescleanup(ui, repo):
  1229   > def testnodescleanup(ui, repo):
  1230   >     def nodes(expr):
  1230   >     def nodes(expr):
  1231   >         return [repo.changelog.node(r) for r in repo.revs(expr)]
  1231   >         return [repo.changelog.node(r) for r in repo.revs(expr)]
  1232   >     def node(expr):
  1232   >     def node(expr):
  1233   >         return nodes(expr)[0]
  1233   >         return nodes(expr)[0]
  1234   >     with repo.wlock():
  1234   >     with repo.wlock():
  1235   >         with repo.lock():
  1235   >         with repo.lock():
  1236   >             with repo.transaction('delayedstrip'):
  1236   >             with repo.transaction(b'delayedstrip'):
  1237   >                 mapping = {node('F'): [node('F2')],
  1237   >                 mapping = {node(b'F'): [node(b'F2')],
  1238   >                            node('D'): [node('D2')],
  1238   >                            node(b'D'): [node(b'D2')],
  1239   >                            node('G'): [node('G2')]}
  1239   >                            node(b'G'): [node(b'G2')]}
  1240   >                 scmutil.cleanupnodes(repo, mapping, 'replace')
  1240   >                 scmutil.cleanupnodes(repo, mapping, b'replace')
  1241   >                 scmutil.cleanupnodes(repo, nodes('((B::)+I+Z)-D2'), 'replace')
  1241   >                 scmutil.cleanupnodes(repo, nodes(b'((B::)+I+Z)-D2'),
       
  1242   >                                      b'replace')
  1242   > EOF
  1243   > EOF
  1243   $ hg testnodescleanup --config extensions.t=$TESTTMP/scmutilcleanup.py
  1244   $ hg testnodescleanup --config extensions.t=$TESTTMP/scmutilcleanup.py
  1244   warning: orphaned descendants detected, not stripping 112478962961, 1fc8102cda62, 26805aba1e60
  1245   warning: orphaned descendants detected, not stripping 112478962961, 1fc8102cda62, 26805aba1e60
  1245   saved backup bundle to $TESTTMP/scmutilcleanup/.hg/strip-backup/f585351a92f8-73fb7c03-replace.hg
  1246   saved backup bundle to $TESTTMP/scmutilcleanup/.hg/strip-backup/f585351a92f8-73fb7c03-replace.hg
  1246 
  1247