~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/knit.py

  • Committer: John Arbash Meinel
  • Date: 2007-06-28 23:18:09 UTC
  • mfrom: (2562 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2566.
  • Revision ID: john@arbash-meinel.com-20070628231809-pqbt7puoqj8bl07b
[merge] bzr.dev 2562

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
1185
1185
                # or a different failure, and raise. RBC 20060407
1186
1186
                continue
1187
1187
 
1188
 
            parents = []
1189
 
            for value in rec[4:-1]:
1190
 
                if value[0] == '.':
1191
 
                    # uncompressed reference
1192
 
                    parent_id = value[1:]
1193
 
                else:
1194
 
                    parent_id = history[int(value)]
1195
 
                parents.append(parent_id)
 
1188
            try:
 
1189
                parents = []
 
1190
                for value in rec[4:-1]:
 
1191
                    if value[0] == '.':
 
1192
                        # uncompressed reference
 
1193
                        parent_id = value[1:]
 
1194
                    else:
 
1195
                        parent_id = history[int(value)]
 
1196
                    parents.append(parent_id)
 
1197
            except (IndexError, ValueError), e:
 
1198
                # The parent could not be decoded to get its parent row. This
 
1199
                # at a minimum will cause this row to have wrong parents, or
 
1200
                # even to apply a delta to the wrong base and decode
 
1201
                # incorrectly. its therefore not usable, and because we have
 
1202
                # encountered a situation where a new knit index had this
 
1203
                # corrupt we can't asssume that no other rows referring to the
 
1204
                # index of this record actually mean the subsequent uncorrupt
 
1205
                # one, so we error.
 
1206
                raise errors.KnitCorrupt(self._filename,
 
1207
                    "line %r: %s" % (rec, e))
1196
1208
 
1197
1209
            version_id, options, pos, size = rec[:4]
1198
1210
            version_id = version_id
1217
1229
    def get_graph(self):
1218
1230
        return [(vid, idx[4]) for vid, idx in self._cache.iteritems()]
1219
1231
 
1220
 
    def get_ancestry(self, versions):
 
1232
    def get_ancestry(self, versions, topo_sorted=True):
1221
1233
        """See VersionedFile.get_ancestry."""
1222
1234
        # get a graph of all the mentioned versions:
1223
1235
        graph = {}
1233
1245
            # if not completed and not a ghost
1234
1246
            pending.update([p for p in parents if p not in graph])
1235
1247
            graph[version] = parents
 
1248
        if not topo_sorted:
 
1249
            return graph.keys()
1236
1250
        return topo_sort(graph.items())
1237
1251
 
1238
1252
    def get_ancestry_with_ghosts(self, versions):