Rev 2915: Switch around to properly look up the executable bit in the basis. in http://bzr.arbash-meinel.com/branches/bzr/0.92-dev/dirstate_error_149113

John Arbash Meinel john at arbash-meinel.com
Wed Oct 17 18:09:53 BST 2007


At http://bzr.arbash-meinel.com/branches/bzr/0.92-dev/dirstate_error_149113

------------------------------------------------------------
revno: 2915
revision-id: john at arbash-meinel.com-20071017170306-20w50sk1djh0i14k
parent: john at arbash-meinel.com-20071017164405-fzauwbvx9wbwbtt5
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: dirstate_error_149113
timestamp: Wed 2007-10-17 12:03:06 -0500
message:
  Switch around to properly look up the executable bit in the basis.
  We do this with a load-time switch around supports_executable(), rather than
  a runtime if supports_executable() check.
  It would be nice to inline the _is_executable_* check on platforms that support
  executable, but we had a function call before, so we haven't degraded
  performance.
modified:
  bzrlib/tests/test_workingtree.py testworkingtree.py-20051004024258-b88d0fe8f101d468
  bzrlib/tests/workingtree_implementations/test_executable.py test_executable.py-20060628162557-tr7h57kl80l3ma8i-1
  bzrlib/workingtree.py          workingtree.py-20050511021032-29b6ec0a681e02e3
  bzrlib/workingtree_4.py        workingtree_4.py-20070208044105-5fgpc5j3ljlh5q6c-1
-------------- next part --------------
=== modified file 'bzrlib/tests/test_workingtree.py'
--- a/bzrlib/tests/test_workingtree.py	2007-10-16 22:12:59 +0000
+++ b/bzrlib/tests/test_workingtree.py	2007-10-17 17:03:06 +0000
@@ -219,35 +219,6 @@
         tree._control_files._transport.delete("pending-merges")
         self.assertEqual([], tree.get_parent_ids())
 
-    def test_commit_with_exec_from_basis(self):
-        tree = self.make_branch_and_tree('tree',
-                format=bzrdir.format_registry.get('knit')())
-        self.build_tree(['tree/file'])
-        tree.add(['file'], ['file-id'])
-        tree._is_executable_from_path_and_stat = \
-            tree._is_executable_from_path_and_stat_from_basis
-        rev_id1 = tree.commit('one')
-        rev_tree1 = tree.branch.repository.revision_tree(rev_id1)
-        self.assertFalse(rev_tree1.inventory['file-id'].executable)
-        tree.lock_write()
-        try:
-            tree._inventory['file-id'].executable = True
-            rev_id2 = tree.commit('two')
-        finally:
-            tree.unlock()
-        rev_tree2 = tree.branch.repository.revision_tree(rev_id2)
-        self.assertTrue(rev_tree2.inventory['file-id'].executable)
-
-        # Now set it back to False, and make sure that is preserved
-        tree.lock_write()
-        try:
-            tree._inventory['file-id'].executable = False
-            rev_id3 = tree.commit('four')
-        finally:
-            tree.unlock()
-        rev_tree3 = tree.branch.repository.revision_tree(rev_id3)
-        self.assertFalse(rev_tree3.inventory['file-id'].executable)
-
 
 class TestFormat2WorkingTree(TestCaseWithTransport):
     """Tests that are specific to format 2 trees."""

=== modified file 'bzrlib/tests/workingtree_implementations/test_executable.py'
--- a/bzrlib/tests/workingtree_implementations/test_executable.py	2007-08-29 16:09:51 +0000
+++ b/bzrlib/tests/workingtree_implementations/test_executable.py	2007-10-17 17:03:06 +0000
@@ -18,6 +18,9 @@
 
 import os
 
+from bzrlib import (
+    osutils,
+    )
 from bzrlib.inventory import InventoryFile
 from bzrlib.transform import TreeTransform
 from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
@@ -175,3 +178,22 @@
         self.wt.revert(old_tree=rev_tree, backups=False)
         self.check_exist(self.wt)
 
+    def test_commit_with_exec_from_basis(self):
+        self.wt._is_executable_from_path_and_stat = \
+            self.wt._is_executable_from_path_and_stat_from_basis
+        rev_id1 = self.wt.commit('one')
+        rev_tree1 = self.wt.branch.repository.revision_tree(rev_id1)
+        a_executable = rev_tree1.inventory[self.a_id].executable
+        b_executable = rev_tree1.inventory[self.b_id].executable
+        self.assertIsNot(None, a_executable)
+        self.assertTrue(a_executable)
+        self.assertIsNot(None, b_executable)
+        self.assertFalse(b_executable)
+
+    def test_use_exec_from_basis(self):
+        if osutils.supports_executable():
+            self.assertEqual(self.wt._is_executable_from_path_and_stat_from_stat,
+                             self.wt._is_executable_from_path_and_stat)
+        else:
+            self.assertEqual(self.wt._is_executable_from_path_and_stat_from_basis,
+                             self.wt._is_executable_from_path_and_stat)

=== modified file 'bzrlib/workingtree.py'
--- a/bzrlib/workingtree.py	2007-10-16 22:12:59 +0000
+++ b/bzrlib/workingtree.py	2007-10-17 17:03:06 +0000
@@ -612,7 +612,7 @@
             return self._inventory[file_id].executable
 
         _is_executable_from_path_and_stat = \
-            _is_executable_from_path_and_stat_from_stat
+            _is_executable_from_path_and_stat_from_basis
     else:
         def is_executable(self, file_id, path=None):
             if not path:
@@ -621,7 +621,7 @@
             return bool(stat.S_ISREG(mode) and stat.S_IEXEC & mode)
 
         _is_executable_from_path_and_stat = \
-            _is_executable_from_path_and_stat_from_basis
+            _is_executable_from_path_and_stat_from_stat
 
     @needs_tree_write_lock
     def _add(self, files, ids, kinds):

=== modified file 'bzrlib/workingtree_4.py'
--- a/bzrlib/workingtree_4.py	2007-10-09 06:28:04 +0000
+++ b/bzrlib/workingtree_4.py	2007-10-17 17:03:06 +0000
@@ -467,6 +467,12 @@
         path_utf8 = osutils.pathjoin(entry[0][0], entry[0][1])
         return path_utf8.decode('utf8')
 
+    def _is_executable_from_path_and_stat_from_basis(self, path, stat_result):
+        entry = self._get_entry(path=path)
+        if entry == (None, None):
+            return False # Missing entries are not executable
+        return entry[1][0][3] # Executable?
+
     if not osutils.supports_executable():
         def is_executable(self, file_id, path=None):
             """Test if a file is executable or not.
@@ -477,6 +483,9 @@
             if entry == (None, None):
                 return False
             return entry[1][0][3]
+
+        _is_executable_from_path_and_stat = \
+            _is_executable_from_path_and_stat_from_basis
     else:
         def is_executable(self, file_id, path=None):
             """Test if a file is executable or not.



More information about the bazaar-commits mailing list