Rev 3585: Apply the review changes from Martin to the exact patch he approved. in http://bzr.arbash-meinel.com/branches/bzr/1.7-dev/branch_builder

John Arbash Meinel john at arbash-meinel.com
Tue Jul 29 17:16:59 BST 2008


At http://bzr.arbash-meinel.com/branches/bzr/1.7-dev/branch_builder

------------------------------------------------------------
revno: 3585
revision-id: john at arbash-meinel.com-20080729161636-aekx4mzqqf4733wl
parent: john at arbash-meinel.com-20080722204034-x54day968ipfmr1y
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: branch_builder
timestamp: Tue 2008-07-29 11:16:36 -0500
message:
  Apply the review changes from Martin to the exact patch he approved.
-------------- next part --------------
=== modified file 'bzrlib/branchbuilder.py'
--- a/bzrlib/branchbuilder.py	2008-07-22 20:40:34 +0000
+++ b/bzrlib/branchbuilder.py	2008-07-29 16:16:36 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2007 Canonical Ltd
+# Copyright (C) 2007, 2008 Canonical Ltd
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -26,12 +26,24 @@
     BranchBuilder on the transport you want your branch on, and then call
     appropriate build_ methods on it to get the shape of history you want.
 
+    This is meant as a helper for the test suite, not as a general class for
+    real data.
+
     For instance:
       builder = BranchBuilder(self.get_transport().clone('relpath'))
-      builder.build_commit()
-      builder.build_commit()
-      builder.build_commit()
+      builder.start_series()
+      builder.build_snapshot('rev-id', [],
+        [('add', ('filename', 'f-id', 'file', 'content\n'))])
+      builder.build_snapshot('rev2-id', ['rev-id'],
+        [('modify', ('f-id', 'new-content\n'))])
+      builder.finish_series()
       branch = builder.get_branch()
+
+    :ivar _tree: This is a private member which is not meant to be modified by
+        users of this class. While a 'series' is in progress, it should hold a
+        MemoryTree with the contents of the last commit (ready to be modified
+        by the next build_snapshot command) with a held write lock. Outside of
+        a series in progress, it should be None.
     """
 
     def __init__(self, transport, format=None):
@@ -40,8 +52,8 @@
         :param transport: The transport the branch should be created on.
             If the path of the transport does not exist but its parent does
             it will be created.
-        :param format: The name of a format in the bzrdir format registry
-            for the branch to be built.
+        :param format: Either a BzrDirFormat, or the name of a format in the
+            bzrdir format registry for the branch to be built.
         """
         if not transport.has('.'):
             transport.mkdir('.')
@@ -95,6 +107,9 @@
 
         Make sure to call 'finish_series' when you are done.
         """
+        if self._tree is not None:
+            raise AssertionError('You cannot start a new series while a'
+                                 ' series is already going.')
         self._tree = memorytree.MemoryTree.create_on_branch(self._branch)
         self._tree.lock_write()
 
@@ -117,7 +132,7 @@
             # not supported yet: ('rename', ('orig-path', 'new-path'))
         :param message: An optional commit message, if not supplied, a default
             commit message will be written.
-        ;return: The revision_id of the new commit
+        :return: The revision_id of the new commit
         """
         if parent_ids is not None:
             base_id = parent_ids[0]
@@ -163,7 +178,7 @@
                 elif action == 'unversion':
                     to_unversion_ids.append(info)
                 else:
-                    raise errors.UnknownBuildAction(action)
+                    raise ValueError('Unknown build action: "%s"' % (action,))
             if to_unversion_ids:
                 tree.unversion(to_unversion_ids)
             for path, file_id in to_add_directories:

=== modified file 'bzrlib/errors.py'
--- a/bzrlib/errors.py	2008-07-22 17:35:59 +0000
+++ b/bzrlib/errors.py	2008-07-29 16:16:36 +0000
@@ -584,16 +584,6 @@
         self.key = key
 
 
-class UnknownBuildAction(BzrError):
-    """Raised when a BranchBuilder gets an action it doesn't know"""
-
-    _fmt = "Unknown build action: %(action)s"
-
-    def __init__(self, action):
-        BzrError.__init__(self)
-        self.action = action
-
-
 class UnknownHook(BzrError):
 
     _fmt = "The %(type)s hook '%(hook)s' is unknown in this version of bzrlib."

=== modified file 'bzrlib/tests/test_branchbuilder.py'
--- a/bzrlib/tests/test_branchbuilder.py	2008-07-22 20:40:34 +0000
+++ b/bzrlib/tests/test_branchbuilder.py	2008-07-29 16:16:36 +0000
@@ -193,8 +193,9 @@
 
     def test_unknown_action(self):
         builder = self.build_a_rev()
-        self.assertRaises(errors.UnknownBuildAction,
+        e = self.assertRaises(ValueError,
             builder.build_snapshot, 'B-id', None, [('weirdo', ('foo',))])
+        self.assertEqual('Unknown build action: "weirdo"', str(e))
 
     # TODO: rename a file/directory, but rename isn't supported by the
     #       MemoryTree api yet, so for now we wait until it is used

=== modified file 'bzrlib/tests/test_errors.py'
--- a/bzrlib/tests/test_errors.py	2008-07-22 17:35:59 +0000
+++ b/bzrlib/tests/test_errors.py	2008-07-29 16:16:36 +0000
@@ -502,10 +502,6 @@
             "user encoding " + osutils.get_user_encoding(),
             str(err))
 
-    def test_unknown_build_action(self):
-        err = errors.UnknownBuildAction('myaction')
-        self.assertEqual("Unknown build action: myaction", str(err))
-
     def test_unknown_format(self):
         err = errors.UnknownFormatError('bar', kind='foo')
         self.assertEquals("Unknown foo format: 'bar'", str(err))

=== modified file 'bzrlib/tests/test_selftest.py'
--- a/bzrlib/tests/test_selftest.py	2008-07-22 19:26:36 +0000
+++ b/bzrlib/tests/test_selftest.py	2008-07-29 16:16:36 +0000
@@ -556,8 +556,11 @@
         self.failIf(osutils.lexists('dir'))
 
     def test_make_branch_builder_with_format(self):
+        # Use a repo layout that doesn't conform to a 'named' layout, to ensure
+        # that the format objects are used.
         format = bzrdir.BzrDirMetaFormat1()
-        format.repository_format = weaverepo.RepositoryFormat7()
+        repo_format = weaverepo.RepositoryFormat7()
+        format.repository_format = repo_format
         builder = self.make_branch_builder('dir', format=format)
         the_branch = builder.get_branch()
         # Guard against regression into MemoryTransport leaking
@@ -565,6 +568,9 @@
         self.failIf(osutils.lexists('dir'))
         self.assertEqual(format.repository_format.__class__,
                          the_branch.repository._format.__class__)
+        self.assertEqual(repo_format.get_format_string(),
+                         self.get_transport().get_bytes(
+                            'dir/.bzr/repository/format'))
 
     def test_make_branch_builder_with_format_name(self):
         builder = self.make_branch_builder('dir', format='knit')
@@ -575,6 +581,9 @@
         dir_format = bzrdir.format_registry.make_bzrdir('knit')
         self.assertEqual(dir_format.repository_format.__class__,
                          the_branch.repository._format.__class__)
+        self.assertEqual('Bazaar-NG Knit Repository Format 1',
+                         self.get_transport().get_bytes(
+                            'dir/.bzr/repository/format'))
 
     def test_safety_net(self):
         """No test should modify the safety .bzr directory.



More information about the bazaar-commits mailing list