Rev 4631: Some refactoring to help address bug #531967. in file:///home/vila/src/bzr/experimental/unify-name-conflicts/

Vincent Ladeuil v.ladeuil+lp at free.fr
Fri Mar 5 10:23:55 GMT 2010


At file:///home/vila/src/bzr/experimental/unify-name-conflicts/

------------------------------------------------------------
revno: 4631
revision-id: v.ladeuil+lp at free.fr-20100305102355-fiu8pue5ujd2aux6
parent: v.ladeuil+lp at free.fr-20100304205346-229wleg1jkosmmsl
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: unify-name-conflicts
timestamp: Fri 2010-03-05 11:23:55 +0100
message:
  Some refactoring to help address bug #531967.
  
  * bzrlib/tests/test_conflicts.py:
  (TestParametrizedResolveConflicts.check_resolved): Use 'path' as
  the parameter name as it's clearer than 'item'.
  
  * bzrlib/conflicts.py:
  (PathConflict._resolve): Implement the rename with a proper
  TreeTransform. This doesn't address bug #531967 yet.
  (PathConflict._get_or_infer_file_id): First (unsuccesful) try to
  infer the file-id.
  (ContentsConflict._resolve): Renamed from _take_it.
-------------- next part --------------
=== modified file 'bzrlib/conflicts.py'
--- a/bzrlib/conflicts.py	2010-03-02 07:58:53 +0000
+++ b/bzrlib/conflicts.py	2010-03-05 10:23:55 +0000
@@ -436,6 +436,12 @@
     def action_take_other(self, tree):
         raise NotImplementedError(self.action_take_other)
 
+    def _resolve_with_cleanups(self, tree, *args, **kwargs):
+        tt = transform.TreeTransform(tree)
+        op = cleanup.OperationWithCleanups(self._resolve)
+        op.add_cleanup(tt.finalize)
+        op.run_simple(tt, *args, **kwargs)
+
 
 class PathConflict(Conflict):
     """A conflict was encountered merging file paths"""
@@ -460,8 +466,33 @@
         # No additional files have been generated here
         return []
 
+    def _resolve(self, tt, file_id, path):
+        """Resolve the conflict.
+
+        :param tt: The TreeTransform where the conflict is resolved.
+        :param file_id: The retained file id.
+        :param path: The retained path.
+        """
+        # Rename 'item.suffix_to_remove' (note that if
+        # 'item.suffix_to_remove' has been deleted, this is a no-op)
+        tid = tt.trans_id_file_id(file_id)
+        parent_tid = tt.get_tree_parent(tid)
+        tt.adjust_path(path, parent_tid, tid)
+        tt.apply()
+
+    def _get_or_infer_file_id(self, tree):
+        if self.file_id is not None:
+            return self.file_id
+
+        # Prior to bug #531967, file_id wasn't always set, there may still be
+        # conflict files in the wild so we need to cope with them
+        return tree.path2id(self.conflict_path)
+
     def action_take_this(self, tree):
-        tree.rename_one(self.conflict_path, self.path)
+        file_id = self._get_or_infer_file_id(tree)
+        if file_id is None:
+            import pdb ; pdb.set_trace()
+        self._resolve_with_cleanups(tree, file_id, self.path)
 
     def action_take_other(self, tree):
         # just acccept bzr proposal
@@ -480,7 +511,7 @@
     def associated_filenames(self):
         return [self.path + suffix for suffix in ('.BASE', '.OTHER')]
 
-    def _take_it(self, tt, suffix_to_remove):
+    def _resolve(self, tt, suffix_to_remove):
         """Resolve the conflict.
 
         :param tt: The TreeTransform where the conflict is resolved.
@@ -506,17 +537,11 @@
         tt.adjust_path(self.path, parent_tid, this_tid)
         tt.apply()
 
-    def _take_it_with_cleanups(self, tree, suffix_to_remove):
-        tt = transform.TreeTransform(tree)
-        op = cleanup.OperationWithCleanups(self._take_it)
-        op.add_cleanup(tt.finalize)
-        op.run_simple(tt, suffix_to_remove)
-
     def action_take_this(self, tree):
-        self._take_it_with_cleanups(tree, 'OTHER')
+        self._resolve_with_cleanups(tree, 'OTHER')
 
     def action_take_other(self, tree):
-        self._take_it_with_cleanups(tree, 'THIS')
+        self._resolve_with_cleanups(tree, 'THIS')
 
 
 # FIXME: TextConflict is about a single file-id, there never is a conflict_path

=== modified file 'bzrlib/tests/test_conflicts.py'
--- a/bzrlib/tests/test_conflicts.py	2010-03-04 20:53:46 +0000
+++ b/bzrlib/tests/test_conflicts.py	2010-03-05 10:23:55 +0000
@@ -312,8 +312,8 @@
         _assert_conflict = getattr(self, self._assert_conflict)
         _assert_conflict(c)
 
-    def check_resolved(self, wt, item, action):
-        conflicts.resolve(wt, [item], action=action)
+    def check_resolved(self, wt, path, action):
+        conflicts.resolve(wt, [path], action=action)
         # Check that we don't have any conflicts nor unknown left
         self.assertLength(0, wt.conflicts())
         self.assertLength(0, list(wt.unknowns()))



More information about the bazaar-commits mailing list