211
"""Construct a WorkingTree for basedir.
213
"""Construct a WorkingTree instance. This is not a public API.
213
If the branch is not supplied, it is opened automatically.
214
If the branch is supplied, it must be the branch for this basedir.
215
(branch.base is not cross checked, because for remote branches that
216
would be meaningless).
215
:param branch: A branch to override probing for the branch.
218
217
self._format = _format
219
218
self.bzrdir = _bzrdir
220
219
if not _internal:
221
# not created via open etc.
222
warnings.warn("WorkingTree() is deprecated as of bzr version 0.8. "
223
"Please use bzrdir.open_workingtree or WorkingTree.open().",
226
wt = WorkingTree.open(basedir)
227
self._branch = wt.branch
228
self.basedir = wt.basedir
229
self._control_files = wt._control_files
230
self._hashcache = wt._hashcache
231
self._set_inventory(wt._inventory, dirty=False)
232
self._format = wt._format
233
self.bzrdir = wt.bzrdir
220
raise errors.BzrError("Please use bzrdir.open_workingtree or "
221
"WorkingTree.open() to obtain a WorkingTree.")
234
222
assert isinstance(basedir, basestring), \
235
223
"base directory %r is not a string" % basedir
236
224
basedir = safe_unicode(basedir)
237
225
mutter("opening working tree %r", basedir)
238
226
if deprecated_passed(branch):
240
warnings.warn("WorkingTree(..., branch=XXX) is deprecated"
241
" as of bzr 0.8. Please use bzrdir.open_workingtree() or"
242
" WorkingTree.open().",
246
227
self._branch = branch
248
229
self._branch = self.bzrdir.open_branch()
545
526
return self.abspath(self.id2path(file_id))
548
def clone(self, to_bzrdir, revision_id=None, basis=None):
529
def clone(self, to_bzrdir, revision_id=None):
549
530
"""Duplicate this working tree into to_bzr, including all state.
551
532
Specifically modified files are kept as modified, but
557
538
If not None, the cloned tree will have its last revision set to
558
539
revision, and and difference between the source trees last revision
559
540
and this one merged in.
562
If not None, a closer copy of a tree which may have some files in
563
common, and which file content should be preferentially copied from.
565
542
# assumes the target bzr dir format is compatible.
566
543
result = self._format.initialize(to_bzrdir)
1418
1395
# prevent race conditions with the lock
1420
1397
[subp for subp in self.extras() if not self.is_ignored(subp)])
1422
1399
@needs_tree_write_lock
1423
1400
def unversion(self, file_ids):
1424
1401
"""Remove the file ids in file_ids from the current versioned set.
2288
2265
self.set_conflicts(un_resolved)
2289
2266
return un_resolved, resolved
2268
def _validate(self):
2269
"""Validate internal structures.
2271
This is meant mostly for the test suite. To give it a chance to detect
2272
corruption after actions have occurred. The default implementation is a
2275
:return: None. An exception should be raised if there is an error.
2292
2280
class WorkingTree2(WorkingTree):
2293
2281
"""This is the Format 2 working tree.
2454
2442
requires_rich_root = False
2444
upgrade_recommended = False
2457
2447
def find_format(klass, a_bzrdir):
2458
2448
"""Return the format for the working tree object in a_bzrdir."""
2507
2497
del klass._formats[format.get_format_string()]
2511
2500
class WorkingTreeFormat2(WorkingTreeFormat):
2512
2501
"""The second working tree format.
2514
2503
This format modified the hash cache from the format 1 hash cache.
2506
upgrade_recommended = True
2517
2508
def get_format_description(self):
2518
2509
"""See WorkingTreeFormat.get_format_description()."""
2519
2510
return "Working tree format 2"
2582
2573
raise NotImplementedError
2583
2574
if not isinstance(a_bzrdir.transport, LocalTransport):
2584
2575
raise errors.NotLocalUrl(a_bzrdir.transport.base)
2585
return WorkingTree2(a_bzrdir.root_transport.local_abspath('.'),
2576
wt = WorkingTree2(a_bzrdir.root_transport.local_abspath('.'),
2586
2577
_internal=True,
2588
2579
_bzrdir=a_bzrdir)
2591
2582
class WorkingTreeFormat3(WorkingTreeFormat):
2592
2583
"""The second working tree format updated to record a format marker.
2689
2682
raise NotImplementedError
2690
2683
if not isinstance(a_bzrdir.transport, LocalTransport):
2691
2684
raise errors.NotLocalUrl(a_bzrdir.transport.base)
2692
return self._open(a_bzrdir, self._open_control_files(a_bzrdir))
2685
wt = self._open(a_bzrdir, self._open_control_files(a_bzrdir))
2694
2688
def _open(self, a_bzrdir, control_files):
2695
2689
"""Open the tree itself.