Comments
Patch
@@ -110,6 +110,26 @@
> cd .. ; rm -rf export/
> 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 examples
+
+This action will create an executable file named init_level0.
+
+To run this executable, give as argument the path where you want
+the repository to be initialized.
+
+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, which is likely to be the path to c-hglib sources (it's the case if
+only `make build` 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
@@ -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;
+}