cmdutils: Take over glob expansion duties from util

This commit is contained in:
Matt Mackall 2009-05-24 16:38:29 -05:00
parent bd7c2104ff
commit a30eb02911
4 changed files with 21 additions and 17 deletions

View File

@ -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 @@ def make_file(repo, pat, node=None,
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 @@ def copy(ui, repo, pats, opts, rename=False):
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:

View File

@ -13,6 +13,7 @@ posixfile = file
nulldev = '/dev/null'
normpath = os.path.normpath
samestat = os.path.samestat
expandglobs = False
umask = os.umask(0)
os.umask(umask)

View File

@ -16,7 +16,7 @@ hide platform-specific details from the core.
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 @@ def lookup_reg(key, name=None, scope=None):
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 *

View File

@ -280,3 +280,5 @@ try:
from win32 import *
except ImportError:
pass
expandglobs = True