50
50
from bzrlib.branch import (Branch,
55
53
from bzrlib.errors import (BzrCheckError,
58
56
WeaveRevisionNotPresent,
61
60
from bzrlib.inventory import InventoryEntry
62
61
from bzrlib.osutils import (appendpath,
251
252
path = os.path.dirname(path)
252
253
if lastpath == path:
253
254
# reached the root, whatever that may be
254
raise NotBranchError(path=path)
255
raise NotBranchError(path=orig_path)
256
257
def __iter__(self):
257
258
"""Iterate through file_ids for this tree.
413
414
self.set_pending_merges(p)
415
417
def pending_merges(self):
416
418
"""Return a list of pending merges.
418
420
These are revisions that have been merged into the working
419
421
directory but not yet committed.
421
cfn = self.branch._rel_controlfilename('pending-merges')
422
if not self.branch._transport.has(cfn):
424
f = self.branch.control_files.get_utf8('pending-merges')
425
for l in self.branch.controlfile('pending-merges', 'r').readlines():
428
for l in f.readlines():
426
429
p.append(l.rstrip('\n'))
429
432
@needs_write_lock
430
433
def set_pending_merges(self, rev_list):
431
self.branch.put_controlfile('pending-merges', '\n'.join(rev_list))
434
self.branch.control_files.put_utf8('pending-merges', '\n'.join(rev_list))
433
436
def get_symlink_target(self, file_id):
434
437
return os.readlink(self.id2abspath(file_id))
677
680
other_revision = old_revision_history[-1]
679
682
other_revision = None
683
repository = self.branch.repository
680
684
merge_inner(self.branch,
681
685
self.branch.basis_tree(),
682
self.branch.revision_tree(other_revision))
686
repository.revision_tree(other_revision))
790
794
return 'basis-inventory.%s' % revision_id
792
796
def set_last_revision(self, new_revision, old_revision=None):
797
if old_revision is not None:
795
799
path = self._basis_inventory_name(old_revision)
796
path = self.branch._rel_controlfilename(path)
797
self.branch._transport.delete(path)
800
path = self.branch.control_files._escape(path)
801
self.branch.control_files._transport.delete(path)
801
xml = self.branch.get_inventory_xml(new_revision)
805
xml = self.branch.repository.get_inventory_xml(new_revision)
802
806
path = self._basis_inventory_name(new_revision)
803
self.branch.put_controlfile(path, xml)
807
self.branch.control_files.put_utf8(path, xml)
804
808
except WeaveRevisionNotPresent:
807
811
def read_basis_inventory(self, revision_id):
808
812
"""Read the cached basis inventory."""
809
813
path = self._basis_inventory_name(revision_id)
810
return self.branch.controlfile(path, 'r').read()
814
return self.branch.control_files.get_utf8(path).read()
813
817
def read_working_inventory(self):
814
818
"""Read the working inventory."""
815
819
# ElementTree does its own conversion from UTF-8, so open in
817
f = self.branch.controlfile('inventory', 'rb')
821
f = self.branch.control_files.get('inventory')
818
822
return bzrlib.xml5.serializer_v5.read_inventory(f)
820
824
@needs_write_lock
913
917
between multiple working trees, i.e. via shared storage, then we
914
918
would probably want to lock both the local tree, and the branch.
916
if self._hashcache.needs_write and self.branch._lock_count==1:
920
# FIXME: We want to write out the hashcache only when the last lock on
921
# this working copy is released. Peeking at the lock count is a bit
922
# of a nasty hack; probably it's better to have a transaction object,
923
# which can do some finalization when it's either successfully or
924
# unsuccessfully completed. (Denys's original patch did that.)
925
if self._hashcache.needs_write and self.branch.control_files._lock_count==1:
917
926
self._hashcache.write()
918
927
return self.branch.unlock()