Rev 2253: Start support for flagging tag conflicts in http://sourcefrog.net/bzr/tags

Martin Pool mbp at sourcefrog.net
Thu Feb 22 05:49:04 GMT 2007


At http://sourcefrog.net/bzr/tags

------------------------------------------------------------
revno: 2253
revision-id: mbp at sourcefrog.net-20070222054903-nmadtvw96a88uq2w
parent: mbp at sourcefrog.net-20070222050352-98ohnhisvcc71ela
committer: Martin Pool <mbp at sourcefrog.net>
branch nick: tags
timestamp: Thu 2007-02-22 16:49:03 +1100
message:
  Start support for flagging tag conflicts
modified:
  BRANCH.TODO                    BRANCH.TODO-20060103052123-79ac4969351c03a9
  bzrlib/tag.py                  tag.py-20070212110532-91cw79inah2cfozx-1
  bzrlib/tests/blackbox/test_tags.py test_tags.py-20070116132048-5h4qak2cm22jlb9e-1
  bzrlib/tests/branch_implementations/test_tags.py test_tags.py-20070212110545-w2s799hm2jlbsmg5-1
=== modified file 'BRANCH.TODO'
--- a/BRANCH.TODO	2007-02-22 05:03:52 +0000
+++ b/BRANCH.TODO	2007-02-22 05:49:03 +0000
@@ -47,6 +47,7 @@
  - delete tags, and mark as deleted
  - command to show all tags
  - make the experimental branch format available through a bzrdir format
+ - if tag already exists, don't overwrite it
 
 Plan
 ----
@@ -57,7 +58,6 @@
  - if tags conflict when copying
    - return them and give a warning
    - option to override this and copy anyhow
- - 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)?
@@ -65,6 +65,7 @@
 
 Later
 -----
+ - copy only selected tags
  - record who set tags, when, why
  - show tags in log
  - test copying tags between different branch formats?  a 

=== modified file 'bzrlib/tag.py'
--- a/bzrlib/tag.py	2007-02-22 05:03:52 +0000
+++ b/bzrlib/tag.py	2007-02-22 05:49:03 +0000
@@ -168,6 +168,9 @@
         :param just_warn: If the destination doesn't support tags and the 
             source does have tags, just give a warning.  Otherwise, raise
             TagsNotSupported (default).
+
+        :returns: A list of tags that conflicted, each of which is 
+            (tagname, source_target, dest_target).
         """
         if self.branch == to_tags.branch:
             return
@@ -182,17 +185,34 @@
         to_tags.branch.lock_write()
         try:
             dest_dict = to_tags.get_tag_dict()
-            result = self._reconcile_tags(source_dict, dest_dict)
+            result, conflicts = self._reconcile_tags(source_dict, dest_dict)
             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):
-        """Return the result of a two-way merge of tags"""
-        result = dict(source_dict)
-        result.update(dest_dict)
-        return result
+        """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
+
+        :returns: (result_dict,
+            [(conflicting_tag, source_target, dest_target)])
+        """
+        conflicts = []
+        result = dict(dest_dict) # copy
+        for name, target in source_dict.items():
+            if name not in result:
+                result[name] = target
+            elif result[name] == target:
+                pass
+            else:
+                conflicts.append((name, target, result[name]))
+        return result, conflicts
 
 
 def _merge_tags_if_possible(from_branch, to_branch):

=== modified file 'bzrlib/tests/blackbox/test_tags.py'
--- a/bzrlib/tests/blackbox/test_tags.py	2007-02-21 05:08:28 +0000
+++ b/bzrlib/tests/blackbox/test_tags.py	2007-02-22 05:49:03 +0000
@@ -100,5 +100,7 @@
         tagname = u'\u30d0zaar'
         b1.tags.set_tag(tagname, 'revid-1')
         out, err = self.run_bzr('tags', '-d', 'branch1')
-        self.assertEquals(err, '')
+        self.assertEquals(err, '') 
 
+    def test_merge_conflicting_tags(self):
+        pass

=== modified file 'bzrlib/tests/branch_implementations/test_tags.py'
--- a/bzrlib/tests/branch_implementations/test_tags.py	2007-02-22 05:03:52 +0000
+++ b/bzrlib/tests/branch_implementations/test_tags.py	2007-02-22 05:49:03 +0000
@@ -89,8 +89,19 @@
         # 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)
+        result = b1.tags.merge_to(b2.tags)
+        self.assertEquals(result, [])
         self.assertEquals(b2.tags.lookup_tag('in-destination'), 'revid')
+        # if there's a conflicting tag, it's reported -- the command line
+        # interface will say "these tags couldn't be copied"
+        b1.tags.set_tag('conflicts', 'revid-1')
+        b2.tags.set_tag('conflicts', 'revid-2')
+        result = b1.tags.merge_to(b2.tags)
+        self.assertEquals(result,
+            [('conflicts', 'revid-1', 'revid-2')])
+        # and it keeps the same value
+        self.assertEquals(b2.tags.lookup_tag('conflicts'), 'revid-2')
+
 
     def test_unicode_tag(self):
         b1 = self.make_branch('b')




More information about the bazaar-commits mailing list