[PATCH 55 of 55 RFC c-hglib:level1] hg_version: creating a high level function for mercurial version command
Iulian Stana
julian.stana at gmail.com
Fri Sep 13 19:36:07 CDT 2013
# HG changeset patch
# User Iulian Stana <julian.stana at gmail.com>
# Date 1379118651 -10800
# Sat Sep 14 03:30:51 2013 +0300
# Node ID 6edd42c46d96dfb9a5e8e9e467b2f859c86c46cb
# Parent 6f885ae8f3c02696497e3a31c768629c0b5bf481
hg_version: creating a high level function for mercurial version command
diff --git a/client.c b/client.c
--- a/client.c
+++ b/client.c
@@ -1489,6 +1489,34 @@
return out;
}
+/* The high level version command for hglib API. */
+char *hg_version(hg_handle *handle, int(*callback)(const char *msg,
+ size_t len))
+{
+ int exitcode;
+ char **command = cmdbuilder("version", NULL , NULL);
+
+ if(hg_rawcommand(handle, command) < 0){
+ return NULL;
+ }
+ free(command);
+
+ exitcode = hg_runcommand(handle, callback, NULL);
+ if(exitcode)
+ return NULL;
+
+ char *out = get_output_data(handle);
+ char *origin = out;
+ char *version;
+ out = strstr(out, "version");
+ /* len('version ') == 8 */
+ version = out + 8;
+ out = strstr(out, ")");
+ origin[out - origin] = '\0';
+
+ return version;
+}
+
/* 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
@@ -2328,6 +2328,25 @@
size_t len));
/**
+ * \brief hg_version command for hglib API.
+ *
+ * Return hg version that runs the command server
+ *
+ * \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.
+ * \retval version Return the hg version. Also will indicate the end of
+ * version_command.
+ * \retval NULL To indicate an error.
+ *
+ * errno can be:
+ * - hg_rawcommand errors
+ *
+ * */
+char *hg_version(hg_handle *handle, int(*callback)(const char *msg,
+ size_t len));
+
+/**
* \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