85
79
tree.commit(descendant, rev_id=descendant)
86
80
pending.append(descendant)
89
83
"""Test finding distinct common ancestor.
91
85
ancestry_1 should always have a single common ancestor
93
87
graph_walker = self.make_walker(ancestry_1)
94
88
self.assertEqual(set([NULL_REVISION]),
95
graph_walker.distinct_common(NULL_REVISION,
89
graph_walker.find_lca(NULL_REVISION,
97
91
self.assertEqual(set([NULL_REVISION]),
98
graph_walker.distinct_common(NULL_REVISION,
92
graph_walker.find_lca(NULL_REVISION,
100
94
self.assertEqual(set(['rev1']),
101
graph_walker.distinct_common('rev1', 'rev1'))
95
graph_walker.find_lca('rev1', 'rev1'))
102
96
self.assertEqual(set(['rev1']),
103
graph_walker.distinct_common('rev2a', 'rev2b'))
97
graph_walker.find_lca('rev2a', 'rev2b'))
105
def test_dca_criss_cross(self):
99
def test_lca_criss_cross(self):
106
100
graph_walker = self.make_walker(criss_cross)
107
101
self.assertEqual(set(['rev2a', 'rev2b']),
108
graph_walker.distinct_common('rev3a', 'rev3b'))
102
graph_walker.find_lca('rev3a', 'rev3b'))
109
103
self.assertEqual(set(['rev2b']),
110
graph_walker.distinct_common('rev3a', 'rev3b',
104
graph_walker.find_lca('rev3a', 'rev3b',
113
def test_dca_shortcut(self):
107
def test_lca_shortcut(self):
114
108
graph_walker = self.make_walker(history_shortcut)
115
109
self.assertEqual(set(['rev2b']),
116
graph_walker.distinct_common('rev3a', 'rev3b'))
110
graph_walker.find_lca('rev3a', 'rev3b'))
118
def test_recursive_unique_dca(self):
112
def test_recursive_unique_lca(self):
119
113
"""Test finding a unique distinct common ancestor.
121
115
ancestry_1 should always have a single common ancestor
123
117
graph_walker = self.make_walker(ancestry_1)
124
118
self.assertEqual(NULL_REVISION,
125
graph_walker.unique_common(NULL_REVISION,
119
graph_walker.find_unique_lca(NULL_REVISION,
127
121
self.assertEqual(NULL_REVISION,
128
graph_walker.unique_common(NULL_REVISION,
130
self.assertEqual('rev1', graph_walker.unique_common('rev1', 'rev1'))
131
self.assertEqual('rev1', graph_walker.unique_common('rev2a', 'rev2b'))
122
graph_walker.find_unique_lca(NULL_REVISION,
124
self.assertEqual('rev1', graph_walker.find_unique_lca('rev1',
126
self.assertEqual('rev1', graph_walker.find_unique_lca('rev2a',
133
def test_dca_criss_cross(self):
129
def test_lca_criss_cross(self):
134
130
graph_walker = self.make_walker(criss_cross)
135
131
self.assertEqual(set(['rev2a', 'rev2b']),
136
graph_walker.distinct_common('rev3a', 'rev3b'))
132
graph_walker.find_lca('rev3a', 'rev3b'))
137
133
self.assertEqual(set(['rev2b']),
138
graph_walker.distinct_common('rev3a', 'rev3b',
134
graph_walker.find_lca('rev3a', 'rev3b',
141
def test_unique_common_criss_cross(self):
142
"""Ensure we don't pick non-unique dcas in a criss-cross"""
137
def test_unique_lca_criss_cross(self):
138
"""Ensure we don't pick non-unique lcas in a criss-cross"""
143
139
graph_walker = self.make_walker(criss_cross)
144
140
self.assertEqual('rev1',
145
graph_walker.unique_common('rev3a', 'rev3b'))
141
graph_walker.find_unique_lca('rev3a', 'rev3b'))
147
def test_unique_common_null_revision(self):
143
def test_unique_lca_null_revision(self):
148
144
"""Ensure we pick NULL_REVISION when necessary"""
149
145
graph_walker = self.make_walker(criss_cross2)
150
146
self.assertEqual('rev1b',
151
graph_walker.unique_common('rev2a', 'rev1b'))
147
graph_walker.find_unique_lca('rev2a', 'rev1b'))
152
148
self.assertEqual(NULL_REVISION,
153
graph_walker.unique_common('rev2a', 'rev2b'))
149
graph_walker.find_unique_lca('rev2a', 'rev2b'))
155
def test_unique_common_null_revision2(self):
151
def test_unique_lca_null_revision2(self):
156
152
"""Ensure we pick NULL_REVISION when necessary"""
157
153
graph_walker = self.make_walker(ancestry_2)
158
154
self.assertEqual(NULL_REVISION,
159
graph_walker.unique_common('rev4a', 'rev1b'))
155
graph_walker.find_unique_lca('rev4a', 'rev1b'))
161
157
def test_common_ancestor_two_repos(self):
162
"""Ensure we do unique_common using data from two repos"""
158
"""Ensure we do unique_lca using data from two repos"""
163
159
mainline_tree = self.prepare_memory_tree('mainline')
164
160
self.build_ancestry(mainline_tree, mainline)
165
161
mainline_tree.unlock()