Rev 3542: Bring in both branch-builder threads. in http://bzr.arbash-meinel.com/branches/bzr/1.7-dev/merge_lca_multi

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


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

------------------------------------------------------------
revno: 3542
revision-id: john at arbash-meinel.com-20080729163409-3x3n0ba1xt2gmlvf
parent: john at arbash-meinel.com-20080723025925-8k0ornn7gcle8z2g
parent: john at arbash-meinel.com-20080729162837-4bcjhmvi405qp25h
parent: john at arbash-meinel.com-20080729163121-mw5rb5b4dimsi1zv
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: merge_lca_multi
timestamp: Tue 2008-07-29 11:34:09 -0500
message:
  Bring in both branch-builder threads.
modified:
  bzrlib/branchbuilder.py        branchbuilder.py-20070427022007-zlxpqz2lannhk6y8-1
  bzrlib/errors.py               errors.py-20050309040759-20512168c4e14fbd
  bzrlib/tests/test_branchbuilder.py test_branchbuilder.p-20070427022007-zlxpqz2lannhk6y8-2
  bzrlib/tests/test_errors.py    test_errors.py-20060210110251-41aba2deddf936a8
  bzrlib/tests/test_selftest.py  test_selftest.py-20051202044319-c110a115d8c0456a
  doc/developers/HACKING.txt     HACKING-20050805200004-2a5dc975d870f78c
    ------------------------------------------------------------
    revno: 3514.49.2
    revision-id: john at arbash-meinel.com-20080729162837-4bcjhmvi405qp25h
    parent: john at arbash-meinel.com-20080729161636-aekx4mzqqf4733wl
    committer: John Arbash Meinel <john at arbash-meinel.com>
    branch nick: branch_builder
    timestamp: Tue 2008-07-29 11:28:37 -0500
    message:
      Add directions to use BranchBuilder for tests.
    modified:
      doc/developers/HACKING.txt     HACKING-20050805200004-2a5dc975d870f78c
    ------------------------------------------------------------
    revno: 3514.49.1
    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.
    modified:
      bzrlib/branchbuilder.py        branchbuilder.py-20070427022007-zlxpqz2lannhk6y8-1
      bzrlib/errors.py               errors.py-20050309040759-20512168c4e14fbd
      bzrlib/tests/test_branchbuilder.py test_branchbuilder.p-20070427022007-zlxpqz2lannhk6y8-2
      bzrlib/tests/test_errors.py    test_errors.py-20060210110251-41aba2deddf936a8
      bzrlib/tests/test_selftest.py  test_selftest.py-20051202044319-c110a115d8c0456a
    ------------------------------------------------------------
    revno: 3514.1.72
    revision-id: john at arbash-meinel.com-20080729163121-mw5rb5b4dimsi1zv
    parent: john at arbash-meinel.com-20080723023509-1t4wkw5wjif7h72i
    committer: John Arbash Meinel <john at arbash-meinel.com>
    branch nick: use_branch_builder
    timestamp: Tue 2008-07-29 11:31:21 -0500
    message:
      'rename' is a supported action.
    modified:
      bzrlib/branchbuilder.py        branchbuilder.py-20070427022007-zlxpqz2lannhk6y8-1
-------------- next part --------------
=== modified file 'bzrlib/branchbuilder.py'
--- a/bzrlib/branchbuilder.py	2008-07-23 02:35:09 +0000
+++ b/bzrlib/branchbuilder.py	2008-07-29 16:34:09 +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()
 
@@ -114,10 +129,10 @@
             ('add', ('path', 'file-id', 'kind', 'content' or None))
             ('modify', ('file-id', 'new-content'))
             ('unversion', 'file-id')
-            # not supported yet: ('rename', ('orig-path', 'new-path'))
+            ('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 @@
                     from_relpath, to_relpath = info
                     to_rename.append((from_relpath, to_relpath))
                 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-23 02:35:09 +0000
+++ b/bzrlib/tests/test_branchbuilder.py	2008-07-29 16:34:09 +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))
 
     def test_rename(self):
         builder = self.build_a_rev()

=== 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.

=== modified file 'doc/developers/HACKING.txt'
--- a/doc/developers/HACKING.txt	2008-07-15 05:06:13 +0000
+++ b/doc/developers/HACKING.txt	2008-07-29 16:28:37 +0000
@@ -406,6 +406,17 @@
     subprocess you can use ``run_bzr_subprocess``. By default the spawned
     process will not load plugins unless ``--allow-plugins`` is supplied.
 
+When writing library functionality, it is often necessary to set up a
+branch with a certain history. Most current tests do this by inheriting
+from ``TestCaseWithTransport`` and using the ``make_branch_and_tree``
+helper to give them a ``WorkingTree`` that they can commit to. However,
+there is a newer api available from ``TestCaseWithMemoryTransport`` using
+the ``make_branch_builder`` helper. This helper is preferred, because it
+can build the changes in memory, rather than on disk. Tests that are
+explictly testing how we work with disk objects should, of course, use a
+real ``WorkingTree``. See ``bzrlib/branch_builder.py`` for how to use the
+class.
+
 
 Doctests
 --------



More information about the bazaar-commits mailing list