[PATCH 53 of 55 RFC c-hglib:level1] hg_update: creating a high level function for mercurial update command

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


# HG changeset patch
# User Iulian Stana <julian.stana at gmail.com>
# Date 1379118474 -10800
#      Sat Sep 14 03:27:54 2013 +0300
# Node ID 4a430affaa639c3e7466b3570611baae9e79aae4
# Parent  164989405186a4fb1a481ea6c57ffbcfc93641ca
hg_update: creating a high level function for mercurial update command

diff --git a/client.c b/client.c
--- a/client.c
+++ b/client.c
@@ -1432,6 +1432,45 @@
 	return exitcode;
 }
 
+/* The high level update command for hglib API. */
+hg_update_entry *hg_update(hg_handle *handle, int(*callback)(const char *msg, 
+						size_t len), char *argument[])
+{
+	int exitcode;
+	char **command = cmdbuilder("update", argument , NULL);
+
+	if(hg_rawcommand(handle, command) < 0){
+		return NULL;
+	}
+	free(command);
+
+	exitcode = hg_runcommand(handle, callback, NULL);
+	if(exitcode)
+		return NULL;
+
+	hg_update_entry *update = malloc(sizeof(hg_update_entry));
+	char *out = get_output_data(handle);
+	char *tok = strtok(out, " ,");
+	int tok_numb = 0;
+	while(tok != NULL){
+		if(tok_numb % 3 == 0){
+			if(tok_numb / 3 == 0){
+				update->update = atoi(tok);
+			}else if(tok_numb / 3 == 1){
+				update->merge = atoi(tok);
+			}else if(tok_numb / 3 == 2){
+				update->removed = atoi(tok);
+			}else if(tok_numb / 3 == 3){
+				update->unresolved = atoi(tok);
+			}
+		}
+		++tok_numb;
+		tok = strtok(NULL, " ,");
+	}
+
+	return update;
+}
+
 /* 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
@@ -373,6 +373,38 @@
 }hg_summary_entry;
 
 /**
+ * \struct hg_update_entry
+ * \brief This structure contains the variables for a parse update entry. 
+ *
+ * \var hg_update_entry::update
+ * The update field will stock the number of updated files. 
+ * \var hg_update_entry::merge
+ * The merge field will stock the number of merged files. 
+ * \var hg_update_entry::removed
+ * The removed field will stock the number of removed files. 
+ * \var hg_update_entry::unresolved
+ * The unresolved field will stock the number of unresolved files. 
+ * 
+ * \typedef hg_update_entry
+ * \brief This structure contains the variables for a parse update entry. 
+ *
+ * \param update
+ * The update field will stock the number of updated files. 
+ * \param merge
+ * The merge field will stock the number of merged files. 
+ * \param removed
+ * The removed field will stock the number of removed files. 
+ * \param unresolved
+ * The unresolved field will stock the number of unresolved files. 
+ * */
+typedef struct hg_update_entry{
+	int update;
+	int merge;
+	int removed;
+	int unresolved;
+}hg_update_entry;
+
+/**
  * \brief Reading the header from cmdsrv.
  *
  * The function will read the header from the command server and will save it to
@@ -2231,6 +2263,46 @@
 						size_t len), char *argument[]);
 
 /**
+ * \brief hg_update command for hglib API.
+ *
+ * Update the repository's working directory to the specified changeset. If no
+ * changeset is specified, update to the tip of the current named branch and
+ * move the current bookmark (see hg help bookmarks).
+ *
+ * Update sets the working directory's parent revision to the specified
+ * changeset (see hg help parents).
+ *
+ * If the changeset is not a descendant or ancestor of the working directory's
+ * parent, the update is aborted. With the -c/--check option, the working
+ * directory is checked for uncommitted changes; if none are found, the working
+ * directory is updated to the specified changeset.
+ *
+ * Options/Argument list option:
+ *
+ *	-C, --clean	discard uncommitted changes (no backup)
+ *	-c, --check	update across branches if no uncommitted changes
+ *	-d, --date		tipmost revision matching date
+ *	-r, --rev		revision
+ *
+ *  aliases: up checkout co
+ *
+ * \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_update_entry  To indicate the end of update_command. Also will
+ * contain some useful information about the upate operation.
+ * \retval NULL To indicate an error.
+ *
+ * errno can be:
+ *      - hg_rawcommand errors
+ *      - hg_exitcode errors
+ *
+ * */
+hg_update_entry *hg_update(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()


More information about the Mercurial-devel mailing list