348
350
Otherwise, rev_id will be the last entry. ancestor_id will never appear.
349
351
If ancestor_id is not an ancestor, NotAncestor will be thrown
351
[rev_source.get_revision(r) for r in (ancestor_id, rev_id)]
352
if ancestor_id == rev_id:
354
def historical_lines(line):
355
"""Return a tuple of historical/non_historical lines, for sorting.
356
The non_historical count is negative, since non_historical lines are
361
for revision in line:
362
if revision in revision_history:
366
return good_count, bad_count
368
successful_lines = []
369
while len(active) > 0:
372
parent_ids = [p.revision_id for p in
373
rev_source.get_revision(line[-1]).parents]
374
for parent in parent_ids:
376
if parent == ancestor_id:
377
successful_lines.append(line_copy)
379
line_copy.append(parent)
380
new_active.append(line_copy)
382
if len(successful_lines) == 0:
383
raise bzrlib.errors.NotAncestor(rev_id, ancestor_id)
384
for line in successful_lines:
386
if revision_history is not None:
387
by_historical_lines = []
388
for line in successful_lines:
389
count = historical_lines(line)
390
by_historical_lines.append((count, line))
391
by_historical_lines.sort()
392
if by_historical_lines[-1][0][0] > 0:
393
return by_historical_lines[-1][1]
394
assert len(successful_lines)
395
successful_lines.sort(cmp, len)
396
return successful_lines[-1]
353
root, ancestors, descendants = revision_graph(rev_id, rev_source)
354
if len(descendants) == 0:
355
raise NoSuchRevision(rev_source, rev_id)
356
if ancestor_id not in descendants:
357
rev_source.get_revision(ancestor_id)
358
raise bzrlib.errors.NotAncestor(rev_id, ancestor_id)
359
root_descendants = all_descendants(descendants, ancestor_id)
360
root_descendants.add(ancestor_id)
361
if rev_id not in root_descendants:
362
raise bzrlib.errors.NotAncestor(rev_id, ancestor_id)
363
distances = node_distances(descendants, ancestors, ancestor_id,
364
root_descendants=root_descendants)
366
def best_ancestor(rev_id):
368
for anc_id in ancestors[rev_id]:
370
distance = distances[anc_id]
373
if revision_history is not None and anc_id in revision_history:
375
elif best is None or distance > best[1]:
376
best = (anc_id, distance)
381
while next != ancestor_id:
383
next = best_ancestor(next)