Rev 2252: Slightly smarter tag merge in http://sourcefrog.net/bzr/tags
Martin Pool
mbp at sourcefrog.net
Thu Feb 22 05:03:52 GMT 2007
At http://sourcefrog.net/bzr/tags
------------------------------------------------------------
revno: 2252
revision-id: mbp at sourcefrog.net-20070222050352-98ohnhisvcc71ela
parent: mbp at sourcefrog.net-20070222045206-zxhd8xxpepbuw8uj
committer: Martin Pool <mbp at sourcefrog.net>
branch nick: tags
timestamp: Thu 2007-02-22 16:03:52 +1100
message:
Slightly smarter tag merge
modified:
BRANCH.TODO BRANCH.TODO-20060103052123-79ac4969351c03a9
bzrlib/tag.py tag.py-20070212110532-91cw79inah2cfozx-1
bzrlib/tests/branch_implementations/test_tags.py test_tags.py-20070212110545-w2s799hm2jlbsmg5-1
=== modified file 'BRANCH.TODO'
--- a/BRANCH.TODO 2007-02-22 04:39:08 +0000
+++ b/BRANCH.TODO 2007-02-22 05:03:52 +0000
@@ -60,6 +60,7 @@
- copy only selected tags
- refuse to add tags if the tag is already present, but allow it to
be forced
+ - maybe rename merge_to to merge_from (and invert the code)?
Later
=== modified file 'bzrlib/tag.py'
--- a/bzrlib/tag.py 2007-02-22 04:39:08 +0000
+++ b/bzrlib/tag.py 2007-02-22 05:03:52 +0000
@@ -153,14 +153,17 @@
return r
except ValueError, e:
raise ValueError("failed to deserialize tag dictionary %r: %s"
- % (tag_content, e))
+ % (tag_content, e))
- def merge_to(self, to_tags, just_warn=False):
+ def merge_to(self, to_tags):
"""Copy tags between repositories if necessary and possible.
This method has common command-line behaviour about handling
error cases.
+ All new definitions are copied across, except that tags that already
+ exist keep their existing definitions.
+
:param to_tags: Branch to receive these tags
:param just_warn: If the destination doesn't support tags and the
source does have tags, just give a warning. Otherwise, raise
@@ -171,17 +174,26 @@
if not self.supports_tags():
# obviously nothing to copy
return
- td = self.get_tag_dict()
- if not td:
+ source_dict = self.get_tag_dict()
+ if not source_dict:
# no tags in the source, and we don't want to clobber anything
# that's in the destination
return
to_tags.branch.lock_write()
try:
- to_tags._set_tag_dict(td)
+ dest_dict = to_tags.get_tag_dict()
+ result = self._reconcile_tags(source_dict, dest_dict)
+ if result != dest_dict:
+ to_tags._set_tag_dict(result)
finally:
to_tags.branch.unlock()
+ def _reconcile_tags(self, source_dict, dest_dict):
+ """Return the result of a two-way merge of tags"""
+ result = dict(source_dict)
+ result.update(dest_dict)
+ return result
+
def _merge_tags_if_possible(from_branch, to_branch):
from_branch.tags.merge_to(to_branch.tags)
=== modified file 'bzrlib/tests/branch_implementations/test_tags.py'
--- a/bzrlib/tests/branch_implementations/test_tags.py 2007-02-22 04:52:06 +0000
+++ b/bzrlib/tests/branch_implementations/test_tags.py 2007-02-22 05:03:52 +0000
@@ -86,6 +86,11 @@
b1.tags.set_tag('tagname', 'revid')
b1.tags.merge_to(b2.tags)
self.assertEquals(b2.tags.lookup_tag('tagname'), 'revid')
+ # if a tag is in the destination and not in the source, it is not
+ # removed when we merge them
+ b2.tags.set_tag('in-destination', 'revid')
+ b1.tags.merge_to(b2.tags)
+ self.assertEquals(b2.tags.lookup_tag('in-destination'), 'revid')
def test_unicode_tag(self):
b1 = self.make_branch('b')
More information about the bazaar-commits
mailing list