/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')
7143.15.2 by Jelmer Vernooij
Run autopep8.
121
        super(AllInOneRepository, self).__init__(
122
            _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
    def _all_possible_ids(self):
125
        """Return all the possible revisions that we could find."""
126
        if 'evil' in debug.debug_flags:
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
127
            trace.mutter_callsite(
128
                3, "_all_possible_ids scales with size of history.")
6754.8.16 by Jelmer Vernooij
Get rid of all uses of needs_read_lock
129
        with self.lock_read():
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
    def _all_revision_ids(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
133
        """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.
134
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
135
        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.
136
        present: for weaves ghosts may lead to a lack of correctness until
137
        the reweave updates the parents list.
138
        """
6754.8.16 by Jelmer Vernooij
Get rid of all uses of needs_read_lock
139
        with self.lock_read():
140
            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.
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,
7143.15.2 by Jelmer Vernooij
Run autopep8.
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,
7143.15.2 by Jelmer Vernooij
Run autopep8.
170
                             check_content=True):
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
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,
7143.15.2 by Jelmer Vernooij
Run autopep8.
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
    def set_make_working_trees(self, new_value):
185
        """Set the policy flag for making working trees when creating branches.
186
187
        This only applies to branches that use this repository.
188
189
        The default is 'True'.
190
        :param new_value: True to restore the default, False to disable making
191
                          working trees.
192
        """
5158.6.10 by Martin Pool
Update more code to use user_transport when it should
193
        raise errors.RepositoryUpgradeRequired(self.user_url)
3349.1.1 by Aaron Bentley
Enable setting and getting make_working_trees for all repositories
194
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
195
    def make_working_trees(self):
196
        """Returns the policy for making working trees on new branches."""
197
        return True
198
199
3316.2.3 by Robert Collins
Remove manual notification of transaction finishing on versioned files.
200
class WeaveMetaDirRepository(MetaDirVersionedFileRepository):
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
201
    """A subclass of MetaDirRepository to set weave specific policy."""
202
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
203
    def __init__(self, _format, a_controldir, control_files):
6754.8.16 by Jelmer Vernooij
Get rid of all uses of needs_read_lock
204
        super(WeaveMetaDirRepository, self).__init__(
7143.15.2 by Jelmer Vernooij
Run autopep8.
205
            _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
    def _all_possible_ids(self):
209
        """Return all the possible revisions that we could find."""
210
        if 'evil' in debug.debug_flags:
5184.1.1 by Vincent Ladeuil
Random cleanups to catch up with copyright updates in trunk.
211
            trace.mutter_callsite(
212
                3, "_all_possible_ids scales with size of history.")
6754.8.16 by Jelmer Vernooij
Get rid of all uses of needs_read_lock
213
        with self.lock_read():
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
    def _all_revision_ids(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
217
        """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.
218
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
219
        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.
220
        present: for weaves ghosts may lead to a lack of correctness until
221
        the reweave updates the parents list.
222
        """
6754.8.16 by Jelmer Vernooij
Get rid of all uses of needs_read_lock
223
        with self.lock_read():
224
            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.
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,
7143.15.2 by Jelmer Vernooij
Run autopep8.
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
    def get_revision(self, revision_id):
254
        """Return the Revision object for a named revision"""
6754.8.16 by Jelmer Vernooij
Get rid of all uses of needs_read_lock
255
        with self.lock_read():
256
            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.
257
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.
258
    def _inventory_add_lines(self, revision_id, parents, lines,
7143.15.2 by Jelmer Vernooij
Run autopep8.
259
                             check_content=True):
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
260
        """Store lines in inv_vf and return the sha1 of the inventory."""
261
        present_parents = self.get_graph().get_parent_map(parents)
262
        final_parents = []
263
        for parent in parents:
264
            if parent in present_parents:
265
                final_parents.append((parent,))
266
        return self.inventories.add_lines((revision_id,), final_parents, lines,
7143.15.2 by Jelmer Vernooij
Run autopep8.
267
                                          check_content=check_content)[0]
3172.3.1 by Robert Collins
Repository has a new method ``has_revisions`` which signals the presence
268
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
269
5815.4.5 by Jelmer Vernooij
Use MetaDirVersionedFileRepositoryFormat (a Soyuz worthy name).
270
class PreSplitOutRepositoryFormat(VersionedFileRepositoryFormat):
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
271
    """Base class for the pre split out repository formats."""
272
273
    rich_root_data = False
2323.5.17 by Martin Pool
Add supports_tree_reference to all repo formats (robert)
274
    supports_tree_reference = False
2949.1.2 by Robert Collins
* Fetch with pack repositories will no longer read the entire history graph.
275
    supports_ghosts = False
3221.3.1 by Robert Collins
* Repository formats have a new supported-feature attribute
276
    supports_external_lookups = False
4246.2.1 by Ian Clatworthy
supports_chks flag on repo formats & log tuning
277
    supports_chks = False
6145.2.2 by Jelmer Vernooij
Set supports_nesting_repositories.
278
    supports_nesting_repositories = True
4053.1.4 by Robert Collins
Move the fetch control attributes from Repository to RepositoryFormat.
279
    _fetch_order = 'topological'
280
    _fetch_reconcile = True
4183.5.1 by Robert Collins
Add RepositoryFormat.fast_deltas to signal fast delta creation.
281
    fast_deltas = False
5674.1.1 by Jelmer Vernooij
Add supports_leave_lock flag to BranchFormat and RepositoryFormat.
282
    supports_leaving_lock = False
6820.2.1 by Jelmer Vernooij
Add flag to check whether overriding transport is supported.
283
    supports_overriding_transport = False
5766.1.1 by Jelmer Vernooij
Make revision-graph-can-have-wrong-parents a repository format attribute rather than a repository method.
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,
7143.15.2 by Jelmer Vernooij
Run autopep8.
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:
6926.1.4 by Jelmer Vernooij
remove mkdir_multi.
312
            transport.mkdir('revision-store',
313
                            mode=a_controldir._get_dir_mode())
314
            transport.mkdir('weaves', mode=a_controldir._get_dir_mode())
3407.2.18 by Martin Pool
BzrDir takes responsibility for default file/dir modes
315
            transport.put_bytes_non_atomic('inventory.weave', empty_weave,
7143.15.2 by Jelmer Vernooij
Run autopep8.
316
                                           mode=a_controldir._get_file_mode())
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
317
        finally:
318
            control_files.unlock()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
319
        repository = self.open(a_controldir, _found=True)
320
        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',
321
        return repository
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
322
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
323
    def open(self, a_controldir, _found=False):
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
324
        """See RepositoryFormat.open()."""
325
        if not _found:
326
            # we are being called directly and must probe.
327
            raise NotImplementedError
328
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
329
        repo_transport = a_controldir.get_repository_transport(None)
330
        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.
331
        result.revisions = self._get_revisions(repo_transport, result)
332
        result.signatures = self._get_signatures(repo_transport, result)
333
        result.inventories = self._get_inventories(repo_transport, result)
334
        result.texts = self._get_texts(repo_transport, result)
4246.2.1 by Ian Clatworthy
supports_chks flag on repo formats & log tuning
335
        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.
336
        return result
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
337
5675.2.1 by Jelmer Vernooij
Add RepositoryFormat.is_deprecated(). This removes the need for
338
    def is_deprecated(self):
339
        return True
340
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
341
342
class RepositoryFormat4(PreSplitOutRepositoryFormat):
343
    """Bzr repository format 4.
344
345
    This repository format has:
346
     - flat stores
347
     - TextStores for texts, inventories,revisions.
348
349
    This format is deprecated: it indexes texts using a text id which is
350
    removed in format 5; initialization and write support for this format
351
    has been removed.
352
    """
353
5582.9.1 by Jelmer Vernooij
Add flag for 'supports_funky_characters'.
354
    supports_funky_characters = False
355
6746.2.1 by Jelmer Vernooij
Rename matchingbzrdir to matchingcontroldir.
356
    _matchingcontroldir = weave_bzrdir.BzrDirFormat4()
2241.1.11 by Martin Pool
Get rid of RepositoryFormat*_instance objects. Instead the format
357
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
358
    def get_format_description(self):
359
        """See RepositoryFormat.get_format_description()."""
360
        return "Repository format 4"
361
362
    def initialize(self, url, shared=False, _internal=False):
363
        """Format 4 branches cannot be created."""
364
        raise errors.UninitializableFormat(self)
365
366
    def is_supported(self):
367
        """Format 4 is not supported.
368
369
        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
370
        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.
371
        feasible.
372
        """
373
        return False
374
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
    def _get_inventories(self, repo_transport, repo, name='inventory'):
376
        # No inventories store written so far.
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
377
        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.
378
379
    def _get_revisions(self, repo_transport, repo):
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
380
        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.
381
        return RevisionTextStore(repo_transport.clone('revision-store'),
7143.15.2 by Jelmer Vernooij
Run autopep8.
382
                                 serializer_v4, True, versionedfile.PrefixMapper(),
383
                                 repo.is_locked, repo.is_write_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.
384
385
    def _get_signatures(self, repo_transport, repo):
386
        return SignatureTextStore(repo_transport.clone('revision-store'),
7143.15.2 by Jelmer Vernooij
Run autopep8.
387
                                  False, versionedfile.PrefixMapper(),
388
                                  repo.is_locked, repo.is_write_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.
389
390
    def _get_texts(self, repo_transport, repo):
391
        return None
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
392
393
394
class RepositoryFormat5(PreSplitOutRepositoryFormat):
395
    """Bzr control format 5.
396
397
    This repository format has:
398
     - weaves for file texts and inventory
399
     - flat stores
400
     - TextStores for revisions and signatures.
401
    """
402
5582.10.42 by Jelmer Vernooij
Some weave fixes.
403
    _versionedfile_class = weave.WeaveFile
6746.2.1 by Jelmer Vernooij
Rename matchingbzrdir to matchingcontroldir.
404
    _matchingcontroldir = weave_bzrdir.BzrDirFormat5()
5582.9.1 by Jelmer Vernooij
Add flag for 'supports_funky_characters'.
405
    supports_funky_characters = False
406
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)
407
    @property
408
    def _serializer(self):
409
        return xml5.serializer_v5
2241.1.10 by Martin Pool
Remove more references to weaves from the repository.py file
410
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
411
    def get_format_description(self):
412
        """See RepositoryFormat.get_format_description()."""
413
        return "Weave repository format 5"
4032.1.2 by John Arbash Meinel
Track down a few more files that have trailing whitespace.
414
3990.5.1 by Andrew Bennetts
Add network_name() to RepositoryFormat.
415
    def network_name(self):
3990.5.3 by Robert Collins
Docs and polish on RepositoryFormat.network_name.
416
        """The network name for this format is the control dirs disk label."""
6746.2.1 by Jelmer Vernooij
Rename matchingbzrdir to matchingcontroldir.
417
        return self._matchingcontroldir.get_format_string()
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
418
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.
419
    def _get_inventories(self, repo_transport, repo, name='inventory'):
420
        mapper = versionedfile.ConstantMapper(name)
421
        return versionedfile.ThunkedVersionedFiles(repo_transport,
7143.15.2 by Jelmer Vernooij
Run autopep8.
422
                                                   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.
423
424
    def _get_revisions(self, repo_transport, repo):
425
        return RevisionTextStore(repo_transport.clone('revision-store'),
7143.15.2 by Jelmer Vernooij
Run autopep8.
426
                                 xml5.serializer_v5, False, versionedfile.PrefixMapper(),
427
                                 repo.is_locked, repo.is_write_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.
428
429
    def _get_signatures(self, repo_transport, repo):
430
        return SignatureTextStore(repo_transport.clone('revision-store'),
7143.15.2 by Jelmer Vernooij
Run autopep8.
431
                                  False, versionedfile.PrefixMapper(),
432
                                  repo.is_locked, repo.is_write_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.
433
434
    def _get_texts(self, repo_transport, repo):
435
        mapper = versionedfile.PrefixMapper()
436
        base_transport = repo_transport.clone('weaves')
437
        return versionedfile.ThunkedVersionedFiles(base_transport,
7143.15.2 by Jelmer Vernooij
Run autopep8.
438
                                                   weave.WeaveFile, mapper, repo.is_locked)
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
439
440
441
class RepositoryFormat6(PreSplitOutRepositoryFormat):
442
    """Bzr control format 6.
443
444
    This repository format has:
445
     - weaves for file texts and inventory
446
     - hash subdirectory based stores.
447
     - TextStores for revisions and signatures.
448
    """
449
5582.10.42 by Jelmer Vernooij
Some weave fixes.
450
    _versionedfile_class = weave.WeaveFile
6746.2.1 by Jelmer Vernooij
Rename matchingbzrdir to matchingcontroldir.
451
    _matchingcontroldir = weave_bzrdir.BzrDirFormat6()
5582.9.1 by Jelmer Vernooij
Add flag for 'supports_funky_characters'.
452
    supports_funky_characters = False
7143.15.2 by Jelmer Vernooij
Run autopep8.
453
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)
454
    @property
455
    def _serializer(self):
456
        return xml5.serializer_v5
2241.1.10 by Martin Pool
Remove more references to weaves from the repository.py file
457
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
458
    def get_format_description(self):
459
        """See RepositoryFormat.get_format_description()."""
460
        return "Weave repository format 6"
461
3990.5.1 by Andrew Bennetts
Add network_name() to RepositoryFormat.
462
    def network_name(self):
3990.5.3 by Robert Collins
Docs and polish on RepositoryFormat.network_name.
463
        """The network name for this format is the control dirs disk label."""
6746.2.1 by Jelmer Vernooij
Rename matchingbzrdir to matchingcontroldir.
464
        return self._matchingcontroldir.get_format_string()
3990.5.1 by Andrew Bennetts
Add network_name() to RepositoryFormat.
465
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
    def _get_inventories(self, repo_transport, repo, name='inventory'):
467
        mapper = versionedfile.ConstantMapper(name)
468
        return versionedfile.ThunkedVersionedFiles(repo_transport,
7143.15.2 by Jelmer Vernooij
Run autopep8.
469
                                                   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.
470
471
    def _get_revisions(self, repo_transport, repo):
472
        return RevisionTextStore(repo_transport.clone('revision-store'),
7143.15.2 by Jelmer Vernooij
Run autopep8.
473
                                 xml5.serializer_v5, False, versionedfile.HashPrefixMapper(),
474
                                 repo.is_locked, repo.is_write_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.
475
476
    def _get_signatures(self, repo_transport, repo):
477
        return SignatureTextStore(repo_transport.clone('revision-store'),
7143.15.2 by Jelmer Vernooij
Run autopep8.
478
                                  False, versionedfile.HashPrefixMapper(),
479
                                  repo.is_locked, repo.is_write_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.
480
481
    def _get_texts(self, repo_transport, repo):
482
        mapper = versionedfile.HashPrefixMapper()
483
        base_transport = repo_transport.clone('weaves')
484
        return versionedfile.ThunkedVersionedFiles(base_transport,
7143.15.2 by Jelmer Vernooij
Run autopep8.
485
                                                   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.
486
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
487
5815.4.5 by Jelmer Vernooij
Use MetaDirVersionedFileRepositoryFormat (a Soyuz worthy name).
488
class RepositoryFormat7(MetaDirVersionedFileRepositoryFormat):
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
489
    """Bzr repository 7.
490
491
    This repository format has:
492
     - weaves for file texts and inventory
493
     - hash subdirectory based stores.
494
     - TextStores for revisions and signatures.
495
     - a format marker of its own
496
     - an optional 'shared-storage' flag
497
     - an optional 'no-working-trees' flag
498
    """
499
5582.10.42 by Jelmer Vernooij
Some weave fixes.
500
    _versionedfile_class = weave.WeaveFile
2949.1.2 by Robert Collins
* Fetch with pack repositories will no longer read the entire history graph.
501
    supports_ghosts = False
4246.2.1 by Ian Clatworthy
supports_chks flag on repo formats & log tuning
502
    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.
503
    supports_funky_characters = False
5766.1.4 by Jelmer Vernooij
Set revision_graph_can_have_wrong_parents on RepositoryFormat7.
504
    revision_graph_can_have_wrong_parents = False
4246.2.1 by Ian Clatworthy
supports_chks flag on repo formats & log tuning
505
4053.1.4 by Robert Collins
Move the fetch control attributes from Repository to RepositoryFormat.
506
    _fetch_order = 'topological'
507
    _fetch_reconcile = True
4183.5.1 by Robert Collins
Add RepositoryFormat.fast_deltas to signal fast delta creation.
508
    fast_deltas = False
7143.15.2 by Jelmer Vernooij
Run autopep8.
509
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)
510
    @property
511
    def _serializer(self):
512
        return xml5.serializer_v5
2241.1.10 by Martin Pool
Remove more references to weaves from the repository.py file
513
6213.1.16 by Jelmer Vernooij
Feature support in repository.
514
    @classmethod
515
    def get_format_string(cls):
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
516
        """See RepositoryFormat.get_format_string()."""
6855.2.2 by Jelmer Vernooij
Format strings are bytes.
517
        return b"Bazaar-NG Repository format 7"
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
518
519
    def get_format_description(self):
520
        """See RepositoryFormat.get_format_description()."""
521
        return "Weave repository format 7"
522
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.
523
    def _get_inventories(self, repo_transport, repo, name='inventory'):
524
        mapper = versionedfile.ConstantMapper(name)
525
        return versionedfile.ThunkedVersionedFiles(repo_transport,
7143.15.2 by Jelmer Vernooij
Run autopep8.
526
                                                   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.
527
528
    def _get_revisions(self, repo_transport, repo):
529
        return RevisionTextStore(repo_transport.clone('revision-store'),
7143.15.2 by Jelmer Vernooij
Run autopep8.
530
                                 xml5.serializer_v5, True, versionedfile.HashPrefixMapper(),
531
                                 repo.is_locked, repo.is_write_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.
532
533
    def _get_signatures(self, repo_transport, repo):
534
        return SignatureTextStore(repo_transport.clone('revision-store'),
7143.15.2 by Jelmer Vernooij
Run autopep8.
535
                                  True, versionedfile.HashPrefixMapper(),
536
                                  repo.is_locked, repo.is_write_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.
537
538
    def _get_texts(self, repo_transport, repo):
539
        mapper = versionedfile.HashPrefixMapper()
540
        base_transport = repo_transport.clone('weaves')
541
        return versionedfile.ThunkedVersionedFiles(base_transport,
7143.15.2 by Jelmer Vernooij
Run autopep8.
542
                                                   weave.WeaveFile, mapper, repo.is_locked)
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
543
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
544
    def initialize(self, a_controldir, shared=False):
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
545
        """Create a weave repository.
546
547
        :param shared: If true the repository will be initialized as a shared
548
                       repository.
549
        """
550
        # Create an empty weave
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
551
        sio = BytesIO()
5582.10.44 by Jelmer Vernooij
Clean up patch.
552
        weavefile.write_weave_v5(weave.Weave(), sio)
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
553
        empty_weave = sio.getvalue()
554
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
555
        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.
556
        dirs = ['revision-store', 'weaves']
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
557
        files = [('inventory.weave', BytesIO(empty_weave)),
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
558
                 ]
559
        utf8_files = [('format', self.get_format_string())]
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
560
7143.15.2 by Jelmer Vernooij
Run autopep8.
561
        self._upload_blank_content(
562
            a_controldir, dirs, files, utf8_files, shared)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
563
        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.
564
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
565
    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.
566
        """See RepositoryFormat.open().
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
567
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
568
        :param _override_transport: INTERNAL USE ONLY. Allows opening the
569
                                    repository at a slightly different url
570
                                    than normal. I.e. during 'upgrade'.
571
        """
572
        if not _found:
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
573
            format = RepositoryFormatMetaDir.find_format(a_controldir)
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
574
        if _override_transport is not None:
575
            repo_transport = _override_transport
576
        else:
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
577
            repo_transport = a_controldir.get_repository_transport(None)
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
578
        control_files = lockable_files.LockableFiles(repo_transport,
7143.15.2 by Jelmer Vernooij
Run autopep8.
579
                                                     'lock', lockdir.LockDir)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
580
        result = WeaveMetaDirRepository(_format=self, a_controldir=a_controldir,
7143.15.2 by Jelmer Vernooij
Run autopep8.
581
                                        control_files=control_files)
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
582
        result.revisions = self._get_revisions(repo_transport, result)
583
        result.signatures = self._get_signatures(repo_transport, result)
584
        result.inventories = self._get_inventories(repo_transport, result)
585
        result.texts = self._get_texts(repo_transport, result)
4246.2.1 by Ian Clatworthy
supports_chks flag on repo formats & log tuning
586
        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.
587
        result._transport = repo_transport
588
        return result
589
5675.2.1 by Jelmer Vernooij
Add RepositoryFormat.is_deprecated(). This removes the need for
590
    def is_deprecated(self):
591
        return True
592
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.
593
594
class TextVersionedFiles(VersionedFiles):
595
    """Just-a-bunch-of-files based VersionedFile stores."""
596
597
    def __init__(self, transport, compressed, mapper, is_locked, can_write):
598
        self._compressed = compressed
599
        self._transport = transport
600
        self._mapper = mapper
601
        if self._compressed:
602
            self._ext = '.gz'
603
        else:
604
            self._ext = ''
605
        self._is_locked = is_locked
606
        self._can_write = can_write
607
608
    def add_lines(self, key, parents, lines):
609
        """Add a revision to the store."""
610
        if not self._is_locked():
611
            raise errors.ObjectNotLocked(self)
612
        if not self._can_write():
613
            raise errors.ReadOnlyError(self)
6963.2.6 by Jelmer Vernooij
Fix some more tests.
614
        if b'/' in key[-1]:
3350.6.10 by Martin Pool
VersionedFiles review cleanups
615
            raise ValueError('bad idea to put / in %r' % (key,))
6833.6.1 by Jelmer Vernooij
Remove bytes_to_gzip; work with chunks instead.
616
        chunks = lines
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
617
        if self._compressed:
6833.6.1 by Jelmer Vernooij
Remove bytes_to_gzip; work with chunks instead.
618
            chunks = tuned_gzip.chunks_to_gzip(chunks)
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
619
        path = self._map(key)
6833.6.1 by Jelmer Vernooij
Remove bytes_to_gzip; work with chunks instead.
620
        self._transport.put_file_non_atomic(
7143.15.2 by Jelmer Vernooij
Run autopep8.
621
            path, BytesIO(b''.join(chunks)),
622
            create_parent_dir=True)
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
623
5195.3.26 by Parth Malwankar
reverted changes done to insert_record_stream API
624
    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.
625
        adapters = {}
626
        for record in stream:
627
            # Raise an error when a record is missing.
628
            if record.storage_kind == 'absent':
629
                raise errors.RevisionNotPresent([record.key[0]], self)
630
            # adapt to non-tuple interface
631
            if record.storage_kind == 'fulltext':
632
                self.add_lines(record.key, None,
7143.15.2 by Jelmer Vernooij
Run autopep8.
633
                               osutils.split_lines(record.get_bytes_as('fulltext')))
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.
634
            else:
635
                adapter_key = record.storage_kind, 'fulltext'
636
                try:
637
                    adapter = adapters[adapter_key]
638
                except KeyError:
639
                    adapter_factory = adapter_registry.get(adapter_key)
640
                    adapter = adapter_factory(self)
641
                    adapters[adapter_key] = adapter
642
                lines = osutils.split_lines(adapter.get_bytes(
643
                    record, record.get_bytes_as(record.storage_kind)))
644
                try:
645
                    self.add_lines(record.key, None, lines)
5815.4.17 by Jelmer Vernooij
Remove unused test method.
646
                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.
647
                    pass
648
649
    def _load_text(self, key):
650
        if not self._is_locked():
651
            raise errors.ObjectNotLocked(self)
652
        path = self._map(key)
653
        try:
654
            text = self._transport.get_bytes(path)
655
            compressed = self._compressed
656
        except errors.NoSuchFile:
657
            if self._compressed:
658
                # try without the .gz
659
                path = path[:-3]
660
                try:
661
                    text = self._transport.get_bytes(path)
662
                    compressed = False
663
                except errors.NoSuchFile:
664
                    return None
665
            else:
666
                return None
667
        if compressed:
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
668
            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.
669
        return text
670
671
    def _map(self, key):
672
        return self._mapper.map(key) + self._ext
673
674
675
class RevisionTextStore(TextVersionedFiles):
676
    """Legacy thunk for format 4 repositories."""
677
678
    def __init__(self, transport, serializer, compressed, mapper, is_locked,
7143.15.2 by Jelmer Vernooij
Run autopep8.
679
                 can_write):
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.
680
        """Create a RevisionTextStore at transport with serializer."""
681
        TextVersionedFiles.__init__(self, transport, compressed, mapper,
7143.15.2 by Jelmer Vernooij
Run autopep8.
682
                                    is_locked, can_write)
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.
683
        self._serializer = serializer
684
685
    def _load_text_parents(self, key):
686
        text = self._load_text(key)
687
        if text is None:
688
            return None, None
689
        parents = self._serializer.read_revision_from_string(text).parent_ids
690
        return text, tuple((parent,) for parent in parents)
691
692
    def get_parent_map(self, keys):
693
        result = {}
694
        for key in keys:
695
            parents = self._load_text_parents(key)[1]
696
            if parents is None:
697
                continue
698
            result[key] = parents
699
        return result
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
700
4593.5.34 by John Arbash Meinel
Change the KnownGraph.merge_sort api.
701
    def get_known_graph_ancestry(self, keys):
702
        """Get a KnownGraph instance with the ancestry of keys."""
703
        keys = self.keys()
704
        parent_map = self.get_parent_map(keys)
705
        kg = _mod_graph.KnownGraph(parent_map)
706
        return kg
707
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.
708
    def get_record_stream(self, keys, sort_order, include_delta_closure):
709
        for key in keys:
710
            text, parents = self._load_text_parents(key)
711
            if text is None:
712
                yield AbsentContentFactory(key)
713
            else:
714
                yield FulltextContentFactory(key, parents, None, text)
715
716
    def keys(self):
717
        if not self._is_locked():
718
            raise errors.ObjectNotLocked(self)
719
        relpaths = set()
720
        for quoted_relpath in self._transport.iter_files_recursive():
6379.4.2 by Jelmer Vernooij
Add urlutils.quote / urlutils.unquote.
721
            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.
722
            path, ext = os.path.splitext(relpath)
723
            if ext == '.gz':
724
                relpath = path
4695.2.1 by Vincent Ladeuil
Align RevisionTextStore and SignatureTextStore keys() definitions.
725
            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.
726
                relpaths.add(relpath)
727
        paths = list(relpaths)
6619.3.12 by Jelmer Vernooij
Use 2to3 set_literal fixer.
728
        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.
729
730
731
class SignatureTextStore(TextVersionedFiles):
732
    """Legacy thunk for format 4-7 repositories."""
733
734
    def __init__(self, transport, compressed, mapper, is_locked, can_write):
735
        TextVersionedFiles.__init__(self, transport, compressed, mapper,
7143.15.2 by Jelmer Vernooij
Run autopep8.
736
                                    is_locked, can_write)
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.
737
        self._ext = '.sig' + self._ext
738
739
    def get_parent_map(self, keys):
740
        result = {}
741
        for key in keys:
742
            text = self._load_text(key)
743
            if text is None:
744
                continue
745
            result[key] = None
746
        return result
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
747
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.
748
    def get_record_stream(self, keys, sort_order, include_delta_closure):
749
        for key in keys:
750
            text = self._load_text(key)
751
            if text is None:
752
                yield AbsentContentFactory(key)
753
            else:
754
                yield FulltextContentFactory(key, None, None, text)
755
756
    def keys(self):
757
        if not self._is_locked():
758
            raise errors.ObjectNotLocked(self)
759
        relpaths = set()
760
        for quoted_relpath in self._transport.iter_files_recursive():
6379.4.2 by Jelmer Vernooij
Add urlutils.quote / urlutils.unquote.
761
            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.
762
            path, ext = os.path.splitext(relpath)
763
            if ext == '.gz':
764
                relpath = path
765
            if not relpath.endswith('.sig'):
766
                continue
767
            relpaths.add(relpath[:-4])
768
        paths = list(relpaths)
6619.3.12 by Jelmer Vernooij
Use 2to3 set_literal fixer.
769
        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
770
5537.2.1 by Jelmer Vernooij
Move InterWeaveRepo and InterKnitRepo to related repository files.
771
772
class InterWeaveRepo(InterSameDataRepository):
773
    """Optimised code paths between Weave based repositories.
774
    """
775
776
    @classmethod
777
    def _get_repo_format_to_test(self):
778
        return RepositoryFormat7()
779
780
    @staticmethod
781
    def is_compatible(source, target):
782
        """Be compatible with known Weave formats.
783
784
        We don't test for the stores being of specific types because that
785
        could lead to confusing results, and there is no need to be
786
        overly general.
787
        """
788
        try:
789
            return (isinstance(source._format, (RepositoryFormat5,
790
                                                RepositoryFormat6,
7143.15.2 by Jelmer Vernooij
Run autopep8.
791
                                                RepositoryFormat7))
792
                    and isinstance(target._format, (RepositoryFormat5,
7143.15.5 by Jelmer Vernooij
More PEP8 fixes.
793
                                                    RepositoryFormat6,
794
                                                    RepositoryFormat7)))
5537.2.1 by Jelmer Vernooij
Move InterWeaveRepo and InterKnitRepo to related repository files.
795
        except AttributeError:
796
            return False
797
798
    def copy_content(self, revision_id=None):
799
        """See InterRepository.copy_content()."""
6754.8.17 by Jelmer Vernooij
Remove uses of needs_write_lock.
800
        with self.lock_write():
801
            # weave specific optimised path:
5537.2.1 by Jelmer Vernooij
Move InterWeaveRepo and InterKnitRepo to related repository files.
802
            try:
7143.15.2 by Jelmer Vernooij
Run autopep8.
803
                self.target.set_make_working_trees(
804
                    self.source.make_working_trees())
6855.4.5 by Jelmer Vernooij
Fix more bees, use with rather than try/finally for some files.
805
            except (errors.RepositoryUpgradeRequired, NotImplementedError):
6754.8.17 by Jelmer Vernooij
Remove uses of needs_write_lock.
806
                pass
807
            # FIXME do not peek!
808
            if self.source._transport.listable():
6861.4.1 by Jelmer Vernooij
Make progress bars context managers.
809
                with ui.ui_factory.nested_progress_bar() as pb:
6754.8.17 by Jelmer Vernooij
Remove uses of needs_write_lock.
810
                    self.target.texts.insert_record_stream(
811
                        self.source.texts.get_record_stream(
812
                            self.source.texts.keys(), 'topological', False))
813
                    pb.update('Copying inventory', 0, 1)
814
                    self.target.inventories.insert_record_stream(
815
                        self.source.inventories.get_record_stream(
816
                            self.source.inventories.keys(), 'topological', False))
817
                    self.target.signatures.insert_record_stream(
818
                        self.source.signatures.get_record_stream(
819
                            self.source.signatures.keys(),
820
                            'unordered', True))
821
                    self.target.revisions.insert_record_stream(
822
                        self.source.revisions.get_record_stream(
823
                            self.source.revisions.keys(),
824
                            'topological', True))
825
            else:
826
                self.target.fetch(self.source, revision_id=revision_id)
5537.2.1 by Jelmer Vernooij
Move InterWeaveRepo and InterKnitRepo to related repository files.
827
6754.8.16 by Jelmer Vernooij
Get rid of all uses of needs_read_lock
828
    def search_missing_revision_ids(self, find_ghosts=True, revision_ids=None,
829
                                    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.
830
        """See InterRepository.search_missing_revision_ids()."""
6754.8.16 by Jelmer Vernooij
Get rid of all uses of needs_read_lock
831
        with self.lock_read():
832
            # we want all revisions to satisfy revision_id in source.
833
            # but we don't want to stat every file here and there.
834
            # we want then, all revisions other needs to satisfy revision_id
835
            # checked, but not those that we have locally.
836
            # so the first thing is to get a subset of the revisions to
837
            # satisfy revision_id in source, and then eliminate those that
838
            # we do already have.
839
            # this is slow on high latency connection to self, but as this
840
            # disk format scales terribly for push anyway due to rewriting
841
            # inventory.weave, this is considered acceptable.
842
            # - RBC 20060209
843
            source_ids_set = self._present_source_revisions_for(
844
                revision_ids, if_present_ids)
845
            # source_ids is the worst possible case we may need to pull.
846
            # now we want to filter source_ids against what we actually
847
            # have in target, but don't try to check for existence where we
848
            # know we do not have a revision as that would be pointless.
849
            target_ids = set(self.target._all_possible_ids())
850
            possibly_present_revisions = target_ids.intersection(
7143.15.2 by Jelmer Vernooij
Run autopep8.
851
                source_ids_set)
6754.8.16 by Jelmer Vernooij
Get rid of all uses of needs_read_lock
852
            actually_present_revisions = set(
853
                self.target._eliminate_revisions_not_present(
854
                    possibly_present_revisions))
855
            required_revisions = source_ids_set.difference(
7143.15.2 by Jelmer Vernooij
Run autopep8.
856
                actually_present_revisions)
6754.8.16 by Jelmer Vernooij
Get rid of all uses of needs_read_lock
857
            if revision_ids is not None:
858
                # we used get_ancestry to determine source_ids then we are
859
                # assured all revisions referenced are present as they are
860
                # installed in topological order. and the tip revision was
861
                # validated by get_ancestry.
862
                result_set = required_revisions
863
            else:
864
                # if we just grabbed the possibly available ids, then
865
                # we only have an estimate of whats available and need to
866
                # validate that against the revision records.
867
                result_set = set(
868
                    self.source._eliminate_revisions_not_present(
869
                        required_revisions))
870
            if limit is not None:
871
                topo_ordered = self.get_graph().iter_topo_order(result_set)
872
                result_set = set(itertools.islice(topo_ordered, limit))
873
            return self.source.revision_ids_to_search_result(result_set)
5537.2.1 by Jelmer Vernooij
Move InterWeaveRepo and InterKnitRepo to related repository files.
874
875
876
InterRepository.register_optimiser(InterWeaveRepo)
5676.1.9 by Jelmer Vernooij
Fix existing implementation.
877
878
879
def get_extra_interrepo_test_combinations():
6670.4.5 by Jelmer Vernooij
Move breezy.repofmt contents to breezy.bzr.
880
    from ...bzr import knitrepo
5676.1.9 by Jelmer Vernooij
Fix existing implementation.
881
    return [(InterRepository, RepositoryFormat5(),
7143.15.2 by Jelmer Vernooij
Run autopep8.
882
             knitrepo.RepositoryFormatKnit3())]