Rev 5666: (jelmer) Add basic support for feature flags. (Jelmer Vernooij) in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/2.3/

Patch Queue Manager pqm at pqm.ubuntu.com
Wed Mar 28 00:42:47 UTC 2012


At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/2.3/

------------------------------------------------------------
revno: 5666 [merge]
revision-id: pqm at pqm.ubuntu.com-20120328004246-kx0vzifaqi142b8i
parent: pqm at pqm.ubuntu.com-20111219122856-w2pwurat6tsj5mx7
parent: jelmer at samba.org-20120327203956-tsjypc7mhi9173d6
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: 2.3
timestamp: Wed 2012-03-28 00:42:46 +0000
message:
  (jelmer) Add basic 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-07-12 16:48:25 +0000
+++ b/bzrlib/branch.py	2012-03-15 14:47:19 +0000
@@ -1568,7 +1568,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"))
             format = klass._formats[format_string]
             if isinstance(format, MetaDirBranchFormatFactory):
                 return format()

=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py	2011-01-26 19:34:58 +0000
+++ b/bzrlib/bzrdir.py	2012-03-27 20:39:56 +0000
@@ -93,6 +93,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.
 
@@ -1471,6 +1497,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[format_string]
         except KeyError:

=== modified file 'bzrlib/errors.py'
--- a/bzrlib/errors.py	2011-11-10 10:46:54 +0000
+++ b/bzrlib/errors.py	2012-03-15 14:47:19 +0000
@@ -3232,3 +3232,22 @@
     def __init__(self, branch_url):
         self.branch_url = branch_url
 
+
+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-27 02:14:12 +0000
+++ b/bzrlib/repository.py	2012-03-15 14:47:19 +0000
@@ -3108,6 +3108,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-05-13 11:34:44 +0000
+++ b/bzrlib/tests/test_bzrdir.py	2012-03-15 14:47:19 +0000
@@ -1457,3 +1457,25 @@
     def test_exiting(self):
         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-01-13 02:05:17 +0000
+++ b/bzrlib/workingtree.py	2012-03-15 14:47:19 +0000
@@ -2864,6 +2864,7 @@
         try:
             transport = a_bzrdir.get_workingtree_transport(None)
             format_string = transport.get_bytes("format")
+            format_string = bzrdir.extract_format_string(format_string)
             return klass._formats[format_string]
         except errors.NoSuchFile:
             raise errors.NoWorkingTree(base=transport.base)




More information about the bazaar-commits mailing list