Patchwork [37,of,55,RFC,c-hglib:level1] hg_phase: creating a high level function for mercurial phase command

login
register
mail settings
Submitter Iulian Stana
Date Sept. 14, 2013, 12:35 a.m.
Message ID <2ef0b9466449a194a4d7.1379118949@doppler>
Download mbox | patch
Permalink /patch/2480/
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 1379115303 -10800
#      Sat Sep 14 02:35:03 2013 +0300
# Node ID 2ef0b9466449a194a4d71aa61996efdcd5e75b0a
# Parent  0b729e5b81951203e1251c4eb65df8be84bb0198
hg_phase: creating a high level function for mercurial phase command

Patch

diff --git a/client.c b/client.c
--- a/client.c
+++ b/client.c
@@ -1092,6 +1092,26 @@ 
 	return path;
 }
 
+/* The high level phase command for hglib API. */
+hg_linestream_buffer *hg_phase(hg_handle *handle, int(*callback)
+			(const char *msg, size_t len), char *argument[])
+{
+	hg_linestream_buffer *lbuf = malloc(sizeof(hg_linestream_buffer));
+	lbuf->handle = handle;
+
+	lbuf->command = cmdbuilder("phase", argument, NULL);
+
+	if(hg_rawcommand(handle, lbuf->command) < 0){
+		return NULL;
+	}
+
+	lbuf->callback = callback;
+	lbuf->buffer = NULL;
+	lbuf->buf_size = 0;
+
+	return lbuf;
+}
+
 /* 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)
@@ -1289,3 +1309,21 @@ 
 
 	return return_value;
 }
+
+/* The lbuf next step. */
+int hg_fetch_phase_entry(hg_linestream_buffer *pbuf, hg_rev_entry *pentry)
+{
+	char *buff = NULL;
+	int return_value = hg_fetch_line_entry(pbuf, &buff);
+
+	if(return_value <= 0)
+		return return_value;
+
+	pentry->rev = buff;
+	char *aux = strstr(buff, ":");
+	buff[aux - buff] = '\0';
+	pentry->name = aux + 2;
+
+	return return_value;
+}
+
diff --git a/client.h b/client.h
--- a/client.h
+++ b/client.h
@@ -1626,6 +1626,50 @@ 
 				size_t len), char *path_name, int *path_size);
 
 /**
+ * \brief hg_phase command for hglib API.
+ *
+ * With no argument, show the phase name of specified revisions.
+ *
+ * With one of -p/--public, -d/--draft or -s/--secret, change the phase value of
+ * the specified revisions.
+ *
+ * Unless -f/--force is specified, hg phase won't move changeset from a lower
+ * phase to an higher phase. Phases are ordered as follows:
+ *
+ * public < draft < secret
+ *
+ * Options/Argument list option:
+ * 
+ *	-p, --public	set changeset phase to public
+ *	-d, --draft	set changeset phase to draft
+ *	-s, --secret	set changeset phase to secret
+ *	-f, --force	allow to move boundary backward
+ *	-r, --rev		target revision
+ *
+ * To get phase information use the returned hg_linestream_buffer structure
+ * with hg_fetch_line_entry() or hg_fetch_manifest_entry().
+ *
+ * - Using the return value in hg_fetch_line_entry() function you will get 
+ * unparse data, one line at once.
+ * - Using the return value in hg_fetch_phase_entry() function you will get 
+ * the data parse in hg_rev_entry structure.
+ *
+ * \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_phase(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()
@@ -1780,5 +1824,24 @@ 
 int hg_fetch_manifest_entry(hg_linestream_buffer *lbuf, 
 						hg_manifest_entry *mentry);
 
+/**
+ * \brief The iterator step. Getting the next line.
+ *
+ * Some commands could perform huge amount of data, to pass this data to users
+ * in a parse way mode I provide this function. This function will return a line
+ * in a single call.
+ *
+ * \param pbuf The buffer structure to store line data.
+ * \param pentry Address where a line will be placed in a parse way.
+ * \retval 1  Succesful operation, pass the first find line to lentry pointer.
+ * \retval 0  To indicate the end of command, everything works well.
+ * \retval -1 to indicate an error, with errno set appropriately.
+ *
+ * errno can be:
+ *      - EINVAL  - Invalid argument (handle it's set to a null pointer)
+ *      - read(2) command errors
+ *      - read_header error
+ * */
+int hg_fetch_phase_entry(hg_linestream_buffer *lbuf, hg_rev_entry *pentry);
 
 #endif