Patchwork [21,of,55,RFC,c-hglib:level1] hg_export: creating a high level function for mercurial export command

login
register
mail settings
Submitter Iulian Stana
Date Sept. 14, 2013, 12:35 a.m.
Message ID <96cf6fc587a26c0c104e.1379118933@doppler>
Download mbox | patch
Permalink /patch/2465/
State Deferred, archived
Headers show

Comments

Iulian Stana - Sept. 14, 2013, 12:35 a.m.
# HG changeset patch
# User Iulian Stana <julian.stana@gmail.com>
# Date 1379111863 -10800
#      Sat Sep 14 01:37:43 2013 +0300
# Node ID 96cf6fc587a26c0c104ec243f9305b69ad7ecb99
# Parent  30726b3c4e0788afaaf354cdd85cda30906a90b9
hg_export: creating a high level function for mercurial export command

Patch

diff --git a/client.c b/client.c
--- a/client.c
+++ b/client.c
@@ -740,6 +740,26 @@ 
 	return dbuf;
 }
 
+/* The high level cat command for hglib API. */
+hg_linestream_buffer *hg_export(hg_handle *handle, int (*callback)
+			(const char *msg, size_t len), char *argument[])
+{
+	hg_linestream_buffer *ebuf = malloc(sizeof(hg_csetstream_buffer));
+	ebuf->handle = handle;
+
+	ebuf->command = cmdbuilder("export", argument, NULL);
+
+	if(hg_rawcommand(handle, ebuf->command) < 0){
+		return NULL;
+	}
+
+	ebuf->callback = callback;
+	ebuf->buffer = NULL;
+	ebuf->buf_size = 0;
+
+	return ebuf;
+}
+
 /* The yield next step. Getting the next entry. */
 int hg_fetch_entry(hg_stream_buffer *stream, int (*detect_byte)(char *buff, 
 			int buf_size, int data_on_pipe), int func_type)
diff --git a/client.h b/client.h
--- a/client.h
+++ b/client.h
@@ -918,6 +918,43 @@ 
 			(const char *msg, size_t len), char *argument[]);
 
 /**
+ * \brief hg_export command for hglib API.
+ *
+ * Print the changeset header and diffs for one or more revisions. If no
+ * revision is given, the parent of the working directory is used.
+ *
+ * The information shown in the changeset header is: author, date, branch name
+ * (if non-default), changeset hash, parent(s) and commit comment.
+ *
+ * Options/Argument list option:
+ *
+ *	-o, --output	print output to file with formatted name
+ *	--switch-parent	diff against the second parent
+ *	-r, --rev		revisions to export
+ *	-a, --text		treat all files as text
+ *	-g, --git		use git extended diff format
+ *	--nodates		omit dates from diff headers
+ *
+ * To get export information use the hg_linestream_buffer returned value with
+ * hg_fetch_line_entry() function.
+ *
+ * If you use -o option, you still need to call hg_fetch_line_entry() function.
+ *
+ * \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_linestream_buffer A pointer to hg_linestream_buffer structure if 
+ *                              successful
+ * \retval NULL to indicate an error, with errno set appropriately.
+ *
+ * errno can be:
+ *      - hg_rawcommand errors
+ * */
+hg_linestream_buffer *hg_export(hg_handle *handle, int (*callback)
+			(const char *msg, size_t len), char *argument[]);
+
+/**
  * \brief The yield mechanism that will get the next entry.
  *
  * This function is used inside of hg_fetch_cset_entry() and hg_fetch_line_entry()