[PATCH 3 of 5] chgserver: use _readlist and _readstr

Jun Wu quark at fb.com
Mon Feb 15 09:42:51 EST 2016


# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1455546086 0
#      Mon Feb 15 14:21:26 2016 +0000
# Node ID d1444fdc143a66f041052701d5de27a3f13881d8
# Parent  b20ad79f7cf0e20f6020cadab057367afcf96d06
chgserver: use _readlist and _readstr

Use _readlist and _readstr to make the code shorter.

diff --git a/hgext/chgserver.py b/hgext/chgserver.py
--- a/hgext/chgserver.py
+++ b/hgext/chgserver.py
@@ -283,10 +283,9 @@
         Note that the behavior of --cwd option is bit different from this.
         It does not affect --config parameter.
         """
-        length = struct.unpack('>I', self._read(4))[0]
-        if not length:
+        path = self._readstr()
+        if path is None:
             return
-        path = self._read(length)
         _log('chdir to %r\n' % path)
         os.chdir(path)
 
@@ -296,11 +295,7 @@
         If pager isn't enabled, this writes '\0' because channeledoutput
         does not allow to write empty data.
         """
-        length = struct.unpack('>I', self._read(4))[0]
-        if not length:
-            args = []
-        else:
-            args = self._read(length).split('\0')
+        args = self._readlist()
         try:
             cmd, _func, args, options, _cmdoptions = dispatch._parse(self.ui,
                                                                      args)
@@ -323,12 +318,9 @@
 
         Note that not all variables can make an effect on the running process.
         """
-        length = struct.unpack('>I', self._read(4))[0]
-        if not length:
-            return
-        s = self._read(length)
+        l = self._readlist()
         try:
-            newenv = dict(l.split('=', 1) for l in s.split('\0'))
+            newenv = dict(s.split('=', 1) for s in l)
         except ValueError:
             raise ValueError('unexpected value in setenv request')
 


More information about the Mercurial-devel mailing list