Rev 2496: Some updates to how we handle the executable bit. In preparation for supporting Win32 in http://bzr.arbash-meinel.com/branches/bzr/experimental/dirstate-nohc

John Arbash Meinel john at arbash-meinel.com
Fri Mar 2 02:12:11 GMT 2007


At http://bzr.arbash-meinel.com/branches/bzr/experimental/dirstate-nohc

------------------------------------------------------------
revno: 2496
revision-id: john at arbash-meinel.com-20070302021159-ioaqbmd0ihuqteav
parent: john at arbash-meinel.com-20070302013806-q40tsj7ohnfz9vj0
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: dirstate-nohc
timestamp: Thu 2007-03-01 20:11:59 -0600
message:
  Some updates to how we handle the executable bit. In preparation for supporting Win32
modified:
  bzrlib/dirstate.py             dirstate.py-20060728012006-d6mvoihjb3je9peu-1
  bzrlib/tests/test_dirstate.py  test_dirstate.py-20060728012006-d6mvoihjb3je9peu-2
  bzrlib/workingtree_4.py        workingtree_4.py-20070208044105-5fgpc5j3ljlh5q6c-1
-------------- next part --------------
=== modified file 'bzrlib/dirstate.py'
--- a/bzrlib/dirstate.py	2007-03-02 01:38:06 +0000
+++ b/bzrlib/dirstate.py	2007-03-02 02:11:59 +0000
@@ -193,12 +193,11 @@
 
 import bisect
 import codecs
-import cStringIO
 import errno
 import os
-import sha
 from stat import S_IEXEC
 import struct
+import sys
 import time
 import zlib
 
@@ -209,12 +208,6 @@
     osutils,
     trace,
     )
-from bzrlib.osutils import (
-    pathjoin,
-    sha_file,
-    sha_string,
-    walkdirs,
-    )
 
 
 class _Bisector(object):
@@ -1125,13 +1118,21 @@
 
     def _is_executable(self, mode, old_executable):
         """Is this file executable?"""
-        # TODO: jam 20070301 Win32 should just return the original value
         return bool(S_IEXEC & mode)
 
+    def _is_executable_win32(self, mode, old_executable):
+        """On win32 the executable bit is stored in the dirstate."""
+        return old_executable
+
+    if sys.platform == 'win32':
+        _is_executable = _is_executable_win32
+
     def _read_link(self, abspath, old_link):
         """Read the target of a symlink"""
         # TODO: jam 200700301 On Win32, this could just return the value
-        #       already in memory.
+        #       already in memory. However, this really needs to be done at a
+        #       higher level, because there either won't be anything on disk,
+        #       or the thing on disk will be a file.
         return os.readlink(abspath)
 
     def get_ghosts(self):

=== modified file 'bzrlib/tests/test_dirstate.py'
--- a/bzrlib/tests/test_dirstate.py	2007-03-02 01:38:06 +0000
+++ b/bzrlib/tests/test_dirstate.py	2007-03-02 02:11:59 +0000
@@ -18,6 +18,7 @@
 
 import bisect
 import os
+import time
 
 from bzrlib import (
     dirstate,
@@ -1319,6 +1320,28 @@
         os.remove('a')
         self.create_and_test_dir(state, entry)
 
+    def test__is_executable_win32(self):
+        state, entry = self.get_state_with_a()
+        self.build_tree(['a'])
+
+        # Make sure we are using the win32 implementation of _is_executable
+        state._is_executable = state._is_executable_win32
+
+        # The file on disk is not executable, but we are marking it as though
+        # it is. With _is_executable_win32 we ignore what is on disk.
+        entry[1][0] = ('f', '', 0, True, dirstate.DirState.NULLSTAT)
+
+        stat_value = os.lstat('a')
+        packed_stat = dirstate.pack_stat(stat_value)
+
+        state.adjust_time(-10) # Make sure everything is new
+        # Make sure it wants to kkkkkkkk
+        state.update_entry(entry, abspath='a', stat_value=stat_value)
+
+        # The row is updated, but the executable bit stays set.
+        digest = 'b50e5406bb5e153ebbeb20268fcf37c87e1ecfb6'
+        self.assertEqual([('f', digest, 14, True, packed_stat)], entry[1])
+
 
 class TestPackStat(TestCaseWithTransport):
 

=== modified file 'bzrlib/workingtree_4.py'
--- a/bzrlib/workingtree_4.py	2007-03-02 01:27:53 +0000
+++ b/bzrlib/workingtree_4.py	2007-03-02 02:11:59 +0000
@@ -1665,7 +1665,9 @@
                             # sha1 hash.
                             content_change = (link_or_sha1 != source_details[1])
                         # Target details is updated at update_entry time
-                        target_exec = target_details[3]
+                        target_exec = bool(
+                            stat.S_ISREG(path_info[3].st_mode)
+                            and stat.S_IEXEC & path_info[3].st_mode)
                     elif target_kind == 'symlink':
                         if source_minikind != 'l':
                             content_change = True
@@ -1723,7 +1725,9 @@
                                                  path_utf8=entry[0][0])[0][2]
                     if parent_id == entry[0][2]:
                         parent_id = None
-                    target_exec = target_details[3]
+                    target_exec = bool(
+                        stat.S_ISREG(path_info[3].st_mode)
+                        and stat.S_IEXEC & path_info[3].st_mode)
                     return ((entry[0][2], path, True,
                             (False, True),
                             (None, parent_id),



More information about the bazaar-commits mailing list