Mercurial > hg > mercurial-crew-with-dirclash
diff 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 |
line wrap: on
line diff
--- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -231,7 +231,7 @@ def revrange(ui, repo, revs): """Yield revision as strings from a list of revision specifications.""" seen = {} for spec in revs: - if spec.find(revrangesep) >= 0: + if revrangesep in spec: start, end = spec.split(revrangesep, 1) start = revfix(repo, start, 0) end = revfix(repo, end, repo.changelog.count() - 1) @@ -2742,7 +2742,7 @@ def tag(ui, repo, name, rev_=None, **opt disallowed = (revrangesep, '\r', '\n') for c in disallowed: - if name.find(c) >= 0: + if c in name: raise util.Abort(_("%s cannot be used in a tag name") % repr(c)) repo.hook('pretag', throw=True, node=r, tag=name,