Merge lp:~jelmer/brz/no-more-id2path into lp:brz

Proposed by Jelmer Vernooij on 2019-09-21
Status: Work in progress
Proposed branch: lp:~jelmer/brz/no-more-id2path
Merge into: lp:brz
Diff against target: 728 lines (+275/-130)
17 files modified
BRANCH.TODO (+167/-0)
breezy/builtins.py (+2/-2)
breezy/git/tree.py (+0/-23)
breezy/log.py (+3/-2)
breezy/merge.py (+8/-8)
breezy/plugins/fastimport/revision_store.py (+0/-8)
breezy/tests/blackbox/test_join.py (+13/-8)
breezy/tests/matchers.py (+3/-3)
breezy/tests/per_intertree/test_compare.py (+21/-14)
breezy/tests/per_tree/test_tree.py (+2/-0)
breezy/tests/per_workingtree/test_commit.py (+7/-3)
breezy/tests/test_branchbuilder.py (+1/-1)
breezy/tests/test_bundle.py (+2/-2)
breezy/tests/test_extract.py (+6/-4)
breezy/tests/test_tree.py (+6/-4)
breezy/transform.py (+4/-4)
breezy/tree.py (+30/-44)
To merge this branch: bzr merge lp:~jelmer/brz/no-more-id2path
Reviewer Review Type Date Requested Status
Breezy developers 2019-09-21 Pending
Review via email: mp+373057@code.launchpad.net

Commit message

Remove id2path.

Description of the change

Remove id2path.

To post a comment you must log in.

Unmerged revisions

7362. By Jelmer Vernooij on 2019-09-21

merge trunk.

7361. By Jelmer Vernooij on 2019-09-21

Fix some more.

7360. By Jelmer Vernooij on 2019-06-23

Pass in path rather than file id.

7359. By Jelmer Vernooij on 2019-06-23

Remove id2path in a few places.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'BRANCH.TODO'
2--- BRANCH.TODO 2010-07-10 21:28:56 +0000
3+++ BRANCH.TODO 2019-09-21 22:32:04 +0000
4@@ -3,3 +3,170 @@
5 #
6 #
7
8+# --file-ids-from requires a tree that supports file ids
9+breezy/add.py: parent_path = self.base_tree.id2path(parent_ie.file_id)
10+
11+# Need to move bundle stuff to breezy.bzr.
12+breezy/bundle/bundle_data.py: def id2path(self, file_id):
13+breezy/bundle/bundle_data.py: old_path = self.base_tree.id2path(file_id)
14+breezy/bundle/bundle_data.py: new_path = self.id2path(file_id)
15+breezy/bundle/bundle_data.py: old_path = self.base_tree.id2path(base_id)
16+breezy/bundle/bundle_data.py: path = self.id2path(id)
17+breezy/bundle/serializer/v08.py: old_rev = old_tree.get_file_revision(old_tree.id2path(file_id))
18+
19+# Conflicts need to deal with paths
20+breezy/conflicts.py: tt, tid, tree, tree.id2path(file_id))
21+breezy/conflicts.py: tree.revert([revtree.id2path(file_id)],
22+breezy/conflicts.py: tree.revert([revtree.id2path(file_id)],
23+breezy/conflicts.py: this_path = tt._tree.id2path(self.file_id)
24+breezy/git/fetch.py: ppath = ptree.id2path(file_id)
25+
26+# get_deltas_for_revisions takes a file id argument
27+breezy/git/repository.py: specific_files = [new_tree.id2path(
28+
29+breezy/log.py: specific_files = [tree_2.id2path(id) for id in file_ids]
30+breezy/merge.py: base_path = self.base_tree.id2path(file_id)
31+breezy/merge.py: this_path = self.this_tree.id2path(file_id)
32+breezy/merge.py: filter_tree_path = wt.id2path(file_id)
33+breezy/merge.py: # Skip the id2path lookup for older formats
34+breezy/multiwalker.py: cur_path = other_tree.id2path(file_id)
35+breezy/plugins/fastimport/revision_store.py: path = revtree.id2path(file_id)
36+breezy/plugins/fastimport/revision_store.py: path = revtree.id2path(file_id)
37+breezy/plugins/fastimport/tests/test_revision_store.py: def test_id2path_no_delta(self):
38+breezy/plugins/fastimport/tests/test_revision_store.py: self.assertEqual('', shim.id2path(b'TREE_ROOT'))
39+breezy/plugins/fastimport/tests/test_revision_store.py: self.assertEqual('foo', shim.id2path(b'foo-id'))
40+breezy/plugins/fastimport/tests/test_revision_store.py: self.assertEqual('bar', shim.id2path(b'bar-id'))
41+breezy/plugins/fastimport/tests/test_revision_store.py: self.assertEqual('bar/baz', shim.id2path(b'baz-id'))
42+breezy/plugins/fastimport/tests/test_revision_store.py: self.assertRaises(errors.NoSuchId, shim.id2path, b'qux-id')
43+breezy/plugins/fastimport/tests/test_revision_store.py: def test_id2path_with_delta(self):
44+breezy/plugins/fastimport/tests/test_revision_store.py: self.assertEqual('', shim.id2path(b'TREE_ROOT'))
45+breezy/plugins/fastimport/tests/test_revision_store.py: self.assertEqual('foo2', shim.id2path(b'foo-id'))
46+breezy/plugins/fastimport/tests/test_revision_store.py: self.assertEqual('bar', shim.id2path(b'bar-id'))
47+breezy/plugins/fastimport/tests/test_revision_store.py: self.assertRaises(errors.NoSuchId, shim.id2path, b'baz-id')
48+
49+# Rename map is bzr-specific
50+breezy/rename_map.py: desired_files = [(tree.id2path(f), f) for f in file_ids]
51+breezy/rename_map.py: self.tree.id2path(change.parent_id[0])):
52+breezy/rename_map.py: file_id_query.append(self.tree.id2path(f))
53+
54+breezy/shelf.py: new_path = self.target_tree.id2path(file_id)
55+breezy/shelf.py: old_path = self.work_tree.id2path(file_id)
56+breezy/shelf.py: transform.create_from_tree(tt, trans_id, tree, tree.id2path(file_id))
57+breezy/shelf.py: existing_path = self.target_tree.id2path(file_id)
58+breezy/shelf.py: tree.id2path(file_id))
59+breezy/shelf.py: target_path = self.target_tree.id2path(file_id)
60+breezy/shelf.py: work_path = self.work_tree.id2path(file_id)
61+breezy/shelf_ui.py: old_path = old_tree.id2path(file_id)
62+breezy/shelf_ui.py: new_path = new_tree.id2path(file_id)
63+breezy/shelf_ui.py: path = self.work_tree.id2path(file_id)
64+breezy/shelf_ui.py: path = self.target_tree.id2path(file_id)
65+breezy/shelf_ui.py: self.change_editor.old_tree.id2path(file_id),
66+breezy/shelf_ui.py: self.change_editor.new_tree.id2path(file_id)))
67+breezy/tests/per_intertree/test_compare.py: path = tree.id2path(file_id)
68+breezy/tests/per_intertree/test_compare.py: path = tree.id2path(file_id)
69+breezy/tests/per_workingtree/test_parents.py: delta.append((old.id2path(file_id), None, file_id, None))
70+breezy/tests/per_workingtree/test_parents.py: delta.append((None, new.id2path(file_id),
71+breezy/tests/per_workingtree/test_parents.py: delta.append((old.id2path(file_id), new.id2path(file_id),
72+breezy/tests/test_bundle.py: def id2path(self, file_id):
73+breezy/tests/test_bundle.py: return self.id2path(file_id) is not None
74+breezy/tests/test_bundle.py: self.assertEqual(btree.id2path(b"a"), "grandparent")
75+breezy/tests/test_bundle.py: self.assertEqual(btree.id2path(b"b"), "grandparent/parent")
76+breezy/tests/test_bundle.py: self.assertEqual(btree.id2path(b"c"), "grandparent/parent/file")
77+breezy/tests/test_bundle.py: self.assertEqual(btree.id2path(b"a"), "grandparent2")
78+breezy/tests/test_bundle.py: self.assertEqual(btree.id2path(b"b"), "grandparent2/parent")
79+breezy/tests/test_bundle.py: self.assertEqual(btree.id2path(b"c"), "grandparent2/parent/file")
80+breezy/tests/test_bundle.py: self.assertEqual(btree.id2path(b"a"), "grandparent2")
81+breezy/tests/test_bundle.py: self.assertEqual(btree.id2path(b"b"), "grandparent2/parent2")
82+breezy/tests/test_bundle.py: self.assertEqual(btree.id2path(b"c"), "grandparent2/parent2/file")
83+breezy/tests/test_bundle.py: self.assertEqual(btree.id2path(b"a"), "grandparent2")
84+breezy/tests/test_bundle.py: self.assertEqual(btree.id2path(b"b"), "grandparent2/parent2")
85+breezy/tests/test_bundle.py: self.assertEqual(btree.id2path(b"c"), "grandparent2/parent2/file2")
86+breezy/tests/test_bundle.py: self.assertEqual(btree.id2path(b"c"), "grandparent/alt_parent/file")
87+breezy/tests/test_bundle.py: self.assertTrue(btree.id2path(b"e") is None)
88+breezy/tests/test_bundle.py: self.assertEqual(btree.id2path(b"e"), "grandparent/parent/file")
89+breezy/tests/test_bundle.py: with btree.get_file(btree.id2path(b"e")) as f:
90+breezy/tests/test_bundle.py: with btree.get_file(btree.id2path(b"c")) as f:
91+breezy/tests/test_bundle.py: with btree.get_file(btree.id2path(b"c")) as f:
92+breezy/tests/test_bundle.py: self.assertTrue(btree.id2path(b"c") is None)
93+breezy/tests/test_commit.py: eq(tree1.id2path(b'hello-id'), 'hello')
94+breezy/tests/test_commit.py: eq(tree2.id2path(b'hello-id'), 'fruity')
95+breezy/tests/test_conflicts.py: return wt.id2path(self._other['dir_id'])
96+breezy/tests/test_extract.py: self.assertEqual('c', b_wt.id2path(b'c-id'))
97+breezy/tests/test_extract.py: self.assertRaises(errors.BzrError, wt.id2path, b'b-id')
98+breezy/tests/test_memorytree.py: self.assertEqual('afile', tree.id2path(tree.path2id('afile')))
99+breezy/tests/test_memorytree.py: self.assertEqual('adir', tree.id2path(tree.path2id('adir')))
100+breezy/tests/test_memorytree.py: self.assertEqual('adir/afile', tree.id2path(b'file-id'))
101+breezy/tests/test_memorytree.py: self.assertEqual('adir', tree.id2path(b'dir-id'))
102+breezy/tests/test_memorytree.py: self.assertEqual('bar', tree.id2path(b'foo-id'))
103+breezy/tests/test_memorytree.py: self.assertEqual('bar', rev_tree2.id2path(b'foo-id'))
104+breezy/tests/test_memorytree.py: self.assertEqual('subdir/bar', tree.id2path(b'foo-id'))
105+breezy/tests/test_memorytree.py: self.assertEqual('subdir/bar', rev_tree2.id2path(b'foo-id'))
106+breezy/tests/test_merge_core.py: builder.this.get_file(builder.this.id2path(b"a")).read(),
107+breezy/tests/test_merge_core.py: with builder.this.get_file(builder.this.id2path(b'2')) as f:
108+breezy/tests/test_merge_core.py: os.lstat(builder.this.abspath(builder.this.id2path(b"2")))
109+breezy/tests/test_merge.py: self.assertEqual('baz', wt.id2path(b'foo-id'))
110+breezy/tests/test_merge.py: self.assertRaises(errors.NoSuchId, wt.id2path, b'foo-id')
111+breezy/tests/test_merge.py: self.assertEqual('barry', wt.id2path(b'foo-id'))
112+breezy/tests/test_merge.py: self.assertEqual('barry', wt.id2path(b'foo-id'))
113+breezy/tests/test_merge.py: self.assertEqual('blah', wt.id2path(b'foo-id'))
114+breezy/tests/test_merge.py: self.assertEqual('foo', wt.id2path(b'foo-id'))
115+breezy/tests/test_rename_map.py: self.assertEqual('file2', tree.id2path(b'file-id'))
116+breezy/tests/test_rename_map.py: self.assertEqual('dir2/file', tree.id2path(b'file-id'))
117+breezy/tests/test_rename_map.py: self.assertEqual('dir2', tree.id2path(b'dir-id'))
118+breezy/tests/test_rename_map.py: self.assertEqual('topdir2', tree.id2path(b'topdir-id'))
119+breezy/tests/test_rename_map.py: self.assertEqual('baz/empty', tree.id2path(b'empty-id'))
120+breezy/tests/test_rename_map.py: self.assertEqual('file', tree.id2path(b'file-id'))
121+breezy/tests/test_shelf.py: self.assertEqual('foo/baz', tree.id2path(b'baz-id'))
122+breezy/tests/test_shelf.py: ptree.get_symlink_target(ptree.id2path(b'foo-id')))
123+breezy/tests/test_shelf.py: ptree.id2path(b'foo-id')))
124+breezy/tests/test_subsume.py: self.assertEqual('subtree/file2', base_tree.id2path(b'file2-id'))
125+breezy/tests/test_transform.py: tree_mod_paths = [self.wt.abspath(self.wt.id2path(f)) for f in
126+breezy/tests/test_transform.py: self.assertEqual(self.wt.id2path(b'mfile2'), 'new_directory/mfile2')
127+breezy/tests/test_transform.py: with this.wt.get_file(this.wt.id2path(b'a')) as f:
128+breezy/tests/test_transform.py: with this.wt.get_file(this.wt.id2path(b'b')) as f:
129+breezy/tests/test_transform.py: self.assertEqual(this.wt.get_file(this.wt.id2path(b'c')).read(), b'c2')
130+breezy/tests/test_transform.py: self.assertEqual(this.wt.get_file(this.wt.id2path(b'd')).read(), b'd2')
131+breezy/tests/test_transform.py: self.assertEqual(this.wt.get_file(this.wt.id2path(b'e')).read(), b'e2')
132+breezy/tests/test_transform.py: self.assertEqual(this.wt.get_file(this.wt.id2path(b'f')).read(), b'f')
133+breezy/tests/test_transform.py: self.assertEqual(this.wt.get_file(this.wt.id2path(b'g')).read(), b'g')
134+breezy/tests/test_transform.py: self.assertEqual(this.wt.get_file(this.wt.id2path(b'h')).read(),
135+breezy/tests/test_transform.py: self.assertEqual(this.wt.get_file(this.wt.id2path(b'i')).read(),
136+breezy/tests/test_transform.py: with open(this.wt.abspath(this.wt.id2path(b'a')), 'wb') as f:
137+breezy/tests/test_transform.py: self.assertEqual(this.wt.id2path(b'd'), 'd.OTHER')
138+breezy/tests/test_transform.py: self.assertEqual(this.wt.id2path(b'f'), 'f.THIS')
139+breezy/tests/test_transform.py: self.assertEqual(this.wt.id2path(b'c'), pathjoin('b/c1'))
140+breezy/tests/test_transform.py: self.assertEqual(this.wt.id2path(b'd'), pathjoin('b/d1'))
141+breezy/tests/test_transform.py: self.assertEqual(this.wt.id2path(b'e'), pathjoin('b/e1'))
142+breezy/tests/test_transform.py: self.assertEqual(this.wt.id2path(b'f'), pathjoin('b/f1'))
143+breezy/tests/test_transform.py: self.assertEqual(this.wt.id2path(b'g'), pathjoin('b/g1.OTHER'))
144+breezy/tests/test_transform.py: self.assertEqual(this.wt.id2path(b'h'), pathjoin('b/h1.THIS'))
145+breezy/tests/test_transform.py: self.assertEqual(this.wt.id2path(b'i'), pathjoin('b/i1.OTHER'))
146+breezy/tests/test_transform.py: self.assertEqual('file.moved', target.id2path(b'lower-id'))
147+breezy/tests/test_transform.py: self.assertEqual('FILE', target.id2path(b'upper-id'))
148+breezy/tests/test_transform.py: self.assertEqual('file', tree.id2path(b'file-id'))
149+breezy/tests/test_transform.py: self.assertEqual('dir', tree.id2path(b'dir-id'))
150+breezy/tests/test_transform.py: self.assertEqual('dir/symlink', tree.id2path(b'symlink-id'))
151+breezy/tests/test_transform.py: final_tree.get_file_text(final_tree.id2path(b'file-id')))
152+breezy/tests/test_workingtree_4.py: def test_id2path(self):
153+breezy/tests/test_workingtree_4.py: self.assertEqual(u'a', tree.id2path(b'a-id'))
154+breezy/tests/test_workingtree_4.py: self.assertRaises(errors.NoSuchId, tree.id2path, 'a')
155+breezy/tests/test_workingtree_4.py: self.assertEqual(new_path, tree.id2path(b'a-id'))
156+breezy/tests/test_workingtree_4.py: self.assertRaises(errors.NoSuchId, tree.id2path, b'a-id')
157+breezy/tests/test_workingtree_4.py: self.assertEqual('b', tree.id2path(b'b-id'))
158+breezy/tests/test_workingtree_4.py: self.assertRaises(errors.NoSuchId, tree.id2path, b'c-id')
159+breezy/transform.py: path = self._tree.id2path(file_id)
160+breezy/transform.py: path = self._tree.id2path(file_id)
161+breezy/transform.py: kind = self._tree.stored_kind(self._tree.id2path(file_id))
162+breezy/transform.py: old_path = self._tree.id2path(new_entry.file_id)
163+breezy/transform.py: (file_id, t.get_file_revision(t.id2path(file_id)))
164+breezy/transform.py: def id2path(self, file_id):
165+breezy/transform.py: self._transform._tree.id2path(file_id))
166+breezy/transform.py: self._transform._tree.id2path(file_id))
167+breezy/transform.py: self._transform._tree.id2path(file_id))
168+breezy/transform.py: file_ids.sort(key=tree.id2path)
169+breezy/transform.py: filter_tree_path = target_tree.id2path(file_id)
170+breezy/transform.py: specific_files=[path_tree.id2path(file_id)]))
171+breezy/tree.py: paths.append(self.target.id2path(parent_id))
172+breezy/tree.py: source_path = self.source.id2path(file_id)
173+breezy/tree.py: target_path = self.target.id2path(file_id)
174+breezy/tree.py: return self.target.id2path(file_id)
175
176=== modified file 'breezy/builtins.py'
177--- breezy/builtins.py 2019-08-11 13:33:45 +0000
178+++ breezy/builtins.py 2019-09-21 22:32:04 +0000
179@@ -3401,9 +3401,9 @@
180 filename, rev_tree.get_revision_id()))
181 rev_tree_path = relpath
182 else:
183+ inter = _mod_tree.InterTree.get(tree, rev_tree)
184 try:
185- rev_tree_path = _mod_tree.find_previous_path(
186- tree, rev_tree, relpath)
187+ rev_tree_path = inter.find_target_path(relpath)
188 except errors.NoSuchFile:
189 rev_tree_path = None
190
191
192=== modified file 'breezy/git/tree.py'
193--- breezy/git/tree.py 2019-08-11 13:33:45 +0000
194+++ breezy/git/tree.py 2019-09-21 22:32:04 +0000
195@@ -323,15 +323,6 @@
196 raise _mod_tree.FileTimestampUnavailable(path)
197 return rev.timestamp
198
199- def id2path(self, file_id):
200- try:
201- path = self.mapping.parse_file_id(file_id)
202- except ValueError:
203- raise errors.NoSuchId(self, file_id)
204- if self.is_versioned(path):
205- return path
206- raise errors.NoSuchId(self, file_id)
207-
208 def is_versioned(self, path):
209 return self.has_filename(path)
210
211@@ -1039,20 +1030,6 @@
212 else:
213 return True
214
215- def id2path(self, file_id):
216- if file_id is None:
217- return ''
218- if type(file_id) is not bytes:
219- raise TypeError(file_id)
220- with self.lock_read():
221- try:
222- path = self.mapping.parse_file_id(file_id)
223- except ValueError:
224- raise errors.NoSuchId(self, file_id)
225- if self.is_versioned(path):
226- return path
227- raise errors.NoSuchId(self, file_id)
228-
229 def _set_root_id(self, file_id):
230 raise errors.UnsupportedOperation(self._set_root_id, self)
231
232
233=== modified file 'breezy/log.py'
234--- breezy/log.py 2019-09-21 17:08:09 +0000
235+++ breezy/log.py 2019-09-21 22:32:04 +0000
236@@ -89,7 +89,7 @@
237 range,
238 zip,
239 )
240-from .tree import find_previous_path
241+from .tree import InterTree
242
243
244 def find_touching_revisions(repository, last_revision, last_tree, last_path):
245@@ -109,7 +109,8 @@
246 revno = len(history)
247 for revision_id in history:
248 this_tree = repository.revision_tree(revision_id)
249- this_path = find_previous_path(last_tree, this_tree, last_path)
250+ intertree = InterTree.get(last_tree, this_tree)
251+ this_path = intertree.find_target_path(last_path)
252
253 # now we know how it was last time, and how it is in this revision.
254 # are those two states effectively the same or not?
255
256=== modified file 'breezy/merge.py'
257--- breezy/merge.py 2019-07-27 22:47:49 +0000
258+++ breezy/merge.py 2019-09-21 22:32:04 +0000
259@@ -643,8 +643,8 @@
260 sub_merge.merge_type = self.merge_type
261 other_branch = self.other_branch.reference_parent(relpath)
262 sub_merge.set_other_revision(other_revision, other_branch)
263- base_tree_path = _mod_tree.find_previous_path(
264- self.this_tree, self.base_tree, relpath)
265+ base_tree_path = _mod_tree.InterTree(
266+ self.this_tree, self.base_tree).find_target_path(relpath)
267 base_revision = self.base_tree.get_reference_revision(
268 base_tree_path)
269 sub_merge.base_tree = \
270@@ -842,11 +842,11 @@
271 specific_files=this_interesting_files))
272 for change in iterator:
273 if change.path[0] is not None:
274- this_path = _mod_tree.find_previous_path(
275- self.base_tree, self.this_tree, change.path[0])
276+ this_path = _mod_tree.InterTree(
277+ self.base_tree, self.this_tree).find_target_path(change.path[0])
278 else:
279- this_path = _mod_tree.find_previous_path(
280- self.other_tree, self.this_tree, change.path[1])
281+ this_path = _mod_tree.InterTree(
282+ self.other_tree, self.this_tree).find_target_path(change.path[1])
283 this_entry = this_entries.get(this_path)
284 if this_entry is not None:
285 this_name = this_entry.name
286@@ -1441,8 +1441,8 @@
287 # That fails though when OTHER is adding a file, so
288 # we fall back to the other tree to find the path if
289 # it doesn't exist locally.
290- filter_path = _mod_tree.find_previous_path(
291- self.other_tree, self.working_tree, path)
292+ filter_path = _mod_tree.InterTree(
293+ self.other_tree, self.working_tree).find_target_path(path)
294 if filter_path is None:
295 filter_path = path
296 return filter_path
297
298=== modified file 'breezy/plugins/fastimport/revision_store.py'
299--- breezy/plugins/fastimport/revision_store.py 2019-06-15 12:04:34 +0000
300+++ breezy/plugins/fastimport/revision_store.py 2019-09-21 22:32:04 +0000
301@@ -47,14 +47,6 @@
302 self._new_info_by_path = {new_path: ie
303 for _, new_path, file_id, ie in inv_delta}
304
305- def id2path(self, file_id):
306- if file_id in self._new_info_by_id:
307- new_path = self._new_info_by_id[file_id][0]
308- if new_path is None:
309- raise errors.NoSuchId(self, file_id)
310- return new_path
311- return self._basis_inv.id2path(file_id)
312-
313 def path2id(self, path):
314 # CommitBuilder currently only requires access to the root id. We don't
315 # build a map of renamed files, etc. One possibility if we ever *do*
316
317=== modified file 'breezy/tests/blackbox/test_join.py'
318--- breezy/tests/blackbox/test_join.py 2019-06-29 13:16:26 +0000
319+++ breezy/tests/blackbox/test_join.py 2019-09-21 22:32:04 +0000
320@@ -71,16 +71,21 @@
321 self.run_bzr('join . --reference', working_dir='tree/subtree')
322 sub_tree.lock_read()
323 self.addCleanup(sub_tree.unlock)
324- self.assertEqual(b'file1-id', sub_tree.path2id('file1'))
325- self.assertTrue(sub_tree.has_id(b'file1-id'))
326- self.assertEqual(subtree_root_id, sub_tree.path2id(''))
327- self.assertEqual('', sub_tree.id2path(subtree_root_id))
328- self.assertIs(None, base_tree.path2id('subtree/file1'))
329+ if sub_tree.supports_setting_file_ids():
330+ self.assertEqual(b'file1-id', sub_tree.path2id('file1'))
331+ self.assertTrue(sub_tree.has_id(b'file1-id'))
332+ self.assertEqual(subtree_root_id, sub_tree.path2id(''))
333+ self.assertEqual('', sub_tree.id2path(subtree_root_id))
334+ self.assertIs(None, base_tree.path2id('subtree/file1'))
335+
336 base_tree.lock_read()
337 self.addCleanup(base_tree.unlock)
338- self.assertFalse(base_tree.has_id(b'file1-id'))
339- self.assertEqual(subtree_root_id, base_tree.path2id('subtree'))
340- self.assertEqual('subtree', base_tree.id2path(subtree_root_id))
341+ self.assertEqual(['subtree'], list(base_tree.iter_references()))
342+ if base_tree.supports_setting_file_ids():
343+ self.assertEqual(b'file1-id', sub_tree.path2id('file1'))
344+ self.assertFalse(base_tree.has_id(b'file1-id'))
345+ self.assertEqual(subtree_root_id, base_tree.path2id('subtree'))
346+ self.assertEqual('subtree', base_tree.id2path(subtree_root_id))
347
348 def test_references_check_repository_support(self):
349 """Users are stopped from adding a reference that can't be committed."""
350
351=== modified file 'breezy/tests/matchers.py'
352--- breezy/tests/matchers.py 2018-11-11 04:08:32 +0000
353+++ breezy/tests/matchers.py 2019-09-21 22:32:04 +0000
354@@ -48,7 +48,7 @@
355 from ..sixish import (
356 text_type,
357 )
358-from ..tree import find_previous_path
359+from ..tree import InterTree
360
361 from testtools.matchers import Equals, Mismatch, Matcher
362
363@@ -204,8 +204,8 @@
364 with tree.lock_read(), self.previous_tree.lock_read():
365 for path, ie in tree.iter_entries_by_dir():
366 if tree.supports_rename_tracking():
367- previous_path = find_previous_path(
368- tree, self.previous_tree, path)
369+ intertree = InterTree(tree, self.previous_tree)
370+ previous_path = intertree.find_target_path(path)
371 else:
372 if self.previous_tree.is_versioned(path):
373 previous_path = path
374
375=== modified file 'breezy/tests/per_intertree/test_compare.py'
376--- breezy/tests/per_intertree/test_compare.py 2019-08-11 13:33:45 +0000
377+++ breezy/tests/per_intertree/test_compare.py 2019-09-21 22:32:04 +0000
378@@ -571,24 +571,24 @@
379 self.check_has_changes(False, tree1, tree2)
380
381 def added(self, tree, file_id):
382- path, entry = self.get_path_entry(tree, file_id)
383+ path = tree.id2path(file_id)
384+ entry = self.get_path_entry(tree, path)
385 return TreeChange(
386- file_id, (None, path), True, (False, True), (None, entry.parent_id),
387+ entry.file_id, (None, path), True, (False, True), (None, entry.parent_id),
388 (None, entry.name), (None, entry.kind),
389 (None, entry.executable))
390
391 @staticmethod
392- def get_path_entry(tree, file_id):
393- with tree.lock_read():
394- path = tree.id2path(file_id)
395+ def get_path_entry(tree, path):
396 iterator = tree.iter_entries_by_dir(specific_files=[path])
397 try:
398- return next(iterator)
399+ return next(iterator)[1]
400 except StopIteration:
401 raise KeyError(file_id)
402
403 def changed_content(self, tree, file_id):
404- path, entry = self.get_path_entry(tree, file_id)
405+ path = tree.id2path(file_id)
406+ entry = self.get_path_entry(tree, path)
407 return TreeChange(
408 file_id, (path, path), True, (True, True),
409 (entry.parent_id, entry.parent_id),
410@@ -596,8 +596,10 @@
411 (entry.executable, entry.executable))
412
413 def kind_changed(self, from_tree, to_tree, file_id):
414- from_path, old_entry = self.get_path_entry(from_tree, file_id)
415- path, new_entry = self.get_path_entry(to_tree, file_id)
416+ from_path = from_tree.id2path(file_id)
417+ path = to_tree.id2path(file_id)
418+ old_entry = self.get_path_entry(from_tree, from_path)
419+ new_entry = self.get_path_entry(to_tree, path)
420 return TreeChange(
421 file_id, (from_path, path), True, (True, True),
422 (old_entry.parent_id, new_entry.parent_id),
423@@ -622,9 +624,13 @@
424 (entry.name, None), (entry.kind, None),
425 (entry.executable, None))
426
427- def renamed(self, from_tree, to_tree, file_id, changed_content):
428- from_path, from_entry = self.get_path_entry(from_tree, file_id)
429- to_path, to_entry = self.get_path_entry(to_tree, file_id)
430+ def renamed(self, from_tree, to_tree, file_id, content_changed):
431+ with from_tree.lock_read():
432+ from_path = from_tree.id2path(file_id)
433+ with to_tree.lock_read():
434+ to_path = to_tree.id2path(file_id)
435+ from_entry = self.get_path_entry(from_tree, from_path)
436+ to_entry = self.get_path_entry(to_tree, to_path)
437 return TreeChange(
438 file_id, (from_path, to_path), changed_content, (True, True),
439 (from_entry.parent_id, to_entry.parent_id),
440@@ -633,13 +639,14 @@
441 (from_entry.executable, to_entry.executable))
442
443 def unchanged(self, tree, file_id):
444- path, entry = self.get_path_entry(tree, file_id)
445+ path = tree.id2path(file_id)
446+ entry = self.get_path_entry(tree, path)
447 parent = entry.parent_id
448 name = entry.name
449 kind = entry.kind
450 executable = entry.executable
451 return TreeChange(
452- file_id, (path, path), False, (True, True),
453+ entry.file_id, (path, path), False, (True, True),
454 (parent, parent), (name, name), (kind, kind),
455 (executable, executable))
456
457
458=== modified file 'breezy/tests/per_tree/test_tree.py'
459--- breezy/tests/per_tree/test_tree.py 2019-07-25 23:22:30 +0000
460+++ breezy/tests/per_tree/test_tree.py 2019-09-21 22:32:04 +0000
461@@ -141,6 +141,8 @@
462 def test_id2path(self):
463 # translate from file-id back to path
464 work_tree = self.make_branch_and_tree('wt')
465+ if not work_tree.supports_setting_file_ids():
466+ self.skipTest("working tree does not support setting file ids")
467 tree = self.get_tree_no_parents_abc_content(work_tree)
468 a_id = tree.path2id('a')
469 with tree.lock_read():
470
471=== modified file 'breezy/tests/per_workingtree/test_commit.py'
472--- breezy/tests/per_workingtree/test_commit.py 2019-09-21 17:08:09 +0000
473+++ breezy/tests/per_workingtree/test_commit.py 2019-09-21 22:32:04 +0000
474@@ -214,14 +214,18 @@
475 def test_commit_aborted_does_not_apply_automatic_changes_bug_282402(self):
476 wt = self.make_branch_and_tree('.')
477 wt.add(['a'], None, ['file'])
478- a_id = wt.path2id('a')
479- self.assertEqual('a', wt.id2path(a_id))
480+ self.assertTrue(wt.is_versioned('a'))
481+ if wt.supports_setting_file_ids():
482+ a_id = wt.path2id('a')
483+ self.assertEqual('a', wt.id2path(a_id))
484
485 def fail_message(obj):
486 raise errors.BzrCommandError("empty commit message")
487 self.assertRaises(errors.BzrCommandError, wt.commit,
488 message_callback=fail_message)
489- self.assertEqual('a', wt.id2path(a_id))
490+ self.assertTrue(wt.is_versioned('a'))
491+ if wt.supports_setting_file_ids():
492+ self.assertEqual('a', wt.id2path(a_id))
493
494 def test_local_commit_ignores_master(self):
495 # a --local commit does not require access to the master branch
496
497=== modified file 'breezy/tests/test_branchbuilder.py'
498--- breezy/tests/test_branchbuilder.py 2018-11-11 04:08:32 +0000
499+++ breezy/tests/test_branchbuilder.py 2019-09-21 22:32:04 +0000
500@@ -208,7 +208,7 @@
501 rev_tree.lock_read()
502 self.addCleanup(rev_tree.unlock)
503 self.assertEqual(b'new\ncontent\n',
504- rev_tree.get_file_text(rev_tree.id2path(b'a-id')))
505+ rev_tree.get_file_text('a'))
506
507 def test_delete_file(self):
508 builder = self.build_a_rev()
509
510=== modified file 'breezy/tests/test_bundle.py'
511--- breezy/tests/test_bundle.py 2019-08-11 13:33:45 +0000
512+++ breezy/tests/test_bundle.py 2019-09-21 22:32:04 +0000
513@@ -43,7 +43,7 @@
514 features,
515 test_commit,
516 )
517-from ..tree import find_previous_path
518+from ..tree import InterTree
519
520
521 def get_text(vf, key):
522@@ -582,7 +582,7 @@
523
524 for path, status, kind, entry in base_files:
525 # Check that the meta information is the same
526- to_path = find_previous_path(base_tree, to_tree, path)
527+ to_path = InterTree.get(base_tree, to_tree).find_target_path(path)
528 self.assertEqual(
529 base_tree.get_file_size(path),
530 to_tree.get_file_size(to_path))
531
532=== modified file 'breezy/tests/test_extract.py'
533--- breezy/tests/test_extract.py 2019-06-29 13:16:26 +0000
534+++ breezy/tests/test_extract.py 2019-09-21 22:32:04 +0000
535@@ -29,10 +29,12 @@
536 wt.add(['b', 'b/c', 'd'], [b'b-id', b'c-id', b'd-id'])
537 wt.commit('added files')
538 b_wt = wt.extract('b')
539- self.assertEqual(b'b-id', b_wt.path2id(''))
540- self.assertEqual(b'c-id', b_wt.path2id('c'))
541- self.assertEqual('c', b_wt.id2path(b'c-id'))
542- self.assertRaises(errors.BzrError, wt.id2path, b'b-id')
543+ self.assertTrue(b_wt.is_versioned(''))
544+ if b_wt.supports_setting_file_ids():
545+ self.assertEqual(b'b-id', b_wt.path2id(''))
546+ self.assertEqual(b'c-id', b_wt.path2id('c'))
547+ self.assertEqual('c', b_wt.id2path(b'c-id'))
548+ self.assertRaises(errors.BzrError, wt.id2path, b'b-id')
549 self.assertEqual(b_wt.basedir, wt.abspath('b'))
550 self.assertEqual(wt.get_parent_ids(), b_wt.get_parent_ids())
551 self.assertEqual(wt.branch.last_revision(),
552
553=== modified file 'breezy/tests/test_tree.py'
554--- breezy/tests/test_tree.py 2019-06-29 19:50:18 +0000
555+++ breezy/tests/test_tree.py 2019-09-21 22:32:04 +0000
556@@ -28,7 +28,6 @@
557 from breezy.tree import (
558 FileTimestampUnavailable,
559 InterTree,
560- find_previous_paths,
561 get_canonical_path,
562 )
563
564@@ -174,7 +173,9 @@
565
566 tree0 = tree.branch.repository.revision_tree(revision.NULL_REVISION)
567
568- self.assertEqual({'b': None}, find_previous_paths(tree1, tree0, ['b']))
569+ self.assertEqual(
570+ {'b': None},
571+ InterTree.get(tree1, tree0).find_target_paths(['b']))
572
573 def test_find_previous_paths(self):
574 tree = self.make_branch_and_tree('tree')
575@@ -189,8 +190,9 @@
576 revid2 = tree.commit('second')
577 tree2 = tree.branch.repository.revision_tree(revid2)
578
579- self.assertEqual({'c': 'b', 'b': None},
580- find_previous_paths(tree2, tree1, ['b', 'c']))
581+ self.assertEqual(
582+ {'c': 'b', 'b': None},
583+ InterTree.get(tree2, tree1).find_target_paths(['b', 'c']))
584
585
586 class GetCanonicalPath(TestCaseWithTransport):
587
588=== modified file 'breezy/transform.py'
589--- breezy/transform.py 2019-09-21 17:08:09 +0000
590+++ breezy/transform.py 2019-09-21 22:32:04 +0000
591@@ -71,7 +71,7 @@
592 viewvalues,
593 )
594 from .tree import (
595- find_previous_path,
596+ InterTree,
597 TreeChange,
598 )
599
600@@ -2965,8 +2965,8 @@
601 if basis_tree is None:
602 basis_tree = working_tree.basis_tree()
603 basis_tree.lock_read()
604- basis_path = find_previous_path(
605- working_tree, basis_tree, wt_path)
606+ basis_path = InterTree.get(
607+ working_tree, basis_tree).find_target_path(wt_path)
608 if basis_path is None:
609 if target_kind is None and not target_versioned:
610 keep_content = True
611@@ -3005,7 +3005,7 @@
612 basis_tree = working_tree.basis_tree()
613 basis_tree.lock_read()
614 new_sha1 = target_tree.get_file_sha1(target_path)
615- basis_path = find_previous_path(target_tree, basis_tree, target_path)
616+ basis_path = InterTree.get(target_tree, basis_tree).find_target_path(target_path)
617 if (basis_path is not None and
618 new_sha1 == basis_tree.get_file_sha1(basis_path)):
619 # If the new contents of the file match what is in basis,
620
621=== modified file 'breezy/tree.py'
622--- breezy/tree.py 2019-09-21 17:08:09 +0000
623+++ breezy/tree.py 2019-09-21 22:32:04 +0000
624@@ -300,13 +300,6 @@
625 """Iterate through all paths, including paths for missing files."""
626 raise NotImplementedError(self.all_versioned_paths)
627
628- def id2path(self, file_id):
629- """Return the path for a file id.
630-
631- :raises NoSuchId:
632- """
633- raise NotImplementedError(self.id2path)
634-
635 def iter_entries_by_dir(self, specific_files=None):
636 """Walk the tree in 'by_dir' order.
637
638@@ -946,8 +939,8 @@
639 from_data = dict(from_entries_by_dir)
640 to_entries_by_dir = list(self.target.iter_entries_by_dir(
641 specific_files=target_specific_files))
642- path_equivs = find_previous_paths(
643- self.target, self.source, [p for p, e in to_entries_by_dir])
644+ path_equivs = InterTree.get(
645+ self.target, self.source).find_target_paths([p for p, e in to_entries_by_dir])
646 num_entries = len(from_entries_by_dir) + len(to_entries_by_dir)
647 entry_count = 0
648 # the unversioned path lookup only occurs on real trees - where there
649@@ -1010,7 +1003,7 @@
650 if file_id in to_paths:
651 # already returned
652 continue
653- to_path = find_previous_path(self.source, self.target, path)
654+ to_path = self.find_target_path(path)
655 entry_count += 1
656 if pb is not None:
657 pb.update('comparing files', entry_count, num_entries)
658@@ -1174,44 +1167,37 @@
659 target_sha1 = target_verifier_data
660 return (source_sha1 == target_sha1)
661
662+ def find_target_path(self, path):
663+ """Find previous tree path.
664+
665+ :param path: Path to search for (exists in source)
666+ :return: path in target, or None if there is no equivalent path.
667+ :raise NoSuchFile: If the path doesn't exist in source
668+ """
669+ file_id = self.source.path2id(path)
670+ if file_id is None:
671+ raise errors.NoSuchFile(path)
672+ try:
673+ return self.target.id2path(file_id)
674+ except errors.NoSuchId:
675+ return None
676+
677+ def find_target_paths(self, paths):
678+ """Find previous tree paths.
679+
680+ :param paths: Iterable over paths in source to search for
681+ :return: Dictionary mapping from source paths to paths in target , or
682+ None if there is no equivalent path.
683+ """
684+ ret = {}
685+ for path in paths:
686+ ret[path] = self.find_target_path(path)
687+ return ret
688+
689
690 InterTree.register_optimiser(InterTree)
691
692
693-def find_previous_paths(from_tree, to_tree, paths):
694- """Find previous tree paths.
695-
696- :param from_tree: From tree
697- :param to_tree: To tree
698- :param paths: Iterable over paths in from_tree to search for
699- :return: Dictionary mapping from from_tree paths to paths in to_tree, or
700- None if there is no equivalent path.
701- """
702- ret = {}
703- for path in paths:
704- ret[path] = find_previous_path(from_tree, to_tree, path)
705- return ret
706-
707-
708-def find_previous_path(from_tree, to_tree, path, file_id=None):
709- """Find previous tree path.
710-
711- :param from_tree: From tree
712- :param to_tree: To tree
713- :param path: Path to search for (exists in from_tree)
714- :return: path in to_tree, or None if there is no equivalent path.
715- :raise NoSuchFile: If the path doesn't exist in from_tree
716- """
717- if file_id is None:
718- file_id = from_tree.path2id(path)
719- if file_id is None:
720- raise errors.NoSuchFile(path)
721- try:
722- return to_tree.id2path(file_id)
723- except errors.NoSuchId:
724- return None
725-
726-
727 def get_canonical_path(tree, path, normalize):
728 """Find the canonical path of an item, ignoring case.
729

Subscribers

People subscribed via source and target branches