/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

  • Committer: Andrew Bennetts
  • Date: 2010-04-13 04:33:55 UTC
  • mfrom: (5147 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5149.
  • Revision ID: andrew.bennetts@canonical.com-20100413043355-lg3id0uwtju0k3zs
MergeĀ lp:bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
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
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Deprecated weave-based repository formats.
18
18
 
28
28
lazy_import(globals(), """
29
29
from bzrlib import (
30
30
    xml5,
 
31
    graph as _mod_graph,
31
32
    )
32
33
""")
33
34
from bzrlib import (
38
39
    lockdir,
39
40
    osutils,
40
41
    revision as _mod_revision,
 
42
    urlutils,
41
43
    versionedfile,
42
44
    weave,
43
45
    weavefile,
67
69
    def _serializer(self):
68
70
        return xml5.serializer_v5
69
71
 
 
72
    def _escape(self, file_or_path):
 
73
        if not isinstance(file_or_path, basestring):
 
74
            file_or_path = '/'.join(file_or_path)
 
75
        if file_or_path == '':
 
76
            return u''
 
77
        return urlutils.escape(osutils.safe_unicode(file_or_path))
 
78
 
70
79
    def __init__(self, _format, a_bzrdir):
71
80
        # we reuse one control files instance.
72
81
        dir_mode = a_bzrdir._get_dir_mode()
74
83
 
75
84
        def get_store(name, compressed=True, prefixed=False):
76
85
            # FIXME: This approach of assuming stores are all entirely compressed
77
 
            # or entirely uncompressed is tidy, but breaks upgrade from 
78
 
            # some existing branches where there's a mixture; we probably 
 
86
            # or entirely uncompressed is tidy, but breaks upgrade from
 
87
            # some existing branches where there's a mixture; we probably
79
88
            # still want the option to look for both.
80
 
            relpath = a_bzrdir._control_files._escape(name)
 
89
            relpath = self._escape(name)
81
90
            store = TextStore(a_bzrdir.transport.clone(relpath),
82
91
                              prefixed=prefixed, compressed=compressed,
83
92
                              dir_mode=dir_mode,
87
96
        # not broken out yet because the controlweaves|inventory_store
88
97
        # and texts bits are still different.
89
98
        if isinstance(_format, RepositoryFormat4):
90
 
            # cannot remove these - there is still no consistent api 
 
99
            # cannot remove these - there is still no consistent api
91
100
            # which allows access to this old info.
92
101
            self.inventory_store = get_store('inventory-store')
93
102
            self._text_store = get_store('text-store')
94
103
        super(AllInOneRepository, self).__init__(_format, a_bzrdir, a_bzrdir._control_files)
95
 
        self._fetch_order = 'topological'
96
 
        self._fetch_reconcile = True
97
104
 
98
105
    @needs_read_lock
99
106
    def _all_possible_ids(self):
104
111
 
105
112
    @needs_read_lock
106
113
    def _all_revision_ids(self):
107
 
        """Returns a list of all the revision ids in the repository. 
 
114
        """Returns a list of all the revision ids in the repository.
108
115
 
109
 
        These are in as much topological order as the underlying store can 
 
116
        These are in as much topological order as the underlying store can
110
117
        present: for weaves ghosts may lead to a lack of correctness until
111
118
        the reweave updates the parents list.
112
119
        """
184
191
class WeaveMetaDirRepository(MetaDirVersionedFileRepository):
185
192
    """A subclass of MetaDirRepository to set weave specific policy."""
186
193
 
187
 
    @property
188
 
    def _serializer(self):
189
 
        return xml5.serializer_v5
190
 
 
191
194
    def __init__(self, _format, a_bzrdir, control_files):
192
195
        super(WeaveMetaDirRepository, self).__init__(_format, a_bzrdir, control_files)
193
 
        self._fetch_order = 'topological'
194
 
        self._fetch_reconcile = True
 
196
        self._serializer = _format._serializer
195
197
 
196
198
    @needs_read_lock
197
199
    def _all_possible_ids(self):
202
204
 
203
205
    @needs_read_lock
204
206
    def _all_revision_ids(self):
205
 
        """Returns a list of all the revision ids in the repository. 
 
207
        """Returns a list of all the revision ids in the repository.
206
208
 
207
 
        These are in as much topological order as the underlying store can 
 
209
        These are in as much topological order as the underlying store can
208
210
        present: for weaves ghosts may lead to a lack of correctness until
209
211
        the reweave updates the parents list.
210
212
        """
265
267
    supports_tree_reference = False
266
268
    supports_ghosts = False
267
269
    supports_external_lookups = False
 
270
    supports_chks = False
 
271
    _fetch_order = 'topological'
 
272
    _fetch_reconcile = True
 
273
    fast_deltas = False
268
274
 
269
275
    def initialize(self, a_bzrdir, shared=False, _internal=False):
270
276
        """Create a weave repository."""
274
280
        if not _internal:
275
281
            # always initialized when the bzrdir is.
276
282
            return self.open(a_bzrdir, _found=True)
277
 
        
 
283
 
278
284
        # Create an empty weave
279
285
        sio = StringIO()
280
286
        weavefile.write_weave_v5(weave.Weave(), sio)
281
287
        empty_weave = sio.getvalue()
282
288
 
283
289
        mutter('creating repository in %s.', a_bzrdir.transport.base)
284
 
        
 
290
 
285
291
        # FIXME: RBC 20060125 don't peek under the covers
286
292
        # NB: no need to escape relative paths that are url safe.
287
293
        control_files = lockable_files.LockableFiles(a_bzrdir.transport,
292
298
        try:
293
299
            transport.mkdir_multi(['revision-store', 'weaves'],
294
300
                mode=a_bzrdir._get_dir_mode())
295
 
            transport.put_bytes_non_atomic('inventory.weave', empty_weave)
 
301
            transport.put_bytes_non_atomic('inventory.weave', empty_weave,
 
302
                mode=a_bzrdir._get_file_mode())
296
303
        finally:
297
304
            control_files.unlock()
298
305
        return self.open(a_bzrdir, _found=True)
310
317
        result.signatures = self._get_signatures(repo_transport, result)
311
318
        result.inventories = self._get_inventories(repo_transport, result)
312
319
        result.texts = self._get_texts(repo_transport, result)
 
320
        result.chk_bytes = None
313
321
        return result
314
322
 
315
 
    def check_conversion_target(self, target_format):
316
 
        pass
317
 
 
318
323
 
319
324
class RepositoryFormat4(PreSplitOutRepositoryFormat):
320
325
    """Bzr repository format 4.
330
335
 
331
336
    _matchingbzrdir = bzrdir.BzrDirFormat4()
332
337
 
333
 
    def __init__(self):
334
 
        super(RepositoryFormat4, self).__init__()
335
 
        self._fetch_order = 'topological'
336
 
        self._fetch_reconcile = True
337
 
 
338
338
    def get_format_description(self):
339
339
        """See RepositoryFormat.get_format_description()."""
340
340
        return "Repository format 4"
347
347
        """Format 4 is not supported.
348
348
 
349
349
        It is not supported because the model changed from 4 to 5 and the
350
 
        conversion logic is expensive - so doing it on the fly was not 
 
350
        conversion logic is expensive - so doing it on the fly was not
351
351
        feasible.
352
352
        """
353
353
        return False
382
382
 
383
383
    _versionedfile_class = weave.WeaveFile
384
384
    _matchingbzrdir = bzrdir.BzrDirFormat5()
385
 
 
386
 
    def __init__(self):
387
 
        super(RepositoryFormat5, self).__init__()
388
 
        self._fetch_order = 'topological'
389
 
        self._fetch_reconcile = True
 
385
    @property
 
386
    def _serializer(self):
 
387
        return xml5.serializer_v5
390
388
 
391
389
    def get_format_description(self):
392
390
        """See RepositoryFormat.get_format_description()."""
393
391
        return "Weave repository format 5"
394
392
 
 
393
    def network_name(self):
 
394
        """The network name for this format is the control dirs disk label."""
 
395
        return self._matchingbzrdir.get_format_string()
 
396
 
395
397
    def _get_inventories(self, repo_transport, repo, name='inventory'):
396
398
        mapper = versionedfile.ConstantMapper(name)
397
399
        return versionedfile.ThunkedVersionedFiles(repo_transport,
398
400
            weave.WeaveFile, mapper, repo.is_locked)
399
401
 
400
402
    def _get_revisions(self, repo_transport, repo):
401
 
        from bzrlib.xml5 import serializer_v5
402
403
        return RevisionTextStore(repo_transport.clone('revision-store'),
403
 
            serializer_v5, False, versionedfile.PrefixMapper(),
 
404
            xml5.serializer_v5, False, versionedfile.PrefixMapper(),
404
405
            repo.is_locked, repo.is_write_locked)
405
406
 
406
407
    def _get_signatures(self, repo_transport, repo):
426
427
 
427
428
    _versionedfile_class = weave.WeaveFile
428
429
    _matchingbzrdir = bzrdir.BzrDirFormat6()
429
 
 
430
 
    def __init__(self):
431
 
        super(RepositoryFormat6, self).__init__()
432
 
        self._fetch_order = 'topological'
433
 
        self._fetch_reconcile = True
 
430
    @property
 
431
    def _serializer(self):
 
432
        return xml5.serializer_v5
434
433
 
435
434
    def get_format_description(self):
436
435
        """See RepositoryFormat.get_format_description()."""
437
436
        return "Weave repository format 6"
438
437
 
 
438
    def network_name(self):
 
439
        """The network name for this format is the control dirs disk label."""
 
440
        return self._matchingbzrdir.get_format_string()
 
441
 
439
442
    def _get_inventories(self, repo_transport, repo, name='inventory'):
440
443
        mapper = versionedfile.ConstantMapper(name)
441
444
        return versionedfile.ThunkedVersionedFiles(repo_transport,
442
445
            weave.WeaveFile, mapper, repo.is_locked)
443
446
 
444
447
    def _get_revisions(self, repo_transport, repo):
445
 
        from bzrlib.xml5 import serializer_v5
446
448
        return RevisionTextStore(repo_transport.clone('revision-store'),
447
 
            serializer_v5, False, versionedfile.HashPrefixMapper(),
 
449
            xml5.serializer_v5, False, versionedfile.HashPrefixMapper(),
448
450
            repo.is_locked, repo.is_write_locked)
449
451
 
450
452
    def _get_signatures(self, repo_transport, repo):
473
475
 
474
476
    _versionedfile_class = weave.WeaveFile
475
477
    supports_ghosts = False
 
478
    supports_chks = False
 
479
 
 
480
    _fetch_order = 'topological'
 
481
    _fetch_reconcile = True
 
482
    fast_deltas = False
 
483
    @property
 
484
    def _serializer(self):
 
485
        return xml5.serializer_v5
476
486
 
477
487
    def get_format_string(self):
478
488
        """See RepositoryFormat.get_format_string()."""
482
492
        """See RepositoryFormat.get_format_description()."""
483
493
        return "Weave repository format 7"
484
494
 
485
 
    def check_conversion_target(self, target_format):
486
 
        pass
487
 
 
488
495
    def _get_inventories(self, repo_transport, repo, name='inventory'):
489
496
        mapper = versionedfile.ConstantMapper(name)
490
497
        return versionedfile.ThunkedVersionedFiles(repo_transport,
491
498
            weave.WeaveFile, mapper, repo.is_locked)
492
499
 
493
500
    def _get_revisions(self, repo_transport, repo):
494
 
        from bzrlib.xml5 import serializer_v5
495
501
        return RevisionTextStore(repo_transport.clone('revision-store'),
496
 
            serializer_v5, True, versionedfile.HashPrefixMapper(),
 
502
            xml5.serializer_v5, True, versionedfile.HashPrefixMapper(),
497
503
            repo.is_locked, repo.is_write_locked)
498
504
 
499
505
    def _get_signatures(self, repo_transport, repo):
520
526
 
521
527
        mutter('creating repository in %s.', a_bzrdir.transport.base)
522
528
        dirs = ['revision-store', 'weaves']
523
 
        files = [('inventory.weave', StringIO(empty_weave)), 
 
529
        files = [('inventory.weave', StringIO(empty_weave)),
524
530
                 ]
525
531
        utf8_files = [('format', self.get_format_string())]
526
 
 
 
532
 
527
533
        self._upload_blank_content(a_bzrdir, dirs, files, utf8_files, shared)
528
534
        return self.open(a_bzrdir=a_bzrdir, _found=True)
529
535
 
530
536
    def open(self, a_bzrdir, _found=False, _override_transport=None):
531
537
        """See RepositoryFormat.open().
532
 
        
 
538
 
533
539
        :param _override_transport: INTERNAL USE ONLY. Allows opening the
534
540
                                    repository at a slightly different url
535
541
                                    than normal. I.e. during 'upgrade'.
548
554
        result.signatures = self._get_signatures(repo_transport, result)
549
555
        result.inventories = self._get_inventories(repo_transport, result)
550
556
        result.texts = self._get_texts(repo_transport, result)
 
557
        result.chk_bytes = None
551
558
        result._transport = repo_transport
552
559
        return result
553
560
 
656
663
                continue
657
664
            result[key] = parents
658
665
        return result
659
 
    
 
666
 
 
667
    def get_known_graph_ancestry(self, keys):
 
668
        """Get a KnownGraph instance with the ancestry of keys."""
 
669
        keys = self.keys()
 
670
        parent_map = self.get_parent_map(keys)
 
671
        kg = _mod_graph.KnownGraph(parent_map)
 
672
        return kg
 
673
 
660
674
    def get_record_stream(self, keys, sort_order, include_delta_closure):
661
675
        for key in keys:
662
676
            text, parents = self._load_text_parents(key)
674
688
            path, ext = os.path.splitext(relpath)
675
689
            if ext == '.gz':
676
690
                relpath = path
677
 
            if '.sig' not in relpath:
 
691
            if not relpath.endswith('.sig'):
678
692
                relpaths.add(relpath)
679
693
        paths = list(relpaths)
680
694
        return set([self._mapper.unmap(path) for path in paths])
696
710
                continue
697
711
            result[key] = None
698
712
        return result
699
 
    
 
713
 
700
714
    def get_record_stream(self, keys, sort_order, include_delta_closure):
701
715
        for key in keys:
702
716
            text = self._load_text(key)