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

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
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 Approve
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.
Revision history for this message
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
=== modified file 'breezy/tests/matchers.py'
--- breezy/tests/matchers.py 2018-03-18 14:48:55 +0000
+++ breezy/tests/matchers.py 2018-03-24 13:52:34 +0000
@@ -222,22 +222,20 @@
222222
223 :param entries: List of path strings or (path, previous_path) tuples to process223 :param entries: List of path strings or (path, previous_path) tuples to process
224 """224 """
225 directory_used = set()
225 directories = []226 directories = []
226 for entry in entries:227 for (path, previous_path) in entries:
227 if isinstance(entry, (str, text_type)):
228 path = entry
229 else:
230 path = entry[0]
231 if not path or path[-1] == "/":228 if not path or path[-1] == "/":
232 # directory229 # directory
233 directories.append((path, entry))230 directories.append((path, previous_path))
234 else:231 else:
235 # Yield the referenced parent directories232 # Yield the referenced parent directories
236 for dirpath, direntry in directories:233 for direntry in directories:
237 if osutils.is_inside(dirpath, path):234 if osutils.is_inside(direntry[0], path):
238 yield direntry235 directory_used.add(direntry[0])
239 directories = []236 for (path, previous_path) in entries:
240 yield entry237 if (not path.endswith("/")) or path in directory_used:
238 yield (path, previous_path)
241239
242 def __str__(self):240 def __str__(self):
243 return 'HasPathRelations(%r, %r)' % (self.previous_tree, self.previous_entries)241 return 'HasPathRelations(%r, %r)' % (self.previous_tree, self.previous_entries)
244242
=== modified file 'breezy/tests/per_workingtree/test_commit.py'
--- breezy/tests/per_workingtree/test_commit.py 2018-03-10 14:20:40 +0000
+++ breezy/tests/per_workingtree/test_commit.py 2018-03-24 13:52:34 +0000
@@ -33,6 +33,7 @@
33 CannotCommitSelectedFileMerge,33 CannotCommitSelectedFileMerge,
34 PointlessCommit,34 PointlessCommit,
35 )35 )
36from breezy.tests.matchers import HasPathRelations
36from breezy.tests.per_workingtree import TestCaseWithWorkingTree37from breezy.tests.per_workingtree import TestCaseWithWorkingTree
37from breezy.tests.testui import ProgressRecordingUIFactory38from breezy.tests.testui import ProgressRecordingUIFactory
3839
@@ -66,51 +67,37 @@
66 tree_a = self.make_branch_and_tree('a')67 tree_a = self.make_branch_and_tree('a')
67 self.build_tree(['a/dir/', 'a/dir/f1', 'a/dir/f2', 'a/dir2/'])68 self.build_tree(['a/dir/', 'a/dir/f1', 'a/dir/f2', 'a/dir2/'])
68 tree_a.add(['dir', 'dir/f1', 'dir/f2', 'dir2'])69 tree_a.add(['dir', 'dir/f1', 'dir/f2', 'dir2'])
69 dir2_id = tree_a.path2id('dir2')
70 f1_id = tree_a.path2id('dir/f1')
71 rev_id1 = tree_a.commit('init')70 rev_id1 = tree_a.commit('init')
71 revtree = tree_a.branch.repository.revision_tree(rev_id1)
72 # Rename one entry out of this directory72 # Rename one entry out of this directory
73 tree_a.rename_one('dir/f1', 'dir2/a')73 tree_a.rename_one('dir/f1', 'dir2/a')
74 osutils.rmtree('a/dir')74 osutils.rmtree('a/dir')
75 tree_a.commit('autoremoved')75 tree_a.commit('autoremoved')
7676
77 with tree_a.lock_read():
78 root_id = tree_a.get_root_id()
79 paths = [(path, ie.file_id)
80 for path, ie in tree_a.iter_entries_by_dir()]
81 # The only paths left should be the root77 # The only paths left should be the root
82 self.assertEqual([('', root_id),78 self.assertThat(
83 ('dir2', dir2_id),79 tree_a, HasPathRelations(
84 ('dir2/a', f1_id),80 revtree,
85 ], paths)81 [('', ''), ('dir2/', 'dir2/'), ('dir2/a', 'dir/f1')]))
8682
87 def test_no_autodelete_alternate_renamed(self):83 def test_no_autodelete_alternate_renamed(self):
88 # Test for bug #11461584 # Test for bug #114615
89 tree_a = self.make_branch_and_tree('A')85 tree_a = self.make_branch_and_tree('A')
90 self.build_tree(['A/a/', 'A/a/m', 'A/a/n'])86 self.build_tree(['A/a/', 'A/a/m', 'A/a/n'])
91 tree_a.add(['a', 'a/m', 'a/n'])87 tree_a.add(['a', 'a/m', 'a/n'])
92 a_id = tree_a.path2id('a')
93 m_id = tree_a.path2id('a/m')
94 n_id = tree_a.path2id('a/n')
95 tree_a.commit('init')88 tree_a.commit('init')
9689
97 with tree_a.lock_read():
98 root_id = tree_a.get_root_id()
99
100 tree_b = tree_a.controldir.sprout('B').open_workingtree()90 tree_b = tree_a.controldir.sprout('B').open_workingtree()
101 self.build_tree(['B/xyz/'])91 self.build_tree(['B/xyz/'])
102 tree_b.add(['xyz'])92 tree_b.add(['xyz'])
103 xyz_id = tree_b.path2id('xyz')
104 tree_b.rename_one('a/m', 'xyz/m')93 tree_b.rename_one('a/m', 'xyz/m')
105 osutils.rmtree('B/a')94 osutils.rmtree('B/a')
106 tree_b.commit('delete in B')95 tree_b.commit('delete in B')
10796
108 paths = [(path, ie.file_id)97 self.assertThat(
109 for path, ie in tree_b.iter_entries_by_dir()]98 tree_b,
110 self.assertEqual([('', root_id),99 HasPathRelations(
111 ('xyz', xyz_id),100 tree_a, [('', ''), ('xyz/', None), ('xyz/m', 'a/m')]))
112 ('xyz/m', m_id),
113 ], paths)
114101
115 self.build_tree_contents([('A/a/n', 'new contents for n\n')])102 self.build_tree_contents([('A/a/n', 'new contents for n\n')])
116 tree_a.commit('change n in A')103 tree_a.commit('change n in A')
@@ -119,14 +106,13 @@
119 # (in A) and removed (in B), so 'a' needs to be restored.106 # (in A) and removed (in B), so 'a' needs to be restored.
120 num_conflicts = tree_b.merge_from_branch(tree_a.branch)107 num_conflicts = tree_b.merge_from_branch(tree_a.branch)
121 self.assertEqual(3, num_conflicts)108 self.assertEqual(3, num_conflicts)
122 paths = [(path, ie.file_id)109
123 for path, ie in tree_b.iter_entries_by_dir()]110 self.assertThat(
124 self.assertEqual([('', root_id),111 tree_b, HasPathRelations(
125 ('a', a_id),112 tree_a,
126 ('xyz', xyz_id),113 [('', ''), ('a/', 'a/'), ('xyz/', None),
127 ('a/n.OTHER', n_id),114 ('a/n.OTHER', 'a/n'), ('xyz/m', 'a/m')]))
128 ('xyz/m', m_id),115
129 ], paths)
130 osutils.rmtree('B/a')116 osutils.rmtree('B/a')
131 try:117 try:
132 # bzr resolve --all118 # bzr resolve --all
@@ -136,12 +122,11 @@
136 # effect.122 # effect.
137 pass123 pass
138 tree_b.commit('autoremove a, without touching xyz/m')124 tree_b.commit('autoremove a, without touching xyz/m')
139 paths = [(path, ie.file_id)125
140 for path, ie in tree_b.iter_entries_by_dir()]126 self.assertThat(
141 self.assertEqual([('', root_id),127 tree_b, HasPathRelations(
142 ('xyz', xyz_id),128 tree_a,
143 ('xyz/m', m_id),129 [('', ''), ('xyz/', None), ('xyz/m', 'a/m')]))
144 ], paths)
145130
146 def test_commit_exclude_pending_merge_fails(self):131 def test_commit_exclude_pending_merge_fails(self):
147 """Excludes are a form of partial commit."""132 """Excludes are a form of partial commit."""
@@ -173,15 +158,13 @@
173 tree.lock_read()158 tree.lock_read()
174 self.addCleanup(tree.unlock)159 self.addCleanup(tree.unlock)
175 changes = list(tree.iter_changes(tree.basis_tree()))160 changes = list(tree.iter_changes(tree.basis_tree()))
176 self.assertEqual(2, len(changes))161 self.assertEqual([(None, 'b'), (None, 'c')], [c[1] for c in changes])
177 self.assertEqual((None, 'b'), changes[0][1])
178 self.assertEqual((None, 'c'), changes[1][1])
179162
180 def test_commit_exclude_subtree_of_selected(self):163 def test_commit_exclude_subtree_of_selected(self):
181 tree = self.make_branch_and_tree('.')164 tree = self.make_branch_and_tree('.')
182 self.build_tree(['a/', 'a/b'])165 self.build_tree(['a/', 'a/b', 'a/c'])
183 tree.smart_add(['.'])166 tree.smart_add(['.'])
184 tree.commit('test', specific_files=['a'], exclude=['a/b'])167 tree.commit('test', specific_files=['a', 'a/c'], exclude=['a/b'])
185 # If a/b was excluded it will still be 'added' in status.168 # If a/b was excluded it will still be 'added' in status.
186 tree.lock_read()169 tree.lock_read()
187 self.addCleanup(tree.unlock)170 self.addCleanup(tree.unlock)
188171
=== modified file 'breezy/tests/per_workingtree/test_unversion.py'
--- breezy/tests/per_workingtree/test_unversion.py 2018-03-10 14:20:40 +0000
+++ breezy/tests/per_workingtree/test_unversion.py 2018-03-24 13:52:34 +0000
@@ -19,6 +19,7 @@
19from breezy import (19from breezy import (
20 errors,20 errors,
21 )21 )
22from breezy.tests.matchers import HasPathRelations
22from breezy.tests.per_workingtree import TestCaseWithWorkingTree23from breezy.tests.per_workingtree import TestCaseWithWorkingTree
2324
2425
@@ -44,12 +45,19 @@
44 tree = self.make_branch_and_tree('.')45 tree = self.make_branch_and_tree('.')
45 self.build_tree(['del/', 'del/sub/', 'del/sub/b'])46 self.build_tree(['del/', 'del/sub/', 'del/sub/b'])
46 tree.add(['del', 'del/sub', 'del/sub/b'])47 tree.add(['del', 'del/sub', 'del/sub/b'])
47 b_id = tree.path2id('del/sub/b')48 revid = tree.commit('setup')
48 tree.commit('setup')49 revtree = tree.branch.repository.revision_tree(revid)
49 tree.rename_one('del/sub', 'sub')50 tree.rename_one('del/sub', 'sub')
50 self.assertEqual('sub/b', tree.id2path(b_id))51 self.assertThat(
51 tree.unversion(['del', 'sub/b'])52 tree,
52 self.assertRaises(errors.NoSuchId, tree.id2path, b_id)53 HasPathRelations(revtree, [('', ''), ('del/', 'del/'), ('sub/', 'del/sub/'), ('sub/b', 'del/sub/b')]))
54 if tree.has_versioned_directories():
55 tree.unversion(['del', 'sub/b'])
56 else:
57 tree.unversion(['sub/b'])
58 self.assertThat(
59 tree,
60 HasPathRelations(revtree, [('', ''), ('sub/', 'del/sub/')]))
5361
54 def test_unversion_several_files(self):62 def test_unversion_several_files(self):
55 """After unversioning several files, they should not be versioned."""63 """After unversioning several files, they should not be versioned."""
@@ -119,72 +127,47 @@
119 self.build_tree(['a/dir/', 'a/dir/f1', 'a/dir/f2', 'a/dir/f3',127 self.build_tree(['a/dir/', 'a/dir/f1', 'a/dir/f2', 'a/dir/f3',
120 'a/dir2/'])128 'a/dir2/'])
121 tree.add(['dir', 'dir/f1', 'dir/f2', 'dir/f3', 'dir2'])129 tree.add(['dir', 'dir/f1', 'dir/f2', 'dir/f3', 'dir2'])
122 dir_id = tree.path2id('dir')
123 dir2_id = tree.path2id('dir2')
124 f1_id = tree.path2id('dir/f1')
125 f2_id = tree.path2id('dir/f2')
126 f3_id = tree.path2id('dir/f3')
127 rev_id1 = tree.commit('init')130 rev_id1 = tree.commit('init')
131 revtree = tree.branch.repository.revision_tree(rev_id1)
128 # Start off by renaming entries, and then unversion a bunch of entries132 # Start off by renaming entries, and then unversion a bunch of entries
129 # https://bugs.launchpad.net/bzr/+bug/114615133 # https://bugs.launchpad.net/bzr/+bug/114615
130 tree.rename_one('dir/f1', 'dir/a')134 tree.rename_one('dir/f1', 'dir/a')
131 tree.rename_one('dir/f2', 'dir/z')135 tree.rename_one('dir/f2', 'dir/z')
132 tree.move(['dir/f3'], 'dir2')136 tree.move(['dir/f3'], 'dir2')
133137
134 tree.lock_read()138 self.assertThat(
135 try:139 tree, HasPathRelations(
136 root_id = tree.get_root_id()140 revtree,
137 paths = [(path, ie.file_id)141 [('', ''), ('dir/', 'dir/'), ('dir2/', 'dir2/'),
138 for path, ie in tree.iter_entries_by_dir()]142 ('dir/a', 'dir/f1'), ('dir/z', 'dir/f2'),
139 finally:143 ('dir2/f3', 'dir/f3')]))
140 tree.unlock()
141 self.assertEqual([('', root_id),
142 ('dir', dir_id),
143 ('dir2', dir2_id),
144 ('dir/a', f1_id),
145 ('dir/z', f2_id),
146 ('dir2/f3', f3_id),
147 ], paths)
148144
149 tree.unversion({'dir'})145 tree.unversion({'dir'})
150 paths = [(path, ie.file_id)146 self.assertThat(
151 for path, ie in tree.iter_entries_by_dir()]147 tree,
152148 HasPathRelations(
153 self.assertEqual([('', root_id),149 revtree,
154 ('dir2', dir2_id),150 [('', ''), ('dir2/', 'dir2/'), ('dir2/f3', 'dir/f3')]))
155 ('dir2/f3', f3_id),
156 ], paths)
157151
158 def test_unversion_after_conflicted_merge(self):152 def test_unversion_after_conflicted_merge(self):
159 # Test for bug #114615153 # Test for bug #114615
160 tree_a = self.make_branch_and_tree('A')154 tree_a = self.make_branch_and_tree('A')
161 self.build_tree(['A/a/', 'A/a/m', 'A/a/n'])155 self.build_tree(['A/a/', 'A/a/m', 'A/a/n'])
162 tree_a.add(['a', 'a/m', 'a/n'])156 tree_a.add(['a', 'a/m', 'a/n'])
163 a_id = tree_a.path2id('a')
164 m_id = tree_a.path2id('a/m')
165 n_id = tree_a.path2id('a/n')
166 tree_a.commit('init')157 tree_a.commit('init')
167158
168 tree_a.lock_read()
169 try:
170 root_id = tree_a.get_root_id()
171 finally:
172 tree_a.unlock()
173
174 tree_b = tree_a.controldir.sprout('B').open_workingtree()159 tree_b = tree_a.controldir.sprout('B').open_workingtree()
175 self.build_tree(['B/xyz/'])160 self.build_tree(['B/xyz/'])
176 tree_b.add(['xyz'])161 tree_b.add(['xyz'])
177 xyz_id = tree_b.path2id('xyz')
178 tree_b.rename_one('a/m', 'xyz/m')162 tree_b.rename_one('a/m', 'xyz/m')
179 tree_b.unversion(['a'])163 tree_b.unversion(['a'])
180 tree_b.commit('delete in B')164 tree_b.commit('delete in B')
181165
182 paths = [(path, ie.file_id)166 self.assertThat(
183 for path, ie in tree_b.iter_entries_by_dir()]167 tree_b,
184 self.assertEqual([('', root_id),168 HasPathRelations(
185 ('xyz', xyz_id),169 tree_a,
186 ('xyz/m', m_id),170 [('', ''), ('xyz/', None), ('xyz/m', 'a/m')]))
187 ], paths)
188171
189 self.build_tree_contents([('A/a/n', 'new contents for n\n')])172 self.build_tree_contents([('A/a/n', 'new contents for n\n')])
190 tree_a.commit('change n in A')173 tree_a.commit('change n in A')
@@ -194,18 +177,17 @@
194 # because 'a' is still an existing directory177 # because 'a' is still an existing directory
195 num_conflicts = tree_b.merge_from_branch(tree_a.branch)178 num_conflicts = tree_b.merge_from_branch(tree_a.branch)
196 self.assertEqual(4, num_conflicts)179 self.assertEqual(4, num_conflicts)
197 paths = [(path, ie.file_id)180
198 for path, ie in tree_b.iter_entries_by_dir()]181 self.assertThat(
199 self.assertEqual([('', root_id),182 tree_b,
200 ('a', a_id),183 HasPathRelations(
201 ('xyz', xyz_id),184 tree_a,
202 ('a/n.OTHER', n_id),185 [('', ''), ('a/', 'a/'), ('xyz/', None),
203 ('xyz/m', m_id),186 ('a/n.OTHER', 'a/n'), ('xyz/m', 'a/m')]))
204 ], paths)187
205 tree_b.unversion(['a'])188 tree_b.unversion(['a'])
206 paths = [(path, ie.file_id)189 self.assertThat(
207 for path, ie in tree_b.iter_entries_by_dir()]190 tree_b,
208 self.assertEqual([('', root_id),191 HasPathRelations(
209 ('xyz', xyz_id),192 tree_a,
210 ('xyz/m', m_id),193 [('', ''), ('xyz/', None), ('xyz/m', 'a/m')]))
211 ], paths)

Subscribers

People subscribed via source and target branches