~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: Aaron Bentley
  • Date: 2005-10-18 20:19:44 UTC
  • mfrom: (1463) (0.2.1)
  • mto: (1185.25.1)
  • mto: This revision was merged to the branch mainline in revision 1474.
  • Revision ID: abentley@panoramicfeedback.com-20051018201944-42864e79d8e9ad29
Merged more from Robert

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
import stat
25
25
import fnmatch
26
26
 
27
 
from bzrlib.branch import Branch
 
27
from bzrlib.branch import Branch, needs_read_lock, needs_write_lock, quotefn
28
28
import bzrlib.tree
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
32
32
 
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.
96
96
    """
 
97
 
97
98
    def __init__(self, basedir, branch=None):
98
99
        """Construct a WorkingTree for basedir.
99
100
 
304
305
                conflicted.add(stem)
305
306
                yield stem
306
307
 
 
308
    @needs_write_lock
 
309
    def pull(self, source, remember=False, clobber=False):
 
310
        from bzrlib.merge import merge
 
311
        source.lock_read()
 
312
        try:
 
313
            old_revno = self.branch.revno()
 
314
            old_revision_history = self.branch.revision_history()
 
315
            try:
 
316
                self.branch.update_revisions(source)
 
317
            except DivergedBranches:
 
318
                if not clobber:
 
319
                    raise
 
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)
 
326
        finally:
 
327
            source.unlock()
 
328
 
307
329
    def extras(self):
308
330
        """Yield all unknown files in this WorkingTree.
309
331
 
398
420
    def kind(self, file_id):
399
421
        return file_kind(self.id2abspath(file_id))
400
422
 
 
423
    def lock_read(self):
 
424
        """See Branch.lock_read, and WorkingTree.unlock."""
 
425
        return self.branch.lock_read()
 
426
 
 
427
    def lock_write(self):
 
428
        """See Branch.lock_write, and WorkingTree.unlock."""
 
429
        return self.branch.lock_write()
 
430
 
 
431
    @needs_write_lock
 
432
    def remove(self, files, verbose=False):
 
433
        """Remove nominated files from the working inventory..
 
434
 
 
435
        This does not remove their text.  This does not run on XXX on what? RBC
 
436
 
 
437
        TODO: Refuse to remove modified files unless --force is given?
 
438
 
 
439
        TODO: Do something useful with directories.
 
440
 
 
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.
 
445
        """
 
446
        ## TODO: Normalize names
 
447
        ## TODO: Remove nested loops; better scalability
 
448
        if isinstance(files, basestring):
 
449
            files = [files]
 
450
 
 
451
        inv = self.inventory
 
452
 
 
453
        # do this before any modifications
 
454
        for f in files:
 
455
            fid = inv.path2id(f)
 
456
            if not fid:
 
457
                raise BzrError("cannot remove unversioned file %s" % quotefn(f))
 
458
            mutter("remove inventory entry %s {%s}" % (quotefn(f), fid))
 
459
            if verbose:
 
460
                # having remove it, it must be either ignored or unknown
 
461
                if self.is_ignored(f):
 
462
                    new_status = 'I'
 
463
                else:
 
464
                    new_status = '?'
 
465
                show_status(new_status, inv[fid].kind, quotefn(f))
 
466
            del inv[fid]
 
467
 
 
468
        self.branch._write_inventory(inv)
 
469
 
 
470
    def unlock(self):
 
471
        """See Branch.unlock.
 
472
        
 
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.
 
478
        """
 
479
        return self.branch.unlock()
 
480
 
 
481
 
401
482
CONFLICT_SUFFIXES = ('.THIS', '.BASE', '.OTHER')
402
483
def get_conflicted_stem(path):
403
484
    for suffix in CONFLICT_SUFFIXES: