~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Aaron Bentley
  • Date: 2005-09-12 13:48:32 UTC
  • mfrom: (1185.3.4)
  • mto: (1185.1.16)
  • mto: This revision was merged to the branch mainline in revision 1390.
  • Revision ID: abentley@panoramicfeedback.com-20050912134832-c23db11dc63170b6
Merged from mpool

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 pack_xml
306
305
        
307
306
        os.mkdir(self.controlfilename([]))
308
307
        self.controlfile('README', 'w').write(
321
320
        # if we want per-tree root ids then this is the place to set
322
321
        # them; they're not needed for now and so ommitted for
323
322
        # simplicity.
324
 
        pack_xml(Inventory(), self.controlfile('inventory','w'))
 
323
        f = self.controlfile('inventory','w')
 
324
        bzrlib.xml.serializer_v4.write_inventory(Inventory(), f)
 
325
 
325
326
 
326
327
    def _check_format(self):
327
328
        """Check this branch format is supported.
335
336
        # on Windows from Linux and so on.  I think it might be better
336
337
        # to always make all internal files in unix format.
337
338
        fmt = self.controlfile('branch-format', 'r').read()
338
 
        fmt.replace('\r\n', '')
 
339
        fmt = fmt.replace('\r\n', '\n')
339
340
        if fmt != BZR_BRANCH_FORMAT:
340
341
            raise BzrError('sorry, branch format %r not supported' % fmt,
341
342
                           ['use a different bzr version',
361
362
    def read_working_inventory(self):
362
363
        """Read the working inventory."""
363
364
        from bzrlib.inventory import Inventory
364
 
        from bzrlib.xml import unpack_xml
365
 
        from time import time
366
 
        before = time()
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
 
            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
 
369
            f = self.controlfile('inventory', 'rb')
 
370
            return bzrlib.xml.serializer_v4.read_inventory(f)
376
371
        finally:
377
372
            self.unlock()
378
373
            
384
379
        will be committed to the next revision.
385
380
        """
386
381
        from bzrlib.atomicfile import AtomicFile
387
 
        from bzrlib.xml import pack_xml
388
382
        
389
383
        self.lock_write()
390
384
        try:
391
385
            f = AtomicFile(self.controlfilename('inventory'), 'wb')
392
386
            try:
393
 
                pack_xml(inv, f)
 
387
                bzrlib.xml.serializer_v4.write_inventory(inv, f)
394
388
                f.commit()
395
389
            finally:
396
390
                f.close()
581
575
            f.close()
582
576
 
583
577
 
584
 
    def get_revision_xml(self, revision_id):
 
578
    def get_revision_xml_file(self, revision_id):
585
579
        """Return XML file object for revision object."""
586
580
        if not revision_id or not isinstance(revision_id, basestring):
587
581
            raise InvalidRevisionId(revision_id)
596
590
            self.unlock()
597
591
 
598
592
 
 
593
    #deprecated
 
594
    get_revision_xml = get_revision_xml_file
 
595
 
 
596
 
599
597
    def get_revision(self, revision_id):
600
598
        """Return the Revision object for a named revision"""
601
 
        xml_file = self.get_revision_xml(revision_id)
 
599
        xml_file = self.get_revision_xml_file(revision_id)
602
600
 
603
601
        try:
604
 
            r = unpack_xml(Revision, xml_file)
 
602
            r = bzrlib.xml.serializer_v4.read_revision(xml_file)
605
603
        except SyntaxError, e:
606
604
            raise bzrlib.errors.BzrError('failed to unpack revision_xml',
607
605
                                         [revision_id,
652
650
               parameter which can be either an integer revno or a
653
651
               string hash."""
654
652
        from bzrlib.inventory import Inventory
655
 
        from bzrlib.xml import unpack_xml
656
653
 
657
 
        return unpack_xml(Inventory, self.get_inventory_xml(inventory_id))
 
654
        f = self.get_inventory_xml_file(inventory_id)
 
655
        return bzrlib.xml.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):