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

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merged at revision: 6068
Proposed branch: lp:~jelmer/bzr/2.4-feature-flags
Merge into: lp:bzr/2.4
Diff against target: 139 lines (+72/-1)
6 files modified
bzrlib/branch.py (+2/-1)
bzrlib/bzrdir.py (+27/-0)
bzrlib/errors.py (+20/-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.4-feature-flags
Reviewer Review Type Date Requested Status
bzr-core Pending
Review via email: mp+97673@code.launchpad.net

Commit message

Add support for feature flags.

Description of the change

Add basic support for feature flags to the 2.4 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 'bzrlib/branch.py'
2--- bzrlib/branch.py 2011-08-12 10:34:58 +0000
3+++ bzrlib/branch.py 2012-03-27 20:34:33 +0000
4@@ -1591,7 +1591,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 return format_registry.get(format_string)
12 except errors.NoSuchFile:
13 raise errors.NotBranchError(path=transport.base, bzrdir=a_bzrdir)
14
15=== modified file 'bzrlib/bzrdir.py'
16--- bzrlib/bzrdir.py 2011-05-31 21:08:52 +0000
17+++ bzrlib/bzrdir.py 2012-03-27 20:34:33 +0000
18@@ -74,6 +74,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@@ -1344,6 +1370,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.get(format_string)
58 except KeyError:
59
60=== modified file 'bzrlib/errors.py'
61--- bzrlib/errors.py 2011-11-10 17:24:13 +0000
62+++ bzrlib/errors.py 2012-03-27 20:34:33 +0000
63@@ -3317,3 +3317,23 @@
64 def __init__(self, source, target):
65 self.source = source
66 self.target = target
67+
68+
69+class MissingFeature(BzrError):
70+
71+ _fmt = ("Missing feature %(feature)s not provided by this "
72+ "version of Bazaar or any plugin.")
73+
74+ def __init__(self, feature):
75+ self.feature = feature
76+
77+
78+class ParseFormatError(BzrError):
79+
80+ _fmt = "Parse error on line %(lineno)d of format name: %(line)s"
81+
82+ def __init__(self, lineno, line, text):
83+ BzrError.__init__(self)
84+ self.lineno = lineno
85+ self.line = line
86+ self.text = text
87
88=== modified file 'bzrlib/repository.py'
89--- bzrlib/repository.py 2011-08-30 10:54:28 +0000
90+++ bzrlib/repository.py 2012-03-27 20:34:33 +0000
91@@ -1452,6 +1452,7 @@
92 try:
93 transport = a_bzrdir.get_repository_transport(None)
94 format_string = transport.get_bytes("format")
95+ format_string = bzrdir.extract_format_string(format_string)
96 return format_registry.get(format_string)
97 except errors.NoSuchFile:
98 raise errors.NoRepositoryPresent(a_bzrdir)
99
100=== modified file 'bzrlib/tests/test_bzrdir.py'
101--- bzrlib/tests/test_bzrdir.py 2011-08-10 14:02:04 +0000
102+++ bzrlib/tests/test_bzrdir.py 2012-03-27 20:34:33 +0000
103@@ -1365,3 +1365,24 @@
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-06-28 17:25:26 +0000
131+++ bzrlib/workingtree.py 2012-03-27 20:34:33 +0000
132@@ -3030,6 +3030,7 @@
133 """Return the format for the working tree object in a_bzrdir."""
134 try:
135 format_string = klass.find_format_string(a_bzrdir)
136+ format_string = bzrdir.extract_format_string(format_string)
137 return format_registry.get(format_string)
138 except KeyError:
139 raise errors.UnknownFormatError(format=format_string,

Subscribers

People subscribed via source and target branches