[PATCH 4 of 5 V2] dispatch: add wd parameter to _getlocal

Jun Wu quark at fb.com
Fri Feb 26 10:36:23 EST 2016


# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1456499278 0
#      Fri Feb 26 15:07:58 2016 +0000
# Node ID 93c4a18979328bf50acb2132c031d96fdda46bfc
# Parent  0515c0cdf7b24f5db0727f2bc2eb4f83526e0caf
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 @@
               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


More information about the Mercurial-devel mailing list