Mercurial > public > mercurial-scm > hg
comparison hgext/chgserver.py @ 28158:7cc57a531f0c
chgserver: use _readlist and _readstr
Use _readlist and _readstr to make the code shorter.
author | Jun Wu <quark@fb.com> |
---|---|
date | Tue, 16 Feb 2016 19:21:05 +0000 |
parents | 83fc0c055664 |
children | d2d04d1d2f92 |
comparison
equal
deleted
inserted
replaced
28157:e7c9b59dbbcf | 28158:7cc57a531f0c |
---|---|
281 """Change current directory | 281 """Change current directory |
282 | 282 |
283 Note that the behavior of --cwd option is bit different from this. | 283 Note that the behavior of --cwd option is bit different from this. |
284 It does not affect --config parameter. | 284 It does not affect --config parameter. |
285 """ | 285 """ |
286 length = struct.unpack('>I', self._read(4))[0] | 286 path = self._readstr() |
287 if not length: | 287 if not path: |
288 return | 288 return |
289 path = self._read(length) | |
290 _log('chdir to %r\n' % path) | 289 _log('chdir to %r\n' % path) |
291 os.chdir(path) | 290 os.chdir(path) |
292 | 291 |
293 def getpager(self): | 292 def getpager(self): |
294 """Read cmdargs and write pager command to r-channel if enabled | 293 """Read cmdargs and write pager command to r-channel if enabled |
295 | 294 |
296 If pager isn't enabled, this writes '\0' because channeledoutput | 295 If pager isn't enabled, this writes '\0' because channeledoutput |
297 does not allow to write empty data. | 296 does not allow to write empty data. |
298 """ | 297 """ |
299 length = struct.unpack('>I', self._read(4))[0] | 298 args = self._readlist() |
300 if not length: | |
301 args = [] | |
302 else: | |
303 args = self._read(length).split('\0') | |
304 try: | 299 try: |
305 cmd, _func, args, options, _cmdoptions = dispatch._parse(self.ui, | 300 cmd, _func, args, options, _cmdoptions = dispatch._parse(self.ui, |
306 args) | 301 args) |
307 except (error.Abort, error.AmbiguousCommand, error.CommandError, | 302 except (error.Abort, error.AmbiguousCommand, error.CommandError, |
308 error.UnknownCommand): | 303 error.UnknownCommand): |
321 def setenv(self): | 316 def setenv(self): |
322 """Clear and update os.environ | 317 """Clear and update os.environ |
323 | 318 |
324 Note that not all variables can make an effect on the running process. | 319 Note that not all variables can make an effect on the running process. |
325 """ | 320 """ |
326 length = struct.unpack('>I', self._read(4))[0] | 321 l = self._readlist() |
327 if not length: | |
328 return | |
329 s = self._read(length) | |
330 try: | 322 try: |
331 newenv = dict(l.split('=', 1) for l in s.split('\0')) | 323 newenv = dict(s.split('=', 1) for s in l) |
332 except ValueError: | 324 except ValueError: |
333 raise ValueError('unexpected value in setenv request') | 325 raise ValueError('unexpected value in setenv request') |
334 | 326 |
335 diffkeys = set(k for k in set(os.environ.keys() + newenv.keys()) | 327 diffkeys = set(k for k in set(os.environ.keys() + newenv.keys()) |
336 if os.environ.get(k) != newenv.get(k)) | 328 if os.environ.get(k) != newenv.get(k)) |