comparison mercurial/util.py @ 4059:431f3c1d3a37

Merge with crew-stable
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Tue, 30 Jan 2007 19:36:56 -0200
parents ea6174c96ae1 3600b84656d3
children 5b1f663ef86d
comparison
equal deleted inserted replaced
4051:022056263354 4059:431f3c1d3a37
12 platform-specific details from the core. 12 platform-specific details from the core.
13 """ 13 """
14 14
15 from i18n import _ 15 from i18n import _
16 import cStringIO, errno, getpass, popen2, re, shutil, sys, tempfile 16 import cStringIO, errno, getpass, popen2, re, shutil, sys, tempfile
17 import os, threading, time, calendar, ConfigParser, locale 17 import os, threading, time, calendar, ConfigParser, locale, glob
18 18
19 _encoding = os.environ.get("HGENCODING") or locale.getpreferredencoding() \ 19 try:
20 or "ascii" 20 _encoding = os.environ.get("HGENCODING") or locale.getpreferredencoding() \
21 or "ascii"
22 except locale.Error:
23 _encoding = 'ascii'
21 _encodingmode = os.environ.get("HGENCODINGMODE", "strict") 24 _encodingmode = os.environ.get("HGENCODINGMODE", "strict")
22 _fallbackencoding = 'ISO-8859-1' 25 _fallbackencoding = 'ISO-8859-1'
23 26
24 def tolocal(s): 27 def tolocal(s):
25 """ 28 """
230 class UnexpectedOutput(Abort): 233 class UnexpectedOutput(Abort):
231 """Raised to print an error with part of output and exit.""" 234 """Raised to print an error with part of output and exit."""
232 235
233 def always(fn): return True 236 def always(fn): return True
234 def never(fn): return False 237 def never(fn): return False
238
239 def expand_glob(pats):
240 '''On Windows, expand the implicit globs in a list of patterns'''
241 if os.name != 'nt':
242 return list(pats)
243 ret = []
244 for p in pats:
245 kind, name = patkind(p, None)
246 if kind is None:
247 globbed = glob.glob(name)
248 if globbed:
249 ret.extend(globbed)
250 continue
251 # if we couldn't expand the glob, just keep it around
252 ret.append(p)
253 return ret
235 254
236 def patkind(name, dflt_pat='glob'): 255 def patkind(name, dflt_pat='glob'):
237 """Split a string into an optional pattern kind prefix and the 256 """Split a string into an optional pattern kind prefix and the
238 actual pattern.""" 257 actual pattern."""
239 for prefix in 're', 'glob', 'path', 'relglob', 'relpath', 'relre': 258 for prefix in 're', 'glob', 'path', 'relglob', 'relpath', 'relre':
356 raise Abort('%s not under root' % myname) 375 raise Abort('%s not under root' % myname)
357 376
358 def matcher(canonroot, cwd='', names=['.'], inc=[], exc=[], head='', src=None): 377 def matcher(canonroot, cwd='', names=['.'], inc=[], exc=[], head='', src=None):
359 return _matcher(canonroot, cwd, names, inc, exc, head, 'glob', src) 378 return _matcher(canonroot, cwd, names, inc, exc, head, 'glob', src)
360 379
361 def cmdmatcher(canonroot, cwd='', names=['.'], inc=[], exc=[], head='', src=None): 380 def cmdmatcher(canonroot, cwd='', names=['.'], inc=[], exc=[], head='',
362 if os.name == 'nt': 381 src=None, globbed=False):
363 dflt_pat = 'glob' 382 if not globbed:
364 else: 383 names = expand_glob(names)
365 dflt_pat = 'relpath' 384 return _matcher(canonroot, cwd, names, inc, exc, head, 'relpath', src)
366 return _matcher(canonroot, cwd, names, inc, exc, head, dflt_pat, src)
367 385
368 def _matcher(canonroot, cwd, names, inc, exc, head, dflt_pat, src): 386 def _matcher(canonroot, cwd, names, inc, exc, head, dflt_pat, src):
369 """build a function to match a set of file patterns 387 """build a function to match a set of file patterns
370 388
371 arguments: 389 arguments: