<div dir="ltr"><div>After some of Matt's remarks I write a new API proposal for c-hglib. </div><div>I come with some answers for Matt's questions and a header file for </div><div>the level 0 ( here are some of the basic functions that will help me </div>
<div>to achieve the API purpose)</div><div>I would like to get feedback to know if I am on the good path.    <br></div><div><br></div><div><br></div>What does this return?<br>- int hg_rawread(hg_handle *handle, char *buffer, size_t sizebuff);<br>
- int hg_rawcommand(hg_handle *handle, const char *command);<br>- int hg_close(hg_handle *handle);<br><br>.h file:<br><br>typedef struct hg_handle hg_handle;<br>typedef struct hg_header{<br>   char channel;<br>   uint32_t length;<br>
} hg_header;<br><br>/* return the handle for a connection */<br>hg_handle* hg_open(const char *path);<br><br>/* The function returns 0 if successful, -1 to indicate an error, with errno set appropriately. */<br>int hg_close(hg_handle *handle);<br>
<br>/* The function returns 0 if successful, -1 to indicate an error, with errno set appropriately. */<br>/* It's just sending the command to the cmdsrv.*/<br>int hg_rawcommand(hg_handle *handle, const char *command);<br>
<br>/* The function returns the number of bytes read. On end-of-file, 0 is returned, on error it returns -1, setting errno to indicate the type of error that occurred. */<br>int hg_rawread(hg_handle *handle, char *buffer, size_t sizebuff);<br>
<br>/* The function returns the number of bytes written to the file. A return value of -1 indicates an error, with errno set appropriately. */<br>int hg_rawsend( hg_handle *handle, char *buffer);<br><br>/* The function returns the channel for the next chunk*/<br>
char hg_channel(hg_handle *handle);<br><br>/* The function returns the header in advance. */<br>hg_header hg_ rawchunk(hg_handle *handle);<br><br>/* The function returns the exitcode received from cmdserver.*/<div>int hg_exitcode(hg_handle * handle);</div>
<div><br>/* It's just a proposal for how to send/receive data through connection<br>while 1:<br>    switch(hg_channel(handle)):<br>        case 'r':<br><div>            hg_exitcode(handle);</div><div>            break;</div>
<div>        case 'o':<br>            /* Make something with data save it into a data structure*/<br>            hg_rawread(handle, buffer , size);<br>            save_into_out_channel(buffer);<br>        case 'e':<br>
            hg_rawread(handle, buffer , size);<br>            save_into_err_channel(buffer);<br>        case 'I':<br>        case 'L':<br>            hg_rawsend(handle, buffer);<br>*/<br><br>This doesn't mean "figure out how to wrap these commands" in C code, instead it means "figure out how to expose enough of the protocol to the user so that they can run these sorts commands"<br>
In figuring out what needs to be in the level 0 API, here are the commands you should probably figure out a story for:<br><br>a) hg init <- doesn't start with a repo<br>In this case, I will create a new process were I will execute the init command, to create the new repo. After this, I will establish the connection through pipes, with the cmdserver.<br>
For the clone command, there I will execute the same steps.<br>The return in those cases will be the handle for the connection.<br><br>b) hg log <- can produce huge output<br>I know that some repo could have a huge log, but I don't know if the user will use that huge output. My single thought right now is to set a limit for the huge mass of data.<br>
“The memory is full, the log data for this repo it's bigger than MAX_SIZE, you can specify a file were the data to be store.”<br>I don't know if this is the best solution... Other ideas are welcome.<br><br>c) hg import - <- wants a patch fed to it from client<br>
If patch is a list of files or a file-like, then the input for the command server will be from those files. In this case the data will be send line by line to the server.<br><br>d) hg merge <- has prompts<br>By default, if there will be any prompts the merge will abort.<br>
There can be use the '-y' option or a function that gets a single argument which are the contents of stdout. It should return one of the expected choices (a single character).<br><br>e) hg verify <- might give warnings intermixed with output<br>
Returns 0 on success, 1 if errors are encountered.<br>In handle I will save the good output and warnings/errors.<br>I will let the user to choose if he wants just a verification or the error/output. I think that would be nice to have an option for the user choose. <br>
<br>Have a nice day,</div><div>Iulian
</div></div></div>