Rev 3579: (mbp) branch --stacked should make a stacked format in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Fri Jul 25 07:27:02 BST 2008
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 3579
revision-id:pqm at pqm.ubuntu.com-20080725062645-tsvznpy0m5b0xqhy
parent: pqm at pqm.ubuntu.com-20080725055706-inu9eei2f8epz7az
parent: mbp at sourcefrog.net-20080725053342-x9s9xqirv2ar9f59
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Fri 2008-07-25 07:26:45 +0100
message:
(mbp) branch --stacked should make a stacked format
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/bzrdir.py bzrdir.py-20060131065624-156dfea39c4387cb
bzrlib/tests/blackbox/test_branch.py test_branch.py-20060524161337-noms9gmcwqqrfi8y-1
------------------------------------------------------------
revno: 3575.2.3
revision-id:mbp at sourcefrog.net-20080725053342-x9s9xqirv2ar9f59
parent: mbp at sourcefrog.net-20080725053245-pzj4ojq610mls3rv
committer: Martin Pool <mbp at sourcefrog.net>
branch nick: stacking
timestamp: Fri 2008-07-25 15:33:42 +1000
message:
NEWS update
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
------------------------------------------------------------
revno: 3575.2.2
revision-id:mbp at sourcefrog.net-20080725053245-pzj4ojq610mls3rv
parent: mbp at sourcefrog.net-20080724051940-h9reurya2k9v2gqt
committer: Martin Pool <mbp at sourcefrog.net>
branch nick: stacking
timestamp: Fri 2008-07-25 15:32:45 +1000
message:
branch --stacked should force a stacked format
modified:
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/bzrdir.py bzrdir.py-20060131065624-156dfea39c4387cb
bzrlib/tests/blackbox/test_branch.py test_branch.py-20060524161337-noms9gmcwqqrfi8y-1
=== modified file 'NEWS'
--- a/NEWS 2008-07-25 02:45:30 +0000
+++ b/NEWS 2008-07-25 06:26:45 +0000
@@ -31,6 +31,10 @@
BUG FIXES:
+ * ``bzr branch --stacked`` ensures the destination branch format can
+ support stacking, even if the origin does not.
+ (Martin Pool)
+
* Fix a test case that was failing if encoding wasn't UTF-8.
(John Arbash Meinel, #247585)
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py 2008-07-16 07:30:18 +0000
+++ b/bzrlib/branch.py 2008-07-25 05:32:45 +0000
@@ -1061,6 +1061,10 @@
def set_default_format(klass, format):
klass._default_format = format
+ def supports_stacking(self):
+ """True if this format records a stacked-on branch."""
+ return False
+
@classmethod
def unregister_format(klass, format):
del klass._formats[format.get_format_string()]
@@ -1368,6 +1372,9 @@
self._matchingbzrdir.repository_format = \
RepositoryFormatPackDevelopment1Subtree()
+ def supports_stacking(self):
+ return True
+
class BranchReferenceFormat(BranchFormat):
"""Bzr branch reference format.
=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py 2008-07-24 05:19:40 +0000
+++ b/bzrlib/bzrdir.py 2008-07-25 05:32:45 +0000
@@ -380,6 +380,7 @@
repository used instead.
If stack_on is supplied, will not seek a containing shared repo.
+
:param force_new_repo: If True, require a new repository to be created.
:param stack_on: If supplied, the location to stack on. If not
supplied, a default_stack_on location may be used.
@@ -978,7 +979,10 @@
return False
def _cloning_metadir(self):
- """Produce a metadir suitable for cloning with."""
+ """Produce a metadir suitable for cloning with.
+
+ :returns: (destination_bzrdir_format, source_repository)
+ """
result_format = self._format.__class__()
try:
try:
@@ -1013,6 +1017,10 @@
These operations may produce workingtrees (yes, even though they're
"cloning" something that doesn't have a tree), so a viable workingtree
format must be selected.
+
+ :returns: a BzrDirFormat with all component formats either set
+ appropriately or set to None if that component should not be
+ created.
"""
format, repository = self._cloning_metadir()
if format._workingtree_format is None:
@@ -1073,15 +1081,34 @@
force_new_repo, stacked_branch_url, require_stacking=stacked)
result_repo = repository_policy.acquire_repository()
if source_repository is not None:
+ # XXX: Isn't this redundant with the copy_content_into used below
+ # after creating the branch? -- mbp 20080724
result_repo.fetch(source_repository, revision_id=revision_id)
# Create/update the result branch
- if source_branch is not None:
- result_branch = source_branch.sprout(result,
- revision_id=revision_id)
- else:
+ if ((stacked
+ or repository_policy._require_stacking
+ or repository_policy._stack_on)
+ and not result._format.get_branch_format().supports_stacking()):
+ # force a branch that can support stacking
+ from bzrlib.branch import BzrBranchFormat7
+ format = BzrBranchFormat7()
+ result_branch = format.initialize(result)
+ mutter("using %r for stacking" % (format,))
+ elif source_branch is None:
+ # this is for sprouting a bzrdir without a branch; is that
+ # actually useful?
result_branch = result.create_branch()
+ else:
+ result_branch = source_branch._format.initialize(result)
+ mutter("created new branch %r" % (result_branch,))
repository_policy.configure_branch(result_branch)
+ if source_branch is not None:
+ # XXX: this duplicates Branch.sprout(); it probably belongs on an
+ # InterBranch method? -- mbp 20080724
+ source_branch.copy_content_into(result_branch,
+ revision_id=revision_id)
+ result_branch.set_parent(self.root_transport.base)
# Create/update the result working tree
if isinstance(target_transport, LocalTransport) and (
@@ -2859,7 +2886,29 @@
Creates the desired repository in the bzrdir we already have.
"""
- repository = self._bzrdir.create_repository(shared=shared)
+ if self._stack_on or self._require_stacking:
+ # we may be coming from a format that doesn't support stacking,
+ # but we require it in the destination, so force creation of a new
+ # one here.
+ #
+ # TODO: perhaps this should be treated as a distinct repository
+ # acquisition policy?
+ repository_format = self._bzrdir._format.repository_format
+ if not repository_format.supports_external_lookups:
+ # should possibly be controlled by the registry rather than
+ # hardcoded here.
+ from bzrlib.repofmt import pack_repo
+ if repository_format.rich_root_data:
+ repository_format = \
+ pack_repo.RepositoryFormatKnitPack5RichRoot()
+ else:
+ repository_format = pack_repo.RepositoryFormatKnitPack5()
+ note("using %r for stacking" % (repository_format,))
+ repository = repository_format.initialize(self._bzrdir,
+ shared=shared)
+ else:
+ # let bzrdir choose
+ repository = self._bzrdir.create_repository(shared=shared)
self._add_fallback(repository)
if make_working_trees is not None:
repository.set_make_working_trees(make_working_trees)
=== modified file 'bzrlib/tests/blackbox/test_branch.py'
--- a/bzrlib/tests/blackbox/test_branch.py 2008-07-17 08:00:25 +0000
+++ b/bzrlib/tests/blackbox/test_branch.py 2008-07-25 05:32:45 +0000
@@ -97,6 +97,9 @@
target_stat = os.stat('target/file1')
self.assertEqual(source_stat, target_stat)
+class TestBranchStacked(ExternalBase):
+ """Tests for branch --stacked"""
+
def check_shallow_branch(self, branch_revid, stacked_on):
"""Assert that the branch 'newbranch' has been published correctly.
@@ -153,6 +156,9 @@
self.assertEqual('', out)
self.assertEqual('Branched 1 revision(s).\n',
err)
+ # it should have preserved the branch format, and so it should be
+ # capable of supporting stacking, but not actually have a stacked_on
+ # branch configured
self.assertRaises(errors.NotStacked,
bzrdir.BzrDir.open('newbranch').open_branch().get_stacked_on_url)
@@ -207,6 +213,12 @@
out, err = self.run_bzr(
['branch', '--stacked', self.get_url('mainline'), 'shallow'])
+ def test_branch_stacked_from_non_stacked_format(self):
+ """The origin format doesn't support stacking"""
+ trunk = self.make_branch('trunk', format='pack-0.92')
+ out, err = self.run_bzr(
+ ['branch', '--stacked', 'trunk', 'shallow'])
+
class TestRemoteBranch(TestCaseWithSFTPServer):
More information about the bazaar-commits
mailing list