Download:
child 3:48f6ea626b5c
parent 1:f765e0e5649b
2:2038aaa338fb
Anton Shestakov <av6@dwimlabs.net>, Thu, 08 Sep 2016 13:03:21 +0800
hglib: starting a new command server via Client.open()

2 файлов изменено, 32 вставок(+), 2 удалений(-) [+]
hglib.lua file | annotate | diff | comparison | revisions
spec/hglib_spec.lua file | annotate | diff | comparison | revisions
--- a/hglib.lua Wed Sep 07 21:15:06 2016 +0800
+++ b/hglib.lua Thu Sep 08 13:03:21 2016 +0800
@@ -1,3 +1,5 @@
+local lpc = require('lpc')
+
local sizes = { i4 = 4, u4 = 4, c = 1 }
local function read_u4(rh)
@@ -31,9 +33,28 @@
setmetatable(client, Client)
client.rh = rh
client.wh = wh
+ client:read_hello()
return client
end
+function Client.open(repo)
+ local cmd = { 'hg', 'serve', '--cmdserver', 'pipe', '--config', 'ui.interactive=True' }
+ if repo ~= nil then
+ table.insert(cmd, '-R')
+ table.insert(cmd, repo)
+ end
+ local pid, wh, rh = lpc.run(unpack(cmd))
+ local client = Client.connect(rh, wh)
+ client.lpcpid = pid
+ return client
+end
+
+function Client:close()
+ if self.wh ~= nil then self.wh:close() end
+ if self.rh ~= nil then self.rh:close() end
+ if self.lpcpid ~= nil then lpc.wait(self.lpcpid) end
+end
+
function Client:read_hello()
local channel, message = read_channel(self.rh)
assert(channel == 'o', 'channel for the hello message must be "o"')
--- a/spec/hglib_spec.lua Wed Sep 07 21:15:06 2016 +0800
+++ b/spec/hglib_spec.lua Thu Sep 08 13:03:21 2016 +0800
@@ -1,10 +1,9 @@
local hglib = require('hglib')
describe('hglib client', function()
- it('can read hello', function()
+ it('can connect using just file handles', function()
local rh = io.open('spec/data/hello', 'rb')
local client = hglib.Client.connect(rh, nil)
- client:read_hello()
rh:close()
assert.is_true(client.capabilities.getencoding)
assert.is_true(client.capabilities.runcommand)
@@ -12,4 +11,14 @@
assert.are_equal(3615, client.pid)
assert.are_equal(3615, client.pgid)
end)
+
+ it('can launch a new cmdserver process', function()
+ local client = hglib.Client.open()
+ assert.is_true(client.capabilities.getencoding)
+ assert.is_true(client.capabilities.runcommand)
+ assert.are_equal('UTF-8', client.encoding)
+ assert.are_equal('number', type(client.pid))
+ assert.are_equal('number', type(client.lpcpid))
+ client:close()
+ end)
end)