Merge lp:~jelmer/brz/detect-local-wt into lp:brz
- detect-local-wt
- Merge into trunk
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/detect-local-wt |
Merge into: | lp:brz |
Diff against target: |
369 lines (+94/-90) 8 files modified
breezy/bzr/bzrdir.py (+18/-17) breezy/bzr/workingtree.py (+28/-1) breezy/controldir.py (+24/-3) breezy/git/dir.py (+8/-5) breezy/git/workingtree.py (+1/-2) breezy/tests/test_controldir.py (+1/-1) breezy/tests/test_workingtree.py (+0/-12) breezy/workingtree.py (+14/-49) |
To merge this branch: | bzr merge lp:~jelmer/brz/detect-local-wt |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jelmer Vernooij | Approve | ||
Review via email: mp+368240@code.launchpad.net |
Commit message
Remove WorkingTree.
Description of the change
Remove unused WorkingTree.
Only detect .bzr subtrees in Bzr workingtrees and .git subtrees in Git workingtrees.
To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) : | # |
review:
Approve
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote : | # |
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote : | # |
Running landing tests failed
https:/
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'breezy/bzr/bzrdir.py' |
2 | --- breezy/bzr/bzrdir.py 2018-11-18 19:48:57 +0000 |
3 | +++ breezy/bzr/bzrdir.py 2019-06-03 21:45:42 +0000 |
4 | @@ -662,23 +662,6 @@ |
5 | def control_transport(self): |
6 | return self.transport |
7 | |
8 | - def is_control_filename(self, filename): |
9 | - """True if filename is the name of a path which is reserved for bzrdir's. |
10 | - |
11 | - :param filename: A filename within the root transport of this bzrdir. |
12 | - |
13 | - This is true IF and ONLY IF the filename is part of the namespace |
14 | - reserved for bzr control dirs. Currently this is the '.bzr' directory |
15 | - in the root of the root_transport. |
16 | - """ |
17 | - # this might be better on the BzrDirFormat class because it refers to |
18 | - # all the possible bzrdir disk formats. |
19 | - # This method is tested via the workingtree is_control_filename tests- |
20 | - # it was extracted from WorkingTree.is_control_filename. If the |
21 | - # method's contract is extended beyond the current trivial |
22 | - # implementation, please add new tests for it to the appropriate place. |
23 | - return filename == '.bzr' or filename.startswith('.bzr/') |
24 | - |
25 | def _cloning_metadir(self): |
26 | """Produce a metadir suitable for cloning with. |
27 | |
28 | @@ -1469,6 +1452,24 @@ |
29 | BzrFormat.check_support_status(self, allow_unsupported=allow_unsupported, |
30 | recommend_upgrade=recommend_upgrade, basedir=basedir) |
31 | |
32 | + @classmethod |
33 | + def is_control_filename(klass, filename): |
34 | + """True if filename is the name of a path which is reserved for bzrdir's. |
35 | + |
36 | + :param filename: A filename within the root transport of this bzrdir. |
37 | + |
38 | + This is true IF and ONLY IF the filename is part of the namespace |
39 | + reserved for bzr control dirs. Currently this is the '.bzr' directory |
40 | + in the root of the root_transport. |
41 | + """ |
42 | + # this might be better on the BzrDirFormat class because it refers to |
43 | + # all the possible bzrdir disk formats. |
44 | + # This method is tested via the workingtree is_control_filename tests- |
45 | + # it was extracted from WorkingTree.is_control_filename. If the |
46 | + # method's contract is extended beyond the current trivial |
47 | + # implementation, please add new tests for it to the appropriate place. |
48 | + return filename == '.bzr' or filename.startswith('.bzr/') |
49 | + |
50 | |
51 | class BzrDirMetaFormat1(BzrDirFormat): |
52 | """Bzr meta control format 1 |
53 | |
54 | === modified file 'breezy/bzr/workingtree.py' |
55 | --- breezy/bzr/workingtree.py 2018-12-11 00:51:46 +0000 |
56 | +++ breezy/bzr/workingtree.py 2019-06-03 21:45:42 +0000 |
57 | @@ -126,6 +126,7 @@ |
58 | |
59 | self._control_files = _control_files |
60 | self._detect_case_handling() |
61 | + self._setup_directory_is_tree_reference() |
62 | |
63 | if _inventory is None: |
64 | # This will be acquired on lock_read() or lock_write() |
65 | @@ -160,7 +161,33 @@ |
66 | else: |
67 | self.case_sensitive = False |
68 | |
69 | - self._setup_directory_is_tree_reference() |
70 | + def _setup_directory_is_tree_reference(self): |
71 | + if self._branch.repository._format.supports_tree_reference: |
72 | + self._directory_is_tree_reference = \ |
73 | + self._directory_may_be_tree_reference |
74 | + else: |
75 | + self._directory_is_tree_reference = \ |
76 | + self._directory_is_never_tree_reference |
77 | + |
78 | + def _directory_is_never_tree_reference(self, relpath): |
79 | + return False |
80 | + |
81 | + def _directory_may_be_tree_reference(self, relpath): |
82 | + # as a special case, if a directory contains control files then |
83 | + # it's a tree reference, except that the root of the tree is not |
84 | + return relpath and osutils.isdir(self.abspath(relpath) + u"/.bzr") |
85 | + # TODO: We could ask all the control formats whether they |
86 | + # recognize this directory, but at the moment there's no cheap api |
87 | + # to do that. Since we probably can only nest bzr checkouts and |
88 | + # they always use this name it's ok for now. -- mbp 20060306 |
89 | + # |
90 | + # FIXME: There is an unhandled case here of a subdirectory |
91 | + # containing .bzr but not a branch; that will probably blow up |
92 | + # when you try to commit it. It might happen if there is a |
93 | + # checkout in a subdirectory. This can be avoided by not adding |
94 | + # it. mbp 20070306 |
95 | + |
96 | + |
97 | |
98 | def _serialize(self, inventory, out_file): |
99 | xml5.serializer_v5.write_inventory( |
100 | |
101 | === modified file 'breezy/controldir.py' |
102 | --- breezy/controldir.py 2018-11-12 01:41:38 +0000 |
103 | +++ breezy/controldir.py 2019-06-03 21:45:42 +0000 |
104 | @@ -152,7 +152,7 @@ |
105 | this in the future - for instance to make bzr talk with svn working |
106 | trees. |
107 | """ |
108 | - raise NotImplementedError(self.is_control_filename) |
109 | + return self._format.is_control_filename(filename) |
110 | |
111 | def needs_format_conversion(self, format=None): |
112 | """Return true if this controldir needs convert_format run on it. |
113 | @@ -1246,6 +1246,22 @@ |
114 | """ |
115 | raise NotImplementedError(self.supports_transport) |
116 | |
117 | + @classmethod |
118 | + def is_control_filename(klass, filename): |
119 | + """True if filename is the name of a path which is reserved for |
120 | + controldirs. |
121 | + |
122 | + :param filename: A filename within the root transport of this |
123 | + controldir. |
124 | + |
125 | + This is true IF and ONLY IF the filename is part of the namespace reserved |
126 | + for bzr control dirs. Currently this is the '.bzr' directory in the root |
127 | + of the root_transport. it is expected that plugins will need to extend |
128 | + this in the future - for instance to make bzr talk with svn working |
129 | + trees. |
130 | + """ |
131 | + raise NotImplementedError(self.is_control_filename) |
132 | + |
133 | |
134 | class Prober(object): |
135 | """Abstract class that can be used to detect a particular kind of |
136 | @@ -1461,8 +1477,13 @@ |
137 | |
138 | def is_control_filename(filename): |
139 | """Check if filename is used for control directories.""" |
140 | - # TODO(jelmer): Allow registration by other VCSes |
141 | - return filename == '.bzr' |
142 | + # TODO(jelmer): Instead, have a function that returns all control |
143 | + # filenames. |
144 | + for key, format in format_registry.items(): |
145 | + if format().is_control_filename(filename): |
146 | + return True |
147 | + else: |
148 | + return False |
149 | |
150 | |
151 | class RepositoryAcquisitionPolicy(object): |
152 | |
153 | === modified file 'breezy/git/dir.py' |
154 | --- breezy/git/dir.py 2019-03-18 04:31:21 +0000 |
155 | +++ breezy/git/dir.py 2019-06-03 21:45:42 +0000 |
156 | @@ -401,6 +401,11 @@ |
157 | raise brz_errors.NotBranchError(path=transport.base) |
158 | return external_url.startswith("file:") |
159 | |
160 | + def is_control_filename(self, filename): |
161 | + return (filename == '.git' |
162 | + or filename.startswith('.git/') |
163 | + or filename.startswith('.git\\')) |
164 | + |
165 | |
166 | class BareLocalGitControlDirFormat(LocalGitControlDirFormat): |
167 | |
168 | @@ -410,6 +415,9 @@ |
169 | def get_format_description(self): |
170 | return "Local Git Repository (bare)" |
171 | |
172 | + def is_control_filename(self, filename): |
173 | + return False |
174 | + |
175 | |
176 | class LocalGitDir(GitDir): |
177 | """An adapter to the '.git' dir used by git.""" |
178 | @@ -443,11 +451,6 @@ |
179 | self.transport = transport.clone('.git') |
180 | self._mode_check_done = None |
181 | |
182 | - def is_control_filename(self, filename): |
183 | - return (filename == '.git' |
184 | - or filename.startswith('.git/') |
185 | - or filename.startswith('.git\\')) |
186 | - |
187 | def _get_symref(self, ref): |
188 | ref_chain, unused_sha = self._git.refs.follow(ref) |
189 | if len(ref_chain) == 1: |
190 | |
191 | === modified file 'breezy/git/workingtree.py' |
192 | --- breezy/git/workingtree.py 2019-02-05 04:00:02 +0000 |
193 | +++ breezy/git/workingtree.py 2019-06-03 21:45:42 +0000 |
194 | @@ -568,8 +568,7 @@ |
195 | except OSError as e: |
196 | if e.errno == errno.ENOENT: |
197 | raise errors.NoSuchFile(fullpath) |
198 | - if (kind == 'directory' and f != '' and |
199 | - os.path.exists(os.path.join(fullpath, '.git'))): |
200 | + if f != '' and self._directory_is_tree_reference(f): |
201 | kind = 'tree-reference' |
202 | kinds[pos] = kind |
203 | |
204 | |
205 | === modified file 'breezy/tests/test_controldir.py' |
206 | --- breezy/tests/test_controldir.py 2018-11-11 04:08:32 +0000 |
207 | +++ breezy/tests/test_controldir.py 2019-06-03 21:45:42 +0000 |
208 | @@ -241,7 +241,7 @@ |
209 | |
210 | def test_is_bzrdir(self): |
211 | self.assertTrue(controldir.is_control_filename('.bzr')) |
212 | + self.assertTrue(controldir.is_control_filename('.git')) |
213 | |
214 | def test_is_not_bzrdir(self): |
215 | - self.assertFalse(controldir.is_control_filename('.git')) |
216 | self.assertFalse(controldir.is_control_filename('bla')) |
217 | |
218 | === modified file 'breezy/tests/test_workingtree.py' |
219 | --- breezy/tests/test_workingtree.py 2018-11-12 01:41:38 +0000 |
220 | +++ breezy/tests/test_workingtree.py 2019-06-03 21:45:42 +0000 |
221 | @@ -452,18 +452,6 @@ |
222 | tree.auto_resolve() |
223 | |
224 | |
225 | -class TestFindTrees(TestCaseWithTransport): |
226 | - |
227 | - def test_find_trees(self): |
228 | - self.make_branch_and_tree('foo') |
229 | - self.make_branch_and_tree('foo/bar') |
230 | - # Sticking a tree inside a control dir is heinous, so let's skip it |
231 | - self.make_branch_and_tree('foo/.bzr/baz') |
232 | - self.make_branch('qux') |
233 | - trees = workingtree.WorkingTree.find_trees('.') |
234 | - self.assertEqual(2, len(list(trees))) |
235 | - |
236 | - |
237 | class TestStoredUncommitted(TestCaseWithTransport): |
238 | |
239 | def store_uncommitted(self): |
240 | |
241 | === modified file 'breezy/workingtree.py' |
242 | --- breezy/workingtree.py 2019-02-14 22:18:59 +0000 |
243 | +++ breezy/workingtree.py 2019-06-03 21:45:42 +0000 |
244 | @@ -43,7 +43,6 @@ |
245 | |
246 | from breezy import ( |
247 | conflicts as _mod_conflicts, |
248 | - controldir, |
249 | errors, |
250 | filters as _mod_filters, |
251 | merge, |
252 | @@ -57,6 +56,13 @@ |
253 | ) |
254 | """) |
255 | |
256 | +from .controldir import ( |
257 | + ControlComponent, |
258 | + ControlComponentFormatRegistry, |
259 | + ControlComponentFormat, |
260 | + ControlDir, |
261 | + ControlDirFormat, |
262 | + ) |
263 | from . import ( |
264 | osutils, |
265 | ) |
266 | @@ -78,7 +84,7 @@ |
267 | _fmt = "This format does not support shelving changes." |
268 | |
269 | |
270 | -class WorkingTree(mutabletree.MutableTree, controldir.ControlComponent): |
271 | +class WorkingTree(mutabletree.MutableTree, ControlComponent): |
272 | """Working copy tree. |
273 | |
274 | :ivar basedir: The root of the tree on disk. This is a unicode path object |
275 | @@ -198,7 +204,7 @@ |
276 | """ |
277 | if path is None: |
278 | path = osutils.getcwd() |
279 | - control = controldir.ControlDir.open(path, _unsupported=_unsupported) |
280 | + control = ControlDir.open(path, _unsupported=_unsupported) |
281 | return control.open_workingtree(unsupported=_unsupported) |
282 | |
283 | @staticmethod |
284 | @@ -216,7 +222,7 @@ |
285 | """ |
286 | if path is None: |
287 | path = osutils.getcwd() |
288 | - control, relpath = controldir.ControlDir.open_containing(path) |
289 | + control, relpath = ControlDir.open_containing(path) |
290 | return control.open_workingtree(), relpath |
291 | |
292 | @staticmethod |
293 | @@ -294,24 +300,6 @@ |
294 | """ |
295 | return WorkingTree.open(path, _unsupported=True) |
296 | |
297 | - @staticmethod |
298 | - def find_trees(location): |
299 | - def list_current(transport): |
300 | - return [d for d in transport.list_dir('') |
301 | - if not controldir.is_control_filename(d)] |
302 | - |
303 | - def evaluate(controldir): |
304 | - try: |
305 | - tree = controldir.open_workingtree() |
306 | - except errors.NoWorkingTree: |
307 | - return True, None |
308 | - else: |
309 | - return True, tree |
310 | - t = transport.get_transport(location) |
311 | - iterator = controldir.ControlDir.find_controldirs(t, evaluate=evaluate, |
312 | - list_current=list_current) |
313 | - return [tr for tr in iterator if tr is not None] |
314 | - |
315 | def __repr__(self): |
316 | return "<%s of %s>" % (self.__class__.__name__, |
317 | getattr(self, 'basedir', None)) |
318 | @@ -729,31 +717,8 @@ |
319 | def subsume(self, other_tree): |
320 | raise NotImplementedError(self.subsume) |
321 | |
322 | - def _setup_directory_is_tree_reference(self): |
323 | - if self._branch.repository._format.supports_tree_reference: |
324 | - self._directory_is_tree_reference = \ |
325 | - self._directory_may_be_tree_reference |
326 | - else: |
327 | - self._directory_is_tree_reference = \ |
328 | - self._directory_is_never_tree_reference |
329 | - |
330 | - def _directory_is_never_tree_reference(self, relpath): |
331 | - return False |
332 | - |
333 | - def _directory_may_be_tree_reference(self, relpath): |
334 | - # as a special case, if a directory contains control files then |
335 | - # it's a tree reference, except that the root of the tree is not |
336 | - return relpath and osutils.isdir(self.abspath(relpath) + u"/.bzr") |
337 | - # TODO: We could ask all the control formats whether they |
338 | - # recognize this directory, but at the moment there's no cheap api |
339 | - # to do that. Since we probably can only nest bzr checkouts and |
340 | - # they always use this name it's ok for now. -- mbp 20060306 |
341 | - # |
342 | - # FIXME: There is an unhandled case here of a subdirectory |
343 | - # containing .bzr but not a branch; that will probably blow up |
344 | - # when you try to commit it. It might happen if there is a |
345 | - # checkout in a subdirectory. This can be avoided by not adding |
346 | - # it. mbp 20070306 |
347 | + def _directory_is_tree_reference(self, relpath): |
348 | + raise NotImplementedError(self._directory_is_tree_reference) |
349 | |
350 | def extract(self, path, format=None): |
351 | """Extract a subtree from this tree. |
352 | @@ -1373,7 +1338,7 @@ |
353 | return next(self.get_canonical_paths([path])) |
354 | |
355 | |
356 | -class WorkingTreeFormatRegistry(controldir.ControlComponentFormatRegistry): |
357 | +class WorkingTreeFormatRegistry(ControlComponentFormatRegistry): |
358 | """Registry for working tree formats.""" |
359 | |
360 | def __init__(self, other_registry=None): |
361 | @@ -1402,7 +1367,7 @@ |
362 | format_registry = WorkingTreeFormatRegistry() |
363 | |
364 | |
365 | -class WorkingTreeFormat(controldir.ControlComponentFormat): |
366 | +class WorkingTreeFormat(ControlComponentFormat): |
367 | """An encapsulation of the initialization and open routines for a format. |
368 | |
369 | Formats provide three things: |
Running landing tests failed /ci.breezy- vcs.org/ job/brz/ job/brz- land/321/
https:/