Patchwork [48,of,55,RFC,c-hglib:level1] hg_summary: creating a high level function for mercurial summary command

login
register
mail settings
Submitter Iulian Stana
Date Sept. 14, 2013, 12:36 a.m.
Message ID <f364c9f6e36ff1a50bb5.1379118960@doppler>
Download mbox | patch
Permalink /patch/2493/
State Deferred, archived
Headers show

Comments

Iulian Stana - Sept. 14, 2013, 12:36 a.m.
# HG changeset patch
# User Iulian Stana <julian.stana@gmail.com>
# Date 1379116524 -10800
#      Sat Sep 14 02:55:24 2013 +0300
# Node ID f364c9f6e36ff1a50bb5ffa13f3a04ee0e42f9d9
# Parent  959eeb9a3691f2cb57b0a2e6b18ae6db930c089a
hg_summary: creating a high level function for mercurial summary command

Patch

diff --git a/client.c b/client.c
--- a/client.c
+++ b/client.c
@@ -1292,6 +1292,70 @@ 
 	return sbuf;
 }
 
+
+/* The high level tag command for hglib API. */
+hg_summary_entry *hg_summary(hg_handle *handle, int(*callback)
+			(const char *msg, size_t len), char *argument[])
+{
+	int exitcode;
+	char **command = cmdbuilder("summary", argument , NULL);
+
+	if(hg_rawcommand(handle, command) < 0){
+		return NULL;
+	}
+	free(command);
+
+	exitcode = hg_runcommand(handle, callback, NULL);
+	if(exitcode != 0)
+		return NULL;
+
+	char *out_data = get_output_data(handle);
+	char *aux = out_data;
+	char *verify;
+	hg_summary_entry *sum = malloc(sizeof(hg_summary_entry));
+
+	sum->parent = aux + 8;
+
+
+	aux = strstr(aux, "branch: ") + 8;
+	while(verify = strstr(aux, "branch: "), verify != NULL){
+		aux = verify + 8;
+	}
+
+	sum->branch = aux;
+	out_data[aux - out_data - 9] = '\0';
+
+	aux = strstr(aux, "commit: ") + 8;
+	sum->commit = aux;
+	out_data[aux - out_data - 9] = '\0';
+
+	aux = strstr(aux, "update: ") + 8;
+	sum->update = aux;
+	out_data[aux - out_data - 9] = '\0';
+
+	verify = strstr(aux, "remote: ");
+	if(verify){
+		aux = verify + 8;
+		sum->remote = aux;
+		out_data[aux - out_data - 9] = '\0';
+	}else{
+		sum->remote = NULL;
+	}
+
+	verify = strstr(aux, "mq: ");
+	if(verify){
+		aux = verify + 4;
+		sum->mq = aux;
+		out_data[aux - out_data - 5] = '\0';
+	}else{
+		sum->mq = NULL;
+	}
+	aux = strstr(aux, "\n");
+	out_data[aux - out_data] = '\0';
+
+	return sum;
+}
+
 /* 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
@@ -2038,7 +2038,35 @@ 
  * */
 hg_linestream_buffer *hg_status(hg_handle *handle, int(*callback)
 			(const char *msg, size_t len), char *argument[]);
-			
+
+/**
+ * \brief hg_summary command for hglib API.
+ * 
+ * This generates a brief summary of the working directory state, including
+ * parents, branch, commit status, and available updates.
+ *
+ * With the --remote option, this will check the default paths for incoming and
+ * outgoing changes. This can be time-consuming.
+ *
+ * Options/Argument list option:
+ *
+ *	--remote	check for push and pull
+ *
+ *	aliases: sum
+ *
+ * \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 summary  A parse data structure.
+ * \retval NULL     To indicate an error with errno set.
+ *
+ * errno can be:
+ *      - hg_rawcommand errors
+ **/
+hg_summary_entry *hg_summary(hg_handle *handle, int(*callback)
+			(const char *msg, size_t len), char *argument[]);
+	
 /**
  * \brief The yield mechanism that will get the next entry.
  *