[PATCH 50 of 55 RFC c-hglib:level1] hg_tags: creating a high level function for mercurial tags command

Iulian Stana julian.stana at gmail.com
Fri Sep 13 19:36:02 CDT 2013


# HG changeset patch
# User Iulian Stana <julian.stana at gmail.com>
# Date 1379118203 -10800
#      Sat Sep 14 03:23:23 2013 +0300
# Node ID 3e3b964c17ed8e117717dce8ae090976e9b6cc16
# Parent  06c9374f55e90df473cbd274027cb8527e125406
hg_tags: creating a high level function for mercurial tags command

diff --git a/client.c b/client.c
--- a/client.c
+++ b/client.c
@@ -1373,6 +1373,26 @@
 	return exitcode;
 }
 
+/* The high level tags command for hglib API. */
+hg_linestream_buffer *hg_tags(hg_handle *handle, int (*callback)
+			(const char *msg, size_t len))
+{
+	hg_linestream_buffer *lbuf = malloc(sizeof(hg_csetstream_buffer));
+	lbuf->handle = handle;
+
+	lbuf->command = cmdbuilder("tags", NULL, 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)
@@ -1603,3 +1623,8 @@
 	return return_value;
 }
 
+/* The lbuf next step. */
+int hg_fetch_tags_entry(hg_linestream_buffer *lbuf, hg_rev_entry *tentry)
+{
+	return hg_fetch_branches_entry(lbuf, tentry);
+}
diff --git a/client.h b/client.h
--- a/client.h
+++ b/client.h
@@ -330,6 +330,49 @@
 }hg_st_entry;
 
 /**
+ * \struct hg_summary_entry
+ * \brief This structure contains the variables for a parse summary entry. 
+ *
+ * \var hg_summary_entry::parent
+ * The parent field will stock information about rev/node/tags/message. 
+ * \var hg_summary_entry::branch
+ * The branch field will stock the current branch. 
+ * \var hg_summary_entry::commmit
+ * True if the working directory is clean, False otherwise. 
+ * \var hg_summary_entry::update
+ * The update field will stock the number of available updates
+ * \var hg_summary_entry::remote
+ * The remote field will stock (in, in bookmarks, out, out bookmarks).
+ * \var hg_summary_entry::mq
+ * The mq field will stock (applied, unapplied) mq patches. 
+ *
+ * \typedef hg_summary_entry
+ * \brief This structure contains the variables for a parse update entry. 
+ *
+ * \param parent
+ * The parent field will stock information about rev/node/tags/message. 
+ * \param branch
+ * The branch field will stock the current branch. 
+ * \param commmit
+ * True if the working directory is clean, False otherwise. 
+ * \param update
+ * The update field will stock the number of available updates
+ * \param remote
+ * The remote field will stock (in, in bookmarks, out, out bookmarks).
+ * \param mq
+ * The mq field will stock (applied, unapplied) mq patches. *
+ *
+ **/
+typedef struct hg_summary_entry{
+	char *parent;
+	char *branch;
+	char *commit;
+	char *update;
+	char *remote;
+	char *mq;
+}hg_summary_entry;
+
+/**
  * \brief Reading the header from cmdsrv.
  *
  * The function will read the header from the command server and will save it to
@@ -2101,6 +2144,35 @@
  **/
 int hg_tag(hg_handle *handle, int(*callback)(const char *msg, size_t len),
 							char *argument[]);
+
+/**
+ * \brief hg_tags command for hglib API.
+ * 
+ * This lists both regular and local tags.
+ *
+ * To get tags information use the returned hg_linestream_buffer structure
+ * with hg_fetch_line_entry() or hg_fetch_tags_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_tags_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_tags(hg_handle *handle, int(*callback)
+			(const char *msg, size_t len));
+
 	
 /**
  * \brief The yield mechanism that will get the next entry.
@@ -2176,7 +2248,7 @@
 int hg_fetch_line_entry(hg_linestream_buffer *lbuf, char **lentry);
 
 /**
- * \brief The iterator step. Getting the next line.
+ * \brief The yield mechanism that will get the next annotate.
  *
  * 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
@@ -2197,7 +2269,7 @@
 						hg_annotate_entry *aentry);
 
 /**
- * \brief The iterator step. Getting the next line.
+ * \brief The yield mechanism that will get the next bookmark.
  *
  * 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
@@ -2217,7 +2289,7 @@
 int hg_fetch_bookmarks_entry(hg_linestream_buffer *lbuf, hg_rev_entry *rentry);
 
 /**
- * \brief The iterator step. Getting the next line.
+ * \brief The yield mechanism that will get the next branch.
  *
  * 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
@@ -2237,7 +2309,7 @@
 int hg_fetch_branches_entry(hg_linestream_buffer *lbuf, hg_rev_entry *rentry);
 
 /**
- * \brief The iterator step. Getting the next line.
+ * \brief The yield mechanism that will get the next manifest 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
@@ -2258,7 +2330,7 @@
 						hg_manifest_entry *mentry);
 
 /**
- * \brief The iterator step. Getting the next line.
+ * \brief The yield mechanism that will get the next phase.
  *
  * 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
@@ -2278,7 +2350,7 @@
 int hg_fetch_phase_entry(hg_linestream_buffer *lbuf, hg_rev_entry *pentry);
 
 /**
- * \brief The iterator step. Getting the next line.
+ * \brief The yield mechanism that will get the next status.
  *
  * 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
@@ -2297,4 +2369,24 @@
  * */
 int hg_fetch_status_entry(hg_linestream_buffer *lbuf, hg_st_entry *sentry);
 
+/**
+ * \brief The yield mechanism that will get the next tag.
+ *
+ * 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 lbuf The buffer structure to store line data.
+ * \param sentry 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_tag_entry(hg_linestream_buffer *lbuf, hg_rev_entry *tentry);
+
 #endif


More information about the Mercurial-devel mailing list