Rev 8: Shave off a bit more time by using set_parent_trees instead of set_parent_ids in http://bzr.arbash-meinel.com/plugins/per_file_remerge

John Arbash Meinel john at arbash-meinel.com
Wed Jun 18 17:24:41 BST 2008


At http://bzr.arbash-meinel.com/plugins/per_file_remerge

------------------------------------------------------------
revno: 8
revision-id: john at arbash-meinel.com-20080618162428-ocbq9geijm3pppg5
parent: john at arbash-meinel.com-20080618152746-0o45ad0xxu9x77xg
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: per_file_remerge
timestamp: Wed 2008-06-18 11:24:28 -0500
message:
  Shave off a bit more time by using set_parent_trees instead of set_parent_ids
-------------- next part --------------
=== modified file '__init__.py'
--- a/__init__.py	2008-06-18 15:27:46 +0000
+++ b/__init__.py	2008-06-18 16:24:28 +0000
@@ -44,10 +44,10 @@
         import per_file_remerge
         if merge_type is None:
             merge_type = merge.Merge3Merger
-        tree, relpaths = builtins.tree_files(file_list)
-        tree.lock_tree_write()
+        wt, relpaths = builtins.tree_files(file_list)
+        wt.lock_tree_write()
         try:
-            parent_ids = tree.get_parent_ids()
+            parent_ids = wt.get_parent_ids()
             if len(parent_ids) != 2:
                 raise errors.BzrCommandError(
                     "Sorry, per-file-remerge only works after normal"
@@ -57,29 +57,44 @@
                 # use the list of conflicted files
                 trace.mutter('Doing per-file remerge using the conflict list')
                 relpaths = []
-                for conflict in tree.conflicts():
+                for conflict in wt.conflicts():
                     if conflict.typestring == 'text conflict':
                         relpaths.append(conflict.path)
-            merge_tree = tree.branch.repository.revision_tree(merge_revision_id)
+            # The dirstate probably has quick access to the merge tree,
+            # however, it is unsafe to access it, because we will be removing
+            # it from the dirstate. For now it doesn't seem to help enough to
+            # be worth the risk.
+            locked_trees = []
+            merge_tree = wt.branch.repository.revision_tree(merge_revision_id)
+            merge_tree.lock_read()
+            locked_trees.append(merge_tree)
+            basis_tree = wt.basis_tree()
+            basis_tree.lock_read()
+            locked_trees.append(basis_tree)
+
             num_conflicts = 0
             pb = ui.ui_factory.nested_progress_bar()
             # While remerging, we need to pretend nothing is merged,
             # but restore it at the end
-            tree.set_parent_ids(parent_ids[:1])
+            wt.set_parent_trees([(parent_ids[0], basis_tree)])
             try:
                 num_conflicted = len(relpaths)
                 for idx, relpath in enumerate(relpaths):
                     pb.update('resolving', idx, num_conflicted)
                     trace.mutter('processing file: %s', relpath)
-                    num_conflicts += per_file_remerge._remerge_file(tree,
+                    num_conflicts += per_file_remerge._remerge_file(wt,
                                         relpath, merge_type,
                                         merge_revision_id,
                                         merge_tree)
             finally:
-                tree.set_parent_ids(parent_ids)
+                wt.set_parent_trees([(parent_ids[0], basis_tree),
+                                       (merge_revision_id, merge_tree)])
+                for tree in reversed(locked_trees):
+                    tree.unlock()
+                del locked_trees[:]
                 pb.finished()
         finally:
-            tree.unlock()
+            wt.unlock()
 
         if num_conflicts > 0:
             return 1

=== modified file 'per_file_remerge.py'
--- a/per_file_remerge.py	2008-06-18 15:27:46 +0000
+++ b/per_file_remerge.py	2008-06-18 16:24:28 +0000
@@ -83,8 +83,10 @@
     """Get a Graph object for this file's history."""
     repo = tree.branch.repository
     weave = repo.weave_store.get_weave(file_id, repo.get_transaction())
-    # TODO: Do we want to use a CachingParentsProvider inbetween weave and
-    #       Graph?
+    # Adding a CachingParentsProvider doesn't help much here. We don't revisit
+    # the same revisions very often. And this isn't a strict performance
+    # bottleneck. Revisit if we get rid of the other bottlenecks.
+    # cache = graph.CachingParentsProvider(weave)
     graph_obj = graph.Graph(weave)
     return graph_obj
 



More information about the bazaar-commits mailing list