~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-03-05 13:13:43 UTC
  • mfrom: (3240.1.7 faster_generate_history)
  • Revision ID: pqm@pqm.ubuntu.com-20080305131343-toq33x607hecihie
Accelerate Branch revision-history operations, looms (abentley)

Show diffs side-by-side

added added

removed removed

Lines of Context:
260
260
            if last_revision is None:
261
261
                pb.update('get source history')
262
262
                last_revision = from_branch.last_revision()
263
 
                if last_revision is None:
264
 
                    last_revision = _mod_revision.NULL_REVISION
 
263
                last_revision = _mod_revision.ensure_null(last_revision)
265
264
            return self.repository.fetch(from_branch.repository,
266
265
                                         revision_id=last_revision,
267
266
                                         pb=nested_pb)
1394
1393
        configured to check constraints on history, in which case this may not
1395
1394
        be permitted.
1396
1395
        """
 
1396
        revision_id = _mod_revision.ensure_null(revision_id)
1397
1397
        history = self._lefthand_history(revision_id)
1398
1398
        assert len(history) == revno, '%d != %d' % (len(history), revno)
1399
1399
        self.set_revision_history(history)
1410
1410
        if 'evil' in debug.debug_flags:
1411
1411
            mutter_callsite(4, "_lefthand_history scales with history.")
1412
1412
        # stop_revision must be a descendant of last_revision
1413
 
        stop_graph = self.repository.get_revision_graph(revision_id)
1414
 
        if (last_rev is not None and last_rev != _mod_revision.NULL_REVISION
1415
 
            and last_rev not in stop_graph):
1416
 
            # our previous tip is not merged into stop_revision
1417
 
            raise errors.DivergedBranches(self, other_branch)
 
1413
        graph = self.repository.get_graph()
 
1414
        if last_rev is not None:
 
1415
            if not graph.is_ancestor(last_rev, revision_id):
 
1416
                # our previous tip is not merged into stop_revision
 
1417
                raise errors.DivergedBranches(self, other_branch)
1418
1418
        # make a new revision history from the graph
 
1419
        parents_map = graph.get_parent_map([revision_id])
 
1420
        if revision_id not in parents_map:
 
1421
            raise errors.NoSuchRevision(self, revision_id)
1419
1422
        current_rev_id = revision_id
1420
1423
        new_history = []
1421
 
        while current_rev_id not in (None, _mod_revision.NULL_REVISION):
 
1424
        # Do not include ghosts or graph origin in revision_history
 
1425
        while (current_rev_id in parents_map and
 
1426
               len(parents_map[current_rev_id]) > 0):
1422
1427
            new_history.append(current_rev_id)
1423
 
            current_rev_id_parents = stop_graph[current_rev_id]
1424
 
            try:
1425
 
                current_rev_id = current_rev_id_parents[0]
1426
 
            except IndexError:
1427
 
                current_rev_id = None
 
1428
            current_rev_id = parents_map[current_rev_id][0]
 
1429
            parents_map = graph.get_parent_map([current_rev_id])
1428
1430
        new_history.reverse()
1429
1431
        return new_history
1430
1432
 
1824
1826
        Intended to be called by set_last_revision_info and
1825
1827
        _write_revision_history.
1826
1828
        """
1827
 
        if revision_id is None:
1828
 
            revision_id = 'null:'
 
1829
        assert revision_id is not None, "Use NULL_REVISION, not None"
1829
1830
        out_string = '%d %s\n' % (revno, revision_id)
1830
1831
        self.control_files.put_bytes('last-revision', out_string)
1831
1832
 
1832
1833
    @needs_write_lock
1833
1834
    def set_last_revision_info(self, revno, revision_id):
 
1835
        revision_id = _mod_revision.ensure_null(revision_id)
1834
1836
        if self._get_append_revisions_only():
1835
1837
            self._check_history_violation(revision_id)
1836
1838
        self._write_last_revision_info(revno, revision_id)
1959
1961
    def _make_tags(self):
1960
1962
        return BasicTags(self)
1961
1963
 
 
1964
    @needs_write_lock
 
1965
    def generate_revision_history(self, revision_id, last_rev=None,
 
1966
                                  other_branch=None):
 
1967
        """See BzrBranch5.generate_revision_history"""
 
1968
        history = self._lefthand_history(revision_id, last_rev, other_branch)
 
1969
        revno = len(history)
 
1970
        self.set_last_revision_info(revno, revision_id)
 
1971
 
1962
1972
 
1963
1973
######################################################################
1964
1974
# results of operations