Patchwork [17,of,55,RFC,c-hglib:level1] hg_cat: creating a high level function for mercurial cat command

login
register
mail settings
Submitter Iulian Stana
Date Sept. 14, 2013, 12:35 a.m.
Message ID <0eee111297a5551f532f.1379118929@doppler>
Download mbox | patch
Permalink /patch/2461/
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 1379111505 -10800
#      Sat Sep 14 01:31:45 2013 +0300
# Node ID 0eee111297a5551f532f261612d6c96b810cedef
# Parent  e3a0213de50dc628b9e4d8cb610657c37c1dee24
hg_cat: creating a high level function for mercurial cat command

Patch

diff --git a/client.c b/client.c
--- a/client.c
+++ b/client.c
@@ -650,6 +650,26 @@ 
 	return exitcode;
 }
 
+/* The high level cat command for hglib API. */
+hg_linestream_buffer *hg_cat(hg_handle *handle, int (*callback)
+			(const char *msg, size_t len), char *argument[])
+{
+	hg_linestream_buffer *cbuf = malloc(sizeof(hg_csetstream_buffer));
+	cbuf->handle = handle;
+
+	cbuf->command = cmdbuilder("cat", argument, NULL);
+
+	if(hg_rawcommand(handle, cbuf->command) < 0){
+		return NULL;
+	}
+
+	cbuf->callback = callback;
+	cbuf->buffer = NULL;
+	cbuf->buf_size = 0;
+
+	return cbuf;
+}
+
 /* 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
@@ -757,7 +757,48 @@ 
  * */
 int hg_bundle(hg_handle *handle, int (*callback)(const char *msg, size_t len),
 							char *argument[]);
-		
+	
+/**
+ * \brief hg_cat command for hglib API.
+ *
+ * Print the specified files as they were at the given revision. If no revision
+ * is given, the parent of the working directory is used.
+ *
+ * Output may be to a file, in which case the name of the file is given using a
+ * format string. The formatting rules are the same as for the export command,
+ * with the following additions:
+ *
+ *	%s:	basename of file being printed
+ *	%d:	dirname of file being printed, or '.' if in repository root
+ *	%p:	root-relative path name of file being printed
+ *
+ * Options/Argument list option:
+ *
+ *	-o, --output	print output to file with formatted name
+ *	-r, --rev		print the given revision
+ *	--decode		apply any matching decode filter
+ *	-I, --include	include names matching the given patterns
+ *	-X, --exclude	exclude names matching the given patterns
+ *
+ * To get cat information use the returned hg_linestream_buffer structure 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_cat(hg_handle *handle, int (*callback)
+			(const char *msg, size_t len), char *argument[]);
+	
 /**
  * \brief The yield mechanism that will get the next entry.
  *