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
303
303
def _make_control(self):
304
304
from bzrlib.inventory import Inventory
305
from bzrlib.xml import pack_xml
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
324
pack_xml(Inventory(), self.controlfile('inventory','w'))
323
f = self.controlfile('inventory','w')
324
bzrlib.xml.serializer_v4.write_inventory(Inventory(), f)
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
369
367
# ElementTree does its own conversion from UTF-8, so open in
371
inv = unpack_xml(Inventory,
372
self.controlfile('inventory', 'rb'))
373
mutter("loaded inventory of %d items in %f"
374
% (len(inv), time() - before))
369
f = self.controlfile('inventory', 'rb')
370
return bzrlib.xml.serializer_v4.read_inventory(f)
384
379
will be committed to the next revision.
386
381
from bzrlib.atomicfile import AtomicFile
387
from bzrlib.xml import pack_xml
389
383
self.lock_write()
391
385
f = AtomicFile(self.controlfilename('inventory'), 'wb')
387
bzrlib.xml.serializer_v4.write_inventory(inv, f)
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)
594
get_revision_xml = get_revision_xml_file
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)
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',
652
650
parameter which can be either an integer revno or a
654
652
from bzrlib.inventory import Inventory
655
from bzrlib.xml import unpack_xml
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)
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]
662
get_inventory_xml_file = get_inventory_xml
665
665
def get_inventory_sha1(self, inventory_id):
805
805
"""Pull in all new revisions from other branch.
807
807
from bzrlib.fetch import greedy_fetch
808
from bzrlib.revision import get_intervening_revisions
809
810
pb = bzrlib.ui.ui_factory.progress_bar()
810
811
pb.update('comparing histories')
812
revision_ids = self.missing_revisions(other, stop_revision)
814
if len(revision_ids) > 0:
815
count = greedy_fetch(self, other, revision_ids[-1], pb)[0]
812
if stop_revision is None:
813
other_revision = other.last_patch()
815
other_revision = other.lookup_revision(stop_revision)
816
count = greedy_fetch(self, other, other_revision, pb)[0]
818
revision_ids = self.missing_revisions(other, stop_revision)
819
except DivergedBranches, e:
821
revision_ids = get_intervening_revisions(self.last_patch(),
822
other_revision, self)
823
assert self.last_patch() not in revision_ids
824
except bzrlib.errors.NotAncestor:
818
827
self.append_revision(*revision_ids)
819
## note("Added %d revisions." % count)
822
830
def install_revisions(self, other, revision_ids, pb):