Comments
Patch
@@ -152,6 +152,7 @@
return handle;
}
+
/*
* Close the connection for the given handle.
* */
@@ -175,6 +176,55 @@
return 0;
}
+/* Release data from handle pointers. */
+void free_data(hg_handle *handle){
+ if(handle->out_data){
+ free(handle->out_data);
+ handle->out_data = NULL;
+ handle->out_data_size = 0;
+ }
+}
+
+/**
+ * \brief Prepare the command for sending process.
+ *
+ * Replace all the blank space with the '\0' character.
+ * \param command an array that will contain the mercurial command
+ * \param cmd_size - array size
+ * \retval string representing the command that will be send to cmdsrv
+ * \retval *cmd_size will be set on string size
+ *
+ * \code
+ * char *command[] = {"tip", "-p", NULL};
+ * char *cmd_str = cmd_prepare(command, 0);
+ * prinf("==%s==", cmd_str);
+ * ---> ==tip\0-p==
+ * \endcode
+ * */
+char *cmd_prepare(char *const command[], int *cmd_size)
+{
+ size_t cmd_length = 0;
+ char *new_cmd;
+ int i = 0;
+
+ while(command[i]){
+ cmd_length += strlen(command[i]) + 1;
+ ++i;
+ }
+
+ new_cmd = malloc(cmd_length + 1);
+ i = 0;
+ while(command[i]){
+ strcpy(new_cmd, command[i]);
+ new_cmd += strlen(command[i]) + 1;
+ ++i;
+ }
+ new_cmd -= cmd_length;
+
+ *cmd_size = cmd_length - 1;
+ return new_cmd;
+}
+
/*
* Sending a command to the mercurial command server, through the given handle.
* */