comparison tests/test-parseindex.t @ 26053:b68c9d232db6

reachableroots: use internal "revstates" array to test if rev is a root The main goal of this patch series is to reduce the use of PyXxx() function that is likely to require ugly error handling and inc/decref. Plus, this is faster than using PySet_Contains(). revset #0: 0::tip 0) 0.004168 1) 0.003678 88% This patch ignores out-of-range roots as they are in the pure implementation. Because reachable sets are calculated from heads, and out-of-range heads raise IndexError, we can just take out-of-range roots as unreachable. Otherwise, the test of "hg log -Gr '. + wdir()'" would fail. "heads" argument is changed to a list. Should we have to rename the C function as its signature is changed?
author Yuya Nishihara <yuya@tcha.org>
date Fri, 14 Aug 2015 15:43:29 +0900
parents c6115c30a376
children be8a4e0800d8
comparison
equal deleted inserted replaced
26052:b970418bbafe 26053:b68c9d232db6
67 $ cd a 67 $ cd a
68 68
69 $ python <<EOF 69 $ python <<EOF
70 > from mercurial import changelog, scmutil 70 > from mercurial import changelog, scmutil
71 > cl = changelog.changelog(scmutil.vfs('.hg/store')) 71 > cl = changelog.changelog(scmutil.vfs('.hg/store'))
72 > print 'goods:' 72 > print 'good heads:'
73 > for head in [0, len(cl) - 1, -1]: 73 > for head in [0, len(cl) - 1, -1]:
74 > print'%s: %r' % (head, cl.reachableroots(0, [head], set([0]))) 74 > print'%s: %r' % (head, cl.reachableroots(0, [head], [0]))
75 > print 'bads:' 75 > print 'bad heads:'
76 > for head in [len(cl), 10000, -2, -10000, None]: 76 > for head in [len(cl), 10000, -2, -10000, None]:
77 > print '%s:' % head, 77 > print '%s:' % head,
78 > try: 78 > try:
79 > cl.reachableroots(0, [head], set([0])) 79 > cl.reachableroots(0, [head], [0])
80 > print 'uncaught buffer overflow?' 80 > print 'uncaught buffer overflow?'
81 > except (IndexError, TypeError) as inst: 81 > except (IndexError, TypeError) as inst:
82 > print inst 82 > print inst
83 > print 'good roots:'
84 > for root in [0, len(cl) - 1, -1]:
85 > print '%s: %r' % (root, cl.reachableroots(root, [len(cl) - 1], [root]))
86 > print 'out-of-range roots are ignored:'
87 > for root in [len(cl), 10000, -2, -10000]:
88 > print '%s: %r' % (root, cl.reachableroots(root, [len(cl) - 1], [root]))
89 > print 'bad roots:'
90 > for root in [None]:
91 > print '%s:' % root,
92 > try:
93 > cl.reachableroots(root, [len(cl) - 1], [root])
94 > print 'uncaught error?'
95 > except TypeError as inst:
96 > print inst
83 > EOF 97 > EOF
84 goods: 98 good heads:
85 0: <baseset [0]> 99 0: <baseset [0]>
86 1: <baseset [0]> 100 1: <baseset [0]>
87 -1: <baseset []> 101 -1: <baseset []>
88 bads: 102 bad heads:
89 2: head out of range 103 2: head out of range
90 10000: head out of range 104 10000: head out of range
91 -2: head out of range 105 -2: head out of range
92 -10000: head out of range 106 -10000: head out of range
107 None: an integer is required
108 good roots:
109 0: <baseset [0]>
110 1: <baseset [1]>
111 -1: <baseset [-1]>
112 out-of-range roots are ignored:
113 2: <baseset []>
114 10000: <baseset []>
115 -2: <baseset []>
116 -10000: <baseset []>
117 bad roots:
93 None: an integer is required 118 None: an integer is required
94 119
95 $ cd .. 120 $ cd ..
96 121
97 Test corrupted p1/p2 fields that could cause SEGV at parsers.c: 122 Test corrupted p1/p2 fields that could cause SEGV at parsers.c:
125 > from mercurial import changelog, scmutil 150 > from mercurial import changelog, scmutil
126 > cl = changelog.changelog(scmutil.vfs(sys.argv[1])) 151 > cl = changelog.changelog(scmutil.vfs(sys.argv[1]))
127 > n0, n1 = cl.node(0), cl.node(1) 152 > n0, n1 = cl.node(0), cl.node(1)
128 > ops = [ 153 > ops = [
129 > ('reachableroots', 154 > ('reachableroots',
130 > lambda: cl.index.reachableroots(0, [1], set([0]), False)), 155 > lambda: cl.index.reachableroots2(0, [1], [0], False)),
131 > ('compute_phases_map_sets', lambda: cl.computephases([[0], []])), 156 > ('compute_phases_map_sets', lambda: cl.computephases([[0], []])),
132 > ('index_headrevs', lambda: cl.headrevs()), 157 > ('index_headrevs', lambda: cl.headrevs()),
133 > ('find_gca_candidates', lambda: cl.commonancestorsheads(n0, n1)), 158 > ('find_gca_candidates', lambda: cl.commonancestorsheads(n0, n1)),
134 > ('find_deepest', lambda: cl.ancestor(n0, n1)), 159 > ('find_deepest', lambda: cl.ancestor(n0, n1)),
135 > ] 160 > ]