/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5590.1.6 by John Arbash Meinel
Found another tuned_gzip use in weaverepo
1
# Copyright (C) 2007-2011 Canonical Ltd
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
16
2803.2.1 by Robert Collins
* CommitBuilder now advertises itself as requiring the root entry to be
17
"""Deprecated weave-based repository formats.
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
18
2803.2.1 by Robert Collins
* CommitBuilder now advertises itself as requiring the root entry to be
19
Weave based formats scaled linearly with history size and could not represent
20
ghosts.
21
"""
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
22
5590.1.6 by John Arbash Meinel
Found another tuned_gzip use in weaverepo
23
import gzip
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
24
import os
25
from cStringIO import StringIO
26
import urllib
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
27
3224.5.1 by Andrew Bennetts
Lots of assorted hackery to reduce the number of imports for common operations. Improves 'rocks', 'st' and 'help' times by ~50ms on my laptop.
28
from bzrlib.lazy_import import lazy_import
29
lazy_import(globals(), """
30
from bzrlib import (
31
    xml5,
4593.5.34 by John Arbash Meinel
Change the KnownGraph.merge_sort api.
32
    graph as _mod_graph,
5537.2.1 by Jelmer Vernooij
Move InterWeaveRepo and InterKnitRepo to related repository files.
33
    ui,
3224.5.1 by Andrew Bennetts
Lots of assorted hackery to reduce the number of imports for common operations. Improves 'rocks', 'st' and 'help' times by ~50ms on my laptop.
34
    )
35
""")
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
36
from bzrlib import (
37
    bzrdir,
2850.3.1 by Robert Collins
Move various weave specific code out of the base Repository class to weaverepo.py.
38
    debug,
39
    errors,
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
40
    lockable_files,
41
    lockdir,
2803.2.1 by Robert Collins
* CommitBuilder now advertises itself as requiring the root entry to be
42
    osutils,
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
43
    trace,
5590.1.6 by John Arbash Meinel
Found another tuned_gzip use in weaverepo
44
    tuned_gzip,
3834.2.2 by Martin Pool
Deprecated LockableFiles._escape
45
    urlutils,
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
46
    versionedfile,
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
47
    weave,
48
    weavefile,
3224.5.4 by Andrew Bennetts
Fix test suite, mainly weeding out uses of bzrlib.user_encoding.
49
    )
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
50
from bzrlib.decorators import needs_read_lock, needs_write_lock
51
from bzrlib.repository import (
2803.2.1 by Robert Collins
* CommitBuilder now advertises itself as requiring the root entry to be
52
    CommitBuilder,
5537.2.1 by Jelmer Vernooij
Move InterWeaveRepo and InterKnitRepo to related repository files.
53
    InterRepository,
54
    InterSameDataRepository,
3316.2.3 by Robert Collins
Remove manual notification of transaction finishing on versioned files.
55
    MetaDirVersionedFileRepository,
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
56
    MetaDirRepositoryFormat,
57
    Repository,
58
    RepositoryFormat,
59
    )
60
from bzrlib.store.text import TextStore
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
61
from bzrlib.versionedfile import (
62
    AbsentContentFactory,
63
    FulltextContentFactory,
64
    VersionedFiles,
65
    )
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
66
67
68
class AllInOneRepository(Repository):
69
    """Legacy support - the repository behaviour for all-in-one branches."""
70
3224.5.1 by Andrew Bennetts
Lots of assorted hackery to reduce the number of imports for common operations. Improves 'rocks', 'st' and 'help' times by ~50ms on my laptop.
71
    @property
72
    def _serializer(self):
73
        return xml5.serializer_v5
2241.1.8 by Martin Pool
Set the repository's serializer in the places it's needed, not in the base class
74
3834.2.2 by Martin Pool
Deprecated LockableFiles._escape
75
    def _escape(self, file_or_path):
76
        if not isinstance(file_or_path, basestring):
77
            file_or_path = '/'.join(file_or_path)
78
        if file_or_path == '':
79
            return u''
80
        return urlutils.escape(osutils.safe_unicode(file_or_path))
81
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
82
    def __init__(self, _format, a_bzrdir):
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
83
        # we reuse one control files instance.
3416.2.3 by Martin Pool
typo
84
        dir_mode = a_bzrdir._get_dir_mode()
85
        file_mode = a_bzrdir._get_file_mode()
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
86
87
        def get_store(name, compressed=True, prefixed=False):
88
            # FIXME: This approach of assuming stores are all entirely compressed
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
89
            # or entirely uncompressed is tidy, but breaks upgrade from
90
            # some existing branches where there's a mixture; we probably
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
91
            # still want the option to look for both.
3834.2.2 by Martin Pool
Deprecated LockableFiles._escape
92
            relpath = self._escape(name)
3407.2.13 by Martin Pool
Remove indirection through control_files to get transports
93
            store = TextStore(a_bzrdir.transport.clone(relpath),
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
94
                              prefixed=prefixed, compressed=compressed,
95
                              dir_mode=dir_mode,
96
                              file_mode=file_mode)
97
            return store
98
99
        # not broken out yet because the controlweaves|inventory_store
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
100
        # and texts bits are still different.
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
101
        if isinstance(_format, RepositoryFormat4):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
102
            # cannot remove these - there is still no consistent api
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
103
            # which allows access to this old info.
104
            self.inventory_store = get_store('inventory-store')
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
105
            self._text_store = get_store('text-store')
106
        super(AllInOneRepository, self).__init__(_format, a_bzrdir, a_bzrdir._control_files)
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
107
2850.3.1 by Robert Collins
Move various weave specific code out of the base Repository class to weaverepo.py.
108
    @needs_read_lock
109
    def _all_possible_ids(self):
110
        """Return all the possible revisions that we could find."""
111
        if 'evil' in debug.debug_flags:
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
112
            trace.mutter_callsite(
113
                3, "_all_possible_ids scales with size of history.")
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
114
        return [key[-1] for key in self.inventories.keys()]
2850.3.1 by Robert Collins
Move various weave specific code out of the base Repository class to weaverepo.py.
115
116
    @needs_read_lock
117
    def _all_revision_ids(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
118
        """Returns a list of all the revision ids in the repository.
2850.3.1 by Robert Collins
Move various weave specific code out of the base Repository class to weaverepo.py.
119
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
120
        These are in as much topological order as the underlying store can
2850.3.1 by Robert Collins
Move various weave specific code out of the base Repository class to weaverepo.py.
121
        present: for weaves ghosts may lead to a lack of correctness until
122
        the reweave updates the parents list.
123
        """
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
124
        return [key[-1] for key in self.revisions.keys()]
125
126
    def _activate_new_inventory(self):
127
        """Put a replacement inventory.new into use as inventories."""
128
        # Copy the content across
129
        t = self.bzrdir._control_files._transport
130
        t.copy('inventory.new.weave', 'inventory.weave')
131
        # delete the temp inventory
132
        t.delete('inventory.new.weave')
133
        # Check we can parse the new weave properly as a sanity check
134
        self.inventories.keys()
135
136
    def _backup_inventory(self):
137
        t = self.bzrdir._control_files._transport
138
        t.copy('inventory.weave', 'inventory.backup.weave')
139
140
    def _temp_inventories(self):
141
        t = self.bzrdir._control_files._transport
142
        return self._format._get_inventories(t, self, 'inventory.new')
2850.3.1 by Robert Collins
Move various weave specific code out of the base Repository class to weaverepo.py.
143
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
144
    def get_commit_builder(self, branch, parents, config, timestamp=None,
145
                           timezone=None, committer=None, revprops=None,
146
                           revision_id=None):
147
        self._check_ascii_revisionid(revision_id, self.get_commit_builder)
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
148
        result = CommitBuilder(self, parents, config, timestamp, timezone,
2803.2.1 by Robert Collins
* CommitBuilder now advertises itself as requiring the root entry to be
149
                              committer, revprops, revision_id)
150
        self.start_write_group()
151
        return result
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
152
153
    @needs_read_lock
2850.3.1 by Robert Collins
Move various weave specific code out of the base Repository class to weaverepo.py.
154
    def get_revisions(self, revision_ids):
155
        revs = self._get_revisions(revision_ids)
156
        return revs
157
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
158
    def _inventory_add_lines(self, revision_id, parents, lines,
159
        check_content=True):
160
        """Store lines in inv_vf and return the sha1 of the inventory."""
161
        present_parents = self.get_graph().get_parent_map(parents)
162
        final_parents = []
163
        for parent in parents:
164
            if parent in present_parents:
165
                final_parents.append((parent,))
166
        return self.inventories.add_lines((revision_id,), final_parents, lines,
167
            check_content=check_content)[0]
3172.3.1 by Robert Collins
Repository has a new method ``has_revisions`` which signals the presence
168
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
169
    def is_shared(self):
170
        """AllInOne repositories cannot be shared."""
171
        return False
172
173
    @needs_write_lock
174
    def set_make_working_trees(self, new_value):
175
        """Set the policy flag for making working trees when creating branches.
176
177
        This only applies to branches that use this repository.
178
179
        The default is 'True'.
180
        :param new_value: True to restore the default, False to disable making
181
                          working trees.
182
        """
5158.6.10 by Martin Pool
Update more code to use user_transport when it should
183
        raise errors.RepositoryUpgradeRequired(self.user_url)
3349.1.1 by Aaron Bentley
Enable setting and getting make_working_trees for all repositories
184
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
185
    def make_working_trees(self):
186
        """Returns the policy for making working trees on new branches."""
187
        return True
188
2819.2.4 by Andrew Bennetts
Add a 'revision_graph_can_have_wrong_parents' method to repository.
189
    def revision_graph_can_have_wrong_parents(self):
190
        # XXX: This is an old format that we don't support full checking on, so
191
        # just claim that checking for this inconsistency is not required.
192
        return False
193
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
194
3316.2.3 by Robert Collins
Remove manual notification of transaction finishing on versioned files.
195
class WeaveMetaDirRepository(MetaDirVersionedFileRepository):
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
196
    """A subclass of MetaDirRepository to set weave specific policy."""
197
3565.3.1 by Robert Collins
* The generic fetch code now uses two attributes on Repository objects
198
    def __init__(self, _format, a_bzrdir, control_files):
199
        super(WeaveMetaDirRepository, self).__init__(_format, a_bzrdir, control_files)
4022.1.1 by Robert Collins
Refactoring of fetch to have a sender and sink component enabling splitting the logic over a network stream. (Robert Collins, Andrew Bennetts)
200
        self._serializer = _format._serializer
3565.3.1 by Robert Collins
* The generic fetch code now uses two attributes on Repository objects
201
2850.3.1 by Robert Collins
Move various weave specific code out of the base Repository class to weaverepo.py.
202
    @needs_read_lock
203
    def _all_possible_ids(self):
204
        """Return all the possible revisions that we could find."""
205
        if 'evil' in debug.debug_flags:
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
206
            trace.mutter_callsite(
207
                3, "_all_possible_ids scales with size of history.")
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
208
        return [key[-1] for key in self.inventories.keys()]
2850.3.1 by Robert Collins
Move various weave specific code out of the base Repository class to weaverepo.py.
209
210
    @needs_read_lock
211
    def _all_revision_ids(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
212
        """Returns a list of all the revision ids in the repository.
2850.3.1 by Robert Collins
Move various weave specific code out of the base Repository class to weaverepo.py.
213
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
214
        These are in as much topological order as the underlying store can
2850.3.1 by Robert Collins
Move various weave specific code out of the base Repository class to weaverepo.py.
215
        present: for weaves ghosts may lead to a lack of correctness until
216
        the reweave updates the parents list.
217
        """
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
218
        return [key[-1] for key in self.revisions.keys()]
219
220
    def _activate_new_inventory(self):
221
        """Put a replacement inventory.new into use as inventories."""
222
        # Copy the content across
223
        t = self._transport
224
        t.copy('inventory.new.weave', 'inventory.weave')
225
        # delete the temp inventory
226
        t.delete('inventory.new.weave')
227
        # Check we can parse the new weave properly as a sanity check
228
        self.inventories.keys()
229
230
    def _backup_inventory(self):
231
        t = self._transport
232
        t.copy('inventory.weave', 'inventory.backup.weave')
233
234
    def _temp_inventories(self):
235
        t = self._transport
236
        return self._format._get_inventories(t, self, 'inventory.new')
2850.3.1 by Robert Collins
Move various weave specific code out of the base Repository class to weaverepo.py.
237
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
238
    def get_commit_builder(self, branch, parents, config, timestamp=None,
239
                           timezone=None, committer=None, revprops=None,
240
                           revision_id=None):
241
        self._check_ascii_revisionid(revision_id, self.get_commit_builder)
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
242
        result = CommitBuilder(self, parents, config, timestamp, timezone,
2803.2.1 by Robert Collins
* CommitBuilder now advertises itself as requiring the root entry to be
243
                              committer, revprops, revision_id)
244
        self.start_write_group()
245
        return result
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
246
2850.3.1 by Robert Collins
Move various weave specific code out of the base Repository class to weaverepo.py.
247
    @needs_read_lock
248
    def get_revision(self, revision_id):
249
        """Return the Revision object for a named revision"""
250
        r = self.get_revision_reconcile(revision_id)
251
        return r
252
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
253
    def _inventory_add_lines(self, revision_id, parents, lines,
254
        check_content=True):
255
        """Store lines in inv_vf and return the sha1 of the inventory."""
256
        present_parents = self.get_graph().get_parent_map(parents)
257
        final_parents = []
258
        for parent in parents:
259
            if parent in present_parents:
260
                final_parents.append((parent,))
261
        return self.inventories.add_lines((revision_id,), final_parents, lines,
262
            check_content=check_content)[0]
3172.3.1 by Robert Collins
Repository has a new method ``has_revisions`` which signals the presence
263
2819.2.4 by Andrew Bennetts
Add a 'revision_graph_can_have_wrong_parents' method to repository.
264
    def revision_graph_can_have_wrong_parents(self):
265
        return False
266
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
267
268
class PreSplitOutRepositoryFormat(RepositoryFormat):
269
    """Base class for the pre split out repository formats."""
270
271
    rich_root_data = False
2323.5.17 by Martin Pool
Add supports_tree_reference to all repo formats (robert)
272
    supports_tree_reference = False
2949.1.2 by Robert Collins
* Fetch with pack repositories will no longer read the entire history graph.
273
    supports_ghosts = False
3221.3.1 by Robert Collins
* Repository formats have a new supported-feature attribute
274
    supports_external_lookups = False
4246.2.1 by Ian Clatworthy
supports_chks flag on repo formats & log tuning
275
    supports_chks = False
4053.1.4 by Robert Collins
Move the fetch control attributes from Repository to RepositoryFormat.
276
    _fetch_order = 'topological'
277
    _fetch_reconcile = True
4183.5.1 by Robert Collins
Add RepositoryFormat.fast_deltas to signal fast delta creation.
278
    fast_deltas = False
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
279
280
    def initialize(self, a_bzrdir, shared=False, _internal=False):
2949.1.2 by Robert Collins
* Fetch with pack repositories will no longer read the entire history graph.
281
        """Create a weave repository."""
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
282
        if shared:
283
            raise errors.IncompatibleFormat(self, a_bzrdir._format)
284
285
        if not _internal:
286
            # always initialized when the bzrdir is.
287
            return self.open(a_bzrdir, _found=True)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
288
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
289
        # Create an empty weave
290
        sio = StringIO()
291
        weavefile.write_weave_v5(weave.Weave(), sio)
292
        empty_weave = sio.getvalue()
293
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
294
        trace.mutter('creating repository in %s.', a_bzrdir.transport.base)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
295
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
296
        # FIXME: RBC 20060125 don't peek under the covers
297
        # NB: no need to escape relative paths that are url safe.
298
        control_files = lockable_files.LockableFiles(a_bzrdir.transport,
3407.2.4 by Martin Pool
Small cleanups to initial creation of repository files
299
            'branch-lock', lockable_files.TransportLock)
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
300
        control_files.create_lock()
301
        control_files.lock_write()
3407.2.13 by Martin Pool
Remove indirection through control_files to get transports
302
        transport = a_bzrdir.transport
3407.2.4 by Martin Pool
Small cleanups to initial creation of repository files
303
        try:
304
            transport.mkdir_multi(['revision-store', 'weaves'],
3407.2.18 by Martin Pool
BzrDir takes responsibility for default file/dir modes
305
                mode=a_bzrdir._get_dir_mode())
306
            transport.put_bytes_non_atomic('inventory.weave', empty_weave,
307
                mode=a_bzrdir._get_file_mode())
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
308
        finally:
309
            control_files.unlock()
5107.3.1 by Marco Pantaleoni
Added the new hooks 'post_branch', 'post_switch' and 'post_repo_init',
310
        repository = self.open(a_bzrdir, _found=True)
311
        self._run_post_repo_init_hooks(repository, a_bzrdir, shared)
312
        return repository
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
313
314
    def open(self, a_bzrdir, _found=False):
315
        """See RepositoryFormat.open()."""
316
        if not _found:
317
            # we are being called directly and must probe.
318
            raise NotImplementedError
319
320
        repo_transport = a_bzrdir.get_repository_transport(None)
321
        control_files = a_bzrdir._control_files
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
322
        result = AllInOneRepository(_format=self, a_bzrdir=a_bzrdir)
323
        result.revisions = self._get_revisions(repo_transport, result)
324
        result.signatures = self._get_signatures(repo_transport, result)
325
        result.inventories = self._get_inventories(repo_transport, result)
326
        result.texts = self._get_texts(repo_transport, result)
4246.2.1 by Ian Clatworthy
supports_chks flag on repo formats & log tuning
327
        result.chk_bytes = None
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
328
        return result
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
329
330
331
class RepositoryFormat4(PreSplitOutRepositoryFormat):
332
    """Bzr repository format 4.
333
334
    This repository format has:
335
     - flat stores
336
     - TextStores for texts, inventories,revisions.
337
338
    This format is deprecated: it indexes texts using a text id which is
339
    removed in format 5; initialization and write support for this format
340
    has been removed.
341
    """
342
2241.1.11 by Martin Pool
Get rid of RepositoryFormat*_instance objects. Instead the format
343
    _matchingbzrdir = bzrdir.BzrDirFormat4()
344
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
345
    def get_format_description(self):
346
        """See RepositoryFormat.get_format_description()."""
347
        return "Repository format 4"
348
349
    def initialize(self, url, shared=False, _internal=False):
350
        """Format 4 branches cannot be created."""
351
        raise errors.UninitializableFormat(self)
352
353
    def is_supported(self):
354
        """Format 4 is not supported.
355
356
        It is not supported because the model changed from 4 to 5 and the
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
357
        conversion logic is expensive - so doing it on the fly was not
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
358
        feasible.
359
        """
360
        return False
361
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
362
    def _get_inventories(self, repo_transport, repo, name='inventory'):
363
        # No inventories store written so far.
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
364
        return None
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
365
366
    def _get_revisions(self, repo_transport, repo):
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
367
        from bzrlib.xml4 import serializer_v4
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
368
        return RevisionTextStore(repo_transport.clone('revision-store'),
369
            serializer_v4, True, versionedfile.PrefixMapper(),
370
            repo.is_locked, repo.is_write_locked)
371
372
    def _get_signatures(self, repo_transport, repo):
373
        return SignatureTextStore(repo_transport.clone('revision-store'),
374
            False, versionedfile.PrefixMapper(),
375
            repo.is_locked, repo.is_write_locked)
376
377
    def _get_texts(self, repo_transport, repo):
378
        return None
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
379
380
381
class RepositoryFormat5(PreSplitOutRepositoryFormat):
382
    """Bzr control format 5.
383
384
    This repository format has:
385
     - weaves for file texts and inventory
386
     - flat stores
387
     - TextStores for revisions and signatures.
388
    """
389
2241.1.10 by Martin Pool
Remove more references to weaves from the repository.py file
390
    _versionedfile_class = weave.WeaveFile
2241.1.11 by Martin Pool
Get rid of RepositoryFormat*_instance objects. Instead the format
391
    _matchingbzrdir = bzrdir.BzrDirFormat5()
4022.1.1 by Robert Collins
Refactoring of fetch to have a sender and sink component enabling splitting the logic over a network stream. (Robert Collins, Andrew Bennetts)
392
    @property
393
    def _serializer(self):
394
        return xml5.serializer_v5
2241.1.10 by Martin Pool
Remove more references to weaves from the repository.py file
395
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
396
    def get_format_description(self):
397
        """See RepositoryFormat.get_format_description()."""
398
        return "Weave repository format 5"
4032.1.2 by John Arbash Meinel
Track down a few more files that have trailing whitespace.
399
3990.5.1 by Andrew Bennetts
Add network_name() to RepositoryFormat.
400
    def network_name(self):
3990.5.3 by Robert Collins
Docs and polish on RepositoryFormat.network_name.
401
        """The network name for this format is the control dirs disk label."""
3990.5.1 by Andrew Bennetts
Add network_name() to RepositoryFormat.
402
        return self._matchingbzrdir.get_format_string()
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
403
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
404
    def _get_inventories(self, repo_transport, repo, name='inventory'):
405
        mapper = versionedfile.ConstantMapper(name)
406
        return versionedfile.ThunkedVersionedFiles(repo_transport,
407
            weave.WeaveFile, mapper, repo.is_locked)
408
409
    def _get_revisions(self, repo_transport, repo):
410
        return RevisionTextStore(repo_transport.clone('revision-store'),
4022.1.1 by Robert Collins
Refactoring of fetch to have a sender and sink component enabling splitting the logic over a network stream. (Robert Collins, Andrew Bennetts)
411
            xml5.serializer_v5, False, versionedfile.PrefixMapper(),
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
412
            repo.is_locked, repo.is_write_locked)
413
414
    def _get_signatures(self, repo_transport, repo):
415
        return SignatureTextStore(repo_transport.clone('revision-store'),
416
            False, versionedfile.PrefixMapper(),
417
            repo.is_locked, repo.is_write_locked)
418
419
    def _get_texts(self, repo_transport, repo):
420
        mapper = versionedfile.PrefixMapper()
421
        base_transport = repo_transport.clone('weaves')
422
        return versionedfile.ThunkedVersionedFiles(base_transport,
423
            weave.WeaveFile, mapper, repo.is_locked)
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
424
425
426
class RepositoryFormat6(PreSplitOutRepositoryFormat):
427
    """Bzr control format 6.
428
429
    This repository format has:
430
     - weaves for file texts and inventory
431
     - hash subdirectory based stores.
432
     - TextStores for revisions and signatures.
433
    """
434
2241.1.10 by Martin Pool
Remove more references to weaves from the repository.py file
435
    _versionedfile_class = weave.WeaveFile
2241.1.11 by Martin Pool
Get rid of RepositoryFormat*_instance objects. Instead the format
436
    _matchingbzrdir = bzrdir.BzrDirFormat6()
4022.1.1 by Robert Collins
Refactoring of fetch to have a sender and sink component enabling splitting the logic over a network stream. (Robert Collins, Andrew Bennetts)
437
    @property
438
    def _serializer(self):
439
        return xml5.serializer_v5
2241.1.10 by Martin Pool
Remove more references to weaves from the repository.py file
440
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
441
    def get_format_description(self):
442
        """See RepositoryFormat.get_format_description()."""
443
        return "Weave repository format 6"
444
3990.5.1 by Andrew Bennetts
Add network_name() to RepositoryFormat.
445
    def network_name(self):
3990.5.3 by Robert Collins
Docs and polish on RepositoryFormat.network_name.
446
        """The network name for this format is the control dirs disk label."""
3990.5.1 by Andrew Bennetts
Add network_name() to RepositoryFormat.
447
        return self._matchingbzrdir.get_format_string()
448
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
449
    def _get_inventories(self, repo_transport, repo, name='inventory'):
450
        mapper = versionedfile.ConstantMapper(name)
451
        return versionedfile.ThunkedVersionedFiles(repo_transport,
452
            weave.WeaveFile, mapper, repo.is_locked)
453
454
    def _get_revisions(self, repo_transport, repo):
455
        return RevisionTextStore(repo_transport.clone('revision-store'),
4022.1.1 by Robert Collins
Refactoring of fetch to have a sender and sink component enabling splitting the logic over a network stream. (Robert Collins, Andrew Bennetts)
456
            xml5.serializer_v5, False, versionedfile.HashPrefixMapper(),
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
457
            repo.is_locked, repo.is_write_locked)
458
459
    def _get_signatures(self, repo_transport, repo):
460
        return SignatureTextStore(repo_transport.clone('revision-store'),
461
            False, versionedfile.HashPrefixMapper(),
462
            repo.is_locked, repo.is_write_locked)
463
464
    def _get_texts(self, repo_transport, repo):
465
        mapper = versionedfile.HashPrefixMapper()
466
        base_transport = repo_transport.clone('weaves')
467
        return versionedfile.ThunkedVersionedFiles(base_transport,
468
            weave.WeaveFile, mapper, repo.is_locked)
469
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
470
471
class RepositoryFormat7(MetaDirRepositoryFormat):
472
    """Bzr repository 7.
473
474
    This repository format has:
475
     - weaves for file texts and inventory
476
     - hash subdirectory based stores.
477
     - TextStores for revisions and signatures.
478
     - a format marker of its own
479
     - an optional 'shared-storage' flag
480
     - an optional 'no-working-trees' flag
481
    """
482
2241.1.10 by Martin Pool
Remove more references to weaves from the repository.py file
483
    _versionedfile_class = weave.WeaveFile
2949.1.2 by Robert Collins
* Fetch with pack repositories will no longer read the entire history graph.
484
    supports_ghosts = False
4246.2.1 by Ian Clatworthy
supports_chks flag on repo formats & log tuning
485
    supports_chks = False
486
4053.1.4 by Robert Collins
Move the fetch control attributes from Repository to RepositoryFormat.
487
    _fetch_order = 'topological'
488
    _fetch_reconcile = True
4183.5.1 by Robert Collins
Add RepositoryFormat.fast_deltas to signal fast delta creation.
489
    fast_deltas = False
4022.1.1 by Robert Collins
Refactoring of fetch to have a sender and sink component enabling splitting the logic over a network stream. (Robert Collins, Andrew Bennetts)
490
    @property
491
    def _serializer(self):
492
        return xml5.serializer_v5
2241.1.10 by Martin Pool
Remove more references to weaves from the repository.py file
493
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
494
    def get_format_string(self):
495
        """See RepositoryFormat.get_format_string()."""
496
        return "Bazaar-NG Repository format 7"
497
498
    def get_format_description(self):
499
        """See RepositoryFormat.get_format_description()."""
500
        return "Weave repository format 7"
501
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
502
    def _get_inventories(self, repo_transport, repo, name='inventory'):
503
        mapper = versionedfile.ConstantMapper(name)
504
        return versionedfile.ThunkedVersionedFiles(repo_transport,
505
            weave.WeaveFile, mapper, repo.is_locked)
506
507
    def _get_revisions(self, repo_transport, repo):
508
        return RevisionTextStore(repo_transport.clone('revision-store'),
4022.1.1 by Robert Collins
Refactoring of fetch to have a sender and sink component enabling splitting the logic over a network stream. (Robert Collins, Andrew Bennetts)
509
            xml5.serializer_v5, True, versionedfile.HashPrefixMapper(),
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
510
            repo.is_locked, repo.is_write_locked)
511
512
    def _get_signatures(self, repo_transport, repo):
513
        return SignatureTextStore(repo_transport.clone('revision-store'),
514
            True, versionedfile.HashPrefixMapper(),
515
            repo.is_locked, repo.is_write_locked)
516
517
    def _get_texts(self, repo_transport, repo):
518
        mapper = versionedfile.HashPrefixMapper()
519
        base_transport = repo_transport.clone('weaves')
520
        return versionedfile.ThunkedVersionedFiles(base_transport,
521
            weave.WeaveFile, mapper, repo.is_locked)
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
522
523
    def initialize(self, a_bzrdir, shared=False):
524
        """Create a weave repository.
525
526
        :param shared: If true the repository will be initialized as a shared
527
                       repository.
528
        """
529
        # Create an empty weave
530
        sio = StringIO()
531
        weavefile.write_weave_v5(weave.Weave(), sio)
532
        empty_weave = sio.getvalue()
533
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
534
        trace.mutter('creating repository in %s.', a_bzrdir.transport.base)
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
535
        dirs = ['revision-store', 'weaves']
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
536
        files = [('inventory.weave', StringIO(empty_weave)),
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
537
                 ]
538
        utf8_files = [('format', self.get_format_string())]
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
539
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
540
        self._upload_blank_content(a_bzrdir, dirs, files, utf8_files, shared)
541
        return self.open(a_bzrdir=a_bzrdir, _found=True)
542
543
    def open(self, a_bzrdir, _found=False, _override_transport=None):
544
        """See RepositoryFormat.open().
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
545
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
546
        :param _override_transport: INTERNAL USE ONLY. Allows opening the
547
                                    repository at a slightly different url
548
                                    than normal. I.e. during 'upgrade'.
549
        """
550
        if not _found:
551
            format = RepositoryFormat.find_format(a_bzrdir)
552
        if _override_transport is not None:
553
            repo_transport = _override_transport
554
        else:
555
            repo_transport = a_bzrdir.get_repository_transport(None)
556
        control_files = lockable_files.LockableFiles(repo_transport,
557
                                'lock', lockdir.LockDir)
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
558
        result = WeaveMetaDirRepository(_format=self, a_bzrdir=a_bzrdir,
559
            control_files=control_files)
560
        result.revisions = self._get_revisions(repo_transport, result)
561
        result.signatures = self._get_signatures(repo_transport, result)
562
        result.inventories = self._get_inventories(repo_transport, result)
563
        result.texts = self._get_texts(repo_transport, result)
4246.2.1 by Ian Clatworthy
supports_chks flag on repo formats & log tuning
564
        result.chk_bytes = None
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
565
        result._transport = repo_transport
566
        return result
567
568
569
class TextVersionedFiles(VersionedFiles):
570
    """Just-a-bunch-of-files based VersionedFile stores."""
571
572
    def __init__(self, transport, compressed, mapper, is_locked, can_write):
573
        self._compressed = compressed
574
        self._transport = transport
575
        self._mapper = mapper
576
        if self._compressed:
577
            self._ext = '.gz'
578
        else:
579
            self._ext = ''
580
        self._is_locked = is_locked
581
        self._can_write = can_write
582
583
    def add_lines(self, key, parents, lines):
584
        """Add a revision to the store."""
585
        if not self._is_locked():
586
            raise errors.ObjectNotLocked(self)
587
        if not self._can_write():
588
            raise errors.ReadOnlyError(self)
589
        if '/' in key[-1]:
3350.6.10 by Martin Pool
VersionedFiles review cleanups
590
            raise ValueError('bad idea to put / in %r' % (key,))
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
591
        text = ''.join(lines)
592
        if self._compressed:
5590.1.6 by John Arbash Meinel
Found another tuned_gzip use in weaverepo
593
            text = tuned_gzip.bytes_to_gzip(text)
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
594
        path = self._map(key)
595
        self._transport.put_bytes_non_atomic(path, text, create_parent_dir=True)
596
5195.3.26 by Parth Malwankar
reverted changes done to insert_record_stream API
597
    def insert_record_stream(self, stream):
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
598
        adapters = {}
599
        for record in stream:
600
            # Raise an error when a record is missing.
601
            if record.storage_kind == 'absent':
602
                raise errors.RevisionNotPresent([record.key[0]], self)
603
            # adapt to non-tuple interface
604
            if record.storage_kind == 'fulltext':
605
                self.add_lines(record.key, None,
606
                    osutils.split_lines(record.get_bytes_as('fulltext')))
607
            else:
608
                adapter_key = record.storage_kind, 'fulltext'
609
                try:
610
                    adapter = adapters[adapter_key]
611
                except KeyError:
612
                    adapter_factory = adapter_registry.get(adapter_key)
613
                    adapter = adapter_factory(self)
614
                    adapters[adapter_key] = adapter
615
                lines = osutils.split_lines(adapter.get_bytes(
616
                    record, record.get_bytes_as(record.storage_kind)))
617
                try:
618
                    self.add_lines(record.key, None, lines)
619
                except RevisionAlreadyPresent:
620
                    pass
621
622
    def _load_text(self, key):
623
        if not self._is_locked():
624
            raise errors.ObjectNotLocked(self)
625
        path = self._map(key)
626
        try:
627
            text = self._transport.get_bytes(path)
628
            compressed = self._compressed
629
        except errors.NoSuchFile:
630
            if self._compressed:
631
                # try without the .gz
632
                path = path[:-3]
633
                try:
634
                    text = self._transport.get_bytes(path)
635
                    compressed = False
636
                except errors.NoSuchFile:
637
                    return None
638
            else:
639
                return None
640
        if compressed:
5590.1.6 by John Arbash Meinel
Found another tuned_gzip use in weaverepo
641
            text = gzip.GzipFile(mode='rb', fileobj=StringIO(text)).read()
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
642
        return text
643
644
    def _map(self, key):
645
        return self._mapper.map(key) + self._ext
646
647
648
class RevisionTextStore(TextVersionedFiles):
649
    """Legacy thunk for format 4 repositories."""
650
651
    def __init__(self, transport, serializer, compressed, mapper, is_locked,
652
        can_write):
653
        """Create a RevisionTextStore at transport with serializer."""
654
        TextVersionedFiles.__init__(self, transport, compressed, mapper,
655
            is_locked, can_write)
656
        self._serializer = serializer
657
658
    def _load_text_parents(self, key):
659
        text = self._load_text(key)
660
        if text is None:
661
            return None, None
662
        parents = self._serializer.read_revision_from_string(text).parent_ids
663
        return text, tuple((parent,) for parent in parents)
664
665
    def get_parent_map(self, keys):
666
        result = {}
667
        for key in keys:
668
            parents = self._load_text_parents(key)[1]
669
            if parents is None:
670
                continue
671
            result[key] = parents
672
        return result
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
673
4593.5.34 by John Arbash Meinel
Change the KnownGraph.merge_sort api.
674
    def get_known_graph_ancestry(self, keys):
675
        """Get a KnownGraph instance with the ancestry of keys."""
676
        keys = self.keys()
677
        parent_map = self.get_parent_map(keys)
678
        kg = _mod_graph.KnownGraph(parent_map)
679
        return kg
680
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
681
    def get_record_stream(self, keys, sort_order, include_delta_closure):
682
        for key in keys:
683
            text, parents = self._load_text_parents(key)
684
            if text is None:
685
                yield AbsentContentFactory(key)
686
            else:
687
                yield FulltextContentFactory(key, parents, None, text)
688
689
    def keys(self):
690
        if not self._is_locked():
691
            raise errors.ObjectNotLocked(self)
692
        relpaths = set()
693
        for quoted_relpath in self._transport.iter_files_recursive():
694
            relpath = urllib.unquote(quoted_relpath)
695
            path, ext = os.path.splitext(relpath)
696
            if ext == '.gz':
697
                relpath = path
4695.2.1 by Vincent Ladeuil
Align RevisionTextStore and SignatureTextStore keys() definitions.
698
            if not relpath.endswith('.sig'):
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
699
                relpaths.add(relpath)
700
        paths = list(relpaths)
701
        return set([self._mapper.unmap(path) for path in paths])
702
703
704
class SignatureTextStore(TextVersionedFiles):
705
    """Legacy thunk for format 4-7 repositories."""
706
707
    def __init__(self, transport, compressed, mapper, is_locked, can_write):
708
        TextVersionedFiles.__init__(self, transport, compressed, mapper,
709
            is_locked, can_write)
710
        self._ext = '.sig' + self._ext
711
712
    def get_parent_map(self, keys):
713
        result = {}
714
        for key in keys:
715
            text = self._load_text(key)
716
            if text is None:
717
                continue
718
            result[key] = None
719
        return result
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
720
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
721
    def get_record_stream(self, keys, sort_order, include_delta_closure):
722
        for key in keys:
723
            text = self._load_text(key)
724
            if text is None:
725
                yield AbsentContentFactory(key)
726
            else:
727
                yield FulltextContentFactory(key, None, None, text)
728
729
    def keys(self):
730
        if not self._is_locked():
731
            raise errors.ObjectNotLocked(self)
732
        relpaths = set()
733
        for quoted_relpath in self._transport.iter_files_recursive():
734
            relpath = urllib.unquote(quoted_relpath)
735
            path, ext = os.path.splitext(relpath)
736
            if ext == '.gz':
737
                relpath = path
738
            if not relpath.endswith('.sig'):
739
                continue
740
            relpaths.add(relpath[:-4])
741
        paths = list(relpaths)
742
        return set([self._mapper.unmap(path) for path in paths])
2803.2.1 by Robert Collins
* CommitBuilder now advertises itself as requiring the root entry to be
743
5537.2.1 by Jelmer Vernooij
Move InterWeaveRepo and InterKnitRepo to related repository files.
744
745
class InterWeaveRepo(InterSameDataRepository):
746
    """Optimised code paths between Weave based repositories.
747
    """
748
749
    @classmethod
750
    def _get_repo_format_to_test(self):
751
        return RepositoryFormat7()
752
753
    @staticmethod
754
    def is_compatible(source, target):
755
        """Be compatible with known Weave formats.
756
757
        We don't test for the stores being of specific types because that
758
        could lead to confusing results, and there is no need to be
759
        overly general.
760
        """
761
        try:
762
            return (isinstance(source._format, (RepositoryFormat5,
763
                                                RepositoryFormat6,
764
                                                RepositoryFormat7)) and
765
                    isinstance(target._format, (RepositoryFormat5,
766
                                                RepositoryFormat6,
767
                                                RepositoryFormat7)))
768
        except AttributeError:
769
            return False
770
771
    @needs_write_lock
772
    def copy_content(self, revision_id=None):
773
        """See InterRepository.copy_content()."""
774
        # weave specific optimised path:
775
        try:
776
            self.target.set_make_working_trees(self.source.make_working_trees())
777
        except (errors.RepositoryUpgradeRequired, NotImplemented):
778
            pass
779
        # FIXME do not peek!
780
        if self.source._transport.listable():
781
            pb = ui.ui_factory.nested_progress_bar()
782
            try:
783
                self.target.texts.insert_record_stream(
784
                    self.source.texts.get_record_stream(
785
                        self.source.texts.keys(), 'topological', False))
786
                pb.update('Copying inventory', 0, 1)
787
                self.target.inventories.insert_record_stream(
788
                    self.source.inventories.get_record_stream(
789
                        self.source.inventories.keys(), 'topological', False))
790
                self.target.signatures.insert_record_stream(
791
                    self.source.signatures.get_record_stream(
792
                        self.source.signatures.keys(),
793
                        'unordered', True))
794
                self.target.revisions.insert_record_stream(
795
                    self.source.revisions.get_record_stream(
796
                        self.source.revisions.keys(),
797
                        'topological', True))
798
            finally:
799
                pb.finished()
800
        else:
801
            self.target.fetch(self.source, revision_id=revision_id)
802
803
    @needs_read_lock
804
    def search_missing_revision_ids(self, revision_id=None, find_ghosts=True):
805
        """See InterRepository.missing_revision_ids()."""
806
        # we want all revisions to satisfy revision_id in source.
807
        # but we don't want to stat every file here and there.
808
        # we want then, all revisions other needs to satisfy revision_id
809
        # checked, but not those that we have locally.
810
        # so the first thing is to get a subset of the revisions to
811
        # satisfy revision_id in source, and then eliminate those that
812
        # we do already have.
813
        # this is slow on high latency connection to self, but as this
814
        # disk format scales terribly for push anyway due to rewriting
815
        # inventory.weave, this is considered acceptable.
816
        # - RBC 20060209
817
        if revision_id is not None:
818
            source_ids = self.source.get_ancestry(revision_id)
819
            if source_ids[0] is not None:
820
                raise AssertionError()
821
            source_ids.pop(0)
822
        else:
823
            source_ids = self.source._all_possible_ids()
824
        source_ids_set = set(source_ids)
825
        # source_ids is the worst possible case we may need to pull.
826
        # now we want to filter source_ids against what we actually
827
        # have in target, but don't try to check for existence where we know
828
        # we do not have a revision as that would be pointless.
829
        target_ids = set(self.target._all_possible_ids())
830
        possibly_present_revisions = target_ids.intersection(source_ids_set)
831
        actually_present_revisions = set(
832
            self.target._eliminate_revisions_not_present(possibly_present_revisions))
833
        required_revisions = source_ids_set.difference(actually_present_revisions)
834
        if revision_id is not None:
835
            # we used get_ancestry to determine source_ids then we are assured all
836
            # revisions referenced are present as they are installed in topological order.
837
            # and the tip revision was validated by get_ancestry.
838
            result_set = required_revisions
839
        else:
840
            # if we just grabbed the possibly available ids, then
841
            # we only have an estimate of whats available and need to validate
842
            # that against the revision records.
843
            result_set = set(
844
                self.source._eliminate_revisions_not_present(required_revisions))
845
        return self.source.revision_ids_to_search_result(result_set)
846
847
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
848
_legacy_formats = [RepositoryFormat4(),
849
                   RepositoryFormat5(),
850
                   RepositoryFormat6()]
5537.2.1 by Jelmer Vernooij
Move InterWeaveRepo and InterKnitRepo to related repository files.
851
852
853
InterRepository.register_optimiser(InterWeaveRepo)