comparison mercurial/commands.py @ 2579:0875cda033fd

use __contains__, index or split instead of str.find str.find return -1 when the substring is not found, -1 evaluate to True and is a valid index, which can lead to bugs. Using alternatives when possible makes the code clearer and less prone to bugs. (and __contains__ is faster in microbenchmarks)
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Sun, 09 Jul 2006 01:30:30 +0200
parents 78c2903fcabe
children a20a1bb0c396
comparison
equal deleted inserted replaced
2578:cf4f0322851d 2579:0875cda033fd
229 229
230 def revrange(ui, repo, revs): 230 def revrange(ui, repo, revs):
231 """Yield revision as strings from a list of revision specifications.""" 231 """Yield revision as strings from a list of revision specifications."""
232 seen = {} 232 seen = {}
233 for spec in revs: 233 for spec in revs:
234 if spec.find(revrangesep) >= 0: 234 if revrangesep in spec:
235 start, end = spec.split(revrangesep, 1) 235 start, end = spec.split(revrangesep, 1)
236 start = revfix(repo, start, 0) 236 start = revfix(repo, start, 0)
237 end = revfix(repo, end, repo.changelog.count() - 1) 237 end = revfix(repo, end, repo.changelog.count() - 1)
238 step = start > end and -1 or 1 238 step = start > end and -1 or 1
239 for rev in xrange(start, end+step, step): 239 for rev in xrange(start, end+step, step):
2740 else: 2740 else:
2741 r = hex(repo.changelog.tip()) 2741 r = hex(repo.changelog.tip())
2742 2742
2743 disallowed = (revrangesep, '\r', '\n') 2743 disallowed = (revrangesep, '\r', '\n')
2744 for c in disallowed: 2744 for c in disallowed:
2745 if name.find(c) >= 0: 2745 if c in name:
2746 raise util.Abort(_("%s cannot be used in a tag name") % repr(c)) 2746 raise util.Abort(_("%s cannot be used in a tag name") % repr(c))
2747 2747
2748 repo.hook('pretag', throw=True, node=r, tag=name, 2748 repo.hook('pretag', throw=True, node=r, tag=name,
2749 local=int(not not opts['local'])) 2749 local=int(not not opts['local']))
2750 2750