miercuri, 24 iulie 2013

#5 - C implementation of command server API

It was a long week with lots of commits and changes on my project. I
almost finished the level 0 implementation. Right now with those basic
prototypes a client can handle and implement almost all the mercurial
commands.  Now he can easily establish the connection with mercurial
command server and then send and receive data through this connection.

On our weekly meeting, my mentor, Giovanni taught me a lesson about
the ‘log’ issue, how I must handle the huge mass of data, and how to
deliver this data through the pipe, directly to the user. We agreed
that we must use a ‘trunk’ to carry the data. This ‘trunk’ will have a
fixed capacity and will not carry the entire data in one delivery.

After this short lesson, Giovanni asked me to implement some 
mercurial commands with my level 0 API, to show its purpose and 
mechanism.

Here are some examples for those commands:

- init command:

hg_handle *hg_init_by_hand()
{
pid_t cpid;
int status;
hg_handle *handle;
char command[50];
sprintf(command, "hg init %s", INIT_REPO);
if((cpid = fork()) < 0) {
printf("Fork failed\n");
return NULL;
} else if(cpid == 0) {
execl("/bin/sh", "sh", "-c", command, NULL);
printf("dadads\n\n");
} else {
waitpid( cpid, &status, 0);
}
handle = hg_open(INIT_REPO, "");
return handle;
}

- log command:

int hg_log_by_hand(hg_handle *handle)
{
char buff[4096];
char *comm[] = {"log", "-v"};
int exitcode;
hg_rawcommand(handle, comm, 2);
while(hg_rawread(handle, buff, 4096)){
printf("%s", buff);
}
if(hg_channel(handle) == 'r'){
exitcode = hg_exitcode(handle);
printf("exitcode = %d\n", exitcode);
}
return exitcode;

}

- verify command:

int hg_verify_by_hand(hg_handle *handle)
{
int exitcode = 0;
char *comm[] = {"verify"};
char buff[4096];
hg_rawcommand(handle, comm, 1);
while(hg_channel(handle) != 'r'){
if(hg_channel(handle) == 'o'){
hg_rawread(handle, buff, 4096);
printf("out = %s", buff);
}
else if(hg_channel(handle) == 'e'){
hg_rawread(handle, buff, 4096);
printf("err = %s", buff);
}
}
if(hg_channel(handle) == 'r'){
exitcode = hg_exitcode(handle);
printf("exitcode = %d\n", exitcode);
}
return exitcode;
}

You can find more of those commands on my bitbucket repository:

marți, 16 iulie 2013

#4 - C implementation of command server API

Last week I did a new brainstorming session and came up with a new API
header for the level 0, I wrote documentation for the functions,
explained for what arguments are needed and what the return value of
those functions is.


Meanwhile a new idea came up for some special commands which will be
implemented in the future, and how the level 0 function will handle
those commands. I believe that this will help me and lead me in the
same time towards a better viewpoint from where I´ll implement the API
easier.

At the end of the week I started again the implementation of the level
0 functions, according to the new API header.

I think that I am on the right path and will progress faster in the
upcoming weeks.

luni, 8 iulie 2013

#3 - C implementation of command server API

There was some progress last week on my project, but it's still a long
way to the finish. I started the week with some code refactoring and
with a new improvement: the runcommand can handle option arguments
now.

After I've sent a patchbomb to the mercurial-dev list, Matt asked me
to answer some questions and to think about some special commands
(log, merge and import), because those ones are a bit special. A
brainstorming session followed where I made a proposal, for how I
would like to deal with those commands.
At the end of the week I was waiting for some replies. In the meantime
I started to solve some issues from Bugzilla list of the mercurial
main project.

luni, 1 iulie 2013

#2 - C implementation of command server API

The second week got me introduced to the project. I started the week
with a brainstorming session on how to manage the data structure
within my project.
Then I created a header file where the function signatures are found.
This was a good point to start and I got some review and some good
advice concerning it.
In the second part of the week I implemented the “level 0” of the API.
I established a connection with the command server, through the pipes,
and then I changed some messages with the server. This was done by
passing a raw command after which I got unparsed results which were
printed on the standard output.
After my first commit, I received lots of reviews from Giovanni. I am
aware that there are some problems but I will try to solve them so I
can be ready to go to the next level.