changeset 1413:1c64c628d15f

Do not use 'glob' expansion by default on OS != 'nt'
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Wed, 19 Oct 2005 00:02:41 -0700
parents c1e0aebfabc0
children 32fde51910c0
files mercurial/commands.py mercurial/util.py tests/test-walk
diffstat 3 files changed, 22 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Tue Oct 18 23:58:00 2005 -0700
+++ b/mercurial/commands.py	Wed Oct 19 00:02:41 2005 -0700
@@ -32,7 +32,7 @@
     return args
 
 def matchpats(repo, cwd, pats=[], opts={}, head=''):
-    return util.matcher(repo.root, cwd, pats or ['.'], opts.get('include'),
+    return util.cmdmatcher(repo.root, cwd, pats or ['.'], opts.get('include'),
                         opts.get('exclude'), head)
 
 def makewalk(repo, pats, opts, head=''):
--- a/mercurial/util.py	Tue Oct 18 23:58:00 2005 -0700
+++ b/mercurial/util.py	Wed Oct 19 00:02:41 2005 -0700
@@ -179,6 +179,16 @@
         raise Abort('%s not under root' % myname)
 
 def matcher(canonroot, cwd='', names=['.'], inc=[], exc=[], head=''):
+    return _matcher(canonroot, cwd, names, inc, exc, head, 'glob')
+
+def cmdmatcher(canonroot, cwd='', names=['.'], inc=[], exc=[], head=''):
+    if os.name == 'nt':
+        dflt_pat = 'glob'
+    else:
+        dflt_pat = 'relpath'
+    return _matcher(canonroot, cwd, names, inc, exc, head, dflt_pat)
+
+def _matcher(canonroot, cwd, names, inc, exc, head, dflt_pat):
     """build a function to match a set of file patterns
 
     arguments:
@@ -208,12 +218,15 @@
     make head regex a rooted bool
     """
 
-    def patkind(name):
+    def patkind(name, dflt_pat='glob'):
         for prefix in 're', 'glob', 'path', 'relglob', 'relpath', 'relre':
             if name.startswith(prefix + ':'): return name.split(':', 1)
+        return dflt_pat, name
+
+    def contains_glob(name):
         for c in name:
-            if c in _globchars: return 'glob', name
-        return 'relpath', name
+            if c in _globchars: return True
+        return False
 
     def regex(kind, name, tail):
         '''convert a pattern into a regular expression'''
@@ -241,14 +254,14 @@
         '''return the non-glob prefix of a path, e.g. foo/* -> foo'''
         root = []
         for p in pat.split(os.sep):
-            if patkind(p)[0] == 'glob': break
+            if contains_glob(p): break
             root.append(p)
         return '/'.join(root)
 
     pats = []
     files = []
     roots = []
-    for kind, name in map(patkind, names):
+    for kind, name in [patkind(p, dflt_pat) for p in names]:
         if kind in ('glob', 'relpath'):
             name = canonpath(canonroot, cwd, name)
             if name == '':
--- a/tests/test-walk	Tue Oct 18 23:58:00 2005 -0700
+++ b/tests/test-walk	Wed Oct 19 00:02:41 2005 -0700
@@ -30,7 +30,7 @@
 hg debugwalk
 cd ..
 hg debugwalk -Ibeans
-hg debugwalk 'mammals/../beans/b*'
+hg debugwalk 'glob:mammals/../beans/b*'
 hg debugwalk '-X*/Procyonidae' mammals
 hg debugwalk path:mammals
 hg debugwalk ..
@@ -42,8 +42,8 @@
 hg debugwalk glob:\*
 hg debugwalk 're:.*[kb]$'
 hg debugwalk path:beans/black
-hg debugwalk beans 'beans/*'
-hg debugwalk 'j*'
+hg debugwalk beans 'glob:beans/*'
+hg debugwalk 'glob:j*'
 hg debugwalk NOEXIST
 mkfifo fifo
 hg debugwalk fifo