[PATCH c-hglib v2] level0.c: log command example, implemented using level 0
Iulian Stana
julian.stana at gmail.com
Fri Sep 27 10:58:33 UTC 2013
# HG changeset patch
# User Iulian Stana <julian.stana at gmail.com>
# Date 1379682875 -10800
# Fri Sep 20 16:14:35 2013 +0300
# Node ID 86f6f8561a4a8121c7781efee74659b21497b73d
# Parent 0f979fbe86d000fad5f1807cfe7008d034c71483
level0.c: log command example, implemented using level 0
This is a illustative implementation for log command. The data is unparsed and
the implementation is using just level0 functions.
diff --git a/README b/README
--- a/README
+++ b/README
@@ -50,10 +50,58 @@
Deployment
""""""""""
+
c-hglib is build with autotools, i.e. configure/make/make install
should be all what is needed to install it.
+Implementation description
+""""""""""""""""""""""""""
+
+The implementation is splitted in several levels (raw level, command level).
+
+The raw level, also called level 0, contains the basic API functions. The
+purpose of those functions is to wrap the lowest units that will be used
+later to build the mercurial commands.
+In the end using those functions you will be able to pass a raw command string
+to the Command Server and you will get some unparsed results.
+
+The command level, also called level 1, has the purpose of creating a function
+for each mercurial command. As applicable some functions will return the exit
+code and other will process the output and will return results in native C
+datatypes.
+
+
+Example
+"""""""
+
+In the example folder you will find examples on how you can use c-hglib API.
+To compile the binary files you can use the Makefile from the root directory.
+
+* Log example:
+
+The log example will use the level 0 implementation and will provide the history
+data, for a specific repository, in an unparsed way.
+To compile the binary file you can use the make tool with "examples" target.
+ > make example
+
+This action will create an executable file named log_level0.
+
+To run this executable, the first argument must be a path to the repository
+where you want to get the history.
+ e.g: ./log_level0 repository_path
+
+To run this example, you can use an existing mercurial repository,
+or create a throw-away one just for the example. Here is how
+you can create an ad-hoc repository
+ e.g:
+ > hg init tmp
+ > touch foo ; hg add foo ; hg commit -m foo
+ > echo baloo > foo ; hg commit -m 'baloo text'
+ > touch voodoo ; hg add voodoo ; hg commit -m voodoo
+ > echo voodoo > voodoo ; hg commit -m 'voodoo text'
+
+
Contact
""""""""
diff --git a/examples/log.c b/examples/log.c
new file mode 100644
--- /dev/null
+++ b/examples/log.c
@@ -0,0 +1,64 @@
+/* For more details please check the README file from the root directory.*/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "client.h"
+#include "utils.h"
+
+#define BUFF_SIZE 4096
+
+/**
+ * \brief Log command example.
+ *
+ * Will read a huge mass of data in chunks and then will print this data on
+ * stdout.
+ * \param handle The handle of the connection, wherewith I want to communicate
+ * \retval exitcode
+ * */
+int hg_log_by_hand(hg_handle *handle)
+{
+ char buff[BUFF_SIZE];
+ char *comm[] = {"log", "-v", NULL};
+ int exitcode;
+ int ns;
+
+ hg_rawcommand(handle, comm);
+ hg_header *head;
+ while (head = hg_read_header(handle), head != NULL &&
+ head->channel != r) {
+ if (head->channel == o) {
+ if (ns = hg_rawread(handle, buff, BUFF_SIZE), ns > 0) {
+ printf("%s", buff);
+ }
+ } else if (head->channel == e) {
+ if (ns = hg_rawread(handle, buff, BUFF_SIZE), ns > 0) {
+ printf("error data: %s", buff);
+ }
+ }
+ }
+
+ exitcode = hg_exitcode(handle);
+ printf("exitcode = %d\n", exitcode);
+
+ return exitcode;
+}
+
+/**
+ * \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_open(argv[1], NULL);
+ hg_log_by_hand(handle);
+ hg_close(&handle);
+
+ return 0;
+}
More information about the Mercurial-devel
mailing list