~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Robert Collins
  • Date: 2005-09-12 12:49:28 UTC
  • mfrom: (1092.2.12)
  • mto: (1092.2.15)
  • mto: This revision was merged to the branch mainline in revision 1397.
  • Revision ID: robertc@robertcollins.net-20050912124928-1da074d2e9c3344b
mergeĀ fromĀ baz2bzr

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
 
301
301
 
302
302
    def _make_control(self):
303
303
        from bzrlib.inventory import Inventory
304
 
        from bzrlib.xml import pack_xml
305
304
        
306
305
        os.mkdir(self.controlfilename([]))
307
306
        self.controlfile('README', 'w').write(
320
319
        # if we want per-tree root ids then this is the place to set
321
320
        # them; they're not needed for now and so ommitted for
322
321
        # simplicity.
323
 
        pack_xml(Inventory(), self.controlfile('inventory','w'))
 
322
        f = self.controlfile('inventory','w')
 
323
        bzrlib.xml.serializer_v4.write_inventory(Inventory(), f)
 
324
 
324
325
 
325
326
    def _check_format(self):
326
327
        """Check this branch format is supported.
334
335
        # on Windows from Linux and so on.  I think it might be better
335
336
        # to always make all internal files in unix format.
336
337
        fmt = self.controlfile('branch-format', 'r').read()
337
 
        fmt.replace('\r\n', '')
 
338
        fmt = fmt.replace('\r\n', '\n')
338
339
        if fmt != BZR_BRANCH_FORMAT:
339
340
            raise BzrError('sorry, branch format %r not supported' % fmt,
340
341
                           ['use a different bzr version',
360
361
    def read_working_inventory(self):
361
362
        """Read the working inventory."""
362
363
        from bzrlib.inventory import Inventory
363
 
        from bzrlib.xml import unpack_xml
364
 
        from time import time
365
 
        before = time()
366
364
        self.lock_read()
367
365
        try:
368
366
            # ElementTree does its own conversion from UTF-8, so open in
369
367
            # binary.
370
 
            inv = unpack_xml(Inventory,
371
 
                             self.controlfile('inventory', 'rb'))
372
 
            mutter("loaded inventory of %d items in %f"
373
 
                   % (len(inv), time() - before))
374
 
            return inv
 
368
            f = self.controlfile('inventory', 'rb')
 
369
            return bzrlib.xml.serializer_v4.read_inventory(f)
375
370
        finally:
376
371
            self.unlock()
377
372
            
383
378
        will be committed to the next revision.
384
379
        """
385
380
        from bzrlib.atomicfile import AtomicFile
386
 
        from bzrlib.xml import pack_xml
387
381
        
388
382
        self.lock_write()
389
383
        try:
390
384
            f = AtomicFile(self.controlfilename('inventory'), 'wb')
391
385
            try:
392
 
                pack_xml(inv, f)
 
386
                bzrlib.xml.serializer_v4.write_inventory(inv, f)
393
387
                f.commit()
394
388
            finally:
395
389
                f.close()
577
571
        finally:
578
572
            f.close()
579
573
 
580
 
    def get_revision_xml(self, revision_id):
 
574
    def get_revision_xml_file(self, revision_id):
581
575
        """Return XML file object for revision object."""
582
576
        if not revision_id or not isinstance(revision_id, basestring):
583
577
            raise InvalidRevisionId(revision_id)
591
585
        finally:
592
586
            self.unlock()
593
587
 
 
588
    #deprecated
 
589
    get_revision_xml = get_revision_xml_file
 
590
 
594
591
    def get_revision(self, revision_id):
595
 
        """Return the Revision object for a named revision. 
596
 
        
597
 
        This operates on the storage level - it is agnostic as to
598
 
        logical presence or absence from the branch.
599
 
        """
600
 
        xml_file = self.get_revision_xml(revision_id)
 
592
        """Return the Revision object for a named revision"""
 
593
        xml_file = self.get_revision_xml_file(revision_id)
601
594
 
602
595
        try:
603
 
            r = unpack_xml(Revision, xml_file)
 
596
            r = bzrlib.xml.serializer_v4.read_revision(xml_file)
604
597
        except SyntaxError, e:
605
598
            raise bzrlib.errors.BzrError('failed to unpack revision_xml',
606
599
                                         [revision_id,
647
640
               parameter which can be either an integer revno or a
648
641
               string hash."""
649
642
        from bzrlib.inventory import Inventory
650
 
        from bzrlib.xml import unpack_xml
651
 
 
652
 
        return unpack_xml(Inventory, self.get_inventory_xml(inventory_id))
 
643
        f = self.get_inventory_xml_file(inventory_id)
 
644
        return bzrlib.xml.serializer_v4.read_inventory(f)
653
645
 
654
646
    def get_inventory_xml(self, inventory_id):
655
647
        """Get inventory XML as a file object."""
656
648
        return self.inventory_store[inventory_id]
 
649
 
 
650
    get_inventory_xml_file = get_inventory_xml
657
651
            
658
652
    def get_inventory_sha1(self, inventory_id):
659
653
        """Return the sha1 hash of the inventory entry
795
789
        """Pull in all new revisions from other branch.
796
790
        """
797
791
        from bzrlib.fetch import greedy_fetch
 
792
        from bzrlib.revision import get_intervening_revisions
798
793
 
799
794
        pb = bzrlib.ui.ui_factory.progress_bar()
800
795
        pb.update('comparing histories')
801
796
 
802
 
        revision_ids = self.missing_revisions(other, stop_revision)
 
797
        try:
 
798
            revision_ids = self.missing_revisions(other, stop_revision)
 
799
        except DivergedBranches, e:
 
800
            try:
 
801
                if stop_revision is None:
 
802
                    end_revision = other.last_patch()
 
803
                revision_ids = get_intervening_revisions(self.last_patch(), 
 
804
                                                         end_revision, other)
 
805
                assert self.last_patch() not in revision_ids
 
806
            except bzrlib.errors.NotAncestor:
 
807
                raise e
803
808
 
804
809
        if len(revision_ids) > 0:
805
810
            count = greedy_fetch(self, other, revision_ids[-1], pb)[0]