88
82
def test_refine(self):
89
83
# Used when pulling from a stacked repository, so test some revisions
90
84
# being satisfied from the stacking branch.
92
{b"tip": [b"mid"], b"mid": [b"base"], b"tag": [b"base"],
93
b"base": [NULL_REVISION], NULL_REVISION: []})
94
result = vf_search.SearchResult(
96
{NULL_REVISION}, 4, {b'tip', b'mid', b'tag', b'base'})
97
result = result.refine({b'tip'}, {b'mid'})
86
{"tip":["mid"], "mid":["base"], "tag":["base"],
87
"base":[NULL_REVISION], NULL_REVISION:[]})
88
result = vf_search.SearchResult({'tip', 'tag'},
89
{NULL_REVISION}, 4, {'tip', 'mid', 'tag', 'base'})
90
result = result.refine({'tip'}, {'mid'})
98
91
recipe = result.get_recipe()
99
92
# We should be starting from tag (original head) and mid (seen ref)
100
self.assertEqual({b'mid', b'tag'}, recipe[1])
93
self.assertEqual({'mid', 'tag'}, recipe[1])
101
94
# We should be stopping at NULL (original stop) and tip (seen head)
102
self.assertEqual({NULL_REVISION, b'tip'}, recipe[2])
95
self.assertEqual({NULL_REVISION, 'tip'}, recipe[2])
103
96
self.assertEqual(3, recipe[3])
104
result = result.refine({b'mid', b'tag', b'base'},
97
result = result.refine({'mid', 'tag', 'base'},
106
99
recipe = result.get_recipe()
107
100
# We should be starting from nothing (NULL was known as a cut point)
108
101
self.assertEqual(set([]), recipe[1])
110
103
# tag (seen head) and mid(seen mid-point head). We could come back and
111
104
# define this as not including mid, for minimal results, but it is
112
105
# still 'correct' to include mid, and simpler/easier.
113
self.assertEqual({NULL_REVISION, b'tip', b'tag', b'mid'}, recipe[2])
106
self.assertEqual({NULL_REVISION, 'tip', 'tag', 'mid'}, recipe[2])
114
107
self.assertEqual(0, recipe[3])
115
108
self.assertTrue(result.is_empty())
129
122
self.assertSearchResult([], [], 0, None)
131
124
def test_ancestry_1(self):
132
self.assertSearchResult([b'rev4'], [NULL_REVISION], len(ancestry_1),
125
self.assertSearchResult(['rev4'], [NULL_REVISION], len(ancestry_1),
135
128
def test_ancestry_2(self):
136
self.assertSearchResult([b'rev1b', b'rev4a'], [NULL_REVISION],
129
self.assertSearchResult(['rev1b', 'rev4a'], [NULL_REVISION],
137
130
len(ancestry_2), ancestry_2)
138
self.assertSearchResult([b'rev1b', b'rev4a'], [],
139
len(ancestry_2) + 1, ancestry_2,
131
self.assertSearchResult(['rev1b', 'rev4a'], [],
132
len(ancestry_2)+1, ancestry_2,
140
133
missing_keys=[NULL_REVISION])
142
135
def test_partial_search(self):
143
parent_map = dict((k, extended_history_shortcut[k])
144
for k in [b'e', b'f'])
145
self.assertSearchResult([b'e', b'f'], [b'd', b'a'], 2,
147
parent_map.update((k, extended_history_shortcut[k])
148
for k in [b'd', b'a'])
149
self.assertSearchResult([b'e', b'f'], [b'c', NULL_REVISION], 4,
151
parent_map[b'c'] = extended_history_shortcut[b'c']
152
self.assertSearchResult([b'e', b'f'], [b'b'], 6,
136
parent_map = dict((k,extended_history_shortcut[k])
138
self.assertSearchResult(['e', 'f'], ['d', 'a'], 2,
140
parent_map.update((k,extended_history_shortcut[k])
142
self.assertSearchResult(['e', 'f'], ['c', NULL_REVISION], 4,
144
parent_map['c'] = extended_history_shortcut['c']
145
self.assertSearchResult(['e', 'f'], ['b'], 6,
153
146
parent_map, missing_keys=[NULL_REVISION])
154
parent_map[b'b'] = extended_history_shortcut[b'b']
155
self.assertSearchResult([b'e', b'f'], [], 7,
147
parent_map['b'] = extended_history_shortcut['b']
148
self.assertSearchResult(['e', 'f'], [], 7,
156
149
parent_map, missing_keys=[NULL_REVISION])
166
159
(sorted(start), sorted(stop), count))
168
161
def test_empty_ancestry(self):
169
self.assertSearchResult([], [], 0, {}, (), [b'tip-rev-id'], 10)
162
self.assertSearchResult([], [], 0, {}, (), ['tip-rev-id'], 10)
171
164
def test_ancestry_1(self):
172
self.assertSearchResult([b'rev4'], [b'rev1'], 4,
173
ancestry_1, (), [b'rev1'], 10)
174
self.assertSearchResult([b'rev2a', b'rev2b'], [b'rev1'], 2,
175
ancestry_1, (), [b'rev1'], 1)
165
self.assertSearchResult(['rev4'], ['rev1'], 4,
166
ancestry_1, (), ['rev1'], 10)
167
self.assertSearchResult(['rev2a', 'rev2b'], ['rev1'], 2,
168
ancestry_1, (), ['rev1'], 1)
177
171
def test_multiple_heads(self):
178
self.assertSearchResult([b'e', b'f'], [b'a'], 5,
179
extended_history_shortcut, (), [b'a'], 10)
172
self.assertSearchResult(['e', 'f'], ['a'], 5,
173
extended_history_shortcut, (), ['a'], 10)
180
174
# Note that even though we only take 1 step back, we find 'f', which
181
175
# means the described search will still find d and c.
182
self.assertSearchResult([b'f'], [b'a'], 4,
183
extended_history_shortcut, (), [b'a'], 1)
184
self.assertSearchResult([b'f'], [b'a'], 4,
185
extended_history_shortcut, (), [b'a'], 2)
176
self.assertSearchResult(['f'], ['a'], 4,
177
extended_history_shortcut, (), ['a'], 1)
178
self.assertSearchResult(['f'], ['a'], 4,
179
extended_history_shortcut, (), ['a'], 2)
188
182
class TestPendingAncestryResultRefine(tests.TestCase):
194
188
# Used when pulling from a stacked repository, so test some revisions
195
189
# being satisfied from the stacking branch.
196
190
g = self.make_graph(
197
{b"tip": [b"mid"], b"mid": [b"base"], b"tag": [b"base"],
198
b"base": [NULL_REVISION], NULL_REVISION: []})
199
result = vf_search.PendingAncestryResult([b'tip', b'tag'], None)
200
result = result.refine({b'tip'}, {b'mid'})
201
self.assertEqual({b'mid', b'tag'}, result.heads)
202
result = result.refine({b'mid', b'tag', b'base'},
191
{"tip":["mid"], "mid":["base"], "tag":["base"],
192
"base":[NULL_REVISION], NULL_REVISION:[]})
193
result = vf_search.PendingAncestryResult(['tip', 'tag'], None)
194
result = result.refine({'tip'}, {'mid'})
195
self.assertEqual({'mid', 'tag'}, result.heads)
196
result = result.refine({'mid', 'tag', 'base'},
204
198
self.assertEqual({NULL_REVISION}, result.heads)
205
199
self.assertTrue(result.is_empty())
211
205
def test_get_keys(self):
212
206
builder = self.make_branch_builder('b')
213
207
builder.start_series()
214
builder.build_snapshot(None, [
215
('add', ('', b'root-id', 'directory', ''))],
216
revision_id=b'rev-1')
217
builder.build_snapshot([b'rev-1'], [], revision_id=b'rev-2')
208
builder.build_snapshot('rev-1', None, [
209
('add', ('', 'root-id', 'directory', ''))])
210
builder.build_snapshot('rev-2', ['rev-1'], [])
218
211
builder.finish_series()
219
212
repo = builder.get_branch().repository
221
214
self.addCleanup(repo.unlock)
222
result = vf_search.PendingAncestryResult([b'rev-2'], repo)
223
self.assertEqual({b'rev-1', b'rev-2'}, set(result.get_keys()))
215
result = vf_search.PendingAncestryResult(['rev-2'], repo)
216
self.assertEqual({'rev-1', 'rev-2'}, set(result.get_keys()))
225
218
def test_get_keys_excludes_ghosts(self):
226
219
builder = self.make_branch_builder('b')
227
220
builder.start_series()
228
builder.build_snapshot(None, [
229
('add', ('', b'root-id', 'directory', ''))],
230
revision_id=b'rev-1')
231
builder.build_snapshot([b'rev-1', b'ghost'], [], revision_id=b'rev-2')
221
builder.build_snapshot('rev-1', None, [
222
('add', ('', 'root-id', 'directory', ''))])
223
builder.build_snapshot('rev-2', ['rev-1', 'ghost'], [])
232
224
builder.finish_series()
233
225
repo = builder.get_branch().repository
235
227
self.addCleanup(repo.unlock)
236
result = vf_search.PendingAncestryResult([b'rev-2'], repo)
237
self.assertEqual(sorted([b'rev-1', b'rev-2']),
238
sorted(result.get_keys()))
228
result = vf_search.PendingAncestryResult(['rev-2'], repo)
229
self.assertEqual(sorted(['rev-1', 'rev-2']), sorted(result.get_keys()))
240
231
def test_get_keys_excludes_null(self):
241
232
# Make a 'graph' with an iter_ancestry that returns NULL_REVISION
244
235
class StubGraph(object):
245
236
def iter_ancestry(self, keys):
246
return [(NULL_REVISION, ()), (b'foo', (NULL_REVISION,))]
247
result = vf_search.PendingAncestryResult([b'rev-3'], None)
237
return [(NULL_REVISION, ()), ('foo', (NULL_REVISION,))]
238
result = vf_search.PendingAncestryResult(['rev-3'], None)
248
239
result_keys = result._get_keys(StubGraph())
249
240
# Only the non-null keys from the ancestry appear.
250
self.assertEqual({b'foo'}, set(result_keys))
241
self.assertEqual({'foo'}, set(result_keys))