Explicitly expand globs on Windows
authorAlexis S. L. Carvalho <alexis@cecm.usp.br>
Tue, 30 Jan 2007 18:32:18 -0200
changeset 4054 e6d54283c090
parent 4053 994fec0ee900
child 4055 e37786b29bed
Explicitly expand globs on Windows
mercurial/util.py
--- 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