Rev 4328: (Jelmer) Add Tags.rename_revisions(). in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Tue May 5 12:32:46 BST 2009


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 4328
revision-id: pqm at pqm.ubuntu.com-20090505113242-g9477bsuoaswvvje
parent: pqm at pqm.ubuntu.com-20090505094032-o2kvwmfl4dqaf1jr
parent: jelmer at samba.org-20090505102246-q7ebxhsm2nne17lr
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2009-05-05 12:32:42 +0100
message:
  (Jelmer) Add Tags.rename_revisions().
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/tag.py                  tag.py-20070212110532-91cw79inah2cfozx-1
  bzrlib/tests/test_tag.py       test_tag.py-20070212110532-91cw79inah2cfozx-2
    ------------------------------------------------------------
    revno: 4325.2.2
    revision-id: jelmer at samba.org-20090505102246-q7ebxhsm2nne17lr
    parent: jelmer at samba.org-20090504174743-i1k5m3y008ksyl3c
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: bzr.dev
    timestamp: Tue 2009-05-05 12:22:46 +0200
    message:
      Add NEWS item.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
    ------------------------------------------------------------
    revno: 4325.2.1
    revision-id: jelmer at samba.org-20090504174743-i1k5m3y008ksyl3c
    parent: pqm at pqm.ubuntu.com-20090504033314-7mfh3y311028dk2m
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: bzr.dev
    timestamp: Mon 2009-05-04 19:47:43 +0200
    message:
      Add Tags.rename_revisions().
    modified:
      bzrlib/tag.py                  tag.py-20070212110532-91cw79inah2cfozx-1
      bzrlib/tests/test_tag.py       test_tag.py-20070212110532-91cw79inah2cfozx-2
=== modified file 'NEWS'
--- a/NEWS	2009-05-04 07:54:22 +0000
+++ b/NEWS	2009-05-05 11:32:42 +0000
@@ -111,6 +111,9 @@
   refactoring to the core of clone allowing less round trips on new
   branches. (Robert Collins)
 
+* New method ``Tags.rename_revisions`` that can rename revision ids tags
+  are pointing at. (Jelmer Vernooij)
+
 * Updated the bundled ``ConfigObj`` library to 4.6.0 (Matt Nordhoff)
 
 

=== modified file 'bzrlib/tag.py'
--- a/bzrlib/tag.py	2009-03-23 14:59:43 +0000
+++ b/bzrlib/tag.py	2009-05-04 17:47:43 +0000
@@ -67,6 +67,10 @@
         # we never have anything to copy
         pass
 
+    def rename_revisions(self, rename_map):
+        # No tags, so nothing to rename
+        pass
+
     def get_reverse_tag_dict(self):
         # There aren't any tags, so the reverse mapping is empty.
         return {}
@@ -216,6 +220,17 @@
             to_tags.branch.unlock()
         return conflicts
 
+    def rename_revisions(self, rename_map):
+        """Rename revisions in this tags dictionary.
+        
+        :param rename_map: Dictionary mapping old revids to new revids
+        """
+        reverse_tags = self.get_reverse_tag_dict()
+        for revid, names in reverse_tags.iteritems():
+            if revid in rename_map:
+                for name in names:
+                    self.set_tag(name, rename_map[revid])
+
     def _reconcile_tags(self, source_dict, dest_dict, overwrite):
         """Do a two-way merge of two tag dictionaries.
 

=== modified file 'bzrlib/tests/test_tag.py'
--- a/bzrlib/tests/test_tag.py	2009-03-23 14:59:43 +0000
+++ b/bzrlib/tests/test_tag.py	2009-05-04 17:47:43 +0000
@@ -50,6 +50,24 @@
         self.assertEqual(store._deserialize_tag_dict(packed), td)
 
 
+class TestTagRevisionRenames(TestCaseWithTransport):
+
+    def make_branch_supporting_tags(self, relpath):
+        return self.make_branch(relpath, format='dirstate-tags')
+
+    def test_simple(self):
+        store = self.make_branch_supporting_tags('a').tags
+        store.set_tag("foo", "myoldrevid")
+        store.rename_revisions({"myoldrevid": "mynewrevid"})
+        self.assertEquals({"foo": "mynewrevid"}, store.get_tag_dict())
+
+    def test_unknown_ignored(self):
+        store = self.make_branch_supporting_tags('a').tags
+        store.set_tag("foo", "myoldrevid")
+        store.rename_revisions({"anotherrevid": "mynewrevid"})
+        self.assertEquals({"foo": "myoldrevid"}, store.get_tag_dict())
+
+
 class TestTagMerging(TestCaseWithTransport):
 
     def make_knit_branch(self, relpath):




More information about the bazaar-commits mailing list