Rev 2409: Add tests for _iter_changes with symlinks, disabled until unversioned file support is added, as that affects the test expected value. in sftp://bazaar.launchpad.net/%7Ebzr/bzr/dirstate/

Robert Collins robertc at robertcollins.net
Mon Feb 26 03:54:31 GMT 2007


At sftp://bazaar.launchpad.net/%7Ebzr/bzr/dirstate/

------------------------------------------------------------
revno: 2409
revision-id: robertc at robertcollins.net-20070226035330-h52h54murds6wmpi
parent: robertc at robertcollins.net-20070226021929-4t98ucfojjx6udtr
committer: Robert Collins <robertc at robertcollins.net>
branch nick: dirstate
timestamp: Mon 2007-02-26 14:53:30 +1100
message:
  Add tests for _iter_changes with symlinks, disabled until unversioned file support is added, as that affects the test expected value.
modified:
  bzrlib/tests/intertree_implementations/test_compare.py test_compare.py-20060724101752-09ysswo1a92uqyoz-2
  bzrlib/workingtree_4.py        workingtree_4.py-20070208044105-5fgpc5j3ljlh5q6c-1
=== modified file 'bzrlib/tests/intertree_implementations/test_compare.py'
--- a/bzrlib/tests/intertree_implementations/test_compare.py	2007-02-26 02:19:29 +0000
+++ b/bzrlib/tests/intertree_implementations/test_compare.py	2007-02-26 03:53:30 +0000
@@ -322,6 +322,21 @@
                 (None, entry.name), (None, entry.kind),
                 (None, entry.executable))
 
+    def content_changed(self, tree, file_id):
+        entry = tree.inventory[file_id]
+        path = tree.id2path(file_id)
+        return (file_id, path, True, (True, True), (entry.parent_id, entry.parent_id),
+                (entry.name, entry.name), (entry.kind, entry.kind),
+                (entry.executable, entry.executable))
+
+    def kind_changed(self, from_tree, to_tree, file_id):
+        old_entry = from_tree.inventory[file_id]
+        new_entry = to_tree.inventory[file_id]
+        path = to_tree.id2path(file_id)
+        return (file_id, path, True, (True, True), (old_entry.parent_id, new_entry.parent_id),
+                (old_entry.name, new_entry.name), (old_entry.kind, new_entry.kind),
+                (old_entry.executable, new_entry.executable))
+
     def deleted(self, tree, file_id):
         entry = tree.inventory[file_id]
         path = tree.id2path(file_id)
@@ -329,11 +344,21 @@
                 (entry.name, None), (entry.kind, None),
                 (entry.executable, None))
 
+    def unchanged(self, tree, file_id):
+        entry = tree.inventory[file_id]
+        parent = entry.parent_id
+        name = entry.name
+        kind = entry.kind
+        executable = entry.executable
+        return (file_id, tree.id2path(file_id), False, (True, True),
+               (parent, parent), (name, name), (kind, kind),
+               (executable, executable))
+
     def unversioned(self, tree, path):
         """Create an unversioned result."""
         _, basename = os.path.split(path)
         kind = file_kind(tree.abspath(path))
-        return (None, path, False, (False, False), (None, None),
+        return (None, path, True, (False, False), (None, None),
                 (None, basename), (None, kind),
                 (None, False))
 
@@ -492,25 +517,16 @@
         self.addCleanup(tree1.unlock)
         tree2.lock_read()
         self.addCleanup(tree2.unlock)
-        def unchanged(file_id):
-            entry = tree1.inventory[file_id]
-            parent = entry.parent_id
-            name = entry.name
-            kind = entry.kind
-            executable = entry.executable
-            return (file_id, tree1.id2path(file_id), False, (True, True),
-                   (parent, parent), (name, name), (kind, kind),
-                   (executable, executable))
-        self.assertEqual(sorted([unchanged(root_id), unchanged('b-id'),
-                          ('a-id', 'd', True, (True, True),
-                          (root_id, root_id), ('a', 'd'), ('file', 'file'),
-                          (False, False)), unchanged('c-id')]),
-                         self.do_iter_changes(tree1, tree2, include_unchanged=True))
+        self.assertEqual(sorted([self.unchanged(tree1, root_id),
+            unchanged(tree1, 'b-id'), ('a-id', 'd', True, (True, True),
+            (root_id, root_id), ('a', 'd'), ('file', 'file'),
+            (False, False)), unchanged(tree1, 'c-id')]),
+            self.do_iter_changes(tree1, tree2, include_unchanged=True))
 
     def _todo_test_unversioned_paths_in_tree(self):
         tree1 = self.make_branch_and_tree('tree1')
         tree2 = self.make_to_branch_and_tree('tree2')
-        self.build_tree(['tree2/file', 'tree2/dir'])
+        self.build_tree(['tree2/file', 'tree2/dir/'])
         # try:
         os.symlink('target', 'tree2/link')
         links_supported = True
@@ -534,7 +550,7 @@
     def _todo_test_unversioned_paths_in_tree_specific_files(self):
         tree1 = self.make_branch_and_tree('tree1')
         tree2 = self.make_to_branch_and_tree('tree2')
-        self.build_tree(['tree2/file', 'tree2/dir'])
+        self.build_tree(['tree2/file', 'tree2/dir/'])
         # try:
         os.symlink('target', 'tree2/link')
         links_supported = True
@@ -557,3 +573,92 @@
         expected = sorted(expected)
         self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
             specific_files=specific_files))
+
+    def make_trees_with_symlinks(self):
+        tree1 = self.make_branch_and_tree('tree1')
+        tree2 = self.make_to_branch_and_tree('tree2')
+        self.build_tree(['tree1/fromfile', 'tree1/fromdir/'])
+        self.build_tree(['tree2/tofile', 'tree2/todir/', 'tree2/unknown'])
+        # try:
+        os.symlink('original', 'tree1/changed')
+        os.symlink('original', 'tree1/removed')
+        os.symlink('original', 'tree1/tofile')
+        os.symlink('original', 'tree1/todir')
+        # we make the unchanged link point at unknown to catch incorrect
+        # symlink-following code in the specified_files test.
+        os.symlink('unknown', 'tree1/unchanged')
+        os.symlink('new',      'tree2/added')
+        os.symlink('new',      'tree2/changed')
+        os.symlink('new',      'tree2/fromfile')
+        os.symlink('new',      'tree2/fromdir')
+        os.symlink('unknown', 'tree2/unchanged')
+        from_paths_and_ids = [
+            'fromdir',
+            'fromfile',
+            'changed',
+            'removed',
+            'todir',
+            'tofile',
+            'unchanged',
+            ]
+        to_paths_and_ids = [
+            'added',
+            'fromdir',
+            'fromfile',
+            'changed',
+            'todir',
+            'tofile',
+            'unchanged',
+            ]
+        tree1.add(from_paths_and_ids, from_paths_and_ids)
+        tree2.add(to_paths_and_ids, to_paths_and_ids)
+        # except ???:
+        #   raise TestSkipped('OS does not support symlinks')
+        #   links_supported = False
+        return self.mutable_trees_to_test_trees(tree1, tree2)
+
+    def _disabled_test_versioned_symlinks(self):
+        tree1, tree2 = self.make_trees_with_symlinks()
+        root_id = tree1.path2id('')
+        tree1.lock_read()
+        self.addCleanup(tree1.unlock)
+        tree2.lock_read()
+        self.addCleanup(tree2.unlock)
+        expected = [
+            self.unchanged(tree1, tree1.path2id('')),
+            self.added(tree2, 'added'),
+            self.content_changed(tree2, 'changed'),
+            self.kind_changed(tree1, tree2, 'fromdir'),
+            self.kind_changed(tree1, tree2, 'fromfile'),
+            self.deleted(tree1, 'removed'),
+            self.unchanged(tree2, 'unchanged'),
+            self.unversioned(tree2, 'unknown'),
+            self.kind_changed(tree1, tree2, 'todir'),
+            self.kind_changed(tree1, tree2, 'tofile'),
+            ]
+        expected = sorted(expected)
+        self.assertEqual(expected, self.do_iter_changes(tree1, tree2, include_unchanged=True))
+
+    def _disabled_test_versioned_symlinks_specific_files(self):
+        tree1, tree2 = self.make_trees_with_symlinks()
+        root_id = tree1.path2id('')
+        tree1.lock_read()
+        self.addCleanup(tree1.unlock)
+        tree2.lock_read()
+        self.addCleanup(tree2.unlock)
+        expected = [
+            self.added(tree2, 'added'),
+            self.content_changed(tree2, 'changed'),
+            self.kind_changed(tree1, tree2, 'fromdir'),
+            self.kind_changed(tree1, tree2, 'fromfile'),
+            self.deleted(tree1, 'removed'),
+            self.kind_changed(tree1, tree2, 'todir'),
+            self.kind_changed(tree1, tree2, 'tofile'),
+            ]
+        expected = sorted(expected)
+        # we should get back just the changed links. We pass in 'unchanged' to
+        # make sure that it is correctly not returned - and neither is the
+        # unknown path 'unknown' which it points at.
+        self.assertEqual(expected, self.do_iter_changes(tree1, tree2,
+            specific_files=['added', 'changed', 'fromdir', 'fromfile',
+            'removed', 'unchanged', 'todir', 'tofile']))

=== modified file 'bzrlib/workingtree_4.py'
--- a/bzrlib/workingtree_4.py	2007-02-26 02:11:26 +0000
+++ b/bzrlib/workingtree_4.py	2007-02-26 03:53:30 +0000
@@ -1560,32 +1560,35 @@
                     old_path = os.path.join(*entry[0][0:2])
                     result.removed.append((old_path, entry[0][2], dirstate.DirState._minikind_to_kind[source_details[0]]))
                 # use the kind from disk.
-                elif source_details[0] != path_info[2][0]:
-                    # different kind
-                    import pdb;pdb.set_trace()
-                    print "kind change"
                 else:
-                    # same kind
+                    # source and target are both versioned and disk file is present.
                     if path_info[2][0] == 'd':
-                        # directories have no fingerprint
-                        content_change = False
-                        executable_change = False
+                        if source_details[0][0] != 'd':
+                            content_change = True
+                        else:
+                            # directories have no fingerprint
+                            content_change = False
                     elif path_info[2][0] == 'f':
-                        # has it changed? fast path: size, slow path: sha1.
-                        executable_change = source_details[3] != bool(
-                            stat.S_ISREG(path_info[3].st_mode)
-                            and stat.S_IEXEC & path_info[3].st_mode)
-                        if source_details[2] != path_info[3].st_size:
-                            content_change = True
-                        else:
-                            # maybe the same. Get the hash
-                            new_hash = self.target._hashcache.get_sha1(path, path_info[3])
-                            content_change = (new_hash != source_details[1])
-                    elif path_info[2][0] == 'l':
-                        import pdb;pdb.set_trace()
-                        print "link"
+                        if source_details[0][0] != 'f':
+                            content_change = True
+                        else:
+                            # has it changed? fast path: size, slow path: sha1.
+                            if source_details[2] != path_info[3].st_size:
+                                content_change = True
+                            else:
+                                # maybe the same. Get the hash
+                                new_hash = self.target._hashcache.get_sha1(path, path_info[3])
+                                content_change = (new_hash != source_details[1])
+                    elif path_info[2][0] == 's':
+                        if source_details[0][0] != 'l':
+                            content_change = True
+                        else:
+                            # TODO: check symlink supported for windows users and grab
+                            # from target state here.
+                            content_change = os.readlink(path_info[4]) != source_details[1]
+                        target_exec = False
                     else:
-                        raise Exception, "unknown minikind"
+                        raise Exception, "unknown kind %s" % path_info[2]
                     # parent id is the entry for the path in the target tree
                     # TODO: the target is the same for an entire directory: cache em.
                     source_parent_id = state._get_entry(source_index, path_utf8=old_dirname)[0][2]



More information about the bazaar-commits mailing list