/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.358.2 by Jelmer Vernooij
Refresh copyright headers, add my email.
1
# Copyright (C) 2008-2018 Jelmer Vernooij <jelmer@jelmer.uk>
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
2
#
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.
7
#
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.
12
#
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
0.358.1 by Jelmer Vernooij
Fix FSF address.
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
16
0.200.381 by Jelmer Vernooij
Support working trees properly, status and ls.
17
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
18
"""An adapter between a Git index and a Bazaar Working Tree"""
19
0.200.1594 by Jelmer Vernooij
Use absolute_import everywhere.
20
from __future__ import absolute_import
0.200.381 by Jelmer Vernooij
Support working trees properly, status and ls.
21
0.200.1731 by Jelmer Vernooij
Add support for checking untracked changes.
22
import itertools
0.200.1210 by Jelmer Vernooij
Implement GitWorkingTree._walkdirs.
23
from collections import defaultdict
0.239.4 by Jelmer Vernooij
Cope with nonexistent files and directories in get_file_sha1.
24
import errno
0.200.1655 by Jelmer Vernooij
Basic support for git ignores.
25
from dulwich.ignore import (
0.200.1658 by Jelmer Vernooij
Fix handling of ignores - return patterns that matched.
26
    IgnoreFilterManager,
0.200.1655 by Jelmer Vernooij
Basic support for git ignores.
27
    )
7447.3.1 by Jelmer Vernooij
Move tree reference info functions to workingtree.
28
from dulwich.config import ConfigFile as GitConfigFile
0.415.2 by Jelmer Vernooij
Write index manually.
29
from dulwich.file import GitFile, FileLocked
0.200.1096 by Jelmer Vernooij
Implement GitWorkingTreeFormat.initialize.
30
from dulwich.index import (
31
    Index,
0.415.2 by Jelmer Vernooij
Write index manually.
32
    SHA1Writer,
0.371.1 by Jelmer Vernooij
Implement WorkingTree.reset_state().
33
    build_index_from_tree,
0.391.6 by Jelmer Vernooij
Directly call index_entry_from_path.
34
    index_entry_from_path,
0.200.1531 by Jelmer Vernooij
Don't trust index contents - verify against file timestamps.
35
    index_entry_from_stat,
0.369.1 by Jelmer Vernooij
Implement conflict handling.
36
    FLAG_STAGEMASK,
0.429.10 by Jelmer Vernooij
use new read_submodule_head from dulwich.
37
    read_submodule_head,
0.373.1 by Jelmer Vernooij
Fix WorkingTree.reset_state().
38
    validate_path,
0.415.2 by Jelmer Vernooij
Write index manually.
39
    write_index_dict,
0.200.1096 by Jelmer Vernooij
Implement GitWorkingTreeFormat.initialize.
40
    )
0.200.1202 by Jelmer Vernooij
Implement has_or_had_id.
41
from dulwich.object_store import (
42
    tree_lookup_path,
43
    )
0.200.383 by Jelmer Vernooij
Simplify, support rewriting index based on inventory.
44
from dulwich.objects import (
0.373.1 by Jelmer Vernooij
Fix WorkingTree.reset_state().
45
    S_ISGITLINK,
0.429.5 by Jelmer Vernooij
Fix tree_content_summary test.
46
    )
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
47
import os
0.264.10 by Jelmer Vernooij
Yield inventory entries.
48
import posixpath
0.200.384 by Jelmer Vernooij
Fix reading of inventory from index.
49
import stat
0.200.1215 by Jelmer Vernooij
Implement GitWorkingTree.remove.
50
import sys
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
51
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
52
from .. import (
7447.3.1 by Jelmer Vernooij
Move tree reference info functions to workingtree.
53
    branch as _mod_branch,
0.369.1 by Jelmer Vernooij
Implement conflict handling.
54
    conflicts as _mod_conflicts,
0.200.382 by Jelmer Vernooij
Support flushing index.
55
    errors,
0.200.1752 by Jelmer Vernooij
Don't traverse nested trees in WorkingTree.smart_add.
56
    controldir as _mod_controldir,
0.200.1655 by Jelmer Vernooij
Basic support for git ignores.
57
    globbing,
0.200.1476 by Jelmer Vernooij
Cope with working tree refactoring.
58
    lock,
0.380.1 by Jelmer Vernooij
Implement WorkingTree.pull.
59
    merge,
0.200.381 by Jelmer Vernooij
Support working trees properly, status and ls.
60
    osutils,
0.200.1720 by Jelmer Vernooij
Fix handling of pending merges.
61
    revision as _mod_revision,
0.200.1215 by Jelmer Vernooij
Implement GitWorkingTree.remove.
62
    trace,
0.200.1752 by Jelmer Vernooij
Don't traverse nested trees in WorkingTree.smart_add.
63
    transport as _mod_transport,
0.200.519 by Jelmer Vernooij
Move imports down, might not be available in older bzr-git versions.
64
    tree,
7447.3.4 by Jelmer Vernooij
Fix tests.
65
    urlutils,
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
66
    workingtree,
67
    )
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
68
from ..decorators import (
0.383.1 by Jelmer Vernooij
Fix a bunch of locking issues.
69
    only_raises,
70
    )
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
71
from ..mutabletree import (
0.429.2 by Jelmer Vernooij
Some more work on submodule support.
72
    BadReferenceTarget,
0.200.1680 by Jelmer Vernooij
Fix repo locks.
73
    MutableTree,
74
    )
7404.2.1 by Jelmer Vernooij
Add a follow_tree_references argument to Tree.list_files.
75
from ..sixish import text_type
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
76
77
78
from .dir import (
0.200.1096 by Jelmer Vernooij
Implement GitWorkingTreeFormat.initialize.
79
    LocalGitDir,
80
    )
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
81
from .tree import (
0.360.1 by Jelmer Vernooij
Implement GitMemoryTree.
82
    MutableGitIndexTree,
0.200.617 by Jelmer Vernooij
Add custom InterTree for use between git revision trees.
83
    )
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
84
from .mapping import (
7490.70.1 by Jelmer Vernooij
Add functions for encoding/decoding git paths.
85
    encode_git_path,
86
    decode_git_path,
0.264.10 by Jelmer Vernooij
Yield inventory entries.
87
    mode_kind,
0.200.971 by Chadrik
Fix 'bzr status' after 'bzr add' in native git working trees.
88
    )
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
89
0.200.409 by Jelmer Vernooij
Support parsing .gitignore.
90
7143.15.2 by Jelmer Vernooij
Run autopep8.
91
class GitWorkingTree(MutableGitIndexTree, workingtree.WorkingTree):
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
92
    """A Git working tree."""
93
0.415.3 by Jelmer Vernooij
Open index on demand.
94
    def __init__(self, controldir, repo, branch):
0.360.1 by Jelmer Vernooij
Implement GitMemoryTree.
95
        MutableGitIndexTree.__init__(self)
0.200.1741 by Jelmer Vernooij
Fix opentree tests.
96
        basedir = controldir.root_transport.local_abspath('.')
97
        self.basedir = osutils.realpath(basedir)
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
98
        self.controldir = controldir
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
99
        self.repository = repo
0.200.1205 by Jelmer Vernooij
Implement GitWorkingTree.stored_kind.
100
        self.store = self.repository._git.object_store
0.200.384 by Jelmer Vernooij
Fix reading of inventory from index.
101
        self.mapping = self.repository.get_mapping()
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
102
        self._branch = branch
7131.3.1 by Jelmer Vernooij
When opening working trees with .git files, open the right control transport.
103
        self._transport = self.repository._git._controltransport
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
104
        self._format = GitWorkingTreeFormat()
0.415.3 by Jelmer Vernooij
Open index on demand.
105
        self.index = None
0.415.4 by Jelmer Vernooij
proper locking on index.
106
        self._index_file = None
0.200.239 by Jelmer Vernooij
Provide views.
107
        self.views = self._make_views()
0.200.1173 by Jelmer Vernooij
Provide GitWorkingTree._rules_searcher.
108
        self._rules_searcher = None
0.200.381 by Jelmer Vernooij
Support working trees properly, status and ls.
109
        self._detect_case_handling()
0.200.1202 by Jelmer Vernooij
Implement has_or_had_id.
110
        self._reset_data()
0.200.1476 by Jelmer Vernooij
Cope with working tree refactoring.
111
0.200.1650 by Jelmer Vernooij
Implement GitWorkingTree.supports_tree_reference.
112
    def supports_tree_reference(self):
0.429.2 by Jelmer Vernooij
Some more work on submodule support.
113
        return True
0.200.1650 by Jelmer Vernooij
Implement GitWorkingTree.supports_tree_reference.
114
0.349.1 by Jelmer Vernooij
Support supports_rename_tracking method.
115
    def supports_rename_tracking(self):
116
        return False
117
0.415.3 by Jelmer Vernooij
Open index on demand.
118
    def _read_index(self):
119
        self.index = Index(self.control_transport.local_abspath('index'))
120
        self._index_dirty = False
121
7404.2.1 by Jelmer Vernooij
Add a follow_tree_references argument to Tree.list_files.
122
    def _get_submodule_index(self, relpath):
123
        if not isinstance(relpath, bytes):
124
            raise TypeError(relpath)
125
        try:
126
            info = self._submodule_info()[relpath]
127
        except KeyError:
7490.70.1 by Jelmer Vernooij
Add functions for encoding/decoding git paths.
128
            index_path = os.path.join(self.basedir, decode_git_path(relpath), '.git', 'index')
7404.2.1 by Jelmer Vernooij
Add a follow_tree_references argument to Tree.list_files.
129
        else:
130
            index_path = self.control_transport.local_abspath(
7490.70.1 by Jelmer Vernooij
Add functions for encoding/decoding git paths.
131
                posixpath.join('modules', decode_git_path(info[1]), 'index'))
7404.2.1 by Jelmer Vernooij
Add a follow_tree_references argument to Tree.list_files.
132
        return Index(index_path)
133
0.200.1476 by Jelmer Vernooij
Cope with working tree refactoring.
134
    def lock_read(self):
135
        """Lock the repository for read operations.
136
0.200.1646 by Jelmer Vernooij
Rename bzrlib to breezy.
137
        :return: A breezy.lock.LogicalLockResult.
0.200.1476 by Jelmer Vernooij
Cope with working tree refactoring.
138
        """
139
        if not self._lock_mode:
140
            self._lock_mode = 'r'
141
            self._lock_count = 1
0.415.3 by Jelmer Vernooij
Open index on demand.
142
            self._read_index()
0.200.1476 by Jelmer Vernooij
Cope with working tree refactoring.
143
        else:
144
            self._lock_count += 1
145
        self.branch.lock_read()
146
        return lock.LogicalLockResult(self.unlock)
147
0.383.1 by Jelmer Vernooij
Fix a bunch of locking issues.
148
    def _lock_write_tree(self):
149
        if not self._lock_mode:
150
            self._lock_mode = 'w'
151
            self._lock_count = 1
0.415.4 by Jelmer Vernooij
proper locking on index.
152
            try:
7143.15.2 by Jelmer Vernooij
Run autopep8.
153
                self._index_file = GitFile(
154
                    self.control_transport.local_abspath('index'), 'wb')
0.415.4 by Jelmer Vernooij
proper locking on index.
155
            except FileLocked:
156
                raise errors.LockContention('index')
0.415.3 by Jelmer Vernooij
Open index on demand.
157
            self._read_index()
0.383.1 by Jelmer Vernooij
Fix a bunch of locking issues.
158
        elif self._lock_mode == 'r':
159
            raise errors.ReadOnlyError(self)
160
        else:
7143.15.2 by Jelmer Vernooij
Run autopep8.
161
            self._lock_count += 1
0.383.1 by Jelmer Vernooij
Fix a bunch of locking issues.
162
0.200.1477 by Jelmer Vernooij
Implement GitWorkingTree.lock_tree_write.
163
    def lock_tree_write(self):
164
        self.branch.lock_read()
0.383.1 by Jelmer Vernooij
Fix a bunch of locking issues.
165
        try:
166
            self._lock_write_tree()
167
            return lock.LogicalLockResult(self.unlock)
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
168
        except BaseException:
0.383.1 by Jelmer Vernooij
Fix a bunch of locking issues.
169
            self.branch.unlock()
170
            raise
0.200.1477 by Jelmer Vernooij
Implement GitWorkingTree.lock_tree_write.
171
0.200.1476 by Jelmer Vernooij
Cope with working tree refactoring.
172
    def lock_write(self, token=None):
173
        self.branch.lock_write()
0.383.1 by Jelmer Vernooij
Fix a bunch of locking issues.
174
        try:
175
            self._lock_write_tree()
176
            return lock.LogicalLockResult(self.unlock)
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
177
        except BaseException:
0.383.1 by Jelmer Vernooij
Fix a bunch of locking issues.
178
            self.branch.unlock()
179
            raise
0.200.1476 by Jelmer Vernooij
Cope with working tree refactoring.
180
181
    def is_locked(self):
182
        return self._lock_count >= 1
183
184
    def get_physical_lock_status(self):
185
        return False
186
0.415.4 by Jelmer Vernooij
proper locking on index.
187
    def break_lock(self):
188
        try:
189
            self.control_transport.delete('index.lock')
190
        except errors.NoSuchFile:
191
            pass
192
        self.branch.break_lock()
193
0.383.1 by Jelmer Vernooij
Fix a bunch of locking issues.
194
    @only_raises(errors.LockNotHeld, errors.LockBroken)
0.200.1476 by Jelmer Vernooij
Cope with working tree refactoring.
195
    def unlock(self):
196
        if not self._lock_count:
197
            return lock.cant_unlock_not_held(self)
0.383.1 by Jelmer Vernooij
Fix a bunch of locking issues.
198
        try:
199
            self._cleanup()
200
            self._lock_count -= 1
201
            if self._lock_count > 0:
202
                return
0.415.4 by Jelmer Vernooij
proper locking on index.
203
            if self._index_file is not None:
204
                if self._index_dirty:
205
                    self._flush(self._index_file)
206
                    self._index_file.close()
207
                else:
7067.11.1 by Jelmer Vernooij
Fix pull operations on Git repositories on Python 3.
208
                    # Something else already triggered a write of the index
209
                    # file by calling .flush()
0.415.5 by Jelmer Vernooij
Don't flush, just wait for unlock.
210
                    self._index_file.abort()
0.415.4 by Jelmer Vernooij
proper locking on index.
211
                self._index_file = None
0.383.1 by Jelmer Vernooij
Fix a bunch of locking issues.
212
            self._lock_mode = None
0.415.3 by Jelmer Vernooij
Open index on demand.
213
            self.index = None
0.383.1 by Jelmer Vernooij
Fix a bunch of locking issues.
214
        finally:
215
            self.branch.unlock()
0.200.1658 by Jelmer Vernooij
Fix handling of ignores - return patterns that matched.
216
0.360.1 by Jelmer Vernooij
Implement GitMemoryTree.
217
    def _cleanup(self):
218
        pass
219
0.200.1322 by Jelmer Vernooij
Add case detection.
220
    def _detect_case_handling(self):
221
        try:
222
            self._transport.stat(".git/cOnFiG")
223
        except errors.NoSuchFile:
224
            self.case_sensitive = True
225
        else:
226
            self.case_sensitive = False
227
7350.3.6 by Jelmer Vernooij
Support case sensitive argument.
228
    def get_transform(self, pb=None):
229
        from ..transform import TreeTransform
7350.3.8 by Jelmer Vernooij
Fix tests.
230
        return TreeTransform(self, pb=pb)
7350.3.6 by Jelmer Vernooij
Support case sensitive argument.
231
0.200.1315 by Jelmer Vernooij
Implement WorkingTree.merge_modified.
232
    def merge_modified(self):
233
        return {}
234
0.200.1696 by Jelmer Vernooij
Fix set_merge_modified.
235
    def set_merge_modified(self, modified_hashes):
0.298.1 by Jelmer Vernooij
mark GitWorkngTree.set_merge_modified as unsupported.
236
        raise errors.UnsupportedOperation(self.set_merge_modified, self)
0.200.1690 by Jelmer Vernooij
Implement WorkingTree.set_merge_modified.
237
0.200.1220 by Jelmer Vernooij
Support set_parent_trees.
238
    def set_parent_trees(self, parents_list, allow_leftmost_as_ghost=False):
239
        self.set_parent_ids([p for p, t in parents_list])
240
0.305.1 by Jelmer Vernooij
Reset RHS parents after commit.
241
    def _set_merges_from_parent_ids(self, rhs_parent_ids):
0.200.1779 by Jelmer Vernooij
Actually store git revision ids rather than bzr revision ids.
242
        try:
7143.15.2 by Jelmer Vernooij
Run autopep8.
243
            merges = [self.branch.lookup_bzr_revision_id(
244
                revid)[0] for revid in rhs_parent_ids]
0.200.1779 by Jelmer Vernooij
Actually store git revision ids rather than bzr revision ids.
245
        except errors.NoSuchRevision as e:
246
            raise errors.GhostRevisionUnusableHere(e.revision)
0.304.1 by Jelmer Vernooij
Delete MERGE_HEAD if there are no parent ids.
247
        if merges:
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
248
            self.control_transport.put_bytes(
249
                'MERGE_HEAD', b'\n'.join(merges),
250
                mode=self.controldir._get_file_mode())
0.304.1 by Jelmer Vernooij
Delete MERGE_HEAD if there are no parent ids.
251
        else:
252
            try:
253
                self.control_transport.delete('MERGE_HEAD')
254
            except errors.NoSuchFile:
255
                pass
0.200.1720 by Jelmer Vernooij
Fix handling of pending merges.
256
257
    def set_parent_ids(self, revision_ids, allow_leftmost_as_ghost=False):
258
        """Set the parent ids to revision_ids.
259
260
        See also set_parent_trees. This api will try to retrieve the tree data
261
        for each element of revision_ids from the trees repository. If you have
262
        tree data already available, it is more efficient to use
263
        set_parent_trees rather than set_parent_ids. set_parent_ids is however
264
        an easier API to use.
265
266
        :param revision_ids: The revision_ids to set as the parent ids of this
267
            working tree. Any of these may be ghosts.
268
        """
269
        with self.lock_tree_write():
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
270
            self._check_parents_for_ghosts(
271
                revision_ids, allow_leftmost_as_ghost=allow_leftmost_as_ghost)
0.200.1720 by Jelmer Vernooij
Fix handling of pending merges.
272
            for revision_id in revision_ids:
273
                _mod_revision.check_not_reserved_id(revision_id)
274
275
            revision_ids = self._filter_parent_ids_by_ancestry(revision_ids)
276
277
            if len(revision_ids) > 0:
278
                self.set_last_revision(revision_ids[0])
279
            else:
280
                self.set_last_revision(_mod_revision.NULL_REVISION)
281
0.305.1 by Jelmer Vernooij
Reset RHS parents after commit.
282
            self._set_merges_from_parent_ids(revision_ids[1:])
0.200.1720 by Jelmer Vernooij
Fix handling of pending merges.
283
284
    def get_parent_ids(self):
285
        """See Tree.get_parent_ids.
286
287
        This implementation reads the pending merges list and last_revision
288
        value and uses that to decide what the parents list should be.
289
        """
290
        last_rev = _mod_revision.ensure_null(self._last_revision())
291
        if _mod_revision.NULL_REVISION == last_rev:
292
            parents = []
293
        else:
294
            parents = [last_rev]
295
        try:
296
            merges_bytes = self.control_transport.get_bytes('MERGE_HEAD')
297
        except errors.NoSuchFile:
298
            pass
299
        else:
300
            for l in osutils.split_lines(merges_bytes):
7029.4.2 by Jelmer Vernooij
Fix more merge tests.
301
                revision_id = l.rstrip(b'\n')
7143.15.2 by Jelmer Vernooij
Run autopep8.
302
                parents.append(
303
                    self.branch.lookup_foreign_revision_id(revision_id))
0.200.1720 by Jelmer Vernooij
Fix handling of pending merges.
304
        return parents
305
0.200.1243 by Jelmer Vernooij
Implement WorkingTree.check_state.
306
    def check_state(self):
307
        """Check that the working state is/isn't valid."""
308
        pass
309
0.200.1215 by Jelmer Vernooij
Implement GitWorkingTree.remove.
310
    def remove(self, files, verbose=False, to_file=None, keep_files=True,
7143.15.2 by Jelmer Vernooij
Run autopep8.
311
               force=False):
0.200.1215 by Jelmer Vernooij
Implement GitWorkingTree.remove.
312
        """Remove nominated files from the working tree metadata.
313
314
        :param files: File paths relative to the basedir.
315
        :param keep_files: If true, the files will also be kept.
316
        :param force: Delete files and directories, even if they are changed
317
            and even if the directories are not empty.
318
        """
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
319
        if not isinstance(files, list):
0.200.1215 by Jelmer Vernooij
Implement GitWorkingTree.remove.
320
            files = [files]
321
322
        if to_file is None:
323
            to_file = sys.stdout
324
325
        def backup(file_to_backup):
326
            abs_path = self.abspath(file_to_backup)
7143.15.2 by Jelmer Vernooij
Run autopep8.
327
            backup_name = self.controldir._available_backup_name(
328
                file_to_backup)
0.200.1215 by Jelmer Vernooij
Implement GitWorkingTree.remove.
329
            osutils.rename(abs_path, self.abspath(backup_name))
330
            return "removed %s (but kept a copy: %s)" % (
331
                file_to_backup, backup_name)
332
0.357.1 by Jelmer Vernooij
Fix some remove tests.
333
        # Sort needed to first handle directory content before the directory
334
        files_to_backup = []
335
0.357.2 by Jelmer Vernooij
Fix more remove tests.
336
        all_files = set()
337
338
        def recurse_directory_to_add_files(directory):
339
            # Recurse directory and add all files
340
            # so we can check if they have changed.
341
            for parent_info, file_infos in self.walkdirs(directory):
342
                for relpath, basename, kind, lstat, fileid, kind in file_infos:
343
                    # Is it versioned or ignored?
344
                    if self.is_versioned(relpath):
345
                        # Add nested content for deletion.
346
                        all_files.add(relpath)
347
                    else:
348
                        # Files which are not versioned
349
                        # should be treated as unknown.
350
                        files_to_backup.append(relpath)
351
0.200.1675 by Jelmer Vernooij
Remove uses of decorators.
352
        with self.lock_tree_write():
0.357.2 by Jelmer Vernooij
Fix more remove tests.
353
            for filepath in files:
354
                # Get file name into canonical form.
355
                abspath = self.abspath(filepath)
356
                filepath = self.relpath(abspath)
357
358
                if filepath:
359
                    all_files.add(filepath)
360
                    recurse_directory_to_add_files(filepath)
361
362
            files = list(all_files)
363
364
            if len(files) == 0:
7143.15.2 by Jelmer Vernooij
Run autopep8.
365
                return  # nothing to do
0.357.2 by Jelmer Vernooij
Fix more remove tests.
366
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
367
            # Sort needed to first handle directory content before the
368
            # directory
0.357.2 by Jelmer Vernooij
Fix more remove tests.
369
            files.sort(reverse=True)
370
0.357.1 by Jelmer Vernooij
Fix some remove tests.
371
            # Bail out if we are going to delete files we shouldn't
372
            if not keep_files and not force:
7322.1.6 by Jelmer Vernooij
Use the new attributes on TreeChange.
373
                for change in self.iter_changes(
7322.1.7 by Jelmer Vernooij
Fix remaining tests.
374
                        self.basis_tree(), include_unchanged=True,
375
                        require_versioned=False, want_unversioned=True,
376
                        specific_files=files):
7322.1.6 by Jelmer Vernooij
Use the new attributes on TreeChange.
377
                    if change.versioned[0] is False:
0.357.1 by Jelmer Vernooij
Fix some remove tests.
378
                        # The record is unknown or newly added
7322.1.6 by Jelmer Vernooij
Use the new attributes on TreeChange.
379
                        files_to_backup.append(change.path[1])
7143.15.2 by Jelmer Vernooij
Run autopep8.
380
                        files_to_backup.extend(
7322.1.6 by Jelmer Vernooij
Use the new attributes on TreeChange.
381
                            osutils.parent_directories(change.path[1]))
7322.1.7 by Jelmer Vernooij
Fix remaining tests.
382
                    elif (change.changed_content and (change.kind[1] is not None)
7322.1.6 by Jelmer Vernooij
Use the new attributes on TreeChange.
383
                            and osutils.is_inside_any(files, change.path[1])):
0.357.1 by Jelmer Vernooij
Fix some remove tests.
384
                        # Versioned and changed, but not deleted, and still
385
                        # in one of the dirs to be deleted.
7322.1.6 by Jelmer Vernooij
Use the new attributes on TreeChange.
386
                        files_to_backup.append(change.path[1])
7143.15.2 by Jelmer Vernooij
Run autopep8.
387
                        files_to_backup.extend(
7322.1.6 by Jelmer Vernooij
Use the new attributes on TreeChange.
388
                            osutils.parent_directories(change.path[1]))
0.357.2 by Jelmer Vernooij
Fix more remove tests.
389
0.200.1675 by Jelmer Vernooij
Remove uses of decorators.
390
            for f in files:
0.200.1735 by Jelmer Vernooij
Fix remove tests.
391
                if f == '':
392
                    continue
0.357.1 by Jelmer Vernooij
Fix some remove tests.
393
394
                try:
395
                    kind = self.kind(f)
396
                except errors.NoSuchFile:
397
                    kind = None
398
399
                abs_path = self.abspath(f)
400
                if verbose:
401
                    # having removed it, it must be either ignored or unknown
402
                    if self.is_ignored(f):
403
                        new_status = 'I'
404
                    else:
405
                        new_status = '?'
406
                    kind_ch = osutils.kind_marker(kind)
407
                    to_file.write(new_status + '       ' + f + kind_ch + '\n')
408
                if kind is None:
409
                    message = "%s does not exist" % (f, )
0.200.1675 by Jelmer Vernooij
Remove uses of decorators.
410
                else:
0.357.1 by Jelmer Vernooij
Fix some remove tests.
411
                    if not keep_files:
412
                        if f in files_to_backup and not force:
0.357.2 by Jelmer Vernooij
Fix more remove tests.
413
                            message = backup(f)
0.200.1675 by Jelmer Vernooij
Remove uses of decorators.
414
                        else:
0.357.1 by Jelmer Vernooij
Fix some remove tests.
415
                            if kind == 'directory':
416
                                osutils.rmtree(abs_path)
417
                            else:
0.200.1675 by Jelmer Vernooij
Remove uses of decorators.
418
                                osutils.delete_any(abs_path)
0.357.2 by Jelmer Vernooij
Fix more remove tests.
419
                            message = "deleted %s" % (f,)
420
                    else:
421
                        message = "removed %s" % (f,)
0.357.1 by Jelmer Vernooij
Fix some remove tests.
422
                self._unversion_path(f)
0.200.1215 by Jelmer Vernooij
Implement GitWorkingTree.remove.
423
0.200.1675 by Jelmer Vernooij
Remove uses of decorators.
424
                # print only one message (if any) per file.
425
                if message is not None:
426
                    trace.note(message)
0.357.1 by Jelmer Vernooij
Fix some remove tests.
427
            self._versioned_dirs = None
0.200.1192 by Jelmer Vernooij
Implement path2id.
428
0.200.1240 by Jelmer Vernooij
Implement GitWorkingTree.smart_add.
429
    def smart_add(self, file_list, recurse=True, action=None, save=True):
0.200.1771 by Jelmer Vernooij
Fix implicit tree unicode add test.
430
        if not file_list:
431
            file_list = [u'.']
0.200.1781 by Jelmer Vernooij
Support expanding symlinks.
432
433
        # expand any symlinks in the directory part, while leaving the
434
        # filename alone
435
        # only expanding if symlinks are supported avoids windows path bugs
7122.6.3 by Jelmer Vernooij
Merge trunk.
436
        if self.supports_symlinks():
0.200.1781 by Jelmer Vernooij
Support expanding symlinks.
437
            file_list = list(map(osutils.normalizepath, file_list))
438
0.369.1 by Jelmer Vernooij
Implement conflict handling.
439
        conflicts_related = set()
440
        for c in self.conflicts():
441
            conflicts_related.update(c.associated_filenames())
442
0.200.1240 by Jelmer Vernooij
Implement GitWorkingTree.smart_add.
443
        added = []
444
        ignored = {}
445
        user_dirs = []
7143.15.2 by Jelmer Vernooij
Run autopep8.
446
0.200.1733 by Jelmer Vernooij
Support handling of custom ids in smart_add.
447
        def call_action(filepath, kind):
7141.3.2 by Jelmer Vernooij
add some tests.
448
            if filepath == '':
449
                return
0.200.1733 by Jelmer Vernooij
Support handling of custom ids in smart_add.
450
            if action is not None:
451
                parent_path = posixpath.dirname(filepath)
452
                parent_id = self.path2id(parent_path)
453
                parent_ie = self._get_dir_ie(parent_path, parent_id)
454
                file_id = action(self, parent_ie, filepath, kind)
455
                if file_id is not None:
456
                    raise workingtree.SettingFileIdUnsupported()
457
0.200.1675 by Jelmer Vernooij
Remove uses of decorators.
458
        with self.lock_tree_write():
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
459
            for filepath in osutils.canonical_relpaths(
460
                    self.basedir, file_list):
0.352.1 by Jelmer Vernooij
Check for normalization during add.
461
                filepath, can_access = osutils.normalized_filename(filepath)
462
                if not can_access:
463
                    raise errors.InvalidNormalization(filepath)
464
0.200.1675 by Jelmer Vernooij
Remove uses of decorators.
465
                abspath = self.abspath(filepath)
0.200.1240 by Jelmer Vernooij
Implement GitWorkingTree.smart_add.
466
                kind = osutils.file_kind(abspath)
0.200.1675 by Jelmer Vernooij
Remove uses of decorators.
467
                if kind in ("file", "symlink"):
7143.15.2 by Jelmer Vernooij
Run autopep8.
468
                    (index, subpath) = self._lookup_index(
7490.70.1 by Jelmer Vernooij
Add functions for encoding/decoding git paths.
469
                        encode_git_path(filepath))
0.429.2 by Jelmer Vernooij
Some more work on submodule support.
470
                    if subpath in index:
0.369.2 by Jelmer Vernooij
Fix tests.
471
                        # Already present
472
                        continue
0.200.1733 by Jelmer Vernooij
Support handling of custom ids in smart_add.
473
                    call_action(filepath, kind)
0.200.1308 by Jelmer Vernooij
Write index to disk after adding files.
474
                    if save:
0.200.1675 by Jelmer Vernooij
Remove uses of decorators.
475
                        self._index_add_entry(filepath, kind)
476
                    added.append(filepath)
477
                elif kind == "directory":
7143.15.2 by Jelmer Vernooij
Run autopep8.
478
                    (index, subpath) = self._lookup_index(
7490.70.1 by Jelmer Vernooij
Add functions for encoding/decoding git paths.
479
                        encode_git_path(filepath))
0.429.2 by Jelmer Vernooij
Some more work on submodule support.
480
                    if subpath not in index:
0.369.2 by Jelmer Vernooij
Fix tests.
481
                        call_action(filepath, kind)
0.200.1675 by Jelmer Vernooij
Remove uses of decorators.
482
                    if recurse:
483
                        user_dirs.append(filepath)
484
                else:
485
                    raise errors.BadFileKindError(filename=abspath, kind=kind)
486
            for user_dir in user_dirs:
487
                abs_user_dir = self.abspath(user_dir)
0.200.1752 by Jelmer Vernooij
Don't traverse nested trees in WorkingTree.smart_add.
488
                if user_dir != '':
489
                    try:
7143.15.2 by Jelmer Vernooij
Run autopep8.
490
                        transport = _mod_transport.get_transport_from_path(
491
                            abs_user_dir)
0.200.1752 by Jelmer Vernooij
Don't traverse nested trees in WorkingTree.smart_add.
492
                        _mod_controldir.ControlDirFormat.find_format(transport)
493
                        subtree = True
494
                    except errors.NotBranchError:
495
                        subtree = False
496
                    except errors.UnsupportedFormatError:
497
                        subtree = False
498
                else:
499
                    subtree = False
500
                if subtree:
0.200.1769 by Jelmer Vernooij
Raise proper error when encountering nested trees.
501
                    trace.warning('skipping nested tree %r', abs_user_dir)
0.200.1752 by Jelmer Vernooij
Don't traverse nested trees in WorkingTree.smart_add.
502
                    continue
503
0.200.1675 by Jelmer Vernooij
Remove uses of decorators.
504
                for name in os.listdir(abs_user_dir):
505
                    subp = os.path.join(user_dir, name)
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
506
                    if (self.is_control_filename(subp) or
507
                            self.mapping.is_special_file(subp)):
0.200.1675 by Jelmer Vernooij
Remove uses of decorators.
508
                        continue
509
                    ignore_glob = self.is_ignored(subp)
510
                    if ignore_glob is not None:
511
                        ignored.setdefault(ignore_glob, []).append(subp)
512
                        continue
513
                    abspath = self.abspath(subp)
514
                    kind = osutils.file_kind(abspath)
515
                    if kind == "directory":
516
                        user_dirs.append(subp)
517
                    else:
7143.15.2 by Jelmer Vernooij
Run autopep8.
518
                        (index, subpath) = self._lookup_index(
7490.70.1 by Jelmer Vernooij
Add functions for encoding/decoding git paths.
519
                            encode_git_path(subp))
7067.13.14 by Jelmer Vernooij
Fix a smart_add test.
520
                        if subpath in index:
0.369.2 by Jelmer Vernooij
Fix tests.
521
                            # Already present
522
                            continue
0.369.3 by Jelmer Vernooij
Fix another conflict test.
523
                        if subp in conflicts_related:
524
                            continue
7141.3.1 by Brian de Alwis
'brz add' in git format doesn't report files added
525
                        call_action(subp, kind)
0.200.1675 by Jelmer Vernooij
Remove uses of decorators.
526
                        if save:
527
                            self._index_add_entry(subp, kind)
0.200.1751 by Jelmer Vernooij
Fix smart_add return value.
528
                        added.append(subp)
0.200.1675 by Jelmer Vernooij
Remove uses of decorators.
529
            return added, ignored
0.200.1240 by Jelmer Vernooij
Implement GitWorkingTree.smart_add.
530
0.200.1712 by Jelmer Vernooij
Add file_id prefix.
531
    def has_filename(self, filename):
532
        return osutils.lexists(self.abspath(filename))
533
7404.2.1 by Jelmer Vernooij
Add a follow_tree_references argument to Tree.list_files.
534
    def _iter_files_recursive(self, from_dir=None, include_dirs=False,
7404.2.3 by Jelmer Vernooij
s/follow_tree_references/recurse_nested/g
535
                              recurse_nested=False):
0.200.1328 by Jelmer Vernooij
More test fixes.
536
        if from_dir is None:
0.379.1 by Jelmer Vernooij
Improve unicode handling in GitWorkingTree.
537
            from_dir = u""
7404.2.1 by Jelmer Vernooij
Add a follow_tree_references argument to Tree.list_files.
538
        if not isinstance(from_dir, text_type):
539
            raise TypeError(from_dir)
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
540
        encoded_from_dir = self.abspath(from_dir).encode(osutils._fs_enc)
541
        for (dirpath, dirnames, filenames) in os.walk(encoded_from_dir):
7018.3.2 by Jelmer Vernooij
Fix some git tests.
542
            dir_relpath = dirpath[len(self.basedir):].strip(b"/")
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
543
            if self.controldir.is_control_filename(
544
                    dir_relpath.decode(osutils._fs_enc)):
0.200.605 by Jelmer Vernooij
Ignore directories in WorkingTree.extras().
545
                continue
0.200.1766 by Jelmer Vernooij
Fix another list_files test, integrate is_versioned.
546
            for name in list(dirnames):
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
547
                if self.controldir.is_control_filename(
548
                        name.decode(osutils._fs_enc)):
0.200.1766 by Jelmer Vernooij
Fix another list_files test, integrate is_versioned.
549
                    dirnames.remove(name)
550
                    continue
551
                relpath = os.path.join(dir_relpath, name)
7404.2.3 by Jelmer Vernooij
s/follow_tree_references/recurse_nested/g
552
                if not recurse_nested and self._directory_is_tree_reference(relpath.decode(osutils._fs_enc)):
7404.2.1 by Jelmer Vernooij
Add a follow_tree_references argument to Tree.list_files.
553
                    dirnames.remove(name)
0.200.1766 by Jelmer Vernooij
Fix another list_files test, integrate is_versioned.
554
                if include_dirs:
0.341.1 by Jelmer Vernooij
Fix BadFilenameEncoding raising during WorkingTree.extras.
555
                    try:
556
                        yield relpath.decode(osutils._fs_enc)
0.379.1 by Jelmer Vernooij
Improve unicode handling in GitWorkingTree.
557
                    except UnicodeDecodeError:
0.341.1 by Jelmer Vernooij
Fix BadFilenameEncoding raising during WorkingTree.extras.
558
                        raise errors.BadFilenameEncoding(
559
                            relpath, osutils._fs_enc)
7404.2.1 by Jelmer Vernooij
Add a follow_tree_references argument to Tree.list_files.
560
                    if not self.is_versioned(relpath.decode(osutils._fs_enc)):
7199.3.1 by Jelmer Vernooij
Don't report empty directories as changes.
561
                        dirnames.remove(name)
0.200.1766 by Jelmer Vernooij
Fix another list_files test, integrate is_versioned.
562
            for name in filenames:
7265.3.1 by Jelmer Vernooij
Properly ignore .git files.
563
                if self.mapping.is_special_file(name):
564
                    continue
565
                if self.controldir.is_control_filename(
7265.3.3 by Jelmer Vernooij
Cope with non-utf8 characters.
566
                        name.decode(osutils._fs_enc, 'replace')):
7265.3.1 by Jelmer Vernooij
Properly ignore .git files.
567
                    continue
568
                yp = os.path.join(dir_relpath, name)
569
                try:
570
                    yield yp.decode(osutils._fs_enc)
571
                except UnicodeDecodeError:
572
                    raise errors.BadFilenameEncoding(
573
                        yp, osutils._fs_enc)
0.200.1327 by Jelmer Vernooij
Factor out all file browsing in extras.
574
575
    def extras(self):
576
        """Yield all unversioned files in this WorkingTree.
577
        """
0.200.1676 by Jelmer Vernooij
Fix typo.
578
        with self.lock_read():
7199.3.1 by Jelmer Vernooij
Don't report empty directories as changes.
579
            index_paths = set(
7490.70.1 by Jelmer Vernooij
Add functions for encoding/decoding git paths.
580
                [decode_git_path(p) for p, i in self._recurse_index_entries()])
7199.3.1 by Jelmer Vernooij
Don't report empty directories as changes.
581
            all_paths = set(self._iter_files_recursive(include_dirs=False))
582
            return iter(all_paths - index_paths)
0.200.605 by Jelmer Vernooij
Ignore directories in WorkingTree.extras().
583
0.429.17 by Jelmer Vernooij
Fix some more tests.
584
    def _gather_kinds(self, files, kinds):
585
        """See MutableTree._gather_kinds."""
586
        with self.lock_tree_write():
587
            for pos, f in enumerate(files):
588
                if kinds[pos] is None:
589
                    fullpath = osutils.normpath(self.abspath(f))
590
                    try:
7143.15.2 by Jelmer Vernooij
Run autopep8.
591
                        kind = osutils.file_kind(fullpath)
0.429.17 by Jelmer Vernooij
Fix some more tests.
592
                    except OSError as e:
593
                        if e.errno == errno.ENOENT:
594
                            raise errors.NoSuchFile(fullpath)
7311.2.5 by Jelmer Vernooij
Use self._directory_is_tree_reference.
595
                    if f != '' and self._directory_is_tree_reference(f):
0.429.17 by Jelmer Vernooij
Fix some more tests.
596
                        kind = 'tree-reference'
597
                    kinds[pos] = kind
598
0.200.382 by Jelmer Vernooij
Support flushing index.
599
    def flush(self):
0.287.6 by Jelmer Vernooij
Fix some more tests.
600
        if self._lock_mode != 'w':
601
            raise errors.NotWriteLocked(self)
0.415.5 by Jelmer Vernooij
Don't flush, just wait for unlock.
602
        # TODO(jelmer): This shouldn't be writing in-place, but index.lock is
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
603
        # already in use and GitFile doesn't allow overriding the lock file
604
        # name :(
0.415.4 by Jelmer Vernooij
proper locking on index.
605
        f = open(self.control_transport.local_abspath('index'), 'wb')
606
        # Note that _flush will close the file
607
        self._flush(f)
608
609
    def _flush(self, f):
610
        try:
611
            shaf = SHA1Writer(f)
612
            write_index_dict(shaf, self.index)
613
            shaf.close()
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
614
        except BaseException:
0.415.4 by Jelmer Vernooij
proper locking on index.
615
            f.abort()
616
            raise
617
        self._index_dirty = False
0.200.382 by Jelmer Vernooij
Support flushing index.
618
7141.7.1 by Jelmer Vernooij
Get rid of file_ids in most of Tree.
619
    def get_file_mtime(self, path):
0.200.1200 by Jelmer Vernooij
Support GitWorkingTree.get_file_mtime.
620
        """See Tree.get_file_mtime."""
0.285.1 by Jelmer Vernooij
Swap arguments for tree methods.
621
        try:
0.360.1 by Jelmer Vernooij
Implement GitMemoryTree.
622
            return self._lstat(path).st_mtime
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
623
        except OSError as e:
7045.4.1 by Jelmer Vernooij
Some brz-git fixes.
624
            if e.errno == errno.ENOENT:
0.285.1 by Jelmer Vernooij
Swap arguments for tree methods.
625
                raise errors.NoSuchFile(path)
626
            raise
0.200.1200 by Jelmer Vernooij
Support GitWorkingTree.get_file_mtime.
627
0.200.1655 by Jelmer Vernooij
Basic support for git ignores.
628
    def is_ignored(self, filename):
629
        r"""Check whether the filename matches an ignore pattern.
630
631
        If the file is ignored, returns the pattern which caused it to
632
        be ignored, otherwise None.  So this can simply be used as a
633
        boolean if desired."""
634
        if getattr(self, '_global_ignoreglobster', None) is None:
7490.62.3 by Jelmer Vernooij
Move btree and remove references.
635
            from breezy import ignores
0.200.1655 by Jelmer Vernooij
Basic support for git ignores.
636
            ignore_globs = set()
637
            ignore_globs.update(ignores.get_runtime_ignores())
638
            ignore_globs.update(ignores.get_user_ignores())
7143.15.2 by Jelmer Vernooij
Run autopep8.
639
            self._global_ignoreglobster = globbing.ExceptionGlobster(
640
                ignore_globs)
0.200.1656 by Jelmer Vernooij
Report proper patterns, ignore files.
641
        match = self._global_ignoreglobster.match(filename)
642
        if match is not None:
643
            return match
0.200.1716 by Jelmer Vernooij
Fix some more tests.
644
        try:
645
            if self.kind(filename) == 'directory':
7065.1.1 by Jelmer Vernooij
Properly handle ignored directories in Git.
646
                filename += '/'
0.200.1716 by Jelmer Vernooij
Fix some more tests.
647
        except errors.NoSuchFile:
648
            pass
7065.1.1 by Jelmer Vernooij
Properly handle ignored directories in Git.
649
        filename = filename.lstrip('/')
0.200.1658 by Jelmer Vernooij
Fix handling of ignores - return patterns that matched.
650
        ignore_manager = self._get_ignore_manager()
651
        ps = list(ignore_manager.find_matching(filename))
652
        if not ps:
653
            return None
654
        if not ps[-1].is_exclude:
655
            return None
656
        return bytes(ps[-1])
657
658
    def _get_ignore_manager(self):
659
        ignoremanager = getattr(self, '_ignoremanager', None)
660
        if ignoremanager is not None:
661
            return ignoremanager
662
663
        ignore_manager = IgnoreFilterManager.from_repo(self.repository._git)
664
        self._ignoremanager = ignore_manager
665
        return ignore_manager
0.200.409 by Jelmer Vernooij
Support parsing .gitignore.
666
0.200.1716 by Jelmer Vernooij
Fix some more tests.
667
    def _flush_ignore_list_cache(self):
668
        self._ignoremanager = None
669
0.200.508 by Jelmer Vernooij
Skip inventory caching bits.
670
    def set_last_revision(self, revid):
0.200.1720 by Jelmer Vernooij
Fix handling of pending merges.
671
        if _mod_revision.is_null(revid):
672
            self.branch.set_last_revision_info(0, revid)
673
            return False
674
        _mod_revision.check_not_reserved_id(revid)
675
        try:
676
            self.branch.generate_revision_history(revid)
677
        except errors.NoSuchRevision:
678
            raise errors.GhostRevisionUnusableHere(revid)
0.200.508 by Jelmer Vernooij
Skip inventory caching bits.
679
0.200.379 by Jelmer Vernooij
Re-enable working tree support.
680
    def _reset_data(self):
7358.13.1 by Jelmer Vernooij
Drop file id roundtripping support in Git.
681
        pass
0.200.379 by Jelmer Vernooij
Re-enable working tree support.
682
7141.7.1 by Jelmer Vernooij
Get rid of file_ids in most of Tree.
683
    def get_file_verifier(self, path, stat_value=None):
0.200.1675 by Jelmer Vernooij
Remove uses of decorators.
684
        with self.lock_read():
7490.70.1 by Jelmer Vernooij
Add functions for encoding/decoding git paths.
685
            (index, subpath) = self._lookup_index(encode_git_path(path))
0.200.1675 by Jelmer Vernooij
Remove uses of decorators.
686
            try:
0.429.2 by Jelmer Vernooij
Some more work on submodule support.
687
                return ("GIT", index[subpath].sha)
0.200.1675 by Jelmer Vernooij
Remove uses of decorators.
688
            except KeyError:
689
                if self._has_dir(path):
690
                    return ("GIT", None)
0.285.1 by Jelmer Vernooij
Swap arguments for tree methods.
691
                raise errors.NoSuchFile(path)
0.200.1302 by Jelmer Vernooij
Significantly improve performance of WorkingTree.extras().
692
7141.7.1 by Jelmer Vernooij
Get rid of file_ids in most of Tree.
693
    def get_file_sha1(self, path, stat_value=None):
0.200.1675 by Jelmer Vernooij
Remove uses of decorators.
694
        with self.lock_read():
0.200.1772 by Jelmer Vernooij
Fix handling of unversioned file in get_file_sha1.
695
            if not self.is_versioned(path):
696
                raise errors.NoSuchFile(path)
697
            abspath = self.abspath(path)
0.200.1675 by Jelmer Vernooij
Remove uses of decorators.
698
            try:
699
                return osutils.sha_file_by_name(abspath)
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
700
            except OSError as e:
7045.4.1 by Jelmer Vernooij
Some brz-git fixes.
701
                if e.errno in (errno.EISDIR, errno.ENOENT):
0.200.1772 by Jelmer Vernooij
Fix handling of unversioned file in get_file_sha1.
702
                    return None
0.200.1675 by Jelmer Vernooij
Remove uses of decorators.
703
                raise
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
704
0.200.610 by Jelmer Vernooij
Support retrieving basis tree properly.
705
    def revision_tree(self, revid):
706
        return self.repository.revision_tree(revid)
707
0.264.11 by Jelmer Vernooij
Completer implementation of iter_entries_by_dir and list_files.
708
    def _is_executable_from_path_and_stat_from_stat(self, path, stat_result):
709
        mode = stat_result.st_mode
710
        return bool(stat.S_ISREG(mode) and stat.S_IEXEC & mode)
711
0.318.1 by Jelmer Vernooij
Fix executable test.
712
    def _is_executable_from_path_and_stat_from_basis(self, path, stat_result):
713
        return self.basis_tree().is_executable(path)
714
7141.7.1 by Jelmer Vernooij
Get rid of file_ids in most of Tree.
715
    def stored_kind(self, path):
0.200.1675 by Jelmer Vernooij
Remove uses of decorators.
716
        with self.lock_read():
7490.70.1 by Jelmer Vernooij
Add functions for encoding/decoding git paths.
717
            encoded_path = encode_git_path(path)
7018.3.2 by Jelmer Vernooij
Fix some git tests.
718
            (index, subpath) = self._lookup_index(encoded_path)
0.200.1675 by Jelmer Vernooij
Remove uses of decorators.
719
            try:
0.429.2 by Jelmer Vernooij
Some more work on submodule support.
720
                return mode_kind(index[subpath].mode)
0.200.1675 by Jelmer Vernooij
Remove uses of decorators.
721
            except KeyError:
722
                # Maybe it's a directory?
7018.3.2 by Jelmer Vernooij
Fix some git tests.
723
                if self._has_dir(encoded_path):
0.200.1675 by Jelmer Vernooij
Remove uses of decorators.
724
                    return "directory"
0.285.1 by Jelmer Vernooij
Swap arguments for tree methods.
725
                raise errors.NoSuchFile(path)
0.200.1205 by Jelmer Vernooij
Implement GitWorkingTree.stored_kind.
726
0.360.1 by Jelmer Vernooij
Implement GitMemoryTree.
727
    def _lstat(self, path):
728
        return os.lstat(self.abspath(path))
729
6973.1.1 by Jelmer Vernooij
Make InterIndexGitTree suitable for use with MemoryGitTree.
730
    def _live_entry(self, path):
7490.70.1 by Jelmer Vernooij
Add functions for encoding/decoding git paths.
731
        encoded_path = self.abspath(decode_git_path(path)).encode(
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
732
            osutils._fs_enc)
733
        return index_entry_from_path(encoded_path)
6973.1.1 by Jelmer Vernooij
Make InterIndexGitTree suitable for use with MemoryGitTree.
734
7141.7.1 by Jelmer Vernooij
Get rid of file_ids in most of Tree.
735
    def is_executable(self, path):
0.379.1 by Jelmer Vernooij
Improve unicode handling in GitWorkingTree.
736
        with self.lock_read():
7122.7.1 by Jelmer Vernooij
Check for fs type to determine whether executable bit is supported.
737
            if self._supports_executable():
0.379.1 by Jelmer Vernooij
Improve unicode handling in GitWorkingTree.
738
                mode = self._lstat(path).st_mode
739
            else:
7490.70.1 by Jelmer Vernooij
Add functions for encoding/decoding git paths.
740
                (index, subpath) = self._lookup_index(encode_git_path(path))
0.379.1 by Jelmer Vernooij
Improve unicode handling in GitWorkingTree.
741
                try:
0.429.2 by Jelmer Vernooij
Some more work on submodule support.
742
                    mode = index[subpath].mode
0.379.1 by Jelmer Vernooij
Improve unicode handling in GitWorkingTree.
743
                except KeyError:
744
                    mode = 0
745
            return bool(stat.S_ISREG(mode) and stat.S_IEXEC & mode)
0.264.11 by Jelmer Vernooij
Completer implementation of iter_entries_by_dir and list_files.
746
0.200.1539 by Jelmer Vernooij
Cope with new is_executable.
747
    def _is_executable_from_path_and_stat(self, path, stat_result):
7122.7.1 by Jelmer Vernooij
Check for fs type to determine whether executable bit is supported.
748
        if self._supports_executable():
0.200.1539 by Jelmer Vernooij
Cope with new is_executable.
749
            return self._is_executable_from_path_and_stat_from_stat(path, stat_result)
750
        else:
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
751
            return self._is_executable_from_path_and_stat_from_basis(
752
                path, stat_result)
0.264.11 by Jelmer Vernooij
Completer implementation of iter_entries_by_dir and list_files.
753
7404.2.1 by Jelmer Vernooij
Add a follow_tree_references argument to Tree.list_files.
754
    def list_files(self, include_root=False, from_dir=None, recursive=True,
7404.2.3 by Jelmer Vernooij
s/follow_tree_references/recurse_nested/g
755
                   recurse_nested=False):
7143.17.1 by Jelmer Vernooij
Fix grep in git working trees.
756
        if from_dir is None or from_dir == '.':
0.379.1 by Jelmer Vernooij
Improve unicode handling in GitWorkingTree.
757
            from_dir = u""
0.264.11 by Jelmer Vernooij
Completer implementation of iter_entries_by_dir and list_files.
758
        dir_ids = {}
0.200.1767 by Jelmer Vernooij
Fix references to Tree*.
759
        fk_entries = {'directory': tree.TreeDirectory,
760
                      'file': tree.TreeFile,
0.429.5 by Jelmer Vernooij
Fix tree_content_summary test.
761
                      'symlink': tree.TreeLink,
0.429.8 by Jelmer Vernooij
Fix class name.
762
                      'tree-reference': tree.TreeReference}
0.200.1675 by Jelmer Vernooij
Remove uses of decorators.
763
        with self.lock_read():
764
            root_ie = self._get_dir_ie(u"", None)
765
            if include_root and not from_dir:
7143.19.5 by Jelmer Vernooij
Undo removal of kind.
766
                yield "", "V", root_ie.kind, root_ie
0.200.1675 by Jelmer Vernooij
Remove uses of decorators.
767
            dir_ids[u""] = root_ie.file_id
768
            if recursive:
7143.15.2 by Jelmer Vernooij
Run autopep8.
769
                path_iterator = sorted(
7404.2.1 by Jelmer Vernooij
Add a follow_tree_references argument to Tree.list_files.
770
                    self._iter_files_recursive(
771
                        from_dir, include_dirs=True,
7404.2.3 by Jelmer Vernooij
s/follow_tree_references/recurse_nested/g
772
                        recurse_nested=recurse_nested))
0.200.1675 by Jelmer Vernooij
Remove uses of decorators.
773
            else:
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
774
                encoded_from_dir = self.abspath(from_dir).encode(
775
                    osutils._fs_enc)
776
                path_iterator = sorted(
777
                    [os.path.join(from_dir, name.decode(osutils._fs_enc))
778
                     for name in os.listdir(encoded_from_dir)
779
                     if not self.controldir.is_control_filename(
780
                         name.decode(osutils._fs_enc)) and
781
                     not self.mapping.is_special_file(
782
                         name.decode(osutils._fs_enc))])
0.200.1675 by Jelmer Vernooij
Remove uses of decorators.
783
            for path in path_iterator:
784
                try:
7490.70.1 by Jelmer Vernooij
Add functions for encoding/decoding git paths.
785
                    encoded_path = encode_git_path(path)
0.379.1 by Jelmer Vernooij
Improve unicode handling in GitWorkingTree.
786
                except UnicodeEncodeError:
787
                    raise errors.BadFilenameEncoding(
788
                        path, osutils._fs_enc)
0.429.2 by Jelmer Vernooij
Some more work on submodule support.
789
                (index, index_path) = self._lookup_index(encoded_path)
0.379.1 by Jelmer Vernooij
Improve unicode handling in GitWorkingTree.
790
                try:
0.429.2 by Jelmer Vernooij
Some more work on submodule support.
791
                    value = index[index_path]
0.200.1675 by Jelmer Vernooij
Remove uses of decorators.
792
                except KeyError:
793
                    value = None
0.429.5 by Jelmer Vernooij
Fix tree_content_summary test.
794
                kind = self.kind(path)
0.200.1675 by Jelmer Vernooij
Remove uses of decorators.
795
                parent, name = posixpath.split(path)
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
796
                for dir_path, dir_ie in self._add_missing_parent_ids(
797
                        parent, dir_ids):
0.200.1766 by Jelmer Vernooij
Fix another list_files test, integrate is_versioned.
798
                    pass
7404.2.3 by Jelmer Vernooij
s/follow_tree_references/recurse_nested/g
799
                if kind == 'tree-reference' and recurse_nested:
7404.2.2 by Jelmer Vernooij
Fix a test.
800
                    ie = self._get_dir_ie(path, self.path2id(path))
801
                    yield (posixpath.relpath(path, from_dir), 'V', 'directory',
802
                           ie)
803
                    continue
7404.2.1 by Jelmer Vernooij
Add a follow_tree_references argument to Tree.list_files.
804
                if kind == 'directory':
0.200.1766 by Jelmer Vernooij
Fix another list_files test, integrate is_versioned.
805
                    if path != from_dir:
7018.3.2 by Jelmer Vernooij
Fix some git tests.
806
                        if self._has_dir(encoded_path):
0.200.1766 by Jelmer Vernooij
Fix another list_files test, integrate is_versioned.
807
                            ie = self._get_dir_ie(path, self.path2id(path))
808
                            status = "V"
809
                        elif self.is_ignored(path):
810
                            status = "I"
811
                            ie = fk_entries[kind]()
812
                        else:
813
                            status = "?"
814
                            ie = fk_entries[kind]()
7143.19.7 by Jelmer Vernooij
merge trunk
815
                        yield (posixpath.relpath(path, from_dir), status, kind,
816
                               ie)
0.200.1766 by Jelmer Vernooij
Fix another list_files test, integrate is_versioned.
817
                    continue
0.200.1675 by Jelmer Vernooij
Remove uses of decorators.
818
                if value is not None:
819
                    ie = self._get_file_ie(name, path, value, dir_ids[parent])
7143.19.7 by Jelmer Vernooij
merge trunk
820
                    yield (posixpath.relpath(path, from_dir), "V", ie.kind, ie)
0.200.1675 by Jelmer Vernooij
Remove uses of decorators.
821
                else:
7490.26.3 by Jelmer Vernooij
Ignore unknown kind files.
822
                    try:
823
                        ie = fk_entries[kind]()
824
                    except KeyError:
825
                        # unsupported kind
826
                        continue
7143.19.7 by Jelmer Vernooij
merge trunk
827
                    yield (posixpath.relpath(path, from_dir),
828
                           ("I" if self.is_ignored(path) else "?"), kind, ie)
0.264.10 by Jelmer Vernooij
Yield inventory entries.
829
0.200.1206 by Jelmer Vernooij
Implement GitWorkingTree.all_file_ids.
830
    def all_file_ids(self):
7170.3.1 by Jelmer Vernooij
Make Tree.all_file_ids optional.
831
        raise errors.UnsupportedOperation(self.all_file_ids, self)
0.200.1206 by Jelmer Vernooij
Implement GitWorkingTree.all_file_ids.
832
0.200.1710 by Jelmer Vernooij
Regenerate xfail.
833
    def all_versioned_paths(self):
834
        with self.lock_read():
835
            paths = {u""}
836
            for path in self.index:
837
                if self.mapping.is_special_file(path):
838
                    continue
7490.70.1 by Jelmer Vernooij
Add functions for encoding/decoding git paths.
839
                path = decode_git_path(path)
0.200.1710 by Jelmer Vernooij
Regenerate xfail.
840
                paths.add(path)
841
                while path != "":
842
                    path = posixpath.dirname(path).strip("/")
843
                    if path in paths:
844
                        break
845
                    paths.add(path)
846
            return paths
847
7141.7.1 by Jelmer Vernooij
Get rid of file_ids in most of Tree.
848
    def iter_child_entries(self, path):
7490.70.1 by Jelmer Vernooij
Add functions for encoding/decoding git paths.
849
        encoded_path = encode_git_path(path)
0.379.1 by Jelmer Vernooij
Improve unicode handling in GitWorkingTree.
850
        with self.lock_read():
851
            parent_id = self.path2id(path)
852
            found_any = False
853
            for item_path, value in self.index.iteritems():
7490.70.1 by Jelmer Vernooij
Add functions for encoding/decoding git paths.
854
                decoded_item_path = decode_git_path(item_path)
0.379.1 by Jelmer Vernooij
Improve unicode handling in GitWorkingTree.
855
                if self.mapping.is_special_file(item_path):
856
                    continue
7045.4.2 by Jelmer Vernooij
Fix some more gitty tests.
857
                if not osutils.is_inside(path, decoded_item_path):
0.379.1 by Jelmer Vernooij
Improve unicode handling in GitWorkingTree.
858
                    continue
859
                found_any = True
7045.4.2 by Jelmer Vernooij
Fix some more gitty tests.
860
                subpath = posixpath.relpath(decoded_item_path, path)
861
                if '/' in subpath:
862
                    dirname = subpath.split('/', 1)[0]
7143.15.2 by Jelmer Vernooij
Run autopep8.
863
                    file_ie = self._get_dir_ie(
864
                        posixpath.join(path, dirname), parent_id)
0.379.1 by Jelmer Vernooij
Improve unicode handling in GitWorkingTree.
865
                else:
7045.4.2 by Jelmer Vernooij
Fix some more gitty tests.
866
                    (unused_parent, name) = posixpath.split(decoded_item_path)
0.379.1 by Jelmer Vernooij
Improve unicode handling in GitWorkingTree.
867
                    file_ie = self._get_file_ie(
7045.4.2 by Jelmer Vernooij
Fix some more gitty tests.
868
                        name, decoded_item_path, value, parent_id)
0.379.1 by Jelmer Vernooij
Improve unicode handling in GitWorkingTree.
869
                yield file_ie
870
            if not found_any and path != u'':
871
                raise errors.NoSuchFile(path)
0.200.1716 by Jelmer Vernooij
Fix some more tests.
872
0.200.619 by Jelmer Vernooij
Provide dummy WorkingTree.conflicts() implementation rather than spending a lot of time not finding any conflicts.
873
    def conflicts(self):
0.200.1675 by Jelmer Vernooij
Remove uses of decorators.
874
        with self.lock_read():
0.369.2 by Jelmer Vernooij
Fix tests.
875
            conflicts = _mod_conflicts.ConflictList()
0.369.1 by Jelmer Vernooij
Implement conflict handling.
876
            for item_path, value in self.index.iteritems():
877
                if value.flags & FLAG_STAGEMASK:
7143.15.2 by Jelmer Vernooij
Run autopep8.
878
                    conflicts.append(_mod_conflicts.TextConflict(
7490.70.1 by Jelmer Vernooij
Add functions for encoding/decoding git paths.
879
                        decode_git_path(item_path)))
0.369.1 by Jelmer Vernooij
Implement conflict handling.
880
            return conflicts
881
882
    def set_conflicts(self, conflicts):
883
        by_path = set()
884
        for conflict in conflicts:
885
            if conflict.typestring in ('text conflict', 'contents conflict'):
7490.70.1 by Jelmer Vernooij
Add functions for encoding/decoding git paths.
886
                by_path.add(encode_git_path(conflict.path))
0.369.1 by Jelmer Vernooij
Implement conflict handling.
887
            else:
888
                raise errors.UnsupportedOperation(self.set_conflicts, self)
889
        with self.lock_tree_write():
890
            for path in self.index:
891
                self._set_conflicted(path, path in by_path)
892
893
    def _set_conflicted(self, path, conflicted):
894
        trace.mutter('change conflict: %r -> %r', path, conflicted)
895
        value = self.index[path]
0.415.1 by Jelmer Vernooij
Only write index when it's dirty.
896
        self._index_dirty = True
0.369.1 by Jelmer Vernooij
Implement conflict handling.
897
        if conflicted:
898
            self.index[path] = (value[:9] + (value[9] | FLAG_STAGEMASK, ))
899
        else:
7143.15.2 by Jelmer Vernooij
Run autopep8.
900
            self.index[path] = (value[:9] + (value[9] & ~ FLAG_STAGEMASK, ))
0.369.1 by Jelmer Vernooij
Implement conflict handling.
901
902
    def add_conflicts(self, new_conflicts):
903
        with self.lock_tree_write():
904
            for conflict in new_conflicts:
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
905
                if conflict.typestring in ('text conflict',
906
                                           'contents conflict'):
0.369.1 by Jelmer Vernooij
Implement conflict handling.
907
                    try:
7143.15.2 by Jelmer Vernooij
Run autopep8.
908
                        self._set_conflicted(
7490.70.1 by Jelmer Vernooij
Add functions for encoding/decoding git paths.
909
                            encode_git_path(conflict.path), True)
0.369.1 by Jelmer Vernooij
Implement conflict handling.
910
                    except KeyError:
7143.15.2 by Jelmer Vernooij
Run autopep8.
911
                        raise errors.UnsupportedOperation(
912
                            self.add_conflicts, self)
0.369.1 by Jelmer Vernooij
Implement conflict handling.
913
                else:
914
                    raise errors.UnsupportedOperation(self.add_conflicts, self)
0.200.619 by Jelmer Vernooij
Provide dummy WorkingTree.conflicts() implementation rather than spending a lot of time not finding any conflicts.
915
0.200.1705 by Jelmer Vernooij
Fix walkdirs.
916
    def walkdirs(self, prefix=""):
0.324.1 by Jelmer Vernooij
initial work fixing walkdirs.
917
        """Walk the directories of this tree.
918
919
        returns a generator which yields items in the form:
920
                ((curren_directory_path, fileid),
921
                 [(file1_path, file1_name, file1_kind, (lstat), file1_id,
922
                   file1_kind), ... ])
923
924
        This API returns a generator, which is only valid during the current
925
        tree transaction - within a single lock_read or lock_write duration.
926
927
        If the tree is not locked, it may cause an error to be raised,
928
        depending on the tree implementation.
929
        """
930
        from bisect import bisect_left
931
        import operator
932
        disk_top = self.abspath(prefix)
933
        if disk_top.endswith('/'):
934
            disk_top = disk_top[:-1]
935
        top_strip_len = len(disk_top) + 1
936
        inventory_iterator = self._walkdirs(prefix)
937
        disk_iterator = osutils.walkdirs(disk_top, prefix)
938
        try:
939
            current_disk = next(disk_iterator)
940
            disk_finished = False
941
        except OSError as e:
7143.15.2 by Jelmer Vernooij
Run autopep8.
942
            if not (e.errno == errno.ENOENT
943
                    or (sys.platform == 'win32' and e.errno == ERROR_PATH_NOT_FOUND)):
0.324.1 by Jelmer Vernooij
initial work fixing walkdirs.
944
                raise
945
            current_disk = None
946
            disk_finished = True
947
        try:
948
            current_inv = next(inventory_iterator)
949
            inv_finished = False
950
        except StopIteration:
951
            current_inv = None
952
            inv_finished = True
953
        while not inv_finished or not disk_finished:
954
            if current_disk:
955
                ((cur_disk_dir_relpath, cur_disk_dir_path_from_top),
956
                    cur_disk_dir_content) = current_disk
957
            else:
958
                ((cur_disk_dir_relpath, cur_disk_dir_path_from_top),
959
                    cur_disk_dir_content) = ((None, None), None)
960
            if not disk_finished:
961
                # strip out .bzr dirs
7143.15.2 by Jelmer Vernooij
Run autopep8.
962
                if (cur_disk_dir_path_from_top[top_strip_len:] == ''
963
                        and len(cur_disk_dir_content) > 0):
0.324.1 by Jelmer Vernooij
initial work fixing walkdirs.
964
                    # osutils.walkdirs can be made nicer -
965
                    # yield the path-from-prefix rather than the pathjoined
966
                    # value.
967
                    bzrdir_loc = bisect_left(cur_disk_dir_content,
7143.15.2 by Jelmer Vernooij
Run autopep8.
968
                                             ('.git', '.git'))
969
                    if (bzrdir_loc < len(cur_disk_dir_content) and
970
                        self.controldir.is_control_filename(
0.324.1 by Jelmer Vernooij
initial work fixing walkdirs.
971
                            cur_disk_dir_content[bzrdir_loc][0])):
972
                        # we dont yield the contents of, or, .bzr itself.
973
                        del cur_disk_dir_content[bzrdir_loc]
974
            if inv_finished:
975
                # everything is unknown
976
                direction = 1
977
            elif disk_finished:
978
                # everything is missing
979
                direction = -1
980
            else:
7143.15.2 by Jelmer Vernooij
Run autopep8.
981
                direction = ((current_inv[0][0] > cur_disk_dir_relpath)
982
                             - (current_inv[0][0] < cur_disk_dir_relpath))
0.324.1 by Jelmer Vernooij
initial work fixing walkdirs.
983
            if direction > 0:
984
                # disk is before inventory - unknown
985
                dirblock = [(relpath, basename, kind, stat, None, None) for
7143.15.2 by Jelmer Vernooij
Run autopep8.
986
                            relpath, basename, kind, stat, top_path in
987
                            cur_disk_dir_content]
0.324.1 by Jelmer Vernooij
initial work fixing walkdirs.
988
                yield (cur_disk_dir_relpath, None), dirblock
989
                try:
990
                    current_disk = next(disk_iterator)
991
                except StopIteration:
992
                    disk_finished = True
993
            elif direction < 0:
994
                # inventory is before disk - missing.
995
                dirblock = [(relpath, basename, 'unknown', None, fileid, kind)
7143.15.2 by Jelmer Vernooij
Run autopep8.
996
                            for relpath, basename, dkind, stat, fileid, kind in
997
                            current_inv[1]]
0.324.1 by Jelmer Vernooij
initial work fixing walkdirs.
998
                yield (current_inv[0][0], current_inv[0][1]), dirblock
999
                try:
1000
                    current_inv = next(inventory_iterator)
1001
                except StopIteration:
1002
                    inv_finished = True
1003
            else:
1004
                # versioned present directory
1005
                # merge the inventory and disk data together
1006
                dirblock = []
1007
                for relpath, subiterator in itertools.groupby(sorted(
7143.15.2 by Jelmer Vernooij
Run autopep8.
1008
                        current_inv[1] + cur_disk_dir_content,
1009
                        key=operator.itemgetter(0)), operator.itemgetter(1)):
0.324.1 by Jelmer Vernooij
initial work fixing walkdirs.
1010
                    path_elements = list(subiterator)
1011
                    if len(path_elements) == 2:
1012
                        inv_row, disk_row = path_elements
1013
                        # versioned, present file
1014
                        dirblock.append((inv_row[0],
7143.15.2 by Jelmer Vernooij
Run autopep8.
1015
                                         inv_row[1], disk_row[2],
1016
                                         disk_row[3], inv_row[4],
1017
                                         inv_row[5]))
0.324.1 by Jelmer Vernooij
initial work fixing walkdirs.
1018
                    elif len(path_elements[0]) == 5:
1019
                        # unknown disk file
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
1020
                        dirblock.append(
1021
                            (path_elements[0][0], path_elements[0][1],
1022
                                path_elements[0][2], path_elements[0][3],
1023
                                None, None))
0.324.1 by Jelmer Vernooij
initial work fixing walkdirs.
1024
                    elif len(path_elements[0]) == 6:
1025
                        # versioned, absent file.
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
1026
                        dirblock.append(
1027
                            (path_elements[0][0], path_elements[0][1],
1028
                                'unknown', None, path_elements[0][4],
1029
                                path_elements[0][5]))
0.324.1 by Jelmer Vernooij
initial work fixing walkdirs.
1030
                    else:
1031
                        raise NotImplementedError('unreachable code')
1032
                yield current_inv[0], dirblock
1033
                try:
1034
                    current_inv = next(inventory_iterator)
1035
                except StopIteration:
1036
                    inv_finished = True
1037
                try:
1038
                    current_disk = next(disk_iterator)
1039
                except StopIteration:
1040
                    disk_finished = True
1041
7027.5.2 by Jelmer Vernooij
Fix some more git tests.
1042
    def _walkdirs(self, prefix=u""):
1043
        if prefix != u"":
1044
            prefix += u"/"
7490.70.1 by Jelmer Vernooij
Add functions for encoding/decoding git paths.
1045
        prefix = encode_git_path(prefix)
0.353.1 by Jelmer Vernooij
Iterate over dirs in _walkdirs.
1046
        per_dir = defaultdict(set)
7027.5.2 by Jelmer Vernooij
Fix some more git tests.
1047
        if prefix == b"":
7358.14.1 by Jelmer Vernooij
Remove Tree.get_root_id() in favour of Tree.path2id('').
1048
            per_dir[(u'', self.path2id(''))] = set()
7143.15.2 by Jelmer Vernooij
Run autopep8.
1049
0.353.1 by Jelmer Vernooij
Iterate over dirs in _walkdirs.
1050
        def add_entry(path, kind):
7027.5.2 by Jelmer Vernooij
Fix some more git tests.
1051
            if path == b'' or not path.startswith(prefix):
0.353.1 by Jelmer Vernooij
Iterate over dirs in _walkdirs.
1052
                return
0.200.1210 by Jelmer Vernooij
Implement GitWorkingTree._walkdirs.
1053
            (dirname, child_name) = posixpath.split(path)
0.353.1 by Jelmer Vernooij
Iterate over dirs in _walkdirs.
1054
            add_entry(dirname, 'directory')
7490.70.1 by Jelmer Vernooij
Add functions for encoding/decoding git paths.
1055
            dirname = decode_git_path(dirname)
0.200.1210 by Jelmer Vernooij
Implement GitWorkingTree._walkdirs.
1056
            dir_file_id = self.path2id(dirname)
0.361.2 by Jelmer Vernooij
Fix up assert.
1057
            if not isinstance(value, tuple) or len(value) != 10:
0.361.1 by Jelmer Vernooij
Don't use assert.
1058
                raise ValueError(value)
0.353.1 by Jelmer Vernooij
Iterate over dirs in _walkdirs.
1059
            per_dir[(dirname, dir_file_id)].add(
7490.70.1 by Jelmer Vernooij
Add functions for encoding/decoding git paths.
1060
                (decode_git_path(path), decode_git_path(child_name),
7143.15.2 by Jelmer Vernooij
Run autopep8.
1061
                 kind, None,
7490.70.1 by Jelmer Vernooij
Add functions for encoding/decoding git paths.
1062
                 self.path2id(decode_git_path(path)),
7143.15.2 by Jelmer Vernooij
Run autopep8.
1063
                 kind))
0.379.1 by Jelmer Vernooij
Improve unicode handling in GitWorkingTree.
1064
        with self.lock_read():
1065
            for path, value in self.index.iteritems():
1066
                if self.mapping.is_special_file(path):
1067
                    continue
1068
                if not path.startswith(prefix):
1069
                    continue
1070
                add_entry(path, mode_kind(value.mode))
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
1071
        return ((k, sorted(v)) for (k, v) in sorted(per_dir.items()))
0.200.1542 by Jelmer Vernooij
Refactor iter_changes.
1072
0.200.1677 by Jelmer Vernooij
Mark shelving as unsupported.
1073
    def get_shelf_manager(self):
0.200.1729 by Jelmer Vernooij
ShelvingUnsupported doesn't take an argument.
1074
        raise workingtree.ShelvingUnsupported()
0.200.1677 by Jelmer Vernooij
Mark shelving as unsupported.
1075
0.200.1678 by Jelmer Vernooij
Fix tests.
1076
    def store_uncommitted(self):
1077
        raise errors.StoringUncommittedNotSupported(self)
1078
0.200.1703 by Jelmer Vernooij
Implement apply_inventory_delta.
1079
    def apply_inventory_delta(self, changes):
1080
        for (old_path, new_path, file_id, ie) in changes:
1081
            if old_path is not None:
7143.15.2 by Jelmer Vernooij
Run autopep8.
1082
                (index, old_subpath) = self._lookup_index(
7490.70.1 by Jelmer Vernooij
Add functions for encoding/decoding git paths.
1083
                    encode_git_path(old_path))
0.385.1 by Jelmer Vernooij
Use specific_files argument to Tree.iter_entries_by_dir.
1084
                try:
0.429.25 by Jelmer Vernooij
Merge trunk.
1085
                    self._index_del_entry(index, old_subpath)
0.385.1 by Jelmer Vernooij
Use specific_files argument to Tree.iter_entries_by_dir.
1086
                except KeyError:
1087
                    pass
1088
                else:
1089
                    self._versioned_dirs = None
0.200.1703 by Jelmer Vernooij
Implement apply_inventory_delta.
1090
            if new_path is not None and ie.kind != 'directory':
0.429.16 by Jelmer Vernooij
Look at reference_revision on ie.
1091
                if ie.kind == 'tree-reference':
1092
                    self._index_add_entry(
7143.15.2 by Jelmer Vernooij
Run autopep8.
1093
                        new_path, ie.kind,
1094
                        reference_revision=ie.reference_revision)
0.429.16 by Jelmer Vernooij
Look at reference_revision on ie.
1095
                else:
1096
                    self._index_add_entry(new_path, ie.kind)
0.316.2 by Jelmer Vernooij
Flush after modifying index.
1097
        self.flush()
0.200.1703 by Jelmer Vernooij
Implement apply_inventory_delta.
1098
7141.7.1 by Jelmer Vernooij
Get rid of file_ids in most of Tree.
1099
    def annotate_iter(self, path,
0.200.1756 by Jelmer Vernooij
Initial work on annotate support.
1100
                      default_revision=_mod_revision.CURRENT_REVISION):
1101
        """See Tree.annotate_iter
1102
1103
        This implementation will use the basis tree implementation if possible.
1104
        Lines not in the basis are attributed to CURRENT_REVISION
1105
1106
        If there are pending merges, lines added by those merges will be
1107
        incorrectly attributed to CURRENT_REVISION (but after committing, the
1108
        attribution will be correct).
1109
        """
1110
        with self.lock_read():
1111
            maybe_file_parent_keys = []
1112
            for parent_id in self.get_parent_ids():
1113
                try:
1114
                    parent_tree = self.revision_tree(parent_id)
1115
                except errors.NoSuchRevisionInTree:
1116
                    parent_tree = self.branch.repository.revision_tree(
7143.15.2 by Jelmer Vernooij
Run autopep8.
1117
                        parent_id)
0.200.1756 by Jelmer Vernooij
Initial work on annotate support.
1118
                with parent_tree.lock_read():
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
1119
                    # TODO(jelmer): Use rename/copy tracker to find path name
1120
                    # in parent
0.200.1756 by Jelmer Vernooij
Initial work on annotate support.
1121
                    parent_path = path
1122
                    try:
1123
                        kind = parent_tree.kind(parent_path)
1124
                    except errors.NoSuchFile:
1125
                        continue
1126
                    if kind != 'file':
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
1127
                        # Note: this is slightly unnecessary, because symlinks
1128
                        # and directories have a "text" which is the empty
1129
                        # text, and we know that won't mess up annotations. But
1130
                        # it seems cleaner
0.200.1756 by Jelmer Vernooij
Initial work on annotate support.
1131
                        continue
1132
                    parent_text_key = (
1133
                        parent_path,
1134
                        parent_tree.get_file_revision(parent_path))
1135
                    if parent_text_key not in maybe_file_parent_keys:
1136
                        maybe_file_parent_keys.append(parent_text_key)
7045.4.2 by Jelmer Vernooij
Fix some more gitty tests.
1137
            # Now we have the parents of this content
1138
            from breezy.annotate import Annotator
1139
            from .annotate import AnnotateProvider
1140
            annotate_provider = AnnotateProvider(
1141
                self.branch.repository._file_change_scanner)
1142
            annotator = Annotator(annotate_provider)
1143
1144
            from breezy.graph import Graph
1145
            graph = Graph(annotate_provider)
0.200.1756 by Jelmer Vernooij
Initial work on annotate support.
1146
            heads = graph.heads(maybe_file_parent_keys)
1147
            file_parent_keys = []
1148
            for key in maybe_file_parent_keys:
1149
                if key in heads:
1150
                    file_parent_keys.append(key)
1151
1152
            text = self.get_file_text(path)
1153
            this_key = (path, default_revision)
1154
            annotator.add_special_text(this_key, file_parent_keys, text)
1155
            annotations = [(key[-1], line)
1156
                           for key, line in annotator.annotate_flat(this_key)]
1157
            return annotations
1158
0.360.4 by Jelmer Vernooij
Implement MemoryTree.rename_one, MemoryTree.mkdir.
1159
    def _rename_one(self, from_rel, to_rel):
1160
        os.rename(self.abspath(from_rel), self.abspath(to_rel))
1161
0.373.1 by Jelmer Vernooij
Fix WorkingTree.reset_state().
1162
    def _build_checkout_with_index(self):
1163
        build_index_from_tree(
1164
            self.user_transport.local_abspath('.'),
1165
            self.control_transport.local_abspath("index"),
1166
            self.store,
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
1167
            None
1168
            if self.branch.head is None
7122.6.3 by Jelmer Vernooij
Merge trunk.
1169
            else self.store[self.branch.head].tree,
7122.7.5 by Jelmer Vernooij
Only trust filesystem for executable bit where supported.
1170
            honor_filemode=self._supports_executable())
0.373.1 by Jelmer Vernooij
Fix WorkingTree.reset_state().
1171
0.371.1 by Jelmer Vernooij
Implement WorkingTree.reset_state().
1172
    def reset_state(self, revision_ids=None):
1173
        """Reset the state of the working tree.
1174
1175
        This does a hard-reset to a last-known-good state. This is a way to
1176
        fix if something got corrupted (like the .git/index file)
1177
        """
1178
        with self.lock_tree_write():
1179
            if revision_ids is not None:
1180
                self.set_parent_ids(revision_ids)
0.373.1 by Jelmer Vernooij
Fix WorkingTree.reset_state().
1181
            self.index.clear()
0.415.1 by Jelmer Vernooij
Only write index when it's dirty.
1182
            self._index_dirty = True
0.373.1 by Jelmer Vernooij
Fix WorkingTree.reset_state().
1183
            if self.branch.head is not None:
7143.15.3 by Jelmer Vernooij
Fix pep8 issues in breezy.git.
1184
                for entry in self.store.iter_tree_contents(
1185
                        self.store[self.branch.head].tree):
0.373.1 by Jelmer Vernooij
Fix WorkingTree.reset_state().
1186
                    if not validate_path(entry.path):
1187
                        continue
1188
1189
                    if S_ISGITLINK(entry.mode):
7143.15.2 by Jelmer Vernooij
Run autopep8.
1190
                        pass  # TODO(jelmer): record and return submodule paths
0.373.1 by Jelmer Vernooij
Fix WorkingTree.reset_state().
1191
                    else:
1192
                        # Let's at least try to use the working tree file:
1193
                        try:
7143.15.2 by Jelmer Vernooij
Run autopep8.
1194
                            st = self._lstat(self.abspath(
7490.70.1 by Jelmer Vernooij
Add functions for encoding/decoding git paths.
1195
                                decode_git_path(entry.path)))
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
1196
                        except OSError:
0.373.1 by Jelmer Vernooij
Fix WorkingTree.reset_state().
1197
                            # But if it doesn't exist, we'll make something up.
1198
                            obj = self.store[entry.sha]
1199
                            st = os.stat_result((entry.mode, 0, 0, 0,
7143.15.2 by Jelmer Vernooij
Run autopep8.
1200
                                                 0, 0, len(
1201
                                                     obj.as_raw_string()), 0,
1202
                                                 0, 0))
0.429.2 by Jelmer Vernooij
Some more work on submodule support.
1203
                    (index, subpath) = self._lookup_index(entry.path)
1204
                    index[subpath] = index_entry_from_stat(st, entry.sha, 0)
0.371.1 by Jelmer Vernooij
Implement WorkingTree.reset_state().
1205
7290.26.1 by Jelmer Vernooij
Fix switching in git repositories.
1206
    def _update_git_tree(self, old_revision, new_revision, change_reporter=None,
1207
                         show_base=False):
1208
        basis_tree = self.revision_tree(old_revision)
1209
        if new_revision != old_revision:
1210
            with basis_tree.lock_read():
1211
                new_basis_tree = self.branch.basis_tree()
1212
                merge.merge_inner(
1213
                    self.branch,
1214
                    new_basis_tree,
1215
                    basis_tree,
1216
                    this_tree=self,
1217
                    change_reporter=change_reporter,
1218
                    show_base=show_base)
1219
0.380.1 by Jelmer Vernooij
Implement WorkingTree.pull.
1220
    def pull(self, source, overwrite=False, stop_revision=None,
1221
             change_reporter=None, possible_transports=None, local=False,
7489.4.2 by Jelmer Vernooij
Plumb through tag_selector.
1222
             show_base=False, tag_selector=None):
0.380.1 by Jelmer Vernooij
Implement WorkingTree.pull.
1223
        with self.lock_write(), source.lock_read():
1224
            old_revision = self.branch.last_revision()
1225
            count = self.branch.pull(source, overwrite, stop_revision,
1226
                                     possible_transports=possible_transports,
7489.4.2 by Jelmer Vernooij
Plumb through tag_selector.
1227
                                     local=local, tag_selector=tag_selector)
7290.26.1 by Jelmer Vernooij
Fix switching in git repositories.
1228
            self._update_git_tree(
1229
                old_revision=old_revision,
1230
                new_revision=self.branch.last_revision(),
1231
                change_reporter=change_reporter,
1232
                show_base=show_base)
0.380.1 by Jelmer Vernooij
Implement WorkingTree.pull.
1233
            return count
1234
0.429.2 by Jelmer Vernooij
Some more work on submodule support.
1235
    def add_reference(self, sub_tree):
1236
        """Add a TreeReference to the tree, pointing at sub_tree.
1237
1238
        :param sub_tree: subtree to add.
1239
        """
1240
        with self.lock_tree_write():
1241
            try:
1242
                sub_tree_path = self.relpath(sub_tree.basedir)
1243
            except errors.PathNotChild:
1244
                raise BadReferenceTarget(
7143.15.2 by Jelmer Vernooij
Run autopep8.
1245
                    self, sub_tree, 'Target not inside tree.')
0.429.2 by Jelmer Vernooij
Some more work on submodule support.
1246
1247
            self._add([sub_tree_path], [None], ['tree-reference'])
1248
0.429.10 by Jelmer Vernooij
use new read_submodule_head from dulwich.
1249
    def _read_submodule_head(self, path):
1250
        return read_submodule_head(self.abspath(path))
1251
7447.3.3 by Jelmer Vernooij
Fix some blackbox tests.
1252
    def get_reference_revision(self, path, branch=None):
0.429.5 by Jelmer Vernooij
Fix tree_content_summary test.
1253
        hexsha = self._read_submodule_head(path)
0.429.16 by Jelmer Vernooij
Look at reference_revision on ie.
1254
        if hexsha is None:
1255
            return _mod_revision.NULL_REVISION
0.429.5 by Jelmer Vernooij
Fix tree_content_summary test.
1256
        return self.branch.lookup_foreign_revision_id(hexsha)
1257
7141.7.1 by Jelmer Vernooij
Get rid of file_ids in most of Tree.
1258
    def get_nested_tree(self, path):
0.429.2 by Jelmer Vernooij
Some more work on submodule support.
1259
        return workingtree.WorkingTree.open(self.abspath(path))
1260
0.429.5 by Jelmer Vernooij
Fix tree_content_summary test.
1261
    def _directory_is_tree_reference(self, relpath):
1262
        # as a special case, if a directory contains control files then
1263
        # it's a tree reference, except that the root of the tree is not
1264
        return relpath and osutils.lexists(self.abspath(relpath) + u"/.git")
1265
7141.7.1 by Jelmer Vernooij
Get rid of file_ids in most of Tree.
1266
    def extract(self, sub_path, format=None):
0.429.15 by Jelmer Vernooij
Autodetect tree-reference based on index.
1267
        """Extract a subtree from this tree.
1268
1269
        A new branch will be created, relative to the path for this tree.
1270
        """
1271
        def mkdirs(path):
1272
            segments = osutils.splitpath(path)
1273
            transport = self.branch.controldir.root_transport
1274
            for name in segments:
1275
                transport = transport.clone(name)
1276
                transport.ensure_base()
1277
            return transport
1278
1279
        with self.lock_tree_write():
1280
            self.flush()
1281
            branch_transport = mkdirs(sub_path)
1282
            if format is None:
1283
                format = self.controldir.cloning_metadir()
1284
            branch_transport.ensure_base()
1285
            branch_bzrdir = format.initialize_on_transport(branch_transport)
1286
            try:
1287
                repo = branch_bzrdir.find_repository()
1288
            except errors.NoRepositoryPresent:
1289
                repo = branch_bzrdir.create_repository()
1290
            if not repo.supports_rich_root():
1291
                raise errors.RootNotRich()
1292
            new_branch = branch_bzrdir.create_branch()
1293
            new_branch.pull(self.branch)
1294
            for parent_id in self.get_parent_ids():
1295
                new_branch.fetch(self.branch, parent_id)
1296
            tree_transport = self.controldir.root_transport.clone(sub_path)
1297
            if tree_transport.base != branch_transport.base:
1298
                tree_bzrdir = format.initialize_on_transport(tree_transport)
1299
                tree_bzrdir.set_branch_reference(new_branch)
1300
            else:
1301
                tree_bzrdir = branch_bzrdir
1302
            wt = tree_bzrdir.create_workingtree(_mod_revision.NULL_REVISION)
1303
            wt.set_parent_ids(self.get_parent_ids())
1304
            return wt
1305
0.425.1 by Jelmer Vernooij
Add really basic check implementation.
1306
    def _get_check_refs(self):
1307
        """Return the references needed to perform a check of this tree.
1308
1309
        The default implementation returns no refs, and is only suitable for
1310
        trees that have no local caching and can commit on ghosts at any time.
1311
1312
        :seealso: breezy.check for details about check_refs.
1313
        """
1314
        return []
1315
0.428.1 by Jelmer Vernooij
Fix clone_preserves_content test.
1316
    def copy_content_into(self, tree, revision_id=None):
1317
        """Copy the current content and user files of this tree into tree."""
1318
        with self.lock_read():
1319
            if revision_id is None:
1320
                merge.transform_tree(tree, self)
1321
            else:
1322
                # TODO now merge from tree.last_revision to revision (to
1323
                # preserve user local changes)
1324
                try:
1325
                    other_tree = self.revision_tree(revision_id)
1326
                except errors.NoSuchRevision:
1327
                    other_tree = self.branch.repository.revision_tree(
7143.15.2 by Jelmer Vernooij
Run autopep8.
1328
                        revision_id)
0.428.1 by Jelmer Vernooij
Fix clone_preserves_content test.
1329
1330
                merge.transform_tree(tree, other_tree)
1331
                if revision_id == _mod_revision.NULL_REVISION:
1332
                    new_parents = []
1333
                else:
1334
                    new_parents = [revision_id]
1335
                tree.set_parent_ids(new_parents)
1336
7447.3.1 by Jelmer Vernooij
Move tree reference info functions to workingtree.
1337
    def reference_parent(self, path, possible_transports=None):
1338
        remote_url = self.get_reference_info(path)
1339
        if remote_url is None:
1340
            trace.warning("Unable to find submodule info for %s", path)
1341
            return None
1342
        return _mod_branch.Branch.open(remote_url, possible_transports=possible_transports)
1343
1344
    def get_reference_info(self, path):
1345
        submodule_info = self._submodule_info()
7490.70.1 by Jelmer Vernooij
Add functions for encoding/decoding git paths.
1346
        info = submodule_info.get(encode_git_path(path))
7447.3.1 by Jelmer Vernooij
Move tree reference info functions to workingtree.
1347
        if info is None:
1348
            return None
7490.70.1 by Jelmer Vernooij
Add functions for encoding/decoding git paths.
1349
        return decode_git_path(info[0])
7447.3.1 by Jelmer Vernooij
Move tree reference info functions to workingtree.
1350
1351
    def set_reference_info(self, tree_path, branch_location):
1352
        path = self.abspath('.gitmodules')
1353
        try:
1354
            config = GitConfigFile.from_path(path)
1355
        except EnvironmentError as e:
1356
            if e.errno == errno.ENOENT:
1357
                config = GitConfigFile()
1358
            else:
1359
                raise
7490.70.1 by Jelmer Vernooij
Add functions for encoding/decoding git paths.
1360
        section = (b'submodule', encode_git_path(tree_path))
7447.3.1 by Jelmer Vernooij
Move tree reference info functions to workingtree.
1361
        if branch_location is None:
1362
            try:
1363
                del config[section]
1364
            except KeyError:
1365
                pass
1366
        else:
7447.3.4 by Jelmer Vernooij
Fix tests.
1367
            branch_location = urlutils.join(
1368
                urlutils.strip_segment_parameters(self.branch.user_url),
1369
                branch_location)
7447.3.1 by Jelmer Vernooij
Move tree reference info functions to workingtree.
1370
            config.set(
1371
                section,
7490.70.1 by Jelmer Vernooij
Add functions for encoding/decoding git paths.
1372
                b'path', encode_git_path(tree_path))
7447.3.1 by Jelmer Vernooij
Move tree reference info functions to workingtree.
1373
            config.set(
1374
                section,
1375
                b'url', branch_location.encode('utf-8'))
1376
        config.write_to_path(path)
1377
        self.add('.gitmodules')
1378
0.200.1308 by Jelmer Vernooij
Write index to disk after adding files.
1379
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
1380
class GitWorkingTreeFormat(workingtree.WorkingTreeFormat):
1381
0.200.1206 by Jelmer Vernooij
Implement GitWorkingTree.all_file_ids.
1382
    _tree_class = GitWorkingTree
1383
0.200.1295 by Jelmer Vernooij
Mark working trees as not supporting directories.
1384
    supports_versioned_directories = False
1385
0.200.1661 by Jelmer Vernooij
Set supports_setting_file_ids to False.
1386
    supports_setting_file_ids = False
1387
0.200.1677 by Jelmer Vernooij
Mark shelving as unsupported.
1388
    supports_store_uncommitted = False
1389
0.200.1723 by Jelmer Vernooij
Set supports_leftmost_parent_id_as_ghost property.
1390
    supports_leftmost_parent_id_as_ghost = False
1391
0.200.1779 by Jelmer Vernooij
Actually store git revision ids rather than bzr revision ids.
1392
    supports_righthand_parent_id_as_ghost = False
1393
0.200.1768 by Jelmer Vernooij
Fix handling of normalized filenames.
1394
    requires_normalized_unicode_filenames = True
1395
0.367.1 by Jelmer Vernooij
Set supports_merge_modified flag.
1396
    supports_merge_modified = False
1397
7199.4.1 by Jelmer Vernooij
Fix 'brz ignore' in Git working trees.
1398
    ignore_filename = ".gitignore"
1399
0.200.656 by Jelmer Vernooij
Implement GitWorkingTreeFormat._matchingbzrdir.
1400
    @property
0.200.1665 by Jelmer Vernooij
Rename _matchingbzrdir to _matchingcnotroldir.
1401
    def _matchingcontroldir(self):
0.200.1641 by Jelmer Vernooij
Use relative imports where possible.
1402
        from .dir import LocalGitControlDirFormat
0.200.1013 by Jelmer Vernooij
More renames.
1403
        return LocalGitControlDirFormat()
0.200.656 by Jelmer Vernooij
Implement GitWorkingTreeFormat._matchingbzrdir.
1404
0.200.90 by Jelmer Vernooij
Basic support for opening working trees.
1405
    def get_format_description(self):
1406
        return "Git Working Tree"
0.200.616 by Jelmer Vernooij
Provide custom intertree implementation for GitRevisionTree->GitWorkingTree.
1407
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
1408
    def initialize(self, a_controldir, revision_id=None, from_branch=None,
0.200.1096 by Jelmer Vernooij
Implement GitWorkingTreeFormat.initialize.
1409
                   accelerator_tree=None, hardlink=False):
1410
        """See WorkingTreeFormat.initialize()."""
0.200.1648 by Jelmer Vernooij
Fix compatibility with newer versions of breezy.
1411
        if not isinstance(a_controldir, LocalGitDir):
1412
            raise errors.IncompatibleFormat(self, a_controldir)
0.388.2 by Jelmer Vernooij
Allow opening nascent branches when opening trees.
1413
        branch = a_controldir.open_branch(nascent_ok=True)
0.308.1 by Jelmer Vernooij
Set revision id if specified to WorkingTreeFormat.initialize.
1414
        if revision_id is not None:
1415
            branch.set_last_revision(revision_id)
0.200.1680 by Jelmer Vernooij
Fix repo locks.
1416
        wt = GitWorkingTree(
7143.15.2 by Jelmer Vernooij
Run autopep8.
1417
            a_controldir, a_controldir.open_repository(), branch)
0.200.1680 by Jelmer Vernooij
Fix repo locks.
1418
        for hook in MutableTree.hooks['post_build_tree']:
1419
            hook(wt)
1420
        return wt