[PATCH 2 of 6 RFC hglib] hg_log: a high level function for mercurial log command

Iulian Stana julian.stana at gmail.com
Thu Sep 5 14:13:22 UTC 2013


# HG changeset patch
# User Iulian Stana <julian.stana at gmail.com>
# Date 1378383005 -10800
#      Thu Sep 05 15:10:05 2013 +0300
# Node ID 4307b7b1166b01417bb9e15467c9db16d059484b
# Parent  f9378d0bd4c029c52c50ee5205255f24e2073a6d
hg_log: a high level function for mercurial log command

This function can provide a huge amount of data. To prevent a stack overflow
this function will not provide any data. This function will provide a mechanism
to get data in chunks in a parse way.

Using hg_csetstream_buffer structure and hg_fetch_cset_entry function the data
will be delivered to user in chunks(a changeset at a time) and will be put in a
parse structure.

diff --git a/client.c b/client.c
--- a/client.c
+++ b/client.c
@@ -22,3 +22,24 @@
 	*buff = new_buff;
 	return new_buff_size;
 }
+
+/* The high level log command for hglib API. */
+hg_csetstream_buffer *hg_log(hg_handle *handle, int (*callback)(const char *msg,
+						size_t len), char *argument[])
+{
+	hg_csetstream_buffer *cbuf = malloc(sizeof(hg_csetstream_buffer));
+	cbuf->handle = handle;
+
+	cbuf->command = cmdbuilder("log", argument, "--template", CHANGESET,
+							NULL);
+
+	if(hg_rawcommand(handle, cbuf->command) < 0){
+		return NULL;
+	}
+
+	cbuf->callback = callback;
+	cbuf->buffer = NULL;
+	cbuf->buf_size = 0;
+
+	return cbuf;
+}
diff --git a/client.h b/client.h
new file mode 100644
--- /dev/null
+++ b/client.h
@@ -0,0 +1,52 @@
+#ifndef _CLIENT_H_
+#define _CLIENT_H_
+
+#include <errno.h>
+#include <stdint.h>
+#include <sys/types.h>
+
+
+typedef struct hg_csetstream_buffer{
+	hg_handle *handle;
+	int (*callback)(const char *msg, size_t len);
+	char **command;
+	char *buffer;
+	int buf_size;
+	int first_cset_size;
+}hg_csetstream_buffer;
+
+
+
+/**
+ * \brief hg_log command for hglib API.
+ *
+ * It's an advance function to get revision history. It's more like the start 
+ * point of the action, this function will prepare the query question and will 
+ * send it to the cmd-server.
+ *
+ * Return the revision history of the specified files or the entire project.
+ * File history is shown without following rename or copy history of files.
+ * Use follow with a filename to follow history across renames and copies.
+ * follow without a filename will only show ancestors or descendants of the
+ * starting revision. followfirst only follows the first parent of merge
+ * revisions.
+ *
+ * If revrange isn't specified, the default is "tip:0" unless follow is set,
+ * in which case the working directory parent is used as the starting
+ * revision.
+ *
+ * \param handle The handle of the connection, wherewith I want to communicate
+ * \param callback A function that will handle error data. 
+ *                 A NULL pointer will ignore error data.
+ * \param argument The option list. Will contain all option that you wish.
+ * \retval hg_csetstream_buffer A pointer to hg_csetstream_buffer structure if 
+ *                              successful
+ * \retval NULL to indicate an error, with errno set appropriately.
+ *
+ * errno can be:
+ *      - hg_rawcommand errors
+ * */
+hg_csetstream_buffer *hg_log(hg_handle *handle, int (*callback)(const char *msg,
+						size_t len), char *argument[]);
+
+#endif



More information about the Mercurial-devel mailing list