~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/groupcompress.py

  • Committer: Jelmer Vernooij
  • Date: 2011-05-10 07:46:15 UTC
  • mfrom: (5844 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5845.
  • Revision ID: jelmer@samba.org-20110510074615-eptod049ndjxc4i7
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
except ImportError:
24
24
    pylzma = None
25
25
 
 
26
from bzrlib.lazy_import import lazy_import
 
27
lazy_import(globals(), """
26
28
from bzrlib import (
27
29
    annotate,
28
30
    debug,
29
31
    errors,
30
32
    graph as _mod_graph,
31
 
    knit,
32
33
    osutils,
33
34
    pack,
34
35
    static_tuple,
35
36
    trace,
 
37
    tsort,
36
38
    )
 
39
 
 
40
from bzrlib.repofmt import pack_repo
 
41
""")
 
42
 
37
43
from bzrlib.btree_index import BTreeBuilder
38
44
from bzrlib.lru_cache import LRUSizeCache
39
 
from bzrlib.tsort import topo_sort
40
45
from bzrlib.versionedfile import (
 
46
    _KeyRefs,
41
47
    adapter_registry,
42
48
    AbsentContentFactory,
43
49
    ChunkedContentFactory,
44
50
    FulltextContentFactory,
45
 
    VersionedFiles,
 
51
    VersionedFilesWithFallbacks,
46
52
    )
47
53
 
48
54
# Minimum number of uncompressed bytes to try fetch at once when retrieving
77
83
 
78
84
    present_keys = []
79
85
    for prefix in sorted(per_prefix_map):
80
 
        present_keys.extend(reversed(topo_sort(per_prefix_map[prefix])))
 
86
        present_keys.extend(reversed(tsort.topo_sort(per_prefix_map[prefix])))
81
87
    return present_keys
82
88
 
83
89
 
1046
1052
        index = _GCGraphIndex(graph_index, lambda:True, parents=parents,
1047
1053
            add_callback=graph_index.add_nodes,
1048
1054
            inconsistency_fatal=inconsistency_fatal)
1049
 
        access = knit._DirectPackAccess({})
 
1055
        access = pack_repo._DirectPackAccess({})
1050
1056
        access.set_writer(writer, graph_index, (transport, 'newpack'))
1051
1057
        result = GroupCompressVersionedFiles(index, access, delta)
1052
1058
        result.stream = stream
1168
1174
        self.total_bytes = 0
1169
1175
 
1170
1176
 
1171
 
class GroupCompressVersionedFiles(VersionedFiles):
 
1177
class GroupCompressVersionedFiles(VersionedFilesWithFallbacks):
1172
1178
    """A group-compress based VersionedFiles implementation."""
1173
1179
 
1174
 
    def __init__(self, index, access, delta=True, _unadded_refs=None):
 
1180
    def __init__(self, index, access, delta=True, _unadded_refs=None,
 
1181
            _group_cache=None):
1175
1182
        """Create a GroupCompressVersionedFiles object.
1176
1183
 
1177
1184
        :param index: The index object storing access and graph data.
1178
1185
        :param access: The access object storing raw data.
1179
1186
        :param delta: Whether to delta compress or just entropy compress.
1180
1187
        :param _unadded_refs: private parameter, don't use.
 
1188
        :param _group_cache: private parameter, don't use.
1181
1189
        """
1182
1190
        self._index = index
1183
1191
        self._access = access
1185
1193
        if _unadded_refs is None:
1186
1194
            _unadded_refs = {}
1187
1195
        self._unadded_refs = _unadded_refs
1188
 
        self._group_cache = LRUSizeCache(max_size=50*1024*1024)
 
1196
        if _group_cache is None:
 
1197
            _group_cache = LRUSizeCache(max_size=50*1024*1024)
 
1198
        self._group_cache = _group_cache
1189
1199
        self._immediate_fallback_vfs = []
1190
1200
 
1191
1201
    def without_fallbacks(self):
1192
1202
        """Return a clone of this object without any fallbacks configured."""
1193
1203
        return GroupCompressVersionedFiles(self._index, self._access,
1194
 
            self._delta, _unadded_refs=dict(self._unadded_refs))
 
1204
            self._delta, _unadded_refs=dict(self._unadded_refs),
 
1205
            _group_cache=self._group_cache)
1195
1206
 
1196
1207
    def add_lines(self, key, parents, lines, parent_texts=None,
1197
1208
        left_matching_blocks=None, nostore_sha=None, random_id=False,
1470
1481
            the defined order, regardless of source.
1471
1482
        """
1472
1483
        if ordering == 'topological':
1473
 
            present_keys = topo_sort(parent_map)
 
1484
            present_keys = tsort.topo_sort(parent_map)
1474
1485
        else:
1475
1486
            # ordering == 'groupcompress'
1476
1487
            # XXX: This only optimizes for the target ordering. We may need
1921
1932
        # repeated over and over, this creates a surplus of ints
1922
1933
        self._int_cache = {}
1923
1934
        if track_external_parent_refs:
1924
 
            self._key_dependencies = knit._KeyRefs(
 
1935
            self._key_dependencies = _KeyRefs(
1925
1936
                track_new_keys=track_new_keys)
1926
1937
        else:
1927
1938
            self._key_dependencies = None