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