Merge lp:~jelmer/brz/detect-local-wt 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/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
Reviewer Review Type Date Requested Status
Jelmer Vernooij Approve
Review via email: mp+368240@code.launchpad.net

Commit message

Remove WorkingTree.find_trees, simplify detection of subtrees.

Description of the change

Remove unused WorkingTree.find_trees method.

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 :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'breezy/bzr/bzrdir.py'
--- breezy/bzr/bzrdir.py 2018-11-18 19:48:57 +0000
+++ breezy/bzr/bzrdir.py 2019-06-03 21:45:42 +0000
@@ -662,23 +662,6 @@
662 def control_transport(self):662 def control_transport(self):
663 return self.transport663 return self.transport
664664
665 def is_control_filename(self, filename):
666 """True if filename is the name of a path which is reserved for bzrdir's.
667
668 :param filename: A filename within the root transport of this bzrdir.
669
670 This is true IF and ONLY IF the filename is part of the namespace
671 reserved for bzr control dirs. Currently this is the '.bzr' directory
672 in the root of the root_transport.
673 """
674 # this might be better on the BzrDirFormat class because it refers to
675 # all the possible bzrdir disk formats.
676 # This method is tested via the workingtree is_control_filename tests-
677 # it was extracted from WorkingTree.is_control_filename. If the
678 # method's contract is extended beyond the current trivial
679 # implementation, please add new tests for it to the appropriate place.
680 return filename == '.bzr' or filename.startswith('.bzr/')
681
682 def _cloning_metadir(self):665 def _cloning_metadir(self):
683 """Produce a metadir suitable for cloning with.666 """Produce a metadir suitable for cloning with.
684667
@@ -1469,6 +1452,24 @@
1469 BzrFormat.check_support_status(self, allow_unsupported=allow_unsupported,1452 BzrFormat.check_support_status(self, allow_unsupported=allow_unsupported,
1470 recommend_upgrade=recommend_upgrade, basedir=basedir)1453 recommend_upgrade=recommend_upgrade, basedir=basedir)
14711454
1455 @classmethod
1456 def is_control_filename(klass, filename):
1457 """True if filename is the name of a path which is reserved for bzrdir's.
1458
1459 :param filename: A filename within the root transport of this bzrdir.
1460
1461 This is true IF and ONLY IF the filename is part of the namespace
1462 reserved for bzr control dirs. Currently this is the '.bzr' directory
1463 in the root of the root_transport.
1464 """
1465 # this might be better on the BzrDirFormat class because it refers to
1466 # all the possible bzrdir disk formats.
1467 # This method is tested via the workingtree is_control_filename tests-
1468 # it was extracted from WorkingTree.is_control_filename. If the
1469 # method's contract is extended beyond the current trivial
1470 # implementation, please add new tests for it to the appropriate place.
1471 return filename == '.bzr' or filename.startswith('.bzr/')
1472
14721473
1473class BzrDirMetaFormat1(BzrDirFormat):1474class BzrDirMetaFormat1(BzrDirFormat):
1474 """Bzr meta control format 11475 """Bzr meta control format 1
14751476
=== modified file 'breezy/bzr/workingtree.py'
--- breezy/bzr/workingtree.py 2018-12-11 00:51:46 +0000
+++ breezy/bzr/workingtree.py 2019-06-03 21:45:42 +0000
@@ -126,6 +126,7 @@
126126
127 self._control_files = _control_files127 self._control_files = _control_files
128 self._detect_case_handling()128 self._detect_case_handling()
129 self._setup_directory_is_tree_reference()
129130
130 if _inventory is None:131 if _inventory is None:
131 # This will be acquired on lock_read() or lock_write()132 # This will be acquired on lock_read() or lock_write()
@@ -160,7 +161,33 @@
160 else:161 else:
161 self.case_sensitive = False162 self.case_sensitive = False
162163
163 self._setup_directory_is_tree_reference()164 def _setup_directory_is_tree_reference(self):
165 if self._branch.repository._format.supports_tree_reference:
166 self._directory_is_tree_reference = \
167 self._directory_may_be_tree_reference
168 else:
169 self._directory_is_tree_reference = \
170 self._directory_is_never_tree_reference
171
172 def _directory_is_never_tree_reference(self, relpath):
173 return False
174
175 def _directory_may_be_tree_reference(self, relpath):
176 # as a special case, if a directory contains control files then
177 # it's a tree reference, except that the root of the tree is not
178 return relpath and osutils.isdir(self.abspath(relpath) + u"/.bzr")
179 # TODO: We could ask all the control formats whether they
180 # recognize this directory, but at the moment there's no cheap api
181 # to do that. Since we probably can only nest bzr checkouts and
182 # they always use this name it's ok for now. -- mbp 20060306
183 #
184 # FIXME: There is an unhandled case here of a subdirectory
185 # containing .bzr but not a branch; that will probably blow up
186 # when you try to commit it. It might happen if there is a
187 # checkout in a subdirectory. This can be avoided by not adding
188 # it. mbp 20070306
189
190
164191
165 def _serialize(self, inventory, out_file):192 def _serialize(self, inventory, out_file):
166 xml5.serializer_v5.write_inventory(193 xml5.serializer_v5.write_inventory(
167194
=== modified file 'breezy/controldir.py'
--- breezy/controldir.py 2018-11-12 01:41:38 +0000
+++ breezy/controldir.py 2019-06-03 21:45:42 +0000
@@ -152,7 +152,7 @@
152 this in the future - for instance to make bzr talk with svn working152 this in the future - for instance to make bzr talk with svn working
153 trees.153 trees.
154 """154 """
155 raise NotImplementedError(self.is_control_filename)155 return self._format.is_control_filename(filename)
156156
157 def needs_format_conversion(self, format=None):157 def needs_format_conversion(self, format=None):
158 """Return true if this controldir needs convert_format run on it.158 """Return true if this controldir needs convert_format run on it.
@@ -1246,6 +1246,22 @@
1246 """1246 """
1247 raise NotImplementedError(self.supports_transport)1247 raise NotImplementedError(self.supports_transport)
12481248
1249 @classmethod
1250 def is_control_filename(klass, filename):
1251 """True if filename is the name of a path which is reserved for
1252 controldirs.
1253
1254 :param filename: A filename within the root transport of this
1255 controldir.
1256
1257 This is true IF and ONLY IF the filename is part of the namespace reserved
1258 for bzr control dirs. Currently this is the '.bzr' directory in the root
1259 of the root_transport. it is expected that plugins will need to extend
1260 this in the future - for instance to make bzr talk with svn working
1261 trees.
1262 """
1263 raise NotImplementedError(self.is_control_filename)
1264
12491265
1250class Prober(object):1266class Prober(object):
1251 """Abstract class that can be used to detect a particular kind of1267 """Abstract class that can be used to detect a particular kind of
@@ -1461,8 +1477,13 @@
14611477
1462def is_control_filename(filename):1478def is_control_filename(filename):
1463 """Check if filename is used for control directories."""1479 """Check if filename is used for control directories."""
1464 # TODO(jelmer): Allow registration by other VCSes1480 # TODO(jelmer): Instead, have a function that returns all control
1465 return filename == '.bzr'1481 # filenames.
1482 for key, format in format_registry.items():
1483 if format().is_control_filename(filename):
1484 return True
1485 else:
1486 return False
14661487
14671488
1468class RepositoryAcquisitionPolicy(object):1489class RepositoryAcquisitionPolicy(object):
14691490
=== modified file 'breezy/git/dir.py'
--- breezy/git/dir.py 2019-03-18 04:31:21 +0000
+++ breezy/git/dir.py 2019-06-03 21:45:42 +0000
@@ -401,6 +401,11 @@
401 raise brz_errors.NotBranchError(path=transport.base)401 raise brz_errors.NotBranchError(path=transport.base)
402 return external_url.startswith("file:")402 return external_url.startswith("file:")
403403
404 def is_control_filename(self, filename):
405 return (filename == '.git'
406 or filename.startswith('.git/')
407 or filename.startswith('.git\\'))
408
404409
405class BareLocalGitControlDirFormat(LocalGitControlDirFormat):410class BareLocalGitControlDirFormat(LocalGitControlDirFormat):
406411
@@ -410,6 +415,9 @@
410 def get_format_description(self):415 def get_format_description(self):
411 return "Local Git Repository (bare)"416 return "Local Git Repository (bare)"
412417
418 def is_control_filename(self, filename):
419 return False
420
413421
414class LocalGitDir(GitDir):422class LocalGitDir(GitDir):
415 """An adapter to the '.git' dir used by git."""423 """An adapter to the '.git' dir used by git."""
@@ -443,11 +451,6 @@
443 self.transport = transport.clone('.git')451 self.transport = transport.clone('.git')
444 self._mode_check_done = None452 self._mode_check_done = None
445453
446 def is_control_filename(self, filename):
447 return (filename == '.git'
448 or filename.startswith('.git/')
449 or filename.startswith('.git\\'))
450
451 def _get_symref(self, ref):454 def _get_symref(self, ref):
452 ref_chain, unused_sha = self._git.refs.follow(ref)455 ref_chain, unused_sha = self._git.refs.follow(ref)
453 if len(ref_chain) == 1:456 if len(ref_chain) == 1:
454457
=== modified file 'breezy/git/workingtree.py'
--- breezy/git/workingtree.py 2019-02-05 04:00:02 +0000
+++ breezy/git/workingtree.py 2019-06-03 21:45:42 +0000
@@ -568,8 +568,7 @@
568 except OSError as e:568 except OSError as e:
569 if e.errno == errno.ENOENT:569 if e.errno == errno.ENOENT:
570 raise errors.NoSuchFile(fullpath)570 raise errors.NoSuchFile(fullpath)
571 if (kind == 'directory' and f != '' and571 if f != '' and self._directory_is_tree_reference(f):
572 os.path.exists(os.path.join(fullpath, '.git'))):
573 kind = 'tree-reference'572 kind = 'tree-reference'
574 kinds[pos] = kind573 kinds[pos] = kind
575574
576575
=== modified file 'breezy/tests/test_controldir.py'
--- breezy/tests/test_controldir.py 2018-11-11 04:08:32 +0000
+++ breezy/tests/test_controldir.py 2019-06-03 21:45:42 +0000
@@ -241,7 +241,7 @@
241241
242 def test_is_bzrdir(self):242 def test_is_bzrdir(self):
243 self.assertTrue(controldir.is_control_filename('.bzr'))243 self.assertTrue(controldir.is_control_filename('.bzr'))
244 self.assertTrue(controldir.is_control_filename('.git'))
244245
245 def test_is_not_bzrdir(self):246 def test_is_not_bzrdir(self):
246 self.assertFalse(controldir.is_control_filename('.git'))
247 self.assertFalse(controldir.is_control_filename('bla'))247 self.assertFalse(controldir.is_control_filename('bla'))
248248
=== modified file 'breezy/tests/test_workingtree.py'
--- breezy/tests/test_workingtree.py 2018-11-12 01:41:38 +0000
+++ breezy/tests/test_workingtree.py 2019-06-03 21:45:42 +0000
@@ -452,18 +452,6 @@
452 tree.auto_resolve()452 tree.auto_resolve()
453453
454454
455class TestFindTrees(TestCaseWithTransport):
456
457 def test_find_trees(self):
458 self.make_branch_and_tree('foo')
459 self.make_branch_and_tree('foo/bar')
460 # Sticking a tree inside a control dir is heinous, so let's skip it
461 self.make_branch_and_tree('foo/.bzr/baz')
462 self.make_branch('qux')
463 trees = workingtree.WorkingTree.find_trees('.')
464 self.assertEqual(2, len(list(trees)))
465
466
467class TestStoredUncommitted(TestCaseWithTransport):455class TestStoredUncommitted(TestCaseWithTransport):
468456
469 def store_uncommitted(self):457 def store_uncommitted(self):
470458
=== modified file 'breezy/workingtree.py'
--- breezy/workingtree.py 2019-02-14 22:18:59 +0000
+++ breezy/workingtree.py 2019-06-03 21:45:42 +0000
@@ -43,7 +43,6 @@
4343
44from breezy import (44from breezy import (
45 conflicts as _mod_conflicts,45 conflicts as _mod_conflicts,
46 controldir,
47 errors,46 errors,
48 filters as _mod_filters,47 filters as _mod_filters,
49 merge,48 merge,
@@ -57,6 +56,13 @@
57 )56 )
58""")57""")
5958
59from .controldir import (
60 ControlComponent,
61 ControlComponentFormatRegistry,
62 ControlComponentFormat,
63 ControlDir,
64 ControlDirFormat,
65 )
60from . import (66from . import (
61 osutils,67 osutils,
62 )68 )
@@ -78,7 +84,7 @@
78 _fmt = "This format does not support shelving changes."84 _fmt = "This format does not support shelving changes."
7985
8086
81class WorkingTree(mutabletree.MutableTree, controldir.ControlComponent):87class WorkingTree(mutabletree.MutableTree, ControlComponent):
82 """Working copy tree.88 """Working copy tree.
8389
84 :ivar basedir: The root of the tree on disk. This is a unicode path object90 :ivar basedir: The root of the tree on disk. This is a unicode path object
@@ -198,7 +204,7 @@
198 """204 """
199 if path is None:205 if path is None:
200 path = osutils.getcwd()206 path = osutils.getcwd()
201 control = controldir.ControlDir.open(path, _unsupported=_unsupported)207 control = ControlDir.open(path, _unsupported=_unsupported)
202 return control.open_workingtree(unsupported=_unsupported)208 return control.open_workingtree(unsupported=_unsupported)
203209
204 @staticmethod210 @staticmethod
@@ -216,7 +222,7 @@
216 """222 """
217 if path is None:223 if path is None:
218 path = osutils.getcwd()224 path = osutils.getcwd()
219 control, relpath = controldir.ControlDir.open_containing(path)225 control, relpath = ControlDir.open_containing(path)
220 return control.open_workingtree(), relpath226 return control.open_workingtree(), relpath
221227
222 @staticmethod228 @staticmethod
@@ -294,24 +300,6 @@
294 """300 """
295 return WorkingTree.open(path, _unsupported=True)301 return WorkingTree.open(path, _unsupported=True)
296302
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):303 def __repr__(self):
316 return "<%s of %s>" % (self.__class__.__name__,304 return "<%s of %s>" % (self.__class__.__name__,
317 getattr(self, 'basedir', None))305 getattr(self, 'basedir', None))
@@ -729,31 +717,8 @@
729 def subsume(self, other_tree):717 def subsume(self, other_tree):
730 raise NotImplementedError(self.subsume)718 raise NotImplementedError(self.subsume)
731719
732 def _setup_directory_is_tree_reference(self):720 def _directory_is_tree_reference(self, relpath):
733 if self._branch.repository._format.supports_tree_reference:721 raise NotImplementedError(self._directory_is_tree_reference)
734 self._directory_is_tree_reference = \
735 self._directory_may_be_tree_reference
736 else:
737 self._directory_is_tree_reference = \
738 self._directory_is_never_tree_reference
739
740 def _directory_is_never_tree_reference(self, relpath):
741 return False
742
743 def _directory_may_be_tree_reference(self, relpath):
744 # as a special case, if a directory contains control files then
745 # it's a tree reference, except that the root of the tree is not
746 return relpath and osutils.isdir(self.abspath(relpath) + u"/.bzr")
747 # TODO: We could ask all the control formats whether they
748 # recognize this directory, but at the moment there's no cheap api
749 # to do that. Since we probably can only nest bzr checkouts and
750 # they always use this name it's ok for now. -- mbp 20060306
751 #
752 # FIXME: There is an unhandled case here of a subdirectory
753 # containing .bzr but not a branch; that will probably blow up
754 # when you try to commit it. It might happen if there is a
755 # checkout in a subdirectory. This can be avoided by not adding
756 # it. mbp 20070306
757722
758 def extract(self, path, format=None):723 def extract(self, path, format=None):
759 """Extract a subtree from this tree.724 """Extract a subtree from this tree.
@@ -1373,7 +1338,7 @@
1373 return next(self.get_canonical_paths([path]))1338 return next(self.get_canonical_paths([path]))
13741339
13751340
1376class WorkingTreeFormatRegistry(controldir.ControlComponentFormatRegistry):1341class WorkingTreeFormatRegistry(ControlComponentFormatRegistry):
1377 """Registry for working tree formats."""1342 """Registry for working tree formats."""
13781343
1379 def __init__(self, other_registry=None):1344 def __init__(self, other_registry=None):
@@ -1402,7 +1367,7 @@
1402format_registry = WorkingTreeFormatRegistry()1367format_registry = WorkingTreeFormatRegistry()
14031368
14041369
1405class WorkingTreeFormat(controldir.ControlComponentFormat):1370class WorkingTreeFormat(ControlComponentFormat):
1406 """An encapsulation of the initialization and open routines for a format.1371 """An encapsulation of the initialization and open routines for a format.
14071372
1408 Formats provide three things:1373 Formats provide three things:

Subscribers

People subscribed via source and target branches