~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/revision.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-06-08 06:38:32 UTC
  • mfrom: (1685.1.81 encoding)
  • Revision ID: pqm@pqm.ubuntu.com-20060608063832-74b46cf8fdd4567a
(jam,mbp,wvh) Lots of updates to unicode,url,and encoding support

Show diffs side-by-side

added added

removed removed

Lines of Context:
404
404
    def unlock(self):
405
405
        for source in self._revision_sources:
406
406
            source.unlock()
 
407
 
 
408
 
 
409
@deprecated_function(zero_eight)
 
410
def get_intervening_revisions(ancestor_id, rev_id, rev_source,
 
411
                              revision_history=None):
 
412
    """Find the longest line of descent from maybe_ancestor to revision.
 
413
    Revision history is followed where possible.
 
414
 
 
415
    If ancestor_id == rev_id, list will be empty.
 
416
    Otherwise, rev_id will be the last entry.  ancestor_id will never appear.
 
417
    If ancestor_id is not an ancestor, NotAncestor will be thrown
 
418
    """
 
419
    root, ancestors, descendants = revision_graph(rev_id, rev_source)
 
420
    if len(descendants) == 0:
 
421
        raise NoSuchRevision(rev_source, rev_id)
 
422
    if ancestor_id not in descendants:
 
423
        rev_source.get_revision(ancestor_id)
 
424
        raise bzrlib.errors.NotAncestor(rev_id, ancestor_id)
 
425
    root_descendants = all_descendants(descendants, ancestor_id)
 
426
    root_descendants.add(ancestor_id)
 
427
    if rev_id not in root_descendants:
 
428
        raise bzrlib.errors.NotAncestor(rev_id, ancestor_id)
 
429
    distances = node_distances(descendants, ancestors, ancestor_id,
 
430
                               root_descendants=root_descendants)
 
431
 
 
432
    def best_ancestor(rev_id):
 
433
        best = None
 
434
        for anc_id in ancestors[rev_id]:
 
435
            try:
 
436
                distance = distances[anc_id]
 
437
            except KeyError:
 
438
                continue
 
439
            if revision_history is not None and anc_id in revision_history:
 
440
                return anc_id
 
441
            elif best is None or distance > best[1]:
 
442
                best = (anc_id, distance)
 
443
        return best[0]
 
444
 
 
445
    next = rev_id
 
446
    path = []
 
447
    while next != ancestor_id:
 
448
        path.append(next)
 
449
        next = best_ancestor(next)
 
450
    path.reverse()
 
451
    return path