~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: John Arbash Meinel
  • Date: 2008-05-28 21:53:46 UTC
  • mfrom: (3453 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3458.
  • Revision ID: john@arbash-meinel.com-20080528215346-l8plys9h9ps624pn
merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
215
215
        else:
216
216
            # assume all other formats have their own control files.
217
217
            self._control_files = _control_files
 
218
        self._transport = self._control_files._transport
218
219
        # update the whole cache up front and write to disk if anything changed;
219
220
        # in the future we might want to do this more selectively
220
221
        # two possible ways offer themselves : in self._unlock, write the cache
224
225
        wt_trans = self.bzrdir.get_workingtree_transport(None)
225
226
        cache_filename = wt_trans.local_abspath('stat-cache')
226
227
        self._hashcache = hashcache.HashCache(basedir, cache_filename,
227
 
                                              self._control_files._file_mode)
 
228
            self.bzrdir._get_file_mode())
228
229
        hc = self._hashcache
229
230
        hc.read()
230
231
        # is this scan needed ? it makes things kinda slow.
485
486
        else:
486
487
            parents = [last_rev]
487
488
        try:
488
 
            merges_file = self._control_files.get('pending-merges')
 
489
            merges_file = self._transport.get('pending-merges')
489
490
        except errors.NoSuchFile:
490
491
            pass
491
492
        else:
720
721
 
721
722
    def _set_merges_from_parent_ids(self, parent_ids):
722
723
        merges = parent_ids[1:]
723
 
        self._control_files.put_bytes('pending-merges', '\n'.join(merges))
 
724
        self._transport.put_bytes('pending-merges', '\n'.join(merges),
 
725
            mode=self._control_files._file_mode)
724
726
 
725
727
    @needs_tree_write_lock
726
728
    def set_parent_ids(self, revision_ids, allow_leftmost_as_ghost=False):
802
804
    def _put_rio(self, filename, stanzas, header):
803
805
        self._must_be_locked()
804
806
        my_file = rio_file(stanzas, header)
805
 
        self._control_files.put(filename, my_file)
 
807
        self._transport.put_file(filename, my_file,
 
808
            mode=self._control_files._file_mode)
806
809
 
807
810
    @needs_write_lock # because merge pulls data into the branch.
808
811
    def merge_from_branch(self, branch, to_revision=None, from_revision=None,
867
870
        still in the working inventory and have that text hash.
868
871
        """
869
872
        try:
870
 
            hashfile = self._control_files.get('merge-hashes')
 
873
            hashfile = self._transport.get('merge-hashes')
871
874
        except errors.NoSuchFile:
872
875
            return {}
873
876
        merge_hashes = {}
1030
1033
        sio = StringIO()
1031
1034
        self._serialize(self._inventory, sio)
1032
1035
        sio.seek(0)
1033
 
        self._control_files.put('inventory', sio)
 
1036
        self._transport.put_file('inventory', sio,
 
1037
            mode=self._control_files._file_mode)
1034
1038
        self._inventory_is_modified = False
1035
1039
 
1036
1040
    def _kind(self, relpath):
1716
1720
    def _reset_data(self):
1717
1721
        """Reset transient data that cannot be revalidated."""
1718
1722
        self._inventory_is_modified = False
1719
 
        result = self._deserialize(self._control_files.get('inventory'))
 
1723
        result = self._deserialize(self._transport.get('inventory'))
1720
1724
        self._set_inventory(result, dirty=False)
1721
1725
 
1722
1726
    @needs_tree_write_lock
1745
1749
        """Write the basis inventory XML to the basis-inventory file"""
1746
1750
        path = self._basis_inventory_name()
1747
1751
        sio = StringIO(xml)
1748
 
        self._control_files.put(path, sio)
 
1752
        self._transport.put_file(path, sio,
 
1753
            mode=self._control_files._file_mode)
1749
1754
 
1750
1755
    def _create_basis_xml_from_inventory(self, revision_id, inventory):
1751
1756
        """Create the text that will be saved in basis-inventory"""
1782
1787
    def read_basis_inventory(self):
1783
1788
        """Read the cached basis inventory."""
1784
1789
        path = self._basis_inventory_name()
1785
 
        return self._control_files.get(path).read()
 
1790
        return self._transport.get_bytes(path)
1786
1791
        
1787
1792
    @needs_read_lock
1788
1793
    def read_working_inventory(self):
1797
1802
        # binary.
1798
1803
        if self._inventory_is_modified:
1799
1804
            raise errors.InventoryModified(self)
1800
 
        result = self._deserialize(self._control_files.get('inventory'))
 
1805
        result = self._deserialize(self._transport.get('inventory'))
1801
1806
        self._set_inventory(result, dirty=False)
1802
1807
        return result
1803
1808
 
2500
2505
    def _last_revision(self):
2501
2506
        """See Mutable.last_revision."""
2502
2507
        try:
2503
 
            return self._control_files.get('last-revision').read()
 
2508
            return self._transport.get_bytes('last-revision')
2504
2509
        except errors.NoSuchFile:
2505
2510
            return _mod_revision.NULL_REVISION
2506
2511
 
2508
2513
        """See WorkingTree._change_last_revision."""
2509
2514
        if revision_id is None or revision_id == NULL_REVISION:
2510
2515
            try:
2511
 
                self._control_files._transport.delete('last-revision')
 
2516
                self._transport.delete('last-revision')
2512
2517
            except errors.NoSuchFile:
2513
2518
                pass
2514
2519
            return False
2515
2520
        else:
2516
 
            self._control_files.put_bytes('last-revision', revision_id)
 
2521
            self._transport.put_bytes('last-revision', revision_id,
 
2522
                mode=self._control_files._file_mode)
2517
2523
            return True
2518
2524
 
2519
2525
    @needs_tree_write_lock
2531
2537
    @needs_read_lock
2532
2538
    def conflicts(self):
2533
2539
        try:
2534
 
            confile = self._control_files.get('conflicts')
 
2540
            confile = self._transport.get('conflicts')
2535
2541
        except errors.NoSuchFile:
2536
2542
            return _mod_conflicts.ConflictList()
2537
2543
        try:
2656
2662
        """See WorkingTreeFormat.get_format_description()."""
2657
2663
        return "Working tree format 2"
2658
2664
 
2659
 
    def stub_initialize_remote(self, control_files):
2660
 
        """As a special workaround create critical control files for a remote working tree
 
2665
    def _stub_initialize_remote(self, branch):
 
2666
        """As a special workaround create critical control files for a remote working tree.
2661
2667
        
2662
2668
        This ensures that it can later be updated and dealt with locally,
2663
2669
        since BzrDirFormat6 and BzrDirFormat5 cannot represent dirs with 
2667
2673
        inv = Inventory()
2668
2674
        xml5.serializer_v5.write_inventory(inv, sio, working=True)
2669
2675
        sio.seek(0)
2670
 
        control_files.put('inventory', sio)
2671
 
 
2672
 
        control_files.put_bytes('pending-merges', '')
 
2676
        branch._transport.put_file('inventory', sio,
 
2677
            mode=branch.control_files._file_mode)
 
2678
        branch._transport.put_bytes('pending-merges', '',
 
2679
            mode=branch.control_files._file_mode)
2673
2680
        
2674
2681
 
2675
2682
    def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
2784
2791
        control_files = self._open_control_files(a_bzrdir)
2785
2792
        control_files.create_lock()
2786
2793
        control_files.lock_write()
2787
 
        control_files.put_utf8('format', self.get_format_string())
 
2794
        transport.put_bytes('format', self.get_format_string(),
 
2795
            mode=control_files._file_mode)
2788
2796
        if from_branch is not None:
2789
2797
            branch = from_branch
2790
2798
        else: