[PATCH] alternative patch for issue 1364 - take 2 with crew notes incorporated

Petr Kodl petrkodl at gmail.com
Sat Nov 1 11:47:44 CDT 2008


# HG changeset patch
# User Petr Kodl <petrkodl at gmail.com>
# Date 1225558046 14400
# Node ID f5d9578d068ff6e27488fbd0f9e20a486c165d7c
# Parent  c4461ea8b4c8022568080ecc847ba4ed3e17906c
alternative patch for issue 1364 - take 2 with crew notes incorporated

Disable osutil.c and related optimizations for Python < 2.5 on Win32.

osutil.c uses Win32 API instead of msvcrt calls which leads to inconsistent
DST offset handling between Python lstat modification time and osutil.c reported
values. Starting Python 2.5 lstat is implemented directly as Win32 call and
there is no inconsistency bestween lstat and osutil.c

Also add is_native_module test for easier checking of module type.

diff -r c4461ea8b4c8 -r f5d9578d068f mercurial/util.py
--- a/mercurial/util.py	Sun Oct 26 17:26:28 2008 +0100
+++ b/mercurial/util.py	Sat Nov 01 12:47:26 2008 -0400
@@ -831,6 +831,17 @@
     '''return true if it is safe to hold open file handles to hardlinks'''
     return True
 
+def is_native_module(module):
+    '''return 1 if module is compiled binary or builtin, 0 otherwise'''
+    try:
+        name = module.__file__.lower()
+        for ext in ('.py', '.pyw', '.pyc', '.pyo'):
+            if name.endswith(ext):
+                return 0
+    except AttributeError:
+        pass # builtins do not implementd __file__ attribute
+    return 1
+
 def _statfiles(files):
     'Stat each file in files and yield stat or None if file does not exist.'
     lstat = os.lstat
@@ -874,7 +885,7 @@
             cache = dircache.setdefault(dir, dmap)
         yield cache.get(base, None)
 
-if sys.platform == 'win32':
+if sys.platform == 'win32' and is_native_module(osutil):
     statfiles = _statfiles_clustered
 else:
     statfiles = _statfiles
diff -r c4461ea8b4c8 -r f5d9578d068f setup.py
--- a/setup.py	Sun Oct 26 17:26:28 2008 +0100
+++ b/setup.py	Sat Nov 01 12:47:26 2008 -0400
@@ -103,7 +103,12 @@
 
 try:
     import msvcrt
-    ext_modules.append(Extension('mercurial.osutil', ['mercurial/osutil.c']))
+    import sys
+    # avoid Win32 native osutil for Python < 2.5
+    # Python versions older than 2.5 use msvcrt fstat call
+    # with inconsistent DST time handling
+    if sys.version_info[:2] > (2, 4):
+        ext_modules.append(Extension('mercurial.osutil', ['mercurial/osutil.c']))
 except ImportError:
     pass
 


More information about the Mercurial-devel mailing list