comparison mercurial/util.py @ 5949:48d01b1e315f

Permit glob patterns to use nested curly braces.
author Jesse Glick <jesse.glick@sun.com>
date Fri, 25 Jan 2008 15:54:25 -0500
parents 549a7ebe1607
children 75d9fe70c654
comparison
equal deleted inserted replaced
5942:b75105de8573 5949:48d01b1e315f
260 260
261 def globre(pat, head='^', tail='$'): 261 def globre(pat, head='^', tail='$'):
262 "convert a glob pattern into a regexp" 262 "convert a glob pattern into a regexp"
263 i, n = 0, len(pat) 263 i, n = 0, len(pat)
264 res = '' 264 res = ''
265 group = False 265 group = 0
266 def peek(): return i < n and pat[i] 266 def peek(): return i < n and pat[i]
267 while i < n: 267 while i < n:
268 c = pat[i] 268 c = pat[i]
269 i = i+1 269 i = i+1
270 if c == '*': 270 if c == '*':
290 stuff = '^' + stuff[1:] 290 stuff = '^' + stuff[1:]
291 elif stuff[0] == '^': 291 elif stuff[0] == '^':
292 stuff = '\\' + stuff 292 stuff = '\\' + stuff
293 res = '%s[%s]' % (res, stuff) 293 res = '%s[%s]' % (res, stuff)
294 elif c == '{': 294 elif c == '{':
295 group = True 295 group += 1
296 res += '(?:' 296 res += '(?:'
297 elif c == '}' and group: 297 elif c == '}' and group:
298 res += ')' 298 res += ')'
299 group = False 299 group -= 1
300 elif c == ',' and group: 300 elif c == ',' and group:
301 res += '|' 301 res += '|'
302 elif c == '\\': 302 elif c == '\\':
303 p = peek() 303 p = peek()
304 if p: 304 if p: