C-hglib, first plan attempt

Matt Mackall mpm at selenic.com
Thu Jun 20 11:50:25 CDT 2013


On Thu, 2013-06-20 at 00:28 +0300, Iulian Stana wrote:
> *C-hglib - C implementation of command server API*
> 
> A C library for interfacing with Mercurial's CommandServer.
> 
> The communication between C library and Mercurial CommandServer will be
> over a pipe.
> 
> I have to create an API for the Command server, in other words I have to
> create a connection mechanism and a set of some specific commands that will
> help the user to interrogate the server, in order to get some useful
> information.

You should probably begin by:

a) reviewing all of python-hglib
b) reviewing all of https://bitbucket.org/yuja/chg/src

Note: you probably won't be able to actually use any code from the
latter, as its desirable for your project to NOT be GPL.

You'll probably also want to talk to Idan and Yuya about their projects
(cc: the list, please).

Also, be forewarned: the hardest technical aspect of this will probably
not be the code itself. It'll probably be crafting a good API for your
users... since you won't be able to change your API later. So you should
start sketching that out soon and getting feedback on it.

I think there are several levels of functionality you should aim to
build, in this order:

0) raw level - pass a raw command string, get unparsed results
1) command level - function per command, returns results in native C
datatypes
2) "object" level - emulate important Mercurial internal APIs like
contexts with a native C paradigm




> Some steps that I want to do first:
> 
>    -
> 
>    create an open mechanism between Client (C library) and Server (
>    Mercurial Command Server)
>    -
> 
>    close the connection
>    -
> 
>    readchannel function that will get the channel and the length of message.
>    -
> 
>    create the _hello function, that will receive the first message, after
>    the connection.
>    -
> 
>    cmdbuilder, will compute the command that will be sent to CommandServer.
>    -
> 
>    runcommand, will send the build command to the server and will return
>    the compute message.
>    -
> 
>    mercurial commands.
> 
> 
> 
> How to make it happen:
> 
> -Create an open mechanism between Client (C library) and Server ( Mercurial
> Command Server)
> 
> First I will try to compute a command that will be execute in the child
> process.
> 
> It will be of the form “HGPATH serve --cmdserver pipe --config
> ui.interactive=True” + “-R path ”
> 
> I will create two pipes for the bidirectional connection. Then I will fork
> a new process, where I’ll execute the command that will open the Command
> Server. In the child process I will redirect the input, the output and the
> error in to the pipes (for the communication Client-Server). In my case the
> child process will open the Command Server and the parent process will be
> the client.
> 
> The communication will be through the pipes descriptors.
> 
> The open function will return a Client structure that will contain the
> pipes descriptors and other useful information.
> 
> 
> - Close the connection
> 
> Will kill the command server and will close the pipe descriptors for a
> specific Client.
> 
> 
> - readchannel function that will get the channel and the length of message.
> 
> Will read a char (the channel) and a uint (the length). There are chances
> for a problem to occur over here with the unsigned integer (the Command
> Server will send to me an integer in big endian form). Most probably I will
> have to create a conversion mechanism.
> 
> 
>  - create the _hello function that will receive the first message, after
> the connection.
> 
> This function will read the channel and the default data. Then I will check
> the correctness of data.
> 
> 
> - cmdbuilder, will compute the command that will be sent to CommandServer.
> 
> This function will return a list with a compute command that will be send
> to CommandServer. This function will be called by all mercurial commands.
> 
> 
> - runcommand, will send the build command to the server and will return the
> compute message.
> 
> >From this function I will sent through pipes the commands and I will
> receive the specific answers. This will be the function that will make the
> communication.
> 
> 
>  My starts points will be:
> 
> *http://mercurial.selenic.com/wiki/CommandServer*
> 
> *http://www.selenic.com/repo/python-hglib/file/ca5f8f43e585/*
> 
> 
>  I made a directory schema that will serve my purpose.
> 
> .
> 
> ├── hglib
> 
> │   ├── main.c
> 
> │   ├── Makefile.am
> 
> │   ├── utils.c
> 
> │   └── utils.h
> 
> ├── Makefile.am
> 
> ├── README.md
> 
> └── tests
> 
> └── Makefile.am
> 
> 
>  Progressing I will try to integrate the testing tool in my code, and to
> bring correctness in project.
> 
> 
>  I had stated a bitbucket repository, with marmoute advice:
> 
> *https://bitbucket.org/istana/c-hglib*
> 
> 
> 2013/6/20 Iulian Stana <julian.stana at gmail.com>
> 
> > I had attached my plan for C-hglib project.
> >
> > I would like some advice about this plan and what I must do to achieve my
> > project.
> >
> > Regards,
> > Iulian
> >
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel


-- 
Mathematics is the supreme nostalgia of our time.




More information about the Mercurial-devel mailing list