~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

(mbp) merge bzr.dev to 0.8, prepare for release

Show diffs side-by-side

added added

removed removed

Lines of Context:
223
223
                 DeprecationWarning,
224
224
                 stacklevel=2)
225
225
            wt = WorkingTree.open(basedir)
226
 
            self.branch = wt.branch
 
226
            self._branch = wt.branch
227
227
            self.basedir = wt.basedir
228
228
            self._control_files = wt._control_files
229
229
            self._hashcache = wt._hashcache
244
244
                     DeprecationWarning,
245
245
                     stacklevel=2
246
246
                     )
247
 
            self.branch = branch
 
247
            self._branch = branch
248
248
        else:
249
 
            self.branch = self.bzrdir.open_branch()
 
249
            self._branch = self.bzrdir.open_branch()
250
250
        assert isinstance(self.branch, Branch), \
251
251
            "branch %r is not a Branch" % self.branch
252
252
        self.basedir = realpath(basedir)
282
282
        else:
283
283
            self._set_inventory(_inventory)
284
284
 
 
285
    branch = property(
 
286
        fget=lambda self: self._branch,
 
287
        doc="""The branch this WorkingTree is connected to.
 
288
 
 
289
            This cannot be set - it is reflective of the actual disk structure
 
290
            the working tree has been constructed from.
 
291
            """)
 
292
 
 
293
    def break_lock(self):
 
294
        """Break a lock if one is present from another instance.
 
295
 
 
296
        Uses the ui factory to ask for confirmation if the lock may be from
 
297
        an active process.
 
298
 
 
299
        This will probe the repository for its lock as well.
 
300
        """
 
301
        self._control_files.break_lock()
 
302
        self.branch.break_lock()
 
303
 
285
304
    def _set_inventory(self, inv):
286
305
        self._inventory = inv
287
306
        self.path2id = self._inventory.path2id
1023
1042
        """
1024
1043
        return self.branch.last_revision()
1025
1044
 
 
1045
    def is_locked(self):
 
1046
        return self._control_files.is_locked()
 
1047
 
1026
1048
    def lock_read(self):
1027
1049
        """See Branch.lock_read, and WorkingTree.unlock."""
1028
1050
        self.branch.lock_read()
1041
1063
            self.branch.unlock()
1042
1064
            raise
1043
1065
 
 
1066
    def get_physical_lock_status(self):
 
1067
        return self._control_files.get_physical_lock_status()
 
1068
 
1044
1069
    def _basis_inventory_name(self):
1045
1070
        return 'basis-inventory'
1046
1071
 
1221
1246
             self._control_files._lock_count==3)):
1222
1247
            self._hashcache.write()
1223
1248
        # reverse order of locking.
1224
 
        result = self._control_files.unlock()
1225
1249
        try:
 
1250
            return self._control_files.unlock()
 
1251
        finally:
1226
1252
            self.branch.unlock()
1227
 
        finally:
1228
 
            return result
1229
1253
 
1230
1254
    @needs_write_lock
1231
1255
    def update(self):
1486
1510
        """See WorkingTreeFormat.get_format_description()."""
1487
1511
        return "Working tree format 2"
1488
1512
 
 
1513
    def stub_initialize_remote(self, control_files):
 
1514
        """As a special workaround create critical control files for a remote working tree
 
1515
        
 
1516
        This ensures that it can later be updated and dealt with locally,
 
1517
        since BzrDirFormat6 and BzrDirFormat5 cannot represent dirs with 
 
1518
        no working tree.  (See bug #43064).
 
1519
        """
 
1520
        sio = StringIO()
 
1521
        inv = Inventory()
 
1522
        bzrlib.xml5.serializer_v5.write_inventory(inv, sio)
 
1523
        sio.seek(0)
 
1524
        control_files.put('inventory', sio)
 
1525
 
 
1526
        control_files.put_utf8('pending-merges', '')
 
1527
        
 
1528
 
1489
1529
    def initialize(self, a_bzrdir, revision_id=None):
1490
1530
        """See WorkingTreeFormat.initialize()."""
1491
1531
        if not isinstance(a_bzrdir.transport, LocalTransport):
1577
1617
        transport = a_bzrdir.get_workingtree_transport(self)
1578
1618
        control_files = self._open_control_files(a_bzrdir)
1579
1619
        control_files.create_lock()
 
1620
        control_files.lock_write()
1580
1621
        control_files.put_utf8('format', self.get_format_string())
1581
1622
        branch = a_bzrdir.open_branch()
1582
1623
        if revision_id is None:
1589
1630
                         _format=self,
1590
1631
                         _bzrdir=a_bzrdir,
1591
1632
                         _control_files=control_files)
1592
 
        wt._write_inventory(inv)
1593
 
        wt.set_root_id(inv.root.file_id)
1594
 
        wt.set_last_revision(revision_id)
1595
 
        wt.set_pending_merges([])
1596
 
        build_tree(wt.basis_tree(), wt)
 
1633
        wt.lock_write()
 
1634
        try:
 
1635
            wt._write_inventory(inv)
 
1636
            wt.set_root_id(inv.root.file_id)
 
1637
            wt.set_last_revision(revision_id)
 
1638
            wt.set_pending_merges([])
 
1639
            build_tree(wt.basis_tree(), wt)
 
1640
        finally:
 
1641
            wt.unlock()
 
1642
            control_files.unlock()
1597
1643
        return wt
1598
1644
 
1599
1645
    def __init__(self):