Mercurial > hg
comparison mercurial/hgweb/hgweb_mod.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 | 1120302009d7 |
children | a20a1bb0c396 |
comparison
equal
deleted
inserted
replaced
2578:cf4f0322851d | 2579:0875cda033fd |
---|---|
460 for f,n in mf.items(): | 460 for f,n in mf.items(): |
461 if f[:l] != p: | 461 if f[:l] != p: |
462 continue | 462 continue |
463 remain = f[l:] | 463 remain = f[l:] |
464 if "/" in remain: | 464 if "/" in remain: |
465 short = remain[:remain.find("/") + 1] # bleah | 465 short = remain[:remain.index("/") + 1] # bleah |
466 files[short] = (f, None) | 466 files[short] = (f, None) |
467 else: | 467 else: |
468 short = os.path.basename(remain) | 468 short = os.path.basename(remain) |
469 files[short] = (f, n) | 469 files[short] = (f, n) |
470 | 470 |