changeset 8614:573734e7e6d0

cmdutils: Take over glob expansion duties from util
author Matt Mackall <mpm@selenic.com>
date Sun, 24 May 2009 16:38:29 -0500
parents 4dea46d4e3f8
children 94ca38e63576
files mercurial/cmdutil.py mercurial/posix.py mercurial/util.py mercurial/windows.py
diffstat 4 files changed, 21 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cmdutil.py	Sun May 24 16:37:34 2009 -0500
+++ b/mercurial/cmdutil.py	Sun May 24 16:38:29 2009 -0500
@@ -7,7 +7,7 @@
 
 from node import hex, nullid, nullrev, short
 from i18n import _
-import os, sys, bisect, stat, errno, re
+import os, sys, bisect, stat, errno, re, glob
 import mdiff, bdiff, util, templater, patch, error, encoding
 import match as _match
 
@@ -235,9 +235,23 @@
                               pathname),
                 mode)
 
+def expandpats(pats):
+    if not util.expandglobs:
+        return list(pats)
+    ret = []
+    for p in pats:
+        kind, name = _match._patsplit(p, None)
+        if kind is None:
+            globbed = glob.glob(name)
+            if globbed:
+                ret.extend(globbed)
+                continue
+        ret.append(p)
+    return ret
+
 def match(repo, pats=[], opts={}, globbed=False, default='relpath'):
     if not globbed and default == 'relpath':
-        pats = util.expand_glob(pats or [])
+        pats = expandpats(pats or [])
     m = _match.match(repo.root, repo.getcwd(), pats,
                     opts.get('include'), opts.get('exclude'), default)
     def badfn(f, msg):
@@ -487,7 +501,7 @@
         return res
 
 
-    pats = util.expand_glob(pats)
+    pats = expandpats(pats)
     if not pats:
         raise util.Abort(_('no source or destination specified'))
     if len(pats) == 1:
--- a/mercurial/posix.py	Sun May 24 16:37:34 2009 -0500
+++ b/mercurial/posix.py	Sun May 24 16:38:29 2009 -0500
@@ -13,6 +13,7 @@
 nulldev = '/dev/null'
 normpath = os.path.normpath
 samestat = os.path.samestat
+expandglobs = False
 
 umask = os.umask(0)
 os.umask(umask)
--- a/mercurial/util.py	Sun May 24 16:37:34 2009 -0500
+++ b/mercurial/util.py	Sun May 24 16:38:29 2009 -0500
@@ -16,7 +16,7 @@
 from i18n import _
 import error, osutil
 import cStringIO, errno, re, shutil, sys, tempfile, traceback
-import os, stat, time, calendar, glob, random
+import os, stat, time, calendar, random
 import imp
 
 # Python compatibility
@@ -540,19 +540,6 @@
 
 if os.name == 'nt':
     from windows import *
-    def expand_glob(pats):
-        '''On Windows, expand the implicit globs in a list of patterns'''
-        ret = []
-        for p in pats:
-            kind, name = _patsplit(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
 else:
     from posix import *
 
--- a/mercurial/windows.py	Sun May 24 16:37:34 2009 -0500
+++ b/mercurial/windows.py	Sun May 24 16:38:29 2009 -0500
@@ -280,3 +280,5 @@
     from win32 import *
 except ImportError:
     pass
+
+expandglobs = True