##// END OF EJS Templates
sidedatacopies: only fetch information once for merge...
sidedatacopies: only fetch information once for merge Before this change, merge would result in reading the data from revlog twice. With this change, we keep the information in memory until we encounter the other parent. When looking at pypy, I see about 1/3 of the changesets with copy information being merge. Not doing duplicated fetch for them provide a significant speedup. revision: large amount; added files: large amount; rename small amount; c3b14617fbd7 9ba6ab77fd29 before: ! wall 0.767042 comb 0.760000 user 0.750000 sys 0.010000 (median of 11) after: ! wall 0.671162 comb 0.670000 user 0.650000 sys 0.020000 (median of 13) revision: large amount; added files: small amount; rename small amount; c3b14617fbd7 f650a9b140d2 before: ! wall 1.170169 comb 1.170000 user 1.130000 sys 0.040000 (median of 10) after: ! wall 1.030596 comb 1.040000 user 1.010000 sys 0.030000 (median of 10) revision: large amount; added files: large amount; rename large amount; 08ea3258278e d9fa043f30c0 before: ! wall 0.209846 comb 0.200000 user 0.200000 sys 0.000000 (median of 46) after: ! wall 0.170981 comb 0.170000 user 0.170000 sys 0.000000 (median of 56) revision: small amount; added files: large amount; rename large amount; df6f7a526b60 a83dc6a2d56f before: ! wall 0.013248 comb 0.010000 user 0.010000 sys 0.000000 (median of 223) after: ! wall 0.013295 comb 0.020000 user 0.020000 sys 0.000000 (median of 222) revision: small amount; added files: large amount; rename small amount; 4aa4e1f8e19a 169138063d63 before: ! wall 0.001672 comb 0.000000 user 0.000000 sys 0.000000 (median of 1000) after: ! wall 0.001666 comb 0.000000 user 0.000000 sys 0.000000 (median of 1000) revision: small amount; added files: small amount; rename small amount; 4bc173b045a6 964879152e2e before: ! wall 0.000119 comb 0.000000 user 0.000000 sys 0.000000 (median of 8010) after: ! wall 0.000119 comb 0.000000 user 0.000000 sys 0.000000 (median of 8007) revision: medium amount; added files: large amount; rename medium amount; c95f1ced15f2 2c68e87c3efe before: ! wall 0.168599 comb 0.160000 user 0.160000 sys 0.000000 (median of 58) after: ! wall 0.133316 comb 0.140000 user 0.140000 sys 0.000000 (median of 73) revision: medium amount; added files: medium amount; rename small amount; d343da0c55a8 d7746d32bf9d before: ! wall 0.036052 comb 0.030000 user 0.030000 sys 0.000000 (median of 100) after: ! wall 0.032558 comb 0.030000 user 0.030000 sys 0.000000 (median of 100) Differential Revision: https://phab.mercurial-scm.org/D7127

File last commit:

r43346:2372284d default
r43595:90213d02 default
Show More
hgclient.py
163 lines | 4.0 KiB | text/x-python | PythonLexer
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566 # A minimal client for Mercurial's command server
Pulkit Goyal
hgclient: use absolute_import and print_function
r28355 from __future__ import absolute_import, print_function
Yuya Nishihara
py3: rewrite StringIO fallback for Python 3
r40353
import io
Pulkit Goyal
hgclient: use absolute_import and print_function
r28355 import os
Yuya Nishihara
py3: reinvent print() function for contrib/hgclient.py
r40352 import re
Pulkit Goyal
hgclient: use absolute_import and print_function
r28355 import signal
import socket
import struct
import subprocess
import sys
import time
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566
Yuya Nishihara
py3: work around unicode stdio streams in contrib/hgclient.py
r40351 if sys.version_info[0] >= 3:
stdout = sys.stdout.buffer
stderr = sys.stderr.buffer
Yuya Nishihara
py3: rewrite StringIO fallback for Python 3
r40353 stringio = io.BytesIO
Augie Fackler
formatting: blacken the codebase...
r43346
Yuya Nishihara
py3: reinvent print() function for contrib/hgclient.py
r40352 def bprint(*args):
# remove b'' as well for ease of test migration
pargs = [re.sub(br'''\bb(['"])''', br'\1', b'%s' % a) for a in args]
stdout.write(b' '.join(pargs) + b'\n')
Augie Fackler
formatting: blacken the codebase...
r43346
Yuya Nishihara
py3: work around unicode stdio streams in contrib/hgclient.py
r40351 else:
Yuya Nishihara
py3: rewrite StringIO fallback for Python 3
r40353 import cStringIO
Augie Fackler
formatting: blacken the codebase...
r43346
Yuya Nishihara
py3: work around unicode stdio streams in contrib/hgclient.py
r40351 stdout = sys.stdout
stderr = sys.stderr
Yuya Nishihara
py3: rewrite StringIO fallback for Python 3
r40353 stringio = cStringIO.StringIO
Yuya Nishihara
py3: reinvent print() function for contrib/hgclient.py
r40352 bprint = print
Yuya Nishihara
py3: work around unicode stdio streams in contrib/hgclient.py
r40351
Augie Fackler
formatting: blacken the codebase...
r43346
Yuya Nishihara
commandserver: add experimental option to use separate message channel...
r40625 def connectpipe(path=None, extraargs=()):
Yuya Nishihara
py3: convert string literals to bytes in contrib/hgclient.py...
r40350 cmdline = [b'hg', b'serve', b'--cmdserver', b'pipe']
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566 if path:
Yuya Nishihara
py3: convert string literals to bytes in contrib/hgclient.py...
r40350 cmdline += [b'-R', path]
Yuya Nishihara
commandserver: add experimental option to use separate message channel...
r40625 cmdline.extend(extraargs)
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566
Matt Harbison
py3: convert popen() command arguments in hgclient to str on Windows...
r41020 def tonative(cmdline):
if os.name != r'nt':
return cmdline
return [arg.decode("utf-8") for arg in cmdline]
Augie Fackler
formatting: blacken the codebase...
r43346 server = subprocess.Popen(
tonative(cmdline), stdin=subprocess.PIPE, stdout=subprocess.PIPE
)
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566
return server
Augie Fackler
formatting: blacken the codebase...
r43346
Yuya Nishihara
test-commandserver: add connector for unix domain socket server...
r22993 class unixconnection(object):
def __init__(self, sockpath):
self.sock = sock = socket.socket(socket.AF_UNIX)
sock.connect(sockpath)
self.stdin = sock.makefile('wb')
self.stdout = sock.makefile('rb')
def wait(self):
self.stdin.close()
self.stdout.close()
self.sock.close()
Augie Fackler
formatting: blacken the codebase...
r43346
Yuya Nishihara
test-commandserver: add connector for unix domain socket server...
r22993 class unixserver(object):
def __init__(self, sockpath, logpath=None, repopath=None):
self.sockpath = sockpath
Yuya Nishihara
py3: convert string literals to bytes in contrib/hgclient.py...
r40350 cmdline = [b'hg', b'serve', b'--cmdserver', b'unix', b'-a', sockpath]
Yuya Nishihara
test-commandserver: add connector for unix domain socket server...
r22993 if repopath:
Yuya Nishihara
py3: convert string literals to bytes in contrib/hgclient.py...
r40350 cmdline += [b'-R', repopath]
Yuya Nishihara
test-commandserver: add connector for unix domain socket server...
r22993 if logpath:
stdout = open(logpath, 'a')
stderr = subprocess.STDOUT
else:
stdout = stderr = None
self.server = subprocess.Popen(cmdline, stdout=stdout, stderr=stderr)
# wait for listen()
while self.server.poll() is None:
if os.path.exists(sockpath):
break
time.sleep(0.1)
def connect(self):
return unixconnection(self.sockpath)
def shutdown(self):
os.kill(self.server.pid, signal.SIGTERM)
self.server.wait()
Augie Fackler
formatting: blacken the codebase...
r43346
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566 def writeblock(server, data):
Yuya Nishihara
py3: convert string literals to bytes in contrib/hgclient.py...
r40350 server.stdin.write(struct.pack(b'>I', len(data)))
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566 server.stdin.write(data)
server.stdin.flush()
Augie Fackler
formatting: blacken the codebase...
r43346
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566 def readchannel(server):
data = server.stdout.read(5)
if not data:
raise EOFError
channel, length = struct.unpack('>cI', data)
Yuya Nishihara
py3: convert string literals to bytes in contrib/hgclient.py...
r40350 if channel in b'IL':
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566 return channel, length
else:
return channel, server.stdout.read(length)
Augie Fackler
formatting: blacken the codebase...
r43346
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566 def sep(text):
Yuya Nishihara
py3: convert string literals to bytes in contrib/hgclient.py...
r40350 return text.replace(b'\\', b'/')
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566
Augie Fackler
formatting: blacken the codebase...
r43346
def runcommand(
server, args, output=stdout, error=stderr, input=None, outfilter=lambda x: x
):
Yuya Nishihara
py3: reinvent print() function for contrib/hgclient.py
r40352 bprint(b'*** runcommand', b' '.join(args))
Yuya Nishihara
py3: work around unicode stdio streams in contrib/hgclient.py
r40351 stdout.flush()
Yuya Nishihara
py3: convert string literals to bytes in contrib/hgclient.py...
r40350 server.stdin.write(b'runcommand\n')
writeblock(server, b'\0'.join(args))
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566
if not input:
timeless
test-commandserver: handle cStringIO.StringIO/io.StringIO divergence
r28836 input = stringio()
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566
while True:
ch, data = readchannel(server)
Yuya Nishihara
py3: convert string literals to bytes in contrib/hgclient.py...
r40350 if ch == b'o':
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566 output.write(outfilter(data))
output.flush()
Yuya Nishihara
py3: convert string literals to bytes in contrib/hgclient.py...
r40350 elif ch == b'e':
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566 error.write(data)
error.flush()
Yuya Nishihara
py3: convert string literals to bytes in contrib/hgclient.py...
r40350 elif ch == b'I':
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566 writeblock(server, input.read(data))
Yuya Nishihara
py3: convert string literals to bytes in contrib/hgclient.py...
r40350 elif ch == b'L':
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566 writeblock(server, input.readline(data))
Yuya Nishihara
commandserver: add experimental option to use separate message channel...
r40625 elif ch == b'm':
bprint(b"message: %r" % data)
Yuya Nishihara
py3: convert string literals to bytes in contrib/hgclient.py...
r40350 elif ch == b'r':
Augie Fackler
formatting: blacken the codebase...
r43346 (ret,) = struct.unpack('>i', data)
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566 if ret != 0:
Yuya Nishihara
py3: reinvent print() function for contrib/hgclient.py
r40352 bprint(b' [%d]' % ret)
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566 return ret
else:
Yuya Nishihara
py3: reinvent print() function for contrib/hgclient.py
r40352 bprint(b"unexpected channel %c: %r" % (ch, data))
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566 if ch.isupper():
return
Augie Fackler
formatting: blacken the codebase...
r43346
Yuya Nishihara
test-commandserver: allow check() to make connection in different way...
r22992 def check(func, connect=connectpipe):
Yuya Nishihara
py3: work around unicode stdio streams in contrib/hgclient.py
r40351 stdout.flush()
Yuya Nishihara
test-commandserver: remove unused repopath argument from check()...
r22991 server = connect()
Yuya Nishihara
test-commandserver: split helper functions to new hgclient module...
r22566 try:
return func(server)
finally:
server.stdin.close()
server.wait()
Yuya Nishihara
commandserver: add experimental option to use separate message channel...
r40625
Augie Fackler
formatting: blacken the codebase...
r43346
Yuya Nishihara
commandserver: add experimental option to use separate message channel...
r40625 def checkwith(connect=connectpipe, **kwargs):
def wrap(func):
return check(func, lambda: connect(**kwargs))
Augie Fackler
formatting: blacken the codebase...
r43346
Yuya Nishihara
commandserver: add experimental option to use separate message channel...
r40625 return wrap