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

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merged at revision: 5136
Proposed branch: lp:~jelmer/bzr/2.2-feature-flags
Merge into: lp:bzr/2.2
Diff against target: 158 lines (+78/-3)
7 files modified
NEWS (+4/-0)
bzrlib/branch.py (+2/-1)
bzrlib/bzrdir.py (+30/-2)
bzrlib/errors.py (+19/-0)
bzrlib/repository.py (+1/-0)
bzrlib/tests/test_bzrdir.py (+21/-0)
bzrlib/workingtree.py (+1/-0)
To merge this branch: bzr merge lp:~jelmer/bzr/2.2-feature-flags
Reviewer Review Type Date Requested Status
bzr-core Pending
Review via email: mp+97666@code.launchpad.net

Commit message

Add basic support for feature flags.

Description of the change

Add basic support for feature flags to the 2.2 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 as approved, simply upmerging 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 'NEWS'
--- NEWS 2011-09-02 18:47:36 +0000
+++ NEWS 2012-03-28 00:19:19 +0000
@@ -115,6 +115,10 @@
115Improvements115Improvements
116************116************
117117
118 * When opening formats with feature flags, optional features are
119 ignored and an improved error is printed for non-optional features.
120 (Jelmer Vernooij)
121
118Documentation122Documentation
119*************123*************
120124
121125
=== modified file 'bzrlib/branch.py'
--- bzrlib/branch.py 2010-08-13 07:32:06 +0000
+++ bzrlib/branch.py 2012-03-28 00:19:19 +0000
@@ -1549,7 +1549,8 @@
1549 """Return the format for the branch object in a_bzrdir."""1549 """Return the format for the branch object in a_bzrdir."""
1550 try:1550 try:
1551 transport = a_bzrdir.get_branch_transport(None, name=name)1551 transport = a_bzrdir.get_branch_transport(None, name=name)
1552 format_string = transport.get_bytes("format")1552 format_string = bzrdir.extract_format_string(
1553 transport.get_bytes("format"))
1553 format = klass._formats[format_string]1554 format = klass._formats[format_string]
1554 if isinstance(format, MetaDirBranchFormatFactory):1555 if isinstance(format, MetaDirBranchFormatFactory):
1555 return format()1556 return format()
15561557
=== modified file 'bzrlib/bzrdir.py'
--- bzrlib/bzrdir.py 2010-11-26 18:13:30 +0000
+++ bzrlib/bzrdir.py 2012-03-28 00:19:19 +0000
@@ -86,8 +86,34 @@
86 registry,86 registry,
87 symbol_versioning,87 symbol_versioning,
88 )88 )
89 89
90 90
91def extract_format_string(text):
92 """Read a format string from a file.
93
94 The first line is returned. The other lines can contain
95 optional features. An exception is raised when a
96 required feature is present.
97 """
98 lines = text.splitlines(True)
99 try:
100 firstline = lines.pop(0)
101 except IndexError:
102 raise errors.UnknownFormatError(format=text, kind='')
103 for lineno, line in enumerate(lines):
104 try:
105 (necessity, feature) = line.split(" ", 1)
106 except ValueError:
107 raise errors.ParseFormatError(lineno=lineno+2,
108 line=line, text=text)
109 else:
110 if necessity == "optional":
111 mutter("Ignoring optional feature %s", feature)
112 else:
113 raise errors.MissingFeature(feature)
114 return firstline
115
116
91class ControlComponent(object):117class ControlComponent(object):
92 """Abstract base class for control directory components.118 """Abstract base class for control directory components.
93 119
@@ -1959,6 +1985,8 @@
1959 format_string = transport.get_bytes(".bzr/branch-format")1985 format_string = transport.get_bytes(".bzr/branch-format")
1960 except errors.NoSuchFile:1986 except errors.NoSuchFile:
1961 raise errors.NotBranchError(path=transport.base)1987 raise errors.NotBranchError(path=transport.base)
1988 format_string = extract_format_string(format_string)
1989
1962 try:1990 try:
1963 return klass._formats[format_string]1991 return klass._formats[format_string]
1964 except KeyError:1992 except KeyError:
19651993
=== modified file 'bzrlib/errors.py'
--- bzrlib/errors.py 2011-01-19 22:26:11 +0000
+++ bzrlib/errors.py 2012-03-28 00:19:19 +0000
@@ -3194,3 +3194,22 @@
3194 def __init__(self, branch_url):3194 def __init__(self, branch_url):
3195 self.branch_url = branch_url3195 self.branch_url = branch_url
31963196
3197
3198class MissingFeature(BzrError):
3199
3200 _fmt = ("Missing feature %(feature)s not provided by this "
3201 "version of Bazaar or any plugin.")
3202
3203 def __init__(self, feature):
3204 self.feature = feature
3205
3206
3207class ParseFormatError(BzrError):
3208
3209 _fmt = "Parse error on line %(lineno)d of format name: %(line)s"
3210
3211 def __init__(self, lineno, line, text):
3212 BzrError.__init__(self)
3213 self.lineno = lineno
3214 self.line = line
3215 self.text = text
31973216
=== modified file 'bzrlib/repository.py'
--- bzrlib/repository.py 2010-12-02 09:23:10 +0000
+++ bzrlib/repository.py 2012-03-28 00:19:19 +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 2010-08-13 07:43:51 +0000
+++ bzrlib/tests/test_bzrdir.py 2012-03-28 00:19:19 +0000
@@ -1411,3 +1411,24 @@
1411 param_repr = param_reprs[0]1411 param_repr = param_reprs[0]
1412 self.assertStartsWith(param_repr, '<RepoInitHookParams for ')1412 self.assertStartsWith(param_repr, '<RepoInitHookParams for ')
14131413
1414
1415class ExtractFormatStringTests(TestCase):
1416
1417 def test_normal(self):
1418 self.assertEquals("Bazaar-NG branch, format 0.0.4\n",
1419 bzrdir.extract_format_string("Bazaar-NG branch, format 0.0.4\n"))
1420
1421 def test_with_optional_feature(self):
1422 self.assertEquals("Bazaar-NG branch, format 0.0.4\n",
1423 bzrdir.extract_format_string("Bazaar-NG branch, format 0.0.4\n"
1424 "optional feature foo\n"))
1425
1426 def test_with_required_feature(self):
1427 self.assertRaises(errors.MissingFeature,
1428 bzrdir.extract_format_string, "Bazaar-NG branch, format 0.0.4\n"
1429 "required feature foo\n")
1430
1431 def test_with_invalid_line(self):
1432 self.assertRaises(errors.ParseFormatError,
1433 bzrdir.extract_format_string, "Bazaar-NG branch, format 0.0.4\n"
1434 "requiredfoo\n")
14141435
=== modified file 'bzrlib/workingtree.py'
--- bzrlib/workingtree.py 2010-08-17 02:28:46 +0000
+++ bzrlib/workingtree.py 2012-03-28 00:19:19 +0000
@@ -2811,6 +2811,7 @@
2811 try:2811 try:
2812 transport = a_bzrdir.get_workingtree_transport(None)2812 transport = a_bzrdir.get_workingtree_transport(None)
2813 format_string = transport.get_bytes("format")2813 format_string = transport.get_bytes("format")
2814 format_string = bzrdir.extract_format_string(format_string)
2814 return klass._formats[format_string]2815 return klass._formats[format_string]
2815 except errors.NoSuchFile:2816 except errors.NoSuchFile:
2816 raise errors.NoWorkingTree(base=transport.base)2817 raise errors.NoWorkingTree(base=transport.base)

Subscribers

People subscribed via source and target branches