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