Rev 2496: (Robert Collins) Add a BranchBuilder API for use by the test suite. in http://bzr.arbash-meinel.com/branches/bzr/jam-integration
John Arbash Meinel
john at arbash-meinel.com
Wed May 30 13:45:35 BST 2007
At http://bzr.arbash-meinel.com/branches/bzr/jam-integration
------------------------------------------------------------
revno: 2496
revision-id: john at arbash-meinel.com-20070530124523-gxsp1617s70fhwqc
parent: pqm at pqm.ubuntu.com-20070525050023-ip6kst9coq8a32z5
parent: robertc at robertcollins.net-20070427061629-hqnq6rocm9dgljhx
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: jam-integration
timestamp: Wed 2007-05-30 07:45:23 -0500
message:
(Robert Collins) Add a BranchBuilder API for use by the test suite.
added:
bzrlib/branchbuilder.py branchbuilder.py-20070427022007-zlxpqz2lannhk6y8-1
bzrlib/tests/test_branchbuilder.py test_branchbuilder.p-20070427022007-zlxpqz2lannhk6y8-2
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
doc/developers/HACKING HACKING-20050805200004-2a5dc975d870f78c
------------------------------------------------------------
revno: 2466.7.10
revision-id: robertc at robertcollins.net-20070427061629-hqnq6rocm9dgljhx
parent: robertc at robertcollins.net-20070427033909-bsuz8ogd7r75dbfl
committer: Robert Collins <robertc at robertcollins.net>
branch nick: build-branch
timestamp: Fri 2007-04-27 16:16:29 +1000
message:
Add a format parameter to BranchBuilder.
------------------------------------------------------------
revno: 2466.7.9
revision-id: robertc at robertcollins.net-20070427033909-bsuz8ogd7r75dbfl
parent: robertc at robertcollins.net-20070427031822-1ga7jck9yw5ivsfr
committer: Robert Collins <robertc at robertcollins.net>
branch nick: build-branch
timestamp: Fri 2007-04-27 13:39:09 +1000
message:
Return the commited revision id from BranchBuilder.build_commit to save later instrospection.
------------------------------------------------------------
revno: 2466.7.8
revision-id: robertc at robertcollins.net-20070427031822-1ga7jck9yw5ivsfr
parent: robertc at robertcollins.net-20070427031300-wqxk6eo04pxn6trg
committer: Robert Collins <robertc at robertcollins.net>
branch nick: build-branch
timestamp: Fri 2007-04-27 13:18:22 +1000
message:
NEWS too.
------------------------------------------------------------
revno: 2466.7.7
revision-id: robertc at robertcollins.net-20070427031300-wqxk6eo04pxn6trg
parent: robertc at robertcollins.net-20070427030205-ll4s3d57mf0dcaqk
committer: Robert Collins <robertc at robertcollins.net>
branch nick: build-branch
timestamp: Fri 2007-04-27 13:13:00 +1000
message:
Document basic usage.
------------------------------------------------------------
revno: 2466.7.6
revision-id: robertc at robertcollins.net-20070427030205-ll4s3d57mf0dcaqk
parent: robertc at robertcollins.net-20070427023229-0a72vfyt4forz2c5
committer: Robert Collins <robertc at robertcollins.net>
branch nick: build-branch
timestamp: Fri 2007-04-27 13:02:05 +1000
message:
Add BranchBuilder.build_commit.
------------------------------------------------------------
revno: 2466.7.5
revision-id: robertc at robertcollins.net-20070427023229-0a72vfyt4forz2c5
parent: robertc at robertcollins.net-20070427023143-na837vjyw8y7ulns
committer: Robert Collins <robertc at robertcollins.net>
branch nick: build-branch
timestamp: Fri 2007-04-27 12:32:29 +1000
message:
Better docstring for BranchBuilder.__init__.
------------------------------------------------------------
revno: 2466.7.4
revision-id: robertc at robertcollins.net-20070427023143-na837vjyw8y7ulns
parent: robertc at robertcollins.net-20070427022014-gw8g0qi639fquuba
committer: Robert Collins <robertc at robertcollins.net>
branch nick: build-branch
timestamp: Fri 2007-04-27 12:31:43 +1000
message:
Add BranchBuilder.get_branch().
------------------------------------------------------------
revno: 2466.7.3
revision-id: robertc at robertcollins.net-20070427022014-gw8g0qi639fquuba
parent: robertc at robertcollins.net-20070427003620-6fjf8dbiblgt5am7
committer: Robert Collins <robertc at robertcollins.net>
branch nick: build-branch
timestamp: Fri 2007-04-27 12:20:14 +1000
message:
Create bzrlib.branchbuilder.
-------------- next part --------------
=== added file 'bzrlib/branchbuilder.py'
--- a/bzrlib/branchbuilder.py 1970-01-01 00:00:00 +0000
+++ b/bzrlib/branchbuilder.py 2007-04-27 06:16:29 +0000
@@ -0,0 +1,65 @@
+# Copyright (C) 2007 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
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+"""Utility for create branches with particular contents."""
+
+from bzrlib import bzrdir, errors, memorytree
+
+
+class BranchBuilder(object):
+ """A BranchBuilder aids creating Branches with particular shapes.
+
+ The expected way to use BranchBuilder is to construct a
+ 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.
+
+ For instance:
+ builder = BranchBuilder(self.get_transport().clone('relpath'))
+ builder.build_commit()
+ builder.build_commit()
+ builder.build_commit()
+ branch = builder.get_branch()
+ """
+
+ def __init__(self, transport, format=None):
+ """Construct a BranchBuilder on transport.
+
+ :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.
+ """
+ if not transport.has('.'):
+ transport.mkdir('.')
+ if format is None:
+ format = 'default'
+ self._branch = bzrdir.BzrDir.create_branch_convenience(transport.base,
+ format=bzrdir.format_registry.make_bzrdir(format))
+
+ def build_commit(self):
+ """Build a commit on the branch."""
+ tree = memorytree.MemoryTree.create_on_branch(self._branch)
+ tree.lock_write()
+ try:
+ tree.add('')
+ return tree.commit('commit %d' % (self._branch.revno() + 1))
+ finally:
+ tree.unlock()
+
+ def get_branch(self):
+ """Return the branch created by the builder."""
+ return self._branch
=== added file 'bzrlib/tests/test_branchbuilder.py'
--- a/bzrlib/tests/test_branchbuilder.py 1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/test_branchbuilder.py 2007-04-27 06:16:29 +0000
@@ -0,0 +1,73 @@
+# Copyright (C) 2007 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
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+"""Tests for the BranchBuilder class."""
+
+from bzrlib import (
+ branch as _mod_branch,
+ revision as _mod_revision,
+ tests,
+ )
+from bzrlib.branchbuilder import BranchBuilder
+
+
+class TestBranchBuilder(tests.TestCaseWithMemoryTransport):
+
+ def test_create(self):
+ """Test the constructor api."""
+ builder = BranchBuilder(self.get_transport().clone('foo'))
+ # we dont care if the branch has been built or not at this point.
+
+ def test_get_branch(self):
+ """get_branch returns the created branch."""
+ builder = BranchBuilder(self.get_transport().clone('foo'))
+ branch = builder.get_branch()
+ self.assertIsInstance(branch, _mod_branch.Branch)
+ self.assertEqual(self.get_transport().clone('foo').base,
+ branch.base)
+ self.assertEqual(
+ (0, _mod_revision.NULL_REVISION),
+ branch.last_revision_info())
+
+ def test_format(self):
+ """Making a BranchBuilder with a format option sets the branch type."""
+ builder = BranchBuilder(self.get_transport(), format='dirstate-tags')
+ branch = builder.get_branch()
+ self.assertIsInstance(branch, _mod_branch.BzrBranch6)
+
+ def test_build_one_commit(self):
+ """doing build_commit causes a commit to happen."""
+ builder = BranchBuilder(self.get_transport().clone('foo'))
+ rev_id = builder.build_commit()
+ branch = builder.get_branch()
+ self.assertEqual((1, rev_id), branch.last_revision_info())
+ self.assertEqual(
+ 'commit 1',
+ branch.repository.get_revision(branch.last_revision()).message)
+
+ def test_build_two_commits(self):
+ """The second commit has the right parents and message."""
+ builder = BranchBuilder(self.get_transport().clone('foo'))
+ rev_id1 = builder.build_commit()
+ rev_id2 = builder.build_commit()
+ branch = builder.get_branch()
+ self.assertEqual((2, rev_id2), branch.last_revision_info())
+ self.assertEqual(
+ 'commit 2',
+ branch.repository.get_revision(branch.last_revision()).message)
+ self.assertEqual(
+ [rev_id1],
+ branch.repository.get_revision(branch.last_revision()).parent_ids)
=== modified file 'NEWS'
--- a/NEWS 2007-05-25 04:00:47 +0000
+++ b/NEWS 2007-05-30 12:45:23 +0000
@@ -8,6 +8,10 @@
is specified, and are labelled "revision-id:", as per mainline
revisions, instead of "merged:". (Kent Gibson)
+ * New ``BranchBuilder`` API which allows the construction of particular
+ histories quickly. Useful for testing and potentially other applications
+ too. (Robert Collins)
+
IMPROVEMENTS:
* There are two new help topics, working-trees and repositories that
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2007-05-23 08:54:14 +0000
+++ b/bzrlib/tests/__init__.py 2007-05-30 12:45:23 +0000
@@ -2268,6 +2268,7 @@
'bzrlib.tests.test_atomicfile',
'bzrlib.tests.test_bad_files',
'bzrlib.tests.test_branch',
+ 'bzrlib.tests.test_branchbuilder',
'bzrlib.tests.test_bugtracker',
'bzrlib.tests.test_bundle',
'bzrlib.tests.test_bzrdir',
=== modified file 'doc/developers/HACKING'
--- a/doc/developers/HACKING 2007-05-23 09:07:35 +0000
+++ b/doc/developers/HACKING 2007-05-30 12:45:23 +0000
@@ -757,6 +757,19 @@
Please see bzrlib.treebuilder for more details.
+BranchBuilder
+~~~~~~~~~~~~~
+
+The ``BranchBuilder`` interface allows the creation of test branches in a
+quick and easy manner. A sample session::
+
+ builder = BranchBuilder(self.get_transport().clone('relpath'))
+ builder.build_commit()
+ builder.build_commit()
+ builder.build_commit()
+ branch = builder.get_branch()
+
+Please see bzrlib.branchbuilder for more details.
Doctests
--------
More information about the bazaar-commits
mailing list