Command Server

A server that allows communication with Mercurial's API over a pipe.

1. Protocol

All communication with the server is done on stdin/stdout. The byte order used by the server is big-endian.

Data sent from the server is channel based, meaning a (channel [character], length [unsigned int]) pair is sent before the actual data. For example:

o
1234
<data: 1234 bytes>

that is 1234 bytes sent on channel 'o', with the data following.

When starting the server, it will send a new-line separated list of capabilities (on the 'o' channel), in this format:

capabilities:\n
capability1\n
capability2\n
...

At the most basic level, the server will support the 'runcommand' capability.

1.1. Encoding

Strings are encoded in the local encoding.

1.2. Channels

There are currently 5 channels:

Input should be sent on stdin in the following format:

length
data

length = 0 sent by the client is interpreted as EOF by the server.

1.3. Capabilities

The server is running on an endless loop (until stdin is closed) waiting for commands. A command request looks like this:

commandname\n
<command specific request>

runcommand\n
8
log\0
-l\0
5

Which corresponds to running 'hg log -l 5'.


CategoryDeveloper