~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/revision.py

  • Committer: Aaron Bentley
  • Date: 2005-08-25 13:10:25 UTC
  • mfrom: (974.1.38)
  • mto: (1092.1.42) (1185.3.4)
  • mto: This revision was merged to the branch mainline in revision 1178.
  • Revision ID: abentley@panoramicfeedback.com-20050825131025-2aa94bcbbd646a00
Fixed return value when not an ImmutableStore

Show diffs side-by-side

added added

removed removed

Lines of Context:
271
271
            except bzrlib.errors.NoSuchRevision, e:
272
272
                pass
273
273
        raise e
274
 
 
275
 
def get_intervening_revisions(ancestor_id, rev_id, rev_source, 
276
 
                              revision_history=None):
277
 
    """Find the longest line of descent from maybe_ancestor to revision.
278
 
    Revision history is followed where possible.
279
 
 
280
 
    If ancestor_id == rev_id, list will be empty.
281
 
    Otherwise, rev_id will be the last entry.  ancestor_id will never appear.
282
 
    If ancestor_id is not an ancestor, NotAncestor will be thrown
283
 
    """
284
 
    [rev_source.get_revision(r) for r in (ancestor_id, rev_id)]
285
 
    if ancestor_id == rev_id:
286
 
        return []
287
 
    def historical_lines(line):
288
 
        """Return a tuple of historical/non_historical lines, for sorting.
289
 
        The non_historical count is negative, since non_historical lines are
290
 
        a bad thing.
291
 
        """
292
 
        good_count = 0
293
 
        bad_count = 0
294
 
        for revision in line:
295
 
            if revision in revision_history:
296
 
                good_count += 1
297
 
            else:
298
 
                bad_count -= 1
299
 
        return good_count, bad_count
300
 
    active = [[rev_id]]
301
 
    successful_lines = []
302
 
    while len(active) > 0:
303
 
        new_active = []
304
 
        for line in active:
305
 
            parent_ids = [p.revision_id for p in 
306
 
                          rev_source.get_revision(line[-1]).parents]
307
 
            for parent in parent_ids:
308
 
                line_copy = line[:]
309
 
                if parent == ancestor_id:
310
 
                    successful_lines.append(line_copy)
311
 
                else:
312
 
                    line_copy.append(parent)
313
 
                    new_active.append(line_copy)
314
 
        active = new_active
315
 
    if len(successful_lines) == 0:
316
 
        raise bzrlib.errors.NotAncestor(rev_id, ancestor_id)
317
 
    for line in successful_lines:
318
 
        line.reverse()
319
 
    if revision_history is not None:
320
 
        by_historical_lines = []
321
 
        for line in successful_lines:
322
 
            count = historical_lines(line)
323
 
            by_historical_lines.append((count, line))
324
 
        by_historical_lines.sort()
325
 
        if by_historical_lines[-1][0][0] > 0:
326
 
            return by_historical_lines[-1][1]
327
 
    assert len(successful_lines)
328
 
    successful_lines.sort(cmp, len)
329
 
    return successful_lines[-1]