/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5630.2.2 by John Arbash Meinel
Start fleshing out the design. Something weird is causing my tests to all fail.
1
# Copyright (C) 2005-2011 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
453 by Martin Pool
- Split WorkingTree into its own file
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
7
#
453 by Martin Pool
- Split WorkingTree into its own file
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
12
#
453 by Martin Pool
- Split WorkingTree into its own file
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
453 by Martin Pool
- Split WorkingTree into its own file
16
1185.16.72 by Martin Pool
[merge] from robert and fix up tests
17
"""WorkingTree object and friends.
18
19
A WorkingTree represents the editable working copy of a branch.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
20
Operations which represent the WorkingTree are also done here,
6672.2.6 by Jelmer Vernooij
Some cleanups.
21
such as renaming or adding files.
1185.16.72 by Martin Pool
[merge] from robert and fix up tests
22
23
At the moment every WorkingTree has its own branch.  Remote
24
WorkingTrees aren't supported.
25
6681.2.4 by Jelmer Vernooij
More renames.
26
To get a WorkingTree, call controldir.open_workingtree() or
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
27
WorkingTree.open(dir).
1185.16.72 by Martin Pool
[merge] from robert and fix up tests
28
"""
29
6379.6.7 by Jelmer Vernooij
Move importing from future until after doc string, otherwise the doc string will disappear.
30
from __future__ import absolute_import
956 by Martin Pool
doc
31
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
32
import errno
1996.3.6 by John Arbash Meinel
Find a few places that weren't importing their dependencies.
33
import os
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
34
import re
2423.2.1 by Alexander Belchenko
Fix for walkdirs in missing dir with Py2.4 @ win32
35
import sys
1996.3.6 by John Arbash Meinel
Find a few places that weren't importing their dependencies.
36
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
37
import breezy
38
39
from .lazy_import import lazy_import
1996.3.6 by John Arbash Meinel
Find a few places that weren't importing their dependencies.
40
lazy_import(globals(), """
1852.15.7 by Robert Collins
Start testing behaviour of unknowns in WorkingTree.walkdirs.
41
from bisect import bisect_left
42
import itertools
43
import operator
1398 by Robert Collins
integrate in Gustavos x-bit patch
44
import stat
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
45
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
46
from breezy import (
1731.2.17 by Aaron Bentley
Support extracting with checkouts
47
    branch,
1996.3.6 by John Arbash Meinel
Find a few places that weren't importing their dependencies.
48
    conflicts as _mod_conflicts,
5363.2.10 by Jelmer Vernooij
base ControlDir on ControlComponent.
49
    controldir,
1996.3.6 by John Arbash Meinel
Find a few places that weren't importing their dependencies.
50
    errors,
5745.3.2 by Jelmer Vernooij
Add filters to import tariff blacklist.
51
    filters as _mod_filters,
2116.4.1 by John Arbash Meinel
Update file and revision id generators.
52
    generate_ids,
2135.2.7 by Kent Gibson
Implement JAM's review suggestions.
53
    globbing,
1996.3.6 by John Arbash Meinel
Find a few places that weren't importing their dependencies.
54
    ignores,
55
    merge,
2598.5.1 by Aaron Bentley
Start eliminating the use of None to indicate null revision
56
    revision as _mod_revision,
6538.1.5 by Aaron Bentley
Implement WorkingTree.store_uncommitted.
57
    shelf,
1996.3.6 by John Arbash Meinel
Find a few places that weren't importing their dependencies.
58
    transform,
6653.3.9 by Jelmer Vernooij
Missing import.
59
    transport,
2323.6.2 by Martin Pool
Move responsibility for suggesting upgrades to ui object
60
    ui,
3586.1.3 by Ian Clatworthy
add views attribute to working trees
61
    views,
1731.2.17 by Aaron Bentley
Support extracting with checkouts
62
    )
1996.3.6 by John Arbash Meinel
Find a few places that weren't importing their dependencies.
63
""")
64
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
65
from . import (
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
66
    osutils,
6213.1.35 by Jelmer Vernooij
Simplify importing of bzrdir.
67
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
68
from .decorators import needs_read_lock, needs_write_lock
69
from .i18n import gettext
70
from . import mutabletree
71
from .mutabletree import needs_tree_write_lock
72
from .trace import mutter, note
1996.3.6 by John Arbash Meinel
Find a few places that weren't importing their dependencies.
73
74
2423.2.1 by Alexander Belchenko
Fix for walkdirs in missing dir with Py2.4 @ win32
75
ERROR_PATH_NOT_FOUND = 3    # WindowsError errno code, equivalent to ENOENT
76
2116.4.1 by John Arbash Meinel
Update file and revision id generators.
77
1399.1.2 by Robert Collins
push kind character creation into InventoryEntry and TreeEntry
78
class TreeEntry(object):
1759.2.1 by Jelmer Vernooij
Fix some types (found using aspell).
79
    """An entry that implements the minimum interface used by commands.
1399.1.2 by Robert Collins
push kind character creation into InventoryEntry and TreeEntry
80
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
81
    This needs further inspection, it may be better to have
1399.1.2 by Robert Collins
push kind character creation into InventoryEntry and TreeEntry
82
    InventoryEntries without ids - though that seems wrong. For now,
83
    this is a parallel hierarchy to InventoryEntry, and needs to become
84
    one of several things: decorates to that hierarchy, children of, or
85
    parents of it.
1399.1.3 by Robert Collins
move change detection for text and metadata from delta to entry.detect_changes
86
    Another note is that these objects are currently only used when there is
87
    no InventoryEntry available - i.e. for unversioned objects.
88
    Perhaps they should be UnversionedEntry et al. ? - RBC 20051003
1399.1.2 by Robert Collins
push kind character creation into InventoryEntry and TreeEntry
89
    """
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
90
1399.1.2 by Robert Collins
push kind character creation into InventoryEntry and TreeEntry
91
    def __eq__(self, other):
92
        # yes, this us ugly, TODO: best practice __eq__ style.
93
        return (isinstance(other, TreeEntry)
94
                and other.__class__ == self.__class__)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
95
1399.1.2 by Robert Collins
push kind character creation into InventoryEntry and TreeEntry
96
    def kind_character(self):
97
        return "???"
98
99
100
class TreeDirectory(TreeEntry):
101
    """See TreeEntry. This is a directory in a working tree."""
102
103
    def __eq__(self, other):
104
        return (isinstance(other, TreeDirectory)
105
                and other.__class__ == self.__class__)
106
107
    def kind_character(self):
108
        return "/"
109
110
111
class TreeFile(TreeEntry):
112
    """See TreeEntry. This is a regular file in a working tree."""
113
114
    def __eq__(self, other):
115
        return (isinstance(other, TreeFile)
116
                and other.__class__ == self.__class__)
117
118
    def kind_character(self):
119
        return ''
120
121
122
class TreeLink(TreeEntry):
123
    """See TreeEntry. This is a symlink in a working tree."""
124
125
    def __eq__(self, other):
126
        return (isinstance(other, TreeLink)
127
                and other.__class__ == self.__class__)
128
129
    def kind_character(self):
130
        return ''
131
132
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
133
class WorkingTree(mutabletree.MutableTree,
5363.2.10 by Jelmer Vernooij
base ControlDir on ControlComponent.
134
    controldir.ControlComponent):
453 by Martin Pool
- Split WorkingTree into its own file
135
    """Working copy tree.
136
5335.1.2 by Robert Collins
Add note that basedir is a unicode object as per John's review.
137
    :ivar basedir: The root of the tree on disk. This is a unicode path object
138
        (as opposed to a URL).
453 by Martin Pool
- Split WorkingTree into its own file
139
    """
1442.1.65 by Robert Collins
Branch.remove has been moved to WorkingTree.
140
3586.1.3 by Ian Clatworthy
add views attribute to working trees
141
    # override this to set the strategy for storing views
142
    def _make_views(self):
143
        return views.DisabledViews(self)
144
1534.4.51 by Robert Collins
Test the disk layout of format3 working trees.
145
    def __init__(self, basedir='.',
6630.1.1 by Jelmer Vernooij
Remove deprecated functionality.
146
                 branch=None,
1534.4.51 by Robert Collins
Test the disk layout of format3 working trees.
147
                 _internal=False,
6313.1.1 by Jelmer Vernooij
Move bzr-specific functionality to InventoryWorkingTree.
148
                 _transport=None,
1534.4.51 by Robert Collins
Test the disk layout of format3 working trees.
149
                 _format=None,
6681.2.4 by Jelmer Vernooij
More renames.
150
                 _controldir=None):
2367.2.1 by Robert Collins
Remove bzrlib 0.8 compatability where it was making the code unclear or messy. (Robert Collins)
151
        """Construct a WorkingTree instance. This is not a public API.
1457.1.1 by Robert Collins
rather than getting the branch inventory, WorkingTree can use the whole Branch, or make its own.
152
2367.2.1 by Robert Collins
Remove bzrlib 0.8 compatability where it was making the code unclear or messy. (Robert Collins)
153
        :param branch: A branch to override probing for the branch.
1457.1.1 by Robert Collins
rather than getting the branch inventory, WorkingTree can use the whole Branch, or make its own.
154
        """
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
155
        self._format = _format
6681.2.4 by Jelmer Vernooij
More renames.
156
        self.controldir = _controldir
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
157
        if not _internal:
6681.2.4 by Jelmer Vernooij
More renames.
158
            raise errors.BzrError("Please use controldir.open_workingtree or "
2367.2.1 by Robert Collins
Remove bzrlib 0.8 compatability where it was making the code unclear or messy. (Robert Collins)
159
                "WorkingTree.open() to obtain a WorkingTree.")
6653.3.1 by Jelmer Vernooij
Move bzr-specific code to breezy.bzrworkingtree.
160
        basedir = osutils.safe_unicode(basedir)
1534.5.3 by Robert Collins
Make format 4/5/6 branches share a single LockableFiles instance across wt/branch/repository.
161
        mutter("opening working tree %r", basedir)
6630.1.1 by Jelmer Vernooij
Remove deprecated functionality.
162
        if branch is not None:
6313.1.4 by Jelmer Vernooij
Fix tests.
163
            self._branch = branch
164
        else:
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
165
            self._branch = self.controldir.open_branch()
6653.3.1 by Jelmer Vernooij
Move bzr-specific code to breezy.bzrworkingtree.
166
        self.basedir = osutils.realpath(basedir)
6313.1.1 by Jelmer Vernooij
Move bzr-specific functionality to InventoryWorkingTree.
167
        self._transport = _transport
3398.1.24 by Ian Clatworthy
make iter_search_rules a tree method
168
        self._rules_searcher = None
3586.1.3 by Ian Clatworthy
add views attribute to working trees
169
        self.views = self._make_views()
3034.4.3 by Aaron Bentley
Add case-sensitivity handling to WorkingTree
170
5158.6.5 by Martin Pool
Implement ControlComponent on WorkingTree
171
    @property
172
    def user_transport(self):
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
173
        return self.controldir.user_transport
5158.6.5 by Martin Pool
Implement ControlComponent on WorkingTree
174
175
    @property
176
    def control_transport(self):
177
        return self._transport
178
5699.2.1 by Jelmer Vernooij
Move is_control_filename() from Tree to MutableTree.
179
    def is_control_filename(self, filename):
180
        """True if filename is the name of a control file in this tree.
181
182
        :param filename: A filename within the tree. This is a relative path
5891.1.2 by Andrew Bennetts
Fix a bunch of docstring formatting nits, making pydoctor a bit happier.
183
            from the root of this tree.
5699.2.1 by Jelmer Vernooij
Move is_control_filename() from Tree to MutableTree.
184
185
        This is true IF and ONLY IF the filename is part of the meta data
186
        that bzr controls in this tree. I.E. a random .bzr directory placed
187
        on disk will not be a control file for this tree.
188
        """
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
189
        return self.controldir.is_control_filename(filename)
5699.2.1 by Jelmer Vernooij
Move is_control_filename() from Tree to MutableTree.
190
1681.1.1 by Robert Collins
Make WorkingTree.branch a read only property. (Robert Collins)
191
    branch = property(
192
        fget=lambda self: self._branch,
193
        doc="""The branch this WorkingTree is connected to.
194
195
            This cannot be set - it is reflective of the actual disk structure
196
            the working tree has been constructed from.
197
            """)
198
6110.6.1 by Jelmer Vernooij
Add Tree.has_versioned_directories.
199
    def has_versioned_directories(self):
200
        """See `Tree.has_versioned_directories`."""
201
        return self._format.supports_versioned_directories
202
6379.7.2 by Jelmer Vernooij
Deprecate supports_executable, move check to working tree.
203
    def _supports_executable(self):
204
        if sys.platform == 'win32':
205
            return False
206
        # FIXME: Ideally this should check the file system
207
        return True
208
1687.1.9 by Robert Collins
Teach WorkingTree about break-lock.
209
    def break_lock(self):
210
        """Break a lock if one is present from another instance.
211
212
        Uses the ui factory to ask for confirmation if the lock may be from
213
        an active process.
214
215
        This will probe the repository for its lock as well.
216
        """
6313.1.1 by Jelmer Vernooij
Move bzr-specific functionality to InventoryWorkingTree.
217
        raise NotImplementedError(self.break_lock)
1687.1.9 by Robert Collins
Teach WorkingTree about break-lock.
218
2100.3.14 by Aaron Bentley
Test workingtree4 format, prevent use with old repos
219
    def requires_rich_root(self):
220
        return self._format.requires_rich_root
221
2100.3.20 by Aaron Bentley
Implement tree comparison for tree references
222
    def supports_tree_reference(self):
2255.2.232 by Robert Collins
Make WorkingTree4 report support for references based on the repositories capabilities.
223
        return False
2100.3.20 by Aaron Bentley
Implement tree comparison for tree references
224
3907.2.1 by Ian Clatworthy
WorkingTreeFormat5 supporting content filtering and views
225
    def supports_content_filtering(self):
226
        return self._format.supports_content_filtering()
227
3586.1.3 by Ian Clatworthy
add views attribute to working trees
228
    def supports_views(self):
229
        return self.views.supports_views()
230
6449.4.1 by Jelmer Vernooij
Add convenience method WorkingTree.get_config_stack().
231
    def get_config_stack(self):
6449.4.5 by Jelmer Vernooij
Review feedback from vila.
232
        """Retrieve the config stack for this tree.
233
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
234
        :return: A ``breezy.config.Stack``
6449.4.5 by Jelmer Vernooij
Review feedback from vila.
235
        """
236
        # For the moment, just provide the branch config stack.
6449.4.1 by Jelmer Vernooij
Add convenience method WorkingTree.get_config_stack().
237
        return self.branch.get_config_stack()
238
1508.1.1 by Robert Collins
Provide a open_containing for WorkingTree.
239
    @staticmethod
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
240
    def open(path=None, _unsupported=False):
241
        """Open an existing working tree at path.
242
243
        """
244
        if path is None:
3753.1.1 by John Arbash Meinel
Add some simple direct tests for WT.open and WT.open_containing.
245
            path = osutils.getcwd()
6402.3.3 by Jelmer Vernooij
Simplify safe open a bit more.
246
        control = controldir.ControlDir.open(path, _unsupported=_unsupported)
6402.1.1 by Jelmer Vernooij
Simplify probing.
247
        return control.open_workingtree(unsupported=_unsupported)
3753.1.1 by John Arbash Meinel
Add some simple direct tests for WT.open and WT.open_containing.
248
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
249
    @staticmethod
1508.1.1 by Robert Collins
Provide a open_containing for WorkingTree.
250
    def open_containing(path=None):
251
        """Open an existing working tree which has its root about path.
3753.1.1 by John Arbash Meinel
Add some simple direct tests for WT.open and WT.open_containing.
252
1508.1.1 by Robert Collins
Provide a open_containing for WorkingTree.
253
        This probes for a working tree at path and searches upwards from there.
254
255
        Basically we keep looking up until we find the control directory or
256
        run into /.  If there isn't one, raises NotBranchError.
257
        TODO: give this a new exception.
258
        If there is one, it is returned, along with the unused portion of path.
1685.1.27 by John Arbash Meinel
BzrDir works in URLs, but WorkingTree works in unicode paths
259
260
        :return: The WorkingTree that contains 'path', and the rest of path
1508.1.1 by Robert Collins
Provide a open_containing for WorkingTree.
261
        """
262
        if path is None:
1830.3.14 by John Arbash Meinel
WorkingTree.open_containing() was directly calling os.getcwdu(), which on mac returns the wrong normalization, and on win32 would have the wrong slashes
263
            path = osutils.getcwd()
6207.3.3 by jelmer at samba
Fix tests and the like.
264
        control, relpath = controldir.ControlDir.open_containing(path)
1685.1.28 by John Arbash Meinel
Changing open_containing to always return a unicode path.
265
        return control.open_workingtree(), relpath
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
266
267
    @staticmethod
5521.1.1 by Vincent Ladeuil
Handle --directory when paths are also provided to shelve and restore.
268
    def open_containing_paths(file_list, default_directory=None,
269
                              canonicalize=True, apply_view=True):
5346.4.2 by Martin Pool
Move internal_tree_files and safe_relpath_files onto WorkingTree
270
        """Open the WorkingTree that contains a set of paths.
271
272
        Fail if the paths given are not all in a single tree.
273
274
        This is used for the many command-line interfaces that take a list of
275
        any number of files and that require they all be in the same tree.
276
        """
5521.1.1 by Vincent Ladeuil
Handle --directory when paths are also provided to shelve and restore.
277
        if default_directory is None:
278
            default_directory = u'.'
5346.4.2 by Martin Pool
Move internal_tree_files and safe_relpath_files onto WorkingTree
279
        # recommended replacement for builtins.internal_tree_files
280
        if file_list is None or len(file_list) == 0:
281
            tree = WorkingTree.open_containing(default_directory)[0]
5346.4.5 by Martin Pool
Deprecate and avoid internal_tree_files and tree_files.
282
            # XXX: doesn't really belong here, and seems to have the strange
283
            # side effect of making it return a bunch of files, not the whole
284
            # tree -- mbp 20100716
5346.4.2 by Martin Pool
Move internal_tree_files and safe_relpath_files onto WorkingTree
285
            if tree.supports_views() and apply_view:
286
                view_files = tree.views.lookup_view()
287
                if view_files:
288
                    file_list = view_files
289
                    view_str = views.view_display_str(view_files)
6138.3.4 by Jonathan Riddell
add gettext() to uses of trace.note()
290
                    note(gettext("Ignoring files outside view. View is %s") % view_str)
5346.4.2 by Martin Pool
Move internal_tree_files and safe_relpath_files onto WorkingTree
291
            return tree, file_list
5521.1.1 by Vincent Ladeuil
Handle --directory when paths are also provided to shelve and restore.
292
        if default_directory == u'.':
293
            seed = file_list[0]
294
        else:
295
            seed = default_directory
296
            file_list = [osutils.pathjoin(default_directory, f)
297
                         for f in file_list]
298
        tree = WorkingTree.open_containing(seed)[0]
5346.4.2 by Martin Pool
Move internal_tree_files and safe_relpath_files onto WorkingTree
299
        return tree, tree.safe_relpath_files(file_list, canonicalize,
5521.1.1 by Vincent Ladeuil
Handle --directory when paths are also provided to shelve and restore.
300
                                             apply_view=apply_view)
5346.4.2 by Martin Pool
Move internal_tree_files and safe_relpath_files onto WorkingTree
301
302
    def safe_relpath_files(self, file_list, canonicalize=True, apply_view=True):
303
        """Convert file_list into a list of relpaths in tree.
304
305
        :param self: A tree to operate on.
306
        :param file_list: A list of user provided paths or None.
307
        :param apply_view: if True and a view is set, apply it or check that
308
            specified files are within it
309
        :return: A list of relative paths.
310
        :raises errors.PathNotChild: When a provided path is in a different self
311
            than self.
312
        """
313
        if file_list is None:
314
            return None
315
        if self.supports_views() and apply_view:
316
            view_files = self.views.lookup_view()
317
        else:
318
            view_files = []
319
        new_list = []
320
        # self.relpath exists as a "thunk" to osutils, but canonical_relpath
321
        # doesn't - fix that up here before we enter the loop.
322
        if canonicalize:
323
            fixer = lambda p: osutils.canonical_relpath(self.basedir, p)
324
        else:
325
            fixer = self.relpath
326
        for filename in file_list:
5346.4.3 by Martin Pool
PathNotChild should not give a traceback.
327
            relpath = fixer(osutils.dereference_path(filename))
328
            if view_files and not osutils.is_inside_any(view_files, relpath):
329
                raise errors.FileOutsideView(filename, view_files)
330
            new_list.append(relpath)
5346.4.2 by Martin Pool
Move internal_tree_files and safe_relpath_files onto WorkingTree
331
        return new_list
332
333
    @staticmethod
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
334
    def open_downlevel(path=None):
335
        """Open an unsupported working tree.
336
6681.2.4 by Jelmer Vernooij
More renames.
337
        Only intended for advanced situations like upgrading part of a controldir.
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
338
        """
339
        return WorkingTree.open(path, _unsupported=True)
1508.1.1 by Robert Collins
Provide a open_containing for WorkingTree.
340
3140.1.4 by Aaron Bentley
Add WorkingTree.find_trees
341
    @staticmethod
342
    def find_trees(location):
343
        def list_current(transport):
6681.2.4 by Jelmer Vernooij
More renames.
344
            return [d for d in transport.list_dir('')
345
                    if not controldir.is_control_filename(d)]
346
        def evaluate(controldir):
3140.1.4 by Aaron Bentley
Add WorkingTree.find_trees
347
            try:
6681.2.4 by Jelmer Vernooij
More renames.
348
                tree = controldir.open_workingtree()
3140.1.4 by Aaron Bentley
Add WorkingTree.find_trees
349
            except errors.NoWorkingTree:
350
                return True, None
351
            else:
352
                return True, tree
5273.1.7 by Vincent Ladeuil
No more use of the get_transport imported *symbol*, all uses are through
353
        t = transport.get_transport(location)
6681.2.3 by Jelmer Vernooij
Rename find_bzrdir.
354
        iterator = controldir.ControlDir.find_controldirs(t, evaluate=evaluate,
3140.1.4 by Aaron Bentley
Add WorkingTree.find_trees
355
                                              list_current=list_current)
5273.1.7 by Vincent Ladeuil
No more use of the get_transport imported *symbol*, all uses are through
356
        return [tr for tr in iterator if tr is not None]
3140.1.4 by Aaron Bentley
Add WorkingTree.find_trees
357
453 by Martin Pool
- Split WorkingTree into its own file
358
    def __repr__(self):
359
        return "<%s of %s>" % (self.__class__.__name__,
954 by Martin Pool
- separate out code that just scans the hash cache to find files that are possibly
360
                               getattr(self, 'basedir', None))
453 by Martin Pool
- Split WorkingTree into its own file
361
362
    def abspath(self, filename):
6653.3.1 by Jelmer Vernooij
Move bzr-specific code to breezy.bzrworkingtree.
363
        return osutils.pathjoin(self.basedir, filename)
2292.1.30 by Marius Kruger
* Minor text fixes.
364
1534.4.35 by Robert Collins
Give branch its own basis tree and last_revision methods; deprecated branch.working_tree()
365
    def basis_tree(self):
1927.2.3 by Robert Collins
review comment application - paired with Martin.
366
        """Return RevisionTree for the current last revision.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
367
1927.2.3 by Robert Collins
review comment application - paired with Martin.
368
        If the left most parent is a ghost then the returned tree will be an
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
369
        empty tree - one obtained by calling
3668.5.1 by Jelmer Vernooij
Use NULL_REVISION rather than None for Repository.revision_tree().
370
        repository.revision_tree(NULL_REVISION).
1927.2.3 by Robert Collins
review comment application - paired with Martin.
371
        """
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
372
        try:
373
            revision_id = self.get_parent_ids()[0]
374
        except IndexError:
375
            # no parents, return an empty revision tree.
376
            # in the future this should return the tree for
377
            # 'empty:' - the implicit root empty tree.
3668.5.1 by Jelmer Vernooij
Use NULL_REVISION rather than None for Repository.revision_tree().
378
            return self.branch.repository.revision_tree(
379
                       _mod_revision.NULL_REVISION)
1908.11.2 by Robert Collins
Implement WorkingTree interface conformance tests for
380
        try:
381
            return self.revision_tree(revision_id)
382
        except errors.NoSuchRevision:
383
            pass
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
384
        # No cached copy available, retrieve from the repository.
385
        # FIXME? RBC 20060403 should we cache the inventory locally
386
        # at this point ?
1927.2.1 by Robert Collins
Alter set_pending_merges to shove the left most merge into the trees last-revision if that is not set. Related bugfixes include basis_tree handling ghosts, de-duping the merges with the last-revision and update changing where and how it adds its pending merge.
387
        try:
388
            return self.branch.repository.revision_tree(revision_id)
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
389
        except (errors.RevisionNotPresent, errors.NoSuchRevision):
1927.2.1 by Robert Collins
Alter set_pending_merges to shove the left most merge into the trees last-revision if that is not set. Related bugfixes include basis_tree handling ghosts, de-duping the merges with the last-revision and update changing where and how it adds its pending merge.
390
            # the basis tree *may* be a ghost or a low level error may have
4031.3.1 by Frank Aspell
Fixing various typos
391
            # occurred. If the revision is present, its a problem, if its not
1927.2.1 by Robert Collins
Alter set_pending_merges to shove the left most merge into the trees last-revision if that is not set. Related bugfixes include basis_tree handling ghosts, de-duping the merges with the last-revision and update changing where and how it adds its pending merge.
392
            # its a ghost.
393
            if self.branch.repository.has_revision(revision_id):
394
                raise
1927.2.3 by Robert Collins
review comment application - paired with Martin.
395
            # the basis tree is a ghost so return an empty tree.
3668.5.1 by Jelmer Vernooij
Use NULL_REVISION rather than None for Repository.revision_tree().
396
            return self.branch.repository.revision_tree(
397
                       _mod_revision.NULL_REVISION)
453 by Martin Pool
- Split WorkingTree into its own file
398
2665.3.2 by Daniel Watkins
Created _cleanup() method in WorkingTree.
399
    def _cleanup(self):
400
        self._flush_ignore_list_cache()
401
1713.1.9 by Robert Collins
Paired performance tuning of bzr add. (Robert Collins, Martin Pool).
402
    def relpath(self, path):
403
        """Return the local path portion from a given path.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
404
405
        The path may be absolute or relative. If its a relative path it is
1713.1.9 by Robert Collins
Paired performance tuning of bzr add. (Robert Collins, Martin Pool).
406
        interpreted relative to the python current working directory.
407
        """
1996.3.6 by John Arbash Meinel
Find a few places that weren't importing their dependencies.
408
        return osutils.relpath(self.basedir, path)
1457.1.3 by Robert Collins
make Branch.relpath delegate to the working tree.
409
453 by Martin Pool
- Split WorkingTree into its own file
410
    def has_filename(self, filename):
1836.1.22 by John Arbash Meinel
[merge] bzr.dev 1861
411
        return osutils.lexists(self.abspath(filename))
453 by Martin Pool
- Split WorkingTree into its own file
412
3368.2.11 by Ian Clatworthy
add filtered option to get_file and get_file_byname in workingtree.py
413
    def get_file(self, file_id, path=None, filtered=True):
3368.2.45 by Ian Clatworthy
add and use supports_content_filtering API
414
        return self.get_file_with_stat(file_id, path, filtered=filtered)[0]
3709.3.2 by Robert Collins
Race-free stat-fingerprint updating during commit via a new method get_file_with_stat.
415
3368.2.45 by Ian Clatworthy
add and use supports_content_filtering API
416
    def get_file_with_stat(self, file_id, path=None, filtered=True,
5609.29.5 by John Arbash Meinel
Fix bug #740932. Transform should update the sha cache.
417
                           _fstat=osutils.fstat):
4354.4.7 by Aaron Bentley
Move MutableTree.get_file_with_stat to Tree.get_file_with_stat.
418
        """See Tree.get_file_with_stat."""
2743.3.3 by Ian Clatworthy
Skip path lookup for tree.get_file() when we already know the path
419
        if path is None:
420
            path = self.id2path(file_id)
3368.2.41 by Ian Clatworthy
1st cut merge of bzr.dev r3907
421
        file_obj = self.get_file_byname(path, filtered=False)
3368.2.45 by Ian Clatworthy
add and use supports_content_filtering API
422
        stat_value = _fstat(file_obj.fileno())
4413.4.3 by John Arbash Meinel
Move the boolean check to the first part of the if statement
423
        if filtered and self.supports_content_filtering():
3368.2.46 by Ian Clatworthy
minor fix
424
            filters = self._content_filter_stack(path)
5745.3.2 by Jelmer Vernooij
Add filters to import tariff blacklist.
425
            file_obj = _mod_filters.filtered_input_file(file_obj, filters)
3368.2.45 by Ian Clatworthy
add and use supports_content_filtering API
426
        return (file_obj, stat_value)
453 by Martin Pool
- Split WorkingTree into its own file
427
3368.2.41 by Ian Clatworthy
1st cut merge of bzr.dev r3907
428
    def get_file_text(self, file_id, path=None, filtered=True):
5236.1.1 by Tim Penhey
Close the file after read.
429
        my_file = self.get_file(file_id, path=path, filtered=filtered)
4708.2.1 by Martin
Ensure all files opened by bazaar proper are explicitly closed
430
        try:
5236.1.1 by Tim Penhey
Close the file after read.
431
            return my_file.read()
4708.2.1 by Martin
Ensure all files opened by bazaar proper are explicitly closed
432
        finally:
5236.1.1 by Tim Penhey
Close the file after read.
433
            my_file.close()
1852.6.9 by Robert Collins
Add more test trees to the tree-implementations tests.
434
3368.2.11 by Ian Clatworthy
add filtered option to get_file and get_file_byname in workingtree.py
435
    def get_file_byname(self, filename, filtered=True):
3368.2.1 by Ian Clatworthy
first cut at working tree content filtering
436
        path = self.abspath(filename)
3368.2.11 by Ian Clatworthy
add filtered option to get_file and get_file_byname in workingtree.py
437
        f = file(path, 'rb')
4413.4.3 by John Arbash Meinel
Move the boolean check to the first part of the if statement
438
        if filtered and self.supports_content_filtering():
3368.2.11 by Ian Clatworthy
add filtered option to get_file and get_file_byname in workingtree.py
439
            filters = self._content_filter_stack(filename)
5745.3.2 by Jelmer Vernooij
Add filters to import tariff blacklist.
440
            return _mod_filters.filtered_input_file(f, filters)
3368.2.11 by Ian Clatworthy
add filtered option to get_file and get_file_byname in workingtree.py
441
        else:
442
            return f
453 by Martin Pool
- Split WorkingTree into its own file
443
3368.2.45 by Ian Clatworthy
add and use supports_content_filtering API
444
    def get_file_lines(self, file_id, path=None, filtered=True):
3774.1.4 by Aaron Bentley
Use file.readlines on working trees.
445
        """See Tree.get_file_lines()"""
3368.2.45 by Ian Clatworthy
add and use supports_content_filtering API
446
        file = self.get_file(file_id, path, filtered=filtered)
3774.1.4 by Aaron Bentley
Use file.readlines on working trees.
447
        try:
448
            return file.readlines()
449
        finally:
450
            file.close()
451
1773.2.1 by Robert Collins
Teach all trees about unknowns, conflicts and get_parent_ids.
452
    def get_parent_ids(self):
453
        """See Tree.get_parent_ids.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
454
1773.2.1 by Robert Collins
Teach all trees about unknowns, conflicts and get_parent_ids.
455
        This implementation reads the pending merges list and last_revision
456
        value and uses that to decide what the parents list should be.
457
        """
2598.5.3 by Aaron Bentley
Push NULL_REVISION deeper
458
        last_rev = _mod_revision.ensure_null(self._last_revision())
2598.5.7 by Aaron Bentley
Updates from review
459
        if _mod_revision.NULL_REVISION == last_rev:
1773.2.1 by Robert Collins
Teach all trees about unknowns, conflicts and get_parent_ids.
460
            parents = []
461
        else:
462
            parents = [last_rev]
1908.6.10 by Robert Collins
forward to get_parent_ids in pending_merges.
463
        try:
4852.1.7 by John Arbash Meinel
Lots of tweaks in WorkingTree.
464
            merges_bytes = self._transport.get_bytes('pending-merges')
2206.1.7 by Marius Kruger
* errors
465
        except errors.NoSuchFile:
1908.6.10 by Robert Collins
forward to get_parent_ids in pending_merges.
466
            pass
467
        else:
4852.1.9 by John Arbash Meinel
Minor typo fix.
468
            for l in osutils.split_lines(merges_bytes):
2858.2.1 by Martin Pool
Remove most calls to safe_file_id and safe_revision_id.
469
                revision_id = l.rstrip('\n')
2249.5.9 by John Arbash Meinel
Update WorkingTree to use safe_revision_id when appropriate
470
                parents.append(revision_id)
1908.6.10 by Robert Collins
forward to get_parent_ids in pending_merges.
471
        return parents
1773.2.1 by Robert Collins
Teach all trees about unknowns, conflicts and get_parent_ids.
472
1497 by Robert Collins
Move Branch.read_working_inventory to WorkingTree.
473
    def get_root_id(self):
474
        """Return the id of this trees root"""
5777.5.2 by Jelmer Vernooij
Split inventory-specific methods and WorkingTree interface method
475
        raise NotImplementedError(self.get_root_id)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
476
1534.4.35 by Robert Collins
Give branch its own basis tree and last_revision methods; deprecated branch.working_tree()
477
    @needs_read_lock
6207.3.5 by Jelmer Vernooij
Use controldir rather than bzrdir.
478
    def clone(self, to_controldir, revision_id=None):
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
479
        """Duplicate this working tree into to_bzr, including all state.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
480
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
481
        Specifically modified files are kept as modified, but
482
        ignored and unknown files are discarded.
1534.4.35 by Robert Collins
Give branch its own basis tree and last_revision methods; deprecated branch.working_tree()
483
6207.3.5 by Jelmer Vernooij
Use controldir rather than bzrdir.
484
        If you want to make a new line of development, see ControlDir.sprout()
1534.4.35 by Robert Collins
Give branch its own basis tree and last_revision methods; deprecated branch.working_tree()
485
486
        revision
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
487
            If not None, the cloned tree will have its last revision set to
4031.3.1 by Frank Aspell
Fixing various typos
488
            revision, and difference between the source trees last revision
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
489
            and this one merged in.
1534.4.35 by Robert Collins
Give branch its own basis tree and last_revision methods; deprecated branch.working_tree()
490
        """
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
491
        # assumes the target bzr dir format is compatible.
6207.3.5 by Jelmer Vernooij
Use controldir rather than bzrdir.
492
        result = to_controldir.create_workingtree()
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
493
        self.copy_content_into(result, revision_id)
494
        return result
495
496
    @needs_read_lock
497
    def copy_content_into(self, tree, revision_id=None):
498
        """Copy the current content and user files of this tree into tree."""
1731.1.33 by Aaron Bentley
Revert no-special-root changes
499
        tree.set_root_id(self.get_root_id())
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
500
        if revision_id is None:
1996.3.6 by John Arbash Meinel
Find a few places that weren't importing their dependencies.
501
            merge.transform_tree(tree, self)
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
502
        else:
1908.6.1 by Robert Collins
Change all callers of set_last_revision to use set_parent_trees.
503
            # TODO now merge from tree.last_revision to revision (to preserve
504
            # user local changes)
6519.3.4 by Neil Martinsen-Burrell
try looking up revision in tree first
505
            try:
506
                other_tree = self.revision_tree(revision_id)
507
            except errors.NoSuchRevision:
508
                other_tree = self.branch.repository.revision_tree(revision_id)
509
510
            merge.transform_tree(tree, other_tree)
6241.3.1 by Jelmer Vernooij
Support WorkingTree.clone() having its revision argument set to the NULL revision.
511
            if revision_id == _mod_revision.NULL_REVISION:
512
                new_parents = []
513
            else:
514
                new_parents = [revision_id]
515
            tree.set_parent_ids(new_parents)
1534.4.35 by Robert Collins
Give branch its own basis tree and last_revision methods; deprecated branch.working_tree()
516
1248 by Martin Pool
- new weave based cleanup [broken]
517
    def id2abspath(self, file_id):
518
        return self.abspath(self.id2path(file_id))
519
453 by Martin Pool
- Split WorkingTree into its own file
520
    def get_file_size(self, file_id):
3363.3.4 by Aaron Bentley
Add get_file_size to Tree interface
521
        """See Tree.get_file_size"""
4595.11.11 by Martin Pool
Split out _file_content_summary from path_content_summary and let it return None for size
522
        # XXX: this returns the on-disk size; it should probably return the
523
        # canonical size
3363.2.7 by Aaron Bentley
Implement alterntative-to-inventory tests
524
        try:
525
            return os.path.getsize(self.id2abspath(file_id))
6619.3.2 by Jelmer Vernooij
Apply 2to3 except fix.
526
        except OSError as e:
3363.2.7 by Aaron Bentley
Implement alterntative-to-inventory tests
527
            if e.errno != errno.ENOENT:
528
                raise
529
            else:
530
                return None
453 by Martin Pool
- Split WorkingTree into its own file
531
1997.1.3 by Robert Collins
All WorkingTree methods which write to the tree, but not to the branch
532
    @needs_tree_write_lock
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
533
    def _gather_kinds(self, files, kinds):
534
        """See MutableTree._gather_kinds."""
535
        for pos, f in enumerate(files):
536
            if kinds[pos] is None:
6653.3.1 by Jelmer Vernooij
Move bzr-specific code to breezy.bzrworkingtree.
537
                fullpath = osutils.normpath(self.abspath(f))
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
538
                try:
6653.3.1 by Jelmer Vernooij
Move bzr-specific code to breezy.bzrworkingtree.
539
                    kinds[pos] = osutils.file_kind(fullpath)
6619.3.2 by Jelmer Vernooij
Apply 2to3 except fix.
540
                except OSError as e:
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
541
                    if e.errno == errno.ENOENT:
2206.1.7 by Marius Kruger
* errors
542
                        raise errors.NoSuchFile(fullpath)
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
543
1508.1.5 by Robert Collins
Move add from Branch to WorkingTree.
544
    @needs_write_lock
1908.5.9 by Robert Collins
Add a guard against setting the tree last-revision value to a ghost in the new tree parent management api.
545
    def add_parent_tree_id(self, revision_id, allow_leftmost_as_ghost=False):
1908.5.4 by Robert Collins
Add add_parent_tree_id WorkingTree helper api.
546
        """Add revision_id as a parent.
547
548
        This is equivalent to retrieving the current list of parent ids
549
        and setting the list to its value plus revision_id.
550
551
        :param revision_id: The revision id to add to the parent list. It may
5891.1.2 by Andrew Bennetts
Fix a bunch of docstring formatting nits, making pydoctor a bit happier.
552
            be a ghost revision as long as its not the first parent to be
553
            added, or the allow_leftmost_as_ghost parameter is set True.
1908.5.12 by Robert Collins
Apply review feedback - paired with Martin.
554
        :param allow_leftmost_as_ghost: Allow the first parent to be a ghost.
1908.5.4 by Robert Collins
Add add_parent_tree_id WorkingTree helper api.
555
        """
1908.5.13 by Robert Collins
Adding a parent when the first is a ghost already should not require forcing it.
556
        parents = self.get_parent_ids() + [revision_id]
2220.1.9 by Marius Kruger
Remove all trailing white space this bundle would have
557
        self.set_parent_ids(parents, allow_leftmost_as_ghost=len(parents) > 1
2206.1.7 by Marius Kruger
* errors
558
            or allow_leftmost_as_ghost)
1908.5.4 by Robert Collins
Add add_parent_tree_id WorkingTree helper api.
559
1997.1.3 by Robert Collins
All WorkingTree methods which write to the tree, but not to the branch
560
    @needs_tree_write_lock
1908.5.9 by Robert Collins
Add a guard against setting the tree last-revision value to a ghost in the new tree parent management api.
561
    def add_parent_tree(self, parent_tuple, allow_leftmost_as_ghost=False):
1908.5.6 by Robert Collins
Add add_parent_tree to WorkingTree.
562
        """Add revision_id, tree tuple as a parent.
563
564
        This is equivalent to retrieving the current list of parent trees
565
        and setting the list to its value plus parent_tuple. See also
566
        add_parent_tree_id - if you only have a parent id available it will be
567
        simpler to use that api. If you have the parent already available, using
568
        this api is preferred.
569
1908.5.12 by Robert Collins
Apply review feedback - paired with Martin.
570
        :param parent_tuple: The (revision id, tree) to add to the parent list.
571
            If the revision_id is a ghost, pass None for the tree.
572
        :param allow_leftmost_as_ghost: Allow the first parent to be a ghost.
1908.5.6 by Robert Collins
Add add_parent_tree to WorkingTree.
573
        """
1979.2.1 by Robert Collins
(robertc) adds a convenience method "merge_from_branch" to WorkingTree.
574
        parent_ids = self.get_parent_ids() + [parent_tuple[0]]
575
        if len(parent_ids) > 1:
576
            # the leftmost may have already been a ghost, preserve that if it
577
            # was.
578
            allow_leftmost_as_ghost = True
579
        self.set_parent_ids(parent_ids,
1908.5.9 by Robert Collins
Add a guard against setting the tree last-revision value to a ghost in the new tree parent management api.
580
            allow_leftmost_as_ghost=allow_leftmost_as_ghost)
1908.5.6 by Robert Collins
Add add_parent_tree to WorkingTree.
581
1997.1.3 by Robert Collins
All WorkingTree methods which write to the tree, but not to the branch
582
    @needs_tree_write_lock
1457.1.15 by Robert Collins
Move add_pending_merge to WorkingTree.
583
    def add_pending_merge(self, *revision_ids):
584
        # TODO: Perhaps should check at this point that the
585
        # history of the revision is actually present?
1908.6.7 by Robert Collins
Remove all users of set_pending_merges and add_pending_merge except tests that they work correctly.
586
        parents = self.get_parent_ids()
1457.1.15 by Robert Collins
Move add_pending_merge to WorkingTree.
587
        updated = False
588
        for rev_id in revision_ids:
1908.6.7 by Robert Collins
Remove all users of set_pending_merges and add_pending_merge except tests that they work correctly.
589
            if rev_id in parents:
590
                continue
591
            parents.append(rev_id)
1457.1.15 by Robert Collins
Move add_pending_merge to WorkingTree.
592
            updated = True
593
        if updated:
1908.6.7 by Robert Collins
Remove all users of set_pending_merges and add_pending_merge except tests that they work correctly.
594
            self.set_parent_ids(parents, allow_leftmost_as_ghost=True)
1457.1.15 by Robert Collins
Move add_pending_merge to WorkingTree.
595
2949.6.2 by Alexander Belchenko
more changes osutils.lstat -> os.lstat
596
    def path_content_summary(self, path, _lstat=os.lstat,
2776.1.7 by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a
597
        _mapper=osutils.file_kind_from_stat_mode):
598
        """See Tree.path_content_summary."""
599
        abspath = self.abspath(path)
600
        try:
601
            stat_result = _lstat(abspath)
6619.3.2 by Jelmer Vernooij
Apply 2to3 except fix.
602
        except OSError as e:
2776.1.7 by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a
603
            if getattr(e, 'errno', None) == errno.ENOENT:
604
                # no file.
605
                return ('missing', None, None, None)
2776.1.9 by Robert Collins
Review feedback.
606
            # propagate other errors
2776.1.7 by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a
607
            raise
608
        kind = _mapper(stat_result.st_mode)
609
        if kind == 'file':
4595.11.11 by Martin Pool
Split out _file_content_summary from path_content_summary and let it return None for size
610
            return self._file_content_summary(path, stat_result)
2776.1.7 by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a
611
        elif kind == 'directory':
612
            # perhaps it looks like a plain directory, but it's really a
613
            # reference.
614
            if self._directory_is_tree_reference(path):
615
                kind = 'tree-reference'
616
            return kind, None, None, None
617
        elif kind == 'symlink':
4241.14.18 by Vincent Ladeuil
Use better fixes for unicode symlinks handling in WTs.
618
            target = osutils.readlink(abspath)
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
619
            return ('symlink', None, None, target)
2776.1.7 by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a
620
        else:
621
            return (kind, None, None, None)
622
4595.11.11 by Martin Pool
Split out _file_content_summary from path_content_summary and let it return None for size
623
    def _file_content_summary(self, path, stat_result):
624
        size = stat_result.st_size
625
        executable = self._is_executable_from_path_and_stat(path, stat_result)
626
        # try for a stat cache lookup
627
        return ('file', size, executable, self._sha_from_stat(
628
            path, stat_result))
629
2041.1.2 by John Arbash Meinel
Update WorkingTree.set_parent_trees() to directly cache inv.
630
    def _check_parents_for_ghosts(self, revision_ids, allow_leftmost_as_ghost):
631
        """Common ghost checking functionality from set_parent_*.
632
633
        This checks that the left hand-parent exists if there are any
634
        revisions present.
635
        """
636
        if len(revision_ids) > 0:
637
            leftmost_id = revision_ids[0]
638
            if (not allow_leftmost_as_ghost and not
639
                self.branch.repository.has_revision(leftmost_id)):
640
                raise errors.GhostRevisionUnusableHere(leftmost_id)
641
642
    def _set_merges_from_parent_ids(self, parent_ids):
643
        merges = parent_ids[1:]
3407.2.7 by Martin Pool
Deprecate LockableFiles.put_utf8 and put_bytes.
644
        self._transport.put_bytes('pending-merges', '\n'.join(merges),
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
645
            mode=self.controldir._get_file_mode())
2041.1.2 by John Arbash Meinel
Update WorkingTree.set_parent_trees() to directly cache inv.
646
3462.1.2 by John Arbash Meinel
Change WT.set_parent_(ids/trees) to filter out ancestors.
647
    def _filter_parent_ids_by_ancestry(self, revision_ids):
648
        """Check that all merged revisions are proper 'heads'.
649
650
        This will always return the first revision_id, and any merged revisions
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
651
        which are
3462.1.2 by John Arbash Meinel
Change WT.set_parent_(ids/trees) to filter out ancestors.
652
        """
653
        if len(revision_ids) == 0:
654
            return revision_ids
655
        graph = self.branch.repository.get_graph()
656
        heads = graph.heads(revision_ids)
657
        new_revision_ids = revision_ids[:1]
658
        for revision_id in revision_ids[1:]:
659
            if revision_id in heads and revision_id not in new_revision_ids:
660
                new_revision_ids.append(revision_id)
661
        if new_revision_ids != revision_ids:
5753.2.2 by Jelmer Vernooij
Remove some unnecessary imports, clean up lazy imports.
662
            mutter('requested to set revision_ids = %s,'
3462.1.2 by John Arbash Meinel
Change WT.set_parent_(ids/trees) to filter out ancestors.
663
                         ' but filtered to %s', revision_ids, new_revision_ids)
664
        return new_revision_ids
665
1997.1.3 by Robert Collins
All WorkingTree methods which write to the tree, but not to the branch
666
    @needs_tree_write_lock
1908.5.9 by Robert Collins
Add a guard against setting the tree last-revision value to a ghost in the new tree parent management api.
667
    def set_parent_ids(self, revision_ids, allow_leftmost_as_ghost=False):
1908.5.5 by Robert Collins
Add WorkingTree.set_parent_ids.
668
        """Set the parent ids to revision_ids.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
669
1908.5.5 by Robert Collins
Add WorkingTree.set_parent_ids.
670
        See also set_parent_trees. This api will try to retrieve the tree data
671
        for each element of revision_ids from the trees repository. If you have
672
        tree data already available, it is more efficient to use
673
        set_parent_trees rather than set_parent_ids. set_parent_ids is however
674
        an easier API to use.
675
676
        :param revision_ids: The revision_ids to set as the parent ids of this
677
            working tree. Any of these may be ghosts.
678
        """
2041.1.2 by John Arbash Meinel
Update WorkingTree.set_parent_trees() to directly cache inv.
679
        self._check_parents_for_ghosts(revision_ids,
680
            allow_leftmost_as_ghost=allow_leftmost_as_ghost)
2598.5.2 by Aaron Bentley
Got all tests passing with Branch returning 'null:' for null revision
681
        for revision_id in revision_ids:
682
            _mod_revision.check_not_reserved_id(revision_id)
2041.1.2 by John Arbash Meinel
Update WorkingTree.set_parent_trees() to directly cache inv.
683
3462.1.2 by John Arbash Meinel
Change WT.set_parent_(ids/trees) to filter out ancestors.
684
        revision_ids = self._filter_parent_ids_by_ancestry(revision_ids)
685
1908.6.7 by Robert Collins
Remove all users of set_pending_merges and add_pending_merge except tests that they work correctly.
686
        if len(revision_ids) > 0:
2041.1.2 by John Arbash Meinel
Update WorkingTree.set_parent_trees() to directly cache inv.
687
            self.set_last_revision(revision_ids[0])
1908.6.7 by Robert Collins
Remove all users of set_pending_merges and add_pending_merge except tests that they work correctly.
688
        else:
2598.5.3 by Aaron Bentley
Push NULL_REVISION deeper
689
            self.set_last_revision(_mod_revision.NULL_REVISION)
2041.1.2 by John Arbash Meinel
Update WorkingTree.set_parent_trees() to directly cache inv.
690
691
        self._set_merges_from_parent_ids(revision_ids)
1908.5.5 by Robert Collins
Add WorkingTree.set_parent_ids.
692
1997.1.3 by Robert Collins
All WorkingTree methods which write to the tree, but not to the branch
693
    @needs_tree_write_lock
1457.1.16 by Robert Collins
Move set_pending_merges to WorkingTree.
694
    def set_pending_merges(self, rev_list):
1908.6.7 by Robert Collins
Remove all users of set_pending_merges and add_pending_merge except tests that they work correctly.
695
        parents = self.get_parent_ids()
696
        leftmost = parents[:1]
697
        new_parents = leftmost + rev_list
698
        self.set_parent_ids(new_parents)
1457.1.16 by Robert Collins
Move set_pending_merges to WorkingTree.
699
1997.1.3 by Robert Collins
All WorkingTree methods which write to the tree, but not to the branch
700
    @needs_tree_write_lock
1534.7.192 by Aaron Bentley
Record hashes produced by merges
701
    def set_merge_modified(self, modified_hashes):
6313.1.1 by Jelmer Vernooij
Move bzr-specific functionality to InventoryWorkingTree.
702
        """Set the merge modified hashes."""
703
        raise NotImplementedError(self.set_merge_modified)
1534.10.3 by Aaron Bentley
Simplify set_merge_modified with rio_file
704
2776.1.8 by Robert Collins
Retrieve the sha from the dirstate for path_content_summary on hash cache hits; slight performance hit but a big win for incremental commits.
705
    def _sha_from_stat(self, path, stat_result):
706
        """Get a sha digest from the tree's stat cache.
707
708
        The default implementation assumes no stat cache is present.
709
710
        :param path: The path.
711
        :param stat_result: The stat result being looked up.
712
        """
713
        return None
714
1997.1.3 by Robert Collins
All WorkingTree methods which write to the tree, but not to the branch
715
    @needs_write_lock # because merge pulls data into the branch.
1551.15.69 by Aaron Bentley
Add merge_type to merge_from_branch
716
    def merge_from_branch(self, branch, to_revision=None, from_revision=None,
4721.3.2 by Vincent Ladeuil
Simplify mutable_tree.has_changes() and update call sites.
717
                          merge_type=None, force=False):
1979.2.1 by Robert Collins
(robertc) adds a convenience method "merge_from_branch" to WorkingTree.
718
        """Merge from a branch into this working tree.
719
720
        :param branch: The branch to merge from.
2220.1.9 by Marius Kruger
Remove all trailing white space this bundle would have
721
        :param to_revision: If non-None, the merge will merge to to_revision,
722
            but not beyond it. to_revision does not need to be in the history
2206.1.7 by Marius Kruger
* errors
723
            of the branch when it is supplied. If None, to_revision defaults to
1979.2.1 by Robert Collins
(robertc) adds a convenience method "merge_from_branch" to WorkingTree.
724
            branch.last_revision().
725
        """
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
726
        from .merge import Merger, Merge3Merger
4961.2.10 by Martin Pool
No longer need to pass pb in to Merger
727
        merger = Merger(self.branch, this_tree=self)
728
        # check that there are no local alterations
729
        if not force and self.has_changes():
730
            raise errors.UncommittedChanges(self)
731
        if to_revision is None:
732
            to_revision = _mod_revision.ensure_null(branch.last_revision())
733
        merger.other_rev_id = to_revision
734
        if _mod_revision.is_null(merger.other_rev_id):
735
            raise errors.NoCommits(branch)
736
        self.branch.fetch(branch, last_revision=merger.other_rev_id)
737
        merger.other_basis = merger.other_rev_id
738
        merger.other_tree = self.branch.repository.revision_tree(
739
            merger.other_rev_id)
740
        merger.other_branch = branch
741
        if from_revision is None:
742
            merger.find_base()
743
        else:
744
            merger.set_base_revision(from_revision, branch)
745
        if merger.base_rev_id == merger.other_rev_id:
746
            raise errors.PointlessMerge
747
        merger.backup_files = False
748
        if merge_type is None:
749
            merger.merge_type = Merge3Merger
750
        else:
751
            merger.merge_type = merge_type
752
        merger.set_interesting_files(None)
753
        merger.show_base = False
754
        merger.reprocess = False
755
        conflicts = merger.do_merge()
756
        merger.set_pending()
1979.2.1 by Robert Collins
(robertc) adds a convenience method "merge_from_branch" to WorkingTree.
757
        return conflicts
758
2255.2.156 by Martin Pool
Merge WorkingTree implementation back from trunk
759
    def merge_modified(self):
2298.1.1 by Martin Pool
Add test for merge_modified
760
        """Return a dictionary of files modified by a merge.
761
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
762
        The list is initialized by WorkingTree.set_merge_modified, which is
2298.1.1 by Martin Pool
Add test for merge_modified
763
        typically called after we make some automatic updates to the tree
764
        because of a merge.
765
766
        This returns a map of file_id->sha1, containing only files which are
767
        still in the working inventory and have that text hash.
768
        """
5777.5.2 by Jelmer Vernooij
Split inventory-specific methods and WorkingTree interface method
769
        raise NotImplementedError(self.merge_modified)
2255.2.156 by Martin Pool
Merge WorkingTree implementation back from trunk
770
771
    @needs_write_lock
772
    def mkdir(self, path, file_id=None):
773
        """See MutableTree.mkdir()."""
774
        if file_id is None:
775
            file_id = generate_ids.gen_file_id(os.path.basename(path))
776
        os.mkdir(self.abspath(path))
777
        self.add(path, file_id, 'directory')
778
        return file_id
779
5858.1.1 by Jelmer Vernooij
Support optional path argument to Tree.get_symlink_target.
780
    def get_symlink_target(self, file_id, path=None):
781
        if path is not None:
782
            abspath = self.abspath(path)
783
        else:
784
            abspath = self.id2abspath(file_id)
4241.14.18 by Vincent Ladeuil
Use better fixes for unicode symlinks handling in WTs.
785
        target = osutils.readlink(abspath)
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
786
        return target
2255.2.156 by Martin Pool
Merge WorkingTree implementation back from trunk
787
1731.2.1 by Aaron Bentley
Initial subsume implementation
788
    def subsume(self, other_tree):
5777.5.2 by Jelmer Vernooij
Split inventory-specific methods and WorkingTree interface method
789
        raise NotImplementedError(self.subsume)
1731.2.1 by Aaron Bentley
Initial subsume implementation
790
2974.2.2 by John Arbash Meinel
Only one test failed, because it was incorrectly succeeding.
791
    def _setup_directory_is_tree_reference(self):
792
        if self._branch.repository._format.supports_tree_reference:
793
            self._directory_is_tree_reference = \
794
                self._directory_may_be_tree_reference
795
        else:
796
            self._directory_is_tree_reference = \
797
                self._directory_is_never_tree_reference
798
799
    def _directory_is_never_tree_reference(self, relpath):
800
        return False
801
802
    def _directory_may_be_tree_reference(self, relpath):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
803
        # as a special case, if a directory contains control files then
2776.1.7 by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a
804
        # it's a tree reference, except that the root of the tree is not
805
        return relpath and osutils.isdir(self.abspath(relpath) + u"/.bzr")
806
        # TODO: We could ask all the control formats whether they
807
        # recognize this directory, but at the moment there's no cheap api
808
        # to do that.  Since we probably can only nest bzr checkouts and
809
        # they always use this name it's ok for now.  -- mbp 20060306
810
        #
811
        # FIXME: There is an unhandled case here of a subdirectory
812
        # containing .bzr but not a branch; that will probably blow up
813
        # when you try to commit it.  It might happen if there is a
814
        # checkout in a subdirectory.  This can be avoided by not adding
815
        # it.  mbp 20070306
816
1731.2.17 by Aaron Bentley
Support extracting with checkouts
817
    def extract(self, file_id, format=None):
1731.2.16 by Aaron Bentley
Get extract working for standalone trees
818
        """Extract a subtree from this tree.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
819
1731.2.16 by Aaron Bentley
Get extract working for standalone trees
820
        A new branch will be created, relative to the path for this tree.
821
        """
5777.5.2 by Jelmer Vernooij
Split inventory-specific methods and WorkingTree interface method
822
        raise NotImplementedError(self.extract)
453 by Martin Pool
- Split WorkingTree into its own file
823
1986.5.3 by Robert Collins
New method ``WorkingTree.flush()`` which will write the current memory
824
    def flush(self):
5777.5.2 by Jelmer Vernooij
Split inventory-specific methods and WorkingTree interface method
825
        """Write the in memory meta data to disk."""
826
        raise NotImplementedError(self.flush)
1986.5.3 by Robert Collins
New method ``WorkingTree.flush()`` which will write the current memory
827
1551.10.29 by Aaron Bentley
Fix tree.list_files when file kind changes
828
    def _kind(self, relpath):
829
        return osutils.file_kind(self.abspath(relpath))
830
4370.5.2 by Ian Clatworthy
extend list_files() with from_dir and recursive parameters
831
    def list_files(self, include_root=False, from_dir=None, recursive=True):
832
        """List all files as (path, class, kind, id, entry).
453 by Martin Pool
- Split WorkingTree into its own file
833
834
        Lists, but does not descend into unversioned directories.
835
        This does not include files that have been deleted in this
4370.5.2 by Ian Clatworthy
extend list_files() with from_dir and recursive parameters
836
        tree. Skips the control directory.
453 by Martin Pool
- Split WorkingTree into its own file
837
5128.1.1 by Vincent Ladeuil
Uncontroversial cleanups, mostly comments
838
        :param include_root: if True, return an entry for the root
4370.5.2 by Ian Clatworthy
extend list_files() with from_dir and recursive parameters
839
        :param from_dir: start from this directory or None for the root
840
        :param recursive: whether to recurse into subdirectories or not
453 by Martin Pool
- Split WorkingTree into its own file
841
        """
5777.5.2 by Jelmer Vernooij
Split inventory-specific methods and WorkingTree interface method
842
        raise NotImplementedError(self.list_files)
843
5346.1.5 by Vincent Ladeuil
Delete the to_name parameter from WorkingTree.move()
844
    def move(self, from_paths, to_dir=None, after=False):
1508.1.8 by Robert Collins
move move() from Branch to WorkingTree.
845
        """Rename files.
846
5777.5.2 by Jelmer Vernooij
Split inventory-specific methods and WorkingTree interface method
847
        to_dir must be known to the working tree.
1508.1.8 by Robert Collins
move move() from Branch to WorkingTree.
848
2123.3.1 by Steffen Eichenberg
the mv command is now able to move files that have already been moved on the file system
849
        If to_dir exists and is a directory, the files are moved into
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
850
        it, keeping their old names.
1508.1.8 by Robert Collins
move move() from Branch to WorkingTree.
851
2123.3.1 by Steffen Eichenberg
the mv command is now able to move files that have already been moved on the file system
852
        Note that to_dir is only the last component of the new name;
1508.1.8 by Robert Collins
move move() from Branch to WorkingTree.
853
        this doesn't change the directory.
854
2220.1.9 by Marius Kruger
Remove all trailing white space this bundle would have
855
        For each entry in from_paths the move mode will be determined
2123.3.1 by Steffen Eichenberg
the mv command is now able to move files that have already been moved on the file system
856
        independently.
857
2220.1.9 by Marius Kruger
Remove all trailing white space this bundle would have
858
        The first mode moves the file in the filesystem and updates the
5777.5.2 by Jelmer Vernooij
Split inventory-specific methods and WorkingTree interface method
859
        working tree metadata. The second mode only updates the working tree
860
        metadata without touching the file on the filesystem.
2220.1.9 by Marius Kruger
Remove all trailing white space this bundle would have
861
2123.3.1 by Steffen Eichenberg
the mv command is now able to move files that have already been moved on the file system
862
        move uses the second mode if 'after == True' and the target is not
863
        versioned but present in the working tree.
864
2220.1.9 by Marius Kruger
Remove all trailing white space this bundle would have
865
        move uses the second mode if 'after == False' and the source is
866
        versioned but no longer in the working tree, and the target is not
2123.3.1 by Steffen Eichenberg
the mv command is now able to move files that have already been moved on the file system
867
        versioned but present in the working tree.
868
2220.1.9 by Marius Kruger
Remove all trailing white space this bundle would have
869
        move uses the first mode if 'after == False' and the source is
870
        versioned and present in the working tree, and the target is not
2123.3.1 by Steffen Eichenberg
the mv command is now able to move files that have already been moved on the file system
871
        versioned and not present in the working tree.
872
873
        Everything else results in an error.
874
1508.1.8 by Robert Collins
move move() from Branch to WorkingTree.
875
        This returns a list of (from_path, to_path) pairs for each
2220.1.6 by Marius Kruger
* change error message telling user about --after option sightly
876
        entry that is moved.
1508.1.8 by Robert Collins
move move() from Branch to WorkingTree.
877
        """
5777.5.2 by Jelmer Vernooij
Split inventory-specific methods and WorkingTree interface method
878
        raise NotImplementedError(self.move)
1508.1.8 by Robert Collins
move move() from Branch to WorkingTree.
879
1997.1.3 by Robert Collins
All WorkingTree methods which write to the tree, but not to the branch
880
    @needs_tree_write_lock
2123.3.1 by Steffen Eichenberg
the mv command is now able to move files that have already been moved on the file system
881
    def rename_one(self, from_rel, to_rel, after=False):
1508.1.7 by Robert Collins
Move rename_one from Branch to WorkingTree. (Robert Collins).
882
        """Rename one file.
883
884
        This can change the directory or the filename or both.
2123.3.1 by Steffen Eichenberg
the mv command is now able to move files that have already been moved on the file system
885
2220.1.9 by Marius Kruger
Remove all trailing white space this bundle would have
886
        rename_one has several 'modes' to work. First, it can rename a physical
887
        file and change the file_id. That is the normal mode. Second, it can
5777.5.2 by Jelmer Vernooij
Split inventory-specific methods and WorkingTree interface method
888
        only change the file_id without touching any physical file.
2220.1.9 by Marius Kruger
Remove all trailing white space this bundle would have
889
5911.1.4 by Benoît Pierre
Update docstrings for WorkingTree.move() and WorkingTree.rename_one().
890
        rename_one uses the second mode if 'after == True' and 'to_rel' is
891
        either not versioned or newly added, and present in the working tree.
2123.3.1 by Steffen Eichenberg
the mv command is now able to move files that have already been moved on the file system
892
2220.1.9 by Marius Kruger
Remove all trailing white space this bundle would have
893
        rename_one uses the second mode if 'after == False' and 'from_rel' is
894
        versioned but no longer in the working tree, and 'to_rel' is not
2123.3.1 by Steffen Eichenberg
the mv command is now able to move files that have already been moved on the file system
895
        versioned but present in the working tree.
896
2220.1.9 by Marius Kruger
Remove all trailing white space this bundle would have
897
        rename_one uses the first mode if 'after == False' and 'from_rel' is
898
        versioned and present in the working tree, and 'to_rel' is not
2123.3.1 by Steffen Eichenberg
the mv command is now able to move files that have already been moved on the file system
899
        versioned and not present in the working tree.
900
901
        Everything else results in an error.
1508.1.7 by Robert Collins
Move rename_one from Branch to WorkingTree. (Robert Collins).
902
        """
5777.5.2 by Jelmer Vernooij
Split inventory-specific methods and WorkingTree interface method
903
        raise NotImplementedError(self.rename_one)
2123.3.1 by Steffen Eichenberg
the mv command is now able to move files that have already been moved on the file system
904
1508.1.7 by Robert Collins
Move rename_one from Branch to WorkingTree. (Robert Collins).
905
    @needs_read_lock
453 by Martin Pool
- Split WorkingTree into its own file
906
    def unknowns(self):
1508.1.6 by Robert Collins
Move Branch.unknowns() to WorkingTree.
907
        """Return all unknown files.
908
909
        These are files in the working directory that are not versioned or
910
        control files or ignored.
911
        """
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
912
        # force the extras method to be fully executed before returning, to
2255.2.15 by Robert Collins
Dirstate - truncate state file fixing bug in saving a smaller file, get more tree_implementation tests passing.
913
        # prevent race conditions with the lock
914
        return iter(
915
            [subp for subp in self.extras() if not self.is_ignored(subp)])
2323.6.1 by Martin Pool
(broken) Give a message when opening old workingtree formats suggesting upgrade
916
1988.2.1 by Robert Collins
WorkingTree has a new api ``unversion`` which allow the unversioning of
917
    def unversion(self, file_ids):
918
        """Remove the file ids in file_ids from the current versioned set.
919
920
        When a file_id is unversioned, all of its children are automatically
921
        unversioned.
922
923
        :param file_ids: The file ids to stop versioning.
924
        :raises: NoSuchId if any fileid is not currently versioned.
925
        """
5777.5.2 by Jelmer Vernooij
Split inventory-specific methods and WorkingTree interface method
926
        raise NotImplementedError(self.unversion)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
927
1442.1.67 by Robert Collins
Factor out the guts of 'pull' from the command into WorkingTree.pull().
928
    @needs_write_lock
1551.11.10 by Aaron Bentley
Add change reporting to pull
929
    def pull(self, source, overwrite=False, stop_revision=None,
5430.7.1 by Rory Yorke
Added --show-base to pull and update (bug 202374).
930
             change_reporter=None, possible_transports=None, local=False,
931
             show_base=False):
1442.1.67 by Robert Collins
Factor out the guts of 'pull' from the command into WorkingTree.pull().
932
        source.lock_read()
933
        try:
2249.4.2 by Wouter van Heyst
Convert callers of Branch.revision_history() to Branch.last_revision_info() where sensible.
934
            old_revision_info = self.branch.last_revision_info()
1563.1.4 by Robert Collins
Fix 'bzr pull' on metadir trees.
935
            basis_tree = self.basis_tree()
2817.4.3 by Vincent Ladeuil
Add tests for commit, reuse master branch transport.
936
            count = self.branch.pull(source, overwrite, stop_revision,
4056.6.4 by Gary van der Merwe
Implement pull --local.
937
                                     possible_transports=possible_transports,
938
                                     local=local)
2249.4.2 by Wouter van Heyst
Convert callers of Branch.revision_history() to Branch.last_revision_info() where sensible.
939
            new_revision_info = self.branch.last_revision_info()
940
            if new_revision_info != old_revision_info:
1185.67.2 by Aaron Bentley
Renamed Branch.storage to Branch.repository
941
                repository = self.branch.repository
5847.2.1 by John Arbash Meinel
Bug #780677, use a RevisionTree for pull
942
                if repository._format.fast_deltas:
5847.2.2 by John Arbash Meinel
Forgot that sometimes we don't have any parents during pull.
943
                    parent_ids = self.get_parent_ids()
944
                    if parent_ids:
945
                        basis_id = parent_ids[0]
946
                        basis_tree = repository.revision_tree(basis_id)
2255.2.38 by Robert Collins
Fix WorkingTree4.pull to work.
947
                basis_tree.lock_read()
1594.1.3 by Robert Collins
Fixup pb usage to use nested_progress_bar.
948
                try:
1908.6.1 by Robert Collins
Change all callers of set_last_revision to use set_parent_trees.
949
                    new_basis_tree = self.branch.basis_tree()
1996.3.6 by John Arbash Meinel
Find a few places that weren't importing their dependencies.
950
                    merge.merge_inner(
951
                                self.branch,
1908.6.1 by Robert Collins
Change all callers of set_last_revision to use set_parent_trees.
952
                                new_basis_tree,
953
                                basis_tree,
954
                                this_tree=self,
4961.2.11 by Martin Pool
Pull out pbs and ProgressPhases stored in object state; just use them in single functions
955
                                pb=None,
5430.7.1 by Rory Yorke
Added --show-base to pull and update (bug 202374).
956
                                change_reporter=change_reporter,
957
                                show_base=show_base)
4634.123.11 by John Arbash Meinel
fix 'pull' to also set the root id.
958
                    basis_root_id = basis_tree.get_root_id()
959
                    new_root_id = new_basis_tree.get_root_id()
6243.1.1 by Jelmer Vernooij
Fix WorkingTree.pull(stop_revision='null:', overwrite=True).
960
                    if new_root_id is not None and basis_root_id != new_root_id:
4634.123.11 by John Arbash Meinel
fix 'pull' to also set the root id.
961
                        self.set_root_id(new_root_id)
1594.1.3 by Robert Collins
Fixup pb usage to use nested_progress_bar.
962
                finally:
2255.2.38 by Robert Collins
Fix WorkingTree4.pull to work.
963
                    basis_tree.unlock()
1908.6.1 by Robert Collins
Change all callers of set_last_revision to use set_parent_trees.
964
                # TODO - dedup parents list with things merged by pull ?
1908.6.3 by Robert Collins
Tidy up the last_revision_id and add_pending_merge conversion to use cleaner apis.
965
                # reuse the revisiontree we merged against to set the new
966
                # tree data.
6243.1.1 by Jelmer Vernooij
Fix WorkingTree.pull(stop_revision='null:', overwrite=True).
967
                parent_trees = []
968
                if self.branch.last_revision() != _mod_revision.NULL_REVISION:
969
                    parent_trees.append(
970
                        (self.branch.last_revision(), new_basis_tree))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
971
                # we have to pull the merge trees out again, because
972
                # merge_inner has set the ids. - this corner is not yet
1908.6.3 by Robert Collins
Tidy up the last_revision_id and add_pending_merge conversion to use cleaner apis.
973
                # layered well enough to prevent double handling.
2255.2.38 by Robert Collins
Fix WorkingTree4.pull to work.
974
                # XXX TODO: Fix the double handling: telling the tree about
975
                # the already known parent data is wasteful.
1908.6.1 by Robert Collins
Change all callers of set_last_revision to use set_parent_trees.
976
                merges = self.get_parent_ids()[1:]
977
                parent_trees.extend([
978
                    (parent, repository.revision_tree(parent)) for
979
                     parent in merges])
980
                self.set_parent_trees(parent_trees)
1185.33.44 by Martin Pool
[patch] show number of revisions pushed/pulled/merged (Robey Pointer)
981
            return count
1442.1.67 by Robert Collins
Factor out the guts of 'pull' from the command into WorkingTree.pull().
982
        finally:
983
            source.unlock()
984
1986.1.2 by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely
985
    @needs_write_lock
986
    def put_file_bytes_non_atomic(self, file_id, bytes):
987
        """See MutableTree.put_file_bytes_non_atomic."""
988
        stream = file(self.id2abspath(file_id), 'wb')
989
        try:
990
            stream.write(bytes)
991
        finally:
992
            stream.close()
993
453 by Martin Pool
- Split WorkingTree into its own file
994
    def extras(self):
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
995
        """Yield all unversioned files in this WorkingTree.
453 by Martin Pool
- Split WorkingTree into its own file
996
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
997
        If there are any unversioned directories then only the directory is
998
        returned, not all its children.  But if there are unversioned files
453 by Martin Pool
- Split WorkingTree into its own file
999
        under a versioned subdirectory, they are returned.
1000
1001
        Currently returned depth-first, sorted by name within directories.
2255.7.85 by Robert Collins
Teach _iter_changes to gather unversioned path details upon request.
1002
        This is the same order used by 'osutils.walkdirs'.
453 by Martin Pool
- Split WorkingTree into its own file
1003
        """
5777.5.2 by Jelmer Vernooij
Split inventory-specific methods and WorkingTree interface method
1004
        raise NotImplementedError(self.extras)
453 by Martin Pool
- Split WorkingTree into its own file
1005
1006
    def ignored_files(self):
1007
        """Yield list of PATH, IGNORE_PATTERN"""
1008
        for subp in self.extras():
1009
            pat = self.is_ignored(subp)
1963.2.6 by Robey Pointer
pychecker is on crack; go back to using 'is None'.
1010
            if pat is not None:
453 by Martin Pool
- Split WorkingTree into its own file
1011
                yield subp, pat
1012
1013
    def get_ignore_list(self):
1014
        """Return list of ignore patterns.
1015
1016
        Cached in the Tree object after the first call.
1017
        """
1836.1.30 by John Arbash Meinel
Change ignore functions to use sets instead of lists.
1018
        ignoreset = getattr(self, '_ignoreset', None)
1019
        if ignoreset is not None:
1020
            return ignoreset
1021
2696.1.1 by Martin Pool
Remove things deprecated in 0.11 and earlier
1022
        ignore_globs = set()
1836.1.30 by John Arbash Meinel
Change ignore functions to use sets instead of lists.
1023
        ignore_globs.update(ignores.get_runtime_ignores())
1024
        ignore_globs.update(ignores.get_user_ignores())
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
1025
        if self.has_filename(breezy.IGNORE_FILENAME):
1026
            f = self.get_file_byname(breezy.IGNORE_FILENAME)
1836.1.4 by John Arbash Meinel
Cleanup is_ignored to handle comment lines, and a global ignore pattern
1027
            try:
1836.1.30 by John Arbash Meinel
Change ignore functions to use sets instead of lists.
1028
                ignore_globs.update(ignores.parse_ignore_file(f))
1836.1.4 by John Arbash Meinel
Cleanup is_ignored to handle comment lines, and a global ignore pattern
1029
            finally:
1030
                f.close()
1836.1.30 by John Arbash Meinel
Change ignore functions to use sets instead of lists.
1031
        self._ignoreset = ignore_globs
1836.1.4 by John Arbash Meinel
Cleanup is_ignored to handle comment lines, and a global ignore pattern
1032
        return ignore_globs
453 by Martin Pool
- Split WorkingTree into its own file
1033
2135.2.7 by Kent Gibson
Implement JAM's review suggestions.
1034
    def _flush_ignore_list_cache(self):
2135.2.1 by Kent Gibson
Added glob module to replace broken fnmatch based ignore pattern matching (#57637)
1035
        """Resets the cached ignore list to force a cache rebuild."""
1036
        self._ignoreset = None
1037
        self._ignoreglobster = None
1713.2.3 by Robert Collins
Combine ignore rules into a single regex preventing pathological behaviour during add.
1038
453 by Martin Pool
- Split WorkingTree into its own file
1039
    def is_ignored(self, filename):
1040
        r"""Check whether the filename matches an ignore pattern.
1041
1042
        Patterns containing '/' or '\' need to match the whole path;
4948.5.1 by John Whitley
Implementation of ignore exclusions and basic tests for same.
1043
        others match against only the last component.  Patterns starting
4948.5.7 by John Whitley
Terminology change: exclusion => exception.
1044
        with '!' are ignore exceptions.  Exceptions take precedence
4948.5.1 by John Whitley
Implementation of ignore exclusions and basic tests for same.
1045
        over regular patterns and cause the filename to not be ignored.
453 by Martin Pool
- Split WorkingTree into its own file
1046
1047
        If the file is ignored, returns the pattern which caused it to
1048
        be ignored, otherwise None.  So this can simply be used as a
1049
        boolean if desired."""
2135.2.1 by Kent Gibson
Added glob module to replace broken fnmatch based ignore pattern matching (#57637)
1050
        if getattr(self, '_ignoreglobster', None) is None:
4948.5.7 by John Whitley
Terminology change: exclusion => exception.
1051
            self._ignoreglobster = globbing.ExceptionGlobster(self.get_ignore_list())
4948.5.3 by John Whitley
Refactor the exclusion handling functionality out of
1052
        return self._ignoreglobster.match(filename)
1185.14.6 by Aaron Bentley
Made iter_conflicts a WorkingTree method
1053
1185.12.28 by Aaron Bentley
Removed use of readonly path for executability test
1054
    def kind(self, file_id):
6653.3.1 by Jelmer Vernooij
Move bzr-specific code to breezy.bzrworkingtree.
1055
        return osutils.file_kind(self.id2abspath(file_id))
1185.12.28 by Aaron Bentley
Removed use of readonly path for executability test
1056
3146.8.4 by Aaron Bentley
Eliminate direct use of inventory from transform application
1057
    def stored_kind(self, file_id):
1058
        """See Tree.stored_kind"""
5777.5.2 by Jelmer Vernooij
Split inventory-specific methods and WorkingTree interface method
1059
        raise NotImplementedError(self.stored_kind)
3146.8.4 by Aaron Bentley
Eliminate direct use of inventory from transform application
1060
2012.1.7 by Aaron Bentley
Get tree._iter_changed down to ~ 1 stat per file
1061
    def _comparison_data(self, entry, path):
1062
        abspath = self.abspath(path)
1063
        try:
1064
            stat_value = os.lstat(abspath)
6619.3.2 by Jelmer Vernooij
Apply 2to3 except fix.
1065
        except OSError as e:
2012.1.7 by Aaron Bentley
Get tree._iter_changed down to ~ 1 stat per file
1066
            if getattr(e, 'errno', None) == errno.ENOENT:
1067
                stat_value = None
1068
                kind = None
1069
                executable = False
1070
            else:
1071
                raise
1072
        else:
1073
            mode = stat_value.st_mode
1074
            kind = osutils.file_kind_from_stat_mode(mode)
6379.7.1 by Jelmer Vernooij
Add and use WorkingTree._supports_executable.
1075
            if not self._supports_executable():
2409.1.2 by Dmitry Vasiliev
Used one-line conditional expression instead of the multi-line one
1076
                executable = entry is not None and entry.executable
2012.1.7 by Aaron Bentley
Get tree._iter_changed down to ~ 1 stat per file
1077
            else:
1078
                executable = bool(stat.S_ISREG(mode) and stat.S_IEXEC & mode)
1079
        return kind, executable, stat_value
1080
1081
    def _file_size(self, entry, stat_value):
1082
        return stat_value.st_size
1083
1534.4.35 by Robert Collins
Give branch its own basis tree and last_revision methods; deprecated branch.working_tree()
1084
    def last_revision(self):
1986.1.6 by Robert Collins
Add MemoryTree.last_revision.
1085
        """Return the last revision of the branch for this tree.
1086
1087
        This format tree does not support a separate marker for last-revision
1088
        compared to the branch.
1089
1090
        See MutableTree.last_revision
1534.4.35 by Robert Collins
Give branch its own basis tree and last_revision methods; deprecated branch.working_tree()
1091
        """
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
1092
        return self._last_revision()
1093
1094
    @needs_read_lock
1095
    def _last_revision(self):
1096
        """helper for get_parent_ids."""
2598.5.10 by Aaron Bentley
Return NULL_REVISION instead of None for the null revision
1097
        return _mod_revision.ensure_null(self.branch.last_revision())
1534.4.35 by Robert Collins
Give branch its own basis tree and last_revision methods; deprecated branch.working_tree()
1098
1694.2.6 by Martin Pool
[merge] bzr.dev
1099
    def is_locked(self):
6313.1.1 by Jelmer Vernooij
Move bzr-specific functionality to InventoryWorkingTree.
1100
        """Check if this tree is locked."""
1101
        raise NotImplementedError(self.is_locked)
2298.1.1 by Martin Pool
Add test for merge_modified
1102
1442.1.65 by Robert Collins
Branch.remove has been moved to WorkingTree.
1103
    def lock_read(self):
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1104
        """Lock the tree for reading.
1105
1106
        This also locks the branch, and can be unlocked via self.unlock().
1107
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
1108
        :return: A breezy.lock.LogicalLockResult.
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1109
        """
6313.1.1 by Jelmer Vernooij
Move bzr-specific functionality to InventoryWorkingTree.
1110
        raise NotImplementedError(self.lock_read)
1442.1.65 by Robert Collins
Branch.remove has been moved to WorkingTree.
1111
1997.1.1 by Robert Collins
Add WorkingTree.lock_tree_write.
1112
    def lock_tree_write(self):
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1113
        """See MutableTree.lock_tree_write, and WorkingTree.unlock.
1114
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
1115
        :return: A breezy.lock.LogicalLockResult.
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1116
        """
6313.1.1 by Jelmer Vernooij
Move bzr-specific functionality to InventoryWorkingTree.
1117
        raise NotImplementedError(self.lock_tree_write)
1997.1.1 by Robert Collins
Add WorkingTree.lock_tree_write.
1118
1442.1.65 by Robert Collins
Branch.remove has been moved to WorkingTree.
1119
    def lock_write(self):
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1120
        """See MutableTree.lock_write, and WorkingTree.unlock.
1121
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
1122
        :return: A breezy.lock.LogicalLockResult.
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
1123
        """
6313.1.1 by Jelmer Vernooij
Move bzr-specific functionality to InventoryWorkingTree.
1124
        raise NotImplementedError(self.lock_write)
1442.1.65 by Robert Collins
Branch.remove has been moved to WorkingTree.
1125
1694.2.6 by Martin Pool
[merge] bzr.dev
1126
    def get_physical_lock_status(self):
6313.1.1 by Jelmer Vernooij
Move bzr-specific functionality to InventoryWorkingTree.
1127
        raise NotImplementedError(self.get_physical_lock_status)
2255.2.204 by Robert Collins
Fix info and status again.
1128
1638.1.2 by Robert Collins
Change the basis-inventory file to not have the revision-id in the file name.
1129
    def set_last_revision(self, new_revision):
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
1130
        """Change the last revision in the working tree."""
5777.5.2 by Jelmer Vernooij
Split inventory-specific methods and WorkingTree interface method
1131
        raise NotImplementedError(self.set_last_revision)
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
1132
1133
    def _change_last_revision(self, new_revision):
1638.1.2 by Robert Collins
Change the basis-inventory file to not have the revision-id in the file name.
1134
        """Template method part of set_last_revision to perform the change.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1135
1638.1.2 by Robert Collins
Change the basis-inventory file to not have the revision-id in the file name.
1136
        This is used to allow WorkingTree3 instances to not affect branch
1137
        when their last revision is set.
1138
        """
2598.5.1 by Aaron Bentley
Start eliminating the use of None to indicate null revision
1139
        if _mod_revision.is_null(new_revision):
5718.7.13 by Jelmer Vernooij
Avoid using set_revision_history.
1140
            self.branch.set_last_revision_info(0, new_revision)
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
1141
            return False
5718.8.14 by Jelmer Vernooij
Check for reserved revids.
1142
        _mod_revision.check_not_reserved_id(new_revision)
1534.4.35 by Robert Collins
Give branch its own basis tree and last_revision methods; deprecated branch.working_tree()
1143
        try:
1908.1.1 by Robert Collins
Relax WorkingTree.set_last-revision to allow any revision to be set.
1144
            self.branch.generate_revision_history(new_revision)
1145
        except errors.NoSuchRevision:
1146
            # not present in the repo - dont try to set it deeper than the tip
5807.6.1 by Jelmer Vernooij
Use undeprecated wrappers.
1147
            self.branch._set_revision_history([new_revision])
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
1148
        return True
1149
1997.1.3 by Robert Collins
All WorkingTree methods which write to the tree, but not to the branch
1150
    @needs_tree_write_lock
2292.1.22 by Marius Kruger
Implement TODO: Normalize names.
1151
    def remove(self, files, verbose=False, to_file=None, keep_files=True,
2292.1.10 by Marius Kruger
* workingtree.remove
1152
        force=False):
5777.5.2 by Jelmer Vernooij
Split inventory-specific methods and WorkingTree interface method
1153
        """Remove nominated files from the working tree metadata.
1442.1.65 by Robert Collins
Branch.remove has been moved to WorkingTree.
1154
2292.1.22 by Marius Kruger
Implement TODO: Normalize names.
1155
        :files: File paths relative to the basedir.
2292.1.7 by Marius Kruger
First pass at only deleting files on 'bzr remove' when
1156
        :keep_files: If true, the files will also be kept.
2292.1.10 by Marius Kruger
* workingtree.remove
1157
        :force: Delete files and directories, even if they are changed and
1158
            even if the directories are not empty.
1442.1.65 by Robert Collins
Branch.remove has been moved to WorkingTree.
1159
        """
1160
        if isinstance(files, basestring):
1161
            files = [files]
1162
1551.15.12 by Aaron Bentley
Stop using inventory directly in WorkingTree.remove
1163
        inv_delta = []
2292.1.25 by Marius Kruger
* Add utility method delta.get_changes_as_text to get the output of .show()
1164
5340.8.3 by Marius Kruger
new_files => all_files
1165
        all_files = set() # specified and nested files 
2655.2.16 by Marius Kruger
* Rename `unknown_files_in_directory` to `unknown_nested_files`, which
1166
        unknown_nested_files=set()
4792.5.2 by Martin Pool
Move stubby show_status from bzrlib.textui into remove(), its only user
1167
        if to_file is None:
1168
            to_file = sys.stdout
2292.1.25 by Marius Kruger
* Add utility method delta.get_changes_as_text to get the output of .show()
1169
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
1170
        files_to_backup = []
1171
2292.1.25 by Marius Kruger
* Add utility method delta.get_changes_as_text to get the output of .show()
1172
        def recurse_directory_to_add_files(directory):
2655.2.16 by Marius Kruger
* Rename `unknown_files_in_directory` to `unknown_nested_files`, which
1173
            # Recurse directory and add all files
2292.1.25 by Marius Kruger
* Add utility method delta.get_changes_as_text to get the output of .show()
1174
            # so we can check if they have changed.
5160.2.2 by Marius Kruger
check if changed file isStillInDirToBeRemoved before bailing out
1175
            for parent_info, file_infos in self.walkdirs(directory):
3585.2.4 by Robert Collins
* Deleting directories by hand before running ``bzr rm`` will not
1176
                for relpath, basename, kind, lstat, fileid, kind in file_infos:
2655.2.16 by Marius Kruger
* Rename `unknown_files_in_directory` to `unknown_nested_files`, which
1177
                    # Is it versioned or ignored?
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
1178
                    if self.path2id(relpath):
2655.2.16 by Marius Kruger
* Rename `unknown_files_in_directory` to `unknown_nested_files`, which
1179
                        # Add nested content for deletion.
5340.8.3 by Marius Kruger
new_files => all_files
1180
                        all_files.add(relpath)
2655.2.16 by Marius Kruger
* Rename `unknown_files_in_directory` to `unknown_nested_files`, which
1181
                    else:
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
1182
                        # Files which are not versioned
2655.2.16 by Marius Kruger
* Rename `unknown_files_in_directory` to `unknown_nested_files`, which
1183
                        # should be treated as unknown.
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
1184
                        files_to_backup.append(relpath)
2292.1.25 by Marius Kruger
* Add utility method delta.get_changes_as_text to get the output of .show()
1185
1186
        for filename in files:
1187
            # Get file name into canonical form.
1551.15.11 by Aaron Bentley
Bugfix WorkingTree.remove to handle subtrees, and non-cwd trees
1188
            abspath = self.abspath(filename)
1189
            filename = self.relpath(abspath)
2292.1.25 by Marius Kruger
* Add utility method delta.get_changes_as_text to get the output of .show()
1190
            if len(filename) > 0:
5340.8.3 by Marius Kruger
new_files => all_files
1191
                all_files.add(filename)
3585.2.4 by Robert Collins
* Deleting directories by hand before running ``bzr rm`` will not
1192
                recurse_directory_to_add_files(filename)
2655.2.4 by Marius Kruger
* workingtree.remove
1193
5340.8.3 by Marius Kruger
new_files => all_files
1194
        files = list(all_files)
2292.1.22 by Marius Kruger
Implement TODO: Normalize names.
1195
2475.5.2 by Marius Kruger
* blackbox/test_remove
1196
        if len(files) == 0:
1197
            return # nothing to do
1198
2292.1.22 by Marius Kruger
Implement TODO: Normalize names.
1199
        # Sort needed to first handle directory content before the directory
1200
        files.sort(reverse=True)
2655.2.6 by Marius Kruger
* workingtree.remove
1201
2655.2.4 by Marius Kruger
* workingtree.remove
1202
        # Bail out if we are going to delete files we shouldn't
2292.1.11 by Marius Kruger
* workingtree.remove
1203
        if not keep_files and not force:
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
1204
            for (file_id, path, content_change, versioned, parent_id, name,
1205
                 kind, executable) in self.iter_changes(self.basis_tree(),
1206
                     include_unchanged=True, require_versioned=False,
1207
                     want_unversioned=True, specific_files=files):
1208
                if versioned[0] == False:
1209
                    # The record is unknown or newly added
1210
                    files_to_backup.append(path[1])
1211
                elif (content_change and (kind[1] is not None) and
1212
                        osutils.is_inside_any(files, path[1])):
1213
                    # Versioned and changed, but not deleted, and still
1214
                    # in one of the dirs to be deleted.
1215
                    files_to_backup.append(path[1])
2475.5.2 by Marius Kruger
* blackbox/test_remove
1216
5340.8.5 by Marius Kruger
* extract backup_files
1217
        def backup(file_to_backup):
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
1218
            backup_name = self.controldir._available_backup_name(file_to_backup)
5340.8.5 by Marius Kruger
* extract backup_files
1219
            osutils.rename(abs_path, self.abspath(backup_name))
5409.5.4 by Vincent Ladeuil
Deprecate BzrDir.generate_backup_name and use osutils.available_backup_name.
1220
            return "removed %s (but kept a copy: %s)" % (file_to_backup,
1221
                                                         backup_name)
5340.8.5 by Marius Kruger
* extract backup_files
1222
4031.3.1 by Frank Aspell
Fixing various typos
1223
        # Build inv_delta and delete files where applicable,
5777.5.2 by Jelmer Vernooij
Split inventory-specific methods and WorkingTree interface method
1224
        # do this before any modifications to meta data.
1442.1.65 by Robert Collins
Branch.remove has been moved to WorkingTree.
1225
        for f in files:
1551.15.12 by Aaron Bentley
Stop using inventory directly in WorkingTree.remove
1226
            fid = self.path2id(f)
2655.2.4 by Marius Kruger
* workingtree.remove
1227
            message = None
1442.1.65 by Robert Collins
Branch.remove has been moved to WorkingTree.
1228
            if not fid:
2655.2.4 by Marius Kruger
* workingtree.remove
1229
                message = "%s is not versioned." % (f,)
2245.5.1 by Marius Kruger
Let bzr rm rather give a warning than an error when trying to remove a non-versioned file.
1230
            else:
1231
                if verbose:
2292.1.10 by Marius Kruger
* workingtree.remove
1232
                    # having removed it, it must be either ignored or unknown
2245.5.1 by Marius Kruger
Let bzr rm rather give a warning than an error when trying to remove a non-versioned file.
1233
                    if self.is_ignored(f):
1234
                        new_status = 'I'
1235
                    else:
1236
                        new_status = '?'
4792.5.2 by Martin Pool
Move stubby show_status from bzrlib.textui into remove(), its only user
1237
                    # XXX: Really should be a more abstract reporter interface
4792.5.3 by Martin Pool
Further cleanup of removal reporting code
1238
                    kind_ch = osutils.kind_marker(self.kind(fid))
1239
                    to_file.write(new_status + '       ' + f + kind_ch + '\n')
2655.2.17 by Marius Kruger
Minor doc and spacing updates.
1240
                # Unversion file
1551.15.12 by Aaron Bentley
Stop using inventory directly in WorkingTree.remove
1241
                inv_delta.append((f, None, fid, None))
2655.2.4 by Marius Kruger
* workingtree.remove
1242
                message = "removed %s" % (f,)
2292.1.7 by Marius Kruger
First pass at only deleting files on 'bzr remove' when
1243
2292.1.13 by Marius Kruger
* merge the unversion command back into the remove command,
1244
            if not keep_files:
2292.1.30 by Marius Kruger
* Minor text fixes.
1245
                abs_path = self.abspath(f)
1246
                if osutils.lexists(abs_path):
1247
                    if (osutils.isdir(abs_path) and
1248
                        len(os.listdir(abs_path)) > 0):
2655.2.4 by Marius Kruger
* workingtree.remove
1249
                        if force:
1250
                            osutils.rmtree(abs_path)
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
1251
                            message = "deleted %s" % (f,)
2655.2.4 by Marius Kruger
* workingtree.remove
1252
                        else:
5340.8.5 by Marius Kruger
* extract backup_files
1253
                            message = backup(f)
2292.1.25 by Marius Kruger
* Add utility method delta.get_changes_as_text to get the output of .show()
1254
                    else:
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
1255
                        if f in files_to_backup:
5340.8.5 by Marius Kruger
* extract backup_files
1256
                            message = backup(f)
5340.8.1 by Marius Kruger
* make the backup file name generator in bzrdir available to others
1257
                        else:
1258
                            osutils.delete_any(abs_path)
1259
                            message = "deleted %s" % (f,)
2292.1.13 by Marius Kruger
* merge the unversion command back into the remove command,
1260
                elif message is not None:
2655.2.17 by Marius Kruger
Minor doc and spacing updates.
1261
                    # Only care if we haven't done anything yet.
1262
                    message = "%s does not exist." % (f,)
2292.1.25 by Marius Kruger
* Add utility method delta.get_changes_as_text to get the output of .show()
1263
2655.2.17 by Marius Kruger
Minor doc and spacing updates.
1264
            # Print only one message (if any) per file.
2292.1.1 by Marius Kruger
"bzr remove" and "bzr rm" will now remove the working file.
1265
            if message is not None:
1266
                note(message)
1551.15.12 by Aaron Bentley
Stop using inventory directly in WorkingTree.remove
1267
        self.apply_inventory_delta(inv_delta)
1442.1.65 by Robert Collins
Branch.remove has been moved to WorkingTree.
1268
1997.1.3 by Robert Collins
All WorkingTree methods which write to the tree, but not to the branch
1269
    @needs_tree_write_lock
2748.3.2 by Aaron Bentley
Fix revert, remove-tree, and various tests to use None for 'no files specified'
1270
    def revert(self, filenames=None, old_tree=None, backups=True,
4961.2.9 by Martin Pool
Rip out most remaining uses of DummyProgressBar
1271
               pb=None, report_changes=False):
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
1272
        from .conflicts import resolve
1501 by Robert Collins
Move revert from Branch to WorkingTree.
1273
        if old_tree is None:
2949.2.1 by Robert Collins
* Revert takes out an appropriate lock when reverting to a basis tree, and
1274
            basis_tree = self.basis_tree()
1275
            basis_tree.lock_read()
1276
            old_tree = basis_tree
1534.10.14 by Aaron Bentley
Made revert clear conflicts
1277
        else:
2949.2.1 by Robert Collins
* Revert takes out an appropriate lock when reverting to a basis tree, and
1278
            basis_tree = None
1279
        try:
1280
            conflicts = transform.revert(self, old_tree, filenames, backups, pb,
1281
                                         report_changes)
2949.2.2 by Robert Collins
Avoid dirstate parent resetting when it is not needed during revert.
1282
            if filenames is None and len(self.get_parent_ids()) > 1:
2949.2.1 by Robert Collins
* Revert takes out an appropriate lock when reverting to a basis tree, and
1283
                parent_trees = []
1284
                last_revision = self.last_revision()
4496.3.4 by Andrew Bennetts
Tidy up unused and redundant imports in workingtree.py.
1285
                if last_revision != _mod_revision.NULL_REVISION:
2949.2.1 by Robert Collins
* Revert takes out an appropriate lock when reverting to a basis tree, and
1286
                    if basis_tree is None:
1287
                        basis_tree = self.basis_tree()
1288
                        basis_tree.lock_read()
1289
                    parent_trees.append((last_revision, basis_tree))
1290
                self.set_parent_trees(parent_trees)
1291
                resolve(self)
1292
            else:
3017.2.1 by Aaron Bentley
Revert now resolves conflicts recursively (#102739)
1293
                resolve(self, filenames, ignore_misses=True, recursive=True)
2949.2.1 by Robert Collins
* Revert takes out an appropriate lock when reverting to a basis tree, and
1294
        finally:
1295
            if basis_tree is not None:
1296
                basis_tree.unlock()
1558.7.13 by Aaron Bentley
WorkingTree.revert returns conflicts
1297
        return conflicts
1501 by Robert Collins
Move revert from Branch to WorkingTree.
1298
6538.1.20 by Aaron Bentley
Cleanup
1299
    @needs_write_lock
6538.1.5 by Aaron Bentley
Implement WorkingTree.store_uncommitted.
1300
    def store_uncommitted(self):
6538.1.20 by Aaron Bentley
Cleanup
1301
        """Store uncommitted changes from the tree in the branch."""
1302
        target_tree = self.basis_tree()
1303
        shelf_creator = shelf.ShelfCreator(self, target_tree)
6538.1.5 by Aaron Bentley
Implement WorkingTree.store_uncommitted.
1304
        try:
6538.1.20 by Aaron Bentley
Cleanup
1305
            if not shelf_creator.shelve_all():
1306
                return
1307
            self.branch.store_uncommitted(shelf_creator)
1308
            shelf_creator.transform()
6538.1.5 by Aaron Bentley
Implement WorkingTree.store_uncommitted.
1309
        finally:
6538.1.20 by Aaron Bentley
Cleanup
1310
            shelf_creator.finalize()
6538.1.7 by Aaron Bentley
Move to shelve_all and improve it.
1311
        note('Uncommitted changes stored in branch "%s".', self.branch.nick)
6538.1.5 by Aaron Bentley
Implement WorkingTree.store_uncommitted.
1312
6538.1.20 by Aaron Bentley
Cleanup
1313
    @needs_write_lock
1314
    def restore_uncommitted(self):
1315
        """Restore uncommitted changes from the branch into the tree."""
6538.1.12 by Aaron Bentley
Move unshelver construction to Branch.
1316
        unshelver = self.branch.get_unshelver(self)
1317
        if unshelver is None:
6538.1.11 by Aaron Bentley
Switch to much simpler implementation of restore_uncommitted.
1318
            return
6538.1.10 by Aaron Bentley
Implement WorkingTree.get_uncommitted_data
1319
        try:
6538.1.11 by Aaron Bentley
Switch to much simpler implementation of restore_uncommitted.
1320
            merger = unshelver.make_merger()
1321
            merger.ignore_zero = True
1322
            merger.do_merge()
6538.1.21 by Aaron Bentley
Ensure shelves are deleted when restored.
1323
            self.branch.store_uncommitted(None)
6538.1.11 by Aaron Bentley
Switch to much simpler implementation of restore_uncommitted.
1324
        finally:
1325
            unshelver.finalize()
6538.1.10 by Aaron Bentley
Implement WorkingTree.get_uncommitted_data
1326
1908.11.2 by Robert Collins
Implement WorkingTree interface conformance tests for
1327
    def revision_tree(self, revision_id):
1328
        """See Tree.revision_tree.
1329
1330
        WorkingTree can supply revision_trees for the basis revision only
1331
        because there is only one cached inventory in the bzr directory.
1332
        """
5777.5.2 by Jelmer Vernooij
Split inventory-specific methods and WorkingTree interface method
1333
        raise NotImplementedError(self.revision_tree)
1497 by Robert Collins
Move Branch.read_working_inventory to WorkingTree.
1334
1997.1.3 by Robert Collins
All WorkingTree methods which write to the tree, but not to the branch
1335
    @needs_tree_write_lock
1457.1.10 by Robert Collins
Move set_root_id to WorkingTree.
1336
    def set_root_id(self, file_id):
1337
        """Set the root id for this tree."""
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1338
        # for compatability
2858.2.4 by Martin Pool
Restore deprecated behaviour of accepting None for WorkingTree.set_root_id (thanks igc)
1339
        if file_id is None:
3400.3.6 by Martin Pool
Remove code deprecated prior to 1.1 and its tests
1340
            raise ValueError(
1341
                'WorkingTree.set_root_id with fileid=None')
1342
        file_id = osutils.safe_file_id(file_id)
2255.2.15 by Robert Collins
Dirstate - truncate state file fixing bug in saving a smaller file, get more tree_implementation tests passing.
1343
        self._set_root_id(file_id)
1344
1345
    def _set_root_id(self, file_id):
1346
        """Set the root id for this tree, in a format specific manner.
1347
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1348
        :param file_id: The file id to assign to the root. It must not be
2255.2.15 by Robert Collins
Dirstate - truncate state file fixing bug in saving a smaller file, get more tree_implementation tests passing.
1349
            present in the current inventory or an error will occur. It must
1350
            not be None, but rather a valid file id.
1351
        """
5777.5.2 by Jelmer Vernooij
Split inventory-specific methods and WorkingTree interface method
1352
        raise NotImplementedError(self._set_root_id)
1457.1.10 by Robert Collins
Move set_root_id to WorkingTree.
1353
1442.1.65 by Robert Collins
Branch.remove has been moved to WorkingTree.
1354
    def unlock(self):
1355
        """See Branch.unlock.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1356
1442.1.65 by Robert Collins
Branch.remove has been moved to WorkingTree.
1357
        WorkingTree locking just uses the Branch locking facilities.
1358
        This is current because all working trees have an embedded branch
1359
        within them. IF in the future, we were to make branch data shareable
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1360
        between multiple working trees, i.e. via shared storage, then we
1442.1.65 by Robert Collins
Branch.remove has been moved to WorkingTree.
1361
        would probably want to lock both the local tree, and the branch.
1362
        """
1852.4.2 by Robert Collins
Refactor workingtree.unlock to be cleaner, adding a trivial test for unlock. Introduces an explicit Format2 tree type, making the base WorkingTree cleaner to derive from.
1363
        raise NotImplementedError(self.unlock)
1442.1.65 by Robert Collins
Branch.remove has been moved to WorkingTree.
1364
1907.5.7 by Matthieu Moy
Coding style fixes thanks to jam.
1365
    _marker = object()
1366
2009.1.4 by Mark Hammond
First attempt to merge .dev and resolve the conflicts (but tests are
1367
    def update(self, change_reporter=None, possible_transports=None,
5430.7.1 by Rory Yorke
Added --show-base to pull and update (bug 202374).
1368
               revision=None, old_tip=_marker, show_base=False):
1587.1.11 by Robert Collins
Local commits appear to be working properly.
1369
        """Update a working tree along its branch.
1370
1731.1.33 by Aaron Bentley
Revert no-special-root changes
1371
        This will update the branch if its bound too, which means we have
1372
        multiple trees involved:
1373
1374
        - The new basis tree of the master.
1375
        - The old basis tree of the branch.
1376
        - The old basis tree of the working tree.
1377
        - The current working tree state.
1378
1379
        Pathologically, all three may be different, and non-ancestors of each
1380
        other.  Conceptually we want to:
1381
1382
        - Preserve the wt.basis->wt.state changes
1383
        - Transform the wt.basis to the new master basis.
1384
        - Apply a merge of the old branch basis to get any 'local' changes from
1385
          it into the tree.
1386
        - Restore the wt.basis->wt.state changes.
1587.1.11 by Robert Collins
Local commits appear to be working properly.
1387
1388
        There isn't a single operation at the moment to do that, so we:
5891.1.2 by Andrew Bennetts
Fix a bunch of docstring formatting nits, making pydoctor a bit happier.
1389
1731.1.33 by Aaron Bentley
Revert no-special-root changes
1390
        - Merge current state -> basis tree of the master w.r.t. the old tree
1391
          basis.
1392
        - Do a 'normal' merge of the old branch basis if it is relevant.
1907.5.4 by Matthieu Moy
Added test-cases for update -r. Tweaked the implementation too.
1393
2009.1.2 by John Arbash Meinel
minor whitespace cleanup.
1394
        :param revision: The target revision to update to. Must be in the
1395
            revision history.
1396
        :param old_tip: If branch.update() has already been run, the value it
1397
            returned (old tip of the branch or None). _marker is used
1398
            otherwise.
1587.1.11 by Robert Collins
Local commits appear to be working properly.
1399
        """
3280.5.1 by John Arbash Meinel
Avoid opening the master branch when we won't use it.
1400
        if self.branch.get_bound_location() is not None:
2084.2.1 by Aaron Bentley
Support updating lightweight checkouts of readonly branches
1401
            self.lock_write()
2009.1.6 by Mark Hammond
more tweaks of the merge to get the tests passing.
1402
            update_branch = (old_tip is self._marker)
2084.2.1 by Aaron Bentley
Support updating lightweight checkouts of readonly branches
1403
        else:
1404
            self.lock_tree_write()
1405
            update_branch = False
1406
        try:
1407
            if update_branch:
2806.2.2 by Vincent Ladeuil
Fix #128076 and #131396 by reusing bound branch transport.
1408
                old_tip = self.branch.update(possible_transports)
2084.2.1 by Aaron Bentley
Support updating lightweight checkouts of readonly branches
1409
            else:
2009.1.6 by Mark Hammond
more tweaks of the merge to get the tests passing.
1410
                if old_tip is self._marker:
1411
                    old_tip = None
5430.7.1 by Rory Yorke
Added --show-base to pull and update (bug 202374).
1412
            return self._update_tree(old_tip, change_reporter, revision, show_base)
2084.2.1 by Aaron Bentley
Support updating lightweight checkouts of readonly branches
1413
        finally:
1414
            self.unlock()
1415
1416
    @needs_tree_write_lock
5430.7.1 by Rory Yorke
Added --show-base to pull and update (bug 202374).
1417
    def _update_tree(self, old_tip=None, change_reporter=None, revision=None,
1418
                     show_base=False):
2084.2.1 by Aaron Bentley
Support updating lightweight checkouts of readonly branches
1419
        """Update a tree to the master branch.
1420
1421
        :param old_tip: if supplied, the previous tip revision the branch,
1422
            before it was changed to the master branch's tip.
1423
        """
1927.2.3 by Robert Collins
review comment application - paired with Martin.
1424
        # here if old_tip is not None, it is the old tip of the branch before
1425
        # it was updated from the master branch. This should become a pending
1426
        # merge in the working tree to preserve the user existing work.  we
1427
        # cant set that until we update the working trees last revision to be
1428
        # one from the new branch, because it will just get absorbed by the
1429
        # parent de-duplication logic.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1430
        #
1927.2.3 by Robert Collins
review comment application - paired with Martin.
1431
        # We MUST save it even if an error occurs, because otherwise the users
1432
        # local work is unreferenced and will appear to have been lost.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1433
        #
4985.3.17 by Vincent Ladeuil
Some cleanup.
1434
        nb_conflicts = 0
1907.5.13 by Matthieu Moy
Fixed bad conflict resolution.
1435
        try:
1436
            last_rev = self.get_parent_ids()[0]
1437
        except IndexError:
2598.5.1 by Aaron Bentley
Start eliminating the use of None to indicate null revision
1438
            last_rev = _mod_revision.NULL_REVISION
1907.5.8 by Matthieu Moy
merge (with conflicts)
1439
        if revision is None:
1907.5.13 by Matthieu Moy
Fixed bad conflict resolution.
1440
            revision = self.branch.last_revision()
4985.3.17 by Vincent Ladeuil
Some cleanup.
1441
4985.3.14 by Gerard Krol
Don't compare old_tip to revision, just do the merge.
1442
        old_tip = old_tip or _mod_revision.NULL_REVISION
4985.3.17 by Vincent Ladeuil
Some cleanup.
1443
4985.3.15 by Gerard Krol
Now correctly determine the branch point (instead of some lucky guesses)
1444
        if not _mod_revision.is_null(old_tip) and old_tip != last_rev:
4985.3.14 by Gerard Krol
Don't compare old_tip to revision, just do the merge.
1445
            # the branch we are bound to was updated
1446
            # merge those changes in first
1447
            base_tree  = self.basis_tree()
4985.3.1 by Gerard Krol
Werkt wel ok
1448
            other_tree = self.branch.repository.revision_tree(old_tip)
4985.3.17 by Vincent Ladeuil
Some cleanup.
1449
            nb_conflicts = merge.merge_inner(self.branch, other_tree,
1450
                                             base_tree, this_tree=self,
5430.7.1 by Rory Yorke
Added --show-base to pull and update (bug 202374).
1451
                                             change_reporter=change_reporter,
1452
                                             show_base=show_base)
4985.3.17 by Vincent Ladeuil
Some cleanup.
1453
            if nb_conflicts:
4985.3.14 by Gerard Krol
Don't compare old_tip to revision, just do the merge.
1454
                self.add_parent_tree((old_tip, other_tree))
6138.3.4 by Jonathan Riddell
add gettext() to uses of trace.note()
1455
                note(gettext('Rerun update after fixing the conflicts.'))
4985.3.17 by Vincent Ladeuil
Some cleanup.
1456
                return nb_conflicts
4985.3.1 by Gerard Krol
Werkt wel ok
1457
2009.1.4 by Mark Hammond
First attempt to merge .dev and resolve the conflicts (but tests are
1458
        if last_rev != _mod_revision.ensure_null(revision):
4985.3.15 by Gerard Krol
Now correctly determine the branch point (instead of some lucky guesses)
1459
            # the working tree is up to date with the branch
1460
            # we can merge the specified revision from master
1461
            to_tree = self.branch.repository.revision_tree(revision)
1462
            to_root_id = to_tree.get_root_id()
1463
1927.2.3 by Robert Collins
review comment application - paired with Martin.
1464
            basis = self.basis_tree()
2255.2.44 by Robert Collins
Fix tree unlock on readonly Format4 trees with dirty hashcache.
1465
            basis.lock_read()
1466
            try:
5777.5.2 by Jelmer Vernooij
Split inventory-specific methods and WorkingTree interface method
1467
                if (basis.get_root_id() is None or basis.get_root_id() != to_root_id):
4634.123.10 by John Arbash Meinel
update now properly handles root-id changes.
1468
                    self.set_root_id(to_root_id)
2255.6.6 by Aaron Bentley
Fix update to set unique roots, and work with dirstate
1469
                    self.flush()
2255.2.44 by Robert Collins
Fix tree unlock on readonly Format4 trees with dirty hashcache.
1470
            finally:
1471
                basis.unlock()
4985.3.15 by Gerard Krol
Now correctly determine the branch point (instead of some lucky guesses)
1472
1473
            # determine the branch point
1474
            graph = self.branch.repository.get_graph()
4985.3.17 by Vincent Ladeuil
Some cleanup.
1475
            base_rev_id = graph.find_unique_lca(self.branch.last_revision(),
1476
                                                last_rev)
4985.3.15 by Gerard Krol
Now correctly determine the branch point (instead of some lucky guesses)
1477
            base_tree = self.branch.repository.revision_tree(base_rev_id)
1478
4985.3.17 by Vincent Ladeuil
Some cleanup.
1479
            nb_conflicts = merge.merge_inner(self.branch, to_tree, base_tree,
1480
                                             this_tree=self,
5430.7.1 by Rory Yorke
Added --show-base to pull and update (bug 202374).
1481
                                             change_reporter=change_reporter,
1482
                                             show_base=show_base)
4985.3.15 by Gerard Krol
Now correctly determine the branch point (instead of some lucky guesses)
1483
            self.set_last_revision(revision)
1908.6.6 by Robert Collins
Merge updated set_parents api.
1484
            # TODO - dedup parents list with things merged by pull ?
1485
            # reuse the tree we've updated to to set the basis:
1907.5.11 by Matthieu Moy
Simple fixes (deprecation warning, use revision where needed)
1486
            parent_trees = [(revision, to_tree)]
1908.6.6 by Robert Collins
Merge updated set_parents api.
1487
            merges = self.get_parent_ids()[1:]
1488
            # Ideally we ask the tree for the trees here, that way the working
1907.5.12 by Matthieu Moy
Manage InvalidRevisionSpec in update command.
1489
            # tree can decide whether to give us the entire tree or give us a
1908.6.6 by Robert Collins
Merge updated set_parents api.
1490
            # lazy initialised tree. dirstate for instance will have the trees
1491
            # in ram already, whereas a last-revision + basis-inventory tree
1492
            # will not, but also does not need them when setting parents.
1493
            for parent in merges:
1494
                parent_trees.append(
1495
                    (parent, self.branch.repository.revision_tree(parent)))
4985.3.14 by Gerard Krol
Don't compare old_tip to revision, just do the merge.
1496
            if not _mod_revision.is_null(old_tip):
1497
                parent_trees.append(
1498
                    (old_tip, self.branch.repository.revision_tree(old_tip)))
1908.6.6 by Robert Collins
Merge updated set_parents api.
1499
            self.set_parent_trees(parent_trees)
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
1500
            last_rev = parent_trees[0][0]
4985.3.17 by Vincent Ladeuil
Some cleanup.
1501
        return nb_conflicts
1508.1.24 by Robert Collins
Add update command for use with checkouts.
1502
1534.10.22 by Aaron Bentley
Got ConflictList implemented
1503
    def set_conflicts(self, arg):
2206.1.7 by Marius Kruger
* errors
1504
        raise errors.UnsupportedOperation(self.set_conflicts, self)
1534.10.8 by Aaron Bentley
Implemented conflict_lines in terms of old system on WorkingTree
1505
1551.7.11 by Aaron Bentley
Add WorkingTree.add_conflicts
1506
    def add_conflicts(self, arg):
2206.1.7 by Marius Kruger
* errors
1507
        raise errors.UnsupportedOperation(self.add_conflicts, self)
1551.7.11 by Aaron Bentley
Add WorkingTree.add_conflicts
1508
1534.10.22 by Aaron Bentley
Got ConflictList implemented
1509
    def conflicts(self):
5582.10.47 by Jelmer Vernooij
Move some upgrade tests that rely on bzrdirformat 0.0.4.
1510
        raise NotImplementedError(self.conflicts)
1534.10.22 by Aaron Bentley
Got ConflictList implemented
1511
1852.15.3 by Robert Collins
Add a first-cut Tree.walkdirs method.
1512
    def walkdirs(self, prefix=""):
2255.2.18 by Robert Collins
Dirstate: all tree_implementation tests passing.
1513
        """Walk the directories of this tree.
1514
2292.1.25 by Marius Kruger
* Add utility method delta.get_changes_as_text to get the output of .show()
1515
        returns a generator which yields items in the form:
2292.1.30 by Marius Kruger
* Minor text fixes.
1516
                ((curren_directory_path, fileid),
2292.1.25 by Marius Kruger
* Add utility method delta.get_changes_as_text to get the output of .show()
1517
                 [(file1_path, file1_name, file1_kind, (lstat), file1_id,
1518
                   file1_kind), ... ])
1519
2255.2.18 by Robert Collins
Dirstate: all tree_implementation tests passing.
1520
        This API returns a generator, which is only valid during the current
1521
        tree transaction - within a single lock_read or lock_write duration.
1522
2292.1.25 by Marius Kruger
* Add utility method delta.get_changes_as_text to get the output of .show()
1523
        If the tree is not locked, it may cause an error to be raised,
1524
        depending on the tree implementation.
2255.2.18 by Robert Collins
Dirstate: all tree_implementation tests passing.
1525
        """
1852.15.7 by Robert Collins
Start testing behaviour of unknowns in WorkingTree.walkdirs.
1526
        disk_top = self.abspath(prefix)
1527
        if disk_top.endswith('/'):
1528
            disk_top = disk_top[:-1]
1529
        top_strip_len = len(disk_top) + 1
1852.15.11 by Robert Collins
Tree.walkdirs handles missing contents in workingtrees.
1530
        inventory_iterator = self._walkdirs(prefix)
1852.15.7 by Robert Collins
Start testing behaviour of unknowns in WorkingTree.walkdirs.
1531
        disk_iterator = osutils.walkdirs(disk_top, prefix)
1852.15.10 by Robert Collins
Tweak the Tree.walkdirs interface more to be more useful.
1532
        try:
6634.2.1 by Martin
Apply 2to3 next fixer and make compatible
1533
            current_disk = next(disk_iterator)
1852.15.11 by Robert Collins
Tree.walkdirs handles missing contents in workingtrees.
1534
            disk_finished = False
6619.3.2 by Jelmer Vernooij
Apply 2to3 except fix.
1535
        except OSError as e:
2423.2.1 by Alexander Belchenko
Fix for walkdirs in missing dir with Py2.4 @ win32
1536
            if not (e.errno == errno.ENOENT or
1537
                (sys.platform == 'win32' and e.errno == ERROR_PATH_NOT_FOUND)):
1852.15.11 by Robert Collins
Tree.walkdirs handles missing contents in workingtrees.
1538
                raise
1539
            current_disk = None
1540
            disk_finished = True
1541
        try:
6634.2.1 by Martin
Apply 2to3 next fixer and make compatible
1542
            current_inv = next(inventory_iterator)
1852.15.10 by Robert Collins
Tweak the Tree.walkdirs interface more to be more useful.
1543
            inv_finished = False
1544
        except StopIteration:
1545
            current_inv = None
1546
            inv_finished = True
1852.15.7 by Robert Collins
Start testing behaviour of unknowns in WorkingTree.walkdirs.
1547
        while not inv_finished or not disk_finished:
2457.2.3 by Marius Kruger
factor out tuples into better readable variables
1548
            if current_disk:
1549
                ((cur_disk_dir_relpath, cur_disk_dir_path_from_top),
1550
                    cur_disk_dir_content) = current_disk
1551
            else:
1552
                ((cur_disk_dir_relpath, cur_disk_dir_path_from_top),
1553
                    cur_disk_dir_content) = ((None, None), None)
1852.15.7 by Robert Collins
Start testing behaviour of unknowns in WorkingTree.walkdirs.
1554
            if not disk_finished:
1555
                # strip out .bzr dirs
2457.2.3 by Marius Kruger
factor out tuples into better readable variables
1556
                if (cur_disk_dir_path_from_top[top_strip_len:] == '' and
1557
                    len(cur_disk_dir_content) > 0):
1558
                    # osutils.walkdirs can be made nicer -
1852.15.7 by Robert Collins
Start testing behaviour of unknowns in WorkingTree.walkdirs.
1559
                    # yield the path-from-prefix rather than the pathjoined
1560
                    # value.
2457.2.3 by Marius Kruger
factor out tuples into better readable variables
1561
                    bzrdir_loc = bisect_left(cur_disk_dir_content,
1562
                        ('.bzr', '.bzr'))
3719.1.1 by Vincent Ladeuil
Fix bug #272648
1563
                    if (bzrdir_loc < len(cur_disk_dir_content)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
1564
                        and self.controldir.is_control_filename(
4324.5.1 by Jelmer Vernooij
Use utility function to check for control filename rather than assuming it is '.bzr.'
1565
                            cur_disk_dir_content[bzrdir_loc][0])):
1852.15.7 by Robert Collins
Start testing behaviour of unknowns in WorkingTree.walkdirs.
1566
                        # we dont yield the contents of, or, .bzr itself.
2457.2.3 by Marius Kruger
factor out tuples into better readable variables
1567
                        del cur_disk_dir_content[bzrdir_loc]
1852.15.10 by Robert Collins
Tweak the Tree.walkdirs interface more to be more useful.
1568
            if inv_finished:
1569
                # everything is unknown
1852.15.12 by Robert Collins
WorkingTree.walkdirs handling of changing file kinds, and multi-directory with missing and unknown ordering bugfix.
1570
                direction = 1
1852.15.11 by Robert Collins
Tree.walkdirs handles missing contents in workingtrees.
1571
            elif disk_finished:
1572
                # everything is missing
1852.15.12 by Robert Collins
WorkingTree.walkdirs handling of changing file kinds, and multi-directory with missing and unknown ordering bugfix.
1573
                direction = -1
1852.15.10 by Robert Collins
Tweak the Tree.walkdirs interface more to be more useful.
1574
            else:
2457.2.3 by Marius Kruger
factor out tuples into better readable variables
1575
                direction = cmp(current_inv[0][0], cur_disk_dir_relpath)
1852.15.12 by Robert Collins
WorkingTree.walkdirs handling of changing file kinds, and multi-directory with missing and unknown ordering bugfix.
1576
            if direction > 0:
1852.15.10 by Robert Collins
Tweak the Tree.walkdirs interface more to be more useful.
1577
                # disk is before inventory - unknown
1852.15.11 by Robert Collins
Tree.walkdirs handles missing contents in workingtrees.
1578
                dirblock = [(relpath, basename, kind, stat, None, None) for
2457.2.7 by Marius Kruger
extract method as per review request
1579
                    relpath, basename, kind, stat, top_path in
2457.2.3 by Marius Kruger
factor out tuples into better readable variables
1580
                    cur_disk_dir_content]
1581
                yield (cur_disk_dir_relpath, None), dirblock
1852.15.7 by Robert Collins
Start testing behaviour of unknowns in WorkingTree.walkdirs.
1582
                try:
6634.2.1 by Martin
Apply 2to3 next fixer and make compatible
1583
                    current_disk = next(disk_iterator)
1852.15.7 by Robert Collins
Start testing behaviour of unknowns in WorkingTree.walkdirs.
1584
                except StopIteration:
1585
                    disk_finished = True
1852.15.12 by Robert Collins
WorkingTree.walkdirs handling of changing file kinds, and multi-directory with missing and unknown ordering bugfix.
1586
            elif direction < 0:
1852.15.10 by Robert Collins
Tweak the Tree.walkdirs interface more to be more useful.
1587
                # inventory is before disk - missing.
1852.15.11 by Robert Collins
Tree.walkdirs handles missing contents in workingtrees.
1588
                dirblock = [(relpath, basename, 'unknown', None, fileid, kind)
2457.2.7 by Marius Kruger
extract method as per review request
1589
                    for relpath, basename, dkind, stat, fileid, kind in
1852.15.11 by Robert Collins
Tree.walkdirs handles missing contents in workingtrees.
1590
                    current_inv[1]]
1591
                yield (current_inv[0][0], current_inv[0][1]), dirblock
1852.15.7 by Robert Collins
Start testing behaviour of unknowns in WorkingTree.walkdirs.
1592
                try:
6634.2.1 by Martin
Apply 2to3 next fixer and make compatible
1593
                    current_inv = next(inventory_iterator)
1852.15.7 by Robert Collins
Start testing behaviour of unknowns in WorkingTree.walkdirs.
1594
                except StopIteration:
1595
                    inv_finished = True
1596
            else:
1597
                # versioned present directory
1598
                # merge the inventory and disk data together
1599
                dirblock = []
1852.15.11 by Robert Collins
Tree.walkdirs handles missing contents in workingtrees.
1600
                for relpath, subiterator in itertools.groupby(sorted(
2457.2.7 by Marius Kruger
extract method as per review request
1601
                    current_inv[1] + cur_disk_dir_content,
2457.2.3 by Marius Kruger
factor out tuples into better readable variables
1602
                    key=operator.itemgetter(0)), operator.itemgetter(1)):
1852.15.7 by Robert Collins
Start testing behaviour of unknowns in WorkingTree.walkdirs.
1603
                    path_elements = list(subiterator)
1604
                    if len(path_elements) == 2:
1852.15.12 by Robert Collins
WorkingTree.walkdirs handling of changing file kinds, and multi-directory with missing and unknown ordering bugfix.
1605
                        inv_row, disk_row = path_elements
1852.15.7 by Robert Collins
Start testing behaviour of unknowns in WorkingTree.walkdirs.
1606
                        # versioned, present file
1852.15.12 by Robert Collins
WorkingTree.walkdirs handling of changing file kinds, and multi-directory with missing and unknown ordering bugfix.
1607
                        dirblock.append((inv_row[0],
1608
                            inv_row[1], disk_row[2],
1609
                            disk_row[3], inv_row[4],
1610
                            inv_row[5]))
1852.15.7 by Robert Collins
Start testing behaviour of unknowns in WorkingTree.walkdirs.
1611
                    elif len(path_elements[0]) == 5:
1612
                        # unknown disk file
1852.15.11 by Robert Collins
Tree.walkdirs handles missing contents in workingtrees.
1613
                        dirblock.append((path_elements[0][0],
1614
                            path_elements[0][1], path_elements[0][2],
1615
                            path_elements[0][3], None, None))
1616
                    elif len(path_elements[0]) == 6:
1617
                        # versioned, absent file.
1618
                        dirblock.append((path_elements[0][0],
1619
                            path_elements[0][1], 'unknown', None,
1620
                            path_elements[0][4], path_elements[0][5]))
1621
                    else:
1622
                        raise NotImplementedError('unreachable code')
1852.15.7 by Robert Collins
Start testing behaviour of unknowns in WorkingTree.walkdirs.
1623
                yield current_inv[0], dirblock
1624
                try:
6634.2.1 by Martin
Apply 2to3 next fixer and make compatible
1625
                    current_inv = next(inventory_iterator)
1852.15.7 by Robert Collins
Start testing behaviour of unknowns in WorkingTree.walkdirs.
1626
                except StopIteration:
1627
                    inv_finished = True
1628
                try:
6634.2.1 by Martin
Apply 2to3 next fixer and make compatible
1629
                    current_disk = next(disk_iterator)
1852.15.7 by Robert Collins
Start testing behaviour of unknowns in WorkingTree.walkdirs.
1630
                except StopIteration:
1631
                    disk_finished = True
1632
1633
    def _walkdirs(self, prefix=""):
2292.1.25 by Marius Kruger
* Add utility method delta.get_changes_as_text to get the output of .show()
1634
        """Walk the directories of this tree.
1635
5891.1.2 by Andrew Bennetts
Fix a bunch of docstring formatting nits, making pydoctor a bit happier.
1636
        :param prefix: is used as the directrory to start with.
1637
        :returns: a generator which yields items in the form::
1638
1639
            ((curren_directory_path, fileid),
1640
             [(file1_path, file1_name, file1_kind, None, file1_id,
1641
               file1_kind), ... ])
2292.1.25 by Marius Kruger
* Add utility method delta.get_changes_as_text to get the output of .show()
1642
        """
5777.5.2 by Jelmer Vernooij
Split inventory-specific methods and WorkingTree interface method
1643
        raise NotImplementedError(self._walkdirs)
1852.15.3 by Robert Collins
Add a first-cut Tree.walkdirs method.
1644
2120.7.2 by Aaron Bentley
Move autoresolve functionality to workingtree
1645
    @needs_tree_write_lock
1646
    def auto_resolve(self):
1647
        """Automatically resolve text conflicts according to contents.
1648
1649
        Only text conflicts are auto_resolvable. Files with no conflict markers
1650
        are considered 'resolved', because bzr always puts conflict markers
1651
        into files that have text conflicts.  The corresponding .THIS .BASE and
1652
        .OTHER files are deleted, as per 'resolve'.
5891.1.2 by Andrew Bennetts
Fix a bunch of docstring formatting nits, making pydoctor a bit happier.
1653
2120.7.2 by Aaron Bentley
Move autoresolve functionality to workingtree
1654
        :return: a tuple of ConflictLists: (un_resolved, resolved).
1655
        """
1656
        un_resolved = _mod_conflicts.ConflictList()
1657
        resolved = _mod_conflicts.ConflictList()
1658
        conflict_re = re.compile('^(<{7}|={7}|>{7})')
1659
        for conflict in self.conflicts():
2120.7.3 by Aaron Bentley
Update resolve command to automatically mark conflicts as resolved
1660
            if (conflict.typestring != 'text conflict' or
1661
                self.kind(conflict.file_id) != 'file'):
2120.7.2 by Aaron Bentley
Move autoresolve functionality to workingtree
1662
                un_resolved.append(conflict)
1663
                continue
1664
            my_file = open(self.id2abspath(conflict.file_id), 'rb')
1665
            try:
1666
                for line in my_file:
1667
                    if conflict_re.search(line):
1668
                        un_resolved.append(conflict)
1669
                        break
1670
                else:
1671
                    resolved.append(conflict)
1672
            finally:
1673
                my_file.close()
1674
        resolved.remove_files(self)
1675
        self.set_conflicts(un_resolved)
1676
        return un_resolved, resolved
1677
2371.2.1 by John Arbash Meinel
Update DirState._validate() to detect rename errors.
1678
    def _validate(self):
1679
        """Validate internal structures.
1680
1681
        This is meant mostly for the test suite. To give it a chance to detect
1682
        corruption after actions have occurred. The default implementation is a
1683
        just a no-op.
1684
1685
        :return: None. An exception should be raised if there is an error.
1686
        """
1687
        return
1688
5630.2.3 by John Arbash Meinel
Looks like it was a stale experimental .pyd file causing trouble. Tests pass again now.
1689
    def check_state(self):
1690
        """Check that the working state is/isn't valid."""
5850.1.2 by Jelmer Vernooij
Move inventory tree specific check implementation to InventoryWorkingTree.
1691
        raise NotImplementedError(self.check_state)
5630.2.4 by John Arbash Meinel
Basically works in the case where the dirstate isn't corrupted.
1692
1693
    def reset_state(self, revision_ids=None):
1694
        """Reset the state of the working tree.
1695
1696
        This does a hard-reset to a last-known-good state. This is a way to
1697
        fix if something got corrupted (like the .bzr/checkout/dirstate file)
1698
        """
5777.5.2 by Jelmer Vernooij
Split inventory-specific methods and WorkingTree interface method
1699
        raise NotImplementedError(self.reset_state)
5630.2.2 by John Arbash Meinel
Start fleshing out the design. Something weird is causing my tests to all fail.
1700
3398.1.24 by Ian Clatworthy
make iter_search_rules a tree method
1701
    def _get_rules_searcher(self, default_searcher):
1702
        """See Tree._get_rules_searcher."""
1703
        if self._rules_searcher is None:
1704
            self._rules_searcher = super(WorkingTree,
1705
                self)._get_rules_searcher(default_searcher)
1706
        return self._rules_searcher
1707
0.12.68 by Aaron Bentley
Update docs, move items to proper files.
1708
    def get_shelf_manager(self):
1709
        """Return the ShelfManager for this WorkingTree."""
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
1710
        from .shelf import ShelfManager
0.12.68 by Aaron Bentley
Update docs, move items to proper files.
1711
        return ShelfManager(self, self._transport)
1712
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
1713
5669.3.9 by Jelmer Vernooij
Consistent naming.
1714
class WorkingTreeFormatRegistry(controldir.ControlComponentFormatRegistry):
5662.3.1 by Jelmer Vernooij
Add WorkingTreeFormatRegistry.
1715
    """Registry for working tree formats."""
1716
1717
    def __init__(self, other_registry=None):
1718
        super(WorkingTreeFormatRegistry, self).__init__(other_registry)
1719
        self._default_format = None
5816.2.1 by Jelmer Vernooij
Allow lazily setting default for working trees.
1720
        self._default_format_key = None
5662.3.1 by Jelmer Vernooij
Add WorkingTreeFormatRegistry.
1721
1722
    def get_default(self):
1723
        """Return the current default format."""
5816.2.1 by Jelmer Vernooij
Allow lazily setting default for working trees.
1724
        if (self._default_format_key is not None and
1725
            self._default_format is None):
1726
            self._default_format = self.get(self._default_format_key)
5662.3.1 by Jelmer Vernooij
Add WorkingTreeFormatRegistry.
1727
        return self._default_format
1728
1729
    def set_default(self, format):
5816.2.3 by Jelmer Vernooij
Add docstrings.
1730
        """Set the default format."""
5662.3.1 by Jelmer Vernooij
Add WorkingTreeFormatRegistry.
1731
        self._default_format = format
5816.2.1 by Jelmer Vernooij
Allow lazily setting default for working trees.
1732
        self._default_format_key = None
1733
1734
    def set_default_key(self, format_string):
5816.2.3 by Jelmer Vernooij
Add docstrings.
1735
        """Set the default format by its format string."""
5816.2.1 by Jelmer Vernooij
Allow lazily setting default for working trees.
1736
        self._default_format_key = format_string
1737
        self._default_format = None
5662.3.1 by Jelmer Vernooij
Add WorkingTreeFormatRegistry.
1738
1739
1740
format_registry = WorkingTreeFormatRegistry()
1741
1742
5669.3.10 by Jelmer Vernooij
Use ControlComponentFormat.
1743
class WorkingTreeFormat(controldir.ControlComponentFormat):
1534.4.45 by Robert Collins
Start WorkingTree -> .bzr/checkout transition
1744
    """An encapsulation of the initialization and open routines for a format.
1745
1746
    Formats provide three things:
1747
     * An initialization routine,
1748
     * a format string,
1749
     * an open routine.
1750
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1751
    Formats are placed in an dict by their format string for reference
1534.4.45 by Robert Collins
Start WorkingTree -> .bzr/checkout transition
1752
    during workingtree opening. Its not required that these be instances, they
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1753
    can be classes themselves with class methods - it simply depends on
1534.4.45 by Robert Collins
Start WorkingTree -> .bzr/checkout transition
1754
    whether state is needed for a given format or not.
1755
1756
    Once a format is deprecated, just deprecate the initialize and open
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1757
    methods on the format class. Do not deprecate the object, as the
1534.4.45 by Robert Collins
Start WorkingTree -> .bzr/checkout transition
1758
    object will be created every time regardless.
1759
    """
1760
2100.3.14 by Aaron Bentley
Test workingtree4 format, prevent use with old repos
1761
    requires_rich_root = False
1762
2323.6.4 by Martin Pool
BzrDir._check_supported now also takes care of recommending upgrades, which
1763
    upgrade_recommended = False
1764
5582.10.29 by Jelmer Vernooij
Add requires_normalized_unicode_filenames
1765
    requires_normalized_unicode_filenames = False
1766
5632.1.1 by John Arbash Meinel
Make case_sensitive_filename an attribute of the format.
1767
    case_sensitive_filename = "FoRMaT"
1768
5661.1.1 by Jelmer Vernooij
Add 'WorkingTreeFormat.missing_parent_conflicts' flag to use in tests.
1769
    missing_parent_conflicts = False
1770
    """If this format supports missing parent conflicts."""
1771
5993.3.1 by Jelmer Vernooij
Add WorkingTreeFormat.supports_versioned_directories attribute.
1772
    supports_versioned_directories = None
1773
6207.3.3 by jelmer at samba
Fix tests and the like.
1774
    def initialize(self, controldir, revision_id=None, from_branch=None,
5683.1.1 by Jelmer Vernooij
Add stub WorkingTreeFormat.initialize().
1775
                   accelerator_tree=None, hardlink=False):
6207.3.3 by jelmer at samba
Fix tests and the like.
1776
        """Initialize a new working tree in controldir.
5683.1.1 by Jelmer Vernooij
Add stub WorkingTreeFormat.initialize().
1777
6207.3.3 by jelmer at samba
Fix tests and the like.
1778
        :param controldir: ControlDir to initialize the working tree in.
5683.1.1 by Jelmer Vernooij
Add stub WorkingTreeFormat.initialize().
1779
        :param revision_id: allows creating a working tree at a different
1780
            revision than the branch is at.
1781
        :param from_branch: Branch to checkout
1782
        :param accelerator_tree: A tree which can be used for retrieving file
1783
            contents more quickly than the revision tree, i.e. a workingtree.
1784
            The revision tree will be used for cases where accelerator_tree's
1785
            content is different.
1786
        :param hardlink: If true, hard-link files from accelerator_tree,
1787
            where possible.
1788
        """
1789
        raise NotImplementedError(self.initialize)
1790
2100.3.35 by Aaron Bentley
equality operations on bzrdir
1791
    def __eq__(self, other):
1792
        return self.__class__ is other.__class__
1793
1794
    def __ne__(self, other):
1795
        return not (self == other)
1796
1624.3.19 by Olaf Conradi
New call get_format_description to give a user-friendly description of a
1797
    def get_format_description(self):
1798
        """Return the short description for this format."""
1799
        raise NotImplementedError(self.get_format_description)
1800
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
1801
    def is_supported(self):
1802
        """Is this format supported?
1803
1804
        Supported formats can be initialized and opened.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1805
        Unsupported formats may not support initialization or committing or
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
1806
        some other features depending on the reason for not being supported.
1807
        """
1808
        return True
1809
3907.2.1 by Ian Clatworthy
WorkingTreeFormat5 supporting content filtering and views
1810
    def supports_content_filtering(self):
1811
        """True if this format supports content filtering."""
1812
        return False
1813
3586.1.4 by Ian Clatworthy
first cut at tree-level view tests
1814
    def supports_views(self):
1815
        """True if this format supports stored views."""
1816
        return False
1817
6162.3.2 by Jelmer Vernooij
Add WorkingTreeFormat.get_controldir_for_branch().
1818
    def get_controldir_for_branch(self):
1819
        """Get the control directory format for creating branches.
1820
1821
        This is to support testing of working tree formats that can not exist
1822
        in the same control directory as a branch.
1823
        """
1824
        return self._matchingbzrdir
1825
1534.4.45 by Robert Collins
Start WorkingTree -> .bzr/checkout transition
1826
5662.3.1 by Jelmer Vernooij
Add WorkingTreeFormatRegistry.
1827
format_registry.register_lazy("Bazaar Working Tree Format 4 (bzr 0.15)\n",
6670.4.1 by Jelmer Vernooij
Update imports.
1828
    "breezy.bzr.workingtree_4", "WorkingTreeFormat4")
5662.3.1 by Jelmer Vernooij
Add WorkingTreeFormatRegistry.
1829
format_registry.register_lazy("Bazaar Working Tree Format 5 (bzr 1.11)\n",
6670.4.1 by Jelmer Vernooij
Update imports.
1830
    "breezy.bzr.workingtree_4", "WorkingTreeFormat5")
5662.3.1 by Jelmer Vernooij
Add WorkingTreeFormatRegistry.
1831
format_registry.register_lazy("Bazaar Working Tree Format 6 (bzr 1.14)\n",
6670.4.1 by Jelmer Vernooij
Update imports.
1832
    "breezy.bzr.workingtree_4", "WorkingTreeFormat6")
5816.5.1 by Jelmer Vernooij
Move WorkingTree3 to bzrlib.workingtree_3.
1833
format_registry.register_lazy("Bazaar-NG Working Tree format 3",
6670.4.1 by Jelmer Vernooij
Update imports.
1834
    "breezy.bzr.workingtree_3", "WorkingTreeFormat3")
5816.2.1 by Jelmer Vernooij
Allow lazily setting default for working trees.
1835
format_registry.set_default_key("Bazaar Working Tree Format 6 (bzr 1.14)\n")