Show More
@@ -1,136 +1,140 b'' | |||||
1 | from mercurial import ancestor, commands, hg, ui, util |
|
1 | from mercurial import ancestor, commands, hg, ui, util | |
2 |
|
2 | |||
3 | # graph is a dict of child->parent adjacency lists for this graph: |
|
3 | # graph is a dict of child->parent adjacency lists for this graph: | |
4 | # o 13 |
|
4 | # o 13 | |
5 | # | |
|
5 | # | | |
6 | # | o 12 |
|
6 | # | o 12 | |
7 | # | | |
|
7 | # | | | |
8 | # | | o 11 |
|
8 | # | | o 11 | |
9 | # | | |\ |
|
9 | # | | |\ | |
10 | # | | | | o 10 |
|
10 | # | | | | o 10 | |
11 | # | | | | | |
|
11 | # | | | | | | |
12 | # | o---+ | 9 |
|
12 | # | o---+ | 9 | |
13 | # | | | | | |
|
13 | # | | | | | | |
14 | # o | | | | 8 |
|
14 | # o | | | | 8 | |
15 | # / / / / |
|
15 | # / / / / | |
16 | # | | o | 7 |
|
16 | # | | o | 7 | |
17 | # | | | | |
|
17 | # | | | | | |
18 | # o---+ | 6 |
|
18 | # o---+ | 6 | |
19 | # / / / |
|
19 | # / / / | |
20 | # | | o 5 |
|
20 | # | | o 5 | |
21 | # | |/ |
|
21 | # | |/ | |
22 | # | o 4 |
|
22 | # | o 4 | |
23 | # | | |
|
23 | # | | | |
24 | # o | 3 |
|
24 | # o | 3 | |
25 | # | | |
|
25 | # | | | |
26 | # | o 2 |
|
26 | # | o 2 | |
27 | # |/ |
|
27 | # |/ | |
28 | # o 1 |
|
28 | # o 1 | |
29 | # | |
|
29 | # | | |
30 | # o 0 |
|
30 | # o 0 | |
31 |
|
31 | |||
32 | graph = {0: [-1], 1: [0], 2: [1], 3: [1], 4: [2], 5: [4], 6: [4], |
|
32 | graph = {0: [-1], 1: [0], 2: [1], 3: [1], 4: [2], 5: [4], 6: [4], | |
33 | 7: [4], 8: [-1], 9: [6, 7], 10: [5], 11: [3, 7], 12: [9], |
|
33 | 7: [4], 8: [-1], 9: [6, 7], 10: [5], 11: [3, 7], 12: [9], | |
34 | 13: [8]} |
|
34 | 13: [8]} | |
35 | pfunc = graph.get |
|
35 | pfunc = graph.get | |
36 |
|
36 | |||
37 | class mockchangelog(object): |
|
37 | class mockchangelog(object): | |
38 | parentrevs = graph.get |
|
38 | parentrevs = graph.get | |
39 |
|
39 | |||
40 | def runmissingancestors(revs, bases): |
|
40 | def runmissingancestors(revs, bases): | |
41 | print "%% ancestors of %s and not of %s" % (revs, bases) |
|
41 | print "%% ancestors of %s and not of %s" % (revs, bases) | |
42 | print ancestor.missingancestors(revs, bases, pfunc) |
|
42 | print ancestor.missingancestors(revs, bases, pfunc) | |
43 |
|
43 | |||
44 | def test_missingancestors(): |
|
44 | def test_missingancestors(): | |
45 | # Empty revs |
|
45 | # Empty revs | |
46 | runmissingancestors([], [1]) |
|
46 | runmissingancestors([], [1]) | |
47 | runmissingancestors([], []) |
|
47 | runmissingancestors([], []) | |
48 |
|
48 | |||
49 | # If bases is empty, it's the same as if it were [nullrev] |
|
49 | # If bases is empty, it's the same as if it were [nullrev] | |
50 | runmissingancestors([12], []) |
|
50 | runmissingancestors([12], []) | |
51 |
|
51 | |||
52 | # Trivial case: revs == bases |
|
52 | # Trivial case: revs == bases | |
53 | runmissingancestors([0], [0]) |
|
53 | runmissingancestors([0], [0]) | |
54 | runmissingancestors([4, 5, 6], [6, 5, 4]) |
|
54 | runmissingancestors([4, 5, 6], [6, 5, 4]) | |
55 |
|
55 | |||
56 | # With nullrev |
|
56 | # With nullrev | |
57 | runmissingancestors([-1], [12]) |
|
57 | runmissingancestors([-1], [12]) | |
58 | runmissingancestors([12], [-1]) |
|
58 | runmissingancestors([12], [-1]) | |
59 |
|
59 | |||
60 | # 9 is a parent of 12. 7 is a parent of 9, so an ancestor of 12. 6 is an |
|
60 | # 9 is a parent of 12. 7 is a parent of 9, so an ancestor of 12. 6 is an | |
61 | # ancestor of 12 but not of 7. |
|
61 | # ancestor of 12 but not of 7. | |
62 | runmissingancestors([12], [9]) |
|
62 | runmissingancestors([12], [9]) | |
63 | runmissingancestors([9], [12]) |
|
63 | runmissingancestors([9], [12]) | |
64 | runmissingancestors([12, 9], [7]) |
|
64 | runmissingancestors([12, 9], [7]) | |
65 | runmissingancestors([7, 6], [12]) |
|
65 | runmissingancestors([7, 6], [12]) | |
66 |
|
66 | |||
67 | # More complex cases |
|
67 | # More complex cases | |
68 | runmissingancestors([10], [11, 12]) |
|
68 | runmissingancestors([10], [11, 12]) | |
69 | runmissingancestors([11], [10]) |
|
69 | runmissingancestors([11], [10]) | |
70 | runmissingancestors([11], [10, 12]) |
|
70 | runmissingancestors([11], [10, 12]) | |
71 | runmissingancestors([12], [10]) |
|
71 | runmissingancestors([12], [10]) | |
72 | runmissingancestors([12], [11]) |
|
72 | runmissingancestors([12], [11]) | |
73 | runmissingancestors([10, 11, 12], [13]) |
|
73 | runmissingancestors([10, 11, 12], [13]) | |
74 | runmissingancestors([13], [10, 11, 12]) |
|
74 | runmissingancestors([13], [10, 11, 12]) | |
75 |
|
75 | |||
76 | def genlazyancestors(revs, stoprev=0, inclusive=False): |
|
76 | def genlazyancestors(revs, stoprev=0, inclusive=False): | |
77 | print ("%% lazy ancestor set for %s, stoprev = %s, inclusive = %s" % |
|
77 | print ("%% lazy ancestor set for %s, stoprev = %s, inclusive = %s" % | |
78 | (revs, stoprev, inclusive)) |
|
78 | (revs, stoprev, inclusive)) | |
79 | return ancestor.lazyancestors(mockchangelog, revs, stoprev=stoprev, |
|
79 | return ancestor.lazyancestors(mockchangelog, revs, stoprev=stoprev, | |
80 | inclusive=inclusive) |
|
80 | inclusive=inclusive) | |
81 |
|
81 | |||
82 | def printlazyancestors(s, l): |
|
82 | def printlazyancestors(s, l): | |
83 | print [n for n in l if n in s] |
|
83 | print [n for n in l if n in s] | |
84 |
|
84 | |||
85 | def test_lazyancestors(): |
|
85 | def test_lazyancestors(): | |
86 | # Empty revs |
|
86 | # Empty revs | |
87 | s = genlazyancestors([]) |
|
87 | s = genlazyancestors([]) | |
88 | printlazyancestors(s, [3, 0, -1]) |
|
88 | printlazyancestors(s, [3, 0, -1]) | |
89 |
|
89 | |||
90 | # Standard example |
|
90 | # Standard example | |
91 | s = genlazyancestors([11, 13]) |
|
91 | s = genlazyancestors([11, 13]) | |
92 | printlazyancestors(s, [11, 13, 7, 9, 8, 3, 6, 4, 1, -1, 0]) |
|
92 | printlazyancestors(s, [11, 13, 7, 9, 8, 3, 6, 4, 1, -1, 0]) | |
93 |
|
93 | |||
|
94 | # Standard with ancestry in the initial set (1 is ancestor of 3) | |||
|
95 | s = genlazyancestors([1, 3]) | |||
|
96 | printlazyancestors(s, [1, -1, 0]) | |||
|
97 | ||||
94 | # Including revs |
|
98 | # Including revs | |
95 | s = genlazyancestors([11, 13], inclusive=True) |
|
99 | s = genlazyancestors([11, 13], inclusive=True) | |
96 | printlazyancestors(s, [11, 13, 7, 9, 8, 3, 6, 4, 1, -1, 0]) |
|
100 | printlazyancestors(s, [11, 13, 7, 9, 8, 3, 6, 4, 1, -1, 0]) | |
97 |
|
101 | |||
98 | # Test with stoprev |
|
102 | # Test with stoprev | |
99 | s = genlazyancestors([11, 13], stoprev=6) |
|
103 | s = genlazyancestors([11, 13], stoprev=6) | |
100 | printlazyancestors(s, [11, 13, 7, 9, 8, 3, 6, 4, 1, -1, 0]) |
|
104 | printlazyancestors(s, [11, 13, 7, 9, 8, 3, 6, 4, 1, -1, 0]) | |
101 | s = genlazyancestors([11, 13], stoprev=6, inclusive=True) |
|
105 | s = genlazyancestors([11, 13], stoprev=6, inclusive=True) | |
102 | printlazyancestors(s, [11, 13, 7, 9, 8, 3, 6, 4, 1, -1, 0]) |
|
106 | printlazyancestors(s, [11, 13, 7, 9, 8, 3, 6, 4, 1, -1, 0]) | |
103 |
|
107 | |||
104 |
|
108 | |||
105 | # The C gca algorithm requires a real repo. These are textual descriptions of |
|
109 | # The C gca algorithm requires a real repo. These are textual descriptions of | |
106 | # DAGs that have been known to be problematic. |
|
110 | # DAGs that have been known to be problematic. | |
107 | dagtests = [ |
|
111 | dagtests = [ | |
108 | '+2*2*2/*3/2', |
|
112 | '+2*2*2/*3/2', | |
109 | '+3*3/*2*2/*4*4/*4/2*4/2*2', |
|
113 | '+3*3/*2*2/*4*4/*4/2*4/2*2', | |
110 | ] |
|
114 | ] | |
111 | def test_gca(): |
|
115 | def test_gca(): | |
112 | u = ui.ui() |
|
116 | u = ui.ui() | |
113 | for i, dag in enumerate(dagtests): |
|
117 | for i, dag in enumerate(dagtests): | |
114 | repo = hg.repository(u, 'gca%d' % i, create=1) |
|
118 | repo = hg.repository(u, 'gca%d' % i, create=1) | |
115 | cl = repo.changelog |
|
119 | cl = repo.changelog | |
116 | if not util.safehasattr(cl.index, 'ancestors'): |
|
120 | if not util.safehasattr(cl.index, 'ancestors'): | |
117 | # C version not available |
|
121 | # C version not available | |
118 | return |
|
122 | return | |
119 |
|
123 | |||
120 | commands.debugbuilddag(u, repo, dag) |
|
124 | commands.debugbuilddag(u, repo, dag) | |
121 | # Compare the results of the Python and C versions. This does not |
|
125 | # Compare the results of the Python and C versions. This does not | |
122 | # include choosing a winner when more than one gca exists -- we make |
|
126 | # include choosing a winner when more than one gca exists -- we make | |
123 | # sure both return exactly the same set of gcas. |
|
127 | # sure both return exactly the same set of gcas. | |
124 | for a in cl: |
|
128 | for a in cl: | |
125 | for b in cl: |
|
129 | for b in cl: | |
126 | cgcas = sorted(cl.index.ancestors(a, b)) |
|
130 | cgcas = sorted(cl.index.ancestors(a, b)) | |
127 | pygcas = sorted(ancestor.ancestors(cl.parentrevs, a, b)) |
|
131 | pygcas = sorted(ancestor.ancestors(cl.parentrevs, a, b)) | |
128 | if cgcas != pygcas: |
|
132 | if cgcas != pygcas: | |
129 | print "test_gca: for dag %s, gcas for %d, %d:" % (dag, a, b) |
|
133 | print "test_gca: for dag %s, gcas for %d, %d:" % (dag, a, b) | |
130 | print " C returned: %s" % cgcas |
|
134 | print " C returned: %s" % cgcas | |
131 | print " Python returned: %s" % pygcas |
|
135 | print " Python returned: %s" % pygcas | |
132 |
|
136 | |||
133 | if __name__ == '__main__': |
|
137 | if __name__ == '__main__': | |
134 | test_missingancestors() |
|
138 | test_missingancestors() | |
135 | test_lazyancestors() |
|
139 | test_lazyancestors() | |
136 | test_gca() |
|
140 | test_gca() |
@@ -1,46 +1,48 b'' | |||||
1 | % ancestors of [] and not of [1] |
|
1 | % ancestors of [] and not of [1] | |
2 | [] |
|
2 | [] | |
3 | % ancestors of [] and not of [] |
|
3 | % ancestors of [] and not of [] | |
4 | [] |
|
4 | [] | |
5 | % ancestors of [12] and not of [] |
|
5 | % ancestors of [12] and not of [] | |
6 | [0, 1, 2, 4, 6, 7, 9, 12] |
|
6 | [0, 1, 2, 4, 6, 7, 9, 12] | |
7 | % ancestors of [0] and not of [0] |
|
7 | % ancestors of [0] and not of [0] | |
8 | [] |
|
8 | [] | |
9 | % ancestors of [4, 5, 6] and not of [6, 5, 4] |
|
9 | % ancestors of [4, 5, 6] and not of [6, 5, 4] | |
10 | [] |
|
10 | [] | |
11 | % ancestors of [-1] and not of [12] |
|
11 | % ancestors of [-1] and not of [12] | |
12 | [] |
|
12 | [] | |
13 | % ancestors of [12] and not of [-1] |
|
13 | % ancestors of [12] and not of [-1] | |
14 | [0, 1, 2, 4, 6, 7, 9, 12] |
|
14 | [0, 1, 2, 4, 6, 7, 9, 12] | |
15 | % ancestors of [12] and not of [9] |
|
15 | % ancestors of [12] and not of [9] | |
16 | [12] |
|
16 | [12] | |
17 | % ancestors of [9] and not of [12] |
|
17 | % ancestors of [9] and not of [12] | |
18 | [] |
|
18 | [] | |
19 | % ancestors of [12, 9] and not of [7] |
|
19 | % ancestors of [12, 9] and not of [7] | |
20 | [6, 9, 12] |
|
20 | [6, 9, 12] | |
21 | % ancestors of [7, 6] and not of [12] |
|
21 | % ancestors of [7, 6] and not of [12] | |
22 | [] |
|
22 | [] | |
23 | % ancestors of [10] and not of [11, 12] |
|
23 | % ancestors of [10] and not of [11, 12] | |
24 | [5, 10] |
|
24 | [5, 10] | |
25 | % ancestors of [11] and not of [10] |
|
25 | % ancestors of [11] and not of [10] | |
26 | [3, 7, 11] |
|
26 | [3, 7, 11] | |
27 | % ancestors of [11] and not of [10, 12] |
|
27 | % ancestors of [11] and not of [10, 12] | |
28 | [3, 11] |
|
28 | [3, 11] | |
29 | % ancestors of [12] and not of [10] |
|
29 | % ancestors of [12] and not of [10] | |
30 | [6, 7, 9, 12] |
|
30 | [6, 7, 9, 12] | |
31 | % ancestors of [12] and not of [11] |
|
31 | % ancestors of [12] and not of [11] | |
32 | [6, 9, 12] |
|
32 | [6, 9, 12] | |
33 | % ancestors of [10, 11, 12] and not of [13] |
|
33 | % ancestors of [10, 11, 12] and not of [13] | |
34 | [0, 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12] |
|
34 | [0, 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12] | |
35 | % ancestors of [13] and not of [10, 11, 12] |
|
35 | % ancestors of [13] and not of [10, 11, 12] | |
36 | [8, 13] |
|
36 | [8, 13] | |
37 | % lazy ancestor set for [], stoprev = 0, inclusive = False |
|
37 | % lazy ancestor set for [], stoprev = 0, inclusive = False | |
38 | [] |
|
38 | [] | |
39 | % lazy ancestor set for [11, 13], stoprev = 0, inclusive = False |
|
39 | % lazy ancestor set for [11, 13], stoprev = 0, inclusive = False | |
40 | [7, 8, 3, 4, 1, 0] |
|
40 | [7, 8, 3, 4, 1, 0] | |
|
41 | % lazy ancestor set for [1, 3], stoprev = 0, inclusive = False | |||
|
42 | [1, 0] | |||
41 | % lazy ancestor set for [11, 13], stoprev = 0, inclusive = True |
|
43 | % lazy ancestor set for [11, 13], stoprev = 0, inclusive = True | |
42 | [11, 13, 7, 8, 3, 4, 1, 0] |
|
44 | [11, 13, 7, 8, 3, 4, 1, 0] | |
43 | % lazy ancestor set for [11, 13], stoprev = 6, inclusive = False |
|
45 | % lazy ancestor set for [11, 13], stoprev = 6, inclusive = False | |
44 | [7, 8] |
|
46 | [7, 8] | |
45 | % lazy ancestor set for [11, 13], stoprev = 6, inclusive = True |
|
47 | % lazy ancestor set for [11, 13], stoprev = 6, inclusive = True | |
46 | [11, 13, 7, 8] |
|
48 | [11, 13, 7, 8] |
General Comments 0
You need to be logged in to leave comments.
Login now