Handle copy of a file/symlink already modified in this commit
authorIan Clatworthy <ian.clatworthy@canonical.com>
Mon, 24 Aug 2009 02:55:06 +0000 (12:55 +1000)
committerIan Clatworthy <ian.clatworthy@canonical.com>
Mon, 24 Aug 2009 02:55:06 +0000 (12:55 +1000)
bzr_commit_handler.py
tests/test_generic_processor.py

index 74264fe2002c3f1025c92461134377c49da48df0..1a5ab5be2aa21b3e830978211acbc479a04a2c47 100644 (file)
@@ -352,10 +352,11 @@ class GenericCommitHandler(processor.CommitHandler):
         self.record_delete(path, ie)
 
     def _copy_item(self, src_path, dest_path, inv):
-        newly_added = self._new_file_ids.get(src_path)
-        if newly_added:
-            # We've only just added this path earlier in this commit.
-            file_id = newly_added
+        newly_changed = self._new_file_ids.get(src_path) or \
+            self._modified_file_ids.get(src_path)
+        if newly_changed:
+            # We've only just added/changed this path earlier in this commit.
+            file_id = newly_changed
             # note: delta entries look like (old, new, file-id, ie)
             ie = self._delta_entries_by_fileid[file_id][3]
         else:
@@ -367,7 +368,7 @@ class GenericCommitHandler(processor.CommitHandler):
             ie = inv[file_id]
         kind = ie.kind
         if kind == 'file':
-            if newly_added:
+            if newly_changed:
                 content = ''.join(self.lines_for_commit[file_id])
             else:
                 content = self.rev_store.get_file_text(self.parents[0], file_id)
index 30c35271bf2fe9f0c94d4f3a38044047d0299fee..0b6f8f463ccaed8351ffcd3daaca733d576e6b4b 100644 (file)
@@ -1332,98 +1332,103 @@ class TestImportToPackCopyToDeleted(TestCaseForGenericProcessor):
         self.assertSymlinkTarget(branch, revtree2, dest_path, "aaa")
 
 
-#class TestImportToPackCopyModified(TestCaseForGenericProcessor):
-#    """Test copy of a modified file."""
-#
-#    def file_command_iter(self, src_path, dest_path, kind='file'):
-#        # Revno 1: create a file or symlink
-#        # Revno 2: modify and copy it
-#        def command_list():
-#            author = ['', 'bugs@a.com', time.time(), time.timezone]
-#            committer = ['', 'elmer@a.com', time.time(), time.timezone]
-#            def files_one():
-#                yield commands.FileModifyCommand(src_path, kind, False,
-#                        None, "aaa")
-#            yield commands.CommitCommand('head', '1', author,
-#                committer, "commit 1", None, [], files_one)
-#            def files_two():
-#                yield commands.FileModifyCommand(src_path, kind, False,
-#                        None, "bbb")
-#                yield commands.FileCopyCommand(src_path, dest_path)
-#            yield commands.CommitCommand('head', '2', author,
-#                committer, "commit 2", ":1", [], files_two)
-#        return command_list
-#
-#    def test_copy_modified_file_in_root(self):
-#        handler, branch = self.get_handler()
-#        src_path = 'a'
-#        dest_path = 'b'
-#        handler.process(self.file_command_iter(src_path, dest_path))
-#        revtree1, revtree2 = self.assertChanges(branch, 2,
-#            expected_modified=[(src_path,)],
-#            expected_added=[(dest_path,)])
-#        self.assertContent(branch, revtree1, src_path, "aaa")
-#        self.assertContent(branch, revtree2, src_path, "bbb")
-#        self.assertContent(branch, revtree2, dest_path, "bbb")
-#        self.assertRevisionRoot(revtree1, src_path)
-#        self.assertRevisionRoot(revtree2, dest_path)
-#
-#    def test_copy_modified_file_in_subdir(self):
-#        handler, branch = self.get_handler()
-#        src_path = 'a/a'
-#        dest_path = 'a/b'
-#        handler.process(self.file_command_iter(src_path, dest_path))
-#        revtree1, revtree2 = self.assertChanges(branch, 2,
-#            expected_added=[(dest_path,)])
-#        self.assertContent(branch, revtree1, src_path, "aaa")
-#        self.assertContent(branch, revtree2, src_path, "aaa")
-#        self.assertContent(branch, revtree2, dest_path, "bbb")
-#
-#    def test_copy_modified_file_to_new_dir(self):
-#        handler, branch = self.get_handler()
-#        src_path = 'a/a'
-#        dest_path = 'b/a'
-#        handler.process(self.file_command_iter(src_path, dest_path))
-#        revtree1, revtree2 = self.assertChanges(branch, 2,
-#            expected_added=[('b',), (dest_path,)])
-#        self.assertContent(branch, revtree1, src_path, "aaa")
-#        self.assertContent(branch, revtree2, src_path, "aaa")
-#        self.assertContent(branch, revtree2, dest_path, "bbb")
-#
-#    def test_copy_modified_symlink_in_root(self):
-#        handler, branch = self.get_handler()
-#        src_path = 'a'
-#        dest_path = 'b'
-#        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
-#        revtree1, revtree2 = self.assertChanges(branch, 2,
-#            expected_added=[(dest_path,)])
-#        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
-#        self.assertSymlinkTarget(branch, revtree2, src_path, "aaa")
-#        self.assertSymlinkTarget(branch, revtree2, dest_path, "bbb")
-#        self.assertRevisionRoot(revtree1, src_path)
-#        self.assertRevisionRoot(revtree2, dest_path)
-#
-#    def test_copy_modified_symlink_in_subdir(self):
-#        handler, branch = self.get_handler()
-#        src_path = 'a/a'
-#        dest_path = 'a/b'
-#        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
-#        revtree1, revtree2 = self.assertChanges(branch, 2,
-#            expected_added=[(dest_path,)])
-#        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
-#        self.assertSymlinkTarget(branch, revtree2, src_path, "aaa")
-#        self.assertSymlinkTarget(branch, revtree2, dest_path, "bbb")
-#
-#    def test_copy_modified_symlink_to_new_dir(self):
-#        handler, branch = self.get_handler()
-#        src_path = 'a/a'
-#        dest_path = 'b/a'
-#        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
-#        revtree1, revtree2 = self.assertChanges(branch, 2,
-#            expected_added=[('b',), (dest_path,)])
-#        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
-#        self.assertSymlinkTarget(branch, revtree2, src_path, "aaa")
-#        self.assertSymlinkTarget(branch, revtree2, dest_path, "bbb")
+class TestImportToPackCopyModified(TestCaseForGenericProcessor):
+    """Test copy of file/symlink already modified in this commit."""
+
+    def file_command_iter(self, src_path, dest_path, kind='file'):
+        # Revno 1: create a file or symlink
+        # Revno 2: modify and copy it
+        def command_list():
+            author = ['', 'bugs@a.com', time.time(), time.timezone]
+            committer = ['', 'elmer@a.com', time.time(), time.timezone]
+            def files_one():
+                yield commands.FileModifyCommand(src_path, kind, False,
+                        None, "aaa")
+            yield commands.CommitCommand('head', '1', author,
+                committer, "commit 1", None, [], files_one)
+            def files_two():
+                yield commands.FileModifyCommand(src_path, kind, False,
+                        None, "bbb")
+                yield commands.FileCopyCommand(src_path, dest_path)
+            yield commands.CommitCommand('head', '2', author,
+                committer, "commit 2", ":1", [], files_two)
+        return command_list
+
+    def test_copy_of_modified_file_in_root(self):
+        handler, branch = self.get_handler()
+        src_path = 'a'
+        dest_path = 'b'
+        handler.process(self.file_command_iter(src_path, dest_path))
+        revtree1, revtree2 = self.assertChanges(branch, 2,
+            expected_modified=[(src_path,)],
+            expected_added=[(dest_path,)])
+        self.assertContent(branch, revtree1, src_path, "aaa")
+        self.assertContent(branch, revtree2, src_path, "bbb")
+        self.assertContent(branch, revtree2, dest_path, "bbb")
+        self.assertRevisionRoot(revtree1, src_path)
+        self.assertRevisionRoot(revtree2, dest_path)
+
+    def test_copy_of_modified_file_in_subdir(self):
+        handler, branch = self.get_handler()
+        src_path = 'd/a'
+        dest_path = 'd/b'
+        handler.process(self.file_command_iter(src_path, dest_path))
+        revtree1, revtree2 = self.assertChanges(branch, 2,
+            expected_modified=[(src_path,)],
+            expected_added=[(dest_path,)])
+        self.assertContent(branch, revtree1, src_path, "aaa")
+        self.assertContent(branch, revtree2, src_path, "bbb")
+        self.assertContent(branch, revtree2, dest_path, "bbb")
+
+    def test_copy_of_modified_file_to_new_dir(self):
+        handler, branch = self.get_handler()
+        src_path = 'd1/a'
+        dest_path = 'd2/a'
+        handler.process(self.file_command_iter(src_path, dest_path))
+        revtree1, revtree2 = self.assertChanges(branch, 2,
+            expected_modified=[(src_path,)],
+            expected_added=[('d2',), (dest_path,)])
+        self.assertContent(branch, revtree1, src_path, "aaa")
+        self.assertContent(branch, revtree2, src_path, "bbb")
+        self.assertContent(branch, revtree2, dest_path, "bbb")
+
+    def test_copy_of_modified_symlink_in_root(self):
+        handler, branch = self.get_handler()
+        src_path = 'a'
+        dest_path = 'b'
+        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
+        revtree1, revtree2 = self.assertChanges(branch, 2,
+            expected_modified=[(src_path,)],
+            expected_added=[(dest_path,)])
+        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
+        self.assertSymlinkTarget(branch, revtree2, src_path, "bbb")
+        self.assertSymlinkTarget(branch, revtree2, dest_path, "bbb")
+        self.assertRevisionRoot(revtree1, src_path)
+        self.assertRevisionRoot(revtree2, dest_path)
+
+    def test_copy_of_modified_symlink_in_subdir(self):
+        handler, branch = self.get_handler()
+        src_path = 'd/a'
+        dest_path = 'd/b'
+        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
+        revtree1, revtree2 = self.assertChanges(branch, 2,
+            expected_modified=[(src_path,)],
+            expected_added=[(dest_path,)])
+        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
+        self.assertSymlinkTarget(branch, revtree2, src_path, "bbb")
+        self.assertSymlinkTarget(branch, revtree2, dest_path, "bbb")
+
+    def test_copy_of_modified_symlink_to_new_dir(self):
+        handler, branch = self.get_handler()
+        src_path = 'd1/a'
+        dest_path = 'd2/a'
+        handler.process(self.file_command_iter(src_path, dest_path, 'symlink'))
+        revtree1, revtree2 = self.assertChanges(branch, 2,
+            expected_modified=[(src_path,)],
+            expected_added=[('d2',), (dest_path,)])
+        self.assertSymlinkTarget(branch, revtree1, src_path, "aaa")
+        self.assertSymlinkTarget(branch, revtree2, src_path, "bbb")
+        self.assertSymlinkTarget(branch, revtree2, dest_path, "bbb")
 
 
 class TestImportToPackFileKinds(TestCaseForGenericProcessor):
@@ -1494,6 +1499,9 @@ class TestImportToRichRootCopyNew(TestImportToPackCopyNew):
 class TestImportToRichRootCopyToDeleted(TestImportToPackCopyToDeleted):
     branch_format = "1.9-rich-root"
 
+class TestImportToRichRootCopyModified(TestImportToPackCopyModified):
+    branch_format = "1.9-rich-root"
+
 class TestImportToRichRootFileKinds(TestImportToPackFileKinds):
     branch_format = "1.9-rich-root"
 
@@ -1545,6 +1553,9 @@ try:
     class TestImportToChkCopyToDeleted(TestImportToPackCopyToDeleted):
         branch_format = "2a"
 
+    class TestImportToChkCopyModified(TestImportToPackCopyModified):
+        branch_format = "2a"
+
     class TestImportToChkFileKinds(TestImportToPackFileKinds):
         branch_format = "2a"