212
212
right = searchers[1].seen
213
213
return (left.difference(right), right.difference(left))
215
def find_distance_to_null(self, target_revision_id, known_revision_ids):
216
"""Find the left-hand distance to the NULL_REVISION.
218
(This can also be considered the revno of a branch at
221
:param target_revision_id: A revision_id which we would like to know
223
:param known_revision_ids: [(revision_id, revno)] A list of known
224
revno, revision_id tuples. We'll use this to seed the search.
226
# Map from revision_ids to a known value for their revno
227
known_revnos = dict(known_revision_ids)
228
cur_tip = target_revision_id
230
NULL_REVISION = revision.NULL_REVISION
231
known_revnos[NULL_REVISION] = 0
233
searching_known_tips = list(known_revnos.keys())
235
unknown_searched = {}
237
while cur_tip not in known_revnos:
238
unknown_searched[cur_tip] = num_steps
240
to_search = set([cur_tip])
241
to_search.update(searching_known_tips)
242
parent_map = self.get_parent_map(to_search)
243
parents = parent_map.get(cur_tip, None)
244
if not parents: # An empty list or None is a ghost
245
raise errors.GhostRevisionsHaveNoRevno(target_revision_id,
249
for revision_id in searching_known_tips:
250
parents = parent_map.get(revision_id, None)
254
next_revno = known_revnos[revision_id] - 1
255
if next in unknown_searched:
256
# We have enough information to return a value right now
257
return next_revno + unknown_searched[next]
258
if next in known_revnos:
260
known_revnos[next] = next_revno
261
next_known_tips.append(next)
262
searching_known_tips = next_known_tips
264
# We reached a known revision, so just add in how many steps it took to
266
return known_revnos[cur_tip] + num_steps
215
268
def find_unique_ancestors(self, unique_revision, common_revisions):
216
269
"""Find the unique ancestors for a revision versus others.