Rev 2811: merge push|pull --overwrite and tweak in http://sourcefrog.net/bzr/tag-overwrite
Martin Pool
mbp at sourcefrog.net
Tue Sep 11 01:15:58 BST 2007
At http://sourcefrog.net/bzr/tag-overwrite
------------------------------------------------------------
revno: 2811
revision-id: mbp at sourcefrog.net-20070911001556-7lji6zrw4xw9vv1f
parent: pqm at pqm.ubuntu.com-20070910121243-ccy1gej0kqy4feen
parent: lalinsky at gmail.com-20070907113713-9xb7l82n81g2amdn
committer: Martin Pool <mbp at sourcefrog.net>
branch nick: tag-overwrite
timestamp: Tue 2007-09-11 10:15:56 +1000
message:
merge push|pull --overwrite and tweak
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/tag.py tag.py-20070212110532-91cw79inah2cfozx-1
bzrlib/tests/test_tag.py test_tag.py-20070212110532-91cw79inah2cfozx-2
------------------------------------------------------------
revno: 2804.3.1
revision-id: lalinsky at gmail.com-20070907113713-9xb7l82n81g2amdn
parent: pqm at pqm.ubuntu.com-20070906063814-iiwx3hccoukt499k
committer: Lukáš Lalinský <lalinsky at gmail.com>
branch nick: overwrite-tags
timestamp: Fri 2007-09-07 13:37:13 +0200
message:
Overwrite conflicting tags by push|pull --overwrite.
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/tag.py tag.py-20070212110532-91cw79inah2cfozx-1
bzrlib/tests/test_tag.py test_tag.py-20070212110532-91cw79inah2cfozx-2
=== modified file 'NEWS'
--- a/NEWS 2007-09-10 08:00:59 +0000
+++ b/NEWS 2007-09-11 00:15:56 +0000
@@ -126,6 +126,9 @@
* Prompt for an ftp password if none is provided.
(Vincent Ladeuil, #137044)
+ * Overwrite conflicting tags by ``push`` and ``pull`` if the
+ ``--overwrite`` option is specified. (Lukáš Lalinský, #93947)
+
IMPROVEMENTS:
* Add the option "--show-diff" to the commit command in order to display
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py 2007-08-27 08:38:37 +0000
+++ b/bzrlib/branch.py 2007-09-07 11:37:13 +0000
@@ -1485,7 +1485,7 @@
if stop_revision is None:
stop_revision = source.last_revision()
self.generate_revision_history(stop_revision)
- result.tag_conflicts = source.tags.merge_to(self.tags)
+ result.tag_conflicts = source.tags.merge_to(self.tags, overwrite)
result.new_revno, result.new_revid = self.last_revision_info()
if _hook_master:
result.master_branch = _hook_master
@@ -1594,7 +1594,7 @@
raise
if overwrite:
target.set_revision_history(self.revision_history())
- result.tag_conflicts = self.tags.merge_to(target.tags)
+ result.tag_conflicts = self.tags.merge_to(target.tags, overwrite)
result.new_revno, result.new_revid = target.last_revision_info()
return result
=== modified file 'bzrlib/tag.py'
--- a/bzrlib/tag.py 2007-09-10 09:55:45 +0000
+++ b/bzrlib/tag.py 2007-09-11 00:15:56 +0000
@@ -62,7 +62,7 @@
lookup_tag = _not_supported
delete_tag = _not_supported
- def merge_to(self, to_tags):
+ def merge_to(self, to_tags, overwrite=False):
# we never have anything to copy
pass
@@ -170,7 +170,7 @@
raise ValueError("failed to deserialize tag dictionary %r: %s"
% (tag_content, e))
- def merge_to(self, to_tags):
+ def merge_to(self, to_tags, overwrite=False):
"""Copy tags between repositories if necessary and possible.
This method has common command-line behaviour about handling
@@ -180,9 +180,7 @@
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
- TagsNotSupported (default).
+ :param overwrite: Overwrite conflicting tags in the target branch
:returns: A list of tags that conflicted, each of which is
(tagname, source_target, dest_target).
@@ -200,20 +198,22 @@
to_tags.branch.lock_write()
try:
dest_dict = to_tags.get_tag_dict()
- result, conflicts = self._reconcile_tags(source_dict, dest_dict)
+ result, conflicts = self._reconcile_tags(source_dict, dest_dict,
+ overwrite)
if result != dest_dict:
to_tags._set_tag_dict(result)
finally:
to_tags.branch.unlock()
return conflicts
- def _reconcile_tags(self, source_dict, dest_dict):
+ def _reconcile_tags(self, source_dict, dest_dict, overwrite):
"""Do a two-way merge of two tag dictionaries.
only in source => source value
only in destination => destination value
same definitions => that
- different definitions => keep destination value, give a warning
+ different definitions => if overwrite is False, keep destination
+ value and give a warning, otherwise use the source value
:returns: (result_dict,
[(conflicting_tag, source_target, dest_target)])
@@ -221,7 +221,7 @@
conflicts = []
result = dict(dest_dict) # copy
for name, target in source_dict.items():
- if name not in result:
+ if name not in result or overwrite:
result[name] = target
elif result[name] == target:
pass
=== modified file 'bzrlib/tests/test_tag.py'
--- a/bzrlib/tests/test_tag.py 2007-03-14 03:42:40 +0000
+++ b/bzrlib/tests/test_tag.py 2007-09-07 11:37:13 +0000
@@ -78,3 +78,23 @@
old_branch.tags.merge_to(new_branch.tags)
self.assertRaises(errors.TagsNotSupported,
new_branch.tags.merge_to, old_branch.tags)
+
+ def test_merge_to(self):
+ a = self.make_branch_supporting_tags('a')
+ b = self.make_branch_supporting_tags('b')
+ # simple merge
+ a.tags.set_tag('tag-1', 'x')
+ b.tags.set_tag('tag-2', 'y')
+ a.tags.merge_to(b.tags)
+ self.assertEqual('x', b.tags.lookup_tag('tag-1'))
+ self.assertEqual('y', b.tags.lookup_tag('tag-2'))
+ self.assertRaises(errors.NoSuchTag, a.tags.lookup_tag, 'tag-2')
+ # conflicting merge
+ a.tags.set_tag('tag-2', 'z')
+ conflicts = a.tags.merge_to(b.tags)
+ self.assertEqual(conflicts, [('tag-2', 'z', 'y')])
+ self.assertEqual('y', b.tags.lookup_tag('tag-2'))
+ # overwrite conflicts
+ conflicts = a.tags.merge_to(b.tags, overwrite=True)
+ self.assertEqual(conflicts, [])
+ self.assertEqual('z', b.tags.lookup_tag('tag-2'))
More information about the bazaar-commits
mailing list