~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/knit.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-06-21 05:22:37 UTC
  • mfrom: (2490.2.33 graphwalker)
  • Revision ID: pqm@pqm.ubuntu.com-20070621052237-2phm1z5dg4arrwnk
Avoid topological sorting in Repository.get_ancestry where possible

Show diffs side-by-side

added added

removed removed

Lines of Context:
939
939
        except KeyError:
940
940
            raise RevisionNotPresent(version_id, self.filename)
941
941
 
942
 
    def get_ancestry(self, versions):
 
942
    def get_ancestry(self, versions, topo_sorted=True):
943
943
        """See VersionedFile.get_ancestry."""
944
944
        if isinstance(versions, basestring):
945
945
            versions = [versions]
946
946
        if not versions:
947
947
            return []
948
948
        versions = [osutils.safe_revision_id(v) for v in versions]
949
 
        return self._index.get_ancestry(versions)
 
949
        return self._index.get_ancestry(versions, topo_sorted)
950
950
 
951
951
    def get_ancestry_with_ghosts(self, versions):
952
952
        """See VersionedFile.get_ancestry_with_ghosts."""
967
967
        from bzrlib.weave import Weave
968
968
 
969
969
        w = Weave(self.filename)
970
 
        ancestry = self.get_ancestry(version_ids)
 
970
        ancestry = set(self.get_ancestry(version_ids, topo_sorted=False))
971
971
        sorted_graph = topo_sort(self._index.get_graph())
972
972
        version_list = [vid for vid in sorted_graph if vid in ancestry]
973
973
        
982
982
        """See VersionedFile.plan_merge."""
983
983
        ver_a = osutils.safe_revision_id(ver_a)
984
984
        ver_b = osutils.safe_revision_id(ver_b)
985
 
        ancestors_b = set(self.get_ancestry(ver_b))
 
985
        ancestors_b = set(self.get_ancestry(ver_b, topo_sorted=False))
986
986
        def status_a(revision, text):
987
987
            if revision in ancestors_b:
988
988
                return 'killed-b', text
989
989
            else:
990
990
                return 'new-a', text
991
991
        
992
 
        ancestors_a = set(self.get_ancestry(ver_a))
 
992
        ancestors_a = set(self.get_ancestry(ver_a, topo_sorted=False))
993
993
        def status_b(revision, text):
994
994
            if revision in ancestors_a:
995
995
                return 'killed-a', text
1217
1217
    def get_graph(self):
1218
1218
        return [(vid, idx[4]) for vid, idx in self._cache.iteritems()]
1219
1219
 
1220
 
    def get_ancestry(self, versions):
 
1220
    def get_ancestry(self, versions, topo_sorted=True):
1221
1221
        """See VersionedFile.get_ancestry."""
1222
1222
        # get a graph of all the mentioned versions:
1223
1223
        graph = {}
1233
1233
            # if not completed and not a ghost
1234
1234
            pending.update([p for p in parents if p not in graph])
1235
1235
            graph[version] = parents
 
1236
        if not topo_sorted:
 
1237
            return graph.keys()
1236
1238
        return topo_sort(graph.items())
1237
1239
 
1238
1240
    def get_ancestry_with_ghosts(self, versions):