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