[MERGE] allow pushing/pulling/branching between branches within a shared repository.
John A Meinel
john at arbash-meinel.com
Tue Feb 21 16:33:28 GMT 2006
Robert Collins wrote:
> http://people.ubuntu.com/~robertc/baz2.0/repository new adds pushing and
> pulling and branching support within shared repositories. (I had tested
> branches *into* a shared repo but not *within* one.)
>
> fetch.py | 7 +--
> tests/bzrdir_implementations/test_bzrdir.py | 42
> +++++++++++++++++++-
> tests/repository_implementations/test_repository.py | 10 ++++
> 3 files changed, 55 insertions(+), 4 deletions(-)
>
>
>
>
> ------------------------------------------------------------------------
>
> === modified file 'bzrlib/fetch.py'
> --- bzrlib/fetch.py
> +++ bzrlib/fetch.py
> @@ -80,9 +80,10 @@
> """
> def __init__(self, to_repository, from_repository, last_revision=None, pb=None):
> if to_repository.bzrdir.transport.base == from_repository.bzrdir.transport.base:
> - raise Exception("can't fetch from a repository to itself %s, %s" %
> - (from_repository.bzrdir.transport.base,
> - to_repository.bzrdir.transport.base))
> + # check that last_revision is in 'from' and then return a no-operation.
> + if last_revision not in (None, NULL_REVISION):
> + from_repository.get_revision(last_revision)
> + return
> self.to_repository = to_repository
> self.from_repository = from_repository
> # must not mutate self._last_revision as its potentially a shared instance
>
This seems like you will get 'NoSuchRevision' if it doesn't exist. Is
that the exception you want? I would just expect more of a "if not
from_repository.has_revision(last_revision): raise NoSuchRevision". But
I'm guessing the side effect of get_revision() does what you want.
> === modified file 'bzrlib/tests/bzrdir_implementations/test_bzrdir.py'
> --- bzrlib/tests/bzrdir_implementations/test_bzrdir.py
> +++ bzrlib/tests/bzrdir_implementations/test_bzrdir.py
> @@ -147,6 +147,26 @@
> target = dir.clone(self.get_url('target/child'))
> self.assertNotEqual(dir.transport.base, target.transport.base)
> self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
> +
> + def test_clone_bzrdir_repository_branch_both_under_shared(self):
> + try:
> + shared_repo = self.make_repository('shared', shared=True)
> + except errors.IncompatibleFormat:
> + return
> + tree = self.make_branch_and_tree('commit_tree')
> + self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
> + tree.add('foo')
> + tree.commit('revision 1', rev_id='1')
> + tree.bzrdir.open_branch().set_revision_history([])
> + tree.set_last_revision(None)
> + tree.commit('revision 2', rev_id='2')
> + tree.bzrdir.open_repository().copy_content_into(shared_repo)
> + dir = self.make_bzrdir('shared/source')
> + dir.create_branch()
> + target = dir.clone(self.get_url('shared/target'))
> + self.assertNotEqual(dir.transport.base, target.transport.base)
> + self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
> + self.assertTrue(shared_repo.has_revision('1'))
>
> def test_clone_bzrdir_repository_under_shared_force_new_repo(self):
> dir = self.make_bzrdir('source')
> @@ -376,7 +396,7 @@
> self.assertNotEqual(dir.transport.base, target.transport.base)
> self.assertDirectoriesEqual(dir.root_transport, target.root_transport)
>
> - def test_sprout_bzrdir_repository_under_shared(self):
> + def test_sprout_bzrdir_with_repository_to_shared(self):
> tree = self.make_branch_and_tree('commit_tree')
> self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
> tree.add('foo')
> @@ -393,6 +413,26 @@
> return
> target = dir.sprout(self.get_url('target/child'))
> self.assertNotEqual(dir.transport.base, target.transport.base)
> + self.assertTrue(shared_repo.has_revision('1'))
> +
> + def test_sprout_bzrdir_repository_branch_both_under_shared(self):
> + try:
> + shared_repo = self.make_repository('shared', shared=True)
> + except errors.IncompatibleFormat:
> + return
> + tree = self.make_branch_and_tree('commit_tree')
> + self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
> + tree.add('foo')
> + tree.commit('revision 1', rev_id='1')
> + tree.bzrdir.open_branch().set_revision_history([])
> + tree.set_last_revision(None)
> + tree.commit('revision 2', rev_id='2')
> + tree.bzrdir.open_repository().copy_content_into(shared_repo)
> + dir = self.make_bzrdir('shared/source')
> + dir.create_branch()
> + target = dir.sprout(self.get_url('shared/target'))
> + self.assertNotEqual(dir.transport.base, target.transport.base)
> + self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
> self.assertTrue(shared_repo.has_revision('1'))
>
> def test_sprout_bzrdir_repository_under_shared_force_new_repo(self):
>
> === modified file 'bzrlib/tests/repository_implementations/test_repository.py'
> --- bzrlib/tests/repository_implementations/test_repository.py
> +++ bzrlib/tests/repository_implementations/test_repository.py
> @@ -195,6 +195,16 @@
> # makes a this-version repo:
> repo_c = self.make_repository('c')
> check_push_rev1(repo_c)
> +
> + def test_fetch_missing_revision_same_location_fails(self):
> + repo_a = self.make_repository('.')
> + repo_b = repository.Repository.open('.')
> + self.assertRaises(errors.NoSuchRevision, repo_b.fetch, repo_a, revision_id='XXX')
> +
> + def test_fetch_same_location_trivial_works(self):
> + repo_a = self.make_repository('.')
> + repo_b = repository.Repository.open('.')
> + repo_a.fetch(repo_b)
>
> def test_clone_bzrdir_repository_revision(self):
> # make a repository with some revisions,
>
The tests look good. +1 from me (if this hasn't already been merged).
It is nice to review a patch from you with less than 1000 lines for once. :)
John
=:->
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 249 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060221/31068411/attachment.pgp
More information about the bazaar
mailing list