/brz/remove-bazaar

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