Rev 2227: Add Repository.copy_tags_to in file:///home/mbp/bzr/Work/tags/
Martin Pool
mbp at sourcefrog.net
Sun Jan 21 08:56:54 GMT 2007
------------------------------------------------------------
revno: 2227
revision-id: mbp at sourcefrog.net-20070121085653-ptonrp6w7ini27un
parent: mbp at sourcefrog.net-20070119084751-zcoq7c4t7yockec1
committer: Martin Pool <mbp at sourcefrog.net>
branch nick: tags
timestamp: Sun 2007-01-21 19:56:53 +1100
message:
Add Repository.copy_tags_to
modified:
bzrlib/repository.py rev_storage.py-20051111201905-119e9401e46257e3
bzrlib/tests/repository_implementations/test_tags.py test_tags.py-20070114073919-azsbo9l26ph1rr09-1
=== modified file 'bzrlib/repository.py'
--- a/bzrlib/repository.py 2007-01-19 02:46:50 +0000
+++ b/bzrlib/repository.py 2007-01-21 08:56:53 +0000
@@ -873,6 +873,17 @@
def get_tag_dict(self):
return self._tag_store.get_tag_dict()
+ def _set_tag_dict(self, new_dict):
+ return self._tag_store._set_tag_dict(new_dict)
+
+ def copy_tags_to(self, to_repository):
+ """Copy tags to another repository.
+
+ Subclasses should not override this, but rather customize copying
+ through the InterRepository mechanism.
+ """
+ return InterRepository.get(self, to_repository).copy_tags()
+
class AllInOneRepository(Repository):
"""Legacy support - the repository behaviour for all-in-one branches."""
@@ -1987,6 +1998,17 @@
# that we've decided we need.
return [rev_id for rev_id in source_ids if rev_id in result_set]
+ def copy_tags(self):
+ """Copy all tags from source to the target."""
+ # A default implementation is provided even though not all
+ # Repositories will support tags... we'll just get an error back from
+ # the underlying method.
+ self.target.lock_write()
+ try:
+ self.target._set_tag_dict(self.source.get_tag_dict())
+ finally:
+ self.target.unlock()
+
class InterSameDataRepository(InterRepository):
"""Code for converting between repositories that represent the same data.
=== modified file 'bzrlib/tests/repository_implementations/test_tags.py'
--- a/bzrlib/tests/repository_implementations/test_tags.py 2007-01-19 08:31:42 +0000
+++ b/bzrlib/tests/repository_implementations/test_tags.py 2007-01-21 08:56:53 +0000
@@ -75,6 +75,14 @@
else:
self.fail("didn't get expected exception")
+ def test_copy_tags(self):
+ repo1 = self.make_repository('repo1')
+ repo2 = self.make_repository('repo2')
+ repo1.set_tag('tagname', 'revid')
+ repo1.copy_tags_to(repo2)
+ self.assertEquals(repo2.lookup_tag('tagname'), 'revid')
+
+
class TestUnsupportedTags(TestCaseWithRepository):
"""Formats that don't support tags should give reasonable errors."""
More information about the bazaar-commits
mailing list