~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Martin Pool
  • Date: 2005-09-05 09:27:11 UTC
  • Revision ID: mbp@sourcefrog.net-20050905092711-f9f5bded3fd82605
- more disentangling of xml storage format from objects

- remove pack_xml and unpack_xml function in favor of 
  serializer object

- test unpacking canned revision xml

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
import bzrlib.errors
29
29
from bzrlib.textui import show_status
30
30
from bzrlib.revision import Revision
31
 
from bzrlib.xml import unpack_xml
32
31
from bzrlib.delta import compare_trees
33
32
from bzrlib.tree import EmptyTree, RevisionTree
 
33
import bzrlib.xml
34
34
import bzrlib.ui
35
35
 
36
36
 
302
302
 
303
303
    def _make_control(self):
304
304
        from bzrlib.inventory import Inventory
305
 
        from bzrlib.xml import serializer_v4
306
305
        
307
306
        os.mkdir(self.controlfilename([]))
308
307
        self.controlfile('README', 'w').write(
322
321
        # them; they're not needed for now and so ommitted for
323
322
        # simplicity.
324
323
        f = self.controlfile('inventory','w')
325
 
        serializer_v4.write_inventory(Inventory(), f)
 
324
        bzrlib.xml.serializer_v4.write_inventory(Inventory(), f)
326
325
 
327
326
 
328
327
    def _check_format(self):
363
362
    def read_working_inventory(self):
364
363
        """Read the working inventory."""
365
364
        from bzrlib.inventory import Inventory
366
 
        from bzrlib.xml import serializer_v4
367
365
        self.lock_read()
368
366
        try:
369
367
            # ElementTree does its own conversion from UTF-8, so open in
370
368
            # binary.
371
369
            f = self.controlfile('inventory', 'rb')
372
 
            return serializer_v4.read_inventory(f)
 
370
            return bzrlib.xml.serializer_v4.read_inventory(f)
373
371
        finally:
374
372
            self.unlock()
375
373
            
381
379
        will be committed to the next revision.
382
380
        """
383
381
        from bzrlib.atomicfile import AtomicFile
384
 
        from bzrlib.xml import serializer_v4
385
382
        
386
383
        self.lock_write()
387
384
        try:
388
385
            f = AtomicFile(self.controlfilename('inventory'), 'wb')
389
386
            try:
390
 
                serializer_v4.write_inventory(inv, f)
 
387
                bzrlib.xml.serializer_v4.write_inventory(inv, f)
391
388
                f.commit()
392
389
            finally:
393
390
                f.close()
578
575
            f.close()
579
576
 
580
577
 
581
 
    def get_revision_xml(self, revision_id):
 
578
    def get_revision_xml_file(self, revision_id):
582
579
        """Return XML file object for revision object."""
583
580
        if not revision_id or not isinstance(revision_id, basestring):
584
581
            raise InvalidRevisionId(revision_id)
593
590
            self.unlock()
594
591
 
595
592
 
 
593
    #deprecated
 
594
    get_revision_xml = get_revision_xml_file
 
595
 
 
596
 
596
597
    def get_revision(self, revision_id):
597
598
        """Return the Revision object for a named revision"""
598
 
        xml_file = self.get_revision_xml(revision_id)
 
599
        xml_file = self.get_revision_xml_file(revision_id)
599
600
 
600
601
        try:
601
 
            r = unpack_xml(Revision, xml_file)
 
602
            r = bzrlib.xml.serializer_v4.read_revision(xml_file)
602
603
        except SyntaxError, e:
603
604
            raise bzrlib.errors.BzrError('failed to unpack revision_xml',
604
605
                                         [revision_id,
649
650
               parameter which can be either an integer revno or a
650
651
               string hash."""
651
652
        from bzrlib.inventory import Inventory
652
 
        from bzrlib.xml import serializer_v4
653
653
 
654
654
        f = self.get_inventory_xml_file(inventory_id)
655
 
        return serializer_v4.read_inventory(f)
 
655
        return bzrlib.xml.serializer_v4.read_inventory(f)
656
656
 
657
657
 
658
658
    def get_inventory_xml(self, inventory_id):