~bzr-pqm/bzr/bzr.dev

2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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
23
from StringIO import StringIO
24
25
from bzrlib import (
26
    bzrdir,
2850.3.1 by Robert Collins
Move various weave specific code out of the base Repository class to weaverepo.py.
27
    debug,
28
    errors,
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
29
    lockable_files,
30
    lockdir,
2803.2.1 by Robert Collins
* CommitBuilder now advertises itself as requiring the root entry to be
31
    osutils,
2850.3.1 by Robert Collins
Move various weave specific code out of the base Repository class to weaverepo.py.
32
    revision as _mod_revision,
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
33
    weave,
34
    weavefile,
2241.1.8 by Martin Pool
Set the repository's serializer in the places it's needed, not in the base class
35
    xml5,
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
36
    )
37
from bzrlib.decorators import needs_read_lock, needs_write_lock
38
from bzrlib.repository import (
2803.2.1 by Robert Collins
* CommitBuilder now advertises itself as requiring the root entry to be
39
    CommitBuilder,
3316.2.3 by Robert Collins
Remove manual notification of transaction finishing on versioned files.
40
    MetaDirVersionedFileRepository,
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
41
    MetaDirRepositoryFormat,
42
    Repository,
43
    RepositoryFormat,
44
    )
45
from bzrlib.store.text import TextStore
3287.6.1 by Robert Collins
* ``VersionedFile.get_graph`` is deprecated, with no replacement method.
46
from bzrlib.symbol_versioning import deprecated_method, one_four
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
47
from bzrlib.trace import mutter
48
49
50
class AllInOneRepository(Repository):
51
    """Legacy support - the repository behaviour for all-in-one branches."""
52
2241.1.8 by Martin Pool
Set the repository's serializer in the places it's needed, not in the base class
53
    _serializer = xml5.serializer_v5
54
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
55
    def __init__(self, _format, a_bzrdir, _revision_store, control_store, text_store):
56
        # we reuse one control files instance.
57
        dir_mode = a_bzrdir._control_files._dir_mode
58
        file_mode = a_bzrdir._control_files._file_mode
59
60
        def get_store(name, compressed=True, prefixed=False):
61
            # FIXME: This approach of assuming stores are all entirely compressed
62
            # or entirely uncompressed is tidy, but breaks upgrade from 
63
            # some existing branches where there's a mixture; we probably 
64
            # still want the option to look for both.
65
            relpath = a_bzrdir._control_files._escape(name)
66
            store = TextStore(a_bzrdir._control_files._transport.clone(relpath),
67
                              prefixed=prefixed, compressed=compressed,
68
                              dir_mode=dir_mode,
69
                              file_mode=file_mode)
70
            return store
71
72
        # not broken out yet because the controlweaves|inventory_store
73
        # and text_store | weave_store bits are still different.
74
        if isinstance(_format, RepositoryFormat4):
75
            # cannot remove these - there is still no consistent api 
76
            # which allows access to this old info.
77
            self.inventory_store = get_store('inventory-store')
78
            text_store = get_store('text-store')
79
        super(AllInOneRepository, self).__init__(_format, a_bzrdir, a_bzrdir._control_files, _revision_store, control_store, text_store)
3316.2.3 by Robert Collins
Remove manual notification of transaction finishing on versioned files.
80
        if control_store is not None:
81
            control_store.get_scope = self.get_transaction
82
        text_store.get_scope = self.get_transaction
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
83
2850.3.1 by Robert Collins
Move various weave specific code out of the base Repository class to weaverepo.py.
84
    @needs_read_lock
85
    def _all_possible_ids(self):
86
        """Return all the possible revisions that we could find."""
87
        if 'evil' in debug.debug_flags:
88
            mutter_callsite(3, "_all_possible_ids scales with size of history.")
89
        return self.get_inventory_weave().versions()
90
91
    @needs_read_lock
92
    def _all_revision_ids(self):
93
        """Returns a list of all the revision ids in the repository. 
94
95
        These are in as much topological order as the underlying store can 
96
        present: for weaves ghosts may lead to a lack of correctness until
97
        the reweave updates the parents list.
98
        """
99
        if self._revision_store.text_store.listable():
100
            return self._revision_store.all_revision_ids(self.get_transaction())
101
        result = self._all_possible_ids()
102
        # TODO: jam 20070210 Ensure that _all_possible_ids returns non-unicode
103
        #       ids. (It should, since _revision_store's API should change to
104
        #       return utf8 revision_ids)
105
        return self._eliminate_revisions_not_present(result)
106
107
    def _check_revision_parents(self, revision, inventory):
108
        """Private to Repository and Fetch.
109
        
110
        This checks the parentage of revision in an inventory weave for 
111
        consistency and is only applicable to inventory-weave-for-ancestry
112
        using repository formats & fetchers.
113
        """
3287.5.2 by Robert Collins
Deprecate VersionedFile.get_parents, breaking pulling from a ghost containing knit or pack repository to weaves, which improves correctness and allows simplification of core code.
114
        weave_parents = inventory.get_parent_map(
115
            [revision.revision_id])[revision.revision_id]
116
        parent_map = inventory.get_parent_map(revision.parent_ids)
2850.3.1 by Robert Collins
Move various weave specific code out of the base Repository class to weaverepo.py.
117
        for parent_id in revision.parent_ids:
3287.5.2 by Robert Collins
Deprecate VersionedFile.get_parents, breaking pulling from a ghost containing knit or pack repository to weaves, which improves correctness and allows simplification of core code.
118
            if parent_id in parent_map:
2850.3.1 by Robert Collins
Move various weave specific code out of the base Repository class to weaverepo.py.
119
                # this parent must not be a ghost.
120
                if not parent_id in weave_parents:
121
                    # but it is a ghost
122
                    raise errors.CorruptRepository(self)
123
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
124
    def get_commit_builder(self, branch, parents, config, timestamp=None,
125
                           timezone=None, committer=None, revprops=None,
126
                           revision_id=None):
127
        self._check_ascii_revisionid(revision_id, self.get_commit_builder)
2803.2.1 by Robert Collins
* CommitBuilder now advertises itself as requiring the root entry to be
128
        result = WeaveCommitBuilder(self, parents, config, timestamp, timezone,
129
                              committer, revprops, revision_id)
130
        self.start_write_group()
131
        return result
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
132
133
    @needs_read_lock
2850.3.1 by Robert Collins
Move various weave specific code out of the base Repository class to weaverepo.py.
134
    def get_revisions(self, revision_ids):
135
        revs = self._get_revisions(revision_ids)
136
        # weave corruption can lead to absent revision markers that should be
137
        # present.
138
        # the following test is reasonably cheap (it needs a single weave read)
139
        # and the weave is cached in read transactions. In write transactions
140
        # it is not cached but typically we only read a small number of
141
        # revisions. For knits when they are introduced we will probably want
142
        # to ensure that caching write transactions are in use.
143
        inv = self.get_inventory_weave()
144
        for rev in revs:
145
            self._check_revision_parents(rev, inv)
146
        return revs
147
3287.6.1 by Robert Collins
* ``VersionedFile.get_graph`` is deprecated, with no replacement method.
148
    @deprecated_method(one_four)
2850.3.1 by Robert Collins
Move various weave specific code out of the base Repository class to weaverepo.py.
149
    @needs_read_lock
150
    def get_revision_graph(self, revision_id=None):
151
        """Return a dictionary containing the revision graph.
152
        
153
        :param revision_id: The revision_id to get a graph from. If None, then
154
        the entire revision graph is returned. This is a deprecated mode of
155
        operation and will be removed in the future.
156
        :return: a dictionary of revision_id->revision_parents_list.
157
        """
158
        if 'evil' in debug.debug_flags:
159
            mutter_callsite(2,
160
                "get_revision_graph scales with size of history.")
161
        # special case NULL_REVISION
162
        if revision_id == _mod_revision.NULL_REVISION:
163
            return {}
164
        a_weave = self.get_inventory_weave()
165
        all_revisions = self._eliminate_revisions_not_present(
166
                                a_weave.versions())
3287.5.2 by Robert Collins
Deprecate VersionedFile.get_parents, breaking pulling from a ghost containing knit or pack repository to weaves, which improves correctness and allows simplification of core code.
167
        entire_graph = a_weave.get_parent_map(all_revisions)
2850.3.1 by Robert Collins
Move various weave specific code out of the base Repository class to weaverepo.py.
168
        if revision_id is None:
169
            return entire_graph
170
        elif revision_id not in entire_graph:
171
            raise errors.NoSuchRevision(self, revision_id)
172
        else:
173
            # add what can be reached from revision_id
174
            result = {}
175
            pending = set([revision_id])
176
            while len(pending) > 0:
177
                node = pending.pop()
178
                result[node] = entire_graph[node]
179
                for revision_id in result[node]:
180
                    if revision_id not in result:
181
                        pending.add(revision_id)
182
            return result
183
3172.3.1 by Robert Collins
Repository has a new method ``has_revisions`` which signals the presence
184
    def has_revisions(self, revision_ids):
185
        """See Repository.has_revisions()."""
186
        result = set()
187
        transaction = self.get_transaction()
188
        for revision_id in revision_ids:
189
            if self._revision_store.has_revision_id(revision_id, transaction):
190
                result.add(revision_id)
191
        return result
192
2850.3.1 by Robert Collins
Move various weave specific code out of the base Repository class to weaverepo.py.
193
    @needs_read_lock
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
194
    def is_shared(self):
195
        """AllInOne repositories cannot be shared."""
196
        return False
197
198
    @needs_write_lock
199
    def set_make_working_trees(self, new_value):
200
        """Set the policy flag for making working trees when creating branches.
201
202
        This only applies to branches that use this repository.
203
204
        The default is 'True'.
205
        :param new_value: True to restore the default, False to disable making
206
                          working trees.
207
        """
3349.1.2 by Aaron Bentley
Change ValueError to RepositoryUpgradeRequired
208
        raise errors.RepositoryUpgradeRequired(self.bzrdir.root_transport.base)
3349.1.1 by Aaron Bentley
Enable setting and getting make_working_trees for all repositories
209
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
210
    def make_working_trees(self):
211
        """Returns the policy for making working trees on new branches."""
212
        return True
213
2819.2.4 by Andrew Bennetts
Add a 'revision_graph_can_have_wrong_parents' method to repository.
214
    def revision_graph_can_have_wrong_parents(self):
215
        # XXX: This is an old format that we don't support full checking on, so
216
        # just claim that checking for this inconsistency is not required.
217
        return False
218
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
219
3316.2.3 by Robert Collins
Remove manual notification of transaction finishing on versioned files.
220
class WeaveMetaDirRepository(MetaDirVersionedFileRepository):
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
221
    """A subclass of MetaDirRepository to set weave specific policy."""
222
2241.1.8 by Martin Pool
Set the repository's serializer in the places it's needed, not in the base class
223
    _serializer = xml5.serializer_v5
224
2850.3.1 by Robert Collins
Move various weave specific code out of the base Repository class to weaverepo.py.
225
    @needs_read_lock
226
    def _all_possible_ids(self):
227
        """Return all the possible revisions that we could find."""
228
        if 'evil' in debug.debug_flags:
229
            mutter_callsite(3, "_all_possible_ids scales with size of history.")
230
        return self.get_inventory_weave().versions()
231
232
    @needs_read_lock
233
    def _all_revision_ids(self):
234
        """Returns a list of all the revision ids in the repository. 
235
236
        These are in as much topological order as the underlying store can 
237
        present: for weaves ghosts may lead to a lack of correctness until
238
        the reweave updates the parents list.
239
        """
240
        if self._revision_store.text_store.listable():
241
            return self._revision_store.all_revision_ids(self.get_transaction())
242
        result = self._all_possible_ids()
243
        # TODO: jam 20070210 Ensure that _all_possible_ids returns non-unicode
244
        #       ids. (It should, since _revision_store's API should change to
245
        #       return utf8 revision_ids)
246
        return self._eliminate_revisions_not_present(result)
247
248
    def _check_revision_parents(self, revision, inventory):
249
        """Private to Repository and Fetch.
250
        
251
        This checks the parentage of revision in an inventory weave for 
252
        consistency and is only applicable to inventory-weave-for-ancestry
253
        using repository formats & fetchers.
254
        """
3287.5.2 by Robert Collins
Deprecate VersionedFile.get_parents, breaking pulling from a ghost containing knit or pack repository to weaves, which improves correctness and allows simplification of core code.
255
        weave_parents = inventory.get_parent_map(
256
            [revision.revision_id])[revision.revision_id]
257
        parent_map = inventory.get_parent_map(revision.parent_ids)
2850.3.1 by Robert Collins
Move various weave specific code out of the base Repository class to weaverepo.py.
258
        for parent_id in revision.parent_ids:
3287.5.2 by Robert Collins
Deprecate VersionedFile.get_parents, breaking pulling from a ghost containing knit or pack repository to weaves, which improves correctness and allows simplification of core code.
259
            if parent_id in parent_map:
2850.3.1 by Robert Collins
Move various weave specific code out of the base Repository class to weaverepo.py.
260
                # this parent must not be a ghost.
261
                if not parent_id in weave_parents:
262
                    # but it is a ghost
263
                    raise errors.CorruptRepository(self)
264
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
265
    def get_commit_builder(self, branch, parents, config, timestamp=None,
266
                           timezone=None, committer=None, revprops=None,
267
                           revision_id=None):
268
        self._check_ascii_revisionid(revision_id, self.get_commit_builder)
2803.2.1 by Robert Collins
* CommitBuilder now advertises itself as requiring the root entry to be
269
        result = WeaveCommitBuilder(self, parents, config, timestamp, timezone,
270
                              committer, revprops, revision_id)
271
        self.start_write_group()
272
        return result
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
273
2850.3.1 by Robert Collins
Move various weave specific code out of the base Repository class to weaverepo.py.
274
    @needs_read_lock
275
    def get_revision(self, revision_id):
276
        """Return the Revision object for a named revision"""
277
        # TODO: jam 20070210 get_revision_reconcile should do this for us
278
        r = self.get_revision_reconcile(revision_id)
279
        # weave corruption can lead to absent revision markers that should be
280
        # present.
281
        # the following test is reasonably cheap (it needs a single weave read)
282
        # and the weave is cached in read transactions. In write transactions
283
        # it is not cached but typically we only read a small number of
284
        # revisions. For knits when they are introduced we will probably want
285
        # to ensure that caching write transactions are in use.
286
        inv = self.get_inventory_weave()
287
        self._check_revision_parents(r, inv)
288
        return r
289
3287.6.1 by Robert Collins
* ``VersionedFile.get_graph`` is deprecated, with no replacement method.
290
    @deprecated_method(one_four)
2850.3.1 by Robert Collins
Move various weave specific code out of the base Repository class to weaverepo.py.
291
    @needs_read_lock
292
    def get_revision_graph(self, revision_id=None):
293
        """Return a dictionary containing the revision graph.
294
        
295
        :param revision_id: The revision_id to get a graph from. If None, then
296
        the entire revision graph is returned. This is a deprecated mode of
297
        operation and will be removed in the future.
298
        :return: a dictionary of revision_id->revision_parents_list.
299
        """
300
        if 'evil' in debug.debug_flags:
301
            mutter_callsite(3,
302
                "get_revision_graph scales with size of history.")
303
        # special case NULL_REVISION
304
        if revision_id == _mod_revision.NULL_REVISION:
305
            return {}
306
        a_weave = self.get_inventory_weave()
307
        all_revisions = self._eliminate_revisions_not_present(
308
                                a_weave.versions())
3287.5.2 by Robert Collins
Deprecate VersionedFile.get_parents, breaking pulling from a ghost containing knit or pack repository to weaves, which improves correctness and allows simplification of core code.
309
        entire_graph = a_weave.get_parent_map(all_revisions)
2850.3.1 by Robert Collins
Move various weave specific code out of the base Repository class to weaverepo.py.
310
        if revision_id is None:
311
            return entire_graph
312
        elif revision_id not in entire_graph:
313
            raise errors.NoSuchRevision(self, revision_id)
314
        else:
315
            # add what can be reached from revision_id
316
            result = {}
317
            pending = set([revision_id])
318
            while len(pending) > 0:
319
                node = pending.pop()
320
                result[node] = entire_graph[node]
321
                for revision_id in result[node]:
322
                    if revision_id not in result:
323
                        pending.add(revision_id)
324
            return result
325
3172.3.1 by Robert Collins
Repository has a new method ``has_revisions`` which signals the presence
326
    def has_revisions(self, revision_ids):
327
        """See Repository.has_revisions()."""
328
        result = set()
329
        transaction = self.get_transaction()
330
        for revision_id in revision_ids:
331
            if self._revision_store.has_revision_id(revision_id, transaction):
332
                result.add(revision_id)
333
        return result
334
2819.2.4 by Andrew Bennetts
Add a 'revision_graph_can_have_wrong_parents' method to repository.
335
    def revision_graph_can_have_wrong_parents(self):
336
        # XXX: This is an old format that we don't support full checking on, so
337
        # just claim that checking for this inconsistency is not required.
338
        return False
339
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
340
341
class PreSplitOutRepositoryFormat(RepositoryFormat):
342
    """Base class for the pre split out repository formats."""
343
344
    rich_root_data = False
2323.5.17 by Martin Pool
Add supports_tree_reference to all repo formats (robert)
345
    supports_tree_reference = False
2949.1.2 by Robert Collins
* Fetch with pack repositories will no longer read the entire history graph.
346
    supports_ghosts = False
3221.3.1 by Robert Collins
* Repository formats have a new supported-feature attribute
347
    supports_external_lookups = False
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
348
349
    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.
350
        """Create a weave repository."""
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
351
        if shared:
352
            raise errors.IncompatibleFormat(self, a_bzrdir._format)
353
354
        if not _internal:
355
            # always initialized when the bzrdir is.
356
            return self.open(a_bzrdir, _found=True)
357
        
358
        # Create an empty weave
359
        sio = StringIO()
360
        weavefile.write_weave_v5(weave.Weave(), sio)
361
        empty_weave = sio.getvalue()
362
363
        mutter('creating repository in %s.', a_bzrdir.transport.base)
364
        dirs = ['revision-store', 'weaves']
365
        files = [('inventory.weave', StringIO(empty_weave)),
366
                 ]
367
        
368
        # FIXME: RBC 20060125 don't peek under the covers
369
        # NB: no need to escape relative paths that are url safe.
370
        control_files = lockable_files.LockableFiles(a_bzrdir.transport,
371
                                'branch-lock', lockable_files.TransportLock)
372
        control_files.create_lock()
373
        control_files.lock_write()
374
        control_files._transport.mkdir_multi(dirs,
375
                mode=control_files._dir_mode)
376
        try:
377
            for file, content in files:
378
                control_files.put(file, content)
379
        finally:
380
            control_files.unlock()
381
        return self.open(a_bzrdir, _found=True)
382
383
    def _get_control_store(self, repo_transport, control_files):
384
        """Return the control store for this repository."""
385
        return self._get_versioned_file_store('',
386
                                              repo_transport,
387
                                              control_files,
388
                                              prefixed=False)
389
390
    def _get_text_store(self, transport, control_files):
391
        """Get a store for file texts for this format."""
392
        raise NotImplementedError(self._get_text_store)
393
394
    def open(self, a_bzrdir, _found=False):
395
        """See RepositoryFormat.open()."""
396
        if not _found:
397
            # we are being called directly and must probe.
398
            raise NotImplementedError
399
400
        repo_transport = a_bzrdir.get_repository_transport(None)
401
        control_files = a_bzrdir._control_files
402
        text_store = self._get_text_store(repo_transport, control_files)
403
        control_store = self._get_control_store(repo_transport, control_files)
404
        _revision_store = self._get_revision_store(repo_transport, control_files)
405
        return AllInOneRepository(_format=self,
406
                                  a_bzrdir=a_bzrdir,
407
                                  _revision_store=_revision_store,
408
                                  control_store=control_store,
409
                                  text_store=text_store)
410
411
    def check_conversion_target(self, target_format):
412
        pass
413
414
415
class RepositoryFormat4(PreSplitOutRepositoryFormat):
416
    """Bzr repository format 4.
417
418
    This repository format has:
419
     - flat stores
420
     - TextStores for texts, inventories,revisions.
421
422
    This format is deprecated: it indexes texts using a text id which is
423
    removed in format 5; initialization and write support for this format
424
    has been removed.
425
    """
426
2241.1.11 by Martin Pool
Get rid of RepositoryFormat*_instance objects. Instead the format
427
    _matchingbzrdir = bzrdir.BzrDirFormat4()
428
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
429
    def __init__(self):
430
        super(RepositoryFormat4, self).__init__()
431
432
    def get_format_description(self):
433
        """See RepositoryFormat.get_format_description()."""
434
        return "Repository format 4"
435
436
    def initialize(self, url, shared=False, _internal=False):
437
        """Format 4 branches cannot be created."""
438
        raise errors.UninitializableFormat(self)
439
440
    def is_supported(self):
441
        """Format 4 is not supported.
442
443
        It is not supported because the model changed from 4 to 5 and the
444
        conversion logic is expensive - so doing it on the fly was not 
445
        feasible.
446
        """
447
        return False
448
449
    def _get_control_store(self, repo_transport, control_files):
450
        """Format 4 repositories have no formal control store at this point.
451
        
452
        This will cause any control-file-needing apis to fail - this is desired.
453
        """
454
        return None
455
    
456
    def _get_revision_store(self, repo_transport, control_files):
457
        """See RepositoryFormat._get_revision_store()."""
458
        from bzrlib.xml4 import serializer_v4
459
        return self._get_text_rev_store(repo_transport,
460
                                        control_files,
461
                                        'revision-store',
462
                                        serializer=serializer_v4)
463
464
    def _get_text_store(self, transport, control_files):
465
        """See RepositoryFormat._get_text_store()."""
466
467
468
class RepositoryFormat5(PreSplitOutRepositoryFormat):
469
    """Bzr control format 5.
470
471
    This repository format has:
472
     - weaves for file texts and inventory
473
     - flat stores
474
     - TextStores for revisions and signatures.
475
    """
476
2241.1.10 by Martin Pool
Remove more references to weaves from the repository.py file
477
    _versionedfile_class = weave.WeaveFile
2241.1.11 by Martin Pool
Get rid of RepositoryFormat*_instance objects. Instead the format
478
    _matchingbzrdir = bzrdir.BzrDirFormat5()
2241.1.10 by Martin Pool
Remove more references to weaves from the repository.py file
479
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
480
    def __init__(self):
481
        super(RepositoryFormat5, self).__init__()
482
483
    def get_format_description(self):
484
        """See RepositoryFormat.get_format_description()."""
485
        return "Weave repository format 5"
486
487
    def _get_revision_store(self, repo_transport, control_files):
488
        """See RepositoryFormat._get_revision_store()."""
489
        """Return the revision store object for this a_bzrdir."""
490
        return self._get_text_rev_store(repo_transport,
491
                                        control_files,
492
                                        'revision-store',
493
                                        compressed=False)
494
495
    def _get_text_store(self, transport, control_files):
496
        """See RepositoryFormat._get_text_store()."""
497
        return self._get_versioned_file_store('weaves', transport, control_files, prefixed=False)
498
499
500
class RepositoryFormat6(PreSplitOutRepositoryFormat):
501
    """Bzr control format 6.
502
503
    This repository format has:
504
     - weaves for file texts and inventory
505
     - hash subdirectory based stores.
506
     - TextStores for revisions and signatures.
507
    """
508
2241.1.10 by Martin Pool
Remove more references to weaves from the repository.py file
509
    _versionedfile_class = weave.WeaveFile
2241.1.11 by Martin Pool
Get rid of RepositoryFormat*_instance objects. Instead the format
510
    _matchingbzrdir = bzrdir.BzrDirFormat6()
2241.1.10 by Martin Pool
Remove more references to weaves from the repository.py file
511
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
512
    def __init__(self):
513
        super(RepositoryFormat6, self).__init__()
514
515
    def get_format_description(self):
516
        """See RepositoryFormat.get_format_description()."""
517
        return "Weave repository format 6"
518
519
    def _get_revision_store(self, repo_transport, control_files):
520
        """See RepositoryFormat._get_revision_store()."""
521
        return self._get_text_rev_store(repo_transport,
522
                                        control_files,
523
                                        'revision-store',
524
                                        compressed=False,
525
                                        prefixed=True)
526
527
    def _get_text_store(self, transport, control_files):
528
        """See RepositoryFormat._get_text_store()."""
529
        return self._get_versioned_file_store('weaves', transport, control_files)
530
531
class RepositoryFormat7(MetaDirRepositoryFormat):
532
    """Bzr repository 7.
533
534
    This repository format has:
535
     - weaves for file texts and inventory
536
     - hash subdirectory based stores.
537
     - TextStores for revisions and signatures.
538
     - a format marker of its own
539
     - an optional 'shared-storage' flag
540
     - an optional 'no-working-trees' flag
541
    """
542
2241.1.10 by Martin Pool
Remove more references to weaves from the repository.py file
543
    _versionedfile_class = weave.WeaveFile
2949.1.2 by Robert Collins
* Fetch with pack repositories will no longer read the entire history graph.
544
    supports_ghosts = False
2241.1.10 by Martin Pool
Remove more references to weaves from the repository.py file
545
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
546
    def _get_control_store(self, repo_transport, control_files):
547
        """Return the control store for this repository."""
548
        return self._get_versioned_file_store('',
549
                                              repo_transport,
550
                                              control_files,
551
                                              prefixed=False)
552
553
    def get_format_string(self):
554
        """See RepositoryFormat.get_format_string()."""
555
        return "Bazaar-NG Repository format 7"
556
557
    def get_format_description(self):
558
        """See RepositoryFormat.get_format_description()."""
559
        return "Weave repository format 7"
560
561
    def check_conversion_target(self, target_format):
562
        pass
563
564
    def _get_revision_store(self, repo_transport, control_files):
565
        """See RepositoryFormat._get_revision_store()."""
566
        return self._get_text_rev_store(repo_transport,
567
                                        control_files,
568
                                        'revision-store',
569
                                        compressed=False,
570
                                        prefixed=True,
571
                                        )
572
573
    def _get_text_store(self, transport, control_files):
574
        """See RepositoryFormat._get_text_store()."""
575
        return self._get_versioned_file_store('weaves',
576
                                              transport,
577
                                              control_files)
578
579
    def initialize(self, a_bzrdir, shared=False):
580
        """Create a weave repository.
581
582
        :param shared: If true the repository will be initialized as a shared
583
                       repository.
584
        """
585
        # Create an empty weave
586
        sio = StringIO()
587
        weavefile.write_weave_v5(weave.Weave(), sio)
588
        empty_weave = sio.getvalue()
589
590
        mutter('creating repository in %s.', a_bzrdir.transport.base)
591
        dirs = ['revision-store', 'weaves']
592
        files = [('inventory.weave', StringIO(empty_weave)), 
593
                 ]
594
        utf8_files = [('format', self.get_format_string())]
595
 
596
        self._upload_blank_content(a_bzrdir, dirs, files, utf8_files, shared)
597
        return self.open(a_bzrdir=a_bzrdir, _found=True)
598
599
    def open(self, a_bzrdir, _found=False, _override_transport=None):
600
        """See RepositoryFormat.open().
601
        
602
        :param _override_transport: INTERNAL USE ONLY. Allows opening the
603
                                    repository at a slightly different url
604
                                    than normal. I.e. during 'upgrade'.
605
        """
606
        if not _found:
607
            format = RepositoryFormat.find_format(a_bzrdir)
608
            assert format.__class__ ==  self.__class__
609
        if _override_transport is not None:
610
            repo_transport = _override_transport
611
        else:
612
            repo_transport = a_bzrdir.get_repository_transport(None)
613
        control_files = lockable_files.LockableFiles(repo_transport,
614
                                'lock', lockdir.LockDir)
615
        text_store = self._get_text_store(repo_transport, control_files)
616
        control_store = self._get_control_store(repo_transport, control_files)
617
        _revision_store = self._get_revision_store(repo_transport, control_files)
618
        return WeaveMetaDirRepository(_format=self,
619
            a_bzrdir=a_bzrdir,
620
            control_files=control_files,
621
            _revision_store=_revision_store,
622
            control_store=control_store,
623
            text_store=text_store)
624
625
2803.2.1 by Robert Collins
* CommitBuilder now advertises itself as requiring the root entry to be
626
class WeaveCommitBuilder(CommitBuilder):
627
    """A builder for weave based repos that don't support ghosts."""
628
2592.3.131 by Robert Collins
Fix weaverepo commits due to api change.
629
    def _add_text_to_weave(self, file_id, new_lines, parents, nostore_sha):
2803.2.1 by Robert Collins
* CommitBuilder now advertises itself as requiring the root entry to be
630
        versionedfile = self.repository.weave_store.get_weave_or_empty(
631
            file_id, self.repository.get_transaction())
632
        result = versionedfile.add_lines(
2776.4.9 by Robert Collins
Unbreak weaves.
633
            self._new_revision_id, parents, new_lines,
634
            nostore_sha=nostore_sha)[0:2]
2803.2.1 by Robert Collins
* CommitBuilder now advertises itself as requiring the root entry to be
635
        return result
636
637
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
638
_legacy_formats = [RepositoryFormat4(),
639
                   RepositoryFormat5(),
640
                   RepositoryFormat6()]