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

Proposed by Jelmer Vernooij on 2012-03-15
Status: Merged
Approved by: Jelmer Vernooij on 2012-03-27
Approved revision: 5666
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 2012-03-15 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.
Jelmer Vernooij (jelmer) wrote :

Marking approved, simply merging up from 2.1.

Jelmer Vernooij (jelmer) wrote :

sent to pqm by email

Jelmer Vernooij (jelmer) wrote :

sent to pqm by email

lp:~jelmer/bzr/2.3-feature-flags updated on 2012-03-27
5667. By Jelmer Vernooij on 2012-03-27

Merge test fixes.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/branch.py'
2--- bzrlib/branch.py 2011-07-12 16:48:25 +0000
3+++ bzrlib/branch.py 2012-03-27 20:43:18 +0000
4@@ -1568,7 +1568,8 @@
5 """Return the format for the branch object in a_bzrdir."""
6 try:
7 transport = a_bzrdir.get_branch_transport(None, name=name)
8- format_string = transport.get_bytes("format")
9+ format_string = bzrdir.extract_format_string(
10+ transport.get_bytes("format"))
11 format = klass._formats[format_string]
12 if isinstance(format, MetaDirBranchFormatFactory):
13 return format()
14
15=== modified file 'bzrlib/bzrdir.py'
16--- bzrlib/bzrdir.py 2011-01-26 19:34:58 +0000
17+++ bzrlib/bzrdir.py 2012-03-27 20:43:18 +0000
18@@ -93,6 +93,32 @@
19 )
20
21
22+def extract_format_string(text):
23+ """Read a format string from a file.
24+
25+ The first line is returned. The other lines can contain
26+ optional features. An exception is raised when a
27+ required feature is present.
28+ """
29+ lines = text.splitlines(True)
30+ try:
31+ firstline = lines.pop(0)
32+ except IndexError:
33+ raise errors.UnknownFormatError(format=text, kind='')
34+ for lineno, line in enumerate(lines):
35+ try:
36+ (necessity, feature) = line.split(" ", 1)
37+ except ValueError:
38+ raise errors.ParseFormatError(lineno=lineno+2,
39+ line=line, text=text)
40+ else:
41+ if necessity == "optional":
42+ mutter("Ignoring optional feature %s", feature)
43+ else:
44+ raise errors.MissingFeature(feature)
45+ return firstline
46+
47+
48 class BzrDir(controldir.ControlDir):
49 """A .bzr control diretory.
50
51@@ -1471,6 +1497,7 @@
52 format_string = transport.get_bytes(".bzr/branch-format")
53 except errors.NoSuchFile:
54 raise errors.NotBranchError(path=transport.base)
55+ format_string = extract_format_string(format_string)
56 try:
57 return klass._formats[format_string]
58 except KeyError:
59
60=== modified file 'bzrlib/errors.py'
61--- bzrlib/errors.py 2011-11-10 10:46:54 +0000
62+++ bzrlib/errors.py 2012-03-27 20:43:18 +0000
63@@ -3232,3 +3232,22 @@
64 def __init__(self, branch_url):
65 self.branch_url = branch_url
66
67+
68+class MissingFeature(BzrError):
69+
70+ _fmt = ("Missing feature %(feature)s not provided by this "
71+ "version of Bazaar or any plugin.")
72+
73+ def __init__(self, feature):
74+ self.feature = feature
75+
76+
77+class ParseFormatError(BzrError):
78+
79+ _fmt = "Parse error on line %(lineno)d of format name: %(line)s"
80+
81+ def __init__(self, lineno, line, text):
82+ BzrError.__init__(self)
83+ self.lineno = lineno
84+ self.line = line
85+ self.text = text
86
87=== modified file 'bzrlib/repository.py'
88--- bzrlib/repository.py 2011-08-27 02:14:12 +0000
89+++ bzrlib/repository.py 2012-03-27 20:43:18 +0000
90@@ -3108,6 +3108,7 @@
91 try:
92 transport = a_bzrdir.get_repository_transport(None)
93 format_string = transport.get_bytes("format")
94+ format_string = bzrdir.extract_format_string(format_string)
95 return format_registry.get(format_string)
96 except errors.NoSuchFile:
97 raise errors.NoRepositoryPresent(a_bzrdir)
98
99=== modified file 'bzrlib/tests/test_bzrdir.py'
100--- bzrlib/tests/test_bzrdir.py 2011-05-13 11:34:44 +0000
101+++ bzrlib/tests/test_bzrdir.py 2012-03-27 20:43:18 +0000
102@@ -1457,3 +1457,25 @@
103 def test_exiting(self):
104 self._transport.put_bytes("a.~1~", "some content")
105 self.assertEqual("a.~2~", self._bzrdir._available_backup_name("a"))
106+
107+
108+class ExtractFormatStringTests(TestCase):
109+
110+ def test_normal(self):
111+ self.assertEquals("Bazaar-NG branch, format 0.0.4\n",
112+ bzrdir.extract_format_string("Bazaar-NG branch, format 0.0.4\n"))
113+
114+ def test_with_optional_feature(self):
115+ self.assertEquals("Bazaar-NG branch, format 0.0.4\n",
116+ bzrdir.extract_format_string("Bazaar-NG branch, format 0.0.4\n"
117+ "optional feature foo\n"))
118+
119+ def test_with_required_feature(self):
120+ self.assertRaises(errors.MissingFeature,
121+ bzrdir.extract_format_string, "Bazaar-NG branch, format 0.0.4\n"
122+ "required feature foo\n")
123+
124+ def test_with_invalid_line(self):
125+ self.assertRaises(errors.ParseFormatError,
126+ bzrdir.extract_format_string, "Bazaar-NG branch, format 0.0.4\n"
127+ "requiredfoo\n")
128
129=== modified file 'bzrlib/workingtree.py'
130--- bzrlib/workingtree.py 2011-01-13 02:05:17 +0000
131+++ bzrlib/workingtree.py 2012-03-27 20:43:18 +0000
132@@ -2864,6 +2864,7 @@
133 try:
134 transport = a_bzrdir.get_workingtree_transport(None)
135 format_string = transport.get_bytes("format")
136+ format_string = bzrdir.extract_format_string(format_string)
137 return klass._formats[format_string]
138 except errors.NoSuchFile:
139 raise errors.NoWorkingTree(base=transport.base)

Subscribers

People subscribed via source and target branches