changeset 4054:e6d54283c090

Explicitly expand globs on Windows
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Tue, 30 Jan 2007 18:32:18 -0200
parents 994fec0ee900
children e37786b29bed
files mercurial/util.py
diffstat 1 files changed, 19 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/util.py	Tue Jan 30 00:26:19 2007 +0100
+++ b/mercurial/util.py	Tue Jan 30 18:32:18 2007 -0200
@@ -15,7 +15,7 @@
 from i18n import gettext as _
 from demandload import *
 demandload(globals(), "cStringIO errno getpass popen2 re shutil sys tempfile")
-demandload(globals(), "os threading time calendar ConfigParser locale")
+demandload(globals(), "os threading time calendar ConfigParser locale glob")
 
 _encoding = os.environ.get("HGENCODING") or locale.getpreferredencoding() \
             or "ascii"
@@ -234,6 +234,22 @@
 def always(fn): return True
 def never(fn): return False
 
+def expand_glob(pats):
+    '''On Windows, expand the implicit globs in a list of patterns'''
+    if os.name != 'nt':
+        return list(pats)
+    ret = []
+    for p in pats:
+        kind, name = patkind(p, None)
+        if kind is None:
+            globbed = glob.glob(name)
+            if globbed:
+                ret.extend(globbed)
+                continue
+            # if we couldn't expand the glob, just keep it around
+        ret.append(p)
+    return ret
+
 def patkind(name, dflt_pat='glob'):
     """Split a string into an optional pattern kind prefix and the
     actual pattern."""
@@ -360,11 +376,8 @@
     return _matcher(canonroot, cwd, names, inc, exc, head, 'glob', src)
 
 def cmdmatcher(canonroot, cwd='', names=['.'], inc=[], exc=[], head='', src=None):
-    if os.name == 'nt':
-        dflt_pat = 'glob'
-    else:
-        dflt_pat = 'relpath'
-    return _matcher(canonroot, cwd, names, inc, exc, head, dflt_pat, src)
+    names = expand_glob(names)
+    return _matcher(canonroot, cwd, names, inc, exc, head, 'relpath', src)
 
 def _matcher(canonroot, cwd, names, inc, exc, head, dflt_pat, src):
     """build a function to match a set of file patterns