~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Martin Pool
  • Date: 2005-06-28 05:33:40 UTC
  • Revision ID: mbp@sourcefrog.net-20050628053340-ea73b03fbcde9c46
- Remove XMLMixin class in favour of simple pack_xml, unpack_xml functions
  called as needed.  

- Avoid importing xml and ElementTree library unless needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
291
291
 
292
292
    def _make_control(self):
293
293
        from bzrlib.inventory import Inventory
 
294
        from bzrlib.xml import pack_xml
 
295
        
294
296
        os.mkdir(self.controlfilename([]))
295
297
        self.controlfile('README', 'w').write(
296
298
            "This is a Bazaar-NG control directory.\n"
303
305
                  'branch-lock'):
304
306
            self.controlfile(f, 'w').write('')
305
307
        mutter('created control directory in ' + self.base)
306
 
        Inventory().write_xml(self.controlfile('inventory','w'))
 
308
 
 
309
        pack_xml(Inventory(), self.controlfile('inventory','w'))
307
310
 
308
311
 
309
312
    def _check_format(self):
329
332
    def read_working_inventory(self):
330
333
        """Read the working inventory."""
331
334
        from bzrlib.inventory import Inventory
 
335
        from bzrlib.xml import unpack_xml
332
336
        from time import time
333
337
        before = time()
334
 
        # ElementTree does its own conversion from UTF-8, so open in
335
 
        # binary.
336
338
        self.lock_read()
337
339
        try:
338
 
            inv = Inventory.read_xml(self.controlfile('inventory', 'rb'))
 
340
            # ElementTree does its own conversion from UTF-8, so open in
 
341
            # binary.
 
342
            inv = unpack_xml(Inventory,
 
343
                                  self.controlfile('inventory', 'rb'))
339
344
            mutter("loaded inventory of %d items in %f"
340
345
                   % (len(inv), time() - before))
341
346
            return inv
349
354
        That is to say, the inventory describing changes underway, that
350
355
        will be committed to the next revision.
351
356
        """
 
357
        from bzrlib.atomicfile import AtomicFile
 
358
        from bzrlib.xml import pack_xml
 
359
        
352
360
        self.lock_write()
353
361
        try:
354
 
            from bzrlib.atomicfile import AtomicFile
355
 
 
356
362
            f = AtomicFile(self.controlfilename('inventory'), 'wb')
357
363
            try:
358
 
                inv.write_xml(f)
 
364
                pack_xml(inv, f)
359
365
                f.commit()
360
366
            finally:
361
367
                f.close()
555
561
    def get_revision(self, revision_id):
556
562
        """Return the Revision object for a named revision"""
557
563
        from bzrlib.revision import Revision
558
 
        if not revision_id or not isinstance(revision_id, basestring):
559
 
            raise ValueError('invalid revision-id: %r' % revision_id)
560
 
        r = Revision.read_xml(self.revision_store[revision_id])
 
564
        from bzrlib.xml import unpack_xml
 
565
 
 
566
        self.lock_read()
 
567
        try:
 
568
            if not revision_id or not isinstance(revision_id, basestring):
 
569
                raise ValueError('invalid revision-id: %r' % revision_id)
 
570
            r = unpack_xml(Revision, self.revision_store[revision_id])
 
571
        finally:
 
572
            self.unlock()
 
573
            
561
574
        assert r.revision_id == revision_id
562
575
        return r
 
576
        
563
577
 
564
578
    def get_revision_sha1(self, revision_id):
565
579
        """Hash the stored value of a revision, and return it."""
579
593
               parameter which can be either an integer revno or a
580
594
               string hash."""
581
595
        from bzrlib.inventory import Inventory
582
 
        i = Inventory.read_xml(self.inventory_store[inventory_id])
583
 
        return i
 
596
        from bzrlib.xml import unpack_xml
 
597
 
 
598
        return unpack_xml(Inventory, self.inventory_store[inventory_id])
 
599
            
584
600
 
585
601
    def get_inventory_sha1(self, inventory_id):
586
602
        """Return the sha1 hash of the inventory entry