~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/groupcompress.py

  • Committer: John Arbash Meinel
  • Date: 2010-08-23 19:10:35 UTC
  • mto: This revision was merged to the branch mainline in revision 5390.
  • Revision ID: john@arbash-meinel.com-20100823191035-57bojnmqw54nutsz
switch 'x += 1' to 'x = x + 1' to deal with brain-damaged old versions of pyrex.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008, 2009 Canonical Ltd
 
1
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
1631
1631
        keys_to_add = []
1632
1632
        def flush():
1633
1633
            bytes = self._compressor.flush().to_bytes()
 
1634
            self._compressor = GroupCompressor()
1634
1635
            index, start, length = self._access.add_raw_records(
1635
1636
                [(None, len(bytes))], bytes)[0]
1636
1637
            nodes = []
1639
1640
            self._index.add_records(nodes, random_id=random_id)
1640
1641
            self._unadded_refs = {}
1641
1642
            del keys_to_add[:]
1642
 
            self._compressor = GroupCompressor()
1643
1643
 
1644
1644
        last_prefix = None
1645
1645
        max_fulltext_len = 0
1809
1809
        return result
1810
1810
 
1811
1811
 
 
1812
class _GCBuildDetails(object):
 
1813
    """A blob of data about the build details.
 
1814
 
 
1815
    This stores the minimal data, which then allows compatibility with the old
 
1816
    api, without taking as much memory.
 
1817
    """
 
1818
 
 
1819
    __slots__ = ('_index', '_group_start', '_group_end', '_basis_end',
 
1820
                 '_delta_end', '_parents')
 
1821
 
 
1822
    method = 'group'
 
1823
    compression_parent = None
 
1824
 
 
1825
    def __init__(self, parents, position_info):
 
1826
        self._parents = parents
 
1827
        (self._index, self._group_start, self._group_end, self._basis_end,
 
1828
         self._delta_end) = position_info
 
1829
 
 
1830
    def __repr__(self):
 
1831
        return '%s(%s, %s)' % (self.__class__.__name__,
 
1832
            self.index_memo, self._parents)
 
1833
 
 
1834
    @property
 
1835
    def index_memo(self):
 
1836
        return (self._index, self._group_start, self._group_end,
 
1837
                self._basis_end, self._delta_end)
 
1838
 
 
1839
    @property
 
1840
    def record_details(self):
 
1841
        return static_tuple.StaticTuple(self.method, None)
 
1842
 
 
1843
    def __getitem__(self, offset):
 
1844
        """Compatibility thunk to act like a tuple."""
 
1845
        if offset == 0:
 
1846
            return self.index_memo
 
1847
        elif offset == 1:
 
1848
            return self.compression_parent # Always None
 
1849
        elif offset == 2:
 
1850
            return self._parents
 
1851
        elif offset == 3:
 
1852
            return self.record_details
 
1853
        else:
 
1854
            raise IndexError('offset out of range')
 
1855
            
 
1856
    def __len__(self):
 
1857
        return 4
 
1858
 
 
1859
 
1812
1860
class _GCGraphIndex(object):
1813
1861
    """Mapper from GroupCompressVersionedFiles needs into GraphIndex storage."""
1814
1862
 
2009
2057
                parents = None
2010
2058
            else:
2011
2059
                parents = entry[3][0]
2012
 
            method = 'group'
2013
 
            result[key] = (self._node_to_position(entry),
2014
 
                                  None, parents, (method, None))
 
2060
            details = _GCBuildDetails(parents, self._node_to_position(entry))
 
2061
            result[key] = details
2015
2062
        return result
2016
2063
 
2017
2064
    def keys(self):
2033
2080
        # each, or about 7MB. Note that it might be even more when you consider
2034
2081
        # how PyInt is allocated in separate slabs. And you can't return a slab
2035
2082
        # to the OS if even 1 int on it is in use. Note though that Python uses
2036
 
        # a LIFO when re-using PyInt slots, which probably causes more
 
2083
        # a LIFO when re-using PyInt slots, which might cause more
2037
2084
        # fragmentation.
2038
2085
        start = int(bits[0])
2039
2086
        start = self._int_cache.setdefault(start, start)