Mercurial > hg > mercurial-crew-with-dirclash
comparison mercurial/hg.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 | d6605381c6df |
children | edb66cb05ded |
comparison
equal
deleted
inserted
replaced
2578:cf4f0322851d | 2579:0875cda033fd |
---|---|
59 | 59 |
60 def repository(ui, path=None, create=0): | 60 def repository(ui, path=None, create=0): |
61 if not path: path = '' | 61 if not path: path = '' |
62 scheme = path | 62 scheme = path |
63 if scheme: | 63 if scheme: |
64 c = scheme.find(':') | 64 scheme = scheme.split(":", 1)[0] |
65 scheme = c >= 0 and scheme[:c] | |
66 ctor = schemes.get(scheme) or schemes['file'] | 65 ctor = schemes.get(scheme) or schemes['file'] |
67 if create: | 66 if create: |
68 try: | 67 try: |
69 return ctor(ui, path, create) | 68 return ctor(ui, path, create) |
70 except TypeError: | 69 except TypeError: |