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
1=== modified file 'NEWS'
2--- NEWS 2011-09-02 18:47:36 +0000
3+++ NEWS 2012-03-28 00:19:19 +0000
4@@ -115,6 +115,10 @@
5 Improvements
6 ************
7
8+ * When opening formats with feature flags, optional features are
9+ ignored and an improved error is printed for non-optional features.
10+ (Jelmer Vernooij)
11+
12 Documentation
13 *************
14
15
16=== modified file 'bzrlib/branch.py'
17--- bzrlib/branch.py 2010-08-13 07:32:06 +0000
18+++ bzrlib/branch.py 2012-03-28 00:19:19 +0000
19@@ -1549,7 +1549,8 @@
20 """Return the format for the branch object in a_bzrdir."""
21 try:
22 transport = a_bzrdir.get_branch_transport(None, name=name)
23- format_string = transport.get_bytes("format")
24+ format_string = bzrdir.extract_format_string(
25+ transport.get_bytes("format"))
26 format = klass._formats[format_string]
27 if isinstance(format, MetaDirBranchFormatFactory):
28 return format()
29
30=== modified file 'bzrlib/bzrdir.py'
31--- bzrlib/bzrdir.py 2010-11-26 18:13:30 +0000
32+++ bzrlib/bzrdir.py 2012-03-28 00:19:19 +0000
33@@ -86,8 +86,34 @@
34 registry,
35 symbol_versioning,
36 )
37-
38-
39+
40+
41+def extract_format_string(text):
42+ """Read a format string from a file.
43+
44+ The first line is returned. The other lines can contain
45+ optional features. An exception is raised when a
46+ required feature is present.
47+ """
48+ lines = text.splitlines(True)
49+ try:
50+ firstline = lines.pop(0)
51+ except IndexError:
52+ raise errors.UnknownFormatError(format=text, kind='')
53+ for lineno, line in enumerate(lines):
54+ try:
55+ (necessity, feature) = line.split(" ", 1)
56+ except ValueError:
57+ raise errors.ParseFormatError(lineno=lineno+2,
58+ line=line, text=text)
59+ else:
60+ if necessity == "optional":
61+ mutter("Ignoring optional feature %s", feature)
62+ else:
63+ raise errors.MissingFeature(feature)
64+ return firstline
65+
66+
67 class ControlComponent(object):
68 """Abstract base class for control directory components.
69
70@@ -1959,6 +1985,8 @@
71 format_string = transport.get_bytes(".bzr/branch-format")
72 except errors.NoSuchFile:
73 raise errors.NotBranchError(path=transport.base)
74+ format_string = extract_format_string(format_string)
75+
76 try:
77 return klass._formats[format_string]
78 except KeyError:
79
80=== modified file 'bzrlib/errors.py'
81--- bzrlib/errors.py 2011-01-19 22:26:11 +0000
82+++ bzrlib/errors.py 2012-03-28 00:19:19 +0000
83@@ -3194,3 +3194,22 @@
84 def __init__(self, branch_url):
85 self.branch_url = branch_url
86
87+
88+class MissingFeature(BzrError):
89+
90+ _fmt = ("Missing feature %(feature)s not provided by this "
91+ "version of Bazaar or any plugin.")
92+
93+ def __init__(self, feature):
94+ self.feature = feature
95+
96+
97+class ParseFormatError(BzrError):
98+
99+ _fmt = "Parse error on line %(lineno)d of format name: %(line)s"
100+
101+ def __init__(self, lineno, line, text):
102+ BzrError.__init__(self)
103+ self.lineno = lineno
104+ self.line = line
105+ self.text = text
106
107=== modified file 'bzrlib/repository.py'
108--- bzrlib/repository.py 2010-12-02 09:23:10 +0000
109+++ bzrlib/repository.py 2012-03-28 00:19:19 +0000
110@@ -3108,6 +3108,7 @@
111 try:
112 transport = a_bzrdir.get_repository_transport(None)
113 format_string = transport.get_bytes("format")
114+ format_string = bzrdir.extract_format_string(format_string)
115 return format_registry.get(format_string)
116 except errors.NoSuchFile:
117 raise errors.NoRepositoryPresent(a_bzrdir)
118
119=== modified file 'bzrlib/tests/test_bzrdir.py'
120--- bzrlib/tests/test_bzrdir.py 2010-08-13 07:43:51 +0000
121+++ bzrlib/tests/test_bzrdir.py 2012-03-28 00:19:19 +0000
122@@ -1411,3 +1411,24 @@
123 param_repr = param_reprs[0]
124 self.assertStartsWith(param_repr, '<RepoInitHookParams for ')
125
126+
127+class ExtractFormatStringTests(TestCase):
128+
129+ def test_normal(self):
130+ self.assertEquals("Bazaar-NG branch, format 0.0.4\n",
131+ bzrdir.extract_format_string("Bazaar-NG branch, format 0.0.4\n"))
132+
133+ def test_with_optional_feature(self):
134+ self.assertEquals("Bazaar-NG branch, format 0.0.4\n",
135+ bzrdir.extract_format_string("Bazaar-NG branch, format 0.0.4\n"
136+ "optional feature foo\n"))
137+
138+ def test_with_required_feature(self):
139+ self.assertRaises(errors.MissingFeature,
140+ bzrdir.extract_format_string, "Bazaar-NG branch, format 0.0.4\n"
141+ "required feature foo\n")
142+
143+ def test_with_invalid_line(self):
144+ self.assertRaises(errors.ParseFormatError,
145+ bzrdir.extract_format_string, "Bazaar-NG branch, format 0.0.4\n"
146+ "requiredfoo\n")
147
148=== modified file 'bzrlib/workingtree.py'
149--- bzrlib/workingtree.py 2010-08-17 02:28:46 +0000
150+++ bzrlib/workingtree.py 2012-03-28 00:19:19 +0000
151@@ -2811,6 +2811,7 @@
152 try:
153 transport = a_bzrdir.get_workingtree_transport(None)
154 format_string = transport.get_bytes("format")
155+ format_string = bzrdir.extract_format_string(format_string)
156 return klass._formats[format_string]
157 except errors.NoSuchFile:
158 raise errors.NoWorkingTree(base=transport.base)

Subscribers

People subscribed via source and target branches