/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
5766.1.1 by Jelmer Vernooij
Make revision-graph-can-have-wrong-parents a repository format attribute rather than a repository method.
282
    # XXX: This is an old format that we don't support full checking on, so
283
    # just claim that checking for this inconsistency is not required.
284
    revision_graph_can_have_wrong_parents = False
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
285
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
286
    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.
287
        """Create a weave repository."""
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
288
        if shared:
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
289
            raise errors.IncompatibleFormat(self, a_controldir._format)
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
290
291
        if not _internal:
292
            # always initialized when the bzrdir is.
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
293
            return self.open(a_controldir, _found=True)
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
        # Create an empty weave
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
296
        sio = BytesIO()
5582.10.44 by Jelmer Vernooij
Clean up patch.
297
        weavefile.write_weave_v5(weave.Weave(), sio)
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
298
        empty_weave = sio.getvalue()
299
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
300
        trace.mutter('creating repository in %s.', a_controldir.transport.base)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
301
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
302
        # FIXME: RBC 20060125 don't peek under the covers
303
        # 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.
304
        control_files = lockable_files.LockableFiles(a_controldir.transport,
3407.2.4 by Martin Pool
Small cleanups to initial creation of repository files
305
            'branch-lock', lockable_files.TransportLock)
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
306
        control_files.create_lock()
307
        control_files.lock_write()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
308
        transport = a_controldir.transport
3407.2.4 by Martin Pool
Small cleanups to initial creation of repository files
309
        try:
310
            transport.mkdir_multi(['revision-store', 'weaves'],
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
311
                mode=a_controldir._get_dir_mode())
3407.2.18 by Martin Pool
BzrDir takes responsibility for default file/dir modes
312
            transport.put_bytes_non_atomic('inventory.weave', empty_weave,
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
313
                mode=a_controldir._get_file_mode())
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
314
        finally:
315
            control_files.unlock()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
316
        repository = self.open(a_controldir, _found=True)
317
        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',
318
        return repository
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
319
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
320
    def open(self, a_controldir, _found=False):
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
321
        """See RepositoryFormat.open()."""
322
        if not _found:
323
            # we are being called directly and must probe.
324
            raise NotImplementedError
325
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
326
        repo_transport = a_controldir.get_repository_transport(None)
327
        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.
328
        result.revisions = self._get_revisions(repo_transport, result)
329
        result.signatures = self._get_signatures(repo_transport, result)
330
        result.inventories = self._get_inventories(repo_transport, result)
331
        result.texts = self._get_texts(repo_transport, result)
4246.2.1 by Ian Clatworthy
supports_chks flag on repo formats & log tuning
332
        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.
333
        return result
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
334
5675.2.1 by Jelmer Vernooij
Add RepositoryFormat.is_deprecated(). This removes the need for
335
    def is_deprecated(self):
336
        return True
337
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
338
339
class RepositoryFormat4(PreSplitOutRepositoryFormat):
340
    """Bzr repository format 4.
341
342
    This repository format has:
343
     - flat stores
344
     - TextStores for texts, inventories,revisions.
345
346
    This format is deprecated: it indexes texts using a text id which is
347
    removed in format 5; initialization and write support for this format
348
    has been removed.
349
    """
350
5582.9.1 by Jelmer Vernooij
Add flag for 'supports_funky_characters'.
351
    supports_funky_characters = False
352
6746.2.1 by Jelmer Vernooij
Rename matchingbzrdir to matchingcontroldir.
353
    _matchingcontroldir = weave_bzrdir.BzrDirFormat4()
2241.1.11 by Martin Pool
Get rid of RepositoryFormat*_instance objects. Instead the format
354
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
355
    def get_format_description(self):
356
        """See RepositoryFormat.get_format_description()."""
357
        return "Repository format 4"
358
359
    def initialize(self, url, shared=False, _internal=False):
360
        """Format 4 branches cannot be created."""
361
        raise errors.UninitializableFormat(self)
362
363
    def is_supported(self):
364
        """Format 4 is not supported.
365
366
        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
367
        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.
368
        feasible.
369
        """
370
        return False
371
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
    def _get_inventories(self, repo_transport, repo, name='inventory'):
373
        # No inventories store written so far.
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
374
        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.
375
376
    def _get_revisions(self, repo_transport, repo):
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
377
        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.
378
        return RevisionTextStore(repo_transport.clone('revision-store'),
379
            serializer_v4, True, versionedfile.PrefixMapper(),
380
            repo.is_locked, repo.is_write_locked)
381
382
    def _get_signatures(self, repo_transport, repo):
383
        return SignatureTextStore(repo_transport.clone('revision-store'),
384
            False, versionedfile.PrefixMapper(),
385
            repo.is_locked, repo.is_write_locked)
386
387
    def _get_texts(self, repo_transport, repo):
388
        return None
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
389
390
391
class RepositoryFormat5(PreSplitOutRepositoryFormat):
392
    """Bzr control format 5.
393
394
    This repository format has:
395
     - weaves for file texts and inventory
396
     - flat stores
397
     - TextStores for revisions and signatures.
398
    """
399
5582.10.42 by Jelmer Vernooij
Some weave fixes.
400
    _versionedfile_class = weave.WeaveFile
6746.2.1 by Jelmer Vernooij
Rename matchingbzrdir to matchingcontroldir.
401
    _matchingcontroldir = weave_bzrdir.BzrDirFormat5()
5582.9.1 by Jelmer Vernooij
Add flag for 'supports_funky_characters'.
402
    supports_funky_characters = False
403
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)
404
    @property
405
    def _serializer(self):
406
        return xml5.serializer_v5
2241.1.10 by Martin Pool
Remove more references to weaves from the repository.py file
407
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
408
    def get_format_description(self):
409
        """See RepositoryFormat.get_format_description()."""
410
        return "Weave repository format 5"
4032.1.2 by John Arbash Meinel
Track down a few more files that have trailing whitespace.
411
3990.5.1 by Andrew Bennetts
Add network_name() to RepositoryFormat.
412
    def network_name(self):
3990.5.3 by Robert Collins
Docs and polish on RepositoryFormat.network_name.
413
        """The network name for this format is the control dirs disk label."""
6746.2.1 by Jelmer Vernooij
Rename matchingbzrdir to matchingcontroldir.
414
        return self._matchingcontroldir.get_format_string()
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
415
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.
416
    def _get_inventories(self, repo_transport, repo, name='inventory'):
417
        mapper = versionedfile.ConstantMapper(name)
418
        return versionedfile.ThunkedVersionedFiles(repo_transport,
5582.10.42 by Jelmer Vernooij
Some weave fixes.
419
            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.
420
421
    def _get_revisions(self, repo_transport, repo):
422
        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)
423
            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.
424
            repo.is_locked, repo.is_write_locked)
425
426
    def _get_signatures(self, repo_transport, repo):
427
        return SignatureTextStore(repo_transport.clone('revision-store'),
428
            False, versionedfile.PrefixMapper(),
429
            repo.is_locked, repo.is_write_locked)
430
431
    def _get_texts(self, repo_transport, repo):
432
        mapper = versionedfile.PrefixMapper()
433
        base_transport = repo_transport.clone('weaves')
434
        return versionedfile.ThunkedVersionedFiles(base_transport,
5582.10.42 by Jelmer Vernooij
Some weave fixes.
435
            weave.WeaveFile, mapper, repo.is_locked)
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
436
437
438
class RepositoryFormat6(PreSplitOutRepositoryFormat):
439
    """Bzr control format 6.
440
441
    This repository format has:
442
     - weaves for file texts and inventory
443
     - hash subdirectory based stores.
444
     - TextStores for revisions and signatures.
445
    """
446
5582.10.42 by Jelmer Vernooij
Some weave fixes.
447
    _versionedfile_class = weave.WeaveFile
6746.2.1 by Jelmer Vernooij
Rename matchingbzrdir to matchingcontroldir.
448
    _matchingcontroldir = weave_bzrdir.BzrDirFormat6()
5582.9.1 by Jelmer Vernooij
Add flag for 'supports_funky_characters'.
449
    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)
450
    @property
451
    def _serializer(self):
452
        return xml5.serializer_v5
2241.1.10 by Martin Pool
Remove more references to weaves from the repository.py file
453
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
454
    def get_format_description(self):
455
        """See RepositoryFormat.get_format_description()."""
456
        return "Weave repository format 6"
457
3990.5.1 by Andrew Bennetts
Add network_name() to RepositoryFormat.
458
    def network_name(self):
3990.5.3 by Robert Collins
Docs and polish on RepositoryFormat.network_name.
459
        """The network name for this format is the control dirs disk label."""
6746.2.1 by Jelmer Vernooij
Rename matchingbzrdir to matchingcontroldir.
460
        return self._matchingcontroldir.get_format_string()
3990.5.1 by Andrew Bennetts
Add network_name() to RepositoryFormat.
461
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.
462
    def _get_inventories(self, repo_transport, repo, name='inventory'):
463
        mapper = versionedfile.ConstantMapper(name)
464
        return versionedfile.ThunkedVersionedFiles(repo_transport,
5582.10.42 by Jelmer Vernooij
Some weave fixes.
465
            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.
466
467
    def _get_revisions(self, repo_transport, repo):
468
        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)
469
            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.
470
            repo.is_locked, repo.is_write_locked)
471
472
    def _get_signatures(self, repo_transport, repo):
473
        return SignatureTextStore(repo_transport.clone('revision-store'),
474
            False, versionedfile.HashPrefixMapper(),
475
            repo.is_locked, repo.is_write_locked)
476
477
    def _get_texts(self, repo_transport, repo):
478
        mapper = versionedfile.HashPrefixMapper()
479
        base_transport = repo_transport.clone('weaves')
480
        return versionedfile.ThunkedVersionedFiles(base_transport,
5582.10.42 by Jelmer Vernooij
Some weave fixes.
481
            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.
482
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
483
5815.4.5 by Jelmer Vernooij
Use MetaDirVersionedFileRepositoryFormat (a Soyuz worthy name).
484
class RepositoryFormat7(MetaDirVersionedFileRepositoryFormat):
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
485
    """Bzr repository 7.
486
487
    This repository format has:
488
     - weaves for file texts and inventory
489
     - hash subdirectory based stores.
490
     - TextStores for revisions and signatures.
491
     - a format marker of its own
492
     - an optional 'shared-storage' flag
493
     - an optional 'no-working-trees' flag
494
    """
495
5582.10.42 by Jelmer Vernooij
Some weave fixes.
496
    _versionedfile_class = weave.WeaveFile
2949.1.2 by Robert Collins
* Fetch with pack repositories will no longer read the entire history graph.
497
    supports_ghosts = False
4246.2.1 by Ian Clatworthy
supports_chks flag on repo formats & log tuning
498
    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.
499
    supports_funky_characters = False
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
6213.1.16 by Jelmer Vernooij
Feature support in repository.
509
    @classmethod
510
    def get_format_string(cls):
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
511
        """See RepositoryFormat.get_format_string()."""
512
        return "Bazaar-NG Repository format 7"
513
514
    def get_format_description(self):
515
        """See RepositoryFormat.get_format_description()."""
516
        return "Weave repository format 7"
517
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.
518
    def _get_inventories(self, repo_transport, repo, name='inventory'):
519
        mapper = versionedfile.ConstantMapper(name)
520
        return versionedfile.ThunkedVersionedFiles(repo_transport,
5582.10.42 by Jelmer Vernooij
Some weave fixes.
521
            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.
522
523
    def _get_revisions(self, repo_transport, repo):
524
        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)
525
            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.
526
            repo.is_locked, repo.is_write_locked)
527
528
    def _get_signatures(self, repo_transport, repo):
529
        return SignatureTextStore(repo_transport.clone('revision-store'),
530
            True, versionedfile.HashPrefixMapper(),
531
            repo.is_locked, repo.is_write_locked)
532
533
    def _get_texts(self, repo_transport, repo):
534
        mapper = versionedfile.HashPrefixMapper()
535
        base_transport = repo_transport.clone('weaves')
536
        return versionedfile.ThunkedVersionedFiles(base_transport,
5582.10.42 by Jelmer Vernooij
Some weave fixes.
537
            weave.WeaveFile, mapper, repo.is_locked)
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
538
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
539
    def initialize(self, a_controldir, shared=False):
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
540
        """Create a weave repository.
541
542
        :param shared: If true the repository will be initialized as a shared
543
                       repository.
544
        """
545
        # Create an empty weave
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
546
        sio = BytesIO()
5582.10.44 by Jelmer Vernooij
Clean up patch.
547
        weavefile.write_weave_v5(weave.Weave(), sio)
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
548
        empty_weave = sio.getvalue()
549
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
550
        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.
551
        dirs = ['revision-store', 'weaves']
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
552
        files = [('inventory.weave', BytesIO(empty_weave)),
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
553
                 ]
554
        utf8_files = [('format', self.get_format_string())]
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
555
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
556
        self._upload_blank_content(a_controldir, dirs, files, utf8_files, shared)
557
        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.
558
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
559
    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.
560
        """See RepositoryFormat.open().
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
561
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
562
        :param _override_transport: INTERNAL USE ONLY. Allows opening the
563
                                    repository at a slightly different url
564
                                    than normal. I.e. during 'upgrade'.
565
        """
566
        if not _found:
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
567
            format = RepositoryFormatMetaDir.find_format(a_controldir)
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
568
        if _override_transport is not None:
569
            repo_transport = _override_transport
570
        else:
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
571
            repo_transport = a_controldir.get_repository_transport(None)
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
572
        control_files = lockable_files.LockableFiles(repo_transport,
573
                                'lock', lockdir.LockDir)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
574
        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.
575
            control_files=control_files)
576
        result.revisions = self._get_revisions(repo_transport, result)
577
        result.signatures = self._get_signatures(repo_transport, result)
578
        result.inventories = self._get_inventories(repo_transport, result)
579
        result.texts = self._get_texts(repo_transport, result)
4246.2.1 by Ian Clatworthy
supports_chks flag on repo formats & log tuning
580
        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.
581
        result._transport = repo_transport
582
        return result
583
5675.2.1 by Jelmer Vernooij
Add RepositoryFormat.is_deprecated(). This removes the need for
584
    def is_deprecated(self):
585
        return True
586
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.
587
588
class TextVersionedFiles(VersionedFiles):
589
    """Just-a-bunch-of-files based VersionedFile stores."""
590
591
    def __init__(self, transport, compressed, mapper, is_locked, can_write):
592
        self._compressed = compressed
593
        self._transport = transport
594
        self._mapper = mapper
595
        if self._compressed:
596
            self._ext = '.gz'
597
        else:
598
            self._ext = ''
599
        self._is_locked = is_locked
600
        self._can_write = can_write
601
602
    def add_lines(self, key, parents, lines):
603
        """Add a revision to the store."""
604
        if not self._is_locked():
605
            raise errors.ObjectNotLocked(self)
606
        if not self._can_write():
607
            raise errors.ReadOnlyError(self)
608
        if '/' in key[-1]:
3350.6.10 by Martin Pool
VersionedFiles review cleanups
609
            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.
610
        text = ''.join(lines)
611
        if self._compressed:
5590.1.6 by John Arbash Meinel
Found another tuned_gzip use in weaverepo
612
            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.
613
        path = self._map(key)
614
        self._transport.put_bytes_non_atomic(path, text, create_parent_dir=True)
615
5195.3.26 by Parth Malwankar
reverted changes done to insert_record_stream API
616
    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.
617
        adapters = {}
618
        for record in stream:
619
            # Raise an error when a record is missing.
620
            if record.storage_kind == 'absent':
621
                raise errors.RevisionNotPresent([record.key[0]], self)
622
            # adapt to non-tuple interface
623
            if record.storage_kind == 'fulltext':
624
                self.add_lines(record.key, None,
625
                    osutils.split_lines(record.get_bytes_as('fulltext')))
626
            else:
627
                adapter_key = record.storage_kind, 'fulltext'
628
                try:
629
                    adapter = adapters[adapter_key]
630
                except KeyError:
631
                    adapter_factory = adapter_registry.get(adapter_key)
632
                    adapter = adapter_factory(self)
633
                    adapters[adapter_key] = adapter
634
                lines = osutils.split_lines(adapter.get_bytes(
635
                    record, record.get_bytes_as(record.storage_kind)))
636
                try:
637
                    self.add_lines(record.key, None, lines)
5815.4.17 by Jelmer Vernooij
Remove unused test method.
638
                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.
639
                    pass
640
641
    def _load_text(self, key):
642
        if not self._is_locked():
643
            raise errors.ObjectNotLocked(self)
644
        path = self._map(key)
645
        try:
646
            text = self._transport.get_bytes(path)
647
            compressed = self._compressed
648
        except errors.NoSuchFile:
649
            if self._compressed:
650
                # try without the .gz
651
                path = path[:-3]
652
                try:
653
                    text = self._transport.get_bytes(path)
654
                    compressed = False
655
                except errors.NoSuchFile:
656
                    return None
657
            else:
658
                return None
659
        if compressed:
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
660
            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.
661
        return text
662
663
    def _map(self, key):
664
        return self._mapper.map(key) + self._ext
665
666
667
class RevisionTextStore(TextVersionedFiles):
668
    """Legacy thunk for format 4 repositories."""
669
670
    def __init__(self, transport, serializer, compressed, mapper, is_locked,
671
        can_write):
672
        """Create a RevisionTextStore at transport with serializer."""
673
        TextVersionedFiles.__init__(self, transport, compressed, mapper,
674
            is_locked, can_write)
675
        self._serializer = serializer
676
677
    def _load_text_parents(self, key):
678
        text = self._load_text(key)
679
        if text is None:
680
            return None, None
681
        parents = self._serializer.read_revision_from_string(text).parent_ids
682
        return text, tuple((parent,) for parent in parents)
683
684
    def get_parent_map(self, keys):
685
        result = {}
686
        for key in keys:
687
            parents = self._load_text_parents(key)[1]
688
            if parents is None:
689
                continue
690
            result[key] = parents
691
        return result
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
692
4593.5.34 by John Arbash Meinel
Change the KnownGraph.merge_sort api.
693
    def get_known_graph_ancestry(self, keys):
694
        """Get a KnownGraph instance with the ancestry of keys."""
695
        keys = self.keys()
696
        parent_map = self.get_parent_map(keys)
697
        kg = _mod_graph.KnownGraph(parent_map)
698
        return kg
699
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.
700
    def get_record_stream(self, keys, sort_order, include_delta_closure):
701
        for key in keys:
702
            text, parents = self._load_text_parents(key)
703
            if text is None:
704
                yield AbsentContentFactory(key)
705
            else:
706
                yield FulltextContentFactory(key, parents, None, text)
707
708
    def keys(self):
709
        if not self._is_locked():
710
            raise errors.ObjectNotLocked(self)
711
        relpaths = set()
712
        for quoted_relpath in self._transport.iter_files_recursive():
6379.4.2 by Jelmer Vernooij
Add urlutils.quote / urlutils.unquote.
713
            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.
714
            path, ext = os.path.splitext(relpath)
715
            if ext == '.gz':
716
                relpath = path
4695.2.1 by Vincent Ladeuil
Align RevisionTextStore and SignatureTextStore keys() definitions.
717
            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.
718
                relpaths.add(relpath)
719
        paths = list(relpaths)
6619.3.12 by Jelmer Vernooij
Use 2to3 set_literal fixer.
720
        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.
721
722
723
class SignatureTextStore(TextVersionedFiles):
724
    """Legacy thunk for format 4-7 repositories."""
725
726
    def __init__(self, transport, compressed, mapper, is_locked, can_write):
727
        TextVersionedFiles.__init__(self, transport, compressed, mapper,
728
            is_locked, can_write)
729
        self._ext = '.sig' + self._ext
730
731
    def get_parent_map(self, keys):
732
        result = {}
733
        for key in keys:
734
            text = self._load_text(key)
735
            if text is None:
736
                continue
737
            result[key] = None
738
        return result
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
739
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.
740
    def get_record_stream(self, keys, sort_order, include_delta_closure):
741
        for key in keys:
742
            text = self._load_text(key)
743
            if text is None:
744
                yield AbsentContentFactory(key)
745
            else:
746
                yield FulltextContentFactory(key, None, None, text)
747
748
    def keys(self):
749
        if not self._is_locked():
750
            raise errors.ObjectNotLocked(self)
751
        relpaths = set()
752
        for quoted_relpath in self._transport.iter_files_recursive():
6379.4.2 by Jelmer Vernooij
Add urlutils.quote / urlutils.unquote.
753
            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.
754
            path, ext = os.path.splitext(relpath)
755
            if ext == '.gz':
756
                relpath = path
757
            if not relpath.endswith('.sig'):
758
                continue
759
            relpaths.add(relpath[:-4])
760
        paths = list(relpaths)
6619.3.12 by Jelmer Vernooij
Use 2to3 set_literal fixer.
761
        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
762
5537.2.1 by Jelmer Vernooij
Move InterWeaveRepo and InterKnitRepo to related repository files.
763
764
class InterWeaveRepo(InterSameDataRepository):
765
    """Optimised code paths between Weave based repositories.
766
    """
767
768
    @classmethod
769
    def _get_repo_format_to_test(self):
770
        return RepositoryFormat7()
771
772
    @staticmethod
773
    def is_compatible(source, target):
774
        """Be compatible with known Weave formats.
775
776
        We don't test for the stores being of specific types because that
777
        could lead to confusing results, and there is no need to be
778
        overly general.
779
        """
780
        try:
781
            return (isinstance(source._format, (RepositoryFormat5,
782
                                                RepositoryFormat6,
783
                                                RepositoryFormat7)) and
784
                    isinstance(target._format, (RepositoryFormat5,
785
                                                RepositoryFormat6,
786
                                                RepositoryFormat7)))
787
        except AttributeError:
788
            return False
789
790
    def copy_content(self, revision_id=None):
791
        """See InterRepository.copy_content()."""
6754.8.17 by Jelmer Vernooij
Remove uses of needs_write_lock.
792
        with self.lock_write():
793
            # weave specific optimised path:
5537.2.1 by Jelmer Vernooij
Move InterWeaveRepo and InterKnitRepo to related repository files.
794
            try:
6754.8.17 by Jelmer Vernooij
Remove uses of needs_write_lock.
795
                self.target.set_make_working_trees(self.source.make_working_trees())
796
            except (errors.RepositoryUpgradeRequired, NotImplemented):
797
                pass
798
            # FIXME do not peek!
799
            if self.source._transport.listable():
800
                pb = ui.ui_factory.nested_progress_bar()
801
                try:
802
                    self.target.texts.insert_record_stream(
803
                        self.source.texts.get_record_stream(
804
                            self.source.texts.keys(), 'topological', False))
805
                    pb.update('Copying inventory', 0, 1)
806
                    self.target.inventories.insert_record_stream(
807
                        self.source.inventories.get_record_stream(
808
                            self.source.inventories.keys(), 'topological', False))
809
                    self.target.signatures.insert_record_stream(
810
                        self.source.signatures.get_record_stream(
811
                            self.source.signatures.keys(),
812
                            'unordered', True))
813
                    self.target.revisions.insert_record_stream(
814
                        self.source.revisions.get_record_stream(
815
                            self.source.revisions.keys(),
816
                            'topological', True))
817
                finally:
818
                    pb.finished()
819
            else:
820
                self.target.fetch(self.source, revision_id=revision_id)
5537.2.1 by Jelmer Vernooij
Move InterWeaveRepo and InterKnitRepo to related repository files.
821
6754.8.16 by Jelmer Vernooij
Get rid of all uses of needs_read_lock
822
    def search_missing_revision_ids(self, find_ghosts=True, revision_ids=None,
823
                                    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.
824
        """See InterRepository.search_missing_revision_ids()."""
6754.8.16 by Jelmer Vernooij
Get rid of all uses of needs_read_lock
825
        with self.lock_read():
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
837
            source_ids_set = self._present_source_revisions_for(
838
                revision_ids, if_present_ids)
839
            # source_ids is the worst possible case we may need to pull.
840
            # now we want to filter source_ids against what we actually
841
            # have in target, but don't try to check for existence where we
842
            # know we do not have a revision as that would be pointless.
843
            target_ids = set(self.target._all_possible_ids())
844
            possibly_present_revisions = target_ids.intersection(
845
                    source_ids_set)
846
            actually_present_revisions = set(
847
                self.target._eliminate_revisions_not_present(
848
                    possibly_present_revisions))
849
            required_revisions = source_ids_set.difference(
850
                    actually_present_revisions)
851
            if revision_ids is not None:
852
                # we used get_ancestry to determine source_ids then we are
853
                # assured all revisions referenced are present as they are
854
                # installed in topological order. and the tip revision was
855
                # validated by get_ancestry.
856
                result_set = required_revisions
857
            else:
858
                # if we just grabbed the possibly available ids, then
859
                # we only have an estimate of whats available and need to
860
                # validate that against the revision records.
861
                result_set = set(
862
                    self.source._eliminate_revisions_not_present(
863
                        required_revisions))
864
            if limit is not None:
865
                topo_ordered = self.get_graph().iter_topo_order(result_set)
866
                result_set = set(itertools.islice(topo_ordered, limit))
867
            return self.source.revision_ids_to_search_result(result_set)
5537.2.1 by Jelmer Vernooij
Move InterWeaveRepo and InterKnitRepo to related repository files.
868
869
870
InterRepository.register_optimiser(InterWeaveRepo)
5676.1.9 by Jelmer Vernooij
Fix existing implementation.
871
872
873
def get_extra_interrepo_test_combinations():
6670.4.5 by Jelmer Vernooij
Move breezy.repofmt contents to breezy.bzr.
874
    from ...bzr import knitrepo
5676.1.9 by Jelmer Vernooij
Fix existing implementation.
875
    return [(InterRepository, RepositoryFormat5(),
876
        knitrepo.RepositoryFormatKnit3())]