Comments
Patch
new file mode 100644
@@ -0,0 +1,126 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <unistd.h>
+
+#include "../hglib/client.h"
+#include "../hglib/utils.h"
+
+#define BUFF_SIZE 4096
+
+/****** Convenience functions. *******/
+
+/**
+ * \brief Create and setup the tmp directory where the acction will happends.
+ * */
+void setup_tmp()
+{
+ system("hg init tmp");
+ chdir("tmp");
+}
+
+/**
+ * \brief Remove the tmp directory and all his files.
+ * */
+void clean_tmp()
+{
+ chdir("..");
+ system("rm -rf tmp");
+}
+
+/**
+ * \brief Fill the current repository with commits for log command.
+ * */
+void setup_log()
+{
+ system("touch foo ; hg add foo ; hg commit -m foo");
+ system("echo baloo > foo ; hg commit -m 'baloo text'");
+ system("touch voodoo ; hg add voodoo ; hg commit -m voodoo");
+ system("echo voodoo > voodoo ; hg commit -m 'voodoo text'");
+}
+
+/**
+ * \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->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 Printing the welcome message.
+ *
+ * Will print the options that you will have in this example.
+ **/
+void print_select_case()
+{
+ printf("Select test case to run:\n");
+ printf("1) log \n");
+ printf("\n");
+ printf("Your choice: ");
+}
+
+
+/***** Main function. *******/
+/**
+ * \brief The main function
+ * */
+int main(int argc, char **argv)
+{
+ int select_case;
+ hg_handle *handle;
+
+ print_select_case();
+ scanf("%d", &select_case);
+ printf("\n");
+
+ if (select_case < 1 || select_case > 1) {
+ printf("Your choice is not an option...\n");
+ return -1;
+ }
+
+ switch(select_case){
+ case 1:
+ setup_tmp();
+ setup_log();
+ handle = hg_open(NULL, NULL);
+ hg_log_by_hand(handle);
+
+ hg_close(&handle);
+ clean_tmp();
+ break;
+ default:
+ break;
+ }
+
+ return 0;
+}