[PATCH 4 of 5 c-hglib] examples: init command example, implemented using level 0

Giovanni Gherdovich g.gherdovich at gmail.com
Sat Dec 7 05:55:33 CST 2013


:::: diff --git a/README b/README
:::: --- a/README
:::: +++ b/README
:::: @@ -102,6 +102,19 @@
::::    > cd ..
::::    > hg init import
::::
:::: +* Init example:
:::: +
:::: +The init example will use the level 0 implementation and will create
a new
:::: +repository with the given name.
:::: +To compile the binary file you can use the make tool with "examples"
target.
:::: +  > make example
:::: +
:::: +This action will create an executable file named init_level0.
:::: +
:::: +To run this executable, the first argument must be a path to the
repository
:::: +where you want to import the patch, second argument.

replace the above two lines with

"To run this executable, give as argument the path where you want
the repository to be initialized."

also:

"If c-hglib has not been installed system-wide via `make install`,
the environment variable LD_LIBRARY_PATH has to be augmented with the
path of libhg.so, wich is likely to be the path to c-hglib sources
(it's the case if only `make install` has been run).

e.g: LD_LIBRARY_PATH=/path/to/c-hglib:$LD_LIBRARY_PATH \
     ./import_level0 repository_name

:::: +
::::  * Log example:
::::
::::  The log example will use the level 0 implementation and will provide
the history
:::: diff --git a/examples/init.c b/examples/init.c
:::: new file mode 100644
:::: --- /dev/null
:::: +++ b/examples/init.c
:::: @@ -0,0 +1,67 @@
:::: +/* For more details please check the README file from the root
directory.*/
:::: +#include <stdio.h>
:::: +#include <stdlib.h>
:::: +#include <string.h>
:::: +#include <sys/wait.h>
:::: +#include <unistd.h>
:::: +#include <fcntl.h>
:::: +
:::: +#include "client.h"
:::: +#include "utils.h"
:::: +
:::: +#define BUFF_SIZE 4096
:::: +
:::: +/**
:::: + * \brief Init command example.
:::: + *
:::: + * Create a repo to the specific path, and then open the connection
with
:::: + * this new repo.
:::: + *
:::: + * The clone command will follow the same steps.
:::: + *  - clone repo
:::: + *  - open connection.
:::: + *
:::: + * \retval handle for the new repo.
:::: + * */
:::: +hg_handle *hg_init_by_hand(char *init_repo)
:::: +{
:::: + 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);
:::: + } else {
:::: + waitpid(cpid, &status, 0);
:::: + }
:::: +
:::: + handle = hg_open(init_repo, NULL);
:::: +
:::: + return handle;
:::: +}
:::: +
:::: +
:::: +/**
:::: + * \brief The main function
:::: + * */
:::: +int main(int argc, char **argv)
:::: +{
:::: + hg_handle *handle;
:::: +
:::: + if (argc != 2) {
:::: + printf("Usage: %s repository_path\n", argv[0]);
:::: + return 1;
:::: + }
:::: +
:::: + handle = hg_init_by_hand(argv[1]);
:::: + hg_close(&handle);
:::: +
:::: + return 0;
:::: +}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20131207/9c819c15/attachment.html>


More information about the Mercurial-devel mailing list