mercurial/util.py
changeset 4054 e6d54283c090
parent 3905 a8c0365b2ace
child 4055 e37786b29bed
equal deleted inserted replaced
4053:994fec0ee900 4054:e6d54283c090
    13 """
    13 """
    14 
    14 
    15 from i18n import gettext as _
    15 from i18n import gettext as _
    16 from demandload import *
    16 from demandload import *
    17 demandload(globals(), "cStringIO errno getpass popen2 re shutil sys tempfile")
    17 demandload(globals(), "cStringIO errno getpass popen2 re shutil sys tempfile")
    18 demandload(globals(), "os threading time calendar ConfigParser locale")
    18 demandload(globals(), "os threading time calendar ConfigParser locale glob")
    19 
    19 
    20 _encoding = os.environ.get("HGENCODING") or locale.getpreferredencoding() \
    20 _encoding = os.environ.get("HGENCODING") or locale.getpreferredencoding() \
    21             or "ascii"
    21             or "ascii"
    22 _encodingmode = os.environ.get("HGENCODINGMODE", "strict")
    22 _encodingmode = os.environ.get("HGENCODINGMODE", "strict")
    23 _fallbackencoding = 'ISO-8859-1'
    23 _fallbackencoding = 'ISO-8859-1'
   231 class UnexpectedOutput(Abort):
   231 class UnexpectedOutput(Abort):
   232     """Raised to print an error with part of output and exit."""
   232     """Raised to print an error with part of output and exit."""
   233 
   233 
   234 def always(fn): return True
   234 def always(fn): return True
   235 def never(fn): return False
   235 def never(fn): return False
       
   236 
       
   237 def expand_glob(pats):
       
   238     '''On Windows, expand the implicit globs in a list of patterns'''
       
   239     if os.name != 'nt':
       
   240         return list(pats)
       
   241     ret = []
       
   242     for p in pats:
       
   243         kind, name = patkind(p, None)
       
   244         if kind is None:
       
   245             globbed = glob.glob(name)
       
   246             if globbed:
       
   247                 ret.extend(globbed)
       
   248                 continue
       
   249             # if we couldn't expand the glob, just keep it around
       
   250         ret.append(p)
       
   251     return ret
   236 
   252 
   237 def patkind(name, dflt_pat='glob'):
   253 def patkind(name, dflt_pat='glob'):
   238     """Split a string into an optional pattern kind prefix and the
   254     """Split a string into an optional pattern kind prefix and the
   239     actual pattern."""
   255     actual pattern."""
   240     for prefix in 're', 'glob', 'path', 'relglob', 'relpath', 'relre':
   256     for prefix in 're', 'glob', 'path', 'relglob', 'relpath', 'relre':
   358 
   374 
   359 def matcher(canonroot, cwd='', names=['.'], inc=[], exc=[], head='', src=None):
   375 def matcher(canonroot, cwd='', names=['.'], inc=[], exc=[], head='', src=None):
   360     return _matcher(canonroot, cwd, names, inc, exc, head, 'glob', src)
   376     return _matcher(canonroot, cwd, names, inc, exc, head, 'glob', src)
   361 
   377 
   362 def cmdmatcher(canonroot, cwd='', names=['.'], inc=[], exc=[], head='', src=None):
   378 def cmdmatcher(canonroot, cwd='', names=['.'], inc=[], exc=[], head='', src=None):
   363     if os.name == 'nt':
   379     names = expand_glob(names)
   364         dflt_pat = 'glob'
   380     return _matcher(canonroot, cwd, names, inc, exc, head, 'relpath', src)
   365     else:
       
   366         dflt_pat = 'relpath'
       
   367     return _matcher(canonroot, cwd, names, inc, exc, head, dflt_pat, src)
       
   368 
   381 
   369 def _matcher(canonroot, cwd, names, inc, exc, head, dflt_pat, src):
   382 def _matcher(canonroot, cwd, names, inc, exc, head, dflt_pat, src):
   370     """build a function to match a set of file patterns
   383     """build a function to match a set of file patterns
   371 
   384 
   372     arguments:
   385     arguments: