# HG changeset patch # User Jun Wu # Date 2016-02-26 15:07:58 # Node ID 59509c6724c773589c19f32bee89c28867a1458c # Parent 53dc4aada2d9eeb93302caa5b7b9a244193f2f41 dispatch: add wd parameter to _getlocal Before this patch, _getlocal uses os.getcwd() to locate repo in current dir. chgserver needs it to load repo config and has to do chdir twice: the first is to set current directory and the second is to redo the side effect (in case hg --cwd some/relative/path, chdir will be called again in dispatch later), which is not pretty. This patch adds an optional wd parameter to make it possible to specify wd without chdir (and its side effect). diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py --- a/mercurial/dispatch.py +++ b/mercurial/dispatch.py @@ -685,16 +685,17 @@ def runcommand(lui, repo, cmd, fullargs, result=ret, pats=cmdpats, opts=cmdoptions) return ret -def _getlocal(ui, rpath): +def _getlocal(ui, rpath, wd=None): """Return (path, local ui object) for the given target path. Takes paths in [cwd]/.hg/hgrc into account." """ - try: - wd = os.getcwd() - except OSError as e: - raise error.Abort(_("error getting current working directory: %s") % - e.strerror) + if wd is None: + try: + wd = os.getcwd() + except OSError as e: + raise error.Abort(_("error getting current working directory: %s") % + e.strerror) path = cmdutil.findrepo(wd) or "" if not path: lui = ui