Merge lp:~jelmer/bzr/2.3-feature-flags into lp:bzr/2.3

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merged at revision: 5666
Proposed branch: lp:~jelmer/bzr/2.3-feature-flags
Merge into: lp:bzr/2.3
Diff against target: 139 lines (+72/-1)
6 files modified
bzrlib/branch.py (+2/-1)
bzrlib/bzrdir.py (+27/-0)
bzrlib/errors.py (+19/-0)
bzrlib/repository.py (+1/-0)
bzrlib/tests/test_bzrdir.py (+22/-0)
bzrlib/workingtree.py (+1/-0)
To merge this branch: bzr merge lp:~jelmer/bzr/2.3-feature-flags
Reviewer Review Type Date Requested Status
bzr-core Pending
Review via email: mp+97668@code.launchpad.net

Commit message

Add basic support for feature flags.

Description of the change

Add basic support for feature flags to the 2.3 release series.

This does the bare minimum to:
 * ignore optional feature flags
 * raise an appropriate error (non-confusing) for any other feature flags

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

Marking approved, simply merging up from 2.1.

Revision history for this message
Jelmer Vernooij (jelmer) wrote :

sent to pqm by email

Revision history for this message
Jelmer Vernooij (jelmer) wrote :

sent to pqm by email

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bzrlib/branch.py'
--- bzrlib/branch.py 2011-07-12 16:48:25 +0000
+++ bzrlib/branch.py 2012-03-27 20:43:18 +0000
@@ -1568,7 +1568,8 @@
1568 """Return the format for the branch object in a_bzrdir."""1568 """Return the format for the branch object in a_bzrdir."""
1569 try:1569 try:
1570 transport = a_bzrdir.get_branch_transport(None, name=name)1570 transport = a_bzrdir.get_branch_transport(None, name=name)
1571 format_string = transport.get_bytes("format")1571 format_string = bzrdir.extract_format_string(
1572 transport.get_bytes("format"))
1572 format = klass._formats[format_string]1573 format = klass._formats[format_string]
1573 if isinstance(format, MetaDirBranchFormatFactory):1574 if isinstance(format, MetaDirBranchFormatFactory):
1574 return format()1575 return format()
15751576
=== modified file 'bzrlib/bzrdir.py'
--- bzrlib/bzrdir.py 2011-01-26 19:34:58 +0000
+++ bzrlib/bzrdir.py 2012-03-27 20:43:18 +0000
@@ -93,6 +93,32 @@
93 )93 )
9494
9595
96def extract_format_string(text):
97 """Read a format string from a file.
98
99 The first line is returned. The other lines can contain
100 optional features. An exception is raised when a
101 required feature is present.
102 """
103 lines = text.splitlines(True)
104 try:
105 firstline = lines.pop(0)
106 except IndexError:
107 raise errors.UnknownFormatError(format=text, kind='')
108 for lineno, line in enumerate(lines):
109 try:
110 (necessity, feature) = line.split(" ", 1)
111 except ValueError:
112 raise errors.ParseFormatError(lineno=lineno+2,
113 line=line, text=text)
114 else:
115 if necessity == "optional":
116 mutter("Ignoring optional feature %s", feature)
117 else:
118 raise errors.MissingFeature(feature)
119 return firstline
120
121
96class BzrDir(controldir.ControlDir):122class BzrDir(controldir.ControlDir):
97 """A .bzr control diretory.123 """A .bzr control diretory.
98124
@@ -1471,6 +1497,7 @@
1471 format_string = transport.get_bytes(".bzr/branch-format")1497 format_string = transport.get_bytes(".bzr/branch-format")
1472 except errors.NoSuchFile:1498 except errors.NoSuchFile:
1473 raise errors.NotBranchError(path=transport.base)1499 raise errors.NotBranchError(path=transport.base)
1500 format_string = extract_format_string(format_string)
1474 try:1501 try:
1475 return klass._formats[format_string]1502 return klass._formats[format_string]
1476 except KeyError:1503 except KeyError:
14771504
=== modified file 'bzrlib/errors.py'
--- bzrlib/errors.py 2011-11-10 10:46:54 +0000
+++ bzrlib/errors.py 2012-03-27 20:43:18 +0000
@@ -3232,3 +3232,22 @@
3232 def __init__(self, branch_url):3232 def __init__(self, branch_url):
3233 self.branch_url = branch_url3233 self.branch_url = branch_url
32343234
3235
3236class MissingFeature(BzrError):
3237
3238 _fmt = ("Missing feature %(feature)s not provided by this "
3239 "version of Bazaar or any plugin.")
3240
3241 def __init__(self, feature):
3242 self.feature = feature
3243
3244
3245class ParseFormatError(BzrError):
3246
3247 _fmt = "Parse error on line %(lineno)d of format name: %(line)s"
3248
3249 def __init__(self, lineno, line, text):
3250 BzrError.__init__(self)
3251 self.lineno = lineno
3252 self.line = line
3253 self.text = text
32353254
=== modified file 'bzrlib/repository.py'
--- bzrlib/repository.py 2011-08-27 02:14:12 +0000
+++ bzrlib/repository.py 2012-03-27 20:43:18 +0000
@@ -3108,6 +3108,7 @@
3108 try:3108 try:
3109 transport = a_bzrdir.get_repository_transport(None)3109 transport = a_bzrdir.get_repository_transport(None)
3110 format_string = transport.get_bytes("format")3110 format_string = transport.get_bytes("format")
3111 format_string = bzrdir.extract_format_string(format_string)
3111 return format_registry.get(format_string)3112 return format_registry.get(format_string)
3112 except errors.NoSuchFile:3113 except errors.NoSuchFile:
3113 raise errors.NoRepositoryPresent(a_bzrdir)3114 raise errors.NoRepositoryPresent(a_bzrdir)
31143115
=== modified file 'bzrlib/tests/test_bzrdir.py'
--- bzrlib/tests/test_bzrdir.py 2011-05-13 11:34:44 +0000
+++ bzrlib/tests/test_bzrdir.py 2012-03-27 20:43:18 +0000
@@ -1457,3 +1457,25 @@
1457 def test_exiting(self):1457 def test_exiting(self):
1458 self._transport.put_bytes("a.~1~", "some content")1458 self._transport.put_bytes("a.~1~", "some content")
1459 self.assertEqual("a.~2~", self._bzrdir._available_backup_name("a"))1459 self.assertEqual("a.~2~", self._bzrdir._available_backup_name("a"))
1460
1461
1462class ExtractFormatStringTests(TestCase):
1463
1464 def test_normal(self):
1465 self.assertEquals("Bazaar-NG branch, format 0.0.4\n",
1466 bzrdir.extract_format_string("Bazaar-NG branch, format 0.0.4\n"))
1467
1468 def test_with_optional_feature(self):
1469 self.assertEquals("Bazaar-NG branch, format 0.0.4\n",
1470 bzrdir.extract_format_string("Bazaar-NG branch, format 0.0.4\n"
1471 "optional feature foo\n"))
1472
1473 def test_with_required_feature(self):
1474 self.assertRaises(errors.MissingFeature,
1475 bzrdir.extract_format_string, "Bazaar-NG branch, format 0.0.4\n"
1476 "required feature foo\n")
1477
1478 def test_with_invalid_line(self):
1479 self.assertRaises(errors.ParseFormatError,
1480 bzrdir.extract_format_string, "Bazaar-NG branch, format 0.0.4\n"
1481 "requiredfoo\n")
14601482
=== modified file 'bzrlib/workingtree.py'
--- bzrlib/workingtree.py 2011-01-13 02:05:17 +0000
+++ bzrlib/workingtree.py 2012-03-27 20:43:18 +0000
@@ -2864,6 +2864,7 @@
2864 try:2864 try:
2865 transport = a_bzrdir.get_workingtree_transport(None)2865 transport = a_bzrdir.get_workingtree_transport(None)
2866 format_string = transport.get_bytes("format")2866 format_string = transport.get_bytes("format")
2867 format_string = bzrdir.extract_format_string(format_string)
2867 return klass._formats[format_string]2868 return klass._formats[format_string]
2868 except errors.NoSuchFile:2869 except errors.NoSuchFile:
2869 raise errors.NoWorkingTree(base=transport.base)2870 raise errors.NoWorkingTree(base=transport.base)

Subscribers

People subscribed via source and target branches