Rev 5792: (Jelmer) Add support for bound branches for 'bzr commit --lossy'. in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Sat Apr 16 15:11:52 UTC 2011
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 5792 [merge]
revision-id: pqm at pqm.ubuntu.com-20110416151149-qlsm8s7wy37mw3kx
parent: pqm at pqm.ubuntu.com-20110416141650-nyf3g3jmhw9cjoff
parent: jelmer at samba.org-20110416084221-g9kgp1j4o9zo0kk4
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Sat 2011-04-16 15:11:49 +0000
message:
(Jelmer) Add support for bound branches for 'bzr commit --lossy'.
modified:
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/commit.py commit.py-20050511101309-79ec1a0168e0e825
bzrlib/tests/per_branch/test_last_revision_info.py test_last_revision_i-20070201133317-51mzi40m8hv1i0i9-1
bzrlib/tests/test_commit.py test_commit.py-20050914060732-279f057f8c295434
bzrlib/tests/test_foreign.py test_foreign.py-20081125004048-ywb901edgp9lluxo-1
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py 2011-04-11 00:18:12 +0000
+++ b/bzrlib/branch.py 2011-04-12 00:44:43 +0000
@@ -1028,7 +1028,8 @@
self.repository.fetch(source_repo, revision_id=revid)
self.set_last_revision_info(revno, revid)
- def import_last_revision_info_and_tags(self, source, revno, revid):
+ def import_last_revision_info_and_tags(self, source, revno, revid,
+ lossy=False):
"""Set the last revision info, importing from another repo if necessary.
This is used by the bound branch code to upload a revision to
@@ -1038,6 +1039,10 @@
:param source: Source branch to optionally fetch from
:param revno: Revision number of the new tip
:param revid: Revision id of the new tip
+ :param lossy: Whether to discard metadata that can not be
+ natively represented
+ :return: Tuple with the new revision number and revision id
+ (should only be different from the arguments when lossy=True)
"""
if not self.repository.has_same_location(source.repository):
try:
@@ -1049,6 +1054,7 @@
if_present_ids=tags_to_fetch).execute()
self.repository.fetch(source.repository, fetch_spec=fetch_spec)
self.set_last_revision_info(revno, revid)
+ return (revno, revid)
def revision_id_to_revno(self, revision_id):
"""Given a revision id, return its revno"""
=== modified file 'bzrlib/commit.py'
--- a/bzrlib/commit.py 2011-04-13 00:58:10 +0000
+++ b/bzrlib/commit.py 2011-04-13 02:16:48 +0000
@@ -455,8 +455,10 @@
self._set_progress_stage("Uploading data to master branch")
# 'commit' to the master first so a timeout here causes the
# local branch to be out of date
- self.master_branch.import_last_revision_info_and_tags(
- self.branch, new_revno, self.rev_id)
+ (new_revno, self.rev_id) = self.master_branch.import_last_revision_info_and_tags(
+ self.branch, new_revno, self.rev_id, lossy=lossy)
+ if lossy:
+ self.branch.fetch(self.master_branch, self.rev_id)
# and now do the commit locally.
self.branch.set_last_revision_info(new_revno, self.rev_id)
=== modified file 'bzrlib/tests/per_branch/test_last_revision_info.py'
--- a/bzrlib/tests/per_branch/test_last_revision_info.py 2011-02-07 04:30:00 +0000
+++ b/bzrlib/tests/per_branch/test_last_revision_info.py 2011-04-12 00:44:43 +0000
@@ -62,10 +62,23 @@
tree1.commit('1st post')
revid = tree1.commit('2st post', allow_pointless=True)
branch2 = self.make_branch('branch2')
- branch2.import_last_revision_info_and_tags(tree1.branch, 2, revid)
+ self.assertEquals((2, revid),
+ branch2.import_last_revision_info_and_tags(tree1.branch, 2, revid))
self.assertEqual((2, revid), branch2.last_revision_info())
self.assertTrue(branch2.repository.has_revision(revid))
+ def test_import_lossy(self):
+ # importing with lossy=True works
+ tree1 = self.make_branch_and_tree('branch1')
+ tree1.commit('1st post')
+ revid = tree1.commit('2st post', allow_pointless=True)
+ branch2 = self.make_branch('branch2')
+ ret = branch2.import_last_revision_info_and_tags(tree1.branch, 2,
+ revid, lossy=True)
+ self.assertIsInstance(ret, tuple)
+ self.assertIsInstance(ret[0], int)
+ self.assertIsInstance(ret[1], str)
+
def test_same_repo(self):
# importing and setting last revision within the same repo
tree = self.make_branch_and_tree('branch1')
=== modified file 'bzrlib/tests/test_commit.py'
--- a/bzrlib/tests/test_commit.py 2011-04-16 08:18:28 +0000
+++ b/bzrlib/tests/test_commit.py 2011-04-16 08:42:21 +0000
@@ -128,6 +128,23 @@
timestamp=1302659388, timezone=0)
self.assertEquals('dummy-v1:1302659388.0-0-UNKNOWN', revid)
+ def test_commit_bound_lossy_foreign(self):
+ """Attempt a lossy commit to a bzr branch bound to a foreign branch."""
+ test_foreign.register_dummy_foreign_for_test(self)
+ foreign_branch = self.make_branch('foreign',
+ format=test_foreign.DummyForeignVcsDirFormat())
+ wt = foreign_branch.create_checkout("local")
+ b = wt.branch
+ file('local/hello', 'w').write('hello world')
+ wt.add('hello')
+ revid = wt.commit(message='add hello', lossy=True,
+ timestamp=1302659388, timezone=0)
+ self.assertEquals('dummy-v1:1302659388.0-0-0', revid)
+ self.assertEquals('dummy-v1:1302659388.0-0-0',
+ foreign_branch.last_revision())
+ self.assertEquals('dummy-v1:1302659388.0-0-0',
+ wt.branch.last_revision())
+
def test_missing_commit(self):
"""Test a commit with a missing file"""
wt = self.make_branch_and_tree('.')
=== modified file 'bzrlib/tests/test_foreign.py'
--- a/bzrlib/tests/test_foreign.py 2011-04-16 08:41:33 +0000
+++ b/bzrlib/tests/test_foreign.py 2011-04-16 08:42:21 +0000
@@ -100,6 +100,22 @@
branch.BzrBranch6.__init__(self, _format, _control_files, a_bzrdir,
*args, **kwargs)
+ def _get_checkout_format(self):
+ """Return the most suitable metadir for a checkout of this branch.
+ Weaves are used if this branch's repository uses weaves.
+ """
+ return self.bzrdir.checkout_metadir()
+
+ def import_last_revision_info_and_tags(self, source, revno, revid,
+ lossy=False):
+ interbranch = InterToDummyVcsBranch(source, self)
+ if lossy:
+ result = interbranch.lossy_push(revid)
+ revid = result.revidmap[revid]
+ else:
+ interbranch.push(revid)
+ return (revno, revid)
+
class DummyForeignCommitBuilder(repository.RootCommitBuilder):
@@ -109,6 +125,8 @@
self._new_revision_id = mapping.revision_id_foreign_to_bzr(
(str(self._timestamp), str(self._timezone), "UNKNOWN"))
self.random_revid = False
+ elif self._new_revision_id is not None:
+ self.random_revid = False
else:
self._new_revision_id = self._gen_revision_id()
self.random_revid = True
@@ -150,7 +168,10 @@
try:
# This just handles simple cases, but that's good enough for tests
my_history = self.target.revision_history()
- their_history = self.source.revision_history()
+ if stop_revision is None:
+ stop_revision = self.source.last_revision()
+ their_history = list(self.source.repository.iter_reverse_revision_history(stop_revision))
+ their_history.reverse()
if their_history[:min(len(my_history), len(their_history))] != my_history:
raise errors.DivergedBranches(self.target, self.source)
todo = their_history[len(my_history):]
@@ -206,7 +227,8 @@
super(DummyForeignVcsBranchFormat, self).__init__()
self._matchingbzrdir = DummyForeignVcsDirFormat()
- def open(self, a_bzrdir, name=None, _found=False, found_repository=None):
+ def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
+ found_repository=None):
if not _found:
raise NotImplementedError
try:
@@ -291,6 +313,9 @@
"""Produce a metadir suitable for cloning with."""
return bzrdir.format_registry.make_bzrdir("default")
+ def checkout_metadir(self):
+ return self.cloning_metadir()
+
def sprout(self, url, revision_id=None, force_new_repo=False,
recurse='down', possible_transports=None,
accelerator_tree=None, hardlink=False, stacked=False,
@@ -310,6 +335,9 @@
repository.format_registry.register(DummyForeignVcsRepositoryFormat())
testcase.addCleanup(repository.format_registry.remove,
DummyForeignVcsRepositoryFormat())
+ branch.format_registry.register(DummyForeignVcsBranchFormat())
+ testcase.addCleanup(branch.format_registry.remove,
+ DummyForeignVcsBranchFormat())
# We need to register the optimiser to make the dummy appears really
# different from a regular bzr repository.
branch.InterBranch.register_optimiser(InterToDummyVcsBranch)
More information about the bazaar-commits
mailing list