~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/revision.py

MergeĀ inĀ upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
158
158
    return matches
159
159
 
160
160
 
161
 
def old_common_ancestor(revision_a, revision_b, revision_source):
162
 
    """Find the ancestor common to both revisions that is closest to both.
163
 
    """
164
 
    from bzrlib.trace import mutter
165
 
    a_ancestors = find_present_ancestors(revision_a, revision_source)
166
 
    b_ancestors = find_present_ancestors(revision_b, revision_source)
167
 
    a_intersection = []
168
 
    b_intersection = []
169
 
    # a_order is used as a tie-breaker when two equally-good bases are found
170
 
    for revision, (a_order, a_distance) in a_ancestors.iteritems():
171
 
        if b_ancestors.has_key(revision):
172
 
            a_intersection.append((a_distance, a_order, revision))
173
 
            b_intersection.append((b_ancestors[revision][1], a_order, revision))
174
 
    mutter("a intersection: %r", a_intersection)
175
 
    mutter("b intersection: %r", b_intersection)
176
 
 
177
 
    a_closest = __get_closest(a_intersection)
178
 
    if len(a_closest) == 0:
179
 
        return None
180
 
    b_closest = __get_closest(b_intersection)
181
 
    assert len(b_closest) != 0
182
 
    mutter ("a_closest %r", a_closest)
183
 
    mutter ("b_closest %r", b_closest)
184
 
    if a_closest[0] in b_closest:
185
 
        return a_closest[0]
186
 
    elif b_closest[0] in a_closest:
187
 
        return b_closest[0]
188
 
    else:
189
 
        raise bzrlib.errors.AmbiguousBase((a_closest[0], b_closest[0]))
190
 
    return a_closest[0]
191
 
 
192
161
def revision_graph(revision, revision_source):
193
162
    """Produce a graph of the ancestry of the specified revision.
194
163
    Return root, ancestors map, descendants map
199
168
    RBC: 20051024: note that when we have two partial histories, this may not
200
169
         be possible. But if we are willing to pretend :)... sure.
201
170
    """
 
171
    revision_source.lock_read()
 
172
    try:
 
173
        return _revision_graph(revision, revision_source)
 
174
    finally:
 
175
        revision_source.unlock()
 
176
 
 
177
def _revision_graph(revision, revision_source):
 
178
    """See revision_graph."""
202
179
    ancestors = {}
203
180
    descendants = {}
204
181
    lines = [revision]
316
293
                pass
317
294
        raise e
318
295
 
 
296
    def lock_read(self):
 
297
        for source in self._revision_sources:
 
298
            source.lock_read()
 
299
 
 
300
    def unlock(self):
 
301
        for source in self._revision_sources:
 
302
            source.unlock()
 
303
 
319
304
def get_intervening_revisions(ancestor_id, rev_id, rev_source, 
320
305
                              revision_history=None):
321
306
    """Find the longest line of descent from maybe_ancestor to revision.