[PATCH 32 of 55 RFC c-hglib:level1] hg_manifest: creating a high level function for mercurial manifest command

Iulian Stana julian.stana at gmail.com
Sat Sep 14 00:35:44 UTC 2013


# HG changeset patch
# User Iulian Stana <julian.stana at gmail.com>
# Date 1379112845 -10800
#      Sat Sep 14 01:54:05 2013 +0300
# Node ID 6887a39c19974bcf519c0a49797d61e26e9ffef8
# Parent  c67bbcf6e45df6deb1e0f009c5f1145c541b4b83
hg_manifest: creating a high level function for mercurial manifest command

diff --git a/client.c b/client.c
--- a/client.c
+++ b/client.c
@@ -953,6 +953,26 @@
 	return cbuf;
 }
 
+/* The high level manifest command for hglib API. */
+hg_linestream_buffer *hg_manifest(hg_handle *handle, int (*callback)
+			(const char *msg, size_t len), char *argument[])
+{
+	hg_linestream_buffer *mbuf = malloc(sizeof(hg_linestream_buffer));
+	mbuf->handle = handle;
+
+	mbuf->command = cmdbuilder("manifest", argument, "--debug", NULL);
+
+	if(hg_rawcommand(handle, mbuf->command) < 0){
+		return NULL;
+	}
+
+	mbuf->callback = callback;
+	mbuf->buffer = NULL;
+	mbuf->buf_size = 0;
+
+	return mbuf;
+}
+
 /* 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)
@@ -1129,3 +1149,24 @@
 
 	return return_value;
 }
+
+/* The lbuf next step. Getting the next changeset. */
+int hg_fetch_manifest_entry(hg_linestream_buffer *lbuf, 
+						hg_manifest_entry *mentry)
+{
+	char *buff = NULL;
+	int return_value = hg_fetch_line_entry(lbuf, &buff);
+
+	if(return_value <= 0)
+		return return_value;
+
+	mentry->node = buff;
+	buff[40] = '\0';
+	char *perm = buff + 41;
+	buff[44] = '\0';
+	mentry->perm = atoi(perm);
+	mentry->mode = buff[45];
+	mentry->name = buff + 47;
+
+	return return_value;
+}
diff --git a/client.h b/client.h
--- a/client.h
+++ b/client.h
@@ -210,6 +210,38 @@
 }hg_cset_entry;
 
 /**
+ * \struct hg_manifest_entry
+ * \brief This structure will contain information about a manifest entry. 
+ *
+ * \var hg_manifest_entry::node
+ * The node field will stock the node hash.
+ * \var hg_manifest_entry::name
+ * The name field will stock a content or a name(file name).
+ * \var hg_manifest_entry::perm
+ * The perm field will stock the file permision.
+ * \var hg_manifest_entry::mode
+ * The mode field will stock the mode.
+ *
+ * \typedef hg_manifest_entry
+ * \brief This structure will contain information about a manifest entry. 
+ *
+ * \param node
+ * The node field will stock the node hash.
+ * \param name
+ * The name field will stock a content or a name(file name).
+ * \param perm
+ * The perm field will stock the file permision.
+ * \param mode
+ * The mode field will stock the mode.
+ * */
+typedef struct hg_manifest_entry{
+	char *node;
+	char *name;
+	int perm;
+	char mode;
+}hg_manifest_entry;
+
+/**
  * \struct hg_rev_entry
  * \brief This structure will contain revision information about a file.
  * (rev:node name) 
@@ -1387,6 +1419,46 @@
 						size_t len), char *argument[]);
 
 /**
+ * \brief hg_manifest command for hglib API.
+ *
+ * Print a list of version controlled files for the given revision. If no
+ * revision is given, the first parent of the working directory is used, or the
+ * null revision if no revision is checked out.
+ *
+ * With -v, print file permissions, symlink and executable bits. With --debug,
+ * print file revision hashes.
+ *
+ * If option --all is specified, the list of all files from all revisions is
+ * printed. This includes deleted and renamed files.
+ *
+ * Options/Argument list option:
+ *
+ *	-r, --rev	revision to display
+ *	--all	list files from all revisions
+ *
+ * To get manifest 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_manifest_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_manifest(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()
@@ -1520,4 +1592,26 @@
  * */
 int hg_fetch_branches_entry(hg_linestream_buffer *lbuf, hg_rev_entry *rentry);
 
+/**
+ * \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 lbuf The buffer structure to store line data.
+ * \param mentry 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_manifest_entry(hg_linestream_buffer *lbuf, 
+						hg_manifest_entry *mentry);
+
+
 #endif



More information about the Mercurial-devel mailing list