--- a/hglib.lua Wed Sep 07 21:15:06 2016 +0800
+++ b/hglib.lua Thu Sep 08 13:03:21 2016 +0800
+local lpc = require('lpc')
local sizes = { i4 = 4, u4 = 4, c = 1 }
local function read_u4(rh)
setmetatable(client, Client)
+function Client.open(repo)
+ local cmd = { 'hg', 'serve', '--cmdserver', 'pipe', '--config', 'ui.interactive=True' }
+ table.insert(cmd, '-R')
+ table.insert(cmd, repo)
+ local pid, wh, rh = lpc.run(unpack(cmd))
+ local client = Client.connect(rh, wh)
+ 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
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
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)
assert.is_true(client.capabilities.getencoding)
assert.is_true(client.capabilities.runcommand)
assert.are_equal(3615, client.pid)
assert.are_equal(3615, client.pgid)
+ 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))