~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 08:00:35 UTC
  • Revision ID: mbp@sourcefrog.net-20050905080035-e0439293f8b6b9f9
- start splitting code for xml (de)serialization away from objects
  preparatory to supporting multiple formats by a single library

Show diffs side-by-side

added added

removed removed

Lines of Context:
302
302
 
303
303
    def _make_control(self):
304
304
        from bzrlib.inventory import Inventory
305
 
        from bzrlib.xml import pack_xml
 
305
        from bzrlib.xml import serializer_v4
306
306
        
307
307
        os.mkdir(self.controlfilename([]))
308
308
        self.controlfile('README', 'w').write(
321
321
        # if we want per-tree root ids then this is the place to set
322
322
        # them; they're not needed for now and so ommitted for
323
323
        # simplicity.
324
 
        pack_xml(Inventory(), self.controlfile('inventory','w'))
 
324
        f = self.controlfile('inventory','w')
 
325
        serializer_v4.write_inventory(Inventory(), f)
 
326
 
325
327
 
326
328
    def _check_format(self):
327
329
        """Check this branch format is supported.
361
363
    def read_working_inventory(self):
362
364
        """Read the working inventory."""
363
365
        from bzrlib.inventory import Inventory
364
 
        from bzrlib.xml import unpack_xml
365
 
        from time import time
366
 
        before = time()
 
366
        from bzrlib.xml import serializer_v4
367
367
        self.lock_read()
368
368
        try:
369
369
            # ElementTree does its own conversion from UTF-8, so open in
370
370
            # binary.
371
 
            inv = unpack_xml(Inventory,
372
 
                             self.controlfile('inventory', 'rb'))
373
 
            mutter("loaded inventory of %d items in %f"
374
 
                   % (len(inv), time() - before))
375
 
            return inv
 
371
            f = self.controlfile('inventory', 'rb')
 
372
            return serializer_v4.read_inventory(f)
376
373
        finally:
377
374
            self.unlock()
378
375
            
384
381
        will be committed to the next revision.
385
382
        """
386
383
        from bzrlib.atomicfile import AtomicFile
387
 
        from bzrlib.xml import pack_xml
 
384
        from bzrlib.xml import serializer_v4
388
385
        
389
386
        self.lock_write()
390
387
        try:
391
388
            f = AtomicFile(self.controlfilename('inventory'), 'wb')
392
389
            try:
393
 
                pack_xml(inv, f)
 
390
                serializer_v4.write_inventory(inv, f)
394
391
                f.commit()
395
392
            finally:
396
393
                f.close()
652
649
               parameter which can be either an integer revno or a
653
650
               string hash."""
654
651
        from bzrlib.inventory import Inventory
655
 
        from bzrlib.xml import unpack_xml
 
652
        from bzrlib.xml import serializer_v4
656
653
 
657
 
        return unpack_xml(Inventory, self.get_inventory_xml(inventory_id))
 
654
        f = self.get_inventory_xml_file(inventory_id)
 
655
        return serializer_v4.read_inventory(f)
658
656
 
659
657
 
660
658
    def get_inventory_xml(self, inventory_id):
661
659
        """Get inventory XML as a file object."""
662
660
        return self.inventory_store[inventory_id]
 
661
 
 
662
    get_inventory_xml_file = get_inventory_xml
663
663
            
664
664
 
665
665
    def get_inventory_sha1(self, inventory_id):