Patchwork [09,of,55,RFC,c-hglib:level1] client: adding cset structure and cset parser

login
register
mail settings
Submitter Iulian Stana
Date Sept. 14, 2013, 12:35 a.m.
Message ID <f21b87f4e6a36ca368f4.1379118921@doppler>
Download mbox | patch
Permalink /patch/2453/
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 1379110577 -10800
#      Sat Sep 14 01:16:17 2013 +0300
# Node ID f21b87f4e6a36ca368f469e5e5c6673aafa98f66
# Parent  f3bcd2f00b3ee02fba48024dd95c757509791d66
client: adding cset structure and cset parser

Patch

diff --git a/client.c b/client.c
--- a/client.c
+++ b/client.c
@@ -314,12 +314,85 @@ 
 	return handle->out_data;
 }
 
+/**
+ * \brief 'Parse a changeset'. It's more like pointing to the correct position.
+ *
+ * The changeset could be found on buff pointer. To not duplicate the data I 
+ * choose to point every hg_cset_entry field to the right position.
+ * \param cset The pointer where changeset could be found.
+ * \param ce   The hg_cset_entry structure where the changeset will be parse.
+ * \retval 0 if successful.
+ * */
+int parse_changeset(char *cset, hg_cset_entry *ce)
+{
+	char *position = cset;
+	/* set pointer for revision position */
+	ce->rev = cset;
+	position = strstr(position, "\n");
+	cset[position - cset] = '\0';
+
+	/* set pointer for node position */
+	ce->node = position + 1;
+	position = strstr(position + 1, "\n");
+	cset[position - cset] = '\0';
+
+	/* set pointer for tag position */
+	ce->tags = position + 1;
+	position = strstr(position + 1, "\n");
+	cset[position - cset] = '\0';
+
+	/* set pointer for branch position */
+	ce->branch = position + 1;
+	position = strstr(position + 1, "\n");
+	cset[position - cset] = '\0';
+
+	/* set pointer for author position */
+	ce->author = position + 1;
+	position = strstr(position + 1, "\n");
+	cset[position - cset] = '\0';
+
+	/* set pointer for data position */
+	ce->date = position + 1;
+	position = strstr(position + 1, "\n");
+	cset[position - cset] = '\0';
+
+	/* set pointer for description position */
+	ce->desc = position + 1;
+	/* */
+	return 0;
+}
+
 /* Will return a zero-length string. */
 char *hg_abort(const char *msg, size_t size)
 {
 	return "";
 }
 
+int trash_data(hg_handle *handle, int(*callback)(const char *msg, size_t len))
+{
+	char buff[4096];
+	int nb;
+	int exitcode;
+	hg_header *head = hg_read_header(handle);
+	while(head->channel != r){
+		head = hg_read_header(handle);
+		/* trash output data. */
+		if(head->channel == o){
+			hg_rawread(handle, buff, 4096);
+		}
+		/* handle error data. */
+		else if(head->channel == e){
+			if(nb = hg_rawread(handle, buff, 4096), nb > 0)
+				if(callback)
+					callback(buff, strlen(buff));
+		}
+	}
+	if(head->channel == r){
+		exitcode = hg_exitcode(handle);
+	}
+	return exitcode;
+}
+
 /* Read and add to some pointers the received data from cmdserver. */
 int hg_runcommand(hg_handle *handle, int (*callback)(const char *msg, size_t len),
 				char *(*prompt)(const char *msg, size_t len))
diff --git a/client.h b/client.h
--- a/client.h
+++ b/client.h
@@ -163,6 +163,53 @@ 
 }hg_annotate_entry;
 
 /**
+ * \struct hg_cset_entry
+ * \brief This structure will contain informations about a changeset.
+ *
+ * \var hg_cset_entry::author
+ * The author field will stock the author of the cset.
+ * \var hg_cset_entry::branch
+ * The branch field will stock the cset branch.
+ * \var hg_cset_entry::date
+ * The date field will stock the data when cset was created.
+ * \var hg_cset_entry::desc
+ * The desc field will stock the cset message.
+ * \var hg_cset_entry::node
+ * The node field will stock the node hash.
+ * \var hg_cset_entry::rev
+ * The rev field will stock the revision number.
+ * \var hg_cset_entry::tags
+ * The tags field will stock the tag of the cset.
+ *
+ * \typedef hg_cset_entry
+ * \brief This structure will contain informations about a changeset.
+ *
+ * \param author
+ * The author field will stock the author of the cset.
+ * \param branch
+ * The branch field will stock the cset branch.
+ * \param date
+ * The date field will stock the data when cset was created.
+ * \param desc
+ * The desc field will stock the cset message.
+ * \param node
+ * The node field will stock the node hash.
+ * \param rev
+ * The rev field will stock the revision number.
+ * \param tags
+ * The tags field will stock the tag of the cset.
+ * */
+typedef struct hg_cset_entry{
+	char *author; 
+	char *branch; 
+	char *date;
+	char *desc;
+	char *node;
+	char *rev;
+	char *tags;
+}hg_cset_entry;
+
+/**
  * \brief Reading the header from cmdsrv.
  *
  * The function will read the header from the command server and will save it to