comparison mercurial/fileset.py @ 14716:552329013bac stable

fileset: use ParseError pos field correctly The pos field is intended to describe the position of the error - it should not be used for other potentially interesting information.
author Mads Kiilerich <mads@kiilerich.com>
date Fri, 24 Jun 2011 00:18:41 +0200
parents 4b93bd041772
children c8ee2729e89f
comparison
equal deleted inserted replaced
14715:a97ebfec8c29 14716:552329013bac
252 for k, v in _units.items(): 252 for k, v in _units.items():
253 if s.endswith(k): 253 if s.endswith(k):
254 return int(float(s[:-len(k)]) * v) 254 return int(float(s[:-len(k)]) * v)
255 return int(s) 255 return int(s)
256 except ValueError: 256 except ValueError:
257 raise 257 raise error.ParseError(_("couldn't parse size: %s") % s)
258 raise error.ParseError(_("couldn't parse size"), s)
259 258
260 def _sizetomax(s): 259 def _sizetomax(s):
261 try: 260 try:
262 s = s.strip() 261 s = s.strip()
263 for k, v in _units.items(): 262 for k, v in _units.items():
269 inc /= 10 ** len(n.split(".")[1]) 268 inc /= 10 ** len(n.split(".")[1])
270 return int((float(n) + inc) * v) - 1 269 return int((float(n) + inc) * v) - 1
271 # no extension, this is a precise value 270 # no extension, this is a precise value
272 return int(s) 271 return int(s)
273 except ValueError: 272 except ValueError:
274 raise 273 raise error.ParseError(_("couldn't parse size: %s") % s)
275 raise error.ParseError(_("couldn't parse size"), s)
276 274
277 def size(mctx, x): 275 def size(mctx, x):
278 """``size(expression)`` 276 """``size(expression)``
279 File size matches the given expression. Examples: 277 File size matches the given expression. Examples:
280 278
305 elif expr[0].isdigit or expr[0] == '.': 303 elif expr[0].isdigit or expr[0] == '.':
306 a = _sizetoint(expr) 304 a = _sizetoint(expr)
307 b = _sizetomax(expr) 305 b = _sizetomax(expr)
308 m = lambda x: x >= a and x <= b 306 m = lambda x: x >= a and x <= b
309 else: 307 else:
310 raise error.ParseError(_("couldn't parse size"), expr) 308 raise error.ParseError(_("couldn't parse size: %s") % expr)
311 309
312 return [f for f in mctx.subset if m(mctx.ctx[f].size())] 310 return [f for f in mctx.subset if m(mctx.ctx[f].size())]
313 311
314 def encoding(mctx, x): 312 def encoding(mctx, x):
315 """``encoding(name)`` 313 """``encoding(name)``