##// END OF EJS Templates
bruterebase: port to python 3
Augie Fackler -
r34201:bab82c43 default
parent child Browse files
Show More
@@ -1,69 +1,74 b''
1 # bruterebase.py - brute force rebase testing
1 # bruterebase.py - brute force rebase testing
2 #
2 #
3 # Copyright 2017 Facebook, Inc.
3 # Copyright 2017 Facebook, Inc.
4 #
4 #
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7
7
8 from __future__ import absolute_import
8 from __future__ import absolute_import
9
9
10 from mercurial import (
10 from mercurial import (
11 error,
11 error,
12 registrar,
12 registrar,
13 revsetlang,
13 revsetlang,
14 )
14 )
15
15
16 from hgext import rebase
16 from hgext import rebase
17
17
18 try:
19 xrange
20 except NameError:
21 xrange = range
22
18 cmdtable = {}
23 cmdtable = {}
19 command = registrar.command(cmdtable)
24 command = registrar.command(cmdtable)
20
25
21 @command('debugbruterebase')
26 @command(b'debugbruterebase')
22 def debugbruterebase(ui, repo, source, dest):
27 def debugbruterebase(ui, repo, source, dest):
23 """for every non-empty subset of source, run rebase -r subset -d dest
28 """for every non-empty subset of source, run rebase -r subset -d dest
24
29
25 Print one line summary for each subset. Assume obsstore is enabled.
30 Print one line summary for each subset. Assume obsstore is enabled.
26 """
31 """
27 srevs = list(repo.revs(source))
32 srevs = list(repo.revs(source))
28
33
29 with repo.wlock(), repo.lock():
34 with repo.wlock(), repo.lock():
30 repolen = len(repo)
35 repolen = len(repo)
31 cl = repo.changelog
36 cl = repo.changelog
32
37
33 def getdesc(rev):
38 def getdesc(rev):
34 result = cl.changelogrevision(rev).description
39 result = cl.changelogrevision(rev).description
35 if rev >= repolen:
40 if rev >= repolen:
36 result += "'"
41 result += b"'"
37 return result
42 return result
38
43
39 for i in xrange(1, 2 ** len(srevs)):
44 for i in xrange(1, 2 ** len(srevs)):
40 subset = [rev for j, rev in enumerate(srevs) if i & (1 << j) != 0]
45 subset = [rev for j, rev in enumerate(srevs) if i & (1 << j) != 0]
41 spec = revsetlang.formatspec('%ld', subset)
46 spec = revsetlang.formatspec(b'%ld', subset)
42 tr = repo.transaction('rebase')
47 tr = repo.transaction(b'rebase')
43 tr.report = lambda x: 0 # hide "transaction abort"
48 tr.report = lambda x: 0 # hide "transaction abort"
44
49
45 ui.pushbuffer()
50 ui.pushbuffer()
46 try:
51 try:
47 rebase.rebase(ui, repo, dest=dest, rev=[spec])
52 rebase.rebase(ui, repo, dest=dest, rev=[spec])
48 except error.Abort as ex:
53 except error.Abort as ex:
49 summary = 'ABORT: %s' % ex
54 summary = b'ABORT: %s' % ex
50 except Exception as ex:
55 except Exception as ex:
51 summary = 'CRASH: %s' % ex
56 summary = b'CRASH: %s' % ex
52 else:
57 else:
53 # short summary about new nodes
58 # short summary about new nodes
54 cl = repo.changelog
59 cl = repo.changelog
55 descs = []
60 descs = []
56 for rev in xrange(repolen, len(repo)):
61 for rev in xrange(repolen, len(repo)):
57 desc = '%s:' % getdesc(rev)
62 desc = b'%s:' % getdesc(rev)
58 for prev in cl.parentrevs(rev):
63 for prev in cl.parentrevs(rev):
59 if prev > -1:
64 if prev > -1:
60 desc += getdesc(prev)
65 desc += getdesc(prev)
61 descs.append(desc)
66 descs.append(desc)
62 descs.sort()
67 descs.sort()
63 summary = ' '.join(descs)
68 summary = ' '.join(descs)
64 ui.popbuffer()
69 ui.popbuffer()
65 repo.vfs.tryunlink('rebasestate')
70 repo.vfs.tryunlink(b'rebasestate')
66
71
67 subsetdesc = ''.join(getdesc(rev) for rev in subset)
72 subsetdesc = b''.join(getdesc(rev) for rev in subset)
68 ui.write(('%s: %s\n') % (subsetdesc.rjust(len(srevs)), summary))
73 ui.write((b'%s: %s\n') % (subsetdesc.rjust(len(srevs)), summary))
69 tr.abort()
74 tr.abort()
General Comments 0
You need to be logged in to leave comments. Login now