/brz/remove-bazaar

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