~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: Martin Pool
  • Date: 2006-01-30 06:23:50 UTC
  • mfrom: (1534.1.17 integration)
  • Revision ID: mbp@sourcefrog.net-20060130062350-d6f25277ddcdfd79
[merge] robert's integration of much recent work

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,
77
76
import bzrlib.tree
78
77
from bzrlib.trace import mutter
79
78
import bzrlib.xml5
 
79
from bzrlib.decorators import needs_read_lock, needs_write_lock
80
80
 
81
81
 
82
82
def gen_file_id(name):
411
411
        if updated:
412
412
            self.set_pending_merges(p)
413
413
 
 
414
    @needs_read_lock
414
415
    def pending_merges(self):
415
416
        """Return a list of pending merges.
416
417
 
417
418
        These are revisions that have been merged into the working
418
419
        directory but not yet committed.
419
420
        """
420
 
        cfn = self.branch._rel_controlfilename('pending-merges')
421
 
        if not self.branch._transport.has(cfn):
 
421
        try:
 
422
            f = self.branch.control_files.get_utf8('pending-merges')
 
423
        except NoSuchFile:
422
424
            return []
423
425
        p = []
424
 
        for l in self.branch.controlfile('pending-merges', 'r').readlines():
 
426
        for l in f.readlines():
425
427
            p.append(l.rstrip('\n'))
426
428
        return p
427
429
 
428
430
    @needs_write_lock
429
431
    def set_pending_merges(self, rev_list):
430
 
        self.branch.put_controlfile('pending-merges', '\n'.join(rev_list))
 
432
        self.branch.control_files.put_utf8('pending-merges', '\n'.join(rev_list))
431
433
 
432
434
    def get_symlink_target(self, file_id):
433
435
        return os.readlink(self.id2abspath(file_id))
676
678
                    other_revision = old_revision_history[-1]
677
679
                else:
678
680
                    other_revision = None
 
681
                repository = self.branch.repository
679
682
                merge_inner(self.branch,
680
683
                            self.branch.basis_tree(), 
681
 
                            self.branch.revision_tree(other_revision))
 
684
                            repository.revision_tree(other_revision))
682
685
            return count
683
686
        finally:
684
687
            source.unlock()
789
792
        return 'basis-inventory.%s' % revision_id
790
793
 
791
794
    def set_last_revision(self, new_revision, old_revision=None):
792
 
        if old_revision:
 
795
        if old_revision is not None:
793
796
            try:
794
797
                path = self._basis_inventory_name(old_revision)
795
 
                path = self.branch._rel_controlfilename(path)
796
 
                self.branch._transport.delete(path)
797
 
            except:
 
798
                path = self.branch.control_files._escape(path)
 
799
                self.branch.control_files._transport.delete(path)
 
800
            except NoSuchFile:
798
801
                pass
799
802
        try:
800
 
            xml = self.branch.get_inventory_xml(new_revision)
 
803
            xml = self.branch.repository.get_inventory_xml(new_revision)
801
804
            path = self._basis_inventory_name(new_revision)
802
 
            self.branch.put_controlfile(path, xml)
 
805
            self.branch.control_files.put_utf8(path, xml)
803
806
        except WeaveRevisionNotPresent:
804
807
            pass
805
808
 
806
809
    def read_basis_inventory(self, revision_id):
807
810
        """Read the cached basis inventory."""
808
811
        path = self._basis_inventory_name(revision_id)
809
 
        return self.branch.controlfile(path, 'r').read()
 
812
        return self.branch.control_files.get_utf8(path).read()
810
813
        
811
814
    @needs_read_lock
812
815
    def read_working_inventory(self):
813
816
        """Read the working inventory."""
814
817
        # ElementTree does its own conversion from UTF-8, so open in
815
818
        # binary.
816
 
        f = self.branch.controlfile('inventory', 'rb')
 
819
        f = self.branch.control_files.get('inventory')
817
820
        return bzrlib.xml5.serializer_v5.read_inventory(f)
818
821
 
819
822
    @needs_write_lock
915
918
        between multiple working trees, i.e. via shared storage, then we 
916
919
        would probably want to lock both the local tree, and the branch.
917
920
        """
918
 
        if self._hashcache.needs_write and self.branch._lock_count==1:
 
921
        # FIXME: We want to write out the hashcache only when the last lock on
 
922
        # this working copy is released.  Peeking at the lock count is a bit
 
923
        # of a nasty hack; probably it's better to have a transaction object,
 
924
        # which can do some finalization when it's either successfully or
 
925
        # unsuccessfully completed.  (Denys's original patch did that.)
 
926
        if self._hashcache.needs_write and self.branch.control_files._lock_count==1:
919
927
            self._hashcache.write()
920
928
        return self.branch.unlock()
921
929
 
927
935
        sio = StringIO()
928
936
        bzrlib.xml5.serializer_v5.write_inventory(inv, sio)
929
937
        sio.seek(0)
930
 
        f = AtomicFile(self.branch.controlfilename('inventory'))
 
938
        f = AtomicFile(self.branch.control_files.controlfilename('inventory'))
931
939
        try:
932
940
            pumpfile(sio, f)
933
941
            f.commit()