/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

Update to 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)
 
726
 
 
727
    def _filter_parent_ids_by_ancestry(self, revision_ids):
 
728
        """Check that all merged revisions are proper 'heads'.
 
729
 
 
730
        This will always return the first revision_id, and any merged revisions
 
731
        which are 
 
732
        """
 
733
        if len(revision_ids) == 0:
 
734
            return revision_ids
 
735
        graph = self.branch.repository.get_graph()
 
736
        heads = graph.heads(revision_ids)
 
737
        new_revision_ids = revision_ids[:1]
 
738
        for revision_id in revision_ids[1:]:
 
739
            if revision_id in heads and revision_id not in new_revision_ids:
 
740
                new_revision_ids.append(revision_id)
 
741
        if new_revision_ids != revision_ids:
 
742
            trace.mutter('requested to set revision_ids = %s,'
 
743
                         ' but filtered to %s', revision_ids, new_revision_ids)
 
744
        return new_revision_ids
724
745
 
725
746
    @needs_tree_write_lock
726
747
    def set_parent_ids(self, revision_ids, allow_leftmost_as_ghost=False):
740
761
        for revision_id in revision_ids:
741
762
            _mod_revision.check_not_reserved_id(revision_id)
742
763
 
 
764
        revision_ids = self._filter_parent_ids_by_ancestry(revision_ids)
 
765
 
743
766
        if len(revision_ids) > 0:
744
767
            self.set_last_revision(revision_ids[0])
745
768
        else:
757
780
        self._check_parents_for_ghosts(parent_ids,
758
781
            allow_leftmost_as_ghost=allow_leftmost_as_ghost)
759
782
 
 
783
        parent_ids = self._filter_parent_ids_by_ancestry(parent_ids)
 
784
 
760
785
        if len(parent_ids) == 0:
761
786
            leftmost_parent_id = _mod_revision.NULL_REVISION
762
787
            leftmost_parent_tree = None
802
827
    def _put_rio(self, filename, stanzas, header):
803
828
        self._must_be_locked()
804
829
        my_file = rio_file(stanzas, header)
805
 
        self._control_files.put(filename, my_file)
 
830
        self._transport.put_file(filename, my_file,
 
831
            mode=self._control_files._file_mode)
806
832
 
807
833
    @needs_write_lock # because merge pulls data into the branch.
808
834
    def merge_from_branch(self, branch, to_revision=None, from_revision=None,
867
893
        still in the working inventory and have that text hash.
868
894
        """
869
895
        try:
870
 
            hashfile = self._control_files.get('merge-hashes')
 
896
            hashfile = self._transport.get('merge-hashes')
871
897
        except errors.NoSuchFile:
872
898
            return {}
873
899
        merge_hashes = {}
1030
1056
        sio = StringIO()
1031
1057
        self._serialize(self._inventory, sio)
1032
1058
        sio.seek(0)
1033
 
        self._control_files.put('inventory', sio)
 
1059
        self._transport.put_file('inventory', sio,
 
1060
            mode=self._control_files._file_mode)
1034
1061
        self._inventory_is_modified = False
1035
1062
 
1036
1063
    def _kind(self, relpath):
1716
1743
    def _reset_data(self):
1717
1744
        """Reset transient data that cannot be revalidated."""
1718
1745
        self._inventory_is_modified = False
1719
 
        result = self._deserialize(self._control_files.get('inventory'))
 
1746
        result = self._deserialize(self._transport.get('inventory'))
1720
1747
        self._set_inventory(result, dirty=False)
1721
1748
 
1722
1749
    @needs_tree_write_lock
1745
1772
        """Write the basis inventory XML to the basis-inventory file"""
1746
1773
        path = self._basis_inventory_name()
1747
1774
        sio = StringIO(xml)
1748
 
        self._control_files.put(path, sio)
 
1775
        self._transport.put_file(path, sio,
 
1776
            mode=self._control_files._file_mode)
1749
1777
 
1750
1778
    def _create_basis_xml_from_inventory(self, revision_id, inventory):
1751
1779
        """Create the text that will be saved in basis-inventory"""
1782
1810
    def read_basis_inventory(self):
1783
1811
        """Read the cached basis inventory."""
1784
1812
        path = self._basis_inventory_name()
1785
 
        return self._control_files.get(path).read()
 
1813
        return self._transport.get_bytes(path)
1786
1814
        
1787
1815
    @needs_read_lock
1788
1816
    def read_working_inventory(self):
1797
1825
        # binary.
1798
1826
        if self._inventory_is_modified:
1799
1827
            raise errors.InventoryModified(self)
1800
 
        result = self._deserialize(self._control_files.get('inventory'))
 
1828
        result = self._deserialize(self._transport.get('inventory'))
1801
1829
        self._set_inventory(result, dirty=False)
1802
1830
        return result
1803
1831
 
2500
2528
    def _last_revision(self):
2501
2529
        """See Mutable.last_revision."""
2502
2530
        try:
2503
 
            return self._control_files.get('last-revision').read()
 
2531
            return self._transport.get_bytes('last-revision')
2504
2532
        except errors.NoSuchFile:
2505
2533
            return _mod_revision.NULL_REVISION
2506
2534
 
2508
2536
        """See WorkingTree._change_last_revision."""
2509
2537
        if revision_id is None or revision_id == NULL_REVISION:
2510
2538
            try:
2511
 
                self._control_files._transport.delete('last-revision')
 
2539
                self._transport.delete('last-revision')
2512
2540
            except errors.NoSuchFile:
2513
2541
                pass
2514
2542
            return False
2515
2543
        else:
2516
 
            self._control_files.put_bytes('last-revision', revision_id)
 
2544
            self._transport.put_bytes('last-revision', revision_id,
 
2545
                mode=self._control_files._file_mode)
2517
2546
            return True
2518
2547
 
2519
2548
    @needs_tree_write_lock
2531
2560
    @needs_read_lock
2532
2561
    def conflicts(self):
2533
2562
        try:
2534
 
            confile = self._control_files.get('conflicts')
 
2563
            confile = self._transport.get('conflicts')
2535
2564
        except errors.NoSuchFile:
2536
2565
            return _mod_conflicts.ConflictList()
2537
2566
        try:
2656
2685
        """See WorkingTreeFormat.get_format_description()."""
2657
2686
        return "Working tree format 2"
2658
2687
 
2659
 
    def stub_initialize_remote(self, control_files):
2660
 
        """As a special workaround create critical control files for a remote working tree
 
2688
    def _stub_initialize_remote(self, branch):
 
2689
        """As a special workaround create critical control files for a remote working tree.
2661
2690
        
2662
2691
        This ensures that it can later be updated and dealt with locally,
2663
2692
        since BzrDirFormat6 and BzrDirFormat5 cannot represent dirs with 
2667
2696
        inv = Inventory()
2668
2697
        xml5.serializer_v5.write_inventory(inv, sio, working=True)
2669
2698
        sio.seek(0)
2670
 
        control_files.put('inventory', sio)
2671
 
 
2672
 
        control_files.put_bytes('pending-merges', '')
 
2699
        branch._transport.put_file('inventory', sio,
 
2700
            mode=branch.control_files._file_mode)
 
2701
        branch._transport.put_bytes('pending-merges', '',
 
2702
            mode=branch.control_files._file_mode)
2673
2703
        
2674
2704
 
2675
2705
    def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
2784
2814
        control_files = self._open_control_files(a_bzrdir)
2785
2815
        control_files.create_lock()
2786
2816
        control_files.lock_write()
2787
 
        control_files.put_utf8('format', self.get_format_string())
 
2817
        transport.put_bytes('format', self.get_format_string(),
 
2818
            mode=control_files._file_mode)
2788
2819
        if from_branch is not None:
2789
2820
            branch = from_branch
2790
2821
        else: