bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5752.3.8
by John Arbash Meinel
Merge bzr.dev 5764 to resolve release-notes (aka NEWS) conflicts |
1 |
# Copyright (C) 2005-2011 Canonical Ltd
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
2 |
#
|
1
by mbp at sourcefrog
import from baz patch-364 |
3 |
# This program is free software; you can redistribute it and/or modify
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
7 |
#
|
1
by mbp at sourcefrog
import from baz patch-364 |
8 |
# This program is distributed in the hope that it will be useful,
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
12 |
#
|
1
by mbp at sourcefrog
import from baz patch-364 |
13 |
# You should have received a copy of the GNU General Public License
|
14 |
# along with this program; if not, write to the Free Software
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
1
by mbp at sourcefrog
import from baz patch-364 |
16 |
|
17 |
"""Tree classes, representing directory at point in time.
|
|
18 |
"""
|
|
19 |
||
6731.1.1
by Jelmer Vernooij
Move FileTimestampUnavailable to breezy.tree. |
20 |
from . import ( |
21 |
errors, |
|
6754.8.3
by Jelmer Vernooij
Use context manager in decorators. |
22 |
lock, |
6731.1.1
by Jelmer Vernooij
Move FileTimestampUnavailable to breezy.tree. |
23 |
osutils, |
7490.79.2
by Jelmer Vernooij
Add Tree.preview_transform. |
24 |
revision as _mod_revision, |
7467.4.15
by Jelmer Vernooij
Split out InventoryInterTree. |
25 |
trace, |
6731.1.1
by Jelmer Vernooij
Move FileTimestampUnavailable to breezy.tree. |
26 |
)
|
6624
by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes') |
27 |
from .inter import InterObject |
1
by mbp at sourcefrog
import from baz patch-364 |
28 |
|
1852.5.1
by Robert Collins
Deprecate EmptyTree in favour of using Repository.revision_tree. |
29 |
|
6731.1.1
by Jelmer Vernooij
Move FileTimestampUnavailable to breezy.tree. |
30 |
class FileTimestampUnavailable(errors.BzrError): |
31 |
||
32 |
_fmt = "The filestamp for %(path)s is not available." |
|
33 |
||
34 |
internal_error = True |
|
35 |
||
36 |
def __init__(self, path): |
|
37 |
self.path = path |
|
38 |
||
39 |
||
7358.4.1
by Jelmer Vernooij
Add Tree.get_nested_tree. |
40 |
class MissingNestedTree(errors.BzrError): |
41 |
||
42 |
_fmt = "The nested tree for %(path)s can not be resolved.""" |
|
43 |
||
44 |
def __init__(self, path): |
|
45 |
self.path = path |
|
46 |
||
47 |
||
6846.6.1
by Jelmer Vernooij
Move Tree{Link,File,Directory,Entry} to breezy.tree. |
48 |
class TreeEntry(object): |
49 |
"""An entry that implements the minimum interface used by commands. |
|
50 |
"""
|
|
51 |
||
7322.3.1
by Jelmer Vernooij
Use slots on default Tree objects. |
52 |
__slots__ = [] |
53 |
||
6846.6.1
by Jelmer Vernooij
Move Tree{Link,File,Directory,Entry} to breezy.tree. |
54 |
def __eq__(self, other): |
6857
by Jelmer Vernooij
Merge lp:~jelmer/brz/move-ie. |
55 |
# yes, this is ugly, TODO: best practice __eq__ style.
|
6846.6.1
by Jelmer Vernooij
Move Tree{Link,File,Directory,Entry} to breezy.tree. |
56 |
return (isinstance(other, TreeEntry) |
57 |
and other.__class__ == self.__class__) |
|
58 |
||
7143.19.2
by Jelmer Vernooij
Some test fixes. |
59 |
kind = None |
60 |
||
6846.6.1
by Jelmer Vernooij
Move Tree{Link,File,Directory,Entry} to breezy.tree. |
61 |
def kind_character(self): |
62 |
return "???" |
|
63 |
||
7397.2.1
by Jelmer Vernooij
Add TreeEntry.is_unmodified. |
64 |
def is_unmodified(self, other): |
65 |
"""Does this entry reference the same entry? |
|
66 |
||
67 |
This is mostly the same as __eq__, but returns False
|
|
68 |
for entries without enough information (i.e. revision is None)
|
|
69 |
"""
|
|
70 |
return False |
|
71 |
||
6846.6.1
by Jelmer Vernooij
Move Tree{Link,File,Directory,Entry} to breezy.tree. |
72 |
|
73 |
class TreeDirectory(TreeEntry): |
|
74 |
"""See TreeEntry. This is a directory in a working tree.""" |
|
75 |
||
7322.3.1
by Jelmer Vernooij
Use slots on default Tree objects. |
76 |
__slots__ = [] |
77 |
||
7143.19.2
by Jelmer Vernooij
Some test fixes. |
78 |
kind = 'directory' |
79 |
||
6846.6.1
by Jelmer Vernooij
Move Tree{Link,File,Directory,Entry} to breezy.tree. |
80 |
def kind_character(self): |
81 |
return "/" |
|
82 |
||
83 |
||
84 |
class TreeFile(TreeEntry): |
|
85 |
"""See TreeEntry. This is a regular file in a working tree.""" |
|
86 |
||
7322.3.1
by Jelmer Vernooij
Use slots on default Tree objects. |
87 |
__slots__ = [] |
88 |
||
7143.19.2
by Jelmer Vernooij
Some test fixes. |
89 |
kind = 'file' |
90 |
||
6846.6.1
by Jelmer Vernooij
Move Tree{Link,File,Directory,Entry} to breezy.tree. |
91 |
def kind_character(self): |
92 |
return '' |
|
93 |
||
94 |
||
95 |
class TreeLink(TreeEntry): |
|
96 |
"""See TreeEntry. This is a symlink in a working tree.""" |
|
97 |
||
7322.3.1
by Jelmer Vernooij
Use slots on default Tree objects. |
98 |
__slots__ = [] |
99 |
||
7143.19.2
by Jelmer Vernooij
Some test fixes. |
100 |
kind = 'symlink' |
101 |
||
6846.6.1
by Jelmer Vernooij
Move Tree{Link,File,Directory,Entry} to breezy.tree. |
102 |
def kind_character(self): |
103 |
return '' |
|
104 |
||
105 |
||
6926.2.1
by Jelmer Vernooij
Some tree reference fixes. |
106 |
class TreeReference(TreeEntry): |
107 |
"""See TreeEntry. This is a reference to a nested tree in a working tree.""" |
|
108 |
||
7322.3.1
by Jelmer Vernooij
Use slots on default Tree objects. |
109 |
__slots__ = [] |
110 |
||
7143.19.2
by Jelmer Vernooij
Some test fixes. |
111 |
kind = 'tree-reference' |
112 |
||
6926.2.1
by Jelmer Vernooij
Some tree reference fixes. |
113 |
def kind_character(self): |
7143.19.2
by Jelmer Vernooij
Some test fixes. |
114 |
return '+' |
6926.2.1
by Jelmer Vernooij
Some tree reference fixes. |
115 |
|
116 |
||
7322.1.1
by Jelmer Vernooij
Add TreeChange object. |
117 |
class TreeChange(object): |
118 |
"""Describes the changes between the same item in two different trees.""" |
|
119 |
||
7490.120.2
by Jelmer Vernooij
Add InventoryTreeChange. |
120 |
__slots__ = ['path', 'changed_content', 'versioned', |
7358.17.1
by Jelmer Vernooij
Add TreeDelta.copied and TreeChange.copied fields. |
121 |
'name', 'kind', 'executable', 'copied'] |
7322.1.1
by Jelmer Vernooij
Add TreeChange object. |
122 |
|
7490.120.3
by Jelmer Vernooij
Split out InventoryTreeChange from TreeChange. |
123 |
def __init__(self, path, changed_content, versioned, |
7358.17.1
by Jelmer Vernooij
Add TreeDelta.copied and TreeChange.copied fields. |
124 |
name, kind, executable, copied=False): |
7322.1.4
by Jelmer Vernooij
Use singular for consistency. |
125 |
self.path = path |
7322.1.1
by Jelmer Vernooij
Add TreeChange object. |
126 |
self.changed_content = changed_content |
127 |
self.versioned = versioned |
|
128 |
self.name = name |
|
129 |
self.kind = kind |
|
130 |
self.executable = executable |
|
7358.17.1
by Jelmer Vernooij
Add TreeDelta.copied and TreeChange.copied fields. |
131 |
self.copied = copied |
7322.1.1
by Jelmer Vernooij
Add TreeChange object. |
132 |
|
7358.11.3
by Jelmer Vernooij
TreeDelta holds TreeChange objects rather than tuples of various sizes. |
133 |
def __repr__(self): |
7358.16.1
by Jelmer Vernooij
Don't make TreeChange tuple-like objects anymore, so we can add and remove attributes as necessary. |
134 |
return "%s%r" % (self.__class__.__name__, self._as_tuple()) |
7358.11.3
by Jelmer Vernooij
TreeDelta holds TreeChange objects rather than tuples of various sizes. |
135 |
|
7358.16.1
by Jelmer Vernooij
Don't make TreeChange tuple-like objects anymore, so we can add and remove attributes as necessary. |
136 |
def _as_tuple(self): |
7490.120.2
by Jelmer Vernooij
Add InventoryTreeChange. |
137 |
return (self.path, self.changed_content, self.versioned, |
138 |
self.name, self.kind, self.executable, self.copied) |
|
7322.1.1
by Jelmer Vernooij
Add TreeChange object. |
139 |
|
140 |
def __eq__(self, other): |
|
141 |
if isinstance(other, TreeChange): |
|
7358.16.1
by Jelmer Vernooij
Don't make TreeChange tuple-like objects anymore, so we can add and remove attributes as necessary. |
142 |
return self._as_tuple() == other._as_tuple() |
7322.1.1
by Jelmer Vernooij
Add TreeChange object. |
143 |
if isinstance(other, tuple): |
7358.16.1
by Jelmer Vernooij
Don't make TreeChange tuple-like objects anymore, so we can add and remove attributes as necessary. |
144 |
return self._as_tuple() == other |
7322.1.1
by Jelmer Vernooij
Add TreeChange object. |
145 |
return False |
146 |
||
7322.1.7
by Jelmer Vernooij
Fix remaining tests. |
147 |
def __lt__(self, other): |
7358.16.1
by Jelmer Vernooij
Don't make TreeChange tuple-like objects anymore, so we can add and remove attributes as necessary. |
148 |
return self._as_tuple() < other._as_tuple() |
7322.1.7
by Jelmer Vernooij
Fix remaining tests. |
149 |
|
7358.11.3
by Jelmer Vernooij
TreeDelta holds TreeChange objects rather than tuples of various sizes. |
150 |
def meta_modified(self): |
7358.11.9
by Jelmer Vernooij
Fix other tests. |
151 |
if self.versioned == (True, True): |
7358.11.3
by Jelmer Vernooij
TreeDelta holds TreeChange objects rather than tuples of various sizes. |
152 |
return (self.executable[0] != self.executable[1]) |
153 |
return False |
|
154 |
||
7490.134.1
by Jelmer Vernooij
Fix merging of copies. |
155 |
@property
|
156 |
def renamed(self): |
|
157 |
return ( |
|
158 |
not self.copied and |
|
159 |
None not in self.name and |
|
160 |
self.path[0] != self.path[1]) |
|
161 |
||
7324.2.1
by Jelmer Vernooij
Use find_previous_path in InterTree.iter_changes. |
162 |
def is_reparented(self): |
7490.120.2
by Jelmer Vernooij
Add InventoryTreeChange. |
163 |
return os.path.dirname(self.path[0]) != os.path.dirname(self.path[1]) |
7324.2.1
by Jelmer Vernooij
Use find_previous_path in InterTree.iter_changes. |
164 |
|
7322.1.7
by Jelmer Vernooij
Fix remaining tests. |
165 |
def discard_new(self): |
166 |
return self.__class__( |
|
7490.120.2
by Jelmer Vernooij
Add InventoryTreeChange. |
167 |
(self.path[0], None), self.changed_content, |
168 |
(self.versioned[0], None), |
|
7322.1.7
by Jelmer Vernooij
Fix remaining tests. |
169 |
(self.name[0], None), (self.kind[0], None), |
7358.17.1
by Jelmer Vernooij
Add TreeDelta.copied and TreeChange.copied fields. |
170 |
(self.executable[0], None), |
171 |
copied=False) |
|
7322.1.7
by Jelmer Vernooij
Fix remaining tests. |
172 |
|
7322.1.1
by Jelmer Vernooij
Add TreeChange object. |
173 |
|
558
by Martin Pool
- All top-level classes inherit from object |
174 |
class Tree(object): |
1
by mbp at sourcefrog
import from baz patch-364 |
175 |
"""Abstract file tree. |
176 |
||
177 |
There are several subclasses:
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
178 |
|
1
by mbp at sourcefrog
import from baz patch-364 |
179 |
* `WorkingTree` exists as files on disk editable by the user.
|
180 |
||
181 |
* `RevisionTree` is a tree as recorded at some point in the past.
|
|
182 |
||
183 |
Trees can be compared, etc, regardless of whether they are working
|
|
184 |
trees or versioned trees.
|
|
185 |
"""
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
186 |
|
6883.5.17
by Jelmer Vernooij
Add Tree.supports_rename_tracking(). |
187 |
def supports_rename_tracking(self): |
188 |
"""Whether this tree supports rename tracking. |
|
189 |
||
190 |
This defaults to True, but some implementations may want to override
|
|
191 |
it.
|
|
192 |
"""
|
|
193 |
return True |
|
194 |
||
6110.6.1
by Jelmer Vernooij
Add Tree.has_versioned_directories. |
195 |
def has_versioned_directories(self): |
196 |
"""Whether this tree can contain explicitly versioned directories. |
|
197 |
||
198 |
This defaults to True, but some implementations may want to override
|
|
199 |
it.
|
|
200 |
"""
|
|
201 |
return True |
|
202 |
||
7122.6.3
by Jelmer Vernooij
Merge trunk. |
203 |
def supports_symlinks(self): |
204 |
"""Does this tree support symbolic links? |
|
205 |
"""
|
|
206 |
return osutils.has_symlinks() |
|
207 |
||
1852.9.6
by Robert Collins
Merge the change from Tree.compare to Tree.changes_from. |
208 |
def changes_from(self, other, want_unchanged=False, specific_files=None, |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
209 |
extra_trees=None, require_versioned=False, include_root=False, |
210 |
want_unversioned=False): |
|
1852.8.8
by Robert Collins
change Tree.compare to Tree.changes_from - its better for the common case. |
211 |
"""Return a TreeDelta of the changes from other to this tree. |
1852.9.3
by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate. |
212 |
|
213 |
:param other: A tree to compare with.
|
|
214 |
:param specific_files: An optional list of file paths to restrict the
|
|
215 |
comparison to. When mapping filenames to ids, all matches in all
|
|
216 |
trees (including optional extra_trees) are used, and all children of
|
|
217 |
matched directories are included.
|
|
1852.9.4
by Robert Collins
Add minimal test for Tree.compare(extra_trees=...). |
218 |
:param want_unchanged: An optional boolean requesting the inclusion of
|
219 |
unchanged entries in the result.
|
|
220 |
:param extra_trees: An optional list of additional trees to use when
|
|
7141.7.1
by Jelmer Vernooij
Get rid of file_ids in most of Tree. |
221 |
mapping the contents of specific_files (paths) to their identities.
|
1852.9.5
by Robert Collins
Add tests for require_versioned to the InterTree.compare() test suite. |
222 |
:param require_versioned: An optional boolean (defaults to False). When
|
223 |
supplied and True all the 'specific_files' must be versioned, or
|
|
224 |
a PathsNotVersionedError will be thrown.
|
|
2255.7.90
by Robert Collins
Add unversioned path reporting to TreeDelta. |
225 |
:param want_unversioned: Scan for unversioned paths.
|
1852.9.3
by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate. |
226 |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
227 |
The comparison will be performed by an InterTree object looked up on
|
1852.8.4
by Robert Collins
Hook InterTree into Tree. |
228 |
self and other.
|
229 |
"""
|
|
1852.8.8
by Robert Collins
change Tree.compare to Tree.changes_from - its better for the common case. |
230 |
# Martin observes that Tree.changes_from returns a TreeDelta and this
|
231 |
# may confuse people, because the class name of the returned object is
|
|
232 |
# a synonym of the object referenced in the method name.
|
|
1852.9.6
by Robert Collins
Merge the change from Tree.compare to Tree.changes_from. |
233 |
return InterTree.get(other, self).compare( |
1852.9.4
by Robert Collins
Add minimal test for Tree.compare(extra_trees=...). |
234 |
want_unchanged=want_unchanged, |
235 |
specific_files=specific_files, |
|
1852.9.5
by Robert Collins
Add tests for require_versioned to the InterTree.compare() test suite. |
236 |
extra_trees=extra_trees, |
237 |
require_versioned=require_versioned, |
|
2255.7.90
by Robert Collins
Add unversioned path reporting to TreeDelta. |
238 |
include_root=include_root, |
239 |
want_unversioned=want_unversioned, |
|
1852.9.5
by Robert Collins
Add tests for require_versioned to the InterTree.compare() test suite. |
240 |
)
|
2012.1.1
by Aaron Bentley
Implement change iterator |
241 |
|
3254.1.1
by Aaron Bentley
Make Tree.iter_changes a public method |
242 |
def iter_changes(self, from_tree, include_unchanged=False, |
2255.2.149
by Robert Collins
Crufty but existing _iter_changes implementation for WorkingTreeFormat4. |
243 |
specific_files=None, pb=None, extra_trees=None, |
2255.7.85
by Robert Collins
Teach _iter_changes to gather unversioned path details upon request. |
244 |
require_versioned=True, want_unversioned=False): |
4988.10.6
by John Arbash Meinel
Fix bug #304182 by adding a trivial docstring to Tree.iter_changes |
245 |
"""See InterTree.iter_changes""" |
2012.1.5
by Aaron Bentley
Implement specific file id and dangling id handling |
246 |
intertree = InterTree.get(from_tree, self) |
3254.1.1
by Aaron Bentley
Make Tree.iter_changes a public method |
247 |
return intertree.iter_changes(include_unchanged, specific_files, pb, |
7122.6.5
by Jelmer Vernooij
More improvements, add tests. |
248 |
extra_trees, require_versioned, |
249 |
want_unversioned=want_unversioned) |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
250 |
|
1773.2.1
by Robert Collins
Teach all trees about unknowns, conflicts and get_parent_ids. |
251 |
def conflicts(self): |
252 |
"""Get a list of the conflicts in the tree. |
|
253 |
||
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
254 |
Each conflict is an instance of breezy.conflicts.Conflict.
|
1773.2.1
by Robert Collins
Teach all trees about unknowns, conflicts and get_parent_ids. |
255 |
"""
|
7490.79.2
by Jelmer Vernooij
Add Tree.preview_transform. |
256 |
from . import conflicts as _mod_conflicts |
2748.2.1
by Lukáš Lalinsky
Return ConflictsList() instead of [] from Tree.conflicts. |
257 |
return _mod_conflicts.ConflictList() |
1773.2.1
by Robert Collins
Teach all trees about unknowns, conflicts and get_parent_ids. |
258 |
|
2255.7.91
by Robert Collins
Move unknown detection in long status into the delta creation, saving a tree-scan. |
259 |
def extras(self): |
260 |
"""For trees that can have unversioned files, return all such paths.""" |
|
261 |
return [] |
|
262 |
||
1773.2.1
by Robert Collins
Teach all trees about unknowns, conflicts and get_parent_ids. |
263 |
def get_parent_ids(self): |
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
264 |
"""Get the parent ids for this tree. |
1773.2.1
by Robert Collins
Teach all trees about unknowns, conflicts and get_parent_ids. |
265 |
|
266 |
:return: a list of parent ids. [] is returned to indicate
|
|
267 |
a tree with no parents.
|
|
268 |
:raises: BzrError if the parents are not known.
|
|
269 |
"""
|
|
270 |
raise NotImplementedError(self.get_parent_ids) |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
271 |
|
1
by mbp at sourcefrog
import from baz patch-364 |
272 |
def has_filename(self, filename): |
273 |
"""True if the tree has given filename.""" |
|
2818.2.1
by Ian Clatworthy
minor tree & dirstate code cleanups |
274 |
raise NotImplementedError(self.has_filename) |
1
by mbp at sourcefrog
import from baz patch-364 |
275 |
|
2255.7.97
by Robert Collins
Teach delta.report_changes about unversioned files, removing all inventory access during status --short. |
276 |
def is_ignored(self, filename): |
277 |
"""Check whether the filename is ignored by this tree. |
|
278 |
||
279 |
:param filename: The relative filename within the tree.
|
|
280 |
:return: True if the filename is ignored.
|
|
281 |
"""
|
|
282 |
return False |
|
283 |
||
3146.8.16
by Aaron Bentley
Updates from review |
284 |
def all_file_ids(self): |
3146.8.2
by Aaron Bentley
Introduce iter_all_file_ids, to avoid hitting Inventory for this case |
285 |
"""Iterate through all file ids, including ids for missing files.""" |
5837.2.1
by Jelmer Vernooij
Deprecate Tree.__iter__. |
286 |
raise NotImplementedError(self.all_file_ids) |
3146.8.2
by Aaron Bentley
Introduce iter_all_file_ids, to avoid hitting Inventory for this case |
287 |
|
6825.5.1
by Jelmer Vernooij
Implement Tree.all_versioned_paths. |
288 |
def all_versioned_paths(self): |
289 |
"""Iterate through all paths, including paths for missing files.""" |
|
290 |
raise NotImplementedError(self.all_versioned_paths) |
|
291 |
||
7450.1.1
by Jelmer Vernooij
Support recurse argument to id2path. |
292 |
def id2path(self, file_id, recurse='down'): |
2255.11.5
by Martin Pool
Tree.id2path should raise NoSuchId, not return None. |
293 |
"""Return the path for a file id. |
294 |
||
295 |
:raises NoSuchId:
|
|
296 |
"""
|
|
5777.3.1
by Jelmer Vernooij
Split InventoryTree out of Tree. |
297 |
raise NotImplementedError(self.id2path) |
1
by mbp at sourcefrog
import from baz patch-364 |
298 |
|
7404.3.2
by Jelmer Vernooij
Merge rename of flag to recurse_nested. |
299 |
def iter_entries_by_dir(self, specific_files=None, recurse_nested=False): |
1852.6.9
by Robert Collins
Add more test trees to the tree-implementations tests. |
300 |
"""Walk the tree in 'by_dir' order. |
301 |
||
3363.2.23
by Aaron Bentley
Fix iter_entries_by_dir ordering |
302 |
This will yield each entry in the tree as a (path, entry) tuple.
|
303 |
The order that they are yielded is:
|
|
304 |
||
305 |
Directories are walked in a depth-first lexicographical order,
|
|
306 |
however, whenever a directory is reached, all of its direct child
|
|
307 |
nodes are yielded in lexicographical order before yielding the
|
|
308 |
grandchildren.
|
|
309 |
||
310 |
For example, in the tree::
|
|
311 |
||
312 |
a/
|
|
313 |
b/
|
|
314 |
c
|
|
315 |
d/
|
|
316 |
e
|
|
317 |
f/
|
|
318 |
g
|
|
319 |
||
3363.5.4
by Aaron Bentley
Fix iteration order of iter_entries_by_dir |
320 |
The yield order (ignoring root) would be::
|
5891.1.3
by Andrew Bennetts
Move docstring formatting fixes. |
321 |
|
3363.2.23
by Aaron Bentley
Fix iter_entries_by_dir ordering |
322 |
a, f, a/b, a/d, a/b/c, a/d/e, f/g
|
7404.3.1
by Jelmer Vernooij
Add follow_tree_references argument to Tree.iter_entries_by_dir. |
323 |
|
7404.3.2
by Jelmer Vernooij
Merge rename of flag to recurse_nested. |
324 |
If recurse_nested is enabled then nested trees are included as if
|
7404.3.1
by Jelmer Vernooij
Add follow_tree_references argument to Tree.iter_entries_by_dir. |
325 |
they were a part of the tree. If is disabled then TreeReference
|
326 |
objects (without any children) are yielded.
|
|
1852.6.9
by Robert Collins
Add more test trees to the tree-implementations tests. |
327 |
"""
|
5777.3.1
by Jelmer Vernooij
Split InventoryTree out of Tree. |
328 |
raise NotImplementedError(self.iter_entries_by_dir) |
1852.6.9
by Robert Collins
Add more test trees to the tree-implementations tests. |
329 |
|
7141.7.1
by Jelmer Vernooij
Get rid of file_ids in most of Tree. |
330 |
def iter_child_entries(self, path): |
6471.1.2
by Jelmer Vernooij
Add Tree.iter_child_entries. |
331 |
"""Iterate over the children of a directory or tree reference. |
332 |
||
6844.1.1
by Jelmer Vernooij
Many more foreign branch fixes. |
333 |
:param path: Path of the directory
|
7141.7.1
by Jelmer Vernooij
Get rid of file_ids in most of Tree. |
334 |
:raise NoSuchFile: When the path does not exist
|
6471.1.3
by Jelmer Vernooij
Add Tree.iter_child_entries. |
335 |
:return: Iterator over entries in the directory
|
6471.1.2
by Jelmer Vernooij
Add Tree.iter_child_entries. |
336 |
"""
|
337 |
raise NotImplementedError(self.iter_child_entries) |
|
338 |
||
7404.2.1
by Jelmer Vernooij
Add a follow_tree_references argument to Tree.list_files. |
339 |
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 |
340 |
recurse_nested=False): |
5793.2.1
by Jelmer Vernooij
Add Tree.list_files stub. |
341 |
"""List all files in this tree. |
342 |
||
343 |
:param include_root: Whether to include the entry for the tree root
|
|
344 |
:param from_dir: Directory under which to list files
|
|
345 |
:param recursive: Whether to list files recursively
|
|
7404.2.3
by Jelmer Vernooij
s/follow_tree_references/recurse_nested/g |
346 |
:param recurse_nested: enter nested trees
|
7143.19.5
by Jelmer Vernooij
Undo removal of kind. |
347 |
:return: iterator over tuples of
|
348 |
(path, versioned, kind, inventory entry)
|
|
5793.2.1
by Jelmer Vernooij
Add Tree.list_files stub. |
349 |
"""
|
350 |
raise NotImplementedError(self.list_files) |
|
351 |
||
2255.2.226
by Robert Collins
Get merge_nested finally working: change nested tree iterators to take file_ids, and ensure the right branch is connected to in the merge logic. May not be suitable for shared repositories yet. |
352 |
def iter_references(self): |
4370.3.2
by Ian Clatworthy
apply jam's review feedback |
353 |
if self.supports_tree_reference(): |
354 |
for path, entry in self.iter_entries_by_dir(): |
|
355 |
if entry.kind == 'tree-reference': |
|
7350.2.1
by Jelmer Vernooij
Drop file_id return value from Tree.iter_references. |
356 |
yield path |
2100.3.27
by Aaron Bentley
Enable nested commits |
357 |
|
7404.2.1
by Jelmer Vernooij
Add a follow_tree_references argument to Tree.list_files. |
358 |
def get_containing_nested_tree(self, path): |
359 |
"""Find the nested tree that contains a path. |
|
360 |
||
361 |
:return: tuple with (nested tree and path inside the nested tree)
|
|
362 |
"""
|
|
363 |
for nested_path in self.iter_references(): |
|
364 |
nested_path += '/' |
|
365 |
if path.startswith(nested_path): |
|
366 |
nested_tree = self.get_nested_tree(nested_path) |
|
367 |
return nested_tree, path[len(nested_path):] |
|
368 |
else: |
|
369 |
return None, None |
|
370 |
||
7358.4.1
by Jelmer Vernooij
Add Tree.get_nested_tree. |
371 |
def get_nested_tree(self, path): |
372 |
"""Open the nested tree at the specified path. |
|
373 |
||
374 |
:param path: Path from which to resolve tree reference.
|
|
375 |
:return: A Tree object for the nested tree
|
|
376 |
:raise MissingNestedTree: If the nested tree can not be resolved
|
|
377 |
"""
|
|
378 |
raise NotImplementedError(self.get_nested_tree) |
|
379 |
||
7141.7.1
by Jelmer Vernooij
Get rid of file_ids in most of Tree. |
380 |
def kind(self, path): |
2255.2.159
by Martin Pool
reference-trees in dirstate pass all tests. |
381 |
raise NotImplementedError("Tree subclass %s must implement kind" |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
382 |
% self.__class__.__name__) |
1465
by Robert Collins
Bugfix the new pull --clobber to not generate spurious conflicts. |
383 |
|
7141.7.1
by Jelmer Vernooij
Get rid of file_ids in most of Tree. |
384 |
def stored_kind(self, path): |
385 |
"""File kind stored for this path. |
|
3146.8.4
by Aaron Bentley
Eliminate direct use of inventory from transform application |
386 |
|
3146.8.15
by Aaron Bentley
Cleanup and docs |
387 |
May not match kind on disk for working trees. Always available
|
388 |
for versioned files, even when the file itself is missing.
|
|
3146.8.4
by Aaron Bentley
Eliminate direct use of inventory from transform application |
389 |
"""
|
7141.7.1
by Jelmer Vernooij
Get rid of file_ids in most of Tree. |
390 |
return self.kind(path) |
3146.8.4
by Aaron Bentley
Eliminate direct use of inventory from transform application |
391 |
|
2776.1.7
by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a |
392 |
def path_content_summary(self, path): |
393 |
"""Get a summary of the information about path. |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
394 |
|
4595.11.2
by Martin Pool
Clarify contract of path_content_summary |
395 |
All the attributes returned are for the canonical form, not the
|
396 |
convenient form (if content filters are in use.)
|
|
397 |
||
2776.1.7
by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a |
398 |
:param path: A relative path within the tree.
|
399 |
:return: A tuple containing kind, size, exec, sha1-or-link.
|
|
400 |
Kind is always present (see tree.kind()).
|
|
7195.5.1
by Martin
Fix remaining whitespace lint in codebase |
401 |
size is present if kind is file and the size of the
|
4595.11.13
by Martin Pool
Remove get_kind_and_executable_by_path; go back to using plain path_content_summary |
402 |
canonical form can be cheaply determined, None otherwise.
|
2776.1.7
by Robert Collins
* New method on ``bzrlib.tree.Tree`` ``path_content_summary`` provides a |
403 |
exec is None unless kind is file and the platform supports the 'x'
|
404 |
bit.
|
|
405 |
sha1-or-link is the link target if kind is symlink, or the sha1 if
|
|
406 |
it can be obtained without reading the file.
|
|
407 |
"""
|
|
408 |
raise NotImplementedError(self.path_content_summary) |
|
409 |
||
7447.3.3
by Jelmer Vernooij
Fix some blackbox tests. |
410 |
def get_reference_revision(self, path, branch=None): |
2255.2.158
by Martin Pool
Most of the integration of dirstate and subtree |
411 |
raise NotImplementedError("Tree subclass %s must implement " |
412 |
"get_reference_revision"
|
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
413 |
% self.__class__.__name__) |
2100.3.20
by Aaron Bentley
Implement tree comparison for tree references |
414 |
|
2012.1.7
by Aaron Bentley
Get tree._iter_changed down to ~ 1 stat per file |
415 |
def _comparison_data(self, entry, path): |
2012.1.15
by Aaron Bentley
Minor tweaks |
416 |
"""Return a tuple of kind, executable, stat_value for a file. |
417 |
||
418 |
entry may be None if there is no inventory entry for the file, but
|
|
419 |
path must always be supplied.
|
|
420 |
||
421 |
kind is None if there is no file present (even if an inventory id is
|
|
422 |
present). executable is False for non-file entries.
|
|
423 |
"""
|
|
2012.1.7
by Aaron Bentley
Get tree._iter_changed down to ~ 1 stat per file |
424 |
raise NotImplementedError(self._comparison_data) |
425 |
||
7141.7.1
by Jelmer Vernooij
Get rid of file_ids in most of Tree. |
426 |
def get_file(self, path): |
427 |
"""Return a file object for the file path in the tree. |
|
2772.2.1
by Ian Clatworthy
(Ian Clatworthy) Quicker initial commit - skip SHAing twice & skip path lookup as we know it |
428 |
"""
|
1986.1.2
by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely |
429 |
raise NotImplementedError(self.get_file) |
2255.7.36
by John Arbash Meinel
All trees should implement get_file_mtime() |
430 |
|
7141.7.1
by Jelmer Vernooij
Get rid of file_ids in most of Tree. |
431 |
def get_file_with_stat(self, path): |
432 |
"""Get a file handle and stat object for path. |
|
4354.4.7
by Aaron Bentley
Move MutableTree.get_file_with_stat to Tree.get_file_with_stat. |
433 |
|
434 |
The default implementation returns (self.get_file, None) for backwards
|
|
435 |
compatibility.
|
|
436 |
||
6809.4.5
by Jelmer Vernooij
Swap arguments for get_file_*. |
437 |
:param path: The path of the file.
|
4354.4.7
by Aaron Bentley
Move MutableTree.get_file_with_stat to Tree.get_file_with_stat. |
438 |
:return: A tuple (file_handle, stat_value_or_None). If the tree has
|
439 |
no stat facility, or need for a stat cache feedback during commit,
|
|
440 |
it may return None for the second element of the tuple.
|
|
441 |
"""
|
|
7141.7.1
by Jelmer Vernooij
Get rid of file_ids in most of Tree. |
442 |
return (self.get_file(path), None) |
4354.4.5
by Aaron Bentley
Ensure Tree.get_file_with_stat is provided. |
443 |
|
7141.7.1
by Jelmer Vernooij
Get rid of file_ids in most of Tree. |
444 |
def get_file_text(self, path): |
3774.1.1
by Aaron Bentley
Test Tree.get_file_text() and supply default implementation. |
445 |
"""Return the byte content of a file. |
446 |
||
6809.4.5
by Jelmer Vernooij
Swap arguments for get_file_*. |
447 |
:param path: The path of the file.
|
6006.3.1
by Martin Pool
Start adding ContentFilterTree |
448 |
|
449 |
:returns: A single byte string for the whole file.
|
|
3774.1.1
by Aaron Bentley
Test Tree.get_file_text() and supply default implementation. |
450 |
"""
|
7141.7.1
by Jelmer Vernooij
Get rid of file_ids in most of Tree. |
451 |
with self.get_file(path) as my_file: |
3774.1.1
by Aaron Bentley
Test Tree.get_file_text() and supply default implementation. |
452 |
return my_file.read() |
453 |
||
7141.7.1
by Jelmer Vernooij
Get rid of file_ids in most of Tree. |
454 |
def get_file_lines(self, path): |
3774.1.2
by Aaron Bentley
Test Tree.get_file_lines, provide a default implementation |
455 |
"""Return the content of a file, as lines. |
456 |
||
6809.4.5
by Jelmer Vernooij
Swap arguments for get_file_*. |
457 |
:param path: The path of the file.
|
3774.1.2
by Aaron Bentley
Test Tree.get_file_lines, provide a default implementation |
458 |
"""
|
7141.7.1
by Jelmer Vernooij
Get rid of file_ids in most of Tree. |
459 |
return osutils.split_lines(self.get_file_text(path)) |
3774.1.2
by Aaron Bentley
Test Tree.get_file_lines, provide a default implementation |
460 |
|
7141.7.1
by Jelmer Vernooij
Get rid of file_ids in most of Tree. |
461 |
def get_file_verifier(self, path, stat_value=None): |
5906.1.2
by Jelmer Vernooij
Add Tree.get_file_verifier. |
462 |
"""Return a verifier for a file. |
463 |
||
464 |
The default implementation returns a sha1.
|
|
465 |
||
466 |
:param path: The path that this file can be found at.
|
|
467 |
These must point to the same object.
|
|
468 |
:param stat_value: Optional stat value for the object
|
|
469 |
:return: Tuple with verifier name and verifier data
|
|
470 |
"""
|
|
7141.7.1
by Jelmer Vernooij
Get rid of file_ids in most of Tree. |
471 |
return ("SHA1", self.get_file_sha1(path, stat_value=stat_value)) |
5906.1.2
by Jelmer Vernooij
Add Tree.get_file_verifier. |
472 |
|
7141.7.1
by Jelmer Vernooij
Get rid of file_ids in most of Tree. |
473 |
def get_file_sha1(self, path, stat_value=None): |
5777.1.3
by Jelmer Vernooij
Add stub for Tree.get_file_sha1. |
474 |
"""Return the SHA1 file for a file. |
475 |
||
5906.1.4
by Jelmer Vernooij
Add InterTree.file_contents_match. |
476 |
:note: callers should use get_file_verifier instead
|
477 |
where possible, as the underlying repository implementation may
|
|
478 |
have quicker access to a non-sha1 verifier.
|
|
479 |
||
6809.4.5
by Jelmer Vernooij
Swap arguments for get_file_*. |
480 |
:param path: The path that this file can be found at.
|
5883.1.2
by Jelmer Vernooij
Support stat_value argument to get_file_sha1 |
481 |
:param stat_value: Optional stat value for the object
|
5777.1.3
by Jelmer Vernooij
Add stub for Tree.get_file_sha1. |
482 |
"""
|
483 |
raise NotImplementedError(self.get_file_sha1) |
|
484 |
||
7141.7.1
by Jelmer Vernooij
Get rid of file_ids in most of Tree. |
485 |
def get_file_mtime(self, path): |
2255.7.36
by John Arbash Meinel
All trees should implement get_file_mtime() |
486 |
"""Return the modification time for a file. |
487 |
||
6809.4.5
by Jelmer Vernooij
Swap arguments for get_file_*. |
488 |
:param path: The path that this file can be found at.
|
2255.7.36
by John Arbash Meinel
All trees should implement get_file_mtime() |
489 |
"""
|
490 |
raise NotImplementedError(self.get_file_mtime) |
|
491 |
||
7141.7.1
by Jelmer Vernooij
Get rid of file_ids in most of Tree. |
492 |
def get_file_size(self, path): |
3363.3.4
by Aaron Bentley
Add get_file_size to Tree interface |
493 |
"""Return the size of a file in bytes. |
494 |
||
495 |
This applies only to regular files. If invoked on directories or
|
|
496 |
symlinks, it will return None.
|
|
497 |
"""
|
|
498 |
raise NotImplementedError(self.get_file_size) |
|
499 |
||
7141.7.1
by Jelmer Vernooij
Get rid of file_ids in most of Tree. |
500 |
def is_executable(self, path): |
5777.1.4
by Jelmer Vernooij
Stub for is_executable. |
501 |
"""Check if a file is executable. |
502 |
||
6809.4.4
by Jelmer Vernooij
Swap arguments for Tree.is_executable. |
503 |
:param path: The path that this file can be found at.
|
5777.1.4
by Jelmer Vernooij
Stub for is_executable. |
504 |
"""
|
505 |
raise NotImplementedError(self.is_executable) |
|
506 |
||
2708.1.7
by Aaron Bentley
Rename extract_files_bytes to iter_files_bytes |
507 |
def iter_files_bytes(self, desired_files): |
2708.1.6
by Aaron Bentley
Turn extract_files_bytes into an iterator |
508 |
"""Iterate through file contents. |
2708.1.1
by Aaron Bentley
Implement Tree.extract_files |
509 |
|
2708.1.10
by Aaron Bentley
Update docstrings |
510 |
Files will not necessarily be returned in the order they occur in
|
511 |
desired_files. No specific order is guaranteed.
|
|
512 |
||
513 |
Yields pairs of identifier, bytes_iterator. identifier is an opaque
|
|
514 |
value supplied by the caller as part of desired_files. It should
|
|
515 |
uniquely identify the file version in the caller's context. (Examples:
|
|
516 |
an index number or a TreeTransform trans_id.)
|
|
517 |
||
518 |
bytes_iterator is an iterable of bytestrings for the file. The
|
|
519 |
kind of iterable and length of the bytestrings are unspecified, but for
|
|
520 |
this implementation, it is a tuple containing a single bytestring with
|
|
521 |
the complete text of the file.
|
|
522 |
||
6874.2.1
by Jelmer Vernooij
Make Tree.iter_files_bytes() take paths rather than file_ids. |
523 |
:param desired_files: a list of (path, identifier) pairs
|
2708.1.1
by Aaron Bentley
Implement Tree.extract_files |
524 |
"""
|
6874.2.1
by Jelmer Vernooij
Make Tree.iter_files_bytes() take paths rather than file_ids. |
525 |
for path, identifier in desired_files: |
2708.1.10
by Aaron Bentley
Update docstrings |
526 |
# We wrap the string in a tuple so that we can return an iterable
|
527 |
# of bytestrings. (Technically, a bytestring is also an iterable
|
|
528 |
# of bytestrings, but iterating through each character is not
|
|
529 |
# performant.)
|
|
6874.2.1
by Jelmer Vernooij
Make Tree.iter_files_bytes() take paths rather than file_ids. |
530 |
cur_file = (self.get_file_text(path),) |
2708.1.6
by Aaron Bentley
Turn extract_files_bytes into an iterator |
531 |
yield identifier, cur_file |
2708.1.1
by Aaron Bentley
Implement Tree.extract_files |
532 |
|
7141.7.1
by Jelmer Vernooij
Get rid of file_ids in most of Tree. |
533 |
def get_symlink_target(self, path): |
534 |
"""Get the target for a given path. |
|
2255.2.134
by John Arbash Meinel
Add a tree-test for get_symlink_target |
535 |
|
7141.7.1
by Jelmer Vernooij
Get rid of file_ids in most of Tree. |
536 |
It is assumed that the caller already knows that path is referencing
|
2255.2.134
by John Arbash Meinel
Add a tree-test for get_symlink_target |
537 |
a symlink.
|
5858.1.1
by Jelmer Vernooij
Support optional path argument to Tree.get_symlink_target. |
538 |
:param path: The path of the file.
|
2255.2.134
by John Arbash Meinel
Add a tree-test for get_symlink_target |
539 |
:return: The path the symlink points to.
|
540 |
"""
|
|
541 |
raise NotImplementedError(self.get_symlink_target) |
|
542 |
||
7141.7.1
by Jelmer Vernooij
Get rid of file_ids in most of Tree. |
543 |
def annotate_iter(self, path, |
3224.1.2
by John Arbash Meinel
Updated the base Tree.annotate_iter() since all implemenations take an optional kwarg. |
544 |
default_revision=_mod_revision.CURRENT_REVISION): |
2818.2.1
by Ian Clatworthy
minor tree & dirstate code cleanups |
545 |
"""Return an iterator of revision_id, line tuples. |
1551.9.18
by Aaron Bentley
Updates from review comments |
546 |
|
1551.9.16
by Aaron Bentley
Implement Tree.annotate_iter for RevisionTree and WorkingTree |
547 |
For working trees (and mutable trees in general), the special
|
548 |
revision_id 'current:' will be used for lines that are new in this
|
|
549 |
tree, e.g. uncommitted changes.
|
|
7141.7.1
by Jelmer Vernooij
Get rid of file_ids in most of Tree. |
550 |
:param path: The file to produce an annotated version from
|
3224.1.2
by John Arbash Meinel
Updated the base Tree.annotate_iter() since all implemenations take an optional kwarg. |
551 |
:param default_revision: For lines that don't match a basis, mark them
|
552 |
with this revision id. Not all implementations will make use of
|
|
553 |
this value.
|
|
1551.9.16
by Aaron Bentley
Implement Tree.annotate_iter for RevisionTree and WorkingTree |
554 |
"""
|
555 |
raise NotImplementedError(self.annotate_iter) |
|
556 |
||
1986.1.2
by Robert Collins
Various changes to allow non-workingtree specific tests to run entirely |
557 |
def path2id(self, path): |
558 |
"""Return the id for path in this tree.""" |
|
5777.3.1
by Jelmer Vernooij
Split InventoryTree out of Tree. |
559 |
raise NotImplementedError(self.path2id) |
1
by mbp at sourcefrog
import from baz patch-364 |
560 |
|
6852.3.1
by Jelmer Vernooij
add Tree.is_versioned. |
561 |
def is_versioned(self, path): |
562 |
"""Check whether path is versioned. |
|
563 |
||
564 |
:param path: Path to check
|
|
565 |
:return: boolean
|
|
566 |
"""
|
|
6856
by Jelmer Vernooij
Merge lp:~jelmer/brz/is-versioned. |
567 |
return self.path2id(path) is not None |
6852.3.1
by Jelmer Vernooij
add Tree.is_versioned. |
568 |
|
6885.5.3
by Jelmer Vernooij
Add a Tree.find_related_paths_across_trees. |
569 |
def find_related_paths_across_trees(self, paths, trees=[], |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
570 |
require_versioned=True): |
6885.5.3
by Jelmer Vernooij
Add a Tree.find_related_paths_across_trees. |
571 |
"""Find related paths in tree corresponding to specified filenames in any |
572 |
of `lookup_trees`.
|
|
573 |
||
574 |
All matches in all trees will be used, and all children of matched
|
|
575 |
directories will be used.
|
|
576 |
||
577 |
:param paths: The filenames to find related paths for (if None, returns
|
|
578 |
None)
|
|
579 |
:param trees: The trees to find file_ids within
|
|
580 |
:param require_versioned: if true, all specified filenames must occur in
|
|
581 |
at least one tree.
|
|
582 |
:return: a set of paths for the specified filenames and their children
|
|
583 |
in `tree`
|
|
584 |
"""
|
|
6885.5.4
by Jelmer Vernooij
Move paths2ids to InventoryTree. |
585 |
raise NotImplementedError(self.find_related_paths_across_trees) |
3363.12.2
by Aaron Bentley
Implement tree.iter_children to instead of adjusting InventoryEntry handling |
586 |
|
1543.1.1
by Denys Duchier
lock operations for trees - use them for diff |
587 |
def lock_read(self): |
5200.3.6
by Robert Collins
Make all lock methods return Result objects, rather than lock_read returning self, as per John's review. |
588 |
"""Lock this tree for multiple read only operations. |
6468.3.1
by Jelmer Vernooij
Use iter_children in a couple more places. |
589 |
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
590 |
:return: A breezy.lock.LogicalLockResult.
|
5200.3.6
by Robert Collins
Make all lock methods return Result objects, rather than lock_read returning self, as per John's review. |
591 |
"""
|
6754.8.3
by Jelmer Vernooij
Use context manager in decorators. |
592 |
return lock.LogicalLockResult(self.unlock) |
1543.1.1
by Denys Duchier
lock operations for trees - use them for diff |
593 |
|
1908.11.1
by Robert Collins
Add a new method ``Tree.revision_tree`` which allows access to cached |
594 |
def revision_tree(self, revision_id): |
595 |
"""Obtain a revision tree for the revision revision_id. |
|
596 |
||
597 |
The intention of this method is to allow access to possibly cached
|
|
598 |
tree data. Implementors of this method should raise NoSuchRevision if
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
599 |
the tree is not locally available, even if they could obtain the
|
600 |
tree via a repository or some other means. Callers are responsible
|
|
1908.11.1
by Robert Collins
Add a new method ``Tree.revision_tree`` which allows access to cached |
601 |
for finding the ultimate source for a revision tree.
|
602 |
||
603 |
:param revision_id: The revision_id of the requested tree.
|
|
604 |
:return: A Tree.
|
|
605 |
:raises: NoSuchRevision if the tree cannot be obtained.
|
|
606 |
"""
|
|
607 |
raise errors.NoSuchRevisionInTree(self, revision_id) |
|
608 |
||
1773.2.1
by Robert Collins
Teach all trees about unknowns, conflicts and get_parent_ids. |
609 |
def unknowns(self): |
610 |
"""What files are present in this tree and unknown. |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
611 |
|
1773.2.1
by Robert Collins
Teach all trees about unknowns, conflicts and get_parent_ids. |
612 |
:return: an iterator over the unknown files.
|
613 |
"""
|
|
614 |
return iter([]) |
|
615 |
||
1543.1.1
by Denys Duchier
lock operations for trees - use them for diff |
616 |
def unlock(self): |
617 |
pass
|
|
1658.1.9
by Martin Pool
Give an error for bzr diff on an nonexistent file (Malone #3619) |
618 |
|
619 |
def filter_unversioned_files(self, paths): |
|
2255.7.62
by Robert Collins
Update the Tree.filter_unversioned_files docstring to reflect what the existing implementations actually do, and change the WorkingTree4 implementation to match a newly created test for it. |
620 |
"""Filter out paths that are versioned. |
1658.1.9
by Martin Pool
Give an error for bzr diff on an nonexistent file (Malone #3619) |
621 |
|
622 |
:return: set of paths.
|
|
623 |
"""
|
|
6974.1.1
by Jelmer Vernooij
Provide a sensible default implementaton of Tree.filter_unversioned_files. |
624 |
# NB: we specifically *don't* call self.has_filename, because for
|
625 |
# WorkingTrees that can indicate files that exist on disk but that
|
|
626 |
# are not versioned.
|
|
6974.1.2
by Jelmer Vernooij
Avoid unnecessary parentheses. |
627 |
return set(p for p in paths if not self.is_versioned(p)) |
1852.7.1
by Robert Collins
Move RevisionTree out of tree.py. |
628 |
|
1852.15.3
by Robert Collins
Add a first-cut Tree.walkdirs method. |
629 |
def walkdirs(self, prefix=""): |
630 |
"""Walk the contents of this tree from path down. |
|
631 |
||
632 |
This yields all the data about the contents of a directory at a time.
|
|
633 |
After each directory has been yielded, if the caller has mutated the
|
|
634 |
list to exclude some directories, they are then not descended into.
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
635 |
|
1852.15.3
by Robert Collins
Add a first-cut Tree.walkdirs method. |
636 |
The data yielded is of the form:
|
7490.121.1
by Jelmer Vernooij
Drop file ids from the Tree.walkdirs API. |
637 |
(directory-relpath,
|
638 |
[(relpath, basename, kind, lstat, path_from_tree_root,
|
|
1852.15.7
by Robert Collins
Start testing behaviour of unknowns in WorkingTree.walkdirs. |
639 |
versioned_kind), ...]),
|
640 |
- directory-path-from-root is the containing dirs path from /
|
|
1852.15.3
by Robert Collins
Add a first-cut Tree.walkdirs method. |
641 |
- relpath is the relative path within the subtree being walked.
|
642 |
- basename is the basename
|
|
643 |
- kind is the kind of the file now. If unknonwn then the file is not
|
|
644 |
present within the tree - but it may be recorded as versioned. See
|
|
645 |
versioned_kind.
|
|
646 |
- lstat is the stat data *if* the file was statted.
|
|
647 |
- path_from_tree_root is the path from the root of the tree.
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
648 |
- versioned_kind is the kind of the file as last recorded in the
|
1852.15.3
by Robert Collins
Add a first-cut Tree.walkdirs method. |
649 |
versioning system. If 'unknown' the file is not versioned.
|
650 |
One of 'kind' and 'versioned_kind' must not be 'unknown'.
|
|
651 |
||
652 |
:param prefix: Start walking from prefix within the tree rather than
|
|
653 |
at the root. This allows one to walk a subtree but get paths that are
|
|
654 |
relative to a tree rooted higher up.
|
|
655 |
:return: an iterator over the directory data.
|
|
656 |
"""
|
|
657 |
raise NotImplementedError(self.walkdirs) |
|
658 |
||
3368.2.45
by Ian Clatworthy
add and use supports_content_filtering API |
659 |
def supports_content_filtering(self): |
660 |
return False |
|
661 |
||
6883.5.3
by Jelmer Vernooij
Add find_previous_path. |
662 |
def _content_filter_stack(self, path=None): |
3368.2.45
by Ian Clatworthy
add and use supports_content_filtering API |
663 |
"""The stack of content filters for a path if filtering is supported. |
3368.2.47
by Ian Clatworthy
merge bzr.dev r4042 |
664 |
|
3368.2.4
by Ian Clatworthy
make content filter lookup a tree responsibility |
665 |
Readers will be applied in first-to-last order.
|
666 |
Writers will be applied in last-to-first order.
|
|
3368.2.5
by Ian Clatworthy
incorporate jameinel's review feedback |
667 |
Either the path or the file-id needs to be provided.
|
668 |
||
669 |
:param path: path relative to the root of the tree
|
|
670 |
or None if unknown
|
|
671 |
:return: the list of filters - [] if there are none
|
|
3368.2.4
by Ian Clatworthy
make content filter lookup a tree responsibility |
672 |
"""
|
7490.79.2
by Jelmer Vernooij
Add Tree.preview_transform. |
673 |
from . import debug, filters |
3368.2.16
by Ian Clatworthy
add real implementation of Tree.get_filter_stack |
674 |
filter_pref_names = filters._get_registered_names() |
675 |
if len(filter_pref_names) == 0: |
|
676 |
return [] |
|
6634.2.1
by Martin
Apply 2to3 next fixer and make compatible |
677 |
prefs = next(self.iter_search_rules([path], filter_pref_names)) |
3368.2.30
by Ian Clatworthy
add -Dfilters support |
678 |
stk = filters._get_filter_stack_for(prefs) |
679 |
if 'filters' in debug.debug_flags: |
|
7490.126.1
by Jelmer Vernooij
Drop unnecessary gettext. |
680 |
trace.note("*** {0} content-filter: {1} => {2!r}").format(path, prefs, stk) |
3368.2.30
by Ian Clatworthy
add -Dfilters support |
681 |
return stk |
3368.2.4
by Ian Clatworthy
make content filter lookup a tree responsibility |
682 |
|
3368.2.45
by Ian Clatworthy
add and use supports_content_filtering API |
683 |
def _content_filter_stack_provider(self): |
684 |
"""A function that returns a stack of ContentFilters. |
|
685 |
||
686 |
The function takes a path (relative to the top of the tree) and a
|
|
687 |
file-id as parameters.
|
|
688 |
||
689 |
:return: None if content filtering is not supported by this tree.
|
|
690 |
"""
|
|
691 |
if self.supports_content_filtering(): |
|
7476.3.1
by Jelmer Vernooij
Disable file ids for content filter stack. |
692 |
return self._content_filter_stack |
3368.2.45
by Ian Clatworthy
add and use supports_content_filtering API |
693 |
else: |
694 |
return None |
|
695 |
||
3398.1.24
by Ian Clatworthy
make iter_search_rules a tree method |
696 |
def iter_search_rules(self, path_names, pref_names=None, |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
697 |
_default_searcher=None): |
3398.1.24
by Ian Clatworthy
make iter_search_rules a tree method |
698 |
"""Find the preferences for filenames in a tree. |
699 |
||
700 |
:param path_names: an iterable of paths to find attributes for.
|
|
701 |
Paths are given relative to the root of the tree.
|
|
702 |
:param pref_names: the list of preferences to lookup - None for all
|
|
703 |
:param _default_searcher: private parameter to assist testing - don't use
|
|
704 |
:return: an iterator of tuple sequences, one per path-name.
|
|
705 |
See _RulesSearcher.get_items for details on the tuple sequence.
|
|
706 |
"""
|
|
7490.79.2
by Jelmer Vernooij
Add Tree.preview_transform. |
707 |
from . import rules |
4324.4.1
by Marius Kruger
Make it possible to blackboxtest rules |
708 |
if _default_searcher is None: |
709 |
_default_searcher = rules._per_user_searcher |
|
3398.1.24
by Ian Clatworthy
make iter_search_rules a tree method |
710 |
searcher = self._get_rules_searcher(_default_searcher) |
711 |
if searcher is not None: |
|
3398.1.34
by Ian Clatworthy
changed API design as requested by jam during review |
712 |
if pref_names is not None: |
713 |
for path in path_names: |
|
714 |
yield searcher.get_selected_items(path, pref_names) |
|
715 |
else: |
|
716 |
for path in path_names: |
|
717 |
yield searcher.get_items(path) |
|
3398.1.24
by Ian Clatworthy
make iter_search_rules a tree method |
718 |
|
719 |
def _get_rules_searcher(self, default_searcher): |
|
720 |
"""Get the RulesSearcher for this tree given the default one.""" |
|
721 |
searcher = default_searcher |
|
722 |
return searcher |
|
723 |
||
6968.2.7
by Jelmer Vernooij
Add breezy.archive. |
724 |
def archive(self, format, name, root='', subdir=None, |
725 |
force_mtime=None): |
|
6968.2.1
by Jelmer Vernooij
Add Tree.archive, which streams an archived version of a tree. |
726 |
"""Create an archive of this tree. |
727 |
||
6995
by Jelmer Vernooij
Merge lp:~jelmer/brz/hpss-archive. |
728 |
:param format: Format name (e.g. 'tar')
|
6968.2.1
by Jelmer Vernooij
Add Tree.archive, which streams an archived version of a tree. |
729 |
:param name: target file name
|
730 |
:param root: Root directory name (or None)
|
|
731 |
:param subdir: Subdirectory to export (or None)
|
|
732 |
:return: Iterator over archive chunks
|
|
733 |
"""
|
|
6968.2.10
by Jelmer Vernooij
Review comments. |
734 |
from .archive import create_archive |
6968.2.1
by Jelmer Vernooij
Add Tree.archive, which streams an archived version of a tree. |
735 |
with self.lock_read(): |
6968.2.7
by Jelmer Vernooij
Add breezy.archive. |
736 |
return create_archive(format, self, name, root, |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
737 |
subdir, force_mtime=force_mtime) |
6968.2.1
by Jelmer Vernooij
Add Tree.archive, which streams an archived version of a tree. |
738 |
|
6929.3.3
by Jelmer Vernooij
Add Tree.versionable_kind. |
739 |
@classmethod
|
740 |
def versionable_kind(cls, kind): |
|
741 |
"""Check if this tree support versioning a specific file kind.""" |
|
742 |
return (kind in ('file', 'directory', 'symlink', 'tree-reference')) |
|
743 |
||
7490.77.2
by Jelmer Vernooij
Split out git and bzr-specific transforms. |
744 |
def preview_transform(self, pb=None): |
7490.79.2
by Jelmer Vernooij
Add Tree.preview_transform. |
745 |
"""Obtain a transform object.""" |
7490.77.2
by Jelmer Vernooij
Split out git and bzr-specific transforms. |
746 |
raise NotImplementedError(self.preview_transform) |
747 |
||
1852.7.1
by Robert Collins
Move RevisionTree out of tree.py. |
748 |
|
1852.8.2
by Robert Collins
Add InterTree class to represent InterTree operations. |
749 |
class InterTree(InterObject): |
750 |
"""This class represents operations taking place between two Trees. |
|
751 |
||
752 |
Its instances have methods like 'compare' and contain references to the
|
|
753 |
source and target trees these operations are to be carried out on.
|
|
754 |
||
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
755 |
Clients of breezy should not need to use InterTree directly, rather they
|
1852.8.2
by Robert Collins
Add InterTree class to represent InterTree operations. |
756 |
should use the convenience methods on Tree such as 'Tree.compare()' which
|
757 |
will pass through to InterTree as appropriate.
|
|
758 |
"""
|
|
759 |
||
4585.1.18
by Jelmer Vernooij
Add note saying that InterTree will not be tested if the from and to formats are not set. |
760 |
# Formats that will be used to test this InterTree. If both are
|
761 |
# None, this InterTree will not be tested (e.g. because a complex
|
|
762 |
# setup is required)
|
|
763 |
_matching_from_tree_format = None |
|
764 |
_matching_to_tree_format = None |
|
765 |
||
1910.2.15
by Aaron Bentley
Back out inter.get changes, make optimizers an ordered list |
766 |
_optimisers = [] |
1852.8.2
by Robert Collins
Add InterTree class to represent InterTree operations. |
767 |
|
5837.1.2
by Jelmer Vernooij
Register defaults as first optimiser for existing Inter objects. |
768 |
@classmethod
|
769 |
def is_compatible(kls, source, target): |
|
770 |
# The default implementation is naive and uses the public API, so
|
|
771 |
# it works for all trees.
|
|
772 |
return True |
|
773 |
||
1852.9.4
by Robert Collins
Add minimal test for Tree.compare(extra_trees=...). |
774 |
def compare(self, want_unchanged=False, specific_files=None, |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
775 |
extra_trees=None, require_versioned=False, include_root=False, |
776 |
want_unversioned=False): |
|
1852.9.3
by Robert Collins
Convert the test_delta tests to intertree_implementation and workingtree_implementation tests as appropriate. |
777 |
"""Return the changes from source to target. |
1852.8.3
by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case. |
778 |
|
779 |
:return: A TreeDelta.
|
|
1852.9.4
by Robert Collins
Add minimal test for Tree.compare(extra_trees=...). |
780 |
:param specific_files: An optional list of file paths to restrict the
|
781 |
comparison to. When mapping filenames to ids, all matches in all
|
|
782 |
trees (including optional extra_trees) are used, and all children of
|
|
783 |
matched directories are included.
|
|
784 |
:param want_unchanged: An optional boolean requesting the inclusion of
|
|
785 |
unchanged entries in the result.
|
|
786 |
:param extra_trees: An optional list of additional trees to use when
|
|
787 |
mapping the contents of specific_files (paths) to file_ids.
|
|
1852.9.5
by Robert Collins
Add tests for require_versioned to the InterTree.compare() test suite. |
788 |
:param require_versioned: An optional boolean (defaults to False). When
|
789 |
supplied and True all the 'specific_files' must be versioned, or
|
|
790 |
a PathsNotVersionedError will be thrown.
|
|
2255.7.90
by Robert Collins
Add unversioned path reporting to TreeDelta. |
791 |
:param want_unversioned: Scan for unversioned paths.
|
1852.8.3
by Robert Collins
Implement an InterTreeTestProvider and a trivial test_compare test case. |
792 |
"""
|
7490.79.2
by Jelmer Vernooij
Add Tree.preview_transform. |
793 |
from . import delta |
2255.2.105
by Robert Collins
Unfuck InterTree.compare which I broke with the paths2ids implementation. |
794 |
trees = (self.source,) |
1852.11.1
by Robert Collins
Deprecate compare_trees and move its body to InterTree.changes_from. |
795 |
if extra_trees is not None: |
796 |
trees = trees + tuple(extra_trees) |
|
6754.8.16
by Jelmer Vernooij
Get rid of all uses of needs_read_lock |
797 |
with self.lock_read(): |
798 |
return delta._compare_trees(self.source, self.target, want_unchanged, |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
799 |
specific_files, include_root, extra_trees=extra_trees, |
800 |
require_versioned=require_versioned, |
|
801 |
want_unversioned=want_unversioned) |
|
2012.1.1
by Aaron Bentley
Implement change iterator |
802 |
|
3254.1.1
by Aaron Bentley
Make Tree.iter_changes a public method |
803 |
def iter_changes(self, include_unchanged=False, |
7143.15.2
by Jelmer Vernooij
Run autopep8. |
804 |
specific_files=None, pb=None, extra_trees=[], |
805 |
require_versioned=True, want_unversioned=False): |
|
2012.1.1
by Aaron Bentley
Implement change iterator |
806 |
"""Generate an iterator of changes between trees. |
807 |
||
808 |
A tuple is returned:
|
|
2255.7.96
by Robert Collins
Change _iter_changes interface to yield both old and new paths. |
809 |
(file_id, (path_in_source, path_in_target),
|
810 |
changed_content, versioned, parent, name, kind,
|
|
2012.1.1
by Aaron Bentley
Implement change iterator |
811 |
executable)
|
812 |
||
2255.7.96
by Robert Collins
Change _iter_changes interface to yield both old and new paths. |
813 |
Changed_content is True if the file's content has changed. This
|
814 |
includes changes to its kind, and to a symlink's target.
|
|
2012.1.1
by Aaron Bentley
Implement change iterator |
815 |
|
2012.1.15
by Aaron Bentley
Minor tweaks |
816 |
versioned, parent, name, kind, executable are tuples of (from, to).
|
817 |
If a file is missing in a tree, its kind is None.
|
|
2012.1.1
by Aaron Bentley
Implement change iterator |
818 |
|
2255.2.122
by Robert Collins
Alter intertree implementation tests to let dirstate inter-trees be correctly parameterised. |
819 |
Iteration is done in parent-to-child order, relative to the target
|
820 |
tree.
|
|
2255.2.149
by Robert Collins
Crufty but existing _iter_changes implementation for WorkingTreeFormat4. |
821 |
|
822 |
There is no guarantee that all paths are in sorted order: the
|
|
823 |
requirement to expand the search due to renames may result in children
|
|
824 |
that should be found early being found late in the search, after
|
|
825 |
lexically later results have been returned.
|
|
826 |
:param require_versioned: Raise errors.PathsNotVersionedError if a
|
|
827 |
path in the specific_files list is not versioned in one of
|
|
828 |
source, target or extra_trees.
|
|
4570.2.3
by Robert Collins
Change the way iter_changes treats specific files to prevent InconsistentDeltas. |
829 |
:param specific_files: An optional list of file paths to restrict the
|
830 |
comparison to. When mapping filenames to ids, all matches in all
|
|
831 |
trees (including optional extra_trees) are used, and all children
|
|
832 |
of matched directories are included. The parents in the target tree
|
|
833 |
of the specific files up to and including the root of the tree are
|
|
834 |
always evaluated for changes too.
|
|
2255.7.85
by Robert Collins
Teach _iter_changes to gather unversioned path details upon request. |
835 |
:param want_unversioned: Should unversioned files be returned in the
|
836 |
output. An unversioned file is defined as one with (False, False)
|
|
837 |
for the versioned pair.
|
|
2012.1.1
by Aaron Bentley
Implement change iterator |
838 |
"""
|
7467.4.15
by Jelmer Vernooij
Split out InventoryInterTree. |
839 |
raise NotImplementedError(self.iter_changes) |
3514.3.1
by John Arbash Meinel
Start working on a special walker that can iterate several trees at once. |
840 |
|
6754.8.16
by Jelmer Vernooij
Get rid of all uses of needs_read_lock |
841 |
def file_content_matches( |
6883.1.3
by Jelmer Vernooij
Add test, make file_id optional. |
842 |
self, source_path, target_path, |
6883.1.2
by Jelmer Vernooij
Fix order. |
843 |
source_stat=None, target_stat=None): |
5906.1.8
by Jelmer Vernooij
Tests. |
844 |
"""Check if two files are the same in the source and target trees. |
845 |
||
846 |
This only checks that the contents of the files are the same,
|
|
847 |
it does not touch anything else.
|
|
848 |
||
6883.7.1
by Jelmer Vernooij
Swap order of arguments to Tree.file_content_matches. |
849 |
:param source_path: Path of the file in the source tree
|
850 |
:param target_path: Path of the file in the target tree
|
|
5906.1.8
by Jelmer Vernooij
Tests. |
851 |
:param source_stat: Optional stat value of the file in the source tree
|
852 |
:param target_stat: Optional stat value of the file in the target tree
|
|
853 |
:return: Boolean indicating whether the files have the same contents
|
|
854 |
"""
|
|
6754.8.16
by Jelmer Vernooij
Get rid of all uses of needs_read_lock |
855 |
with self.lock_read(): |
856 |
source_verifier_kind, source_verifier_data = ( |
|
7143.15.15
by Jelmer Vernooij
Merge trunk. |
857 |
self.source.get_file_verifier(source_path, source_stat)) |
6754.8.16
by Jelmer Vernooij
Get rid of all uses of needs_read_lock |
858 |
target_verifier_kind, target_verifier_data = ( |
859 |
self.target.get_file_verifier( |
|
7141.7.1
by Jelmer Vernooij
Get rid of file_ids in most of Tree. |
860 |
target_path, target_stat)) |
6754.8.16
by Jelmer Vernooij
Get rid of all uses of needs_read_lock |
861 |
if source_verifier_kind == target_verifier_kind: |
862 |
return (source_verifier_data == target_verifier_data) |
|
863 |
# Fall back to SHA1 for now
|
|
864 |
if source_verifier_kind != "SHA1": |
|
865 |
source_sha1 = self.source.get_file_sha1( |
|
7325.1.1
by Jelmer Vernooij
Get rid of file_id arguments to get_file_sha1. |
866 |
source_path, source_stat) |
6754.8.16
by Jelmer Vernooij
Get rid of all uses of needs_read_lock |
867 |
else: |
868 |
source_sha1 = source_verifier_data |
|
869 |
if target_verifier_kind != "SHA1": |
|
870 |
target_sha1 = self.target.get_file_sha1( |
|
7325.1.1
by Jelmer Vernooij
Get rid of file_id arguments to get_file_sha1. |
871 |
target_path, target_stat) |
6754.8.16
by Jelmer Vernooij
Get rid of all uses of needs_read_lock |
872 |
else: |
873 |
target_sha1 = target_verifier_data |
|
874 |
return (source_sha1 == target_sha1) |
|
3514.3.1
by John Arbash Meinel
Start working on a special walker that can iterate several trees at once. |
875 |
|
7357.1.4
by Jelmer Vernooij
Merge trunk. |
876 |
def find_target_path(self, path, recurse='none'): |
7357.1.1
by Jelmer Vernooij
Move logic for find_previous_path onto InterTree. |
877 |
"""Find target tree path. |
878 |
||
879 |
:param path: Path to search for (exists in source)
|
|
880 |
:return: path in target, or None if there is no equivalent path.
|
|
881 |
:raise NoSuchFile: If the path doesn't exist in source
|
|
882 |
"""
|
|
7467.4.21
by Jelmer Vernooij
Move find_{source,target}_path as well. |
883 |
raise NotImplementedError(self.find_target_path) |
7357.1.1
by Jelmer Vernooij
Move logic for find_previous_path onto InterTree. |
884 |
|
7357.1.6
by Jelmer Vernooij
Add find_source_path. |
885 |
def find_source_path(self, path, recurse='none'): |
886 |
"""Find the source tree path. |
|
887 |
||
888 |
:param path: Path to search for (exists in target)
|
|
889 |
:return: path in source, or None if there is no equivalent path.
|
|
890 |
:raise NoSuchFile: if the path doesn't exist in target
|
|
891 |
"""
|
|
7467.4.21
by Jelmer Vernooij
Move find_{source,target}_path as well. |
892 |
raise NotImplementedError(self.find_source_path) |
7357.1.6
by Jelmer Vernooij
Add find_source_path. |
893 |
|
7357.1.4
by Jelmer Vernooij
Merge trunk. |
894 |
def find_target_paths(self, paths, recurse='none'): |
7357.1.1
by Jelmer Vernooij
Move logic for find_previous_path onto InterTree. |
895 |
"""Find target tree paths. |
896 |
||
897 |
:param paths: Iterable over paths in target to search for
|
|
898 |
:return: Dictionary mapping from source paths to paths in target , or
|
|
899 |
None if there is no equivalent path.
|
|
900 |
"""
|
|
901 |
ret = {} |
|
902 |
for path in paths: |
|
7357.1.4
by Jelmer Vernooij
Merge trunk. |
903 |
ret[path] = self.find_target_path(path, recurse=recurse) |
7357.1.1
by Jelmer Vernooij
Move logic for find_previous_path onto InterTree. |
904 |
return ret |
905 |
||
7357.1.6
by Jelmer Vernooij
Add find_source_path. |
906 |
def find_source_paths(self, paths, recurse='none'): |
907 |
"""Find source tree paths. |
|
908 |
||
909 |
:param paths: Iterable over paths in target to search for
|
|
910 |
:return: Dictionary mapping from target paths to paths in source, or
|
|
911 |
None if there is no equivalent path.
|
|
912 |
"""
|
|
913 |
ret = {} |
|
914 |
for path in paths: |
|
915 |
ret[path] = self.find_source_path(path, recurse=recurse) |
|
916 |
return ret |
|
917 |
||
7143.15.2
by Jelmer Vernooij
Run autopep8. |
918 |
|
7458.1.1
by Jelmer Vernooij
Support importing Git submodules as tree references. |
919 |
def find_previous_paths(from_tree, to_tree, paths, recurse='none'): |
6883.5.2
by Jelmer Vernooij
Add find_previous_paths call. |
920 |
"""Find previous tree paths. |
921 |
||
922 |
:param from_tree: From tree
|
|
923 |
:param to_tree: To tree
|
|
7324.2.1
by Jelmer Vernooij
Use find_previous_path in InterTree.iter_changes. |
924 |
:param paths: Iterable over paths in from_tree to search for
|
6883.5.2
by Jelmer Vernooij
Add find_previous_paths call. |
925 |
:return: Dictionary mapping from from_tree paths to paths in to_tree, or
|
926 |
None if there is no equivalent path.
|
|
927 |
"""
|
|
7357.1.6
by Jelmer Vernooij
Add find_source_path. |
928 |
return InterTree.get(to_tree, from_tree).find_source_paths(paths, recurse=recurse) |
7357.1.4
by Jelmer Vernooij
Merge trunk. |
929 |
|
930 |
||
931 |
def find_previous_path(from_tree, to_tree, path, recurse='none'): |
|
6883.5.3
by Jelmer Vernooij
Add find_previous_path. |
932 |
"""Find previous tree path. |
933 |
||
934 |
:param from_tree: From tree
|
|
935 |
:param to_tree: To tree
|
|
7324.2.1
by Jelmer Vernooij
Use find_previous_path in InterTree.iter_changes. |
936 |
:param path: Path to search for (exists in from_tree)
|
6883.5.3
by Jelmer Vernooij
Add find_previous_path. |
937 |
:return: path in to_tree, or None if there is no equivalent path.
|
7350.5.1
by Jelmer Vernooij
Remove file_id from transform's create_from_tree, get filter tree paths by path. |
938 |
:raise NoSuchFile: If the path doesn't exist in from_tree
|
6883.5.3
by Jelmer Vernooij
Add find_previous_path. |
939 |
"""
|
7357.1.6
by Jelmer Vernooij
Add find_source_path. |
940 |
return InterTree.get(to_tree, from_tree).find_source_path( |
7357.1.4
by Jelmer Vernooij
Merge trunk. |
941 |
path, recurse=recurse) |
7104.3.3
by Jelmer Vernooij
Move get_canonical_paths to WorkingTree. |
942 |
|
943 |
||
7104.3.4
by Jelmer Vernooij
Fix tests. |
944 |
def get_canonical_path(tree, path, normalize): |
7104.3.3
by Jelmer Vernooij
Move get_canonical_paths to WorkingTree. |
945 |
"""Find the canonical path of an item, ignoring case. |
946 |
||
947 |
:param tree: Tree to traverse
|
|
948 |
:param path: Case-insensitive path to look up
|
|
7104.3.4
by Jelmer Vernooij
Fix tests. |
949 |
:param normalize: Function to normalize a filename for comparison
|
7104.3.3
by Jelmer Vernooij
Move get_canonical_paths to WorkingTree. |
950 |
:return: The canonical path
|
951 |
"""
|
|
952 |
# go walkin...
|
|
953 |
cur_path = '' |
|
954 |
bit_iter = iter(path.split("/")) |
|
955 |
for elt in bit_iter: |
|
7104.3.4
by Jelmer Vernooij
Fix tests. |
956 |
lelt = normalize(elt) |
7104.3.3
by Jelmer Vernooij
Move get_canonical_paths to WorkingTree. |
957 |
new_path = None |
958 |
try: |
|
7192.5.2
by Jelmer Vernooij
Fixes. |
959 |
for child in tree.iter_child_entries(cur_path): |
7104.3.3
by Jelmer Vernooij
Move get_canonical_paths to WorkingTree. |
960 |
try: |
961 |
if child.name == elt: |
|
962 |
# if we found an exact match, we can stop now; if
|
|
963 |
# we found an approximate match we need to keep
|
|
964 |
# searching because there might be an exact match
|
|
965 |
# later.
|
|
966 |
new_path = osutils.pathjoin(cur_path, child.name) |
|
967 |
break
|
|
7104.3.4
by Jelmer Vernooij
Fix tests. |
968 |
elif normalize(child.name) == lelt: |
7104.3.3
by Jelmer Vernooij
Move get_canonical_paths to WorkingTree. |
969 |
new_path = osutils.pathjoin(cur_path, child.name) |
970 |
except errors.NoSuchId: |
|
971 |
# before a change is committed we can see this error...
|
|
972 |
continue
|
|
973 |
except errors.NotADirectory: |
|
974 |
pass
|
|
975 |
if new_path: |
|
976 |
cur_path = new_path |
|
977 |
else: |
|
978 |
# got to the end of this directory and no entries matched.
|
|
979 |
# Return what matched so far, plus the rest as specified.
|
|
980 |
cur_path = osutils.pathjoin(cur_path, elt, *list(bit_iter)) |
|
981 |
break
|
|
982 |
return cur_path |