Rev 121: Simplify replay snapshot functions. in file:///home/jelmer/bzr-rebase/trunk/

Jelmer Vernooij jelmer at samba.org
Sun Feb 1 02:50:44 GMT 2009


At file:///home/jelmer/bzr-rebase/trunk/

------------------------------------------------------------
revno: 121
revision-id: jelmer at samba.org-20090201025043-nh3ce9ox1jy04e33
parent: jelmer at samba.org-20090201012454-kj6i3dedjxvfpt2b
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: trunk
timestamp: Sun 2009-02-01 03:50:43 +0100
message:
  Simplify replay snapshot functions.
modified:
  rebase.py                      rebase.py-20070626221123-ellanmf93nw8z9r1-1
  test_rebase.py                 test_rebase.py-20070626221123-ellanmf93nw8z9r1-2
=== modified file 'rebase.py'
--- a/rebase.py	2009-02-01 01:24:54 +0000
+++ b/rebase.py	2009-02-01 02:50:43 +0000
@@ -17,7 +17,7 @@
 
 from bzrlib.config import Config
 from bzrlib.errors import (BzrError, NoSuchFile, UnknownFormatError,
-                           NoCommonAncestor, UnrelatedBranches)
+                           NoCommonAncestor, NoSuchId, UnrelatedBranches)
 from bzrlib.generate_ids import gen_revision_id
 from bzrlib.graph import FrozenHeadsCache
 from bzrlib.merge import Merger
@@ -325,8 +325,7 @@
         pb.finished()
         
 
-def replay_snapshot(repository, oldrevid, newrevid, new_parents, 
-                    revid_renames, fix_revid=None):
+def replay_snapshot(repository, oldrevid, newrevid, new_parents):
     """Replay a commit by simply commiting the same snapshot with different 
     parents.
 
@@ -334,7 +333,6 @@
     :param oldrevid: Revision id of the revision to copy.
     :param newrevid: Revision id of the revision to create.
     :param new_parents: Revision ids of the new parent revisions.
-    :param revid_renames: Revision id renames for texts.
     """
     assert isinstance(new_parents, tuple), "replay_snapshot: Expected tuple for %r" % new_parents
     mutter('creating copy %r of %r with new parents %r' % 
@@ -356,38 +354,43 @@
         # Check what new_ie.file_id should be
         # use old and new parent inventories to generate new_id map
         fileid_map = map_file_ids(repository, oldrev.parent_ids, new_parents)
-        oldtree = MapTree(repository.revision_tree(oldrevid), fileid_map)
-        total = len(oldtree.inventory)
+        oldtree = repository.revision_tree(oldrevid)
+        mappedtree = MapTree(oldtree, fileid_map)
         pb = ui.ui_factory.nested_progress_bar()
-        i = 0
         try:
-            parent_invs = map(repository.get_revision_inventory, new_parents)
-            for i, (path, old_ie) in enumerate(oldtree.inventory.iter_entries()):
-                pb.update('upgrading file', i, len(oldtree.inventory))
+            old_parent_invs = list(repository.iter_inventories(oldrev.parent_ids))
+            new_parent_invs = list(repository.iter_inventories(new_parents))
+            for i, (path, old_ie) in enumerate(mappedtree.inventory.iter_entries()):
+                pb.update('upgrading file', i, len(mappedtree.inventory))
                 ie = old_ie.copy()
                 # Either this file was modified last in this revision, 
                 # in which case it has to be rewritten
-                if fix_revid is not None:
-                    ie.revision = fix_revid(ie.revision)
-                if ie.revision == oldrevid:
-                    key = (ie.file_id, newrevid)
-                    if repository.texts.get_parent_map([key]):
+                if old_ie.revision == oldrevid:
+                    if repository.texts.has_key((ie.file_id, newrevid)):
+                        # Use the existing text
                         ie.revision = newrevid
                     else:
+                        # Create a new text
                         ie.revision = None
                 else:
                     # or it was already there before the commit, in 
                     # which case the right revision should be used
-                    if revid_renames.has_key(ie.revision):
-                        ie.revision = revid_renames[ie.revision]
-                    # make sure at least one of the new parents contains 
-                    # the ie.file_id, ie.revision combination
-                    if (len(filter(lambda inv: ie.file_id in inv and
-                        inv[ie.file_id].text_sha1 == ie.text_sha1, parent_invs))
-                        == 0):
-                        raise ReplayParentsInconsistent(ie.file_id, ie.revision)
-                builder.record_entry_contents(ie, parent_invs, path, oldtree,
-                        oldtree.path_content_summary(path))
+                    # one of the old parents had this revision, so find that
+                    # and then use the matching new parent
+                    old_file_id = oldtree.inventory.path2id(path)
+                    assert old_file_id is not None
+                    ie = None
+                    for (old_pinv, new_pinv) in zip(old_parent_invs, new_parent_invs):
+                        if (old_pinv.has_id(old_file_id) and
+                            old_pinv[old_file_id].revision == old_ie.revision):
+                            try:
+                                ie = new_pinv[old_ie.file_id].copy()
+                            except NoSuchId:
+                                raise ReplayParentsInconsistent(old_ie.file_id, old_ie.revision)
+                            break
+                    assert ie is not None
+                builder.record_entry_contents(ie, new_parent_invs, path, mappedtree,
+                        mappedtree.path_content_summary(path))
         finally:
             pb.finished()
         builder.finish_inventory()

=== modified file 'test_rebase.py'
--- a/test_rebase.py	2008-08-31 20:30:21 +0000
+++ b/test_rebase.py	2009-02-01 02:50:43 +0000
@@ -75,7 +75,7 @@
 
         wt.branch.repository.lock_write()
         newrev = replay_snapshot(wt.branch.repository, "bla2", "bla4", 
-                ("bloe",), {"bla": "bloe"})
+                ("bloe",))
         self.assertEqual("bla4", newrev)
         self.assertTrue(wt.branch.repository.has_revision(newrev))
         self.assertEqual(("bloe",), 
@@ -352,8 +352,7 @@
         wt.add(["afile"])
         wt.commit("bla", rev_id="oldcommit")
         wt.branch.repository.lock_write()
-        replay_snapshot(wt.branch.repository, "oldcommit", "newcommit", (),
-                        {})
+        replay_snapshot(wt.branch.repository, "oldcommit", "newcommit", ())
         wt.branch.repository.unlock()
         oldrev = wt.branch.repository.get_revision("oldcommit")
         newrev = wt.branch.repository.get_revision("newcommit")
@@ -381,8 +380,7 @@
         wt.branch.repository.lock_write()
         self.assertRaises(
                 ReplayParentsInconsistent, replay_snapshot, 
-                wt.branch.repository, "oldcommit", "newcommit", 
-                ("base",), {"oldparent": "base"})
+                wt.branch.repository, "oldcommit", "newcommit", ("base",))
         wt.branch.repository.unlock()
 
     def test_two_revisions(self):
@@ -400,7 +398,7 @@
         wt.branch.repository.fetch(oldrepos)
         wt.branch.repository.lock_write()
         replay_snapshot(wt.branch.repository, "oldcommit", "newcommit", 
-                ("newparent",), {"oldparent": "newparent"})
+                ("newparent",))
         wt.branch.repository.unlock()
         oldrev = wt.branch.repository.get_revision("oldcommit")
         newrev = wt.branch.repository.get_revision("newcommit")
@@ -427,10 +425,8 @@
         wt.commit("bla", rev_id="newparent")
         wt.branch.repository.fetch(oldrepos)
         wt.branch.repository.lock_write()
-        self.assertRaises(ReplayParentsInconsistent, 
-                          replay_snapshot, wt.branch.repository, 
-                          "oldcommit", "newcommit", 
-                        ("newparent",), revid_renames={})
+        replay_snapshot(wt.branch.repository, "oldcommit", "newcommit", 
+                        ("newparent",))
         wt.branch.repository.unlock()
 
     def test_multi_revisions(self):
@@ -458,8 +454,7 @@
         wt.branch.repository.fetch(oldrepos)
         wt.branch.repository.lock_write()
         replay_snapshot(wt.branch.repository, "oldcommit", "newcommit", 
-                ("newparent",), {"oldgrandparent": "newgrandparent", 
-                                "oldparent": "newparent"})
+                ("newparent",))
         wt.branch.repository.unlock()
         oldrev = wt.branch.repository.get_revision("oldcommit")
         newrev = wt.branch.repository.get_revision("newcommit")
@@ -489,7 +484,7 @@
         wt.branch.repository.fetch(oldrepos)
         wt.branch.repository.lock_write()
         replay_snapshot(wt.branch.repository, "oldcommit", "newcommit", 
-                ("newparent",), {"oldparent": "newparent"})
+                ("newparent",))
         wt.branch.repository.unlock()
         oldrev = wt.branch.repository.get_revision("oldcommit")
         newrev = wt.branch.repository.get_revision("newcommit")




More information about the bazaar-commits mailing list