~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: Robey Pointer
  • Date: 2006-07-01 19:03:33 UTC
  • mfrom: (1829 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1830.
  • Revision ID: robey@lag.net-20060701190333-f58465aec4bd3412
merge from bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
import re
50
50
import stat
51
51
from time import time
 
52
import warnings
52
53
 
53
54
from bzrlib.atomicfile import AtomicFile
54
 
from bzrlib.branch import (Branch,
55
 
                           quotefn)
56
55
from bzrlib.conflicts import Conflict, ConflictList, CONFLICT_SUFFIXES
57
56
import bzrlib.bzrdir as bzrdir
58
57
from bzrlib.decorators import needs_read_lock, needs_write_lock
60
59
from bzrlib.errors import (BzrCheckError,
61
60
                           BzrError,
62
61
                           ConflictFormatError,
63
 
                           DivergedBranches,
64
62
                           WeaveRevisionNotPresent,
65
63
                           NotBranchError,
66
64
                           NoSuchFile,
92
90
from bzrlib.progress import DummyProgress, ProgressPhase
93
91
from bzrlib.revision import NULL_REVISION
94
92
from bzrlib.rio import RioReader, rio_file, Stanza
95
 
from bzrlib.symbol_versioning import *
 
93
from bzrlib.symbol_versioning import (deprecated_passed,
 
94
        deprecated_method,
 
95
        deprecated_function,
 
96
        DEPRECATED_PARAMETER,
 
97
        zero_eight,
 
98
        )
 
99
 
96
100
from bzrlib.textui import show_status
97
101
import bzrlib.tree
98
102
from bzrlib.transform import build_tree
231
235
        self.bzrdir = _bzrdir
232
236
        if not _internal:
233
237
            # not created via open etc.
234
 
            warn("WorkingTree() is deprecated as of bzr version 0.8. "
 
238
            warnings.warn("WorkingTree() is deprecated as of bzr version 0.8. "
235
239
                 "Please use bzrdir.open_workingtree or WorkingTree.open().",
236
240
                 DeprecationWarning,
237
241
                 stacklevel=2)
251
255
        mutter("opening working tree %r", basedir)
252
256
        if deprecated_passed(branch):
253
257
            if not _internal:
254
 
                warn("WorkingTree(..., branch=XXX) is deprecated as of bzr 0.8."
 
258
                warnings.warn("WorkingTree(..., branch=XXX) is deprecated as of bzr 0.8."
255
259
                     " Please use bzrdir.open_workingtree() or"
256
260
                     " WorkingTree.open().",
257
261
                     DeprecationWarning,
260
264
            self._branch = branch
261
265
        else:
262
266
            self._branch = self.bzrdir.open_branch()
263
 
        assert isinstance(self.branch, Branch), \
264
 
            "branch %r is not a Branch" % self.branch
265
267
        self.basedir = realpath(basedir)
266
268
        # if branch is at our basedir and is a format 6 or less
267
269
        if isinstance(self._format, WorkingTreeFormat2):
417
419
        XXX: When BzrDir is present, these should be created through that 
418
420
        interface instead.
419
421
        """
420
 
        warn('delete WorkingTree.create', stacklevel=3)
 
422
        warnings.warn('delete WorkingTree.create', stacklevel=3)
421
423
        transport = get_transport(directory)
422
424
        if branch.bzrdir.root_transport.base == transport.base:
423
425
            # same dir 
609
611
        inv = self.read_working_inventory()
610
612
        for f,file_id in zip(files, ids):
611
613
            if self.is_control_filename(f):
612
 
                raise BzrError("cannot add control file %s" % quotefn(f))
 
614
                raise errors.ForbiddenControlFileError(filename=f)
613
615
 
614
616
            fp = splitpath(f)
615
617
 
617
619
                raise BzrError("cannot add top-level %r" % f)
618
620
 
619
621
            fullpath = normpath(self.abspath(f))
620
 
 
621
622
            try:
622
623
                kind = file_kind(fullpath)
623
624
            except OSError, e:
624
625
                if e.errno == errno.ENOENT:
625
626
                    raise NoSuchFile(fullpath)
626
 
                # maybe something better?
627
 
                raise BzrError('cannot add: not a regular file, symlink or directory: %s' % quotefn(f))
628
 
 
629
627
            if not InventoryEntry.versionable_kind(kind):
630
 
                raise BzrError('cannot add: not a versionable file ('
631
 
                               'i.e. regular file, symlink or directory): %s' % quotefn(f))
632
 
 
 
628
                raise errors.BadFileKindError(filename=f, kind=kind)
633
629
            if file_id is None:
634
630
                inv.add_path(f, kind=kind)
635
631
            else:
660
656
        """
661
657
        try:
662
658
            merges_file = self._control_files.get_utf8('pending-merges')
663
 
        except OSError, e:
664
 
            if e.errno != errno.ENOENT:
665
 
                raise
 
659
        except NoSuchFile:
666
660
            return []
667
661
        p = []
668
662
        for l in merges_file.readlines():
932
926
 
933
927
        These are files in the working directory that are not versioned or
934
928
        control files or ignored.
935
 
        
936
 
        >>> from bzrlib.bzrdir import ScratchDir
937
 
        >>> d = ScratchDir(files=['foo', 'foo~'])
938
 
        >>> b = d.open_branch()
939
 
        >>> tree = d.open_workingtree()
940
 
        >>> map(str, tree.unknowns())
941
 
        ['foo']
942
 
        >>> tree.add('foo')
943
 
        >>> list(b.unknowns())
944
 
        []
945
 
        >>> tree.remove('foo')
946
 
        >>> list(b.unknowns())
947
 
        [u'foo']
948
929
        """
949
930
        for subp in self.extras():
950
931
            if not self.is_ignored(subp):
1285
1266
                # TODO: Perhaps make this just a warning, and continue?
1286
1267
                # This tends to happen when 
1287
1268
                raise NotVersionedError(path=f)
1288
 
            mutter("remove inventory entry %s {%s}", quotefn(f), fid)
1289
1269
            if verbose:
1290
1270
                # having remove it, it must be either ignored or unknown
1291
1271
                if self.is_ignored(f):
1292
1272
                    new_status = 'I'
1293
1273
                else:
1294
1274
                    new_status = '?'
1295
 
                show_status(new_status, inv[fid].kind, quotefn(f), to_file=to_file)
 
1275
                show_status(new_status, inv[fid].kind, f, to_file=to_file)
1296
1276
            del inv[fid]
1297
1277
 
1298
1278
        self._write_inventory(inv)
1586
1566
        except NoSuchFile:
1587
1567
            raise errors.NoWorkingTree(base=transport.base)
1588
1568
        except KeyError:
1589
 
            raise errors.UnknownFormatError(format_string)
 
1569
            raise errors.UnknownFormatError(format=format_string)
1590
1570
 
1591
1571
    @classmethod
1592
1572
    def get_default_format(klass):