/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/groupcompress.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-10-19 10:59:16 UTC
  • mfrom: (4585.1.10 foreign-tests)
  • Revision ID: pqm@pqm.ubuntu.com-20091019105916-6z2jo34eqr6s0008
(Jelmer) Add infrastructure for testing foreign branch
        implementations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2008, 2009 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
31
31
    knit,
32
32
    osutils,
33
33
    pack,
34
 
    static_tuple,
35
34
    trace,
36
35
    )
37
36
from bzrlib.btree_index import BTreeBuilder
1266
1265
        else:
1267
1266
            return self.get_record_stream(keys, 'unordered', True)
1268
1267
 
1269
 
    def clear_cache(self):
1270
 
        """See VersionedFiles.clear_cache()"""
1271
 
        self._group_cache.clear()
1272
 
        self._index._graph_index.clear_cache()
1273
 
        self._index._int_cache.clear()
1274
 
 
1275
1268
    def _check_add(self, key, lines, random_id, check_content):
1276
1269
        """check that version_id and lines are safe to add."""
1277
1270
        version_id = key[-1]
1631
1624
        keys_to_add = []
1632
1625
        def flush():
1633
1626
            bytes = self._compressor.flush().to_bytes()
1634
 
            self._compressor = GroupCompressor()
1635
1627
            index, start, length = self._access.add_raw_records(
1636
1628
                [(None, len(bytes))], bytes)[0]
1637
1629
            nodes = []
1640
1632
            self._index.add_records(nodes, random_id=random_id)
1641
1633
            self._unadded_refs = {}
1642
1634
            del keys_to_add[:]
 
1635
            self._compressor = GroupCompressor()
1643
1636
 
1644
1637
        last_prefix = None
1645
1638
        max_fulltext_len = 0
1747
1740
                key = record.key
1748
1741
            self._unadded_refs[key] = record.parents
1749
1742
            yield found_sha1
1750
 
            as_st = static_tuple.StaticTuple.from_sequence
1751
 
            if record.parents is not None:
1752
 
                parents = as_st([as_st(p) for p in record.parents])
1753
 
            else:
1754
 
                parents = None
1755
 
            refs = static_tuple.StaticTuple(parents)
1756
 
            keys_to_add.append((key, '%d %d' % (start_point, end_point), refs))
 
1743
            keys_to_add.append((key, '%d %d' % (start_point, end_point),
 
1744
                (record.parents,)))
1757
1745
        if len(keys_to_add):
1758
1746
            flush()
1759
1747
        self._compressor = None
1839
1827
        self.has_graph = parents
1840
1828
        self._is_locked = is_locked
1841
1829
        self._inconsistency_fatal = inconsistency_fatal
1842
 
        # GroupCompress records tend to have the same 'group' start + offset
1843
 
        # repeated over and over, this creates a surplus of ints
1844
 
        self._int_cache = {}
1845
1830
        if track_external_parent_refs:
1846
1831
            self._key_dependencies = knit._KeyRefs(
1847
1832
                track_new_keys=track_new_keys)
1883
1868
        if not random_id:
1884
1869
            present_nodes = self._get_entries(keys)
1885
1870
            for (index, key, value, node_refs) in present_nodes:
1886
 
                # Sometimes these are passed as a list rather than a tuple
1887
 
                node_refs = static_tuple.as_tuples(node_refs)
1888
 
                passed = static_tuple.as_tuples(keys[key])
1889
 
                if node_refs != passed[1]:
1890
 
                    details = '%s %s %s' % (key, (value, node_refs), passed)
 
1871
                if node_refs != keys[key][1]:
 
1872
                    details = '%s %s %s' % (key, (value, node_refs), keys[key])
1891
1873
                    if self._inconsistency_fatal:
1892
1874
                        raise errors.KnitCorrupt(self, "inconsistent details"
1893
1875
                                                 " in add_records: %s" %
2026
2008
        """Convert an index value to position details."""
2027
2009
        bits = node[2].split(' ')
2028
2010
        # It would be nice not to read the entire gzip.
2029
 
        # start and stop are put into _int_cache because they are very common.
2030
 
        # They define the 'group' that an entry is in, and many groups can have
2031
 
        # thousands of objects.
2032
 
        # Branching Launchpad, for example, saves ~600k integers, at 12 bytes
2033
 
        # each, or about 7MB. Note that it might be even more when you consider
2034
 
        # how PyInt is allocated in separate slabs. And you can't return a slab
2035
 
        # 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
2037
 
        # fragmentation.
2038
2011
        start = int(bits[0])
2039
 
        start = self._int_cache.setdefault(start, start)
2040
2012
        stop = int(bits[1])
2041
 
        stop = self._int_cache.setdefault(stop, stop)
2042
2013
        basis_end = int(bits[2])
2043
2014
        delta_end = int(bits[3])
2044
 
        # We can't use StaticTuple here, because node[0] is a BTreeGraphIndex
2045
 
        # instance...
2046
 
        return (node[0], start, stop, basis_end, delta_end)
 
2015
        return node[0], start, stop, basis_end, delta_end
2047
2016
 
2048
2017
    def scan_unvalidated_index(self, graph_index):
2049
2018
        """Inform this _GCGraphIndex that there is an unvalidated index.