~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/knit.py

  • Committer: Alexander Belchenko
  • Date: 2008-02-16 10:03:17 UTC
  • mfrom: (3224 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3230.
  • Revision ID: bialix@ukr.net-20080216100317-xg1hdw306evlgt94
merge bzr.dev; update for 1.3; $BZR_LOG used in trace.py module (again), not in the main bzr script (req. by Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
874
874
 
875
875
        This data is intended to be used for retrieving the knit records.
876
876
 
877
 
        A dict of version_id to (method, data_pos, data_size, next) is
 
877
        A dict of version_id to (method, index_memo, next) is
878
878
        returned.
879
879
        method is the way referenced data should be applied.
880
880
        data_pos is the position of the data in the knit.
882
882
        next is the build-parent of the version, or None for fulltexts.
883
883
        """
884
884
        component_data = {}
885
 
        for version_id in version_ids:
886
 
            cursor = version_id
887
 
 
888
 
            while cursor is not None and cursor not in component_data:
889
 
                method = self._index.get_method(cursor)
890
 
                if method == 'fulltext':
891
 
                    next = None
892
 
                else:
893
 
                    next = self.get_parents_with_ghosts(cursor)[0]
894
 
                index_memo = self._index.get_position(cursor)
895
 
                component_data[cursor] = (method, index_memo, next)
896
 
                cursor = next
 
885
        pending_components = version_ids
 
886
        while pending_components:
 
887
            build_details = self._index.get_build_details(pending_components)
 
888
            pending_components = set()
 
889
            for version_id, details in build_details.items():
 
890
                method, index_memo, compression_parent = details
 
891
                if compression_parent is not None:
 
892
                    pending_components.add(compression_parent)
 
893
                component_data[version_id] = details
897
894
        return component_data
898
895
       
899
896
    def _get_content(self, version_id, parent_texts={}):
1426
1423
                graph[version] = parents
1427
1424
        return topo_sort(graph.items())
1428
1425
 
 
1426
    def get_build_details(self, version_ids):
 
1427
        """Get the method, index_memo and compression parent for version_ids.
 
1428
 
 
1429
        :param version_ids: An iterable of version_ids.
 
1430
        :return: A dict of version_id:(method, index_memo, compression_parent).
 
1431
        """
 
1432
        result = {}
 
1433
        for version_id in version_ids:
 
1434
            method = self.get_method(version_id)
 
1435
            if method == 'fulltext':
 
1436
                compression_parent = None
 
1437
            else:
 
1438
                compression_parent = self.get_parents_with_ghosts(version_id)[0]
 
1439
            index_memo = self.get_position(version_id)
 
1440
            result[version_id] = (method, index_memo, compression_parent)
 
1441
        return result
 
1442
 
1429
1443
    def iter_parents(self, version_ids):
1430
1444
        """Iterate through the parents for many version ids.
1431
1445
 
1689
1703
        result_keys = topo_sort(graph.items())
1690
1704
        return [key[0] for key in result_keys]
1691
1705
 
 
1706
    def get_build_details(self, version_ids):
 
1707
        """Get the method, index_memo and compression parent for version_ids.
 
1708
 
 
1709
        :param version_ids: An iterable of version_ids.
 
1710
        :return: A dict of version_id:(method, index_memo, compression_parent).
 
1711
        """
 
1712
        result = {}
 
1713
        entries = self._get_entries(self._version_ids_to_keys(version_ids), True)
 
1714
        for entry in entries:
 
1715
            version_id = self._keys_to_version_ids((entry[1],))[0]
 
1716
            if not self._deltas:
 
1717
                compression_parent = None
 
1718
            else:
 
1719
                compression_parent_key = self._compression_parent(entry)
 
1720
                if compression_parent_key:
 
1721
                    compression_parent = self._keys_to_version_ids(
 
1722
                    (compression_parent_key,))[0]
 
1723
                else:
 
1724
                    compression_parent = None
 
1725
            if compression_parent:
 
1726
                method = 'line-delta'
 
1727
            else:
 
1728
                method = 'fulltext'
 
1729
            result[version_id] = (method, self._node_to_position(entry),
 
1730
                compression_parent)
 
1731
        return result
 
1732
 
 
1733
    def _compression_parent(self, an_entry):
 
1734
        # return the key that an_entry is compressed against, or None
 
1735
        # Grab the second parent list (as deltas implies parents currently)
 
1736
        compression_parents = an_entry[3][1]
 
1737
        if not compression_parents:
 
1738
            return None
 
1739
        assert len(compression_parents) == 1
 
1740
        return compression_parents[0]
 
1741
 
 
1742
    def _get_method(self, node):
 
1743
        if not self._deltas:
 
1744
            return 'fulltext'
 
1745
        if self._compression_parent(node):
 
1746
            return 'line-delta'
 
1747
        else:
 
1748
            return 'fulltext'
 
1749
 
1692
1750
    def get_graph(self):
1693
1751
        """Return a list of the node:parents lists from this knit index."""
1694
1752
        if not self._parents:
1750
1808
            logic to get the record.
1751
1809
        """
1752
1810
        node = self._get_node(version_id)
 
1811
        return self._node_to_position(node)
 
1812
 
 
1813
    def _node_to_position(self, node):
 
1814
        """Convert an index value to position details."""
1753
1815
        bits = node[2][1:].split(' ')
1754
1816
        return node[0], int(bits[0]), int(bits[1])
1755
1817
 
1756
1818
    def get_method(self, version_id):
1757
1819
        """Return compression method of specified version."""
1758
 
        if not self._deltas:
1759
 
            return 'fulltext'
1760
 
        return self._parent_compression(self._get_node(version_id)[3][1])
1761
 
 
1762
 
    def _parent_compression(self, reference_list):
1763
 
        # use the second reference list to decide if this is delta'd or not.
1764
 
        if len(reference_list):
1765
 
            return 'line-delta'
1766
 
        else:
1767
 
            return 'fulltext'
 
1820
        return self._get_method(self._get_node(version_id))
1768
1821
 
1769
1822
    def _get_node(self, version_id):
1770
1823
        try:
1778
1831
        e.g. ['foo', 'bar']
1779
1832
        """
1780
1833
        node = self._get_node(version_id)
1781
 
        if not self._deltas:
1782
 
            options = ['fulltext']
1783
 
        else:
1784
 
            options = [self._parent_compression(node[3][1])]
 
1834
        options = [self._get_method(node)]
1785
1835
        if node[2][0] == 'N':
1786
1836
            options.append('no-eol')
1787
1837
        return options
2159
2209
            ancestry.add(version)
2160
2210
        return list(ancestry)
2161
2211
 
 
2212
    def get_build_details(self, version_ids):
 
2213
        """Get the method, index_memo and compression parent for version_ids.
 
2214
 
 
2215
        :param version_ids: An iterable of version_ids.
 
2216
        :return: A dict of version_id:(method, index_memo, compression_parent).
 
2217
        """
 
2218
        result = {}
 
2219
        for version_id in version_ids:
 
2220
            method = self.get_method(version_id)
 
2221
            if method == 'fulltext':
 
2222
                compression_parent = None
 
2223
            else:
 
2224
                compression_parent = self.get_parents_with_ghosts(version_id)[0]
 
2225
            index_memo = self.get_position(version_id)
 
2226
            result[version_id] = (method, index_memo, compression_parent)
 
2227
        return result
 
2228
 
2162
2229
    def get_method(self, version_id):
2163
2230
        """Return compression method of specified version."""
2164
2231
        try: