Merge lp:~bialix/bzr/lock-unicode-win32 into lp:~bzr/bzr/trunk-old

Proposed by Alexander Belchenko
Status: Merged
Approved by: John A Meinel
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~bialix/bzr/lock-unicode-win32
Merge into: lp:~bzr/bzr/trunk-old
Diff against target: 67 lines
To merge this branch: bzr merge lp:~bialix/bzr/lock-unicode-win32
Reviewer Review Type Date Requested Status
John A Meinel Approve
bzr-core Pending
Review via email: mp+8305@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Alexander Belchenko (bialix) wrote :

This patch fixes regression in OS locks @ win32 re unicode paths.

Please, merge it to 1.17.

Revision history for this message
John A Meinel (jameinel) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Alexander Belchenko wrote:
> Alexander Belchenko has proposed merging lp:~bialix/bzr/lock-unicode-win32 into lp:bzr.
>
> Requested reviews:
> John A Meinel (jameinel)
> bzr-core (bzr-core)
>
> This patch fixes regression in OS locks @ win32 re unicode paths.
>
> Please, merge it to 1.17.
>

  Review: approve

This seems fine, though I'll note that we haven't use 'os.path.sup..' in
the past to determine W versus A. Why not use:

   # for Windows NT/2K/XP/etc vs Windows 98
   win32file_CreateFile = getattr(win32file, 'CreateFileW',
      win32file.CreateFile)

Also, I thought we used ctypes preferentially to win32file, since that
was "already present in python 2.5", do we need fixes on the ctypes side
as well?

John
=:->

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkpTUB8ACgkQJdeBCYSNAAPt4wCgyg9SKrgwgdy3KpHIT5B6smPP
k9MAoKG5xtvbcKDmDidPAYOQUoEH+QGu
=Ggvf
-----END PGP SIGNATURE-----

Revision history for this message
Alexander Belchenko (bialix) wrote :

John A Meinel пишет:
> Review: approve

Can you merge it, please?

> This seems fine, though I'll note that we haven't use 'os.path.sup..' in
> the past to determine W versus A. Why not use:
>
> # for Windows NT/2K/XP/etc vs Windows 98
> win32file_CreateFile = getattr(win32file, 'CreateFileW',
> win32file.CreateFile)

Because 'CreateFileW' function present even on Windows 98, but it cannot
be actually called.

os.path.supports_unicode_filenames is uised in lock.py in the code
related to ctypes-based locks. So my patch is basically do the same for
win32file-based locks as it works today (in bzr.dev) for ctypes-based locks.

> Also, I thought we used ctypes preferentially to win32file, since that
> was "already present in python 2.5", do we need fixes on the ctypes side
> as well?

As I could see we prefer win32file-based locks, because by default first
defined locks implementation is used by bzrlib API, and win32file-based
is first implementation for win32. IIUC bzr prefer win32file because
it's a C extension around Win32 API, while ctypes is universal FFI and
therefore slower (at least from theory).

Also ctypes-based implementation uses unicode API on Windows NT, and it
successfully passed new unicode tests.

Revision history for this message
John A Meinel (jameinel) :
review: Approve
Revision history for this message
Martin Pool (mbp) wrote :

I'll merge it

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bzrlib/lock.py'
--- bzrlib/lock.py 2009-06-19 10:04:02 +0000
+++ bzrlib/lock.py 2009-07-07 17:35:09 +0000
@@ -301,13 +301,19 @@
301301
302302
303if have_pywin32 and sys.platform == 'win32':303if have_pywin32 and sys.platform == 'win32':
304 if os.path.supports_unicode_filenames:
305 # for Windows NT/2K/XP/etc
306 win32file_CreateFile = win32file.CreateFileW
307 else:
308 # for Windows 98
309 win32file_CreateFile = win32file.CreateFile
304310
305 class _w32c_FileLock(_OSLock):311 class _w32c_FileLock(_OSLock):
306312
307 def _open(self, filename, access, share, cflags, pymode):313 def _open(self, filename, access, share, cflags, pymode):
308 self.filename = osutils.realpath(filename)314 self.filename = osutils.realpath(filename)
309 try:315 try:
310 self._handle = win32file.CreateFile(filename, access, share,316 self._handle = win32file_CreateFile(filename, access, share,
311 None, win32file.OPEN_ALWAYS,317 None, win32file.OPEN_ALWAYS,
312 win32file.FILE_ATTRIBUTE_NORMAL, None)318 win32file.FILE_ATTRIBUTE_NORMAL, None)
313 except pywintypes.error, e:319 except pywintypes.error, e:
314320
=== modified file 'bzrlib/tests/per_lock/__init__.py'
--- bzrlib/tests/per_lock/__init__.py 2009-03-23 14:59:43 +0000
+++ bzrlib/tests/per_lock/__init__.py 2009-07-07 17:35:09 +0000
@@ -39,7 +39,6 @@
39 return result39 return result
4040
4141
42
43def load_tests(standard_tests, module, loader):42def load_tests(standard_tests, module, loader):
44 submod_tests = loader.loadTestsFromModuleNames([43 submod_tests = loader.loadTestsFromModuleNames([
45 'bzrlib.tests.per_lock.test_lock',44 'bzrlib.tests.per_lock.test_lock',
4645
=== modified file 'bzrlib/tests/per_lock/test_lock.py'
--- bzrlib/tests/per_lock/test_lock.py 2009-03-23 14:59:43 +0000
+++ bzrlib/tests/per_lock/test_lock.py 2009-07-07 17:35:10 +0000
@@ -21,6 +21,7 @@
21 osutils,21 osutils,
22 )22 )
2323
24from bzrlib.tests import UnicodeFilenameFeature
24from bzrlib.tests.per_lock import TestCaseWithLock25from bzrlib.tests.per_lock import TestCaseWithLock
2526
2627
@@ -160,3 +161,18 @@
160 b_lock.unlock()161 b_lock.unlock()
161 if c_lock is not None:162 if c_lock is not None:
162 c_lock.unlock()163 c_lock.unlock()
164
165
166class TestLockUnicodePath(TestCaseWithLock):
167
168 _test_needs_features = [UnicodeFilenameFeature]
169
170 def test_read_lock(self):
171 self.build_tree([u'\u1234'])
172 u_lock = self.read_lock(u'\u1234')
173 self.addCleanup(u_lock.unlock)
174
175 def test_write_lock(self):
176 self.build_tree([u'\u1234'])
177 u_lock = self.write_lock(u'\u1234')
178 self.addCleanup(u_lock.unlock)