Rev 6068: (jelmer) Add support for feature flags. (Jelmer Vernooij) in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/2.4/
Patch Queue Manager
pqm at pqm.ubuntu.com
Tue Mar 27 23:20:36 UTC 2012
At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/2.4/
------------------------------------------------------------
revno: 6068 [merge]
revision-id: pqm at pqm.ubuntu.com-20120327232036-bnbqjsu6nx2qd4js
parent: pqm at pqm.ubuntu.com-20120227154537-xuts4sno7f8ltifc
parent: jelmer at samba.org-20120327203026-dbbjbwhzp4nne4in
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: 2.4
timestamp: Tue 2012-03-27 23:20:36 +0000
message:
(jelmer) Add support for feature flags. (Jelmer Vernooij)
modified:
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/bzrdir.py bzrdir.py-20060131065624-156dfea39c4387cb
bzrlib/errors.py errors.py-20050309040759-20512168c4e14fbd
bzrlib/repository.py rev_storage.py-20051111201905-119e9401e46257e3
bzrlib/tests/test_bzrdir.py test_bzrdir.py-20060131065654-deba40eef51cf220
bzrlib/workingtree.py workingtree.py-20050511021032-29b6ec0a681e02e3
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py 2011-08-12 10:34:58 +0000
+++ b/bzrlib/branch.py 2012-03-15 14:54:05 +0000
@@ -1591,7 +1591,8 @@
"""Return the format for the branch object in a_bzrdir."""
try:
transport = a_bzrdir.get_branch_transport(None, name=name)
- format_string = transport.get_bytes("format")
+ format_string = bzrdir.extract_format_string(
+ transport.get_bytes("format"))
return format_registry.get(format_string)
except errors.NoSuchFile:
raise errors.NotBranchError(path=transport.base, bzrdir=a_bzrdir)
=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py 2011-05-31 21:08:52 +0000
+++ b/bzrlib/bzrdir.py 2012-03-27 20:30:26 +0000
@@ -74,6 +74,32 @@
)
+def extract_format_string(text):
+ """Read a format string from a file.
+
+ The first line is returned. The other lines can contain
+ optional features. An exception is raised when a
+ required feature is present.
+ """
+ lines = text.splitlines(True)
+ try:
+ firstline = lines.pop(0)
+ except IndexError:
+ raise errors.UnknownFormatError(format=text, kind='')
+ for lineno, line in enumerate(lines):
+ try:
+ (necessity, feature) = line.split(" ", 1)
+ except ValueError:
+ raise errors.ParseFormatError(lineno=lineno+2,
+ line=line, text=text)
+ else:
+ if necessity == "optional":
+ mutter("Ignoring optional feature %s", feature)
+ else:
+ raise errors.MissingFeature(feature)
+ return firstline
+
+
class BzrDir(controldir.ControlDir):
"""A .bzr control diretory.
@@ -1344,6 +1370,7 @@
format_string = transport.get_bytes(".bzr/branch-format")
except errors.NoSuchFile:
raise errors.NotBranchError(path=transport.base)
+ format_string = extract_format_string(format_string)
try:
return klass.formats.get(format_string)
except KeyError:
=== modified file 'bzrlib/errors.py'
--- a/bzrlib/errors.py 2011-11-10 17:24:13 +0000
+++ b/bzrlib/errors.py 2012-03-15 14:54:05 +0000
@@ -3317,3 +3317,23 @@
def __init__(self, source, target):
self.source = source
self.target = target
+
+
+class MissingFeature(BzrError):
+
+ _fmt = ("Missing feature %(feature)s not provided by this "
+ "version of Bazaar or any plugin.")
+
+ def __init__(self, feature):
+ self.feature = feature
+
+
+class ParseFormatError(BzrError):
+
+ _fmt = "Parse error on line %(lineno)d of format name: %(line)s"
+
+ def __init__(self, lineno, line, text):
+ BzrError.__init__(self)
+ self.lineno = lineno
+ self.line = line
+ self.text = text
=== modified file 'bzrlib/repository.py'
--- a/bzrlib/repository.py 2011-08-30 10:54:28 +0000
+++ b/bzrlib/repository.py 2012-03-15 14:54:05 +0000
@@ -1452,6 +1452,7 @@
try:
transport = a_bzrdir.get_repository_transport(None)
format_string = transport.get_bytes("format")
+ format_string = bzrdir.extract_format_string(format_string)
return format_registry.get(format_string)
except errors.NoSuchFile:
raise errors.NoRepositoryPresent(a_bzrdir)
=== modified file 'bzrlib/tests/test_bzrdir.py'
--- a/bzrlib/tests/test_bzrdir.py 2011-08-10 14:02:04 +0000
+++ b/bzrlib/tests/test_bzrdir.py 2012-03-15 14:54:05 +0000
@@ -1365,3 +1365,24 @@
self._transport.put_bytes("a.~1~", "some content")
self.assertEqual("a.~2~", self._bzrdir._available_backup_name("a"))
+
+class ExtractFormatStringTests(TestCase):
+
+ def test_normal(self):
+ self.assertEquals("Bazaar-NG branch, format 0.0.4\n",
+ bzrdir.extract_format_string("Bazaar-NG branch, format 0.0.4\n"))
+
+ def test_with_optional_feature(self):
+ self.assertEquals("Bazaar-NG branch, format 0.0.4\n",
+ bzrdir.extract_format_string("Bazaar-NG branch, format 0.0.4\n"
+ "optional feature foo\n"))
+
+ def test_with_required_feature(self):
+ self.assertRaises(errors.MissingFeature,
+ bzrdir.extract_format_string, "Bazaar-NG branch, format 0.0.4\n"
+ "required feature foo\n")
+
+ def test_with_invalid_line(self):
+ self.assertRaises(errors.ParseFormatError,
+ bzrdir.extract_format_string, "Bazaar-NG branch, format 0.0.4\n"
+ "requiredfoo\n")
=== modified file 'bzrlib/workingtree.py'
--- a/bzrlib/workingtree.py 2011-06-28 17:25:26 +0000
+++ b/bzrlib/workingtree.py 2012-03-15 14:54:05 +0000
@@ -3030,6 +3030,7 @@
"""Return the format for the working tree object in a_bzrdir."""
try:
format_string = klass.find_format_string(a_bzrdir)
+ format_string = bzrdir.extract_format_string(format_string)
return format_registry.get(format_string)
except KeyError:
raise errors.UnknownFormatError(format=format_string,
More information about the bazaar-commits
mailing list