~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repofmt/knitrepo.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-10-09 00:18:32 UTC
  • mfrom: (2889.1.3 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20071009001832-kl9ak6vzgz6d4fpy
(robertc) Fold KnitRepositry3 into KnitRepository and move xml serialisation logic from it into the serializer classes. (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
 
38
38
from bzrlib.decorators import needs_read_lock, needs_write_lock
39
39
from bzrlib.repository import (
 
40
    CommitBuilder,
40
41
    MetaDirRepository,
41
42
    MetaDirRepositoryFormat,
42
43
    RepositoryFormat,
76
77
class KnitRepository(MetaDirRepository):
77
78
    """Knit format repository."""
78
79
 
79
 
    _serializer = xml5.serializer_v5
 
80
    # These attributes are inherited from the Repository base class. Setting
 
81
    # them to None ensures that if the constructor is changed to not initialize
 
82
    # them, or a subclass fails to call the constructor, that an error will
 
83
    # occur rather than the system working but generating incorrect data.
 
84
    _commit_builder_class = None
 
85
    _serializer = None
 
86
 
 
87
    def __init__(self, _format, a_bzrdir, control_files, _revision_store,
 
88
        control_store, text_store, _commit_builder_class, _serializer):
 
89
        MetaDirRepository.__init__(self, _format, a_bzrdir, control_files,
 
90
            _revision_store, control_store, text_store)
 
91
        self._commit_builder_class = _commit_builder_class
 
92
        self._serializer = _serializer
80
93
 
81
94
    def _warn_if_deprecated(self):
82
95
        # This class isn't deprecated
228
241
        return _KnitParentsProvider(self._get_revision_vf())
229
242
 
230
243
 
231
 
class KnitRepository3(KnitRepository):
232
 
 
233
 
    # knit3 repositories need a RootCommitBuilder
234
 
    _commit_builder_class = RootCommitBuilder
235
 
 
236
 
    def __init__(self, _format, a_bzrdir, control_files, _revision_store,
237
 
                 control_store, text_store):
238
 
        KnitRepository.__init__(self, _format, a_bzrdir, control_files,
239
 
                              _revision_store, control_store, text_store)
240
 
        self._serializer = xml7.serializer_v7
241
 
 
242
 
    def deserialise_inventory(self, revision_id, xml):
243
 
        """Transform the xml into an inventory object. 
244
 
 
245
 
        :param revision_id: The expected revision id of the inventory.
246
 
        :param xml: A serialised inventory.
247
 
        """
248
 
        result = self._serializer.read_inventory_from_string(xml)
249
 
        assert result.root.revision is not None
250
 
        return result
251
 
 
252
 
    def serialise_inventory(self, inv):
253
 
        """Transform the inventory object into XML text.
254
 
 
255
 
        :param revision_id: The expected revision id of the inventory.
256
 
        :param xml: A serialised inventory.
257
 
        """
258
 
        assert inv.revision_id is not None
259
 
        assert inv.root.revision is not None
260
 
        return KnitRepository.serialise_inventory(self, inv)
261
 
 
262
 
 
263
244
class RepositoryFormatKnit(MetaDirRepositoryFormat):
264
245
    """Bzr repository knit format (generalized). 
265
246
 
277
258
    # Set this attribute in derived classes to control the repository class
278
259
    # created by open and initialize.
279
260
    repository_class = None
 
261
    # Set this attribute in derived classes to control the
 
262
    # _commit_builder_class that the repository objects will have passed to
 
263
    # their constructor.
 
264
    _commit_builder_class = None
 
265
    # Set this attribute in derived clases to control the _serializer that the
 
266
    # repository objects will have passed to their constructor.
 
267
    _serializer = xml5.serializer_v5
280
268
 
281
269
    def _get_control_store(self, repo_transport, control_files):
282
270
        """Return the control store for this repository."""
368
356
                              control_files=control_files,
369
357
                              _revision_store=_revision_store,
370
358
                              control_store=control_store,
371
 
                              text_store=text_store)
 
359
                              text_store=text_store,
 
360
                              _commit_builder_class=self._commit_builder_class,
 
361
                              _serializer=self._serializer)
372
362
 
373
363
 
374
364
class RepositoryFormatKnit1(RepositoryFormatKnit):
388
378
    """
389
379
 
390
380
    repository_class = KnitRepository
 
381
    _commit_builder_class = CommitBuilder
 
382
    _serializer = xml5.serializer_v5
391
383
 
392
384
    def __ne__(self, other):
393
385
        return self.__class__ is not other.__class__
420
412
     - support for recording tree-references
421
413
    """
422
414
 
423
 
    repository_class = KnitRepository3
 
415
    repository_class = KnitRepository
 
416
    _commit_builder_class = RootCommitBuilder
424
417
    rich_root_data = True
425
418
    supports_tree_reference = True
 
419
    _serializer = xml7.serializer_v7
426
420
 
427
421
    def _get_matching_bzrdir(self):
428
422
        return bzrdir.format_registry.make_bzrdir('dirstate-with-subtree')