Merge lp:~jelmer/brz/has-path-relations into lp:brz

Proposed by Jelmer Vernooij on 2018-03-24
Status: Merged
Approved by: Jelmer Vernooij on 2018-03-24
Approved revision: 6916
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/has-path-relations
Merge into: lp:brz
Diff against target: 326 lines (+77/-114)
3 files modified
breezy/tests/matchers.py (+9/-11)
breezy/tests/per_workingtree/test_commit.py (+25/-42)
breezy/tests/per_workingtree/test_unversion.py (+43/-61)
To merge this branch: bzr merge lp:~jelmer/brz/has-path-relations
Reviewer Review Type Date Requested Status
Martin Packman 2018-03-24 Approve on 2018-03-24
Review via email: mp+342034@code.launchpad.net

Description of the change

Use HasPathRelations in a few more places.

Simplify the actual HasPathRelations implementation to always take tuples with
current and previous path. The mode in which only the current path is specified
is not useful; the HasLayout matcher can already be used for that.

To post a comment you must log in.
Martin Packman (gz) wrote :

Looks good, thanks.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/tests/matchers.py'
2--- breezy/tests/matchers.py 2018-03-18 14:48:55 +0000
3+++ breezy/tests/matchers.py 2018-03-24 13:52:34 +0000
4@@ -222,22 +222,20 @@
5
6 :param entries: List of path strings or (path, previous_path) tuples to process
7 """
8+ directory_used = set()
9 directories = []
10- for entry in entries:
11- if isinstance(entry, (str, text_type)):
12- path = entry
13- else:
14- path = entry[0]
15+ for (path, previous_path) in entries:
16 if not path or path[-1] == "/":
17 # directory
18- directories.append((path, entry))
19+ directories.append((path, previous_path))
20 else:
21 # Yield the referenced parent directories
22- for dirpath, direntry in directories:
23- if osutils.is_inside(dirpath, path):
24- yield direntry
25- directories = []
26- yield entry
27+ for direntry in directories:
28+ if osutils.is_inside(direntry[0], path):
29+ directory_used.add(direntry[0])
30+ for (path, previous_path) in entries:
31+ if (not path.endswith("/")) or path in directory_used:
32+ yield (path, previous_path)
33
34 def __str__(self):
35 return 'HasPathRelations(%r, %r)' % (self.previous_tree, self.previous_entries)
36
37=== modified file 'breezy/tests/per_workingtree/test_commit.py'
38--- breezy/tests/per_workingtree/test_commit.py 2018-03-10 14:20:40 +0000
39+++ breezy/tests/per_workingtree/test_commit.py 2018-03-24 13:52:34 +0000
40@@ -33,6 +33,7 @@
41 CannotCommitSelectedFileMerge,
42 PointlessCommit,
43 )
44+from breezy.tests.matchers import HasPathRelations
45 from breezy.tests.per_workingtree import TestCaseWithWorkingTree
46 from breezy.tests.testui import ProgressRecordingUIFactory
47
48@@ -66,51 +67,37 @@
49 tree_a = self.make_branch_and_tree('a')
50 self.build_tree(['a/dir/', 'a/dir/f1', 'a/dir/f2', 'a/dir2/'])
51 tree_a.add(['dir', 'dir/f1', 'dir/f2', 'dir2'])
52- dir2_id = tree_a.path2id('dir2')
53- f1_id = tree_a.path2id('dir/f1')
54 rev_id1 = tree_a.commit('init')
55+ revtree = tree_a.branch.repository.revision_tree(rev_id1)
56 # Rename one entry out of this directory
57 tree_a.rename_one('dir/f1', 'dir2/a')
58 osutils.rmtree('a/dir')
59 tree_a.commit('autoremoved')
60
61- with tree_a.lock_read():
62- root_id = tree_a.get_root_id()
63- paths = [(path, ie.file_id)
64- for path, ie in tree_a.iter_entries_by_dir()]
65 # The only paths left should be the root
66- self.assertEqual([('', root_id),
67- ('dir2', dir2_id),
68- ('dir2/a', f1_id),
69- ], paths)
70+ self.assertThat(
71+ tree_a, HasPathRelations(
72+ revtree,
73+ [('', ''), ('dir2/', 'dir2/'), ('dir2/a', 'dir/f1')]))
74
75 def test_no_autodelete_alternate_renamed(self):
76 # Test for bug #114615
77 tree_a = self.make_branch_and_tree('A')
78 self.build_tree(['A/a/', 'A/a/m', 'A/a/n'])
79 tree_a.add(['a', 'a/m', 'a/n'])
80- a_id = tree_a.path2id('a')
81- m_id = tree_a.path2id('a/m')
82- n_id = tree_a.path2id('a/n')
83 tree_a.commit('init')
84
85- with tree_a.lock_read():
86- root_id = tree_a.get_root_id()
87-
88 tree_b = tree_a.controldir.sprout('B').open_workingtree()
89 self.build_tree(['B/xyz/'])
90 tree_b.add(['xyz'])
91- xyz_id = tree_b.path2id('xyz')
92 tree_b.rename_one('a/m', 'xyz/m')
93 osutils.rmtree('B/a')
94 tree_b.commit('delete in B')
95
96- paths = [(path, ie.file_id)
97- for path, ie in tree_b.iter_entries_by_dir()]
98- self.assertEqual([('', root_id),
99- ('xyz', xyz_id),
100- ('xyz/m', m_id),
101- ], paths)
102+ self.assertThat(
103+ tree_b,
104+ HasPathRelations(
105+ tree_a, [('', ''), ('xyz/', None), ('xyz/m', 'a/m')]))
106
107 self.build_tree_contents([('A/a/n', 'new contents for n\n')])
108 tree_a.commit('change n in A')
109@@ -119,14 +106,13 @@
110 # (in A) and removed (in B), so 'a' needs to be restored.
111 num_conflicts = tree_b.merge_from_branch(tree_a.branch)
112 self.assertEqual(3, num_conflicts)
113- paths = [(path, ie.file_id)
114- for path, ie in tree_b.iter_entries_by_dir()]
115- self.assertEqual([('', root_id),
116- ('a', a_id),
117- ('xyz', xyz_id),
118- ('a/n.OTHER', n_id),
119- ('xyz/m', m_id),
120- ], paths)
121+
122+ self.assertThat(
123+ tree_b, HasPathRelations(
124+ tree_a,
125+ [('', ''), ('a/', 'a/'), ('xyz/', None),
126+ ('a/n.OTHER', 'a/n'), ('xyz/m', 'a/m')]))
127+
128 osutils.rmtree('B/a')
129 try:
130 # bzr resolve --all
131@@ -136,12 +122,11 @@
132 # effect.
133 pass
134 tree_b.commit('autoremove a, without touching xyz/m')
135- paths = [(path, ie.file_id)
136- for path, ie in tree_b.iter_entries_by_dir()]
137- self.assertEqual([('', root_id),
138- ('xyz', xyz_id),
139- ('xyz/m', m_id),
140- ], paths)
141+
142+ self.assertThat(
143+ tree_b, HasPathRelations(
144+ tree_a,
145+ [('', ''), ('xyz/', None), ('xyz/m', 'a/m')]))
146
147 def test_commit_exclude_pending_merge_fails(self):
148 """Excludes are a form of partial commit."""
149@@ -173,15 +158,13 @@
150 tree.lock_read()
151 self.addCleanup(tree.unlock)
152 changes = list(tree.iter_changes(tree.basis_tree()))
153- self.assertEqual(2, len(changes))
154- self.assertEqual((None, 'b'), changes[0][1])
155- self.assertEqual((None, 'c'), changes[1][1])
156+ self.assertEqual([(None, 'b'), (None, 'c')], [c[1] for c in changes])
157
158 def test_commit_exclude_subtree_of_selected(self):
159 tree = self.make_branch_and_tree('.')
160- self.build_tree(['a/', 'a/b'])
161+ self.build_tree(['a/', 'a/b', 'a/c'])
162 tree.smart_add(['.'])
163- tree.commit('test', specific_files=['a'], exclude=['a/b'])
164+ tree.commit('test', specific_files=['a', 'a/c'], exclude=['a/b'])
165 # If a/b was excluded it will still be 'added' in status.
166 tree.lock_read()
167 self.addCleanup(tree.unlock)
168
169=== modified file 'breezy/tests/per_workingtree/test_unversion.py'
170--- breezy/tests/per_workingtree/test_unversion.py 2018-03-10 14:20:40 +0000
171+++ breezy/tests/per_workingtree/test_unversion.py 2018-03-24 13:52:34 +0000
172@@ -19,6 +19,7 @@
173 from breezy import (
174 errors,
175 )
176+from breezy.tests.matchers import HasPathRelations
177 from breezy.tests.per_workingtree import TestCaseWithWorkingTree
178
179
180@@ -44,12 +45,19 @@
181 tree = self.make_branch_and_tree('.')
182 self.build_tree(['del/', 'del/sub/', 'del/sub/b'])
183 tree.add(['del', 'del/sub', 'del/sub/b'])
184- b_id = tree.path2id('del/sub/b')
185- tree.commit('setup')
186+ revid = tree.commit('setup')
187+ revtree = tree.branch.repository.revision_tree(revid)
188 tree.rename_one('del/sub', 'sub')
189- self.assertEqual('sub/b', tree.id2path(b_id))
190- tree.unversion(['del', 'sub/b'])
191- self.assertRaises(errors.NoSuchId, tree.id2path, b_id)
192+ self.assertThat(
193+ tree,
194+ HasPathRelations(revtree, [('', ''), ('del/', 'del/'), ('sub/', 'del/sub/'), ('sub/b', 'del/sub/b')]))
195+ if tree.has_versioned_directories():
196+ tree.unversion(['del', 'sub/b'])
197+ else:
198+ tree.unversion(['sub/b'])
199+ self.assertThat(
200+ tree,
201+ HasPathRelations(revtree, [('', ''), ('sub/', 'del/sub/')]))
202
203 def test_unversion_several_files(self):
204 """After unversioning several files, they should not be versioned."""
205@@ -119,72 +127,47 @@
206 self.build_tree(['a/dir/', 'a/dir/f1', 'a/dir/f2', 'a/dir/f3',
207 'a/dir2/'])
208 tree.add(['dir', 'dir/f1', 'dir/f2', 'dir/f3', 'dir2'])
209- dir_id = tree.path2id('dir')
210- dir2_id = tree.path2id('dir2')
211- f1_id = tree.path2id('dir/f1')
212- f2_id = tree.path2id('dir/f2')
213- f3_id = tree.path2id('dir/f3')
214 rev_id1 = tree.commit('init')
215+ revtree = tree.branch.repository.revision_tree(rev_id1)
216 # Start off by renaming entries, and then unversion a bunch of entries
217 # https://bugs.launchpad.net/bzr/+bug/114615
218 tree.rename_one('dir/f1', 'dir/a')
219 tree.rename_one('dir/f2', 'dir/z')
220 tree.move(['dir/f3'], 'dir2')
221
222- tree.lock_read()
223- try:
224- root_id = tree.get_root_id()
225- paths = [(path, ie.file_id)
226- for path, ie in tree.iter_entries_by_dir()]
227- finally:
228- tree.unlock()
229- self.assertEqual([('', root_id),
230- ('dir', dir_id),
231- ('dir2', dir2_id),
232- ('dir/a', f1_id),
233- ('dir/z', f2_id),
234- ('dir2/f3', f3_id),
235- ], paths)
236+ self.assertThat(
237+ tree, HasPathRelations(
238+ revtree,
239+ [('', ''), ('dir/', 'dir/'), ('dir2/', 'dir2/'),
240+ ('dir/a', 'dir/f1'), ('dir/z', 'dir/f2'),
241+ ('dir2/f3', 'dir/f3')]))
242
243 tree.unversion({'dir'})
244- paths = [(path, ie.file_id)
245- for path, ie in tree.iter_entries_by_dir()]
246-
247- self.assertEqual([('', root_id),
248- ('dir2', dir2_id),
249- ('dir2/f3', f3_id),
250- ], paths)
251+ self.assertThat(
252+ tree,
253+ HasPathRelations(
254+ revtree,
255+ [('', ''), ('dir2/', 'dir2/'), ('dir2/f3', 'dir/f3')]))
256
257 def test_unversion_after_conflicted_merge(self):
258 # Test for bug #114615
259 tree_a = self.make_branch_and_tree('A')
260 self.build_tree(['A/a/', 'A/a/m', 'A/a/n'])
261 tree_a.add(['a', 'a/m', 'a/n'])
262- a_id = tree_a.path2id('a')
263- m_id = tree_a.path2id('a/m')
264- n_id = tree_a.path2id('a/n')
265 tree_a.commit('init')
266
267- tree_a.lock_read()
268- try:
269- root_id = tree_a.get_root_id()
270- finally:
271- tree_a.unlock()
272-
273 tree_b = tree_a.controldir.sprout('B').open_workingtree()
274 self.build_tree(['B/xyz/'])
275 tree_b.add(['xyz'])
276- xyz_id = tree_b.path2id('xyz')
277 tree_b.rename_one('a/m', 'xyz/m')
278 tree_b.unversion(['a'])
279 tree_b.commit('delete in B')
280
281- paths = [(path, ie.file_id)
282- for path, ie in tree_b.iter_entries_by_dir()]
283- self.assertEqual([('', root_id),
284- ('xyz', xyz_id),
285- ('xyz/m', m_id),
286- ], paths)
287+ self.assertThat(
288+ tree_b,
289+ HasPathRelations(
290+ tree_a,
291+ [('', ''), ('xyz/', None), ('xyz/m', 'a/m')]))
292
293 self.build_tree_contents([('A/a/n', 'new contents for n\n')])
294 tree_a.commit('change n in A')
295@@ -194,18 +177,17 @@
296 # because 'a' is still an existing directory
297 num_conflicts = tree_b.merge_from_branch(tree_a.branch)
298 self.assertEqual(4, num_conflicts)
299- paths = [(path, ie.file_id)
300- for path, ie in tree_b.iter_entries_by_dir()]
301- self.assertEqual([('', root_id),
302- ('a', a_id),
303- ('xyz', xyz_id),
304- ('a/n.OTHER', n_id),
305- ('xyz/m', m_id),
306- ], paths)
307+
308+ self.assertThat(
309+ tree_b,
310+ HasPathRelations(
311+ tree_a,
312+ [('', ''), ('a/', 'a/'), ('xyz/', None),
313+ ('a/n.OTHER', 'a/n'), ('xyz/m', 'a/m')]))
314+
315 tree_b.unversion(['a'])
316- paths = [(path, ie.file_id)
317- for path, ie in tree_b.iter_entries_by_dir()]
318- self.assertEqual([('', root_id),
319- ('xyz', xyz_id),
320- ('xyz/m', m_id),
321- ], paths)
322+ self.assertThat(
323+ tree_b,
324+ HasPathRelations(
325+ tree_a,
326+ [('', ''), ('xyz/', None), ('xyz/m', 'a/m')]))

Subscribers

People subscribed via source and target branches