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