~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

Dirty merge of the mainline

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
 
50
50
from bzrlib.branch import (Branch,
51
51
                           is_control_file,
52
 
                           needs_read_lock,
53
 
                           needs_write_lock,
54
52
                           quotefn)
55
53
from bzrlib.errors import (BzrCheckError,
56
54
                           BzrError,
57
55
                           DivergedBranches,
58
56
                           WeaveRevisionNotPresent,
59
57
                           NotBranchError,
 
58
                           NoSuchFile,
60
59
                           NotVersionedError)
61
60
from bzrlib.inventory import InventoryEntry
62
61
from bzrlib.osutils import (appendpath,
79
78
import bzrlib.tree
80
79
from bzrlib.trace import mutter
81
80
import bzrlib.xml5
 
81
from bzrlib.decorators import needs_read_lock, needs_write_lock
82
82
 
83
83
 
84
84
def gen_file_id(name):
237
237
            if path.find('://') != -1:
238
238
                raise NotBranchError(path=path)
239
239
        path = abspath(path)
 
240
        orig_path = path[:]
240
241
        tail = u''
241
242
        while True:
242
243
            try:
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)
255
256
 
256
257
    def __iter__(self):
257
258
        """Iterate through file_ids for this tree.
412
413
        if updated:
413
414
            self.set_pending_merges(p)
414
415
 
 
416
    @needs_read_lock
415
417
    def pending_merges(self):
416
418
        """Return a list of pending merges.
417
419
 
418
420
        These are revisions that have been merged into the working
419
421
        directory but not yet committed.
420
422
        """
421
 
        cfn = self.branch._rel_controlfilename('pending-merges')
422
 
        if not self.branch._transport.has(cfn):
 
423
        try:
 
424
            f = self.branch.control_files.get_utf8('pending-merges')
 
425
        except NoSuchFile:
423
426
            return []
424
427
        p = []
425
 
        for l in self.branch.controlfile('pending-merges', 'r').readlines():
 
428
        for l in f.readlines():
426
429
            p.append(l.rstrip('\n'))
427
430
        return p
428
431
 
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))
432
435
 
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]
678
681
                else:
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))
683
687
            return count
684
688
        finally:
685
689
            source.unlock()
790
794
        return 'basis-inventory.%s' % revision_id
791
795
 
792
796
    def set_last_revision(self, new_revision, old_revision=None):
793
 
        if old_revision:
 
797
        if old_revision is not None:
794
798
            try:
795
799
                path = self._basis_inventory_name(old_revision)
796
 
                path = self.branch._rel_controlfilename(path)
797
 
                self.branch._transport.delete(path)
798
 
            except:
 
800
                path = self.branch.control_files._escape(path)
 
801
                self.branch.control_files._transport.delete(path)
 
802
            except NoSuchFile:
799
803
                pass
800
804
        try:
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:
805
809
            pass
806
810
 
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()
811
815
        
812
816
    @needs_read_lock
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
816
820
        # binary.
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)
819
823
 
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.
915
919
        """
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()
919
928
 
925
934
        sio = StringIO()
926
935
        bzrlib.xml5.serializer_v5.write_inventory(inv, sio)
927
936
        sio.seek(0)
928
 
        f = AtomicFile(self.branch.controlfilename('inventory'))
 
937
        f = AtomicFile(self.branch.control_files.controlfilename('inventory'))
929
938
        try:
930
939
            pumpfile(sio, f)
931
940
            f.commit()