diff mercurial/ui.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 18cf95ad3666
children a20a1bb0c396
line wrap: on
line diff
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -76,7 +76,7 @@ class ui(object):
         if root is None:
             root = os.path.expanduser('~')
         for name, path in self.configitems("paths"):
-            if path and path.find("://") == -1 and not os.path.isabs(path):
+            if path and "://" not in path and not os.path.isabs(path):
                 self.cdata.set("paths", name, os.path.join(root, path))
 
     def setconfig(self, section, name, val):
@@ -208,7 +208,7 @@ class ui(object):
 
     def expandpath(self, loc, default=None):
         """Return repository location relative to cwd or from [paths]"""
-        if loc.find("://") != -1 or os.path.exists(loc):
+        if "://" in loc or os.path.exists(loc):
             return loc
 
         path = self.config("paths", loc)