@@ -17,7 +17,57 @@
#define CHANGESET "\\0{rev}\\n{node}\\n{tags}\\n{branch}\\n{author}\
\\n{date|isodate}\\n{desc}"
+/* return the output data. */
+char *get_output_data(hg_handle *handle)
+{
+ return handle->out_data;
+}
+/* Read and add to some pointers the received data from cmdserver. */
+int runcommand(hg_handle *handle, int (*callback)(const char *msg, size_t len),
+ char *(*prompt)(const char *msg, size_t len))
+{
+ char buff[4096];
+ int exitcode;
+ int ns;
+ char *err = "unexpected data on required channel";
+ char *w_data;
+ while(hg_next_channel(handle) != 'r'){
+ /* output channels 'o', 'e' channels verify in rawread func. */
+ while(ns = hg_rawread(handle, buff, 4096), ns > 0){
+ if(hg_current_channel(handle) == 'o'){
+ char *out = handle->out_data;
+ adding_data(&handle->out_data, buff,
+ (!out)? 0 : handle->out_data_size, ns);
+ handle->out_data_size += ns;
+ }
+ else if(hg_current_channel(handle) == 'e'){
+ if(callback)
+ callback(buff, strlen(buff));
+ }
+ }
+ switch (hg_next_channel(handle)){
+ case 'I':
+ break;
+ case 'L':
+ w_data = prompt(handle->out_data,
+ strlen(handle->out_data));
+ hg_rawwrite(handle, w_data, strlen(w_data));
+ break;
+ case 'r':
+ break;
+ /* a channel that we don't know and can't ignore*/
+ default:
+ if(callback)
+ callback(err, strlen(err));
+ return 1;
+ }
+ }
+ if(hg_next_channel(handle) == 'r'){
+ exitcode = hg_exitcode(handle);
+ }
+ return exitcode;
+}
/**
* \brief 'Parse a changeset'. It's more like pointing to the correct position.
@@ -91,6 +141,22 @@
return new_cset_size;
}
+/* The high level add command for hglib API.*/
+int hg_add(hg_handle *handle, int (*callback)(const char *msg, size_t len),
+ char *argument[])
+{
+ int exitcode;
+ char **command = cmdbuilder("add", argument, NULL);
+
+ if(hg_rawcommand(handle, command) < 0){
+ return -1;
+ }
+ free(command);
+
+ exitcode = runcommand(handle, callback, NULL);
+
+ return exitcode;
+}
/* The high level log command for hglib API. */
hg_csetstream_buffer *hg_log(hg_handle *handle, char *option[])
@@ -233,6 +233,30 @@
* */
int hg_exitcode(hg_handle *handle);
+/* return the output data. */
+char *get_output_data(hg_handle *handle);
+
+/**
+ * \brief hg_add command for hglib API.
+ *
+ * Add the specified files on the next commit.
+ * If no files are given, add all files to the repository.
+ *
+ * dryrun - do no perform actions
+ * subrepos - recurse into subrepositories
+ * include - include names matching the given patterns
+ * exclude - exclude names matching the given patterns
+ *
+ * \param handle The handle of the connection, wherewith I want to communicate
+ * \param option The option list for mercurial add command.
+ * \retval exitcode To indicate the end of add_command.
+ *
+ * errno can be:
+ * - hg_rawcommand errors
+ * */
+int hg_add(hg_handle *handle, int (*callback)(const char *msg, size_t len),
+ char *argument[]);
+
/**
* \brief hg_log command for hglib API.
*
@@ -89,11 +89,16 @@
{
printf("Select test case to run:\n");
printf("1) log \n");
+ printf("2) add \n");
printf("\n");
printf("Your choice: ");
}
-
+int callback(const char *msg, size_t len)
+{
+ printf("message = %s\n", msg);
+ return 1;
+}
/***** Main function. *******/
/**
@@ -106,7 +111,7 @@
print_select_case();
scanf("%d", &select_case);
- if(select_case < 1 || select_case > 1){
+ if(select_case < 1 || select_case > 2){
printf("Your choice is not an option...\n");
return -1;
}
@@ -122,6 +127,19 @@
hg_close(&handle);
clean_tmp();
break;
+ case 2:
+ setup_tmp();
+
+ system("touch 'foo_bar'");
+
+ handle = hg_open(NULL, "");
+ hg_add(handle, &callback, NULL);
+ char *commit_arg[] = {"-m", "-l", NULL};
+ system("hg st");
+ hg_commit(handle, &callback, commit_arg);
+ hg_close(&handle);
+ clean_tmp();
+ break;
}
return 0;