/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/repofmt/weaverepo.py

Remove more cases of getting transport via control_files

Show diffs side-by-side

added added

removed removed

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