annotate contrib/hgclient.py @ 46406:95054317e172

revlog: use a less probable revlog version for backwards compatibility This allows us to define a usable v2. Differential Revision: https://phab.mercurial-scm.org/D9902
author Raphaël Gomès <rgomes@octobus.net>
date Thu, 28 Jan 2021 15:12:48 +0100
parents 9f70512ae2cf
children 6000f5b25c9b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22566
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
1 # A minimal client for Mercurial's command server
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
2
28355
897a4bbd578b hgclient: use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 22993
diff changeset
3 from __future__ import absolute_import, print_function
40317
6958eb9bdcd6 py3: rewrite StringIO fallback for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 40316
diff changeset
4
6958eb9bdcd6 py3: rewrite StringIO fallback for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 40316
diff changeset
5 import io
28355
897a4bbd578b hgclient: use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 22993
diff changeset
6 import os
40316
09540a5f0a15 py3: reinvent print() function for contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents: 40315
diff changeset
7 import re
28355
897a4bbd578b hgclient: use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 22993
diff changeset
8 import signal
897a4bbd578b hgclient: use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 22993
diff changeset
9 import socket
897a4bbd578b hgclient: use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 22993
diff changeset
10 import struct
897a4bbd578b hgclient: use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 22993
diff changeset
11 import subprocess
897a4bbd578b hgclient: use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 22993
diff changeset
12 import sys
897a4bbd578b hgclient: use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 22993
diff changeset
13 import time
22566
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
14
40315
431a831342d2 py3: work around unicode stdio streams in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents: 40314
diff changeset
15 if sys.version_info[0] >= 3:
431a831342d2 py3: work around unicode stdio streams in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents: 40314
diff changeset
16 stdout = sys.stdout.buffer
431a831342d2 py3: work around unicode stdio streams in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents: 40314
diff changeset
17 stderr = sys.stderr.buffer
40317
6958eb9bdcd6 py3: rewrite StringIO fallback for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 40316
diff changeset
18 stringio = io.BytesIO
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40984
diff changeset
19
40316
09540a5f0a15 py3: reinvent print() function for contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents: 40315
diff changeset
20 def bprint(*args):
09540a5f0a15 py3: reinvent print() function for contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents: 40315
diff changeset
21 # remove b'' as well for ease of test migration
09540a5f0a15 py3: reinvent print() function for contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents: 40315
diff changeset
22 pargs = [re.sub(br'''\bb(['"])''', br'\1', b'%s' % a) for a in args]
09540a5f0a15 py3: reinvent print() function for contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents: 40315
diff changeset
23 stdout.write(b' '.join(pargs) + b'\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40984
diff changeset
24
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40984
diff changeset
25
40315
431a831342d2 py3: work around unicode stdio streams in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents: 40314
diff changeset
26 else:
40317
6958eb9bdcd6 py3: rewrite StringIO fallback for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 40316
diff changeset
27 import cStringIO
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40984
diff changeset
28
40315
431a831342d2 py3: work around unicode stdio streams in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents: 40314
diff changeset
29 stdout = sys.stdout
431a831342d2 py3: work around unicode stdio streams in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents: 40314
diff changeset
30 stderr = sys.stderr
40317
6958eb9bdcd6 py3: rewrite StringIO fallback for Python 3
Yuya Nishihara <yuya@tcha.org>
parents: 40316
diff changeset
31 stringio = cStringIO.StringIO
40316
09540a5f0a15 py3: reinvent print() function for contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents: 40315
diff changeset
32 bprint = print
40315
431a831342d2 py3: work around unicode stdio streams in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents: 40314
diff changeset
33
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40984
diff changeset
34
40589
054d0fcba2c4 commandserver: add experimental option to use separate message channel
Yuya Nishihara <yuya@tcha.org>
parents: 40317
diff changeset
35 def connectpipe(path=None, extraargs=()):
40314
73c2b9c9cd3c py3: convert string literals to bytes in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents: 28836
diff changeset
36 cmdline = [b'hg', b'serve', b'--cmdserver', b'pipe']
22566
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
37 if path:
40314
73c2b9c9cd3c py3: convert string literals to bytes in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents: 28836
diff changeset
38 cmdline += [b'-R', path]
40589
054d0fcba2c4 commandserver: add experimental option to use separate message channel
Yuya Nishihara <yuya@tcha.org>
parents: 40317
diff changeset
39 cmdline.extend(extraargs)
22566
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
40
40984
6a372f943e49 py3: convert popen() command arguments in hgclient to str on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 40589
diff changeset
41 def tonative(cmdline):
43506
9f70512ae2cf cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
42 if os.name != 'nt':
40984
6a372f943e49 py3: convert popen() command arguments in hgclient to str on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 40589
diff changeset
43 return cmdline
6a372f943e49 py3: convert popen() command arguments in hgclient to str on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 40589
diff changeset
44 return [arg.decode("utf-8") for arg in cmdline]
6a372f943e49 py3: convert popen() command arguments in hgclient to str on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents: 40589
diff changeset
45
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40984
diff changeset
46 server = subprocess.Popen(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40984
diff changeset
47 tonative(cmdline), stdin=subprocess.PIPE, stdout=subprocess.PIPE
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40984
diff changeset
48 )
22566
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
49
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
50 return server
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
51
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40984
diff changeset
52
22993
24c5fd2894f8 test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents: 22992
diff changeset
53 class unixconnection(object):
24c5fd2894f8 test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents: 22992
diff changeset
54 def __init__(self, sockpath):
24c5fd2894f8 test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents: 22992
diff changeset
55 self.sock = sock = socket.socket(socket.AF_UNIX)
24c5fd2894f8 test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents: 22992
diff changeset
56 sock.connect(sockpath)
24c5fd2894f8 test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents: 22992
diff changeset
57 self.stdin = sock.makefile('wb')
24c5fd2894f8 test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents: 22992
diff changeset
58 self.stdout = sock.makefile('rb')
24c5fd2894f8 test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents: 22992
diff changeset
59
24c5fd2894f8 test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents: 22992
diff changeset
60 def wait(self):
24c5fd2894f8 test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents: 22992
diff changeset
61 self.stdin.close()
24c5fd2894f8 test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents: 22992
diff changeset
62 self.stdout.close()
24c5fd2894f8 test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents: 22992
diff changeset
63 self.sock.close()
24c5fd2894f8 test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents: 22992
diff changeset
64
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40984
diff changeset
65
22993
24c5fd2894f8 test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents: 22992
diff changeset
66 class unixserver(object):
24c5fd2894f8 test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents: 22992
diff changeset
67 def __init__(self, sockpath, logpath=None, repopath=None):
24c5fd2894f8 test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents: 22992
diff changeset
68 self.sockpath = sockpath
40314
73c2b9c9cd3c py3: convert string literals to bytes in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents: 28836
diff changeset
69 cmdline = [b'hg', b'serve', b'--cmdserver', b'unix', b'-a', sockpath]
22993
24c5fd2894f8 test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents: 22992
diff changeset
70 if repopath:
40314
73c2b9c9cd3c py3: convert string literals to bytes in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents: 28836
diff changeset
71 cmdline += [b'-R', repopath]
22993
24c5fd2894f8 test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents: 22992
diff changeset
72 if logpath:
24c5fd2894f8 test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents: 22992
diff changeset
73 stdout = open(logpath, 'a')
24c5fd2894f8 test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents: 22992
diff changeset
74 stderr = subprocess.STDOUT
24c5fd2894f8 test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents: 22992
diff changeset
75 else:
24c5fd2894f8 test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents: 22992
diff changeset
76 stdout = stderr = None
24c5fd2894f8 test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents: 22992
diff changeset
77 self.server = subprocess.Popen(cmdline, stdout=stdout, stderr=stderr)
24c5fd2894f8 test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents: 22992
diff changeset
78 # wait for listen()
24c5fd2894f8 test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents: 22992
diff changeset
79 while self.server.poll() is None:
24c5fd2894f8 test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents: 22992
diff changeset
80 if os.path.exists(sockpath):
24c5fd2894f8 test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents: 22992
diff changeset
81 break
24c5fd2894f8 test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents: 22992
diff changeset
82 time.sleep(0.1)
24c5fd2894f8 test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents: 22992
diff changeset
83
24c5fd2894f8 test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents: 22992
diff changeset
84 def connect(self):
24c5fd2894f8 test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents: 22992
diff changeset
85 return unixconnection(self.sockpath)
24c5fd2894f8 test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents: 22992
diff changeset
86
24c5fd2894f8 test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents: 22992
diff changeset
87 def shutdown(self):
24c5fd2894f8 test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents: 22992
diff changeset
88 os.kill(self.server.pid, signal.SIGTERM)
24c5fd2894f8 test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents: 22992
diff changeset
89 self.server.wait()
24c5fd2894f8 test-commandserver: add connector for unix domain socket server
Yuya Nishihara <yuya@tcha.org>
parents: 22992
diff changeset
90
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40984
diff changeset
91
22566
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
92 def writeblock(server, data):
40314
73c2b9c9cd3c py3: convert string literals to bytes in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents: 28836
diff changeset
93 server.stdin.write(struct.pack(b'>I', len(data)))
22566
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
94 server.stdin.write(data)
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
95 server.stdin.flush()
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
96
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40984
diff changeset
97
22566
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
98 def readchannel(server):
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
99 data = server.stdout.read(5)
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
100 if not data:
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
101 raise EOFError
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
102 channel, length = struct.unpack('>cI', data)
40314
73c2b9c9cd3c py3: convert string literals to bytes in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents: 28836
diff changeset
103 if channel in b'IL':
22566
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
104 return channel, length
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
105 else:
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
106 return channel, server.stdout.read(length)
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
107
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40984
diff changeset
108
22566
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
109 def sep(text):
40314
73c2b9c9cd3c py3: convert string literals to bytes in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents: 28836
diff changeset
110 return text.replace(b'\\', b'/')
22566
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
111
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40984
diff changeset
112
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40984
diff changeset
113 def runcommand(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40984
diff changeset
114 server, args, output=stdout, error=stderr, input=None, outfilter=lambda x: x
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40984
diff changeset
115 ):
40316
09540a5f0a15 py3: reinvent print() function for contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents: 40315
diff changeset
116 bprint(b'*** runcommand', b' '.join(args))
40315
431a831342d2 py3: work around unicode stdio streams in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents: 40314
diff changeset
117 stdout.flush()
40314
73c2b9c9cd3c py3: convert string literals to bytes in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents: 28836
diff changeset
118 server.stdin.write(b'runcommand\n')
73c2b9c9cd3c py3: convert string literals to bytes in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents: 28836
diff changeset
119 writeblock(server, b'\0'.join(args))
22566
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
120
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
121 if not input:
28836
3f45488d70df test-commandserver: handle cStringIO.StringIO/io.StringIO divergence
timeless <timeless@mozdev.org>
parents: 28355
diff changeset
122 input = stringio()
22566
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
123
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
124 while True:
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
125 ch, data = readchannel(server)
40314
73c2b9c9cd3c py3: convert string literals to bytes in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents: 28836
diff changeset
126 if ch == b'o':
22566
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
127 output.write(outfilter(data))
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
128 output.flush()
40314
73c2b9c9cd3c py3: convert string literals to bytes in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents: 28836
diff changeset
129 elif ch == b'e':
22566
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
130 error.write(data)
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
131 error.flush()
40314
73c2b9c9cd3c py3: convert string literals to bytes in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents: 28836
diff changeset
132 elif ch == b'I':
22566
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
133 writeblock(server, input.read(data))
40314
73c2b9c9cd3c py3: convert string literals to bytes in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents: 28836
diff changeset
134 elif ch == b'L':
22566
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
135 writeblock(server, input.readline(data))
40589
054d0fcba2c4 commandserver: add experimental option to use separate message channel
Yuya Nishihara <yuya@tcha.org>
parents: 40317
diff changeset
136 elif ch == b'm':
054d0fcba2c4 commandserver: add experimental option to use separate message channel
Yuya Nishihara <yuya@tcha.org>
parents: 40317
diff changeset
137 bprint(b"message: %r" % data)
40314
73c2b9c9cd3c py3: convert string literals to bytes in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents: 28836
diff changeset
138 elif ch == b'r':
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40984
diff changeset
139 (ret,) = struct.unpack('>i', data)
22566
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
140 if ret != 0:
40316
09540a5f0a15 py3: reinvent print() function for contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents: 40315
diff changeset
141 bprint(b' [%d]' % ret)
22566
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
142 return ret
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
143 else:
40316
09540a5f0a15 py3: reinvent print() function for contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents: 40315
diff changeset
144 bprint(b"unexpected channel %c: %r" % (ch, data))
22566
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
145 if ch.isupper():
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
146 return
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
147
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40984
diff changeset
148
22992
892b2b8c1b50 test-commandserver: allow check() to make connection in different way
Yuya Nishihara <yuya@tcha.org>
parents: 22991
diff changeset
149 def check(func, connect=connectpipe):
40315
431a831342d2 py3: work around unicode stdio streams in contrib/hgclient.py
Yuya Nishihara <yuya@tcha.org>
parents: 40314
diff changeset
150 stdout.flush()
22991
a94594f5d52f test-commandserver: remove unused repopath argument from check()
Yuya Nishihara <yuya@tcha.org>
parents: 22572
diff changeset
151 server = connect()
22566
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
152 try:
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
153 return func(server)
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
154 finally:
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
155 server.stdin.close()
480b7fefbb08 test-commandserver: split helper functions to new hgclient module
Yuya Nishihara <yuya@tcha.org>
parents:
diff changeset
156 server.wait()
40589
054d0fcba2c4 commandserver: add experimental option to use separate message channel
Yuya Nishihara <yuya@tcha.org>
parents: 40317
diff changeset
157
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40984
diff changeset
158
40589
054d0fcba2c4 commandserver: add experimental option to use separate message channel
Yuya Nishihara <yuya@tcha.org>
parents: 40317
diff changeset
159 def checkwith(connect=connectpipe, **kwargs):
054d0fcba2c4 commandserver: add experimental option to use separate message channel
Yuya Nishihara <yuya@tcha.org>
parents: 40317
diff changeset
160 def wrap(func):
054d0fcba2c4 commandserver: add experimental option to use separate message channel
Yuya Nishihara <yuya@tcha.org>
parents: 40317
diff changeset
161 return check(func, lambda: connect(**kwargs))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 40984
diff changeset
162
40589
054d0fcba2c4 commandserver: add experimental option to use separate message channel
Yuya Nishihara <yuya@tcha.org>
parents: 40317
diff changeset
163 return wrap