/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 ...decorators import needs_read_lock, needs_write_lock
56
from ...repository import (
5537.2.1 by Jelmer Vernooij
Move InterWeaveRepo and InterKnitRepo to related repository files.
57
    InterRepository,
6653.2.1 by Jelmer Vernooij
Move bzr-specific repository code out of breezy.bzrrepository.
58
    )
6670.4.1 by Jelmer Vernooij
Update imports.
59
from ...bzr.repository import (
6349.2.1 by Jelmer Vernooij
Add BzrDirMetaComponentFormat.
60
    RepositoryFormatMetaDir,
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
61
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
62
from ...sixish import (
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
63
    BytesIO,
6695.3.1 by Martin
Remove remaining uses of basestring from the codebase
64
    text_type,
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
65
    )
6686.2.1 by Jelmer Vernooij
Move breezy.store to breezy.plugins.weave_fmt, its only user.
66
from .store.text import TextStore
6670.4.1 by Jelmer Vernooij
Update imports.
67
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.
68
    AbsentContentFactory,
69
    FulltextContentFactory,
70
    VersionedFiles,
71
    )
6670.4.1 by Jelmer Vernooij
Update imports.
72
from ...bzr.vf_repository import (
5815.4.19 by Jelmer Vernooij
Fix test failures.
73
    InterSameDataRepository,
5815.4.2 by Jelmer Vernooij
split out versionedfile-specific stuff from commitbuilder.
74
    VersionedFileCommitBuilder,
5815.4.14 by Jelmer Vernooij
Fix imports.
75
    VersionedFileRepository,
5815.4.5 by Jelmer Vernooij
Use MetaDirVersionedFileRepositoryFormat (a Soyuz worthy name).
76
    VersionedFileRepositoryFormat,
77
    MetaDirVersionedFileRepository,
78
    MetaDirVersionedFileRepositoryFormat,
5815.4.2 by Jelmer Vernooij
split out versionedfile-specific stuff from commitbuilder.
79
    )
5582.10.23 by Jelmer Vernooij
Move bzrlib.weavefile.
80
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
81
from . import bzrdir as weave_bzrdir
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
82
5582.10.23 by Jelmer Vernooij
Move bzrlib.weavefile.
83
5815.4.14 by Jelmer Vernooij
Fix imports.
84
class AllInOneRepository(VersionedFileRepository):
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
85
    """Legacy support - the repository behaviour for all-in-one branches."""
86
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.
87
    @property
88
    def _serializer(self):
89
        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
90
3834.2.2 by Martin Pool
Deprecated LockableFiles._escape
91
    def _escape(self, file_or_path):
6695.3.1 by Martin
Remove remaining uses of basestring from the codebase
92
        if not isinstance(file_or_path, (str, text_type)):
3834.2.2 by Martin Pool
Deprecated LockableFiles._escape
93
            file_or_path = '/'.join(file_or_path)
94
        if file_or_path == '':
95
            return u''
96
        return urlutils.escape(osutils.safe_unicode(file_or_path))
97
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
98
    def __init__(self, _format, a_controldir):
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
99
        # we reuse one control files instance.
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
100
        dir_mode = a_controldir._get_dir_mode()
101
        file_mode = a_controldir._get_file_mode()
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
102
103
        def get_store(name, compressed=True, prefixed=False):
104
            # FIXME: This approach of assuming stores are all entirely compressed
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
105
            # or entirely uncompressed is tidy, but breaks upgrade from
106
            # 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.
107
            # still want the option to look for both.
3834.2.2 by Martin Pool
Deprecated LockableFiles._escape
108
            relpath = self._escape(name)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
109
            store = TextStore(a_controldir.transport.clone(relpath),
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
110
                              prefixed=prefixed, compressed=compressed,
111
                              dir_mode=dir_mode,
112
                              file_mode=file_mode)
113
            return store
114
115
        # 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.
116
        # and texts bits are still different.
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
117
        if isinstance(_format, RepositoryFormat4):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
118
            # 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.
119
            # which allows access to this old info.
120
            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.
121
            self._text_store = get_store('text-store')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
122
        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.
123
2850.3.1 by Robert Collins
Move various weave specific code out of the base Repository class to weaverepo.py.
124
    @needs_read_lock
125
    def _all_possible_ids(self):
126
        """Return all the possible revisions that we could find."""
127
        if 'evil' in debug.debug_flags:
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
128
            trace.mutter_callsite(
129
                3, "_all_possible_ids scales with size of history.")
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
130
        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.
131
132
    @needs_read_lock
133
    def _all_revision_ids(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
134
        """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.
135
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
136
        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.
137
        present: for weaves ghosts may lead to a lack of correctness until
138
        the reweave updates the parents list.
139
        """
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
        return [key[-1] for key in self.revisions.keys()]
141
142
    def _activate_new_inventory(self):
143
        """Put a replacement inventory.new into use as inventories."""
144
        # Copy the content across
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
145
        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.
146
        t.copy('inventory.new.weave', 'inventory.weave')
147
        # delete the temp inventory
148
        t.delete('inventory.new.weave')
149
        # Check we can parse the new weave properly as a sanity check
150
        self.inventories.keys()
151
152
    def _backup_inventory(self):
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
153
        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.
154
        t.copy('inventory.weave', 'inventory.backup.weave')
155
156
    def _temp_inventories(self):
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
157
        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.
158
        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.
159
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
160
    def get_commit_builder(self, branch, parents, config, timestamp=None,
161
                           timezone=None, committer=None, revprops=None,
5777.6.12 by Jelmer Vernooij
Fix get_commit_builder.
162
                           revision_id=None, lossy=False):
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
163
        self._check_ascii_revisionid(revision_id, self.get_commit_builder)
5815.4.2 by Jelmer Vernooij
split out versionedfile-specific stuff from commitbuilder.
164
        result = VersionedFileCommitBuilder(self, parents, config, timestamp,
165
            timezone, committer, revprops, revision_id, lossy=lossy)
2803.2.1 by Robert Collins
* CommitBuilder now advertises itself as requiring the root entry to be
166
        self.start_write_group()
167
        return result
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
168
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.
169
    def _inventory_add_lines(self, revision_id, parents, lines,
170
        check_content=True):
171
        """Store lines in inv_vf and return the sha1 of the inventory."""
172
        present_parents = self.get_graph().get_parent_map(parents)
173
        final_parents = []
174
        for parent in parents:
175
            if parent in present_parents:
176
                final_parents.append((parent,))
177
        return self.inventories.add_lines((revision_id,), final_parents, lines,
178
            check_content=check_content)[0]
3172.3.1 by Robert Collins
Repository has a new method ``has_revisions`` which signals the presence
179
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
180
    def is_shared(self):
181
        """AllInOne repositories cannot be shared."""
182
        return False
183
184
    @needs_write_lock
185
    def set_make_working_trees(self, new_value):
186
        """Set the policy flag for making working trees when creating branches.
187
188
        This only applies to branches that use this repository.
189
190
        The default is 'True'.
191
        :param new_value: True to restore the default, False to disable making
192
                          working trees.
193
        """
5158.6.10 by Martin Pool
Update more code to use user_transport when it should
194
        raise errors.RepositoryUpgradeRequired(self.user_url)
3349.1.1 by Aaron Bentley
Enable setting and getting make_working_trees for all repositories
195
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
196
    def make_working_trees(self):
197
        """Returns the policy for making working trees on new branches."""
198
        return True
199
200
3316.2.3 by Robert Collins
Remove manual notification of transaction finishing on versioned files.
201
class WeaveMetaDirRepository(MetaDirVersionedFileRepository):
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
202
    """A subclass of MetaDirRepository to set weave specific policy."""
203
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
204
    def __init__(self, _format, a_controldir, control_files):
205
        super(WeaveMetaDirRepository, self).__init__(_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)
206
        self._serializer = _format._serializer
3565.3.1 by Robert Collins
* The generic fetch code now uses two attributes on Repository objects
207
2850.3.1 by Robert Collins
Move various weave specific code out of the base Repository class to weaverepo.py.
208
    @needs_read_lock
209
    def _all_possible_ids(self):
210
        """Return all the possible revisions that we could find."""
211
        if 'evil' in debug.debug_flags:
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
212
            trace.mutter_callsite(
213
                3, "_all_possible_ids scales with size of history.")
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
214
        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.
215
216
    @needs_read_lock
217
    def _all_revision_ids(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
218
        """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.
219
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
220
        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.
221
        present: for weaves ghosts may lead to a lack of correctness until
222
        the reweave updates the parents list.
223
        """
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
        return [key[-1] for key in self.revisions.keys()]
225
226
    def _activate_new_inventory(self):
227
        """Put a replacement inventory.new into use as inventories."""
228
        # Copy the content across
229
        t = self._transport
230
        t.copy('inventory.new.weave', 'inventory.weave')
231
        # delete the temp inventory
232
        t.delete('inventory.new.weave')
233
        # Check we can parse the new weave properly as a sanity check
234
        self.inventories.keys()
235
236
    def _backup_inventory(self):
237
        t = self._transport
238
        t.copy('inventory.weave', 'inventory.backup.weave')
239
240
    def _temp_inventories(self):
241
        t = self._transport
242
        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.
243
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
244
    def get_commit_builder(self, branch, parents, config, timestamp=None,
245
                           timezone=None, committer=None, revprops=None,
5777.6.13 by Jelmer Vernooij
Fix get_commit_builder for weaves.
246
                           revision_id=None, lossy=False):
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
247
        self._check_ascii_revisionid(revision_id, self.get_commit_builder)
5815.4.2 by Jelmer Vernooij
split out versionedfile-specific stuff from commitbuilder.
248
        result = VersionedFileCommitBuilder(self, parents, config, timestamp,
249
            timezone, committer, revprops, revision_id, lossy=lossy)
2803.2.1 by Robert Collins
* CommitBuilder now advertises itself as requiring the root entry to be
250
        self.start_write_group()
251
        return result
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
252
2850.3.1 by Robert Collins
Move various weave specific code out of the base Repository class to weaverepo.py.
253
    @needs_read_lock
254
    def get_revision(self, revision_id):
255
        """Return the Revision object for a named revision"""
256
        r = self.get_revision_reconcile(revision_id)
257
        return r
258
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.
259
    def _inventory_add_lines(self, revision_id, parents, lines,
260
        check_content=True):
261
        """Store lines in inv_vf and return the sha1 of the inventory."""
262
        present_parents = self.get_graph().get_parent_map(parents)
263
        final_parents = []
264
        for parent in parents:
265
            if parent in present_parents:
266
                final_parents.append((parent,))
267
        return self.inventories.add_lines((revision_id,), final_parents, lines,
268
            check_content=check_content)[0]
3172.3.1 by Robert Collins
Repository has a new method ``has_revisions`` which signals the presence
269
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
270
5815.4.5 by Jelmer Vernooij
Use MetaDirVersionedFileRepositoryFormat (a Soyuz worthy name).
271
class PreSplitOutRepositoryFormat(VersionedFileRepositoryFormat):
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
272
    """Base class for the pre split out repository formats."""
273
274
    rich_root_data = False
2323.5.17 by Martin Pool
Add supports_tree_reference to all repo formats (robert)
275
    supports_tree_reference = False
2949.1.2 by Robert Collins
* Fetch with pack repositories will no longer read the entire history graph.
276
    supports_ghosts = False
3221.3.1 by Robert Collins
* Repository formats have a new supported-feature attribute
277
    supports_external_lookups = False
4246.2.1 by Ian Clatworthy
supports_chks flag on repo formats & log tuning
278
    supports_chks = False
6145.2.2 by Jelmer Vernooij
Set supports_nesting_repositories.
279
    supports_nesting_repositories = True
4053.1.4 by Robert Collins
Move the fetch control attributes from Repository to RepositoryFormat.
280
    _fetch_order = 'topological'
281
    _fetch_reconcile = True
4183.5.1 by Robert Collins
Add RepositoryFormat.fast_deltas to signal fast delta creation.
282
    fast_deltas = False
5674.1.1 by Jelmer Vernooij
Add supports_leave_lock flag to BranchFormat and RepositoryFormat.
283
    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.
284
    # XXX: This is an old format that we don't support full checking on, so
285
    # just claim that checking for this inconsistency is not required.
286
    revision_graph_can_have_wrong_parents = False
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
287
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
288
    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.
289
        """Create a weave repository."""
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
290
        if shared:
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
291
            raise errors.IncompatibleFormat(self, a_controldir._format)
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
292
293
        if not _internal:
294
            # always initialized when the bzrdir is.
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
295
            return self.open(a_controldir, _found=True)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
296
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
297
        # Create an empty weave
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
298
        sio = BytesIO()
5582.10.44 by Jelmer Vernooij
Clean up patch.
299
        weavefile.write_weave_v5(weave.Weave(), sio)
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
300
        empty_weave = sio.getvalue()
301
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
302
        trace.mutter('creating repository in %s.', a_controldir.transport.base)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
303
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
304
        # FIXME: RBC 20060125 don't peek under the covers
305
        # 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.
306
        control_files = lockable_files.LockableFiles(a_controldir.transport,
3407.2.4 by Martin Pool
Small cleanups to initial creation of repository files
307
            'branch-lock', lockable_files.TransportLock)
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
308
        control_files.create_lock()
309
        control_files.lock_write()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
310
        transport = a_controldir.transport
3407.2.4 by Martin Pool
Small cleanups to initial creation of repository files
311
        try:
312
            transport.mkdir_multi(['revision-store', 'weaves'],
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
313
                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()."""
514
        return "Bazaar-NG Repository format 7"
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)
610
        if '/' in key[-1]:
3350.6.10 by Martin Pool
VersionedFiles review cleanups
611
            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.
612
        text = ''.join(lines)
613
        if self._compressed:
5590.1.6 by John Arbash Meinel
Found another tuned_gzip use in weaverepo
614
            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.
615
        path = self._map(key)
616
        self._transport.put_bytes_non_atomic(path, text, create_parent_dir=True)
617
5195.3.26 by Parth Malwankar
reverted changes done to insert_record_stream API
618
    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.
619
        adapters = {}
620
        for record in stream:
621
            # Raise an error when a record is missing.
622
            if record.storage_kind == 'absent':
623
                raise errors.RevisionNotPresent([record.key[0]], self)
624
            # adapt to non-tuple interface
625
            if record.storage_kind == 'fulltext':
626
                self.add_lines(record.key, None,
627
                    osutils.split_lines(record.get_bytes_as('fulltext')))
628
            else:
629
                adapter_key = record.storage_kind, 'fulltext'
630
                try:
631
                    adapter = adapters[adapter_key]
632
                except KeyError:
633
                    adapter_factory = adapter_registry.get(adapter_key)
634
                    adapter = adapter_factory(self)
635
                    adapters[adapter_key] = adapter
636
                lines = osutils.split_lines(adapter.get_bytes(
637
                    record, record.get_bytes_as(record.storage_kind)))
638
                try:
639
                    self.add_lines(record.key, None, lines)
5815.4.17 by Jelmer Vernooij
Remove unused test method.
640
                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.
641
                    pass
642
643
    def _load_text(self, key):
644
        if not self._is_locked():
645
            raise errors.ObjectNotLocked(self)
646
        path = self._map(key)
647
        try:
648
            text = self._transport.get_bytes(path)
649
            compressed = self._compressed
650
        except errors.NoSuchFile:
651
            if self._compressed:
652
                # try without the .gz
653
                path = path[:-3]
654
                try:
655
                    text = self._transport.get_bytes(path)
656
                    compressed = False
657
                except errors.NoSuchFile:
658
                    return None
659
            else:
660
                return None
661
        if compressed:
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
662
            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.
663
        return text
664
665
    def _map(self, key):
666
        return self._mapper.map(key) + self._ext
667
668
669
class RevisionTextStore(TextVersionedFiles):
670
    """Legacy thunk for format 4 repositories."""
671
672
    def __init__(self, transport, serializer, compressed, mapper, is_locked,
673
        can_write):
674
        """Create a RevisionTextStore at transport with serializer."""
675
        TextVersionedFiles.__init__(self, transport, compressed, mapper,
676
            is_locked, can_write)
677
        self._serializer = serializer
678
679
    def _load_text_parents(self, key):
680
        text = self._load_text(key)
681
        if text is None:
682
            return None, None
683
        parents = self._serializer.read_revision_from_string(text).parent_ids
684
        return text, tuple((parent,) for parent in parents)
685
686
    def get_parent_map(self, keys):
687
        result = {}
688
        for key in keys:
689
            parents = self._load_text_parents(key)[1]
690
            if parents is None:
691
                continue
692
            result[key] = parents
693
        return result
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
694
4593.5.34 by John Arbash Meinel
Change the KnownGraph.merge_sort api.
695
    def get_known_graph_ancestry(self, keys):
696
        """Get a KnownGraph instance with the ancestry of keys."""
697
        keys = self.keys()
698
        parent_map = self.get_parent_map(keys)
699
        kg = _mod_graph.KnownGraph(parent_map)
700
        return kg
701
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.
702
    def get_record_stream(self, keys, sort_order, include_delta_closure):
703
        for key in keys:
704
            text, parents = self._load_text_parents(key)
705
            if text is None:
706
                yield AbsentContentFactory(key)
707
            else:
708
                yield FulltextContentFactory(key, parents, None, text)
709
710
    def keys(self):
711
        if not self._is_locked():
712
            raise errors.ObjectNotLocked(self)
713
        relpaths = set()
714
        for quoted_relpath in self._transport.iter_files_recursive():
6379.4.2 by Jelmer Vernooij
Add urlutils.quote / urlutils.unquote.
715
            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.
716
            path, ext = os.path.splitext(relpath)
717
            if ext == '.gz':
718
                relpath = path
4695.2.1 by Vincent Ladeuil
Align RevisionTextStore and SignatureTextStore keys() definitions.
719
            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.
720
                relpaths.add(relpath)
721
        paths = list(relpaths)
6619.3.12 by Jelmer Vernooij
Use 2to3 set_literal fixer.
722
        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.
723
724
725
class SignatureTextStore(TextVersionedFiles):
726
    """Legacy thunk for format 4-7 repositories."""
727
728
    def __init__(self, transport, compressed, mapper, is_locked, can_write):
729
        TextVersionedFiles.__init__(self, transport, compressed, mapper,
730
            is_locked, can_write)
731
        self._ext = '.sig' + self._ext
732
733
    def get_parent_map(self, keys):
734
        result = {}
735
        for key in keys:
736
            text = self._load_text(key)
737
            if text is None:
738
                continue
739
            result[key] = None
740
        return result
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
741
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.
742
    def get_record_stream(self, keys, sort_order, include_delta_closure):
743
        for key in keys:
744
            text = self._load_text(key)
745
            if text is None:
746
                yield AbsentContentFactory(key)
747
            else:
748
                yield FulltextContentFactory(key, None, None, text)
749
750
    def keys(self):
751
        if not self._is_locked():
752
            raise errors.ObjectNotLocked(self)
753
        relpaths = set()
754
        for quoted_relpath in self._transport.iter_files_recursive():
6379.4.2 by Jelmer Vernooij
Add urlutils.quote / urlutils.unquote.
755
            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.
756
            path, ext = os.path.splitext(relpath)
757
            if ext == '.gz':
758
                relpath = path
759
            if not relpath.endswith('.sig'):
760
                continue
761
            relpaths.add(relpath[:-4])
762
        paths = list(relpaths)
6619.3.12 by Jelmer Vernooij
Use 2to3 set_literal fixer.
763
        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
764
5537.2.1 by Jelmer Vernooij
Move InterWeaveRepo and InterKnitRepo to related repository files.
765
766
class InterWeaveRepo(InterSameDataRepository):
767
    """Optimised code paths between Weave based repositories.
768
    """
769
770
    @classmethod
771
    def _get_repo_format_to_test(self):
772
        return RepositoryFormat7()
773
774
    @staticmethod
775
    def is_compatible(source, target):
776
        """Be compatible with known Weave formats.
777
778
        We don't test for the stores being of specific types because that
779
        could lead to confusing results, and there is no need to be
780
        overly general.
781
        """
782
        try:
783
            return (isinstance(source._format, (RepositoryFormat5,
784
                                                RepositoryFormat6,
785
                                                RepositoryFormat7)) and
786
                    isinstance(target._format, (RepositoryFormat5,
787
                                                RepositoryFormat6,
788
                                                RepositoryFormat7)))
789
        except AttributeError:
790
            return False
791
792
    @needs_write_lock
793
    def copy_content(self, revision_id=None):
794
        """See InterRepository.copy_content()."""
795
        # weave specific optimised path:
796
        try:
797
            self.target.set_make_working_trees(self.source.make_working_trees())
798
        except (errors.RepositoryUpgradeRequired, NotImplemented):
799
            pass
800
        # FIXME do not peek!
801
        if self.source._transport.listable():
802
            pb = ui.ui_factory.nested_progress_bar()
803
            try:
804
                self.target.texts.insert_record_stream(
805
                    self.source.texts.get_record_stream(
806
                        self.source.texts.keys(), 'topological', False))
807
                pb.update('Copying inventory', 0, 1)
808
                self.target.inventories.insert_record_stream(
809
                    self.source.inventories.get_record_stream(
810
                        self.source.inventories.keys(), 'topological', False))
811
                self.target.signatures.insert_record_stream(
812
                    self.source.signatures.get_record_stream(
813
                        self.source.signatures.keys(),
814
                        'unordered', True))
815
                self.target.revisions.insert_record_stream(
816
                    self.source.revisions.get_record_stream(
817
                        self.source.revisions.keys(),
818
                        'topological', True))
819
            finally:
820
                pb.finished()
821
        else:
822
            self.target.fetch(self.source, revision_id=revision_id)
823
824
    @needs_read_lock
5539.2.10 by Andrew Bennetts
s/NotInOtherForRev/NotInOtherForRevs/, and allow passing multiple revision_ids to search_missing_revision_ids.
825
    def search_missing_revision_ids(self,
5852.1.6 by Jelmer Vernooij
Add extra test for Repository.search_missing_revision_ids.
826
            find_ghosts=True, revision_ids=None, if_present_ids=None,
827
            limit=None):
5539.2.10 by Andrew Bennetts
s/NotInOtherForRev/NotInOtherForRevs/, and allow passing multiple revision_ids to search_missing_revision_ids.
828
        """See InterRepository.search_missing_revision_ids()."""
5537.2.1 by Jelmer Vernooij
Move InterWeaveRepo and InterKnitRepo to related repository files.
829
        # we want all revisions to satisfy revision_id in source.
830
        # but we don't want to stat every file here and there.
831
        # we want then, all revisions other needs to satisfy revision_id
832
        # checked, but not those that we have locally.
833
        # so the first thing is to get a subset of the revisions to
834
        # satisfy revision_id in source, and then eliminate those that
835
        # we do already have.
836
        # this is slow on high latency connection to self, but as this
837
        # disk format scales terribly for push anyway due to rewriting
838
        # inventory.weave, this is considered acceptable.
839
        # - RBC 20060209
5535.3.32 by Andrew Bennetts
Implement if_present_ids behaviour in all implementations and code paths of searching_missing_revision_ids
840
        source_ids_set = self._present_source_revisions_for(
841
            revision_ids, if_present_ids)
5537.2.1 by Jelmer Vernooij
Move InterWeaveRepo and InterKnitRepo to related repository files.
842
        # source_ids is the worst possible case we may need to pull.
843
        # now we want to filter source_ids against what we actually
844
        # have in target, but don't try to check for existence where we know
845
        # we do not have a revision as that would be pointless.
846
        target_ids = set(self.target._all_possible_ids())
847
        possibly_present_revisions = target_ids.intersection(source_ids_set)
848
        actually_present_revisions = set(
849
            self.target._eliminate_revisions_not_present(possibly_present_revisions))
850
        required_revisions = source_ids_set.difference(actually_present_revisions)
5539.2.10 by Andrew Bennetts
s/NotInOtherForRev/NotInOtherForRevs/, and allow passing multiple revision_ids to search_missing_revision_ids.
851
        if revision_ids is not None:
5537.2.1 by Jelmer Vernooij
Move InterWeaveRepo and InterKnitRepo to related repository files.
852
            # we used get_ancestry to determine source_ids then we are assured all
853
            # revisions referenced are present as they are installed in topological order.
854
            # and the tip revision was validated by get_ancestry.
855
            result_set = required_revisions
856
        else:
857
            # if we just grabbed the possibly available ids, then
858
            # we only have an estimate of whats available and need to validate
859
            # that against the revision records.
860
            result_set = set(
861
                self.source._eliminate_revisions_not_present(required_revisions))
5852.1.6 by Jelmer Vernooij
Add extra test for Repository.search_missing_revision_ids.
862
        if limit is not None:
5852.1.8 by Jelmer Vernooij
Simplify revision limiting.
863
            topo_ordered = self.get_graph().iter_topo_order(result_set)
864
            result_set = set(itertools.islice(topo_ordered, limit))
5537.2.1 by Jelmer Vernooij
Move InterWeaveRepo and InterKnitRepo to related repository files.
865
        return self.source.revision_ids_to_search_result(result_set)
866
867
868
InterRepository.register_optimiser(InterWeaveRepo)
5676.1.9 by Jelmer Vernooij
Fix existing implementation.
869
870
871
def get_extra_interrepo_test_combinations():
6670.4.5 by Jelmer Vernooij
Move breezy.repofmt contents to breezy.bzr.
872
    from ...bzr import knitrepo
5676.1.9 by Jelmer Vernooij
Fix existing implementation.
873
    return [(InterRepository, RepositoryFormat5(),
874
        knitrepo.RepositoryFormatKnit3())]