# HG changeset patch # User Augie Fackler # Date 1311627202 18000 # Node ID c035f1c53e395a057ffb4889ab753cce8fea811c # Parent 1c917bc66cccab4bdd13cd56bfae4e747f69034c subrepo: use safehasattr instead of hasattr Some of these instances could be rewritten as clever getattr(x, y, default) ladders, but that felt like it impeded readability too much to be worth the modest efficiency gain. diff -r 1c917bc66ccc -r c035f1c53e39 mercurial/subrepo.py --- a/mercurial/subrepo.py Mon Jul 25 15:47:43 2011 -0500 +++ b/mercurial/subrepo.py Mon Jul 25 15:53:22 2011 -0500 @@ -181,22 +181,22 @@ def reporelpath(repo): """return path to this (sub)repo as seen from outermost repo""" parent = repo - while hasattr(parent, '_subparent'): + while util.safehasattr(parent, '_subparent'): parent = parent._subparent return repo.root[len(parent.root)+1:] def subrelpath(sub): """return path to this subrepo as seen from outermost repo""" - if hasattr(sub, '_relpath'): + if util.safehasattr(sub, '_relpath'): return sub._relpath - if not hasattr(sub, '_repo'): + if not util.safehasattr(sub, '_repo'): return sub._path return reporelpath(sub._repo) def _abssource(repo, push=False, abort=True): """return pull/push path of repo - either based on parent repo .hgsub info or on the top repo config. Abort or return None if no source found.""" - if hasattr(repo, '_subparent'): + if util.safehasattr(repo, '_subparent'): source = util.url(repo._subsource) if source.isabs(): return str(source) @@ -208,7 +208,7 @@ parent.path = posixpath.normpath(parent.path) return str(parent) else: # recursion reached top repo - if hasattr(repo, '_subtoppath'): + if util.safehasattr(repo, '_subtoppath'): return repo._subtoppath if push and repo.ui.config('paths', 'default-push'): return repo.ui.config('paths', 'default-push')