[PATCH] chgserver: resolve relative path before sending via system channel

Jun Wu quark at fb.com
Sat Mar 12 05:12:36 UTC 2016


# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1457754336 0
#      Sat Mar 12 03:45:36 2016 +0000
# Node ID 82abdd91e22e218fbf17d032cbb15be72252fb28
# Parent  3bd824c35cd84e5259e65be611a40ad2f8080922
chgserver: resolve relative path before sending via system channel

The chgserver may have a different cwd from the client because of the side
effect of "--cwd" and other possible os.chdir done by extensions. Therefore
relative paths can be misunderstood by the client.

This patch solves it by expanding relative cwd path to absolute one before
sending them via the 'S' channel. It helps chg to pass a testcase in
test-alias.t.

diff --git a/hgext/chgserver.py b/hgext/chgserver.py
--- a/hgext/chgserver.py
+++ b/hgext/chgserver.py
@@ -243,6 +243,8 @@
                 csystem = self._csystem
             else:
                 csystem = defaultcsystem
+            if cwd is not None and not os.path.isabs(cwd):
+                cwd = os.path.realpath(cwd)
             rc = csystem(cmd, env, cwd)
             if rc and onerr:
                 errmsg = '%s %s' % (os.path.basename(cmd.split(None, 1)[0]),
@@ -311,7 +313,7 @@
         self.channel = channel
 
     def __call__(self, cmd, environ, cwd):
-        args = [util.quotecommand(cmd), cwd or '.']
+        args = [util.quotecommand(cmd), cwd or os.getcwd()]
         args.extend('%s=%s' % (k, v) for k, v in environ.iteritems())
         data = '\0'.join(args)
         self.out.write(struct.pack('>cI', self.channel, len(data)))


More information about the Mercurial-devel mailing list