Rev 6446: (jelmer) Add ControlDir.set_branch_reference. (Jelmer Vernooij) in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/2.5/
Patch Queue Manager
pqm at pqm.ubuntu.com
Thu Jan 19 12:48:14 UTC 2012
At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/2.5/
------------------------------------------------------------
revno: 6446 [merge]
revision-id: pqm at pqm.ubuntu.com-20120119124813-1qz4rgkgeuwaf0jk
parent: pqm at pqm.ubuntu.com-20120119115439-3f3x594uv515t86n
parent: jelmer at samba.org-20120118190855-bfkwrfb5raaqal6f
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: 2.5
timestamp: Thu 2012-01-19 12:48:13 +0000
message:
(jelmer) Add ControlDir.set_branch_reference. (Jelmer Vernooij)
modified:
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/bzrdir.py bzrdir.py-20060131065624-156dfea39c4387cb
bzrlib/controldir.py controldir.py-20100802102926-hvtvh0uae5epuibp-1
bzrlib/plugins/weave_fmt/bzrdir.py bzrdir_weave.py-20110310114200-ndz63gzqll03nf4z-1
bzrlib/reconfigure.py reconfigure.py-20070908040425-6ykgo7escxhyrg9p-1
bzrlib/remote.py remote.py-20060720103555-yeeg2x51vn0rbtdp-1
bzrlib/tests/blackbox/test_branches.py test_branches.py-20110815154803-0t6tna5x9ud2osj3-1
bzrlib/tests/blackbox/test_break_lock.py test_break_lock.py-20060303014503-a90e07d38d042d1d
bzrlib/tests/blackbox/test_info.py test_info.py-20060215045507-bbdd2d34efab9e0a
bzrlib/tests/blackbox/test_status.py teststatus.py-20050712014354-508855eb9f29f7dc
bzrlib/tests/blackbox/test_switch.py test_switch.py-20071122111948-0c5en6uz92bwl76h-1
bzrlib/tests/blackbox/test_update.py test_update.py-20060212125639-c4dad1a5c56d5919
bzrlib/tests/per_bzrdir/test_bzrdir.py test_bzrdir.py-20100829143338-2uachgod1c3liktl-1
bzrlib/tests/per_controldir/test_controldir.py test_bzrdir.py-20060131065642-0ebeca5e30e30866
bzrlib/tests/per_controldir_colo/test_supported.py test_supported.py-20100411192232-kawv9qu1t42gv89k-3
bzrlib/tests/per_controldir_colo/test_unsupported.py test_unsupported.py-20100411192232-kawv9qu1t42gv89k-4
bzrlib/tests/per_workingtree/test_workingtree.py test_workingtree.py-20060203003124-817757d3e31444fb
bzrlib/tests/test_branch.py test_branch.py-20060116013032-97819aa07b8ab3b5
bzrlib/workingtree.py workingtree.py-20050511021032-29b6ec0a681e02e3
doc/en/release-notes/bzr-2.5.txt bzr2.5.txt-20110708125756-587p0hpw7oke4h05-1
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py 2012-01-07 01:45:31 +0000
+++ b/bzrlib/branch.py 2012-01-18 17:47:06 +0000
@@ -1459,8 +1459,7 @@
format = self._get_checkout_format(lightweight=lightweight)
if lightweight:
checkout = format.initialize_on_transport(t)
- from_branch = BranchReferenceFormat().initialize(checkout,
- target_branch=self)
+ from_branch = checkout.set_branch_reference(target_branch=self)
else:
checkout_branch = controldir.ControlDir.create_branch_convenience(
to_location, force_new_tree=False, format=format)
=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py 2012-01-07 01:06:26 +0000
+++ b/bzrlib/bzrdir.py 2012-01-18 17:46:57 +0000
@@ -887,6 +887,10 @@
format = BranchFormatMetadir.find_format(self, name=name)
return format.get_reference(self, name=name)
+ def set_branch_reference(self, target_branch, name=None):
+ format = _mod_branch.BranchReferenceFormat()
+ return format.initialize(self, target_branch=target_branch, name=name)
+
def get_branch_transport(self, branch_format, name=None):
"""See BzrDir.get_branch_transport()."""
if name is None:
=== modified file 'bzrlib/controldir.py'
--- a/bzrlib/controldir.py 2012-01-06 23:29:07 +0000
+++ b/bzrlib/controldir.py 2012-01-18 17:46:57 +0000
@@ -230,6 +230,17 @@
raise errors.NoColocatedBranchSupport(self)
return None
+ def set_branch_reference(self, target_branch, name=None):
+ """Set the referenced URL for the branch in this controldir.
+
+ :param name: Optional colocated branch name
+ :param target_branch: Branch to reference
+ :raises NoColocatedBranchSupport: If a branch name was specified
+ but colocated branches are not supported.
+ :return: The referencing branch
+ """
+ raise NotImplementedError(self.set_branch_reference)
+
def open_branch(self, name=None, unsupported=False,
ignore_fallbacks=False, possible_transports=None):
"""Open the branch object at this ControlDir if one is present.
=== modified file 'bzrlib/plugins/weave_fmt/bzrdir.py'
--- a/bzrlib/plugins/weave_fmt/bzrdir.py 2012-01-03 13:47:01 +0000
+++ b/bzrlib/plugins/weave_fmt/bzrdir.py 2012-01-18 19:08:55 +0000
@@ -927,6 +927,12 @@
hardlink=hardlink)
return result
+ def set_branch_reference(self, target_branch, name=None):
+ from bzrlib.branch import BranchReferenceFormat
+ if name is not None:
+ raise errors.NoColocatedBranchSupport(self)
+ raise errors.IncompatibleFormat(BranchReferenceFormat, self._format)
+
class BzrDir4(BzrDirPreSplitOut):
"""A .bzr version 4 control object.
=== modified file 'bzrlib/reconfigure.py'
--- a/bzrlib/reconfigure.py 2011-12-19 13:23:58 +0000
+++ b/bzrlib/reconfigure.py 2012-01-18 17:47:06 +0000
@@ -369,8 +369,7 @@
else:
local_branch = self.local_branch
if self._create_reference:
- format = branch.BranchReferenceFormat().initialize(self.bzrdir,
- target_branch=reference_branch)
+ self.bzrdir.set_branch_reference(reference_branch)
if self._destroy_tree:
self.bzrdir.destroy_workingtree()
if self._create_tree:
=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py 2012-01-07 01:06:26 +0000
+++ b/bzrlib/remote.py 2012-01-18 17:37:38 +0000
@@ -679,6 +679,11 @@
b = self.open_branch(name=name)
return b._format
+ def set_branch_reference(self, target_branch, name=None):
+ """See BzrDir.set_branch_reference()."""
+ self._ensure_real()
+ return self._real_bzrdir.set_branch_reference(target_branch, name=name)
+
def get_branch_reference(self, name=None):
"""See BzrDir.get_branch_reference()."""
if name is not None:
=== modified file 'bzrlib/tests/blackbox/test_branches.py'
--- a/bzrlib/tests/blackbox/test_branches.py 2011-12-21 14:28:03 +0000
+++ b/bzrlib/tests/blackbox/test_branches.py 2012-01-18 17:47:06 +0000
@@ -17,7 +17,6 @@
"""Black-box tests for bzr branches."""
-from bzrlib.branch import BranchReferenceFormat
from bzrlib.tests import TestCaseWithTransport
@@ -73,7 +72,7 @@
t = self.make_repository('a', format='development-colo')
t.bzrdir.create_branch(name='another')
branch = t.bzrdir.create_branch(name='colocated')
- BranchReferenceFormat().initialize(t.bzrdir, target_branch=branch)
+ t.bzrdir.set_branch_reference(target_branch=branch)
out, err = self.run_bzr('branches a')
self.assertEquals(out, " another\n"
"* colocated\n")
=== modified file 'bzrlib/tests/blackbox/test_break_lock.py'
--- a/bzrlib/tests/blackbox/test_break_lock.py 2011-12-14 20:21:52 +0000
+++ b/bzrlib/tests/blackbox/test_break_lock.py 2012-01-18 17:47:06 +0000
@@ -61,8 +61,7 @@
local_branch = bzrdir.BzrDir.create_branch_convenience('repo/branch')
local_branch.bind(self.master_branch)
checkoutdir = bzrdir.BzrDir.create('checkout')
- branch.BranchReferenceFormat().initialize(
- checkoutdir, target_branch=local_branch)
+ checkoutdir.set_branch_reference(local_branch)
self.wt = checkoutdir.create_workingtree()
def test_break_lock_help(self):
=== modified file 'bzrlib/tests/blackbox/test_info.py'
--- a/bzrlib/tests/blackbox/test_info.py 2011-12-14 20:21:52 +0000
+++ b/bzrlib/tests/blackbox/test_info.py 2012-01-18 17:47:06 +0000
@@ -1256,8 +1256,7 @@
# Do a light checkout of the heavy one
transport.mkdir('tree/lightcheckout')
lco_dir = bzrdir.BzrDirMetaFormat1().initialize('tree/lightcheckout')
- branch.BranchReferenceFormat().initialize(lco_dir,
- target_branch=co_branch)
+ lco_dir.set_branch_reference(co_branch)
lco_dir.create_workingtree()
lco_tree = lco_dir.open_workingtree()
=== modified file 'bzrlib/tests/blackbox/test_status.py'
--- a/bzrlib/tests/blackbox/test_status.py 2011-11-17 20:11:33 +0000
+++ b/bzrlib/tests/blackbox/test_status.py 2012-01-18 17:47:06 +0000
@@ -598,8 +598,7 @@
def make_branch_and_tree(self, relpath):
source = self.make_branch(pathjoin('..', relpath))
checkout = bzrdir.BzrDirMetaFormat1().initialize(relpath)
- bzrlib.branch.BranchReferenceFormat().initialize(checkout,
- target_branch=source)
+ checkout.set_branch_reference(source)
return checkout.create_workingtree()
=== modified file 'bzrlib/tests/blackbox/test_switch.py'
--- a/bzrlib/tests/blackbox/test_switch.py 2011-12-14 21:57:37 +0000
+++ b/bzrlib/tests/blackbox/test_switch.py 2012-01-18 17:47:06 +0000
@@ -183,8 +183,7 @@
# Use switch to change it to 'anotherbranch'
repo = self.make_repository('branch-1', format='development-colo')
target_branch = repo.bzrdir.create_branch(name='foo')
- branch.BranchReferenceFormat().initialize(
- repo.bzrdir, target_branch=target_branch)
+ repo.bzrdir.set_branch_reference(target_branch)
tree = repo.bzrdir.create_workingtree()
self.build_tree(['branch-1/file-1', 'branch-1/file-2'])
tree.add('file-1')
@@ -203,8 +202,7 @@
# Use switch to create 'anotherbranch' which derives from that
repo = self.make_repository('branch-1', format='development-colo')
target_branch = repo.bzrdir.create_branch(name='foo')
- branch.BranchReferenceFormat().initialize(
- repo.bzrdir, target_branch=target_branch)
+ repo.bzrdir.set_branch_reference(target_branch)
tree = repo.bzrdir.create_workingtree()
self.build_tree(['branch-1/file-1', 'branch-1/file-2'])
tree.add('file-1')
@@ -223,8 +221,7 @@
self.requireFeature(UnicodeFilenameFeature)
repo = self.make_repository('branch-1', format='development-colo')
target_branch = repo.bzrdir.create_branch(name='foo')
- branch.BranchReferenceFormat().initialize(
- repo.bzrdir, target_branch=target_branch)
+ repo.bzrdir.set_branch_reference(target_branch)
tree = repo.bzrdir.create_workingtree()
self.build_tree(['branch-1/file-1', 'branch-1/file-2'])
tree.add('file-1')
=== modified file 'bzrlib/tests/blackbox/test_update.py'
--- a/bzrlib/tests/blackbox/test_update.py 2011-09-29 01:03:18 +0000
+++ b/bzrlib/tests/blackbox/test_update.py 2012-01-18 17:47:06 +0000
@@ -194,8 +194,7 @@
self.build_tree(['checkout1/'])
checkout_dir = bzrdir.BzrDirMetaFormat1().initialize('checkout1')
- branch.BranchReferenceFormat().initialize(checkout_dir,
- target_branch=master.branch)
+ checkout_dir.set_branch_reference(master.branch)
checkout1 = checkout_dir.create_workingtree('m1')
# Create a second branch, with an extra commit
@@ -251,8 +250,7 @@
self.build_tree(['checkout1/'])
checkout_dir = bzrdir.BzrDirMetaFormat1().initialize('checkout1')
- branch.BranchReferenceFormat().initialize(checkout_dir,
- target_branch=master.branch)
+ checkout_dir.set_branch_reference(master.branch)
checkout1 = checkout_dir.create_workingtree('m1')
# Create a second branch, with an extra commit
=== modified file 'bzrlib/tests/per_bzrdir/test_bzrdir.py'
--- a/bzrlib/tests/per_bzrdir/test_bzrdir.py 2012-01-07 01:45:31 +0000
+++ b/bzrlib/tests/per_bzrdir/test_bzrdir.py 2012-01-18 17:47:06 +0000
@@ -376,8 +376,7 @@
referenced_branch = self.make_branch('referencced')
dir = self.make_bzrdir('source')
try:
- reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
- target_branch=referenced_branch)
+ dir.set_branch_reference(referenced_branch)
except errors.IncompatibleFormat:
# this is ok too, not all formats have to support references.
return
@@ -420,8 +419,7 @@
referenced_branch = self.make_branch('referencced')
dir = self.make_bzrdir('source')
try:
- reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
- target_branch=referenced_branch)
+ dir.set_branch_reference(referenced_branch)
except errors.IncompatibleFormat:
# this is ok too, not all formats have to support references.
return
@@ -691,7 +689,6 @@
target_branch = repo.bzrdir.create_branch(name='foo')
except errors.NoColocatedBranchSupport:
raise TestNotApplicable('Format does not support colocation')
- reference = branch.BranchReferenceFormat().initialize(
- repo.bzrdir, target_branch=target_branch)
+ repo.bzrdir.set_branch_reference(target_branch)
self.assertEqual(set(["", 'foo']),
set(repo.bzrdir.get_branches().keys()))
=== modified file 'bzrlib/tests/per_controldir/test_controldir.py'
--- a/bzrlib/tests/per_controldir/test_controldir.py 2012-01-06 23:29:07 +0000
+++ b/bzrlib/tests/per_controldir/test_controldir.py 2012-01-18 17:47:06 +0000
@@ -415,13 +415,56 @@
"not support stacking")
self.assertEqual(child.open_branch().get_stacked_on_url(), branch.base)
+ def test_set_branch_reference(self):
+ """set_branch_reference creates a branch reference"""
+ referenced_branch = self.make_branch('referenced')
+ dir = self.make_bzrdir('source')
+ try:
+ reference = dir.set_branch_reference(referenced_branch)
+ except errors.IncompatibleFormat:
+ # this is ok too, not all formats have to support references.
+ raise TestNotApplicable("control directory does not "
+ "support branch references")
+ self.assertEqual(
+ referenced_branch.bzrdir.root_transport.abspath('') + '/',
+ dir.get_branch_reference())
+
+ def test_set_branch_reference_on_existing_reference(self):
+ """set_branch_reference creates a branch reference"""
+ referenced_branch1 = self.make_branch('old-referenced')
+ referenced_branch2 = self.make_branch('new-referenced')
+ dir = self.make_bzrdir('source')
+ try:
+ reference = dir.set_branch_reference(referenced_branch1)
+ except errors.IncompatibleFormat:
+ # this is ok too, not all formats have to support references.
+ raise TestNotApplicable("control directory does not "
+ "support branch references")
+ reference = dir.set_branch_reference(referenced_branch2)
+ self.assertEqual(
+ referenced_branch2.bzrdir.root_transport.abspath('') + '/',
+ dir.get_branch_reference())
+
+ def test_set_branch_reference_on_existing_branch(self):
+ """set_branch_reference creates a branch reference"""
+ referenced_branch = self.make_branch('referenced')
+ dir = self.make_branch('source').bzrdir
+ try:
+ reference = dir.set_branch_reference(referenced_branch)
+ except errors.IncompatibleFormat:
+ # this is ok too, not all formats have to support references.
+ raise TestNotApplicable("control directory does not "
+ "support branch references")
+ self.assertEqual(
+ referenced_branch.bzrdir.root_transport.abspath('') + '/',
+ dir.get_branch_reference())
+
def test_get_branch_reference_on_reference(self):
"""get_branch_reference should return the right url."""
referenced_branch = self.make_branch('referenced')
dir = self.make_bzrdir('source')
try:
- reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
- target_branch=referenced_branch)
+ dir.set_branch_reference(referenced_branch)
except errors.IncompatibleFormat:
# this is ok too, not all formats have to support references.
raise TestNotApplicable("control directory does not "
@@ -652,8 +695,7 @@
referenced_branch = self.make_branch('referenced')
dir = self.make_bzrdir('source')
try:
- reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
- target_branch=referenced_branch)
+ dir.set_branch_reference(referenced_branch)
except errors.IncompatibleFormat:
raise TestNotApplicable("format does not support branch "
"references")
@@ -672,8 +714,7 @@
referenced_tree.commit('1', rev_id='1', allow_pointless=True)
dir = self.make_bzrdir('source')
try:
- reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
- target_branch=referenced_tree.branch)
+ dir.set_branch_reference(referenced_tree.branch)
except errors.IncompatibleFormat:
raise TestNotApplicable("format does not support branch "
"references")
@@ -699,8 +740,7 @@
referenced_tree.commit('1', rev_id='1', allow_pointless=True)
dir = self.make_bzrdir('source')
try:
- reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
- target_branch=referenced_tree.branch)
+ dir.set_branch_reference(referenced_tree.branch)
except errors.IncompatibleFormat:
# this is ok too, not all formats have to support references.
raise TestNotApplicable("format does not support "
@@ -851,8 +891,7 @@
referenced_branch = self.make_branch('referencced')
dir = self.make_bzrdir('source')
try:
- reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
- target_branch=referenced_branch)
+ dir.set_branch_reference(referenced_branch)
except errors.IncompatibleFormat:
# this is ok too, not all formats have to support references.
raise TestNotApplicable("format does not support "
@@ -878,8 +917,7 @@
referenced_branch = self.make_branch('referencced')
dir = self.make_bzrdir('source')
try:
- reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
- target_branch=referenced_branch)
+ dir.set_branch_reference(referenced_branch)
except errors.IncompatibleFormat:
# this is ok too, not all formats have to support references.
raise TestNotApplicable("format does not support "
@@ -1581,8 +1619,7 @@
master = self.make_branch('branch')
thisdir = self.make_bzrdir('this')
try:
- bzrlib.branch.BranchReferenceFormat().initialize(
- thisdir, target_branch=master)
+ thisdir.set_branch_reference(master)
except errors.IncompatibleFormat:
raise TestNotApplicable("format does not support "
"branch references")
=== modified file 'bzrlib/tests/per_controldir_colo/test_supported.py'
--- a/bzrlib/tests/per_controldir_colo/test_supported.py 2011-12-12 12:08:58 +0000
+++ b/bzrlib/tests/per_controldir_colo/test_supported.py 2012-01-18 17:37:38 +0000
@@ -134,3 +134,10 @@
self.assertEqual(['foo'], repo.bzrdir.get_branches().keys())
self.assertEqual(target_branch.base,
repo.bzrdir.get_branches()['foo'].base)
+
+ def test_branch_reference(self):
+ referenced = self.make_branch('referenced')
+ repo = self.make_repository('repo')
+ repo.bzrdir.set_branch_reference(referenced, name='foo')
+ self.assertEquals(referenced.base,
+ repo.bzrdir.get_branch_reference('foo'))
=== modified file 'bzrlib/tests/per_controldir_colo/test_unsupported.py'
--- a/bzrlib/tests/per_controldir_colo/test_unsupported.py 2012-01-06 23:29:07 +0000
+++ b/bzrlib/tests/per_controldir_colo/test_unsupported.py 2012-01-18 17:37:38 +0000
@@ -69,6 +69,12 @@
self.assertRaises(errors.NoColocatedBranchSupport,
made_control.get_branch_reference, "colo")
+ def test_set_branch_reference(self):
+ referenced = self.make_branch('referenced')
+ made_control = self.make_bzrdir_with_repo()
+ self.assertRaises(errors.NoColocatedBranchSupport,
+ made_control.set_branch_reference, referenced, name="colo")
+
def test_get_branches(self):
made_control = self.make_bzrdir_with_repo()
made_control.create_branch()
=== modified file 'bzrlib/tests/per_workingtree/test_workingtree.py'
--- a/bzrlib/tests/per_workingtree/test_workingtree.py 2012-01-06 19:46:41 +0000
+++ b/bzrlib/tests/per_workingtree/test_workingtree.py 2012-01-18 17:47:06 +0000
@@ -490,8 +490,7 @@
# current format
self.build_tree(['checkout/', 'tree/file'])
checkout = bzrdir.BzrDirMetaFormat1().initialize('checkout')
- branch.BranchReferenceFormat().initialize(checkout,
- target_branch=main_branch)
+ checkout.set_branch_reference(main_branch)
old_tree = self.workingtree_format.initialize(checkout)
# now commit to 'tree'
wt.add('file')
@@ -558,8 +557,7 @@
# current format
self.build_tree(['checkout/', 'tree/file'])
checkout = bzrdir.BzrDirMetaFormat1().initialize('checkout')
- branch.BranchReferenceFormat().initialize(checkout,
- target_branch=main_branch)
+ checkout.set_branch_reference(main_branch)
old_tree = self.workingtree_format.initialize(checkout)
# now commit to 'tree'
wt.add('file')
=== modified file 'bzrlib/tests/test_branch.py'
--- a/bzrlib/tests/test_branch.py 2012-01-04 17:12:42 +0000
+++ b/bzrlib/tests/test_branch.py 2012-01-18 17:47:06 +0000
@@ -575,7 +575,7 @@
self.assertEqual(opened_branch.base, target_branch.base)
def test_get_reference(self):
- """For a BranchReference, get_reference should reutrn the location."""
+ """For a BranchReference, get_reference should return the location."""
branch = self.make_branch('target')
checkout = branch.create_checkout('checkout', lightweight=True)
reference_url = branch.bzrdir.root_transport.abspath('') + '/'
=== modified file 'bzrlib/workingtree.py'
--- a/bzrlib/workingtree.py 2012-01-03 13:47:01 +0000
+++ b/bzrlib/workingtree.py 2012-01-18 17:47:06 +0000
@@ -2420,8 +2420,7 @@
tree_transport = self.bzrdir.root_transport.clone(sub_path)
if tree_transport.base != branch_transport.base:
tree_bzrdir = format.initialize_on_transport(tree_transport)
- branch.BranchReferenceFormat().initialize(tree_bzrdir,
- target_branch=new_branch)
+ tree_bzrdir.set_branch_reference(new_branch)
else:
tree_bzrdir = branch_bzrdir
wt = tree_bzrdir.create_workingtree(_mod_revision.NULL_REVISION)
=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- a/doc/en/release-notes/bzr-2.5.txt 2012-01-19 10:28:11 +0000
+++ b/doc/en/release-notes/bzr-2.5.txt 2012-01-19 12:48:13 +0000
@@ -49,6 +49,9 @@
.. Changes that may require updates in plugins or other code that uses
bzrlib.
+* ``ControlDir`` now has a new method ``set_branch_reference`` which can
+ be used for setting branch references. (Jelmer Vernooij)
+
Internals
*********
More information about the bazaar-commits
mailing list