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