27
from bzrlib.branch import Branch
27
from bzrlib.branch import Branch, needs_read_lock, needs_write_lock, quotefn
29
29
from bzrlib.osutils import appendpath, file_kind, isdir, splitpath, relpath
30
from bzrlib.errors import BzrCheckError
30
from bzrlib.errors import BzrCheckError, DivergedBranches
31
31
from bzrlib.trace import mutter
33
33
class TreeEntry(object):
94
94
It is possible for a `WorkingTree` to have a filename which is
95
95
not listed in the Inventory and vice versa.
97
98
def __init__(self, basedir, branch=None):
98
99
"""Construct a WorkingTree for basedir.
304
305
conflicted.add(stem)
309
def pull(self, source, remember=False, clobber=False):
310
from bzrlib.merge import merge
313
old_revno = self.branch.revno()
314
old_revision_history = self.branch.revision_history()
316
self.branch.update_revisions(source)
317
except DivergedBranches:
320
self.branch.set_revision_history(source.revision_history())
321
new_revision_history = self.branch.revision_history()
322
if new_revision_history != old_revision_history:
323
merge((self.basedir, -1), (self.basedir, old_revno), check_clean=False)
324
if self.branch.get_parent() is None or remember:
325
self.branch.set_parent(source.base)
307
329
def extras(self):
308
330
"""Yield all unknown files in this WorkingTree.
398
420
def kind(self, file_id):
399
421
return file_kind(self.id2abspath(file_id))
424
"""See Branch.lock_read, and WorkingTree.unlock."""
425
return self.branch.lock_read()
427
def lock_write(self):
428
"""See Branch.lock_write, and WorkingTree.unlock."""
429
return self.branch.lock_write()
432
def remove(self, files, verbose=False):
433
"""Remove nominated files from the working inventory..
435
This does not remove their text. This does not run on XXX on what? RBC
437
TODO: Refuse to remove modified files unless --force is given?
439
TODO: Do something useful with directories.
441
TODO: Should this remove the text or not? Tough call; not
442
removing may be useful and the user can just use use rm, and
443
is the opposite of add. Removing it is consistent with most
444
other tools. Maybe an option.
446
## TODO: Normalize names
447
## TODO: Remove nested loops; better scalability
448
if isinstance(files, basestring):
453
# do this before any modifications
457
raise BzrError("cannot remove unversioned file %s" % quotefn(f))
458
mutter("remove inventory entry %s {%s}" % (quotefn(f), fid))
460
# having remove it, it must be either ignored or unknown
461
if self.is_ignored(f):
465
show_status(new_status, inv[fid].kind, quotefn(f))
468
self.branch._write_inventory(inv)
471
"""See Branch.unlock.
473
WorkingTree locking just uses the Branch locking facilities.
474
This is current because all working trees have an embedded branch
475
within them. IF in the future, we were to make branch data shareable
476
between multiple working trees, i.e. via shared storage, then we
477
would probably want to lock both the local tree, and the branch.
479
return self.branch.unlock()
401
482
CONFLICT_SUFFIXES = ('.THIS', '.BASE', '.OTHER')
402
483
def get_conflicted_stem(path):
403
484
for suffix in CONFLICT_SUFFIXES: