Patchwork [3,of,5,V2] chgserver: use _readlist and _readstr

login
register
mail settings
Submitter Jun Wu
Date Feb. 16, 2016, 7:50 p.m.
Message ID <f66564e297d91c89e142.1455652224@x1c>
Download mbox | patch
Permalink /patch/13234/
State Accepted
Delegated to: Yuya Nishihara
Headers show

Comments

Jun Wu - Feb. 16, 2016, 7:50 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1455650465 0
#      Tue Feb 16 19:21:05 2016 +0000
# Node ID f66564e297d91c89e1422923a1360ac31a5e14d3
# Parent  142c74f520634a006d1aa9ae5a69e37c63e41256
chgserver: use _readlist and _readstr

Use _readlist and _readstr to make the code shorter.

Patch

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 not path:
             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')