Rev 4788: Refactor the glob_expand code a bit, making the inner function more reusable. in http://bazaar.launchpad.net/~jameinel/bzr/2.1.0b3-win32-shell-completion
John Arbash Meinel
john at arbash-meinel.com
Wed Nov 4 22:13:07 GMT 2009
At http://bazaar.launchpad.net/~jameinel/bzr/2.1.0b3-win32-shell-completion
------------------------------------------------------------
revno: 4788
revision-id: john at arbash-meinel.com-20091104221246-xkbux8f428u9hn5i
parent: john at arbash-meinel.com-20091104220346-ncxbtnp4d0fc6glb
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1.0b3-win32-shell-completion
timestamp: Wed 2009-11-04 16:12:46 -0600
message:
Refactor the glob_expand code a bit, making the inner function more reusable.
For now backslash is always translated back into forward slash.
-------------- next part --------------
=== modified file 'bzrlib/tests/test_win32utils.py'
--- a/bzrlib/tests/test_win32utils.py 2009-11-04 22:03:46 +0000
+++ b/bzrlib/tests/test_win32utils.py 2009-11-04 22:12:46 +0000
@@ -345,3 +345,9 @@
self.build_tree(['a/', 'a/b.c', 'a/c.c', 'a/c.h'])
self.assertCommandLine([u'a/*.c'], '"a/*.c"')
self.assertCommandLine([u'a/*.c'], "'a/*.c'")
+
+ def test_slashes_changed(self):
+ self.assertCommandLine([u'a/*.c'], '"a\\*.c"')
+ # Expands the glob, but nothing matches
+ self.assertCommandLine([u'a/*.c'], 'a\\*.c')
+ self.assertCommandLine([u'a/foo.c'], 'a\\foo.c')
=== modified file 'bzrlib/win32utils.py'
--- a/bzrlib/win32utils.py 2009-11-04 22:03:46 +0000
+++ b/bzrlib/win32utils.py 2009-11-04 22:12:46 +0000
@@ -426,6 +426,26 @@
+def glob_one(possible_glob):
+ """Same as glob.glob().
+
+ work around bugs in glob.glob()
+ - Python bug #1001604 ("glob doesn't return unicode with ...")
+ - failing expansion for */* with non-iso-8859-* chars
+ """
+ corrected_glob, corrected = _ensure_with_dir(possible_glob)
+ glob_files = glob.glob(corrected_glob)
+
+ if not glob_files:
+ # special case to let the normal code path handle
+ # files that do not exist, etc.
+ glob_files = [possible_glob]
+ elif corrected:
+ glob_files = [_undo_ensure_with_dir(elem, corrected)
+ for elem in glob_files]
+ return [elem.replace(u'\\', u'/') for elem in glob_files]
+
+
def glob_expand(file_list):
"""Replacement for glob expansion by the shell.
@@ -441,22 +461,8 @@
return []
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(
- _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 [elem.replace(u'\\', u'/') for elem in expanded_file_list]
+ expanded_file_list.extend(glob_one(possible_glob))
+ return expanded_file_list
def get_app_path(appname):
@@ -625,10 +631,10 @@
# '**/' style globs
args = []
for is_quoted, arg in s:
- if is_quoted:
- args.append(arg)
+ if is_quoted or not glob.has_magic(arg):
+ args.append(arg.replace(u'\\', u'/'))
else:
- args.extend(glob_expand([arg]))
+ args.extend(glob_one(arg))
return args
More information about the bazaar-commits
mailing list