comparison 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
comparison
equal deleted inserted replaced
2578:cf4f0322851d 2579:0875cda033fd
74 raise util.Abort(_("Failed to parse %s\n%s") % (f, inst)) 74 raise util.Abort(_("Failed to parse %s\n%s") % (f, inst))
75 # translate paths relative to root (or home) into absolute paths 75 # translate paths relative to root (or home) into absolute paths
76 if root is None: 76 if root is None:
77 root = os.path.expanduser('~') 77 root = os.path.expanduser('~')
78 for name, path in self.configitems("paths"): 78 for name, path in self.configitems("paths"):
79 if path and path.find("://") == -1 and not os.path.isabs(path): 79 if path and "://" not in path and not os.path.isabs(path):
80 self.cdata.set("paths", name, os.path.join(root, path)) 80 self.cdata.set("paths", name, os.path.join(root, path))
81 81
82 def setconfig(self, section, name, val): 82 def setconfig(self, section, name, val):
83 self.overlay[(section, name)] = val 83 self.overlay[(section, name)] = val
84 84
206 if not self.verbose: user = util.shortuser(user) 206 if not self.verbose: user = util.shortuser(user)
207 return user 207 return user
208 208
209 def expandpath(self, loc, default=None): 209 def expandpath(self, loc, default=None):
210 """Return repository location relative to cwd or from [paths]""" 210 """Return repository location relative to cwd or from [paths]"""
211 if loc.find("://") != -1 or os.path.exists(loc): 211 if "://" in loc or os.path.exists(loc):
212 return loc 212 return loc
213 213
214 path = self.config("paths", loc) 214 path = self.config("paths", loc)
215 if not path and default is not None: 215 if not path and default is not None:
216 path = self.config("paths", default) 216 path = self.config("paths", default)