/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Robert Collins
  • Date: 2005-09-12 12:39:58 UTC
  • mfrom: (1185.3.4)
  • mto: (1185.1.10)
  • mto: This revision was merged to the branch mainline in revision 1390.
  • Revision ID: robertc@robertcollins.net-20050912123958-7982e808f291f439
merge up with head

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
 
303
303
 
304
304
    def _make_control(self):
305
305
        from bzrlib.inventory import Inventory
306
 
        from bzrlib.xml import pack_xml
307
306
        
308
307
        os.mkdir(self.controlfilename([]))
309
308
        self.controlfile('README', 'w').write(
322
321
        # if we want per-tree root ids then this is the place to set
323
322
        # them; they're not needed for now and so ommitted for
324
323
        # simplicity.
325
 
        pack_xml(Inventory(), self.controlfile('inventory','w'))
 
324
        f = self.controlfile('inventory','w')
 
325
        bzrlib.xml.serializer_v4.write_inventory(Inventory(), f)
 
326
 
326
327
 
327
328
    def _check_format(self):
328
329
        """Check this branch format is supported.
336
337
        # on Windows from Linux and so on.  I think it might be better
337
338
        # to always make all internal files in unix format.
338
339
        fmt = self.controlfile('branch-format', 'r').read()
339
 
        fmt.replace('\r\n', '')
 
340
        fmt = fmt.replace('\r\n', '\n')
340
341
        if fmt != BZR_BRANCH_FORMAT:
341
342
            raise BzrError('sorry, branch format %r not supported' % fmt,
342
343
                           ['use a different bzr version',
362
363
    def read_working_inventory(self):
363
364
        """Read the working inventory."""
364
365
        from bzrlib.inventory import Inventory
365
 
        from bzrlib.xml import unpack_xml
366
 
        from time import time
367
 
        before = time()
368
366
        self.lock_read()
369
367
        try:
370
368
            # ElementTree does its own conversion from UTF-8, so open in
371
369
            # binary.
372
 
            inv = unpack_xml(Inventory,
373
 
                             self.controlfile('inventory', 'rb'))
374
 
            mutter("loaded inventory of %d items in %f"
375
 
                   % (len(inv), time() - before))
376
 
            return inv
 
370
            f = self.controlfile('inventory', 'rb')
 
371
            return bzrlib.xml.serializer_v4.read_inventory(f)
377
372
        finally:
378
373
            self.unlock()
379
374
            
385
380
        will be committed to the next revision.
386
381
        """
387
382
        from bzrlib.atomicfile import AtomicFile
388
 
        from bzrlib.xml import pack_xml
389
383
        
390
384
        self.lock_write()
391
385
        try:
392
386
            f = AtomicFile(self.controlfilename('inventory'), 'wb')
393
387
            try:
394
 
                pack_xml(inv, f)
 
388
                bzrlib.xml.serializer_v4.write_inventory(inv, f)
395
389
                f.commit()
396
390
            finally:
397
391
                f.close()
582
576
            f.close()
583
577
 
584
578
 
585
 
    def get_revision_xml(self, revision_id):
 
579
    def get_revision_xml_file(self, revision_id):
586
580
        """Return XML file object for revision object."""
587
581
        if not revision_id or not isinstance(revision_id, basestring):
588
582
            raise InvalidRevisionId(revision_id)
597
591
            self.unlock()
598
592
 
599
593
 
 
594
    #deprecated
 
595
    get_revision_xml = get_revision_xml_file
 
596
 
 
597
 
600
598
    def get_revision(self, revision_id):
601
599
        """Return the Revision object for a named revision"""
602
 
        xml_file = self.get_revision_xml(revision_id)
 
600
        xml_file = self.get_revision_xml_file(revision_id)
603
601
 
604
602
        try:
605
 
            r = unpack_xml(Revision, xml_file)
 
603
            r = bzrlib.xml.serializer_v4.read_revision(xml_file)
606
604
        except SyntaxError, e:
607
605
            raise bzrlib.errors.BzrError('failed to unpack revision_xml',
608
606
                                         [revision_id,
653
651
               parameter which can be either an integer revno or a
654
652
               string hash."""
655
653
        from bzrlib.inventory import Inventory
656
 
        from bzrlib.xml import unpack_xml
657
654
 
658
 
        return unpack_xml(Inventory, self.get_inventory_xml(inventory_id))
 
655
        f = self.get_inventory_xml_file(inventory_id)
 
656
        return bzrlib.xml.serializer_v4.read_inventory(f)
659
657
 
660
658
 
661
659
    def get_inventory_xml(self, inventory_id):
662
660
        """Get inventory XML as a file object."""
663
661
        return self.inventory_store[inventory_id]
 
662
 
 
663
    get_inventory_xml_file = get_inventory_xml
664
664
            
665
665
 
666
666
    def get_inventory_sha1(self, inventory_id):
806
806
        """Pull in all new revisions from other branch.
807
807
        """
808
808
        from bzrlib.fetch import greedy_fetch
 
809
        from bzrlib.revision import get_intervening_revisions
809
810
 
810
811
        pb = bzrlib.ui.ui_factory.progress_bar()
811
812
        pb.update('comparing histories')
812
813
 
813
 
        revision_ids = self.missing_revisions(other, stop_revision)
 
814
        try:
 
815
            revision_ids = self.missing_revisions(other, stop_revision)
 
816
        except DivergedBranches, e:
 
817
            try:
 
818
                if stop_revision is None:
 
819
                    end_revision = other.last_patch()
 
820
                revision_ids = get_intervening_revisions(self.last_patch(), 
 
821
                                                         end_revision, other)
 
822
                assert self.last_patch() not in revision_ids
 
823
            except bzrlib.errors.NotAncestor:
 
824
                raise e
814
825
 
815
826
        if len(revision_ids) > 0:
816
827
            count = greedy_fetch(self, other, revision_ids[-1], pb)[0]