Rev 2655: (Kuno Meyer) Tests for glob expansions on win32 + bugfix for `bzr in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Fri Jul 27 07:15:35 BST 2007


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 2655
revision-id: pqm at pqm.ubuntu.com-20070727061532-14ly852y2g2dbcb8
parent: pqm at pqm.ubuntu.com-20070726223348-t2howycr63c04q7r
parent: bialix at ukr.net-20070727043624-yu52vk3823cq5idv
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Fri 2007-07-27 07:15:32 +0100
message:
  (Kuno Meyer) Tests for glob expansions on win32 + bugfix for `bzr
   add *` when non-ascii filenames are in working tree (#127361) (r=aaron,r=bialix)
added:
  bzrlib/tests/test_win32utils.py test_win32utils.py-20070713181630-8xsrjymd3e8mgw23-108
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
  bzrlib/tests/blackbox/test_add.py test_add.py-20060518072250-857e4f86f54a30b2
  bzrlib/win32utils.py           win32console.py-20051021033308-123c6c929d04973d
    ------------------------------------------------------------
    revno: 2617.5.10
    merged: bialix at ukr.net-20070727043624-yu52vk3823cq5idv
    parent: bialix at ukr.net-20070727042926-mtf1gaddq2gj8bso
    committer: Alexander Belchenko <bialix at ukr.net>
    branch nick: win32_glob
    timestamp: Fri 2007-07-27 07:36:24 +0300
    message:
      NEWS
    ------------------------------------------------------------
    revno: 2617.5.9
    merged: bialix at ukr.net-20070727042926-mtf1gaddq2gj8bso
    parent: kuno.meyer at gmx.ch-20070724194040-ocyjulqhy31xe3j1
    parent: pqm at pqm.ubuntu.com-20070726134355-tlidmsn3eux09idz
    committer: Alexander Belchenko <bialix at ukr.net>
    branch nick: win32_glob
    timestamp: Fri 2007-07-27 07:29:26 +0300
    message:
      merge bzr.dev
    ------------------------------------------------------------
    revno: 2617.5.8
    merged: kuno.meyer at gmx.ch-20070724194040-ocyjulqhy31xe3j1
    parent: kuno.meyer at gmx.ch-20070722215816-c6lrm9ayg2emrtb0
    committer: Kuno Meyer <kuno.meyer at gmx.ch>
    branch nick: win32tests
    timestamp: Tue 2007-07-24 21:40:40 +0200
    message:
      Extended tests for unicode chars outside of the iso-8859-* range
      Two workarounds for incorrect glob.glob() implementation
    ------------------------------------------------------------
    revno: 2617.5.7
    merged: kuno.meyer at gmx.ch-20070722215816-c6lrm9ayg2emrtb0
    parent: kuno.meyer at gmx.ch-20070722202110-l7pvj1z3a741ha9s
    committer: Kuno Meyer <kuno.meyer at gmx.ch>
    branch nick: win32tests
    timestamp: Sun 2007-07-22 23:58:16 +0200
    message:
      Fix for non-ASCII filenames
    ------------------------------------------------------------
    revno: 2617.5.6
    merged: kuno.meyer at gmx.ch-20070722202110-l7pvj1z3a741ha9s
    parent: kuno.meyer at gmx.ch-20070718215235-nb6fmud5yuv3q9am
    committer: Kuno Meyer <kuno.meyer at gmx.ch>
    branch nick: win32tests
    timestamp: Sun 2007-07-22 22:21:10 +0200
    message:
      Incorporated feedback from the mailinglist.
    ------------------------------------------------------------
    revno: 2617.5.5
    merged: kuno.meyer at gmx.ch-20070718215235-nb6fmud5yuv3q9am
    parent: kuno.meyer at gmx.ch-20070718201527-rn6j933vii35b6gm
    committer: Kuno Meyer <kuno.meyer at gmx.ch>
    branch nick: win32tests
    timestamp: Wed 2007-07-18 23:52:35 +0200
    message:
      Just a typo remained from testing.
    ------------------------------------------------------------
    revno: 2617.5.4
    merged: kuno.meyer at gmx.ch-20070718201527-rn6j933vii35b6gm
    parent: kuno.meyer at gmx.ch-20070713223733-ns6gvwhe4ef8wjru
    committer: Kuno Meyer <kuno.meyer at gmx.ch>
    branch nick: win32tests
    timestamp: Wed 2007-07-18 22:15:27 +0200
    message:
      Included feedback on initial patch.
    ------------------------------------------------------------
    revno: 2617.5.3
    merged: kuno.meyer at gmx.ch-20070713223733-ns6gvwhe4ef8wjru
    parent: kuno.meyer at gmx.ch-20070713220117-vwei142086q2ophm
    committer: Kuno Meyer <kuno.meyer at gmx.ch>
    branch nick: win32tests
    timestamp: Sat 2007-07-14 00:37:33 +0200
    message:
      Blackbox test for adding with wildcards (Win32).
    ------------------------------------------------------------
    revno: 2617.5.2
    merged: kuno.meyer at gmx.ch-20070713220117-vwei142086q2ophm
    parent: kuno.meyer at gmx.ch-20070713184301-aqd22mud85c4gz1x
    committer: Kuno Meyer <kuno.meyer at gmx.ch>
    branch nick: win32tests
    timestamp: Sat 2007-07-14 00:01:17 +0200
    message:
      just reformatting
    ------------------------------------------------------------
    revno: 2617.5.1
    merged: kuno.meyer at gmx.ch-20070713184301-aqd22mud85c4gz1x
    parent: pqm at pqm.ubuntu.com-20070713074627-93zxs9uh528y0fki
    committer: Kuno Meyer <kuno.meyer at gmx.ch>
    branch nick: win32tests
    timestamp: Fri 2007-07-13 20:43:01 +0200
    message:
      Added direct unit tests for win32utils.glob_expand().
=== added file 'bzrlib/tests/test_win32utils.py'
--- a/bzrlib/tests/test_win32utils.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/test_win32utils.py	2007-07-24 19:40:40 +0000
@@ -0,0 +1,130 @@
+# Copyright (C) 2007 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+import sys
+
+from bzrlib import osutils
+from bzrlib.tests import TestCase, TestCaseInTempDir, Feature
+from bzrlib.win32utils import glob_expand
+
+
+# Features
+# --------
+
+class _NeedsGlobExpansionFeature(Feature):
+
+    def _probe(self):
+        return sys.platform == 'win32'
+
+    def feature_name(self):
+        return 'Internally performed glob expansion'
+
+NeedsGlobExpansionFeature = _NeedsGlobExpansionFeature()
+
+
+# Tests
+# -----
+
+class TestNeedsGlobExpansionFeature(TestCase):
+    
+    def test_available(self):
+        self.assertEqual(sys.platform == 'win32', 
+                         NeedsGlobExpansionFeature.available())
+        
+    def test_str(self):
+        self.assertTrue("performed" in str(NeedsGlobExpansionFeature))
+
+
+class TestWin32UtilsGlobExpand(TestCaseInTempDir):
+
+    _test_needs_features = [NeedsGlobExpansionFeature]
+   
+    def test_empty_tree(self):
+        self.build_tree([])
+        self._run_testset([
+            [['a'], ['a']],
+            [['?'], ['?']],
+            [['*'], ['*']],
+            [['a', 'a'], ['a', 'a']]])
+        
+    def test_tree_ascii(self):
+        """Checks the glob expansion and path separation char
+        normalization"""
+        self.build_tree(['a', 'a1', 'a2', 'a11', 'a.1',
+                         'b', 'b1', 'b2', 'b3',
+                         'c/', 'c/c1', 'c/c2', 
+                         'd/', 'd/d1', 'd/d2', 'd/e/', 'd/e/e1'])
+        self._run_testset([
+            # no wildcards
+            [[u'a'], [u'a']],
+            [[u'a', u'a' ], [u'a', u'a']],
+            [[u'A'], [u'A']],
+                
+            [[u'd'], [u'd']],
+            [[u'd/'], [u'd/']],
+            [[u'd\\'], [u'd/']],
+            
+            # wildcards
+            [[u'a*'], [u'a', u'a1', u'a2', u'a11', u'a.1']],
+            [[u'?'], [u'a', u'b', u'c', u'd']],
+            [[u'a?'], [u'a1', u'a2']],
+            [[u'a??'], [u'a11', u'a.1']],
+            [[u'b[1-2]'], [u'b1', u'b2']],
+            [[u'A?'], [u'a1', u'a2']],
+               
+            [[u'd/*'], [u'd/d1', u'd/d2', u'd/e']],
+            [[u'd\\*'], [u'd/d1', u'd/d2', u'd/e']],
+            [[u'?\\*'], [u'c/c1', u'c/c2', u'd/d1', u'd/d2', u'd/e']],
+            [[u'*\\*'], [u'c/c1', u'c/c2', u'd/d1', u'd/d2', u'd/e']],
+            [[u'*/'], [u'c/', u'd/']],
+            [[u'*\\'], [u'c/', u'd/']]])
+        
+    def test_tree_unicode(self):
+        """Checks behaviour with non-ascii filenames"""
+        self.build_tree([u'\u1234', u'\u1234\u1234', u'\u1235/', u'\u1235/\u1235'])
+        self._run_testset([
+            # no wildcards
+            [[u'\u1234'], [u'\u1234']],
+            [[u'\u1235'], [u'\u1235']],
+         
+            [[u'\u1235/'], [u'\u1235/']],
+            [[u'\u1235/\u1235'], [u'\u1235/\u1235']],
+            
+            # wildcards
+            [[u'?'], [u'\u1234', u'\u1235']],
+            [[u'*'], [u'\u1234', u'\u1234\u1234', u'\u1235']],
+            [[u'\u1234*'], [u'\u1234', u'\u1234\u1234']],
+            
+            [[u'\u1235/?'], [u'\u1235/\u1235']],
+            [[u'\u1235/*'], [u'\u1235/\u1235']],
+            [[u'\u1235\\?'], [u'\u1235/\u1235']],
+            [[u'\u1235\\*'], [u'\u1235/\u1235']],
+            [[u'?/'], [u'\u1235/']],
+            [[u'*/'], [u'\u1235/']],
+            [[u'?\\'], [u'\u1235/']],
+            [[u'*\\'], [u'\u1235/']],
+            [[u'?/?'], [u'\u1235/\u1235']],
+            [[u'*/*'], [u'\u1235/\u1235']],
+            [[u'?\\?'], [u'\u1235/\u1235']],
+            [[u'*\\*'], [u'\u1235/\u1235']]])
+
+    def _run_testset(self, testset):
+        for pattern, expected in testset:
+            result = glob_expand(pattern)
+            expected.sort()
+            result.sort()
+            self.assertEqual(expected, result, 'pattern %s' % pattern)
+

=== modified file 'NEWS'
--- a/NEWS	2007-07-25 21:29:22 +0000
+++ b/NEWS	2007-07-27 04:36:24 +0000
@@ -32,6 +32,9 @@
     * ``bzr checkout`` now honours -r when reconstituting a working tree.
       It also honours -r 0.  (Aaron Bentley, #127708)
 
+    * ``bzr add *`` no more fails on Windows if working tree contains
+      non-ascii file names. (Kuno Meyer, #127361)
+
   IMPROVEMENTS:
 
     * Don't show "dots" progress indicators when run non-interactively, such

=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2007-07-26 21:18:35 +0000
+++ b/bzrlib/tests/__init__.py	2007-07-27 06:15:32 +0000
@@ -2372,6 +2372,7 @@
                    'bzrlib.tests.test_version_info',
                    'bzrlib.tests.test_weave',
                    'bzrlib.tests.test_whitebox',
+                   'bzrlib.tests.test_win32utils',
                    'bzrlib.tests.test_workingtree',
                    'bzrlib.tests.test_workingtree_4',
                    'bzrlib.tests.test_wsgi',

=== modified file 'bzrlib/tests/blackbox/test_add.py'
--- a/bzrlib/tests/blackbox/test_add.py	2007-07-04 08:49:15 +0000
+++ b/bzrlib/tests/blackbox/test_add.py	2007-07-24 19:40:40 +0000
@@ -20,6 +20,7 @@
 import os
 
 from bzrlib.tests.blackbox import ExternalBase
+from bzrlib.tests.test_win32utils import NeedsGlobExpansionFeature
 
 
 class TestAdd(ExternalBase):
@@ -192,3 +193,17 @@
         self.build_tree(['.bzr/crescent'])
         err = self.run_bzr('add .bzr/crescent', retcode=3)[1]
         self.assertContainsRe(err, r'ERROR:.*\.bzr.*control file')
+
+    def test_add_with_wildcards(self):
+        self.requireFeature(NeedsGlobExpansionFeature)
+        self.make_branch_and_tree('.')
+        self.build_tree(['a1', 'a2', 'b', 'c33'])
+        self.run_bzr(['add', 'a?', 'c*'])
+        self.assertEquals(self.run_bzr('unknowns')[0], 'b\n')
+
+    def test_add_with_wildcards_unicode(self):
+        self.requireFeature(NeedsGlobExpansionFeature)
+        self.make_branch_and_tree('.')
+        self.build_tree([u'\u1234A', u'\u1235A', u'\u1235AA', 'cc'])
+        self.run_bzr(['add', u'\u1234?', u'\u1235*'])
+        self.assertEquals(self.run_bzr('unknowns')[0], 'cc\n')

=== modified file 'bzrlib/win32utils.py'
--- a/bzrlib/win32utils.py	2007-07-12 23:42:01 +0000
+++ b/bzrlib/win32utils.py	2007-07-24 19:40:40 +0000
@@ -240,6 +240,20 @@
     return _ensure_unicode(get_host_name())
 
 
+def _ensure_with_dir(path):
+    if not os.path.split(path)[0] or path.startswith(u'*') or path.startswith(u'?'):
+        return u'./' + path, True
+    else:
+        return path, False
+    
+def _undo_ensure_with_dir(path, corrected):
+    if corrected:
+        return path[2:]
+    else:
+        return path
+
+
+
 def glob_expand(file_list):
     """Replacement for glob expansion by the shell.
 
@@ -256,14 +270,20 @@
     import glob
     expanded_file_list = []
     for possible_glob in file_list:
+        
+        # work around bugs in glob.glob()
+        # - Python bug #1001604 ("glob doesn't return unicode with ...")
+        # - failing expansion for */* with non-iso-8859-* chars
+        possible_glob, corrected = _ensure_with_dir(possible_glob)
         glob_files = glob.glob(possible_glob)
 
         if glob_files == []:
             # special case to let the normal code path handle
             # files that do not exists
-            expanded_file_list.append(possible_glob)
+            expanded_file_list.append(
+                _undo_ensure_with_dir(possible_glob, corrected))
         else:
+            glob_files = [_undo_ensure_with_dir(elem, corrected) for elem in glob_files]
             expanded_file_list += glob_files
-    return expanded_file_list
-
-
+            
+    return [elem.replace(u'\\', u'/') for elem in expanded_file_list] 




More information about the bazaar-commits mailing list